@blazediff/agent 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -16,10 +16,10 @@ var sharp = require('sharp');
16
16
  var pc = require('picocolors');
17
17
  var langgraphCheckpoint = require('@langchain/langgraph-checkpoint');
18
18
  var coreNative = require('@blazediff/core-native');
19
- var promises$1 = require('readline/promises');
20
19
  var net = require('net');
21
20
  var util = require('util');
22
21
  var treeKill = require('tree-kill');
22
+ var promises$1 = require('readline/promises');
23
23
  var http = require('http');
24
24
 
25
25
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
@@ -51,7 +51,7 @@ var treeKill__default = /*#__PURE__*/_interopDefault(treeKill);
51
51
 
52
52
  // package.json
53
53
  var package_default = {
54
- version: "0.6.0"};
54
+ version: "0.8.0"};
55
55
  var FROZEN_NOW = Date.UTC(2025, 0, 1, 0, 0, 0);
56
56
  var STABILITY_CSS = `
57
57
  *,*::before,*::after{
@@ -3201,6 +3201,170 @@ async function resumeGraph(opts) {
3201
3201
  junitPath: opts.junitPath
3202
3202
  });
3203
3203
  }
3204
+ var execFileP = util.promisify(child_process.execFile);
3205
+ async function isPortOpen(port, host = "127.0.0.1") {
3206
+ return new Promise((resolve) => {
3207
+ const socket = net.createConnection({ port, host });
3208
+ socket.setTimeout(500);
3209
+ socket.once("connect", () => {
3210
+ socket.destroy();
3211
+ resolve(true);
3212
+ });
3213
+ socket.once("error", () => resolve(false));
3214
+ socket.once("timeout", () => {
3215
+ socket.destroy();
3216
+ resolve(false);
3217
+ });
3218
+ });
3219
+ }
3220
+ async function waitForPort(port, timeoutMs = 6e4) {
3221
+ const deadline = Date.now() + timeoutMs;
3222
+ while (Date.now() < deadline) {
3223
+ if (await isPortOpen(port)) return;
3224
+ await new Promise((r) => setTimeout(r, 250));
3225
+ }
3226
+ throw new Error(`dev server did not open port ${port} within ${timeoutMs}ms`);
3227
+ }
3228
+ async function findPidByPort(port) {
3229
+ const platform = process.platform;
3230
+ try {
3231
+ if (platform === "darwin" || platform === "linux") {
3232
+ const { stdout } = await execFileP("lsof", [
3233
+ "-ti",
3234
+ `tcp:${port}`,
3235
+ "-sTCP:LISTEN"
3236
+ ]);
3237
+ const pid = Number(stdout.trim().split("\n")[0]);
3238
+ return Number.isFinite(pid) && pid > 0 ? pid : null;
3239
+ }
3240
+ if (platform === "win32") {
3241
+ const { stdout } = await execFileP("netstat", ["-ano"]);
3242
+ const line = stdout.split(/\r?\n/).find((l) => l.includes(`:${port} `) && l.includes("LISTENING"));
3243
+ if (!line) return null;
3244
+ const parts = line.trim().split(/\s+/);
3245
+ const pid = Number(parts[parts.length - 1]);
3246
+ return Number.isFinite(pid) && pid > 0 ? pid : null;
3247
+ }
3248
+ } catch {
3249
+ return null;
3250
+ }
3251
+ return null;
3252
+ }
3253
+ async function startServer(opts) {
3254
+ const cwd = opts.cwd ?? process.cwd();
3255
+ const logPath = opts.logPath ?? paths(cwd).serverLog;
3256
+ const pidPath = opts.pidPath ?? paths(cwd).serverPid;
3257
+ await promises.mkdir(path26__default.default.dirname(logPath), { recursive: true });
3258
+ if (await isPortOpen(opts.port)) {
3259
+ const discoveredPid = await findPidByPort(opts.port);
3260
+ if (discoveredPid) {
3261
+ await promises.writeFile(pidPath, String(discoveredPid), "utf8").catch(() => {
3262
+ });
3263
+ }
3264
+ return {
3265
+ pid: discoveredPid ?? 0,
3266
+ port: opts.port,
3267
+ url: `http://127.0.0.1:${opts.port}`,
3268
+ attached: true
3269
+ };
3270
+ }
3271
+ const child = child_process.spawn(opts.command, {
3272
+ cwd,
3273
+ stdio: ["ignore", "pipe", "pipe"],
3274
+ detached: true,
3275
+ shell: true,
3276
+ env: { ...process.env, FORCE_COLOR: "0", CI: "1" }
3277
+ });
3278
+ const logStream = await import('fs').then(
3279
+ (m) => m.createWriteStream(logPath, { flags: "a" })
3280
+ );
3281
+ child.stdout?.pipe(logStream);
3282
+ child.stderr?.pipe(logStream);
3283
+ if (!child.pid) throw new Error("failed to spawn dev server");
3284
+ await promises.writeFile(pidPath, String(child.pid), "utf8");
3285
+ installSignalHandlers(child);
3286
+ try {
3287
+ await waitForPort(opts.port, opts.readyTimeoutMs ?? 6e4);
3288
+ } catch (err) {
3289
+ await stopProcess(child.pid);
3290
+ throw err;
3291
+ }
3292
+ return {
3293
+ pid: child.pid,
3294
+ port: opts.port,
3295
+ url: `http://127.0.0.1:${opts.port}`
3296
+ };
3297
+ }
3298
+ async function stopServer(cwd = process.cwd(), portFallback) {
3299
+ const pidPath = paths(cwd).serverPid;
3300
+ let pid = null;
3301
+ let via = "none";
3302
+ if (fs.existsSync(pidPath)) {
3303
+ const raw = (await promises.readFile(pidPath, "utf8")).trim();
3304
+ const parsed = Number(raw);
3305
+ if (Number.isFinite(parsed) && parsed > 0 && processExists(parsed)) {
3306
+ pid = parsed;
3307
+ via = "pidfile";
3308
+ }
3309
+ }
3310
+ if (!pid && portFallback) {
3311
+ pid = await findPidByPort(portFallback);
3312
+ if (pid) via = "port";
3313
+ }
3314
+ if (!pid) {
3315
+ await promises.writeFile(pidPath, "", "utf8").catch(() => {
3316
+ });
3317
+ return { killed: false, pid: null, via: "none" };
3318
+ }
3319
+ await stopProcess(pid);
3320
+ await promises.writeFile(pidPath, "", "utf8").catch(() => {
3321
+ });
3322
+ return { killed: true, pid, via };
3323
+ }
3324
+ function processExists(pid) {
3325
+ try {
3326
+ process.kill(pid, 0);
3327
+ return true;
3328
+ } catch {
3329
+ return false;
3330
+ }
3331
+ }
3332
+ async function stopProcess(pid) {
3333
+ if (!pid) return;
3334
+ await new Promise((resolve) => {
3335
+ treeKill__default.default(pid, "SIGTERM", (err) => {
3336
+ if (err) {
3337
+ treeKill__default.default(pid, "SIGKILL", () => resolve());
3338
+ return;
3339
+ }
3340
+ resolve();
3341
+ });
3342
+ });
3343
+ }
3344
+ var signalsInstalled = false;
3345
+ function installSignalHandlers(child) {
3346
+ if (signalsInstalled) return;
3347
+ signalsInstalled = true;
3348
+ const cleanup = () => {
3349
+ if (child.pid) {
3350
+ try {
3351
+ process.kill(-child.pid, "SIGTERM");
3352
+ } catch {
3353
+ }
3354
+ treeKill__default.default(child.pid, "SIGKILL", () => {
3355
+ });
3356
+ }
3357
+ };
3358
+ process.on("SIGINT", () => {
3359
+ cleanup();
3360
+ process.exit(130);
3361
+ });
3362
+ process.on("SIGTERM", () => {
3363
+ cleanup();
3364
+ process.exit(143);
3365
+ });
3366
+ process.on("exit", cleanup);
3367
+ }
3204
3368
 
