vibecode-anything 0.3.0 → 0.4.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/README.md +239 -67
- package/dist/cli.js +2140 -73
- package/dist/core/adapters.d.ts +26 -3
- package/dist/core/adapters.js +411 -25
- package/dist/core/agent-adapter.d.ts +67 -0
- package/dist/core/agent-adapter.js +312 -0
- package/dist/core/anti-cheat.d.ts +6 -0
- package/dist/core/anti-cheat.js +372 -0
- package/dist/core/badge.d.ts +18 -0
- package/dist/core/badge.js +360 -0
- package/dist/core/cache.d.ts +47 -0
- package/dist/core/cache.js +403 -0
- package/dist/core/ci-export.d.ts +35 -0
- package/dist/core/ci-export.js +796 -0
- package/dist/core/ci-formats.d.ts +21 -0
- package/dist/core/ci-formats.js +388 -0
- package/dist/core/client-codegen.d.ts +36 -0
- package/dist/core/client-codegen.js +2538 -0
- package/dist/core/compose.d.ts +71 -0
- package/dist/core/compose.js +1088 -0
- package/dist/core/docs-export.d.ts +37 -0
- package/dist/core/docs-export.js +2706 -0
- package/dist/core/doctor.d.ts +21 -1
- package/dist/core/doctor.js +234 -21
- package/dist/core/exec.d.ts +26 -2
- package/dist/core/exec.js +235 -8
- package/dist/core/fixtures.d.ts +153 -0
- package/dist/core/fixtures.js +2245 -0
- package/dist/core/format.d.ts +77 -0
- package/dist/core/format.js +632 -0
- package/dist/core/fs-snapshot.d.ts +37 -0
- package/dist/core/fs-snapshot.js +216 -0
- package/dist/core/graphql-export.d.ts +34 -0
- package/dist/core/graphql-export.js +2482 -0
- package/dist/core/har-export.d.ts +29 -0
- package/dist/core/har-export.js +988 -0
- package/dist/core/html-report.d.ts +27 -0
- package/dist/core/html-report.js +1535 -0
- package/dist/core/http-export.d.ts +31 -0
- package/dist/core/http-export.js +726 -0
- package/dist/core/impact.d.ts +80 -0
- package/dist/core/impact.js +1412 -0
- package/dist/core/lint.d.ts +38 -0
- package/dist/core/lint.js +1111 -0
- package/dist/core/load-export.d.ts +37 -0
- package/dist/core/load-export.js +1813 -0
- package/dist/core/mcp-export.d.ts +35 -0
- package/dist/core/mcp-export.js +1736 -0
- package/dist/core/mock-server.d.ts +47 -0
- package/dist/core/mock-server.js +1722 -0
- package/dist/core/openapi-export.d.ts +44 -0
- package/dist/core/openapi-export.js +1074 -0
- package/dist/core/parity.d.ts +6 -1
- package/dist/core/parity.js +36 -1
- package/dist/core/playwright-exporter.d.ts +23 -0
- package/dist/core/playwright-exporter.js +1343 -0
- package/dist/core/png.js +45 -9
- package/dist/core/regression.d.ts +54 -0
- package/dist/core/regression.js +529 -0
- package/dist/core/responsive.d.ts +86 -0
- package/dist/core/responsive.js +606 -0
- package/dist/core/run.d.ts +74 -0
- package/dist/core/run.js +696 -0
- package/dist/core/scheduler.d.ts +24 -0
- package/dist/core/scheduler.js +162 -0
- package/dist/core/schema-export.d.ts +29 -0
- package/dist/core/schema-export.js +2215 -0
- package/dist/core/schema.d.ts +3 -2
- package/dist/core/schema.js +460 -17
- package/dist/core/security.d.ts +233 -0
- package/dist/core/security.js +1839 -0
- package/dist/core/server-export.d.ts +38 -0
- package/dist/core/server-export.js +3198 -0
- package/dist/core/spec-writer.d.ts +9 -0
- package/dist/core/spec-writer.js +1202 -0
- package/dist/core/store.d.ts +11 -2
- package/dist/core/store.js +128 -8
- package/dist/core/target-map.d.ts +34 -0
- package/dist/core/target-map.js +262 -0
- package/dist/core/test-exporter.d.ts +25 -0
- package/dist/core/test-exporter.js +1918 -0
- package/dist/core/types.d.ts +182 -14
- package/dist/core/visual-semantic.d.ts +67 -0
- package/dist/core/visual-semantic.js +673 -0
- package/dist/core/visual.js +65 -16
- package/dist/core/watch.d.ts +28 -3
- package/dist/core/watch.js +222 -12
- package/dist/core/yaml.d.ts +5 -0
- package/dist/core/yaml.js +1009 -0
- package/dist/diagnostics/diagnose.d.ts +53 -0
- package/dist/diagnostics/diagnose.js +1083 -0
- package/dist/diagnostics/flake.d.ts +71 -0
- package/dist/diagnostics/flake.js +608 -0
- package/dist/diagnostics/mutation-audit.d.ts +69 -0
- package/dist/diagnostics/mutation-audit.js +769 -0
- package/dist/diagnostics/spatial.d.ts +42 -0
- package/dist/diagnostics/spatial.js +346 -0
- package/dist/diagnostics/trends.d.ts +122 -0
- package/dist/diagnostics/trends.js +1190 -0
- package/dist/discovery/discover.d.ts +111 -0
- package/dist/discovery/discover.js +2017 -0
- package/dist/discovery/lock.d.ts +116 -0
- package/dist/discovery/lock.js +1505 -0
- package/dist/discovery/routes.d.ts +36 -0
- package/dist/discovery/routes.js +1494 -0
- package/dist/discovery/test-importer.d.ts +92 -0
- package/dist/discovery/test-importer.js +4952 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +99 -0
- package/dist/ingestors/api-collections.d.ts +28 -0
- package/dist/ingestors/api-collections.js +2335 -0
- package/dist/ingestors/api-repo.d.ts +2 -1
- package/dist/ingestors/api-repo.js +483 -85
- package/dist/ingestors/asyncapi.d.ts +26 -0
- package/dist/ingestors/asyncapi.js +2105 -0
- package/dist/ingestors/bridges.d.ts +2 -0
- package/dist/ingestors/bridges.js +702 -0
- package/dist/ingestors/cli.d.ts +2 -1
- package/dist/ingestors/cli.js +234 -46
- package/dist/ingestors/curl.d.ts +14 -0
- package/dist/ingestors/curl.js +1024 -0
- package/dist/ingestors/graphql.d.ts +56 -0
- package/dist/ingestors/graphql.js +1852 -0
- package/dist/ingestors/http-file.d.ts +20 -0
- package/dist/ingestors/http-file.js +923 -0
- package/dist/ingestors/index.js +486 -6
- package/dist/ingestors/openrpc.d.ts +29 -0
- package/dist/ingestors/openrpc.js +1807 -0
- package/dist/ingestors/proto.d.ts +47 -0
- package/dist/ingestors/proto.js +2690 -0
- package/dist/ingestors/trace.d.ts +10 -0
- package/dist/ingestors/trace.js +599 -0
- package/dist/ingestors/video.d.ts +4 -1
- package/dist/ingestors/video.js +86 -36
- package/dist/ingestors/web.d.ts +16 -1
- package/dist/ingestors/web.js +474 -32
- package/dist/mcp/server.js +3532 -67
- package/dist/oracles/api-repo.js +102 -30
- package/dist/oracles/cli.js +65 -17
- package/dist/oracles/http-workflow.d.ts +68 -0
- package/dist/oracles/http-workflow.js +828 -0
- package/dist/oracles/image.js +178 -28
- package/dist/oracles/index.d.ts +3 -1
- package/dist/oracles/index.js +243 -14
- package/dist/oracles/perf-budget.d.ts +90 -0
- package/dist/oracles/perf-budget.js +1329 -0
- package/dist/oracles/stream.d.ts +94 -0
- package/dist/oracles/stream.js +1268 -0
- package/dist/oracles/ui-states.d.ts +49 -0
- package/dist/oracles/ui-states.js +894 -0
- package/dist/oracles/video.d.ts +1 -1
- package/dist/oracles/video.js +232 -16
- package/dist/oracles/web.js +464 -73
- package/dist/plugins/builtins.d.ts +12 -0
- package/dist/plugins/builtins.js +1052 -0
- package/dist/plugins/registry.d.ts +86 -0
- package/dist/plugins/registry.js +554 -0
- package/dist/setup/index.js +145 -33
- package/package.json +56 -47
- package/skills/vibecode-anything/SKILL.md +75 -52
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency spatial visual diagnostics: 3x3 quadrant pixel-diff heatmaps
|
|
3
|
+
* and bounding-box shift vector extraction.
|
|
4
|
+
*/
|
|
5
|
+
import type { LayoutRegion, MatchedRegion, RgbaImage } from "../core/types.js";
|
|
6
|
+
export type SpatialQuadrantId = "top-left" | "top-center" | "top-right" | "middle-left" | "middle-center" | "middle-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
7
|
+
export interface SpatialCell {
|
|
8
|
+
id: SpatialQuadrantId;
|
|
9
|
+
row: 0 | 1 | 2;
|
|
10
|
+
col: 0 | 1 | 2;
|
|
11
|
+
diffRatio: number;
|
|
12
|
+
meanColorDelta: number;
|
|
13
|
+
changedPixels: number;
|
|
14
|
+
totalPixels: number;
|
|
15
|
+
}
|
|
16
|
+
export interface SpatialHeatmapResult {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
cells: SpatialCell[];
|
|
20
|
+
hottestQuadrants: SpatialQuadrantId[];
|
|
21
|
+
overallDiffRatio: number;
|
|
22
|
+
asciiGrid: string;
|
|
23
|
+
summary: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SpatialHeatmapOptions {
|
|
26
|
+
channelDeltaThreshold?: number;
|
|
27
|
+
maxEdge?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface BBoxShiftVector {
|
|
30
|
+
refId: string;
|
|
31
|
+
candId: string;
|
|
32
|
+
dx: number;
|
|
33
|
+
dy: number;
|
|
34
|
+
dw: number;
|
|
35
|
+
dh: number;
|
|
36
|
+
magnitudePx: number;
|
|
37
|
+
iou: number;
|
|
38
|
+
direction: string;
|
|
39
|
+
}
|
|
40
|
+
export declare function computeSpatialQuadrantHeatmap(refImg: RgbaImage, candImg: RgbaImage, options?: SpatialHeatmapOptions): SpatialHeatmapResult;
|
|
41
|
+
export declare function computeSpatialHeatmapFromFiles(refPath: string, candPath: string, options?: SpatialHeatmapOptions): Promise<SpatialHeatmapResult | null>;
|
|
42
|
+
export declare function computeBBoxShiftVectors(refRegions: readonly LayoutRegion[], candRegions: readonly LayoutRegion[], matches?: readonly MatchedRegion[]): BBoxShiftVector[];
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency spatial visual diagnostics: 3x3 quadrant pixel-diff heatmaps
|
|
3
|
+
* and bounding-box shift vector extraction.
|
|
4
|
+
*/
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { hasCrossPlatformPathEscape, isInsideVaultDirectory } from "../core/security.js";
|
|
8
|
+
import { bboxIoU, compareRegionsIoU, decodeImage, resizeRgba } from "../core/visual.js";
|
|
9
|
+
const DEFAULT_CHANNEL_DELTA_THRESHOLD = 16;
|
|
10
|
+
const DEFAULT_MAX_EDGE = 512;
|
|
11
|
+
const MAX_ALLOWED_EDGE = 4096;
|
|
12
|
+
const MAX_INPUT_PIXELS = 64 * 1024 * 1024;
|
|
13
|
+
const MAX_IMAGE_FILE_BYTES = 32 * 1024 * 1024;
|
|
14
|
+
const MAX_BBOX_REGIONS = 256;
|
|
15
|
+
const GENERIC_REGION_ID_RE = /^r-\d+$/;
|
|
16
|
+
const QUADRANTS = [
|
|
17
|
+
{ id: "top-left", short: "TL", row: 0, col: 0 },
|
|
18
|
+
{ id: "top-center", short: "TC", row: 0, col: 1 },
|
|
19
|
+
{ id: "top-right", short: "TR", row: 0, col: 2 },
|
|
20
|
+
{ id: "middle-left", short: "ML", row: 1, col: 0 },
|
|
21
|
+
{ id: "middle-center", short: "MC", row: 1, col: 1 },
|
|
22
|
+
{ id: "middle-right", short: "MR", row: 1, col: 2 },
|
|
23
|
+
{ id: "bottom-left", short: "BL", row: 2, col: 0 },
|
|
24
|
+
{ id: "bottom-center", short: "BC", row: 2, col: 1 },
|
|
25
|
+
{ id: "bottom-right", short: "BR", row: 2, col: 2 }
|
|
26
|
+
];
|
|
27
|
+
function round4(value) {
|
|
28
|
+
if (!Number.isFinite(value))
|
|
29
|
+
return 0;
|
|
30
|
+
const r = Math.round(value * 10000) / 10000;
|
|
31
|
+
return r === 0 ? 0 : r;
|
|
32
|
+
}
|
|
33
|
+
function round2(value) {
|
|
34
|
+
if (!Number.isFinite(value))
|
|
35
|
+
return 0;
|
|
36
|
+
const r = Math.round(value * 100) / 100;
|
|
37
|
+
return r === 0 ? 0 : r;
|
|
38
|
+
}
|
|
39
|
+
function formatDeltaNum(value) {
|
|
40
|
+
const abs = Math.abs(round2(value));
|
|
41
|
+
return Number.isInteger(abs) ? String(abs) : String(abs);
|
|
42
|
+
}
|
|
43
|
+
function buildAsciiGrid(cells) {
|
|
44
|
+
const rows = [];
|
|
45
|
+
for (let row = 0; row < 3; row++) {
|
|
46
|
+
const cols = [];
|
|
47
|
+
for (let col = 0; col < 3; col++) {
|
|
48
|
+
const idx = row * 3 + col;
|
|
49
|
+
const pct = `${(cells[idx].diffRatio * 100).toFixed(1)}%`.padStart(5, " ");
|
|
50
|
+
cols.push(`[${QUADRANTS[idx].short} ${pct}]`);
|
|
51
|
+
}
|
|
52
|
+
rows.push(cols.join(" "));
|
|
53
|
+
}
|
|
54
|
+
return rows.join("\n");
|
|
55
|
+
}
|
|
56
|
+
function buildSummary(cells, hottest, overallDiffRatio) {
|
|
57
|
+
if (hottest.length === 0 || overallDiffRatio <= 0) {
|
|
58
|
+
return "No pixel differences detected across 3x3 quadrants.";
|
|
59
|
+
}
|
|
60
|
+
const byId = new Map();
|
|
61
|
+
for (const c of cells)
|
|
62
|
+
byId.set(c.id, c);
|
|
63
|
+
const topDesc = hottest
|
|
64
|
+
.map((id) => {
|
|
65
|
+
const cell = byId.get(id);
|
|
66
|
+
const pct = cell ? (cell.diffRatio * 100).toFixed(1) : "0.0";
|
|
67
|
+
return `${id} (${pct}%)`;
|
|
68
|
+
})
|
|
69
|
+
.join(", ");
|
|
70
|
+
return `Overall diff ${(overallDiffRatio * 100).toFixed(1)}%; hottest quadrants: ${topDesc}.`;
|
|
71
|
+
}
|
|
72
|
+
function isSafeDirectImagePath(filePath) {
|
|
73
|
+
if (typeof filePath !== "string")
|
|
74
|
+
return false;
|
|
75
|
+
const raw = filePath.trim();
|
|
76
|
+
return Boolean(raw) && !hasCrossPlatformPathEscape(filePath) && !isInsideVaultDirectory(raw);
|
|
77
|
+
}
|
|
78
|
+
function isValidRgbaImage(img) {
|
|
79
|
+
if (!img || typeof img !== "object")
|
|
80
|
+
return false;
|
|
81
|
+
if (!Number.isSafeInteger(img.width) || !Number.isSafeInteger(img.height))
|
|
82
|
+
return false;
|
|
83
|
+
if (img.width <= 0 || img.height <= 0)
|
|
84
|
+
return false;
|
|
85
|
+
if (img.width * img.height > MAX_INPUT_PIXELS)
|
|
86
|
+
return false;
|
|
87
|
+
if (!(img.data instanceof Uint8Array))
|
|
88
|
+
return false;
|
|
89
|
+
return img.data.length >= img.width * img.height * 4;
|
|
90
|
+
}
|
|
91
|
+
export function computeSpatialQuadrantHeatmap(refImg, candImg, options = {}) {
|
|
92
|
+
const opts = options && typeof options === "object" ? options : {};
|
|
93
|
+
const threshold = typeof opts.channelDeltaThreshold === "number" &&
|
|
94
|
+
Number.isFinite(opts.channelDeltaThreshold) &&
|
|
95
|
+
opts.channelDeltaThreshold >= 0
|
|
96
|
+
? opts.channelDeltaThreshold
|
|
97
|
+
: DEFAULT_CHANNEL_DELTA_THRESHOLD;
|
|
98
|
+
const maxEdge = typeof opts.maxEdge === "number" && Number.isFinite(opts.maxEdge) && opts.maxEdge >= 3
|
|
99
|
+
? Math.min(MAX_ALLOWED_EDGE, Math.floor(opts.maxEdge))
|
|
100
|
+
: DEFAULT_MAX_EDGE;
|
|
101
|
+
if (!isValidRgbaImage(refImg) || !isValidRgbaImage(candImg)) {
|
|
102
|
+
const emptyCells = QUADRANTS.map((q) => ({
|
|
103
|
+
id: q.id,
|
|
104
|
+
row: q.row,
|
|
105
|
+
col: q.col,
|
|
106
|
+
diffRatio: 0,
|
|
107
|
+
meanColorDelta: 0,
|
|
108
|
+
changedPixels: 0,
|
|
109
|
+
totalPixels: 0
|
|
110
|
+
}));
|
|
111
|
+
return {
|
|
112
|
+
width: 0,
|
|
113
|
+
height: 0,
|
|
114
|
+
cells: emptyCells,
|
|
115
|
+
hottestQuadrants: [],
|
|
116
|
+
overallDiffRatio: 0,
|
|
117
|
+
asciiGrid: buildAsciiGrid(emptyCells),
|
|
118
|
+
summary: "No pixel differences detected across 3x3 quadrants."
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
let w = refImg.width;
|
|
122
|
+
let h = refImg.height;
|
|
123
|
+
const edge = Math.max(w, h);
|
|
124
|
+
if (edge > maxEdge) {
|
|
125
|
+
const scale = maxEdge / edge;
|
|
126
|
+
w = Math.max(1, Math.round(w * scale));
|
|
127
|
+
h = Math.max(1, Math.round(h * scale));
|
|
128
|
+
}
|
|
129
|
+
const ref = refImg.width === w && refImg.height === h ? refImg : resizeRgba(refImg, w, h);
|
|
130
|
+
const cand = candImg.width === w && candImg.height === h ? candImg : resizeRgba(candImg, w, h);
|
|
131
|
+
const changedCounts = new Uint32Array(9);
|
|
132
|
+
const totalCounts = new Uint32Array(9);
|
|
133
|
+
const deltaSums = new Float64Array(9);
|
|
134
|
+
let totalChanged = 0;
|
|
135
|
+
const totalPixels = w * h;
|
|
136
|
+
const refData = ref.data;
|
|
137
|
+
const candData = cand.data;
|
|
138
|
+
for (let y = 0; y < h; y++) {
|
|
139
|
+
const row = Math.min(2, Math.floor((y * 3) / h));
|
|
140
|
+
const rowOffset = row * 3;
|
|
141
|
+
const pixelRow = y * w;
|
|
142
|
+
for (let x = 0; x < w; x++) {
|
|
143
|
+
const col = Math.min(2, Math.floor((x * 3) / w));
|
|
144
|
+
const idx = rowOffset + col;
|
|
145
|
+
const p = (pixelRow + x) * 4;
|
|
146
|
+
const dr = Math.abs(refData[p] - candData[p]);
|
|
147
|
+
const dg = Math.abs(refData[p + 1] - candData[p + 1]);
|
|
148
|
+
const db = Math.abs(refData[p + 2] - candData[p + 2]);
|
|
149
|
+
const da = Math.abs(refData[p + 3] - candData[p + 3]);
|
|
150
|
+
const maxChannelDelta = Math.max(dr, dg, db, da);
|
|
151
|
+
const rgbAvg = (dr + dg + db) / 3;
|
|
152
|
+
const normDelta = (da > 0 ? Math.max(rgbAvg, da) : rgbAvg) / 255;
|
|
153
|
+
totalCounts[idx]++;
|
|
154
|
+
deltaSums[idx] += normDelta;
|
|
155
|
+
if (maxChannelDelta > threshold) {
|
|
156
|
+
changedCounts[idx]++;
|
|
157
|
+
totalChanged++;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const cells = QUADRANTS.map((q, idx) => {
|
|
162
|
+
const total = totalCounts[idx];
|
|
163
|
+
const changed = changedCounts[idx];
|
|
164
|
+
return {
|
|
165
|
+
id: q.id,
|
|
166
|
+
row: q.row,
|
|
167
|
+
col: q.col,
|
|
168
|
+
diffRatio: total > 0 ? round4(changed / total) : 0,
|
|
169
|
+
meanColorDelta: total > 0 ? round4(deltaSums[idx] / total) : 0,
|
|
170
|
+
changedPixels: changed,
|
|
171
|
+
totalPixels: total
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
const hottestQuadrants = cells
|
|
175
|
+
.filter((c) => c.changedPixels > 0)
|
|
176
|
+
.sort((a, b) => {
|
|
177
|
+
if (b.diffRatio !== a.diffRatio)
|
|
178
|
+
return b.diffRatio - a.diffRatio;
|
|
179
|
+
if (b.meanColorDelta !== a.meanColorDelta)
|
|
180
|
+
return b.meanColorDelta - a.meanColorDelta;
|
|
181
|
+
return a.row * 3 + a.col - (b.row * 3 + b.col);
|
|
182
|
+
})
|
|
183
|
+
.slice(0, 3)
|
|
184
|
+
.map((c) => c.id);
|
|
185
|
+
const overallDiffRatio = totalPixels > 0 ? round4(totalChanged / totalPixels) : 0;
|
|
186
|
+
const asciiGrid = buildAsciiGrid(cells);
|
|
187
|
+
const summary = buildSummary(cells, hottestQuadrants, overallDiffRatio);
|
|
188
|
+
return {
|
|
189
|
+
width: w,
|
|
190
|
+
height: h,
|
|
191
|
+
cells,
|
|
192
|
+
hottestQuadrants,
|
|
193
|
+
overallDiffRatio,
|
|
194
|
+
asciiGrid,
|
|
195
|
+
summary
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
export async function computeSpatialHeatmapFromFiles(refPath, candPath, options = {}) {
|
|
199
|
+
if (!isSafeDirectImagePath(refPath) || !isSafeDirectImagePath(candPath))
|
|
200
|
+
return null;
|
|
201
|
+
try {
|
|
202
|
+
const refResolved = path.resolve(refPath.trim());
|
|
203
|
+
const candResolved = path.resolve(candPath.trim());
|
|
204
|
+
const refStat = fs.statSync(refResolved);
|
|
205
|
+
const candStat = fs.statSync(candResolved);
|
|
206
|
+
if (!refStat.isFile() || !candStat.isFile())
|
|
207
|
+
return null;
|
|
208
|
+
if (refStat.size <= 0 || refStat.size > MAX_IMAGE_FILE_BYTES)
|
|
209
|
+
return null;
|
|
210
|
+
if (candStat.size <= 0 || candStat.size > MAX_IMAGE_FILE_BYTES)
|
|
211
|
+
return null;
|
|
212
|
+
const realRef = fs.realpathSync(refResolved);
|
|
213
|
+
const realCand = fs.realpathSync(candResolved);
|
|
214
|
+
if (isInsideVaultDirectory(realRef) || isInsideVaultDirectory(realCand))
|
|
215
|
+
return null;
|
|
216
|
+
const [refImg, candImg] = await Promise.all([decodeImage(realRef), decodeImage(realCand)]);
|
|
217
|
+
return computeSpatialQuadrantHeatmap(refImg, candImg, options);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function formatShiftDirection(dx, dy, dw, dh) {
|
|
224
|
+
const parts = [];
|
|
225
|
+
const eps = 1e-6;
|
|
226
|
+
if (dx > eps)
|
|
227
|
+
parts.push(`right +${formatDeltaNum(dx)}px`);
|
|
228
|
+
else if (dx < -eps)
|
|
229
|
+
parts.push(`left -${formatDeltaNum(dx)}px`);
|
|
230
|
+
if (dy > eps)
|
|
231
|
+
parts.push(`down +${formatDeltaNum(dy)}px`);
|
|
232
|
+
else if (dy < -eps)
|
|
233
|
+
parts.push(`up -${formatDeltaNum(dy)}px`);
|
|
234
|
+
if (dw > eps)
|
|
235
|
+
parts.push(`wider +${formatDeltaNum(dw)}px`);
|
|
236
|
+
else if (dw < -eps)
|
|
237
|
+
parts.push(`narrower -${formatDeltaNum(dw)}px`);
|
|
238
|
+
if (dh > eps)
|
|
239
|
+
parts.push(`taller +${formatDeltaNum(dh)}px`);
|
|
240
|
+
else if (dh < -eps)
|
|
241
|
+
parts.push(`shorter -${formatDeltaNum(dh)}px`);
|
|
242
|
+
return parts.length > 0 ? parts.join(", ") : "unchanged";
|
|
243
|
+
}
|
|
244
|
+
function isValidBBox(box) {
|
|
245
|
+
return (box !== null &&
|
|
246
|
+
typeof box === "object" &&
|
|
247
|
+
Number.isFinite(box.x) &&
|
|
248
|
+
Number.isFinite(box.y) &&
|
|
249
|
+
Number.isFinite(box.w) &&
|
|
250
|
+
Number.isFinite(box.h) &&
|
|
251
|
+
box.w >= 0 &&
|
|
252
|
+
box.h >= 0);
|
|
253
|
+
}
|
|
254
|
+
function buildAutoMatches(refRegions, candRegions) {
|
|
255
|
+
const matched = [];
|
|
256
|
+
const usedRef = new Set();
|
|
257
|
+
const usedCand = new Set();
|
|
258
|
+
const candById = new Map();
|
|
259
|
+
for (const c of candRegions) {
|
|
260
|
+
if (!candById.has(c.id))
|
|
261
|
+
candById.set(c.id, c);
|
|
262
|
+
}
|
|
263
|
+
// Prefer semantic ID matching when IDs are not generic auto-generated r-<n> labels.
|
|
264
|
+
for (const r of refRegions) {
|
|
265
|
+
if (GENERIC_REGION_ID_RE.test(r.id))
|
|
266
|
+
continue;
|
|
267
|
+
const c = candById.get(r.id);
|
|
268
|
+
if (!c || usedCand.has(c.id))
|
|
269
|
+
continue;
|
|
270
|
+
usedRef.add(r.id);
|
|
271
|
+
usedCand.add(c.id);
|
|
272
|
+
matched.push({ refId: r.id, candId: c.id, iou: bboxIoU(r.bbox, c.bbox) });
|
|
273
|
+
}
|
|
274
|
+
const remRef = refRegions.filter((r) => !usedRef.has(r.id));
|
|
275
|
+
const remCand = candRegions.filter((c) => !usedCand.has(c.id));
|
|
276
|
+
if (remRef.length > 0 && remCand.length > 0) {
|
|
277
|
+
const cmp = compareRegionsIoU(remRef, remCand);
|
|
278
|
+
matched.push(...cmp.matched);
|
|
279
|
+
}
|
|
280
|
+
return matched;
|
|
281
|
+
}
|
|
282
|
+
export function computeBBoxShiftVectors(refRegions, candRegions, matches) {
|
|
283
|
+
if (!Array.isArray(refRegions) || !Array.isArray(candRegions))
|
|
284
|
+
return [];
|
|
285
|
+
if (refRegions.length === 0 || candRegions.length === 0)
|
|
286
|
+
return [];
|
|
287
|
+
const refById = new Map();
|
|
288
|
+
for (const r of refRegions) {
|
|
289
|
+
if (refById.size >= MAX_BBOX_REGIONS)
|
|
290
|
+
break;
|
|
291
|
+
if (r && typeof r === "object" && typeof r.id === "string" && r.id.length > 0 && isValidBBox(r.bbox)) {
|
|
292
|
+
refById.set(r.id, r);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const candById = new Map();
|
|
296
|
+
for (const c of candRegions) {
|
|
297
|
+
if (candById.size >= MAX_BBOX_REGIONS)
|
|
298
|
+
break;
|
|
299
|
+
if (c && typeof c === "object" && typeof c.id === "string" && c.id.length > 0 && isValidBBox(c.bbox)) {
|
|
300
|
+
candById.set(c.id, c);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (refById.size === 0 || candById.size === 0)
|
|
304
|
+
return [];
|
|
305
|
+
const pairs = Array.isArray(matches) && matches.length > 0
|
|
306
|
+
? matches
|
|
307
|
+
: buildAutoMatches([...refById.values()], [...candById.values()]);
|
|
308
|
+
const vectors = [];
|
|
309
|
+
for (const pair of pairs) {
|
|
310
|
+
if (!pair || typeof pair !== "object" || typeof pair.refId !== "string" || typeof pair.candId !== "string") {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const ref = refById.get(pair.refId);
|
|
314
|
+
const cand = candById.get(pair.candId);
|
|
315
|
+
if (!ref || !cand)
|
|
316
|
+
continue;
|
|
317
|
+
const dx = round2(cand.bbox.x - ref.bbox.x);
|
|
318
|
+
const dy = round2(cand.bbox.y - ref.bbox.y);
|
|
319
|
+
const dw = round2(cand.bbox.w - ref.bbox.w);
|
|
320
|
+
const dh = round2(cand.bbox.h - ref.bbox.h);
|
|
321
|
+
const magnitudePx = round2(Math.hypot(dx, dy));
|
|
322
|
+
const rawIou = typeof pair.iou === "number" && Number.isFinite(pair.iou) ? pair.iou : bboxIoU(ref.bbox, cand.bbox);
|
|
323
|
+
const iou = round4(Math.max(0, Math.min(1, Number.isFinite(rawIou) ? rawIou : 0)));
|
|
324
|
+
const direction = formatShiftDirection(dx, dy, dw, dh);
|
|
325
|
+
vectors.push({
|
|
326
|
+
refId: ref.id,
|
|
327
|
+
candId: cand.id,
|
|
328
|
+
dx,
|
|
329
|
+
dy,
|
|
330
|
+
dw,
|
|
331
|
+
dh,
|
|
332
|
+
magnitudePx,
|
|
333
|
+
iou,
|
|
334
|
+
direction
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
vectors.sort((a, b) => {
|
|
338
|
+
if (b.magnitudePx !== a.magnitudePx)
|
|
339
|
+
return b.magnitudePx - a.magnitudePx;
|
|
340
|
+
const sizeDeltaDiff = Math.abs(b.dw) + Math.abs(b.dh) - (Math.abs(a.dw) + Math.abs(a.dh));
|
|
341
|
+
if (sizeDeltaDiff !== 0)
|
|
342
|
+
return sizeDeltaDiff;
|
|
343
|
+
return a.iou - b.iou;
|
|
344
|
+
});
|
|
345
|
+
return vectors;
|
|
346
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency, bounded, holdout-opaque verification trend & hotspot ledger
|
|
3
|
+
* persisted at `.vibecode/trends.ndjson`.
|
|
4
|
+
*/
|
|
5
|
+
import type { GateStatus, InvariantStatus, ParityReport } from "../core/types.js";
|
|
6
|
+
export declare const TRENDS_FILE = ".vibecode/trends.ndjson";
|
|
7
|
+
export declare const MAX_TREND_ENTRIES = 200;
|
|
8
|
+
export declare const MAX_TRENDS_FILE_BYTES: number;
|
|
9
|
+
export declare const DEFAULT_TREND_WINDOW = 20;
|
|
10
|
+
export declare const DEFAULT_MAX_TREND_BRIEF_CHARS = 1500;
|
|
11
|
+
export type TrendInvariantSample = {
|
|
12
|
+
id: string;
|
|
13
|
+
status: InvariantStatus;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
};
|
|
16
|
+
export type TrendEntry = {
|
|
17
|
+
timestamp: string;
|
|
18
|
+
gitSha?: string;
|
|
19
|
+
gateStatus: GateStatus;
|
|
20
|
+
compositeScore: number;
|
|
21
|
+
hardPassed: number;
|
|
22
|
+
hardTotal: number;
|
|
23
|
+
hardParity: number;
|
|
24
|
+
softPassed: number;
|
|
25
|
+
softTotal: number;
|
|
26
|
+
totalDurationMs: number;
|
|
27
|
+
holdoutCount: number;
|
|
28
|
+
mode?: string;
|
|
29
|
+
affected?: boolean;
|
|
30
|
+
visibleInvariants: TrendInvariantSample[];
|
|
31
|
+
};
|
|
32
|
+
export type HotspotEntry = {
|
|
33
|
+
id: string;
|
|
34
|
+
runs: number;
|
|
35
|
+
failures: number;
|
|
36
|
+
failRate: number;
|
|
37
|
+
flips: number;
|
|
38
|
+
lastStatus: InvariantStatus;
|
|
39
|
+
avgDurationMs: number;
|
|
40
|
+
};
|
|
41
|
+
export type LatencyDriftSummary = {
|
|
42
|
+
regressed: boolean;
|
|
43
|
+
baselineMedianMs: number;
|
|
44
|
+
recentMedianMs: number;
|
|
45
|
+
ratio: number;
|
|
46
|
+
deltaMs: number;
|
|
47
|
+
slowestInvariants: Array<{
|
|
48
|
+
id: string;
|
|
49
|
+
baselineMedianMs: number;
|
|
50
|
+
recentMedianMs: number;
|
|
51
|
+
ratio: number;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
export type TrendDirection = "improving" | "stable" | "regressing" | "insufficient_data";
|
|
55
|
+
export type TrendReport = {
|
|
56
|
+
runCount: number;
|
|
57
|
+
windowSize: number;
|
|
58
|
+
direction: TrendDirection;
|
|
59
|
+
passRate: number;
|
|
60
|
+
streak: {
|
|
61
|
+
status: "pass" | "fail" | "none";
|
|
62
|
+
count: number;
|
|
63
|
+
};
|
|
64
|
+
latest?: TrendEntry;
|
|
65
|
+
scoreDeltaLast: number;
|
|
66
|
+
scoreDeltaWindow: number;
|
|
67
|
+
scoreSparkline: string;
|
|
68
|
+
durationSparkline: string;
|
|
69
|
+
latencyDrift: LatencyDriftSummary;
|
|
70
|
+
hotspots: HotspotEntry[];
|
|
71
|
+
summaryBrief: string;
|
|
72
|
+
};
|
|
73
|
+
export type RecordTrendOptions = {
|
|
74
|
+
gitSha?: string;
|
|
75
|
+
mode?: string;
|
|
76
|
+
affected?: boolean;
|
|
77
|
+
maxEntries?: number;
|
|
78
|
+
totalDurationMs?: number;
|
|
79
|
+
};
|
|
80
|
+
export type AnalyzeTrendsOptions = {
|
|
81
|
+
window?: number;
|
|
82
|
+
maxHotspots?: number;
|
|
83
|
+
maxBriefChars?: number;
|
|
84
|
+
};
|
|
85
|
+
export type FormatPrettyTrendsOptions = {
|
|
86
|
+
color?: boolean;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Maps finite numeric values deterministically to 8-level Unicode sparkline blocks (`▁▂▃▄▅▆▇█`).
|
|
90
|
+
*/
|
|
91
|
+
export declare function renderSparkline(values: readonly number[], options?: {
|
|
92
|
+
min?: number;
|
|
93
|
+
max?: number;
|
|
94
|
+
}): string;
|
|
95
|
+
/**
|
|
96
|
+
* Extracts a compact, sanitized, holdout-opaque `TrendEntry` from a `ParityReport`.
|
|
97
|
+
*/
|
|
98
|
+
export declare function buildTrendEntry(report: ParityReport, options?: RecordTrendOptions): TrendEntry;
|
|
99
|
+
/**
|
|
100
|
+
* Reads chronological trend entries from `.vibecode/trends.ndjson`.
|
|
101
|
+
* Rejects symlink escapes, vault paths, and oversized files (> 4 MiB) with `VibecodeError("CONFIG_INVALID")`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function readTrendEntries(cwd: string, options?: {
|
|
104
|
+
limit?: number;
|
|
105
|
+
}): TrendEntry[];
|
|
106
|
+
/**
|
|
107
|
+
* Appends a sanitized, holdout-opaque trend entry to `.vibecode/trends.ndjson`
|
|
108
|
+
* with bounded rotation and atomic `.tmp` + `renameSync` persistence.
|
|
109
|
+
*/
|
|
110
|
+
export declare function appendTrendEntry(cwd: string, report: ParityReport, options?: RecordTrendOptions): {
|
|
111
|
+
path: string;
|
|
112
|
+
entry: TrendEntry;
|
|
113
|
+
totalEntries: number;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Analyzes chronological verification trend entries over a bounded sliding window.
|
|
117
|
+
*/
|
|
118
|
+
export declare function analyzeTrends(entries: readonly TrendEntry[], options?: AnalyzeTrendsOptions): TrendReport;
|
|
119
|
+
/**
|
|
120
|
+
* Formats a `TrendReport` as a clean terminal dashboard with optional ANSI coloring.
|
|
121
|
+
*/
|
|
122
|
+
export declare function formatPrettyTrends(report: TrendReport, options?: FormatPrettyTrendsOptions): string;
|