mikado-method

A discipline for restructuring code whose true dependency graph is not knowable in advance: try it, let the compiler and tests reveal the dependencies, revert, then build the prerequisites bottom-up.

When to use

Skill structure

Four files, not one:

Precondition

A green safety net must exist (characterize-with-contracts / brownfield-harness-builder). Weak coverage produces false leaves; a CONCERNS/FAIL gate → strengthen the harness first.

The four primitives (apply exactly)

  1. Goal — one concrete, business-value-framed sentence agreed with the human (reject vague goals)
  2. Naive experiment — isolated worktree, attempt the most obvious way, run build + full suite; this is a SENSOR, never a draft
  3. Visualize — every failure is a prerequisite → graph node with an edge toward the goal; cite file:line + error
  4. Undo — discard the worktree entirely; never git stash, never keep “almost working” code; the revert is free

Exit contract

Mandatory validation (8 passes)

bash plugins/skraft-framework/skills/mikado-method/scripts/validate-mikado.sh <path-to-graph.md>

Run before every leaf commit and after every graph-update commit. Exit 0 required to proceed — never advance on an unvalidated graph.

  1. Parse — nodes, edges, classes
  2. Traceability — every non-goal node carries discovered: + error:, unless anticipated
  3. requires: reference validation — every edge must resolve to a defined node
  4. Cycle detection — across tree and requires: edges
  5. Tree-direction ancestry via git — the child’s discovered: commit must be ancestor-or-equal of the parent’s, message matching the refactor(mikado-graph): <what> prefix; gated by --no-git for fixtures
  6. Orphan detection (warning only)
  7. Golden-master gate — a “Golden Master” node or %% no-golden-master: <reason>
  8. True-leaf enumeration — ready for the next dispatch

Invariants

Why this shape

The graph survives between iterations; the failed experiment’s code is always thrown away. Mikado only works with a safety net — without tests, nothing breaks because nothing is checked, not because nothing depends on it.

« The main thing that distinguishes legacy code from non-legacy code is tests, or rather a lack of tests. » — Feathers, M., Working Effectively with Legacy Code, 2004.

Allowed customisation

See also