/** * Tracks in-flight background tasks (run_in_background Bash/Agent) for a single * persistent Claude session, by observing the CLI's stream-json `system` events. * * Observed lifecycle (real shapes, see /tmp/bg-capture.mjs): * - launch: { type:'system', subtype:'task_started', task_id, task_type } * - completion: { type:'system', subtype:'task_updated', task_id, patch:{status:'completed'} } * { type:'system', subtype:'task_notification', task_id, status:'completed', summary } * * IMPORTANT: task_updated{completed} and task_notification are TWO separate events, and the * CLI emits task_updated FIRST — sometimes seconds before the matching task_notification * (gaps up to ~24s observed when several run_in_background tasks finish close together). * task_notification is the one that actually re-invokes the model (the continuation turn). * So pending is keyed off task_notification ONLY; clearing on task_updated would let the * count hit 0 while continuation turns are still undelivered, sealing a turn "done" * prematurely (a continuation result resolving in that gap snapshots pendingCount==0). * * When a background task completes the CLI spontaneously re-invokes the model and * emits a fresh turn whose terminating `result` carries `origin.kind:'task-notification'` * (see isContinuationResult). The adapter uses pendingCount to decide whether a turn's * result should be sealed ("done") or held in a "waiting" state, and continuationArmed * to recognize the spontaneous continuation turn that follows. */ export declare class BgTaskTracker { private readonly pending; /** Set when a background task completes; the spontaneous continuation turn that * follows is recognized via this flag. Cleared by disarmContinuation(). */ continuationArmed: boolean; /** Observe one parsed stream-json event. Idempotent per task_id. */ observe(data: any): void; get pendingCount(): number; hasPending(): boolean; disarmContinuation(): void; } /** A `result` event produced by a background-task continuation turn carries * origin.kind === 'task-notification'. Used to distinguish a spontaneous * continuation result from a normal turn result. */ export declare function isContinuationResult(data: any): boolean; /** How a parsed stream-json line should be routed by the session's handleLine. */ export type LineRoute = 'normal' | 'open-continuation' | 'ignore'; /** * Decide how a parsed line should be routed given whether a turn is currently active. * Pure: depends only on the tracker's armed state and the event type. */ export declare function routeLine(tracker: BgTaskTracker, data: any, hasActiveTurn: boolean): LineRoute;