/** * Session state machine. Models the lifecycle of a single harness session. * * Pattern adapted from t3code's `OrchestrationSession`. We use a tiny * discriminated-union reducer rather than XState — fewer than 100 lines, * zero deps, fully type-checked transitions. */ import type { SessionState } from "../contracts/provider-runtime.js"; export type SessionEvent = { type: "start"; } | { type: "ready"; } | { type: "turn.begin"; } | { type: "turn.end"; } | { type: "interrupt"; } | { type: "resume"; } | { type: "shutdown"; } | { type: "fail"; reason: string; }; export interface SessionTransition { readonly from: SessionState; readonly to: SessionState; readonly event: SessionEvent; readonly at: string; } export declare function nextSessionState(current: SessionState, event: SessionEvent): SessionState; export declare function canTransition(current: SessionState, event: SessionEvent): boolean; export declare function isTerminal(state: SessionState): boolean; export declare class SessionMachine { private state; private readonly history; constructor(initial?: SessionState); current(): SessionState; send(event: SessionEvent): SessionTransition; log(): readonly SessionTransition[]; }