Skip to content

fix(cli): protect Amp settings during default registration - #8076

Merged
morluto merged 1 commit into
morluto:mainfrom
maxazure:fix/default-amp-registration
Nov 3, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
maxazure:fix/default-amp-registration

Conversation

@maxazure

@maxazure maxazure commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extend the existing Amp configuration guard to default rea mcp add registration. Without an explicit agent selector, Incur also writes Amp, but REA currently bypasses its preservation/backup/validation wrapper. An existing rea.env can 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:

  • fix(cli): reject unknown MCP registration options #8069 validates unknown registration options and redacts declared sensitive values. Its early rejection must remain before any Amp reads/backups.
  • fix(cli): keep MCP registration JSON output parseable #8071 owns clean JSON result delivery and the newer registration-option normalization. Both PRs touch the same wrapper and shared splitter. On combination, preserve its normalization before dispatch, avoid reintroducing the late token-wide expansion, and synchronize commandIndices with the tokens retained by this two-stage timing pass.
  • The combined Amp continuation must retain 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

  • Semantic owner / earliest changed stage: CLI registration selection and Amp configuration guard; the existing backup writer and Incur registration producer remain owners of their respective effects.
  • Scope: routine correction within existing registration behavior; no separate maintainer scope decision is required.
  • Effects: default registration already writes Amp and may invoke an external package runner. This change adds the same validation, environment preservation and secure recovery backups already used for explicit Amp registration. No new analysis-target authority.
  • No MCP tool-catalog, provider, bridge, target-format, Evidence or generated/package metadata changes.

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 da89517 and #8071 414f394 passed 41 tests, including six expanded-discovery no-side-effect cases. These are reported cloud results, not Mac reruns. The exact transferred patch matched SHA-256 2a97eb07e32ce2f34347d8cb9cb1b3981fdaeb0b287e835d61dac955b44c66e5; 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 check is 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_ERROR before 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

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed diff appears safe to merge; no blocking defect was established.

Summary

Extends Amp settings protection to default rea mcp add registration.

  • Default MCP registration now checks Amp settings before it runs.
  • The CLI now removes timing globals before parsing command options.

maxazure acknowledges that conflicts with #8069/#8071 need merge-time resolution and retesting. The author also leaves the project-scope contract and remaining argument-binding/discovery limitations outside this fix.

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]
Loading

Reviews (1) · Last reviewed commit: "fix(cli): protect Amp settings during de..." · Reviewed by Greptile

@maxazure
maxazure marked this pull request as ready for review October 30, 2026 04:50
Copilot AI balanced review requested due to automatic review settings October 30, 2026 04:50
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-30T04:50:32.191631Z
We couldn’t complete this review. Comment @codex review to try again.
36fb965 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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/-c values before --agent selectors), 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 splitIncurBuiltinArguments that strips boolean timing globals (--timings, --no-timings, --timings=…) until --, so timing-shaped flags can't hide the mcp add selection while timing-shaped output values remain data.
  • Track a failed registration exit in runRegistration so 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

@morluto
morluto merged commit 4b961e3 into morluto:main Nov 3, 2026
45 of 51 checks passed
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants