Skip to content

refactor(cli): deduplicate lazy subcommand registration - #129351

Merged
steipete merged 1 commit into
mainfrom
codex/cleanup20k-cli-lazy-subcli-registration-20260825
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cleanup20k-cli-lazy-subcli-registration-20260825

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The main CLI lazily registers dozens of subcommands through repetitive, nearly identical descriptor declarations, making command ordering, aliases, and startup behavior harder to audit and maintain.

Why This Change Was Made

Factor the existing private registration descriptors through typed local tuples and the existing canonical lazy-loader helper. Preserve all 35 descriptors, four command groups, five custom registrars, every dynamic import and public command alias, and the existing declaration surface while deleting 122 net lines from shipped CLI production code.

User Impact

No CLI behavior changes: root help, subcommand help, aliases, completion, private-command gating, command ordering, and lazy module loading remain unchanged.

Evidence

  • Seven focused CLI owner suites pass all 63 tests, including descriptor registration, root help, completion state, and plugin registration.
  • The real Commander runtime exposes the same 44 root commands, and 11 representative aliases and help outputs remain byte-identical.
  • Independent source-blind checks preserve all 35 descriptors across the four existing groups, all five custom registrars, all 41 dynamic imports, and the unchanged emitted public declaration hash.
  • An isolated runtime probe observes zero eager module loads and exactly one lazy load when the corresponding command is dispatched.
  • A broadened existing process test for rejected onboarding options fails identically on a pristine detached checkout of this exact pull-request base: the existing startup migration already creates the selected profile directory before invalid gateway-port validation. Its bootstrap/migration owner is recorded as a separate follow-up; it is not introduced or modified by this one-file refactor.
  • The full local changed-file plan reaches unrelated existing stale shared-dependency type errors; targeted formatting, lint, assertion and file-size ratchets, and unused-export/dependency scans pass. Hosted exact-head CI remains the authoritative clean-environment gate.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: M maintainer Maintainer-authored PR labels Aug 25, 2026
@steipete
steipete marked this pull request as ready for review August 25, 2026 13:30
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 11:57 PM ET / August 26, 2026, 03:57 UTC.

ClawSweeper review

What this changes

The PR replaces repeated lazy CLI subcommand descriptor objects with typed tuples mapped through the existing lazy-loader helper.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. Current main still has the repeated object descriptors, while this one-file refactor preserves the existing lazy-registration path with no source-visible correctness defect; it is maintainer-owned and awaits exact-head CI completion.

Priority: P3
Reviewed head: 5668edaf95457938f4b43e8b7a63616e9b75746a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The small local refactor is source-consistent and preserves the existing owner boundary; final readiness depends on the still-running exact-head checks.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored refactor is exempt from the external-contributor proof gate; its body records focused runtime evidence, while this read-only review did not execute it.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored refactor is exempt from the external-contributor proof gate; its body records focused runtime evidence, while this read-only review did not execute it.
Evidence reviewed 6 items Changed owner boundary: The local tuple adapter converts each tuple back into the existing object definition shape before calling the canonical lazy-spec helper; the dynamic imports, command-name arrays, and export names remain explicit.
Entry point and callee: Program construction registers the command registry, which registers core and sub-CLI groups; group registration still invokes each lazy registrar only on dispatch.
Existing behavioral coverage: Adjacent tests exercise primary placeholder registration, lazy dispatch, aliases, gateway fast-path behavior, completion context, and plugin ordering; no tests were changed by this behavior-neutral refactor.
Findings None None.
Security None None.

Live Verification

Command: pnpm build && pnpm openclaw acp --help

Result: FAIL (failed) — step 1 run pnpm build: previous terminal command was still running after 30 seconds: "pnpm build && pnpm openclaw acp --help"

$ node --import tsx scripts/build-all.mts
[build-all] plugins:assets:build
$ node --import tsx scripts/bundled-plugin-assets.mts --phase build
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 99.20 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[build-all] plugins:assets:build done in 1.97s
[build-all] tsdown-ai
[PLUGIN_TIMINGS] Your build spent significant time in plugins. Here is a breakdown:
  - tsdown:deps (48%)
  - rolldown-plugin-dts:generate (21%)
  - rolldown-plugin-dts:fake-js (20%)
See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.

[tsdown-build] invocation 1/1 finished in 4.5s
[build-all] tsdown-ai done in 5.10s
[build-all] tsdown-packages
[tsdown-build] invocation 1/1 finished in 21.2s
[build-all] tsdown-packages done in 21.7s
[build-all] tsdown-unified

Assertions:

  • FAIL expect_output: Usage: openclaw acp

How this fits together

The CLI program builder receives process arguments and registers root-command placeholders. A lazy subcommand group replaces the selected placeholder by dynamically importing its command module when that command is invoked.

flowchart LR
  A[CLI arguments] --> B[Program builder]
  B --> C[Subcommand registry]
  C --> D[Lazy command group]
  D --> E[Dynamic module import]
  E --> F[Registered command]
Loading

Decision needed

Question Recommendation
Once exact-head CI completes, should this maintainer-owned CLI cleanup be accepted as a behavior-neutral refactor? Merge after exact-head CI: Accept the local refactor when the remaining required checks pass on the current head.