3205
3369
  // src/cli/check-output.ts
3206
3370
  function slimResult(r) {
@@ -3399,6 +3563,21 @@ report: ${relPath(reportPath)}`;
3399
3563
  function exitCodeFor(report) {
3400
3564
  return report.failed > 0 ? 1 : void 0;
3401
3565
  }
3566
+ async function ensureDevServer(config, out) {
3567
+ const port = config?.devServer?.port;
3568
+ if (!config?.devServer || !port || await isPortOpen(port)) return;
3569
+ await startServer({
3570
+ command: config.devServer.command,
3571
+ port,
3572
+ readyTimeoutMs: config.devServer.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS
3573
+ });
3574
+ if (!out.isQuiet()) {
3575
+ process.stderr.write(
3576
+ `${dim(`dev server started on :${port} (serve-status --kill to stop)`)}
3577
+ `
3578
+ );
3579
+ }
3580
+ }
3402
3581
  function registerCheck(program, out) {
3403
3582
  program.command("check").description("run the visual regression check (CI verb)").option("--base-url <url>", "override base URL").option(
3404
3583
  "--threshold <n>",
@@ -3436,6 +3615,7 @@ function registerCheck(program, out) {
3436
3615
  }
3437
3616
  const config = await loadConfig();
3438
3617
  const baseUrl = resolveBaseUrl(config, opts.baseUrl);
3618
+ if (!opts.baseUrl) await ensureDevServer(config, out);
3439
3619
  const report = await runGraph({
3440
3620
  baseUrl,
3441
3621
  threshold: parseThreshold(opts.threshold),
@@ -3506,38 +3686,54 @@ async function crawlRoutes(opts) {
3506
3686
  const visited = /* @__PURE__ */ new Set(["/"]);
3507
3687
  const queue = [{ url: "/", depth: 0 }];
3508
3688
  const discovered = [];
3689
+ const recorded = /* @__PURE__ */ new Set();
3690
+ const record = (path30) => {
3691
+ if (recorded.has(path30)) return;
3692
+ recorded.add(path30);
3693
+ discovered.push({ url: path30, source: "crawl" });
3694
+ };
3509
3695
  const handle = await acquireStableContext(CRAWL_VIEWPORT);
3510
3696
  const fetchOne = async () => {
3511
3697
  while (queue.length && discovered.length < maxRoutes) {
3512
3698
  const item = queue.shift();
3513
3699
  if (!item) return;
3514
3700
  if (discovered.length >= maxRoutes) return;
3515
- discovered.push({ url: item.url, source: "crawl" });
3516
- if (item.depth >= maxDepth) continue;
3517
3701
  const page = await handle.context.newPage();
3702
+ const requested = new URL(item.url, base).toString();
3703
+ let finalPath = item.url;
3704
+ let resolved = requested;
3705
+ let hrefs = [];
3518
3706
  try {
3519
- const target = new URL(item.url, base).toString();
3520
- await page.goto(target, {
3707
+ await page.goto(requested, {
3521
3708
  waitUntil: "domcontentloaded",
3522
3709
  timeout: 15e3
3523
3710
  });
3524
- await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
3525
- });
3526
- const hrefs = await page.evaluate(
3527
- () => Array.from(
3528
- document.querySelectorAll("a[href]")
3529
- ).map((a) => a.getAttribute("href") ?? "")
3530
- );
3531
- for (const p of extractInternalLinks(base, target, hrefs)) {
3532
- if (visited.has(p)) continue;
3533
- visited.add(p);
3534
- queue.push({ url: p, depth: item.depth + 1 });
3711
+ const finalUrl = new URL(page.url());
3712
+ if (finalUrl.origin === base.origin) {
3713
+ resolved = finalUrl.toString();
3714
+ finalPath = finalUrl.pathname + finalUrl.search;
3715
+ }
3716
+ if (item.depth < maxDepth) {
3717
+ await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
3718
+ });
3719
+ hrefs = await page.evaluate(
3720
+ () => Array.from(
3721
+ document.querySelectorAll("a[href]")
3722
+ ).map((a) => a.getAttribute("href") ?? "")
3723
+ );
3535
3724
  }
3536
3725
  } catch {
3537
3726
  } finally {
3538
3727
  await page.close().catch(() => {
3539
3728
  });
3540
3729
  }
3730
+ record(finalPath);
3731
+ if (item.depth >= maxDepth) continue;
3732
+ for (const p of extractInternalLinks(base, resolved, hrefs)) {
3733
+ if (visited.has(p)) continue;
3734
+ visited.add(p);
3735
+ queue.push({ url: p, depth: item.depth + 1 });
3736
+ }
3541
3737
  }
3542
3738
  };
3543
3739
  try {
@@ -3582,6 +3778,17 @@ function collapseTemplates(routes, { threshold, samples } = DEFAULT_SAMPLING) {
3582
3778
  }
3583
3779
 
3584
3780
  // src/discover/index.ts
3781
+ function resolveSampling(discovery) {
3782
+ if (discovery?.sampleTemplates === false) return false;
3783
+ const { sampleThreshold, samplesPerTemplate } = discovery ?? {};
3784
+ if (sampleThreshold === void 0 && samplesPerTemplate === void 0) {
3785
+ return true;
3786
+ }
3787
+ return {
3788
+ threshold: sampleThreshold ?? DEFAULT_SAMPLE_THRESHOLD,
3789
+ samples: samplesPerTemplate ?? DEFAULT_SAMPLES_PER_TEMPLATE
3790
+ };
3791
+ }
3585
3792
  function normalizePath(url) {
3586
3793
  const [pathPart, query = ""] = url.split("?", 2);
3587
3794
  const trimmed = pathPart.replace(/\/+$/, "");
@@ -3626,18 +3833,19 @@ function registerDiscover(program, out) {
3626
3833
  "--sample-threshold <n>",
3627
3834
  "group size at which template sampling kicks in",
3628
3835
  String(DEFAULT_SAMPLE_THRESHOLD)
3629
- ).action(async (opts) => {
3630
- const baseUrl = resolveBaseUrl(await loadConfig(), opts.baseUrl);
3836
+ ).action(async (opts, command) => {
3837
+ const config = await loadConfig();
3838
+ const baseUrl = resolveBaseUrl(config, opts.baseUrl);
3839
+ const fromCli = (name) => command.getOptionValueSource(name) === "cli";
3840
+ const d = config?.discovery;
3841
+ const maxRoutes = fromCli("maxRoutes") ? Number(opts.maxRoutes) : d?.maxRoutes ?? Number(opts.maxRoutes);
3842
+ const sampleOn = fromCli("sampleTemplates") ? opts.sampleTemplates : d?.sampleTemplates ?? true;
3843
+ const threshold = fromCli("sampleThreshold") ? posInt(opts.sampleThreshold, DEFAULT_SAMPLE_THRESHOLD) : d?.sampleThreshold ?? DEFAULT_SAMPLE_THRESHOLD;
3844
+ const samples = fromCli("samplesPerTemplate") ? posInt(opts.samplesPerTemplate, DEFAULT_SAMPLES_PER_TEMPLATE) : d?.samplesPerTemplate ?? DEFAULT_SAMPLES_PER_TEMPLATE;
3631
3845
  const routes = await discover({
3632
3846
  baseUrl,
3633
- maxRoutes: Number(opts.maxRoutes),
3634
- sampleTemplates: opts.sampleTemplates && {
3635
- threshold: posInt(opts.sampleThreshold, DEFAULT_SAMPLE_THRESHOLD),
3636
- samples: posInt(
3637
- opts.samplesPerTemplate,
3638
- DEFAULT_SAMPLES_PER_TEMPLATE
3639
- )
3640
- }
3847
+ maxRoutes,
3848
+ sampleTemplates: sampleOn && { threshold, samples }
3641
3849
  });
3642
3850
  await closeBrowser();
3643
3851
  out.emit(
@@ -4470,170 +4678,6 @@ async function installStack(stack, cwd, opts = {}) {
4470
4678
  }
4471
4679
  return { stack, path: target, status: combineStatuses(statuses) };
4472
4680
  }
4473
- var execFileP = util.promisify(child_process.execFile);
4474
- async function isPortOpen(port, host = "127.0.0.1") {
4475
- return new Promise((resolve) => {
4476
- const socket = net.createConnection({ port, host });
4477
- socket.setTimeout(500);
4478
- socket.once("connect", () => {
4479
- socket.destroy();
4480
- resolve(true);
4481
- });
4482
- socket.once("error", () => resolve(false));
4483
- socket.once("timeout", () => {
4484
- socket.destroy();
4485
- resolve(false);
4486
- });
4487
- });
4488
- }
4489
- async function waitForPort(port, timeoutMs = 6e4) {
4490
- const deadline = Date.now() + timeoutMs;
4491
- while (Date.now() < deadline) {
4492
- if (await isPortOpen(port)) return;
4493
- await new Promise((r) => setTimeout(r, 250));
4494
- }
4495
- throw new Error(`dev server did not open port ${port} within ${timeoutMs}ms`);
4496
- }
4497
- async function findPidByPort(port) {
4498
- const platform = process.platform;
4499
- try {
4500
- if (platform === "darwin" || platform === "linux") {
4501
- const { stdout } = await execFileP("lsof", [
4502
- "-ti",
4503
- `tcp:${port}`,
4504
- "-sTCP:LISTEN"
4505
- ]);
4506
- const pid = Number(stdout.trim().split("\n")[0]);
4507
- return Number.isFinite(pid) && pid > 0 ? pid : null;
4508
- }
4509
- if (platform === "win32") {
4510
- const { stdout } = await execFileP("netstat", ["-ano"]);
4511
- const line = stdout.split(/\r?\n/).find((l) => l.includes(`:${port} `) && l.includes("LISTENING"));
4512
- if (!line) return null;
4513
- const parts = line.trim().split(/\s+/);
4514
- const pid = Number(parts[parts.length - 1]);
4515
- return Number.isFinite(pid) && pid > 0 ? pid : null;
4516
- }
4517
- } catch {
4518
- return null;
4519
- }
4520
- return null;
4521
- }
4522
- async function startServer(opts) {
4523
- const cwd = opts.cwd ?? process.cwd();
4524
- const logPath = opts.logPath ?? paths(cwd).serverLog;
4525
- const pidPath = opts.pidPath ?? paths(cwd).serverPid;
4526
- await promises.mkdir(path26__default.default.dirname(logPath), { recursive: true });
4527
- if (await isPortOpen(opts.port)) {
4528
- const discoveredPid = await findPidByPort(opts.port);
4529
- if (discoveredPid) {
4530
- await promises.writeFile(pidPath, String(discoveredPid), "utf8").catch(() => {
4531
- });
4532
- }
4533
- return {
4534
- pid: discoveredPid ?? 0,
4535
- port: opts.port,
4536
- url: `http://127.0.0.1:${opts.port}`,
4537
- attached: true
4538
- };
4539
- }
4540
- const child = child_process.spawn(opts.command, {
4541
- cwd,
4542
- stdio: ["ignore", "pipe", "pipe"],
4543
- detached: true,
4544
- shell: true,
4545
- env: { ...process.env, FORCE_COLOR: "0", CI: "1" }
4546
- });
4547
- const logStream = await import('fs').then(
4548
- (m) => m.createWriteStream(logPath, { flags: "a" })
4549
- );
4550
- child.stdout?.pipe(logStream);
4551
- child.stderr?.pipe(logStream);
4552
- if (!child.pid) throw new Error("failed to spawn dev server");
4553
- await promises.writeFile(pidPath, String(child.pid), "utf8");
4554
- installSignalHandlers(child);
4555
- try {
4556
- await waitForPort(opts.port, opts.readyTimeoutMs ?? 6e4);
4557
- } catch (err) {
4558
- await stopProcess(child.pid);
4559
- throw err;
4560
- }
4561
- return {
4562
- pid: child.pid,
4563
- port: opts.port,
4564
- url: `http://127.0.0.1:${opts.port}`
4565
- };
4566
- }
4567
- async function stopServer(cwd = process.cwd(), portFallback) {
4568
- const pidPath = paths(cwd).serverPid;
4569
- let pid = null;
4570
- let via = "none";
4571
- if (fs.existsSync(pidPath)) {
4572
- const raw = (await promises.readFile(pidPath, "utf8")).trim();
4573
- const parsed = Number(raw);
4574
- if (Number.isFinite(parsed) && parsed > 0 && processExists(parsed)) {
4575
- pid = parsed;
4576
- via = "pidfile";
4577
- }
4578
- }
4579
- if (!pid && portFallback) {
4580
- pid = await findPidByPort(portFallback);
4581
- if (pid) via = "port";
4582
- }
4583
- if (!pid) {
4584
- await promises.writeFile(pidPath, "", "utf8").catch(() => {
4585
- });
4586
- return { killed: false, pid: null, via: "none" };
4587
- }
4588
- await stopProcess(pid);
4589
- await promises.writeFile(pidPath, "", "utf8").catch(() => {
4590
- });
4591
- return { killed: true, pid, via };
4592
- }
4593
- function processExists(pid) {
4594
- try {
4595
- process.kill(pid, 0);
4596
- return true;
4597
- } catch {
4598
- return false;
4599
- }
4600
- }
4601
- async function stopProcess(pid) {
4602
- if (!pid) return;
4603
- await new Promise((resolve) => {
4604
- treeKill__default.default(pid, "SIGTERM", (err) => {
4605
- if (err) {
4606
- treeKill__default.default(pid, "SIGKILL", () => resolve());
4607
- return;
4608
- }
4609
- resolve();
4610
- });
4611
- });
4612
- }
4613
- var signalsInstalled = false;
4614
- function installSignalHandlers(child) {
4615
- if (signalsInstalled) return;
4616
- signalsInstalled = true;
4617
- const cleanup = () => {
4618
- if (child.pid) {
4619
- try {
4620
- process.kill(-child.pid, "SIGTERM");
4621
- } catch {
4622
- }
4623
- treeKill__default.default(child.pid, "SIGKILL", () => {
4624
- });
4625
- }
4626
- };
4627
- process.on("SIGINT", () => {
4628
- cleanup();
4629
- process.exit(130);
4630
- });
4631
- process.on("SIGTERM", () => {
4632
- cleanup();
4633
- process.exit(143);
4634
- });
4635
- process.on("exit", cleanup);
4636
- }
4637
4681
 
