summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/commands
diff options
context:
space:
mode:
authorMorgan Lunt <morganl@anthropic.com>2026-07-08 18:42:18 -0700
committerMorgan Lunt <morganl@anthropic.com>2026-07-08 18:48:30 -0700
commit96e3e8c6af5f8a01f4d71be69201dfb7a2d5dfc1 (patch)
tree4a8b1e9b548abb3c8eb5af7e1aac716ec73f4cdb /plugins/code-modernization/commands
parent8d9e142e4ec5665f6561efef0ec10b3955e747dd (diff)
code-modernization: pilot-first uplift migration, brief-driven execution, deeper preflightmorganl/code-mod-experiment-first
/modernize-uplift migrates one representative project end-to-end and writes its lessons to analysis/<system>/PLAYBOOK.md before touching the rest. The remaining projects then fan out through a new uplift-migrate workflow, one uplift-migrator agent per project, in dependency-aware escalating batches behind a per-batch circuit breaker. A recorded per-test baseline (analysis/<system>/BASELINE.md) gates the migration, and the delta catalog reports a test framework whose runner does not support the target as its own highest-blast-radius dependency. The three execution commands (uplift, transform, reimagine) read MODERNIZATION_BRIEF.md and treat their phase's scope and entry and exit criteria as gates, so editing the brief steers execution. For a same-stack uplift the brief requires the delta catalog and applies the same ordering overrides the execution command does. /modernize-preflight opens with a short interview (scope, local build and test, bespoke build infrastructure, prior attempts, what is off limits) without blocking on the answers, reads the CI/build definition for how the system builds, escalates the smoke test to a whole-project restore and build, and adds a scope-boundary check that enumerates inbound and outbound dependencies when the system directory is a slice of a larger repository. Workflow scripts accept args delivered as either a JSON string or an object.
Diffstat (limited to 'plugins/code-modernization/commands')
-rw-r--r--plugins/code-modernization/commands/modernize-brief.md83
-rw-r--r--plugins/code-modernization/commands/modernize-preflight.md155
-rw-r--r--plugins/code-modernization/commands/modernize-reimagine.md13
-rw-r--r--plugins/code-modernization/commands/modernize-status.md8
-rw-r--r--plugins/code-modernization/commands/modernize-transform.md12
-rw-r--r--plugins/code-modernization/commands/modernize-uplift.md203
6 files changed, 438 insertions, 36 deletions
diff --git a/plugins/code-modernization/commands/modernize-brief.md b/plugins/code-modernization/commands/modernize-brief.md
index 53e4bb3d..1871ce17 100644
--- a/plugins/code-modernization/commands/modernize-brief.md
+++ b/plugins/code-modernization/commands/modernize-brief.md
@@ -15,6 +15,28 @@ interactive viewer with the data minified inside), and
stop — they come from `/modernize-assess`, `/modernize-map`, and
`/modernize-extract-rules` respectively. Run those first.
+Two more inputs are conditional:
+
+- **`analysis/$1/PREFLIGHT.md`** — read it if it exists. It records two
+ things nothing else has: the human's answers to `/modernize-preflight`
+ Check 0 (scope, whether they can build and run tests locally and how
+ long CI takes, bespoke build infrastructure, prior attempts, what is
+ off-limits) and the Check 6 **scope boundary** — whether `legacy/$1` is
+ a slice of a larger codebase, and what *outside* it depends on code
+ *inside* it. Both constrain this plan more than anything derivable from
+ the source. Never override an answer the human gave there with a guess.
+- **`analysis/$1/DELTA_CATALOG.md`** — **required** whenever the target
+ (`$2`, or your recommendation) is a newer version of the *same* stack.
+ A same-stack uplift's phase order is decided by its version deltas, not
+ by the topology alone — most of all by whether the **existing test suite
+ can even execute on the target runtime**. Phasing an uplift without the
+ catalog is planning blind; it is exactly how a test-framework migration
+ ends up scheduled last when it must come first. If the catalog is
+ missing, produce it *before* phasing — run `/modernize-uplift $1
+ <source> $2` through its Step 3 (the delta-catalog step), or spawn the
+ **version-delta-analyst** agent directly — then return here. Do not
+ guess at the deltas.
+
**Staleness check:** compare modification times. If any input is newer
than an existing `MODERNIZATION_BRIEF.md`, the brief is being justifiably
regenerated; but if an existing brief is newer than all inputs and the
@@ -37,11 +59,40 @@ component(s).
### 3. Phased Sequence
Break the work into 3-6 phases. Order by **strangler-fig** for a cross-stack
rewrite (lowest-risk, fewest-dependencies first), or **build-graph leaf-first**
-for a same-stack uplift (libraries before the apps that depend on them). Name
-the per-phase execution command: `/modernize-transform` (cross-stack module
-rewrite), `/modernize-reimagine` (greenfield rebuild), or `/modernize-uplift`
-(same-stack version bump — when the target is a newer version of the *same*
-stack, this is the path, not transform). For each phase:
+for a same-stack uplift (libraries before the apps that depend on them).
+
+For an **uplift**, leaf-first has three overrides, and getting them wrong is
+the most common way an uplift plan fails. Apply them *here*, at planning
+time. `/modernize-uplift` Step 1 re-applies the same rules at execution
+time (its list also names multi-targeting — the *technique* that satisfies
+override 3's first option), and an approved order and a re-derived one must
+never disagree — which is exactly what deciding the order without these
+would produce:
+
+1. **The test harness is not a leaf — it is a prerequisite.** Nothing
+ migrated can be validated until the tests that validate it run on the
+ target. If `DELTA_CATALOG.md` shows the test framework or its runner
+ does not support the target runtime (NUnit 2 or MSTest v1 on modern
+ .NET, JUnit 4 without the vintage engine, `nose` on Python 3, …), then
+ migrating the test framework is **Phase 1 by itself**, before any
+ production code moves.
+2. **Dependency deltas that every consumer shares force a coordinated
+ cut** (a major-version bump of an ORM, a namespace move like
+ `javax`→`jakarta`). These cannot be done leaf-first incrementally —
+ every consumer changes together — so they get their own cross-cutting
+ phase.
+3. **Shared nodes with consumers *outside* the scope** (PREFLIGHT.md's
+ scope-boundary check) need an explicit, recorded decision in whichever
+ phase touches them: keep them buildable for both old and new consumers
+ through the transition (multi-targeting, publishing for both versions,
+ a parallel artifact), expand the scope to include the consumers, or
+ accept and schedule the break. Never silently migrate a shared node in
+ place and break every consumer nobody was looking at.
+
+Name the per-phase execution command: `/modernize-transform` (cross-stack
+module rewrite), `/modernize-reimagine` (greenfield rebuild), or
+`/modernize-uplift` (same-stack version bump — when the target is a newer
+version of the *same* stack, this is the path, not transform). For each phase:
- Scope (which legacy modules, which target services)
- Entry criteria (what must be true to start)
- Exit criteria (what tests/metrics prove it's done)
@@ -53,11 +104,33 @@ stack, this is the path, not transform). For each phase:
units assume, so any time figure here would be misleading.)
- Risk level + top 2 risks + mitigation
+The named execution command **reads this brief** and treats its phase's
+scope, entry criteria, and exit criteria as binding gates. So write entry
+criteria as *checkable preconditions* ("baseline recorded in
+`analysis/$1/BASELINE.md`", "pilot playbook approved"), not aspirations —
+and tell the approver they steer execution by editing this file. An edited
+entry criterion is honored; a note in a chat is not.
+
Render the phases as a Mermaid `flowchart LR` showing **sequence and
dependencies** (Phase 1 → Phase 2 → …, with branches where phases are
independent). Do **not** use a `gantt` chart — gantt encodes calendar
durations, and this plan deliberately makes no time claims.
+**Phase 1 is a pilot, and this brief is a hypothesis.** Whenever a phase's
+units share one execution recipe (an uplift over many projects, a transform
+over many similar modules), name **one representative unit** as that
+phase's own first slice. For an uplift, `/modernize-uplift` Step 5a
+*enforces* this — it will not fan out without a pilot and its playbook; for
+the other execution commands the pilot lives here, written into that
+phase's **entry criteria**, which they read as a gate. A reviewer should
+see it in this document either way. Say explicitly in §3 that what the pilot
+surfaces (a delta the analysis missed, a prerequisite that reorders the
+phases, an environment fact nobody wrote down) is *expected* to revise
+this brief, and that a regenerated brief after the pilot is the normal
+path, not a correction. Legacy systems hide their surprises in the build
+and the runtime, not in the source; no amount of reading substitutes for
+one unit taken all the way through.
+
### 4. Business Walkthroughs
For each persona flow in `analysis/$1/topology.json` (`flows` — produced
by `/modernize-map`), a short narrative table: persona, what happens in
diff --git a/plugins/code-modernization/commands/modernize-preflight.md b/plugins/code-modernization/commands/modernize-preflight.md
index 06f7e5a0..cd433888 100644
--- a/plugins/code-modernization/commands/modernize-preflight.md
+++ b/plugins/code-modernization/commands/modernize-preflight.md
@@ -14,6 +14,49 @@ in the tree.
Run every check even when an early one fails — the point is one complete
readiness report, not the first error.
+## Check 0 — Ask the human (these answers are not in the source)
+
+Before any automated check, ask the person running this command the five
+questions below. The most expensive modernization mistakes are things a
+person who knows the system answers in seconds and that cost real money to
+discover wrong from the source alone. Ask **only** these — add none —
+and accept "don't know" for any of them.
+
+**Ask, then do not block on the answers.** None of Checks 1–6 needs one
+(Check 6 verifies the scope boundary from the source *independently* — the
+human's answer says whether a crossing *matters*, not whether it exists), so
+proceed to the checks immediately after asking and write the report with
+whatever answers exist by then. Any question still unanswered goes in the
+report **verbatim, marked as an open item the human must fill in** — it is
+not dropped. This way an interactive user answers while the checks run, a
+headless or scripted run still produces a complete `PREFLIGHT.md`, and the
+one thing that never happens is a readiness report silently missing the
+questions.
+
+1. **Scope** — Is `legacy/$1` the complete system, or one slice of a
+ larger codebase? If a slice: what *outside* it depends on code *inside*
+ it, and is breaking those consumers acceptable? (Check 6 verifies this
+ from the source independently; the human's answer says whether it
+ *matters*.)
+2. **Build & test locally** — Can this environment restore, build, and run
+ the tests? Roughly how long does the full CI pipeline take? (A pipeline
+ measured in hours changes the whole validation strategy: you cannot
+ afford to first learn you were wrong from CI.)
+3. **Bespoke build infrastructure** — Is there organization-specific build
+ or dependency-resolution machinery (an internal package feed, a custom
+ binary store, a code generator, a wrapper around the standard build
+ tool) that someone new to this codebase would not guess? Where is it
+ documented?
+4. **Prior attempts** — Has anyone tried to modernize any of this before?
+ What went wrong?
+5. **Off limits** — Is anything under `legacy/$1` not allowed to change in
+ this pass (a component another team owns, a frozen branch, generated
+ code)?
+
+Record every answer **verbatim** in the report — downstream commands, and
+`/modernize-brief` most of all, read them from there. Do not paraphrase
+away a caveat the human gave you.
+
## Check 1 — Detect the stack
Fingerprint `legacy/$1` from file extensions and manifests: languages,
@@ -35,19 +78,51 @@ used for, and what degrades without it:
Include the platform's install one-liner for anything missing
(`brew install scc`, `apt install cloc`, `pip install lizard`, …).
-## Check 3 — Build toolchain (smoke test, not just presence)
-
-Identify the compiler/interpreter for the detected legacy stack — e.g.
-GnuCOBOL (`cobc`) for COBOL, JDK + Maven/Gradle for Java, `cc`/`make` for
-C, `dotnet` for .NET. Then **prove it works on this codebase**: pick one
-representative source file and run a syntax-only compile
-(`cobc -fsyntax-only`, `javac`, `gcc -fsyntax-only`, …).
-
-A failed smoke test is the most valuable output of this command — report
-the actual error and diagnose it: missing copybook/include path, missing
-dialect flag (`-std=ibm` etc.), fixed vs free format, missing dependency
-jar. These are the errors that otherwise surface mid-`/modernize-transform`
-with much less context.
+## Check 3 — Build toolchain (prove it on THIS codebase, not just presence)
+
+**3a — The build definition is the ground truth. Find it and read it
+before guessing.** Something already builds this system; go find out how.
+Look for the CI/pipeline definition (`azure-pipelines.yml`, `Jenkinsfile`,
+`.github/workflows/`, `.gitlab-ci.yml`, `bitbucket-pipelines.yml`, build
+JCL procs, a `Makefile`) and any organization-level build configuration
+above or beside the source (`Directory.Build.props`/`.targets` and
+`nuget.config` in .NET; a parent POM, a `settings.xml` mirror, or a
+`.mvn/` directory in Java; a private-registry `.npmrc`/`pip.conf`; a root
+`build/`, `eng/`, `tools/`, or `scripts/` directory). These files are the
+single most honest document about how the system *actually* builds: the
+exact toolchain version it pins, where dependency binaries really come
+from, and which steps a naive build invocation skips. Every mid-migration
+"wait, how do dependencies resolve here?" surprise is already written down
+in one of them. Report what you found (or that none exists), quote the
+pinned toolchain version and the dependency source, and flag anything
+bespoke — a homegrown binary-resolution scheme is exactly the thing a
+transformation must not have to discover halfway through.
+
+**3b — Smoke test, escalating.** Identify the compiler/interpreter for the
+detected legacy stack — e.g. GnuCOBOL (`cobc`) for COBOL, a JDK +
+Maven/Gradle for Java, `cc`/`make` for C, `dotnet` for .NET — then **prove
+it works on this codebase**, at the strongest level available:
+
+- **Level 1 (any stack) — syntax-compile one representative source file**
+ (`cobc -fsyntax-only`, `javac`, `gcc -fsyntax-only`, …). This catches
+ missing copybooks/includes, dialect flags, fixed-vs-free format.
+- **Level 2 (any stack with a build system) — restore + build ONE whole
+ project/module the way 3a says the CI does.** A single file
+ syntax-compiling proves almost nothing about a real build system: a
+ restore that hits a private feed, a code-generation step, a shared props
+ file, a pinned SDK are all invisible to a one-file compile — and are
+ exactly where large codebases hide their surprises. Pick one small
+ *real* unit and take it all the way through.
+
+A failed smoke test at either level is the most valuable output of this
+whole command — report the actual error and diagnose it: missing
+copybook/include path, missing dialect flag (`-std=ibm` etc.), fixed vs
+free format, a dependency the standard feed cannot resolve. These are the
+errors that otherwise surface mid-transformation with far less context.
+Level 2 being *impossible* (no build system in the tree, a mainframe stack
+with no local runtime) is normal for some legacy code: report it as a
+fact, not a failure — equivalence then degrades to recorded traces, which
+the other commands already handle.
If the user passed a `[target-stack]`, do the same for it: runtime,
package manager, test framework (`mvn -v`, `npm -v`, `pytest --version`, …).
@@ -78,15 +153,51 @@ detected stack's equivalents of:
- **Version control history** — is `legacy/$1` under git with meaningful
history? (Change-frequency data sharpens risk ranking.)
+## Check 6 — Scope boundary (is `$1` the whole world, or a slice of one?)
+
+Every downstream command assumes `legacy/$1` *is* the system. When it is
+actually **one directory inside a larger source repository** — a module in
+a monorepo, one solution folder inside a much bigger solution, a subsystem
+sharing copybooks or includes with siblings — that assumption is the most
+dangerous thing in the whole run, and nothing else checks it.
+
+Detect it: after resolving the `legacy/$1` symlink (the recommended setup
+symlinks real code in), is there a repository / solution / workspace /
+reactor root *above* it? Do manifests or includes *inside* `$1` reference
+paths *outside* it? If either is true, report **both directions** of the
+boundary crossing:
+
+- **Outbound** — things inside `$1` that depend on source *outside* it
+ (project/module references, shared includes, a parent build file). The
+ `/modernize-map` topology and any delta catalog only see what is under
+ `$1`, so every outbound reference is a dependency they will silently
+ miss. List them.
+- **Inbound** — things *outside* `$1` that depend on things *inside* it.
+ This is the **blast radius**: an in-place migration (`/modernize-uplift`)
+ of a node with external consumers breaks every one of them. Grep the
+ sibling manifests for references into `$1`, enumerate the
+ inbound-referenced nodes, and say plainly that each needs an explicit
+ decision *before* any in-place change — keep it buildable for both old
+ and new consumers during the transition, expand the scope to include the
+ consumers, or accept and schedule the break. Never let this be
+ discovered by a broken build in a directory nobody was looking at.
+
+If `$1` really is a standalone repository, one line saying so is the whole
+check — it is cheap when it does not apply.
+
## Report
-Write `analysis/$1/PREFLIGHT.md`: a status table — one row per check,
-status ✅ / ⚠️ / ❌, what was found, and the fix for anything not green —
-followed by a **Ready / Ready-with-gaps / Not ready** verdict per command:
+Write `analysis/$1/PREFLIGHT.md`. It **leads with the Check 0 answers,
+verbatim, and the Check 6 scope-boundary finding** — those two are read by
+every downstream command (`/modernize-brief` above all) and are worth
+nothing paraphrased. Then a status table — one row per check, status
+✅ / ⚠️ / ❌, what was found, and the fix for anything not green — followed
+by a **Ready / Ready-with-gaps / Not ready** verdict per command:
- `assess` + `map` + `extract-rules` — need Checks 1–2 green-ish and
Check 4's missing-include count low
-- `brief` — needs only the three discovery artifacts; no tooling
+- `brief` — needs only the three discovery artifacts (plus
+ `DELTA_CATALOG.md` when the plan is a same-stack uplift); no tooling
- `transform` + `reimagine` — additionally need Check 3 green for the
**target** stack. A red legacy toolchain downgrades these to
Ready-with-gaps, not Not-ready: equivalence testing falls back to
@@ -101,7 +212,15 @@ followed by a **Ready / Ready-with-gaps / Not ready** verdict per command:
which). (b) Is the stack's **migration tool** installed (`dotnet tool list`
for `upgrade-assistant`, `apiport`, OpenRewrite, `pyupgrade`, `ng`)? Missing
is Ready-with-gaps, not Not-ready — the delta catalog is then fully
- Claude-derived and loses the tool's coverage; note that.
+ Claude-derived and loses the tool's coverage; note that. (c) Did Check 6
+ find **inbound external consumers** of `$1`? That is **Ready-with-gaps**,
+ not Not-ready — preflight runs before any plan exists, so there is nowhere
+ yet to record a decision — but it is the gap that matters most: name the
+ inbound-referenced shared nodes and say that `/modernize-brief` must give
+ each one an explicit transition decision as its own line item (Check 6
+ lists the options), and that `/modernize-uplift` Step 1 will not migrate a
+ shared node in place without one. Never let this be discovered from a
+ sibling's broken build.
Print the table in the session too, and end with the single most
important fix if anything is red.
diff --git a/plugins/code-modernization/commands/modernize-reimagine.md b/plugins/code-modernization/commands/modernize-reimagine.md
index 668ef60f..5b0ecb12 100644
--- a/plugins/code-modernization/commands/modernize-reimagine.md
+++ b/plugins/code-modernization/commands/modernize-reimagine.md
@@ -13,6 +13,19 @@ This is not a port — it's a rebuild from extracted intent. The legacy system
becomes the *specification source*, not the structural template. This command
orchestrates a multi-agent team with explicit human checkpoints.
+**The brief is binding — read it first.** If `analysis/$1/MODERNIZATION_BRIEF.md`
+exists, this reimagine is executing one of its phases: read it before doing
+anything below. Find the phase that names this command with a scope matching
+`$1` and <vision>, and treat that phase's **scope, entry criteria, exit
+criteria, and any edits the user made to it** as binding on the phases below
+— on top of, never instead of, this command's own two HITL checkpoints.
+Entry criteria are *gates*, not context: if one is not met (a prior phase's
+exit criteria, an SME sign-off the brief requires), meeting it **is** the
+next step — do not proceed past it and do not silently re-plan around it. If
+the brief exists but no phase matches, stop and ask which phase this is. The
+user steers execution by editing the brief; a brief the execution command
+never reads cannot steer anything.
+
## Phase A — Specification mining (parallel agents)
Spawn concurrently and show the user that all three are running:
diff --git a/plugins/code-modernization/commands/modernize-status.md b/plugins/code-modernization/commands/modernize-status.md
index c4de7860..575c3c1f 100644
--- a/plugins/code-modernization/commands/modernize-status.md
+++ b/plugins/code-modernization/commands/modernize-status.md
@@ -13,13 +13,13 @@ workflow stage, with the artifact's presence and modification time:
| Stage | Artifacts |
|---|---|
-| preflight | `PREFLIGHT.md` |
+| preflight | `PREFLIGHT.md` (note whether the Check 0 human answers and the Check 6 scope-boundary finding are present) |
| assess | `ASSESSMENT.md`, `ARCHITECTURE.mmd` |
| map | `topology.json`, `TOPOLOGY.html`, `*.mmd`, `extract_topology.*` |
| extract-rules | `BUSINESS_RULES.md`, `DATA_OBJECTS.md` |
| brief | `MODERNIZATION_BRIEF.md` (note whether the approval block is signed) |
| harden | `SECURITY_FINDINGS.md`, `security_remediation.patch` |
-| uplift | `DELTA_CATALOG.md`; `modernized/$1-uplifted/UPLIFT_NOTES.md` (note per-project: builds on target? baseline reproduced?) |
+| uplift | `DELTA_CATALOG.md`, `BASELINE.md`, `PLAYBOOK.md` (no playbook = the pilot hasn't happened yet — the fan-out must not); `modernized/$1-uplifted/UPLIFT_NOTES.md` (note per-unit: builds on target? baseline reproduced?) |
| transform | each `modernized/$1/<module>/` dir — note test presence and whether `TRANSFORMATION_NOTES.md` exists |
| reimagine | `modernized/$1-reimagined/` — note per-service acceptance tests and the `CLAUDE.md` handoff (reimagine's completion markers; it does NOT write `TRANSFORMATION_NOTES.md`) |
@@ -30,6 +30,10 @@ Flag any artifact older than an upstream artifact it derives from:
- `MODERNIZATION_BRIEF.md` older than `ASSESSMENT.md`, `topology.json`,
or `BUSINESS_RULES.md` → the brief no longer reflects discovery;
recommend re-running `/modernize-brief`.
+- `MODERNIZATION_BRIEF.md` for a same-stack **uplift** plan that is older
+ than `DELTA_CATALOG.md` — or that has no catalog at all — → the phase
+ order was decided before (or without) the version deltas that determine
+ it; recommend re-running `/modernize-brief`.
- `TOPOLOGY.html` older than `topology.json` → re-run the injection step
from `/modernize-map`.
- Any `TRANSFORMATION_NOTES.md` older than `BUSINESS_RULES.md` → the
diff --git a/plugins/code-modernization/commands/modernize-transform.md b/plugins/code-modernization/commands/modernize-transform.md
index 8183fd46..d946b93f 100644
--- a/plugins/code-modernization/commands/modernize-transform.md
+++ b/plugins/code-modernization/commands/modernize-transform.md
@@ -37,6 +37,18 @@ first run:
## Step 0b — Plan (HITL gate)
+**The brief is binding — read it first.** If `analysis/$1/MODERNIZATION_BRIEF.md`
+exists, this transform is one phase (or one module of a phase) of that plan:
+read it before deciding anything below. Find the phase that names this
+command with `$2` in scope, and treat that phase's **scope, entry criteria,
+exit criteria, and any edits the user made to it** as binding on the plan
+you present below. Entry criteria are *gates*, not context: if one is not
+met (a prior phase's exit criteria, an SME sign-off the brief requires),
+meeting it **is** the next step — do not proceed past it and do not silently
+re-plan around it. If the brief exists but no phase covers `$2`, stop and
+ask which phase this is. The user steers execution by editing the brief; a
+brief the execution command never reads cannot steer anything.
+
Read the source module and any business rules in `analysis/$1/BUSINESS_RULES.md`
that reference it. Then present the plan and **stop — write no code until
the user explicitly approves** (use plan mode if the session supports it):
diff --git a/plugins/code-modernization/commands/modernize-uplift.md b/plugins/code-modernization/commands/modernize-uplift.md
index 3a107aed..8df350fc 100644
--- a/plugins/code-modernization/commands/modernize-uplift.md
+++ b/plugins/code-modernization/commands/modernize-uplift.md
@@ -48,7 +48,20 @@ Optional 4th arg `$4` scopes to projects/modules matching a pattern.
recorded/expected outputs (as in `/modernize-transform`). Note this in the
plan and UPLIFT_NOTES — reviewers must know whether the proof was a true
dual-run or target-only.
-4. **Detect the ecosystem migration tool** — and distinguish **present /
+4. **Test framework on the target — the one question that reshapes the plan.**
+ Answer, before any planning: *can the existing test suite execute on $3
+ as-is?* The test framework is a dependency like any other, and one whose
+ runner/adapter does not support the target runtime is the single most
+ common reason an uplift's phase order comes out wrong: the test migration
+ is then a **prerequisite, not a leaf**, because nothing you migrate can be
+ validated until the tests that validate it run on $3. Read the framework
+ and version out of the test manifests and check it against $3 — NUnit 2 or
+ MSTest v1 cannot execute on modern .NET, JUnit 4 needs the vintage engine
+ on newer platforms, `nose`/`unittest2` do not run on Python 3, and so on
+ for whatever this stack's test manifests declare. If the answer is no, say
+ so now: it becomes an explicit *early* phase in the plan (Step 2) and in
+ `/modernize-brief`, never a trailing one.
+5. **Detect the ecosystem migration tool** — and distinguish **present /
runnable-here / actually-ran**. Most of these tools need a working
restore + build (and often network), which a read-only sandbox does not
have, so "installed" ≠ "produced findings". Report all three states and
@@ -70,6 +83,18 @@ Run `/modernize-preflight $1 $3` for the full readiness report.
## Step 1 — Working copy, project graph & ordering
+**The brief is binding — read it first.** If `analysis/$1/MODERNIZATION_BRIEF.md`
+exists, this invocation is executing one of its phases: read it before
+deciding anything below. Find the phase that names this command with a scope
+matching `$1`/`$4`, and treat that phase's **scope, entry criteria, exit
+criteria, and any edits the user made to it** as binding on the plan you
+present in Step 2. Entry criteria are *gates*, not context: if one is not met
+("baseline recorded", "pilot playbook approved"), meeting it **is** the next
+step — do not proceed past it and do not silently re-plan around it. If the
+brief exists but no phase matches, stop and ask which phase this is. The user
+steers execution by editing the brief; a brief the execution command never
+reads cannot steer anything.
+
**Working copy (do this first).** An uplift edits an existing solution *in
place* — it bumps target frameworks and fixes APIs while keeping the `.sln`,
the relative `<ProjectReference>`/module paths, and a reviewable `git diff`.
@@ -100,6 +125,18 @@ leaf-first — call them out in the plan:
libs so old and new consumers can both reference them while the migration is
in flight (the standard .NET technique). Note cycles in the project graph
need a manual cut point.
+- **Shared nodes with consumers OUTSIDE this scope need a recorded decision
+ before an in-place edit.** Read `analysis/$1/PREFLIGHT.md` if it exists:
+ its Check 6 lists the nodes under `$1` that source *outside* `$1` depends
+ on. Uplifting such a node in place breaks every external consumer nobody
+ is looking at — the one kind of damage this command can do beyond its own
+ scope. Do not migrate one without a recorded transition decision (the
+ brief's §3 owns it): keep the node buildable for both old and new
+ consumers through the transition — for many stacks that is exactly the
+ multi-targeting technique above — or expand the scope to include the
+ consumers, or accept and schedule the break. If a shared node has no
+ recorded decision, getting one from the user **is** that node's entry
+ criterion: stop and ask.
Scope to `$4` if given. Present the working-copy plan and the order.
@@ -125,6 +162,12 @@ This replaces `/modernize-transform`'s business-rule extraction. Build
`analysis/$1/DELTA_CATALOG.md`: the breaking/behavioral changes between $2 and
$3 **that this code actually hits**.
+**Reuse it if it already exists and is fresh.** `/modernize-brief` requires
+this catalog for an uplift and may have just produced it by running this
+very step. If `analysis/$1/DELTA_CATALOG.md` exists and is newer than the
+source under `legacy/$1`, read it and move on — do not re-run the fan-out to
+re-derive the identical artifact. Regenerate only if it is missing or stale.
+
**Preferred — Workflow orchestration.** If the **Workflow tool** is available
(this invocation authorizes it):
@@ -170,10 +213,13 @@ this order so you de-risk the oracle before depending on it:
fix the harness now — not mid-migration. (This is the structure
`test-engineer` then fills.) If the $2 leg can't run here (Step 0.3), prove
the $3 leg only and mark the proof target-only.
-2. **Baseline = the oracle.** Run the existing suite on the **$2** target and
- record pass/fail per test. This is the equivalence target — including any
- tests that legacy fails. You are proving *no behavior changed*, not *all
- tests pass*.
+2. **Baseline = the oracle. Record it in a file, not in your head.** Run the
+ existing suite on the **$2** target and write the per-test pass/fail table
+ to **`analysis/$1/BASELINE.md`**. This is the equivalence target —
+ including any tests that legacy fails. You are proving *no behavior
+ changed*, not *all tests pass*. The file is the point: Step 5 refuses to
+ start until it exists, so a migration can neither begin without an oracle
+ nor quietly skip this step under the pressure of many units.
3. **Gap-fill at delta sites.** Using `DELTA_CATALOG.md`, spawn `test-engineer`
to add characterization tests specifically where **Behavioral-silent**
deltas touch under-tested code (culture, encoding, serialization, dates).
@@ -182,8 +228,25 @@ this order so you de-risk the oracle before depending on it:
If only the target runtime is available (Step 0.3), there is no $2 run: pin the
gap-fill tests to expected/recorded outputs and label the proof target-only.
-
-## Step 5 — Migrate, leaf-first, minimal-diff
+`analysis/$1/BASELINE.md` still gets written — as the one-line honest record
+`target-only: <why the $2 runtime is unavailable here>` rather than a table —
+because Step 5 gates on the file existing either way.
+
+## Step 5 — Migrate: pilot ONE unit, then fan out in batches
+
+**Gate — do not start until `analysis/$1/BASELINE.md` exists** (Step 4.2):
+either the per-test $2 pass/fail table, or the one-line
+`target-only: <why the $2 runtime is unavailable here>` record. If it does
+not exist, writing it **is** the next step — not something to come back to.
+A migration without a baseline has no oracle: "the tests pass on $3" means
+nothing if you never learned what they did on $2.
+
+**Never migrate everything at once.** The delta catalog is a hypothesis built
+by *reading*; the **build system** is where a legacy codebase hides its
+surprises — a bespoke dependency-resolution scheme, a pinned toolchain, a
+shared props file, a code-generation step — and none of that enters the
+catalog until a real migration hits it. The cheapest place to hit it is one
+unit, not N.
All editing happens **in place inside the working copy `modernized/$1-uplifted/`** from
Step 1 (so relative project references resolve and the result is a clean
@@ -191,7 +254,8 @@ Step 1 (so relative project references resolve and the result is a clean
tools (`upgrade-assistant`, `ng update`) mutate the tree in place — that is
fine *here* because they run against the `modernized/$1-uplifted/` copy, not `legacy/`.
-For each project in dependency order (respecting the Step 1 overrides):
+Per **unit** (a project / module / package — one node in the Step 1 graph),
+the recipe is always the same:
1. **Run the ecosystem codemod** for the Mechanical deltas (`upgrade-assistant`
apply / OpenRewrite recipe / `pyupgrade` / `ng update`) against the copy.
2. **Apply the Judgment deltas** by hand from the catalog.
@@ -203,12 +267,127 @@ For each project in dependency order (respecting the Step 1 overrides):
here (the inverse of its usual job): any change beyond the minimal uplift is
a finding.
-Keep going until the project **builds on $3**.
+Keep going until the unit **builds on $3**.
+
+### 5a — Pilot (mandatory; do it yourself, in-session, never in a workflow)
+
+Take **one representative unit** all the way through the recipe above until
+it builds on $3 and reproduces its `BASELINE.md` result. *Representative*
+means it exercises the highest-blast-radius deltas from the catalog — a
+mid-complexity unit, **not the easiest one**. An easy pilot teaches you
+nothing you can reuse.
+
+Two outputs, both mandatory before any other unit is touched:
+
+- **Feed the catalog.** Every surprise the pilot hits that `DELTA_CATALOG.md`
+ did not predict — a build error, a step the ecosystem tool got wrong, an
+ environment fact you had to discover — is a delta the catalog missed. Add
+ it now, while you still know why.
+- **Write `analysis/$1/PLAYBOOK.md`** — the proven recipe, and the single
+ most valuable artifact of the whole migration. Concretely: the ordered
+ sequence of edits for one unit; every error hit and what resolved it;
+ every environment fact you had to *discover* rather than already knew
+ (which toolchain version is really in use, how dependency binaries
+ actually resolve, which shared config file governs the build); and the
+ exact build command that proves a unit is done. **Write it as instructions
+ to an engineer who has not read this conversation** — the fan-out agents
+ in 5b are exactly that. Never a credential value in it.
+
+Then **stop and show the user** the pilot's diff, what it added to the
+catalog, and the playbook — *before* any fan-out. The pilot is where a
+human catches the surprise that would otherwise be replicated N times over.
+If the pilot changed the picture materially (a prerequisite you missed, a
+phase in the wrong order), that is a finding about the **brief**, not just
+about this step — say so and update `MODERNIZATION_BRIEF.md` before
+continuing.
+
+### 5b — Fan out in dependency-aware escalating batches
+
+Only after the user has seen the pilot. If only a handful of units remain,
+skip the machinery: repeat the recipe per unit, in dependency order,
+in-session.
+
+For many units, **the playbook is the prompt.** Do not brief fan-out agents
+from your general knowledge of the stack; brief them from what the pilot
+*proved about this codebase*. If the **Workflow tool** is available (this
+invocation authorizes it):
+
+```
+Workflow({
+ scriptPath: "${CLAUDE_PLUGIN_ROOT}/workflows/uplift-migrate.js",
+ args: { system: "$1", source: "$2", target: "$3",
+ units: [ { name: "<unit>", path: "<dir relative to modernized/$1-uplifted/>",
+ deps: ["<name of a sibling unit this one depends on>", ...] },
+ ... ] }
+})
+```
+
+Enumerate `units` from the Step 1 graph, **excluding the pilot** and
+excluding any unit in a Step 1 *coordinated cut* (those change together and
+belong in-session, not in a per-unit fan-out). **`deps` is how the fan-out
+honors the dependency order** — for each unit, list the *other units in this
+list* it depends on, straight from the Step 1 graph. The workflow only
+migrates a unit once every dep it lists has **built**, so a unit and the
+unit it depends on never build concurrently against each other in the same
+working copy; and a unit whose dependency *failed to build* is never
+attempted at all — its build would fail for the dependency's reason, not the
+playbook's, which is exactly the noise that would falsely trip the circuit
+breaker. Naming the pilot (or a unit migrated in-session) as a dep is fine —
+it counts as already satisfied. Omitting `deps` opts that unit out of the
+ordering, so do not leave them off to save typing.
+
+Tell the user how many units before launching, and how they will run: in
+dependency-aware escalating batches (~4, then larger — never all N in one
+shot), one agent per **unit** (never per file — a per-file agent cannot see
+the unit's manifest or run its build), each agent editing only inside its
+own unit's directory and running that unit's real build before reporting,
+and a **circuit breaker** that stops — instead of spending the rest of the
+budget — the moment a batch's build rate drops below two-thirds. The correct
+response to a failing batch is a better playbook, not more agents.
+
+One operational note to give the user before launching: the fan-out agents
+change files and run builds, largely unattended once approved. The README's
+recommended workspace settings only guard the **file tools** (they deny
+`Edit`/`Write` on `legacy/`); a shell command that writes a file goes
+through **Bash permissions instead**, and that prompt is the control that
+keeps a prompt-injected agent inside its scope. Keep Bash on a *prompted*
+permission mode for this step rather than blanket-allowing it to make the
+fan-out faster — and if the session's permission mode auto-approves Bash,
+say so and treat the fan-out's resulting diff as untrusted until reviewed.
+
+When the workflow returns:
+- **Cross-cutting edits are yours.** Apply the returned `sharedFileNeeds`
+ (the solution/workspace manifest, shared build config) yourself — the
+ agents correctly refused to touch files they would race each other on.
+- **Fold `playbookGaps` back into `PLAYBOOK.md`** before doing anything else
+ with the un-migrated units. This is the loop that makes each batch cheaper
+ than the last.
+- The result carries **three re-passable unit lists**, each already in the
+ `{name, path, deps}` shape that `units` takes — so continuing never means
+ re-deriving anything: `remainingUnits` (never attempted), `failedUnits`
+ (attempted; the build failed), and `blockedUnits` (never attempted because
+ a unit they depend on did not build). **A unit in `failedUnits` or
+ `blockedUnits` is NOT migrated** — an empty `remainingUnits` alone does
+ not mean you are done.
+- If it **aborted early**, that is the circuit breaker doing its job, not a
+ failure to route around: revise the playbook from the gaps and the build
+ errors, re-verify the revision on one of the *failed* units in-session,
+ and only then re-invoke with
+ `units: <failedUnits + blockedUnits + remainingUnits>`.
+- Repeat until all three lists are empty, then verify it yourself: each
+ agent's `built` flag is self-reported, so re-run the full build across the
+ whole working copy before moving to Step 6.
+
+**Fallback** (no Workflow tool): the same discipline by hand. Spawn the
+**uplift-migrator** agent per unit in batches of ~4, wait for the batch,
+fold its playbook gaps back in, check the build rate, and only then launch
+the next batch. Never launch all N in one shot.
## Step 6 — Dual-run diff (the proof)
Run the **same suite** on both targets (or target-only per Step 0.3):
-- Every test must reproduce the **$2 baseline** result. A test that passed on
+- Every test must reproduce its result recorded in
+ **`analysis/$1/BASELINE.md`** (Step 4.2). A test that passed on
$2 and fails on $3 is a regression; one that failed on $2 and now passes is a
behavior change to adjudicate (intended fix vs accidental).
- Triage **every** result delta: intended fix vs regression. Unexplained
@@ -222,7 +401,9 @@ Write `modernized/$1-uplifted/UPLIFT_NOTES.md`:
- Dual-run diff table (or "target-only — source runtime unavailable here")
- **Residual manual deltas** the tooling/this pass could not handle
- **Deferred modernization** explicitly NOT done (kept the diff minimal)
-- Per-project: builds on $3 (y/n), baseline reproduced (y/n)
+- Per-unit: builds on $3 (y/n), baseline reproduced (y/n)
+- A pointer to `analysis/$1/PLAYBOOK.md` with its final gap list — the proven
+ recipe is worth more than this diff to whoever uplifts the next system
## Secrets discipline