mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
99967c7f01
* fix: restrict project config trust * fix: preserve daemon auth transport context * refactor: simplify project config trust * fix: restrict project config write sinks
3.0 KiB
3.0 KiB
Adding a CLI Flag
A new flag touches only the layers that need to understand it. Stop at the layer where it stops mattering — threading it further is the common failure, not stopping too early.
packages/contracts/src/cli-flags.ts: add toCliFlags; add the definition to the matchingsrc/commands/cli-grammar/flag-definitions-*.tsowner and the relevant group inflag-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 (cdp,auth,connect,proxy,react-devtools,web) the owner isSCHEMA_ONLY_CLI_COMMAND_SCHEMASinsrc/cli-schema/command-overrides.ts. New flags are operator-only by default. Add a flag toPROJECT_CONFIG_FLAG_KEYSinsrc/cli-schema/cli-config.tsonly when repository control is safe; this positive allowlist is the completeness gate.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.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/parser/cli-help.ts. Flag definitions:src/commands/cli-grammar/. - 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.