/** * CLI router for the harness CLI substrate (Phase 40 / PH40-01 + PH40-02). * * This module owns argv parsing and command dispatch for the * `bin/hivemind-tools.cjs` entrypoint. It is deliberately framework-free * (no commander / yargs / oclif) so that: * - The CLI substrate stays small and reviewable (well under the 500 LOC * project ceiling). * - There is no transitive dependency we need to security-audit for the * harness's bin surface. * - The same router can be unit-tested without spawning a subprocess. * * The router exposes three primitives: * - {@link parseArgs} — argv → `{ command, flags, positionals }` * - {@link createRouter} — build a registry from `CliCommand[]` * - `Router.run(argv)` — dispatch to the matching command * * Exit codes follow the BSD `sysexits.h` convention used by most CLIs: * - `0` — success * - `64` — usage error (`EX_USAGE`) — unknown command, missing command * - `70` — software error (`EX_SOFTWARE`) — handler threw * * Errors raised inside this module always carry the `[Hivemind]` prefix * required by `AGENTS.md`. */ export type CliFlagValue = string | boolean; export type CliCommandContext = { /** Parsed `--flag` / `--flag=value` map. Bare flags become `true`. */ flags: Record; /** Positional arguments after the command name. */ positionals: readonly string[]; /** The argv slice that produced this context, for diagnostic logging. */ argv: readonly string[]; }; export type CliRouterResult = { exitCode: number; error?: string; output?: string; }; export type CliCommand = { name: string; summary: string; aliases?: readonly string[]; handler: (ctx: CliCommandContext) => Promise; }; export type CliRouterOptions = { commands: readonly CliCommand[]; }; export type CliRouter = { /** Dispatch the given argv (without `node` / script name) to a command. */ run: (argv: readonly string[]) => Promise; /** Inspect the registered commands in registration order (read-only copy). */ commands: () => readonly CliCommand[]; }; export type ParsedArgs = { command: string; flags: Record; positionals: string[]; }; /** * Parse a raw argv tail (everything after `node bin/hivemind-tools.cjs`) * into a `{ command, flags, positionals }` triple. * * Supported forms: * - `cmd` — bare command, no args * - `cmd --flag` — boolean flag (set to `true`) * - `cmd --flag value` — string flag * - `cmd --flag=value` — string flag (single-token form) * - `cmd pos1 pos2` — positional arguments */ export declare function parseArgs(argv: readonly string[]): ParsedArgs; /** * Build a router from a list of `CliCommand` entries. Throws `[Hivemind]` * errors at construction time for duplicate command names or aliases that * collide with a different command's name. */ export declare function createRouter(options: CliRouterOptions): CliRouter; //# sourceMappingURL=router.d.ts.map