diff options
| author | Morgan Westlee Lunt <morganl@anthropic.com> | 2026-06-09 23:31:52 +0000 |
|---|---|---|
| committer | Morgan Westlee Lunt <morganl@anthropic.com> | 2026-06-09 23:31:52 +0000 |
| commit | 3b9df6160068f836214bfae942a2ca2530489c84 (patch) | |
| tree | 9cb7e5f2492dc47910b750026a786bcd537ecdd5 /plugins/code-modernization/commands | |
| parent | 4a8250babf1d131c1406b113f3d759d18c55ec48 (diff) | |
code-modernization: fix findings from adversarial audit
Code/security:
- extract-rules.js: guard null agent() verdicts in the verify + P0 loops
(a skipped/dead referee made {rule,v:null} survive .filter(Boolean) and
then crashed on v.injectionSuspected / v.every) — sibling scripts already
had the guard.
- topology viewer XSS: the map injector embedded untrusted JSON (node names
from filenames, etc.) into a <script> island unescaped — a name containing
</script> executed on open. Escape < > & in the injected data and add a CSP
to the template.
- Second-order injection: citation/identifier fields (source / cwe /
source_site / correctedSource) were interpolated UNFENCED into the verifier
prompts that are supposed to be the trust anchor. Fence them in
extract-rules, harden-scan, uplift-deltas.
uplift design (audit of the new feature):
- Working-copy model: copy the WHOLE solution to modernized/ once and edit in
place (relative project refs survive; result is a reviewable git diff) —
the incremental per-project copy broke multi-project builds.
- Dual-run honesty: reframed as 'if both runtimes run here' (net48 needs
Windows; JUnit/pytest don't multi-target); dummy-test gate now binds a real
SUT under both targets; per-stack harness notes.
- Tooling honesty: present/runnable/actually-ran distinction; never fold in a
tool that couldn't run; apiport/2to3 demoted; py2->3 removed from 'preserve'
examples.
- Delta classes: name the high-blast-radius landmines (JPMS strong
encapsulation, .NET trimming/AOT, ICU globalization, hosting/runtime-config,
analyzer/nullable) in the finder briefs + agent.
- Rewrite-vs-uplift signal: weigh by touched sites (siteCount), not delta-card
count; judgment-share demoted to secondary.
Docs/consistency: brief reads topology.json (not TOPOLOGY.html); README
'five commands'; credential-masking claim split (analysts mask+cite vs
code-writers substitute fakes); read-only/write-scope claims softened to
match enforcement (Bash retained -> discipline, not tool-lock); reimagine
nested blockers/pendingRuleIds; status splits transform vs reimagine markers;
portfolio enumeration basenames; plugin.json description updated.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'plugins/code-modernization/commands')
5 files changed, 120 insertions, 40 deletions
diff --git a/plugins/code-modernization/commands/modernize-assess.md b/plugins/code-modernization/commands/modernize-assess.md index 77190d11..67056b9d 100644 --- a/plugins/code-modernization/commands/modernize-assess.md +++ b/plugins/code-modernization/commands/modernize-assess.md @@ -22,7 +22,7 @@ the immediate subdirectories first — the workflow script has no filesystem access — then launch one survey agent per system, all independent: ```bash -ls -d <parent-dir>/*/ +ls -d <parent-dir>/*/ | xargs -n1 basename # bare subdir names, not paths ``` ``` diff --git a/plugins/code-modernization/commands/modernize-map.md b/plugins/code-modernization/commands/modernize-map.md index 53668ca6..afe248ad 100644 --- a/plugins/code-modernization/commands/modernize-map.md +++ b/plugins/code-modernization/commands/modernize-map.md @@ -146,6 +146,12 @@ tpl = open(tpl_path).read() marker = "/*__TOPOLOGY_DATA__*/ null" assert marker in tpl, f"injection marker not found in {tpl_path}" data = json.dumps(json.load(open(f"{out_dir}/topology.json"))) +# topology.json is derived from UNTRUSTED source (node names come from filenames, +# observations/flows from analyzed code). The data is injected into a <script> +# block, and the HTML parser closes <script> on the literal bytes "</script>" +# regardless of JS string context — so a node named "x</script><script>…" would +# execute. json.dumps does NOT escape "<". Escape it (JSON-safe) to kill the breakout. +data = data.replace("<", "\\u003c").replace(">", "\\u003e").replace("&", "\\u0026") open(f"{out_dir}/TOPOLOGY.html", "w").write( tpl.replace(marker, "/*__TOPOLOGY_DATA__*/ " + data)) print(f"wrote {out_dir}/TOPOLOGY.html") diff --git a/plugins/code-modernization/commands/modernize-reimagine.md b/plugins/code-modernization/commands/modernize-reimagine.md index f269aa11..668ef60f 100644 --- a/plugins/code-modernization/commands/modernize-reimagine.md +++ b/plugins/code-modernization/commands/modernize-reimagine.md @@ -87,8 +87,12 @@ Workflow({ Tell the user the service count before launching. Each agent writes only to its own `modernized/$1-reimagined/<service-name>/` directory (disjoint, so parallel writes don't conflict). On return, report from the structured -result: services scaffolded, total acceptance tests, pending rule IDs, and -anything in `blockers` or `notScaffolded`. +result: services scaffolded (`scaffolded[]`) and `totals` (services, +acceptanceTests, pendingRules count); the actual pending rule IDs and any +planted-instruction/blocker notes are per-service at `scaffolded[].pendingRuleIds` +and `scaffolded[].blockers` (check every service's `blockers` — that's where the +untrusted-spec injection signal surfaces); plus `notScaffolded` for anything +skipped. **Fallback** (no Workflow tool): for each service — cap at 3 to keep the run tractable; tell the user which you deferred — spawn a **scaffolder agent diff --git a/plugins/code-modernization/commands/modernize-status.md b/plugins/code-modernization/commands/modernize-status.md index bfae01d3..0a7b3c99 100644 --- a/plugins/code-modernization/commands/modernize-status.md +++ b/plugins/code-modernization/commands/modernize-status.md @@ -20,7 +20,8 @@ workflow stage, with the artifact's presence and modification time: | brief | `MODERNIZATION_BRIEF.md` (note whether the approval block is signed) | | harden | `SECURITY_FINDINGS.md`, `security_remediation.patch` | | uplift | `DELTA_CATALOG.md`; `modernized/$1/UPLIFT_NOTES.md` (note per-project: builds on target? baseline reproduced?) | -| transform / reimagine | each `modernized/$1*/<module>/` dir — note test presence and whether `TRANSFORMATION_NOTES.md` exists | +| 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`) | ## 2 — Staleness diff --git a/plugins/code-modernization/commands/modernize-uplift.md b/plugins/code-modernization/commands/modernize-uplift.md index 8004f3e7..7aa95fca 100644 --- a/plugins/code-modernization/commands/modernize-uplift.md +++ b/plugins/code-modernization/commands/modernize-uplift.md @@ -11,11 +11,24 @@ runtime. You **preserve structure and make the smallest diffs that compile and behave identically on the target**, driven by the *known* breaking changes between $2 and $3 — not by re-deriving the business logic. -The defining advantage of a same-stack uplift: **the same test suite can run -on both the old and new runtime.** That makes your equivalence proof a real -differential test (run on both, diff the results), not a golden-master -recording. The whole command is built around establishing that dual-run -harness early and leaning on it. +The potential advantage of a same-stack uplift: **if both runtimes execute in +this environment, the same test suite can run on both** and your equivalence +proof becomes a real differential test (run on both, diff the results). That +is the strong case — but it is **not always available**, and the command is +explicit about when it is: + +- It depends on the stack. .NET can multi-target one test project to both + framework monikers (`<TargetFrameworks>net48;net8.0</TargetFrameworks>`), + **but `net48` only executes on Windows/Mono** — on a Linux/macOS box or most + CI sandboxes the old leg cannot run. Java 8→17 is not one suite over two + targets at all — it is the whole build run twice under two JDK toolchains. + Python 2→3 cannot import the same un-rewritten module under both + interpreters. So "true dual-run" is the *best* case, common only for + .NET-on-Windows. +- When both runtimes are **not** runnable here, equivalence degrades — exactly + like `/modernize-transform` — to characterization tests pinned to + recorded/expected outputs on the target only. That is fine; it just must be + labelled honestly (Step 0.3, Step 7). Optional 4th arg `$4` scopes to projects/modules matching a pattern. @@ -35,33 +48,75 @@ 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** (see the agent's list): .NET - `upgrade-assistant` / Portability Analyzer / `try-convert`; Java - **OpenRewrite**; Python `pyupgrade`/`2to3`; Angular `ng update`. Report which - are present. These do the mechanical bulk; this command orchestrates them - and owns the residue. +4. **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 + **never fold a tool's findings into the catalog unless it actually ran** — + say "coverage lost: <tool> needs restore+network, unavailable here" instead. + - .NET: **`dotnet upgrade-assistant`** (loads + restores the project; also + *applies* changes in place — see Step 5). The legacy **Portability + Analyzer** (`apiport`) analyzes *compiled assemblies*, not source, and is + Windows-centric/archived — treat as optional, not primary. + - Java/Spring: **OpenRewrite** (`mvn rewrite:dryRun` is genuinely headless + and emits a patch — the most reliable of these; lean on it). + - Python: **`pyupgrade`** (source-level, runnable). Note `2to3` is deprecated + and removed in Python 3.13; `python-modernize` is abandoned — don't rely + on them. + - JS/Angular: `ng update` (edits in place, needs a clean git tree + + `node_modules`; no real report-only mode). Run `/modernize-preflight $1 $3` for the full readiness report. -## Step 1 — Project graph & ordering - -Same-stack uplifts move through a **build dependency graph**, not a strangler -fig. Reuse `/modernize-map $1` if `analysis/$1/topology.json` exists, else -build a quick project/module graph (`.csproj`/`.sln` references, Maven -modules, package imports). Order **leaf-first**: uplift the libraries with no -internal dependents before the apps that depend on them. Scope to `$4` if -given. Present the order. +## Step 1 — Working copy, project graph & ordering + +**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`. +That is fundamentally different from `transform`/`reimagine`, which write a +new tree. So: **copy the whole system once** — `cp -r legacy/$1 modernized/$1` +(the entire solution, not project-by-project) — and do all editing in place +under `modernized/$1/`, git-tracked. `legacy/$1` stays the untouched baseline +oracle. Copying the *whole* solution (not incrementally) is what keeps +relative project references intact and makes the final artifact a real +`git diff` between the seeded copy and the end state — which is exactly what a +reviewer of an uplift wants. + +**Graph & ordering.** Reuse `/modernize-map $1` if `analysis/$1/topology.json` +exists, else build a quick project/module graph (`.csproj`/`.sln` references, +Maven modules, package imports). Default order is **leaf-first** (libraries +before the apps that depend on them), but three things override pure +leaf-first — call them out in the plan: +- **Spanning nodes go first, not last.** The dual-run test project and any + shared test utilities reference SUTs across the whole graph — they are not + leaves. Stand up / multi-target them up front so the harness exists before + you migrate anything. +- **Dependency deltas force a coordinated cut.** A major-version bump consumed + mid-graph (EF6→EF Core, `javax`→`jakarta`) cannot be done leaf-first + incrementally — every consumer changes together. Sequence these as their own + cross-cutting step. +- **Multi-target shared libraries during transition.** Set + `<TargetFrameworks>$2-moniker;$3-moniker</TargetFrameworks>` on shared leaf + 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. + +Scope to `$4` if given. Present the working-copy plan and the order. ## Step 2 — Plan (HITL gate) Present and **stop — change nothing until the user approves** (use plan mode if available): -- The exact version pair and the ecosystem tool you'll drive -- The project order (leaf-first) -- The dual-run harness plan (which test framework multi-targets both $2 and - $3 — e.g. NUnit/xUnit/MSTest all can via multi-targeting) and whether a true - dual-run is possible here or it's target-only (Step 0.3) +- The exact version pair, the working-copy plan (Step 1), and which ecosystem + tool you'll drive (and whether it can actually run here) +- The project order (leaf-first, with the spanning-node / dependency-cut / + multi-target overrides from Step 1) +- The harness plan and **whether a true dual-run is possible here or it's + target-only** (Step 0.3): for .NET, multi-target one test project to both + monikers (the `net48` leg needs Windows); for Java, a double JDK build; for + Python, separate interpreter envs (the suite itself diverges post-`2to3`) - How equivalence is proven: **baseline on $2 = oracle; $3 must reproduce it** + — or, target-only, characterization vs recorded outputs - Anything ambiguous needing a decision now ## Step 3 — Delta catalog (the driver artifact) @@ -81,10 +136,14 @@ Workflow({ ``` It runs one finder per delta category (API-removed, behavioral-silent, -project-system, dependency) in parallel, folds in the ecosystem tool's report, -verifies each delta against the cited code, and returns structured delta -cards. The finders are read-only; **you** write `DELTA_CATALOG.md` from the -result. Surface `injectionFlags` if non-empty. +project-system, dependency — the finders also probe reflection/encapsulation, +globalization/locale, and hosting/runtime-config, the highest-blast-radius +classes) in parallel, folds in the ecosystem tool's report **only if it +actually ran**, verifies each delta against the cited code, and returns +structured delta cards. Tell the user the finder count (one per category) +before launching. The finders are read-only; **you** write `DELTA_CATALOG.md` +from the result. Surface `injectionFlags` if non-empty, and read the +`upliftVsRewriteSignal` (Step "When NOT to use"). **Fallback** (no Workflow tool): spawn the **version-delta-analyst** agent: "Build the delta catalog for uplifting legacy/$1 from $2 to $3. Detect and run @@ -102,10 +161,15 @@ Either way the catalog must rank by blast radius and mark each delta The harness is the safety net the rest of the command leans on. Build it in this order so you de-risk the oracle before depending on it: -1. **Prove the harness shape first.** Stand up a test project that - **multi-targets both $2 and $3** with a single trivial/dummy test, and run - it on *both* targets. If that won't go green on both, fix the harness now — - not mid-migration. (This is the structure `test-engineer` then fills.) +1. **Prove the harness shape first — against a real (tiny) type, not a free + dummy.** A dummy test with no reference to the system-under-test only proves + the *test framework* multi-targets; it does not prove the hard part, which + is one test binding to **two SUT builds** (the $2 build and the $3 build) + via target-conditional references. So pick one trivial real type from the + system and assert on it under both targets. If that won't go green on both, + 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 @@ -121,9 +185,15 @@ gap-fill tests to expected/recorded outputs and label the proof target-only. ## Step 5 — Migrate, leaf-first, minimal-diff -For each project in dependency order: -1. **Run the ecosystem codemod** for the Mechanical deltas (upgrade-assistant / - OpenRewrite recipe / pyupgrade / ng update). Let the tool do what it does. +All editing happens **in place inside the working copy `modernized/$1/`** from +Step 1 (so relative project references resolve and the result is a clean +`git diff` against the seeded copy). `legacy/$1` is never touched. Apply-mode +tools (`upgrade-assistant`, `ng update`) mutate the tree in place — that is +fine *here* because they run against the `modernized/$1/` copy, not `legacy/`. + +For each project in dependency order (respecting the Step 1 overrides): +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. 3. **Smallest diff that builds.** Preserve structure, names, and layout. Adopt a new idiom *only* where the old one was removed and there's no choice. @@ -133,8 +203,7 @@ For each project in dependency order: here (the inverse of its usual job): any change beyond the minimal uplift is a finding. -Write migrated code to `modernized/$1/` (never edit `legacy/` — it stays the -read-only baseline oracle). Keep going until the project **builds on $3**. +Keep going until the project **builds on $3**. ## Step 6 — Dual-run diff (the proof) |
