pinned-debt
Measure technical debt and cognitive load in any JS/TS or Python git repo with a pinned tool set (ESLint 9 + sonarjs cognitive complexity, complexipy, jscpd, git history) running inside a bubblewrap s
Files5
View on GitHubSKILL.mdskills/review/pinned-debt/SKILL.md
GitHubPinned debt analysis (bubblewrap)
pinned-debt in this skill's directory (call it by its absolute path, written <skill-dir>/pinned-debt below) installs pinned tools into ~/.cache/pinned-debt/<hash> and runs the analysis under bwrap: network off, filesystem read-only, every repo read-only, only the report dir writable.
macOS: Linux VM with shared folders
The runner uses the same pinned-skills Lima VM as pinned-eslint. Follow the one-time setup in ../pinned-eslint/SKILL.md; its lima.yaml installs the prerequisites for both skills.
Run the normal commands below from macOS. Repos stay on the Mac disk and are shared at the same absolute paths, including the real target of a ~/git symlink. No clone or sync is needed. The runner starts the existing VM, normalizes repo and output paths, and forwards --since, --print-store, PINNED_DEBT_PLUGINS, and PINNED_DEBT_PY.
Bubblewrap keeps every repo read-only and disables network access during analysis. Tool caches stay in Linux; reports under Mac /tmp use shared /private/tmp and can be opened on the Mac. Unlike pinned-eslint's editor cache, --print-store returns a Linux-only cache path.
Mount other repo roots and output directories explicitly before using them. Stop the VM with limactl stop pinned-skills to release RAM. Do not bypass the sandbox if VM setup fails.
Run
<skill-dir>/pinned-debt <repo> # one repo, report in /tmp/pinned-debt-<date>/
<skill-dir>/pinned-debt <repo> <repo> ... # many repos plus a cross-repo summary.md
<skill-dir>/pinned-debt <repo> --out /tmp/debt # choose the report dir
<skill-dir>/pinned-debt <repo> --since '6 months ago' # history window (git date, default 12 months)
<skill-dir>/pinned-debt --print-store # install if needed, print the pinned install dir, exit
- Each
<repo>must be a git work tree. - The first run per tool set runs
npm installandpip install(network, ~1 min). Later runs use the cache. - Override versions with
PINNED_DEBT_PLUGINS='pkg@ver ...'(npm) orPINNED_DEBT_PY='pkg==ver ...'(pip). Each override creates a new cache entry.
Run it in the background with a timeout. Large repos take minutes:
nohup <skill-dir>/pinned-debt <repos...> --out /tmp/debt > /tmp/debt.log 2>&1 &
timeout 900 tail -f /tmp/debt.log
What it measures
Production code only: git ls-files filtered to .ts .tsx .js .jsx .mjs .cjs .mts .cts .py. Tests (__tests__/, test(s)/, cypress/, e2e/, mocks/, *.test.*, *.spec.*, *.stories.*, test_*.py, conftest.py) and generated output (dist/, build/, coverage/, cdk.out/, node_modules/, *.d.ts, *.min.js, and any file whose first 400 bytes say "automatically generated", "auto-generated", "@generated", "Code generated by" or "do not edit") are excluded and counted separately. Test LOC is reported separately.
| Signal | Tool | Threshold | Why it matters |
|---|---|---|---|
| Cognitive complexity per function | sonarjs/cognitive-complexity (JS/TS), complexipy (Python) |
15 (Sonar default) | Nesting and breaks in linear flow: what a reader must hold in mind |
| Cognitive complexity per 100 LOC | derived | compare repos | Density, independent of repo size |
| File size | non-blank lines | 300 | Long files hide many concepts |
| Duplication | jscpd, 50 tokens min |
~3% (Sonar gate) | Copy-paste means one change must be made in many places |
| Change amplification | git log --no-merges |
10+ code files per commit | Wide commits mean no module owns the decision |
| Hotspots | commits x file cognitive complexity | top 15 | Complex code that changes often costs the most |
| Suppressions | eslint-disable, @ts-ignore, @ts-expect-error, @ts-nocheck, # noqa, # type: ignore, pylint: disable |
compare repos | Silenced checks hide the debt the other metrics would show |
Output
In --out:
summary.md: one row per repo, sorted by cognitive complexity per 100 LOC, worst first. Failed repos are listed at the end.<repo>.md: summary table, hotspots, the 15 most complex functions, largest files, largest clones.<repo>.json: the same data for scripts.
Exit code 1 means at least one repo failed; the other reports are still written.
Then read the code
The numbers find where to look. They do not judge design. For each repo, open the top 3 hotspots and the worst function, then write a short verdict:
- Concept count. How many names, types and layers must a reader hold to follow one feature?
- Shallow modules (Ousterhout). Wrappers, single-implementation interfaces and pass-through layers that add a concept and hide nothing.
- Two-minute test. Can you say what the file does and why it is shaped this way in two minutes? If not, say what blocks you.
- AI-generation smells. Repeated near-identical blocks, defensive checks for impossible states, unused options, comments that restate code.
- Capped functions, huge files. When a repo lints cognitive complexity at 15, "Max fn" sits at 15 and the load moves into files: dozens of small callbacks sharing state through refs or class fields. Judge those by the file's total cognitive score in the hotspot table, not by the per-function maximum.
Finish with a ranked list of fixes: split which function, merge which clones, delete which layer. Point to file:line.
Caveats
- The repo is never written. Any tool that tries to write into it fails, by design.
- Squash-merge history makes one commit equal one PR. Merge-commit history counts each commit. Compare change amplification only between repos with the same style.
- ESLint runs without type information, so it is fast and needs no
node_modules. Files it cannot parse are counted as "Files ESLint could not parse"; report a high count. - jscpd compares production files only. Duplicates inside tests are not counted.
- Not measured: dead code, coupling (fan-in, fan-out). Use
knipormadgeby hand if needed. - Errors such as
install bubblewrapare fatal. Report them as-is.