mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
4f5a87b6b3
Move the vocabulary that both the CLI and commands read but no command's runtime depends on into the package below both: flag types, registry, groups and the four flag-definitions files, command-text, and cli-command-aliases. These are pure moves; only their import specifiers change. No compat re-export at the old paths — every consumer switches to the owning subpath. The per-command defaults stay where they are for now (the daemon's edge into the facet resolver is the harder cut and belongs with the daemon-closure work). Part of #2545 / #2543.
4.1 KiB
4.1 KiB
Adding a CLI Flag
Thread a flag only through the layers that consume it:
packages/contracts/src/cli-flags.ts: add toCliFlags; add the definition to the matchingpackages/command-registry/src/flag-definitions-*.tsowner and the relevant group inpackages/command-registry/src/flag-groups.ts(for exampleSNAPSHOT_FLAGS). Then update the command family metadata/schema that exposes the flag; find the owner withrg -n "<command>|supportedFlags|allowedFlags" src/commands src/cli-schema src/cli/parser. For schema-only CLI commands, the owner isSCHEMA_ONLY_CLI_COMMAND_SCHEMASinsrc/cli-schema/command-overrides.ts. Every flag declaration statesprojectConfig(may be set from a projectagent-device.json) andrecorded(the session recorder copies it intoSessionAction.flags). Both are required, so a new declaration that omits either does not compile — that, not an allowlist, is the completeness gate. SetprojectConfig: trueonly when repository control is safe; a new flag is otherwise operator-only. Setrecorded: trueonly when a.adrecording must carry the flag.src/commands/cli-grammar/*: read the CLI flag into command input.src/commands/command-projection.tsand command-family projection helpers: write the input into the daemon request only if the flag affects daemon execution.src/commands/*-command-contracts.ts: add to the command input schema only if the option should be available through Node.js or MCP as structured input. An input key that names a credential, an endpoint a credential is sent to, or operator infrastructure declaresoperatorField(...)(src/commands/command-input.ts), which is what keeps the MCP and AI SDK tool schemas from offering the model a parameter to write it into. One of the shared common keys declares the same audience in itssrc/commands/common-input-fields.tsrow instead.src/client/client-types.ts: update the public typed client option only when the Node.js interface exposes it.src/client/client-normalizers.ts: update daemon flag normalization only when the request still needs a public-to-internal translation.src/daemon/context.tsandsrc/core/dispatch-context.ts: add the field only when it flows into platform dispatch.- Handler/platform modules: thread the option only after the command surface, grammar, and projection prove it belongs there.
scripts/integration-progress-model.ts: classify the flag (device-observable vs intentionally-outside). The architecture-progress gate fails CI on unclassified public flags.- If the flag changes interaction semantics, revisit the affected cells in
packages/contracts/src/interaction-guarantees.ts(scope withappliesTowhen the flag exists only on some commands).
Command-only flags (like find --first) that never reach the platform layer usually stop at
steps 1-3, plus step 9.
Where CLI help and schema live
- Long help prose:
src/cli-schema/cli-help.ts. Flag definitions:src/commands/cli-grammar/. - Synopsis:
src/cli-schema/usage.tsgenerates the[label]flag tail fromallowedFlags, so a new option reaches--helpwithout any synopsis edit. DeclareusageFlagson the command only when its synopsis names fewer options:[]for a synopsis that is pure grammar (or writes its own mutually-exclusive brackets), otherwise the subset it names.Command flags:always lists everything inallowedFlags. Keep a cross-cutting opt-in out of every synopsis withusageHidden: trueon its flag definition.src/cli-schema/usage.test.tsfails a tail that names an option the command does not accept, or one the hand-written grammar already wrote. - Command-specific usage/flag metadata lives with the command family metadata that owns the command.
- Parser/help rendering stays in
src/cli/parser/; command schema metadata is derived from command metadata, family declarations, and the schema-only merge path insrc/cli-schema/command-overrides.ts. Keep the two separate. - Locating an owner:
rg -n "helpDescription|summary|supportedFlags|allowedFlags" src/commands src/cli/parser src/cli-schema.