diff options
| author | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 18:07:14 -0700 |
|---|---|---|
| committer | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 18:11:07 -0700 |
| commit | c9e990089c6c87cb96e227e998edbada1df82861 (patch) | |
| tree | 623eb2b217930fd1e56558946443cd2ddeb5b849 /plugins/code-modernization/hooks/review | |
| parent | 70caddcb673ac8995d6a5191e02ac51de579d6c3 (diff) | |
code-modernization: add an optional live progress pane
Adds a hooks module, off unless the CLI's early-access function hooks
are enabled, that draws a pane beside the transcript while the commands
run: the system, which steps are done, a map of its code, each unit of
work and where it stands, what needs attention, and the next command.
It reads only the artifacts the commands write and the legacy tree, so
it works for any language and for a rewrite, a same-stack uplift or a
greenfield rebuild. The map comes from topology.json when there is one
and from the source tree when there is not. In an uplift each module is
set against the baseline; tests are read from JUnit XML, .trx reports or
the runs a session sees; a button shows and hides the pane, and
/modernize-panel does the same from the keyboard.
The same module adds x-ray context on legacy reads, a review deck for
business rules (/modernize-review), a sign-off dialog (/modernize-sign)
and a fleet view that spots one failure repeating across agents. It
only watches: it never blocks, rewrites or restores an edit, and it runs
no program inside the trees it reads. An uplift's changed modules are
found by comparing the working copy with the tree by file name and size
through the file API. Its options are the plugin's userConfig. Without
the flag nothing loads and the commands, agents and workflows behave as
before.
91 tests in tests/ run with "claude plugin test"; plugin validate
passes on the release build with the flag on and off.
Diffstat (limited to 'plugins/code-modernization/hooks/review')
| -rw-r--r-- | plugins/code-modernization/hooks/review/deck.ts | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/plugins/code-modernization/hooks/review/deck.ts b/plugins/code-modernization/hooks/review/deck.ts new file mode 100644 index 00000000..823b7969 --- /dev/null +++ b/plugins/code-modernization/hooks/review/deck.ts @@ -0,0 +1,121 @@ +import type { ReviewLedger, ReviewVerdict } from '../reader/progress' +import { needsReview, type Rule, type RuleSet } from '../reader/rules' + +/** + * The rule review deck: the rules a person should look at, in the order they + * matter, and the ledger of what that person decided. The ledger is a file + * of its own beside the rules (`RULE_REVIEWS.json`, with a readable + * `RULE_REVIEWS.md`), so the agent-written rules file is never edited. + */ + +export type DeckScope = 'flagged' | 'p0' | 'all' + +const weight = (rule: Rule): number => + (rule.priority === 'P0' ? 0 : rule.priority === 'P1' ? 10 : 20) + + (rule.sme !== undefined ? 0 : 2) + + (rule.defect !== undefined ? 0 : 1) + + (rule.confidence !== undefined && rule.confidence !== 'High' ? 0 : 1) + +/** The rules to review under `scope`, optionally only those citing a file or under a domain. */ +export function queueOf(rules: RuleSet, scope: DeckScope, filter = ''): Rule[] { + const wanted = filter.trim().toLowerCase() + + return rules.rules + .filter(rule => { + if (scope === 'flagged' && !(rule.priority === 'P0' && needsReview(rule))) { + return false + } + + if (scope === 'p0' && rule.priority !== 'P0') { + return false + } + + if (wanted === '') { + return true + } + + return ( + rule.id.toLowerCase() === wanted || + (rule.domain ?? '').toLowerCase().includes(wanted) || + rule.title.toLowerCase().includes(wanted) || + rule.citations.some(citation => citation.base.includes(wanted)) || + // What the rule says and what is suspected of it: "truncat" finds the rounding defect whatever its title. + [rule.statement, rule.then, rule.defect].some(text => (text ?? '').toLowerCase().includes(wanted)) + ) + }) + .map((rule, index) => ({ rule, index })) + .sort((a, b) => weight(a.rule) - weight(b.rule) || a.index - b.index) + .map(entry => entry.rule) +} + +/** The first card at or after `from` that has no verdict yet; `from` itself when all have. */ +export function nextUnreviewed(queue: readonly Rule[], ledger: ReviewLedger, from: number): number { + for (let step = 0; step < queue.length; step += 1) { + const index = (from + step) % queue.length + const rule = queue[index] + + if (rule !== undefined && ledger[rule.id] === undefined) { + return index + } + } + + return Math.min(Math.max(0, from), Math.max(0, queue.length - 1)) +} + +/** `ledger` with `rule` decided. */ +export function decide( + ledger: ReviewLedger, + rule: Rule, + verdict: ReviewVerdict, + atIso: string, +): ReviewLedger { + return { ...ledger, [rule.id]: { verdict, at: atIso, title: rule.title } } +} + +/** `ledger` with `rule`'s verdict taken back. */ +export function undecide(ledger: ReviewLedger, ruleId: string): ReviewLedger { + const { [ruleId]: _gone, ...rest } = ledger + + return rest +} + +export const tallyOf = (queue: readonly Rule[], ledger: ReviewLedger) => ({ + total: queue.length, + confirmed: queue.filter(rule => ledger[rule.id]?.verdict === 'confirmed').length, + wrong: queue.filter(rule => ledger[rule.id]?.verdict === 'wrong').length, + discuss: queue.filter(rule => ledger[rule.id]?.verdict === 'discuss').length, + open: queue.filter(rule => ledger[rule.id] === undefined).length, +}) + +/** The ledger as `RULE_REVIEWS.json` stores it. */ +export function ledgerJson(system: string, ledger: ReviewLedger): string { + return `${JSON.stringify({ system, version: 1, reviews: ledger }, null, 2)}\n` +} + +const VERDICT_WORDS: Record<ReviewVerdict, string> = { + confirmed: 'Confirmed', + wrong: 'Wrong', + discuss: 'Needs discussion', +} + +/** The ledger as a page a person or a model reads: `RULE_REVIEWS.md`. */ +export function ledgerMarkdown(system: string, ledger: ReviewLedger): string { + const entries = Object.entries(ledger).sort((a, b) => a[0].localeCompare(b[0], 'en', { numeric: true })) + const count = (verdict: ReviewVerdict) => entries.filter(([, entry]) => entry.verdict === verdict).length + + return [ + `# Rule reviews: ${system}`, + '', + `A person's verdict on individual business rules in \`BUSINESS_RULES.md\`, recorded from the review deck. ${count('confirmed')} confirmed, ${count('wrong')} wrong, ${count('discuss')} needing discussion.`, + '', + 'A rule marked **Wrong** or **Needs discussion** is not settled: do not build on it until it is resolved. A rule with no row here has not been reviewed.', + '', + '| Rule | Verdict | When | Title |', + '|---|---|---|---|', + ...entries.map( + ([id, entry]) => + `| ${id} | ${VERDICT_WORDS[entry.verdict]} | ${entry.at.slice(0, 10)} | ${(entry.title ?? '').replace(/\|/g, '\\|')} |`, + ), + '', + ].join('\n') +} |
