react-doctor icon indicating copy to clipboard operation
react-doctor copied to clipboard

feat(react-doctor): interactive code-health TUI as a `tui` subcommand

Open aidenybai opened this issue 6 months ago • 1 comments

Adds an interactive React code-health terminal UI to react-doctor, available as a tui subcommand. Built on Ink, with a focused single-screen dashboard, monorepo project picker, watch mode, and a master/detail diagnostic browser.

react-doctor tui .                       # picker if monorepo, else dashboard
react-doctor tui . --watch               # rescan on file changes
react-doctor tui . --review              # open straight into the diagnostic browser
react-doctor tui . --project ami         # preselect a workspace package

Project picker (monorepo support)

Mirrors the standard CLI's selectProjects behaviour, but as an Ink screen since the TUI owns the TTY. Shown only when 2+ React workspace packages are discovered:

~/projects/ami

  Multiple React projects found. Pick one to scan:

    ami    packages/ami
  ▸ admin  packages/admin
    docs   packages/docs

  [↑↓] move  [↵] scan this project  [q] quit
  • Reuses listWorkspacePackages → discoverReactSubprojects fallback from the existing CLI.
  • 0 packages → scan the root directly. 1 package → auto-select. 2+ → picker.
  • --project <name|basename> skips the picker for non-interactive flows (e.g. inside an editor task).

Dashboard

Answers three questions, in order:

  1. How healthy is the codebase? → score gauge with delta vs. last scan
  2. What's most broken? → focused issue with rule, message, help, file:line, and a source-snippet preview
  3. What else? → compact list of remaining rules with site counts
~/projects/ami

  ┌─────┐  82 / 100 Great  ▲ 4
  │ ◠ ◠ │  █████████████████████████░░░░░
  │  ▽  │
  └─────┘

  ✗ react-doctor/no-fetch-in-effect  2 sites
    Avoid fetch inside useEffect.
    → Use a data-fetching library like TanStack Query.

      src/UserCard.tsx:42
       40│   const [user, setUser] = useState(null);
       41│   useEffect(() => {
     ▸ 42│     fetch(`/api/${id}`).then(r => r.json()).then(setUser);
       43│   }, [id]);

      + 1 more site

  ⚠ no-array-index-as-key           5 sites

  Last scan 2.3s · 7 issues across 6 files · ● watching

  [d] review  [r] rescan  [w] watch off  [?] help  [q] quit

Header is just the project path (home-dir aware: ~/foo/bar). Watching status, scan elapsed time, and offline mode all live in the single-line footer where they belong. The doctor face stays as the cute 4-line ASCII branding next to the score; mood tracks the score.

Review screen

Master/detail diagnostic browser with severity-coloured rule list, source-snippet preview, and an inline filter (/) that searches across rule, plugin, category, message, and file path. Stacks vertically on narrow terminals.

How it's wired up

  • ScanReporter interface and discriminated ScanEvent union added to react-doctor/api. scan() emits structured events alongside its existing stdout output. When no reporter is supplied, behaviour is unchanged.
  • The TUI lives in-package at src/tui/ and ships as a separate vite-plus build entry (dist/tui.js). The CLI lazy-loads it on demand so non-TUI scans never touch Ink/React/chokidar.
  • chokidar watch loop with debounce.
  • useTerminalSize hook subscribes to stdout resize events; layout adapts at 60- and 90-col breakpoints (score bar shrinks, review panes split master/detail vertically).
  • TTY guard with a clear fallback message for non-interactive shells.
  • During scanning, a single inline spinner with active step + M/N counter — not a 10-row checklist.
  • Re-scans keep the dashboard visible and append rescanning… to the footer.
  • Errored scans render a red one-line banner above the score gauge with a recovery hint.
  • Empty scans show ✓ No issues detected — nice work.

Doctor-face fix

The "first 1-2 lines show double" rendering glitch was a width mismatch: the eyes row (│ ◠ ◠ │ = 7 chars) and the mouth row (│ ─ │ = 5 chars) had different widths, so Ink's incremental redraw left stale chars from the previous frame on the shorter row. Every frame across every mood is now exactly 5 inner chars; a unit test enforces this. Animation interval slowed from 240ms to 480ms; a setTimeout leak in the blink scheduler is plugged.

Validation

  • pnpm format — clean
  • pnpm lint — 0 warnings, 0 errors
  • pnpm typecheck — clean
  • pnpm test — 662 tests passing across 55 test files
  • pnpm build — dist/tui.js builds alongside dist/cli.js, dist/index.js, and the lint plugins

Out of scope (follow-ups)

  • Apply-suppression action that writes a react-doctor-disable-next-line comment from the review screen.
  • Open-in-$EDITOR jump from the detail pane.
  • Multi-project scan in a single TUI session (currently one project per session).
  • Persisting score history to .react-doctor/history.json so the trend survives across runs.
Open in Web Open in Cursor 

aidenybai avatar May 08 '26 10:05 aidenybai

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-doctor-website Ready Ready Preview, Comment May 8, 2026 1:03pm

vercel[bot] avatar May 08 '26 10:05 vercel[bot]