Repository navigation
refactor(cli): run one-shot commands through one shared owner - #10405
Merged
Merged
Conversation
scripts/rea.mjs and the test CLI session worker each implemented the one-shot command sequence: argument normalization, output admission, configuration errors, version documents, the Amp scope refusal, and result delivery. The worker copy had drifted: it never rendered formatted version reports or the Amp refusal. Move the sequence into src/cliOneShot.ts. Both callers supply a host for their streams, exit and resource ownership. The launcher keeps closed-pipe status, worker shutdown and process exit; the session worker captures output per command. The cliOutput bundle entry is superseded and removed. The dispatcher test now replaces only the command runtime, so output admission runs production code. A new parity test compares the file session with a fresh process.
Contributor
[Medium impact] The PR appears safe to merge; no new blocking issue was identified. SummaryMoves the one-shot command sequence into
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Executable launcher] --> C[runOneShotCli]
B[Test session worker] --> C
C --> D{Early answer?}
D -->|Yes| E[Write version or refusal]
D -->|No| F[Load command runtime]
F --> G[Run command and deliver result]
G --> H[Host owns exit and cleanup]
Reviews (4) · Last reviewed commit: "Merge branch 'main' into refactor/cli-on..." · Reviewed by Greptile |
1 of 19 tasks
This was referenced Nov 13, 2026
morluto
marked this pull request as ready for review
November 14, 2026 03:47
Codex Review Summary: ✅ CompletedThis 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. |
22 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The one-shot CLI command sequence existed twice: in
scripts/rea.mjsand in the test session workertests/support/cli/cliCommandSessionWorker.mjs(its comment said it "matches scripts/rea.mjs"). The copy had drifted, so tests on the shared session exercised different behavior from the shipped executable. This moves the sequence into one owner that both call.Problem and expected behavior
Before this change, through the file-scoped session (
runFileCli), compared with a freshreaprocess (executed, observed with the new parity test against the old worker):--version --json: the fresh process returns a version document; the session passed it to Incur instead. Failed.mcp add --no-global --agent amp --json: the fresh process refuses withAMP_PROJECT_SCOPE_UNSUPPORTED; the session did not. Failed.capabilities --json --token-limit 5: both reject the output combination. Passed.Expected: the session and a fresh process produce identical exit code, stdout and stderr for the same command.
This duplication is also what blocks moving more tests onto shared sessions, which is the main lever for CLI spawn cost in CI.
Change and scope
src/cliOneShot.tsexportsrunOneShotCli(arguments, host): argument normalization, output admission, configuration errors, version documents, the Amp scope refusal, and dispatch with result delivery. It imports./cli.jslazily, so the early answers still avoid loading the command catalog.scripts/rea.mjskeeps admission, MCP/doctor routing, closed-pipe status, worker shutdown and process exit. It callsrunOneShotCliwith a host bound to its streams.renderCliOutputArgumentErrortakes aCliPreExecutionError, so the Amp refusal code is typed instead of passed as an out-of-union literal.cliOutputruntime bundle entry is superseded and removed (bundle-runtime.mjs,prepack.mjs, launcher runtime file list).cliOneShotis added to the bundle, prepack and both Knip configs.tests/boundary/cli/dispatcher.test.tspreviously stubbedcliOutput.js. It now replaces only the command runtime and result output, so output admission runs production code. The copied runtime links the installation'snode_modulesbecause production chunks importzodandsemver.Not included: moving more tests onto shared sessions, and the 113 test files that spawn
scripts/rea.mjsdirectly.Contribution scope: not applicable (refactor within existing boundaries).
Contract and boundary impact
Semantic owner and earliest changed stage:
src/cliOneShot.tsnow owns the one-shot sequence. Consumers:scripts/rea.mjsand the test session worker. Superseded: the worker's copy and thecliOutputbundle entry.Contribution scope fit and linked maintainer decision: not applicable.
CLI and MCP/tool-catalog contract: no intended change. MCP and doctor routing are untouched.
Provider, bridge, target-format, or platform compatibility: none.
Evidence, artifact, provenance, or reconstruction contract: none.
Target selection, authority, upstream behavior, and cleanup details (if applicable): worker shutdown and closed-pipe handling stay in the launcher; ordering is unchanged (resources close before SDK output finishes on an explicit exit).
Generated metadata, package, or installation impact: packaged files gain
dist/cli-runtime/cliOneShot.jsand losedist/cli-runtime/cliOutput.js;prepack.mjschecks the new set.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.
Evidence and regression coverage
tests/boundary/cli/cliSessionParity.test.ts(new, three cases);tests/boundary/cli/dispatcher.test.tsandtests/boundary/process/runtimeBundle.test.tsfixtures updated.rea --version→6.9.0;--version --format json→ version document;mcp add --no-global --json→AMP_PROJECT_SCOPE_UNSUPPORTED, exit 1;capabilities --json | head -1→ exit 141.prepack.mjsfile checks here, not by a localverify:packagerun.Validation performed
Local macOS, Node 24.22.1:
npm run check:fast— typecheck and lint passed.npm run build:cached— passed.npx vitest run --project cli-boundary— 247 files, 1,850 passed, 5 skipped.runFileCli/sharedCliRun— 333 passed, 1 skipped.npx vitest run tests/boundary/cli/dispatcher.test.ts— 20 passed.npx vitest run tests/boundary/process/runtimeBundle.test.ts— 2 passed (fixture updated for the new bundle entry after review).npm run knipandnpm run knip:production— no new findings.npx oxfmt --check .(the repository formatter) — passed.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.