Repository navigation
Feat/cli progress feedback - #21
Conversation
|
@jojomensah89 is attempting to deploy a commit to the OrcDev Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughInteractive CLI scans and pre-commit setup now show a persistent four-phase progress checklist on ChangesInteractive scan progress
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant ScanProgress
participant Audit
participant Report
User->>CLI: start interactive scan
CLI->>ScanProgress: run resolving and discovery phases
CLI->>Audit: evaluate UI rules
Audit-->>ScanProgress: complete evaluation phase
CLI->>ScanProgress: run report preparation
CLI->>Report: render final output
Report-->>User: write report to stdout
ScanProgress-->>User: write checklist to stderr
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
# Conflicts: # CHANGELOG.md # packages/cli/src/cli.ts # plans/README.md
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (5)
packages/cli/src/scan-progress.ts (2)
106-120: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueGuard against overwriting a live timer.
startassignsthis.timerwithout stopping an existing one. Current CLI callers await each phase sequentially so nothing leaks today, but a nested or concurrentrunwould orphan the previous interval.♻️ Proposed guard
private readonly start = (label: string): void => { + this.stopTimer(); this.activeLabel = label; this.frameIndex = 0;🤖 Prompt for 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. In `@packages/cli/src/scan-progress.ts` around lines 106 - 120, Update the start method to stop and clear any existing live timer before assigning a new interval, using the class’s existing timer cleanup mechanism if available. Preserve the current label reset, rendering, health check, and new timer setup behavior.
76-104: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueHoist
createColorsout of the render path.
complete,fail, andrenderActiveeach rebuild the color object;renderActivedoes so on every animation tick. The value depends only onterminal.color, so compute it once in the constructor.♻️ Proposed refactor
private readonly options: CreateScanProgressOptions; + private readonly colors: ReturnType<typeof picocolors.createColors>; private outputHealthy = true;constructor(options: CreateScanProgressOptions) { this.options = options; + this.colors = picocolors.createColors(options.terminal.color); }Then replace the per-call
const colors = picocolors.createColors(...)withthis.colors.🤖 Prompt for 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. In `@packages/cli/src/scan-progress.ts` around lines 76 - 104, Hoist the color configuration in the scan-progress class constructor by creating one colors instance from terminal.color and storing it on the class. Update complete, fail, and renderActive to reuse this.colors instead of calling picocolors.createColors on each invocation.packages/cli/src/cli.ts (2)
552-571: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the phase labels into shared constants.
The four phase labels are now duplicated between
runProjectScanPhasesand the inline phases inrunScanAction(Lines 596-646). Since the labels are part of the documented CLI contract, drift between the two call sites is easy to introduce.♻️ Proposed refactor
+const SCAN_PHASES = { + discovering: "Discovering app structure", + evaluating: "Evaluating UI rules", + preparing: "Preparing report", + resolving: "Resolving project", +} as const;Then reference
SCAN_PHASES.resolving,SCAN_PHASES.discovering, etc. from bothrunProjectScanPhasesandrunScanAction.🤖 Prompt for 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. In `@packages/cli/src/cli.ts` around lines 552 - 571, Extract the shared scan phase labels into a SCAN_PHASES constants object, including resolving, discovering, evaluating, and any other existing phase label. Update both runProjectScanPhases and the inline phases in runScanAction to reference these constants, preserving the documented label text.
599-636: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the discovery closure into a named function.
This inline callback carries workspace detection, the lone-root-package heuristic, and
--projectresolution in one ~37-line closure, which makes the phase call hard to scan. A namedresolveScanTarget({ options, resolvedProjectPath })returning the discriminated union would keep this phase a one-liner, consistent withrunProjectScanPhases.As per coding guidelines, "Keep functions focused, limit cognitive complexity".
🤖 Prompt for 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. In `@packages/cli/src/cli.ts` around lines 599 - 636, Extract the inline discovery callback from the scan phase into a named resolveScanTarget({ options, resolvedProjectPath }) function that returns the existing project/workspace discriminated union. Preserve the workspace detection, lone-root-package heuristic, --project path resolution, and discovery behavior unchanged, then pass the named function to progress.run so the phase call remains concise.Source: Coding guidelines
packages/cli/test/audit.test.ts (1)
105-126: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDocument what this test guards.
The assertion passes only because the rule loop awaits a macrotask between rules — a microtask-only await would leave
timerAdvancedfalse. That mechanism isn't obvious from the test body, so a short comment would keep it from being "simplified" later.♻️ Proposed comment
it("allows timers to advance between synchronous rules", async () => { const rootDir = await createReactFixture(); + // The audit loop must await a macrotask between rules; a microtask-only + // await would leave this callback pending until after the assertion. let timerAdvanced = false;🤖 Prompt for 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. In `@packages/cli/test/audit.test.ts` around lines 105 - 126, Add a brief explanatory comment in the “allows timers to advance between synchronous rules” test near the setImmediate scheduling or final assertion, documenting that the test requires a macrotask yield between rules and would fail with only a microtask await. Keep the test behavior and assertions unchanged.
🤖 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 `@packages/cli/src/cli.ts`:
- Around line 592-595: Update the eligibility passed to createCliScanProgress so
scan progress depends only on human output and stderr’s TTY/capabilities,
without using canPromptInteractively or resolveInteractiveMode requirements for
stdin/stdout. Keep resolveInteractiveMode and its stdin/stdout checks unchanged
for interactive prompts and menus, and prevent progress escape codes when stdout
is redirected.
In `@packages/cli/test/cli.test.ts`:
- Around line 480-481: Expand the disabled-mode assertions in the three test
blocks at packages/cli/test/cli.test.ts lines 480-481, 500-501, and 523-524 to
also verify stderr excludes “Discovering app structure” and “Preparing report,”
preserving the existing checks for the other two progress phases.
- Around line 411-418: Strengthen the CLI stream assertions in
packages/cli/test/cli.test.ts at lines 411-418 by verifying all four phase
labels are absent from both scan.stdout and setup.stdout while retaining the
existing stderr and report assertions. Apply the same absence checks to the
workspace scan output.stdout at lines 447-452.
---
Nitpick comments:
In `@packages/cli/src/cli.ts`:
- Around line 552-571: Extract the shared scan phase labels into a SCAN_PHASES
constants object, including resolving, discovering, evaluating, and any other
existing phase label. Update both runProjectScanPhases and the inline phases in
runScanAction to reference these constants, preserving the documented label
text.
- Around line 599-636: Extract the inline discovery callback from the scan phase
into a named resolveScanTarget({ options, resolvedProjectPath }) function that
returns the existing project/workspace discriminated union. Preserve the
workspace detection, lone-root-package heuristic, --project path resolution, and
discovery behavior unchanged, then pass the named function to progress.run so
the phase call remains concise.
In `@packages/cli/src/scan-progress.ts`:
- Around line 106-120: Update the start method to stop and clear any existing
live timer before assigning a new interval, using the class’s existing timer
cleanup mechanism if available. Preserve the current label reset, rendering,
health check, and new timer setup behavior.
- Around line 76-104: Hoist the color configuration in the scan-progress class
constructor by creating one colors instance from terminal.color and storing it
on the class. Update complete, fail, and renderActive to reuse this.colors
instead of calling picocolors.createColors on each invocation.
In `@packages/cli/test/audit.test.ts`:
- Around line 105-126: Add a brief explanatory comment in the “allows timers to
advance between synchronous rules” test near the setImmediate scheduling or
final assertion, documenting that the test requires a macrotask yield between
rules and would fail with only a microtask await. Keep the test behavior and
assertions unchanged.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: bb286b87-07a0-4fdd-96ae-4280c3697c42
📒 Files selected for processing (12)
CHANGELOG.mdREADME.mddocs/cli-contract.mdpackages/cli/README.mdpackages/cli/src/audit.tspackages/cli/src/cli.tspackages/cli/src/scan-progress.tspackages/cli/test/audit.test.tspackages/cli/test/cli.test.tspackages/cli/test/scan-progress.test.tsplans/015-interactive-scan-progress.mdplans/README.md
…ite for agent integration and scan output contracts
Summary
Adds immediate phase-based feedback while Shadscan audits a project:
Completed phases remain visible above the existing report. The same four phases are used for single-project scans, monorepo workspace scans, and pre-commit setup.
Why
Shadscan previously displayed a silent cursor while resolving the project, discovering its structure, evaluating rules, and preparing the report. On larger codebases, this made the CLI appear stuck.
This change gives users immediate, truthful feedback without introducing percentages, timings, or counts that may be inaccurate.
Implementation
stderr, preserving report output onstdoutProgress remains disabled for:
--no-interactiveSHADSCAN_INTERACTIVE=0Why not use a worker thread?
The spinner already uses its own timer, but the timer and audit share Node.js's main thread. Synchronous AST evaluation can temporarily prevent timer callbacks from running.
Moving the audit into a worker thread would guarantee uninterrupted animation, including during one exceptionally long rule. However, it would add worker bundling and startup costs, report and error serialization, cancellation plumbing, terminal coordination, and additional Node.js 18 packaging risk for a cosmetic progress feature.
This PR instead yields to the event loop between evaluated rules. It preserves the existing audit architecture and public contracts while keeping the spinner responsive during normal multi-rule scans. A single unusually long synchronous rule may still pause the spinner briefly.
Compatibility
Verification
Summary by CodeRabbit