Skip to main content

Add a new CLI adapter

Status: Ready

Article ID: 050

Truth label: Current

Audience: Backend builder

Reader outcome: Implement and register a CLI backend with explicit invocation, permissions, parsing, usage, resume, and capability contracts.

Related articles: 034, 047, 109

Target week: 20

Last verified: 2026-09-13

Technical reviewer: Codex source audit

Editorial reviewer: Codex editorial audit

Implement the adapter contract​

Subclass CliAgentAdapter and define its stable name, binary, installation hint, whether it takes a system prompt, whether it can resume a session and which error markers mean the session is gone, whether it reports dollar cost, its effort levels, and which model names it owns. There is no turn-limit capability: agent turns are unlimited on every engine. Implement cli_version so the worker can probe and advertise the installed backend version during registration. Build argv from the normalized run spec, never from an unreviewed shell string.

Map authority explicitly​

Translate safe, write, and yolo into documented flags for the new CLI. If the CLI lacks an equivalent, state the gap and choose the least-authority behavior. Do not label a mode safe because its name sounds cautious.

Normalize the result​

Parse terminal success and failure from captured examples. Return summary, error, changed files, verification text, usage, cost only when reported, session id only when meaningful, and extra metadata. The shared executor automatically extracts the ## PR description section from the report text into run_metadata.pr_description for Cortex. Unknown output should fail closed with a bounded diagnostic.

Register and prove it​

Add the adapter to the backend registry so discovery and command-line choices update together. Test argv for every permission, parsing for success and failure, missing binary, malformed output, model filtering, usage, resume, and capability advertisement. Run a disposable end-to-end smoke test.

Current limits​

CLI contracts change across versions. Unit fixtures cannot prove login, keychain, network, or host-sandbox behavior. Live tests must use synthetic repositories and the full diff must be reviewed before production enablement.

Next lesson​

Continue with the reliability and state series.

Derivative map​

  • Weekly package: WEEK-20
  • Long video: VIDEO-W20-LONG
  • Shorts: SHORT-W20-PROBLEM, SHORT-W20-MECHANISM, SHORT-W20-WARNING
  • Email: EMAIL-W20
  • LinkedIn: LI-W20-A, LI-W20-B
  • X: X-W20-A, X-W20-B
  • Visual: VISUAL-W20

Review record​

  • Adapter interface, registry, permission, parsing, model, usage, cost, resume, and discovery contracts checked against current source.
  • Version, login, host, and live-test limits reviewed.
  • Test plan includes malformed and unsupported output paths.
  • Internal links and repository voice reviewed.

Review completed: 2026-09-03

Re-audited against the running product: 2026-09-13