@blazediff/agent 0.3.0 → 0.5.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 +37 -23
- package/SKILL.md +13 -12
- package/dist/cli.js +2977 -1709
- package/dist/index.d.mts +133 -30
- package/dist/index.d.ts +133 -30
- package/dist/index.js +1322 -606
- package/dist/index.mjs +1319 -608
- package/dist/review/client/assets/index-5OALw55C.js +47 -0
- package/dist/review/client/assets/index-CQM1Tg8y.css +1 -0
- package/dist/review/client/index.html +16 -0
- package/package.json +21 -4
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var coreNative = require('@blazediff/core-native');
|
|
|
13
13
|
var util = require('util');
|
|
14
14
|
var langgraph = require('@langchain/langgraph');
|
|
15
15
|
var sharp = require('sharp');
|
|
16
|
+
var pc = require('picocolors');
|
|
16
17
|
var langgraphCheckpoint = require('@langchain/langgraph-checkpoint');
|
|
17
18
|
|
|
18
19
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -39,6 +40,7 @@ function _interopNamespace(e) {
|
|
|
39
40
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
40
41
|
var util__namespace = /*#__PURE__*/_interopNamespace(util);
|
|
41
42
|
var sharp__default = /*#__PURE__*/_interopDefault(sharp);
|
|
43
|
+
var pc__default = /*#__PURE__*/_interopDefault(pc);
|
|
42
44
|
|
|
43
45
|
// src/browser/capture.ts
|
|
44
46
|
var DEFAULT_VIEWPORT = { width: 1280, height: 800 };
|
|
@@ -47,12 +49,15 @@ var DEFAULT_FULL_PAGE = true;
|
|
|
47
49
|
var DEFAULT_THRESHOLD = 0.1;
|
|
48
50
|
var MIN_AUTO_CONCURRENCY = 2;
|
|
49
51
|
var MAX_AUTO_CONCURRENCY = 8;
|
|
50
|
-
function
|
|
52
|
+
function cpuCores() {
|
|
51
53
|
const cores = typeof os.availableParallelism === "function" ? os.availableParallelism() : os.cpus().length;
|
|
52
54
|
if (!cores || !Number.isFinite(cores)) return MIN_AUTO_CONCURRENCY;
|
|
55
|
+
return cores;
|
|
56
|
+
}
|
|
57
|
+
function defaultConcurrency() {
|
|
53
58
|
return Math.max(
|
|
54
59
|
MIN_AUTO_CONCURRENCY,
|
|
55
|
-
Math.min(MAX_AUTO_CONCURRENCY,
|
|
60
|
+
Math.min(MAX_AUTO_CONCURRENCY, cpuCores() - 1)
|
|
56
61
|
);
|
|
57
62
|
}
|
|
58
63
|
var BLAZEDIFF_DIR = ".blazediff";
|
|
@@ -63,12 +68,11 @@ var paths = (cwd = process.cwd()) => {
|
|
|
63
68
|
config: path__default.default.join(root, "config.json"),
|
|
64
69
|
manifest: path__default.default.join(root, "manifest.json"),
|
|
65
70
|
harnesses: path__default.default.join(root, "harnesses"),
|
|
66
|
-
authHarness: path__default.default.join(root, "harnesses", "auth.js"),
|
|
67
71
|
baselines: path__default.default.join(root, "baselines"),
|
|
68
72
|
actual: path__default.default.join(root, "actual"),
|
|
69
73
|
judgments: path__default.default.join(root, "judgments"),
|
|
70
74
|
checkpoints: path__default.default.join(root, "checkpoints"),
|
|
71
|
-
|
|
75
|
+
report: path__default.default.join(root, "report.json"),
|
|
72
76
|
gitignore: path__default.default.join(root, ".gitignore"),
|
|
73
77
|
serverLog: path__default.default.join(root, "dev-server.log"),
|
|
74
78
|
serverPid: path__default.default.join(root, "dev-server.pid")
|
|
@@ -97,7 +101,7 @@ async function loadHarness(harnessFile) {
|
|
|
97
101
|
const absolute = path__default.default.isAbsolute(harnessFile) ? harnessFile : path__default.default.resolve(process.cwd(), harnessFile);
|
|
98
102
|
if (!fs.existsSync(absolute)) {
|
|
99
103
|
throw new HarnessError(
|
|
100
|
-
`harness not found at ${absolute}. Author one under .blazediff/harnesses/ (or run \`blazediff-agent
|
|
104
|
+
`harness not found at ${absolute}. Author one under .blazediff/harnesses/ (or run \`blazediff-agent harness record <name>\` to record one).`
|
|
101
105
|
);
|
|
102
106
|
}
|
|
103
107
|
const cached = moduleCache.get(absolute);
|
|
@@ -106,7 +110,10 @@ async function loadHarness(harnessFile) {
|
|
|
106
110
|
const loading = (async () => {
|
|
107
111
|
let mod;
|
|
108
112
|
try {
|
|
109
|
-
mod = await import(
|
|
113
|
+
mod = await import(
|
|
114
|
+
/* @vite-ignore */
|
|
115
|
+
url$1
|
|
116
|
+
);
|
|
110
117
|
} catch (err) {
|
|
111
118
|
throw new HarnessError(
|
|
112
119
|
`failed to load harness at ${absolute}: ${err.message}`,
|
|
@@ -117,7 +124,7 @@ async function loadHarness(harnessFile) {
|
|
|
117
124
|
if (!harness || typeof harness.run !== "function") {
|
|
118
125
|
if (typeof mod.login === "function") {
|
|
119
126
|
throw new HarnessError(
|
|
120
|
-
`legacy auth harness detected at ${absolute} (exports \`login\`). Re-run \`blazediff-agent auth
|
|
127
|
+
`legacy auth harness detected at ${absolute} (exports \`login\`). Re-run \`blazediff-agent harness record auth --login\` to regenerate it as a harness.`
|
|
121
128
|
);
|
|
122
129
|
}
|
|
123
130
|
throw new HarnessError(
|
|
@@ -186,7 +193,13 @@ var contextPool = /* @__PURE__ */ new Map();
|
|
|
186
193
|
async function getBrowser() {
|
|
187
194
|
if (cachedBrowser?.isConnected()) return cachedBrowser;
|
|
188
195
|
if (launchInFlight) return launchInFlight;
|
|
189
|
-
launchInFlight = playwright.chromium.launch({
|
|
196
|
+
launchInFlight = playwright.chromium.launch({
|
|
197
|
+
headless: true,
|
|
198
|
+
args: CHROMIUM_FLAGS,
|
|
199
|
+
handleSIGINT: false,
|
|
200
|
+
handleSIGTERM: false,
|
|
201
|
+
handleSIGHUP: false
|
|
202
|
+
}).then((b) => {
|
|
190
203
|
cachedBrowser = b;
|
|
191
204
|
return b;
|
|
192
205
|
}).finally(() => {
|
|
@@ -500,32 +513,31 @@ function resolveBaseUrl(config, override) {
|
|
|
500
513
|
if (override) return override;
|
|
501
514
|
if (config?.baseUrl) return config.baseUrl;
|
|
502
515
|
if (config?.devServer) return `http://127.0.0.1:${config.devServer.port}`;
|
|
503
|
-
throw new Error(
|
|
516
|
+
throw new Error(
|
|
517
|
+
"no baseUrl: pass --base-url or run `blazediff-agent onboard`"
|
|
518
|
+
);
|
|
504
519
|
}
|
|
505
520
|
|
|
506
521
|
// src/graph/semaphore.ts
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
if (
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
async run(fn) {
|
|
516
|
-
if (this.current >= this.limit) {
|
|
517
|
-
await new Promise((resolve) => this.queue.push(resolve));
|
|
522
|
+
function createSemaphore(limit) {
|
|
523
|
+
if (limit < 1) throw new Error(`semaphore limit must be >= 1 (got ${limit})`);
|
|
524
|
+
let current = 0;
|
|
525
|
+
const queue = [];
|
|
526
|
+
async function run(fn) {
|
|
527
|
+
if (current >= limit) {
|
|
528
|
+
await new Promise((resolve) => queue.push(resolve));
|
|
518
529
|
}
|
|
519
|
-
|
|
530
|
+
current++;
|
|
520
531
|
try {
|
|
521
532
|
return await fn();
|
|
522
533
|
} finally {
|
|
523
|
-
|
|
524
|
-
const next =
|
|
534
|
+
current--;
|
|
535
|
+
const next = queue.shift();
|
|
525
536
|
if (next) next();
|
|
526
537
|
}
|
|
527
538
|
}
|
|
528
|
-
};
|
|
539
|
+
return { run };
|
|
540
|
+
}
|
|
529
541
|
|
|
530
542
|
// src/types.ts
|
|
531
543
|
var STABILITY_HOOKS_VERSION = 1;
|
|
@@ -682,7 +694,10 @@ async function runCaptures(opts) {
|
|
|
682
694
|
let manifest = writeManifest ? await loadOrCreateManifest(cwd, config) : null;
|
|
683
695
|
let manifestUpdates = 0;
|
|
684
696
|
const slot = new Array(valid.length);
|
|
685
|
-
const
|
|
697
|
+
const pendingUpdates = new Array(valid.length).fill(
|
|
698
|
+
null
|
|
699
|
+
);
|
|
700
|
+
const semaphore = createSemaphore(opts.concurrency ?? defaultConcurrency());
|
|
686
701
|
try {
|
|
687
702
|
await Promise.all(
|
|
688
703
|
valid.map(
|
|
@@ -723,28 +738,19 @@ async function runCaptures(opts) {
|
|
|
723
738
|
fullPage: r.fullPage,
|
|
724
739
|
harnesses: refs.length > 0 ? refs : void 0
|
|
725
740
|
};
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
manifest,
|
|
732
|
-
makeEntry({ id: r.id, ...shared })
|
|
733
|
-
);
|
|
734
|
-
manifestUpdates += 1;
|
|
735
|
-
for (const sub of shot.subCaptures ?? []) {
|
|
736
|
-
manifest = addOrReplaceEntry(
|
|
737
|
-
manifest,
|
|
738
|
-
makeEntry({
|
|
741
|
+
pendingUpdates[i] = {
|
|
742
|
+
baseId: r.id,
|
|
743
|
+
baseEntry: makeEntry({ id: r.id, ...shared }),
|
|
744
|
+
derivedEntries: (shot.subCaptures ?? []).map(
|
|
745
|
+
(sub) => makeEntry({
|
|
739
746
|
id: `${r.id}__${sub.name}`,
|
|
740
747
|
...shared,
|
|
741
748
|
parent: r.id,
|
|
742
749
|
derived: true,
|
|
743
750
|
subName: sub.name
|
|
744
751
|
})
|
|
745
|
-
)
|
|
746
|
-
|
|
747
|
-
}
|
|
752
|
+
)
|
|
753
|
+
};
|
|
748
754
|
}
|
|
749
755
|
} catch (err) {
|
|
750
756
|
slot[i] = {
|
|
@@ -759,7 +765,22 @@ async function runCaptures(opts) {
|
|
|
759
765
|
)
|
|
760
766
|
);
|
|
761
767
|
for (const r of slot) results.push(r);
|
|
762
|
-
if (manifest
|
|
768
|
+
if (manifest) {
|
|
769
|
+
for (const update of pendingUpdates) {
|
|
770
|
+
if (!update) continue;
|
|
771
|
+
manifest = {
|
|
772
|
+
...manifest,
|
|
773
|
+
entries: manifest.entries.filter((e) => e.parent !== update.baseId)
|
|
774
|
+
};
|
|
775
|
+
manifest = addOrReplaceEntry(manifest, update.baseEntry);
|
|
776
|
+
manifestUpdates += 1;
|
|
777
|
+
for (const derived of update.derivedEntries) {
|
|
778
|
+
manifest = addOrReplaceEntry(manifest, derived);
|
|
779
|
+
manifestUpdates += 1;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (manifestUpdates > 0) await saveManifest(manifest, cwd);
|
|
783
|
+
}
|
|
763
784
|
} finally {
|
|
764
785
|
await closeBrowser();
|
|
765
786
|
}
|
|
@@ -802,7 +823,7 @@ async function diffEntry(id, baselinePath, actualPath, opts = {}, cwd = process.
|
|
|
802
823
|
}
|
|
803
824
|
const threshold = opts.threshold ?? DEFAULT_THRESHOLD;
|
|
804
825
|
const antialiasing = opts.antialiasing ?? true;
|
|
805
|
-
const result = await coreNative.compare(baselinePath, actualPath,
|
|
826
|
+
const result = await coreNative.compare(baselinePath, actualPath, void 0, {
|
|
806
827
|
threshold,
|
|
807
828
|
antialiasing,
|
|
808
829
|
interpret: true
|
|
@@ -827,6 +848,13 @@ async function diffEntry(id, baselinePath, actualPath, opts = {}, cwd = process.
|
|
|
827
848
|
reason: "layout-diff"
|
|
828
849
|
};
|
|
829
850
|
}
|
|
851
|
+
if (diffPath) {
|
|
852
|
+
await coreNative.compare(baselinePath, actualPath, diffPath, {
|
|
853
|
+
threshold,
|
|
854
|
+
antialiasing,
|
|
855
|
+
compression: 9
|
|
856
|
+
});
|
|
857
|
+
}
|
|
830
858
|
return {
|
|
831
859
|
id,
|
|
832
860
|
baselinePath,
|
|
@@ -850,9 +878,9 @@ function extractInternalLinks(base, target, hrefs) {
|
|
|
850
878
|
try {
|
|
851
879
|
const u = new URL(href, target);
|
|
852
880
|
if (u.origin !== base.origin) continue;
|
|
853
|
-
const
|
|
854
|
-
if (
|
|
855
|
-
out.push(
|
|
881
|
+
const path23 = u.pathname + u.search;
|
|
882
|
+
if (path23.startsWith("/api/")) continue;
|
|
883
|
+
out.push(path23);
|
|
856
884
|
} catch {
|
|
857
885
|
}
|
|
858
886
|
}
|
|
@@ -906,15 +934,24 @@ async function crawlRoutes(opts) {
|
|
|
906
934
|
}
|
|
907
935
|
return discovered.slice(0, maxRoutes);
|
|
908
936
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
937
|
+
async function fileExists2(p) {
|
|
938
|
+
try {
|
|
939
|
+
await promises.access(p);
|
|
940
|
+
return true;
|
|
941
|
+
} catch {
|
|
942
|
+
return false;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
async function readJsonOrNull(file) {
|
|
912
946
|
try {
|
|
913
947
|
return JSON.parse(await promises.readFile(file, "utf8"));
|
|
914
948
|
} catch {
|
|
915
949
|
return null;
|
|
916
950
|
}
|
|
917
951
|
}
|
|
952
|
+
|
|
953
|
+
// src/discover/next.ts
|
|
954
|
+
var DYNAMIC_SEGMENT = /\[[^\]]+\]/;
|
|
918
955
|
function isPublicRoute(route) {
|
|
919
956
|
if (DYNAMIC_SEGMENT.test(route)) return false;
|
|
920
957
|
if (route === "/api" || route.startsWith("/api/")) return false;
|
|
@@ -930,13 +967,13 @@ async function discoverFromNextManifest(cwd = process.cwd()) {
|
|
|
930
967
|
seen.add(url);
|
|
931
968
|
out.push({ url, source: "next-manifest" });
|
|
932
969
|
};
|
|
933
|
-
const routes = await
|
|
970
|
+
const routes = await readJsonOrNull(
|
|
934
971
|
path__default.default.join(nextDir, "routes-manifest.json")
|
|
935
972
|
);
|
|
936
973
|
for (const r of routes?.staticRoutes ?? []) {
|
|
937
974
|
if (isPublicRoute(r.page)) add(r.page);
|
|
938
975
|
}
|
|
939
|
-
const appPaths = await
|
|
976
|
+
const appPaths = await readJsonOrNull(
|
|
940
977
|
path__default.default.join(nextDir, "server", "app-paths-manifest.json")
|
|
941
978
|
);
|
|
942
979
|
for (const route of Object.keys(appPaths ?? {})) {
|
|
@@ -1049,14 +1086,19 @@ var ENTRIES = [
|
|
|
1049
1086
|
"actual/",
|
|
1050
1087
|
"judgments/",
|
|
1051
1088
|
"checkpoints/",
|
|
1052
|
-
"
|
|
1089
|
+
"report.json",
|
|
1053
1090
|
"dev-server.log",
|
|
1054
1091
|
"dev-server.pid",
|
|
1055
1092
|
".env",
|
|
1056
1093
|
".env.local",
|
|
1057
1094
|
"*.tmp"
|
|
1058
1095
|
];
|
|
1059
|
-
var STALE_ENTRIES = /* @__PURE__ */ new Set([
|
|
1096
|
+
var STALE_ENTRIES = /* @__PURE__ */ new Set([
|
|
1097
|
+
"diffs/",
|
|
1098
|
+
"pending-judgments/",
|
|
1099
|
+
"summary.html",
|
|
1100
|
+
"summary.md"
|
|
1101
|
+
]);
|
|
1060
1102
|
var HEADER = "# blazediff: generated artifacts (committed: config.json, manifest.json, baselines/, harnesses/)\n";
|
|
1061
1103
|
async function ensureGitignore(cwd) {
|
|
1062
1104
|
const file = paths(cwd).gitignore;
|
|
@@ -1083,6 +1125,15 @@ ${missing.join("\n")}
|
|
|
1083
1125
|
await promises.writeFile(file, body, "utf8");
|
|
1084
1126
|
}
|
|
1085
1127
|
var DEFAULT_TOP_N = 5;
|
|
1128
|
+
var READ_PAD_X_FACTOR = 2.5;
|
|
1129
|
+
var READ_PAD_X_MIN = 48;
|
|
1130
|
+
var READ_PAD_X_MAX = 130;
|
|
1131
|
+
var READ_PAD_Y_FACTOR = 0.6;
|
|
1132
|
+
var READ_PAD_Y_MIN = 4;
|
|
1133
|
+
var READ_PAD_Y_MAX = 12;
|
|
1134
|
+
var READ_TARGET_WIDTH = 480;
|
|
1135
|
+
var READ_SCALE_MIN = 2;
|
|
1136
|
+
var READ_SCALE_MAX = 6;
|
|
1086
1137
|
var DEFAULT_PADDING = 16;
|
|
1087
1138
|
var DEFAULT_LOCATOR_MAX_WIDTH = 400;
|
|
1088
1139
|
var DEFAULT_GUTTER = 2;
|
|
@@ -1100,17 +1151,75 @@ function padAndClamp(bbox, padding, imgWidth, imgHeight) {
|
|
|
1100
1151
|
height: Math.max(1, bottom - top)
|
|
1101
1152
|
};
|
|
1102
1153
|
}
|
|
1154
|
+
var clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
1155
|
+
async function prepareRegionReads(opts) {
|
|
1156
|
+
const topN = opts.topN ?? DEFAULT_TOP_N;
|
|
1157
|
+
const meta = await sharp__default.default(opts.actualPath).metadata();
|
|
1158
|
+
const imgWidth = meta.width ?? 0;
|
|
1159
|
+
const imgHeight = meta.height ?? 0;
|
|
1160
|
+
if (!imgWidth || !imgHeight) {
|
|
1161
|
+
throw new Error(`unable to read image dimensions: ${opts.actualPath}`);
|
|
1162
|
+
}
|
|
1163
|
+
const ranked = [...opts.regions].sort((a, b) => b.pixelCount - a.pixelCount).slice(0, topN);
|
|
1164
|
+
return Promise.all(
|
|
1165
|
+
ranked.map(async (region, i) => {
|
|
1166
|
+
const padX = clamp(
|
|
1167
|
+
Math.round(region.bbox.width * READ_PAD_X_FACTOR),
|
|
1168
|
+
READ_PAD_X_MIN,
|
|
1169
|
+
READ_PAD_X_MAX
|
|
1170
|
+
);
|
|
1171
|
+
const padY = clamp(
|
|
1172
|
+
Math.round(region.bbox.height * READ_PAD_Y_FACTOR),
|
|
1173
|
+
READ_PAD_Y_MIN,
|
|
1174
|
+
READ_PAD_Y_MAX
|
|
1175
|
+
);
|
|
1176
|
+
const left = Math.max(0, Math.floor(region.bbox.x - padX));
|
|
1177
|
+
const top = Math.max(0, Math.floor(region.bbox.y - padY));
|
|
1178
|
+
const right = Math.min(
|
|
1179
|
+
imgWidth,
|
|
1180
|
+
Math.ceil(region.bbox.x + region.bbox.width + padX)
|
|
1181
|
+
);
|
|
1182
|
+
const bottom = Math.min(
|
|
1183
|
+
imgHeight,
|
|
1184
|
+
Math.ceil(region.bbox.y + region.bbox.height + padY)
|
|
1185
|
+
);
|
|
1186
|
+
const extract = {
|
|
1187
|
+
left,
|
|
1188
|
+
top,
|
|
1189
|
+
width: Math.max(1, right - left),
|
|
1190
|
+
height: Math.max(1, bottom - top)
|
|
1191
|
+
};
|
|
1192
|
+
const scale = clamp(
|
|
1193
|
+
Math.round(READ_TARGET_WIDTH / extract.width),
|
|
1194
|
+
READ_SCALE_MIN,
|
|
1195
|
+
READ_SCALE_MAX
|
|
1196
|
+
);
|
|
1197
|
+
const render = async (src, suffix) => {
|
|
1198
|
+
const name = `read-${i}.${suffix}.png`;
|
|
1199
|
+
await sharp__default.default(src).extract(extract).resize(extract.width * scale, extract.height * scale, {
|
|
1200
|
+
kernel: "lanczos3"
|
|
1201
|
+
}).png().toFile(path__default.default.join(opts.outputDir, name));
|
|
1202
|
+
return path__default.default.join(opts.outputDir, name);
|
|
1203
|
+
};
|
|
1204
|
+
const [beforePath, afterPath] = await Promise.all([
|
|
1205
|
+
render(opts.baselinePath, "before"),
|
|
1206
|
+
render(opts.actualPath, "after")
|
|
1207
|
+
]);
|
|
1208
|
+
return { changeType: region.changeType, beforePath, afterPath };
|
|
1209
|
+
})
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1103
1212
|
async function prepareTiles(opts) {
|
|
1104
1213
|
const topN = opts.topN ?? DEFAULT_TOP_N;
|
|
1105
1214
|
const padding = opts.padding ?? DEFAULT_PADDING;
|
|
1106
1215
|
const locatorMaxWidth = opts.locatorMaxWidth ?? DEFAULT_LOCATOR_MAX_WIDTH;
|
|
1107
1216
|
const gutter = opts.gutter ?? DEFAULT_GUTTER;
|
|
1108
1217
|
const rowGutter = opts.rowGutter ?? DEFAULT_ROW_GUTTER;
|
|
1109
|
-
const
|
|
1110
|
-
const imgWidth =
|
|
1111
|
-
const imgHeight =
|
|
1218
|
+
const meta = await sharp__default.default(opts.actualPath).metadata();
|
|
1219
|
+
const imgWidth = meta.width ?? 0;
|
|
1220
|
+
const imgHeight = meta.height ?? 0;
|
|
1112
1221
|
if (!imgWidth || !imgHeight) {
|
|
1113
|
-
throw new Error(`unable to read
|
|
1222
|
+
throw new Error(`unable to read image dimensions: ${opts.actualPath}`);
|
|
1114
1223
|
}
|
|
1115
1224
|
const ranked = [...opts.regions].sort((a, b) => b.pixelCount - a.pixelCount).slice(0, topN);
|
|
1116
1225
|
const regionData = await Promise.all(
|
|
@@ -1160,19 +1269,22 @@ async function prepareTiles(opts) {
|
|
|
1160
1269
|
}
|
|
1161
1270
|
}).composite(composites).png().toFile(path__default.default.join(opts.outputDir, tilesName));
|
|
1162
1271
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
const
|
|
1168
|
-
const
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1272
|
+
let locatorName;
|
|
1273
|
+
if (opts.diffPath) {
|
|
1274
|
+
const scale = locatorMaxWidth / Math.max(imgWidth, imgHeight);
|
|
1275
|
+
const locW = Math.max(1, Math.round(imgWidth * scale));
|
|
1276
|
+
const locH = Math.max(1, Math.round(imgHeight * scale));
|
|
1277
|
+
const rects = opts.regions.map((r) => {
|
|
1278
|
+
const x = Math.round(r.bbox.x * scale);
|
|
1279
|
+
const y = Math.round(r.bbox.y * scale);
|
|
1280
|
+
const w = Math.max(1, Math.round(r.bbox.width * scale));
|
|
1281
|
+
const h = Math.max(1, Math.round(r.bbox.height * scale));
|
|
1282
|
+
return `<rect x="${x}" y="${y}" width="${w}" height="${h}" fill="none" stroke="red" stroke-width="2" />`;
|
|
1283
|
+
}).join("");
|
|
1284
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${locW}" height="${locH}">${rects}</svg>`;
|
|
1285
|
+
locatorName = "locator.png";
|
|
1286
|
+
await sharp__default.default(opts.diffPath).resize(locW, locH, { fit: "fill" }).composite([{ input: Buffer.from(svg), left: 0, top: 0 }]).png().toFile(path__default.default.join(opts.outputDir, locatorName));
|
|
1287
|
+
}
|
|
1176
1288
|
return {
|
|
1177
1289
|
locatorPath: locatorName,
|
|
1178
1290
|
tilesPath: tilesName,
|
|
@@ -1183,9 +1295,9 @@ async function prepareTiles(opts) {
|
|
|
1183
1295
|
};
|
|
1184
1296
|
}
|
|
1185
1297
|
|
|
1186
|
-
// src/judge/host
|
|
1298
|
+
// src/judge/coding-agent-host.ts
|
|
1187
1299
|
async function tryPrepareTiles(input, entryDir) {
|
|
1188
|
-
if (!input.regions || input.regions.length === 0
|
|
1300
|
+
if (!input.regions || input.regions.length === 0) {
|
|
1189
1301
|
return null;
|
|
1190
1302
|
}
|
|
1191
1303
|
try {
|
|
@@ -1204,9 +1316,10 @@ async function tryPrepareTiles(input, entryDir) {
|
|
|
1204
1316
|
return null;
|
|
1205
1317
|
}
|
|
1206
1318
|
}
|
|
1207
|
-
var
|
|
1319
|
+
var codingAgentHostJudge = {
|
|
1208
1320
|
name: "host",
|
|
1209
1321
|
async judge(input, cwd) {
|
|
1322
|
+
input.onJudgingStart?.();
|
|
1210
1323
|
const p = paths(cwd);
|
|
1211
1324
|
const entryDir = path__default.default.join(p.judgments, input.entry.id);
|
|
1212
1325
|
await promises.mkdir(entryDir, { recursive: true });
|
|
@@ -1214,366 +1327,598 @@ var hostHarnessJudge = {
|
|
|
1214
1327
|
return { kind: "deferred", requestPath: entryDir };
|
|
1215
1328
|
}
|
|
1216
1329
|
};
|
|
1330
|
+
var dim = pc__default.default.dim;
|
|
1331
|
+
var bold = pc__default.default.bold;
|
|
1217
1332
|
|
|
1218
|
-
// src/judge/
|
|
1219
|
-
var
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1333
|
+
// src/judge/transformers.ts
|
|
1334
|
+
var toMb = (bytes) => (bytes / 1048576).toFixed(1);
|
|
1335
|
+
function createLoadProgress(label) {
|
|
1336
|
+
const interactive = Boolean(process.stderr.isTTY);
|
|
1337
|
+
const bytes = /* @__PURE__ */ new Map();
|
|
1338
|
+
let announced = false;
|
|
1339
|
+
let lastPct = -1;
|
|
1340
|
+
let lastBucket = -1;
|
|
1341
|
+
const totals = () => {
|
|
1342
|
+
let loaded = 0;
|
|
1343
|
+
let total = 0;
|
|
1344
|
+
for (const b of bytes.values()) {
|
|
1345
|
+
loaded += b.loaded;
|
|
1346
|
+
total += b.total;
|
|
1347
|
+
}
|
|
1348
|
+
const pct = total > 0 ? Math.min(100, Math.floor(loaded / total * 100)) : 0;
|
|
1349
|
+
return { loaded, total, pct };
|
|
1350
|
+
};
|
|
1351
|
+
return {
|
|
1352
|
+
onProgress(event) {
|
|
1353
|
+
if (!announced) {
|
|
1354
|
+
process.stderr.write(
|
|
1355
|
+
`${dim("[blazediff]")} loading ${bold(label)} model ${dim("(first run downloads weights)\u2026")}
|
|
1356
|
+
`
|
|
1357
|
+
);
|
|
1358
|
+
announced = true;
|
|
1359
|
+
}
|
|
1360
|
+
if (event.status !== "progress" || !event.file || typeof event.total !== "number")
|
|
1361
|
+
return;
|
|
1362
|
+
bytes.set(event.file, { loaded: event.loaded ?? 0, total: event.total });
|
|
1363
|
+
const { loaded, total, pct } = totals();
|
|
1364
|
+
if (pct === lastPct) return;
|
|
1365
|
+
lastPct = pct;
|
|
1366
|
+
const line = ` ${label}: ${pct}% ${dim(`(${toMb(loaded)}/${toMb(total)} MB)`)}`;
|
|
1367
|
+
if (interactive) {
|
|
1368
|
+
process.stderr.write(`\r${line}\x1B[K`);
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
const bucket = Math.floor(pct / 25);
|
|
1372
|
+
if (bucket > lastBucket) {
|
|
1373
|
+
lastBucket = bucket;
|
|
1374
|
+
process.stderr.write(`${line}
|
|
1375
|
+
`);
|
|
1376
|
+
}
|
|
1377
|
+
},
|
|
1378
|
+
done() {
|
|
1379
|
+
if (!announced) return;
|
|
1380
|
+
if (interactive) {
|
|
1381
|
+
const { total } = totals();
|
|
1382
|
+
const size = total > 0 ? dim(` (${toMb(total)} MB)`) : "";
|
|
1383
|
+
process.stderr.write(
|
|
1384
|
+
`\r ${label}: ${pc__default.default.green("ready")}${size}\x1B[K
|
|
1385
|
+
`
|
|
1386
|
+
);
|
|
1387
|
+
} else if (lastPct < 100) {
|
|
1388
|
+
process.stderr.write(` ${label}: ${pc__default.default.green("ready")}
|
|
1389
|
+
`);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1234
1393
|
}
|
|
1235
|
-
async function
|
|
1394
|
+
async function loadTransformers() {
|
|
1236
1395
|
try {
|
|
1237
|
-
|
|
1238
|
-
return JSON.parse(raw);
|
|
1396
|
+
return await import('@huggingface/transformers');
|
|
1239
1397
|
} catch (err) {
|
|
1240
|
-
|
|
1241
|
-
|
|
1398
|
+
throw new Error(
|
|
1399
|
+
'stack=local requires the optional peer dependency "@huggingface/transformers". Install it with `npm i @huggingface/transformers` (or pnpm/bun add).',
|
|
1400
|
+
{ cause: err instanceof Error ? err : void 0 }
|
|
1401
|
+
);
|
|
1242
1402
|
}
|
|
1243
1403
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1404
|
+
|
|
1405
|
+
// src/judge/classifier.ts
|
|
1406
|
+
var MODEL_ID = "onnx-community/Qwen3.5-0.8B-ONNX";
|
|
1407
|
+
var MAX_NEW_TOKENS = 64;
|
|
1408
|
+
async function defaultFactory() {
|
|
1409
|
+
const mod = await loadTransformers();
|
|
1410
|
+
const progress = createLoadProgress("classifier");
|
|
1411
|
+
const progress_callback = progress.onProgress;
|
|
1412
|
+
const [tokenizer, model] = await Promise.all([
|
|
1413
|
+
mod.AutoTokenizer.from_pretrained(MODEL_ID, { progress_callback }),
|
|
1414
|
+
mod.Qwen3_5ForConditionalGeneration.from_pretrained(MODEL_ID, {
|
|
1415
|
+
dtype: {
|
|
1416
|
+
embed_tokens: "fp32",
|
|
1417
|
+
vision_encoder: "q8",
|
|
1418
|
+
decoder_model_merged: "q4"
|
|
1419
|
+
},
|
|
1420
|
+
device: "cpu",
|
|
1421
|
+
progress_callback
|
|
1422
|
+
})
|
|
1423
|
+
]);
|
|
1424
|
+
progress.done();
|
|
1425
|
+
return {
|
|
1426
|
+
async complete(prompt) {
|
|
1427
|
+
const inputs = tokenizer.apply_chat_template(
|
|
1428
|
+
[{ role: "user", content: prompt }],
|
|
1429
|
+
{
|
|
1430
|
+
add_generation_prompt: true,
|
|
1431
|
+
return_dict: true,
|
|
1432
|
+
enable_thinking: false
|
|
1433
|
+
}
|
|
1434
|
+
);
|
|
1435
|
+
const output = await model.generate({
|
|
1436
|
+
...inputs,
|
|
1437
|
+
do_sample: false,
|
|
1438
|
+
max_new_tokens: MAX_NEW_TOKENS
|
|
1439
|
+
});
|
|
1440
|
+
const promptLen = inputs.input_ids.dims.at(-1);
|
|
1441
|
+
const generated = output.slice(null, [promptLen, null]);
|
|
1442
|
+
const decoded = tokenizer.batch_decode(generated, {
|
|
1443
|
+
skip_special_tokens: true
|
|
1444
|
+
});
|
|
1445
|
+
const raw = Array.isArray(decoded) ? String(decoded[0] ?? "") : String(decoded);
|
|
1446
|
+
return raw.trim();
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1248
1449
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
threadDir(thread) {
|
|
1256
|
-
return path__default.default.join(this.root, thread);
|
|
1257
|
-
}
|
|
1258
|
-
nsPath(thread, ns) {
|
|
1259
|
-
return path__default.default.join(this.threadDir(thread), nsDir(ns));
|
|
1260
|
-
}
|
|
1261
|
-
ckptFile(thread, ns, id) {
|
|
1262
|
-
return path__default.default.join(this.nsPath(thread, ns), `${id}.ckpt.json`);
|
|
1263
|
-
}
|
|
1264
|
-
writesFile(thread, ns, id) {
|
|
1265
|
-
return path__default.default.join(this.nsPath(thread, ns), `${id}.writes.json`);
|
|
1266
|
-
}
|
|
1267
|
-
async withLock(key, fn) {
|
|
1268
|
-
const prev = this.locks.get(key) ?? Promise.resolve();
|
|
1269
|
-
const next = prev.then(fn, fn);
|
|
1270
|
-
this.locks.set(key, next);
|
|
1271
|
-
try {
|
|
1272
|
-
return await next;
|
|
1273
|
-
} finally {
|
|
1274
|
-
if (this.locks.get(key) === next) this.locks.delete(key);
|
|
1450
|
+
function createClassifierRunnerHolder(factory = defaultFactory) {
|
|
1451
|
+
let runnerPromise;
|
|
1452
|
+
return {
|
|
1453
|
+
get() {
|
|
1454
|
+
if (!runnerPromise) runnerPromise = factory();
|
|
1455
|
+
return runnerPromise;
|
|
1275
1456
|
}
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
// src/judge/region-diff.ts
|
|
1461
|
+
var FILLER = /* @__PURE__ */ new Set([
|
|
1462
|
+
"the",
|
|
1463
|
+
"a",
|
|
1464
|
+
"an",
|
|
1465
|
+
"is",
|
|
1466
|
+
"are",
|
|
1467
|
+
"was",
|
|
1468
|
+
"were",
|
|
1469
|
+
"be",
|
|
1470
|
+
"this",
|
|
1471
|
+
"that",
|
|
1472
|
+
"these",
|
|
1473
|
+
"those",
|
|
1474
|
+
"it",
|
|
1475
|
+
"its",
|
|
1476
|
+
"there",
|
|
1477
|
+
"here",
|
|
1478
|
+
"and",
|
|
1479
|
+
"or",
|
|
1480
|
+
"but",
|
|
1481
|
+
"of",
|
|
1482
|
+
"in",
|
|
1483
|
+
"on",
|
|
1484
|
+
"at",
|
|
1485
|
+
"to",
|
|
1486
|
+
"with",
|
|
1487
|
+
"within",
|
|
1488
|
+
"against",
|
|
1489
|
+
"around",
|
|
1490
|
+
"surrounding",
|
|
1491
|
+
"into",
|
|
1492
|
+
"from",
|
|
1493
|
+
"by",
|
|
1494
|
+
"for",
|
|
1495
|
+
"as",
|
|
1496
|
+
"no",
|
|
1497
|
+
"not",
|
|
1498
|
+
"other",
|
|
1499
|
+
"some",
|
|
1500
|
+
"also",
|
|
1501
|
+
"another",
|
|
1502
|
+
"word",
|
|
1503
|
+
"words",
|
|
1504
|
+
"text",
|
|
1505
|
+
"letter",
|
|
1506
|
+
"letters",
|
|
1507
|
+
"character",
|
|
1508
|
+
"characters",
|
|
1509
|
+
"number",
|
|
1510
|
+
"numbers",
|
|
1511
|
+
"digit",
|
|
1512
|
+
"digits",
|
|
1513
|
+
"phrase",
|
|
1514
|
+
"label",
|
|
1515
|
+
"title",
|
|
1516
|
+
"written",
|
|
1517
|
+
"writes",
|
|
1518
|
+
"reads",
|
|
1519
|
+
"read",
|
|
1520
|
+
"says",
|
|
1521
|
+
"displayed",
|
|
1522
|
+
"displays",
|
|
1523
|
+
"display",
|
|
1524
|
+
"shows",
|
|
1525
|
+
"show",
|
|
1526
|
+
"showing",
|
|
1527
|
+
"shown",
|
|
1528
|
+
"appears",
|
|
1529
|
+
"appear",
|
|
1530
|
+
"reading",
|
|
1531
|
+
"prominently",
|
|
1532
|
+
"visible",
|
|
1533
|
+
"positioned",
|
|
1534
|
+
"located",
|
|
1535
|
+
"white",
|
|
1536
|
+
"black",
|
|
1537
|
+
"blue",
|
|
1538
|
+
"red",
|
|
1539
|
+
"green",
|
|
1540
|
+
"purple",
|
|
1541
|
+
"gray",
|
|
1542
|
+
"grey",
|
|
1543
|
+
"background",
|
|
1544
|
+
"foreground",
|
|
1545
|
+
"color",
|
|
1546
|
+
"colors",
|
|
1547
|
+
"colored",
|
|
1548
|
+
"colour",
|
|
1549
|
+
"font",
|
|
1550
|
+
"style",
|
|
1551
|
+
"styled",
|
|
1552
|
+
"bold",
|
|
1553
|
+
"italic",
|
|
1554
|
+
"blurred",
|
|
1555
|
+
"slightly",
|
|
1556
|
+
"image",
|
|
1557
|
+
"photo",
|
|
1558
|
+
"picture",
|
|
1559
|
+
"frame",
|
|
1560
|
+
"scene",
|
|
1561
|
+
"object",
|
|
1562
|
+
"objects",
|
|
1563
|
+
"element",
|
|
1564
|
+
"elements",
|
|
1565
|
+
"ui",
|
|
1566
|
+
"screen",
|
|
1567
|
+
"page",
|
|
1568
|
+
"logo",
|
|
1569
|
+
"icon",
|
|
1570
|
+
"button",
|
|
1571
|
+
"large",
|
|
1572
|
+
"small",
|
|
1573
|
+
"big",
|
|
1574
|
+
"left",
|
|
1575
|
+
"right",
|
|
1576
|
+
"top",
|
|
1577
|
+
"bottom",
|
|
1578
|
+
"center",
|
|
1579
|
+
"corner",
|
|
1580
|
+
"side",
|
|
1581
|
+
"above",
|
|
1582
|
+
"below",
|
|
1583
|
+
"ink",
|
|
1584
|
+
"company",
|
|
1585
|
+
"name",
|
|
1586
|
+
"brand",
|
|
1587
|
+
"create",
|
|
1588
|
+
"creating",
|
|
1589
|
+
"artistic",
|
|
1590
|
+
"effect",
|
|
1591
|
+
"design",
|
|
1592
|
+
"additional"
|
|
1593
|
+
]);
|
|
1594
|
+
function tokenize(text) {
|
|
1595
|
+
return text.toLowerCase().match(/[a-z0-9]+/g) ?? [];
|
|
1596
|
+
}
|
|
1597
|
+
function extractQuoted(read) {
|
|
1598
|
+
const spans = [...read.matchAll(/["“”']([^"“”']+)["“”']/g)].map(
|
|
1599
|
+
(m) => m[1].trim()
|
|
1600
|
+
);
|
|
1601
|
+
if (spans.length === 0) return null;
|
|
1602
|
+
return spans.reduce((a, b) => b.length > a.length ? b : a).trim() || null;
|
|
1603
|
+
}
|
|
1604
|
+
function diffTokens(base, actual) {
|
|
1605
|
+
const n = base.length;
|
|
1606
|
+
const m = actual.length;
|
|
1607
|
+
const dp = Array.from(
|
|
1608
|
+
{ length: n + 1 },
|
|
1609
|
+
() => new Array(m + 1).fill(0)
|
|
1610
|
+
);
|
|
1611
|
+
for (let i2 = n - 1; i2 >= 0; i2--) {
|
|
1612
|
+
for (let j2 = m - 1; j2 >= 0; j2--) {
|
|
1613
|
+
dp[i2][j2] = base[i2] === actual[j2] ? dp[i2 + 1][j2 + 1] + 1 : Math.max(dp[i2 + 1][j2], dp[i2][j2 + 1]);
|
|
1285
1614
|
}
|
|
1286
1615
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1616
|
+
const inserted = [];
|
|
1617
|
+
const removed = [];
|
|
1618
|
+
let i = 0;
|
|
1619
|
+
let j = 0;
|
|
1620
|
+
while (i < n && j < m) {
|
|
1621
|
+
if (base[i] === actual[j]) {
|
|
1622
|
+
i++;
|
|
1623
|
+
j++;
|
|
1624
|
+
} else if (dp[i + 1][j] >= dp[i][j + 1]) {
|
|
1625
|
+
removed.push(base[i++]);
|
|
1626
|
+
} else {
|
|
1627
|
+
inserted.push(actual[j++]);
|
|
1293
1628
|
}
|
|
1294
1629
|
}
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1630
|
+
while (i < n) removed.push(base[i++]);
|
|
1631
|
+
while (j < m) inserted.push(actual[j++]);
|
|
1632
|
+
return { inserted, removed };
|
|
1633
|
+
}
|
|
1634
|
+
var keepToken = (t) => /\d/.test(t) || !FILLER.has(t);
|
|
1635
|
+
var quote = (tokens) => `"${tokens.join(" ")}"`;
|
|
1636
|
+
function describeRegionChange(changeType, baseRead, actualRead) {
|
|
1637
|
+
const baseQuoted = extractQuoted(baseRead);
|
|
1638
|
+
const actualQuoted = extractQuoted(actualRead);
|
|
1639
|
+
const haveCores = baseQuoted !== null && actualQuoted !== null;
|
|
1640
|
+
const base = tokenize(baseQuoted ?? baseRead);
|
|
1641
|
+
const actual = tokenize(actualQuoted ?? actualRead);
|
|
1642
|
+
const { inserted, removed } = diffTokens(base, actual);
|
|
1643
|
+
const ins = haveCores ? inserted : inserted.filter(keepToken);
|
|
1644
|
+
const rem = haveCores ? removed : removed.filter(keepToken);
|
|
1645
|
+
const updated = actualQuoted && actualQuoted.length <= 60 ? ` (region now reads "${actualQuoted}")` : "";
|
|
1646
|
+
if (ins.length > 0 && rem.length === 0)
|
|
1647
|
+
return `added ${quote(ins)}${updated}`;
|
|
1648
|
+
if (rem.length > 0 && ins.length === 0)
|
|
1649
|
+
return `removed ${quote(rem)}${updated}`;
|
|
1650
|
+
if (ins.length > 0 && rem.length > 0)
|
|
1651
|
+
return `replaced ${quote(rem)} with ${quote(ins)}${updated}`;
|
|
1652
|
+
const kind = changeType.replace(/-/g, " ");
|
|
1653
|
+
return `${kind} with no readable text change${updated}`;
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
// src/judge/vision.ts
|
|
1657
|
+
var MODEL_ID2 = "Xenova/moondream2";
|
|
1658
|
+
var PATCH_SIZE = 14;
|
|
1659
|
+
var MAX_NEW_TOKENS2 = 64;
|
|
1660
|
+
var ANSWER_MARKER = "Answer:";
|
|
1661
|
+
async function defaultFactory2() {
|
|
1662
|
+
const mod = await loadTransformers();
|
|
1663
|
+
const progress = createLoadProgress("vision");
|
|
1664
|
+
const progress_callback = progress.onProgress;
|
|
1665
|
+
const [tokenizer, processor, model] = await Promise.all([
|
|
1666
|
+
mod.AutoTokenizer.from_pretrained(MODEL_ID2, { progress_callback }),
|
|
1667
|
+
mod.AutoProcessor.from_pretrained(MODEL_ID2, { progress_callback }),
|
|
1668
|
+
mod.Moondream1ForConditionalGeneration.from_pretrained(MODEL_ID2, {
|
|
1669
|
+
dtype: {
|
|
1670
|
+
embed_tokens: "fp32",
|
|
1671
|
+
vision_encoder: "q8",
|
|
1672
|
+
decoder_model_merged: "q4"
|
|
1673
|
+
},
|
|
1674
|
+
device: "cpu",
|
|
1675
|
+
progress_callback
|
|
1676
|
+
})
|
|
1677
|
+
]);
|
|
1678
|
+
progress.done();
|
|
1679
|
+
return {
|
|
1680
|
+
async describe(imagePath, question) {
|
|
1681
|
+
const image = await mod.RawImage.read(imagePath);
|
|
1682
|
+
const vision = await processor(image);
|
|
1683
|
+
const [, , height, width] = vision.pixel_values.dims;
|
|
1684
|
+
const numImageTokens = Math.floor(height / PATCH_SIZE) * Math.floor(width / PATCH_SIZE);
|
|
1685
|
+
const prompt = `${"<image>".repeat(numImageTokens)}
|
|
1686
|
+
|
|
1687
|
+
Question: ${question}
|
|
1688
|
+
|
|
1689
|
+
${ANSWER_MARKER}`;
|
|
1690
|
+
const textInputs = tokenizer(prompt);
|
|
1691
|
+
const output = await model.generate({
|
|
1692
|
+
...textInputs,
|
|
1693
|
+
...vision,
|
|
1694
|
+
do_sample: false,
|
|
1695
|
+
max_new_tokens: MAX_NEW_TOKENS2,
|
|
1696
|
+
// Moondream loops the same sentence on composite tiles without these.
|
|
1697
|
+
repetition_penalty: 1.3,
|
|
1698
|
+
no_repeat_ngram_size: 3
|
|
1699
|
+
});
|
|
1700
|
+
const decoded = tokenizer.batch_decode(output, {
|
|
1701
|
+
skip_special_tokens: true
|
|
1702
|
+
});
|
|
1703
|
+
const raw = Array.isArray(decoded) ? String(decoded[0] ?? "") : String(decoded);
|
|
1704
|
+
const idx = raw.lastIndexOf(ANSWER_MARKER);
|
|
1705
|
+
return (idx >= 0 ? raw.slice(idx + ANSWER_MARKER.length) : raw).trim();
|
|
1301
1706
|
}
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
if (!data) return [];
|
|
1311
|
-
const out = [];
|
|
1312
|
-
for (const [taskId, channel, serialized] of Object.values(data)) {
|
|
1313
|
-
const value = await this.serde.loadsTyped("json", decode(serialized));
|
|
1314
|
-
out.push([taskId, channel, value]);
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
function createVisionRunnerHolder(factory = defaultFactory2) {
|
|
1710
|
+
let runnerPromise;
|
|
1711
|
+
return {
|
|
1712
|
+
get() {
|
|
1713
|
+
if (!runnerPromise) runnerPromise = factory();
|
|
1714
|
+
return runnerPromise;
|
|
1315
1715
|
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
)
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
// src/judge/local.ts
|
|
1720
|
+
var READ_PROMPT = [
|
|
1721
|
+
"Read the text in this image. Reply with only the exact words and numbers you",
|
|
1722
|
+
'see, wrapped in double quotes. If there is no text, reply "".'
|
|
1723
|
+
].join(" ");
|
|
1724
|
+
var DESCRIBE_PROMPT = [
|
|
1725
|
+
"In one sentence, describe the main UI elements and any visible text in this",
|
|
1726
|
+
"screenshot. Do not judge whether it is good or bad."
|
|
1727
|
+
].join(" ");
|
|
1728
|
+
var LABELS = [
|
|
1729
|
+
"regression-likely",
|
|
1730
|
+
"intentional-likely",
|
|
1731
|
+
"noise-likely",
|
|
1732
|
+
"ambiguous"
|
|
1733
|
+
];
|
|
1734
|
+
var ACTION_BY_LABEL = {
|
|
1735
|
+
"regression-likely": "investigate",
|
|
1736
|
+
"intentional-likely": "rewrite-if-intended",
|
|
1737
|
+
"noise-likely": "ignore-or-rewrite",
|
|
1738
|
+
ambiguous: "investigate"
|
|
1739
|
+
};
|
|
1740
|
+
var VERDICT_MARKER = "VERDICT:";
|
|
1741
|
+
function summarizeInterpret(input) {
|
|
1742
|
+
const lines = [];
|
|
1743
|
+
lines.push(
|
|
1744
|
+
`diff area: ${(input.diffPercentage ?? 0).toFixed(3)}% of the page`
|
|
1745
|
+
);
|
|
1746
|
+
lines.push(`severity: ${input.severity ?? "unknown"}`);
|
|
1747
|
+
const regions = input.regions ?? [];
|
|
1748
|
+
lines.push(`changed regions: ${regions.length}`);
|
|
1749
|
+
if (regions.length > 0) {
|
|
1750
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1751
|
+
for (const r of regions)
|
|
1752
|
+
counts.set(r.changeType, (counts.get(r.changeType) ?? 0) + 1);
|
|
1753
|
+
const byType = [...counts.entries()].sort((a, b) => b[1] - a[1]).map(([type, n]) => `${type} x${n}`).join(", ");
|
|
1754
|
+
lines.push(`change types: ${byType}`);
|
|
1755
|
+
}
|
|
1756
|
+
return lines.join("\n");
|
|
1757
|
+
}
|
|
1758
|
+
function buildClassifyPrompt(summary, description) {
|
|
1759
|
+
return [
|
|
1760
|
+
"You classify a visual regression-test diff into exactly one label.",
|
|
1761
|
+
"",
|
|
1762
|
+
"Deterministic analysis of the changed pixels:",
|
|
1763
|
+
summary,
|
|
1764
|
+
"",
|
|
1765
|
+
"The change in the affected region, read from the screenshots, is:",
|
|
1766
|
+
`"${description}"`,
|
|
1767
|
+
"",
|
|
1768
|
+
"Labels:",
|
|
1769
|
+
"- regression-likely: something looks broken, missing, clipped, or misaligned.",
|
|
1770
|
+
"- intentional-likely: a deliberate content or style update.",
|
|
1771
|
+
"- noise-likely: negligible anti-aliasing / sub-pixel rendering differences.",
|
|
1772
|
+
"- ambiguous: cannot tell from the evidence.",
|
|
1773
|
+
"",
|
|
1774
|
+
"First explain your reasoning in one short sentence. Then, on the final",
|
|
1775
|
+
`line, write "${VERDICT_MARKER} <label>" using exactly one label above.`
|
|
1776
|
+
].join("\n");
|
|
1777
|
+
}
|
|
1778
|
+
function parseLabel(text) {
|
|
1779
|
+
const t = text.toLowerCase();
|
|
1780
|
+
const marked = t.match(/verdict:\s*([a-z-]+)/);
|
|
1781
|
+
if (marked) {
|
|
1782
|
+
const hit = LABELS.find((label) => marked[1].startsWith(label));
|
|
1783
|
+
if (hit) return hit;
|
|
1784
|
+
}
|
|
1785
|
+
let latest2 = null;
|
|
1786
|
+
for (const label of LABELS) {
|
|
1787
|
+
const idx = t.lastIndexOf(label);
|
|
1788
|
+
if (idx >= 0 && (!latest2 || idx > latest2.idx)) latest2 = { label, idx };
|
|
1789
|
+
}
|
|
1790
|
+
return latest2?.label ?? null;
|
|
1791
|
+
}
|
|
1792
|
+
function firstSentence(text) {
|
|
1793
|
+
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
1794
|
+
const m = trimmed.match(/^.*?[.!?](\s|$)/);
|
|
1795
|
+
return (m ? m[0] : trimmed).trim();
|
|
1796
|
+
}
|
|
1797
|
+
function reasonOf(answer, label) {
|
|
1798
|
+
const beforeVerdict = answer.split(/verdict:/i)[0];
|
|
1799
|
+
const withoutLabel = beforeVerdict.replace(new RegExp(label, "gi"), "").trim();
|
|
1800
|
+
return firstSentence(withoutLabel) || firstSentence(answer);
|
|
1801
|
+
}
|
|
1802
|
+
function toError(err) {
|
|
1803
|
+
return err instanceof Error ? err : new Error(String(err));
|
|
1804
|
+
}
|
|
1805
|
+
function classifyFailure(err) {
|
|
1806
|
+
const m = err.message.toLowerCase();
|
|
1807
|
+
if (m.includes("model") || m.includes("weights") || m.includes("download") || m.includes("transformers"))
|
|
1808
|
+
return "model-load";
|
|
1809
|
+
if (m.includes("enoent") || m.includes("read") || m.includes("sharp") || m.includes("crop"))
|
|
1810
|
+
return "read";
|
|
1811
|
+
return "internal";
|
|
1812
|
+
}
|
|
1813
|
+
function createLocalJudge(deps = {}) {
|
|
1814
|
+
const vision = deps.vision ?? createVisionRunnerHolder();
|
|
1815
|
+
const classifier = deps.classifier ?? createClassifierRunnerHolder();
|
|
1816
|
+
const visionSemaphore = createSemaphore(1);
|
|
1817
|
+
const classifierSemaphore = createSemaphore(1);
|
|
1818
|
+
async function describeChange(input, entryDir) {
|
|
1819
|
+
if (!input.regions || input.regions.length === 0) return null;
|
|
1820
|
+
try {
|
|
1821
|
+
const crops = await prepareRegionReads({
|
|
1822
|
+
regions: input.regions,
|
|
1823
|
+
baselinePath: input.baselinePath,
|
|
1824
|
+
actualPath: input.actualPath,
|
|
1825
|
+
outputDir: entryDir
|
|
1826
|
+
});
|
|
1827
|
+
if (crops.length === 0) return null;
|
|
1828
|
+
const v = await vision.get();
|
|
1829
|
+
const phrases = await Promise.all(
|
|
1830
|
+
crops.map(async (crop) => {
|
|
1831
|
+
const [before, after] = await Promise.all([
|
|
1832
|
+
v.describe(crop.beforePath, READ_PROMPT),
|
|
1833
|
+
v.describe(crop.afterPath, READ_PROMPT)
|
|
1834
|
+
]);
|
|
1835
|
+
return describeRegionChange(crop.changeType, before, after);
|
|
1836
|
+
})
|
|
1351
1837
|
);
|
|
1838
|
+
return phrases.length === 1 ? phrases[0] : phrases.map((p, i) => `region ${i + 1}: ${p}`).join("; ");
|
|
1839
|
+
} catch {
|
|
1840
|
+
return null;
|
|
1352
1841
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1842
|
+
}
|
|
1843
|
+
async function describeScreenshot(input) {
|
|
1844
|
+
const v = await vision.get();
|
|
1845
|
+
return (await v.describe(input.actualPath, DESCRIBE_PROMPT)).trim();
|
|
1846
|
+
}
|
|
1847
|
+
return {
|
|
1848
|
+
name: "local",
|
|
1849
|
+
// Stream both models' weights up front (concurrently) so the multi-second
|
|
1850
|
+
// load is a single visible phase before judging, not a silent stall on the
|
|
1851
|
+
// first test. Both are cached promises, so the judge reuses them after.
|
|
1852
|
+
async warmup() {
|
|
1853
|
+
await Promise.all([vision.get(), classifier.get()]);
|
|
1854
|
+
},
|
|
1855
|
+
async judge(input, cwd) {
|
|
1856
|
+
const entryDir = path__default.default.join(paths(cwd).judgments, input.entry.id);
|
|
1857
|
+
await promises.mkdir(entryDir, { recursive: true });
|
|
1858
|
+
try {
|
|
1859
|
+
const description = await visionSemaphore.run(async () => {
|
|
1860
|
+
input.onJudgingStart?.();
|
|
1861
|
+
const fromRegions = await describeChange(input, entryDir);
|
|
1862
|
+
const text = fromRegions ?? await describeScreenshot(input);
|
|
1863
|
+
return text.trim();
|
|
1864
|
+
});
|
|
1865
|
+
const summary = summarizeInterpret(input);
|
|
1866
|
+
const prompt = buildClassifyPrompt(summary, description);
|
|
1867
|
+
const answer = await classifierSemaphore.run(async () => {
|
|
1868
|
+
const c = await classifier.get();
|
|
1869
|
+
return (await c.complete(prompt)).trim();
|
|
1870
|
+
});
|
|
1871
|
+
const label = parseLabel(answer);
|
|
1872
|
+
if (!label) {
|
|
1873
|
+
return {
|
|
1874
|
+
kind: "judged",
|
|
1875
|
+
verdict: input.heuristicVerdict,
|
|
1876
|
+
rationale: `${description}
|
|
1877
|
+
${answer}`.trim()
|
|
1878
|
+
};
|
|
1366
1879
|
}
|
|
1367
|
-
|
|
1880
|
+
const reason = reasonOf(answer, label);
|
|
1881
|
+
const verdict = {
|
|
1882
|
+
label,
|
|
1883
|
+
headline: reason || input.heuristicVerdict.headline,
|
|
1884
|
+
// The headline already carries the classifier's reasoning; keep only
|
|
1885
|
+
// the deterministic region read here so the report doesn't repeat the
|
|
1886
|
+
// reasoning or echo the raw `VERDICT:` line back to the reader.
|
|
1887
|
+
rationale: [description].filter(Boolean),
|
|
1888
|
+
action: ACTION_BY_LABEL[label]
|
|
1889
|
+
};
|
|
1890
|
+
return { kind: "judged", verdict, rationale: answer, confidence: 0.6 };
|
|
1891
|
+
} catch (err) {
|
|
1892
|
+
const error = toError(err);
|
|
1893
|
+
return {
|
|
1894
|
+
kind: "failed",
|
|
1895
|
+
reason: classifyFailure(error),
|
|
1896
|
+
error,
|
|
1897
|
+
fallback: input.heuristicVerdict
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1368
1900
|
}
|
|
1369
|
-
|
|
1370
|
-
}
|
|
1371
|
-
async getTuple(config) {
|
|
1372
|
-
const thread = config.configurable?.thread_id;
|
|
1373
|
-
if (!thread) return void 0;
|
|
1374
|
-
const ns = config.configurable?.checkpoint_ns ?? "";
|
|
1375
|
-
const explicitId = langgraphCheckpoint.getCheckpointId(config);
|
|
1376
|
-
if (explicitId) {
|
|
1377
|
-
return this.readTuple(thread, ns, explicitId, config);
|
|
1378
|
-
}
|
|
1379
|
-
const ids = (await this.listCheckpointIds(thread, ns)).sort(
|
|
1380
|
-
(a, b) => b.localeCompare(a)
|
|
1381
|
-
);
|
|
1382
|
-
if (ids.length === 0) return void 0;
|
|
1383
|
-
const ckptId = ids[0];
|
|
1384
|
-
return this.readTuple(thread, ns, ckptId, {
|
|
1385
|
-
configurable: {
|
|
1386
|
-
thread_id: thread,
|
|
1387
|
-
checkpoint_ns: ns,
|
|
1388
|
-
checkpoint_id: ckptId
|
|
1389
|
-
}
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
async *list(config, options) {
|
|
1393
|
-
const filter = options?.filter;
|
|
1394
|
-
const before = options?.before;
|
|
1395
|
-
let limit = options?.limit;
|
|
1396
|
-
const configThread = config.configurable?.thread_id;
|
|
1397
|
-
const configNs = config.configurable?.checkpoint_ns;
|
|
1398
|
-
const configCkptId = config.configurable?.checkpoint_id;
|
|
1399
|
-
const threads = configThread ? [configThread] : await this.listThreads();
|
|
1400
|
-
for (const thread of threads) {
|
|
1401
|
-
const nsNames = await this.listNamespaces(thread);
|
|
1402
|
-
for (const nsName of nsNames) {
|
|
1403
|
-
const ns = this.decodeNs(nsName);
|
|
1404
|
-
if (configNs !== void 0 && ns !== configNs) continue;
|
|
1405
|
-
const ids = (await this.listCheckpointIds(thread, ns)).sort(
|
|
1406
|
-
(a, b) => b.localeCompare(a)
|
|
1407
|
-
);
|
|
1408
|
-
for (const ckptId of ids) {
|
|
1409
|
-
if (configCkptId && ckptId !== configCkptId) continue;
|
|
1410
|
-
if (before?.configurable?.checkpoint_id && ckptId >= before.configurable.checkpoint_id)
|
|
1411
|
-
continue;
|
|
1412
|
-
const tuple = await this.readTuple(thread, ns, ckptId, {
|
|
1413
|
-
configurable: {
|
|
1414
|
-
thread_id: thread,
|
|
1415
|
-
checkpoint_ns: ns,
|
|
1416
|
-
checkpoint_id: ckptId
|
|
1417
|
-
}
|
|
1418
|
-
});
|
|
1419
|
-
if (!tuple) continue;
|
|
1420
|
-
if (filter) {
|
|
1421
|
-
const md = tuple.metadata;
|
|
1422
|
-
const matches = Object.entries(filter).every(
|
|
1423
|
-
([k, v]) => md?.[k] === v
|
|
1424
|
-
);
|
|
1425
|
-
if (!matches) continue;
|
|
1426
|
-
}
|
|
1427
|
-
if (limit !== void 0) {
|
|
1428
|
-
if (limit <= 0) return;
|
|
1429
|
-
limit -= 1;
|
|
1430
|
-
}
|
|
1431
|
-
yield tuple;
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
async put(config, checkpoint, metadata) {
|
|
1437
|
-
const thread = config.configurable?.thread_id;
|
|
1438
|
-
if (!thread) {
|
|
1439
|
-
throw new Error(
|
|
1440
|
-
'FsCheckpointSaver: missing "thread_id" in configurable. Pass `{ configurable: { thread_id } }` when streaming.'
|
|
1441
|
-
);
|
|
1442
|
-
}
|
|
1443
|
-
const ns = config.configurable?.checkpoint_ns ?? "";
|
|
1444
|
-
const parentCheckpointId = config.configurable?.checkpoint_id;
|
|
1445
|
-
const prepared = langgraphCheckpoint.copyCheckpoint(checkpoint);
|
|
1446
|
-
const [[, serializedCheckpoint], [, serializedMetadata]] = await Promise.all([
|
|
1447
|
-
this.serde.dumpsTyped(prepared),
|
|
1448
|
-
this.serde.dumpsTyped(metadata)
|
|
1449
|
-
]);
|
|
1450
|
-
await promises.mkdir(this.nsPath(thread, ns), { recursive: true });
|
|
1451
|
-
const file = this.ckptFile(thread, ns, checkpoint.id);
|
|
1452
|
-
const body = {
|
|
1453
|
-
checkpoint: encode(serializedCheckpoint),
|
|
1454
|
-
metadata: encode(serializedMetadata),
|
|
1455
|
-
parentCheckpointId
|
|
1456
|
-
};
|
|
1457
|
-
await writeJsonAtomic(file, body);
|
|
1458
|
-
return {
|
|
1459
|
-
configurable: {
|
|
1460
|
-
thread_id: thread,
|
|
1461
|
-
checkpoint_ns: ns,
|
|
1462
|
-
checkpoint_id: checkpoint.id
|
|
1463
|
-
}
|
|
1464
|
-
};
|
|
1465
|
-
}
|
|
1466
|
-
async putWrites(config, writes, taskId) {
|
|
1467
|
-
const thread = config.configurable?.thread_id;
|
|
1468
|
-
if (!thread) {
|
|
1469
|
-
throw new Error(
|
|
1470
|
-
'FsCheckpointSaver: missing "thread_id" in configurable for putWrites.'
|
|
1471
|
-
);
|
|
1472
|
-
}
|
|
1473
|
-
const ns = config.configurable?.checkpoint_ns ?? "";
|
|
1474
|
-
const ckptId = config.configurable?.checkpoint_id;
|
|
1475
|
-
if (!ckptId) {
|
|
1476
|
-
throw new Error(
|
|
1477
|
-
'FsCheckpointSaver: missing "checkpoint_id" in configurable for putWrites.'
|
|
1478
|
-
);
|
|
1479
|
-
}
|
|
1480
|
-
const key = `${thread}|${ns}|${ckptId}`;
|
|
1481
|
-
await this.withLock(key, async () => {
|
|
1482
|
-
const existing = await readJson2(this.writesFile(thread, ns, ckptId)) ?? {};
|
|
1483
|
-
let mutated = false;
|
|
1484
|
-
for (let idx = 0; idx < writes.length; idx++) {
|
|
1485
|
-
const [channel, value] = writes[idx];
|
|
1486
|
-
const writeIdx = langgraphCheckpoint.WRITES_IDX_MAP[channel] ?? idx;
|
|
1487
|
-
const innerKey = `${taskId},${writeIdx}`;
|
|
1488
|
-
if (writeIdx >= 0 && innerKey in existing) continue;
|
|
1489
|
-
const [, serialized] = await this.serde.dumpsTyped(value);
|
|
1490
|
-
existing[innerKey] = [taskId, channel, encode(serialized)];
|
|
1491
|
-
mutated = true;
|
|
1492
|
-
}
|
|
1493
|
-
if (!mutated) return;
|
|
1494
|
-
await promises.mkdir(this.nsPath(thread, ns), { recursive: true });
|
|
1495
|
-
await writeJsonAtomic(this.writesFile(thread, ns, ckptId), existing);
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
async deleteThread(threadId) {
|
|
1499
|
-
await promises.rm(this.threadDir(threadId), { recursive: true, force: true });
|
|
1500
|
-
}
|
|
1501
|
-
};
|
|
1502
|
-
var PREVIEW_WIDTH = 320;
|
|
1503
|
-
function escapeCell(s) {
|
|
1504
|
-
return s.replace(/\n/g, " ");
|
|
1505
|
-
}
|
|
1506
|
-
function toBlazediffRel(cwd, abs) {
|
|
1507
|
-
if (!abs) return void 0;
|
|
1508
|
-
const root = paths(cwd).root;
|
|
1509
|
-
const rel = path__default.default.isAbsolute(abs) ? path__default.default.relative(root, abs) : path__default.default.relative(paths(cwd).root, path__default.default.join(cwd, abs));
|
|
1510
|
-
return rel.split(path__default.default.sep).join("/");
|
|
1511
|
-
}
|
|
1512
|
-
function img(src, alt) {
|
|
1513
|
-
return `<img src="${src}" width="${PREVIEW_WIDTH}" alt="${alt}">`;
|
|
1514
|
-
}
|
|
1515
|
-
function baselineCell(r, cwd) {
|
|
1516
|
-
const rel = toBlazediffRel(cwd, r.baselinePath) ?? `baselines/${r.id}.png`;
|
|
1517
|
-
return img(rel, `${r.id} baseline`);
|
|
1518
|
-
}
|
|
1519
|
-
function actualCell(r, cwd) {
|
|
1520
|
-
const actual = toBlazediffRel(cwd, r.actualPath);
|
|
1521
|
-
return actual ? img(actual, `${r.id} actual`) : "-";
|
|
1522
|
-
}
|
|
1523
|
-
function diffCell(r, cwd) {
|
|
1524
|
-
const diff = toBlazediffRel(cwd, r.diffPath);
|
|
1525
|
-
return diff ? img(diff, `${r.id} diff`) : "-";
|
|
1526
|
-
}
|
|
1527
|
-
function verdictCell(r) {
|
|
1528
|
-
if (r.status === "missing-baseline") {
|
|
1529
|
-
return `missing-baseline - ${r.message ?? "baseline missing"}`;
|
|
1530
|
-
}
|
|
1531
|
-
if (r.status === "stale-baseline") {
|
|
1532
|
-
return `stale-baseline - ${r.message ?? "manifest entry edited without re-capturing"}`;
|
|
1533
|
-
}
|
|
1534
|
-
if (r.status === "needs-judgment") {
|
|
1535
|
-
return `needs-judgment - see judgments/${r.id}/`;
|
|
1536
|
-
}
|
|
1537
|
-
if (!r.verdict) {
|
|
1538
|
-
return r.message ?? r.status;
|
|
1539
|
-
}
|
|
1540
|
-
return `${r.verdict.label} - ${r.verdict.headline} -> ${r.verdict.action}`;
|
|
1541
|
-
}
|
|
1542
|
-
function renderRow(r, cwd) {
|
|
1543
|
-
return `| ${r.id} | ${escapeCell(baselineCell(r, cwd))} | ${escapeCell(actualCell(r, cwd))} | ${escapeCell(diffCell(r, cwd))} | ${escapeCell(verdictCell(r))} |`;
|
|
1544
|
-
}
|
|
1545
|
-
function headerLine(report) {
|
|
1546
|
-
const { passed, failed, pendingJudgments, totalEntries } = report;
|
|
1547
|
-
const parts = [`${passed}/${totalEntries} passed`];
|
|
1548
|
-
if (failed > 0) parts.push(`${failed} failed`);
|
|
1549
|
-
if (pendingJudgments > 0) parts.push(`${pendingJudgments} pending judgment`);
|
|
1550
|
-
return parts.length > 1 ? `${parts[0]} (${parts.slice(1).join(", ")})` : parts[0];
|
|
1901
|
+
};
|
|
1551
1902
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
""
|
|
1559
|
-
];
|
|
1560
|
-
if (nonPass.length === 0) {
|
|
1561
|
-
lines.push("All entries passed.");
|
|
1562
|
-
return `${lines.join("\n")}
|
|
1563
|
-
`;
|
|
1903
|
+
var localJudge = createLocalJudge();
|
|
1904
|
+
|
|
1905
|
+
// src/judge/none.ts
|
|
1906
|
+
var noneJudge = {
|
|
1907
|
+
name: "none",
|
|
1908
|
+
async judge(input) {
|
|
1909
|
+
return { kind: "judged", verdict: input.heuristicVerdict };
|
|
1564
1910
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
return `${lines.join("\n")}
|
|
1569
|
-
`;
|
|
1570
|
-
}
|
|
1571
|
-
async function writeSummaryMarkdown(report, cwd = process.cwd()) {
|
|
1572
|
-
const file = paths(cwd).summary;
|
|
1911
|
+
};
|
|
1912
|
+
async function writeReport(report, cwd = process.cwd()) {
|
|
1913
|
+
const file = paths(cwd).report;
|
|
1573
1914
|
await promises.mkdir(path__default.default.dirname(file), { recursive: true });
|
|
1574
|
-
await promises.writeFile(file,
|
|
1915
|
+
await promises.writeFile(file, `${JSON.stringify(report, null, 2)}
|
|
1916
|
+
`, "utf8");
|
|
1575
1917
|
return file;
|
|
1576
1918
|
}
|
|
1919
|
+
async function readReport(cwd = process.cwd()) {
|
|
1920
|
+
return readJsonOrNull(paths(cwd).report);
|
|
1921
|
+
}
|
|
1577
1922
|
|
|
1578
1923
|
// src/judge/apply.ts
|
|
1579
1924
|
var VALID_LABELS = [
|
|
@@ -1611,21 +1956,6 @@ function parseVerdict(raw) {
|
|
|
1611
1956
|
confidence: typeof r.confidence === "number" ? r.confidence : void 0
|
|
1612
1957
|
};
|
|
1613
1958
|
}
|
|
1614
|
-
async function fileExists2(p) {
|
|
1615
|
-
try {
|
|
1616
|
-
await promises.access(p);
|
|
1617
|
-
return true;
|
|
1618
|
-
} catch {
|
|
1619
|
-
return false;
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
async function readJsonOrNull(file) {
|
|
1623
|
-
try {
|
|
1624
|
-
return JSON.parse(await promises.readFile(file, "utf8"));
|
|
1625
|
-
} catch {
|
|
1626
|
-
return null;
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
1959
|
async function readJudgmentDirs(root) {
|
|
1630
1960
|
let names;
|
|
1631
1961
|
try {
|
|
@@ -1696,7 +2026,7 @@ async function reconstructFromDisk(cwd, dirs) {
|
|
|
1696
2026
|
const manifest = await loadManifest(cwd);
|
|
1697
2027
|
if (!manifest) {
|
|
1698
2028
|
throw new Error(
|
|
1699
|
-
`no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent
|
|
2029
|
+
`no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent onboard\` first.`
|
|
1700
2030
|
);
|
|
1701
2031
|
}
|
|
1702
2032
|
const dirById = new Map(dirs.map((d) => [d.id, d]));
|
|
@@ -1723,7 +2053,7 @@ async function reconstructFromDisk(cwd, dirs) {
|
|
|
1723
2053
|
pendingJudgments,
|
|
1724
2054
|
results
|
|
1725
2055
|
};
|
|
1726
|
-
await
|
|
2056
|
+
await writeReport(report, cwd);
|
|
1727
2057
|
return report;
|
|
1728
2058
|
}
|
|
1729
2059
|
async function hasCheckpoint(cwd, threadId) {
|
|
@@ -1735,13 +2065,12 @@ async function hasCheckpoint(cwd, threadId) {
|
|
|
1735
2065
|
return false;
|
|
1736
2066
|
}
|
|
1737
2067
|
}
|
|
1738
|
-
async function applyJudgments(opts =
|
|
1739
|
-
const
|
|
1740
|
-
const cwd = options.cwd ?? process.cwd();
|
|
2068
|
+
async function applyJudgments(opts = {}) {
|
|
2069
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
1741
2070
|
const manifest = await loadManifest(cwd);
|
|
1742
2071
|
if (!manifest) {
|
|
1743
2072
|
throw new Error(
|
|
1744
|
-
`no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent
|
|
2073
|
+
`no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent onboard\` first.`
|
|
1745
2074
|
);
|
|
1746
2075
|
}
|
|
1747
2076
|
const dirs = await readJudgmentDirs(paths(cwd).judgments);
|
|
@@ -1771,10 +2100,9 @@ async function applyJudgments(opts = process.cwd()) {
|
|
|
1771
2100
|
cwd,
|
|
1772
2101
|
verdicts,
|
|
1773
2102
|
threadId,
|
|
1774
|
-
onEvent:
|
|
1775
|
-
junitPath:
|
|
2103
|
+
onEvent: opts.onEvent,
|
|
2104
|
+
junitPath: opts.junitPath
|
|
1776
2105
|
});
|
|
1777
|
-
await new FsCheckpointSaver(paths(cwd).checkpoints).deleteThread(threadId).catch(() => void 0);
|
|
1778
2106
|
return { report, applied, missing, invalid };
|
|
1779
2107
|
}
|
|
1780
2108
|
var HOST_INSTRUCTIONS = [
|
|
@@ -1784,7 +2112,7 @@ var HOST_INSTRUCTIONS = [
|
|
|
1784
2112
|
"Decide whether the change is a regression, an intentional UI change, or rendering noise.",
|
|
1785
2113
|
"Write your decision to `verdict.json` (next to this `request.json`) with shape:",
|
|
1786
2114
|
' { "id": string, "verdict": { "label": "regression-likely" | "intentional-likely" | "noise-likely", "headline": string, "rationale": string[], "action": "investigate" | "rewrite-if-intended" | "ignore-or-rewrite" }, "rationale": string, "confidence": number }',
|
|
1787
|
-
"Then re-run `blazediff-agent check --apply-judgments --json` to regenerate
|
|
2115
|
+
"Then re-run `blazediff-agent check --apply-judgments --json` to regenerate report.json."
|
|
1788
2116
|
].join("\n");
|
|
1789
2117
|
function relTo(cwd, abs) {
|
|
1790
2118
|
if (!abs) return void 0;
|
|
@@ -1792,24 +2120,10 @@ function relTo(cwd, abs) {
|
|
|
1792
2120
|
}
|
|
1793
2121
|
function signatureOf(r) {
|
|
1794
2122
|
const pct = typeof r.diffPercentage === "number" ? r.diffPercentage.toFixed(4) : "?";
|
|
1795
|
-
const regions = r.regions?.length ?? 0;
|
|
1796
2123
|
const severity = r.severity ?? "?";
|
|
1797
|
-
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
try {
|
|
1801
|
-
await promises.access(p);
|
|
1802
|
-
return true;
|
|
1803
|
-
} catch {
|
|
1804
|
-
return false;
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
async function readJsonOrNull2(file) {
|
|
1808
|
-
try {
|
|
1809
|
-
return JSON.parse(await promises.readFile(file, "utf8"));
|
|
1810
|
-
} catch {
|
|
1811
|
-
return null;
|
|
1812
|
-
}
|
|
2124
|
+
const regions = (r.regions ?? []).map((reg) => `${reg.changeType}:${reg.pixelCount}`).sort().join(",");
|
|
2125
|
+
const regionsKey = regions ? `[${regions}]` : "0";
|
|
2126
|
+
return `${r.status}|diff:${pct}|regions:${regionsKey}|severity:${severity}`;
|
|
1813
2127
|
}
|
|
1814
2128
|
function entryById(manifest, id) {
|
|
1815
2129
|
return manifest.entries.find((e) => e.id === id);
|
|
@@ -1858,8 +2172,8 @@ async function discoverTiles(dir) {
|
|
|
1858
2172
|
const locatorAbs = path__default.default.join(dir, "locator.png");
|
|
1859
2173
|
const tilesAbs = path__default.default.join(dir, "regions.png");
|
|
1860
2174
|
const [locator, tiles] = await Promise.all([
|
|
1861
|
-
|
|
1862
|
-
|
|
2175
|
+
fileExists2(locatorAbs),
|
|
2176
|
+
fileExists2(tilesAbs)
|
|
1863
2177
|
]);
|
|
1864
2178
|
return {
|
|
1865
2179
|
locatorPath: locator ? "locator.png" : void 0,
|
|
@@ -1876,7 +2190,7 @@ async function writeJudgments(opts) {
|
|
|
1876
2190
|
opts.report.results.map(async (result) => {
|
|
1877
2191
|
const dir = path__default.default.join(root, result.id);
|
|
1878
2192
|
if (result.status === "pass") {
|
|
1879
|
-
if (await
|
|
2193
|
+
if (await fileExists2(dir))
|
|
1880
2194
|
await promises.rm(dir, { recursive: true, force: true });
|
|
1881
2195
|
return;
|
|
1882
2196
|
}
|
|
@@ -1888,9 +2202,9 @@ async function writeJudgments(opts) {
|
|
|
1888
2202
|
const requestFile = path__default.default.join(dir, "request.json");
|
|
1889
2203
|
const verdictFile = path__default.default.join(dir, "verdict.json");
|
|
1890
2204
|
const [prior, priorVerdict] = await Promise.all([
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
(exists) => exists ?
|
|
2205
|
+
readJsonOrNull(requestFile),
|
|
2206
|
+
fileExists2(verdictFile).then(
|
|
2207
|
+
(exists) => exists ? readJsonOrNull(verdictFile) : null
|
|
1894
2208
|
)
|
|
1895
2209
|
]);
|
|
1896
2210
|
const signatureMatches = prior !== null && prior.signature === request.signature;
|
|
@@ -1900,68 +2214,356 @@ async function writeJudgments(opts) {
|
|
|
1900
2214
|
`,
|
|
1901
2215
|
"utf8"
|
|
1902
2216
|
);
|
|
1903
|
-
if (priorVerdict && signatureMatches) {
|
|
1904
|
-
return;
|
|
2217
|
+
if (priorVerdict && signatureMatches) {
|
|
2218
|
+
return;
|
|
2219
|
+
}
|
|
2220
|
+
const auto = autoVerdict(result);
|
|
2221
|
+
if (auto) {
|
|
2222
|
+
await promises.writeFile(
|
|
2223
|
+
verdictFile,
|
|
2224
|
+
`${JSON.stringify(auto, null, 2)}
|
|
2225
|
+
`,
|
|
2226
|
+
"utf8"
|
|
2227
|
+
);
|
|
2228
|
+
} else if (priorVerdict && !signatureMatches) {
|
|
2229
|
+
await promises.rm(verdictFile, { force: true });
|
|
2230
|
+
}
|
|
2231
|
+
})
|
|
2232
|
+
);
|
|
2233
|
+
let entries;
|
|
2234
|
+
try {
|
|
2235
|
+
entries = await promises.readdir(root);
|
|
2236
|
+
} catch {
|
|
2237
|
+
return;
|
|
2238
|
+
}
|
|
2239
|
+
await Promise.all(
|
|
2240
|
+
entries.filter((name) => !knownIds.has(name)).map(
|
|
2241
|
+
(name) => promises.rm(path__default.default.join(root, name), { recursive: true, force: true })
|
|
2242
|
+
)
|
|
2243
|
+
);
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
// src/judge/index.ts
|
|
2247
|
+
function resolveJudge(backend) {
|
|
2248
|
+
switch (backend) {
|
|
2249
|
+
case "none":
|
|
2250
|
+
return noneJudge;
|
|
2251
|
+
case "host":
|
|
2252
|
+
return codingAgentHostJudge;
|
|
2253
|
+
case "local":
|
|
2254
|
+
return localJudge;
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
function escapeXml(value) {
|
|
2258
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2259
|
+
}
|
|
2260
|
+
async function writeJunit(report, destPath) {
|
|
2261
|
+
await promises.mkdir(path__default.default.dirname(destPath), { recursive: true });
|
|
2262
|
+
const cases = report.results.map((r) => {
|
|
2263
|
+
if (r.status === "pass") {
|
|
2264
|
+
return ` <testcase classname="blazediff" name="${escapeXml(r.id)}"/>`;
|
|
2265
|
+
}
|
|
2266
|
+
const message = r.message ?? r.status;
|
|
2267
|
+
return ` <testcase classname="blazediff" name="${escapeXml(r.id)}">
|
|
2268
|
+
<failure message="${escapeXml(message)}" type="${escapeXml(r.status)}">${escapeXml(message)}</failure>
|
|
2269
|
+
</testcase>`;
|
|
2270
|
+
});
|
|
2271
|
+
const failures = report.totalEntries - report.passed;
|
|
2272
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
2273
|
+
<testsuites>
|
|
2274
|
+
<testsuite name="blazediff" tests="${report.totalEntries}" failures="${failures}">
|
|
2275
|
+
${cases.join("\n")}
|
|
2276
|
+
</testsuite>
|
|
2277
|
+
</testsuites>
|
|
2278
|
+
`;
|
|
2279
|
+
await promises.writeFile(destPath, xml, "utf8");
|
|
2280
|
+
return destPath;
|
|
2281
|
+
}
|
|
2282
|
+
var ROOT_NS_SENTINEL = "_root";
|
|
2283
|
+
function nsDir(ns) {
|
|
2284
|
+
return ns === "" ? ROOT_NS_SENTINEL : ns;
|
|
2285
|
+
}
|
|
2286
|
+
function encode(buf) {
|
|
2287
|
+
return Buffer.from(buf).toString("base64");
|
|
2288
|
+
}
|
|
2289
|
+
function decode(s) {
|
|
2290
|
+
return Buffer.from(s, "base64");
|
|
2291
|
+
}
|
|
2292
|
+
async function readJson(file) {
|
|
2293
|
+
try {
|
|
2294
|
+
const raw = await promises.readFile(file, "utf8");
|
|
2295
|
+
return JSON.parse(raw);
|
|
2296
|
+
} catch (err) {
|
|
2297
|
+
if (err.code === "ENOENT") return void 0;
|
|
2298
|
+
throw err;
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
async function writeJsonAtomic(file, value) {
|
|
2302
|
+
const tmp = `${file}.tmp.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2, 8)}`;
|
|
2303
|
+
await promises.writeFile(tmp, JSON.stringify(value), "utf8");
|
|
2304
|
+
await promises.rename(tmp, file);
|
|
2305
|
+
}
|
|
2306
|
+
var FsCheckpointSaver = class extends langgraphCheckpoint.BaseCheckpointSaver {
|
|
2307
|
+
constructor(root, serde) {
|
|
2308
|
+
super(serde);
|
|
2309
|
+
this.locks = /* @__PURE__ */ new Map();
|
|
2310
|
+
this.root = root;
|
|
2311
|
+
}
|
|
2312
|
+
threadDir(thread) {
|
|
2313
|
+
return path__default.default.join(this.root, thread);
|
|
2314
|
+
}
|
|
2315
|
+
nsPath(thread, ns) {
|
|
2316
|
+
return path__default.default.join(this.threadDir(thread), nsDir(ns));
|
|
2317
|
+
}
|
|
2318
|
+
ckptFile(thread, ns, id) {
|
|
2319
|
+
return path__default.default.join(this.nsPath(thread, ns), `${id}.ckpt.json`);
|
|
2320
|
+
}
|
|
2321
|
+
writesFile(thread, ns, id) {
|
|
2322
|
+
return path__default.default.join(this.nsPath(thread, ns), `${id}.writes.json`);
|
|
2323
|
+
}
|
|
2324
|
+
async withLock(key, fn) {
|
|
2325
|
+
const prev = this.locks.get(key) ?? Promise.resolve();
|
|
2326
|
+
const next = prev.then(fn, fn);
|
|
2327
|
+
this.locks.set(key, next);
|
|
2328
|
+
try {
|
|
2329
|
+
return await next;
|
|
2330
|
+
} finally {
|
|
2331
|
+
if (this.locks.get(key) === next) this.locks.delete(key);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
async listCheckpointIds(thread, ns) {
|
|
2335
|
+
try {
|
|
2336
|
+
const names = await promises.readdir(this.nsPath(thread, ns));
|
|
2337
|
+
const suffix = ".ckpt.json";
|
|
2338
|
+
return names.filter((n) => n.endsWith(suffix)).map((n) => n.slice(0, -suffix.length));
|
|
2339
|
+
} catch (err) {
|
|
2340
|
+
if (err.code === "ENOENT") return [];
|
|
2341
|
+
throw err;
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
async listNamespaces(thread) {
|
|
2345
|
+
try {
|
|
2346
|
+
return await promises.readdir(this.threadDir(thread));
|
|
2347
|
+
} catch (err) {
|
|
2348
|
+
if (err.code === "ENOENT") return [];
|
|
2349
|
+
throw err;
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
async listThreads() {
|
|
2353
|
+
try {
|
|
2354
|
+
return await promises.readdir(this.root);
|
|
2355
|
+
} catch (err) {
|
|
2356
|
+
if (err.code === "ENOENT") return [];
|
|
2357
|
+
throw err;
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
decodeNs(nsDirName) {
|
|
2361
|
+
return nsDirName === ROOT_NS_SENTINEL ? "" : nsDirName;
|
|
2362
|
+
}
|
|
2363
|
+
async loadPendingWrites(thread, ns, ckptId) {
|
|
2364
|
+
const data = await readJson(
|
|
2365
|
+
this.writesFile(thread, ns, ckptId)
|
|
2366
|
+
);
|
|
2367
|
+
if (!data) return [];
|
|
2368
|
+
const out = [];
|
|
2369
|
+
for (const [taskId, channel, serialized] of Object.values(data)) {
|
|
2370
|
+
const value = await this.serde.loadsTyped("json", decode(serialized));
|
|
2371
|
+
out.push([taskId, channel, value]);
|
|
2372
|
+
}
|
|
2373
|
+
return out;
|
|
2374
|
+
}
|
|
2375
|
+
async migratePendingSends(checkpoint, thread, ns, parentCheckpointId) {
|
|
2376
|
+
const data = await readJson(
|
|
2377
|
+
this.writesFile(thread, ns, parentCheckpointId)
|
|
2378
|
+
);
|
|
2379
|
+
const pendingSends = data ? await Promise.all(
|
|
2380
|
+
Object.values(data).filter(([, channel]) => channel === langgraphCheckpoint.TASKS).map(
|
|
2381
|
+
([, , serialized]) => this.serde.loadsTyped("json", decode(serialized))
|
|
2382
|
+
)
|
|
2383
|
+
) : [];
|
|
2384
|
+
const m = checkpoint;
|
|
2385
|
+
m.channel_values ?? (m.channel_values = {});
|
|
2386
|
+
m.channel_values[langgraphCheckpoint.TASKS] = pendingSends;
|
|
2387
|
+
m.channel_versions ?? (m.channel_versions = {});
|
|
2388
|
+
const versions = Object.values(m.channel_versions);
|
|
2389
|
+
m.channel_versions[langgraphCheckpoint.TASKS] = versions.length > 0 ? langgraphCheckpoint.maxChannelVersion(...versions) : this.getNextVersion(void 0);
|
|
2390
|
+
}
|
|
2391
|
+
async readTuple(thread, ns, ckptId, config) {
|
|
2392
|
+
const data = await readJson(this.ckptFile(thread, ns, ckptId));
|
|
2393
|
+
if (!data) return void 0;
|
|
2394
|
+
const checkpoint = await this.serde.loadsTyped(
|
|
2395
|
+
"json",
|
|
2396
|
+
decode(data.checkpoint)
|
|
2397
|
+
);
|
|
2398
|
+
const metadata = await this.serde.loadsTyped(
|
|
2399
|
+
"json",
|
|
2400
|
+
decode(data.metadata)
|
|
2401
|
+
);
|
|
2402
|
+
if (checkpoint.v < 4 && data.parentCheckpointId !== void 0) {
|
|
2403
|
+
await this.migratePendingSends(
|
|
2404
|
+
checkpoint,
|
|
2405
|
+
thread,
|
|
2406
|
+
ns,
|
|
2407
|
+
data.parentCheckpointId
|
|
2408
|
+
);
|
|
2409
|
+
}
|
|
2410
|
+
const pendingWrites = await this.loadPendingWrites(thread, ns, ckptId);
|
|
2411
|
+
const tuple = {
|
|
2412
|
+
config,
|
|
2413
|
+
checkpoint,
|
|
2414
|
+
metadata,
|
|
2415
|
+
pendingWrites
|
|
2416
|
+
};
|
|
2417
|
+
if (data.parentCheckpointId !== void 0) {
|
|
2418
|
+
tuple.parentConfig = {
|
|
2419
|
+
configurable: {
|
|
2420
|
+
thread_id: thread,
|
|
2421
|
+
checkpoint_ns: ns,
|
|
2422
|
+
checkpoint_id: data.parentCheckpointId
|
|
2423
|
+
}
|
|
2424
|
+
};
|
|
2425
|
+
}
|
|
2426
|
+
return tuple;
|
|
2427
|
+
}
|
|
2428
|
+
async getTuple(config) {
|
|
2429
|
+
const thread = config.configurable?.thread_id;
|
|
2430
|
+
if (!thread) return void 0;
|
|
2431
|
+
const ns = config.configurable?.checkpoint_ns ?? "";
|
|
2432
|
+
const explicitId = langgraphCheckpoint.getCheckpointId(config);
|
|
2433
|
+
if (explicitId) {
|
|
2434
|
+
return this.readTuple(thread, ns, explicitId, config);
|
|
2435
|
+
}
|
|
2436
|
+
const ids = (await this.listCheckpointIds(thread, ns)).sort(
|
|
2437
|
+
(a, b) => b.localeCompare(a)
|
|
2438
|
+
);
|
|
2439
|
+
if (ids.length === 0) return void 0;
|
|
2440
|
+
const ckptId = ids[0];
|
|
2441
|
+
return this.readTuple(thread, ns, ckptId, {
|
|
2442
|
+
configurable: {
|
|
2443
|
+
thread_id: thread,
|
|
2444
|
+
checkpoint_ns: ns,
|
|
2445
|
+
checkpoint_id: ckptId
|
|
1905
2446
|
}
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
async *list(config, options) {
|
|
2450
|
+
const filter = options?.filter;
|
|
2451
|
+
const before = options?.before;
|
|
2452
|
+
let limit = options?.limit;
|
|
2453
|
+
const configThread = config.configurable?.thread_id;
|
|
2454
|
+
const configNs = config.configurable?.checkpoint_ns;
|
|
2455
|
+
const configCkptId = config.configurable?.checkpoint_id;
|
|
2456
|
+
const threads = configThread ? [configThread] : await this.listThreads();
|
|
2457
|
+
for (const thread of threads) {
|
|
2458
|
+
const nsNames = await this.listNamespaces(thread);
|
|
2459
|
+
for (const nsName of nsNames) {
|
|
2460
|
+
const ns = this.decodeNs(nsName);
|
|
2461
|
+
if (configNs !== void 0 && ns !== configNs) continue;
|
|
2462
|
+
const ids = (await this.listCheckpointIds(thread, ns)).sort(
|
|
2463
|
+
(a, b) => b.localeCompare(a)
|
|
1913
2464
|
);
|
|
1914
|
-
|
|
1915
|
-
|
|
2465
|
+
for (const ckptId of ids) {
|
|
2466
|
+
if (configCkptId && ckptId !== configCkptId) continue;
|
|
2467
|
+
if (before?.configurable?.checkpoint_id && ckptId >= before.configurable.checkpoint_id)
|
|
2468
|
+
continue;
|
|
2469
|
+
const tuple = await this.readTuple(thread, ns, ckptId, {
|
|
2470
|
+
configurable: {
|
|
2471
|
+
thread_id: thread,
|
|
2472
|
+
checkpoint_ns: ns,
|
|
2473
|
+
checkpoint_id: ckptId
|
|
2474
|
+
}
|
|
2475
|
+
});
|
|
2476
|
+
if (!tuple) continue;
|
|
2477
|
+
if (filter) {
|
|
2478
|
+
const md = tuple.metadata;
|
|
2479
|
+
const matches = Object.entries(filter).every(
|
|
2480
|
+
([k, v]) => md?.[k] === v
|
|
2481
|
+
);
|
|
2482
|
+
if (!matches) continue;
|
|
2483
|
+
}
|
|
2484
|
+
if (limit !== void 0) {
|
|
2485
|
+
if (limit <= 0) return;
|
|
2486
|
+
limit -= 1;
|
|
2487
|
+
}
|
|
2488
|
+
yield tuple;
|
|
2489
|
+
}
|
|
1916
2490
|
}
|
|
1917
|
-
}
|
|
1918
|
-
);
|
|
1919
|
-
let entries;
|
|
1920
|
-
try {
|
|
1921
|
-
entries = await promises.readdir(root);
|
|
1922
|
-
} catch {
|
|
1923
|
-
return;
|
|
2491
|
+
}
|
|
1924
2492
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
2493
|
+
async put(config, checkpoint, metadata) {
|
|
2494
|
+
const thread = config.configurable?.thread_id;
|
|
2495
|
+
if (!thread) {
|
|
2496
|
+
throw new Error(
|
|
2497
|
+
'FsCheckpointSaver: missing "thread_id" in configurable. Pass `{ configurable: { thread_id } }` when streaming.'
|
|
2498
|
+
);
|
|
2499
|
+
}
|
|
2500
|
+
const ns = config.configurable?.checkpoint_ns ?? "";
|
|
2501
|
+
const parentCheckpointId = config.configurable?.checkpoint_id;
|
|
2502
|
+
const prepared = langgraphCheckpoint.copyCheckpoint(checkpoint);
|
|
2503
|
+
const [[, serializedCheckpoint], [, serializedMetadata]] = await Promise.all([
|
|
2504
|
+
this.serde.dumpsTyped(prepared),
|
|
2505
|
+
this.serde.dumpsTyped(metadata)
|
|
2506
|
+
]);
|
|
2507
|
+
await promises.mkdir(this.nsPath(thread, ns), { recursive: true });
|
|
2508
|
+
const file = this.ckptFile(thread, ns, checkpoint.id);
|
|
2509
|
+
const body = {
|
|
2510
|
+
checkpoint: encode(serializedCheckpoint),
|
|
2511
|
+
metadata: encode(serializedMetadata),
|
|
2512
|
+
parentCheckpointId
|
|
2513
|
+
};
|
|
2514
|
+
await writeJsonAtomic(file, body);
|
|
2515
|
+
return {
|
|
2516
|
+
configurable: {
|
|
2517
|
+
thread_id: thread,
|
|
2518
|
+
checkpoint_ns: ns,
|
|
2519
|
+
checkpoint_id: checkpoint.id
|
|
2520
|
+
}
|
|
2521
|
+
};
|
|
1939
2522
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
const cases = report.results.map((r) => {
|
|
1947
|
-
if (r.status === "pass") {
|
|
1948
|
-
return ` <testcase classname="blazediff" name="${escapeXml(r.id)}"/>`;
|
|
2523
|
+
async putWrites(config, writes, taskId) {
|
|
2524
|
+
const thread = config.configurable?.thread_id;
|
|
2525
|
+
if (!thread) {
|
|
2526
|
+
throw new Error(
|
|
2527
|
+
'FsCheckpointSaver: missing "thread_id" in configurable for putWrites.'
|
|
2528
|
+
);
|
|
1949
2529
|
}
|
|
1950
|
-
const
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
2530
|
+
const ns = config.configurable?.checkpoint_ns ?? "";
|
|
2531
|
+
const ckptId = config.configurable?.checkpoint_id;
|
|
2532
|
+
if (!ckptId) {
|
|
2533
|
+
throw new Error(
|
|
2534
|
+
'FsCheckpointSaver: missing "checkpoint_id" in configurable for putWrites.'
|
|
2535
|
+
);
|
|
2536
|
+
}
|
|
2537
|
+
const key = `${thread}|${ns}|${ckptId}`;
|
|
2538
|
+
await this.withLock(key, async () => {
|
|
2539
|
+
const existing = await readJson(this.writesFile(thread, ns, ckptId)) ?? {};
|
|
2540
|
+
let mutated = false;
|
|
2541
|
+
for (let idx = 0; idx < writes.length; idx++) {
|
|
2542
|
+
const [channel, value] = writes[idx];
|
|
2543
|
+
const writeIdx = langgraphCheckpoint.WRITES_IDX_MAP[channel] ?? idx;
|
|
2544
|
+
const innerKey = `${taskId},${writeIdx}`;
|
|
2545
|
+
if (writeIdx >= 0 && innerKey in existing) continue;
|
|
2546
|
+
const [, serialized] = await this.serde.dumpsTyped(value);
|
|
2547
|
+
existing[innerKey] = [taskId, channel, encode(serialized)];
|
|
2548
|
+
mutated = true;
|
|
2549
|
+
}
|
|
2550
|
+
if (!mutated) return;
|
|
2551
|
+
await promises.mkdir(this.nsPath(thread, ns), { recursive: true });
|
|
2552
|
+
await writeJsonAtomic(this.writesFile(thread, ns, ckptId), existing);
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2555
|
+
async deleteThread(threadId) {
|
|
2556
|
+
await promises.rm(this.threadDir(threadId), { recursive: true, force: true });
|
|
2557
|
+
}
|
|
2558
|
+
};
|
|
2559
|
+
|
|
2560
|
+
// src/graph/events.ts
|
|
2561
|
+
var sink;
|
|
2562
|
+
function setEventSink(fn) {
|
|
2563
|
+
sink = fn;
|
|
2564
|
+
}
|
|
2565
|
+
function emitEvent(event) {
|
|
2566
|
+
sink?.(event);
|
|
1965
2567
|
}
|
|
1966
2568
|
|
|
1967
2569
|
// src/graph/nodes/results.ts
|
|
@@ -2016,6 +2618,8 @@ function failResult(entry, outcome, actualPath, baselinePath, verdict) {
|
|
|
2016
2618
|
diffPercentage: outcome.diffPercentage,
|
|
2017
2619
|
severity: outcome.interpretation?.severity,
|
|
2018
2620
|
regions: outcome.interpretation?.regions?.map(narrowRegion),
|
|
2621
|
+
width: outcome.interpretation?.width,
|
|
2622
|
+
height: outcome.interpretation?.height,
|
|
2019
2623
|
verdict,
|
|
2020
2624
|
diffPath: outcome.diffPath,
|
|
2021
2625
|
baselinePath,
|
|
@@ -2124,6 +2728,10 @@ function makeCaptureNode(semaphore) {
|
|
|
2124
2728
|
);
|
|
2125
2729
|
}
|
|
2126
2730
|
}
|
|
2731
|
+
for (const item of items) {
|
|
2732
|
+
if (item.output.captureOutputPath)
|
|
2733
|
+
emitEvent({ type: "captured", entryId: item.entry.id });
|
|
2734
|
+
}
|
|
2127
2735
|
return { captured: items };
|
|
2128
2736
|
} catch (err) {
|
|
2129
2737
|
if (err instanceof HarnessError) {
|
|
@@ -2352,6 +2960,7 @@ async function judgeNode(state) {
|
|
|
2352
2960
|
throw new Error("judgeNode: entry, options, or diff missing");
|
|
2353
2961
|
}
|
|
2354
2962
|
if (diff.skipResult) {
|
|
2963
|
+
emitEvent({ type: "result", result: diff.skipResult });
|
|
2355
2964
|
return { results: [diff.skipResult] };
|
|
2356
2965
|
}
|
|
2357
2966
|
const outcome = diff.outcome;
|
|
@@ -2361,7 +2970,9 @@ async function judgeNode(state) {
|
|
|
2361
2970
|
throw new Error("judgeNode: diff outputs missing");
|
|
2362
2971
|
}
|
|
2363
2972
|
if (outcome.match) {
|
|
2364
|
-
|
|
2973
|
+
const r = passResult(entry, baselinePath, captureOutputPath);
|
|
2974
|
+
emitEvent({ type: "result", result: r });
|
|
2975
|
+
return { results: [r] };
|
|
2365
2976
|
}
|
|
2366
2977
|
const verdict = deriveVerdict({
|
|
2367
2978
|
reason: outcome.reason,
|
|
@@ -2369,48 +2980,62 @@ async function judgeNode(state) {
|
|
|
2369
2980
|
diffCount: outcome.diffCount,
|
|
2370
2981
|
diffPercentage: outcome.diffPercentage
|
|
2371
2982
|
});
|
|
2372
|
-
|
|
2983
|
+
const initial = failResult(
|
|
2373
2984
|
entry,
|
|
2374
2985
|
outcome,
|
|
2375
2986
|
captureOutputPath,
|
|
2376
2987
|
baselinePath,
|
|
2377
2988
|
verdict
|
|
2378
2989
|
);
|
|
2379
|
-
if (
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2990
|
+
if (!initial.baselinePath || !initial.actualPath) {
|
|
2991
|
+
emitEvent({ type: "result", result: initial });
|
|
2992
|
+
return { results: [initial] };
|
|
2993
|
+
}
|
|
2994
|
+
const judge = resolveJudge(options.judge);
|
|
2995
|
+
const output = await judge.judge(
|
|
2996
|
+
{
|
|
2997
|
+
entry,
|
|
2998
|
+
baselinePath: initial.baselinePath,
|
|
2999
|
+
actualPath: initial.actualPath,
|
|
3000
|
+
diffPath: initial.diffPath,
|
|
3001
|
+
regions: initial.regions,
|
|
3002
|
+
diffPercentage: initial.diffPercentage,
|
|
3003
|
+
severity: initial.severity,
|
|
3004
|
+
heuristicVerdict: initial.verdict ?? verdict,
|
|
3005
|
+
onJudgingStart: options.judge !== "none" ? () => emitEvent({ type: "judging", entryId: entry.id, url: entry.url }) : void 0
|
|
3006
|
+
},
|
|
3007
|
+
options.cwd
|
|
3008
|
+
);
|
|
3009
|
+
let final;
|
|
3010
|
+
if (output.kind === "judged") {
|
|
3011
|
+
final = { ...initial, verdict: output.verdict };
|
|
3012
|
+
} else if (output.kind === "failed") {
|
|
3013
|
+
console.warn(
|
|
3014
|
+
`[blazediff] judge "${judge.name}" failed for ${entry.id} (${output.reason}): ${output.error.message}`
|
|
2393
3015
|
);
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
3016
|
+
final = {
|
|
3017
|
+
...initial,
|
|
3018
|
+
verdict: output.fallback,
|
|
3019
|
+
message: `${initial.message ?? ""}${initial.message ? " \u2014 " : ""}judge failed (${output.reason}): ${output.error.message}`
|
|
3020
|
+
};
|
|
3021
|
+
} else {
|
|
3022
|
+
const pending = {
|
|
3023
|
+
...initial,
|
|
3024
|
+
status: "needs-judgment",
|
|
3025
|
+
message: `awaiting judgment in ${output.requestPath}`
|
|
3026
|
+
};
|
|
3027
|
+
const resumed = interruptForJudgment({
|
|
3028
|
+
kind: "host-judgment-required",
|
|
3029
|
+
entryId: entry.id,
|
|
3030
|
+
url: entry.url,
|
|
3031
|
+
requestPath: output.requestPath,
|
|
3032
|
+
signature: signatureOf(initial),
|
|
3033
|
+
pendingResult: pending
|
|
3034
|
+
});
|
|
3035
|
+
final = resumed ? { ...initial, verdict: resumed } : pending;
|
|
2412
3036
|
}
|
|
2413
|
-
|
|
3037
|
+
emitEvent({ type: "result", result: final });
|
|
3038
|
+
return { results: [final] };
|
|
2414
3039
|
}
|
|
2415
3040
|
|
|
2416
3041
|
// src/graph/nodes/load.ts
|
|
@@ -2421,80 +3046,51 @@ async function loadNode(state) {
|
|
|
2421
3046
|
const manifest = await loadManifest(state.options.cwd);
|
|
2422
3047
|
if (!manifest) {
|
|
2423
3048
|
throw new Error(
|
|
2424
|
-
`no manifest found at ${paths(state.options.cwd).manifest}. Run \`blazediff
|
|
3049
|
+
`no manifest found at ${paths(state.options.cwd).manifest}. Run \`blazediff-agent onboard\` then \`/blazediff\` (or capture manually) first.`
|
|
2425
3050
|
);
|
|
2426
3051
|
}
|
|
2427
3052
|
return { entries: manifest.entries, manifest };
|
|
2428
3053
|
}
|
|
2429
|
-
var
|
|
3054
|
+
var latest = () => langgraph.Annotation({
|
|
3055
|
+
reducer: (acc, next) => next ?? acc,
|
|
3056
|
+
default: () => void 0
|
|
3057
|
+
});
|
|
3058
|
+
var appendList = () => langgraph.Annotation({
|
|
2430
3059
|
reducer: (acc, next) => [...acc, ...next],
|
|
2431
3060
|
default: () => []
|
|
2432
3061
|
});
|
|
2433
|
-
var
|
|
2434
|
-
reducer: (acc, next) =>
|
|
3062
|
+
var replaceList = () => langgraph.Annotation({
|
|
3063
|
+
reducer: (acc, next) => next ?? acc,
|
|
2435
3064
|
default: () => []
|
|
2436
3065
|
});
|
|
3066
|
+
var resultsChannel = appendList();
|
|
3067
|
+
var capturedChannel = appendList();
|
|
2437
3068
|
var CaptureState = langgraph.Annotation.Root({
|
|
2438
|
-
entry:
|
|
2439
|
-
reducer: (_, next) => next,
|
|
2440
|
-
default: () => void 0
|
|
2441
|
-
}),
|
|
3069
|
+
entry: latest(),
|
|
2442
3070
|
children: langgraph.Annotation({
|
|
2443
3071
|
reducer: (_, next) => next,
|
|
2444
3072
|
default: () => []
|
|
2445
3073
|
}),
|
|
2446
|
-
options:
|
|
2447
|
-
reducer: (acc, next) => next ?? acc,
|
|
2448
|
-
default: () => void 0
|
|
2449
|
-
}),
|
|
3074
|
+
options: latest(),
|
|
2450
3075
|
captured: capturedChannel
|
|
2451
3076
|
});
|
|
2452
3077
|
var BranchState = langgraph.Annotation.Root({
|
|
2453
|
-
entry:
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
options: langgraph.Annotation({
|
|
2458
|
-
reducer: (acc, next) => next ?? acc,
|
|
2459
|
-
default: () => void 0
|
|
2460
|
-
}),
|
|
2461
|
-
captureOutput: langgraph.Annotation({
|
|
2462
|
-
reducer: (_, next) => next,
|
|
2463
|
-
default: () => void 0
|
|
2464
|
-
}),
|
|
2465
|
-
diffOutput: langgraph.Annotation({
|
|
2466
|
-
reducer: (_, next) => next,
|
|
2467
|
-
default: () => void 0
|
|
2468
|
-
}),
|
|
3078
|
+
entry: latest(),
|
|
3079
|
+
options: latest(),
|
|
3080
|
+
captureOutput: latest(),
|
|
3081
|
+
diffOutput: latest(),
|
|
2469
3082
|
results: resultsChannel
|
|
2470
3083
|
});
|
|
2471
3084
|
var GraphState = langgraph.Annotation.Root({
|
|
2472
|
-
options:
|
|
2473
|
-
|
|
2474
|
-
default: () => void 0
|
|
2475
|
-
}),
|
|
2476
|
-
entries: langgraph.Annotation({
|
|
2477
|
-
reducer: (acc, next) => next ?? acc,
|
|
2478
|
-
default: () => []
|
|
2479
|
-
}),
|
|
3085
|
+
options: latest(),
|
|
3086
|
+
entries: replaceList(),
|
|
2480
3087
|
captured: capturedChannel,
|
|
2481
3088
|
results: resultsChannel,
|
|
2482
|
-
manifest:
|
|
2483
|
-
|
|
2484
|
-
default: () => void 0
|
|
2485
|
-
}),
|
|
2486
|
-
report: langgraph.Annotation({
|
|
2487
|
-
reducer: (acc, next) => next ?? acc,
|
|
2488
|
-
default: () => void 0
|
|
2489
|
-
})
|
|
3089
|
+
manifest: latest(),
|
|
3090
|
+
report: latest()
|
|
2490
3091
|
});
|
|
2491
3092
|
|
|
2492
3093
|
// src/graph/index.ts
|
|
2493
|
-
function cpuParallelism() {
|
|
2494
|
-
const cores = typeof os.availableParallelism === "function" ? os.availableParallelism() : os.cpus().length;
|
|
2495
|
-
if (!cores || !Number.isFinite(cores)) return 2;
|
|
2496
|
-
return Math.max(2, cores);
|
|
2497
|
-
}
|
|
2498
3094
|
function threadIdFor(cwd) {
|
|
2499
3095
|
return crypto$1.createHash("sha1").update(paths(cwd).manifest).digest("hex").slice(0, 16);
|
|
2500
3096
|
}
|
|
@@ -2504,7 +3100,8 @@ function buildCaptureGraph(captureSemaphore) {
|
|
|
2504
3100
|
function buildBranchGraph(diffSemaphore) {
|
|
2505
3101
|
return new langgraph.StateGraph(BranchState).addNode("diff", makeDiffNode(diffSemaphore)).addNode("judge", judgeNode).addEdge(langgraph.START, "diff").addEdge("diff", "judge").addEdge("judge", langgraph.END).compile();
|
|
2506
3102
|
}
|
|
2507
|
-
function dispatchNode() {
|
|
3103
|
+
async function dispatchNode(state) {
|
|
3104
|
+
if (state.options) await resolveJudge(state.options.judge).warmup?.();
|
|
2508
3105
|
return {};
|
|
2509
3106
|
}
|
|
2510
3107
|
function buildGraph(captureSemaphore, diffSemaphore, checkpointer) {
|
|
@@ -2557,10 +3154,7 @@ async function streamGraph(graph, input, threadId, onEvent) {
|
|
|
2557
3154
|
const part = partial;
|
|
2558
3155
|
if (!part) continue;
|
|
2559
3156
|
if (part.results) {
|
|
2560
|
-
for (const r of part.results)
|
|
2561
|
-
collect.results.push(r);
|
|
2562
|
-
onEvent?.({ type: "result", result: r });
|
|
2563
|
-
}
|
|
3157
|
+
for (const r of part.results) collect.results.push(r);
|
|
2564
3158
|
}
|
|
2565
3159
|
if (part.manifest) collect.manifest = part.manifest;
|
|
2566
3160
|
if (part.report) {
|
|
@@ -2594,15 +3188,15 @@ async function buildPartialReport(collect, cwd) {
|
|
|
2594
3188
|
if (manifest) {
|
|
2595
3189
|
await writeJudgments({ report, manifest, cwd });
|
|
2596
3190
|
}
|
|
2597
|
-
await
|
|
3191
|
+
await writeReport(report, cwd);
|
|
2598
3192
|
await ensureGitignore(cwd);
|
|
2599
3193
|
return report;
|
|
2600
3194
|
}
|
|
2601
3195
|
async function runGraph(opts) {
|
|
2602
3196
|
const cwd = opts.cwd ?? process.cwd();
|
|
2603
3197
|
const concurrency = opts.concurrency ?? defaultConcurrency();
|
|
2604
|
-
const captureSemaphore =
|
|
2605
|
-
const diffSemaphore =
|
|
3198
|
+
const captureSemaphore = createSemaphore(concurrency);
|
|
3199
|
+
const diffSemaphore = createSemaphore(cpuCores());
|
|
2606
3200
|
const baselinesDir = paths(cwd).baselines;
|
|
2607
3201
|
const checkpointer = new FsCheckpointSaver(paths(cwd).checkpoints);
|
|
2608
3202
|
const graph = buildGraph(captureSemaphore, diffSemaphore, checkpointer);
|
|
@@ -2622,9 +3216,11 @@ async function runGraph(opts) {
|
|
|
2622
3216
|
}
|
|
2623
3217
|
};
|
|
2624
3218
|
let collect;
|
|
3219
|
+
setEventSink(opts.onEvent);
|
|
2625
3220
|
try {
|
|
2626
3221
|
collect = await streamGraph(graph, input, threadId, opts.onEvent);
|
|
2627
3222
|
} finally {
|
|
3223
|
+
setEventSink(void 0);
|
|
2628
3224
|
await closeBrowser();
|
|
2629
3225
|
}
|
|
2630
3226
|
const report = collect.report ?? await buildPartialReport(collect, cwd);
|
|
@@ -2650,9 +3246,126 @@ function runCheck(opts) {
|
|
|
2650
3246
|
return runGraph(opts);
|
|
2651
3247
|
}
|
|
2652
3248
|
|
|
3249
|
+
// src/review/map.ts
|
|
3250
|
+
var DEFAULT_DIMS = { width: 1280, height: 800 };
|
|
3251
|
+
function mapLabelToClass(label) {
|
|
3252
|
+
switch (label) {
|
|
3253
|
+
case "regression-likely":
|
|
3254
|
+
return "regression";
|
|
3255
|
+
case "ambiguous":
|
|
3256
|
+
return "layout-shift";
|
|
3257
|
+
default:
|
|
3258
|
+
return "intentional-likely";
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
function mapRegion(region, index) {
|
|
3262
|
+
return {
|
|
3263
|
+
id: index + 1,
|
|
3264
|
+
bbox: {
|
|
3265
|
+
x: region.bbox.x,
|
|
3266
|
+
y: region.bbox.y,
|
|
3267
|
+
w: region.bbox.width,
|
|
3268
|
+
h: region.bbox.height
|
|
3269
|
+
},
|
|
3270
|
+
kind: region.changeType,
|
|
3271
|
+
pixels: region.pixelCount,
|
|
3272
|
+
change: region.percentage
|
|
3273
|
+
};
|
|
3274
|
+
}
|
|
3275
|
+
function reviewStatus(r) {
|
|
3276
|
+
if (r.review === "approved") return "approved";
|
|
3277
|
+
if (r.review === "rejected") return "rejected";
|
|
3278
|
+
return "unreviewed";
|
|
3279
|
+
}
|
|
3280
|
+
function mapResultToEntry(r) {
|
|
3281
|
+
return {
|
|
3282
|
+
id: r.id,
|
|
3283
|
+
name: r.id,
|
|
3284
|
+
url: r.url,
|
|
3285
|
+
width: r.width ?? DEFAULT_DIMS.width,
|
|
3286
|
+
height: r.height ?? DEFAULT_DIMS.height,
|
|
3287
|
+
diff: r.diffPercentage ?? 0,
|
|
3288
|
+
classification: mapLabelToClass(r.verdict?.label),
|
|
3289
|
+
severity: r.severity ?? "low",
|
|
3290
|
+
action: r.verdict?.action ?? "investigate",
|
|
3291
|
+
summary: r.verdict?.headline ?? r.message ?? r.status,
|
|
3292
|
+
changes: r.verdict?.rationale ?? [],
|
|
3293
|
+
regions: (r.regions ?? []).map(mapRegion),
|
|
3294
|
+
status: reviewStatus(r),
|
|
3295
|
+
reviewedBy: r.review ? "you" : void 0
|
|
3296
|
+
};
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
// src/review/actions.ts
|
|
3300
|
+
function recountReport(report) {
|
|
3301
|
+
const passed = report.results.filter((r) => r.status === "pass").length;
|
|
3302
|
+
const pending = report.results.filter(
|
|
3303
|
+
(r) => r.status === "needs-judgment"
|
|
3304
|
+
).length;
|
|
3305
|
+
report.passed = passed;
|
|
3306
|
+
report.pendingJudgments = pending;
|
|
3307
|
+
report.failed = report.results.length - passed - pending;
|
|
3308
|
+
}
|
|
3309
|
+
async function approveEntry(id, cwd = process.cwd()) {
|
|
3310
|
+
const p = paths(cwd);
|
|
3311
|
+
const actualPng = path__default.default.join(p.actual, `${id}.png`);
|
|
3312
|
+
if (!fs.existsSync(actualPng)) return null;
|
|
3313
|
+
await promises.mkdir(p.baselines, { recursive: true });
|
|
3314
|
+
await promises.copyFile(actualPng, path__default.default.join(p.baselines, `${id}.png`));
|
|
3315
|
+
await Promise.all([
|
|
3316
|
+
promises.rm(actualPng, { force: true }),
|
|
3317
|
+
promises.rm(path__default.default.join(p.actual, `${id}.diff.png`), { force: true }),
|
|
3318
|
+
promises.rm(path__default.default.join(p.judgments, id), { recursive: true, force: true })
|
|
3319
|
+
]);
|
|
3320
|
+
const report = await readReport(cwd);
|
|
3321
|
+
const result = report?.results.find((r) => r.id === id);
|
|
3322
|
+
if (!report || !result) return null;
|
|
3323
|
+
result.status = "pass";
|
|
3324
|
+
result.review = "approved";
|
|
3325
|
+
result.diffPercentage = void 0;
|
|
3326
|
+
result.diffCount = void 0;
|
|
3327
|
+
result.regions = void 0;
|
|
3328
|
+
result.verdict = void 0;
|
|
3329
|
+
result.diffPath = void 0;
|
|
3330
|
+
recountReport(report);
|
|
3331
|
+
await writeReport(report, cwd);
|
|
3332
|
+
return mapResultToEntry(result);
|
|
3333
|
+
}
|
|
3334
|
+
async function rejectEntry(id, cwd = process.cwd()) {
|
|
3335
|
+
const report = await readReport(cwd);
|
|
3336
|
+
const result = report?.results.find((r) => r.id === id);
|
|
3337
|
+
if (!report || !result) return null;
|
|
3338
|
+
const verdict = {
|
|
3339
|
+
label: "regression-likely",
|
|
3340
|
+
headline: result.verdict?.headline ?? "Confirmed regression during review",
|
|
3341
|
+
rationale: result.verdict?.rationale ?? [],
|
|
3342
|
+
action: "investigate"
|
|
3343
|
+
};
|
|
3344
|
+
const p = paths(cwd);
|
|
3345
|
+
const dir = path__default.default.join(p.judgments, id);
|
|
3346
|
+
await promises.mkdir(dir, { recursive: true });
|
|
3347
|
+
await promises.writeFile(
|
|
3348
|
+
path__default.default.join(dir, "verdict.json"),
|
|
3349
|
+
`${JSON.stringify({ id, verdict, rationale: "rejected via review" }, null, 2)}
|
|
3350
|
+
`,
|
|
3351
|
+
"utf8"
|
|
3352
|
+
);
|
|
3353
|
+
const updated = {
|
|
3354
|
+
...result,
|
|
3355
|
+
status: "fail",
|
|
3356
|
+
review: "rejected",
|
|
3357
|
+
verdict
|
|
3358
|
+
};
|
|
3359
|
+
report.results = report.results.map((r) => r.id === id ? updated : r);
|
|
3360
|
+
recountReport(report);
|
|
3361
|
+
await writeReport(report, cwd);
|
|
3362
|
+
return mapResultToEntry(updated);
|
|
3363
|
+
}
|
|
3364
|
+
|
|
2653
3365
|
exports.HarnessError = HarnessError;
|
|
2654
3366
|
exports.STABILITY_HOOKS_VERSION = STABILITY_HOOKS_VERSION;
|
|
2655
3367
|
exports.applyJudgments = applyJudgments;
|
|
3368
|
+
exports.approveEntry = approveEntry;
|
|
2656
3369
|
exports.assertLeftLoginPage = assertLeftLoginPage;
|
|
2657
3370
|
exports.captureScreenshot = captureScreenshot;
|
|
2658
3371
|
exports.configHash = configHash;
|
|
@@ -2664,6 +3377,8 @@ exports.loadEnvFiles = loadEnvFiles;
|
|
|
2664
3377
|
exports.loadHarness = loadHarness;
|
|
2665
3378
|
exports.loadManifest = loadManifest;
|
|
2666
3379
|
exports.paths = paths;
|
|
3380
|
+
exports.readReport = readReport;
|
|
3381
|
+
exports.rejectEntry = rejectEntry;
|
|
2667
3382
|
exports.resolveBaseUrl = resolveBaseUrl;
|
|
2668
3383
|
exports.resolveHarnessFile = resolveHarnessFile;
|
|
2669
3384
|
exports.resolveJudge = resolveJudge;
|
|
@@ -2674,3 +3389,4 @@ exports.runGraph = runGraph;
|
|
|
2674
3389
|
exports.saveConfig = saveConfig;
|
|
2675
3390
|
exports.saveManifest = saveManifest;
|
|
2676
3391
|
exports.threadIdFor = threadIdFor;
|
|
3392
|
+
exports.writeReport = writeReport;
|