summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/workflows/extract-rules.js
diff options
context:
space:
mode:
authorMorgan Lunt <morganl@anthropic.com>2026-09-24 20:14:51 -0700
committerMorgan Lunt <morganl@anthropic.com>2026-09-24 20:14:51 -0700
commitcafefb304bde4070c6c0877528ee49c1252eff85 (patch)
tree7e3a0db85edf586817474e04253a4d9d02416676 /plugins/code-modernization/workflows/extract-rules.js
parentb10dab2f5ad83f642a03b5f800dea71651830beb (diff)
code-modernization: simpler commands, a source option, a report page and an 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.
Diffstat (limited to 'plugins/code-modernization/workflows/extract-rules.js')
-rw-r--r--plugins/code-modernization/workflows/extract-rules.js24
1 files changed, 3 insertions, 21 deletions
diff --git a/plugins/code-modernization/workflows/extract-rules.js b/plugins/code-modernization/workflows/extract-rules.js
index 369d96be..efb530d1 100644
--- a/plugins/code-modernization/workflows/extract-rules.js
+++ b/plugins/code-modernization/workflows/extract-rules.js
@@ -3,7 +3,7 @@ export const meta = {
description:
'Business-rule mining — one extractor per module in ordered batches when given a module list (else loop-until-dry lens extraction), per-rule citation verification, and a P0 confirmation panel',
whenToUse:
- 'Invoked by /code-modernization:modernize-extract-rules when the Workflow tool is available. Requires args {system, sourceDir?, modules?: [{name, domain?, files, loc?}], batchSize?, modulePattern?, maxRounds?} — pass `modules` (built from analysis/<system>/topology.json or the directory tree) to shard extraction per module; omit it for whole-estate lens extraction on small systems. Returns structured rule cards — the calling session writes BUSINESS_RULES.md and DATA_OBJECTS.md from them. Resumable after a stop: re-invoke with identical args plus resumeFromRunId and completed agents replay from the journal.',
+ 'Invoked by /code-modernization:modernize-extract-rules when the Workflow tool is available. Requires args {system, modules?: [{name, domain?, files, loc?}], batchSize?, modulePattern?, maxRounds?} — pass `modules` (built from analysis/<system>/topology.json or the directory tree) to shard extraction per module; omit it for whole-estate lens extraction on small systems. Returns structured rule cards — the calling session writes BUSINESS_RULES.md and DATA_OBJECTS.md from them. Resumable after a stop: re-invoke with identical args plus resumeFromRunId and completed agents replay from the journal.',
phases: [
{
title: 'Extract',
@@ -75,26 +75,8 @@ if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(system)) {
}
const modulePattern = (ARGS && ARGS.modulePattern) || ''
const maxRounds = Math.max(1, Math.min((ARGS && ARGS.maxRounds) || 4, 8))
-// Where the code lives: `legacy/<system>` unless the command passes `sourceDir`, the path it read from
-// analysis/<system>/SOURCE. It lands in agent prompts, so it is checked like any text from outside:
-// one line, no quotes, backticks, angle brackets, `$`, `*`, `?` or shell separators, and nothing that
-// starts like a flag or a home directory.
-const rawSourceDir = ARGS && ARGS.sourceDir
-if (
- rawSourceDir != null &&
- !(
- typeof rawSourceDir === 'string' &&
- rawSourceDir.length > 0 &&
- rawSourceDir.length <= 400 &&
- rawSourceDir === rawSourceDir.trim() &&
- !/[\x00-\x1f`<>;|&'"$*?]/.test(rawSourceDir) &&
- !rawSourceDir.startsWith('-') &&
- !rawSourceDir.startsWith('~')
- )
-) {
- throw new Error(`Unsafe sourceDir ${JSON.stringify(String(rawSourceDir).slice(0, 80))} — pass the directory as one plain line, without quotes, backticks, $ or shell separators`)
-}
-const legacyDir = rawSourceDir ? rawSourceDir.replace(/[\\/]+$/, '') || rawSourceDir : `legacy/${system}`
+// The code is `legacy/<system>`: a copy, or a symlink to where it really lives (`preflight --source` makes the link).
+const legacyDir = `legacy/${system}`
// Module list (optional). Entries and file paths land in agent prompts and
// were derived from an untrusted tree (file names), so validate shape and