import type { TerminalAttachment } from './substrate/tmux-stream.js'; import type { NativeSessionIdleProof } from './substrate/native-host.js'; import type { TerminalInputDelivery, TmuxCommand, TmuxWindowSize } from './substrate/tmux.js'; import type { SessionDescriptor } from '@volter-ai-dev/supercode-harness-sdk'; export type TerminalAttachmentGrant = Readonly<{ expiresAt: number; id: string; mode: 'observe' | 'control'; }>; export type EmbeddedTerminalAttachmentGrant = TerminalAttachmentGrant & Readonly<{ baseUrl: string; }>; export type TerminalSession = Readonly<{ activeCommand: string | null; /** Opaque application context association; never a native harness or tmux handle. */ contextKey: string | null; cwd: string | null; id: string; label: string; owned: boolean; /** The pane's root process (its shell), for finding what runs beneath it. */ rootPid: number | null; size: Readonly<{ columns: number; rows: number }> | null; }>; export type StructuredLaunch = Readonly<{ arguments: string[]; env: Readonly>; program: string; }>; export type TmuxTerminalHostOptions = { allowUnownedControl?: boolean; attachmentTtlMs?: number; contextOption?: string; ownerId?: string; ownerOption?: string; openLocalTerminal?: (launch: StructuredLaunch) => Promise; socket?: string; }; export class TmuxTerminalHost { constructor(options?: TmuxTerminalHostOptions); listSessions(): Promise; createSession(input: { command: TmuxCommand; contextKey?: string; cwd?: string; env?: Record; name?: string; }): Promise; capture(sessionId: string, options?: { lines?: number; preserveEscapes?: boolean }): string; sendInput( sessionId: string, data: string, options?: { deadlineMs?: number; submitMode?: 'retry' | 'single' }, ): Promise; /** Persist an opaque application context association on a session owned by this host. */ bindContext(sessionId: string, contextKey: string): Promise; issueAttachment(sessionId: string, options?: { mode?: 'observe' | 'control' }): TerminalAttachmentGrant; attachSocket( attachmentId: string, socket: unknown, size?: { cols?: number; rows?: number }, ): Promise; localAttachLaunch(sessionId: string): StructuredLaunch; openLocalTerminal(sessionId: string): Promise; closeSession(sessionId: string): void; dispose(): void; } export class TerminalWebSocketBridge { constructor(options: { host: Pick; allowedOrigins: string | readonly string[]; }); readonly baseUrl: string; start(): Promise; issueAttachment(sessionId: string, options?: { mode?: 'observe' | 'control' }): EmbeddedTerminalAttachmentGrant; stop(): Promise; } export type SupercodeTerminalHarness = 'claude-code' | 'codex' | 'gemini' | 'grok'; export type SupercodeTerminalLaunch = Readonly<{ arguments?: readonly string[]; cwd: string; env?: Readonly>; program: string; }>; export type SupercodeTerminalAttachment = EmbeddedTerminalAttachmentGrant & Readonly<{ conversationKey: string | null; sessionId: string; }>; export type SupercodeTerminalSnapshot = Readonly<{ attachment: SupercodeTerminalAttachment | null; available: boolean; bindings: readonly Readonly<{ conversationKey: string; sessionId: string }>[]; canOpenLocal: boolean; error: string | null; sessions: readonly TerminalSession[]; }>; export type SupercodeTerminalControllerOptions = Readonly<{ allowedOrigins: string | readonly string[]; formatCwd?: (cwd: string) => string | null | undefined; host?: TmuxTerminalHostOptions; nativeHost?: { socket?: string; home?: string; claudeConfigDir?: string }; sessionNamePrefix?: string; }>; export class SupercodeTerminalController { constructor(options: SupercodeTerminalControllerOptions); start(): Promise; snapshot(): Promise; create(harness: SupercodeTerminalHarness, cwd: string): Promise; launchSession( harness: string, launch: SupercodeTerminalLaunch, conversationKey?: string | null, initialInput?: string, options?: Readonly<{ conversationDiscovery?: Readonly<{ knownConversationKeys: readonly string[]; prompt: string; startedAtMs?: number; }>; }>, ): Promise; attach(sessionId: string, mode: 'observe' | 'control'): Promise; bindContext(sessionId: string, conversationKey: string): Promise; reconcileConversationBindings( descriptors: readonly SessionDescriptor[], keyForDescriptor: (descriptor: SessionDescriptor) => string, options?: Readonly<{ now?: number }>, ): Promise[]; snapshot: SupercodeTerminalSnapshot; }>>; close(sessionId: string): Promise; openLocal(sessionId: string): Promise; dismiss(): Promise; refreshNativeSessions(): Promise; canMoveSession(harness: string, sessionId: string, cwd: string): boolean; prepareMoveSession( harness: string, sessionId: string, cwd: string, proof: NativeSessionIdleProof | null, ): Promise; moveSession( harness: string, sessionId: string, launch: SupercodeTerminalLaunch, conversationKey: string, proof: NativeSessionIdleProof, ): Promise; stop(): Promise; } export class TerminalHostError extends Error { readonly code: string; constructor(code: string, message: string); } /** * Is the program of this kind showing its idle composer on this captured screen? * `null` means this package has no composer pattern for that kind — never read * it as "not ready yet". */ export function composerReadyForInput(kind: string, screen: string | undefined): boolean | null; /** Does the composer hold a typed draft? `screen` is a capture with escapes; null when no composer is on screen. */ export function composerHoldsDraft(kind: string, screen: string | undefined): boolean | null; export { classifyAttentionSignal, observeLifecycle, gatherLifecycleObservation, createLifecycleStore, snapshotProcessTree, snapshotProcessTreeAsync } from './substrate/session-lifecycle.js'; export type { LifecycleSnapshot, LifecycleStore, PaneLifecycle, PaneProcessLifecycle, PaneProcessObservation, SessionAttentionSignal, SessionDerivation, DerivationConfidence, DerivationSource, SessionLifecycle, SessionLifecycleState, } from './substrate/session-lifecycle.js'; export type { TerminalInputDelivery, TmuxCommand, TmuxWindowSize };