diff options
| author | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 20:15:45 -0700 |
|---|---|---|
| committer | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 20:15:45 -0700 |
| commit | 696904602b2bdf3e0ddd07ae1221f9eb3e3b8e62 (patch) | |
| tree | 9888e8e8a4465f5886dcfa1087702d691178acb1 /plugins/code-modernization/scripts | |
| parent | cafefb304bde4070c6c0877528ee49c1252eff85 (diff) | |
code-modernization: rate rules by what the system is for, and make live runs 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.
Diffstat (limited to 'plugins/code-modernization/scripts')
| -rw-r--r-- | plugins/code-modernization/scripts/render_rules.py | 7 | ||||
| -rw-r--r-- | plugins/code-modernization/scripts/tests/test_rules_tools.py | 3 |
2 files changed, 7 insertions, 3 deletions
diff --git a/plugins/code-modernization/scripts/render_rules.py b/plugins/code-modernization/scripts/render_rules.py index da375f55..88d75625 100644 --- a/plugins/code-modernization/scripts/render_rules.py +++ b/plugins/code-modernization/scripts/render_rules.py @@ -5,7 +5,7 @@ Reads analysis/<system>/rules_result.json (the object the workflow returned, saved by the command) and writes analysis/<system>/BUSINESS_RULES.md and DATA_OBJECTS.md. Rules are -numbered RULE-001, RULE-002, ... in priority then category order and the heading is always +numbered RULE-001, RULE-002, ... in the order they appear (by category, then priority) and the heading is always `### RULE-NNN: <name>`, the pattern later commands and the pane look for. Every value comes from analysis of untrusted code, so it is written as plain text on one line where it is a heading or a table cell. Standard library only. @@ -83,9 +83,10 @@ def main(argv): print(f'Cannot read {result_path}: {error}', file=sys.stderr) return 1 + # Numbered in the order they appear in the document (by category, then priority), so RULE-001.. read in sequence. rules = sorted(result.get('confirmedRules') or [], - key=lambda r: (PRIORITY.get(r.get('priority'), 1), - CATEGORIES.index(r['category']) if r.get('category') in CATEGORIES else 9, + key=lambda r: (CATEGORIES.index(r['category']) if r.get('category') in CATEGORIES else 9, + PRIORITY.get(r.get('priority'), 1), str(r.get('source')))) numbered = [(i + 1, r) for i, r in enumerate(rules)] rendered = {n: render_rule(n, r) for n, r in numbered} diff --git a/plugins/code-modernization/scripts/tests/test_rules_tools.py b/plugins/code-modernization/scripts/tests/test_rules_tools.py index f0bbc391..632b2250 100644 --- a/plugins/code-modernization/scripts/tests/test_rules_tools.py +++ b/plugins/code-modernization/scripts/tests/test_rules_tools.py @@ -1,5 +1,6 @@ import json import os +import re import subprocess import sys import tempfile @@ -149,6 +150,8 @@ class RenderTests(unittest.TestCase): headings = [line for line in text.splitlines() if line.startswith('### ')] self.assertEqual(len(headings), 2, headings) self.assertNotIn('\n# injected heading', text) + ids = [int(n) for n in re.findall(r'^### RULE-(\d+): ', text, re.M)] + self.assertEqual(ids, list(range(1, len(ids) + 1)), 'rule numbers read in sequence down the document') self.assertIn('Rules requiring SME confirmation', text) self.assertIn('Is it 5 or 6?', text) self.assertIn('Coverage gaps', text) |
