/** * Claude Code transcript capture connector (FEAT-449). * * Root cause (2026-07-09 distill-starvation dig): the ingest pipeline was * fully starved — `ingest.log` showed 0 successful ingests and 786 * `transcript file not found` errors. The astramem-plugin SubagentStop / * session_end hook read the Claude Code `.jsonl` transcript file on a * DEFERRED sweep, racing worktree/subagent cleanup — by read time the file * was already deleted. `/ingest/transcript` only ever accepted CONTENT * (never a path — src/server/routes/ingest.ts), so the read-races-cleanup * failure was entirely client-side. * * This module reads the transcript CONTENT at the moment the hook fires * (file still guaranteed live) and converts it into the same canonical * transcript envelope `/ingest/transcript` already accepts — the VALUE is * captured immediately, decoupled from any later read. Mirrors * src/capture/codex.ts's structure and tolerance: unknown/malformed lines * are skipped, never fatal. * * Claude Code's on-disk transcript format (main session or a * `subagents/agent-*.jsonl` sidecar): one JSON object per line, each * carrying `type: 'user' | 'assistant' | ...`, a nested `message: {role, * content}` (content is either a plain string or an array of Anthropic * content blocks — only `type: 'text'` blocks are conversational), and * `sessionId` / `cwd` fields repeated on (most) lines. */ export interface ClaudeTurn { role: 'user' | 'assistant'; text: string; } export interface ParsedClaudeTranscript { sessionId: string; cwd: string | null; turns: ClaudeTurn[]; } export type ClaudeCaptureEvent = 'subagent_stop' | 'session_end'; export interface ClaudeCaptureEnvelope { event: ClaudeCaptureEvent; session_id: string; project_id: string; agent_type: string; cwd?: string; captured_at: string; kind: 'transcript'; tool: 'claude-code'; turns: Array<{ role: 'user' | 'assistant'; text: string; }>; client_scrub_applied: boolean; client_scrub_hits: number; client_version: string; client_scrub_version: string; wire_version: 'v1.0'; /** FEAT-455 / ADR-012 decision 4, widened 2026-07-12 (doctor canary * provenance fix): `'auto_capture'` when this envelope was built by the * hook-tap auto-capture trigger, `'hook_close'` when built by the * ordinary astramem-plugin close-capture hook — every `session_end`/ * `subagent_stop` invocation that did NOT pass `--auto-capture`. Omitted * only when a caller invokes `buildClaudeEnvelope` directly without * either (existing unit tests exercising the function in isolation) — * the CLI itself (src/cli/capture.ts) always supplies one or the other. */ capture_source?: 'auto_capture' | 'hook_close'; } /** Parse one Claude Code `.jsonl` transcript (main session or a subagent * sidecar) into turns. Never throws on malformed content — partial/corrupt * lines (a transcript still being written) are skipped, not fatal. */ export declare function parseClaudeTranscript(jsonl: string, filePath: string): ParsedClaudeTranscript; /** Read + parse a transcript file from disk. Throws (missing/unreadable * file, or any other fs error) — the CLI caller is responsible for turning * that into the AC-3 soft-fail (one warning, non-zero exitCode, no crash). */ export declare function readAndParseClaudeTranscript(filePath: string): ParsedClaudeTranscript; export declare function buildClaudeEnvelope(parsed: ParsedClaudeTranscript, event: ClaudeCaptureEvent, clientVersion: string, /** 2026-07-13 timezone-offset bugfix: offset-bearing (local-time.ts's * `localIsoString`) rather than `new Date().toISOString()` — see that * module's doc for why. Callers that pass their own string explicitly * (tests, replay tooling) are unaffected. */ capturedAt?: string, /** FEAT-455 / ADR-012 decision 4, widened 2026-07-12: `'auto_capture'` * from the hook-tap auto-capture trigger, `'hook_close'` from the * ordinary close-capture hook path — see * ClaudeCaptureEnvelope.capture_source. Omitting this argument (direct * callers/unit tests only) keeps the byte-identical no-`capture_source`- * key envelope shape (conditionally spread below, never set to * `undefined`). */ captureSource?: 'auto_capture' | 'hook_close'): ClaudeCaptureEnvelope; /** * Stable idempotency key for the durable ingest spool (AC-2): a SHA-256 * stable-stringify hash of the envelope's CONTENT fields, deliberately * excluding `captured_at` (the one field that varies on every invocation * even when the underlying transcript is byte-identical). Re-running capture * on an unmodified transcript therefore produces the SAME key — the spool * write is a same-path overwrite (refreshed captured_at), never a duplicate. */ export declare function claudeIdempotencyKey(envelope: ClaudeCaptureEnvelope): string;