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);
}