/** * Arrays of blocks, nested deltas and payload-discriminated records do not fit * the flat descriptor match/field spec used by identity decoding. */ import type { CompactionState, CompactionTrigger, HarnessName, LimitCode } from "../knowledge/descriptor.js"; import { type UsageEvent } from "./usage.js"; export interface ToolEvent { readonly kind: "tool"; readonly name: string; readonly input?: unknown; readonly callId?: string; /** Claude subagent lines: the Agent tool call whose subagent produced * this event (the native `parent_tool_use_id`). Present only on lines * that carry one; a main-loop event omits it. */ readonly parentCallId?: string; } export interface ToolResultEvent { readonly kind: "tool-result"; readonly name?: string; readonly callId?: string; readonly result?: unknown; readonly isError?: boolean; /** Claude subagent lines, as on `tool`. */ readonly parentCallId?: string; } /** Background jobs (claude `task_*` system records, 2026-11-09 evidence). * Closed unions a consumer branches on, like CompactionState: only a * shell and an agent exist, and only four states, because those are the * shapes the native records settle into. */ export type BackgroundJob = "shell" | "agent"; export type BackgroundState = "running" | "completed" | "failed" | "stopped"; /** A job whose terminal notification has not arrived. Later records * for the same id read its job when their own line carries no * task_type. */ interface KnownJob { readonly id: string; readonly job: BackgroundJob; } /** One observation of a job the harness itself reported, including * inline Agent calls. Every field is the * harness's own report; hcn derives none. Lossless and ordered: it is * not droppable, and when no published turn owns it, it is emitted as a * bare session sequence item that opens no turn. */ export interface BackgroundEvent { readonly kind: "background"; /** The harness's own job id (claude `task_id`). */ readonly id: string; readonly job: BackgroundJob; readonly state: BackgroundState; /** Claude's `is_backgrounded`: false = an inline (foreground) Agent, * true = a background job. Present only when the event's own native * record carried the boolean (claude puts it on `task_started` today); * later records for the job carry none, and hcn derives nothing. */ readonly backgrounded?: boolean; readonly description?: string; /** The tool call that started the job (claude `tool_use_id`). */ readonly callId?: string; /** The subagent type, on an agent job (claude `subagent_type`). */ readonly agent?: string; /** The harness's own progress text ("Running ..."). */ readonly detail?: string; readonly toolUses?: number; readonly totalTokens?: number; readonly durationMs?: number; /** Where the job's output is being written (claude `output_file`). */ readonly outputFile?: string; readonly summary?: string; } export interface ToolDenial { readonly tool: string; readonly reason: string; readonly callId?: string; /** JSON input preview, limited to 512 characters; it may be truncated. */ readonly inputSummary?: string; } export type ContentEvent = ToolEvent | ToolResultEvent | UsageEvent | BackgroundEvent | { readonly kind: "token"; readonly text: string; } | { readonly kind: "message"; readonly role: string; readonly text: string; readonly parentCallId?: string; } | { readonly kind: "progress"; readonly label: string; } /** ADR 0009: the harness compacted its own context. Passes through * `decode.ts` unchanged, so this shape matches the HarnessEvent arm. */ | { readonly kind: "compaction"; readonly state: CompactionState; readonly trigger?: CompactionTrigger; readonly tokensBefore?: number; readonly tokensAfter?: number; readonly durationMs?: number; readonly detail?: string; } /** `terminal: true` marks an error that ended the turn (a failed result * record); the runner turns it into a task failure. Other errors are * informational and the turn goes on. `provisional: true` qualifies a * terminal error: the harness may still supersede it with a successful * assistant message in the same run (pi retries a stopReason-error * attempt in-process), so the decoder holds the verdict and settles it * at stream/turn end (see `settleProvisionalError`). */ | { readonly kind: "error"; readonly message: string; readonly terminal?: boolean; readonly provisional?: boolean; /** A refused tool call or rejected question: * the native tool name and the harness's reason, which may be * empty. Machine consumers branch on presence, never on prose. */ readonly denial?: ToolDenial; } | { readonly kind: "budget"; readonly detail: string; } /** A structured limit record on the stream (claude's rate_limit_event); * the runner turns it into a limit-class failure. `resetsAt` is epoch * milliseconds when the harness reported one. */ | { readonly kind: "limit"; readonly code: LimitCode; readonly detail: string; readonly resetsAt?: number; }; /** Opaque per-reader decoder state (cursor only in v1): pending tool * call ids, tombstoned ids evicted from pending that must never re-emit * a tool event, completed ids that must not re-emit on a duplicate * completion, and query args by toolCallId for completions that arrive * with no preceding start. Owned by interpretation, threaded by execution * without inspection; reset per turn. Each collection is bounded * (drop-oldest) so a pathological turn cannot grow memory without bound; * the two text fields hold only the current segment's assistant text. * Completions land in their own set precisely so settling normal calls * never pushes an evicted id out of the tombstones. */ export interface CursorReaderState { readonly reader: "cursor"; readonly pending: readonly string[]; readonly tombstones: readonly string[]; readonly completed: readonly string[]; readonly queryArgs: readonly { readonly toolCallId: string; readonly args: unknown; }[]; /** Token text since the last message, tool call or notification. */ readonly pendingText: string; /** Text already ended as a message at a notification, which Cursor's * next full-text record repeats as its prefix. */ readonly emittedText: string; } export declare const freshCursorReaderState: () => CursorReaderState; /** Claude reader state (issue #456, review round 1 F10): the distinct * MAIN-LOOP models the turn's assistant records attested, so the * turn-scoped usage event can carry them - the result record that * carries the turn's usage names no model of its own. Each distinct * model is kept in first-seen order; the result that ends the turn * clears the list. A turn that attested several (a mid-turn settings * change) keeps the truthful list and singles out no `model` * (review rounds 3 H1, 4 J1/J2). */ export interface ClaudeReaderState { readonly reader: "claude"; readonly turnModels: readonly string[]; /** Background jobs by their native id: the job a later task_progress / * task_updated / task_notification names when its own line carries no * task_type. Each entry lives until its terminal task_notification * (kept through the preceding terminal task_updated). It spans the * session, so a job's end after a turn boundary still finds its job. */ readonly backgroundJobs: readonly KnownJob[]; } export declare const freshClaudeReaderState: () => ClaudeReaderState; /** Narrowing guards for the two stateful readers; execution holds the * state without inspection (ADR 0005). */ export declare const isClaudeReaderState: (state: ReaderState) => state is ClaudeReaderState; export declare const isCursorReaderState: (state: ReaderState) => state is CursorReaderState; /** Per-harness reader state: cursor state for cursor, the turn-model * tracker for claude, null otherwise. Execution holds it without * inspection (ADR 0005). */ export type ReaderState = CursorReaderState | ClaudeReaderState | null; export declare const freshReaderState: (harness: HarnessName) => ReaderState; /** Stateful entry point: every harness returns { events, state }. * decode.ts is the one production call site; contentEventsOf below keeps * the array shape for stateless callers. */ export declare const contentEventsWithState: (harness: HarnessName, raw: unknown, state: ReaderState) => { readonly events: ContentEvent[]; readonly state: ReaderState; }; export declare const contentEventsOf: (harness: HarnessName, raw: unknown) => ContentEvent[]; export {}; //# sourceMappingURL=content.d.ts.map