import { type ManagedSessionState, type NativeThreadTransition } from "./managed-session.js"; import type { TerminalControlRef } from "./terminal-control-ref.js"; import { type NativeThreadLifecycleLedgerPhase, type TerminalDispatchLedgerDocument } from "./terminal-dispatch-ledger-codec.js"; import type { CanonicalMutationResources, CanonicalMutationScopes } from "./mutation-transaction.js"; import type { TerminalNativeIdentity as NativeAgentSessionIdentity, TerminalNativeIdentityFence as CodexCompanionIdentity } from "./terminal-binding-authority.js"; type ScopeArgs = [CanonicalMutationScopes, CanonicalMutationResources]; type Scoped = (...args: [...ScopeArgs, ...Args]) => Result; export type NativeThreadLifecycleRecoveryAuthority = { kind: "automatic"; } | { kind: "manual"; expectedTransitionId: string; }; export type NativeThreadLifecycleRecoveryTerminalFacts = Readonly<{ conversationId: string; agent: NativeThreadTransition["agent"]; pid: number; terminalControl: TerminalControlRef; }>; export type NativeThreadLifecycleRecoveryRequest = Readonly<{ /** Fresh post-lock terminal facts; all effects remain capability-bound. */ terminal: NativeThreadLifecycleRecoveryTerminalFacts; }>; export type NativeThreadLifecycleReconcileRequest = NativeThreadLifecycleRecoveryRequest & Readonly<{ ledger: TerminalDispatchLedgerDocument; authority?: NativeThreadLifecycleRecoveryAuthority; }>; export interface CodexCompanionSet { primary?: CodexCompanionIdentity; additional: CodexCompanionIdentity[]; } export type NativeThreadLifecycleOperation = Readonly<{ kind: "new_thread"; }> | Readonly<{ kind: "resume_thread"; nativeThreadId: string; }>; export type NativeThreadLifecycleCapabilityFacts = Readonly<{ status: "supported" | "unsupported" | "unknown"; }>; export type NativeThreadLifecyclePlanFacts = Readonly<{ steps: readonly Readonly<{ kind: string; command: string; effect: string; requiresIdle: true; }>[]; }>; export type NativeThreadLifecycleObservationFacts = Readonly<{ status: "observed" | "verified" | "missing" | "ambiguous" | "mismatch"; nativeThreadId?: string; evidence?: string; idle?: boolean; reason?: string; }>; export type NativeThreadLifecycleProbeContext = Readonly<{ kind: "physical"; }> | Readonly<{ kind: "codex_recovery"; processUuid: string; processBirth: string | undefined; expectedSessionId: string; companions: CodexCompanionSet; }>; export type NativeThreadLifecycleStatusFacts = Readonly<{ reachable: boolean; activityState: "awaiting_approval" | "working" | "idle" | "unknown"; approvalBlocked: boolean; composerVisible: boolean; composerEmpty: boolean; screenDigest?: string; }>; export type NativeThreadLifecycleStatusProbeFacts = Readonly<{ observationBaselineDigest: string; observationScrollbackLines: number; }>; export type NativeThreadLifecycleObservationRequest = Readonly<{ kind: "claude_agents"; operation: NativeThreadLifecycleOperation; pid: number; processStartedAt: number; cwd: string; }> | Readonly<{ kind: "codex_status"; operation: NativeThreadLifecycleOperation; context: Extract; observationBaselineDigest: string; observationScrollbackLines: number; }>; export type NativeThreadLifecycleObservationResult = Readonly<{ kind: "claude_agents"; observation: NativeThreadLifecycleObservationFacts | undefined; }> | Readonly<{ kind: "codex_status"; status: NativeThreadLifecycleStatusFacts; observation: NativeThreadLifecycleObservationFacts | undefined; }>; type LedgerExpectation = Readonly<{ expectedTransitionId: string | null; expectedStatus?: "prepared" | "dispatching" | "submitted"; }>; export type NativeThreadLifecycleRecoveryPorts = Readonly<{ authority: Readonly<{ bind: Scoped<[], Readonly<{ terminalControl: TerminalControlRef; }>>; }>; persistence: Readonly<{ listNativeThreadTransitions: Scoped<[], readonly NativeThreadTransition[]>; loadManagedSession: Scoped<[string], ManagedSessionState>; tryLoadManagedSession: Scoped<[string], ManagedSessionState | undefined>; loadNativeThreadTransition: Scoped<[string], NativeThreadTransition>; saveManagedSession: Scoped<[ ManagedSessionState, Readonly<{ expectedRevision: number | null; }> ], ManagedSessionState>; saveNativeThreadTransition: Scoped<[ NativeThreadTransition, Readonly<{ expectedRevision: number | null; }> ], NativeThreadTransition>; commitVerified: Scoped<[NativeThreadTransition, string], ManagedSessionState>; loadLedger: Scoped<[], TerminalDispatchLedgerDocument | undefined>; buildLedger: Scoped<[ NativeThreadTransition, NativeThreadLifecycleLedgerPhase ], TerminalDispatchLedgerDocument>; saveLedger: Scoped<[ NativeThreadTransition, NativeThreadLifecycleLedgerPhase, LedgerExpectation ], void>; saveFailClosedLedger: Scoped<[ TerminalDispatchLedgerDocument, string, string, string ], void>; }>; terminal: Readonly<{ recoverDeferred: Scoped<[], Promise>; sameTerminalIncarnation: Scoped<[TerminalControlRef], boolean>; aliasMatches: Scoped<[unknown, unknown, unknown], boolean>; workspaceMatches: Scoped<[unknown], boolean>; resolveIdentity: Scoped<[ string | undefined, CodexCompanionSet ], Promise>; observeExternalHandoff: Scoped<[ ManagedSessionState, NativeAgentSessionIdentity | undefined ], Promise>; assertExclusive: Scoped<[string, string | undefined], Promise>; assertTargetExclusive: Scoped<[NativeThreadTransition], Promise>; exactIdentity: Scoped<[ NativeAgentSessionIdentity ], NativeAgentSessionIdentity>; isProcessAlive: Scoped<[number], boolean>; recordedStoreMatches: Scoped<[string], boolean>; recordMatchesControl: Scoped<[TerminalDispatchLedgerDocument], boolean>; runningVersion: Scoped<[], string | undefined>; probeThreadLifecycle: Scoped<[ string | undefined ], NativeThreadLifecycleCapabilityFacts | undefined>; planThreadLifecycle: Scoped<[ NativeThreadLifecycleOperation, NativeThreadLifecycleCapabilityFacts ], NativeThreadLifecyclePlanFacts | undefined>; observeThreadLifecycle: Scoped<[ NativeThreadLifecycleObservationRequest ], Promise>; prepareProbeBridge: Scoped<[], void>; status: Scoped<[ NativeThreadLifecycleProbeContext, number | undefined ], Promise>; clearInputLine: Scoped<[NativeThreadLifecycleProbeContext], Promise>; submitCodexStatusProbe: Scoped<[ string, Extract ], Promise>; assertResumedCodexCandidate: Scoped<[ NativeAgentSessionIdentity, NativeThreadTransition["target_candidate_file_identity"] ], void>; codexKnownRoots: Scoped<[NativeThreadTransition], CodexCompanionSet>; codexCompanionsExcludingPreferred: Scoped<[ CodexCompanionSet, string ], CodexCompanionSet>; codexProcessBirth: Scoped<[], string>; nativeIdentityMatches: Scoped<[ NativeAgentSessionIdentity | undefined, CodexCompanionIdentity | undefined ], boolean>; }>; runtime: Readonly<{ now(): Date; sleep(milliseconds: number): Promise; }>; }>; export declare function recoverLifecycleFenceBeforeMutation(request: NativeThreadLifecycleRecoveryRequest, scopes: CanonicalMutationScopes, resources: CanonicalMutationResources, recoveryPorts: NativeThreadLifecycleRecoveryPorts): Promise; export declare function reconcileLifecycleDispatchLedger(request: NativeThreadLifecycleReconcileRequest, scopes: CanonicalMutationScopes, resources: CanonicalMutationResources, recoveryPorts: NativeThreadLifecycleRecoveryPorts): Promise; export {};