/** * Pure lifecycle transition decisions. * * Callers must collect and validate terminal, Store, process, token, and * candidate facts before invoking these reducers. This module deliberately * owns no I/O, lock acquisition, persistence, clocks, or user-facing text. */ import type { ManagedSessionState, ManagedTerminalBinding, NativeThreadCandidate, NativeThreadTransition } from "./managed-session.js"; import type { ManagedBindingConflictKind, TerminalNativeIdentity } from "./terminal-binding-authority.js"; export type { ManagedBindingConflictKind } from "./terminal-binding-authority.js"; export type NativeThreadCommandOperation = "new_thread" | "resume_thread"; export type NativeThreadTransitionEligibilityDecision = { action: "proceed"; } | { action: "reject"; reason: "binding_token_changed" | "lifecycle_status_not_supported" | "new_thread_not_supported" | "resume_thread_not_supported"; }; export declare function decideNativeThreadTransitionEligibility(input: { operation: NativeThreadCommandOperation; bindingTokenMatches: boolean; capabilityStatus: "supported" | "unsupported" | "unknown"; newThreadSupported: boolean; resumeExactSupported: boolean; }): NativeThreadTransitionEligibilityDecision; export type ResumeCandidateEligibilityDecision = { action: "proceed"; candidate: NativeThreadCandidate; } | { action: "reject"; reason: "candidate_not_found" | "candidate_not_resumable" | "candidate_token_changed"; }; export declare function decideResumeCandidateEligibility(input: { candidate?: NativeThreadCandidate; expectedCandidateToken: string; }): ResumeCandidateEligibilityDecision; export type ResumeTargetSessionDecision = { action: "proceed"; } | { action: "detach_stale_binding"; } | { action: "reject"; reason: "unresolved_turn" | "bound_owner_not_conclusively_inactive"; }; export declare function decideResumeTargetSession(input: { hasUnresolvedTurn: boolean; loadedSession?: ManagedSessionState; boundOwnerConclusivelyInactive: boolean; }): ResumeTargetSessionDecision; export type BindingReconciliationDecision = { action: "detach_conflicting_binding"; } | { action: "reject"; reason: "stale_process_incarnation" | "already_exact" | "unverifiable"; }; export declare function decideBindingReconciliation(conflictKind: ManagedBindingConflictKind | undefined): BindingReconciliationDecision; export type DurableNativeThreadTransitionStatus = "prepared" | "dispatching" | "submitted" | "uncertain" | "verified" | "committed" | "aborted"; export type NativeThreadTransitionFailureDecision = { action: "report_committed_bookkeeping_failure"; } | { action: "require_verified_recovery"; } | { action: "abort_before_terminal_input"; } | { action: "mark_uncertain"; }; export declare function decideNativeThreadTransitionFailure(input: { durableStatus: DurableNativeThreadTransitionStatus; inputStarted: boolean; errorProvesInputNotStarted: boolean; }): NativeThreadTransitionFailureDecision; export type NativeThreadTransitionPhaseEvent = { type: "dispatch_started"; at: string; } | { type: "submission_recorded"; at: string; } | { type: "target_verified"; at: string; afterBinding: ManagedTerminalBinding; } | { type: "commit_recorded"; at: string; } | { type: "aborted_before_input"; at: string; error: string; } | { type: "outcome_uncertain"; at: string; error: string; }; export interface NativeThreadTransitionPreparation { transitionId: string; operation: { kind: "new_thread"; } | { kind: "resume_thread"; nativeThreadId: string; }; terminalId: string; agent: NativeThreadTransition["agent"]; workspace: string; source?: { state: ManagedSessionState; revision: number; }; targetSessionId: string; target?: { state: ManagedSessionState; revision: number; }; candidateFileIdentity?: NativeThreadTransition["target_candidate_file_identity"]; beforeIdentity: TerminalNativeIdentity; beforeProcessUuid: string; beforeBinding?: ManagedTerminalBinding; adapterVersion: string; commandFingerprint: string; dispatcherPid: number; preparedAt: string; } export declare function prepareNativeThreadTransition(input: NativeThreadTransitionPreparation): NativeThreadTransition; /** * Builds the next in-memory transition value only. The caller retains the * revision CAS, durable write, ledger ordering, and crash fences. */ export declare function reduceNativeThreadTransitionPhase(transition: NativeThreadTransition, event: NativeThreadTransitionPhaseEvent): NativeThreadTransition;