Repository navigation
perf(cli): decouple lazy CLI startup from AnalysisView, session contracts, and MCP registration - #13435
Conversation
…acts, and MCP registration
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. |
[Medium impact] The PR appears safe to merge; no blocking issue remains. SummaryThis PR keeps heavy modules out of unrelated CLI startups:
The earlier bundled-control finding is addressed. No new actionable issue or security issue was found. Tests were not rerun during this review. Supersession could not be checked because GitHub access required authentication. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
Start[CLI invocation] --> Command{Requested operation}
Command -->|Unrelated command| Normal[Run without heavy services]
Command -->|mcp add| Registration[Import mcpRegistration]
Command -->|inspect-analysis-view| View[Import AnalysisViewService]
Command -->|Summary evidence delivery| View
Native[Native command registration] --> Target[nativeTargetOption]
Target --> Contracts[sessionToolContracts]
Reviews (2) · Last reviewed commit: "test(cli): use bundled CLI runs for heav..." · Reviewed by Greptile |
Summary
Eliminates three unnecessary static dependency chains pulled into lazy single-command CLI startups (even when running
--helpor single-command queries):nativeTarget(which pullsOPEN_BINARY_TOOL_CONTRACTfromsessionToolContracts.tsand transitively the ~1.2–1.3 MBanalysisViewResultschema module) out ofsrc/cli/options.tsintosrc/cli/nativeTargetOption.ts.AnalysisViewService.jsto dynamicimport(...)insidesrc/cli/analysisEvidenceDelivery.ts(whendetail === "summary") andsrc/cli/analysisViewCommands.ts(when runninginspect_analysis_view).mcpRegistration.jsto dynamicimport(...)insrc/cli/cliShell.ts, guarded by a single shared predicateisMcpRegistrationCommandexported fromsrc/cli/mcpBuiltinCommands.ts(also removing the duplicateprecedingFlagslist).Addresses #13275.
Problem and expected behavior
Previously, single-command CLI invocations via
cliLoader/cliShellstill eagerly loaded:sessionToolContracts.js(483.7 KB chunk on baseline; 92 KB after decoupling) andanalysisViewResult.js(~1.2–1.3 MB) on every command importingcli/options.tsorcontractCommand.tsbecauseoptions.tsimportedOPEN_BINARY_TOOL_CONTRACTfornativeTarget.AnalysisViewService.js(~101 KB) on every command registering viacontractCommand.tsbecauseanalysisEvidenceDelivery.tsimportedinspectAnalysisViewValidatedstatically even though summary delivery is opt-in.mcpRegistration.jsand its client-config registration stack insidecliShell.ts(97.1 KB -> 62.7 KB) even when running unrelated commands.With this change:
mcp add,inspect_analysis_view,--detail summary --evidence-output ..., andcloseCliResources()behavior remain identical (100% SHA-256 stdout parity across tested commands).analysisViewResultin their own family contract (such asinspect-uefi-nvramandinspect-sqlite-database) no longer loadsessionToolContracts,analysisViewResult,AnalysisViewService, ormcpRegistration, cutting startup wall time roughly in half and peak RSS by ~89 MiB.Change and scope
src/cli/nativeTargetOption.ts: new owner fornativeTargetandNATIVE_OPEN_HELP.src/cli/options.ts: retains onlypublishArgvInput,cliDecimalField, andcliDecimalShape(bundledoptionschunk shrinks to 6.0 KB importing onlyzodandjsonSerialization).src/cli/coreBinaryCommands.ts,src/cli/coreNativeCommands.ts,src/cli/decompileDirectoryCommand.ts: updatednativeTargetimports to./nativeTargetOption.js.src/cli/analysisEvidenceDelivery.ts: dynamically imports../application/analysisView/AnalysisViewService.jsinsidepublishDeliveredEvidenceonly wheninput.detail === "summary".src/cli/analysisViewCommands.ts: dynamically imports../application/analysisView/AnalysisViewService.jswhen runninginspect_analysis_view.src/cli/mcpBuiltinCommands.ts,src/cli/mcpRegistration.ts,src/cli/cliShell.ts: unifiedisMcpRegistrationCommandinmcpBuiltinCommands.tsand dynamically loaded./mcpRegistration.jsfromcliShell.tsonly forrea mcp addinvocations.tests/boundary/cli/cliStartupImports.test.ts: addedmcp-registrationtoDEFERRED_IMPORTS, addedHEAVY_SHARED_MODULES(analysis-view-service,analysis-view-result,session-tool-contracts), added positive detection assertions, and verified single-command startup exclusion forinspect-uefi-nvram,inspect-sqlite-database,inspect-wasm-artifact, andguided-workflows.Not included in this PR: build-time compact JSON Schema generation or splitting
APPLICATION_TOOL_CONTRACTS/ domain summary schemas out of family*ToolContracts.tsfiles (tracked in #13275).Contract and boundary impact
src/cli/nativeTargetOption.tsowns the native open-target CLI flag projection;src/cli/mcpBuiltinCommands.tsis the single owner ofisMcpRegistrationCommand(replacing duplicate flag lists inmcpRegistration.tsandmcpBuiltinCommands.ts);cliShell.tsandanalysisEvidenceDelivery.tslazily resolve execution-only modules at dispatch/summary time.--helpstdout SHA-256 identical across all tested commands).mcpRegistration.jsstill registerscloseCliMcpRegistrationResourcesviaownCliProcessResourcewhen loaded, socloseCliResources()disposes its ownedArtifactResourceScopeidentically whenmcp addruns.docs/public/product-catalog.json), package, or installation impact: verified vianpm run docs:check(no catalog contract changes).Expected effects:
Evidence and regression coverage
Tests added or updated:
tests/boundary/cli/cliStartupImports.test.ts(positive triggers foranalysis-view-service,mcp-registration,analysis-view-result,session-tool-contracts, plus single-command--helpresolution assertions forinspect-uefi-nvram,inspect-sqlite-database,inspect-wasm-artifact, andguided-workflows).Base reproduction or other evidence:
Measured on compiled
dist/cli-runtime(scripts/rea.mjs) in fresh isolated child processes via/usr/bin/time -l(3 runs each: run 1 cold, best of runs 2–3 warm; Mac arm64 Node v24.22.1, baselineorigin/main375483b6b3):scripts/rea.mjs ...)inspect-uefi-nvram --help272.7 ms/267.1 ms133.7 ms/133.4 ms(~2.04x / 2.00x)370 / 350 ms->150 / 150 ms194.4 -> 105.2 MiB(-89.2 MiB)588e196e489d56a0(exact)inspect-sqlite-database --help263.9 ms/262.5 ms133.0 ms/129.7 ms(~1.98x / 2.02x)350 / 350 ms->150 / 150 ms192.8 -> 104.0 MiB(-88.8 MiB)0a27aa0e9584d842(exact)inspect-wasm-artifact --help276.8 ms/278.1 ms210.3 ms/208.8 ms(~1.32x / 1.33x)360 / 370 ms->260 / 260 ms197.3 -> 157.2 MiB(-40.1 MiB)93fba6b2ba2e3d8b(exact)guided-workflows --help325.0 ms/321.6 ms272.9 ms/270.2 ms(~1.19x / 1.19x)430 / 430 ms->370 / 360 ms204.0 -> 193.8 MiB(-10.2 MiB)d738d1a0b0d1f68d(exact)mcp add --help(control)635.8 ms/601.0 ms607.2 ms/602.7 ms810 / 810 ms->810 / 810 ms329.5 -> 329.3 MiB3b0ec226cc03086d(exact)Compiled
dist/cli-runtime/static imports (^import ... from):options-zOUZKmj_.js:6.0 KB,badStaticImports=[]contractCommand-B8ca8l_7.js:97.2 KB,badStaticImports=[]uefiCommands-CMdq-_Ww.js:92.6 KB,badStaticImports=[]sqliteCommands-rSUDN5pE.js:2.0 KB,badStaticImports=[]cliShell-DOzHQqIw.js:62.7 KB(down from97.1 KB),badStaticImports=[]sessionToolContractschunk:92 KB(down from483.7 KB)User-visible CLI/MCP output (if applicable): identical
--helpoutput bytes across all tested commands.Remaining proof gaps: Linux/Windows CI environments pending GitHub Actions run; end-to-end execution of
mcp addand--detail summary --evidence-outputrelies on existing CLI boundary suites in CI (onlycliStartupImports.test.ts+readmeConsistency.test.tsran after the final test edit, whilecliLazyRegistration.test.ts,commandEvidenceDelivery.test.ts,clientProfiles.test.ts, andcliBuiltinArguments.test.tspassed prior to the finalcliStartupImports.test.tsassertion adjustment with unchanged production files).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
npx oxfmt --write src/cli/... tests/boundary/cli/cliStartupImports.test.ts— formatted cleanlynpm run check:fast— passed typecheck, lint, and architecture guards across 2951 source filesnpm run test:focused -- tests/boundary/cli/cliStartupImports.test.ts— passed 1 file / 7 testsnpm run docs:check— passeddocs:check:built(6/6 turbo tasks) andtests/conformance/readmeConsistency.test.ts(8/8 tests)npm run test:focusedrun (with identical production source) — passedcliLazyRegistration.test.ts(14/14),commandEvidenceDelivery.test.ts(11/11),cliBuiltinArguments.test.ts(9/9), andclientProfiles.test.ts(15/15)Compatibility, safety, and release
nativeTargetmoved to internalsrc/cli/nativeTargetOption.ts; no public CLI or MCP contract change).src/cli/module boundary only; Linux/Windows via CI).docs:checkpassed).mcpRegistrationstill initializesownCliProcessResourcebefore executingserveMcpRegistration.Author readiness
Human owner:
Before merge
type(scope): outcome.