Crafter.Review/interfaces/Crafter.Review-Normalize.cppm

41 lines
2.2 KiB
Text
Raw Normal View History

feat(pipeline): the pure pipeline, checked against its goldens The modules that turn a frozen range into passes and passes into a verdict: :Schema, :Tools (the DENY, git and base lists, a leaf, so the config and the pool both read them), :Plan, :Artifact, :Inventory, :Dispositions, :State, :Normalize, :Stream, :Prompt, :Config, and the URL half of :PgWire. Units, jobs, results, the config and the claude stream stay JSON from end to end, so every key keeps its place; :Text gives JSON values truthiness, get, ==, membership and Str(), and throws Dyn::Error under a name for each kind of unexpected data. Exactness where the bytes are seen: - the stream classifiers are hand-written scanners with case-insensitive folds (the Kelvin sign is a k), Unicode \b and \s, and `.` stopping at \n; the SQL call detection takes `<exe> sql` with any path before it; - config problems carry the JSON scanner's and the UTF-8 decoder's own texts, positions included; - a float total is Neumaier's compensated sum, and the build passes -ffp-contract=off: -march=native would fuse a*b+c; - `crafter-review inventory` and `config` print what the goldens record, byte for byte (the fixture and 14 configs, broken ones included); a message names this binary as the command to run. tests/Goldens: the recorded answers over the fixtures next to them (the commits fixture, a rich versioned series with CRLF, a folded subject, Markdown headings in and out of fences, the code-key rewrites); the suite compares 2304 results as DumpFile writes them, so a key out of order fails too. All agree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 06:48:55 +01:00
// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Crafter.Review:Normalize;
import std;
import :Json;
// From the raw structured output of a pass to its discharge, its coverage
// contract and its derived verdict; the merge of a lens's parts with the
// cross-unit rule; the coverage matrix. The structured output is the model's
// JSON and stays JSON, with every field the model wrote.
export namespace Crafter::Review::Normalize {
// An exact id, else the one id of `universe` it is a prefix of, else
// itself.
Json ResolveId(const Json& id, std::span<const std::string> universe);
// v: the raw structured output ({verdict, findings, notes, coverage?}).
// Its notes get their items resolved in place, and the result holds them.
// inventory: the units THIS pass must cover (null: no coverage contract);
// allIds: every inventory id, for prefix resolution.
Json NormalizeOutput(Json& v, std::span<const Json> inForce, std::string_view lensFile, std::string_view hash, const Json& inventory,
std::span<const std::string> allIds);
// The distinct values of `items`, first occurrence kept, equal when their
// canonical JSON is.
std::vector<Json> Dedupe(std::span<const Json> items);
// parts: normalized outputs (each with partLabel, expectedIds);
// missingUnits: unit ids whose process never returned. Coverage: one entry
// per unit, blocking > immaterial > the rest, a tie to the later part
// (the block, the zoomed view). The cross-unit rule: a unit cited by an
// undischarged finding whose merged verdict is not blocking is
// overwritten with the lens's blocking verdict.
Json MergeParts(std::string_view lens, std::string_view lensFile, std::span<const Json> parts, std::span<const std::string> missingUnits,
const Json& stoppedEarly = nullptr);
// Units x every lens that returned coverage; holes (a reviewed-kind unit
// no lens owned) and defects. notReviewed: the unit ids no lens that runs
// reads, listed, never holes.
Json Matrix(const Json& inventory, std::span<const Json> results, std::span<const std::string> notReviewed = {});
}