[skills] Fix auto-capture-claude-code parser and add ingest size guard#388
Conversation
The reference hook script failed silently against real Claude Code sessions: 1. parseTranscript expected a plaintext "Human:/Assistant:" format, but Claude Code writes transcripts as JSONL (one JSON object per line, type-tagged). The plaintext parser matched zero turns on every real transcript, so the hook always logged "skipped:too_short" and captured nothing. Rewrote it to parse JSONL — extracting type:user/assistant turns, excluding tool-result messages and sidechain (subagent) turns. 2. No payload size guard. Long sessions exceed the ingest embedding model's ~8191-token limit, so /ingest returned HTTP 500 (and, because the endpoint upserts in parallel with embedding, left an embedding-less row). Added a 24k-char cap (OB_CAPTURE_MAX_CHARS) that preserves the session start and end and drops the middle with a marker. Verified on real Claude Code transcripts (16-turn parse; oversized session truncated to <24k and captured HTTP 200). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MvLAf6xzHoGeGE9h3PWemh
OB1 PR Gate✅ Folder structure — All files are in allowed directories Result: All 15 checks passed! Ready for human review. Post-Merge TasksThese don't block merge — they're reminders for admins after this PR lands.
|
Contribution Type
What does this do?
Fixes two bugs in
skills/auto-capture-claude-code/session-end-capture.mjsthat made the reference hook capture nothing against real Claude Code sessions:parseTranscriptexpected a plaintextHuman:/Assistant:format, but Claude Code writes transcripts as JSONL (one type-tagged JSON object per line). The plaintext parser matched zero turns on every real transcript → the hook always loggedskipped:too_shortand captured nothing. Rewrote it to parse JSONL: extracttype:user/assistantturns, exclude tool-result messages and sidechain (subagent) turns./ingestreturned HTTP 500 (and, because the endpoint upserts in parallel with the embedding call, left an embedding-less row). Added a 24k-char cap (OB_CAPTURE_MAX_CHARS) that keeps the session start and end and drops the middle with a marker.Only
session-end-capture.mjs+ a version bump inmetadata.json. No behavior change to any Edge Function.Requirements
Node.js 18+, a deployed Open Brain (
open-brain-rest/ingest+MCP_ACCESS_KEY). No new dependencies.Checklist
🤖 Generated with Claude Code