/** * Provider-neutral terminal identity and routing primitives. * * Persisted/public terminal control records intentionally keep their current * provider-owned shape. Generic lifecycle code must project those records * through the helpers in this module instead of rebuilding identity from * route fields such as a selector or socket path. */ export type TerminalControlCapability = "screen_status" | "send_keys" | "terminal_approval" | "screen_completion" | "durable_completion" | "terminal_cancel"; /** Transport capabilities owned by a terminal provider, not an agent TUI. */ export type TerminalProviderCapability = "screen_capture" | "ansi_capture" | "text_delivery" | "key_delivery" | "process_inspection" | "stable_resource_resolution"; interface TerminalControlRefBase { target: string; socketPath?: string; session: string; panePid: number; currentCommand?: string; currentPath?: string; capabilities: TerminalControlCapability[]; } export interface TmuxTerminalControlRef extends TerminalControlRefBase { kind: "tmux"; window: number; pane: number; } /** Persisted routing and identity owned by a Herdr server session. */ export interface HerdrTerminalControlRef extends TerminalControlRefBase { kind: "herdr"; /** Canonical Herdr session directory, when reported by session discovery. */ sessionDir?: string; workspaceId: string; tabId: string; /** Current public route. A cross-workspace move may replace this value. */ paneId: string; /** Stable resource identity for the lifetime of the underlying PTY. */ terminalId: string; } /** * Versioned union for provider-owned persisted/public control records. * New providers add a member here; generic callers consume * TerminalEndpointRef instead of narrowing this union themselves. */ export type TerminalControlRef = TmuxTerminalControlRef | HerdrTerminalControlRef; export interface TerminalPhysicalBindingTokenInput { readonly terminalId: string; readonly terminalControl: TerminalControlRef; readonly agent: "codex" | "claude"; readonly pid: number; readonly workspace: string; readonly nativeThreadId?: string; readonly processUuid?: string; readonly processBirth?: string; readonly rollout?: { readonly fd: string; readonly device: string; readonly inode: string; readonly path: string; }; } export interface TerminalEndpointIdentity { providerKind: string; endpointKey: string; resourceKey: string; } export interface TerminalRouteIdentity { routeKey: string; label: string; currentCommand?: string; currentPath?: string; } /** * Authoritative internal reference passed across the provider boundary. * `identity` is stable for binding/locking while `route` may be refreshed. * `providerRef` is opaque to generic lifecycle code. */ export interface TerminalEndpointRef { identity: TerminalEndpointIdentity; route: TerminalRouteIdentity; /** Process-incarnation evidence, deliberately separate from stable identity. */ processAnchorPid?: number; capabilities: readonly TerminalControlCapability[]; /** Opaque provider-owned routing payload. Generic code must never inspect it. */ providerRef: unknown; } /** * Durable evidence shape used by ledgers and snapshot compatibility readers. * Legacy route fields remain additive for diagnostics and old readers. */ export interface TerminalControlEvidence { schema: "agent-knock-knock/terminal-endpoint"; version: 1; kind: string; endpoint_key: string; resource_key: string; route_key: string; process_anchor_pid: number | null; /** Provider-owned compatibility fields; generic code must not derive identity from them. */ target?: string; socket_path?: string | null; pane_pid?: number | null; server_socket_path?: string | null; pane_id?: string | null; session_name?: string | null; session_dir?: string | null; workspace_id?: string | null; tab_id?: string | null; terminal_id?: string | null; current_path?: string | null; } export declare function createTerminalEndpointRef(value: { identity: TerminalEndpointIdentity; route: TerminalRouteIdentity; processAnchorPid?: number; capabilities: readonly TerminalControlCapability[]; providerRef: unknown; }): TerminalEndpointRef; export declare function terminalEndpointFromControlRef(terminalControl: TerminalControlRef): TerminalEndpointRef; export declare function hasCanonicalTerminalEndpoint(terminalControl: TerminalControlRef): boolean; export declare function terminalEndpointIdentityKey(value: TerminalEndpointRef | TerminalEndpointIdentity | TerminalControlRef): string; /** * Stable authority for one exact provider-owned terminal resource and coding * agent process incarnation. Screen generations and route labels are excluded * deliberately: a read-only native dialog may redraw either without changing * the physical pane selected by the user. */ export declare function terminalPhysicalBindingToken(value: TerminalPhysicalBindingTokenInput): string; export declare function sameTerminalEndpointIdentity(left: TerminalEndpointRef | TerminalEndpointIdentity | TerminalControlRef, right: TerminalEndpointRef | TerminalEndpointIdentity | TerminalControlRef): boolean; export declare function sameTerminalControlRoute(left: TerminalEndpointRef | TerminalControlRef, right: TerminalEndpointRef | TerminalControlRef): boolean; export declare function sameTerminalControlIncarnation(left: TerminalEndpointRef | TerminalControlRef, right: TerminalEndpointRef | TerminalControlRef): boolean; export declare function terminalControlEvidence(terminalControl: TerminalControlRef): TerminalControlEvidence; /** * Read canonical identity from a new evidence record or derive it from the * exact v0.11.x tmux fields. Unknown/malformed evidence fails closed. */ export declare function terminalEndpointIdentityFromEvidence(value: unknown): TerminalEndpointIdentity | undefined; export declare function terminalRouteKeyFromEvidence(value: unknown): string | undefined; export declare function terminalControlEvidenceMatches(evidence: unknown, terminalControl: TerminalControlRef, options?: { requireCurrentRoute?: boolean; requireProcessAnchor?: boolean; }): boolean; export declare function sameTerminalControlEvidenceIncarnation(left: unknown, right: unknown): boolean; /** * Restore a persisted additive endpoint record onto its legacy public control * ref. The association is deliberately non-enumerable and never rewrites the * Store object. Conflicting canonical and legacy fields fail closed. */ export declare function associateTerminalEndpointEvidence(terminalControl: TerminalControlRef, evidence: unknown): TerminalControlRef; /** Exact v0.11.x selector/incarnation tuple for compatibility artifacts. */ export declare function terminalLegacyControlEvidence(terminalControl: TerminalControlRef): { kind: TerminalControlRef["kind"]; target: string; socket_path: string | null; pane_pid: number; }; /** Exact legacy runtime route serialized by v0.11.x ledgers and locks. */ export declare function terminalLegacyRuntimeRoute(terminalControl: TerminalControlRef): { target: string; socket_path: string | null; kind?: "herdr"; }; /** Stable runtime resource key shared by terminal locks and capabilities. */ export declare function terminalRuntimeResourceKey(terminalControl: TerminalControlRef, options?: { legacy?: boolean; }): string; export declare function terminalControlWithCapabilities(terminalControl: TerminalControlRef, capabilities: readonly TerminalControlCapability[]): TerminalControlRef; export declare function tmuxTerminalRouteKey(endpointKey: string, target: string, socketPath?: string): string; export declare function herdrTerminalRouteKey(endpointKey: string, session: string, paneId: string): string; export {};