Sed-pipeline (16 patterns, longest-match-first) sweeper residuelle ultra*-treff i prose, command-narrativ, agent-prompts, hook-kommentarer, doc-prosa. Pipeline-utvidelser fra V4-prompten: - BSD-syntax [[:<:]]ultra[[:>:]] istedenfor \bultra\b (BSD sed mangler \b) - 6 compound-patterns for ultraplan/ultraexecute/ultraresearch/ultrabrief/ ultrareview/ultracontinue uten -local-suffiks - ultra*-stats glob -> trek*-stats glob - Linje-eksklusjon redusert til ultra-cc-architect (Q8); session-state- eksklusjonen var over-protektiv - File-eksklusjon utvidet til settings.json, package.json, plugin.json, hele .claude/-treet (gitignored + V5-territorium) Q8-undantak holdt: architecture-discovery.mjs + project-discovery.mjs urort. Filnavn-konvensjon holdt: .session-state.local.json + *.local.* preservert. Manuell narrative-fix: tests/lib/agent-frontmatter.test.mjs linje 10 mangled "/ultra*-local" til "/voyage*-local" (ingen slik kommando finnes); korrigert til "/trek*". Residualer utenfor scope (V5 handterer): package.json + .claude-plugin/ plugin.json (Step 12-14 versjons-bump). .claude/* er gitignored spec-historikk med tilsiktet BEFORE/AFTER-narrativ. Part of voyage-rebrand session 3 (Wave 4 / Step 10). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
// lib/parsers/finding-id.mjs
|
|
// Stable finding-ID for /trekreview v1.0.
|
|
//
|
|
// id = sha1(file:line:rule_key) → 40-char hex.
|
|
// Same input always produces same output (determinism floor SC4).
|
|
// node:crypto is built-in (zero-deps invariant).
|
|
|
|
import { createHash } from 'node:crypto';
|
|
|
|
const HEX_RE = /^[0-9a-f]{40}$/;
|
|
|
|
/**
|
|
* Compute a stable 40-char hex finding-ID.
|
|
* @param {string} filePath — relative path (caller normalizes if needed)
|
|
* @param {number|string} line — 1-based line number; coerced to string
|
|
* @param {string} ruleKey — must be a non-empty string from RULE_KEYS
|
|
* @returns {string} 40-char lowercase hex
|
|
* @throws {TypeError} on bad input
|
|
*/
|
|
export function computeFindingId(filePath, line, ruleKey) {
|
|
if (typeof filePath !== 'string' || filePath.length === 0) {
|
|
throw new TypeError('computeFindingId: filePath must be a non-empty string');
|
|
}
|
|
if (line === null || line === undefined) {
|
|
throw new TypeError('computeFindingId: line must be a number or numeric string');
|
|
}
|
|
if (typeof line === 'number') {
|
|
if (!Number.isFinite(line)) {
|
|
throw new TypeError('computeFindingId: line must be finite');
|
|
}
|
|
} else if (typeof line === 'string') {
|
|
if (line.length === 0) {
|
|
throw new TypeError('computeFindingId: line must not be empty string');
|
|
}
|
|
} else {
|
|
throw new TypeError('computeFindingId: line must be a number or numeric string');
|
|
}
|
|
if (typeof ruleKey !== 'string' || ruleKey.length === 0) {
|
|
throw new TypeError('computeFindingId: ruleKey must be a non-empty string');
|
|
}
|
|
|
|
const composite = `${filePath}:${line}:${ruleKey}`;
|
|
return createHash('sha1').update(composite).digest('hex');
|
|
}
|
|
|
|
/**
|
|
* Validate a finding-ID's shape (40-char lowercase hex).
|
|
* @param {string} id
|
|
* @returns {{valid: boolean}}
|
|
*/
|
|
export function parseFindingId(id) {
|
|
if (typeof id !== 'string') return { valid: false };
|
|
return { valid: HEX_RE.test(id) };
|
|
}
|