@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.mjs
CHANGED
|
@@ -2607,27 +2607,23 @@ var ScreenshotTool = class {
|
|
|
2607
2607
|
*/
|
|
2608
2608
|
const AGENT_DIRNAME = ".cappa-agent";
|
|
2609
2609
|
/** Bumped only if `request.json` or `report.json` change incompatibly. */
|
|
2610
|
-
const AGENT_REPORT_VERSION =
|
|
2610
|
+
const AGENT_REPORT_VERSION = 2;
|
|
2611
2611
|
const agentDir = (outputDir) => path.resolve(outputDir, AGENT_DIRNAME);
|
|
2612
2612
|
const judgmentsRoot = (outputDir) => path.join(agentDir(outputDir), "judgments");
|
|
2613
2613
|
const agentReportPath = (outputDir) => path.join(agentDir(outputDir), "report.json");
|
|
2614
2614
|
//#endregion
|
|
2615
2615
|
//#region src/agent/verdict.ts
|
|
2616
2616
|
/**
|
|
2617
|
-
* What a
|
|
2617
|
+
* What a judge believes a changed screenshot is, after looking at it.
|
|
2618
2618
|
*
|
|
2619
|
-
*
|
|
2620
|
-
*
|
|
2621
|
-
*
|
|
2619
|
+
* Only a judge labels a change. Cappa's diff threshold already absorbs
|
|
2620
|
+
* sub-pixel rendering differences, so a screenshot that reaches `changed`
|
|
2621
|
+
* differs beyond the tolerance the project configured — and classifying it
|
|
2622
|
+
* from diff signals alone (change types, severity, pixel counts) proved to
|
|
2623
|
+
* mislabel exactly the changes that matter: a font-size change reads as a
|
|
2624
|
+
* harmless shift plus recolour. Every changed screenshot is looked at instead.
|
|
2622
2625
|
*/
|
|
2623
2626
|
const VERDICT_LABELS = [
|
|
2624
|
-
"regression-likely",
|
|
2625
|
-
"intentional-likely",
|
|
2626
|
-
"noise-likely",
|
|
2627
|
-
"ambiguous"
|
|
2628
|
-
];
|
|
2629
|
-
/** The labels a judge may hand back — everything but `ambiguous`. */
|
|
2630
|
-
const JUDGED_LABELS = [
|
|
2631
2627
|
"regression-likely",
|
|
2632
2628
|
"intentional-likely",
|
|
2633
2629
|
"noise-likely"
|
|
@@ -2635,125 +2631,43 @@ const JUDGED_LABELS = [
|
|
|
2635
2631
|
const ACTION_BY_LABEL = {
|
|
2636
2632
|
"regression-likely": "investigate",
|
|
2637
2633
|
"intentional-likely": "approve-if-intended",
|
|
2638
|
-
"noise-likely": "mask-or-approve"
|
|
2639
|
-
ambiguous: "investigate"
|
|
2634
|
+
"noise-likely": "mask-or-approve"
|
|
2640
2635
|
};
|
|
2641
2636
|
const isVerdictLabel = (value) => typeof value === "string" && VERDICT_LABELS.includes(value);
|
|
2642
|
-
const isJudgedLabel = (value) => typeof value === "string" && JUDGED_LABELS.includes(value);
|
|
2643
2637
|
/**
|
|
2644
2638
|
* Change types are normalised to kebab-case before they are compared.
|
|
2645
2639
|
*
|
|
2646
2640
|
* `@blazediff/interpret-native` reports `color-change` today but earlier
|
|
2647
|
-
* releases reported `ColorChange`; normalising keeps the
|
|
2648
|
-
* across a diff-engine upgrade
|
|
2649
|
-
* to `ambiguous`.
|
|
2641
|
+
* releases reported `ColorChange`; normalising keeps the capture report's
|
|
2642
|
+
* labels working across a diff-engine upgrade.
|
|
2650
2643
|
*/
|
|
2651
2644
|
const normalizeChangeType = (changeType) => changeType.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
2652
|
-
const normalizeSeverity = (severity) => (severity ?? "").toLowerCase();
|
|
2653
|
-
/** Structural: something appeared, vanished or was replaced. */
|
|
2654
|
-
const REGRESSIVE_TYPES = /* @__PURE__ */ new Set([
|
|
2655
|
-
"content-change",
|
|
2656
|
-
"addition",
|
|
2657
|
-
"deletion"
|
|
2658
|
-
]);
|
|
2659
|
-
/** Restyled or moved, with structure intact. */
|
|
2660
|
-
const RESTYLE_TYPES = /* @__PURE__ */ new Set(["color-change", "shift"]);
|
|
2661
|
-
const NOISE_TYPES = /* @__PURE__ */ new Set(["rendering-noise"]);
|
|
2662
|
-
const ELEVATED_SEVERITY = /* @__PURE__ */ new Set(["medium", "high"]);
|
|
2663
|
-
/**
|
|
2664
|
-
* At or below this many differing pixels, a low-severity change is not
|
|
2665
|
-
* perceptible.
|
|
2666
|
-
*
|
|
2667
|
-
* An absolute count rather than a share of the image: a share depends on how
|
|
2668
|
-
* much empty canvas surrounds the content, so the same changed glyph would be
|
|
2669
|
-
* noise in a 1920x1080 capture and a regression in a tight crop of the
|
|
2670
|
-
* component. The pixels that changed are the same either way.
|
|
2671
|
-
*/
|
|
2672
|
-
const SUB_PERCEPTUAL_PIXELS = 25;
|
|
2673
|
-
/** Mean region confidence above which a pure recolour is trusted. */
|
|
2674
|
-
const RECOLOR_CONFIDENCE = .7;
|
|
2675
2645
|
const formatPercent = (percent) => {
|
|
2676
2646
|
if (percent === void 0) return "?%";
|
|
2677
2647
|
return percent >= .01 ? `${percent.toFixed(2)}%` : `${percent.toFixed(3)}%`;
|
|
2678
2648
|
};
|
|
2679
|
-
const countByType = (regions) => {
|
|
2680
|
-
const counts = /* @__PURE__ */ new Map();
|
|
2681
|
-
for (const region of regions) {
|
|
2682
|
-
const type = normalizeChangeType(region.changeType);
|
|
2683
|
-
counts.set(type, (counts.get(type) ?? 0) + 1);
|
|
2684
|
-
}
|
|
2685
|
-
return counts;
|
|
2686
|
-
};
|
|
2687
|
-
const formatBreakdown = (counts) => [...counts].sort((a, b) => b[1] - a[1]).map(([type, count]) => `${count} ${type}`).join(", ");
|
|
2688
2649
|
const largestRegion = (regions) => regions.reduce((best, region) => !best || region.pixelCount > best.pixelCount ? region : best, void 0);
|
|
2689
|
-
const meanConfidence = (regions) => regions.length === 0 ? 0 : regions.reduce((sum, region) => sum + (region.confidence ?? 0), 0) / regions.length;
|
|
2690
2650
|
/**
|
|
2691
|
-
* A one-line description of
|
|
2692
|
-
* on different screenshots produces the same
|
|
2693
|
-
*
|
|
2694
|
-
* dozens of screenshots
|
|
2651
|
+
* A one-line description of where and how much a screenshot changed, shaped
|
|
2652
|
+
* so that the same change on different screenshots produces the same text —
|
|
2653
|
+
* which is what lets a judge spot one shared cause (a footer timestamp, a
|
|
2654
|
+
* theme toggle) across dozens of screenshots and judge them together.
|
|
2655
|
+
*
|
|
2656
|
+
* Deliberately geometry only: no change types, no severity. Those are guesses
|
|
2657
|
+
* from pixel signals, and a judge primed with "noise" or "shift" looks less
|
|
2658
|
+
* carefully at what is in fact a regression.
|
|
2695
2659
|
*/
|
|
2696
|
-
const
|
|
2697
|
-
const
|
|
2698
|
-
|
|
2699
|
-
if (input.differentSizes) return hasRegions ? `dimensions changed; ${buildHeadline({
|
|
2660
|
+
const describeChange = (input) => {
|
|
2661
|
+
const regions = input.interpretation?.regions ?? [];
|
|
2662
|
+
if (input.differentSizes) return regions.length > 0 ? `dimensions changed; ${describeChange({
|
|
2700
2663
|
...input,
|
|
2701
2664
|
differentSizes: false
|
|
2702
2665
|
})}` : "image dimensions changed";
|
|
2703
|
-
const percent = input.percentDifference ?? interpretation?.diffPercentage;
|
|
2704
|
-
if (
|
|
2705
|
-
const regions = interpretation.regions;
|
|
2706
|
-
const counts = countByType(regions);
|
|
2666
|
+
const percent = input.percentDifference ?? input.interpretation?.diffPercentage;
|
|
2667
|
+
if (regions.length === 0) return `${(input.numDiffPixels ?? input.interpretation?.diffCount)?.toLocaleString("en-US") ?? "?"} px (${formatPercent(percent)}) - no regions located`;
|
|
2707
2668
|
const position = largestRegion(regions)?.position;
|
|
2708
2669
|
const at = position ? ` @ ${position}` : "";
|
|
2709
|
-
|
|
2710
|
-
if (regions.length === 1) return `1 ${[...counts.keys()][0]}${at} (${formatPercent(percent)}, ${severity})`;
|
|
2711
|
-
return `${regions.length} regions: ${formatBreakdown(counts)}${at} (${formatPercent(percent)}, ${severity})`;
|
|
2712
|
-
};
|
|
2713
|
-
const verdict = (label, headline, rationale) => ({
|
|
2714
|
-
label,
|
|
2715
|
-
headline,
|
|
2716
|
-
rationale,
|
|
2717
|
-
action: ACTION_BY_LABEL[label]
|
|
2718
|
-
});
|
|
2719
|
-
/**
|
|
2720
|
-
* Classify a changed screenshot from its diff interpretation alone.
|
|
2721
|
-
*
|
|
2722
|
-
* Deliberately conservative: only the cases the signals settle are labelled,
|
|
2723
|
-
* and everything else is `ambiguous` so that it reaches a judge who can look
|
|
2724
|
-
* at the pixels. A wrong `noise-likely` hides a regression; a wrong
|
|
2725
|
-
* `ambiguous` costs one look.
|
|
2726
|
-
*/
|
|
2727
|
-
const deriveVerdict = (input) => {
|
|
2728
|
-
const headline = buildHeadline(input);
|
|
2729
|
-
const interpretation = input.interpretation;
|
|
2730
|
-
const hasRegions = (interpretation?.regions.length ?? 0) > 0;
|
|
2731
|
-
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"]);
|
|
2732
|
-
if (!interpretation || !hasRegions) return verdict("ambiguous", headline, ["pixels differ but no change regions were found"]);
|
|
2733
|
-
const classified = classifyRegions(input, interpretation, headline, !input.differentSizes);
|
|
2734
|
-
if (!input.differentSizes) return classified;
|
|
2735
|
-
return {
|
|
2736
|
-
...classified,
|
|
2737
|
-
rationale: ["expected and actual have different dimensions — compared on a canvas padded to the larger size", ...classified.rationale]
|
|
2738
|
-
};
|
|
2739
|
-
};
|
|
2740
|
-
const classifyRegions = (input, interpretation, headline, allowNoise) => {
|
|
2741
|
-
const regions = interpretation.regions;
|
|
2742
|
-
const types = regions.map((region) => normalizeChangeType(region.changeType));
|
|
2743
|
-
const severity = normalizeSeverity(interpretation.severity);
|
|
2744
|
-
const percent = input.percentDifference ?? interpretation.diffPercentage;
|
|
2745
|
-
const pixels = input.numDiffPixels ?? interpretation.diffCount;
|
|
2746
|
-
const counts = countByType(regions);
|
|
2747
|
-
if (allowNoise && types.every((type) => NOISE_TYPES.has(type))) return verdict("noise-likely", headline, ["every region is classified as rendering noise"]);
|
|
2748
|
-
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"]);
|
|
2749
|
-
if (types.some((type) => REGRESSIVE_TYPES.has(type)) && ELEVATED_SEVERITY.has(severity)) {
|
|
2750
|
-
const structural = [...counts].filter(([type]) => REGRESSIVE_TYPES.has(type)).map(([type, count]) => `${count} ${type}`).join(", ");
|
|
2751
|
-
return verdict("regression-likely", headline, [`${severity} severity with structural changes (${structural})`, "content or layout changed, not just styling"]);
|
|
2752
|
-
}
|
|
2753
|
-
const allRecolor = types.every((type) => type === "color-change");
|
|
2754
|
-
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"]);
|
|
2755
|
-
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"]);
|
|
2756
|
-
return verdict("ambiguous", headline, [`mix of change types (${formatBreakdown(counts)}) at ${severity || "unknown"} severity`, `${formatPercent(percent)} of the image differs`]);
|
|
2670
|
+
return `${`${regions.length} ${regions.length === 1 ? "region" : "regions"}`}${at} (${formatPercent(percent)})`;
|
|
2757
2671
|
};
|
|
2758
2672
|
//#endregion
|
|
2759
2673
|
//#region src/agent/reviewIndex.ts
|
|
@@ -2771,11 +2685,11 @@ const readAgentReviewIndex = async (outputDir) => {
|
|
|
2771
2685
|
return;
|
|
2772
2686
|
}
|
|
2773
2687
|
const createdAt = typeof raw?.createdAt === "string" ? Date.parse(raw.createdAt) : NaN;
|
|
2774
|
-
if (raw?.version !==
|
|
2688
|
+
if (raw?.version !== 2 || Number.isNaN(createdAt) || !Array.isArray(raw.entries)) return;
|
|
2775
2689
|
const reviews = /* @__PURE__ */ new Map();
|
|
2776
2690
|
for (const entry of raw.entries) {
|
|
2777
2691
|
if (typeof entry !== "object" || entry === null) continue;
|
|
2778
|
-
const { name, category, verdict
|
|
2692
|
+
const { name, category, verdict } = entry;
|
|
2779
2693
|
if (typeof name !== "string" || category !== "changed") continue;
|
|
2780
2694
|
if (typeof verdict !== "object" || verdict === null) continue;
|
|
2781
2695
|
const v = verdict;
|
|
@@ -2785,9 +2699,9 @@ const readAgentReviewIndex = async (outputDir) => {
|
|
|
2785
2699
|
headline: v.headline,
|
|
2786
2700
|
rationale: Array.isArray(v.rationale) ? v.rationale.filter((line) => typeof line === "string") : [],
|
|
2787
2701
|
action: v.action,
|
|
2788
|
-
source:
|
|
2702
|
+
source: "agent",
|
|
2789
2703
|
...typeof v.confidence === "number" ? { confidence: v.confidence } : {},
|
|
2790
|
-
pending:
|
|
2704
|
+
pending: false,
|
|
2791
2705
|
reviewedAt: new Date(createdAt).toISOString()
|
|
2792
2706
|
});
|
|
2793
2707
|
}
|
|
@@ -4606,6 +4520,9 @@ const renderOverview = async (options) => {
|
|
|
4606
4520
|
* Agent review: turn the screenshots on disk into something a coding agent
|
|
4607
4521
|
* can judge cheaply, and fold its judgments back in.
|
|
4608
4522
|
*
|
|
4523
|
+
* Every changed screenshot gets a judgment request. Nothing is labelled from
|
|
4524
|
+
* diff signals alone — see `VERDICT_LABELS` for why.
|
|
4525
|
+
*
|
|
4609
4526
|
* Nothing here captures. It reads `actual/`, `expected/` and `diff/` as the
|
|
4610
4527
|
* last `cappa capture` left them, so it is safe to run repeatedly — a re-run
|
|
4611
4528
|
* is how an agent's verdicts are applied, and a re-capture invalidates them
|
|
@@ -4633,11 +4550,6 @@ const JUDGMENT_FILES = [
|
|
|
4633
4550
|
"regions.png",
|
|
4634
4551
|
"overview.png"
|
|
4635
4552
|
];
|
|
4636
|
-
const JUDGE_MODES = [
|
|
4637
|
-
"ambiguous",
|
|
4638
|
-
"all",
|
|
4639
|
-
"none"
|
|
4640
|
-
];
|
|
4641
4553
|
/**
|
|
4642
4554
|
* The directory holding a screenshot's judgment.
|
|
4643
4555
|
*
|
|
@@ -4690,7 +4602,7 @@ const parseAgentVerdict = (raw) => {
|
|
|
4690
4602
|
const outer = raw;
|
|
4691
4603
|
const inner = typeof outer.verdict === "object" && outer.verdict !== null ? outer.verdict : outer;
|
|
4692
4604
|
const label = inner.label;
|
|
4693
|
-
if (!
|
|
4605
|
+
if (!isVerdictLabel(label)) return {
|
|
4694
4606
|
ok: false,
|
|
4695
4607
|
error: `label must be one of regression-likely, intentional-likely, noise-likely (got ${JSON.stringify(label)})`
|
|
4696
4608
|
};
|
|
@@ -4742,9 +4654,7 @@ const toAgentRegions = (regions) => [...regions].sort((a, b) => b.pixelCount - a
|
|
|
4742
4654
|
pixelCount: region.pixelCount,
|
|
4743
4655
|
percentage: region.percentage,
|
|
4744
4656
|
position: region.position,
|
|
4745
|
-
shape: region.shape
|
|
4746
|
-
changeType: normalizeChangeType(region.changeType),
|
|
4747
|
-
confidence: region.confidence
|
|
4657
|
+
shape: region.shape
|
|
4748
4658
|
}));
|
|
4749
4659
|
/**
|
|
4750
4660
|
* The interpretation a capture already persisted, or a fresh one.
|
|
@@ -4767,8 +4677,10 @@ const interpretationFor = async (screenshot, expectedPath, actualPath, diff) =>
|
|
|
4767
4677
|
}
|
|
4768
4678
|
};
|
|
4769
4679
|
const JUDGE_INSTRUCTIONS = [
|
|
4680
|
+
"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.",
|
|
4770
4681
|
"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.",
|
|
4771
4682
|
"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.",
|
|
4683
|
+
"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.",
|
|
4772
4684
|
"Only open paths.expected / paths.actual / paths.diff (full size) when a change clearly continues outside its crop.",
|
|
4773
4685
|
"Write verdict.json next to this file, or run `cappa agent judge <name> --label <label> --headline <text>`."
|
|
4774
4686
|
];
|
|
@@ -4826,7 +4738,7 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4826
4738
|
const percentDifference = screenshot.diffMeta?.percentDifference ?? interpretation?.diffPercentage;
|
|
4827
4739
|
const numDiffPixels = screenshot.diffMeta?.numDiffPixels ?? interpretation?.diffCount;
|
|
4828
4740
|
const regions = toAgentRegions(interpretation?.regions ?? []);
|
|
4829
|
-
const
|
|
4741
|
+
const change = describeChange({
|
|
4830
4742
|
percentDifference,
|
|
4831
4743
|
numDiffPixels,
|
|
4832
4744
|
interpretation,
|
|
@@ -4850,20 +4762,13 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4850
4762
|
expected: expectedSize,
|
|
4851
4763
|
actual: actualSize
|
|
4852
4764
|
},
|
|
4853
|
-
|
|
4854
|
-
summary: interpretation?.summary,
|
|
4765
|
+
change,
|
|
4855
4766
|
regions,
|
|
4856
|
-
|
|
4857
|
-
verdict: {
|
|
4858
|
-
...heuristic,
|
|
4859
|
-
source: "heuristic"
|
|
4860
|
-
},
|
|
4861
|
-
pending: false
|
|
4767
|
+
pending: true
|
|
4862
4768
|
};
|
|
4863
4769
|
const dir = judgmentDir(outputDir, screenshot.name);
|
|
4864
4770
|
const requestPath = path.join(dir, REQUEST_FILE);
|
|
4865
4771
|
const verdictPath = path.join(dir, VERDICT_FILE);
|
|
4866
|
-
if (!(options.judge === "all" || options.judge === "ambiguous" && heuristic.label === "ambiguous" || await exists(requestPath))) return entry;
|
|
4867
4772
|
const fingerprint = await fingerprintImages(expectedPath, actualPath);
|
|
4868
4773
|
const previous = await readJson(requestPath);
|
|
4869
4774
|
if (previous && previous.fingerprint !== fingerprint) await clearJudgmentFiles(dir);
|
|
@@ -4892,7 +4797,7 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4892
4797
|
}
|
|
4893
4798
|
entry.judgment = judgment;
|
|
4894
4799
|
await writeJson(requestPath, {
|
|
4895
|
-
version:
|
|
4800
|
+
version: 2,
|
|
4896
4801
|
name: entry.name,
|
|
4897
4802
|
taskId: entry.taskId,
|
|
4898
4803
|
plugin: entry.plugin,
|
|
@@ -4900,12 +4805,10 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4900
4805
|
createdAt,
|
|
4901
4806
|
instructions: JUDGE_INSTRUCTIONS,
|
|
4902
4807
|
verdictSchema: VERDICT_SCHEMA,
|
|
4903
|
-
|
|
4808
|
+
change,
|
|
4904
4809
|
percentDifference,
|
|
4905
4810
|
numDiffPixels,
|
|
4906
4811
|
dimensions: entry.dimensions,
|
|
4907
|
-
severity: entry.severity,
|
|
4908
|
-
summary: entry.summary,
|
|
4909
4812
|
regions,
|
|
4910
4813
|
paths: {
|
|
4911
4814
|
locator: judgment.locator,
|
|
@@ -4917,22 +4820,18 @@ const analyseOnCanvas = async ({ screenshot, options, createdAt, paths: { expect
|
|
|
4917
4820
|
verdict: verdictPath
|
|
4918
4821
|
}
|
|
4919
4822
|
});
|
|
4920
|
-
if (!await exists(verdictPath))
|
|
4921
|
-
entry.pending = true;
|
|
4922
|
-
return entry;
|
|
4923
|
-
}
|
|
4823
|
+
if (!await exists(verdictPath)) return entry;
|
|
4924
4824
|
const parsed = parseAgentVerdict(await readJson(verdictPath));
|
|
4925
4825
|
if (!parsed.ok) {
|
|
4926
|
-
entry.pending = true;
|
|
4927
4826
|
entry.verdictError = parsed.error;
|
|
4928
4827
|
return entry;
|
|
4929
4828
|
}
|
|
4829
|
+
entry.pending = false;
|
|
4930
4830
|
entry.verdict = {
|
|
4931
4831
|
label: parsed.label,
|
|
4932
4832
|
headline: parsed.headline,
|
|
4933
4833
|
rationale: parsed.rationale,
|
|
4934
4834
|
action: ACTION_BY_LABEL[parsed.label],
|
|
4935
|
-
source: "agent",
|
|
4936
4835
|
...parsed.confidence !== void 0 ? { confidence: parsed.confidence } : {}
|
|
4937
4836
|
};
|
|
4938
4837
|
return entry;
|
|
@@ -4976,13 +4875,12 @@ const pruneJudgments = async (outputDir, keep) => {
|
|
|
4976
4875
|
}
|
|
4977
4876
|
};
|
|
4978
4877
|
/**
|
|
4979
|
-
* Analyse every non-passing screenshot, write judgment
|
|
4980
|
-
*
|
|
4981
|
-
*
|
|
4878
|
+
* Analyse every non-passing screenshot, write a judgment request for every
|
|
4879
|
+
* changed one, apply any verdicts already written, and persist the full
|
|
4880
|
+
* report to `<outputDir>/.cappa-agent/report.json`.
|
|
4982
4881
|
*/
|
|
4983
4882
|
const runAgentCheck = async (options) => {
|
|
4984
4883
|
const outputDir = path.resolve(options.outputDir);
|
|
4985
|
-
const judge = options.judge ?? "ambiguous";
|
|
4986
4884
|
const createdAt = (options.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
|
|
4987
4885
|
const screenshots = await collectScreenshots(outputDir);
|
|
4988
4886
|
await fsp.mkdir(agentDir(outputDir), { recursive: true });
|
|
@@ -4990,8 +4888,7 @@ const runAgentCheck = async (options) => {
|
|
|
4990
4888
|
const changed = screenshots.filter((s) => s.category === "changed");
|
|
4991
4889
|
const changedEntries = await mapWithConcurrency(options.concurrency ?? 4, changed, (screenshot) => analyseChanged(screenshot, {
|
|
4992
4890
|
...options,
|
|
4993
|
-
outputDir
|
|
4994
|
-
judge
|
|
4891
|
+
outputDir
|
|
4995
4892
|
}, createdAt));
|
|
4996
4893
|
await pruneJudgments(outputDir, new Set(changedEntries.flatMap((entry) => entry.judgment ? [entry.judgment.dir] : [])));
|
|
4997
4894
|
const otherEntries = screenshots.flatMap((s) => {
|
|
@@ -5016,11 +4913,10 @@ const runAgentCheck = async (options) => {
|
|
|
5016
4913
|
const entries = [...changedEntries, ...otherEntries];
|
|
5017
4914
|
const count = (category) => screenshots.filter((s) => s.category === category).length;
|
|
5018
4915
|
const report = {
|
|
5019
|
-
version:
|
|
4916
|
+
version: 2,
|
|
5020
4917
|
createdAt,
|
|
5021
4918
|
outputDir,
|
|
5022
4919
|
reportPath: agentReportPath(outputDir),
|
|
5023
|
-
judge,
|
|
5024
4920
|
totals: {
|
|
5025
4921
|
total: screenshots.length,
|
|
5026
4922
|
passed: count("passed"),
|
|
@@ -5037,7 +4933,7 @@ const runAgentCheck = async (options) => {
|
|
|
5037
4933
|
/** Read the report the last {@link runAgentCheck} wrote, if any. */
|
|
5038
4934
|
const readAgentReport = async (outputDir) => {
|
|
5039
4935
|
const raw = await readJson(agentReportPath(outputDir));
|
|
5040
|
-
return raw?.version ===
|
|
4936
|
+
return raw?.version === 2 ? raw : void 0;
|
|
5041
4937
|
};
|
|
5042
4938
|
/**
|
|
5043
4939
|
* The report as an agent should first see it: one line of state per
|
|
@@ -5050,11 +4946,11 @@ const toSlimAgentReport = (report) => ({
|
|
|
5050
4946
|
results: report.entries.map((entry) => ({
|
|
5051
4947
|
name: entry.name,
|
|
5052
4948
|
category: entry.category,
|
|
4949
|
+
...entry.change ? { change: entry.change } : {},
|
|
5053
4950
|
...entry.verdict ? { verdict: {
|
|
5054
4951
|
label: entry.verdict.label,
|
|
5055
4952
|
headline: entry.verdict.headline,
|
|
5056
|
-
action: entry.verdict.action
|
|
5057
|
-
source: entry.verdict.source
|
|
4953
|
+
action: entry.verdict.action
|
|
5058
4954
|
} } : {},
|
|
5059
4955
|
...entry.pending ? { pending: true } : {},
|
|
5060
4956
|
...entry.pending && entry.judgment ? { judgment: entry.judgment.dir } : {},
|
|
@@ -5067,7 +4963,7 @@ const toSlimAgentReport = (report) => ({
|
|
|
5067
4963
|
*/
|
|
5068
4964
|
const writeAgentVerdict = async (outputDir, name, input) => {
|
|
5069
4965
|
const dir = judgmentDir(outputDir, name);
|
|
5070
|
-
if (!await exists(path.join(dir, REQUEST_FILE))) throw new Error(`No judgment request for "${name}" — run \`cappa agent check\` first
|
|
4966
|
+
if (!await exists(path.join(dir, REQUEST_FILE))) throw new Error(`No judgment request for "${name}" — run \`cappa agent check\` first; only changed screenshots get one.`);
|
|
5071
4967
|
const parsed = parseAgentVerdict(input);
|
|
5072
4968
|
if (!parsed.ok) throw new Error(parsed.error);
|
|
5073
4969
|
const verdictPath = path.join(dir, VERDICT_FILE);
|
|
@@ -5113,6 +5009,6 @@ function resolveWebServerConfig(webServer, configDir, env = process.env) {
|
|
|
5113
5009
|
});
|
|
5114
5010
|
}
|
|
5115
5011
|
//#endregion
|
|
5116
|
-
export { ACTION_BY_LABEL, AGENT_DIRNAME, AGENT_REPORT_VERSION, CONSOLE_LOG_LEVELS, CaptureRunner, DEFAULT_CROP_PADDING, DEFAULT_DEBOUNCE_MS, DEFAULT_IGNORED_DIRS, DEFAULT_KILL_GRACE_MS, DEFAULT_MAX_TASKS, DEFAULT_WEB_SERVER_TIMEOUT_MS, ENGINE_ERROR_CODES, FsScreenshotStore,
|
|
5012
|
+
export { ACTION_BY_LABEL, AGENT_DIRNAME, AGENT_REPORT_VERSION, CONSOLE_LOG_LEVELS, CaptureRunner, DEFAULT_CROP_PADDING, DEFAULT_DEBOUNCE_MS, DEFAULT_IGNORED_DIRS, DEFAULT_KILL_GRACE_MS, DEFAULT_MAX_TASKS, DEFAULT_WEB_SERVER_TIMEOUT_MS, ENGINE_ERROR_CODES, FsScreenshotStore, LocalEngine, MANIFEST_FILENAME, MANIFEST_VERSION, NO_WEB_SERVER_HINT, OutputTail, RunInProgressError, RunStore, ScreenshotFileSystem, ScreenshotTool, UnknownTargetsError, VERDICT_LABELS, WarmBrowser, WatchInProgressError, WatchSession, WebServerError, WebServerPool, agentDir, agentReportPath, attachConsoleLogging, clearJudgment, collectScreenshots, compareImages, compareImagesGMSD, contextPadding, defineConfig, describeChange, didScreenshotFail, filterTasks, findRefusedConnection, fingerprintImages, getDeletedScreenshots, groupScreenshots, imagesMatch, imagesMatchGMSD, isRunInProgressError, isUnknownTargetsError, isUrlReady, isVerdictLabel, isWatchInProgressError, judgmentDir, mapWithConcurrency, measureContentClip, mergeCaptureManifest, normalizeChangeType, padAndClamp, parseAgentVerdict, readAgentReport, readCaptureManifest, readDiffMeta, recordCaptureOrigins, renderJudgmentTiles, renderOverview, resolveCrop, resolveWebServerConfig, runAgentCheck, sameServer, sanitizeScreenshotFilename, selectTasks, spawnServerProcess, toConsoleLogLevel, toDiffMetaPath, toManifestKey, toSerializedError, toSlimAgentReport, toTaskStatus, waitForUrl, writeAgentVerdict };
|
|
5117
5013
|
|
|
5118
5014
|
//# sourceMappingURL=index.mjs.map
|