/** * Claude Code transcript → turn state. * * Reads the end of a Claude Code conversation transcript (JSONL) and says * whether the agent is mid-turn, done with its turn, or done but with * background work (a subagent or a `run_in_background` shell) that will start * another turn when it finishes. Fallback for the hook-fed turn state * (specs/2026-10-02-restart-busy-and-resume.md). * * Completion notices (`…X`) * reach the transcript in three shapes, and all three count: a `user` * message, a `queue-operation` entry's `content`, and a `queued_command` * `attachment`'s `prompt`. Reading only the first left about half of all * transcripts ending in a false "background" (PR #1013 review). * * Launches older than the current runtime (`launchedAfter`) are ignored: a * restart kills background work, and the resumed conversation still lists it. * * Only the main chain counts (`isSidechain` entries belong to subagents). * Nothing read here is logged or stored beyond the verdict. * * @module services/monitoring/claude-transcript-turn */ /** What the transcript says. */ export type TranscriptTurnVerdict = 'turn' | 'background' | 'idle' | 'unknown'; /** Result of reading a transcript. */ export interface TranscriptTurnState { /** Verdict at the end of the file */ verdict: TranscriptTurnVerdict; /** Epoch ms of the newest relevant entry (NaN when none) */ lastEntryAt: number; /** Epoch ms of the newest turn end (end_turn, turn_duration, interrupt, API / usage-limit error); NaN when none */ turnEndedAt: number; /** Background launches with no completion notice yet */ pendingBackground: number; /** Epoch ms of the oldest pending background launch (NaN when none) */ oldestPendingAt: number; /** File modification time (epoch ms) */ mtimeMs: number; } /** Options for parsing. */ export interface TranscriptParseOptions { /** Ignore background launches (and turn-end pending counts) older than this (epoch ms) */ launchedAfter?: number; } /** * Turn state from transcript text (pure; exported for tests). * * @param text - JSONL text (a partial first line is ignored) * @param mtimeMs - File modification time * @param options - Runtime start filter * @returns The state */ export declare function parseClaudeTranscriptTurn(text: string, mtimeMs?: number, options?: TranscriptParseOptions): TranscriptTurnState; /** * Turn state of a transcript file, cached by (size, mtime, launchedAfter). * * @param filePath - Transcript path * @param options - Runtime start filter * @returns The state, or null when the file cannot be read * * @example * ```typescript * const s = claudeTranscriptTurnState('/Users/me/.claude/projects/-x/abc.jsonl', { launchedAfter: startedAt }); * if (s?.verdict === 'turn') // mid-turn * ``` */ export declare function claudeTranscriptTurnState(filePath: string, options?: TranscriptParseOptions): TranscriptTurnState | null; /** * Forget cached transcript reads (tests only). */ export declare function resetTranscriptTurnCache(): void; //# sourceMappingURL=claude-transcript-turn.d.ts.map