diff options
| author | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 20:52:27 -0700 |
|---|---|---|
| committer | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 20:52:27 -0700 |
| commit | 51b1ae9e20486d62b839ed9f37e1cfc7d55bf85c (patch) | |
| tree | eb31cc4964d84b4a82b8032452739fe1e9b37d3f /plugins/code-modernization/hooks/review | |
| parent | 5b8ec4b30f45b5e8b4c8a6efd63719730cf1a5ad (diff) | |
code-modernization: make the live pane work below 144 columns and show the proof
Found by exercising the pane against the real outputs of finished runs:
- Below 144 columns the engine holds an unasked pane back; the pane ignored
that, so it drew no pane, no show bar, and the panel command "hid" a pane
that was never there.
- A symlinked legacy/<name> lists as another kind of entry, so the source
link that preflight now creates was never recognized as a system.
- Uplift and reimagine next steps were placeholders with no button.
- The refresh debounce was starved while agents ran, so the map froze.
- Hostile lines in the brief, rules and baseline could take seconds to match;
lines are now capped. The rule-review ledger is validated on read and
merged on save, and keeps a reviewer's note.
- A baseline with no row read as "the baseline had 0"; one-module baseline
totals now count as that module's row.
New: a verdict chip with words on every built module, a verify-first next
step, and a readable palette that follows the terminal theme. 140 engine
tests pass and the type check is clean.
Diffstat (limited to 'plugins/code-modernization/hooks/review')
| -rw-r--r-- | plugins/code-modernization/hooks/review/deck.ts | 14 | ||||
| -rw-r--r-- | plugins/code-modernization/hooks/review/ledger.ts | 78 |
2 files changed, 88 insertions, 4 deletions
diff --git a/plugins/code-modernization/hooks/review/deck.ts b/plugins/code-modernization/hooks/review/deck.ts index 823b7969..b03739ea 100644 --- a/plugins/code-modernization/hooks/review/deck.ts +++ b/plugins/code-modernization/hooks/review/deck.ts @@ -69,7 +69,10 @@ export function decide( verdict: ReviewVerdict, atIso: string, ): ReviewLedger { - return { ...ledger, [rule.id]: { verdict, at: atIso, title: rule.title } } + // The reviewer's own words on the rule stay through a new verdict: the deck decides, it does not rewrite what was said. + const note = ledger[rule.id]?.note + + return { ...ledger, [rule.id]: { verdict, at: atIso, title: rule.title, ...(note !== undefined && { note }) } } } /** `ledger` with `rule`'s verdict taken back. */ @@ -98,6 +101,9 @@ const VERDICT_WORDS: Record<ReviewVerdict, string> = { discuss: 'Needs discussion', } +/** One table cell: one line, no pipe that would end it. */ +const cell = (text: string | undefined): string => (text ?? '').replace(/\s+/g, ' ').replace(/\\/g, '\\\\').replace(/\|/g, '\\|').trim() + /** 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 })) @@ -110,11 +116,11 @@ export function ledgerMarkdown(system: string, ledger: ReviewLedger): string { '', '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 |', - '|---|---|---|---|', + '| Rule | Verdict | When | Title | Note |', + '|---|---|---|---|---|', ...entries.map( ([id, entry]) => - `| ${id} | ${VERDICT_WORDS[entry.verdict]} | ${entry.at.slice(0, 10)} | ${(entry.title ?? '').replace(/\|/g, '\\|')} |`, + `| ${id} | ${VERDICT_WORDS[entry.verdict]} | ${entry.at.slice(0, 10)} | ${cell(entry.title)} | ${cell(entry.note)} |`, ), '', ].join('\n') diff --git a/plugins/code-modernization/hooks/review/ledger.ts b/plugins/code-modernization/hooks/review/ledger.ts new file mode 100644 index 00000000..4ebc3b0f --- /dev/null +++ b/plugins/code-modernization/hooks/review/ledger.ts @@ -0,0 +1,78 @@ +import { plain } from '../text' +import type { ReviewLedger, ReviewVerdict } from '../reader/progress' + +/** + * `RULE_REVIEWS.json`, read without trusting it. Two writers keep it: this deck, and the `modernize-review` command + * for people who work without the pane. Each entry is `{ verdict, at, title?, note? }`, the note being the reviewer's + * own words. The file sits in a workspace anyone may have edited, and a model may have written it, so every value is + * checked: a verdict is one of three exact words, a rule id is one plain token, a title or a note is cut to one short + * plain line, and anything else in an entry is dropped. + */ + +const VERDICTS: readonly string[] = ['confirmed', 'wrong', 'discuss'] + +/** What a note may hold: a reviewer's sentence or two, not a document. */ +export const MAX_NOTE = 500 +const MAX_TITLE = 120 +const MAX_ENTRIES = 5_000 +const RULE_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,39}$/ +const FORBIDDEN_ID = new Set(['__proto__', 'constructor', 'prototype']) + +const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value) + +/** The ledger a file's text holds; empty when it is not one. */ +export function parseLedger(text: string | null): ReviewLedger { + if (text === null || text.length > 4_000_000) { + return {} + } + + let raw: unknown + + try { + raw = JSON.parse(text) + } catch { + return {} + } + + if (!isRecord(raw) || !isRecord(raw.reviews)) { + return {} + } + + const ledger: ReviewLedger = {} + + for (const [id, item] of Object.entries(raw.reviews).slice(0, MAX_ENTRIES)) { + if (!RULE_ID.test(id) || FORBIDDEN_ID.has(id) || !isRecord(item) || typeof item.verdict !== 'string' || !VERDICTS.includes(item.verdict)) { + continue + } + + const title = typeof item.title === 'string' ? plain(item.title, MAX_TITLE) : '' + const note = typeof item.note === 'string' ? plain(item.note, MAX_NOTE) : '' + // A time is kept only when it is one: the page shows its date. + const at = typeof item.at === 'string' && /^\d{4}-\d{2}-\d{2}/.test(item.at) ? item.at.slice(0, 40) : '' + + ledger[id] = { verdict: item.verdict as ReviewVerdict, at, ...(title !== '' && { title }), ...(note !== '' && { note }) } + } + + return ledger +} + +/** + * The file's ledger with this session's decisions on top. `edits` maps a rule id to what the deck set it to, or null when the + * deck took its verdict back. What the other writer put in the file meanwhile stays, and a note the deck did not write is + * kept on a rule the deck decided again. + */ +export function mergeLedger(onDisk: ReviewLedger, edits: ReadonlyMap<string, ReviewLedger[string] | null>): ReviewLedger { + const merged: ReviewLedger = { ...onDisk } + + for (const [id, edit] of edits) { + if (edit === null) { + delete merged[id] + } else { + const note = edit.note ?? onDisk[id]?.note + + merged[id] = { ...edit, ...(note !== undefined && { note }) } + } + } + + return merged +} |
