import { Transport } from './transport.js'; export interface ConnectionState { connected: boolean; cpuId: number | null; vesselName: string | null; cpuTag: string | null; lastError: string | null; } export interface CommandResult { success: boolean; output: string; error?: string; } export interface KosConnectionOptions { host?: string; port?: number; /** * CPU ID to connect to (1-based). If cpuLabel is provided, this is ignored. */ cpuId?: number; /** * CPU label to connect to (e.g., 'guidance', 'flight'). * If provided, the connection will search for a CPU with this label. */ cpuLabel?: string; /** * Transport type to use. Defaults to 'socket'. * - 'socket': Uses Node.js net.Socket for direct TCP (recommended, no external deps) * - 'tmux': Uses tmux sessions with nc (allows attaching to see output) */ transportType?: 'socket' | 'tmux'; /** * Optional custom transport instance. If provided, overrides transportType. */ transport?: Transport; } export interface ExecuteOptions { /** * Skip waiting for sentinel/prompt output. Useful for commands that intentionally * tear down the session (e.g., quickload) where no response will arrive. */ fireAndForget?: boolean; } /** * High-level kOS connection manager. * * Uses a Transport abstraction for the underlying communication, * making it easy to swap between socket (default) or tmux implementations. */ export declare class KosConnection { private transport; private transportType; private providedTransport; private state; private commandSequence; private options; constructor(options?: KosConnectionOptions); /** * Create the transport instance. Called lazily during connect(). */ private createTransport; /** * Connect to kOS terminal server and attach to a CPU. * @param cpuIdOrLabel - CPU ID (number) or label (string). Overrides constructor options. */ connect(cpuIdOrLabel?: number | string): Promise; /** * Execute a kOS command and return the result */ execute(command: string, timeoutMs?: number, options?: ExecuteOptions): Promise; /** * Disconnect from kOS terminal */ disconnect(): Promise; /** * Get current connection state */ getState(): ConnectionState; /** * Check if connected */ isConnected(): boolean; /** * Get the underlying transport (for debugging/advanced use) */ getTransport(): Transport | null; /** * Parse connection info from kOS menu output * Example line: "[1] no 1 stick 1 (RC-L01(guidance))" */ private parseConnectionInfo; /** * Find CPU ID by label/tag from menu output * Menu format: "[1] no 1 stick 1 (RC-L01(guidance))" * @returns CPU ID if found, undefined otherwise */ private findCpuByLabel; /** * Get first CPU ID from menu output (for auto-selection) * @returns First CPU ID found, or undefined if none */ private getFirstCpuId; /** * List available CPUs from menu output (for error messages) * Menu format: "[1] no 1 stick 1 (RC-L01(guidance))" */ private listCpus; /** * Clean up command output (remove echo, prompts, kOS terminal control chars) * * kOS uses Unicode Private Use Area (U+E000-U+F8FF) for terminal control. * See /docs/kos-protocol-analysis.md for full protocol documentation. * * Key UnicodeCommand values: * - TELEPORTCURSOR (0xE006): followed by 2 bytes (col, row) * - RESIZESCREEN (0xE016): followed by 2 bytes (width, height) * - TITLEBEGIN (0xE004): followed by chars until TITLEEND (0xE005) * - All others: single character commands */ private cleanOutput; /** * Strip kOS UnicodeCommand sequences from output. * * kOS uses Private Use Area chars (U+E000-U+F8FF) for terminal control. * Some commands have trailing parameter bytes that must also be stripped: * - TELEPORTCURSOR (0xE006): + col byte + row byte * - RESIZESCREEN (0xE016): + width byte + height byte * - TITLEBEGIN (0xE004): + chars until TITLEEND (0xE005) */ private stripUnicodeCommands; /** * Detect common kOS errors in output */ private detectError; /** * Create a unique sentinel PRINT command that signals command completion. */ private createSentinel; /** * Build a regex pattern that matches the sentinel token when it appears on its own line. * This prevents triggering on the command echo (which also contains the token). */ private buildSentinelPattern; } //# sourceMappingURL=kos-connection.d.ts.map