diff options
| author | Morgan Lunt <morganl@anthropic.com> | 2026-06-08 15:36:03 -0700 |
|---|---|---|
| committer | Morgan Lunt <morganl@anthropic.com> | 2026-06-09 08:48:04 -0700 |
| commit | bec8d7c93ae523e1cb3204eb061c801eaff017e5 (patch) | |
| tree | 30237fd1d035f173e18c8f513a4cb5f6b9af75fc /plugins/code-modernization/commands | |
| parent | 874596818685794ad06efcf5db115acaf938da68 (diff) | |
code-modernization: vendor d3, viewer robustness, status command, pipeline fixes
Viewer (assets/topology-viewer.html):
- inline a minified d3 subset (hierarchy/pack, zoom, selection,
interpolateZoom, ease; ISC license) instead of loading from a CDN —
the page is now fully self-contained and works on air-gapped networks
- handle duplicate node ids (unique-suffix; edges bind to the first
occurrence) and store parent references directly, fixing
level-of-detail and selection corruption with messy generated data
- share one reveal rule between drawing, edge culling, and hit-testing
so edges no longer draw into collapsed containers
- pre-bucket edges by kind and keep a per-node adjacency map; the
hover/selection pass no longer scans every edge each frame
- cancel in-flight fly-to animations when a new one starts; clamp
fly-to zoom to the zoom extent; derive max zoom from the smallest
leaf so deep estates stay reachable
- render dead-end candidates (new deadEnds field) with a dashed
outline and a sidebar badge
- clicking a node during a flow walkthrough exits the walkthrough;
search results clear on selection and Escape; surrogate-safe label
truncation; clearer stats line; explicit empty-topology message
Commands:
- new /modernize-status: read-only progress report — artifact inventory
with timestamps, staleness flags, secrets-hygiene checks, next step
- map: deadEnds in the topology schema; datastore names must be logical
identifiers with credentials stripped from URLs/DSNs
- brief: read topology.json + .mmd files (not the interactive HTML);
staleness check against inputs; effort unit aligned to person-months
- transform: secret-safe characterization-test prompt; diff -y fallback
when delta is missing; credential-safe diff selection
- reimagine: target vision is everything after the first argument (was
silently truncated to one word); masking rules in spec/scaffold/
handoff prompts
- brief/transform/reimagine: human-approval gates phrased as explicit
stop-and-wait instead of 'enter plan mode'
- preflight: delta in the tool table; brief added to the verdict list
- README: preflight/status in the workflow; legacy/ deny list also
covers Write; plugin + marketplace descriptions updated
Diffstat (limited to 'plugins/code-modernization/commands')
6 files changed, 122 insertions, 23 deletions
diff --git a/plugins/code-modernization/commands/modernize-brief.md b/plugins/code-modernization/commands/modernize-brief.md index 3e9f07e7..5daa611e 100644 --- a/plugins/code-modernization/commands/modernize-brief.md +++ b/plugins/code-modernization/commands/modernize-brief.md @@ -8,10 +8,19 @@ single document a steering committee approves and engineering executes. Target stack: `$2` (if blank, recommend one based on the assessment findings). -Read `analysis/$1/ASSESSMENT.md`, `analysis/$1/TOPOLOGY.html` (and the `.mmd` -files alongside it), and `analysis/$1/BUSINESS_RULES.md` first. If any are -missing, say so and stop — they come from `/modernize-assess`, `/modernize-map`, -and `/modernize-extract-rules` respectively. Run those first. +Read `analysis/$1/ASSESSMENT.md`, `analysis/$1/topology.json` (plus the +`.mmd` files alongside it — do NOT read `TOPOLOGY.html`, it's an +interactive viewer with the data minified inside), and +`analysis/$1/BUSINESS_RULES.md` first. If any are missing, say so and +stop — they come from `/modernize-assess`, `/modernize-map`, and +`/modernize-extract-rules` respectively. Run those first. + +**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 +user re-ran this command anyway, ask what changed. Either way, note the +input timestamps in the brief's header so reviewers can see what it was +built from. ## The Brief @@ -31,7 +40,8 @@ fewest-dependencies first. 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) -- Estimated effort (person-weeks, derived from COCOMO + complexity data) +- Estimated effort (person-months, same unit as the assessment's COCOMO + figure — convert deliberately if you present weeks) - Risk level + top 2 risks + mitigation Render the phases as a Mermaid `gantt` chart. @@ -69,6 +79,7 @@ Approval covers: Phase 1 only | Full plan ## Present -Enter **plan mode** and present a summary of the brief. Do NOT proceed to any -transformation until the user explicitly approves. This gate is the -human-in-the-loop control point. +Present a summary of the brief and **stop — write nothing further until +the user explicitly approves** (use plan mode if the session supports +it). This gate is the human-in-the-loop control point; "no objection" is +not approval. diff --git a/plugins/code-modernization/commands/modernize-map.md b/plugins/code-modernization/commands/modernize-map.md index 21eb58e2..53668ca6 100644 --- a/plugins/code-modernization/commands/modernize-map.md +++ b/plugins/code-modernization/commands/modernize-map.md @@ -78,6 +78,7 @@ summary (cap at ~200 lines for very large estates). { "source": "<id>", "target": "<id>", "kind": "call" } ], "entryPoints": ["<id>", "..."], + "deadEnds": ["<id>", "..."], "observations": ["<architect observation>", "..."], "flows": [ { "name": "<business flow>", "persona": "<who experiences it>", @@ -94,9 +95,20 @@ summary (cap at ~200 lines for very large estates). `job`, `screen`. `loc` drives circle size — include it for modules. - Edge kinds: `call` (direct), `dispatch` (dynamic/router), `read`, `write`. Every edge endpoint must be a leaf id that exists in the tree. +- `deadEnds`: the dead-end candidates from the extraction, rendered with + a dashed outline in the viewer. Apply the suppression rules above — + anything that could be the target of an unresolved dynamic call does + NOT belong here; record that uncertainty in `observations` instead. +- **Datastore ids and names must be logical identifiers** — DD name, + dataset name, table/schema name, at most host:port. If the resolved + config value is a URL or DSN, strip userinfo and credential query + params before it goes anywhere in topology.json: the file gets + committed and the viewer displays names verbatim. Never copy raw + config values into `observations`. - `observations`: 3–7 architect observations — tight coupling clusters, single points of failure, service-extraction candidates, data stores - with too many writers. + with too many writers, dispatch targets the extraction could not + resolve. - `flows` is the **persona walkthrough** section — see below. ## Persona flows @@ -140,11 +152,11 @@ print(f"wrote {out_dir}/TOPOLOGY.html") EOF ``` -The viewer loads d3 (version-pinned) from a CDN, so opening it needs -one-time network access; the rest is self-contained and the page shows an -explicit error if the CDN is unreachable. If the `python3` invocation -fails to find the template, `${CLAUDE_PLUGIN_ROOT}` was not substituted — -report that rather than hand-writing a viewer. +The viewer is fully self-contained (the d3 subset it needs is inlined in +the template) — it works offline and on air-gapped networks. If the +`python3` invocation fails to find the template, +`${CLAUDE_PLUGIN_ROOT}` was not substituted — report that rather than +hand-writing a viewer. Mermaid stays for **small, exportable** diagrams. Generate standalone `.mmd` files for reuse in docs and PRs — but keep each under ~40 edges; diff --git a/plugins/code-modernization/commands/modernize-preflight.md b/plugins/code-modernization/commands/modernize-preflight.md index aa04dd36..21d27ab1 100644 --- a/plugins/code-modernization/commands/modernize-preflight.md +++ b/plugins/code-modernization/commands/modernize-preflight.md @@ -30,6 +30,7 @@ used for, and what degrades without it: | `scc` (or `cloc`) | assess | LOC/complexity fall back to `find`+`wc`; COCOMO estimate gets coarser | | `lizard` | assess --portfolio | complexity estimated from decision-keyword counts | | `glow` | all | markdown artifacts render as plain text | +| `delta` | transform | side-by-side diffs fall back to `diff -y` | Include the platform's install one-liner for anything missing (`brew install scc`, `apt install cloc`, `pip install lizard`, …). @@ -85,6 +86,7 @@ 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 - `transform` + `reimagine` — additionally need Check 3 green for both legacy and target stacks - `harden` — needs Check 2 plus any stack-specific SAST tooling found diff --git a/plugins/code-modernization/commands/modernize-reimagine.md b/plugins/code-modernization/commands/modernize-reimagine.md index c16523ab..ce91724c 100644 --- a/plugins/code-modernization/commands/modernize-reimagine.md +++ b/plugins/code-modernization/commands/modernize-reimagine.md @@ -3,7 +3,11 @@ description: Multi-agent greenfield rebuild — extract specs from legacy, desig argument-hint: <system-dir> <target-vision> --- -**Reimagine** `legacy/$1` as: $2 +The first token of `$ARGUMENTS` is the system dir (`$1`); **everything +after it is the target vision** — it is usually multiple words, so do not +truncate it to one token. Below, `<vision>` means that full remainder. + +**Reimagine** `legacy/$1` as: <vision> 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 @@ -19,7 +23,8 @@ Spawn concurrently and show the user that all three are running: 2. **legacy-analyst** — "Catalog every external interface of legacy/$1: inbound (screens, APIs, batch triggers, queues) and outbound (reports, files, downstream calls, DB writes). For each: name, direction, payload - shape, frequency/SLA if discernible." + shape, frequency/SLA if discernible. Mask any credential embedded in + endpoints or payload examples per your secret-handling rules." 3. **legacy-analyst** — "Identify the core domain entities in legacy/$1 and their relationships. Return as an entity list + Mermaid erDiagram." @@ -32,6 +37,9 @@ Collect results. Write `analysis/$1/AI_NATIVE_SPEC.md` containing: - **Non-functional requirements** inferred from legacy (batch windows, volumes) - **Behavior Contract** (the Given/When/Then rules — these are the acceptance tests) +Credential values are masked everywhere in the spec; connection details +appear as env-var placeholders (`${DATABASE_URL}`), never literals. + ## Phase B — HITL checkpoint #1 Present the spec summary. Ask the user **one focused question**: "Which of @@ -40,20 +48,21 @@ should deliberately drop?" Wait for the answer. Record it in the spec. ## Phase C — Architecture (single agent, then critique) -Design the target architecture for "$2": +Design the target architecture for "<vision>": - Mermaid C4 Container diagram - Service boundaries with rationale (which rules/entities live where) - Technology choices with one-line justification each - Data migration approach from legacy stores Then spawn **architecture-critic**: "Review this proposed architecture for -$2 against the spec in analysis/$1/AI_NATIVE_SPEC.md. Identify over-engineering, +<vision> against the spec in analysis/$1/AI_NATIVE_SPEC.md. Identify over-engineering, missed requirements, scaling risks, and simpler alternatives." Incorporate the critique. Write the result to `analysis/$1/REIMAGINED_ARCHITECTURE.md`. ## Phase D — HITL checkpoint #2 -Enter plan mode. Present the architecture. Wait for approval. +Present the architecture and **stop — scaffold nothing until the user +explicitly approves** (use plan mode if the session supports it). ## Phase E — Parallel scaffolding @@ -65,7 +74,9 @@ in parallel**: and AI_NATIVE_SPEC.md. Create: project skeleton, domain model, API stubs matching the interface contracts, and **executable acceptance tests** for every behavior-contract rule assigned to this service (mark unimplemented ones as -expected-failure/skip with the rule ID). Write to modernized/$1-reimagined/<service-name>/." +expected-failure/skip with the rule ID). No credential literal from legacy +code becomes a test fixture or config default — use fake same-shape values +and env-var placeholders. Write to modernized/$1-reimagined/<service-name>/." Show the agents' progress. When all complete, run the acceptance test suites and report: total tests, passing (scaffolded behavior), pending (rule IDs @@ -77,7 +88,9 @@ Write `modernized/$1-reimagined/CLAUDE.md` — the persistent context file for the new system, containing: architecture summary, service responsibilities, where the spec lives, how to run tests, and the legacy→modern traceability map. This file IS the knowledge graph that future agents and engineers will -load. +load — and it gets committed: connection details and credentials appear +only as env-var names with a pointer to where they're provisioned, never +as values. Report: services scaffolded, acceptance tests defined, % behaviors with a home, location of all artifacts. diff --git a/plugins/code-modernization/commands/modernize-status.md b/plugins/code-modernization/commands/modernize-status.md new file mode 100644 index 00000000..d5fd7594 --- /dev/null +++ b/plugins/code-modernization/commands/modernize-status.md @@ -0,0 +1,54 @@ +--- +description: Where am I in the modernization workflow — artifact inventory, staleness, secrets hygiene, next step +argument-hint: <system-dir> +--- + +Report where the modernization of `$1` stands, in one screen. This is a +read-only command — inspect, never modify. + +## 1 — Artifact inventory + +Check `analysis/$1/` and `modernized/$1*/` and build a table — one row per +workflow stage, with the artifact's presence and modification time: + +| Stage | Artifacts | +|---|---| +| preflight | `PREFLIGHT.md` | +| 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` | +| transform / reimagine | each `modernized/$1*/<module>/` dir — note test presence and whether `TRANSFORMATION_NOTES.md` exists | + +## 2 — Staleness + +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`. +- `TOPOLOGY.html` older than `topology.json` → re-run the injection step + from `/modernize-map`. +- Any `TRANSFORMATION_NOTES.md` older than `BUSINESS_RULES.md` → the + module may not implement the latest rule set; list which. + +## 3 — Secrets hygiene + +- Does `analysis/.gitignore` exist and cover `SECRETS.local.md` / + `*.local.patch`? (`git check-ignore` when in a git repo.) +- If `SECRETS.local.md` exists: confirm it is NOT tracked + (`git ls-files --error-unmatch`, expect failure) and has never been + committed (`git log --all --oneline -- <path>`, expect empty). If + either check fails, say so prominently and recommend rotation plus + history scrubbing. + +## 4 — Verdict + +End with three lines: +- **Where you are** — the furthest completed stage and roughly how much + of the system it covers (e.g. "mapped 100%, 2 of 14 modules + transformed"). +- **What's stale** — or "nothing". +- **Next command** — the single most useful next step, with a one-line + reason. diff --git a/plugins/code-modernization/commands/modernize-transform.md b/plugins/code-modernization/commands/modernize-transform.md index 99961249..139c354d 100644 --- a/plugins/code-modernization/commands/modernize-transform.md +++ b/plugins/code-modernization/commands/modernize-transform.md @@ -29,7 +29,8 @@ proof. ## Step 0b — Plan (HITL gate) Read the source module and any business rules in `analysis/$1/BUSINESS_RULES.md` -that reference it. Then **enter plan mode** and present: +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): - Which source files are in scope - The target module structure (packages/classes/files you'll create) - Which business rules / behaviors this module implements @@ -47,7 +48,9 @@ identify every observable behavior, and encode each as a test case with concrete input → expected output pairs derived from the legacy logic. Target framework: <appropriate for $3>. Write to `modernized/$1/$2/src/test/`. These tests define 'done' — the new code -must pass all of them." +must pass all of them. Follow your secret-handling rules: no credential +literal from legacy code becomes a fixture; substitute fake same-shape +values and read anything genuinely live from environment variables." Show the user the test file. Get a 👍 before proceeding. @@ -85,6 +88,10 @@ Then show a visual diff of one representative behavior, legacy vs modern: ```bash delta --side-by-side <(sed -n '<lines>p' legacy/$1/<file>) modernized/$1/$2/src/main/<file> ``` +(Fall back to `diff -y --width=160` if `delta` isn't installed.) Never +pick a credential-bearing line range for this diff, and mask any +credential-like literal quoted in TRANSFORMATION_NOTES.md — the notes +live in `modernized/` and get committed. ## Step 5 — Architecture review |
