/** * Issue #454/#455: the native-approval ledger of one persistent Claude * session, extracted from openSession (review round 1, F12): which * `can_use_tool` requests are waiting, which were answered, and the * clearing paths (native-resolved, turn-ended, process-ended, * channel-failed). A request keeps its full proposal ONLY while it waits; * an answered id becomes a tombstone (bounded, oldest evicted) so * re-answers keep rejecting `already-answered`, and a cleared request is * deleted outright - its answer right is gone, exactly like a request * never seen. The pending set is capped the way the Codex run lane caps * its own (NATIVE_APPROVAL_LIMITS): a request beyond the cap is denied * natively and surfaced as an error event, never silently dropped. * * Pure decoding and decision application live in * src/interpretation/session-approvals.ts; this module owns state and the * write, the way the runner's other lanes split interpretation from * execution. */ import { type SessionApprovalDecision, type SessionApprovalProposal } from "../interpretation/session-approvals.js"; import type { HarnessEvent } from "./events.js"; /** One decision as the host submitted it - the shape the session handle, * this tracker and the CLI's stdin approval op share. */ export type SessionApprovalDecisionRequest = SessionApprovalDecision & { readonly id: string; readonly requestId: string; }; /** Issue #454/#455: one host decision on a forwarded native permission * request. `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. */ export type SessionApprovalAnswer = { readonly status: "sent"; } | { readonly status: "rejected"; readonly reason: "unknown-request" | "already-answered" | "unknown-choice" | "invalid-answers" | "invalid-message" | "closed" | "write-failed"; }; /** What the tracker needs from the session around it. `write` may throw * (broken stdin); `onWriteFailed` then runs the session's broken-pipe * shutdown. `routeEvent`'s promise enforces the turn channel's high-water * mark: every path the stdout pump reaches must return and await it, or a * flood of requests outpaces the consumer (teardown paths may fire and * forget - the process is ending and nothing can slow it). */ export interface SessionApprovalTrackerIO { /** The caller-side handle, for log lines. */ readonly sessionId: string; /** The id the harness announced, for consumer-facing events (the * harness-minted id on pi-style sessions; claude confirms the * caller's). */ readonly announcedSessionId: () => string; readonly log: (entry: Record) => void; readonly routeEvent: (event: HarnessEvent) => Promise | void; readonly pauseInactivity: () => void; readonly resumeInactivity: () => void; readonly isClosed: () => boolean; readonly write: (line: string) => void; readonly onWriteFailed: () => void; /** The published turn id, for the log lines. */ readonly turnId: () => string; } export interface SessionApprovalTracker { /** Track a freshly decoded native request. A duplicate native id is * ignored; a request beyond the pending cap is denied natively with a * message and reported as an error event, and nothing is tracked. * Returns the delivery promise of the event it routes, for the stdout * pump to await (backpressure). */ offer(requestId: string, proposal: SessionApprovalProposal, turn: object | null): Promise | void; /** Whether the id is already known - waiting, or answered (a * tombstone). The caller uses this to give a duplicate none of the * side effects of a first sighting (it must not open a turn). */ isKnown(requestId: string): boolean; /** The child cancelled its own request: cleared `native-resolved`. * Returns the cleared event's delivery promise, for the stdout pump. */ cancel(requestId: string): Promise | void; /** Clear everything still waiting on one turn: `turn-ended`. */ clearTurn(turn: object): void; /** Clear everything still waiting: `process-ended`. */ clearAll(): void; /** Clear everything still waiting: `channel-failed` (the stdin pipe * broke; nothing can be written any more). */ clearChannel(): void; /** Answer one request (see SessionApprovalAnswer). */ answer(decision: SessionApprovalDecisionRequest): SessionApprovalAnswer; /** Whether any request is still waiting on this turn (the close drain * gives up on such a turn: no decision can arrive once stdin ends). */ isWaitingOn(turn: object): boolean; } export declare const createSessionApprovalTracker: (io: SessionApprovalTrackerIO) => SessionApprovalTracker; //# sourceMappingURL=session-approval-tracker.d.ts.map