aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
72 lines • 3.48 kB
TypeScript
/**
* Shared interactive-prompt utilities.
*
* Every readline-based prompt in the CLI MUST go through these helpers so
* the CLI can never hang indefinitely on a detached or unresponsive terminal.
* All helpers apply a hard timeout (default 60s, overridable via
* AIWG_PROMPT_TIMEOUT_MS) after which the prompt resolves to the supplied
* fallback and a visible warning is emitted.
*
* The underlying setTimeout is `.unref()`'d so a user pressing Ctrl-C mid-prompt
* does not keep the event loop alive for the remaining wait window.
*
* Phase 1 of the CLI Stabilization Epic (#918). Phase 3 (#920) will migrate
* these helpers to @clack/prompts with AbortSignal support; this file is the
* interim abstraction that makes both call-site cleanup and that future
* migration mechanical.
*/
import readline from 'readline';
/**
* Resolve the prompt timeout from env. Falsy / non-numeric / non-positive
* values fall back to 60 seconds.
*/
export declare function promptTimeoutMs(): number;
/**
* Create a readline interface bound to process stdio. Callers must always
* `rl.close()` when done.
*/
export declare function createPromptInterface(): readline.Interface;
/**
* Ask a single question with a hard timeout. On timeout, resolves to `fallback`
* and emits a warn-level UI message describing what default was used.
*
* The timeout timer is `.unref()`'d so the event loop can exit cleanly when
* the caller closes the readline interface (e.g. on Ctrl-C).
*
* Do NOT call this from multiple sites on the same readline interface
* concurrently — each readline interface should own exactly one in-flight
* prompt at a time.
*/
export declare function askWithTimeout<T>(rl: readline.Interface, prompt: string, parse: (answer: string) => T, fallback: T, fallbackLabel: string, timeoutMs?: number, signal?: AbortSignal): Promise<T>;
/**
* Prompt for a trimmed string with timeout and default. Honors `signal` from
* the HandlerContext (Phase 3 #920) so Ctrl-C cancels the prompt cleanly.
*/
export declare function askString(rl: readline.Interface, prompt: string, fallback?: string, signal?: AbortSignal): Promise<string>;
/**
* Prompt for a yes/no answer with timeout and default. Answers starting with
* 'y' (case-insensitive) are considered yes; everything else is no. On
* timeout, returns `defaultValue`.
*/
export declare function askYesNo(rl: readline.Interface, question: string, defaultValue?: boolean, signal?: AbortSignal): Promise<boolean>;
/**
* Prompt for a numeric selection from a list. Returns the selected item, or
* `fallback` on timeout / invalid input. If `fallback` is undefined, returns
* `options[0]`.
*/
export declare function askChoice<T>(rl: readline.Interface, prompt: string, options: T[], fallback?: T, signal?: AbortSignal): Promise<T>;
/**
* Prompt for a labeled selection from a list of options. Renders each option
* as a numbered line before asking. Users can respond by number (1-based) or
* by matching the exact `label`. On timeout or invalid input, returns
* `fallback`.
*
* This replaces the hand-rolled number-or-name logic sprinkled across
* `init.ts` (provider selection) and `use.ts` (topology profile picker).
* POC for the prompt-library spike (#926).
*/
export declare function listSelect<T>(rl: readline.Interface, prompt: string, options: readonly {
label: string;
value: T;
}[], fallback: T, signal?: AbortSignal): Promise<T>;
//# sourceMappingURL=prompt-utils.d.ts.map