summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/workflows/extract-rules.js
AgeCommit message (Collapse)Author
2026-09-24code-modernization: make rule consolidation auditable and injection-safeMorgan Lunt
Follow-ups from review of the consolidation pass: - The agent is a restricted type with the same read-only wording as its siblings, and every field on its numbered list is a single bounded line, so a rule name containing a newline cannot fake another entry. - A group with any number out of range or not an integer is rejected whole instead of being coerced into a different merge. - A merge keeps the most conservative review state: the highest priority, the lowest confidence, and every suspected defect and SME question of the folded rules. - Every folded rule is returned with the rule it went into, and the rules document lists them under "Rules folded into another", so nothing disappears untraceably. Extra citations show as "Also cited" without the joining word.
2026-09-24code-modernization: fold the same rule found in several files into oneMorgan Lunt
A numeric library implemented in C, in a C++ header and in a fixed-point variant produced three "twiddle factor" rules, two "generic butterfly" rules and two "factorization" rules, because the referee's duplicate key is the file plus the rule's name. The plan and the review then carry noise. After verification, one small agent per 150 rules lists the groups that describe the same behavior implemented in more than one place, told to merge only what would be implemented and tested as one thing. The kept rule cites every place (the renderer shows them as "Also cited") and takes the highest priority of its group; overlapping, out-of-range or self-merging groups are ignored, and the rule list is fenced as untrusted data. The count is reported as stats.consolidated.
2026-09-24code-modernization: keep rule extraction proportional to the codeMorgan Lunt
On a roughly thousand-line C utility the whole-estate extraction ran four rounds, spawned 223 agents and returned 141 rules (31 of them P0), because a model can always find one more micro-behavior in a small program and the loop only stopped when a round found nothing at all. Every extractor now gets the same instruction on how fine to cut a rule: one per business decision or calculation, not per branch or field, skipping plumbing, roughly one per 40 to 80 lines of real logic, and rating P0 only for the few rules that would defeat the system's purpose. The whole-estate loop defaults to two rounds and stops when a round adds under 15% of what is already catalogued.
2026-09-24code-modernization: rate rules by what the system is for, and make live runs ↵Morgan Lunt
finish Two problems from running the commands on real repositories: - The P0 definition was money- and regulation-shaped, so a music-library tool got no P0 rules and its behavior contract came out empty. P0 now means the system's core purpose depends on the rule, or a wrong result is costly or irreversible (money, legal, data integrity, security or safety, or the central calculation or decision the system exists to perform). - Citations came back as lists of ranges, and the rule renderer numbered RULE-NNN in a different order from the document. Each rule now cites one range and the numbers read in sequence. Commands that start subagents now say to run them in the foreground and wait, because a headless session ends when the model stops talking even if it said it was waiting for a background agent.
2026-09-24code-modernization: simpler commands, a source option, a report page and an ↵Morgan Lunt
equivalence check Commands hardcoded legacy/<system>, so code too big to copy, or living at an absolute path, needed a hand-made symlink. Preflight now takes --source <path> and makes the legacy/<system> link for you (a junction on Windows); nothing is copied, and every command says where the link points before it starts. The harden patch is applied with patch -p1 -d. Each command ends by naming the next command to run, and the commands are about a third shorter with no step removed: - map accepts an existing dependency graph (--graph) or the stack's own tooling, maps very large estates in resumable chunks, records reflection targets as unresolved instead of dead, asks before describing more than 40 nodes, and never gives two nodes the same location. - transform can take its module and target from the brief, counts the equivalence cases that executed (zero is a failure and a comparison never skips), shows the tests can fail with a deliberate one-line break, and hands "same or different" to a script when both systems can run. - brief writes each phase in one fixed shape: one command, module ids as in the map, and criteria written as conditions a build command may tick but not reword. - reimagine reuses the discovery artifacts instead of extracting them again. - status names the exact command to paste next. scripts/build_report.py turns whatever the commands wrote into one self-contained, offline REPORT.html (Mermaid is vendored, all text from the analysis is escaped, the quarantined secrets file is never read), and scripts/compare.py decides byte-for-byte whether two outputs match, records why, and checks it can fail. The shard builder ignores symbolic links and paths that leave the source, matches a plain name against what lies beneath it, and falls back to the directory tree when the map's modules share a location. The README drops from 275 to about 100 lines; the pane's reference moves to hooks/README.md.
2026-09-24code-modernization: extract-rules uses a shard builder and a rules renderer ↵Morgan Lunt
that ship with the plugin The command used to carry a 35-line shard-building script inline and asked the model to write a rules renderer on every run, so the shard list and the BUSINESS_RULES.md layout varied from run to run and could not be tested. scripts/make_shards.py builds the shard list from topology.json when the map has run, and from the directory tree when it has not (skipping vendored, generated and test-fixture directories, one shard per directory, split at 25 files or about 5,000 lines). scripts/render_rules.py turns the workflow's result into BUSINESS_RULES.md and DATA_OBJECTS.md with RULE-NNN headings, the SME section and the coverage gaps, and writes every value from the analysis as plain text. The workflow takes an optional sourceDir, so the code can live outside the workspace, and shard files are kept relative to it. The command drops from 305 to about 150 lines.
2026-09-24code-modernization: check module and file names before they reach a promptMorgan Lunt
extract-rules puts module names and file paths, which come from the repository's own file names, into agent prompts. They were already checked for traversal, control characters, backticks and angle brackets, but a name such as "a;curl x|sh.cbl" or "$(id).cbl" passed and could be run if an agent pasted it into a command unquoted. A module name and a domain are labels: they are never opened, so they are now cleaned instead of dropped (shell separators, quotes, glob and brace characters, a leading hyphen or space, and a dollar sign that opens an expansion become "_"), and the prompt says a name is a label only. A file path has to round-trip, so it is checked and dropped, with the drop counted and logged, when it holds a command separator, a quote, a glob, brace or bracket character, a dollar sign that opens an expansion ($(, ${, $HOME, $IFS, $@), leading or trailing whitespace, a ~ at the start of a word or after = or :, or a word that starts with - (a shell would split "a -rf.cbl" into a path and a flag). Backslashes are turned into / first, so the checks and a shell see one spelling and Windows-style paths keep working. A dollar sign before a digit or at the end stays allowed, as do #, @, ~ inside a word and a lone hyphen between spaces: mainframe member names use them ("PAY$001"), and a positional parameter expands to nothing or the shell's own name, never to anything the file's author controls. The extractor prompt also says to open paths with the Read tool and to wrap any that goes in a shell command in single quotes.
2026-09-24code-modernization: fix contradictions and stale references in existing textMorgan Lunt
Make the text say what the commands and workflows already do: where each build command writes, which commands need earlier output, the approval stop before an uplift fan-out, a version placeholder that named arguments left unusable, a reference to a README section that does not exist, and a few counts and step references. No new steps or options.
2026-09-24code-modernization: extract-rules per-module shards, resume and coverage gapsMorgan Lunt
Extraction now shards by module: one extractor per module, in ordered batches, so each agent reads a small slice instead of the whole estate. The command builds the module list from analysis/<system>/topology.json when it exists (otherwise from the directory tree), states the shard count and an agent estimate before launching, and documents how to resume an interrupted run with resumeFromRunId and how to re-run only the shards that failed. The workflow stays inside the runtime's agent cap and reports coverage gaps (skipped, failed and unverified shards) instead of returning a partial catalog without saying so. The estimate paragraph carries what was observed on a 44-program, 30,000-line system: 466 to 647 agents, about 8.8M tokens, 50 to 80 minutes. Module-mode extractors cite paths relative to legacy/<system>/, like the lens-mode extractors.
2026-09-24code-modernization: extract-rules citation paths and categoriesMorgan Lunt
2026-09-24code-modernization: named arguments and namespaced command namesMorgan Lunt
Positional placeholders are zero-based ($0 is the first argument), but every command used $1 for the first one, so arguments arrived shifted: modernize-preflight carddemo java-spring analyzed legacy/java-spring. Each command now declares its arguments in frontmatter (for example `arguments: system module target_stack`) and uses the names. A missing optional argument now expands to an empty string instead of a literal placeholder. Plugin commands resolve only by their namespaced name, so the README, command cross-references, agents, workflow descriptions and the topology viewer now say /code-modernization:modernize-*. The extract-rules workflow is renamed modernize-extract-rules-mine. It shared the command's name, so invoking the command could start the workflow directly and skip the command's instructions. Commands launch workflows by script path, so nothing else changes.
2026-07-08code-modernization: pilot-first uplift migration, brief-driven execution, ↵morganl/code-mod-experiment-firstMorgan Lunt
deeper preflight /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.
2026-06-09code-modernization: fix findings from adversarial auditMorgan Westlee Lunt
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>
2026-06-09code-modernization: second-order injection fencing, path guards, scoped ↵Morgan Westlee Lunt
scaffolder agent Addresses automated security review of the workflow conversion: - Agent-produced text (rule specs, finding descriptions, dedup lists) is fenced as untrusted data when interpolated into downstream agent prompts, with embedded fence markers stripped so the fence can't be escaped; referees and judges are told to re-derive claims from the cited code. - system/service/subdir names that land in filesystem paths inside prompts are validated against a strict pattern — traversal-shaped values throw before any agent spawns. - Reimagine scaffolding now uses a dedicated 'scaffolder' agent with an explicit minimal tool list, a single-directory write scope, and the untrusted-content discipline extended to the generated spec/architecture docs it builds from (they derive from untrusted legacy code). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-09code-modernization: dynamic workflow orchestration + untrusted-content hardeningMorgan Westlee Lunt
Four commands gain a Workflow-tool path (with direct-fan-out fallback for older builds): extract-rules loops until dry with per-rule citation referees and a P0 two-judge panel; harden runs class-scoped finders with adversarial per-finding refutation; assess --portfolio pipelines one survey agent per system with COCOMO computed uniformly in script; reimagine Phase E drops the 3-service scaffolding cap. Workflow agents return schema-validated data and only the orchestrating session writes artifacts — analysis agents are structurally read-only. All five agents gain an untrusted-content discipline section (source code is data, never instructions; comment-only claims are findings, not facts), and the README documents the prompt-injection threat model for analyzed code. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>