@blazediff/agent 0.2.1 → 0.3.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 +36 -12
- package/SKILL.md +56 -10
- package/dist/cli.js +598 -397
- package/dist/index.d.mts +79 -12
- package/dist/index.d.ts +79 -12
- package/dist/index.js +429 -191
- package/dist/index.mjs +407 -193
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
var promises = require('fs/promises');
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var os = require('os');
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var url = require('url');
|
|
6
8
|
var playwright = require('playwright');
|
|
7
9
|
var child_process = require('child_process');
|
|
8
|
-
var fs = require('fs');
|
|
9
10
|
var module$1 = require('module');
|
|
10
|
-
var url = require('url');
|
|
11
11
|
var crypto$1 = require('crypto');
|
|
12
12
|
var coreNative = require('@blazediff/core-native');
|
|
13
|
+
var util = require('util');
|
|
13
14
|
var langgraph = require('@langchain/langgraph');
|
|
14
15
|
var sharp = require('sharp');
|
|
15
16
|
var langgraphCheckpoint = require('@langchain/langgraph-checkpoint');
|
|
@@ -17,7 +18,26 @@ var langgraphCheckpoint = require('@langchain/langgraph-checkpoint');
|
|
|
17
18
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
18
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
20
|
|
|
21
|
+
function _interopNamespace(e) {
|
|
22
|
+
if (e && e.__esModule) return e;
|
|
23
|
+
var n = Object.create(null);
|
|
24
|
+
if (e) {
|
|
25
|
+
Object.keys(e).forEach(function (k) {
|
|
26
|
+
if (k !== 'default') {
|
|
27
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
28
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return e[k]; }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
n.default = e;
|
|
36
|
+
return Object.freeze(n);
|
|
37
|
+
}
|
|
38
|
+
|
|
20
39
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
40
|
+
var util__namespace = /*#__PURE__*/_interopNamespace(util);
|
|
21
41
|
var sharp__default = /*#__PURE__*/_interopDefault(sharp);
|
|
22
42
|
|
|
23
43
|
// src/browser/capture.ts
|
|
@@ -42,6 +62,8 @@ var paths = (cwd = process.cwd()) => {
|
|
|
42
62
|
root,
|
|
43
63
|
config: path__default.default.join(root, "config.json"),
|
|
44
64
|
manifest: path__default.default.join(root, "manifest.json"),
|
|
65
|
+
harnesses: path__default.default.join(root, "harnesses"),
|
|
66
|
+
authHarness: path__default.default.join(root, "harnesses", "auth.js"),
|
|
45
67
|
baselines: path__default.default.join(root, "baselines"),
|
|
46
68
|
actual: path__default.default.join(root, "actual"),
|
|
47
69
|
judgments: path__default.default.join(root, "judgments"),
|
|
@@ -52,6 +74,90 @@ var paths = (cwd = process.cwd()) => {
|
|
|
52
74
|
serverPid: path__default.default.join(root, "dev-server.pid")
|
|
53
75
|
};
|
|
54
76
|
};
|
|
77
|
+
|
|
78
|
+
// src/harness/loader.ts
|
|
79
|
+
var HarnessError = class extends Error {
|
|
80
|
+
constructor(message, cause) {
|
|
81
|
+
super(message);
|
|
82
|
+
this.cause = cause;
|
|
83
|
+
this.name = "HarnessError";
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var moduleCache = /* @__PURE__ */ new Map();
|
|
87
|
+
function resolveHarnessFile(name, cwd) {
|
|
88
|
+
if (name.includes("/") || name.includes("\\") || path__default.default.isAbsolute(name)) {
|
|
89
|
+
return path__default.default.isAbsolute(name) ? name : path__default.default.resolve(cwd, name);
|
|
90
|
+
}
|
|
91
|
+
const dir = paths(cwd).harnesses;
|
|
92
|
+
const mjs = path__default.default.join(dir, `${name}.mjs`);
|
|
93
|
+
if (fs.existsSync(mjs)) return mjs;
|
|
94
|
+
return path__default.default.join(dir, `${name}.js`);
|
|
95
|
+
}
|
|
96
|
+
async function loadHarness(harnessFile) {
|
|
97
|
+
const absolute = path__default.default.isAbsolute(harnessFile) ? harnessFile : path__default.default.resolve(process.cwd(), harnessFile);
|
|
98
|
+
if (!fs.existsSync(absolute)) {
|
|
99
|
+
throw new HarnessError(
|
|
100
|
+
`harness not found at ${absolute}. Author one under .blazediff/harnesses/ (or run \`blazediff-agent auth init\` for a login harness).`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
const cached = moduleCache.get(absolute);
|
|
104
|
+
if (cached) return cached;
|
|
105
|
+
const url$1 = url.pathToFileURL(absolute).href;
|
|
106
|
+
const loading = (async () => {
|
|
107
|
+
let mod;
|
|
108
|
+
try {
|
|
109
|
+
mod = await import(url$1);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
throw new HarnessError(
|
|
112
|
+
`failed to load harness at ${absolute}: ${err.message}`,
|
|
113
|
+
err
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
const harness = mod.default;
|
|
117
|
+
if (!harness || typeof harness.run !== "function") {
|
|
118
|
+
if (typeof mod.login === "function") {
|
|
119
|
+
throw new HarnessError(
|
|
120
|
+
`legacy auth harness detected at ${absolute} (exports \`login\`). Re-run \`blazediff-agent auth init\` to regenerate it as a harness.`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
throw new HarnessError(
|
|
124
|
+
`harness at ${absolute} must default-export an object with a \`run(ctx)\` function`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return { phase: harness.phase ?? "interact", run: harness.run };
|
|
128
|
+
})();
|
|
129
|
+
moduleCache.set(absolute, loading);
|
|
130
|
+
return loading;
|
|
131
|
+
}
|
|
132
|
+
function loginPathOf(loginUrl) {
|
|
133
|
+
try {
|
|
134
|
+
return new URL(loginUrl, "http://placeholder").pathname;
|
|
135
|
+
} catch {
|
|
136
|
+
return loginUrl;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function assertLeftLoginPage(page, loginUrl) {
|
|
140
|
+
const loginPath = loginPathOf(loginUrl);
|
|
141
|
+
let currentPath;
|
|
142
|
+
try {
|
|
143
|
+
currentPath = new URL(page.url()).pathname;
|
|
144
|
+
} catch {
|
|
145
|
+
currentPath = page.url();
|
|
146
|
+
}
|
|
147
|
+
if (loginPath && currentPath === loginPath) {
|
|
148
|
+
throw new HarnessError(
|
|
149
|
+
`login harness returned but page is still on the login URL (${currentPath}). Check that the harness submits the form and waits for redirect.`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
await page.locator('input[type="password"]').first().waitFor({ state: "detached", timeout: 2e3 }).catch(() => {
|
|
153
|
+
});
|
|
154
|
+
const passwordInputs = await page.locator('input[type="password"]:visible').count().catch(() => 0);
|
|
155
|
+
if (passwordInputs > 0) {
|
|
156
|
+
throw new HarnessError(
|
|
157
|
+
`login harness returned but a visible password input is still on the page. The login likely did not complete (wrong credentials, captcha, or selectors out of date).`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
55
161
|
var FROZEN_NOW = Date.UTC(2025, 0, 1, 0, 0, 0);
|
|
56
162
|
var STABILITY_CSS = `
|
|
57
163
|
*,*::before,*::after{
|
|
@@ -212,6 +318,11 @@ var DEFAULT_MASK_SELECTOR = `[${DEFAULT_MASK_ATTR}]`;
|
|
|
212
318
|
async function applyMaskOverlays(page, masks) {
|
|
213
319
|
const selectors = [DEFAULT_MASK_SELECTOR, ...masks];
|
|
214
320
|
await page.evaluate((selectors2) => {
|
|
321
|
+
for (const stale of Array.from(
|
|
322
|
+
document.querySelectorAll("[data-blazediff-mask]")
|
|
323
|
+
)) {
|
|
324
|
+
stale.remove();
|
|
325
|
+
}
|
|
215
326
|
for (const sel of selectors2) {
|
|
216
327
|
for (const el of Array.from(
|
|
217
328
|
document.querySelectorAll(sel)
|
|
@@ -234,39 +345,90 @@ async function applyMaskOverlays(page, masks) {
|
|
|
234
345
|
}
|
|
235
346
|
|
|
236
347
|
// src/browser/capture.ts
|
|
237
|
-
|
|
348
|
+
var SCREENSHOT_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/i;
|
|
349
|
+
async function shoot(page, outputPath, fullPage) {
|
|
350
|
+
await promises.mkdir(path__default.default.dirname(outputPath), { recursive: true });
|
|
351
|
+
const buffer = await page.screenshot({
|
|
352
|
+
path: outputPath,
|
|
353
|
+
type: "png",
|
|
354
|
+
fullPage,
|
|
355
|
+
animations: "disabled",
|
|
356
|
+
caret: "hide",
|
|
357
|
+
scale: "device"
|
|
358
|
+
});
|
|
359
|
+
return buffer.length;
|
|
360
|
+
}
|
|
361
|
+
async function stabilize(page, waitFor, masks) {
|
|
362
|
+
await waitForStability(page, waitFor);
|
|
363
|
+
await applyMaskOverlays(page, masks);
|
|
364
|
+
await page.evaluate(
|
|
365
|
+
() => new Promise((r) => requestAnimationFrame(() => r()))
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses) {
|
|
238
369
|
const viewport = opts.viewport ?? DEFAULT_VIEWPORT;
|
|
239
370
|
const waitFor = opts.waitFor ?? DEFAULT_WAIT_FOR;
|
|
240
371
|
const masks = opts.mask ?? [];
|
|
241
372
|
const fullPage = opts.fullPage ?? DEFAULT_FULL_PAGE;
|
|
373
|
+
const setup = (harnesses ?? []).filter(
|
|
374
|
+
(h) => (h.harness.phase ?? "interact") === "setup"
|
|
375
|
+
);
|
|
376
|
+
const interact = (harnesses ?? []).filter(
|
|
377
|
+
(h) => (h.harness.phase ?? "interact") !== "setup"
|
|
378
|
+
);
|
|
242
379
|
const handle = await acquireStableContext(viewport, {
|
|
243
|
-
pool: !
|
|
380
|
+
pool: !(harnesses && harnesses.length > 0),
|
|
244
381
|
baseURL: baseUrl || void 0
|
|
245
382
|
});
|
|
383
|
+
const context = handle.context;
|
|
384
|
+
const browser = await getBrowser();
|
|
246
385
|
const page = await openStablePage(handle);
|
|
247
386
|
try {
|
|
248
|
-
|
|
249
|
-
|
|
387
|
+
const rejectScreenshot = async () => {
|
|
388
|
+
throw new HarnessError("setup harness must not call screenshot()");
|
|
389
|
+
};
|
|
390
|
+
for (const { harness, params } of setup) {
|
|
391
|
+
await harness.run({
|
|
392
|
+
page,
|
|
393
|
+
browser,
|
|
394
|
+
context,
|
|
395
|
+
params,
|
|
396
|
+
screenshot: rejectScreenshot
|
|
397
|
+
});
|
|
250
398
|
}
|
|
251
399
|
const url = new URL(opts.url, baseUrl).toString();
|
|
252
400
|
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 3e4 });
|
|
253
|
-
await
|
|
254
|
-
await applyMaskOverlays(page, masks);
|
|
255
|
-
await page.evaluate(
|
|
256
|
-
() => new Promise((r) => requestAnimationFrame(() => r()))
|
|
257
|
-
);
|
|
401
|
+
await stabilize(page, waitFor, masks);
|
|
258
402
|
const outputDir = opts.mode === "baseline" ? paths(cwd).baselines : paths(cwd).actual;
|
|
259
|
-
await promises.mkdir(outputDir, { recursive: true });
|
|
260
403
|
const outputPath = path__default.default.join(outputDir, `${opts.id}.png`);
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
404
|
+
const bytes = await shoot(page, outputPath, fullPage);
|
|
405
|
+
const subCaptures = [];
|
|
406
|
+
const used = /* @__PURE__ */ new Set();
|
|
407
|
+
const screenshot = async (name) => {
|
|
408
|
+
if (!SCREENSHOT_NAME_RE.test(name)) {
|
|
409
|
+
throw new HarnessError(
|
|
410
|
+
`invalid screenshot name "${name}": use alphanumeric/kebab-case (no "__", spaces, or slashes)`
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
if (used.has(name)) {
|
|
414
|
+
throw new HarnessError(`duplicate screenshot name "${name}"`);
|
|
415
|
+
}
|
|
416
|
+
used.add(name);
|
|
417
|
+
await stabilize(page, waitFor, masks);
|
|
418
|
+
const subPath = path__default.default.join(outputDir, `${opts.id}__${name}.png`);
|
|
419
|
+
const subBytes = await shoot(page, subPath, fullPage);
|
|
420
|
+
subCaptures.push({ name, outputPath: subPath, bytes: subBytes });
|
|
421
|
+
};
|
|
422
|
+
for (const { harness, params } of interact) {
|
|
423
|
+
await harness.run({ page, browser, context, params, screenshot });
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
id: opts.id,
|
|
427
|
+
outputPath,
|
|
428
|
+
mode: opts.mode,
|
|
429
|
+
bytes,
|
|
430
|
+
subCaptures: subCaptures.length > 0 ? subCaptures : void 0
|
|
431
|
+
};
|
|
270
432
|
} finally {
|
|
271
433
|
await page.close().catch(() => {
|
|
272
434
|
});
|
|
@@ -320,112 +482,6 @@ async function installBrowsers(opts = {}) {
|
|
|
320
482
|
const executablePath = await readExecutablePath();
|
|
321
483
|
return { installed: Boolean(executablePath), executablePath, cliPath };
|
|
322
484
|
}
|
|
323
|
-
|
|
324
|
-
// src/auth/env.ts
|
|
325
|
-
var LEGACY_REQUIRED = "required";
|
|
326
|
-
var DEFAULT_PERSONA = "default";
|
|
327
|
-
function canonicalPersona(auth) {
|
|
328
|
-
return auth === LEGACY_REQUIRED ? DEFAULT_PERSONA : auth;
|
|
329
|
-
}
|
|
330
|
-
var AuthHarnessError = class extends Error {
|
|
331
|
-
constructor(message, cause) {
|
|
332
|
-
super(message);
|
|
333
|
-
this.cause = cause;
|
|
334
|
-
this.name = "AuthHarnessError";
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
var moduleCache = /* @__PURE__ */ new Map();
|
|
338
|
-
async function loadAuthHarness(harnessFile) {
|
|
339
|
-
const absolute = path__default.default.isAbsolute(harnessFile) ? harnessFile : path__default.default.resolve(process.cwd(), harnessFile);
|
|
340
|
-
if (!fs.existsSync(absolute)) {
|
|
341
|
-
throw new AuthHarnessError(
|
|
342
|
-
`auth harness not found at ${absolute}. Run \`blazediff-agent auth init\` to create one.`
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
const cached = moduleCache.get(absolute);
|
|
346
|
-
if (cached) return cached;
|
|
347
|
-
const url$1 = url.pathToFileURL(absolute).href;
|
|
348
|
-
const loading = (async () => {
|
|
349
|
-
try {
|
|
350
|
-
const mod = await import(url$1);
|
|
351
|
-
if (typeof mod.login !== "function") {
|
|
352
|
-
throw new AuthHarnessError(
|
|
353
|
-
`auth harness at ${absolute} does not export a \`login\` function`
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
return { login: mod.login };
|
|
357
|
-
} catch (err) {
|
|
358
|
-
if (err instanceof AuthHarnessError) throw err;
|
|
359
|
-
throw new AuthHarnessError(
|
|
360
|
-
`failed to load auth harness at ${absolute}: ${err.message}`,
|
|
361
|
-
err
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
})();
|
|
365
|
-
moduleCache.set(absolute, loading);
|
|
366
|
-
return loading;
|
|
367
|
-
}
|
|
368
|
-
function loginPathOf(loginUrl) {
|
|
369
|
-
try {
|
|
370
|
-
return new URL(loginUrl, "http://placeholder").pathname;
|
|
371
|
-
} catch {
|
|
372
|
-
return loginUrl;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
async function verifyPostLogin(page, loginUrl) {
|
|
376
|
-
const loginPath = loginPathOf(loginUrl);
|
|
377
|
-
let currentPath;
|
|
378
|
-
try {
|
|
379
|
-
currentPath = new URL(page.url()).pathname;
|
|
380
|
-
} catch {
|
|
381
|
-
currentPath = page.url();
|
|
382
|
-
}
|
|
383
|
-
if (loginPath && currentPath === loginPath) {
|
|
384
|
-
throw new AuthHarnessError(
|
|
385
|
-
`auth harness returned but page is still on the login URL (${currentPath}). Check that the harness submits the form and waits for redirect.`
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
await page.locator('input[type="password"]').first().waitFor({ state: "detached", timeout: 2e3 }).catch(() => {
|
|
389
|
-
});
|
|
390
|
-
const passwordInputs = await page.locator('input[type="password"]:visible').count().catch(() => 0);
|
|
391
|
-
if (passwordInputs > 0) {
|
|
392
|
-
throw new AuthHarnessError(
|
|
393
|
-
`auth harness returned but a visible password input is still on the page. The login likely did not complete (wrong credentials, captcha, or selectors out of date).`
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// src/auth/hook.ts
|
|
399
|
-
var AuthConfigMissingError = class extends Error {
|
|
400
|
-
constructor(message) {
|
|
401
|
-
super(message);
|
|
402
|
-
this.name = "AuthConfigMissingError";
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
function buildAuthHook(persona, authConfig, cwd) {
|
|
406
|
-
if (!authConfig) {
|
|
407
|
-
throw new AuthConfigMissingError(
|
|
408
|
-
"auth required but .blazediff/config.json has no `auth` block. Run `blazediff-agent auth init`."
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
const harnessFile = path__default.default.isAbsolute(authConfig.harness) ? authConfig.harness : path__default.default.join(cwd, authConfig.harness);
|
|
412
|
-
const canonical = canonicalPersona(persona);
|
|
413
|
-
const loginUrl = authConfig.loginUrl;
|
|
414
|
-
return {
|
|
415
|
-
hook: async (page) => {
|
|
416
|
-
const mod = await loadAuthHarness(harnessFile);
|
|
417
|
-
try {
|
|
418
|
-
await mod.login(page, canonical);
|
|
419
|
-
} catch (err) {
|
|
420
|
-
throw new AuthHarnessError(
|
|
421
|
-
`auth harness threw for persona "${canonical}": ${err.message}`,
|
|
422
|
-
err
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
await verifyPostLogin(page, loginUrl);
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
485
|
async function loadConfig(cwd = process.cwd()) {
|
|
430
486
|
const file = paths(cwd).config;
|
|
431
487
|
if (!fs.existsSync(file)) return null;
|
|
@@ -475,6 +531,16 @@ var Semaphore = class {
|
|
|
475
531
|
var STABILITY_HOOKS_VERSION = 1;
|
|
476
532
|
|
|
477
533
|
// src/manifest.ts
|
|
534
|
+
function serializeHarnesses(harnesses) {
|
|
535
|
+
return JSON.stringify(
|
|
536
|
+
harnesses.map((h) => ({
|
|
537
|
+
name: h.name,
|
|
538
|
+
params: h.params ? Object.fromEntries(
|
|
539
|
+
Object.entries(h.params).sort(([a], [b]) => a.localeCompare(b))
|
|
540
|
+
) : void 0
|
|
541
|
+
}))
|
|
542
|
+
);
|
|
543
|
+
}
|
|
478
544
|
async function loadManifest(cwd = process.cwd()) {
|
|
479
545
|
const file = paths(cwd).manifest;
|
|
480
546
|
if (!fs.existsSync(file)) return null;
|
|
@@ -500,8 +566,9 @@ function hashMaterial(input) {
|
|
|
500
566
|
viewport: input.viewport,
|
|
501
567
|
mask: [...input.mask].sort(),
|
|
502
568
|
waitFor: input.waitFor,
|
|
503
|
-
|
|
569
|
+
harnesses: serializeHarnesses(input.harnesses),
|
|
504
570
|
fullPage: input.fullPage,
|
|
571
|
+
subName: input.subName ?? null,
|
|
505
572
|
hooks: STABILITY_HOOKS_VERSION
|
|
506
573
|
};
|
|
507
574
|
return `sha256:${crypto$1.createHash("sha256").update(JSON.stringify(material)).digest("hex")}`;
|
|
@@ -510,24 +577,27 @@ function makeEntry(input) {
|
|
|
510
577
|
const viewport = input.viewport ?? DEFAULT_VIEWPORT;
|
|
511
578
|
const waitFor = input.waitFor ?? DEFAULT_WAIT_FOR;
|
|
512
579
|
const mask = input.mask ?? [];
|
|
513
|
-
const
|
|
580
|
+
const harnesses = input.harnesses ?? [];
|
|
514
581
|
const fullPage = input.fullPage ?? DEFAULT_FULL_PAGE;
|
|
515
582
|
return {
|
|
516
583
|
id: input.id,
|
|
517
584
|
url: input.url,
|
|
518
585
|
viewport,
|
|
519
|
-
|
|
586
|
+
harnesses: harnesses.length > 0 ? harnesses : void 0,
|
|
520
587
|
waitFor,
|
|
521
588
|
mask,
|
|
522
589
|
fullPage,
|
|
590
|
+
parent: input.parent,
|
|
591
|
+
derived: input.derived || void 0,
|
|
523
592
|
baselinePath: path__default.default.posix.join(".blazediff", "baselines", `${input.id}.png`),
|
|
524
593
|
captureHash: hashMaterial({
|
|
525
594
|
url: input.url,
|
|
526
595
|
viewport,
|
|
527
596
|
mask,
|
|
528
597
|
waitFor,
|
|
529
|
-
|
|
530
|
-
fullPage
|
|
598
|
+
harnesses,
|
|
599
|
+
fullPage,
|
|
600
|
+
subName: input.subName
|
|
531
601
|
}),
|
|
532
602
|
createdBy: input.createdBy ?? "agent",
|
|
533
603
|
createdAt: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)
|
|
@@ -540,19 +610,40 @@ function addOrReplaceEntry(manifest, entry) {
|
|
|
540
610
|
].sort((a, b) => a.id.localeCompare(b.id));
|
|
541
611
|
return { ...manifest, entries };
|
|
542
612
|
}
|
|
613
|
+
function isDerived(entry) {
|
|
614
|
+
return entry.derived === true || entry.parent != null && entry.id.includes("__");
|
|
615
|
+
}
|
|
616
|
+
function subNameOf(entry) {
|
|
617
|
+
if (!isDerived(entry)) return void 0;
|
|
618
|
+
const idx = entry.id.indexOf("__");
|
|
619
|
+
return idx === -1 ? void 0 : entry.id.slice(idx + 2);
|
|
620
|
+
}
|
|
543
621
|
function isEntryStale(entry) {
|
|
544
622
|
const recomputed = hashMaterial({
|
|
545
623
|
url: entry.url,
|
|
546
624
|
viewport: entry.viewport,
|
|
547
625
|
mask: entry.mask,
|
|
548
626
|
waitFor: entry.waitFor,
|
|
549
|
-
|
|
550
|
-
fullPage: entry.fullPage ?? DEFAULT_FULL_PAGE
|
|
627
|
+
harnesses: entry.harnesses ?? [],
|
|
628
|
+
fullPage: entry.fullPage ?? DEFAULT_FULL_PAGE,
|
|
629
|
+
subName: subNameOf(entry)
|
|
551
630
|
});
|
|
552
631
|
return recomputed !== entry.captureHash;
|
|
553
632
|
}
|
|
554
633
|
|
|
555
634
|
// src/captures.ts
|
|
635
|
+
function normalizeHarnessRefs(refs) {
|
|
636
|
+
if (!refs) return [];
|
|
637
|
+
return refs.map((ref) => typeof ref === "string" ? { name: ref } : ref);
|
|
638
|
+
}
|
|
639
|
+
async function resolveHarnesses(refs, cwd) {
|
|
640
|
+
return Promise.all(
|
|
641
|
+
refs.map(async (ref) => ({
|
|
642
|
+
harness: await loadHarness(resolveHarnessFile(ref.name, cwd)),
|
|
643
|
+
params: ref.params ?? {}
|
|
644
|
+
}))
|
|
645
|
+
);
|
|
646
|
+
}
|
|
556
647
|
function validateRoute(route, i) {
|
|
557
648
|
if (!route || typeof route !== "object")
|
|
558
649
|
return `route[${i}] must be an object`;
|
|
@@ -598,7 +689,8 @@ async function runCaptures(opts) {
|
|
|
598
689
|
(r, i) => semaphore.run(async () => {
|
|
599
690
|
const mode = r.mode ?? defaultMode;
|
|
600
691
|
try {
|
|
601
|
-
const
|
|
692
|
+
const refs = normalizeHarnessRefs(r.harnesses);
|
|
693
|
+
const harnesses = await resolveHarnesses(refs, cwd);
|
|
602
694
|
const shot = await captureScreenshot(
|
|
603
695
|
opts.baseUrl,
|
|
604
696
|
{
|
|
@@ -611,7 +703,7 @@ async function runCaptures(opts) {
|
|
|
611
703
|
mode
|
|
612
704
|
},
|
|
613
705
|
cwd,
|
|
614
|
-
|
|
706
|
+
harnesses
|
|
615
707
|
);
|
|
616
708
|
slot[i] = {
|
|
617
709
|
id: r.id,
|
|
@@ -619,22 +711,40 @@ async function runCaptures(opts) {
|
|
|
619
711
|
mode,
|
|
620
712
|
ok: true,
|
|
621
713
|
outputPath: shot.outputPath,
|
|
622
|
-
bytes: shot.bytes
|
|
714
|
+
bytes: shot.bytes,
|
|
715
|
+
subCaptures: shot.subCaptures?.map((s) => s.name)
|
|
623
716
|
};
|
|
624
717
|
if (mode === "baseline" && manifest) {
|
|
718
|
+
const shared = {
|
|
719
|
+
url: r.url,
|
|
720
|
+
viewport: r.viewport,
|
|
721
|
+
mask: r.mask,
|
|
722
|
+
waitFor: r.waitFor,
|
|
723
|
+
fullPage: r.fullPage,
|
|
724
|
+
harnesses: refs.length > 0 ? refs : void 0
|
|
725
|
+
};
|
|
726
|
+
manifest = {
|
|
727
|
+
...manifest,
|
|
728
|
+
entries: manifest.entries.filter((e) => e.parent !== r.id)
|
|
729
|
+
};
|
|
625
730
|
manifest = addOrReplaceEntry(
|
|
626
731
|
manifest,
|
|
627
|
-
makeEntry({
|
|
628
|
-
id: r.id,
|
|
629
|
-
url: r.url,
|
|
630
|
-
viewport: r.viewport,
|
|
631
|
-
mask: r.mask,
|
|
632
|
-
waitFor: r.waitFor,
|
|
633
|
-
fullPage: r.fullPage,
|
|
634
|
-
auth: r.auth ?? null
|
|
635
|
-
})
|
|
732
|
+
makeEntry({ id: r.id, ...shared })
|
|
636
733
|
);
|
|
637
734
|
manifestUpdates += 1;
|
|
735
|
+
for (const sub of shot.subCaptures ?? []) {
|
|
736
|
+
manifest = addOrReplaceEntry(
|
|
737
|
+
manifest,
|
|
738
|
+
makeEntry({
|
|
739
|
+
id: `${r.id}__${sub.name}`,
|
|
740
|
+
...shared,
|
|
741
|
+
parent: r.id,
|
|
742
|
+
derived: true,
|
|
743
|
+
subName: sub.name
|
|
744
|
+
})
|
|
745
|
+
);
|
|
746
|
+
manifestUpdates += 1;
|
|
747
|
+
}
|
|
638
748
|
}
|
|
639
749
|
} catch (err) {
|
|
640
750
|
slot[i] = {
|
|
@@ -886,6 +996,55 @@ async function discover(opts) {
|
|
|
886
996
|
}
|
|
887
997
|
return Array.from(merged.values()).sort((a, b) => a.url.localeCompare(b.url));
|
|
888
998
|
}
|
|
999
|
+
function envFiles(cwd) {
|
|
1000
|
+
const root = paths(cwd).root;
|
|
1001
|
+
return [
|
|
1002
|
+
path__default.default.join(root, ".env.local"),
|
|
1003
|
+
path__default.default.join(root, ".env"),
|
|
1004
|
+
path__default.default.join(cwd, ".env.local"),
|
|
1005
|
+
path__default.default.join(cwd, ".env")
|
|
1006
|
+
];
|
|
1007
|
+
}
|
|
1008
|
+
function parse(content) {
|
|
1009
|
+
if (typeof util__namespace.parseEnv === "function") {
|
|
1010
|
+
return util__namespace.parseEnv(content);
|
|
1011
|
+
}
|
|
1012
|
+
const out = {};
|
|
1013
|
+
for (const raw of content.split("\n")) {
|
|
1014
|
+
const line = raw.trim();
|
|
1015
|
+
if (!line || line.startsWith("#")) continue;
|
|
1016
|
+
const eq = line.indexOf("=");
|
|
1017
|
+
if (eq === -1) continue;
|
|
1018
|
+
const key = line.slice(0, eq).trim();
|
|
1019
|
+
let value = line.slice(eq + 1).trim();
|
|
1020
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
1021
|
+
value = value.slice(1, -1);
|
|
1022
|
+
}
|
|
1023
|
+
if (key) out[key] = value;
|
|
1024
|
+
}
|
|
1025
|
+
return out;
|
|
1026
|
+
}
|
|
1027
|
+
function loadEnvFiles(cwd = process.cwd()) {
|
|
1028
|
+
const loaded = [];
|
|
1029
|
+
for (const file of envFiles(cwd)) {
|
|
1030
|
+
if (!fs.existsSync(file)) continue;
|
|
1031
|
+
let parsed;
|
|
1032
|
+
try {
|
|
1033
|
+
parsed = parse(fs.readFileSync(file, "utf8"));
|
|
1034
|
+
} catch {
|
|
1035
|
+
continue;
|
|
1036
|
+
}
|
|
1037
|
+
let applied = false;
|
|
1038
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
1039
|
+
if (process.env[key] === void 0) {
|
|
1040
|
+
process.env[key] = value;
|
|
1041
|
+
applied = true;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
if (applied) loaded.push(file);
|
|
1045
|
+
}
|
|
1046
|
+
return loaded;
|
|
1047
|
+
}
|
|
889
1048
|
var ENTRIES = [
|
|
890
1049
|
"actual/",
|
|
891
1050
|
"judgments/",
|
|
@@ -893,10 +1052,12 @@ var ENTRIES = [
|
|
|
893
1052
|
"summary.md",
|
|
894
1053
|
"dev-server.log",
|
|
895
1054
|
"dev-server.pid",
|
|
1055
|
+
".env",
|
|
1056
|
+
".env.local",
|
|
896
1057
|
"*.tmp"
|
|
897
1058
|
];
|
|
898
1059
|
var STALE_ENTRIES = /* @__PURE__ */ new Set(["diffs/", "pending-judgments/", "report.json"]);
|
|
899
|
-
var HEADER = "# blazediff: generated artifacts (committed: config.json, manifest.json, baselines/)\n";
|
|
1060
|
+
var HEADER = "# blazediff: generated artifacts (committed: config.json, manifest.json, baselines/, harnesses/)\n";
|
|
900
1061
|
async function ensureGitignore(cwd) {
|
|
901
1062
|
const file = paths(cwd).gitignore;
|
|
902
1063
|
await promises.mkdir(path__default.default.dirname(file), { recursive: true });
|
|
@@ -1864,13 +2025,8 @@ function failResult(entry, outcome, actualPath, baselinePath, verdict) {
|
|
|
1864
2025
|
}
|
|
1865
2026
|
|
|
1866
2027
|
// src/graph/nodes/capture.ts
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
if (legacyAuthHinted) return;
|
|
1870
|
-
legacyAuthHinted = true;
|
|
1871
|
-
process.stderr.write(
|
|
1872
|
-
'blazediff: manifest entries with auth: "required" are treated as persona "default" \u2014 please migrate.\n'
|
|
1873
|
-
);
|
|
2028
|
+
function asCaptured(entry, output) {
|
|
2029
|
+
return { entry, output };
|
|
1874
2030
|
}
|
|
1875
2031
|
function makeCaptureNode(semaphore) {
|
|
1876
2032
|
return async function captureNode(state) {
|
|
@@ -1879,27 +2035,39 @@ function makeCaptureNode(semaphore) {
|
|
|
1879
2035
|
if (!entry || !options) {
|
|
1880
2036
|
throw new Error("captureNode: entry or options missing");
|
|
1881
2037
|
}
|
|
2038
|
+
const children = state.children;
|
|
1882
2039
|
if (isEntryStale(entry)) {
|
|
1883
2040
|
return {
|
|
1884
|
-
|
|
2041
|
+
captured: [
|
|
2042
|
+
asCaptured(entry, {
|
|
2043
|
+
id: entry.id,
|
|
2044
|
+
skipResult: staleResult(entry)
|
|
2045
|
+
}),
|
|
2046
|
+
...children.map(
|
|
2047
|
+
(c) => asCaptured(c, { id: c.id, skipResult: staleResult(c) })
|
|
2048
|
+
)
|
|
2049
|
+
]
|
|
1885
2050
|
};
|
|
1886
2051
|
}
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
2052
|
+
const failAll = (message) => ({
|
|
2053
|
+
captured: [
|
|
2054
|
+
asCaptured(entry, {
|
|
2055
|
+
id: entry.id,
|
|
2056
|
+
skipResult: errorResult(entry, message)
|
|
2057
|
+
}),
|
|
2058
|
+
...children.map(
|
|
2059
|
+
(c) => asCaptured(c, { id: c.id, skipResult: errorResult(c, message) })
|
|
2060
|
+
)
|
|
2061
|
+
]
|
|
2062
|
+
});
|
|
2063
|
+
let harnesses;
|
|
2064
|
+
try {
|
|
2065
|
+
harnesses = await resolveHarnesses(
|
|
2066
|
+
normalizeHarnessRefs(entry.harnesses),
|
|
2067
|
+
options.cwd
|
|
2068
|
+
);
|
|
2069
|
+
} catch (err) {
|
|
2070
|
+
return failAll(`harness: ${err.message}`);
|
|
1903
2071
|
}
|
|
1904
2072
|
const baselinePath = path__default.default.join(options.baselinesDir, `${entry.id}.png`);
|
|
1905
2073
|
try {
|
|
@@ -1916,24 +2084,50 @@ function makeCaptureNode(semaphore) {
|
|
|
1916
2084
|
mode: "actual"
|
|
1917
2085
|
},
|
|
1918
2086
|
options.cwd,
|
|
1919
|
-
|
|
2087
|
+
harnesses
|
|
1920
2088
|
)
|
|
1921
2089
|
);
|
|
1922
|
-
|
|
1923
|
-
|
|
2090
|
+
const items = [
|
|
2091
|
+
asCaptured(entry, {
|
|
1924
2092
|
id: entry.id,
|
|
1925
2093
|
captureOutputPath: capture.outputPath,
|
|
1926
2094
|
baselinePath
|
|
2095
|
+
})
|
|
2096
|
+
];
|
|
2097
|
+
const subByName = new Map(
|
|
2098
|
+
(capture.subCaptures ?? []).map((s) => [s.name, s])
|
|
2099
|
+
);
|
|
2100
|
+
for (const child of children) {
|
|
2101
|
+
const name = subNameOf(child);
|
|
2102
|
+
const sub = name ? subByName.get(name) : void 0;
|
|
2103
|
+
const childBaseline = path__default.default.join(
|
|
2104
|
+
options.baselinesDir,
|
|
2105
|
+
`${child.id}.png`
|
|
2106
|
+
);
|
|
2107
|
+
if (sub) {
|
|
2108
|
+
items.push(
|
|
2109
|
+
asCaptured(child, {
|
|
2110
|
+
id: child.id,
|
|
2111
|
+
captureOutputPath: sub.outputPath,
|
|
2112
|
+
baselinePath: childBaseline
|
|
2113
|
+
})
|
|
2114
|
+
);
|
|
2115
|
+
} else {
|
|
2116
|
+
items.push(
|
|
2117
|
+
asCaptured(child, {
|
|
2118
|
+
id: child.id,
|
|
2119
|
+
skipResult: errorResult(
|
|
2120
|
+
child,
|
|
2121
|
+
`harness did not produce screenshot "${name ?? child.id}"`
|
|
2122
|
+
)
|
|
2123
|
+
})
|
|
2124
|
+
);
|
|
1927
2125
|
}
|
|
1928
|
-
}
|
|
2126
|
+
}
|
|
2127
|
+
return { captured: items };
|
|
1929
2128
|
} catch (err) {
|
|
1930
|
-
if (err instanceof
|
|
1931
|
-
return {
|
|
1932
|
-
captureOutput: {
|
|
1933
|
-
id: entry.id,
|
|
1934
|
-
skipResult: errorResult(entry, `auth: ${err.message}`)
|
|
1935
|
-
}
|
|
1936
|
-
};
|
|
2129
|
+
if (err instanceof HarnessError) {
|
|
2130
|
+
return failAll(`harness: ${err.message}`);
|
|
1937
2131
|
}
|
|
1938
2132
|
throw err;
|
|
1939
2133
|
}
|
|
@@ -2236,6 +2430,25 @@ var resultsChannel = langgraph.Annotation({
|
|
|
2236
2430
|
reducer: (acc, next) => [...acc, ...next],
|
|
2237
2431
|
default: () => []
|
|
2238
2432
|
});
|
|
2433
|
+
var capturedChannel = langgraph.Annotation({
|
|
2434
|
+
reducer: (acc, next) => [...acc, ...next],
|
|
2435
|
+
default: () => []
|
|
2436
|
+
});
|
|
2437
|
+
var CaptureState = langgraph.Annotation.Root({
|
|
2438
|
+
entry: langgraph.Annotation({
|
|
2439
|
+
reducer: (_, next) => next,
|
|
2440
|
+
default: () => void 0
|
|
2441
|
+
}),
|
|
2442
|
+
children: langgraph.Annotation({
|
|
2443
|
+
reducer: (_, next) => next,
|
|
2444
|
+
default: () => []
|
|
2445
|
+
}),
|
|
2446
|
+
options: langgraph.Annotation({
|
|
2447
|
+
reducer: (acc, next) => next ?? acc,
|
|
2448
|
+
default: () => void 0
|
|
2449
|
+
}),
|
|
2450
|
+
captured: capturedChannel
|
|
2451
|
+
});
|
|
2239
2452
|
var BranchState = langgraph.Annotation.Root({
|
|
2240
2453
|
entry: langgraph.Annotation({
|
|
2241
2454
|
reducer: (_, next) => next,
|
|
@@ -2264,6 +2477,7 @@ var GraphState = langgraph.Annotation.Root({
|
|
|
2264
2477
|
reducer: (acc, next) => next ?? acc,
|
|
2265
2478
|
default: () => []
|
|
2266
2479
|
}),
|
|
2480
|
+
captured: capturedChannel,
|
|
2267
2481
|
results: resultsChannel,
|
|
2268
2482
|
manifest: langgraph.Annotation({
|
|
2269
2483
|
reducer: (acc, next) => next ?? acc,
|
|
@@ -2284,15 +2498,36 @@ function cpuParallelism() {
|
|
|
2284
2498
|
function threadIdFor(cwd) {
|
|
2285
2499
|
return crypto$1.createHash("sha1").update(paths(cwd).manifest).digest("hex").slice(0, 16);
|
|
2286
2500
|
}
|
|
2287
|
-
function
|
|
2288
|
-
return new langgraph.StateGraph(
|
|
2501
|
+
function buildCaptureGraph(captureSemaphore) {
|
|
2502
|
+
return new langgraph.StateGraph(CaptureState).addNode("capture", makeCaptureNode(captureSemaphore)).addEdge(langgraph.START, "capture").addEdge("capture", langgraph.END).compile();
|
|
2503
|
+
}
|
|
2504
|
+
function buildBranchGraph(diffSemaphore) {
|
|
2505
|
+
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
|
+
}
|
|
2507
|
+
function dispatchNode() {
|
|
2508
|
+
return {};
|
|
2289
2509
|
}
|
|
2290
2510
|
function buildGraph(captureSemaphore, diffSemaphore, checkpointer) {
|
|
2291
|
-
const
|
|
2292
|
-
|
|
2511
|
+
const captureBranch = buildCaptureGraph(captureSemaphore);
|
|
2512
|
+
const branch = buildBranchGraph(diffSemaphore);
|
|
2513
|
+
return new langgraph.StateGraph(GraphState).addNode("load", loadNode).addNode("capture", captureBranch).addNode("dispatch", dispatchNode).addNode("branch", branch).addEdge(langgraph.START, "load").addConditionalEdges(
|
|
2293
2514
|
"load",
|
|
2294
|
-
(state) => state.entries.map(
|
|
2295
|
-
(entry) => new langgraph.Send("
|
|
2515
|
+
(state) => state.entries.filter((entry) => !isDerived(entry)).map(
|
|
2516
|
+
(entry) => new langgraph.Send("capture", {
|
|
2517
|
+
entry,
|
|
2518
|
+
children: state.entries.filter((e) => e.parent === entry.id),
|
|
2519
|
+
options: state.options
|
|
2520
|
+
})
|
|
2521
|
+
),
|
|
2522
|
+
["capture"]
|
|
2523
|
+
).addEdge("capture", "dispatch").addConditionalEdges(
|
|
2524
|
+
"dispatch",
|
|
2525
|
+
(state) => state.captured.map(
|
|
2526
|
+
(c) => new langgraph.Send("branch", {
|
|
2527
|
+
entry: c.entry,
|
|
2528
|
+
captureOutput: c.output,
|
|
2529
|
+
options: state.options
|
|
2530
|
+
})
|
|
2296
2531
|
),
|
|
2297
2532
|
["branch"]
|
|
2298
2533
|
).addEdge("branch", langgraph.END).compile({ checkpointer });
|
|
@@ -2375,7 +2610,6 @@ async function runGraph(opts) {
|
|
|
2375
2610
|
if (!opts.resume) {
|
|
2376
2611
|
await checkpointer.deleteThread(threadId);
|
|
2377
2612
|
}
|
|
2378
|
-
const config = await loadConfig(cwd);
|
|
2379
2613
|
const input = opts.resume ? new langgraph.Command({ resume: opts.resume }) : {
|
|
2380
2614
|
options: {
|
|
2381
2615
|
baseUrl: opts.baseUrl ?? "",
|
|
@@ -2384,8 +2618,7 @@ async function runGraph(opts) {
|
|
|
2384
2618
|
concurrency,
|
|
2385
2619
|
emitDiffPng: opts.emitDiffPng ?? true,
|
|
2386
2620
|
judge: opts.judge ?? "none",
|
|
2387
|
-
baselinesDir
|
|
2388
|
-
auth: config?.auth
|
|
2621
|
+
baselinesDir
|
|
2389
2622
|
}
|
|
2390
2623
|
};
|
|
2391
2624
|
let collect;
|
|
@@ -2417,17 +2650,22 @@ function runCheck(opts) {
|
|
|
2417
2650
|
return runGraph(opts);
|
|
2418
2651
|
}
|
|
2419
2652
|
|
|
2653
|
+
exports.HarnessError = HarnessError;
|
|
2420
2654
|
exports.STABILITY_HOOKS_VERSION = STABILITY_HOOKS_VERSION;
|
|
2421
2655
|
exports.applyJudgments = applyJudgments;
|
|
2656
|
+
exports.assertLeftLoginPage = assertLeftLoginPage;
|
|
2422
2657
|
exports.captureScreenshot = captureScreenshot;
|
|
2423
2658
|
exports.configHash = configHash;
|
|
2424
2659
|
exports.diffEntry = diffEntry;
|
|
2425
2660
|
exports.discover = discover;
|
|
2426
2661
|
exports.installBrowsers = installBrowsers;
|
|
2427
2662
|
exports.loadConfig = loadConfig;
|
|
2663
|
+
exports.loadEnvFiles = loadEnvFiles;
|
|
2664
|
+
exports.loadHarness = loadHarness;
|
|
2428
2665
|
exports.loadManifest = loadManifest;
|
|
2429
2666
|
exports.paths = paths;
|
|
2430
2667
|
exports.resolveBaseUrl = resolveBaseUrl;
|
|
2668
|
+
exports.resolveHarnessFile = resolveHarnessFile;
|
|
2431
2669
|
exports.resolveJudge = resolveJudge;
|
|
2432
2670
|
exports.resumeGraph = resumeGraph;
|
|
2433
2671
|
exports.runCaptures = runCaptures;
|