import type { ExecutorKind } from "./executors.js"; import type { FileLockAcquisitionOptions } from "./file-lock-cli-adapter.js"; import { type ManagedSessionState } from "./managed-session.js"; import { type LifecycleTerminalObservation, type NativeThreadLifecycleQueryPorts } from "./native-thread-lifecycle-query-service.js"; import { type Conversation } from "./protocol.js"; import type { TerminalAgentAdapter, TerminalControlRef, TerminalRuntimeIdentity, TerminalThreadLifecycleCapabilities } from "./terminal-agent-adapter.js"; import { type ResolvedTerminalConversation, type TerminalAgentBridge } from "./terminal-agent-bridge.js"; import { type CodexAllowedCompanionSet } from "./terminal-authority-policy.js"; import type { TerminalNativeIdentity } from "./terminal-binding-authority.js"; import type { TerminalDispatchLedgerDocument } from "./terminal-dispatch-ledger-codec.js"; import type { TerminalRuntimeCliAdapter } from "./terminal-runtime-cli-adapter.js"; export type NativeLifecycleCliOptions = Readonly>; export declare const CODEX_FOREGROUND_IDENTIFICATION_TTL_MS = 30000; export declare const CODEX_FOREGROUND_IDENTIFICATION_SCROLLBACK_LINES = 240; /** * Short-lived diagnostic evidence returned only to the in-process caller. * * This is deliberately not a Store binding or an authorization token. The * caller must remain inside the same terminal lock and must still use the * ordinary request-acceptance path before creating durable Session authority. */ export interface CodexForegroundIdentificationProof { readonly terminalId: string; readonly pid: number; readonly processUuid: string; readonly processBirth: string; readonly realCwd: string; readonly nativeThreadId: string; readonly agentVersion: string; readonly behaviorProfile: string; readonly evidenceFingerprint: string; readonly postProbeScreenDigest: string; readonly observationScrollbackLines: typeof CODEX_FOREGROUND_IDENTIFICATION_SCROLLBACK_LINES; readonly observedAt: string; readonly expiresAt: string; readonly terminalSubmission: { readonly command: "/status"; readonly enterCount: 1; readonly materialization: NativeInspectionSubmission["materialization"]; }; } export interface NativeLifecycleSnapshot { readonly identity?: TerminalNativeIdentity; readonly runtimeIdentity?: TerminalNativeIdentity; readonly codexCompanions: CodexAllowedCompanionSet; readonly session?: ManagedSessionState; readonly version?: string; readonly capabilities: TerminalThreadLifecycleCapabilities; readonly bindingToken: string; readonly bindingTokens: readonly string[]; } interface NativeLifecycleIdentityPorts { resolveCurrent(input: { options: NativeLifecycleCliOptions; agent: ExecutorKind; pid: number; cwd?: string; preferredSessionId?: string; allowedCompanionIdentity?: CodexAllowedCompanionSet["primary"]; allowedAdditionalIdentities?: readonly NonNullable[]; }): Promise; managedContext(input: { storeDir: string; terminal: ResolvedTerminalConversation; }): { preferredSessionId?: string; companions: CodexAllowedCompanionSet; }; boundSession(input: { storeDir: string; terminal: ResolvedTerminalConversation; identity?: TerminalNativeIdentity; }): ManagedSessionState | undefined; materializeSession(input: { options: NativeLifecycleCliOptions; terminal: ResolvedTerminalConversation; identity?: TerminalNativeIdentity; }): ManagedSessionState | undefined; refineSession(input: { storeDir: string; session: ManagedSessionState; terminalControl: TerminalControlRef; identity?: TerminalNativeIdentity; }): ManagedSessionState; logicalIdentity(input: { storeDir: string; session: ManagedSessionState; observedIdentity?: TerminalNativeIdentity; }): TerminalNativeIdentity | undefined; companionSet(input: { storeDir: string; session: ManagedSessionState; }): CodexAllowedCompanionSet; processIncarnation(pid: number): { processUuid: string; processBirth: string; }; /** * Provider-independent operating-system process identity used only for * explicit physical-terminal authority. Keep it separate from Codex native * lifecycle identity so the producer and consumer of a physical token cannot * silently choose different UUID namespaces. */ physicalProcessIncarnation(pid: number): { processUuid: string; processBirth: string; }; runtimeForLiveIdentity(input: { terminal: LifecycleTerminalObservation; identity?: TerminalNativeIdentity; expectedEmptyNativeSession?: boolean; physicalOnly?: boolean; }): TerminalRuntimeIdentity; ownerIsInactive(input: { session: ManagedSessionState; terminal: LifecycleTerminalObservation; identity?: TerminalNativeIdentity; }): boolean; assertCodexComposerReady(input: { options: NativeLifecycleCliOptions; terminalControl: TerminalControlRef; }): Promise; } interface NativeLifecycleStatePorts { storeDir(options: NativeLifecycleCliOptions): string; inspectStore(storeDir: string): { writable: boolean; }; runtimeDir(): string; acquireTerminal(storeDir: string, terminalControl: TerminalControlRef, options?: FileLockAcquisitionOptions): () => void; loadLedger(terminalControl: TerminalControlRef): TerminalDispatchLedgerDocument | undefined; managedTurns(storeDir: string, sessionId: string): readonly Conversation[]; terminalBlockingTurns(storeDir: string, terminalControl: TerminalControlRef): readonly Conversation[]; hasUnresolvedTransition(storeDir: string, session: ManagedSessionState): boolean; dispatchOwnership(terminalControl: TerminalControlRef): { state: string; }; assertNativeThreadStoreAuthority(input: { terminalControl: TerminalControlRef; nativeThreadId: string; storeDir: string; }): void; orphanedForRecovery(terminalControl: TerminalControlRef): TerminalDispatchLedgerDocument | undefined; } export interface CreateNativeThreadLifecycleCliAdapterInput { runtime: { forOptions(options: NativeLifecycleCliOptions): TerminalRuntimeCliAdapter; sleep(milliseconds: number): Promise; }; identity: NativeLifecycleIdentityPorts; state: NativeLifecycleStatePorts; output: { cwd(): string; print(value: unknown): void; }; } export interface NativeThreadOwnershipRequest { options: NativeLifecycleCliOptions; agent: ExecutorKind; currentPid: number; nativeThreadId: string; storeDir: string; terminalControl: TerminalControlRef; excludedManagedSessionId?: string; allowedManagedSessionIds?: string[]; } export interface NativeThreadLifecycleCliFacade { resolveLifecycleTerminal(options: NativeLifecycleCliOptions): Promise; queryPorts(options: NativeLifecycleCliOptions): NativeThreadLifecycleQueryPorts; assertExclusive(input: NativeThreadOwnershipRequest): Promise; currentSnapshot(options: NativeLifecycleCliOptions, terminal: ResolvedTerminalConversation, settings?: { materialize?: boolean; }): Promise; lifecycleBindingTokens(input: { session?: ManagedSessionState; terminal: ResolvedTerminalConversation; identity?: TerminalNativeIdentity; }): readonly string[]; agentAdapter(options: NativeLifecycleCliOptions, agent: ExecutorKind): TerminalAgentAdapter; runList(options: NativeLifecycleCliOptions): Promise; runInspect(options: NativeLifecycleCliOptions): Promise; runModelOptions(options: NativeLifecycleCliOptions): Promise; runSetModel(options: NativeLifecycleCliOptions): Promise; runRepairModelControl(options: NativeLifecycleCliOptions): Promise; runIdentifyForeground(options: NativeLifecycleCliOptions): Promise; identifyCodexForegroundWhileLocked(input: { options: NativeLifecycleCliOptions; terminal: LifecycleTerminalObservation; expectedTerminalToken: string; }): Promise; assertSameInspectionTerminal(expected: LifecycleTerminalObservation, actual: LifecycleTerminalObservation, stage: string): void; codexLatentClearResumeObservation(input: { screen?: string; agentVersion?: string; }): { sourceNativeThreadId: string; fingerprint: string; } | undefined; nativeInspectionComposerEmpty(agent: ExecutorKind, screen?: string): boolean; } export declare function createNativeThreadLifecycleCliAdapter(ports: CreateNativeThreadLifecycleCliAdapterInput): NativeThreadLifecycleCliFacade; type NativeInspectionSubmission = Awaited>; export {};