summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/commands
diff options
context:
space:
mode:
authorMorgan Lunt <morganl@anthropic.com>2026-06-08 15:03:49 -0700
committerMorgan Lunt <morganl@anthropic.com>2026-06-09 08:48:04 -0700
commit874596818685794ad06efcf5db115acaf938da68 (patch)
treeb53d96af7f976281db7ce1dcc340d1d16affc85a /plugins/code-modernization/commands
parent1c4a5cfded2cb2e4c8c5420ebd2f3974eb3fdd51 (diff)
code-modernization: harden topology viewer and template injection
Fixes from an adversarial review of the new viewer: - pin d3 to 7.9.0 and load it via dynamic import with an explicit error panel when the CDN is unreachable (previously a blocked CDN produced a silent dark page — a real concern for restricted networks) - coerce ids/names/loc at intake: a single missing name or non-numeric loc previously threw inside the render loop or propagated NaN through the pack layout, blanking the canvas with no error - normalize flows/steps/edges defensively (null entries, missing steps, numeric ids vs string lookups) - mirror the level-of-detail reveal rule in the hit test so clicks can't select nodes that aren't drawn - scope the Escape shortcut so clearing the search box doesn't reset the viewport; set zoom clickDistance(4) so trackpad jitter doesn't swallow selection clicks - round canvas backing-store size (fractional devicePixelRatio caused a reallocation every frame on 125%/150% display scaling) - modernize-map: use braced ${CLAUDE_PLUGIN_ROOT} so substitution actually happens, assert the injection marker exists in the template, and correct the documented failure mode
Diffstat (limited to 'plugins/code-modernization/commands')
-rw-r--r--plugins/code-modernization/commands/modernize-map.md18
1 files changed, 11 insertions, 7 deletions
diff --git a/plugins/code-modernization/commands/modernize-map.md b/plugins/code-modernization/commands/modernize-map.md
index 5f210a5d..21eb58e2 100644
--- a/plugins/code-modernization/commands/modernize-map.md
+++ b/plugins/code-modernization/commands/modernize-map.md
@@ -127,20 +127,24 @@ numbered path. Build it from the template that ships with this plugin —
do not hand-write the viewer:
```bash
-python3 - "$CLAUDE_PLUGIN_ROOT/assets/topology-viewer.html" analysis/$1 <<'EOF'
+python3 - "${CLAUDE_PLUGIN_ROOT}/assets/topology-viewer.html" analysis/$1 <<'EOF'
import json, sys
tpl_path, out_dir = sys.argv[1], sys.argv[2]
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")))
-html = tpl.replace("/*__TOPOLOGY_DATA__*/ null", "/*__TOPOLOGY_DATA__*/ " + data)
-open(f"{out_dir}/TOPOLOGY.html", "w").write(html)
-print(f"wrote {out_dir}/TOPOLOGY.html ({len(html):,} bytes)")
+open(f"{out_dir}/TOPOLOGY.html", "w").write(
+ tpl.replace(marker, "/*__TOPOLOGY_DATA__*/ " + data))
+print(f"wrote {out_dir}/TOPOLOGY.html")
EOF
```
-The viewer loads d3 from a CDN, so opening it needs network access; the
-rest is self-contained. If the data injection marker is missing from the
-output, the template was not found — check `$CLAUDE_PLUGIN_ROOT`.
+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.
Mermaid stays for **small, exportable** diagrams. Generate standalone
`.mmd` files for reuse in docs and PRs — but keep each under ~40 edges;