import type { ExecutorKind } from "./executors.js"; import { type ManagedSessionState } from "./managed-session.js"; export interface TerminalNativeRolloutIdentity { fd: string; device: string; inode: string; path: string; } export interface TerminalNativeIdentity { sessionId: string; processStartedAt?: number; processUuid?: string; processBirth?: string; rollout?: TerminalNativeRolloutIdentity; evidence: string; } /** Exact adapter-neutral fence for one materialized native identity. */ export interface TerminalNativeIdentityFence { sessionId: string; processUuid: string; processBirth: string; rollout: TerminalNativeRolloutIdentity; } export declare function isCompleteNativeRollout(value: unknown): value is TerminalNativeRolloutIdentity; export declare function terminalNativeIdentityFence(identity: TerminalNativeIdentity | undefined): TerminalNativeIdentityFence | undefined; export declare function terminalNativeIdentityMatchesFence(identity: TerminalNativeIdentity | TerminalNativeIdentityFence | undefined, expected: TerminalNativeIdentityFence | undefined): boolean; export type TerminalNativeIdentityObservation = { status: "resolved"; identity: TerminalNativeIdentity; } | { status: "verified_absent"; evidence?: string; } | { status: "unavailable"; reason?: string; } | { status: "not_observed"; }; export interface TerminalCodexOpenRootIdentity { sessionId: string; processUuid: string; processBirth: string; rollout: TerminalNativeRolloutIdentity; } export interface TerminalCodexOpenRootInventory { pid: number; processUuid: string; processBirth: string; roots: readonly TerminalCodexOpenRootIdentity[]; } /** * One ephemeral observation of a live terminal. * * The native identity and process incarnation are deliberately separate. A * list scan may supplement process-incarnation evidence without upgrading the * coding-agent identity returned by its native resolver. Callers must build a * fresh observation at each mutation boundary; this value is never durable * authorization. */ export interface TerminalObservation { agent: ExecutorKind; pid: number; nativeIdentity: TerminalNativeIdentityObservation; processIncarnation: { processUuid?: string; processBirth?: string; }; statusCardNativeThreadId?: string; codexOpenRootInventory?: TerminalCodexOpenRootInventory; } /** Build the list-side observation without importing CLI orchestration. */ export declare function terminalObservationFromListEntry(terminal: Record, agent: ExecutorKind): TerminalObservation; /** Build the mutation-side observation from evidence freshly read under lock. */ export declare function terminalObservationFromResolvedIdentity({ agent, pid, identity, processIncarnation }: { agent: ExecutorKind; pid: number; identity: TerminalNativeIdentity | undefined; processIncarnation: TerminalObservation["processIncarnation"]; }): TerminalObservation; export interface TerminalBindingMatchEvidence { /** Result of the existing canonical/legacy terminal alias fence. */ terminalAliasMatches: boolean; /** Result of the existing realpath-backed workspace fence. */ workspaceMatches: boolean; /** * Store-backed committed-transition evidence. This is false until the * caller has performed that read at the same point as the legacy path. */ codexLingeringBeforeMatches?: boolean; } export type ManagedBindingConflictKind = "stale_process_incarnation" | "live_external_thread_change" | "provisional_orphan" | "unverifiable"; export declare function classifyTerminalBindingConflict(facts: { session: ManagedSessionState; processRelationship: "same" | "different" | "unverifiable"; liveNativeThreadId?: string; statusCardNativeThreadId?: string; managedTurnCount?: number; }): ManagedBindingConflictKind; export type AuthorityDecision = { state: "unrelated"; reason: "session_not_bound" | "missing_binding" | "agent_mismatch" | "pid_mismatch" | "terminal_alias_mismatch" | "workspace_mismatch"; } | { state: "exact"; basis: "native_identity" | "codex_open_root_rollout" | "codex_status_card_process" | "codex_lingering_before"; } | { state: "not_exact"; reason: "status_card_thread_mismatch" | "native_identity_absent" | "native_identity_mismatch"; }; /** * Pure exact-binding policy shared by read-only projection and mutation * preparation. Store, process and filesystem evidence is gathered by the * caller and supplied explicitly so this function cannot widen authorization * or change I/O ordering. */ export declare function decideTerminalBindingMatch(session: ManagedSessionState, observation: TerminalObservation, evidence: TerminalBindingMatchEvidence): AuthorityDecision; export declare function exactRolloutMatches(left: unknown, right: TerminalNativeRolloutIdentity | undefined): boolean; /** Stable Codex rollout-file identity; an open descriptor may churn. */ export declare function rolloutFileIdentityMatches(left: unknown, right: TerminalNativeRolloutIdentity | undefined): boolean; export declare function candidateSourceRootAuthorityMatches(roots: readonly TerminalCodexOpenRootIdentity[], sourceThreadId: string | undefined, sourceRollout: TerminalNativeRolloutIdentity | undefined, authority: "present" | "explicitly_abandoned_predecessor"): boolean; export declare function isCodexStatusCardEvidence(evidence: string): boolean;