{"slug":"mikado-method","title":"mikado-method","summary":"Use to refactor or restructure existing code IN PLACE when the change is likely to break things in ways that are hard to predict up front — drive the Mikado Method loop: attempt the change naively, capture what breaks as prerequisite graph nodes, revert, and implement bottom-up f","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-11-29T00:42:31.150818Z","repo":{"url":"https://github.com/SebastienDegodez/skraft-plugin","stars":17,"forks":3,"license":"GPL-3.0","updatedAt":"2026-11-29T00:18:21Z"},"bodyHtml":"<hr>\n<h2>name: mikado-method\ndescription: \"Use to refactor or restructure existing code IN PLACE when the change is likely to break things in ways that are hard to predict up front — drive the Mikado Method loop: attempt the change naively, capture what breaks as prerequisite graph nodes, revert, and implement bottom-up from the leaves, always keeping the codebase green. Loaded internally by brownfield-refactorer when the human chooses in-place restructuring over Strangler Fig.\"\ndisable-model-invocation: true</h2>\n<h1>Mikado Method</h1>\n<p>A discipline for restructuring code whose true dependency graph is not knowable in advance: try\nthe change, let the compiler and test suite reveal what it actually depends on, revert, then build\nthe missing prerequisites bottom-up. The graph is the artifact — the failed experiment's code is\nalways thrown away.</p>\n<p><strong>Precondition.</strong> A green safety net must exist before starting (see <code>characterize-with-contracts</code>\n/ <code>brownfield-harness-builder</code>). Mikado surfaces prerequisites via real compiler/test failures — a\ncodebase with weak or no test coverage gives false leaves (nothing breaks because nothing was\nchecked, not because nothing depends on it). If the harness gate was CONCERNS or FAIL, stop and\nstrengthen the harness first.</p>\n<h2>The loop (four primitives — apply exactly)</h2>\n<ol>\n<li><strong>Goal</strong> — one concrete, business-value-framed sentence agreed with the human. \"Admin services\nare in a separate package deployable without customer services\" is a goal. \"Improve the\narchitecture\" is not — reject vague goals, ask the human to sharpen it.</li>\n<li><strong>Naive experiment</strong> — in an isolated worktree (<code>git worktree add &lt;path&gt; &lt;branch&gt;</code>), attempt the\ngoal the most obvious way, no scaffolding. Run the build. Run the full test suite (harness\nincluded). This experiment is a SENSOR, not a draft — never polish it, never try to fix what\nbreaks.</li>\n<li><strong>Visualize</strong> — every failure is a prerequisite: something that must be true before the goal is\nachievable. Record it as a graph node with an edge pointing toward the goal (or toward the\nprerequisite it was discovered under, if nested). Cite the evidence: file:line + error message.</li>\n<li><strong>Undo</strong> — discard the worktree entirely (<code>git worktree remove &lt;path&gt; --force</code>). Never <code>git stash</code>, never keep \"almost working\" code. The revert is free for an agent — there is no sunk\ncost. Return to the last known-green state.</li>\n</ol>\n<p>Repeat the loop on each prerequisite (and its own prerequisites) until reaching leaves —\nprerequisites with no unimplemented children. Leaves are implemented for real, on the actual\nbranch, one at a time, committing green after each. Never start a parent until all its children\nare done.</p>\n<h2>Graph persistence (the durable artifact)</h2>\n<p>Persist the graph to <code>.copilot-tracking/skraft-plans/{projectSlug}/refactoring/{YYYY-MM-DD}/ mikado-&lt;slug&gt;.md</code> as a Mermaid <code>graph TD</code>. Minimal skeleton (read\n<a href=\"references/graph-format.md\">references/graph-format.md</a> for the full annotated spec — node\nshapes, the <code>discovered:</code>/<code>error:</code> traceability fields, <code>requires:</code> cross-links for shared\nprerequisites, and the golden-master gate — before writing the first node):</p>\n<pre>graph TD\n  G((Goal: &lt;one sentence&gt;))\n  classDef observed fill:#2e7d32,stroke:#66bb6a\n  classDef anticipated fill:#e65100,stroke:#ff9800,stroke-dasharray:5 5\n  P1[\"[ ] {P1} &lt;prerequisite&gt;&lt;br/&gt;discovered: &lt;sha&gt;&lt;br/&gt;error: &lt;file:line: msg&gt;\"]\n  G --&gt; P1\n  class P1 observed\n</pre>\n<p><code>[ ]</code> / <code>[x]</code> = pending / done, marked in the SAME commit as the leaf's implementation. <code>observed</code>\n= a real naive-experiment failure. <code>anticipated</code> = a hypothesis not yet confirmed by an experiment\n— confirm or refute it with a real attempt before treating it as a true prerequisite. One writer on\nthis file per run (the <code>brownfield-refactorer</code> agent); reload it at every re-grounding boundary\n(before each leaf, after each spawn returns) rather than trusting recall.</p>\n<p><strong>Commit convention (required for the tree-direction check below).</strong> Every graph-update commit\n(creating the file, recording a new discovery) uses the message prefix <code>refactor(mikado-graph): &lt;what&gt;</code> — matching this repo's existing conventional-commit scopes (<code>feat(scope):</code>, <code>docs(scope):</code>).\nExample: <code>refactor(mikado-graph): {P1} requires {P2} in src/Admin.cs:40</code>.</p>\n<h2>Mandatory validation gate (S7 — never assert graph validity from recall)</h2>\n<p>Run the deterministic validator before every leaf commit and after every graph-update commit:</p>\n<pre><code>node \"&lt;skill&gt;/scripts/validate-mikado.mjs\" &lt;path-to-graph.md&gt;\n</code></pre>\n<p><code>&lt;skill&gt;</code> is this skill's folder, the one holding this SKILL.md.</p>\n<p>Exit 0 = valid, safe to proceed. Exit non-zero = STOP and fix the graph first — never proceed on a\ngraph the script has not validated. Eight passes: (1) parse nodes/edges/classes; (2) traceability\n— every non-goal node (unless <code>anticipated</code>) carries <code>discovered:</code> + <code>error:</code> evidence; (3) every\nedge (<code>--&gt;</code> and <code>-.requires.-&gt;</code>) resolves to a defined node id — an unresolved reference is reported\nas exactly that, never left to masquerade as a cycle; (4) no cycle exists across tree and\n<code>requires:</code> edges; (5) tree direction — each child's <code>discovered:</code> commit exists, matches the\n<code>refactor(mikado-graph):</code> prefix, and is an ancestor-or-equal of its parent's commit (skip with\n<code>--no-git</code> for fixtures/examples with fictional SHAs — never on a real graph); (6) orphan detection\n(warning only) — a node never referenced by any edge; (7) a golden-master node or an explicit\n<code>%% no-golden-master: &lt;reason&gt;</code> declaration is present; (8) enumerates the true leaves (pending\nnodes with no pending children) ready for the next dispatch.</p>\n<h2>Driving leaves to completion (per-leaf worker contract)</h2>\n<p>Each leaf is dispatched to <code>refactoring-worker</code> as a fresh, isolated unit — one spawn per leaf,\nnever accumulate leaves in one session (context drift risk). The dispatch packet MUST include:</p>\n<ol>\n<li>The full current graph file content.</li>\n<li>The specific leaf to implement, verbatim, with its evidence citation.</li>\n<li>Acceptance: the harness (characterization + contract tests) passes; the full regression suite\npasses; no new failures anywhere; the change is scoped strictly to this leaf — nothing else;\n<code>scripts/validate-mikado.mjs</code> exits 0 after marking the leaf <code>[x]</code>.</li>\n<li>The explicit instruction: if this leaf turns out to have its own unimplemented prerequisites,\nSTOP and report them as new sub-prerequisites. Do not attempt to fix them inline.</li>\n</ol>\n<h2>Terminal signals (worker -&gt; orchestrator)</h2>\n<p>The worker reports exactly one of these per invocation — this is the drive-to-terminal-state\ncontract the <code>brownfield-refactorer</code> orchestrator polls:</p>\n<ul>\n<li><code>ADVANCE</code> — this leaf is done and committed green; more leaves remain.</li>\n<li><code>EXPAND</code> — this leaf had its own undiscovered prerequisites; new graph nodes were recorded;\nno code was implemented or committed for this leaf.</li>\n<li><code>DONE</code> — the goal is achievable cleanly now (verified by a final naive re-attempt that no longer\nbreaks); the graph is empty of unimplemented leaves.</li>\n<li><code>BLOCKED</code> — needs human input (ambiguous prerequisite, conflicting constraint, harness itself\nbroke in a way the worker cannot diagnose, or <code>validate-mikado.mjs</code> reports an error the worker\ncannot resolve on its own).</li>\n</ul>\n<h2>Common failure modes (reject these)</h2>\n<ul>\n<li><strong>Skipping the revert</strong> — \"I'll keep this working code and clean up later.\" This is how the\nmethod's guarantee (codebase never broken) is lost. Always revert; always start the leaf fresh\non the real branch.</li>\n<li><strong>Fixing during the naive experiment</strong> — the experiment collects signal only; patching mid-attempt\ncontaminates the failure list.</li>\n<li><strong>Treating the graph as optional documentation</strong> — it is the only artifact that survives between\nloop iterations; if it is not reloaded before each leaf, prerequisites get re-discovered or missed.</li>\n<li><strong>Running the naive experiment against a shared/live environment</strong> — always an isolated worktree;\nstale state (caches, migrations) produces false signal otherwise.</li>\n<li><strong>Skipping the validation gate</strong> — marking a leaf <code>[x]</code> or starting a parent without a clean\n<code>validate-mikado.mjs</code> run first. The script is cheap; a corrupted graph discovered three leaves\nlater is not.</li>\n</ul>\n<p>Read <a href=\"references/worked-example.md\">references/worked-example.md</a> for a full traced example\n(naive experiment through leaf execution) the first time this skill runs in a session, or when a\nconcrete reference shape is needed for a dispatch packet.</p>\n","files":[{"path":"LICENSE.md","sizeBytes":1970,"isText":true},{"path":"references/graph-format.md","sizeBytes":6439,"isText":true},{"path":"references/worked-example.md","sizeBytes":3562,"isText":true},{"path":"scripts/validate-mikado.mjs","sizeBytes":10050,"isText":false},{"path":"SKILL.md","sizeBytes":8516,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-11-29T00:44:05.90972Z","sha256":"8F8E2D1550BC01A189FA1411756E0B14D1AC6D5F8CC202C2FDFD19305B1D3ABA","sizeBytes":13599},"review":null,"source":{"repositoryUrl":"https://github.com/SebastienDegodez/skraft-plugin","path":"plugins/skraft-framework/skills/mikado-method","license":"GPL-3.0","commit":"c6117c6236a25490bf1916b131866069740c9b22","subtreeSha":"E9C6E661950149A4AEAFC0711B1EA3D5CBE2B55DECF66263597282E6120F3682","lastSyncedAt":"2026-11-29T00:42:27.348488Z"},"reviewedAt":"2026-11-29T00:47:35.590295Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/SebastienDegodez/skraft-plugin/tree/main/plugins/skraft-framework/skills/mikado-method"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install sebastiendegodez-skraft-plugin@llmmart"},{"target":"git","command":"git clone https://github.com/SebastienDegodez/skraft-plugin.git"}]}