Repository navigation
fix(cli): reject project-scoped Amp registration - #7979
Conversation
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. |
[Low impact] The PR appears safe to merge; no blocking issue remains. SummaryThe PR rejects project-scoped Amp registration before Incur can write global settings.
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 |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
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. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Done, thanks for the review. All 5 threads are resolved now:
Tests on the touched file pass (12/12), plus typecheck, lint, and format checks. Ready for another look whenever you are. |
|
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.
💡 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".
| else if (token === "--agent" && index + 1 < rest.length) { | ||
| agents.push(rest[index + 1]!); | ||
| index += 1; |
There was a problem hiding this comment.
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 👍 / 👎.
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.
8f93584 to
f01db16
Compare
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Summary
Fixes #7535.
rea mcp add --no-global --agent ampexited 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-globalintoglobal: falseand 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 --helppromises--no-globalinstalls to the project instead of globally.Change and scope
src/cliBuiltinArguments.ts: newisProjectScopedAmpRegistrationcheck. It mirrors Incur'smcp addparsing (spaced--agentonly,--commandconsumes 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
mcp adddispatch is unchanged; it never receives this combination.mcp add --no-globalwith Amp now fails nonzero with a diagnostic instead of falsely succeeding. No tool catalog change.docs/public/product-catalog.json), package, or installation impact: none.Expected effects (check known effects; use documentation-only on its own).
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/boundary/cli/cliBuiltinArguments.test.ts, 6 cases (explicit Amp, default Amp with no agent,--jsonstripped before dispatch, global pass-through, non-Amp pass-through, other commands).c19f13ca0), the issue repro in an isolated HOME exited 0, printed success, and wrote$HOME/.config/amp/settings.jsonwith 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. Globalmcp add --agent ampwithout--no-globalstill exits 0 and writes the global file.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.
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
mcp add --no-globalwith 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.Author readiness
Human owner: @sx4im
Before merge
type(scope): outcome.