ADR-007: CLI/API/UI Parity
- Status
- Context
- Decision
- Consequences
- Alternatives Considered
- Amendment 1 (2026-08-24, #1417): human-only authorization surfaces are a documented parity exception
- Amendment 2 (2026-09-17) — as built
- Amendment 3 (2026-09-17, #2154) — as built: CLI Architecture
- Amendment 4 (2026-10-12, #2883, ADR-049) — canopy-cli signs in with the device flow
- Amendment 5 (2026-11-15, #3384) — canopy-cli may carry offline file checks
- Amendment 6 (2026-11-24, #3399) — an operator’s tool is never an xtask verb; work below the API is canopy-manage’s
Status
Accepted — 2026-03-27; Amended — 2026-08-24 (Amendment 1: human-only authorization surfaces, #1417); 2026-09-17 (Amendment 2: as built — command tree, dependencies, container image; Amendment 3: as built — CLI Architecture, #2154)
Amended by ADR-049 (2026-09-30), effective 2026-10-12: Amendment 4 (canopy-cli on canopy-identity’s device flow; Amendment 1 retired). Amended 2026-11-15: Amendment 5 (offline file checks; what the CLI may not link, #3384).
Context
Canopy exposes three interaction surfaces: a REST API (consumed by program services and integrations), a worker portal UI (canopy-web), and an applicant portal UI (canopy-portal). Without a CLI, the only way to script operations, automate testing, or perform ad-hoc queries is by hand-crafting HTTP requests with curl and a Keycloak token.
OpenStack demonstrated that CLI/API/UI parity — where every operation available in one surface is available in all three — enables:
-
Scriptable automation — batch operations, data migration, CI/CD integration
-
Developer productivity — faster iteration than navigating a UI for every test
-
Operational parity — on-call staff can investigate and act without a browser
-
Incremental testability — CLI commands become the foundation for integration test scripts
-
Accessibility — screen reader users and keyboard-only operators get full access via the CLI
The OpenStack CLI (openstack) is the model: a thin client over the REST API using clap-style subcommands, profile-based configuration, and table/json output formatting.
Decision
Every operation exposed by any Canopy service’s REST API must also be available as a canopy CLI subcommand. The CLI is a first-class interface, not a convenience wrapper. New API endpoints ship with corresponding CLI commands in the same MR or the immediately following one.
CLI Architecture
-
Binary:
tools/canopy-cli/— a standalone Rust binary usingclapandreqwest -
Library crate:
tools/canopy-cli/src/lib.rsexportsCli,Commands, subcommand types,ApiClient,output, andconfigmodules so integration tests can drive the CLI programmatically -
API client:
ApiClientwrapsreqwest::Clientwith bearer token injection. All CLI commands call the REST API — no direct database access, no bypassing service boundaries -
Profile config:
~/.config/canopy/profiles.tomlstores named profiles with service URLs and Keycloak settings.--profileflag (default:default). Auto-created on first run. -
Auth:
canopy loginacquires a Keycloak token via ROPC grant and stores it in~/.config/canopy/tokens/.canopy token showdisplays the current token. All other commands auto-refresh expired tokens. -
Output:
--format table|json(global flag, defaulttable). Table output usestabledcrate. JSON output is raw API response for piping tojq. -
Shell completions:
canopy completion bash|zsh|fish|powershell
Command Structure
Commands mirror the API structure:
canopy login
canopy token show|refresh
canopy person create|list|get|update|delete
canopy household create|get|add-member|remove-member
canopy person add-income|add-asset|add-expense|add-address
canopy application create|list|get|update|withdraw
canopy application waive-interview|complete-interview
canopy rules list|get|create|update|delete|import|evaluate
canopy eligibility determine|get-determination|list-determinations
canopy snap evaluate
canopy tanf evaluate
canopy medicaid evaluate
canopy caps evaluate
canopy wic evaluate
canopy enrollment list|get
canopy renewal list|get|process
canopy notice list|get
canopy appeal file|list|get|schedule-hearing|record-decision
canopy report generate|list|export
canopy security events|alerts|nist-controls
canopy security chain-status|chain-verify|chain-attest
canopy completion bash|zsh|fish|powershell
The security chain- trio replaced the original security verify-chain
command when the chain surface was unified under /v1/security/chain/
(#1205, ADR-014 Amendment 9;
GET /v1/security/verify-chain is deleted): chain-status --family <audit|fti>
[--service <canopy-tanf|canopy-medicaid>] (exits non-zero on the fail-closed
503 arm), chain-verify --family … [--service …] [--loop <tail|scrub|family-full>]
[--wait] (202 job handle; --wait polls the job to done/error), and
chain-attest --event-id <uuid> --family … [--service …] (exits non-zero when
not attested). Both families are ACTIVE: the fti arguments
(--family fti --service canopy-{tanf,medicaid}) are served live since MR-3
of #1206 — the CLI forwards them unchanged (honest passthrough, per this
ADR’s thin-client rule), and a dormant fti target (until #1279) comes back as
the server’s typed 503, parsed and named by the same fail-closed exit path.
Parity Enforcement
-
Every plan that adds API endpoints must include a "CLI commands" section in its Steps listing the corresponding
canopysubcommands -
The
canopy-cliCargo.toml depends on no internal crates except via the HTTP API — it is a pure REST client -
Integration tests can use the CLI library crate to drive end-to-end scenarios
Consequences
-
Every service plan must account for CLI command additions — this increases scope slightly but ensures no operation is UI-only
-
The CLI binary ships in the Docker image alongside service binaries for operational use
-
The
tools/canopy-cli/directory grows incrementally as services are implemented — it is never "done" until all services are complete -
Shell completion support enables discoverability without documentation
Alternatives Considered
No CLI (rejected)
Rely on curl + API documentation. Rejected because scripting with curl requires managing tokens, constructing JSON payloads, and parsing responses manually — too slow for development and operations.
Amendment 1 (2026-08-24, #1417): human-only authorization surfaces are a documented parity exception
The post-C1 authorization model (ADR-043 §C, #1443) created a surface class parity cannot reach without weakening the fleet’s authorization controls: endpoints whose HUMAN arm accepts only an exchanged user-context bearer minted by an azp-allowlisted exchanger, and whose service arm is refused at an in-handler human projection. The first member is POST /v1/applications/{id}/documents/{document_id}/scan-override (#1006, #1443): the release must name its accountable human, so a bare service token 403s at the releasing_supervisor projection and a direct worker login — exactly what canopy login's ROPC grant produces (broad audience) — 403s at the receiver contract.
The canopy CLI holds exactly those two credential shapes, and MUST: making the CLI an authorized exchanger would add a user-context-minting client to every receiver’s authorized_exchanger_azps allowlist, widening the fleet’s most sensitive control for a scripting convenience.
Decision: such endpoints are documented CLI-unsupported, with the worker portal — whose canopy-web-exchanger is the audited, allowlisted minting path — as the sole human path. Members are enumerated here and noted in the CLI help of the nearest sibling command:
-
POST /v1/applications/{id}/documents/{document_id}/scan-override(sibling:canopy application document-rescan).
Revisiting this (e.g. a CLI device-flow client with its own exchanger azp) is a maintainer security decision to be taken deliberately, never a parity default.
Amendment 2 (2026-09-17) — as built
Status unchanged (still Accepted). This amendment records where the shipped CLI differs from the 2026-03 text above; the Decision and Consequences are not edited.
-
Command tree. The live command list is
canopy --help— theCommandenum intools/canopy-cli/src/main.rs, one module per command undertools/canopy-cli/src/cmd/. It differs from the §Command Structure tree in both directions:enrollment,appealandreportwere never built (no such command module exists), whiledocument,interview,verification,determine,income,asset,expenseandaddressexist and are not drawn. The parity gaps (appeals, reporting, enrollment) are not tracked by this ADR. -
Dependencies.
tools/canopy-cli/Cargo.tomldepends on the wire-contract cratescanopy-contracts-eligibility,canopy-contracts-persons,canopy-contracts-security,canopy-contracts-snapand oncanopy-common(the shared HTTP helper). No service, database or message-queue crate is a dependency, so the CLI still reaches services only over HTTP; the §Parity Enforcement sentence "depends on no internal crates" reads as-built as "depends on no crate that bypasses the HTTP boundary". -
Container image.
Dockerfilebuilds the workspace minuscanopy-portal(the CLI included) but its runtime stage copies only the service binaries andcanopy-seed; nocanopy-clibinary is copied. The Consequence "ships in the Docker image alongside service binaries" is therefore not as built. Whether the binary joins the image or is distributed separately is a maintainer decision outside this record. Erratum (2026-09-18, #2099): the runtime stage now copies thecanopybinary to/app/canopybeside the service binaries; the Consequence is as built.
Amendment 3 (2026-09-17, #2154) — as built: CLI Architecture
Status unchanged (still Accepted). Three §CLI Architecture claims above are not as built and Amendment 2 does not record them; this amendment does, and the Decision text is not edited.
-
Library exports.
tools/canopy-cli/Cargo.tomldeclares two targets, thecanopybinary (src/main.rs) and thecanopy_clilibrary (src/lib.rs), andlib.rsexports only theauth,client(ApiClient),cmd,configandoutputmodules. The clap tree is the binary’s:pub struct Cliistools/canopy-cli/src/main.rs:22, theCommandenum (there is noCommands) ismain.rs:36, and everyParser/Subcommandderive in the crate is inmain.rs— the library contributes only the flattenedcmd::person::DemographicArgsand theoutput::Formatvalue enum. No other crate can therefore nameCli, parse an argv or callCli::command(); the binary does so itself forcanopy completionand in its own#[cfg(test)]module. The §Parity Enforcement sentence holds one level down: integration tests drive the command layer function by function (canopy_cli::cmd::<module>::<command>(&ApiClient, Format), astests/cli_test.rsdoes), and a test of the command tree itself runs the built binary. -
Token refresh. Nothing refreshes a token.
auth::load_tokenreads~/.config/canopy/tokens/<profile>.jsonand deserialises it; every authenticated arm ofmainhands the storedaccess_tokentoApiClient::newas it is — or, for the nine crypto-shred commands (the four canopy-persons ones and the fivedetermination redacts), after the RFC 8693 audience exchange inauth::exchanged_client, which is minted from that same stored token — andApiClientsends it as the bearer on every request with no 401 handling.StoredToken::is_validis called only bycanopy token show(cmd/token.rs), which printsValid: yesorValid: EXPIRED;StoredToken.refresh_tokenis stored byparse_token_responseand read nowhere; the crate’s only token-endpoint calls areauth::loginandauth::login_service— reached only throughcanopy login user|service, the sole callers ofauth::store_token— andauth::exchange_for_audience, an exchange for an exact audience, not a renewal.TokenActionhas onlyShow: thecanopy token refreshof §Command Structure was never built. An expired token is sent as-is, the service’s refusal surfaces throughoutput::check_statusasHTTP <status>: <detail>, and the remedy is a freshcanopy login. -
Table output.
--format tableis tab-joined text, not thetabledcrate.output::print_listprints the column names joined by tabs, a dash rule per column and each row’s values joined by tabs;output::print_detailprints one right-alignedkey: valueline per field.tools/canopy-cli/Cargo.tomlhas notableddependency; the workspace pintabled = "0.17"in the rootCargo.toml[workspace.dependencies]has no consumer and noCargo.lockentry.
Building any of the three — the clap tree in the library so Cli::command() is testable in-process, a refresh-token grant before authenticated calls, a tabled renderer — is a separate maintainer decision outside this record.
Amendment 4 (2026-10-12, #2883, ADR-049) — canopy-cli signs in with the device flow
Status unchanged (still Accepted). ADR-049 D7 moves canopy-cli onto canopy-identity’s RFC 8628 device flow, and its plan I3g (SW12) wired it. The parity Decision stands. This amendment records how the CLI now authenticates, what it reaches, and what that does to Amendments 1–3. The Decision text is not edited.
-
Sign-in (§CLI Architecture’s Auth bullet).
canopy loginstarts a device flow at canopy-identity and prints a verification URI and a user code. A signed-in worker approves the code on canopy-web’s/devicepage under a step-up, and the CLI polls until the approval opens a native session (ADR-049 D7, Amendments 9 and 21). The session’s refresh credential is bound by DPoP to a device key, and both live in an owner-only store per profile,<config dir>/canopy/identity/<profile>(Amendment 23, O4).canopy logoutrevokes and removes the session.canopy token <SERVICE>prints one service’s token. -
Gone: the password grant,
canopy login service, the CLI-side RFC 8693 audience exchange,canopy token show, and the notice mark-read verb (#2805). -
Tokens. Every command sends through the profile’s device client (
tools/canopy-cli/src/session.rs). Each call’s token comes from a refresh grant for its target, which rotates the stored credential (Amendment 9, N6). The token is a delegation token naming the worker, withact[canopy-cli], one audience and at most 300 s of life. A receiver’s refusal of the bearer is re-minted and resent once (canopy_auth::send_with_retry). This retires Amendment 3’s "Nothing refreshes a token". -
Profiles. A profile in
profiles.tomlnames canopy-identity’s issuer identifier (identity_issuer) and an optionalca_file, beside the service URLs, and no Keycloak settings.devstackis a reserved profile, derived from the running devstack’s.ports.envon every run, and the global--devstackswitch is gone. -
Reach. canopy-cli is a native client in the compiled call graph, with delegation-only edges to 14 services: appeals, applications, caps, eligibility, medicaid, notices, persons, renewals, reporting, rules, security, snap, tanf and wic (
CANOPY_CLIincrates/canopy-auth/src/identity_policy/call_graph.rs). A route admits the CLI’s token when its admission’s user arm admits the worker’s roles, from any actor or through an arm listing canopy-cli. -
Amendment 1 retires. The scan-override route admits a supervisor’s or admin’s delegation from any actor (
services/canopy-applications/src/api/documents_scan.rs), canopy-cli’s included, so it is no longer a parity exception. Nocanopycommand calls it yet, which makes it a parity gap like Amendment 2’s, not an exception. -
Amendment 2’s gaps narrow.
canopy appealandcanopy ipvcover appeals' operator routes, andcanopy reportcovers reporting’s routes except the overpayment summary only canopy-web reads (#2886).enrollmentstill has no command.
Amendment 5 (2026-11-15, #3384) — canopy-cli may carry offline file checks
Status unchanged (still Accepted). The parity Decision stands: every API operation is a command, and a command reaches a service only over HTTP. This amendment admits a second kind of command and states what the CLI still may not link. The Decision text is not edited.
-
Offline file checks. canopy-cli may carry a command that only reads files the operator names: no token, no profile, no network and no database. It has no API operation or UI page to be at parity with, so it is outside §Parity Enforcement.
canopy config check <pack-dir> --federal <federal-dir>is the first: it runs the pack checks ofcanopy-pack-checkon a working copy of a configuration repository (Offline commands). Such a command runs before the session is opened (dispatch,tools/canopy-cli/src/main.rs), ascanopy completiondoes. -
What the CLI links. canopy-cli links no service crate (no package under
services/), norcanopy-db,canopy-mq, the AMQP clientlapinor the database driver (sqlx,sqlx-core,sqlx-postgres), directly or through another crate. A unit test,canopy_cli_links_no_database_message_queue_or_service_crate(tools/canopy-cli/src/dependency_boundary.rs), reads the crate's normal dependencies fromcargo tree -p canopy-cli, which resolves features for the CLI alone, and fails naming any such package. Throughcanopy-pack-checkthe CLI gainszen-engineandcanopy-zen-exact, which evaluate decisions in-process and open nothing. -
No sqlx. Since #3414 canopy-cli resolves and ships without sqlx: canopy-types and canopy-common carry it only behind a
sqlxfeature the CLI does not enable, and the test above refuses it. Cargo unifies features across the packages of one build, so the shippedcanopyis built in a cargo invocation of its own (cargo build -p canopy-cli --bin canopy --target-dir target/car-cli, on the car, in the release job and incargo xtask dev start), and the staging step refuses acanopywhose symbols namesqlx_coreorsqlx_postgres(xtask/src/devstack_binaries/build.rs). Amendment 2's "No service, database or message-queue crate is a dependency" reads, as built, as the list above. -
Not here. A job that needs a direct database connection or key material belongs to a separate
canopy-admin(#3399), not to canopy-cli, by the maintainer's ruling of 2026-11-14.
Amendment 6 (2026-11-24, #3399) — an operator’s tool is never an xtask verb; work below the API is canopy-manage’s
Status unchanged (still Accepted). Amendment 5’s last bullet names the tool for direct-database and key-material jobs canopy-admin. By the maintainer's ruling of 2026-11-24 it is canopy-manage, matching the sibling project's craig-manage; that bullet is otherwise unchanged.
-
Three tools, three users.
cargo xtaskis the developer's task runner: it needs a checkout and a toolchain, has no release version and links test fixtures. It carries nothing an operator runs against a deployment. Work that goes through a service's API is canopy-cli's. Work below the API, on a database or on key material, is canopy-manage's (tools/canopy-manage; canopy-manage Reference). -
No default target. A canopy-manage job is told where to write or what to connect to, and refuses to start otherwise. Nothing in it reads a devstack's files.
-
Released with the services. The binary ships in the service image at the services' version. It links no test library and no service crate; a unit test,
canopy_manage_links_no_test_library_and_no_service(tools/canopy-manage/src/dependency_boundary.rs), reads its resolved dependencies and refuses either. -
No alias. A verb that moves leaves xtask in the change that moves it. A unit test in xtask,
every_xtask_command_a_page_names_exists, fails when a page outsideplans/andadrs/names acargo xtaskcommand xtask does not have. -
As built. canopy-manage carries
gen-signing-keys,migrate apply,rewrap-keksandidentity check, moved from xtask, andgen-client-key, new. A second xtask test,no_operator_page_sends_an_operator_to_xtask, holds the operator pages: an xtask command one of them names must be on a list of developer verbs, each with its reason, and by sub-verb where only some of a verb's are a developer's.