/** * Issue #456: the settings-op sequencer of one persistent session, * extracted from openSession (review round 1, F12). One op is on the wire * at a time (pi answers rpc commands asynchronously; two model writes * racing could apply out of order while both reported applied), and the * writes of one op are sequenced behind each other: on pi, a model op * reads the session's own catalog (`get_available_models`) first and * resolves the selector exactly the way the spawn flags do * (resolvePiSessionModel), and every pi op ends with a `get_state` * readback so the receipt reports the EFFECTIVE model and thinking level * - pi clamps both silently. Claude ops write `set_model` then * `apply_flag_settings` and report the model the harness confirmed plus * the requested effort (claude has no effort readback; the docs say so). * * Every op is owed exactly one receipt whatever happens next: native * rejection (with the part that applied), invalid values (no write), * closed, or write-failed - including ops still queued when the session * dies or the stdin pipe breaks asynchronously. */ import type { SessionRecord } from "../interpretation/session-input.js"; import type { HarnessDescriptor, SessionInputContract } from "../knowledge/descriptor.js"; /** Issue #456: one settings op's receipt, exactly one per well-formed * op. `applied` follows every native response succeeding; a * `native-rejected` partial application reports the part that applied in * `model`/`effort`. A Pi state readback that failed or came back * partial after the writes succeeded (review rounds 3 H2, 4 J4) reports * `applied` with only the values * the readback confirmed and lists the parts it wrote but could not * read back in `unconfirmed` - pi clamps silently, so the write's * acknowledgment is not the effective value. */ export interface SessionSettingsReceipt { readonly state: "applied" | "rejected"; readonly reason?: "invalid-model" | "invalid-effort" | "unsupported" | "native-rejected" | "closed" | "write-failed"; readonly model?: string; readonly effort?: string; readonly unconfirmed?: readonly ("model" | "effort")[]; } /** One settings op as the host submitted it - the shape the session * handle, this sequencer and the CLI's stdin settings op share. */ export interface SessionSettingsRequest { readonly id: string; readonly model?: string; readonly effort?: string; } export interface SettingsSequencerIO { readonly sessionId: string; readonly log: (entry: Record) => void; readonly isClosed: () => boolean; /** May throw: broken stdin pipe. */ readonly write: (line: string) => void; /** The session's broken-pipe shutdown. */ readonly onWriteFailed: () => void; /** The session's --provider (pi), constraining model resolution. */ readonly sessionProvider?: string; /** The session's current model - the last one a settings op applied, * else the spawn model - so a later op's effort ladder follows the * model the session actually runs, not the spawn one. */ readonly currentModel: () => string | undefined; /** Notified with the model each applied op leaves the session on. */ readonly onModelResolved: (model: string) => void; /** Fresh correlation token per op (the runner's command sequence). */ readonly nextToken: () => string; } export interface SettingsSequencer { submit(request: SessionSettingsRequest): Promise; /** Feed one decoded settings-answered record. Only the in-flight op's * OWN outstanding write settles it; any other response is ignored. */ onAnswered(record: Extract): void; /** The stdin pipe broke asynchronously: every in-flight and queued op * settles write-failed with the part that applied. */ writeFailedAll(): void; /** The session is gone: every op settles closed with the part that * applied. */ closeAll(): void; } export declare const createSettingsSequencer: (h: HarnessDescriptor, input: SessionInputContract, io: SettingsSequencerIO) => SettingsSequencer; //# sourceMappingURL=session-settings-sequencer.d.ts.map