Skip to content

fix(cli): reject project-scoped Amp registration - #7979

Merged
morluto merged 7 commits into
morluto:mainfrom
sx4im:fix/7535-amp-no-global
Nov 5, 2026
Merged

morluto merged 7 commits into
morluto:mainfrom
sx4im:fix/7535-amp-no-global

Conversation

@sx4im

@sx4im sx4im commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7535. rea mcp add --no-global --agent amp exited 0 reporting success while writing the global Amp settings file and creating no project file. It now exits 1 with a diagnostic before anything is written.

Problem and expected behavior

Incur parses --no-global into global: false and honors it for its package-runner agents, but its Amp writer ignores the flag and always writes ~/.config/amp/settings.json. A project-scoped request therefore changed global config while reporting success. mcp add --help promises --no-global installs to the project instead of globally.

Change and scope

  • src/cliBuiltinArguments.ts: new isProjectScopedAmpRegistration check. It mirrors Incur's mcp add parsing (spaced --agent only, --command consumes its value) and flags the request when Amp would register under --no-global, including the no-agent case where Incur registers Amp by default.
  • scripts/rea.mjs: the entrypoint rejects flagged requests with a nonzero exit and a plain diagnostic before Incur runs. Global Amp registration is untouched.
  • tests/boundary/cli/cliBuiltinArguments.test.ts: 6 cases for the check.

Not included: real project-scoped Amp registration. That needs an upstream Incur change, since Incur owns the Amp writer. Until then the guard stops the silent global write.

Contract and boundary impact

  • Semantic owner and earliest changed stage: REA CLI entrypoint argument routing. Incur's mcp add dispatch is unchanged; it never receives this combination.
  • Contribution scope fit and linked maintainer decision: ordinary fix within existing boundaries; not applicable.
  • CLI and MCP/tool-catalog contract: mcp add --no-global with Amp now fails nonzero with a diagnostic instead of falsely succeeding. No tool catalog change.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: the rejected request writes nothing, so no cleanup is needed.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

The guard itself writes no files and contacts no services; it only refuses a combination that previously wrote global config. Global registration behavior is unchanged.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/cli/cliBuiltinArguments.test.ts, 6 cases (explicit Amp, default Amp with no agent, --json stripped before dispatch, global pass-through, non-Amp pass-through, other commands).
  • Base reproduction or other evidence: on unmodified main (c19f13ca0), the issue repro in an isolated HOME exited 0, printed success, and wrote $HOME/.config/amp/settings.json with the rea server while the project stayed empty. After the fix, the same command exits 1 with the diagnostic, writes no global file, and creates no project file. Global mcp add --agent amp without --no-global still exits 0 and writes the global file.
  • User-visible CLI/MCP output (if applicable): the diagnostic is:
Amp does not support project-scoped registration: 'rea mcp add --no-global' with Amp would write the global Amp settings file instead of a project file. Run without --no-global to register Amp globally.
  • Remaining proof gaps: real Amp client behavior with project settings is untested, and project-scoped Amp registration itself stays unsupported pending an upstream Incur fix. CI owns the full suite.

Boundary coverage: public success and error delivery. The end-to-end CLI repro asserts more than the exit code: no global file written, no project file created. No lifecycle regressions apply; no resource ownership or finalization changes.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/cli/cliBuiltinArguments.test.ts — 6 passed (failed before the fix: the function did not exist).
  • npm run test:focused -- tests/boundary/cli/cliOutput.test.ts — 64 passed.
  • npm run check:fast — typecheck and lint passed.
  • npm run verify:test-discovery — 2802 test files discovered exactly once.
  • npm run build:cached — passed; isolated-HOME CLI repro run before and after the fix.

Compatibility, safety, and release

  • Breaking changes or migration steps: one previously accepted combination (mcp add --no-global with Amp) now fails. That combination never did what it promised, so this corrects behavior rather than removing a working workflow. Callers that need Amp registration should drop --no-global.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable. Verified on Linux with Node 24.22.1.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the fix prevents an unintended persistent config write outside the requested scope.

Author readiness

Human owner: @sx4im

  • 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

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

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-11-05T17:35:12.243488Z
We couldn’t complete this review. Comment @codex review to try again.
f01db16 New commits
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no blocking issue remains.

Summary

The PR rejects project-scoped Amp registration before Incur can write global settings.

  • Project-scoped Amp registration requests now get a clear refusal.

The earlier agent-spelling finding is fixed. The earlier help and launcher-test concerns are also addressed. No new actionable issue was found.

Tests were not run during this review. Supersession could not be checked because GitHub access required authentication.

Reviews (8) · Last reviewed commit: "fix(cli): share normalized mcp add agent..." · Reviewed by Greptile

Comment thread scripts/rea.mjs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 00648409d7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread scripts/rea.mjs Resolved
Comment thread src/cliBuiltinArguments.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d2bd9c02a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/cliBuiltinArguments.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb538508a0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread scripts/rea.mjs Resolved
@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.

