You are performing a read-only quantitative analysis of <TARGET> using the RP/OP pressure model defined below, plus standard supporting metrics. Use real tools — do NOT eyeball the code. All assumptions must be stated explicitly.
- Find
<TARGET>(index/grep/glob — whichever is best). - Detect primary language(s): count files by extension (use
scc/tokei/cloc/ad-hoc count). If multi-language, either pick the dominant language and state it, or analyze each separately. - Confirm scope: list analyzed files, total LOC, and exclusions (tests, generated code, vendored deps, fixtures, mirror worktrees, sample/dev configs). Be explicit.
- If
<TARGET>doesn't exist or has no tractable codebase → stop and report.
RP = 0.6 × Peak + 0.4 × Base
combined = max_complexity × 0.6 + p90_complexity × 0.4
Peak = 100 × (1 − exp(−0.08 × combined)) × scale
density = (total_complexity / loc) × 100
Base = 100 × (1 − exp(−0.02 × density × scale))
- CC over all functions/methods.
loc= code lines (no blanks, no comments). Defaultscale = min(1, loc/5000)— state your choice.
Build an intra-project dependency graph (modules and/or classes).
class_score = (0.35·fan_out_norm + 0.25·fan_in_norm + 0.25·depth_norm + 0.15·centrality_norm) × 100
OP = (0.4·coupling_norm + 0.6·avg_class_score_norm) × 100
depth— inheritance (preferred) or import-chain (state which). External base = +1.centrality— betweenness on the dep graph.coupling— edge density of dep graph OR average fan_out (state which).- Normalize each to [0, 1] (min-max or a sensible cap — document).
Score = (RP + OP) + k × |RP − OP| # default k = 0.5
Report RP, OP, Score, and the penalty term separately.
RP ≫ OP→ vermicelli / dense branchy logic.OP ≫ RP→ abstraction labyrinth.- both low → healthy. Both high → diffusely degraded (not "balanced").
You need tools for: (a) cyclomatic complexity per function, (b) LOC excluding blanks/comments, (c) type-check / lint signal, (d) dependency-graph extraction, (e) maintainability index or equivalent, (f) graph metrics (centrality, cycles), (g) tabular aggregation.
You must discover the current best-fit tools at the moment this prompt is run. Do NOT rely on your training-time knowledge of tool names — that snapshot may be stale or wrong. Procedure:
- Check what's already installed. Try the obvious candidates you remember; if a tool is on
PATHand produces sensible output on a single file, you can use it. - For each missing slot, research current options. Acceptable research paths, in order of preference:
- Look at the project's own configs (
pyproject.toml,package.json,go.mod,Cargo.toml,.golangci.yml,.eslintrc,pre-commit-config.yaml, CI files) — whatever the team already uses is usually a fine choice and won't conflict with their assumptions. - Web search (if web access is available) with a query like
"<language> cyclomatic complexity cli 2026"or"<language> dependency graph static analysis". Restrict to results from the last ~24 months. - Awesome-lists for the language (
awesome-<lang>,awesome-static-analysis) — they're usually maintained. - Package registry top-results:
pypi.org,npmjs.com,crates.io,pkg.go.dev, etc. — sort by recent activity / downloads.
- Look at the project's own configs (
- Verify each candidate before adopting it:
- Last release within ~18 months (or actively maintained — recent commits).
- Supports the target language version.
- Produces machine-readable output (JSON, SARIF, CSV, or stable text) — if it only prints a human-readable summary, it's much harder to aggregate.
- Installable without root / system pollution (language package manager, single binary, container).
- License is acceptable for the project.
- Pick one tool per metric slot. Briefly note why (e.g. "team already uses it", "only one that emits JSON", "covers all source files including .pyi"). If two tools disagree on a number, prefer the one closest to the team's existing toolchain and report the delta.
- Install into an isolated environment under
docs/artifacts/.toolchain/<lang>/(venv, local npm prefix, GOBIN, cargo install --root, etc.). Neversudo. Never modify global state.
Fallback path — if the language has no good tooling at all (or you can't get anything to run in this environment):
- Use
tree-sitter(orast-grep) as a universal AST extractor and write a small script to compute CC, fan-in/fan-out yourself. - Use the language's own AST library if there's a host runtime available (e.g.
astin Python,@typescript-eslint/parserin JS). - If even that fails, stop and report — do not invent numbers from a regex grep.
A required Tools used table:
| Metric | Tool | Version | Why this one | Output format |
|---|
Anything you discovered but rejected (and why) goes in Limitations & assumptions.
- Per-file: LOC, total CC, max CC, density, MI (or equivalent). Top-10 worst by each.
- Top-10 functions/methods by CC with
file:line. - Top-10 classes/modules by
class_score. - Type-check/lint signal: error & warning totals, top-10 files by count, error-rule histogram (summarize categories, don't dump every line).
- Cycle detection in dep graph.
Aggregate via DataFrame/table. Save raw per-entity data as CSV under docs/artifacts/<target>_metrics_<timestamp>.csv.
- Dominant pressure: RP-heavy / OP-heavy / healthy / diffusely degraded.
- 3–5 concrete hot spots, each with a one-line metric-based reason.
- Pressure cluster: name the sub-package/dir dragging the score if any.
- Fix 3 things — ranked by leverage, each with an expected delta in RP/OP/Score.
Be honest: if the project is clean, say so. If a metric is non-informative for this codebase (no inheritance, no internal coupling), say so. If a measurement artifact dominates the numbers, explain it.
- Scope confirmed: files, LOC, exclusions.
Tools usedtable is present and every number in the report is traceable to a tool in it.- RP, OP, Score computed; scale / normalization /
kdocumented. - Top-N tables present for: files, functions, classes, MI, type-check.
- Dep graph stats: nodes, edges, density, cycles.
- Raw CSVs saved under
docs/artifacts/. - Diagnosis names dominant pressure, hot spots with metric reasons, fix-3 with expected deltas.
- Limitations & assumptions explicit (including which candidate tools you considered and rejected).
If you hit a hard blocker (no tooling installable, language unsupported, target empty) → stop and report. Don't fabricate.
Single Markdown report:
- Scope — root, files, LOC, language mix, exclusions.
- Tools used — the table from §2.
- Methodology — formulas, scale/normalization,
k. - Headline numbers — RP, OP, Score, penalty, verdict.
- Top-N tables.
- Dep graph stats.
- Diagnosis — hot spots with metric reasons.
- Fix 3 things — with expected Score delta.
- Limitations & assumptions — including rejected tool candidates.
- Artifacts — paths to CSVs, scripts, isolated toolchain envs under
docs/artifacts/.
Dense, quantitative. Numbers before narrative.
<TARGET>— directory/component/repo path.- Optionally pass
LANGUAGE=<lang>to skip auto-detection.