ADR-001
Diamond orphan branch rewrite instead of iterative refactor
accepted · 2026-04-13 · L0 L0.5 L1 L2 L3 L4 L5 · cites 9
0ADR-001: Diamond — orphan branch rewrite instead of iterative refactor #
Context #
Legacy Nika (main, v0.79.3) had reached 322k LOC across 31 crates with 1,276 .unwrap() calls and 47 files above the 1,500-LOC cap. The single biggest correctness risk became context loss: no AI assistant could fit the whole system in a single context window. The math in ROADMAP.md is explicit — a 138k-LOC monolith (nika-core) ≈ 750k tokens ≈ 75% of a 1M-token context just to read one crate. Reviewing any non-trivial change devolved into pattern-matching against partial slices, which is how hallucinated refactors land.
Shadow-zone audit (16-agent Rust Council, 2026-04-13) confirmed 7 subsystems where documentation diverged from implementation. Incremental refactor would require untangling these in-place while maintaining compat.
Decision #
Create an orphan branch `nika-diamond` from scratch. No code inherited from main. Legacy main becomes a read-only reference via git show brouillon:path. Every line of the diamond is rewritten, not ported. 32 legacy crate directories are excluded from Cargo.toml members via the exclude key — they sit in the orphan working tree but do not participate in the workspace.
Legacy main stays frozen at v0.79.3. The diamond starts at v0.80.0 to mark the boundary. Users on v0.79.x cannot benefit until v0.90 feature parity.
Consequences #
Positive #
- Each diamond crate fits entirely in an AI context window (≤15k LOC ≈ 70k tokens ≈ 7% of 1M-token context, 10× headroom).
- Zero accumulated legacy debt admitted — each crate enters via the 12-gate protocol (see ADR-003).
- Clean APIs enforced up-front; no breaking-change migrations mid-Diamond.
Negative #
- Approximately 11–12 months to feature parity (v0.90 milestone). Substantially longer than incremental refactor.
- No interim releasable state for Diamond users; the v0.79→v0.80 cliff is real.
- 5 admitted crates at v0.80.0-alpha.x means tiny installable surface today.
Neutral #
- Legacy bug fixes (CVE-class only) require separate back-port commits on
main. None expected post-abandonment.
Evidence #
Cargo.tomllines 1–17 — 5 admittedmembers, 32 excluded legacy cratesROADMAP.mdlines 17–35 — "Why Diamond" context-window argumentCHANGELOG.mdlines 307–320 — v0.80.0-alpha.0 commit42909b1c7DIAMOND.mdlines 40–53 — orphan-branch rationale- memory:
POST_AUDIT_REVISIONS.md— 10 locked decisions, 2026-04-13
Alternatives considered #
Alt A — Iterative in-place refactor #
Split each oversized file, add gates progressively, delete unwraps crate-by-crate on main. Rejected because the ~8k-LOC nika-core/src/binding/ alone would need 4–5 ADR-scale decisions each and the audit proved human+AI context capacity would not hold across 322k LOC over 11+ months.
Alt B — Workspace overlay (additive) #
Keep main, add new crates alongside, migrate consumers lazily. Rejected because compat tax (dual APIs, feature flags, fallback logic) would re-create the 2,945-LOC resolve.rs class of file inside the new crates within months.
Related #
- ADR-003 — 12-gate admission (the quality floor every diamond crate must pass)
- ADR-004 — context-window-sized crates (the sizing rule the rewrite enables)
archive/nika-v0.79/adr/(supernovae-hq monorepo) — 8 pre-Diamond ADRs, superseded by this rewrite
Notes #
Revisit if a v0.95 feature requires legacy behavior that was never documented. Otherwise this ADR is terminal — orphan rewrites are not reverted.
read at v0.107.0 · the decision record ships with the engine