@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @sx4im, thanks for putting this together, the fix looks useful. What's left: there are 5 unresolved review threads from Codex and Greptile (2 still on current code), e.g. "Launcher behavior is untested" and "Restore the executable bit on the CLI launcher"; the 3 on outdated lines may just need resolving if they're already handled. Happy to merge once that's sorted.

@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.

@sx4im

sx4im commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Done, thanks for the review. All 5 threads are resolved now:

  • Launcher test added (commit ba2a093): the new test spawns scripts/rea.mjs with an isolated home and working directory and checks the exit code, the diagnostic, the unchanged global settings, and no project files, for both explicit Amp and the default-agent request. I confirmed it fails with the guard call removed and passes with it in place.
  • Executable bit was a false positive: scripts/rea.mjs is 100755 in both base and head, verified via the git trees. No change there.
  • The three outdated threads were already handled by the later commits: discovery requests bypass the guard through the shared classifyMcpAddDiscovery predicate, which the mcp add routing also consumes, and the refusal renders as a structured document for json, jsonl, and yaml.

Tests on the touched file pass (12/12), plus typecheck, lint, and format checks. Ready for another look whenever you are.

@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.

Comment thread src/cliBuiltinArguments.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f93584c05

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cliBuiltinArguments.ts Outdated
Comment on lines +248 to +250
else if (token === "--agent" && index + 1 < rest.length) {
agents.push(rest[index + 1]!);
index += 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Share normalized MCP agent selection with the preflight guard

For rea mcp add --no-global --agent=claude-code, this scan records no agents and the launcher rejects a non-Amp project registration as default Amp. The existing registration boundary in src/cli.ts:376-380 expands equals-form options before dispatch, but the new guard runs before that normalization. The inverse mismatch occurs with --agent claude-code --agent=amp, which passes this check despite selecting Amp at dispatch. Share the normalized registration arguments and agent selection between the guard and dispatch instead of interpreting the tokens independently.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

sx4im and others added 7 commits November 5, 2026 17:26
Incur's mcp add parses --no-global but its Amp writer always writes the
global settings file, so a project-scoped Amp request exited 0 reporting
success while changing global config. Fail closed in the entrypoint before
Incur dispatches: project-scoped Amp registration now exits 1 with a
diagnostic and leaves global settings untouched. Global Amp registration
is unchanged.

Fixes morluto#7535
Discovery requests are not registrations: mcp add --no-global with a
discovery flag (--help, -h, --llms, --llms-full, --version, --schema) now
passes through to normal handling instead of exiting 1 with the scope
error, matching the discovery set mcp add itself exempts. Real
project-scoped Amp registrations are still rejected before Incur runs.
Also restores the executable bit on scripts/rea.mjs, and adds launcher
dispatch tests proving the guard rejects a real registration before the
CLI runtime loads and passes discovery requests through.
…d routing

The Amp project-scope guard kept its own copy of the mcp add discovery
flags, which could drift from the discovery routing in cli.ts.
classifyMcpAddDiscovery in cliBuiltinArguments.ts is now the single
owner: the guard and the cli.ts mcp add special-casing both consume it,
with bypass/version/schema precedence matching the routing. No behavior
change; covered by classification unit tests and the existing mcp add
discovery serve test.
The Amp project-scope guard wrote a plain message to stderr and left
stdout empty when the caller asked for a structured document (json,
jsonl, yaml), contradicting the failure framing documented for the
output argument. Structured formats now render the refusal through the
same pre-execution error renderer the neighboring output-argument
branch uses, with code AMP_PROJECT_SCOPE_UNSUPPORTED on stdout; every
other format keeps the byte-identical plain stderr message. The guard
still exits 1 before dist/cli-runtime/cli.js is imported.

Co-authored-by: Saim Shafique <[email protected]>
The guard tests only called isProjectScopedAmpRegistration, so they
still passed with its call in scripts/rea.mjs removed. Add a launcher
test with an isolated home and working directory that checks the exit
code, the diagnostic, the unchanged global settings, and the absence
of project files for both explicit Amp and default-agent requests.

Co-authored-by: Saim Shafique <[email protected]>
The --no-global refusal tests locked the full English sentence. Structured output now asserts AMP_PROJECT_SCOPE_UNSUPPORTED and a message field.
The project-scope guard scanned raw arguments and only recognized the spaced --agent form, while dispatch expanded --agent= equals forms first: --agent=claude-code was wrongly refused as default Amp, and --agent claude-code --agent=amp slipped Amp past --no-global. The equals expansion and agent scan now live once in cliBuiltinArguments.ts and both callers consume them, so guard and dispatch read the same selection.
@sx4im
sx4im force-pushed the fix/7535-amp-no-global branch from 8f93584 to f01db16 Compare November 5, 2026 17:35
@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.

@morluto
morluto merged commit e5f6383 into morluto:main Nov 5, 2026
41 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.

[Bug] Amp registration writes global settings despite --no-global

2 participants