Repository navigation
perf(cli): keep single-command discovery lazy and skip throwaway Zod parses - #13254
Merged
Merged
Conversation
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. |
Contributor
[Medium impact] The PR appears safe to merge, with no new actionable findings. SummaryThe PR keeps known-command discovery lazy, avoids throwaway Zod wrappers, and adds indexed command lookup.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[CLI request] --> B{Request type}
B -->|Known command or scoped discovery| C[Load recorded registrar]
B -->|Root, unknown command, or built-in| D[Load complete CLI]
B -->|Standalone version or retired command MCP flag| E[Load no registrars]
C --> F[Build shared CLI shell]
D --> F
E --> F
F --> G[Answer discovery or run command]
Reviews (4) · Last reviewed commit: "fix(cli): test all five lazy discovery f..." · Reviewed by Greptile |
3 tasks done
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
Keep single-command CLI discovery (
--help,-h,--schema,--llms,--llms-fullfor known top-level commands) on the lazy single-registrar path instead of falling back to loading the entire CLI graph, replace throwawayz.object({ value: field }).safeParse({})calls per schema field inpresentOmittableDefaults, and indexcommandRegistryentries in aMapfor O(1) duplicate/lookup checks.Problem and expected behavior
selectCliRegistrationsinsrc/cli/cliLoader.tsonly admittedCOMMAND_OUTPUT_FLAGS, so runningrea <known-command> --helporrea <known-command> --schemadiscardedRECORDED_CLI_COMMAND_REGISTRATIONSand importedsrc/cli.ts(all 55+ CLI registration modules and ~200+ command schemas), even thoughsrc/cli/discovery.tsanswers single-command help, schema, and--llms/--llms-fulldirectly from that single registered command.presentOmittableDefaults(src/cli/omittableDefaults.ts) ranz.object({ value: field }).safeParse({})for every input field withoptout === undefined, allocating thousands of throwawayZodObjectwrappers on full CLI loads.registerCliCommandandcliCommandinsrc/cli/commandRegistry.tsperformed linear scans overentrieson every registration and lookup.Expected behavior: single-command discovery loads only that command's recorded registrar while root help/manifests, unknown commands (for
did you mean), and integration/builtin flags (completions,mcp,--update,--version,--incur-update-check) continue using the complete CLI with identical output.Change and scope
src/cli/cliLoader.ts: AddCOMMAND_DISCOVERY_FLAGS(--help,-h,--schema,--llms,--llms-full) and allow them inselectCliRegistrationswhencommand[0]matches a recorded registrar inRECORDED_CLI_COMMAND_REGISTRATIONS.src/cli/omittableDefaults.ts: UpdatefillsOmissionto short-circuit onfield._zod.optin !== undefinedand callfield.safeParse(undefined).successdirectly instead of wrapping inz.object({ value: field }).safeParse({}).src/cli/commandRegistry.ts: Store a{ entries, byName: Map<string, CliCommandEntry> }registry in theWeakMapso insertion order incliCommands()is preserved while duplicate checks inregisterCliCommand()and lookups incliCommand()are O(1).tests/boundary/cli/cliLazyRegistration.test.ts&tests/boundary/cli/cliInputSchemaRequired.test.ts: Update lazy CLI expectations for known-command--help/--schema, guard root and unknown--helpfallback, and test omission rules (required,.optional(),.default(),.prefault(),.catch(),.default().refine(() => false),.optional().transform(...)).Contract and boundary impact
src/cli/cliLoader.ts(selectCliRegistrations),src/cli/omittableDefaults.ts(fillsOmission), andsrc/cli/commandRegistry.ts(registerCliCommand/cliCommand).--help,--schema,--llms, and error behaviors stay identical.docs/public/product-catalog.json), package, or installation impact: none.Expected effects:
Evidence and regression coverage
tests/boundary/cli/cliLazyRegistration.test.ts(lazy CLI discovery+ updatedlazy CLI execution)tests/boundary/cli/cliInputSchemaRequired.test.ts(omittable defaults omission rules)v24.22.1, macOS arm64, warm OS caches, median of 3 runs after 1 warmup ondist/cli-runtime/built before and after):origin/main)rea list-cutter-sessions --helprea list-cutter-sessions --schemarea list-cutter-sessions --jsonrea decompile --helprea decompile --schemarea demangle-swift --helprea --help(complete CLI)Usage: rea list-cutter-sessions ...and schema document JSON verified incliLazyRegistration.test.ts).check:pr) not run locally; Windows lazy CLI subprocess timing not measured here.Validation performed
npm run build:cached— passed (built runtime & skills cleanly)npm run test:focused -- tests/boundary/cli/cliLazyRegistration.test.ts tests/boundary/cli/cliInputSchemaRequired.test.ts tests/boundary/cli/dispatcher.test.ts— passed (3 test files, 54/54 tests passed)npm run check:fast— passed (typecheck, lint, and architecture guards across 2943 source files)Compatibility, safety, and release
v24.22.1).Author readiness
Human owner:
Before merge
type(scope): outcome.