import { type Observable } from 'rxjs'; import type { ReplEvent, ReplSession } from '../session.js'; export type ConnectionState = { type: 'connecting'; message?: string; } | { type: 'negotiating'; message?: string; } | { type: 'reconnecting'; message?: string; } | { type: 'ready'; chip: string | null; deviceId: string | null; firmwareVersion: string | null; } | { type: 'error'; message: string; } | { type: 'fallback'; }; /** Structured event entries accumulated by the state machine. */ export type ReplLogEvent = ReplEvent | { type: 'connecting'; port?: string; } | { type: 'restarting'; } | { type: 'input'; code: string; }; export interface ReplMachineState { connection: ConnectionState; port?: string; input: string; cursor: number; history: string[]; historyIdx: number; historyDraft: string | null; showWelcome: boolean; evaluating: boolean; /** Whether eval timing is shown on result lines. Host-side toggle (`/time`); * the device always reports timing, the CLI decides whether to render it. */ showTiming: boolean; paused: boolean; ctrlCPending: boolean; returnPending: boolean; disabled: boolean; deployStatus: string | null; /** Sticky error message for the REPL footer (e.g. "Hook failed: tsc * --noEmit (exit 2)"). Cleared when the next deploy cycle starts. */ footerError: string | null; overrideHint: string | null; contextHint: string | null; pendingTiming: string | null; overlay: null | 'env'; events: ReplLogEvent[]; } export type KeyInfo = { ctrl: boolean; meta: boolean; shift: boolean; return: boolean; tab: boolean; backspace: boolean; delete: boolean; leftArrow: boolean; rightArrow: boolean; upArrow: boolean; downArrow: boolean; home: boolean; end: boolean; }; export type ReplAction = { type: 'key'; ch: string; key: KeyInfo; } | { type: 'deviceEvent'; event: ReplEvent; } | { type: 'setDisabled'; disabled: boolean; } | { type: 'setDeployStatus'; message: string | null; } | { type: 'setError'; message: string; suppressLogEntry?: boolean; } | { type: 'setFooterError'; message: string | null; } | { type: 'ctrlCTimeout'; } | { type: 'returnResolve'; } | { type: 'closeOverlay'; }; export type ReplEffect = { type: 'eval'; code: string; } | { type: 'directive'; code: string; } | { type: 'setAlias'; name: string; } | { type: 'unsetAlias'; } | { type: 'exit'; } | { type: 'restart'; } | { type: 'end'; } | { type: 'deploy'; force: boolean; } | { type: 'appendHistory'; entry: string; } | { type: 'scheduleCtrlCTimeout'; } | { type: 'scheduleReturnResolve'; multiline: boolean; }; export declare const WELCOME_HINT = "Enter to submit | Ctrl+D to exit | Ctrl+C to clear | /help for commands"; export declare const MULTILINE_HINT = "Ctrl+Enter to submit | Enter to add line"; /** Find the line index and column for a cursor position in text */ export declare function cursorLocation(text: string, cursor: number): { line: number; col: number; lineCount: number; }; /** Get the start offset of a given line index */ export declare function lineStartOffset(text: string, lineIdx: number): number; export declare function loadHistory(): string[]; export declare function appendHistory(entry: string): void; export declare function createInitialState(port?: string, history?: string[]): ReplMachineState; export declare function reduce(state: ReplMachineState, action: ReplAction): [ReplMachineState, ReplEffect[]]; export interface ReplHandle { state$: Observable; deploys$: Observable<{ force: boolean; }>; keyInput(ch: string, key: KeyInfo): void; setDisabled(disabled: boolean): void; setDeployStatus(message: string | null): void; setError(message: string, opts?: { suppressLogEntry?: boolean; }): void; /** Pin an error message in the REPL footer until the next cycle * starts. Use alongside `logEvent({type:'error', …})` for errors * that should remain visible after the output scrolls past. */ setFooterError(message: string | null): void; /** Append an entry to the REPL log pane without touching connection * state. Use for CLI-originated output (e.g. predeploy hook stdout/ * stderr) that must survive Ink's patched stdout/stderr. */ logEvent(event: ReplLogEvent): void; closeOverlay(): void; } export declare function createRepl(options: { session: ReplSession; port?: string; onEnd: () => void; /** Connection timeout in ms (default: 15000) */ timeout?: number; loadHistory?: () => string[]; saveHistory?: (entry: string) => void; /** When false, Ctrl+S does nothing (deploy isn't meaningful in this * context, e.g. `mikro console`). Defaults to true. */ deployEnabled?: boolean; }): ReplHandle; //# sourceMappingURL=replStateMachine.d.ts.map