Skip to content

[skills] Fix auto-capture-claude-code parser and add ingest size guard#388

Open
eazene wants to merge 1 commit into
NateBJones-Projects:mainfrom
eazene:contrib/ezanaazene/fix-auto-capture-parser-truncation
Open

[skills] Fix auto-capture-claude-code parser and add ingest size guard#388
eazene wants to merge 1 commit into
NateBJones-Projects:mainfrom
eazene:contrib/ezanaazene/fix-auto-capture-parser-truncation

Conversation

@eazene

@eazene eazene commented Jul 5, 2026

Copy link
Copy Markdown

Contribution Type

  • Repo improvement (bug fix to an existing skill)

What does this do?

Fixes two bugs in skills/auto-capture-claude-code/session-end-capture.mjs that made the reference hook capture nothing against real Claude Code sessions:

  1. Transcript parserparseTranscript expected a plaintext Human:/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 logged skipped:too_short and captured nothing. Rewrote it to parse JSONL: extract type:user/assistant turns, exclude 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 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 in metadata.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

  • I've read CONTRIBUTING.md
  • Tested on my own Open Brain instance (real 16-turn transcript parses; oversized session truncates to <24k and captures HTTP 200)
  • No credentials, API keys, or secrets are included

🤖 Generated with Claude Code

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
@github-actions github-actions Bot added the skill Contribution: reusable AI client skill or prompt pack label Jul 5, 2026
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

OB1 PR Gate

Folder structure — All files are in allowed directories
Required files — README.md and metadata.json found in all contribution folders
Metadata valid — All metadata.json files passed JSON Schema validation
No credentials — No API keys, tokens, or secrets detected
SQL safety — No destructive SQL or core table modifications
Category artifacts — Required file types present for each category
PR format — Title follows [category] Description format
No binary blobs — No oversized or binary files
README completeness — All READMEs include Prerequisites, Steps, and Expected Outcome
Contribution dependencies — All declared skill and primitive dependencies exist and are linked in README
LLM clarity review — Covered by Claude PR Review workflow
Remote MCP pattern — No local MCP server patterns detected — uses remote MCP correctly
Tool audit link — Extensions/integrations link to the MCP Tool Audit guide
Scope check — All changes are within the contribution folder(s)
Internal links — All relative links in READMEs resolve to existing files

Result: All 15 checks passed! Ready for human review.


Post-Merge Tasks

These don't block merge — they're reminders for admins after this PR lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skill Contribution: reusable AI client skill or prompt pack

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant