| 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 on any repo. 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, team disables the gates in frustration
- Gates are 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 — just establish the baseline.
cargo llvm-cov nextest --workspace --json > coverage_baseline.json
python -m pytest --cov --cov-report=json > coverage_baseline.json
cargo clippy --workspace --all-targets --message-format json > clippy_baseline.json
ruff check --output-format json > ruff_baseline.json
RUSTFLAGS="-W dead_code" cargo check --workspace 2>&1 | grep "dead_code" > dead_code.txt
vulture . --min-confidence 60 > vulture_baseline.txt
radon cc . -n C > complexity_baseline.txt
python3 .konjo/scripts/dry_check.py --json > dry_baseline.json
find . -name "*.rs" -o -name "*.py" | grep -v target | \
xargs wc -l | sort -n | tail -20 > large_files.txt
cargo mutants --lib --jobs 2 2>&1 | tail -50 > mutation_sample.txt
mutmut run --paths-to-mutate src/ 2>&1 | tail -50 > mutation_sample.txt
Step 2 — Triage
Classify all violations into three categories:
| Priority | Category | Definition | Handle |
|---|
| P0 | CRITICAL | Security issues, data corruption bugs, race conditions | Fix immediately, before framework install |
| P1 | DEBT | Coverage < 60%, unwrap() in production paths, undocumented public APIs | 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 on the day it's installed will be disabled. Set it just above current, then ratchet.
Step 4 — The Coverage Ratchet
Coverage gates increment on a fixed schedule. Never move the gate backward.
| 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 3 | current + 10% | Continue |
| Sprint N | 80% | Hard floor (production gate) |
| Long-term | 95% | Target |
Add to PLAN.md: the current coverage gate value. Never let anyone lower it.
Step 5 — Complexity and Length Ratchet
For each oversized function or file:
Protocol (one function at a time):
- Write a characterization test first — captures current behavior before touching anything
- Make the smallest refactor that improves the metric
- Run full test suite — all tests must pass
- Run 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.
Step 6 — DRY Cleanup
Run dry_check.py --json and sort violations by similarity descending.
Address highest-similarity violations first (easiest wins).
For each violation:
- Identify the canonical location (the version with the best name/tests)
- Write a test for the canonical version if it doesn't have one
- Replace all duplicates with calls to the canonical version
- Confirm tests pass
Step 7 — Activate Wall 3 (adversarial review)
After Walls 1 and 2 are stable (at least 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.
Repo-Type Checklists
Pure Rust (lopi)
Pure Python (squish, kyro, miru, kairu, squash)
Rust + Python hybrid (kohaku, toki, drex, vectro)
Documenting the Retrofit Sprint
After each retrofit sprint, add to CHANGELOG.md:
## [vX.Y.Z] — YYYY-MM-DD — Quality Retrofit Sprint N
### Improved
- Coverage: X% → Y%
- Dead code: N warnings → 0
- Functions refactored: list them
- DRY violations resolved: list them
### Quality Gates Now Active
- Coverage gate: Z%
- Wall 1 (pre-commit): active
- Wall 2 (CI): active
- Wall 3 (adversarial review): soft-fail / blocking
The Shipbuilder's Checklist (Final Verification)
Before declaring retrofit complete, answer these:
If any of these are false, the retrofit is not complete.