| title | CLI contract |
|---|---|
| description | Stable command parsing, exit codes, JSON success envelopes, and JSON error behavior for the current CLI. |
This document describes the stable CLI contract for agentplane command parsing, success output, and error behavior.
Scope: global flags, parsing rules, exit codes, JSON success envelopes, and JSON error output.
agentplane [global-flags] <command> [args/options]
Supported global flags:
--root <path>: resolve project from an explicit root.--json-errors: print machine-readable errors.--allow-network: allow optional network actions that would otherwise be skipped by approval policy.--no-update-check: skip update check call.--help,-h,--version,-v.
Scoped global flags (--json-errors, --allow-network) are recognized only before the command id. For example:
agentplane --json-errors task list ...enables JSON error output.agentplane help --jsonemits JSON help output and does not enable JSON error mode.agentplane task list --json-errorstreats--json-errorsas a command flag candidate, not global mode.
The agentplane CLI requires Node.js 24 or newer. The separately published library packages retain
their wider runtime contracts: @agentplaneorg/core requires Node.js 20.5.0 or newer, and
@agentplaneorg/recipes requires Node.js 20 or newer.
CI builds and packs both library artifacts on Node.js 24, then installs and exercises every public export from those tarballs on both the declared minimum runtime and Node.js 24. Package manifests remain the source of truth for the engine ranges.
The CLI uses stable exit codes for success and every classified failure family. The exhaustive code list and error-code mapping are generated from runtime metadata in the CLI reference. Do not maintain a second handwritten mapping in documentation.
When --json-errors is provided and a command fails, the CLI prints one JSON object to stdout:
{
"error": {
"code": "E_USAGE",
"message": "Missing required argument: --root",
"context": {
"command": "init",
"args": ["--yes"]
}
}
}Rules:
- JSON errors are written to stdout; human-readable diagnostics go to stderr only when
--json-errorsis not set. error.codeis a stable string enum; the exhaustive enum and exit-code mapping are generated in the CLI reference.contextis optional and must not include secrets.- State, remediation, next-action, and reason-decoding fields are optional and omitted when unavailable.
- Field names, nesting, and casing are exact. The generated JSON error envelope reference is canonical.
When --output json is provided and a command succeeds, the CLI emits one stable envelope to stdout:
{
"schema_version": 1,
"mode": "agent_json_v1",
"command": "config show",
"ok": true,
"exit_code": 0,
"stdout": "{\n \"workflow_mode\": \"branch_pr\"\n}",
"stderr": "",
"data": {
"workflow_mode": "branch_pr"
}
}Rules:
- The exact top-level key order is stable:
schema_version,mode,command,ok,exit_code,stdout,stderr, then optionaldata. schema_versionis currently1;modeis currentlyagent_json_v1.commandis the canonical command id selected by the dispatcher, for examplehelp,config show, ortask list.stdoutandstderrpreserve the trimmed text output produced by the command.datais included only whenstdoutis itself valid JSON; when present, it must equalJSON.parse(stdout).- Text commands such as
task list,task search, andtask nexttherefore omitdataand keep only the text instdout. --output jsonalso enables the same machine-readable failure path as--json-errors; theagent_json_v1envelope is the success contract, not the error contract.
Human-facing command output should use createCliEmitter() from packages/agentplane/src/cli/output.ts instead of ad-hoc local render helpers.
Conventions:
- Use
line()/lines()for plain text output. - Use
json()for standalone pretty JSON payloads. - Use
jsonSection()for labeled pretty JSON blocks such as scenario metadata sections. - Use
report()for labeled scalar/status blocks. - Use
success(),info(), andwarn()for framed status messages instead of reformatting emoji/status strings locally. - Treat low-level render plumbing inside
cli/output.tsas internal implementation detail; command modules should depend on the emitter surface, not on helper internals.
Command definitions are registered in packages/agentplane/src/cli/run-cli/command-catalog.ts.
The catalog keeps command specs lightweight and loads command runtime handlers lazily.
This split keeps agentplane help fast and reduces accidental startup cost from heavy imports.
agentplane quickstartandagentplane role <ROLE>are generated frompackages/agentplane/src/cli/command-guide.ts.- The docs-site startup path lives in
docs/start/quickstart.mdx. - Installed runtime surfaces must stay self-contained and must not require repo-only docs files to exist locally.
agentplane role <ROLE>renders one unified surface:- installed
.agentplane/agents/<ROLE>.jsonrole/profile content when available
- installed
- plus built-in CLI/runtime supplements for that role
- For unknown role requests, CLI prints known built-in roles and discovered project role ids.
agentplane help --compactis a human output convenience, not a machine schema.agentplane help --jsonis machine-readable help output.--json-errorsis for failed command output only.--output jsonpreserves text output insidestdout; consumers must not assumedataexists for text commands.- Command descriptions and examples may change, but option names, required flags, error shapes, and exit code mapping are treated as stable contract surface.
- Parser and global flags:
packages/agentplane/src/cli/run-cli.ts
- Error codes and JSON error envelope metadata:
packages/agentplane/src/shared/errors.ts
- Exit-code metadata and error mapping:
packages/agentplane/src/cli/exit-codes.ts
- Generated runtime and command reference renderer:
packages/agentplane/src/cli/spec/docs-render.ts
- Help/role guide text:
packages/agentplane/src/cli/command-guide.ts
- Startup guide source:
packages/agentplane/src/cli/command-guide.ts
- Command catalog:
packages/agentplane/src/cli/run-cli/command-catalog.ts
- Agent Change Record command group:
packages/agentplane/src/commands/acr/acr.command.ts
For command-level help JSON schema details, see CLI help JSON contract.