Repository navigation
Reduce shipped CLI complexity hotspots - #419
Conversation
There was a problem hiding this comment.
Sorry @unbraind, your pull request is larger than the review limit of 150000 diff characters
|
@greptileai review |
|
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Code Review
This pull request refactors several CLI command modules and registration files—including activity, close-many, doctor, and schema normalization—to reduce code complexity by splitting large functions into smaller helpers and extracting inline action handlers. The review feedback suggests two key improvements: first, in src/cli/commands/activity.ts, includeActivityEntry should filter using normalized candidate properties (candidate.op and candidate.author) instead of raw entry properties to ensure consistent filtering for 'unknown' values; second, in src/cli/register-mutation.ts, readStringArrayOption should be hardened to wrap single string values in an array to handle repeatable options robustly.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
📝 WalkthroughWalkthroughThis PR refactors several CLI command registration files (register-mutation.ts, register-operations.ts, register-list-query.ts), activity.ts, close-many.ts, doctor.ts, commander-usage.ts, and runtime-schema.ts by extracting inline logic into dedicated helper functions to reduce cyclomatic complexity, without changing exported behavior. An epic tracking file is also updated. ChangesCLI complexity reduction refactor
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request performs a comprehensive refactoring of the PM CLI codebase to reduce complexity and eliminate ESLint complexity findings. Key changes include splitting large inline command actions and registration logic into modular helper functions across register-list-query.ts, register-mutation.ts, register-operations.ts, commander-usage.ts, activity.ts, close-many.ts, doctor.ts, and runtime-schema.ts. There are no review comments to evaluate, and I have no additional feedback to provide as the changes successfully modularize the codebase and improve maintainability.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR refactors CLI command registration and runtime helpers to reduce complexity hotspots. The main changes are:
Confidence Score: 5/5Safe to merge with minimal risk. The changed code is primarily helper extraction with preserved command flow, option normalization, and output behavior. No accepted runtime, security, schema, or command-registration bugs were identified. No files require special attention.
What T-Rex did
Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant User
participant Commander as CLI registration handlers
participant Helpers as Extracted helper actions
participant Commands as Command runtime modules
participant Output as Output helpers
User->>Commander: Invoke pm command with options
Commander->>Helpers: Dispatch to named action/helper
Helpers->>Helpers: Normalize options and globals
Helpers->>Commands: Import and run command implementation
Commands-->>Helpers: Return command result
Helpers->>Output: Print result / stream / profile output
Output-->>User: CLI response
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant User
participant Commander as CLI registration handlers
participant Helpers as Extracted helper actions
participant Commands as Command runtime modules
participant Output as Output helpers
User->>Commander: Invoke pm command with options
Commander->>Helpers: Dispatch to named action/helper
Helpers->>Helpers: Normalize options and globals
Helpers->>Commands: Import and run command implementation
Commands-->>Helpers: Return command result
Helpers->>Output: Print result / stream / profile output
Output-->>User: CLI response
Reviews (3): Last reviewed commit: "Reduce shipped CLI complexity hotspots" | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/cli/commander-usage.ts`:
- Around line 469-479: Reuse the existing suggestedPaths value when building
didYouMean in commander-usage.ts so the two stay consistent; the current logic
in the unknown-command handling path recomputes combinedCandidates.slice(0, 3)
even though suggestedPaths already holds the same result. Update the didYouMean
construction to derive from suggestedPaths within the
resolveUnknownCommandCandidates / resolveUnknownCommandFallbacks flow, keeping
the fallback behavior unchanged and avoiding duplicate slicing logic.
In `@src/cli/commands/activity.ts`:
- Around line 245-255: Expose the newly extracted activity helpers through the
_testOnly export in activity.ts so they can be unit-tested directly instead of
only via runActivity. Add resolveActivityFilters, resolveActivityRuntimeContext,
prepareActivityHistoryRead, includeActivityEntry, collectActivityEntries, and
formatCompactActivity to the _testOnly object alongside the existing helpers,
keeping the export as the central test hook for these functions.
- Around line 207-233: The includeActivityEntry filter is comparing filters
against raw HistoryEntry fields instead of the normalized ActivityEntry
candidate, which makes op/author filtering inconsistent with the displayed
values. Update includeActivityEntry to use candidate.op and candidate.author for
the op/author checks, and keep the time-window check on the normalized candidate
as well; then adjust collectActivityEntries so it passes only the normalized
entry data needed by includeActivityEntry, removing the raw entry dependency if
it is no longer required.
In `@src/cli/commands/close-many.ts`:
- Around line 393-403: The closable-ID predicate is duplicated across
resolveCloseManyPlannedIds, planCloseManyRows, and runCloseMany, so keep the
source of truth in one place. Add closePlannedIds to CloseManyPlanContext from
resolveCloseManyPlannedIds, use closePlannedIds.has(item.id) when setting the
action field inside planCloseManyRows instead of recomputing from
alreadyTerminal and force, and in runCloseMany reuse the planned set from the
context rather than filtering planRows for action === "close".
- Around line 362-364: The rollback handling in
resolveCloseManyRollbackId/closeManyCommand treats an empty string as missing,
so a provided --rollback "" silently falls through. Update the closeManyCommand
flow to validate the parsed rollback option before the if (rollbackId) branch,
and make resolveCloseManyRollbackId (or its caller) reject empty strings with a
clear “rollback ID required” error instead of returning a falsy value. Use the
existing resolveCloseManyRollbackId and rollbackId logic in close-many.ts to
keep the fix localized.
In `@src/core/schema/runtime-schema.ts`:
- Around line 319-338: The fallback branch in normalizeRuntimeStatusDefinitions
skips the same ordering guarantee used in the primary path. Update the
DEFAULT_RUNTIME_STATUS_DEFINITIONS path so it also produces a sorted
RuntimeStatusDefinitionResolved[] using the same order-then-id comparator as the
deduped values path, ensuring consistent output regardless of default
declaration order or explicit order values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro
Run ID: 086b4904-ec7f-4fb7-8fef-2fc70f4516d4
📒 Files selected for processing (11)
.agents/pm/epics/pm-92if.toon.agents/pm/history/pm-92if.jsonlsrc/cli/commander-usage.tssrc/cli/commands/activity.tssrc/cli/commands/close-many.tssrc/cli/commands/extension/doctor.tssrc/cli/register-list-query.tssrc/cli/register-mutation.tssrc/cli/register-operations.tssrc/cli/registration-helpers.tssrc/core/schema/runtime-schema.ts
Refactor command registration actions into named helpers across mutation, list/query, and operations registration. Split extension doctor runtime activation diagnostics, activity aggregation, close-many orchestration, unknown-command guidance, and runtime schema normalization into smaller helpers. Record pm-92if evidence for the broader static-quality continuation and verify lint, contracts, coverage, package smoke, manual temp smoke, health, validation, security, audit, changelog, Sentry, and GitHub alert state.
9db69eb to
14c5712
Compare
|
Updated head pushed after addressing review feedback. Please review the current head again. @greptileai review |
|
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Code Review
This pull request focuses on a comprehensive refactoring of the CLI command registration, command execution, and schema normalization modules to reduce code complexity. Large functions in modules such as commander-usage, activity, close-many, doctor, register-list-query, register-mutation, register-operations, and runtime-schema have been broken down into smaller, focused helper functions. Additionally, a unit test has been added to verify that close-many rejects blank rollback checkpoint IDs. There are no review comments to address, and I have no further feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Summary
registration-helpers.tsand recorded the continuation under canonicalpm-92ifwithout creating a duplicate PM item.PM Evidence
pm-92ifwith linked source files, test commands, and evidence comments.pm-changelog@2026.6.30generated/check mode leftCHANGELOG.mdunchanged withitem_count=1388.Verification
pnpm buildpnpm typechecknode 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)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:checknode 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)/tmp/tmp.5agjTscYIG:pm init,create,list-open, compactactivity,close,healthpnpm security:scanandpnpm audit --audit-level moderatepm health --check-only --summary --jsonclean,pm validate --check-resolution --check-history-drift --jsonhistory drift ok with known resolution-metadata backlognode scripts/release/sentry-telemetry-gate.mjs --json --telemetry-mode best-effortokpnpm changelog:pmandpnpm changelog:pm:checkgreptile review --branch main --json: final pass confidence 5, safe to merge, no commentsGitHub Sweep
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.registerListCommand,addHiddenOptions, lifecycle option builders).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.readOptionStringinregistration-helpers.tsand removed duplicates in registration modules.pm-92ifgoals for A+ CodeFactor and zero complexity/duplication issues.Written for commit 14c5712. Summary will update on new commits.