/** * Provenance and lifecycle primitives for tmux-resident GJC owners. * This module intentionally accepts and stores only opaque identifiers and * process/cgroup metadata; it never reads panes, prompts, environment, or logs. */ export declare const TMUX_OWNER_ISOLATION_SCHEMA_VERSION = 1; export declare const TMUX_OWNER_ISOLATION_MAX_LINE_BYTES: number; export declare const TMUX_OWNER_ISOLATION_MAX_DIAGNOSTIC_CHARS = 512; export declare function tmuxOwnerIsolationBootstrapArgv(): string[]; export type CgroupClassification = "not_applicable" | "safe" | "unsafe_service" | "unverifiable"; export type ServerState = "absent" | "safe" | "unsafe" | "unverifiable"; export type PlanErrorCode = "scope_unavailable" | "server_unsafe" | "server_unverifiable" | "server_race" | "scope_bootstrap_failed"; export type ExpectedTerminalResult = "owner_term_then_session_cleanup"; export type TerminalSignal = "SIGTERM" | "SIGHUP" | "SIGINT" | "SIGKILL" | "EXIT" | "MANUAL" | "UNKNOWN"; export type VerdictClassification = "expected_operator_shutdown" | "unexpected_owner_loss" | "non_operator_cleanup"; export type TerminalObserver = "sidecar" | "raw_monitor"; export interface CgroupInfo { classification: CgroupClassification; scope?: string; diagnostic?: string; } /** Classify only public cgroup path metadata; malformed Linux data fails closed. */ export declare function classifyCgroup(input: { platform: NodeJS.Platform; cgroupText?: string | null; }): CgroupInfo; export declare function ownerProcessStartTime(platform: NodeJS.Platform, stat: string | null): string | null; export interface TmuxServerProof { state: ServerState; pid?: number; startTime?: string; cgroup?: CgroupInfo; sessionNames?: string[]; /** * Whether `pid` is kernel-proved evidence about the live tmux server. * * Only Linux can prove a server PID (`/proc` + cgroup classification), so * probes on other platforms may report a placeholder PID with this flag set * to `false`. Guards must not build a `#{pid}` predicate from an unproven * PID: no live tmux server can ever satisfy it. Omitted means proven, which * keeps every probe that reads a real `#{pid}` unchanged. */ pidProven?: boolean; } export interface PlanRequest { schema_version: 1; op: "plan"; platform: NodeJS.Platform; session_id: string; owner_generation: string; cwd: string; state_dir: string; socket_key: string; tmux_argv: string[]; baseline: OwnerGenerationBaseline; } export interface PublishGenerationRequest { schema_version: 1; op: "publish_generation"; session_id: string; owner_generation: string; state_dir: string; baseline: OwnerGenerationBaseline; } export interface PublishGenerationResult { schema_version: 1; ok: true; code: "generation_published"; generation: string; } export interface AttemptCapability { token: string; session_name: string; socket_key: string; server_absent_before: boolean; baseline: OwnerGenerationBaseline; expires_at: string; } export interface DirectExecution { mode: "direct"; argv: string[]; attempt_session: string; server_key: string; server_absent_before: boolean; server_pid?: number; server_start_time?: string; } export interface ScopedExecution { mode: "scoped"; argv: string[]; stdin_line: string; expected_scope: string; attempt: AttemptCapability; attempt_session: string; server_key: string; server_absent_before: true; } export type PlanExecution = DirectExecution | ScopedExecution; export interface PlanSuccess { schema_version: 1; ok: true; code: "not_required" | "unsafe_scope_required"; execution: PlanExecution; classification: CgroupInfo; server_state: ServerState; } export interface TmuxOwnerIsolationExecutionSuccess { ok: true; code: "executed"; execution: PlanExecution; server: TmuxServerProof; server_key: string; server_pid: number; server_start_time: string; server_session: string; native_session_id?: string; } export interface PlanFailure { schema_version: 1; ok: false; code: PlanErrorCode; diagnostic: string; } export type PlanResponse = PlanSuccess | PlanFailure; export interface OwnerIsolationProbe { readCallerCgroup(): Promise; probeServer(socketKey: string, tmuxArgv?: string[]): Promise; } /** Synchronous probe boundary for managed launch paths. */ export interface OwnerIsolationProbeSync { readCallerCgroup(): string | null; probeServer(socketKey: string): TmuxServerProof; recordAttempt(input: { stateDir: string; sessionId: string; generation: string; attempt: AttemptCapability; }): void; } export interface TmuxOwnerIsolationExecutionFailure { ok: false; code: PlanErrorCode; diagnostic: string; } export type TmuxOwnerIsolationExecutionResult = TmuxOwnerIsolationExecutionSuccess | TmuxOwnerIsolationExecutionFailure; /** Synchronous spawn boundary; callers pass argv and scoped stdin unchanged. */ export interface TmuxOwnerIsolationExecutionDependencies { socketKey: string; spawn(argv: string[], stdinLine?: string): { exitCode: number | null; stdout?: string; }; probeServer(socketKey: string): TmuxServerProof; /** Reads the published owner generation immediately around direct execution. */ isCurrentGeneration?(): boolean; cleanupSpawned?(input: { execution: DirectExecution; nativeSessionId: string; server: TmuxServerProof; }): void; } export declare function isExactScopedBootstrapSuccessReceipt(stdout: string): boolean; export declare function isSafeServerProof(server: TmuxServerProof, platform?: NodeJS.Platform): server is TmuxServerProof & { state: "safe"; pid: number; startTime: string; cgroup: CgroupInfo; }; /** Compares the stable identity fields of independently observed tmux servers. */ export declare function sameServerIdentity(left: TmuxServerProof, right: TmuxServerProof): boolean; /** * Synchronous equivalent of the target-server truth table for managed callers. * Attempt persistence is injected so a caller can use its existing atomic state writer. */ export declare function planTmuxOwnerIsolationSync(request: PlanRequest, probe: OwnerIsolationProbeSync): PlanResponse; /** * Runs one planned argv exactly and re-proves the target server before callers * perform profile, attach, or cleanup operations. */ export declare function executeTmuxOwnerIsolationPlanSync(plan: PlanResponse, deps: TmuxOwnerIsolationExecutionDependencies): TmuxOwnerIsolationExecutionResult; /** Implements the target-server truth table before any tmux operation. */ export declare function planTmuxOwnerIsolation(request: PlanRequest, probe: OwnerIsolationProbe): Promise; export interface BootstrapRequest { schema_version: 1; op: "bootstrap"; session_id: string; owner_generation: string; state_dir: string; socket_key: string; expected_scope: string; tmux_argv: string[]; attempt: AttemptCapability; } export interface BootstrapResult { schema_version: 1; ok: boolean; code: "bootstrapped" | "scope_bootstrap_failed"; native_session_id?: string; server_pid?: number; server_start_time?: string; session_name?: string; diagnostic?: string; } export interface BootstrapDependencies { readSelfCgroup(): Promise; spawn(argv: string[]): { exitCode: number | null; stdout?: string; }; probeServer(socketKey: string, tmuxControlArgv?: string[]): Promise; } /** Self-proves the scope and synchronously invokes the exact supplied argv. */ export declare function bootstrapTmuxOwnerIsolation(request: BootstrapRequest, deps: BootstrapDependencies): Promise; export interface OwnerIntent { schema_version: 1; intent_id: string; generation: string; session_id: string; server_key: string; expected_terminal: { signal: "SIGTERM"; result: ExpectedTerminalResult; }; dispatch_id: string; created_at: string; expires_at: string; state: "pending"; } export interface OwnerVerdict { schema_version: 1; generation: string; session_id: string; server_key: string; observed_at: string; signal: TerminalSignal; exit_code: number | null; result: string; observer: TerminalObserver; classification: VerdictClassification; reason: string; intent_id?: string; dedupe_key: string; } export interface OwnerIncident { schema_version: 1; generation: string; session_id: string; dedupe_key: string; created_at: string; classification: "unexpected_owner_loss"; } export interface ObserveTerminalRequest { schema_version: 1; op: "observe_terminal"; session_id: string; owner_generation: string; state_dir: string; socket_key: string; observer: TerminalObserver; observed_at: string; signal: TerminalSignal; exit_code: number | null; exit_kind: string; reason: string; operator_dispatch_id?: string; } export interface LifecyclePaths { root: string; generation: string; generationFile: string; generationMarkerFile: string; intentFile: string; verdictFile: string; verdictAliasFile: string; incidentFile: string; lockDatabaseFile: string; journalFile: string; } export declare function lifecyclePaths(stateDir: string, sessionId: string, generation: string): LifecyclePaths; export interface MemoryGuardClaimPaths { root: string; databaseFile: string; walFile: string; shmFile: string; } export declare function memoryGuardClaimPaths(stateDir: string, sessionId: string): MemoryGuardClaimPaths; export declare function replaceOwnerGeneration(stateDir: string, sessionId: string, generation?: string, expectedBaseline?: OwnerGenerationBaseline): Promise; export type OwnerGenerationBaseline = { state: "absent"; } | { state: "current"; schema_version: 1; generation: string; session_id: string; published_at: string; }; export interface ManagedOwnerPredecessorEvidence { generation: string; sessionId: string; runId: string; incarnation: string; predecessorToken: string; } /** Resolve one SIGABRT predecessor from the retained exact prior-generation root. */ export declare function resolveManagedOwnerPredecessorSync(stateDir: string, sessionId: string, baseline: OwnerGenerationBaseline): ManagedOwnerPredecessorEvidence | undefined; export declare function captureOwnerGenerationBaseline(stateDir: string, sessionId: string): Promise; /** Captures the full immutable generation record for a planned owner launch. */ export declare function captureOwnerGenerationBaselineSync(stateDir: string, sessionId: string): OwnerGenerationBaseline; export declare function isOwnerGenerationBaselineCurrentSync(stateDir: string, sessionId: string, baseline: OwnerGenerationBaseline): boolean; /** Synchronous publication for managed launch paths, serialized by a SQLite write transaction. */ export declare function replaceOwnerGenerationSync(stateDir: string, sessionId: string, generation: string, expectedBaseline: OwnerGenerationBaseline): string; /** Publishes a raw-owner generation through the canonical SQLite-serialized CAS path. */ export declare function publishOwnerGenerationSync(request: PublishGenerationRequest): PublishGenerationResult; export declare function createOwnerIntent(stateDir: string, input: Omit): Promise; /** Publish exactly one terminal verdict. Existing valid verdicts always win. */ export declare function observeOwnerTerminal(request: ObserveTerminalRequest): Promise; /** Strictly validate the persisted authorization, optionally against its terminal observation. */ export declare function isValidOwnerIntent(intent: unknown, request?: ObserveTerminalRequest): intent is OwnerIntent; /** Accept only real UTC timestamps in the canonical evidence serialization. */ export declare function isCanonicalUtcTimestamp(value: unknown): value is string; /** Strictly validate a complete persisted verdict, optionally against its observation. */ export declare function isValidOwnerVerdict(verdict: unknown, request?: ObserveTerminalRequest): verdict is OwnerVerdict; export interface ExactOwnerCloseRequest { stateDir: string; sessionId: string; generation: string; serverKey: string; pid: number; startTime: string; dispatchId: string; createdAt: string; expiresAt: string; } export interface ExactOwnerCloseDependencies { readStartTime(pid: number): Promise; sendSigterm(pid: number): Promise; waitForVerdict(): Promise; cleanupSession(): Promise; } /** Authorizes only an exact, start-time-validated SIGTERM before compatibility cleanup. */ export declare function closeExactTmuxOwner(request: ExactOwnerCloseRequest, deps: ExactOwnerCloseDependencies): Promise; export declare function parseOwnerIsolationRequest(line: string): PlanRequest | BootstrapRequest | PublishGenerationRequest | ObserveTerminalRequest | null; export declare function serializeOwnerIsolationResponse(response: PlanResponse | BootstrapResult | PublishGenerationResult | OwnerVerdict): string;