refactor: simplify pass (trekexecute)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-10-16 01:44:43 +02:00
commit bb3884d0f4
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
3 changed files with 16 additions and 17 deletions

View file

@ -50,7 +50,7 @@
import { resolve } from 'node:path';
import {
normalizeSeverity, contentOverlap, contentTokens, DEFAULT_THRESHOLD, ANCHOR_MIN_CONTENT_WORDS,
normalizeSeverity, contentOverlap, contentTokens, DEFAULT_THRESHOLD, ANCHOR_MIN_CONTENT_WORDS, SEVERITIES,
} from './plan-review-dedup.mjs';
import { getRule } from './rule-catalogue.mjs';
@ -215,8 +215,7 @@ export function lineDiff(oldText, newText) {
// ---- counting (rule A, rule B) ----------------------------------------------------
// Lower index = more severe; an unrated severity counts as blocker.
const SEV_ORDER = ['blocker', 'major', 'minor'];
const rankOf = s => SEV_ORDER.indexOf(s);
const rankOf = s => SEVERITIES.indexOf(s);
const countedOf = s => normalizeSeverity(s) ?? 'blocker';
const higher = (a, b) => (rankOf(a) <= rankOf(b) ? a : b);
const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
@ -363,7 +362,7 @@ function carry(p, matched, d, current, prevRound) {
out.line = current.opToFull[n] ?? out.line;
const e = Number.isInteger(p.op_line_end) ? (d.oldToNew[p.op_line_end] ?? null) : null;
const eFull = e !== null ? (current.opToFull[e] ?? null) : null;
if (e !== null && eFull !== null) {
if (eFull !== null) {
out.line_end = eFull;
out.op_line_end = e;
} else {
@ -389,7 +388,7 @@ function carry(p, matched, d, current, prevRound) {
}
/** One line: the reason a round is counted fully. */
const oneLine = s => String(s).replace(/\s*[\r\n]+\s*/g, ' ').trim();
export const oneLine = s => String(s).replace(/\s*[\r\n]+\s*/g, ' ').trim();
/**
* Count one critic round by rule A (from round 2, against the diff since the

View file

@ -51,7 +51,7 @@
import { readFileSync } from 'node:fs';
import { jaccardSimilarity, meetsThreshold } from '../parsers/jaccard.mjs';
import { computeFindingId } from '../parsers/finding-id.mjs';
import { computeFindingId, parseFindingId } from '../parsers/finding-id.mjs';
import { isMain } from '../util/is-main.mjs';
export const DEFAULT_THRESHOLD = 0.7;
@ -160,12 +160,10 @@ function normalizeAgentPayload(payload, fallbackAgent) {
return { agent, pairs: findings.map(f => ({ agent, finding: f })), previous };
}
const FINDING_ID_RE = /^[0-9a-f]{40}$/;
/** A reviewer's mark on a previous finding, or null when it is not {id: 40-hex, resolved: boolean}. */
function readMark(m, agent) {
if (!m || typeof m !== 'object') return null;
if (typeof m.id !== 'string' || !FINDING_ID_RE.test(m.id)) return null;
if (!parseFindingId(m.id).valid) return null;
if (typeof m.resolved !== 'boolean') return null;
return { agent, id: m.id, resolved: m.resolved };
}
@ -278,8 +276,9 @@ export function dedupFindings(sources, opts = {}) {
for (const f of survivors) {
if (taken.has(f.id)) {
let n = 2;
while (taken.has(idOf(f.file, f.line, `${f.rule_key ?? 'unknown'}#${n}`))) n += 1;
f.id = idOf(f.file, f.line, `${f.rule_key ?? 'unknown'}#${n}`);
let id;
while (taken.has(id = idOf(f.file, f.line, `${f.rule_key ?? 'unknown'}#${n}`))) n += 1;
f.id = id;
}
taken.add(f.id);
}

View file

@ -98,7 +98,7 @@ import { dirname, join, resolve } from 'node:path';
import { validatePlanContent } from './plan-validator.mjs';
import { splitSections, fenceTracker, extractPlanVersion, versionAtLeast } from '../parsers/plan-schema.mjs';
import { normalizeSeverity } from '../review/plan-review-dedup.mjs';
import { countRound, lineDiff } from '../review/critic-diff.mjs';
import { countRound, lineDiff, oneLine } from '../review/critic-diff.mjs';
import { resolveRepo } from '../verification/repo-tools.mjs';
import { isMain } from '../util/is-main.mjs';
@ -183,9 +183,11 @@ export function operativeLines(text) {
}
export function planHash(text) {
return createHash('sha256').update(operativeText(text)).digest('hex');
return sha256(operativeText(text));
}
const sha256 = s => createHash('sha256').update(s).digest('hex');
/**
* @returns {{found: boolean, placeholder: boolean, verdict: object|null, error: string|null}}
* placeholder = a `## Critic Verdict` heading with no fenced block at all
@ -280,7 +282,8 @@ export function recordVerdict(text, dedup, opts = {}) {
if (missing.length > 0) {
return { code: 2, message: `reviewer(s) missing from the dedup input: ${missing.join(', ')} — an absent review is not a clean one; rerun the round` };
}
const current = planHash(text);
const lines = operativeLines(text);
const current = sha256(lines.text);
if (typeof opts.reviewed !== 'string' || !/^[0-9a-f]{64}$/.test(opts.reviewed)) {
return { code: 2, message: '--reviewed <sha256> is required: take it with --hash before the reviewers read the plan' };
}
@ -305,7 +308,6 @@ export function recordVerdict(text, dedup, opts = {}) {
}
const extra = prevExtra + (capped ? 1 : 0);
const diffMode = opts.base !== undefined || opts.baseNote !== undefined || opts.planPaths !== undefined;
const lines = operativeLines(text);
const c = countRound({
round,
previous: prev.verdict ?? null,
@ -441,7 +443,6 @@ function out(obj) {
}
const SNAPSHOT_MAX_BYTES = 4 * 1024 * 1024;
const oneLine = s => String(s).replace(/\s*[\r\n]+\s*/g, ' ').trim();
/** `<git dir>/voyage/plan-snapshots` of the repo holding the plan file, or null (no cwd fallback). */
function snapshotDir(planPath) {
@ -524,7 +525,7 @@ function diffReport(text, dir) {
const lb = loadBase(text, dir);
if (!lb.base) return none(lb.reason);
const cur = operativeLines(text);
if (lb.base.sha256 === planHash(text)) return none(`the plan has not changed since round ${lb.verdict.round}`);
if (lb.base.sha256 === sha256(cur.text)) return none(`the plan has not changed since round ${lb.verdict.round}`);
const oldL = lb.base.text.split('\n');
const newL = cur.text.split('\n');
const newCount = newL.length - 1; // the operative text ends with '\n'