import { postmortem } from "@gajae-code/utils"; /** Managed tmux owner provenance propagated only to the launched child process. */ export declare const GJC_TMUX_OWNER_GENERATION_ENV = "GJC_TMUX_OWNER_GENERATION"; export declare const GJC_TMUX_OWNER_STATE_DIR_ENV = "GJC_TMUX_OWNER_STATE_DIR"; export declare const GJC_TMUX_OWNER_SERVER_KEY_ENV = "GJC_TMUX_OWNER_SERVER_KEY"; export declare const GJC_COORDINATOR_SESSION_STATE_FILE_ENV = "GJC_COORDINATOR_SESSION_STATE_FILE"; export declare const GJC_COORDINATOR_SESSION_ID_ENV = "GJC_COORDINATOR_SESSION_ID"; export declare const GJC_COORDINATOR_SESSION_BRANCH_ENV = "GJC_COORDINATOR_SESSION_BRANCH"; export declare const GJC_COORDINATOR_SESSION_LAUNCH_ID_ENV = "GJC_COORDINATOR_SESSION_LAUNCH_ID"; export declare const GJC_COORDINATOR_SESSION_READINESS_FILE_ENV = "GJC_COORDINATOR_SESSION_READINESS_FILE"; export declare const GJC_COORDINATOR_SIDECAR_SIGNING_KEY_ENV = "GJC_COORDINATOR_SIDECAR_SIGNING_KEY"; export declare const GJC_COORDINATOR_SIDECAR_BOOTSTRAP_URL_ENV = "GJC_COORDINATOR_SIDECAR_BOOTSTRAP_URL"; export declare const GJC_COORDINATOR_SIDECAR_KEY_ID_ENV = "GJC_COORDINATOR_SIDECAR_KEY_ID"; /** Explicitly binds this launch to Coordinator-minted sidecar signing authority. */ export declare const GJC_COORDINATOR_SIDECAR_SIGNATURE_REQUIRED_ENV = "GJC_COORDINATOR_SIDECAR_SIGNATURE_REQUIRED"; export declare function coordinatorSidecarSigningBootstrapEnv(): Record; export declare function canonicalCoordinatorSidecarPayload(value: Record): string; export type RuntimeInputReadyMarker = Readonly<{ schema_version: 1; session_id: string; launch_id: string; state: "ready_for_input"; event: "interactive_input_ready"; source: "gjc_interactive_runtime"; ready_for_input: true; created_at: string; }>; export type RuntimeState = "ready_for_input" | "running" | "needs_user_input" | "completed" | "errored"; /** Recorded whenever the caller could not prove a canonical public label for a tool. */ export declare const UNPROVEN_TOOL_LABEL = "custom"; /** Test-only counters for runtime sidecar hot-path assertions. */ export declare const __sessionStateSidecarPerfCounters: { persistFromEventCalls: number; reset(): void; }; interface RuntimeStateEvent { type: string; messages?: unknown[]; toolCallId?: unknown; isError?: unknown; } export type RuntimeToolActivityPhase = "started" | "finished"; /** * A finished call's outcome. `cancelled` is the only honest answer for a call that was * still in flight when the session settled: it neither succeeded nor failed, and nothing * observed its end. */ export type RuntimeToolActivityOutcome = "success" | "failure" | "cancelled"; /** * What a session is doing right now, split into a bounded public projection and the * minimum private state needed to keep that projection exact. * * Deliberately carries no tool arguments, results, command text, paths, output, prompt or * model text, environment values, or credentials — only a proven public tool label, a * phase, and timing. */ export interface RuntimeToolActivity { seq: number; last_activity_at: string; tool: string; phase: RuntimeToolActivityPhase; outcome: RuntimeToolActivityOutcome | null; elapsed_ms: number | null; /** Exact number of in-flight calls; derived with `active_tools`, so it can never be smaller. */ active_tool_count: number; /** Public projection of the newest in-flight calls, capped at `MAX_ACTIVE_TOOL_ENTRIES`. */ active_tools: Array<{ tool: string; started_at: string; }>; /** * Private exact correlation state. Each digest is one-way over the session id and the * tool call id, so no raw call id is persisted, and the whole field is stripped by * `publicRuntimeToolActivity` before any coordinator reader sees the snapshot. */ in_flight: Array<{ digest: string; tool: string; started_at: string; }>; } /** * Collapses anything the caller could not prove into `custom`. * * Public safety comes from the caller's proof plus this closed vocabulary, never from a * syntax check: a label that merely looks like a token is still model-influenced text. */ export declare function safeRuntimeToolLabel(value: unknown): string; export declare function toolActivityPhaseForEvent(event: RuntimeStateEvent): RuntimeToolActivityPhase | null; export type RuntimeToolActivityReadout = { kind: "absent"; } | { kind: "malformed"; } | { kind: "valid"; activity: RuntimeToolActivity; }; /** * Re-validates an activity snapshot read back from disk. * * `absent` and `malformed` are deliberately distinct outcomes: an absent snapshot may be * seeded from sequence 1, while a malformed one must never be replaced by a lower * sequence. The public counters are re-derived from the private in-flight table rather * than trusted from disk, so a hand-edited file cannot publish a contradiction. */ export declare function classifyRuntimeToolActivity(value: unknown): RuntimeToolActivityReadout; export declare function normalizedRuntimeToolActivity(value: unknown): RuntimeToolActivity | null; /** * The only activity shape a coordinator reader may see: the private correlation digests * are dropped here, so no projection can leak them, and a snapshot that contradicts the * lifecycle state it accompanies is withheld entirely. * * Withheld, never repaired: the bytes on disk are preserved exactly as written — a * malformed or contradictory snapshot is evidence — while every public projection shows * nothing rather than a reconciled guess. */ export declare function publicRuntimeToolActivity(value: unknown, lifecycleState: unknown): Record | null; /** * What the caller observed at the exact moment the agent event was dispatched. * * Both the timestamp and the label are captured at that synchronous boundary, never * re-derived here: a later lookup would see a tool registry that may already have been * replaced, and a later clock reading would fold subscriber and lock latency into the * measured interval. */ export interface CoordinatorToolObservation { /** Canonical public label proven at the observation boundary; anything else is `custom`. */ label: string; /** Wall clock captured when the agent event was observed, before any queueing or lock wait. */ observedAt: string; } /** * Settle the activity snapshot a terminal lifecycle transition inherits. * * A settled session cannot still be running a tool, and later tool events are fenced out, * so an unmatched start would otherwise leave a nonzero `active_tool_count` forever. The * orphans are represented honestly — finished, `cancelled`, no elapsed interval — rather * than claimed as a success or a failure nothing observed. * * The same helper serves the runtime `agent_end`/postmortem path and the Coordinator's * canonical terminal repair so the two writers cannot settle differently. * * Two shapes need settling, not one. An orphaned in-flight call is the obvious case. The * other is a `phase: started` snapshot with NOTHING correlated — a start whose call id was * missing or blank never entered the in-flight table, so no end can ever close it — and * leaving it would write the prohibited terminal+started pair, a settled session that * still claims a tool is starting. An already-finished snapshot with nothing in flight is * returned unchanged: a normal terminal transition is not an activity event. */ export declare function terminallySettledRuntimeToolActivity(value: unknown, observedAt: string): RuntimeToolActivityReadout; export interface OwnerTerminalContext { generation: string; stateDir: string; socketKey: string; scope?: string | null; ownerPid?: number | null; ownerName?: string | null; operatorDispatchId?: string | null; } export interface RuntimeStateContext { sessionId: string; cwd: string; sessionFile?: string | null; /** Optional platform seam for deterministic cross-platform path identity checks. */ platform?: NodeJS.Platform; branch?: string | null; /** Public-safe owner metadata used to persist the canonical terminal verdict. */ ownerTerminal?: OwnerTerminalContext | null; /** Internal fail-closed marker set only when managed owner metadata is malformed or missing. */ ownerTerminalMetadataInvalid?: boolean; } export type TerminalRuntimeStateStatus = { terminal: true; state: "completed" | "errored"; } | { terminal: false; reason: "missing_state_file" | "invalid_json" | "invalid_state_marker" | "session_id_mismatch" | "cwd_mismatch" | "session_file_mismatch" | "non_terminal_state"; }; export declare function persistCoordinatorRuntimeInputReady(): Promise; export declare function readTerminalRuntimeStateMarker(input: { stateFile?: string | null; sessionId?: string | null; cwd?: string | null; sessionFile?: string | null; platform?: NodeJS.Platform; }): Promise; export declare function stateForEvent(event: RuntimeStateEvent): RuntimeState | null; /** True for every event the coordinator-shared file records: lifecycle state or tool activity. */ export declare function eventAffectsCoordinatorRuntimeState(event: RuntimeStateEvent): boolean; export declare function persistCoordinatorRuntimeStateFromEvent(event: RuntimeStateEvent, context: RuntimeStateContext, /** * What the caller observed at the synchronous agent-event boundary: the canonical * public label it proved against the ACTIVE tool object, and the wall clock it read * there. Without one, a tool event records `custom` at this writer's own clock — the * sidecar never trusts a model-supplied name. */ observation?: CoordinatorToolObservation): Promise; export declare function ownerTerminalContextFromEnvironment(): OwnerTerminalContext | "invalid" | null; export declare function persistCoordinatorRuntimeStateFromPostmortem(reason: postmortem.Reason, context: RuntimeStateContext): Promise; export declare function registerCoordinatorRuntimeStateFinalizer(context: RuntimeStateContext): () => void; export {};