Reduce shipped CLI complexity hotspots

Merged
UN
4mo ago
+1531-1263

Summary

  • Extracted large CLI registration action bodies into named helpers across list/query, mutation, and operation command registration.
  • Split shipped-code complexity hotspots in activity, close-many, commander usage guidance, extension doctor runtime activation diagnostics, and runtime schema normalization.
  • Deduplicated shared option-string reading through registration-helpers.ts and recorded the continuation under canonical pm-92if without creating a duplicate PM item.

PM Evidence

  • Tracked under pm-92if with linked source files, test commands, and evidence comments.
  • pm-changelog@2026.6.30 generated/check mode left CHANGELOG.md unchanged with item_count=1388.

Verification

  • pnpm build
  • pnpm typecheck
  • Focused affected suite: node scripts/run-tests.mjs test -- tests/unit/cli/register-list-query.spec.ts tests/unit/cli/cli-main-errors.spec.ts tests/unit/commands/history-activity-command.spec.ts tests/unit/commands/close-command.spec.ts tests/unit/commands/close-many-branch.spec.ts tests/unit/core/schema/runtime-schema-command-flags.spec.ts tests/unit/commands/contracts-command.spec.ts tests/unit/sdk/sdk-index.spec.ts tests/unit/extensions/extension-command.spec.ts (545 tests)
  • Final review-fix focused suite: node scripts/run-tests.mjs test -- tests/unit/commands/history-activity-command.spec.ts tests/unit/cli/register-list-query.spec.ts tests/unit/cli/registration-helpers.spec.ts tests/unit/commands/contracts-command.spec.ts tests/unit/sdk/sdk-index.spec.ts (264 tests)
  • pnpm lint (ESLint clean, jscpd 0 clones across 547 files, static quality passed)
  • pnpm contracts:check
  • node scripts/run-tests.mjs coverage (262 files / 5277 tests / 100% statements, branches, functions, lines)
  • node scripts/smoke-npx-from-pack.mjs (packed package smoke passed for 2026.7.2, packages=11)
  • Manual temp-directory installed-CLI smoke in /tmp/tmp.5agjTscYIG: pm init, create, list-open, compact activity, close, health
  • pnpm security:scan and pnpm audit --audit-level moderate
  • pm health --check-only --summary --json clean, pm validate --check-resolution --check-history-drift --json history drift ok with known resolution-metadata backlog
  • node scripts/release/sentry-telemetry-gate.mjs --json --telemetry-mode best-effort ok
  • pnpm changelog:pm and pnpm changelog:pm:check
  • Pre-push greptile review --branch main --json: final pass confidence 5, safe to merge, no comments

GitHub Sweep

  • Open PRs/issues were empty before opening this PR.
  • Secret scanning returned no alerts.
  • Dependabot and CodeQL alert APIs returned only fixed alerts.

Summary by cubic

Refactors the CLI to reduce complexity by extracting helpers and splitting large flows. Improves maintainability with no user-facing changes and supports pm-92if.

  • Refactors
    • Extracted command registration actions into named helpers across list/query, mutations, and operations (e.g., registerListCommand, addHiddenOptions, lifecycle option builders).
    • Split large logic in activity, close-many (plan orchestration and closeability checks), commander unknown-command guidance, extension doctor runtime activation path collection, and runtime schema status normalization into focused helpers.
    • Centralized option-string parsing with readOptionString in registration-helpers.ts and removed duplicates in registration modules.
    • Continues progress toward pm-92if goals for A+ CodeFactor and zero complexity/duplication issues.