/maxi:migrate-from-brownfieldfrom maxi
Use when the user invokes /maxi:migrate-from-brownfield or asks to reverse-engineer an existing brownfield codebase into spec.md baselines so a project with code but no specs can adopt spec-driven development — discovers feature boundaries, drafts as-built specs verified against code, writes them at status done with origin provenance
Ships in maxi. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Reverse-engineers an existing codebase into faithful, traceable spec.md
baselines so a brownfield project can adopt spec-driven development. The skill
discovers feature boundaries, drafts an as-built spec per boundary,
adversarially verifies each draft against the real code, and writes the
accepted ones at status: done with origin: reverse-engineered provenance.
It produces specs and nothing else (Constitution Principle VI). The done-on-creation behavior is sanctioned by the constitution's migration-ingress clause and ADR-0011.
This is a coordinator. The deterministic file-ops live in
brownfield.sh (guard | write-spec | exclude); the
agent work lives in three subagent briefs. The skill orchestrates them and owns
the interactive gates — it does NOT reimplement their logic.
Show every vetted draft to the user and wait for an explicit accept or edit
before writing any file. No exceptions.
| Rationalization | Reality |
|---|---|
| "Discovery was confident about this boundary" | Still show the draft. Still ask. |
| "The verifier already checked it against code" | Verification is not consent. Still ask. |
| "The user already ran the command" | That starts the run; it is not per-spec consent. Still ask. |
| "The user said 'go ahead' earlier" | That applied to the draft already shown. Ask again for this one. |
| "There are too many boundaries to ask each time" | Ask per draft anyway. Serial consent is the rule. |
Violating the letter of this rule violates its spirit.
Resolve brownfield_script from the exact loaded migrate-from-brownfield/SKILL.md path (canonicalize its directory with cd -P and require adjacent brownfield.sh to be a readable regular, non-symlink file; never rely on a client-relative skills/... path):
brownfield_script="$(cd -P "$(dirname "$loaded_skill")" && pwd)/brownfield.sh"
test -f "$brownfield_script" && test ! -L "$brownfield_script"
bash "$brownfield_script" guard
Run that guard from the project root first:
/maxi:constitution first." (and suggest /maxi:migrate-adr separately for ADRs).digraph migrate_brownfield {
"guard (brownfield.sh)" [shape=diamond];
"STOP: prerequisites / provenance failed" [shape=box];
"Resolve source SHA (git rev-parse HEAD)" [shape=box];
"Build exclusion set from docs/maxi/specs/*/spec.md" [shape=box];
"Dispatch multi-modal discovery (parallel)" [shape=box];
"Dedup candidates (Jaccard >= 0.5 / subset)" [shape=box];
"Present boundary map: edit / select" [shape=box];
"Nothing selected / all excluded?" [shape=diamond];
"Report nothing-new, exit" [shape=box];
"Per selected boundary: draft-agent" [shape=box];
"verify-agent (DIFFERENT agent)" [shape=box];
"Consent gate: accept / skip / edit" [shape=diamond];
"write-spec (brownfield.sh)" [shape=box];
"Skip — no file" [shape=box];
"Report summary + next steps" [shape=box];
"guard (brownfield.sh)" -> "STOP: prerequisites / provenance failed" [label="exit 1/2/3"];
"guard (brownfield.sh)" -> "Resolve source SHA (git rev-parse HEAD)" [label="exit 0"];
"Resolve source SHA (git rev-parse HEAD)" -> "Build exclusion set from docs/maxi/specs/*/spec.md";
"Build exclusion set from docs/maxi/specs/*/spec.md" -> "Dispatch multi-modal discovery (parallel)";
"Dispatch multi-modal discovery (parallel)" -> "Dedup candidates (Jaccard >= 0.5 / subset)";
"Dedup candidates (Jaccard >= 0.5 / subset)" -> "Present boundary map: edit / select";
"Present boundary map: edit / select" -> "Nothing selected / all excluded?";
"Nothing selected / all excluded?" -> "Report nothing-new, exit" [label="yes"];
"Nothing selected / all excluded?" -> "Per selected boundary: draft-agent" [label="no"];
"Per selected boundary: draft-agent" -> "verify-agent (DIFFERENT agent)";
"verify-agent (DIFFERENT agent)" -> "Consent gate: accept / skip / edit";
"Consent gate: accept / skip / edit" -> "write-spec (brownfield.sh)" [label="accept / edit"];
"Consent gate: accept / skip / edit" -> "Skip — no file" [label="skip / ambiguous x2"];
"write-spec (brownfield.sh)" -> "Report summary + next steps";
"Skip — no file" -> "Report summary + next steps";
}
Run brownfield.sh guard before discovery. On exit 0, resolve
SHA=$(git rev-parse HEAD) and keep that commit fixed throughout this run.
The guard rejects staged, unstaged and non-ignored untracked changes outside these adoption artifacts only:
docs/maxi/constitution.mddocs/maxi/adr/README.mddocs/maxi/adr/NNNN-*.md (direct Markdown files)docs/maxi/specs/NNNN-*/spec.md (one level below specs/)NNNN is exactly four digits. Other files under docs/maxi/ receive no
exemption. Pass the captured SHA to discovery, drafting and verification agents;
source evidence must come from Git-tracked files, not ignored local/build files.
Keep source and HEAD unchanged during those reads. If either changes, discard
the affected drafts and restart discovery and verification from a fresh guard
and SHA. Updating only an old draft's --sha is not re-verification.
Read existing docs/maxi/specs/*/spec.md to build the exclusion set so re-runs are
resumable. For each candidate, decide with:
bash "$brownfield_script" exclude --name <name> --paths <p1,p2,...>
exclude → already documented; drop it.flag → partial overlap; surface to the user, never auto-exclude.keep → new; propose it.Matching is path-overlap primary (against reverse-engineered specs' file:line
refs); a name token-set fallback covers ref-less forward-pipeline specs. Both
live inside brownfield.sh exclude — do not reimplement.
Dispatch discovery in parallel (REQUIRED SUB-SKILL: maxi:dispatching-parallel-agents)
using discover-subagent.md — one agent per lens
(directory, entrypoint, manifest, route), each passed the exclusion set.
Each returns BoundaryCandidate[] with backing_paths evidence.
Dedup the merged candidates: merge two when their backing_paths sets overlap
by Jaccard ≥ 0.5 or one is a subset of the other (union paths, keep the longer
name, record all lenses). Overlap > 0 but below threshold → keep both, mark
"possibly related".
Present the deduped map. The user may collapse / split / rename / sequence and select which boundaries to document this run. If discovery returned nothing (a structureless monolith), propose a single whole-project floor candidate the user can split.
For each selected boundary, run draft-agent → verify-agent:
draft-subagent.md → DraftedSpec (full
maxi schema, as-built scenarios, file:line on every FR).verify-subagent.md — a different
agent — → Verdict with a corrected revised_spec_markdown. The user only ever
sees a vetted draft.For each vetted draft, show it and ask:
"Record this boundary as a spec baseline? (accept / skip / edit)"
| Response | Action |
|---|---|
accept | Write it (see below). |
edit | Apply the user's amendments, then write immediately — no second confirmation. |
skip | No file written. |
Ambiguous ("ok", "sure", "looks good", silence): do not infer. Re-ask once
naming the verbs. If the second response is still ambiguous, default to skip.
No file is written without an explicit accept or edit — both write; nothing
else does.
On accept/edit, first check for a slug collision — write-spec auto-numbers
NNNN but does not detect a duplicate slug suffix, so grep docs/maxi/specs/
for an existing *-<slug> directory. If one exists, ask the user for a disambiguating
suffix and use that. Then write the vetted markdown to a temp file outside the
Git project (for example, mktemp /tmp/maxi-brownfield-body.XXXXXX) and run:
bash "$brownfield_script" write-spec --slug <slug> --body <file> --sha "$SHA"
write-spec computes NNNN from the current max at write time, emits the
frontmatter (status: done, origin: reverse-engineered, source_sha) and the
## Migration Notes section. Never hand-write that frontmatter. Writes are
serial, so numbering stays race-free. Before creating any spec directory,
write-spec repeats the source guard, verifies that --sha resolves to a real
commit and still matches HEAD, and records its full commit ID. On rejection it
writes no spec. Restart from Step 1 after source or HEAD changes; clean up the
external body file after use.
Summarize what was written (slugs + paths), what was skipped, and that originals
are untouched. Suggest re-running to document more boundaries, or /maxi:migrate-adr
for the ADR log.
| Condition | Behaviour |
|---|---|
No docs/maxi/constitution.md | guard exits 2 → stop, point to /maxi:constitution |
| No recognized code | guard exits 3 → stop cleanly |
| No Git commit or uncommitted source outside the listed artifacts | guard / write-spec exit 1 with a provenance error; stop without publishing |
--sha is not a commit or no longer equals HEAD | write-spec exits 1 before creating a spec directory; restart discovery and verification |
| Structureless repo (no clean boundaries) | Propose a single whole-project floor candidate |
| Slug suffix already used by another spec dir | Coordinator greps docs/maxi/specs/*-<slug> before writing and asks for a disambiguating suffix (like /maxi:specify); write-spec only auto-numbers NNNN |
| All discovered boundaries already documented | Report nothing-new, exit cleanly |
| Verifier cannot confirm a requirement | Drop it (handled in the verify brief); never ship unsupported claims |
/maxi:constitution)./maxi:migrate-adr).plan.md / tasks.md — reverse-engineered specs land at done.When this skill emits prose that references another maxi artifact (an ADR, spec, plan, tasks, constitution, or repo file) — in an artifact body or in a chat report — render it as a relative Markdown link, not a bare slug/number/code span:
.md (an ADR slug like 0003-constitution-decoupled-from-claudemd; for generic spec artifacts use <feature-dir>/<name>, e.g. 0002-migrate-adr-review-fixes/spec; non-.md files keep their full name).related_adrs entries stay bare slugs) or within-document IDs (FR-012, section names).accept/edit → show draft first, always.accept → re-ask once, then default skip.status:/origin:/source_sha/Migration Notes → write-spec emits them.brownfield.sh exclude first.flag (partial overlap) → surface it to the user.| Mistake | Correct behaviour |
|---|---|
| Reimplementing discovery/draft/verify inline | Dispatch the subagent briefs; the skill only coordinates |
| Computing NNNN at proposal time | write-spec computes it at write time |
| Drafting an aspirational spec | As-built only — describe what the code does, FRs carry file:line |
| Skipping the boundary-map review | Always let the user edit/select before drafting |
| Documenting the whole repo at once | Let the user sequence it into waves |
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub amoutiers/maxi-superpowers --plugin maxi34 skills in this plugin
/analyzeUse when the user invokes /maxi:analyze or wants to audit spec/plan/tasks artifacts for quality issues — spec must be at status "tasked" or later; constitution is required/boardUse when the user invokes /maxi:board or wants a kanban overview of all specs and their pipeline status in the current project/brainstormingYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation)./cancelUse when the user invokes /maxi:cancel, says a feature is abandoned, dead, or will never ship — requires active spec status, explicit reason, and explicit yes/no confirmation before writing anything./clarifyUse when the user invokes /maxi:clarify or when a spec.md has open questions, [NEEDS CLARIFICATION] markers, or ambiguous FRs — status must be "specified"/constitutionUse when the user invokes /maxi:constitution, wants to establish or amend project principles, or when docs/maxi/constitution.md does not yet exist and needs to be created