| name | konjo-retrofit |
| description | Retrofit the Konjo Quality Framework onto an existing repo that predates it. Use when asked to add konjo quality gates, improve code quality, audit an existing codebase, or run a quality sprint. Provides the step-by-step migration plan and triage protocol. |
| user-invocable | true |
Konjo Retrofit — Existing Repo Quality Migration
The Problem With Retrofitting Blind
Installing hard quality gates on an existing codebase without measuring first causes one of two outcomes:
- Gates fail on day 1 — blocks all work, the team disables the gates in frustration.
- Gates set too loose — they pass everything, provide no value.
The Retrofit Protocol solves this by measuring before gating, then ratcheting up incrementally.
Step 1 — Baseline Audit (measure everything, fix nothing yet)
Run these and save the output. Do not fix violations yet — establish the baseline.
npm test -- --coverage --coverageReporters=json-summary > coverage_baseline.txt
npx eslint "src/**/*.js" -f json > eslint_baseline.json
npx knip > knip_baseline.txt
npx eslint "src/**/*.js" --rule '{"complexity":["warn",10]}' -f json > complexity_baseline.json
python3 .konjo/scripts/dry_check.py --json > dry_baseline.json
npm audit --json > audit_baseline.json
find src test -name "*.js" | xargs wc -l | sort -n | tail -20 > large_files.txt
Step 2 — Triage
| Priority | Category | Definition | Handle |
|---|
| P0 | CRITICAL | Secrets in tree, injection surface, auth bypass, data corruption | Fix immediately, before framework install |
| P1 | DEBT | Coverage < 60%, swallowed errors, callback Google calls, setTimeout control flow | Fix in first 2 sprints |
| P2 | STYLE | Length violations, moderate duplication, complexity > 20 | Fix incrementally, 1-2 per sprint |
Never retrofit CRITICAL and DEBT in the same commit. Fix P0 first, measure, commit. Then P1.
Step 3 — Install Framework (at current baseline, not ideal baseline)
Install with warn-only mode for the first sprint:
bash .konjo/scripts/install-hooks.sh
Rationale: a gate that fails the day it's installed gets disabled. Set it just above current, then ratchet.
Step 4 — The Coverage Ratchet
| Sprint | Coverage Gate | Action |
|---|
| Sprint 0 (install) | current − 2% | No regressions allowed |
| Sprint 1 | current | Hold the line |
| Sprint 2 | current + 5% | Write missing tests |
| Sprint N | 80% | Hard floor (production gate) |
| Long-term | 95% | Target |
Never move the gate backward.
Step 5 — Complexity and Length Ratchet
For each oversized function or file (one at a time):
- Write a characterization test first — capture current behavior before touching anything.
- Make the smallest refactor that improves the metric.
- Run the full suite — all tests must pass; coverage must not decrease.
- Commit:
refactor(scope): extract X into Y [complexity 23→11, lines 80→35].
Never refactor + change behavior in the same commit. (This is exactly how the songscraper
formatter was migrated: capture the legacy payload as a fixture, then refactor against it.)
Step 6 — DRY Cleanup
Run dry_check.py --json, sort by similarity descending, address highest-similarity first. For each:
identify the canonical version, test it, replace duplicates with calls to it, confirm tests pass.
Step 7 — Activate Wall 3 (adversarial review)
After Walls 1 and 2 are stable (≥ 2 consecutive clean CI runs):
python3 .konjo/scripts/konjo_review.py --soft-fail
python3 .konjo/scripts/konjo_review.py
Add ANTHROPIC_API_KEY to GitHub Actions secrets before enabling.
Node Repo Checklist
The Shipbuilder's Checklist (Final Verification)
If any of these are false, the retrofit is not complete.