@cappa/core 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +53 -162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -75
- package/dist/index.d.mts +48 -75
- package/dist/index.mjs +53 -157
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2633,27 +2633,23 @@ var ScreenshotTool = class {
|
|
|
2633
2633
|
*/
|
|
2634
2634
|
const AGENT_DIRNAME = ".cappa-agent";
|
|
2635
2635
|
/** Bumped only if `request.json` or `report.json` change incompatibly. */
|
|
2636
|
-
const AGENT_REPORT_VERSION =
|
|
2636
|
+
const AGENT_REPORT_VERSION = 2;
|
|
2637
2637
|
const agentDir = (outputDir) => node_path.default.resolve(outputDir, AGENT_DIRNAME);
|
|
2638
2638
|
const judgmentsRoot = (outputDir) => node_path.default.join(agentDir(outputDir), "judgments");
|
|
2639
2639
|
const agentReportPath = (outputDir) => node_path.default.join(agentDir(outputDir), "report.json");
|
|
2640
2640
|
//#endregion
|
|
2641
2641
|
//#region src/agent/verdict.ts
|
|
2642
2642
|
/**
|
|
2643
|
-
* What a
|
|
2643
|
+
* What a judge believes a changed screenshot is, after looking at it.
|
|
2644
2644
|
*
|
|
2645
|
-
*
|
|
2646
|
-
*
|
|
2647
|
-
*
|
|
2645
|
+
* Only a judge labels a change. Cappa's diff threshold already absorbs
|
|
2646
|
+
* sub-pixel rendering differences, so a screenshot that reaches `changed`
|
|
2647
|
+
* differs beyond the tolerance the project configured — and classifying it
|
|
2648
|
+
* from diff signals alone (change types, severity, pixel counts) proved to
|
|
2649
|
+
* mislabel exactly the changes that matter: a font-size change reads as a
|
|
2650
|
+
* harmless shift plus recolour. Every changed screenshot is looked at instead.
|
|
2648
2651
|
*/
|
|
2649
2652
|
const VERDICT_LABELS = [
|
|
2650
|
-
"regression-likely",
|
|
2651
|
-
"intentional-likely",
|
|
2652
|
-
"noise-likely",
|
|
2653
|
-
"ambiguous"
|
|
2654
|
-
];
|
|
2655
|
-
/** The labels a judge may hand back — everything but `ambiguous`. */
|
|
2656
|
-
const JUDGED_LABELS = [
|
|
2657
2653
|
"regression-likely",
|
|
2658
2654
|
"intentional-likely",
|
|
2659
2655
|
"noise-likely"
|
|
@@ -2661,125 +2657,43 @@ const JUDGED_LABELS = [
|
|
|
2661
2657
|
const ACTION_BY_LABEL = {
|
|
2662
2658
|
"regression-likely": "investigate",
|
|
2663
2659
|
"intentional-likely": "approve-if-intended",
|
|
2664
|
-
"noise-likely": "mask-or-approve"
|
|
2665
|
-
ambiguous: "investigate"
|
|
2660
|
+
"noise-likely": "mask-or-approve"
|
|
2666
2661
|
};
|
|
2667
2662
|
const isVerdictLabel = (value) => typeof value === "string" && VERDICT_LABELS.includes(value);
|
|
2668
|
-
const isJudgedLabel = (value) => typeof value === "string" && JUDGED_LABELS.includes(value);
|
|
2669
2663
|
/**
|
|
2670
2664
|
* Change types are normalised to kebab-case before they are compared.
|
|
2671
2665
|
*
|
|
2672
2666
|
* `@blazediff/interpret-native` reports `color-change` today but earlier
|
|
2673
|
-
* releases reported `ColorChange`; normalising keeps the
|
|
2674
|
-
* across a diff-engine upgrade
|
|
2675
|
-
* to `ambiguous`.
|
|
2667
|
+
* releases reported `ColorChange`; normalising keeps the capture report's
|
|
2668
|
+
* labels working across a diff-engine upgrade.
|
|
2676
2669
|
*/
|
|
2677
2670
|
const normalizeChangeType = (changeType) => changeType.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
2678
|
-
const normalizeSeverity = (severity) => (severity ?? "").toLowerCase();
|
|
2679
|
-
/** Structural: something appeared, vanished or was replaced. */
|
|
2680
|
-
const REGRESSIVE_TYPES = /* @__PURE__ */ new Set([
|
|
2681
|
-
"content-change",
|
|
2682
|
-
"addition",
|
|
2683
|
-
"deletion"
|
|
2684
|
-
]);
|
|
2685
|
-
/** Restyled or moved, with structure intact. */
|
|
2686
|
-
const RESTYLE_TYPES = /* @__PURE__ */ new Set(["color-change", "shift"]);
|
|
2687
|
-
const NOISE_TYPES = /* @__PURE__ */ new Set(["rendering-noise"]);
|
|
2688
|
-
const ELEVATED_SEVERITY = /* @__PURE__ */ new Set(["medium", "high"]);
|
|
2689
|
-
/**
|
|
2690
|
-
* At or below this many differing pixels, a low-severity change is not
|
|
2691
|
-
* perceptible.
|
|
2692
|
-
*
|
|
2693
|
-
* An absolute count rather than a share of the image: a share depends on how
|
|
2694
|
-
* much empty canvas surrounds the content, so the same changed glyph would be
|
|
2695
|
-
* noise in a 1920x1080 capture and a regression in a tight crop of the
|
|
2696
|
-
* component. The pixels that changed are the same either way.
|
|
2697
|
-
*/
|
|
2698
|
-
const SUB_PERCEPTUAL_PIXELS = 25;
|
|
2699
|
-
/** Mean region confidence above which a pure recolour is trusted. */
|
|
2700
|
-
const RECOLOR_CONFIDENCE = .7;
|
|
2701
2671
|
const formatPercent = (percent) => {
|
|
2702
2672
|
if (percent === void 0) return "?%";
|
|
2703
2673
|
return percent >= .01 ? `${percent.toFixed(2)}%` : `${percent.toFixed(3)}%`;
|
|
2704
2674
|
};
|
|
2705
|
-
const countByType = (regions) => {
|
|
2706
|
-
const counts = /* @__PURE__ */ new Map();
|
|
2707
|
-
for (const region of regions) {
|
|
2708
|
-
const type = normalizeChangeType(region.changeType);
|
|
2709
|
-
counts.set(type, (counts.get(type) ?? 0) + 1);
|
|
2710
|
-
}
|
|
2711
|
-
return counts;
|
|
2712
|
-
};
|
|
2713
|
-
const formatBreakdown = (counts) => [...counts].sort((a, b) => b[1] - a[1]).map(([type, count]) => `${count} ${type}`).join(", ");
|
|
2714
2675
|
const largestRegion = (regions) => regions.reduce((best, region) => !best || region.pixelCount > best.pixelCount ? region : best, void 0);
|
|
2715
|
-
const meanConfidence = (regions) => regions.length === 0 ? 0 : regions.reduce((sum, region) => sum + (region.confidence ?? 0), 0) / regions.length;
|
|
2716
2676
|
/**
|
|
2717
|
-
* A one-line description of
|
|
2718
|
-
* on different screenshots produces the same
|
|
2719
|
-
*
|
|
2720
|
-
* dozens of screenshots
|
|
2677
|
+
* A one-line description of where and how much a screenshot changed, shaped
|
|
2678
|
+
* so that the same change on different screenshots produces the same text —
|
|
2679
|
+
* which is what lets a judge spot one shared cause (a footer timestamp, a
|
|
2680
|
+
* theme toggle) across dozens of screenshots and judge them together.
|
|
2681
|
+
*
|
|
2682
|
+
* Deliberately geometry only: no change types, no severity. Those are guesses
|
|
2683
|
+
* from pixel signals, and a judge primed with "noise" or "shift" looks less
|
|
2684
|
+
* carefully at what is in fact a regression.
|
|
2721
2685
|
*/
|
|
2722
|
-
const
|
|
2723
|
-
const
|
|
2724
|
-
|
|
2725
|
-
if (input.differentSizes) return hasRegions ? `dimensions changed; ${buildHeadline({
|
|
2686
|
+
const describeChange = (input) => {
|
|
2687
|
+
const regions = input.interpretation?.regions ?? [];
|
|
2688
|
+
if (input.differentSizes) return regions.length > 0 ? `dimensions changed; ${describeChange({
|
|
2726
2689
|
...input,
|
|
2727
2690
|
differentSizes: false
|
|
2728
2691
|
})}` : "image dimensions changed";
|
|
2729
|
-
const percent = input.percentDifference ?? interpretation?.diffPercentage;
|
|
2730
|
-
if (
|
|
2731
|
-
const regions = interpretation.regions;
|
|
2732
|
-
const counts = countByType(regions);
|
|
2692
|
+
const percent = input.percentDifference ?? input.interpretation?.diffPercentage;
|
|
2693
|
+
if (regions.length === 0) return `${(input.numDiffPixels ?? input.interpretation?.diffCount)?.toLocaleString("en-US") ?? "?"} px (${formatPercent(percent)}) - no regions located`;
|
|
2733
2694
|
const position = largestRegion(regions)?.position;
|
|
2734
2695
|
const at = position ? ` @ ${position}` : "";
|
|
2735
|
-
|
|
2736
|
-
if (regions.length === 1) return `1 ${[...counts.keys()][0]}${at} (${formatPercent(percent)}, ${severity})`;
|
|
2737
|
-
return `${regions.length} regions: ${formatBreakdown(counts)}${at} (${formatPercent(percent)}, ${severity})`;
|
|
2738
|
-
};
|
|
2739
|
-
const verdict = (label, headline, rationale) => ({
|
|
2740
|
-
label,
|
|
2741
|
-
headline,
|
|
2742
|
-
rationale,
|
|
2743
|
-
action: ACTION_BY_LABEL[label]
|
|
2744
|
-
});
|
|
2745
|
-
/**
|
|
2746
|
-
* Classify a changed screenshot from its diff interpretation alone.
|
|
2747
|
-
*
|
|
2748
|
-
* Deliberately conservative: only the cases the signals settle are labelled,
|
|
2749
|
-
* and everything else is `ambiguous` so that it reaches a judge who can look
|
|
2750
|
-
* at the pixels. A wrong `noise-likely` hides a regression; a wrong
|
|
2751
|
-
* `ambiguous` costs one look.
|
|
2752
|
-
*/
|
|
2753
|
-
const deriveVerdict = (input) => {
|
|
2754
|
-
const headline = buildHeadline(input);
|
|
2755
|
-
const interpretation = input.interpretation;
|
|
2756
|
-
const hasRegions = (interpretation?.regions.length ?? 0) > 0;
|
|
2757
|
-
if (input.differentSizes && (!interpretation || !hasRegions)) return verdict("ambiguous", headline, ["expected and actual have different dimensions — content likely grew or shrank", "could be an intended content change or a broken layout"]);
|
|
2758
|
-
if (!interpretation || !hasRegions) return verdict("ambiguous", headline, ["pixels differ but no change regions were found"]);
|
|
2759
|
-
const classified = classifyRegions(input, interpretation, headline, !input.differentSizes);
|
|
2760
|
-
if (!input.differentSizes) return classified;
|
|
2761
|
-
return {
|
|
2762
|
-
...classified,
|
|
2763
|
-
rationale: ["expected and actual have different dimensions — compared on a canvas padded to the larger size", ...classified.rationale]
|
|
2764
|
-
};
|
|
2765
|
-
};
|
|
2766
|
-
const classifyRegions = (input, interpretation, headline, allowNoise) => {
|
|
2767
|
-
const regions = interpretation.regions;
|
|
2768
|
-
const types = regions.map((region) => normalizeChangeType(region.changeType));
|
|
2769
|
-
const severity = normalizeSeverity(interpretation.severity);
|
|
2770
|
-
const percent = input.percentDifference ?? interpretation.diffPercentage;
|
|
2771
|
-
const pixels = input.numDiffPixels ?? interpretation.diffCount;
|
|
2772
|
-
const counts = countByType(regions);
|
|
2773
|
-
if (allowNoise && types.every((type) => NOISE_TYPES.has(type))) return verdict("noise-likely", headline, ["every region is classified as rendering noise"]);
|
|
2774
|
-
if (allowNoise && pixels <= 25 && severity === "low") return verdict("noise-likely", headline, [`${pixels.toLocaleString("en-US")} ${pixels === 1 ? "pixel differs" : "pixels differ"} (at most 25) at low severity`, "sub-perceptual change"]);
|
|
2775
|
-
if (types.some((type) => REGRESSIVE_TYPES.has(type)) && ELEVATED_SEVERITY.has(severity)) {
|
|
2776
|
-
const structural = [...counts].filter(([type]) => REGRESSIVE_TYPES.has(type)).map(([type, count]) => `${count} ${type}`).join(", ");
|
|
2777
|
-
return verdict("regression-likely", headline, [`${severity} severity with structural changes (${structural})`, "content or layout changed, not just styling"]);
|
|
2778
|
-
}
|
|
2779
|
-
const allRecolor = types.every((type) => type === "color-change");
|
|
2780
|
-
if (allRecolor && meanConfidence(regions) > RECOLOR_CONFIDENCE) return verdict("intentional-likely", headline, [`${regions.length} confident color-change ${regions.length === 1 ? "region" : "regions"}`, "edge structure preserved — looks like a theming or palette change"]);
|
|
2781
|
-
if (!allRecolor && types.every((type) => RESTYLE_TYPES.has(type))) return verdict("intentional-likely", headline, ["every region is a shift or color change — content moved or was restyled, structure preserved"]);
|
|
2782
|
-
return verdict("ambiguous", headline, [`mix of change types (${formatBreakdown(counts)}) at ${severity || "unknown"} severity`, `${formatPercent(percent)} of the image differs`]);
|
|
2696
|
+
return `${`${regions.length} ${regions.length === 1 ? "region" : "regions"}`}${at} (${formatPercent(percent)})`;
|
|
2783
2697
|
};
|
|
2784
2698
|
//#endregion
|
|
2785
2699
|
//#region src/agent/reviewIndex.ts
|
|
@@ -2797,11 +2711,11 @@ const readAgentReviewIndex = async (outputDir) => {
|
|
|
2797
2711
|
return;
|
|
2798
2712
|
}
|
|
2799
2713
|
const createdAt = typeof raw?.createdAt === "string" ? Date.parse(raw.createdAt) : NaN;
|
|
2800
|
-
if (raw?.version !==
|
|
2714
|
+
if (raw?.version !== 2 || Number.isNaN(createdAt) || !Array.isArray(raw.entries)) return;
|
|
2801
2715
|
const reviews = /* @__PURE__ */ new Map();
|
|
2802
2716
|
for (const entry of raw.entries) {
|
|
2803
2717
|
if (typeof entry !== "object" || entry === null) continue;
|
|
2804
|
-
const { name, category, verdict
|
|
2718
|
+
const { name, category, verdict } = entry;
|
|
2805
2719
|
if (typeof name !== "string" || category !== "changed") continue;
|
|
2806
2720
|
if (typeof verdict !== "object" || verdict === null) continue;
|
|
2807
2721
|
const v = verdict;
|
|
@@ -2811,9 +2725,9 @@ const readAgentReviewIndex = async (outputDir) => {
|
|
|
2811
2725
|
headline: v.headline,
|
|
2812
2726
|
rationale: Array.isArray(v.rationale) ? v.rationale.filter((line) => typeof line === "string") : [],
|
|
2813
2727
|
action: v.action,
|
|
2814
|
-
source:
|
|
2728
|
+
source: "agent",
|
|
2815
2729
|
...typeof v.confidence === "number" ? { confidence: v.confidence } : {},
|
|
2816
|
-
pending:
|
|
2730
|
+
pending: false,
|
|
2817
2731
|
reviewedAt: new Date(createdAt).toISOString()
|
|
2818
2732
|
});
|
|
2819
2733
|
}
|
|
@@ -4632,6 +4546,9 @@ const renderOverview = async (options) => {
|
|
|
4632
4546
|
* Agent review: turn the screenshots on disk into something a coding agent
|
|
4633
4547
|
* can judge cheaply, and fold its judgments back in.
|
|
4634
4548
|
*
|
|
4549
|
+
* Every changed screenshot gets a judgment request. Nothing is labelled from
|
|
4550
|
+
* diff signals alone — see `VERDICT_LABELS` for why.
|
|
4551
|
+
*
|
|
4635
4552
|
* Nothing here captures. It reads `actual/`, `expected/` and `diff/` as the
|
|
4636
4553
|
* last `cappa capture` left them, so it is safe to run repeatedly — a re-run
|
|
4637
4554
|
* is how an agent's verdicts are applied, and a re-capture invalidates them
|
|
@@ -4659,11 +4576,6 @@ const JUDGMENT_FILES = [
|
|
|
4659
4576
|
"regions.png",
|
|
4660
4577
|
"overview.png"
|
|
4661
4578
|
];
|
|
4662
|
-
const JUDGE_MODES = [
|
|
4663
|
-
"ambiguous",
|
|
4664
|
-
"all",
|
|
4665
|
-
"none"
|
|
4666
|
-
];
|
|
4667
4579
|
/**
|
|
4668
4580
|
* The directory holding a screenshot's judgment.
|
|
4669
4581
|
*
|
|
@@ -4716,7 +4628,7 @@ const parseAgentVerdict = (raw) => {
|
|
|
4716
4628
|
const outer = raw;
|
|
4717
4629
|
const inner = typeof outer.verdict === "object" && outer.verdict !== null ? outer.verdict : outer;
|
|
4718
4630
|
const label = inner.label;
|
|
4719
|
-
if (!
|
|
4631
|
+
if (!isVerdictLabel(label)) return {
|
|
4720
4632
|
ok: false,
|
|
4721
4633
|
error: `label must be one of regression-likely, intentional-likely, noise-likely (got ${JSON.stringify(label)})`
|
|
4722
4634
|
};
|
|
@@ -4768,9 +4680,7 @@ const toAgentRegions = (regions) => [...regions].sort((a, b) => b.pixelCount - a
|
|
|
4768
4680
|
pixelCount: region.pixelCount,
|
|
4769
4681
|
percentage: region.percentage,
|
|
4770
4682
|
position: region.position,
|
|
4771
|
-
shape: region.shape
|
|
4772
|
-
changeType: normalizeChangeType(region.changeType),
|
|
4773
|
-
confidence: region.confidence
|
|
4683
|
+
shape: region.shape
|
|
4774
4684
|
}));
|
|
4775
4685
|
/**
|
|
4776
4686
|
* The interpretation a capture already persisted, or a fresh one.
|
|
@@ -4793,8 +4703,10 @@ const interpretationFor = async (screenshot, expectedPath, actualPath, diff) =>
|
|
|
4793
4703
|
}
|
|
4794
4704
|
};
|
|
4795
4705
|
const JUDGE_INSTRUCTIONS = [
|
|
4706
|
+
"Every changed screenshot differs beyond the project's diff threshold, so sub-pixel rendering is already filtered out: look at each change before labelling it.",
|
|
4796
4707
|
"Read locator.png and regions.png together. locator.png outlines every region (numbered) on a thumbnail; regions.png stacks one [expected | actual] row per region, in `regions` order.",
|
|
4797
4708
|
"overview.png exists only when the image dimensions changed: it shows both images whole, side by side. Regions are then located on a canvas padded to the larger size, anchored top-left — in a crop, area that only one image covers is empty.",
|
|
4709
|
+
"Compare sizes, not just content: text that is larger, smaller, bolder or reflowed, and spacing, alignment or wrapping that moved, are regressions unless a code change explains them.",
|
|
4798
4710
|
"Only open paths.expected / paths.actual / paths.diff (full size) when a change clearly continues outside its crop.",
|
|
4799
4711
|
"Write verdict.json next to this file, or run `cappa agent judge <name> --label <label> --headline <text>`."
|
|
4800
4712
|
];
|
|
@@ -4852,7 +4764,7 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4852
4764
|
const percentDifference = screenshot.diffMeta?.percentDifference ?? interpretation?.diffPercentage;
|
|
4853
4765
|
const numDiffPixels = screenshot.diffMeta?.numDiffPixels ?? interpretation?.diffCount;
|
|
4854
4766
|
const regions = toAgentRegions(interpretation?.regions ?? []);
|
|
4855
|
-
const
|
|
4767
|
+
const change = describeChange({
|
|
4856
4768
|
percentDifference,
|
|
4857
4769
|
numDiffPixels,
|
|
4858
4770
|
interpretation,
|
|
@@ -4876,20 +4788,13 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4876
4788
|
expected: expectedSize,
|
|
4877
4789
|
actual: actualSize
|
|
4878
4790
|
},
|
|
4879
|
-
|
|
4880
|
-
summary: interpretation?.summary,
|
|
4791
|
+
change,
|
|
4881
4792
|
regions,
|
|
4882
|
-
|
|
4883
|
-
verdict: {
|
|
4884
|
-
...heuristic,
|
|
4885
|
-
source: "heuristic"
|
|
4886
|
-
},
|
|
4887
|
-
pending: false
|
|
4793
|
+
pending: true
|
|
4888
4794
|
};
|
|
4889
4795
|
const dir = judgmentDir(outputDir, screenshot.name);
|
|
4890
4796
|
const requestPath = node_path.default.join(dir, REQUEST_FILE);
|
|
4891
4797
|
const verdictPath = node_path.default.join(dir, VERDICT_FILE);
|
|
4892
|
-
if (!(options.judge === "all" || options.judge === "ambiguous" && heuristic.label === "ambiguous" || await exists(requestPath))) return entry;
|
|
4893
4798
|
const fingerprint = await fingerprintImages(expectedPath, actualPath);
|
|
4894
4799
|
const previous = await readJson(requestPath);
|
|
4895
4800
|
if (previous && previous.fingerprint !== fingerprint) await clearJudgmentFiles(dir);
|
|
@@ -4918,7 +4823,7 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4918
4823
|
}
|
|
4919
4824
|
entry.judgment = judgment;
|
|
4920
4825
|
await writeJson(requestPath, {
|
|
4921
|
-
version:
|
|
4826
|
+
version: 2,
|
|
4922
4827
|
name: entry.name,
|
|
4923
4828
|
taskId: entry.taskId,
|
|
4924
4829
|
plugin: entry.plugin,
|
|
@@ -4926,12 +4831,10 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4926
4831
|
createdAt,
|
|
4927
4832
|
instructions: JUDGE_INSTRUCTIONS,
|
|
4928
4833
|
verdictSchema: VERDICT_SCHEMA,
|
|
4929
|
-
|
|
4834
|
+
change,
|
|
4930
4835
|
percentDifference,
|
|
4931
4836
|
numDiffPixels,
|
|
4932
4837
|
dimensions: entry.dimensions,
|
|
4933
|
-
severity: entry.severity,
|
|
4934
|
-
summary: entry.summary,
|
|
4935
4838
|
regions,
|
|
4936
4839
|
paths: {
|
|
4937
4840
|
locator: judgment.locator,
|
|
@@ -4943,22 +4846,18 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4943
4846
|
verdict: verdictPath
|
|
4944
4847
|
}
|
|
4945
4848
|
});
|
|
4946
|
-
if (!await exists(verdictPath))
|
|
4947
|
-
entry.pending = true;
|
|
4948
|
-
return entry;
|
|
4949
|
-
}
|
|
4849
|
+
if (!await exists(verdictPath)) return entry;
|
|
4950
4850
|
const parsed = parseAgentVerdict(await readJson(verdictPath));
|
|
4951
4851
|
if (!parsed.ok) {
|
|
4952
|
-
entry.pending = true;
|
|
4953
4852
|
entry.verdictError = parsed.error;
|
|
4954
4853
|
return entry;
|
|
4955
4854
|
}
|
|
4855
|
+
entry.pending = false;
|
|
4956
4856
|
entry.verdict = {
|
|
4957
4857
|
label: parsed.label,
|
|
4958
4858
|
headline: parsed.headline,
|
|
4959
4859
|
rationale: parsed.rationale,
|
|
4960
4860
|
action: ACTION_BY_LABEL[parsed.label],
|
|
4961
|
-
source: "agent",
|
|
4962
4861
|
...parsed.confidence !== void 0 ? { confidence: parsed.confidence } : {}
|
|
4963
4862
|
};
|
|
4964
4863
|
return entry;
|
|
@@ -5002,13 +4901,12 @@ const pruneJudgments = async (outputDir, keep) => {
|
|
|
5002
4901
|
}
|
|
5003
4902
|
};
|
|
5004
4903
|
/**
|
|
5005
|
-
* Analyse every non-passing screenshot, write judgment
|
|
5006
|
-
*
|
|
5007
|
-
*
|
|
4904
|
+
* Analyse every non-passing screenshot, write a judgment request for every
|
|
4905
|
+
* changed one, apply any verdicts already written, and persist the full
|
|
4906
|
+
* report to `<outputDir>/.cappa-agent/report.json`.
|
|
5008
4907
|
*/
|
|
5009
4908
|
const runAgentCheck = async (options) => {
|
|
5010
4909
|
const outputDir = node_path.default.resolve(options.outputDir);
|
|
5011
|
-
const judge = options.judge ?? "ambiguous";
|
|
5012
4910
|
const createdAt = (options.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
|
|
5013
4911
|
const screenshots = await collectScreenshots(outputDir);
|
|
5014
4912
|
await node_fs_promises.default.mkdir(agentDir(outputDir), { recursive: true });
|
|
@@ -5016,8 +4914,7 @@ const runAgentCheck = async (options) => {
|
|
|
5016
4914
|
const changed = screenshots.filter((s) => s.category === "changed");
|
|
5017
4915
|
const changedEntries = await mapWithConcurrency(options.concurrency ?? 4, changed, (screenshot) => analyseChanged(screenshot, {
|
|
5018
4916
|
...options,
|
|
5019
|
-
outputDir
|
|
5020
|
-
judge
|
|
4917
|
+
outputDir
|
|
5021
4918
|
}, createdAt));
|
|
5022
4919
|
await pruneJudgments(outputDir, new Set(changedEntries.flatMap((entry) => entry.judgment ? [entry.judgment.dir] : [])));
|
|
5023
4920
|
const otherEntries = screenshots.flatMap((s) => {
|
|
@@ -5042,11 +4939,10 @@ const runAgentCheck = async (options) => {
|
|
|
5042
4939
|
const entries = [...changedEntries, ...otherEntries];
|
|
5043
4940
|
const count = (category) => screenshots.filter((s) => s.category === category).length;
|
|
5044
4941
|
const report = {
|
|
5045
|
-
version:
|
|
4942
|
+
version: 2,
|
|
5046
4943
|
createdAt,
|
|
5047
4944
|
outputDir,
|
|
5048
4945
|
reportPath: agentReportPath(outputDir),
|
|
5049
|
-
judge,
|
|
5050
4946
|
totals: {
|
|
5051
4947
|
total: screenshots.length,
|
|
5052
4948
|
passed: count("passed"),
|
|
@@ -5063,7 +4959,7 @@ const runAgentCheck = async (options) => {
|
|
|
5063
4959
|
/** Read the report the last {@link runAgentCheck} wrote, if any. */
|
|
5064
4960
|
const readAgentReport = async (outputDir) => {
|
|
5065
4961
|
const raw = await readJson(agentReportPath(outputDir));
|
|
5066
|
-
return raw?.version ===
|
|
4962
|
+
return raw?.version === 2 ? raw : void 0;
|
|
5067
4963
|
};
|
|
5068
4964
|
/**
|
|
5069
4965
|
* The report as an agent should first see it: one line of state per
|
|
@@ -5076,11 +4972,11 @@ const toSlimAgentReport = (report) => ({
|
|
|
5076
4972
|
results: report.entries.map((entry) => ({
|
|
5077
4973
|
name: entry.name,
|
|
5078
4974
|
category: entry.category,
|
|
4975
|
+
...entry.change ? { change: entry.change } : {},
|
|
5079
4976
|
...entry.verdict ? { verdict: {
|
|
5080
4977
|
label: entry.verdict.label,
|
|
5081
4978
|
headline: entry.verdict.headline,
|
|
5082
|
-
action: entry.verdict.action
|
|
5083
|
-
source: entry.verdict.source
|
|
4979
|
+
action: entry.verdict.action
|
|
5084
4980
|
} } : {},
|
|
5085
4981
|
...entry.pending ? { pending: true } : {},
|
|
5086
4982
|
...entry.pending && entry.judgment ? { judgment: entry.judgment.dir } : {},
|
|
@@ -5093,7 +4989,7 @@ const toSlimAgentReport = (report) => ({
|
|
|
5093
4989
|
*/
|
|
5094
4990
|
const writeAgentVerdict = async (outputDir, name, input) => {
|
|
5095
4991
|
const dir = judgmentDir(outputDir, name);
|
|
5096
|
-
if (!await exists(node_path.default.join(dir, REQUEST_FILE))) throw new Error(`No judgment request for "${name}" — run \`cappa agent check\` first
|
|
4992
|
+
if (!await exists(node_path.default.join(dir, REQUEST_FILE))) throw new Error(`No judgment request for "${name}" — run \`cappa agent check\` first; only changed screenshots get one.`);
|
|
5097
4993
|
const parsed = parseAgentVerdict(input);
|
|
5098
4994
|
if (!parsed.ok) throw new Error(parsed.error);
|
|
5099
4995
|
const verdictPath = node_path.default.join(dir, VERDICT_FILE);
|
|
@@ -5152,8 +5048,6 @@ exports.DEFAULT_MAX_TASKS = DEFAULT_MAX_TASKS;
|
|
|
5152
5048
|
exports.DEFAULT_WEB_SERVER_TIMEOUT_MS = DEFAULT_WEB_SERVER_TIMEOUT_MS;
|
|
5153
5049
|
exports.ENGINE_ERROR_CODES = ENGINE_ERROR_CODES;
|
|
5154
5050
|
exports.FsScreenshotStore = FsScreenshotStore;
|
|
5155
|
-
exports.JUDGED_LABELS = JUDGED_LABELS;
|
|
5156
|
-
exports.JUDGE_MODES = JUDGE_MODES;
|
|
5157
5051
|
exports.LocalEngine = LocalEngine;
|
|
5158
5052
|
exports.MANIFEST_FILENAME = MANIFEST_FILENAME;
|
|
5159
5053
|
exports.MANIFEST_VERSION = MANIFEST_VERSION;
|
|
@@ -5161,7 +5055,6 @@ exports.NO_WEB_SERVER_HINT = NO_WEB_SERVER_HINT;
|
|
|
5161
5055
|
exports.OutputTail = OutputTail;
|
|
5162
5056
|
exports.RunInProgressError = RunInProgressError;
|
|
5163
5057
|
exports.RunStore = RunStore;
|
|
5164
|
-
exports.SUB_PERCEPTUAL_PIXELS = SUB_PERCEPTUAL_PIXELS;
|
|
5165
5058
|
exports.ScreenshotFileSystem = ScreenshotFileSystem;
|
|
5166
5059
|
exports.ScreenshotTool = ScreenshotTool;
|
|
5167
5060
|
exports.UnknownTargetsError = UnknownTargetsError;
|
|
@@ -5174,14 +5067,13 @@ exports.WebServerPool = WebServerPool;
|
|
|
5174
5067
|
exports.agentDir = agentDir;
|
|
5175
5068
|
exports.agentReportPath = agentReportPath;
|
|
5176
5069
|
exports.attachConsoleLogging = attachConsoleLogging;
|
|
5177
|
-
exports.buildHeadline = buildHeadline;
|
|
5178
5070
|
exports.clearJudgment = clearJudgment;
|
|
5179
5071
|
exports.collectScreenshots = collectScreenshots;
|
|
5180
5072
|
exports.compareImages = compareImages;
|
|
5181
5073
|
exports.compareImagesGMSD = compareImagesGMSD;
|
|
5182
5074
|
exports.contextPadding = contextPadding;
|
|
5183
5075
|
exports.defineConfig = defineConfig;
|
|
5184
|
-
exports.
|
|
5076
|
+
exports.describeChange = describeChange;
|
|
5185
5077
|
exports.didScreenshotFail = didScreenshotFail;
|
|
5186
5078
|
exports.filterTasks = filterTasks;
|
|
5187
5079
|
exports.findRefusedConnection = findRefusedConnection;
|
|
@@ -5190,7 +5082,6 @@ exports.getDeletedScreenshots = getDeletedScreenshots;
|
|
|
5190
5082
|
exports.groupScreenshots = groupScreenshots;
|
|
5191
5083
|
exports.imagesMatch = imagesMatch;
|
|
5192
5084
|
exports.imagesMatchGMSD = imagesMatchGMSD;
|
|
5193
|
-
exports.isJudgedLabel = isJudgedLabel;
|
|
5194
5085
|
exports.isRunInProgressError = isRunInProgressError;
|
|
5195
5086
|
exports.isUnknownTargetsError = isUnknownTargetsError;
|
|
5196
5087
|
exports.isUrlReady = isUrlReady;
|