/** * CLI Display Module — Formatting Utilities, Spinner, and Status Line Manager * * Provides terminal display primitives for the CLI interactive mode, inspired * by the Electron desktop app UX patterns. All display logic is centralized * here so that `index.ts` handles event routing and `stream.ts` handles * streaming data management. * * FEATURES: * - Pure formatting functions: tool names, elapsed time, tool icons, truncation * - Braille spinner with configurable label * - Unified status line manager combining spinner, elapsed timer, agent queue, * and active tools on a single rewritable terminal line * - Readline coordination via pause/resume to avoid prompt corruption * * NOTES: * - Leaf module with no internal project imports (only Node built-ins) * - All side-effectful output uses process.stdout.write (no console.log) * - Unicode symbols chosen for consistent terminal width (no emoji) * * CHANGES: * - 2026-02-11: Initial creation — Phase 1-3 of CLI UX improvement plan */ /** Entry describing an active or completed tool in the status line. */ export interface ToolDisplayEntry { name: string; status: 'running' | 'done' | 'error'; detail?: string; } /** Entry describing an agent in the status line. */ export interface AgentDisplayEntry { name: string; active: boolean; } /** Full snapshot of what the status line should render. */ export interface StatusLineState { spinner: { label: string; active: boolean; }; elapsedMs: number; agents: AgentDisplayEntry[]; tools: ToolDisplayEntry[]; } /** * Convert a tool name from snake_case / camelCase to Title Case for display. * * Examples: * read_file → Read File * shell_cmd → Shell Cmd * searchAndReplace → Search And Replace * listDir → List Dir */ export declare function formatToolName(toolName: string): string; /** * Format elapsed milliseconds as a human-readable duration string. * * Examples: * 0 → 0:00 * 5000 → 0:05 * 65000 → 1:05 * 3661000 → 1:01:01 */ export declare function formatElapsed(ms: number): string; /** * Return a Unicode icon for a tool based on its name pattern. * * Uses fixed-width Unicode symbols (not emoji) for consistent terminal rendering. */ export declare function getToolIcon(toolName: string): string; /** * Truncate a string to fit within `maxWidth` columns, appending "…" if trimmed. * * Uses simple character count (not full Unicode width detection) which is * correct for the fixed-width symbols we use in the status line. */ export declare function truncateToWidth(text: string, maxWidth: number): string; export interface Spinner { start: (label: string) => void; stop: () => void; isRunning: () => boolean; cleanup: () => void; } /** * Create a braille-character spinner that writes to a single rewritable line. * * The spinner renders frame + label via `process.stdout.write('\r\x1b[K…')` * at 80 ms intervals. Calling `stop()` clears the line. `cleanup()` is an * alias for `stop()` that also nullifies internal references. */ export declare function createSpinner(): Spinner; export interface StatusLineManager { setSpinner: (label: string | null) => void; setElapsed: (ms: number) => void; setAgents: (agents: AgentDisplayEntry[]) => void; addTool: (name: string) => void; removeTool: (name: string, status: 'done' | 'error', detail?: string) => void; render: () => void; clear: () => void; pause: () => void; resume: () => void; startElapsedTimer: () => void; stopElapsedTimer: () => void; reset: () => void; cleanup: () => void; } /** * Create a unified status line manager that composes spinner, elapsed time, * agent queue, and active tools into a single rewritable terminal line. * * Status line format example: * ⠋ AgentA is thinking... [0:12] | ▸ Read File ⟳ * * Supports pause/resume for readline prompt coordination: pause clears the * status line so `console.log()` or `rl.prompt()` output is clean, resume * redraws it. */ export declare function createStatusLineManager(): StatusLineManager; /** * Print permanent output while preserving the status line. * * Usage: `log(statusLine, 'Hello', someVar)` instead of `console.log(...)`. */ export declare function log(statusLine: StatusLineManager, ...args: unknown[]): void;