- Reset master to upstream/main (16,697 commits) - Overlay 2,271 local-only files (skills, tools, workspace, configs, apps) - Restore IDENTITY.md and USER.md templates - Build verified, gateway running, Discord working Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
94 lines
3.6 KiB
Bash
94 lines
3.6 KiB
Bash
#!/usr/bin/env bash
|
|
# Jarvis Deep Context Memory Tracker
|
|
# Learn and remember project patterns, preferences, and decisions
|
|
|
|
set -euo pipefail
|
|
|
|
CONTEXT_DIR="/home/alex/clawd/data/context"
|
|
TRACKER_LOG="/home/alex/clawd/logs/jarvis-context.log"
|
|
MEMORY_DB="$CONTEXT_DIR/memory.json"
|
|
|
|
log() {
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$TRACKER_LOG"
|
|
}
|
|
|
|
# Create directories
|
|
mkdir -p "$CONTEXT_DIR"
|
|
mkdir -p "$(dirname "$TRACKER_LOG")"
|
|
|
|
log "=== CONTEXT TRACKING STARTED ==="
|
|
|
|
# Initialize memory DB if not exists
|
|
if [ ! -f "$MEMORY_DB" ]; then
|
|
echo '{"projects":{},"patterns":{},"preferences":{},"decisions":[]}' > "$MEMORY_DB"
|
|
fi
|
|
|
|
# Track active Kanban projects
|
|
if kanban_data=$(timeout 5 curl -sf http://192.168.1.220:5003/api/tasks 2>/dev/null); then
|
|
active_projects=$(echo "$kanban_data" | jq -r '[.[] | select(.status != "done")] | group_by(.tags) | map({tags: .[0].tags, count: length}) | sort_by(.count) | reverse | .[0:5]' 2>/dev/null || echo "[]")
|
|
|
|
log "📊 Active project areas: $(echo "$active_projects" | jq -c '.')"
|
|
|
|
# Update memory
|
|
tmp=$(mktemp)
|
|
jq --argjson projects "$active_projects" '.projects.kanban_active = $projects | .projects.last_updated = now' "$MEMORY_DB" > "$tmp" && mv "$tmp" "$MEMORY_DB"
|
|
fi
|
|
|
|
# Track Git activity patterns
|
|
if [ -d /home/alex/clawd/.git ]; then
|
|
recent_commits=$(cd /home/alex/clawd && git log --since="24 hours ago" --pretty=format:"%s" 2>/dev/null | head -10 || echo "")
|
|
|
|
if [ -n "$recent_commits" ]; then
|
|
commit_count=$(echo "$recent_commits" | wc -l)
|
|
log "📊 Recent activity: $commit_count commits in last 24h"
|
|
|
|
# Extract patterns from commit messages
|
|
patterns=$(echo "$recent_commits" | grep -oE "^[A-Z][a-z]+:" | sort | uniq -c | sort -rn | head -3 || echo "")
|
|
|
|
if [ -n "$patterns" ]; then
|
|
log "📊 Commit patterns: $patterns"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Track working hours pattern
|
|
current_hour=$(date '+%H')
|
|
tmp=$(mktemp)
|
|
jq --arg hour "$current_hour" '.patterns.working_hours += [$hour] | .patterns.working_hours = (.patterns.working_hours | sort | unique | .[-100:])' "$MEMORY_DB" > "$tmp" && mv "$tmp" "$MEMORY_DB"
|
|
|
|
# Track most used tools/commands
|
|
if [ -f ~/.bash_history ]; then
|
|
top_commands=$(tail -100 ~/.bash_history 2>/dev/null | awk '{print $1}' | sort | uniq -c | sort -rn | head -5 || echo "")
|
|
|
|
if [ -n "$top_commands" ]; then
|
|
log "📊 Recent command patterns: $(echo "$top_commands" | tr '\n' '; ')"
|
|
fi
|
|
fi
|
|
|
|
# Learn preferences from recent actions
|
|
if [ -f /home/alex/clawd/logs/jarvis-delegation.log ]; then
|
|
recent_delegations=$(tail -50 /home/alex/clawd/logs/jarvis-delegation.log 2>/dev/null | grep "agent:" | cut -d':' -f3 | sort | uniq -c | sort -rn || echo "")
|
|
|
|
if [ -n "$recent_delegations" ]; then
|
|
preferred_agent=$(echo "$recent_delegations" | head -1 | awk '{print $2}')
|
|
log "📊 Preferred agent: $preferred_agent"
|
|
|
|
tmp=$(mktemp)
|
|
jq --arg agent "$preferred_agent" '.preferences.preferred_agent = $agent' "$MEMORY_DB" > "$tmp" && mv "$tmp" "$MEMORY_DB"
|
|
fi
|
|
fi
|
|
|
|
# Generate insights
|
|
insights=$(jq -r '
|
|
"Active projects: " + (.projects.kanban_active | length | tostring) + "\n" +
|
|
"Working hours trend: " + (.patterns.working_hours | if length > 10 then "Regular schedule" else "Irregular" end) + "\n" +
|
|
"Preferred agent: " + (.preferences.preferred_agent // "not set")
|
|
' "$MEMORY_DB" 2>/dev/null || echo "No insights yet")
|
|
|
|
log "🧠 Current insights:"
|
|
echo "$insights" | while read -r line; do
|
|
log " $line"
|
|
done
|
|
|
|
log "=== CONTEXT TRACKING COMPLETE ==="
|