import { type SessionPermissionOptions } from "../interpretation/argv.js"; import { type SessionControlsCapability } from "../interpretation/capabilities.js"; import { type QuestionMode } from "../interpretation/question.js"; import type { SkillsSelection } from "../interpretation/skills-selection.js"; import type { HarnessDescriptor, SessionDelivery } from "../knowledge/descriptor.js"; import type { RunnerDeps } from "./deps.js"; import { type HarnessEvent } from "./events.js"; import { type SessionApprovalAnswer, type SessionApprovalDecisionRequest } from "./session-approval-tracker.js"; import { type SessionSettingsReceipt, type SessionSettingsRequest } from "./session-settings-sequencer.js"; /** Grace after stdin EOF before concluding the child will not exit on its * own and escalating signals. */ export declare const CLOSE_GRACE_MS = 5000; export interface SessionSendResult { readonly disposition: "started" | "rejected"; /** Present when rejected. `write-failed` is a broken stdin pipe, which is * a different remedy from a session the caller already closed - the two * must stay distinguishable. `unsupported-delivery` is an explicit * delivery mode this harness does not support: nothing was written and * the session stays usable. */ readonly reason?: "closed" | "native-rejected" | "write-failed" | "unsupported-delivery"; /** Resolves when a harness with command receipts accepts or rejects the input. */ readonly settled?: Promise; } /** One turn's event stream, tagged with the id of the send that opened it. * `inputId` is present for every turn a consumer send opened. A native turn * no send opened (claude output whose records name no waiting send, such as * background task output) omits it. */ export interface SessionTurn extends AsyncIterable { readonly inputId?: string; /** `${sessionId}:turn-${n}`, matching the runner's turn_start log. */ readonly turnId?: string; } export declare const isSessionTurn: (item: SessionTurn | HarnessEvent) => item is SessionTurn; /** A send's payload: the consumer's correlation id travels with the text * from the moment it arrives to the turn it opens and, on death, to the * loss report. Ids are the caller's and may repeat; the runner correlates * each send by its own token. `delivery` requests an explicit native * delivery mode; omitted, the harness's native busy-send behavior applies. * `verbatim` (issue #456) writes the text exactly as given, with no * question preamble in any questions mode - how a host types a slash * command. */ export interface SessionInput { readonly id: string; readonly text: string; readonly delivery?: SessionDelivery; readonly verbatim?: boolean; } /** The terminal outcome of an interrupt request (issue #426). `interrupted` * is the harness's own report that the active run was cancelled; command * acceptance alone is never read as one. `not-active` means the harness * reported no run cancelled (it had already settled, or was idle). */ export interface SessionInterruptReceipt { readonly state: "interrupted" | "not-active" | "rejected"; readonly reason?: "unsupported" | "closed" | "write-failed" | "native-rejected"; } /** Issue #454/#455: one host decision on a forwarded native permission * request - the shape the session handle, the tracker and the CLI's * stdin op share (one type, not three). `sent` means the native reply * was written; a rejected decision names why and nothing was written. * A decision is consumed before its write and never retried. The * answer outcome type lives with the tracker. */ /** `requested`: the native cancellation request was written, and `settled` * resolves exactly once with the terminal receipt. `rejected`: nothing was * written. */ export type SessionInterruptResult = { readonly state: "requested"; readonly settled: Promise; } | { readonly state: "rejected"; readonly reason: "unsupported" | "closed" | "write-failed"; }; /** The receipt a stop-background request settles with. `sent` says the * harness accepted the stop REQUEST - never that the job ended: the job's * own end arrives on the stream as a `background` event. */ export interface SessionStopBackgroundReceipt { readonly state: "sent" | "rejected"; readonly reason?: "unsupported" | "closed" | "write-failed" | "native-rejected"; } export type SessionStopBackgroundResult = { readonly state: "requested"; readonly settled: Promise; } | { readonly state: "rejected"; readonly reason: "unsupported" | "closed" | "write-failed"; }; export interface SessionHandle { /** Ordered turns and events no published turn owns. Drain each turn * through its turn-scoped `done` before reading the next item. Bare * events open no turn. Breaking out of THIS iterable closes the session; * breaking out of a single turn only stops reading that turn. */ readonly turns: AsyncIterable; /** The explicit controls this session supports now. Issue #429: claude * interrupt support is what the running process advertised on its latest * system/init, so it reads unsupported until then and can change; every * change is re-announced on the identity event's * capabilities.sessionControls. */ readonly controls: SessionControlsCapability; send(input: SessionInput): SessionSendResult; /** Request cancellation of the active turn while the process continues. * Carries no replacement text: the caller sends that after the receipt. */ interrupt(request: { readonly id: string; }): SessionInterruptResult; /** Stop one background job by the id its `background` events carry, * while the process continues. The receipt never claims the job ended: * the job's own end arrives as a `background` event. */ stopBackground(request: { readonly id: string; readonly job: string; }): SessionStopBackgroundResult; /** Issue #454/#455: answer one forwarded permission request. Exactly one * answer right per request: answered once, cleared never again. */ answerApproval(decision: SessionApprovalDecisionRequest): SessionApprovalAnswer; /** Issue #456: change the model and/or effort of this session. Takes * effect from the next model request; a busy turn is not interrupted. * Resolves with exactly one receipt. */ settings(request: SessionSettingsRequest): Promise; close(): Promise; } export interface OpenSessionOptions extends SessionPermissionOptions { readonly sessionId: string; readonly model?: string; /** Working directory for the spawned harness. */ readonly cwd?: string; /** question mode for session (ask/assume/none), default "ask" */ readonly questions?: QuestionMode; /** Provider selector (pi); refused on a harness without one. */ readonly provider?: string; /** Named-agent selection (map #288); refused on a harness without a * spec, the same way a one-shot turn refuses. */ readonly agent?: string; readonly contextWindow?: number; /** Effort level for the session spawn, validated per harness/model the * way a one-shot launch validates it. Undefined means the caller made * no effort decision: the session runs at the harness's own default * effort (sessions carry no profile entry). */ readonly effort?: string; /** True when resuming an existing conversation; controls which flag * (resumeFlag vs idFlag) buildSessionArgv renders. */ readonly isResume?: boolean; /** Persistent-memory dimension (ratified 2026-08-26): the session spawn * honors it the way a one-shot launch does - false renders the * descriptor's disable (claude: CLAUDE_CODE_DISABLE_AUTO_MEMORY env var; * pi: nothing, no built-in memory). Undefined means the caller made no * memory decision; openSession adds no env overlay then. Resumed * sessions get it too - it is a spawn property, not a turn option, so * the launch-only rule never silently re-enables memory on a session. */ readonly memory?: boolean; /** The host's own version, reported to harnesses that ask at session * open (codex app-server's initialize handshake carries clientInfo). */ readonly clientVersion?: string; /** Caller-directed skills allowlist (issue #332), resolved by the CLI * against the registry root. Passed to buildSessionArgv, which renders * it through the same owner a one-shot launch uses; a harness that * cannot enforce an allowlist refuses here, before any spawn. */ readonly skills?: SkillsSelection; /** Issue #454/#455: arm the harness's native permission channel * (`--permission-prompt-tool stdio` on claude) so each permission-gated * tool call is forwarded to the session host as an approval-request * event. Without it nothing changes: no channel is armed and the child * answers its own permission gates the way a bare session does. */ readonly nativeApprovals?: boolean; /** Issue #457: which settings scopes the session child loads (claude's * --setting-sources). The descriptor's default renders when omitted. */ readonly settingSources?: readonly string[]; } export type { SessionApprovalAnswer, SessionApprovalDecisionRequest, } from "./session-approval-tracker.js"; export type { SessionSettingsReceipt, SessionSettingsRequest, } from "./session-settings-sequencer.js"; export declare class SessionClosedError extends Error { constructor(); } export declare class SessionSpawnError extends Error { constructor(harness: string, cause: unknown); } export declare const openSession: (h: HarnessDescriptor, opts: OpenSessionOptions, deps: RunnerDeps) => SessionHandle; //# sourceMappingURL=open-session.d.ts.map