/** * Pure validation and encoding for descriptor-declared persistent-session * input, and the decoding of the session records the runner cannot read * without harness knowledge. This module owns the wire records and their * field names (ADR 0005, RFC-02 change 4); the execution layer branches * on the closed kinds it returns and holds no field name of its own. */ import type { HarnessDescriptor, SessionDelivery, SessionInputContract, SessionInputKind } from "../knowledge/descriptor.js"; import { type SessionApprovalProposal } from "./session-approvals.js"; import { type PiModelEntry, type PiStateAnswer } from "./session-settings.js"; export type SessionInputIssue = "missing-session-input-contract" | "unsupported-session-input-kind" | "unsupported-delivery" | "unsupported-interrupt" | "unsupported-stop-background"; export declare class SessionInputRefusalError extends Error { readonly issue: SessionInputIssue; constructor(issue: SessionInputIssue); } /** The marker ids hcn stamps on the rpc commands it writes, so their * responses cannot be confused with anything user-visible. */ export declare const IDENTITY_PROBE_ID = "hcn-identity"; export declare const SEND_ID = "hcn-send"; /** The JSON-RPC request id of the initialize handshake line, written * before the identity probe on a codex session. Its response carries * nothing hcn needs; the marker keeps it recognizable. */ export declare const INITIALIZE_ID = "hcn-initialize"; export interface SessionInputEncodingOptions { readonly busy: boolean; readonly id: string; readonly delivery?: SessionDelivery; /** Claude: the native message uuid stamped on an explicitly delivered * user frame, so turn records naming it correlate back to this input. */ readonly uuid?: string; /** Popeye prompt frames and codex requests carry the minted session id * (popeye session, codex thread). */ readonly sessionId?: string; /** Codex steer precondition: the tracked id of the currently running * native turn. A mismatch fails the request server-side, which is the * rejected disposition. */ readonly activeTurnId?: string; } export declare const resolveSessionInput: (harness: HarnessDescriptor) => SessionInputContract; export declare const encodeSessionInput: (input: SessionInputContract, text: string, options?: SessionInputEncodingOptions) => string; /** Issue #426: the native command that requests cancellation of the active * turn, correlated by the runner's internal token. Pi rpc writes `abort`; * claude (issue #429) writes an `interrupt` control request without * `cancel_queued`, so queued inputs stay with the harness. Every other kind * refuses. */ export declare const encodeSessionInterrupt: (input: SessionInputContract, token: string) => string; /** The native command that stops one background job, correlated by the * runner's internal token and naming the job by the id its `background` * events carry (claude's `task_id`). Claude writes the `stop_task` control * request (verified 2.1.319); every other kind refuses. The answer says * only whether the request was accepted - the job's own end arrives on * the stream as a `background` event, never claimed by the receipt. */ export declare const encodeSessionStopBackground: (input: SessionInputContract, token: string, job: string) => string; /** Issue #429: kinds whose interrupt support is a fact about the running * process, not the descriptor alone. Claude advertises it per process * (`interrupt_receipt_v1` in system/init `capabilities`), so the runner * reports interrupt unsupported until a record says otherwise. */ export declare const requiresInterruptAdvertisement: (kind: SessionInputKind) => boolean; /** Issue #429: what a record says about the process's interrupt support: * null when it says nothing (anything but a claude system/init record), * else whether its capability list names `interrupt_receipt_v1`. A missing * or malformed list grants nothing. */ export declare const readInterruptAdvertisement: (h: HarnessDescriptor, parsed: Record) => boolean | null; /** Issue #426: the native message uuids a claude record names as the * inputs it answers (`user_message_uuids`, else `user_message_uuid`). * Turn-level records carry them (system init/status, the first * message_start and assistant frames, result); inner frames and background * task output omit them, which reads as an empty list. */ export declare const readInputUuids: (h: HarnessDescriptor, parsed: Record) => readonly string[]; /** What one spawn must write to learn the session id, or null when the * harness announces identity on its stream unprompted. pi rpc is * identity-silent at startup (spike fixtures); the response echoes the * marker id. Popeye rpc is likewise silent: the probe is a create frame, * and the snapshot response mints the session. Codex app-server is * silent AND needs a handshake: the probe is two JSON-RPC lines, * `initialize` (required before any other request - verified 0.159.2: * everything else fails with -32600 "Not initialized") then the thread * open named by the descriptor's identityProbe.command - thread/start for * a fresh session, thread/resume with the requested id when isResume. */ export declare const encodeIdentityProbe: (h: HarnessDescriptor, opts?: { readonly sessionId?: string; readonly isResume?: boolean; readonly model?: string; readonly clientVersion?: string; }) => string | null; /** Kinds whose send requests are answered by a native receipt the runner * can correlate (pi rpc responses; codex JSON-RPC responses). The runner * settles the send's disposition on that receipt. */ export declare const hasNativeReceipts: (kind: SessionInputKind) => boolean; /** Issue #426: kinds whose turn records name the native message uuids of * the inputs they answer (claude `user_message_uuids`). The runner stamps * a uuid on every frame and opens a queued input's turn on a record naming * it; a turn record naming none is output no input opened. */ export declare const correlatesByInputUuid: (kind: SessionInputKind) => boolean; /** Issue #426: kinds where a written prompt can produce no run at all (pi * `handled`: an extension consumed it). The runner publishes such a turn * only on run evidence: a started receipt, run output, or a settlement. */ export declare const publishesTurnOnRunEvidence: (kind: SessionInputKind) => boolean; /** What one parsed stdout record means to a session, as a closed kind. */ export type SessionRecord = /** The identity probe answered with the session id. */ { readonly kind: "identity"; readonly sessionId: string; } /** The identity probe answered without an id - surfaced, never silent. */ | { readonly kind: "probe-failed"; readonly message: string; } /** A correlated rpc command was accepted by the harness. `inputId` is the * correlation id the runner wrote after the send marker (its per-command * token), not necessarily a caller id. `nativeTurnId` * is present when the response names the turn it started or steered * into (codex turn/start {turn.id}, turn/steer {turnId}); the runner * tracks it as the steer precondition for the next mid-turn send. */ | { readonly inputId: string; readonly kind: "command-accepted"; readonly nativeTurnId?: string; /** pi prompt receipts name what the harness did with the input: * `started` a new run, `queued` joined the active run, `handled` * consumed it with no run (an extension command). Absent on receipts * that carry no disposition. */ readonly nativeDisposition?: NativeInputDisposition; } /** Issue #426: the native interrupt command was answered. Acceptance is * not confirmation; the settlement record says whether a run aborted. */ | { readonly kind: "interrupt-answered"; readonly token: string; readonly accepted: boolean; } /** The native stop-background request was answered. `ok` says only that * the harness accepted the stop request; the job's own end arrives as a * `background` event. */ | { readonly kind: "stop-background-answered"; readonly token: string; readonly ok: boolean; } /** An rpc command hcn wrote was refused by the harness. */ | { readonly inputId?: string; readonly kind: "command-failed"; readonly message: string; } /** Protocol bookkeeping with nothing to surface. */ | { readonly kind: "ignored"; } /** Issue #454/#455: claude asked the host about a tool use * (`can_use_tool` under --permission-prompt-tool stdio). The proposal * is fully normalized; the runner forwards it as an approval-request * event when the session was opened with --native-approvals. */ | { readonly kind: "approval-request"; readonly requestId: string; readonly proposal: SessionApprovalProposal; } /** Issue #454: claude cancelled a permission request itself (an * interrupt while it waited); the request loses its answer right. */ | { readonly kind: "approval-cancelled"; readonly requestId: string; } /** Issue #456: the harness answered a settings command hcn wrote * (`set_model` / `apply_flag_settings` on claude; `set_model` / * `set_thinking_level` / `get_available_models` / `get_state` on pi). * `model` is the native confirmation where the harness returns one, * `models` is pi's catalog answer, `state` pi's effective-state * readback; else absent. */ | { readonly kind: "settings-answered"; readonly token: string; readonly part: "model" | "effort" | "catalog" | "state"; readonly ok: boolean; readonly model?: string; readonly models?: readonly PiModelEntry[]; readonly state?: PiStateAnswer; } /** The record that delimits a turn, with the harness's own error flag. * `aborted` is present when the harness reports the run was cancelled * (pi agent_settled.aborted true, claude result terminal_reason * aborted_streaming or aborted_tools). */ | { readonly kind: "turn-end"; readonly isError: boolean; readonly aborted?: true; } /** Anything else: content for the stream decoder. */ | { readonly kind: "content"; }; export type NativeInputDisposition = "started" | "queued" | "handled"; export declare const decodeSessionRecord: (h: HarnessDescriptor, parsed: Record) => SessionRecord; //# sourceMappingURL=session-input.d.ts.map