Why: The PR carries the protected maintainer label and is authored by a repository member, so it should not be auto-closed or auto-merged by this workflow.

Before merge

  • Resolve merge risk (P1) - Exact-head CI was still in progress in the supplied PR state, so source review alone should not be treated as final merge validation.
Agent review details

Security

None.

PR surface

Source -122. Total -122 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 61 183 -122
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 61 183 -122

Review metrics

Metric Value Why it matters
Production versus tests production +61/-183 (net -122); tests 0 The sole changed production file removes repeated descriptor boilerplate without adding a test-support or configuration surface.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the local adapter and tuple declarations, then merge after exact-head validation confirms the unchanged lazy CLI behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the local adapter and tuple declarations, then merge after exact-head validation confirms the unchanged lazy CLI behavior.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR is a behavior-preserving refactor, and the relevant question is equivalence of existing CLI registration behavior rather than reproduction of a defect.

Is this the best way to solve the issue?

Yes. Keeping the tuple-to-object conversion local avoids changing the generic command-group API while retaining its existing runtime validation and lazy-loading behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 937c89675b04.

Labels

Label justifications:

  • P3: This is a behavior-neutral CLI maintenance refactor with no reported user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored refactor is exempt from the external-contributor proof gate; its body records focused runtime evidence, while this read-only review did not execute it.

Evidence

What I checked:

  • Changed owner boundary: The local tuple adapter converts each tuple back into the existing object definition shape before calling the canonical lazy-spec helper; the dynamic imports, command-name arrays, and export names remain explicit. (src/cli/program/register.subclis-core.ts:83, 5668edaf9545)
  • Entry point and callee: Program construction registers the command registry, which registers core and sub-CLI groups; group registration still invokes each lazy registrar only on dispatch. (src/cli/program/build-program.ts:27, 5668edaf9545)
  • Existing behavioral coverage: Adjacent tests exercise primary placeholder registration, lazy dispatch, aliases, gateway fast-path behavior, completion context, and plugin ordering; no tests were changed by this behavior-neutral refactor. (src/cli/program/register.subclis.test.ts:161, 5668edaf9545)
  • Current-main necessity check: Current main still uses the repeated object declarations at this boundary, so the central cleanup is not already implemented there. (src/cli/program/register.subclis-core.ts:86, 937c89675b04)
  • Feature history: The current main form of this registration module dates to the recent CLI/gateway refactor; the proposed adapter is a separate local cleanup on top of that owner boundary. (src/cli/program/register.subclis-core.ts:86, 3caf21bdd4c3)
  • Dependency boundary: The diff only reshapes local TypeScript definitions and uses existing dynamic imports; it supplies no affirmative Codex runtime, protocol, or harness dependency signal, so a Codex dependency-contract review is not applicable. (src/cli/program/register.subclis-core.ts:83, 5668edaf9545)

Likely related people:

  • steipete: Current-main history attributes the present registration module to this author, and the author also contributes the local refactor. (role: recent CLI registration contributor; confidence: high; commits: 3caf21bdd4c3, 2175a1502099; files: src/cli/program/register.subclis-core.ts, src/cli/program/register.subclis.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for the required exact-head CI checks to complete before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-25T13:36:32.795Z sha 71820b9 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T14:24:28.592Z sha 71820b9 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/cleanup20k-cli-lazy-subcli-registration-20260825 branch from 71820b9 to 5668eda Compare August 26, 2026 03:50
@steipete
steipete merged commit f0a2920 into main Aug 26, 2026
131 checks passed
@steipete
steipete deleted the codex/cleanup20k-cli-lazy-subcli-registration-20260825 branch August 26, 2026 04:08
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
vincentkoc added a commit that referenced this pull request Aug 26, 2026
* origin/main: (24 commits)
  fix(gateway): reject rootless session permission modes (#128149)
  docs(memory): document shipped turn-taint propagation for network tool output (#129837)
  fix(ui): pool reply-less wake activity into one chat rollup (#128442)
  fix(package): prevent installs from deleting validated runtime assets (#129724)
  fix(nodes): approve silent initial node surfaces and name the pending surface approval (#129795)
  fix(backup): preserve configured agent state roots (#129773)
  fix(ui): own chat history issuance with a closed state machine (#129776)
  fix(cron): preserve cancellation reason after late finalization (#129331)
  fix(cron): prevent run waits from failing after clock changes (#129805)
  fix(telegram): route commentary through one frozen progress owner (#128259)
  fix(release): start approved VCR mirror recovery jobs (#129829)
  test: complete current-plugin-metadata-snapshot mock factories (#129791)
  test(telegram): remove duplicate reaction case (#129848)
  fix(channels): honor supported account reply-threading policies (#129679)
  refactor(cli): deduplicate lazy subcommand registration (#129351)
  fix(ai): report interrupted local-model streams instead of empty success (#129794)
  refactor(cli): consolidate Gateway fallback and hook ownership (#129802)
  fix(qa): reject token confidence lanes without executed evidence (#129830)
  fix(tui): fence session state and delayed actions (#129810)
  fix(control-ui): keep task progress full width on hover (#129832)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant