Rewrite one legacy module in the target stack, with tests that prove it behaves the same
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-claude-plugins-official-88cc01060d03 ,按照其中的说明把「modernize-transform」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Transform module $module of $system into $target_stack, with proof of behavioral
equivalence. This is one vertical slice of the strangler fig; output goes to
modernized/$system/$module/.
The code is legacy/$system, often a symlink to where it really lives: say where it points (readlink legacy/$system) in one line before you start. If legacy/$system does not exist, stop and say so: nothing can run without the code, so the fix is /code-modernization:modernize $system --source <path to the code>. Run every subagent in the foreground and wait for its result: never end your turn while one is still running. Stop any server or other process you started (a legacy app on a local port, a watcher) before you finish, and say you did. If $module or $target_stack is empty, read
analysis/$system/MODERNIZATION_BRIEF.md: take the target stack it names, and the first module of
the earliest phase whose Command: is transform that has no
modernized/$system/<module>/TRANSFORMATION_NOTES.md yet (with no brief, the target in INTENT.md). Say which you picked.
Target stack (required). The runtime, package manager and test framework must respond
(java -version and mvn -v, node -v and npm -v, python3 -V and pytest --version). If not,
stop and say what to install: a plan gate now would only defer the failure an hour. Point to
/code-modernization:modernize-preflight $system $target_stack.
Legacy stack (advisory, never a blocker). Try a syntax-only compile of the module. Legacy code
often cannot build locally by nature (CICS and IMS programs have no local translator; the real runtime
is a mainframe you do not have). If it cannot, dual execution is off the table: the tests assert
against recorded traces and golden-master fixtures (real production outputs, captured reports,
SME-confirmed examples). Say so in the plan and in TRANSFORMATION_NOTES.md ("equivalence is
trace-based; legacy was not executable here"), so reviewers know how strong the proof is.
Run the old system only where it is safe. Record baselines from the legacy code running on this machine, or against a test environment the person named. Never call a production or third-party service, register an account, or send or change real data to record a baseline unless the person approved that exact target in the plan (say which calls, and which of them write). A token, password or session cookie in a recorded response is a secret: replace it with a fixed fake value before anything is saved, and never print it.
The brief is binding. If MODERNIZATION_BRIEF.md exists, find the phase whose Command: is this
one and whose Modules: include $module, and treat its scope, entry criteria, exit criteria and any
edits the user made as binding. An unmet entry criterion is the next step: meet it, never re-plan
around it. If no phase covers $module, stop and ask which phase this is.
Read the module's source and the rules in BUSINESS_RULES.md that reference it, and any verdicts on them in analysis/$system/RULE_REVIEWS.json: a rule marked wrong is not pinned as the oracle (use the reviewer's note for what is right, and if the note does not say, ask), and a P0 rule marked discuss is a question to settle at this plan gate before any code. Then present the
plan and stop: write no code until the user explicitly approves (plan mode if available): which
source files are in scope, the target structure, which rules and behaviors it implements, how you will
prove equivalence, and anything ambiguous that needs a human decision now.
Spawn the test-engineer subagent: "Write characterization tests for module $module of legacy/$system.
Read the source, identify every observable behavior and encode each as a test with concrete input and
expected output derived from the legacy logic. Target framework: <right for $target_stack>. Write to
modernized/$system/$module/src/test/. These tests define 'done'. Name the RULE-NNN id(s) each test pins
(from analysis/$system/BUSINESS_RULES.md) in its name or a one-line comment, so the trace can find it. Follow your secret-handling rules:
no credential from legacy code becomes a fixture; use fake same-shape values and read anything live
from environment variables." Show the user the test file and get a yes before going on.
Write the implementation in modernized/$system/$module/src/main/. Write what a senior
$target_stack engineer would write from the specification, not from the legacy structure: do not
mirror COBOL paragraphs as methods or keep names like WS-TEMP-AMT-X; use the target's idioms
(records, streams, injection, proper error types). Include the domain model, service logic, API
surface and configuration, and link each class to the rule IDs it implements in a short comment.
While iterating, run only this module's tests; run the whole suite once before Step 4.
cd modernized/$system/$module and the stack's test command) and show the
output. Fix and rerun until green.equivalence cases executed: N. A run that executed zero cases proved
nothing, and a comparison test must fail, never skip, when its legacy oracle or fixture is
missing: a suite that is green because everything skipped is not green. If the oracle was
unreachable, fix that; do not report the suite as passing.Canary: <the change> → <N> tests failed in the notes. If nothing failed,
the tests do not pin the behavior: strengthen them before going on.analysis/$system/equivalence/legacy/ and .../new/, list the pairs in
analysis/$system/equivalence/cases.json (paths relative to that folder; the schema is at the top of
scripts/compare.py), and run
python3 "${CLAUDE_PLUGIN_ROOT}/scripts/compare.py" analysis/$system/equivalence/cases.json --out analysis/$system/EQUIVALENCE.json.
That script, not your judgment, decides same or different. Mask only fields that legitimately vary
(timestamps, generated ids) and say what each mask hides. A difference you accept is recorded with a
reason in the case's approvedDifference, and only a person accepts it.
Floating-point numbers that another compiler or math library prints slightly differently are not a
mask: give that case a tolerance (rel or abs, and a why), which compares numbers written with a
decimal point or exponent within it, every other byte exactly, and is listed in the result.Write modernized/$system/$module/TRANSFORMATION_NOTES.md: a mapping table (legacy file:lines to target
file:lines, per behavior); deliberate deviations with rationale; what was NOT migrated (dead code,
unreachable branches) and why; the canary result and the executed-case count; follow-ups for the next
dependent module. Show one representative behavior side by side
(diff -y --width=160 <(sed -n '<lines>p' <legacy file>) <target file>). Never pick a credential-bearing
range, and mask any credential-like literal in the notes: they live in modernized/ and get committed.
This is your own evidence: /code-modernization:modernize-verify $system $module is the independent re-check
(it re-runs the tests and the comparison, tries new inputs, and gives one verdict).
Spawn the architecture-critic subagent to review the code against $target_stack best practice. Apply HIGH-severity feedback and list the rest in the notes.
Report: tests passing, cases executed, lines of legacy retired, where the artifacts are. Refresh the
report (python3 "${CLAUDE_PLUGIN_ROOT}/scripts/build_report.py" $system, a convenience: if it fails or python3 is missing, say so in one line and carry on). The next step is the brief's next module, or /code-modernization:modernize-harden $system
when the phase is done.