Read this before you add or change a command in packages/cli.
Coding agents and CI run this CLI far more often than people do, with no
terminal and nobody to answer a question. Every command follows these rules,
and src/cli.agentMode.test.ts runs every registered command the way an agent
does to hold them.
- Stdout is data, stderr is messages. Results go to stdout. Progress, warnings, notices and errors go to stderr.
- Never prompt without a person.
isUnattended()insrc/utils/attendedTerminal.tsis true without a TTY, under CI, inside a coding agent, or withHYPERFRAMES_AGENT=1. Import prompts and spinners fromsrc/ui/prompts.ts, never from@clack/prompts(lint enforces it): its prompts refuse to ask when unattended. A command that needs a confirmation takes--yesand callsconfirmationRequired()when it is missing. - Exit codes. 0 success, 1 the command ran and failed, 2 the command line
is wrong. Throw
CliUsageErrorfor a usage error; it exits 2. --jsonalways returns an envelope. A command supports--jsonby declaring ajsonarg; every other command rejects the flag with exit 2. On failure, stdout is{"ok": false, "error": {"code", "message", "hint"?}}. Build it withjsonFailure()fromsrc/utils/jsonError.ts. If a failing--jsonrun printed nothing,cli.tswrites the envelope for it.- Define commands with
defineCommandfromsrc/utils/defineCommand.tsand register them incommandLoadersinsrc/cli.ts. The contract test picks up a new command from there, with no change to the test.