Files
loki/scripts
Mao NakamotoandClaude Opus 4.7 7293d3bf0f feat(activity): ingest local Claude Code chats into unified timeline
Before this commit, /activity only knew about prompts dispatched through
/control and runs spawned by orchestration. The much larger pool of
context — every time the founder typed into a local Claude Code session
in their terminal — sat invisible on disk in the JSONL transcripts the
CLI writes to ~/.claude/projects/<encoded-cwd>/<sessionId>.jsonl. The
"god-level context-aware" ask is to fuse the two streams so /activity
becomes "everything you typed about this project anywhere," which is
what an agent fleet's activity view should always have been.

Mechanism:
  1. New table claude_code_history mirrors per-event metadata from the
     JSONL transcripts. (session_id, event_uuid) is UNIQUE so re-ingest
     is idempotent — incremental sync is just a re-run.
  2. scripts/ingest-claude-code-history.ts walks the projects dir,
     resolves cwd → user_projects.dir_path → projectKey, and inserts
     user + assistant turns with ON CONFLICT DO NOTHING. Backfilled the
     31,284 historical events on first run (FleetCrown 11.7k, revamp-it
     6.3k, OrangeCat 5.2k, etc.).
  3. digests.ts pulls the user-only slice into the digest timeline as
     a new "local_chat" kind, includes those events in per-project
     activity counts so the chip wall ranks projects honestly, and
     bumps MAX_TIMELINE_ITEMS 80→120 so a busy day fits without
     starving prompts/runs.

EventStream renders the new kind without changes — it was already
content-agnostic. A FilterCard toggle for "include/exclude local chats"
is a natural follow-up but the timeline is already useful as-is.

Schema applied to local Postgres via raw SQL because drizzle-kit push
wanted to interactively confirm an unrelated agent_tokens.token
constraint backfill. The schema file is the SSOT; this commit is the
source of truth a future migration tool will diff against.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-10 17:15:23 +02:00
..