4638
4682
  // src/cli/commands/onboard.ts
4639
4683
  async function promptForStacks() {
@@ -4696,7 +4740,11 @@ async function captureBaselines(config, baseUrl) {
4696
4740
  startedByUs = true;
4697
4741
  }
4698
4742
  try {
4699
- const discovered = await discover({ baseUrl });
4743
+ const discovered = await discover({
4744
+ baseUrl,
4745
+ maxRoutes: config.discovery?.maxRoutes,
4746
+ sampleTemplates: resolveSampling(config.discovery)
4747
+ });
4700
4748
  const routes = toCaptureRoutes(discovered);
4701
4749
  if (routes.length === 0) return { captured: 0, routes: 0 };
4702
4750
  const report = await runCaptures({
@@ -4746,7 +4794,10 @@ function registerOnboard(program, out) {
4746
4794
  ).option("--dev-command <cmd>", "override detected dev-server command").option("--port <n>", "override detected port").option(
4747
4795
  "--dev-script <name>",
4748
4796
  "select a dev script by name when multiple candidates exist"
4749
- ).option("--no-browsers", "skip the Chromium install step").option("--no-capture", "skip the baseline-capture step").option("--yes", "accept all prompts (capture baselines, install Chromium)").action(async (opts) => {
4797
+ ).option("--no-browsers", "skip the Chromium install step").option("--no-capture", "skip the baseline-capture step").option(
4798
+ "--no-sample-templates",
4799
+ "capture every reachable route; don't collapse large list/detail groups (persisted to config.discovery)"
4800
+ ).option("--yes", "accept all prompts (capture baselines, install Chromium)").action(async (opts) => {
4750
4801
  const cwd = process.cwd();
4751
4802
  const interactive = out.isTTY() && !out.isJson();
4752
4803
  const lines = [];
@@ -4768,6 +4819,16 @@ function registerOnboard(program, out) {
4768
4819
  throw err;
4769
4820
  }
4770
4821
  }
4822
+ if (config && opts.sampleTemplates === false && config.discovery?.sampleTemplates !== false) {
4823
+ config = {
4824
+ ...config,
4825
+ discovery: { ...config.discovery, sampleTemplates: false }
4826
+ };
4827
+ await saveConfig(config, cwd);
4828
+ lines.push(
4829
+ "discovery: template sampling disabled (config.discovery.sampleTemplates=false)"
4830
+ );
4831
+ }
4771
4832
  let chromium2 = {
4772
4833
  installed: true,
4773
4834
  skipped: true
package/dist/index.d.mts CHANGED
@@ -132,6 +132,21 @@ interface DevServerConfig {
132
132
  cwd?: string;
133
133
  readyTimeoutMs?: number;
134
134
  }
135
+ /** Route-discovery tuning, honored by both `discover` and `onboard` captures. */
136
+ interface DiscoveryConfig {
137
+ /** cap on routes returned (default 50) */
138
+ maxRoutes?: number;
139
+ /**
140
+ * Collapse large list/detail template groups (e.g. /blog/:slug) down to a
141
+ * few representatives. Set `false` for content sites where sibling routes are
142
+ * distinct pages you want fully covered (default true).
143
+ */
144
+ sampleTemplates?: boolean;
145
+ /** representatives kept per sampled group (default 2) */
146
+ samplesPerTemplate?: number;
147
+ /** group size at which sampling kicks in (default 5) */
148
+ sampleThreshold?: number;
149
+ }
135
150
  interface AgentConfig {
136
151
  devServer: DevServerConfig | null;
137
152
  framework?: string;
@@ -139,6 +154,8 @@ interface AgentConfig {
139
154
  baseUrl?: string;
140
155
  /** default judge backend for `check`, set by `onboard --stack` */
141
156
  judge?: JudgeBackend;
157
+ /** route-discovery tuning for `discover` and `onboard` captures */
158
+ discovery?: DiscoveryConfig;
142
159
  }
143
160
  interface CaptureOptions {
144
161
  id: string;
@@ -493,4 +510,4 @@ declare function approveEntry(id: string, cwd?: string): Promise<ReviewEntry | n
493
510
  */
494
511
  declare function rejectEntry(id: string, cwd?: string): Promise<ReviewEntry | null>;
495
512
 
496
- export { type AgentConfig, type ApplyJudgmentsResult, type BrowsersInstallOptions, type BrowsersInstallResult, type CaptureOptions, type CaptureRouteInput, type CaptureRouteResult, type CheckOptions, type CheckReport, type CheckResult, type DevServerConfig, type DiffOptions, type DiffOutcome, type DiscoveredRoute, type Harness, type HarnessContext, HarnessError, type HarnessRef, type Judge, type JudgeBackend, type JudgeInput, type JudgeOutput, type JudgmentRequest, type JudgmentRequestRegion, type Manifest, type ManifestEntry, type RegionSummary, type ResumeMap, type ResumeOptions, type ReviewEntry, type ReviewPayload, type ReviewRegion, type ReviewRunMeta, type ReviewStatus, type RunCapturesOptions, type RunCapturesReport, type RunEvent, type RunOptions, STABILITY_HOOKS_VERSION, type Verdict, type VerdictAction, type VerdictLabel, type Viewport, type WaitFor, type WaitForSelector, applyJudgments, approveEntry, assertLeftLoginPage, captureScreenshot, configHash, diffEntry, discover, installBrowsers, loadConfig, loadEnvFiles, loadHarness, loadManifest, paths, readReport, rejectEntry, resolveBaseUrl, resolveHarnessFile, resolveJudge, resumeGraph, runCaptures, runCheck, runGraph, saveConfig, saveManifest, threadIdFor, writeReport };
513
+ export { type AgentConfig, type ApplyJudgmentsResult, type BrowsersInstallOptions, type BrowsersInstallResult, type CaptureOptions, type CaptureRouteInput, type CaptureRouteResult, type CheckOptions, type CheckReport, type CheckResult, type DevServerConfig, type DiffOptions, type DiffOutcome, type DiscoveredRoute, type DiscoveryConfig, type Harness, type HarnessContext, HarnessError, type HarnessRef, type Judge, type JudgeBackend, type JudgeInput, type JudgeOutput, type JudgmentRequest, type JudgmentRequestRegion, type Manifest, type ManifestEntry, type RegionSummary, type ResumeMap, type ResumeOptions, type ReviewEntry, type ReviewPayload, type ReviewRegion, type ReviewRunMeta, type ReviewStatus, type RunCapturesOptions, type RunCapturesReport, type RunEvent, type RunOptions, STABILITY_HOOKS_VERSION, type Verdict, type VerdictAction, type VerdictLabel, type Viewport, type WaitFor, type WaitForSelector, applyJudgments, approveEntry, assertLeftLoginPage, captureScreenshot, configHash, diffEntry, discover, installBrowsers, loadConfig, loadEnvFiles, loadHarness, loadManifest, paths, readReport, rejectEntry, resolveBaseUrl, resolveHarnessFile, resolveJudge, resumeGraph, runCaptures, runCheck, runGraph, saveConfig, saveManifest, threadIdFor, writeReport };
package/dist/index.d.ts CHANGED
@@ -132,6 +132,21 @@ interface DevServerConfig {
132
132
  cwd?: string;
133
133
  readyTimeoutMs?: number;
134
134
  }
135
+ /** Route-discovery tuning, honored by both `discover` and `onboard` captures. */
136
+ interface DiscoveryConfig {
137
+ /** cap on routes returned (default 50) */
138
+ maxRoutes?: number;
139
+ /**
140
+ * Collapse large list/detail template groups (e.g. /blog/:slug) down to a
141
+ * few representatives. Set `false` for content sites where sibling routes are
142
+ * distinct pages you want fully covered (default true).
143
+ */
144
+ sampleTemplates?: boolean;
145
+ /** representatives kept per sampled group (default 2) */
146
+ samplesPerTemplate?: number;
147
+ /** group size at which sampling kicks in (default 5) */
148
+ sampleThreshold?: number;
149
+ }
135
150
  interface AgentConfig {
136
151
  devServer: DevServerConfig | null;
137
152
  framework?: string;
@@ -139,6 +154,8 @@ interface AgentConfig {
139
154
  baseUrl?: string;
140
155
  /** default judge backend for `check`, set by `onboard --stack` */
141
156
  judge?: JudgeBackend;
157
+ /** route-discovery tuning for `discover` and `onboard` captures */
158
+ discovery?: DiscoveryConfig;
142
159
  }
143
160
  interface CaptureOptions {
144
161
  id: string;
@@ -493,4 +510,4 @@ declare function approveEntry(id: string, cwd?: string): Promise<ReviewEntry | n
493
510
  */
494
511
  declare function rejectEntry(id: string, cwd?: string): Promise<ReviewEntry | null>;
495
512
 
496
- export { type AgentConfig, type ApplyJudgmentsResult, type BrowsersInstallOptions, type BrowsersInstallResult, type CaptureOptions, type CaptureRouteInput, type CaptureRouteResult, type CheckOptions, type CheckReport, type CheckResult, type DevServerConfig, type DiffOptions, type DiffOutcome, type DiscoveredRoute, type Harness, type HarnessContext, HarnessError, type HarnessRef, type Judge, type JudgeBackend, type JudgeInput, type JudgeOutput, type JudgmentRequest, type JudgmentRequestRegion, type Manifest, type ManifestEntry, type RegionSummary, type ResumeMap, type ResumeOptions, type ReviewEntry, type ReviewPayload, type ReviewRegion, type ReviewRunMeta, type ReviewStatus, type RunCapturesOptions, type RunCapturesReport, type RunEvent, type RunOptions, STABILITY_HOOKS_VERSION, type Verdict, type VerdictAction, type VerdictLabel, type Viewport, type WaitFor, type WaitForSelector, applyJudgments, approveEntry, assertLeftLoginPage, captureScreenshot, configHash, diffEntry, discover, installBrowsers, loadConfig, loadEnvFiles, loadHarness, loadManifest, paths, readReport, rejectEntry, resolveBaseUrl, resolveHarnessFile, resolveJudge, resumeGraph, runCaptures, runCheck, runGraph, saveConfig, saveManifest, threadIdFor, writeReport };
513
+ export { type AgentConfig, type ApplyJudgmentsResult, type BrowsersInstallOptions, type BrowsersInstallResult, type CaptureOptions, type CaptureRouteInput, type CaptureRouteResult, type CheckOptions, type CheckReport, type CheckResult, type DevServerConfig, type DiffOptions, type DiffOutcome, type DiscoveredRoute, type DiscoveryConfig, type Harness, type HarnessContext, HarnessError, type HarnessRef, type Judge, type JudgeBackend, type JudgeInput, type JudgeOutput, type JudgmentRequest, type JudgmentRequestRegion, type Manifest, type ManifestEntry, type RegionSummary, type ResumeMap, type ResumeOptions, type ReviewEntry, type ReviewPayload, type ReviewRegion, type ReviewRunMeta, type ReviewStatus, type RunCapturesOptions, type RunCapturesReport, type RunEvent, type RunOptions, STABILITY_HOOKS_VERSION, type Verdict, type VerdictAction, type VerdictLabel, type Viewport, type WaitFor, type WaitForSelector, applyJudgments, approveEntry, assertLeftLoginPage, captureScreenshot, configHash, diffEntry, discover, installBrowsers, loadConfig, loadEnvFiles, loadHarness, loadManifest, paths, readReport, rejectEntry, resolveBaseUrl, resolveHarnessFile, resolveJudge, resumeGraph, runCaptures, runCheck, runGraph, saveConfig, saveManifest, threadIdFor, writeReport };
package/dist/index.js CHANGED
@@ -895,38 +895,54 @@ async function crawlRoutes(opts) {
895
895
  const visited = /* @__PURE__ */ new Set(["/"]);
896
896
  const queue = [{ url: "/", depth: 0 }];
897
897
  const discovered = [];
898
+ const recorded = /* @__PURE__ */ new Set();
899
+ const record = (path22) => {
900
+ if (recorded.has(path22)) return;
901
+ recorded.add(path22);
902
+ discovered.push({ url: path22, source: "crawl" });
903
+ };
898
904
  const handle = await acquireStableContext(CRAWL_VIEWPORT);
899
905
  const fetchOne = async () => {
900
906
  while (queue.length && discovered.length < maxRoutes) {
901
907
  const item = queue.shift();
902
908
  if (!item) return;
903
909
  if (discovered.length >= maxRoutes) return;
904
- discovered.push({ url: item.url, source: "crawl" });
905
- if (item.depth >= maxDepth) continue;
906
910
  const page = await handle.context.newPage();
911
+ const requested = new URL(item.url, base).toString();
912
+ let finalPath = item.url;
913
+ let resolved = requested;
914
+ let hrefs = [];
907
915
  try {
908
- const target = new URL(item.url, base).toString();
909
- await page.goto(target, {
916
+ await page.goto(requested, {
910
917
  waitUntil: "domcontentloaded",
911
918
  timeout: 15e3
912
919
  });
913
- await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
914
- });
915
- const hrefs = await page.evaluate(
916
- () => Array.from(
917
- document.querySelectorAll("a[href]")
918
- ).map((a) => a.getAttribute("href") ?? "")
919
- );
920
- for (const p of extractInternalLinks(base, target, hrefs)) {
921
- if (visited.has(p)) continue;
922
- visited.add(p);
923
- queue.push({ url: p, depth: item.depth + 1 });
920
+ const finalUrl = new URL(page.url());
921
+ if (finalUrl.origin === base.origin) {
922
+ resolved = finalUrl.toString();
923
+ finalPath = finalUrl.pathname + finalUrl.search;
924
+ }
925
+ if (item.depth < maxDepth) {
926
+ await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
927
+ });
928
+ hrefs = await page.evaluate(
929
+ () => Array.from(
930
+ document.querySelectorAll("a[href]")
931
+ ).map((a) => a.getAttribute("href") ?? "")
932
+ );
924
933
  }
925
934
  } catch {
926
935
  } finally {
927
936
  await page.close().catch(() => {
928
937
  });
929
938
  }
939
+ record(finalPath);
940
+ if (item.depth >= maxDepth) continue;
941
+ for (const p of extractInternalLinks(base, resolved, hrefs)) {
942
+ if (visited.has(p)) continue;
943
+ visited.add(p);
944
+ queue.push({ url: p, depth: item.depth + 1 });
945
+ }
930
946
  }
931
947
  };
932
948
  try {
package/dist/index.mjs CHANGED
@@ -867,38 +867,54 @@ async function crawlRoutes(opts) {
867
867
  const visited = /* @__PURE__ */ new Set(["/"]);
868
868
  const queue = [{ url: "/", depth: 0 }];
869
869
  const discovered = [];
870
+ const recorded = /* @__PURE__ */ new Set();
871
+ const record = (path22) => {
872
+ if (recorded.has(path22)) return;
873
+ recorded.add(path22);
874
+ discovered.push({ url: path22, source: "crawl" });
875
+ };
870
876
  const handle = await acquireStableContext(CRAWL_VIEWPORT);
871
877
  const fetchOne = async () => {
872
878
  while (queue.length && discovered.length < maxRoutes) {
873
879
  const item = queue.shift();
874
880
  if (!item) return;
875
881
  if (discovered.length >= maxRoutes) return;
876
- discovered.push({ url: item.url, source: "crawl" });
877
- if (item.depth >= maxDepth) continue;
878
882
  const page = await handle.context.newPage();
883
+ const requested = new URL(item.url, base).toString();
884
+ let finalPath = item.url;
885
+ let resolved = requested;
886
+ let hrefs = [];
879
887
  try {
880
- const target = new URL(item.url, base).toString();
881
- await page.goto(target, {
888
+ await page.goto(requested, {
882
889
  waitUntil: "domcontentloaded",
883
890
  timeout: 15e3
884
891
  });
885
- await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
886
- });
887
- const hrefs = await page.evaluate(
888
- () => Array.from(
889
- document.querySelectorAll("a[href]")
890
- ).map((a) => a.getAttribute("href") ?? "")
891
- );
892
- for (const p of extractInternalLinks(base, target, hrefs)) {
893
- if (visited.has(p)) continue;
894
- visited.add(p);
895
- queue.push({ url: p, depth: item.depth + 1 });
892
+ const finalUrl = new URL(page.url());
893
+ if (finalUrl.origin === base.origin) {
894
+ resolved = finalUrl.toString();
895
+ finalPath = finalUrl.pathname + finalUrl.search;
896
+ }
897
+ if (item.depth < maxDepth) {
898
+ await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
899
+ });
900
+ hrefs = await page.evaluate(
901
+ () => Array.from(
902
+ document.querySelectorAll("a[href]")
903
+ ).map((a) => a.getAttribute("href") ?? "")
904
+ );
896
905
  }
897
906
  } catch {
898
907
  } finally {
899
908
  await page.close().catch(() => {
900
909
  });
901
910
  }
911
+ record(finalPath);
912
+ if (item.depth >= maxDepth) continue;
913
+ for (const p of extractInternalLinks(base, resolved, hrefs)) {
914
+ if (visited.has(p)) continue;
915
+ visited.add(p);
916
+ queue.push({ url: p, depth: item.depth + 1 });
917
+ }
902
918
  }
903
919
  };
904
920
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazediff/agent",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Agentic visual regression for BlazeDiff. Auto-discovers routes, captures deterministic screenshots, runs CI checks.",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -48,7 +48,7 @@
48
48
  "sharp": "^0.34.0",
49
49
  "tree-kill": "^1.2.2",
50
50
  "zod": "^3.25.32",
51
- "@blazediff/core-native": "5.0.0"
51
+ "@blazediff/core-native": "5.1.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@huggingface/transformers": "^4.2.0"