Repository navigation
fix(cli): protect Amp settings during default registration - #8076
Conversation
[Medium impact] The reviewed diff appears safe to merge; no blocking defect was established. SummaryExtends Amp settings protection to default
No actionable new defect or security issue was established. Tests were not run during this review. GitHub access required authentication, so whether another PR supersedes this one could not be independently checked. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Normalize arguments] --> B[Separate builtin and timing flags]
B --> C{Registration includes Amp?}
C -->|No| D[Dispatch normally]
C -->|Yes| E[Read and check Amp settings]
E --> F{Settings and backup acceptable?}
F -->|No| G[Report error before registration]
F -->|Yes| H[Keep recovery backup]
H --> I[Run registration]
I --> J{Reported failure?}
J -->|Yes| K[Keep original failure]
J -->|No| L[Verify registration and restore saved environment]
Reviews (1) · Last reviewed commit: "fix(cli): protect Amp settings during de..." · Reviewed by Greptile |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
🔵 Needs a closer look
Key correctness factors—the pinned Incur 0.6.1 arg-parsing semantics, cloud-only combined test coverage, and still-pending merge conflict resolution with #8069/#8071—could not be verified in this diff and require retesting before a confident sign-off.
No open issues 🎉
What changed in this PR
This PR extends REA's existing Amp MCP-registration guard (from #7995) to cover the default rea mcp add path — i.e., invocations with no explicit --agent, where Incur still writes the Amp settings.json. Previously that path bypassed REA's preservation/backup/validation wrapper, so an existing rea.env map could be dropped or invalid settings could reach the external package runner before any failure was reported. It fits into the CLI/Incur boundary layer, where REA must mirror Incur's argument parsing so its guards and Incur's actual dispatch agree.
Changes:
- Compute selected agents from the same normalized tokens handed to Incur (consuming
--command/-cvalues before--agentselectors), and apply the Amp guard when no agents or Amp is selected, while excluding discovery/mode switches (--help,-h,--llms,--llms-full,--mcp,--update,--incur-update-check). - Add a second pass to
splitIncurBuiltinArgumentsthat strips boolean timing globals (--timings,--no-timings,--timings=…) until--, so timing-shaped flags can't hide themcp addselection while timing-shaped output values remain data. - Track a failed registration exit in
runRegistrationso post-registration Amp verification doesn't overwrite the original runner failure, and reuse the expanded (equals-normalized) arguments for both selection and dispatch.
| File | Description |
|---|---|
src/cli.ts |
Derives selected agents from normalized tokens, broadens the Amp guard to the default path, reuses expanded args for dispatch, and tracks runner-failure exit to suppress a spurious post-verify diagnostic. |
src/cliBuiltinArguments.ts |
Adds a second splitter pass extracting boolean timing globals until --, keeping --timings out of the first builtin pass; comment updated accordingly. |
tests/boundary/cli/defaultAmpRegistration.test.ts |
New boundary suite covering default-path preservation/backups in both output modes, invalid-settings/unavailable-backup rejection, non-Amp/discovery no-touch, runner failure, timing-global bypass attempts, and a direct splitter-vs-Incur parity check. |
Note: Per the PR's own description, the merge-time conflict resolution with #8069/#8071 over the shared wrapper/splitter is not included in this independent diff and must be re-applied and retested at merge; combined verification was performed in the cloud rather than locally.
Review effort: Balanced
Summary
Extend the existing Amp configuration guard to default
rea mcp addregistration. Without an explicit agent selector, Incur also writes Amp, but REA currently bypasses its preservation/backup/validation wrapper. An existingrea.envcan consequently be dropped, or invalid settings can reach the external runner before failure is reported.This is a follow-up to merged #7995 and the configuration guarantees discussed in #7536/#7538, not a duplicate of its explicit-Amp path. #7979 addresses the separate project-scope contract; #1732 changes setup-owned client registration.
Problem and expected behavior
Given an existing Amp entry with
env: { KEEP_ME: "1" },rea mcp add --command 'fixture-server --mcp'should retain that environment and peer/settings fields, preserve the original backup and later recovery copies, and report the applicable backup on stderr. Invalid settings or an unavailable backup must fail before any package runner invocation. A runner failure must retain its failure status rather than produce a second Amp post-verification diagnostic.Change and scope
Determine selected agents from the same normalized command tokens passed to Incur, consuming command values before agent selectors. Apply the existing Amp guard when no agents are selected or Amp is selected. Forward normalized equals forms consistently, and avoid configuration access for the checked discovery/mode paths. Track a failed registration exit so post-registration verification does not replace the original failure.
The shared builtin splitter mirrors Incur's two passes: first builtin output options, then boolean timing globals until
--. This keeps timing-shaped output values as data while preventing actual timing globals from hiding the Amp selection.Integration with #8069 and #8071
This branch is based independently on main
317bf3fe235e655b2d752d3be261cc0da7d00f2b; it does not include either PR. The fixes are functionally different but are not conflict-free:commandIndiceswith the tokens retained by this two-stage timing pass.registrationFailed || failed, so neither JSON producer failure nor an exit reported through the wrapper reaches success verification/flushing.The cloud integration exercise resolved these interactions and passed the tests reported below. Those conflict resolutions are not included in this independent diff and must be applied and retested at merge time. This PR does not claim to fix every existing parser/binding or discovery-mode issue by itself.
Contract and boundary impact
Evidence and regression coverage
Development, reproduction and independent review were completed in the cloud before local publication. The handoff reports 11 standalone tests passed; a related run passed 29 with 1 skipped; and a conflict-resolved combination with #8069
da89517and #8071414f394passed 41 tests, including six expanded-discovery no-side-effect cases. These are reported cloud results, not Mac reruns. The exact transferred patch matched SHA-2562a97eb07e32ce2f34347d8cb9cb1b3981fdaeb0b287e835d61dac955b44c66e5; all three resulting file hashes matched the handoff.The new suite covers repeated default registration in ordinary/JSON output, saved environment/peer fields, secure recovery backups, malformed settings and occupied backup paths, non-Amp selectors and command values, runner failures, timing-global forms, output-value/terminator parsing, ordinary discovery and expanded help/LLMS values against absent/invalid/valid settings. Tests use disposable HOME/XDG directories and recording runners; no real client registration or package acquisition is claimed.
Validation performed
Local Mac arm64, Node 24.22.1 and npm 11.16.0:
npm run test:focused -- tests/boundary/cli/defaultAmpRegistration.test.ts tests/boundary/cli/ampRegistrationPreservation.test.ts tests/boundary/cli/mcpAddDiscovery.test.ts— rebuilt the runtime and passed 11 tests across 3 files.npm run check:fast— passed typecheck, lint and module boundaries.npm run verify:test-discovery— all 2,866 test files discovered exactly once.git diff --check— passed.Full
npm run checkis known to be blocked on main by unrelated Knip findings (4 unused exports, 3 unused exported types, 2 duplicate exports), confirmed during earlier local preparation and in the cloud handoff. It was not rerun for this publication. Full CI, real external clients and Windows/Linux were not rerun locally; the combined three-PR tree was tested in the cloud, not on this Mac.Compatibility, safety, and release
Previously unguarded default Amp writes now validate settings and retain recovery data; callers with invalid settings/backup paths receive
VALIDATION_ERRORbefore registration. No migration or dependency/release metadata change. The existing project-scope and remaining argument-binding limitations are not declared solved. No real user settings were changed during verification.Author readiness
Human owner: @maxazure
Before merge