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

@ -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'