feat: codebase metrics (METRICS.md) and bootcamp doctor command#46
Merged
Conversation
Add two deterministic features following the existing analyzer pattern: - Codebase Metrics & Hotspots: new src/metrics.ts computes language breakdown, file/dir hotspots, test:source ratio, size class, and a 0-100 approachability score (grade A-F). Emits METRICS.md, gated by a new showMetrics style-pack section (on for all packs except minimal). Threaded through analysis orchestration and the main command summary. - Environment Doctor: new 'bootcamp doctor' command (src/doctor.ts + command) checks Node >=20, git, gh + auth, Copilot token, mermaid-cli, and cache health. Supports --json and exits non-zero on required failures. Pure evaluateDoctor + injectable deps for testability. Exports both modules from api.ts with ./metrics and ./doctor subpaths. Adds 33 tests (15 metrics, 18 doctor); updates README + CHANGELOG. Full suite: 1018 passing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds two new deterministic capabilities to repo-bootcamp: a codebase metrics/hotspots report emitted as METRICS.md, and a new bootcamp doctor CLI command to validate a local environment before running analysis/generation.
Changes:
- Add
src/metrics.tsto compute codebase metrics (language breakdown, hotspots, directory distribution, test:source ratio, size class, approachability score) and renderMETRICS.mdwhenstyleConfig.sections.showMetricsis enabled. - Add
src/doctor.ts+bootcamp doctorcommand (with--json) to evaluate environment readiness (Node, git, gh/auth, mermaid-cli, cache). - Thread metrics through orchestration + CLI summaries, and expose both new modules via
src/api.tsandpackage.jsonsubpath exports.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/metrics.test.ts | Adds unit tests for metrics computation and METRICS.md rendering. |
| test/doctor.test.ts | Adds unit tests for doctor evaluation, formatting, CLI wiring, and JSON output. |
| test/api.test.ts | Extends export-guard coverage for new public API exports. |
| src/services/analysis-orchestration.ts | Computes metrics during output prep; conditionally emits METRICS.md; returns metrics in result. |
| src/plugins.ts | Adds sections.showMetrics to style config and all built-in style packs. |
| src/metrics.ts | Implements codebase metrics computation and Markdown doc generation. |
| src/doctor.ts | Implements environment snapshot gathering and deterministic doctor evaluation/report formatting. |
| src/commands/main-command.ts | Threads metrics through generation and prints an approachability summary line when enabled. |
| src/commands/doctor-command.ts | Implements bootcamp doctor command with colorized output, JSON mode, and non-zero exit on required failures. |
| src/cli.ts | Wires the new doctor subcommand into the CLI. |
| src/api.ts | Re-exports doctor/metrics APIs and types. |
| README.md | Documents METRICS.md and the new bootcamp doctor command. |
| package.json | Adds ./metrics and ./doctor subpath exports. |
| CHANGELOG.md | Documents the new metrics report and doctor command features. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ctor Address review feedback on PR #46: - metrics: isConfigFile now classifies dotfile env files (.env and .env.*) as config. getExtension('.env') returns '' (leading dot at index 0) and the basename wasn't recognized, so these were counted as 'other', skewing metrics on repos where env files are common. - doctor: gatherEnvironment now probes the cache directory directly with readdir. listCacheEntries() deliberately swallows readdir errors and returns [], so the surrounding try/catch could never observe a real read failure (e.g. EACCES); the probe re-throws non-ENOENT errors so the existing cacheError warning path actually fires. ENOENT (cache not yet created) stays a clean zero-entry result. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/metrics.tscomputes a language breakdown, largest-file and top-directory hotspots, the test:source ratio, a codebase size class, and a 0-100 approachability score (grade A-F) using additive, clamped penalties. It emits a newMETRICS.mdartifact so a newcomer can size up a repo at a glance.bootcamp doctorcommand (src/doctor.ts+ command) diagnoses Node >= 20, git, GitHub CLI + auth, Copilot token env vars, mermaid-cli, and analysis-cache health, giving users a fast way to confirm their machine is ready before running a generation.Approach notes
prepareOutputDocuments(pure and instant fromscanResult.files, so no extra analysis phase) and threaded throughanalysis-orchestrationandmain-command, including a CLI summary line.METRICS.mdoutput is gated behind a newshowMetricsstyle-pack section (on for corporate/startup/oss/academic, off for minimal), so existing fixtures that omit the field stay valid.evaluateDoctorcore with injectablegather/log/exitdeps so tests never spawn processes or call realprocess.exit. It supports--jsonand exits non-zero when a required check fails (useful in CI/scripts).api.tswith new./metricsand./doctorsubpath exports inpackage.json.Type of change
Testing
npm run lintnpm run buildnpm testFull suite: 1018 passing (985 baseline + 15 metrics + 18 doctor). Also smoke-tested the built CLI end to end:
node dist/cli.js doctoranddoctor --jsonboth render correctly and return the expected exit codes. Theapi.tsexport-guard test was updated to include the new runtime exports.Checklist
Linked issues
N/A
Breaking changes
Note:
StyleConfig.sectionsgains a requiredshowMetricsfield, butgetStyleConfigalways merges from a base pack that supplies it, andtsconfig.build.jsonexcludes tests, so no consumer or fixture breaks.