From 51b1ae9e20486d62b839ed9f37e1cfc7d55bf85c Mon Sep 17 00:00:00 2001 From: Morgan Lunt Date: Thu, 24 Sep 2026 20:52:27 -0700 Subject: 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/ 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. --- .../hooks/reader/verification.ts | 150 +++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 plugins/code-modernization/hooks/reader/verification.ts (limited to 'plugins/code-modernization/hooks/reader/verification.ts') diff --git a/plugins/code-modernization/hooks/reader/verification.ts b/plugins/code-modernization/hooks/reader/verification.ts new file mode 100644 index 00000000..c1d6e556 --- /dev/null +++ b/plugins/code-modernization/hooks/reader/verification.ts @@ -0,0 +1,150 @@ +import { plain } from '../text' +import type { TrackKey } from './tracks' + +/** + * `analysis//VERIFICATION.json`, written by the proof pack (`scripts/proof_pack.py`, run by the verify + * command): one verdict per built module, computed by a script from the evidence files. The pane shows the verdicts + * as they are and never computes one. + * + * The file is text from a run on an untrusted tree, and its shape may move between releases, so it is read + * tolerantly: a field of the wrong type is ignored, a verdict is only ever one of the three exact words, a name or a + * reason is cut to one short plain line, and how much is read is capped. + */ + +export type Verdict = 'PROVEN' | 'PARTLY PROVEN' | 'NOT PROVEN' + +const VERDICTS: readonly string[] = ['PROVEN', 'PARTLY PROVEN', 'NOT PROVEN'] + +/** What one module's verdict is, as the file says it. */ +export type ProofEntry = { + /** The module: a folder under `modernized//`, or the uplift's whole working copy. */ + name: string + track: TrackKey + verdict: Verdict + /** The first reason the verdict is not PROVEN, as one plain line; empty when the file gives none. */ + reason: string + /** When the module was checked; null when the file gives no time this can read. */ + atMs: number | null +} + +export type Verification = { + overall: Verdict | null + entries: ProofEntry[] +} + +/** How the module is standing with the proof, for a chip and for the next step. */ +export type ProofState = { + /** `none`: built, and nothing checked it yet. `changed`: checked, and its code or tests are newer than that check. */ + state: 'proven' | 'partly' | 'not' | 'changed' | 'none' + verdict?: Verdict + reason: string +} + +const MAX_TEXT = 4_000_000 +const MAX_ENTRIES = 1_000 +const MAX_NAME = 80 +const MAX_REASON = 160 + +/** The proof pack's own spelling of a track: a rewrite is `rewrite` there. */ +const TRACK_OF: Record = { rewrite: 'transform', transform: 'transform', uplift: 'uplift', reimagine: 'reimagine' } + +/** `2026-09-24 20:31 UTC` (the pack's stamp) as milliseconds since the epoch; null when it is anything else. */ +function timeOf(value: unknown): number | null { + if (typeof value !== 'string') { + return null + } + + const match = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})(?::(\d{2}))?\s*(?:UTC|Z)?$/.exec(value.trim()) + + if (match === null) { + return null + } + + const ms = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number(match[6] ?? 0)) + + return Number.isFinite(ms) ? ms : null +} + +const isRecord = (value: unknown): value is Record => typeof value === 'object' && value !== null && !Array.isArray(value) + +/** The file's text as a Verification; null when it is not one. */ +export function parseVerification(text: string): Verification | null { + if (text.length > MAX_TEXT) { + return null + } + + let raw: unknown + + try { + raw = JSON.parse(text) + } catch { + return null + } + + if (!isRecord(raw) || !Array.isArray(raw.modules)) { + return null + } + + const entries: ProofEntry[] = [] + + for (const item of raw.modules.slice(0, MAX_ENTRIES) as unknown[]) { + if (!isRecord(item)) { + continue + } + + const name = typeof item.name === 'string' ? plain(item.name, MAX_NAME) : '' + const track = typeof item.track === 'string' ? TRACK_OF[item.track] : undefined + + // Only the exact words count: a verdict with anything added to it is not one. + if (name === '' || track === undefined || typeof item.verdict !== 'string' || !VERDICTS.includes(item.verdict)) { + continue + } + + const first = Array.isArray(item.reasons) ? (item.reasons as unknown[]).find(reason => typeof reason === 'string' && reason.trim() !== '') : undefined + + entries.push({ + name, + track, + verdict: item.verdict as Verdict, + reason: typeof first === 'string' ? plain(first, MAX_REASON) : '', + atMs: timeOf(item.verifiedAt), + }) + } + + const overall = isRecord(raw.overall) && typeof raw.overall.verdict === 'string' && VERDICTS.includes(raw.overall.verdict) ? (raw.overall.verdict as Verdict) : null + + return { overall, entries } +} + +/** The pack stamps minutes; a file written in the same minute as the check is not newer than it. */ +const SLACK_MS = 90_000 + +/** + * Where a built module stands with the proof. Null when it has no notes and no verdict, so nothing is claimed of a + * module still being built. + * + * @param verification the file, or null when there is none + * @param track the track the pane follows + * @param name the module's folder under `modernized/` + * @param changedAtMs when the module's notes or test reports last changed (0 when unknown) + * @param hasNotes whether the module has notes: the sign a module was finished being built + */ +export function proofOfModule( + verification: Verification | null, + track: TrackKey, + name: string, + changedAtMs: number, + hasNotes: boolean, +): ProofState | null { + const entry = verification?.entries.find(candidate => candidate.track === track && candidate.name.toLowerCase() === plain(name, MAX_NAME).toLowerCase()) + + if (entry === undefined) { + return hasNotes ? { state: 'none', reason: '' } : null + } + + if (entry.atMs !== null && changedAtMs > entry.atMs + SLACK_MS) { + return { state: 'changed', verdict: entry.verdict, reason: entry.reason } + } + + return { state: entry.verdict === 'PROVEN' ? 'proven' : entry.verdict === 'PARTLY PROVEN' ? 'partly' : 'not', verdict: entry.verdict, reason: entry.reason } +} -- cgit From d49ccb3844876e35262a32f145b7b717646da733 Mon Sep 17 00:00:00 2001 From: Morgan Lunt Date: Fri, 25 Sep 2026 11:28:44 -0700 Subject: code-modernization: a rule is tested only if a test that ran backs it A rule named only by a skipped or pending test no longer counts as covered. It is listed as "named, not run" and fails the rules check. A test-only folder is listed as tooling and gets no verdict. The verify command tries malformed records only when the person asked for exact behavior, so a proof loop has an end. The report parses rule headings and fields in linear time, and the report and pane show the new status. --- .../code-modernization/hooks/reader/verification.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'plugins/code-modernization/hooks/reader/verification.ts') diff --git a/plugins/code-modernization/hooks/reader/verification.ts b/plugins/code-modernization/hooks/reader/verification.ts index c1d6e556..94ef6666 100644 --- a/plugins/code-modernization/hooks/reader/verification.ts +++ b/plugins/code-modernization/hooks/reader/verification.ts @@ -30,6 +30,8 @@ export type ProofEntry = { export type Verification = { overall: Verdict | null entries: ProofEntry[] + /** Built folders that hold only test code and the files that build it: the pack lists them and judges none, so the pane says nothing of them. */ + tooling: { track: TrackKey; name: string }[] } /** How the module is standing with the proof, for a chip and for the next step. */ @@ -112,8 +114,18 @@ export function parseVerification(text: string): Verification | null { } const overall = isRecord(raw.overall) && typeof raw.overall.verdict === 'string' && VERDICTS.includes(raw.overall.verdict) ? (raw.overall.verdict as Verdict) : null + const tooling: Verification['tooling'] = [] - return { overall, entries } + for (const item of (Array.isArray(raw.toolingOnly) ? (raw.toolingOnly as unknown[]) : []).slice(0, MAX_ENTRIES)) { + const name = isRecord(item) && typeof item.name === 'string' ? plain(item.name, MAX_NAME) : '' + const track = isRecord(item) && typeof item.track === 'string' && Object.hasOwn(TRACK_OF, item.track) ? TRACK_OF[item.track] : undefined + + if (name !== '' && track !== undefined) { + tooling.push({ track, name }) + } + } + + return { overall, entries, tooling } } /** The pack stamps minutes; a file written in the same minute as the check is not newer than it. */ @@ -121,7 +133,7 @@ const SLACK_MS = 90_000 /** * Where a built module stands with the proof. Null when it has no notes and no verdict, so nothing is claimed of a - * module still being built. + * module still being built, and null for a folder the pack lists as test tooling (only test code and build files: nothing to prove). * * @param verification the file, or null when there is none * @param track the track the pane follows @@ -139,7 +151,9 @@ export function proofOfModule( const entry = verification?.entries.find(candidate => candidate.track === track && candidate.name.toLowerCase() === plain(name, MAX_NAME).toLowerCase()) if (entry === undefined) { - return hasNotes ? { state: 'none', reason: '' } : null + const isTooling = verification?.tooling.some(item => item.track === track && item.name.toLowerCase() === plain(name, MAX_NAME).toLowerCase()) === true + + return hasNotes && !isTooling ? { state: 'none', reason: '' } : null } if (entry.atMs !== null && changedAtMs > entry.atMs + SLACK_MS) { -- cgit