/** * Shared child-session transcript evidence extraction and fetch. * * Two consumers need "what did the child session end with?": * - `revived-run-tracker` (revive probes, strict v1 transcript shape) * - the quiescent host-outcome settle path in `task-session-manager` * (v2 shim shape — `info` carries only `{id, role}`; terminality is * confirmed upstream via `Session.Info.outcome`) * * Both previously carried their own (and subtly different) extraction * logic. This module is the single source of truth for reading a v1-style * `{data: [{info, parts}]}` messages response and classifying the * trailing assistant turn — and for fetching that transcript: * `fetchChildTranscript` binds the client's `session.messages` endpoint * (degraded hosts may not expose it) and surfaces `response.error` as a * normalized `Error`, replacing the bind/call/unwrap boilerplate that was * previously duplicated at every call site. `responseError` and * `stringifyError` are the shared response-error extraction and error-text * helpers for session-endpoint call sites (revive probes, notification * transport, task cancellation). */ import type { PluginInput } from '@opencode-ai/plugin'; interface ChildTranscriptOptions { /** Only consider messages after this baseline message id (revive flow). */ baselineMessageID?: string; /** Require `info.time.completed` on the trailing assistant (v1 hosts * always provide it once the turn finalizes). Defaults to true; v2 * shim shapes pass false because the flat mapping drops `time` — * terminality there is confirmed via the host outcome gate before * this extractor runs. */ requireCompletionTime?: boolean; /** When the ABSOLUTE trailing message is not an assistant, scan * backward for the last assistant and classify that message instead. * v2 sessions can carry structurally valid non-assistant tails * (synthetic/system/skill); the default (false) keeps the strict * trailing-message semantics the revive probe relies on. */ scanBackToLastAssistant?: boolean; } export type ChildTerminalEvidence = { kind: 'ready'; text: string; } | { kind: 'textless'; } | { kind: 'pending'; } | { kind: 'error'; errorText: string; } | { kind: 'no-assistant'; } | { kind: 'no-new-messages'; }; /** * Fetch a child session's transcript via `client.session.messages`. * * Returns the raw response, or `undefined` when the host client does not * expose a callable `session.messages` endpoint (degraded hosts) — each * call site decides how to degrade. Transport failures propagate to the * caller. A `response.error` payload is surfaced as a normalized `Error` * whose message is `stringifyError(response.error)`, matching the * error-surfacing style previously duplicated at the call sites. */ export declare function fetchChildTranscript(client: PluginInput['client'], sessionID: string, directory: string): Promise; /** Extract a non-null `response.error` payload from an SDK-style * response; `undefined` when the response carries no error. */ export declare function responseError(response: unknown): unknown; /** Normalize an unknown error payload to a displayable message string. */ export declare function stringifyError(error: unknown): string; interface LooseMessage { info?: { id?: unknown; role?: unknown; error?: unknown; finish?: unknown; time?: { completed?: unknown; }; }; parts?: unknown[]; } export type TranscriptMessage = LooseMessage; export declare function extractChildTerminalEvidence(response: unknown, options?: ChildTranscriptOptions): ChildTerminalEvidence; /** * Single source of truth for classifying ONE assistant turn as the * terminal evidence of a run: pending finish states, completion time, * segment-wide pending tool calls, terminal error precedence, and * usable text. Both the revived-run tracker probe and the stop gate's * evidence classifier delegate here so their terminality contracts * cannot diverge (a second independent classifier had already dropped * the pending-tool rule). */ export declare function classifyAssistantTurnEvidence(messages: TranscriptMessage[], targetIndex: number, baselineIndex: number, requireCompletionTime?: boolean): ChildTerminalEvidence; export {};