#!/usr/bin/env node import type { Writable } from 'node:stream'; type Parsed = { positional: string[]; flags: Map>; }; /** * Where a run's output goes. * * The bin writes to the real streams; a host that mounts this CLI (see * `relay-cli.ts`) supplies its own sink. Nothing below `runCli` touches * `process.stdout`/`process.stderr` directly, so the same dispatch serves both. */ export interface CliIo { stdout(chunk: string): void; stderr(chunk: string): void; } export declare const BOOLEAN_FLAGS: Set; export declare const VALUE_FLAGS: Set; export declare function humanLine(value: unknown): string; export declare function output(io: CliIo, value: unknown, json: boolean): void; /** One positional argument, as the mounted help renders it. */ export interface CommandArgSpec { name: string; description: string; required: boolean; variadic?: boolean; } export interface CommandSpec { /** Name used in flag- and argument-rejection messages. */ name: string; /** * One line for the mounted help. * * A host renders its own help from this table rather than forwarding * `--help`, so an empty description is a user-visible hole, not an internal * detail. */ description: string; /** * Path under the mounted group, or `null` for a command the group does not * expose. `['sessions', 'list']` here is `ai-hist sessions list`, reached as * `agent-relay sessions list`. */ surface: readonly string[] | null; /** Extra spellings the mounted group accepts for `surface`. */ surfaceAliases?: readonly string[]; /** * The positionals named for help. `positionals` below stays the authority on * how many are accepted; the drift test asserts the two agree. */ args?: readonly CommandArgSpec[]; allowed: readonly string[]; /** Positional arguments after the command words: [minimum, maximum]. */ positionals: readonly [number, number | null]; /** Named in the usage error when fewer than the minimum are given. */ requires?: string; /** Answers from the local database, so it takes the shared first-use bootstrap. */ readsLocalStore?: boolean; /** Addresses a session by identity; --local/--remote/--all are meaningless. */ rejectsScope?: boolean; /** Remaining command-line checks, run before any store work. */ validate?: (args: Parsed) => void; /** * Reads `RunCliOptions.signal`, so the bin claims the process's signals for * it. Left off, the bin leaves `SIGINT`/`SIGTERM` at their default: a * listener suppresses Node's own termination, so claiming them for a command * that never looks at the signal swallows the user's first Ctrl-C. */ cancellable?: true; } /** * Every option a command may list in `allowed`, spelled the way help shows it. * * This is the only place a flag's user-facing text lives. The drift test * asserts it covers exactly the flags the command table allows, and that each * one's arity matches `BOOLEAN_FLAGS`/`VALUE_FLAGS` — so a flag that `parse` * cannot accept can never reach the mounted help. */ export declare const FLAG_SPECS: Record; /** Options the host owns, so they never reach a mounted command's help. */ export declare const HOST_OWNED_FLAGS: Set; export declare const COMMANDS: Map; /** * Whether this command line routes to a command that reads the cancellation * signal. * * The bin asks before installing a `SIGINT`/`SIGTERM` handler. A listener * replaces Node's default termination, so a handler on an invocation that * never reads the signal swallows the first shutdown request: the user presses * Ctrl-C, nothing happens, and they press it again. Resolved from the same * `COMMANDS` table `dispatch` resolves against, so the two cannot disagree * about which commands those are. */ export declare function usesCancellation(argv: readonly string[]): boolean; /** Knobs the bin owns and a mounted host does not. */ export interface RunCliOptions { /** * Cancels a command whose spec is `cancellable`. * * The signal handlers that produce it belong to whoever owns the process: * the bin installs them, a host passes its own, and `dispatch` installs none. */ signal?: AbortSignal; /** Check npm for a newer release on `--version`. The bin only. */ updateNotice?: boolean; /** Colourize `sessions list --pretty`. Defaults to stdout being a TTY. */ color?: boolean; /** * Where `export` writes when no `--out` is given. * * NDJSON export is unbounded, so it needs a real stream with backpressure * rather than the unbuffered `io.stdout` callback. */ stdoutStream?: Writable; } /** * Run one `ai-hist` command line and resolve to its exit code. * * Never calls `process.exit`, never writes to `process.stdout`/`process.stderr` * and never installs a signal handler: the caller owns all three. `argv` is the * arguments after the program name. A schema migration the command runs is * announced on `io.stderr`; the first call registers the process's one native * migration listener for that (see `onStoreMigration`). */ export declare function runCli(argv: readonly string[], io: CliIo, options?: RunCliOptions): Promise; export {}; //# sourceMappingURL=cli.d.ts.map