@blazediff/agent 0.4.0 → 0.6.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
@@ -6,7 +6,7 @@ var playwright = require('playwright');
6
6
  var child_process = require('child_process');
7
7
  var fs = require('fs');
8
8
  var module$1 = require('module');
9
- var path27 = require('path');
9
+ var path26 = require('path');
10
10
  var promises = require('fs/promises');
11
11
  var os = require('os');
12
12
  var url = require('url');
@@ -43,7 +43,7 @@ function _interopNamespace(e) {
43
43
  return Object.freeze(n);
44
44
  }
45
45
 
46
- var path27__default = /*#__PURE__*/_interopDefault(path27);
46
+ var path26__default = /*#__PURE__*/_interopDefault(path26);
47
47
  var sharp__default = /*#__PURE__*/_interopDefault(sharp);
48
48
  var pc__default = /*#__PURE__*/_interopDefault(pc);
49
49
  var util__namespace = /*#__PURE__*/_interopNamespace(util);
@@ -51,7 +51,7 @@ var treeKill__default = /*#__PURE__*/_interopDefault(treeKill);
51
51
 
52
52
  // package.json
53
53
  var package_default = {
54
- version: "0.4.0"};
54
+ version: "0.6.0"};
55
55
  var FROZEN_NOW = Date.UTC(2025, 0, 1, 0, 0, 0);
56
56
  var STABILITY_CSS = `
57
57
  *,*::before,*::after{
@@ -246,10 +246,10 @@ async function applyMaskOverlays(page, masks) {
246
246
  function resolvePlaywrightCli() {
247
247
  const require_ = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.js', document.baseURI).href)));
248
248
  const pkgJson = require_.resolve("playwright/package.json");
249
- const dir = path27__default.default.dirname(pkgJson);
249
+ const dir = path26__default.default.dirname(pkgJson);
250
250
  const candidates = [
251
- path27__default.default.join(dir, "cli.js"),
252
- path27__default.default.join(dir, "lib", "cli.js")
251
+ path26__default.default.join(dir, "cli.js"),
252
+ path26__default.default.join(dir, "lib", "cli.js")
253
253
  ];
254
254
  const found = candidates.find((p) => fs.existsSync(p));
255
255
  if (!found) {
@@ -326,20 +326,20 @@ function defaultConcurrency() {
326
326
  }
327
327
  var BLAZEDIFF_DIR = ".blazediff";
328
328
  var paths = (cwd = process.cwd()) => {
329
- const root = path27__default.default.join(cwd, BLAZEDIFF_DIR);
329
+ const root = path26__default.default.join(cwd, BLAZEDIFF_DIR);
330
330
  return {
331
331
  root,
332
- config: path27__default.default.join(root, "config.json"),
333
- manifest: path27__default.default.join(root, "manifest.json"),
334
- harnesses: path27__default.default.join(root, "harnesses"),
335
- baselines: path27__default.default.join(root, "baselines"),
336
- actual: path27__default.default.join(root, "actual"),
337
- judgments: path27__default.default.join(root, "judgments"),
338
- checkpoints: path27__default.default.join(root, "checkpoints"),
339
- report: path27__default.default.join(root, "report.json"),
340
- gitignore: path27__default.default.join(root, ".gitignore"),
341
- serverLog: path27__default.default.join(root, "dev-server.log"),
342
- serverPid: path27__default.default.join(root, "dev-server.pid")
332
+ config: path26__default.default.join(root, "config.json"),
333
+ manifest: path26__default.default.join(root, "manifest.json"),
334
+ harnesses: path26__default.default.join(root, "harnesses"),
335
+ baselines: path26__default.default.join(root, "baselines"),
336
+ actual: path26__default.default.join(root, "actual"),
337
+ judgments: path26__default.default.join(root, "judgments"),
338
+ checkpoints: path26__default.default.join(root, "checkpoints"),
339
+ report: path26__default.default.join(root, "report.json"),
340
+ gitignore: path26__default.default.join(root, ".gitignore"),
341
+ serverLog: path26__default.default.join(root, "dev-server.log"),
342
+ serverPid: path26__default.default.join(root, "dev-server.pid")
343
343
  };
344
344
  };
345
345
 
@@ -353,16 +353,16 @@ var HarnessError = class extends Error {
353
353
  };
354
354
  var moduleCache = /* @__PURE__ */ new Map();
355
355
  function resolveHarnessFile(name, cwd) {
356
- if (name.includes("/") || name.includes("\\") || path27__default.default.isAbsolute(name)) {
357
- return path27__default.default.isAbsolute(name) ? name : path27__default.default.resolve(cwd, name);
356
+ if (name.includes("/") || name.includes("\\") || path26__default.default.isAbsolute(name)) {
357
+ return path26__default.default.isAbsolute(name) ? name : path26__default.default.resolve(cwd, name);
358
358
  }
359
359
  const dir = paths(cwd).harnesses;
360
- const mjs = path27__default.default.join(dir, `${name}.mjs`);
360
+ const mjs = path26__default.default.join(dir, `${name}.mjs`);
361
361
  if (fs.existsSync(mjs)) return mjs;
362
- return path27__default.default.join(dir, `${name}.js`);
362
+ return path26__default.default.join(dir, `${name}.js`);
363
363
  }
364
364
  async function loadHarness(harnessFile) {
365
- const absolute = path27__default.default.isAbsolute(harnessFile) ? harnessFile : path27__default.default.resolve(process.cwd(), harnessFile);
365
+ const absolute = path26__default.default.isAbsolute(harnessFile) ? harnessFile : path26__default.default.resolve(process.cwd(), harnessFile);
366
366
  if (!fs.existsSync(absolute)) {
367
367
  throw new HarnessError(
368
368
  `harness not found at ${absolute}. Author one under .blazediff/harnesses/ (or run \`blazediff-agent harness record <name>\` to record one).`
@@ -404,7 +404,7 @@ async function loadHarness(harnessFile) {
404
404
  // src/browser/capture.ts
405
405
  var SCREENSHOT_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/i;
406
406
  async function shoot(page, outputPath, fullPage) {
407
- await promises.mkdir(path27__default.default.dirname(outputPath), { recursive: true });
407
+ await promises.mkdir(path26__default.default.dirname(outputPath), { recursive: true });
408
408
  const buffer = await page.screenshot({
409
409
  path: outputPath,
410
410
  type: "png",
@@ -457,7 +457,7 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
457
457
  await page.goto(url, { waitUntil: "domcontentloaded", timeout: 3e4 });
458
458
  await stabilize(page, waitFor, masks);
459
459
  const outputDir = opts.mode === "baseline" ? paths(cwd).baselines : paths(cwd).actual;
460
- const outputPath = path27__default.default.join(outputDir, `${opts.id}.png`);
460
+ const outputPath = path26__default.default.join(outputDir, `${opts.id}.png`);
461
461
  const bytes = await shoot(page, outputPath, fullPage);
462
462
  const subCaptures = [];
463
463
  const used = /* @__PURE__ */ new Set();
@@ -472,7 +472,7 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
472
472
  }
473
473
  used.add(name);
474
474
  await stabilize(page, waitFor, masks);
475
- const subPath = path27__default.default.join(outputDir, `${opts.id}__${name}.png`);
475
+ const subPath = path26__default.default.join(outputDir, `${opts.id}__${name}.png`);
476
476
  const subBytes = await shoot(page, subPath, fullPage);
477
477
  subCaptures.push({ name, outputPath: subPath, bytes: subBytes });
478
478
  };
@@ -499,7 +499,7 @@ async function loadConfig(cwd = process.cwd()) {
499
499
  }
500
500
  async function saveConfig(config, cwd = process.cwd()) {
501
501
  const file = paths(cwd).config;
502
- await promises.mkdir(path27__default.default.dirname(file), { recursive: true });
502
+ await promises.mkdir(path26__default.default.dirname(file), { recursive: true });
503
503
  await promises.writeFile(file, `${JSON.stringify(config, null, 2)}
504
504
  `, "utf8");
505
505
  }
@@ -510,7 +510,9 @@ function resolveBaseUrl(config, override) {
510
510
  if (override) return override;
511
511
  if (config?.baseUrl) return config.baseUrl;
512
512
  if (config?.devServer) return `http://127.0.0.1:${config.devServer.port}`;
513
- throw new Error("no baseUrl: pass --base-url or run `blazediff-agent init`");
513
+ throw new Error(
514
+ "no baseUrl: pass --base-url or run `blazediff-agent onboard`"
515
+ );
514
516
  }
515
517
 
516
518
  // src/graph/semaphore.ts
@@ -555,7 +557,7 @@ async function loadManifest(cwd = process.cwd()) {
555
557
  }
556
558
  async function saveManifest(manifest, cwd = process.cwd()) {
557
559
  const file = paths(cwd).manifest;
558
- await promises.mkdir(path27__default.default.dirname(file), { recursive: true });
560
+ await promises.mkdir(path26__default.default.dirname(file), { recursive: true });
559
561
  await promises.writeFile(file, `${JSON.stringify(manifest, null, 2)}
560
562
  `, "utf8");
561
563
  }
@@ -596,7 +598,7 @@ function makeEntry(input) {
596
598
  fullPage,
597
599
  parent: input.parent,
598
600
  derived: input.derived || void 0,
599
- baselinePath: path27__default.default.posix.join(".blazediff", "baselines", `${input.id}.png`),
601
+ baselinePath: path26__default.default.posix.join(".blazediff", "baselines", `${input.id}.png`),
600
602
  captureHash: hashMaterial({
601
603
  url: input.url,
602
604
  viewport,
@@ -871,7 +873,7 @@ async function resolveRoutes(opts) {
871
873
  }
872
874
  if (opts.routes) {
873
875
  return parseRoutesPayload(
874
- await promises.readFile(path27__default.default.resolve(opts.routes), "utf8")
876
+ await promises.readFile(path26__default.default.resolve(opts.routes), "utf8")
875
877
  );
876
878
  }
877
879
  if (opts.stdin) {
@@ -950,7 +952,7 @@ var STALE_ENTRIES = /* @__PURE__ */ new Set([
950
952
  var HEADER = "# blazediff: generated artifacts (committed: config.json, manifest.json, baselines/, harnesses/)\n";
951
953
  async function ensureGitignore(cwd) {
952
954
  const file = paths(cwd).gitignore;
953
- await promises.mkdir(path27__default.default.dirname(file), { recursive: true });
955
+ await promises.mkdir(path26__default.default.dirname(file), { recursive: true });
954
956
  const existing = fs.existsSync(file) ? await promises.readFile(file, "utf8") : "";
955
957
  const lines = existing.split("\n").map((l) => l.trim());
956
958
  const hasStale = lines.some((l) => STALE_ENTRIES.has(l));
@@ -1046,8 +1048,8 @@ async function prepareRegionReads(opts) {
1046
1048
  const name = `read-${i}.${suffix}.png`;
1047
1049
  await sharp__default.default(src).extract(extract).resize(extract.width * scale, extract.height * scale, {
1048
1050
  kernel: "lanczos3"
1049
- }).png().toFile(path27__default.default.join(opts.outputDir, name));
1050
- return path27__default.default.join(opts.outputDir, name);
1051
+ }).png().toFile(path26__default.default.join(opts.outputDir, name));
1052
+ return path26__default.default.join(opts.outputDir, name);
1051
1053
  };
1052
1054
  const [beforePath, afterPath] = await Promise.all([
1053
1055
  render(opts.baselinePath, "before"),
@@ -1115,7 +1117,7 @@ async function prepareTiles(opts) {
1115
1117
  channels: 3,
1116
1118
  background: BG_WHITE
1117
1119
  }
1118
- }).composite(composites).png().toFile(path27__default.default.join(opts.outputDir, tilesName));
1120
+ }).composite(composites).png().toFile(path26__default.default.join(opts.outputDir, tilesName));
1119
1121
  }
1120
1122
  let locatorName;
1121
1123
  if (opts.diffPath) {
@@ -1131,7 +1133,7 @@ async function prepareTiles(opts) {
1131
1133
  }).join("");
1132
1134
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${locW}" height="${locH}">${rects}</svg>`;
1133
1135
  locatorName = "locator.png";
1134
- await sharp__default.default(opts.diffPath).resize(locW, locH, { fit: "fill" }).composite([{ input: Buffer.from(svg), left: 0, top: 0 }]).png().toFile(path27__default.default.join(opts.outputDir, locatorName));
1136
+ await sharp__default.default(opts.diffPath).resize(locW, locH, { fit: "fill" }).composite([{ input: Buffer.from(svg), left: 0, top: 0 }]).png().toFile(path26__default.default.join(opts.outputDir, locatorName));
1135
1137
  }
1136
1138
  return {
1137
1139
  locatorPath: locatorName,
@@ -1169,7 +1171,7 @@ var codingAgentHostJudge = {
1169
1171
  async judge(input, cwd) {
1170
1172
  input.onJudgingStart?.();
1171
1173
  const p = paths(cwd);
1172
- const entryDir = path27__default.default.join(p.judgments, input.entry.id);
1174
+ const entryDir = path26__default.default.join(p.judgments, input.entry.id);
1173
1175
  await promises.mkdir(entryDir, { recursive: true });
1174
1176
  await tryPrepareTiles(input, entryDir);
1175
1177
  return { kind: "deferred", requestPath: entryDir };
@@ -1192,7 +1194,7 @@ function statusGlyph(status) {
1192
1194
  }
1193
1195
  function relPath(p, cwd = process.cwd()) {
1194
1196
  if (!p) return p;
1195
- const rel = path27__default.default.relative(cwd, p);
1197
+ const rel = path26__default.default.relative(cwd, p);
1196
1198
  return rel && !rel.startsWith("..") ? rel : p;
1197
1199
  }
1198
1200
 
@@ -1719,7 +1721,7 @@ function createLocalJudge(deps = {}) {
1719
1721
  await Promise.all([vision.get(), classifier.get()]);
1720
1722
  },
1721
1723
  async judge(input, cwd) {
1722
- const entryDir = path27__default.default.join(paths(cwd).judgments, input.entry.id);
1724
+ const entryDir = path26__default.default.join(paths(cwd).judgments, input.entry.id);
1723
1725
  await promises.mkdir(entryDir, { recursive: true });
1724
1726
  try {
1725
1727
  const description = await visionSemaphore.run(async () => {
@@ -1794,7 +1796,7 @@ async function readJsonOrNull(file) {
1794
1796
  // src/report/json.ts
1795
1797
  async function writeReport(report, cwd = process.cwd()) {
1796
1798
  const file = paths(cwd).report;
1797
- await promises.mkdir(path27__default.default.dirname(file), { recursive: true });
1799
+ await promises.mkdir(path26__default.default.dirname(file), { recursive: true });
1798
1800
  await promises.writeFile(file, `${JSON.stringify(report, null, 2)}
1799
1801
  `, "utf8");
1800
1802
  return file;
@@ -1848,7 +1850,7 @@ async function readJudgmentDirs(root) {
1848
1850
  }
1849
1851
  const out = [];
1850
1852
  for (const name of names) {
1851
- const dir = path27__default.default.join(root, name);
1853
+ const dir = path26__default.default.join(root, name);
1852
1854
  let isDir = false;
1853
1855
  try {
1854
1856
  isDir = (await promises.stat(dir)).isDirectory();
@@ -1857,9 +1859,9 @@ async function readJudgmentDirs(root) {
1857
1859
  }
1858
1860
  if (!isDir) continue;
1859
1861
  const request = await readJsonOrNull(
1860
- path27__default.default.join(dir, "request.json")
1862
+ path26__default.default.join(dir, "request.json")
1861
1863
  );
1862
- const verdictFile = path27__default.default.join(dir, "verdict.json");
1864
+ const verdictFile = path26__default.default.join(dir, "verdict.json");
1863
1865
  let verdict = null;
1864
1866
  let verdictInvalid = false;
1865
1867
  if (await fileExists(verdictFile)) {
@@ -1873,7 +1875,7 @@ async function readJudgmentDirs(root) {
1873
1875
  }
1874
1876
  function toAbs(cwd, rel) {
1875
1877
  if (!rel) return void 0;
1876
- return path27__default.default.isAbsolute(rel) ? rel : path27__default.default.join(cwd, rel);
1878
+ return path26__default.default.isAbsolute(rel) ? rel : path26__default.default.join(cwd, rel);
1877
1879
  }
1878
1880
  function fromDiskResult(cwd, dir, entry) {
1879
1881
  const req = dir.request;
@@ -1895,8 +1897,8 @@ function fromDiskResult(cwd, dir, entry) {
1895
1897
  };
1896
1898
  }
1897
1899
  async function passResultFromDisk(entry, cwd) {
1898
- const baselineAbs = path27__default.default.join(paths(cwd).baselines, `${entry.id}.png`);
1899
- const actualAbs = path27__default.default.join(paths(cwd).actual, `${entry.id}.png`);
1900
+ const baselineAbs = path26__default.default.join(paths(cwd).baselines, `${entry.id}.png`);
1901
+ const actualAbs = path26__default.default.join(paths(cwd).actual, `${entry.id}.png`);
1900
1902
  return {
1901
1903
  id: entry.id,
1902
1904
  url: entry.url,
@@ -1909,7 +1911,7 @@ async function reconstructFromDisk(cwd, dirs) {
1909
1911
  const manifest = await loadManifest(cwd);
1910
1912
  if (!manifest) {
1911
1913
  throw new Error(
1912
- `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent init\` first.`
1914
+ `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent onboard\` first.`
1913
1915
  );
1914
1916
  }
1915
1917
  const dirById = new Map(dirs.map((d) => [d.id, d]));
@@ -1940,7 +1942,7 @@ async function reconstructFromDisk(cwd, dirs) {
1940
1942
  return report;
1941
1943
  }
1942
1944
  async function hasCheckpoint(cwd, threadId) {
1943
- const dir = path27__default.default.join(paths(cwd).checkpoints, threadId);
1945
+ const dir = path26__default.default.join(paths(cwd).checkpoints, threadId);
1944
1946
  try {
1945
1947
  const names = await promises.readdir(dir);
1946
1948
  return names.length > 0;
@@ -1953,7 +1955,7 @@ async function applyJudgments(opts = {}) {
1953
1955
  const manifest = await loadManifest(cwd);
1954
1956
  if (!manifest) {
1955
1957
  throw new Error(
1956
- `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent init\` first.`
1958
+ `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent onboard\` first.`
1957
1959
  );
1958
1960
  }
1959
1961
  const dirs = await readJudgmentDirs(paths(cwd).judgments);
@@ -1963,7 +1965,7 @@ async function applyJudgments(opts = {}) {
1963
1965
  const verdicts = {};
1964
1966
  for (const d of dirs) {
1965
1967
  if (d.verdictInvalid) {
1966
- invalid.push(path27__default.default.join(paths(cwd).judgments, d.id));
1968
+ invalid.push(path26__default.default.join(paths(cwd).judgments, d.id));
1967
1969
  continue;
1968
1970
  }
1969
1971
  if (d.verdict) {
@@ -1999,7 +2001,7 @@ var HOST_INSTRUCTIONS = [
1999
2001
  ].join("\n");
2000
2002
  function relTo(cwd, abs) {
2001
2003
  if (!abs) return void 0;
2002
- return path27__default.default.relative(cwd, abs).split(path27__default.default.sep).join("/");
2004
+ return path26__default.default.relative(cwd, abs).split(path26__default.default.sep).join("/");
2003
2005
  }
2004
2006
  function signatureOf(r) {
2005
2007
  const pct = typeof r.diffPercentage === "number" ? r.diffPercentage.toFixed(4) : "?";
@@ -2052,8 +2054,8 @@ function autoVerdict(result) {
2052
2054
  };
2053
2055
  }
2054
2056
  async function discoverTiles(dir) {
2055
- const locatorAbs = path27__default.default.join(dir, "locator.png");
2056
- const tilesAbs = path27__default.default.join(dir, "regions.png");
2057
+ const locatorAbs = path26__default.default.join(dir, "locator.png");
2058
+ const tilesAbs = path26__default.default.join(dir, "regions.png");
2057
2059
  const [locator, tiles] = await Promise.all([
2058
2060
  fileExists(locatorAbs),
2059
2061
  fileExists(tilesAbs)
@@ -2071,7 +2073,7 @@ async function writeJudgments(opts) {
2071
2073
  for (const r of opts.report.results) knownIds.add(r.id);
2072
2074
  await Promise.all(
2073
2075
  opts.report.results.map(async (result) => {
2074
- const dir = path27__default.default.join(root, result.id);
2076
+ const dir = path26__default.default.join(root, result.id);
2075
2077
  if (result.status === "pass") {
2076
2078
  if (await fileExists(dir))
2077
2079
  await promises.rm(dir, { recursive: true, force: true });
@@ -2082,8 +2084,8 @@ async function writeJudgments(opts) {
2082
2084
  await promises.mkdir(dir, { recursive: true });
2083
2085
  const tiles = await discoverTiles(dir);
2084
2086
  const request = buildRequest(result, entry, cwd, tiles);
2085
- const requestFile = path27__default.default.join(dir, "request.json");
2086
- const verdictFile = path27__default.default.join(dir, "verdict.json");
2087
+ const requestFile = path26__default.default.join(dir, "request.json");
2088
+ const verdictFile = path26__default.default.join(dir, "verdict.json");
2087
2089
  const [prior, priorVerdict] = await Promise.all([
2088
2090
  readJsonOrNull(requestFile),
2089
2091
  fileExists(verdictFile).then(
@@ -2121,7 +2123,7 @@ async function writeJudgments(opts) {
2121
2123
  }
2122
2124
  await Promise.all(
2123
2125
  entries.filter((name) => !knownIds.has(name)).map(
2124
- (name) => promises.rm(path27__default.default.join(root, name), { recursive: true, force: true })
2126
+ (name) => promises.rm(path26__default.default.join(root, name), { recursive: true, force: true })
2125
2127
  )
2126
2128
  );
2127
2129
  }
@@ -2141,7 +2143,7 @@ function escapeXml(value) {
2141
2143
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
2142
2144
  }
2143
2145
  async function writeJunit(report, destPath) {
2144
- await promises.mkdir(path27__default.default.dirname(destPath), { recursive: true });
2146
+ await promises.mkdir(path26__default.default.dirname(destPath), { recursive: true });
2145
2147
  const cases = report.results.map((r) => {
2146
2148
  if (r.status === "pass") {
2147
2149
  return ` <testcase classname="blazediff" name="${escapeXml(r.id)}"/>`;
@@ -2193,16 +2195,16 @@ var FsCheckpointSaver = class extends langgraphCheckpoint.BaseCheckpointSaver {
2193
2195
  this.root = root;
2194
2196
  }
2195
2197
  threadDir(thread) {
2196
- return path27__default.default.join(this.root, thread);
2198
+ return path26__default.default.join(this.root, thread);
2197
2199
  }
2198
2200
  nsPath(thread, ns) {
2199
- return path27__default.default.join(this.threadDir(thread), nsDir(ns));
2201
+ return path26__default.default.join(this.threadDir(thread), nsDir(ns));
2200
2202
  }
2201
2203
  ckptFile(thread, ns, id) {
2202
- return path27__default.default.join(this.nsPath(thread, ns), `${id}.ckpt.json`);
2204
+ return path26__default.default.join(this.nsPath(thread, ns), `${id}.ckpt.json`);
2203
2205
  }
2204
2206
  writesFile(thread, ns, id) {
2205
- return path27__default.default.join(this.nsPath(thread, ns), `${id}.writes.json`);
2207
+ return path26__default.default.join(this.nsPath(thread, ns), `${id}.writes.json`);
2206
2208
  }
2207
2209
  async withLock(key, fn) {
2208
2210
  const prev = this.locks.get(key) ?? Promise.resolve();
@@ -2556,7 +2558,7 @@ function makeCaptureNode(semaphore) {
2556
2558
  } catch (err) {
2557
2559
  return failAll(`harness: ${err.message}`);
2558
2560
  }
2559
- const baselinePath = path27__default.default.join(options.baselinesDir, `${entry.id}.png`);
2561
+ const baselinePath = path26__default.default.join(options.baselinesDir, `${entry.id}.png`);
2560
2562
  try {
2561
2563
  const capture = await semaphore.run(
2562
2564
  () => captureScreenshot(
@@ -2587,7 +2589,7 @@ function makeCaptureNode(semaphore) {
2587
2589
  for (const child of children) {
2588
2590
  const name = subNameOf(child);
2589
2591
  const sub = name ? subByName.get(name) : void 0;
2590
- const childBaseline = path27__default.default.join(
2592
+ const childBaseline = path26__default.default.join(
2591
2593
  options.baselinesDir,
2592
2594
  `${child.id}.png`
2593
2595
  );
@@ -2650,7 +2652,7 @@ async function diffEntry(id, baselinePath, actualPath, opts = {}, cwd = process.
2650
2652
  if (opts.emitDiffPng) {
2651
2653
  const actualDir = paths(cwd).actual;
2652
2654
  await promises.mkdir(actualDir, { recursive: true });
2653
- diffPath = path27__default.default.join(actualDir, `${id}.diff.png`);
2655
+ diffPath = path26__default.default.join(actualDir, `${id}.diff.png`);
2654
2656
  }
2655
2657
  const threshold = opts.threshold ?? DEFAULT_THRESHOLD;
2656
2658
  const antialiasing = opts.antialiasing ?? true;
@@ -3003,7 +3005,7 @@ async function loadNode(state) {
3003
3005
  const manifest = await loadManifest(state.options.cwd);
3004
3006
  if (!manifest) {
3005
3007
  throw new Error(
3006
- `no manifest found at ${paths(state.options.cwd).manifest}. Run \`blazediff init\` then \`/blazediff\` (or capture manually) first.`
3008
+ `no manifest found at ${paths(state.options.cwd).manifest}. Run \`blazediff-agent onboard\` then \`/blazediff\` (or capture manually) first.`
3007
3009
  );
3008
3010
  }
3009
3011
  return { entries: manifest.entries, manifest };
@@ -3182,7 +3184,7 @@ async function runGraph(opts) {
3182
3184
  }
3183
3185
  const report = collect.report ?? await buildPartialReport(collect, cwd);
3184
3186
  if (opts.junitPath) {
3185
- const target = path27__default.default.isAbsolute(opts.junitPath) ? opts.junitPath : path27__default.default.join(cwd, opts.junitPath);
3187
+ const target = path26__default.default.isAbsolute(opts.junitPath) ? opts.junitPath : path26__default.default.join(cwd, opts.junitPath);
3186
3188
  await writeJunit(report, target);
3187
3189
  }
3188
3190
  if (collect.interrupts.length === 0) {
@@ -3487,9 +3489,9 @@ function extractInternalLinks(base, target, hrefs) {
3487
3489
  try {
3488
3490
  const u = new URL(href, target);
3489
3491
  if (u.origin !== base.origin) continue;
3490
- const path31 = u.pathname + u.search;
3491
- if (path31.startsWith("/api/")) continue;
3492
- out.push(path31);
3492
+ const path30 = u.pathname + u.search;
3493
+ if (path30.startsWith("/api/")) continue;
3494
+ out.push(path30);
3493
3495
  } catch {
3494
3496
  }
3495
3497
  }
@@ -3519,6 +3521,8 @@ async function crawlRoutes(opts) {
3519
3521
  waitUntil: "domcontentloaded",
3520
3522
  timeout: 15e3
3521
3523
  });
3524
+ await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
3525
+ });
3522
3526
  const hrefs = await page.evaluate(
3523
3527
  () => Array.from(
3524
3528
  document.querySelectorAll("a[href]")
@@ -3543,57 +3547,38 @@ async function crawlRoutes(opts) {
3543
3547
  }
3544
3548
  return discovered.slice(0, maxRoutes);
3545
3549
  }
3546
- var DYNAMIC_SEGMENT = /\[[^\]]+\]/;
3547
- function isPublicRoute(route) {
3548
- if (DYNAMIC_SEGMENT.test(route)) return false;
3549
- if (route === "/api" || route.startsWith("/api/")) return false;
3550
- return true;
3551
- }
3552
- async function discoverFromNextManifest(cwd = process.cwd()) {
3553
- const nextDir = path27__default.default.join(cwd, ".next");
3554
- if (!fs.existsSync(nextDir)) return [];
3555
- const seen = /* @__PURE__ */ new Set();
3556
- const out = [];
3557
- const add = (url) => {
3558
- if (seen.has(url)) return;
3559
- seen.add(url);
3560
- out.push({ url, source: "next-manifest" });
3561
- };
3562
- const routes = await readJsonOrNull(
3563
- path27__default.default.join(nextDir, "routes-manifest.json")
3564
- );
3565
- for (const r of routes?.staticRoutes ?? []) {
3566
- if (isPublicRoute(r.page)) add(r.page);
3567
- }
3568
- const appPaths = await readJsonOrNull(
3569
- path27__default.default.join(nextDir, "server", "app-paths-manifest.json")
3570
- );
3571
- for (const route of Object.keys(appPaths ?? {})) {
3572
- const normalized = route.replace(/\/page$/, "") || "/";
3573
- if (isPublicRoute(normalized)) add(normalized);
3574
- }
3575
- return out;
3576
- }
3577
3550
 
3578
- // src/discover/sitemap.ts
3579
- var CANDIDATES = ["/sitemap.xml", "/sitemap_index.xml"];
3580
- var LOC_RE = /<loc>([^<]+)<\/loc>/g;
3581
- async function discoverFromSitemap(baseUrl) {
3582
- for (const candidate of CANDIDATES) {
3583
- try {
3584
- const res = await fetch(new URL(candidate, baseUrl));
3585
- if (!res.ok) continue;
3586
- const text = await res.text();
3587
- const urls = Array.from(text.matchAll(LOC_RE)).map((m) => m[1]);
3588
- if (!urls.length) continue;
3589
- return urls.map((u) => {
3590
- const url = new URL(u);
3591
- return { url: url.pathname + url.search, source: "sitemap" };
3592
- });
3593
- } catch {
3594
- }
3551
+ // src/discover/templates.ts
3552
+ var DEFAULT_SAMPLE_THRESHOLD = 5;
3553
+ var DEFAULT_SAMPLES_PER_TEMPLATE = 2;
3554
+ var DEFAULT_SAMPLING = {
3555
+ threshold: DEFAULT_SAMPLE_THRESHOLD,
3556
+ samples: DEFAULT_SAMPLES_PER_TEMPLATE
3557
+ };
3558
+ function parentPath(path30) {
3559
+ const [pathPart] = path30.split("?", 2);
3560
+ const idx = pathPart.lastIndexOf("/");
3561
+ return idx <= 0 ? "/" : pathPart.slice(0, idx);
3562
+ }
3563
+ function collapseTemplates(routes, { threshold, samples } = DEFAULT_SAMPLING) {
3564
+ const groups = /* @__PURE__ */ new Map();
3565
+ for (const route of routes) {
3566
+ const parent = parentPath(route.url);
3567
+ const group = groups.get(parent);
3568
+ if (group) group.push(route);
3569
+ else groups.set(parent, [route]);
3570
+ }
3571
+ const drop = /* @__PURE__ */ new Set();
3572
+ const collapsed = [];
3573
+ for (const [parent, group] of groups) {
3574
+ if (parent === "/" || group.length < threshold) continue;
3575
+ for (const route of group.slice(samples)) drop.add(route.url);
3576
+ collapsed.push(`${parent}/* (${group.length} \u2192 ${samples})`);
3595
3577
  }
3596
- return [];
3578
+ return {
3579
+ routes: drop.size ? routes.filter((r) => !drop.has(r.url)) : routes,
3580
+ collapsed
3581
+ };
3597
3582
  }
3598
3583
 
3599
3584
  // src/discover/index.ts
@@ -3603,44 +3588,61 @@ function normalizePath(url) {
3603
3588
  const normalizedPath = trimmed === "" ? "/" : trimmed;
3604
3589
  return query ? `${normalizedPath}?${query}` : normalizedPath;
3605
3590
  }
3606
- function mergeBy(routes, into) {
3591
+ function dedupe(routes) {
3592
+ const merged = /* @__PURE__ */ new Map();
3607
3593
  for (const r of routes) {
3608
3594
  const key = normalizePath(r.url);
3609
- if (!into.has(key)) into.set(key, { ...r, url: key });
3595
+ if (!merged.has(key)) merged.set(key, { ...r, url: key });
3610
3596
  }
3597
+ return Array.from(merged.values());
3611
3598
  }
3612
3599
  async function discover(opts) {
3613
- const cwd = opts.cwd ?? process.cwd();
3614
- const merged = /* @__PURE__ */ new Map();
3615
- mergeBy(await discoverFromNextManifest(cwd), merged);
3616
- mergeBy(await discoverFromSitemap(opts.baseUrl), merged);
3617
- if (!opts.skipCrawl) {
3618
- const crawlMax = Math.max(0, (opts.maxRoutes ?? 50) - merged.size);
3619
- if (crawlMax > 0) {
3620
- mergeBy(
3621
- await crawlRoutes({ baseUrl: opts.baseUrl, maxRoutes: crawlMax }),
3622
- merged
3623
- );
3624
- }
3625
- }
3626
- return Array.from(merged.values()).sort((a, b) => a.url.localeCompare(b.url));
3600
+ const crawled = await crawlRoutes({
3601
+ baseUrl: opts.baseUrl,
3602
+ maxRoutes: opts.maxRoutes ?? 50
3603
+ });
3604
+ const deduped = dedupe(crawled);
3605
+ const sampling = opts.sampleTemplates ?? true;
3606
+ const routes = sampling === false ? deduped : collapseTemplates(deduped, sampling === true ? void 0 : sampling).routes;
3607
+ return routes.sort((a, b) => a.url.localeCompare(b.url));
3627
3608
  }
3628
3609
 
3629
3610
  // src/cli/commands/discover.ts
3611
+ function posInt(value, fallback) {
3612
+ const n = Number(value);
3613
+ return Number.isInteger(n) && n > 0 ? n : fallback;
3614
+ }
3630
3615
  function registerDiscover(program, out) {
3631
3616
  program.command("discover").description(
3632
- "enumerate candidate routes via BFS crawl + Next manifest + sitemap"
3633
- ).option("--base-url <url>", "override base URL").option("--max-routes <n>", "cap on routes returned", "50").option("--no-crawl", "skip BFS crawl fallback").action(async (opts) => {
3617
+ "enumerate reachable routes by crawling links from the landing page"
3618
+ ).option("--base-url <url>", "override base URL").option("--max-routes <n>", "cap on routes returned", "50").option(
3619
+ "--no-sample-templates",
3620
+ "keep every reachable route, even large list/detail groups"
3621
+ ).option(
3622
+ "--samples-per-template <n>",
3623
+ "representatives to keep per templated group",
3624
+ String(DEFAULT_SAMPLES_PER_TEMPLATE)
3625
+ ).option(
3626
+ "--sample-threshold <n>",
3627
+ "group size at which template sampling kicks in",
3628
+ String(DEFAULT_SAMPLE_THRESHOLD)
3629
+ ).action(async (opts) => {
3634
3630
  const baseUrl = resolveBaseUrl(await loadConfig(), opts.baseUrl);
3635
3631
  const routes = await discover({
3636
3632
  baseUrl,
3637
3633
  maxRoutes: Number(opts.maxRoutes),
3638
- skipCrawl: !opts.crawl
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
+ }
3639
3641
  });
3640
3642
  await closeBrowser();
3641
3643
  out.emit(
3642
3644
  { ok: true, baseUrl, routes },
3643
- routes.length ? routes.map((r) => `${r.source.padEnd(14)} ${r.url}`).join("\n") : "no routes discovered"
3645
+ routes.length ? routes.map((r) => r.url).join("\n") : "no routes discovered"
3644
3646
  );
3645
3647
  });
3646
3648
  }
@@ -3651,8 +3653,8 @@ var CodegenError = class extends Error {
3651
3653
  }
3652
3654
  };
3653
3655
  async function runCodegen(opts) {
3654
- const tmp = await promises.mkdtemp(path27__default.default.join(os.tmpdir(), "blazediff-codegen-"));
3655
- const scriptPath = path27__default.default.join(tmp, "recording.js");
3656
+ const tmp = await promises.mkdtemp(path26__default.default.join(os.tmpdir(), "blazediff-codegen-"));
3657
+ const scriptPath = path26__default.default.join(tmp, "recording.js");
3656
3658
  const command = opts.command ?? process.execPath;
3657
3659
  const args = opts.args ?? [
3658
3660
  resolvePlaywrightCli(),
@@ -3900,7 +3902,7 @@ function resolveUrl(opts, config) {
3900
3902
  const baseUrl = config?.baseUrl;
3901
3903
  if (!baseUrl) {
3902
3904
  throw new Error(
3903
- "no recording URL: pass --url <url> or run `blazediff-agent init` first."
3905
+ "no recording URL: pass --url <url> or run `blazediff-agent onboard` first."
3904
3906
  );
3905
3907
  }
3906
3908
  return opts.login ? new URL("/login", baseUrl).toString() : baseUrl;
@@ -3932,7 +3934,7 @@ function registerHarness(program, out) {
3932
3934
  `refusing to record against what looks like a production URL: ${url}. Pass --allow-production to override.`
3933
3935
  );
3934
3936
  }
3935
- const harnessPath = opts.output ? path27__default.default.isAbsolute(opts.output) ? opts.output : path27__default.default.join(process.cwd(), opts.output) : path27__default.default.join(paths().harnesses, `${name}.js`);
3937
+ const harnessPath = opts.output ? path26__default.default.isAbsolute(opts.output) ? opts.output : path26__default.default.join(process.cwd(), opts.output) : path26__default.default.join(paths().harnesses, `${name}.js`);
3936
3938
  if (fs.existsSync(harnessPath) && !opts.force) {
3937
3939
  throw new Error(`refusing to overwrite ${harnessPath} (use --force).`);
3938
3940
  }
@@ -3955,9 +3957,9 @@ function registerHarness(program, out) {
3955
3957
  loginUrl: url,
3956
3958
  persona: opts.persona
3957
3959
  }) : buildHarness(rawSource, { name, url, phase });
3958
- await promises.mkdir(path27__default.default.dirname(harnessPath), { recursive: true });
3960
+ await promises.mkdir(path26__default.default.dirname(harnessPath), { recursive: true });
3959
3961
  await promises.writeFile(harnessPath, built.source, "utf8");
3960
- await promises.rm(path27__default.default.dirname(scriptPath), {
3962
+ await promises.rm(path26__default.default.dirname(scriptPath), {
3961
3963
  recursive: true,
3962
3964
  force: true
3963
3965
  }).catch(() => {
@@ -3996,6 +3998,85 @@ function registerHarness(program, out) {
3996
3998
  });
3997
3999
  }
3998
4000
 
4001
+ // src/cli/commands/manifest.ts
4002
+ function registerManifest(program, out) {
4003
+ const cmd = program.command("manifest").description("manage .blazediff/manifest.json");
4004
+ cmd.command("add <id>").requiredOption("--url <url>").option("--viewport <WxH>", "viewport", "1280x800").option("--mask <selectors>", "selectors", "").option("--wait-for <list>", "wait list", "networkidle,fonts").option("--no-full-page", "viewport-only (default: full page)").option(
4005
+ "--harness <name>",
4006
+ "harness to attach (repeatable; resolves to .blazediff/harnesses/<name>.js). Use the capture JSON to pass params.",
4007
+ (value, prev = []) => [...prev, value]
4008
+ ).option("--created-by <agent|human>", "provenance", "agent").action(async (id, opts) => {
4009
+ const config = await loadConfig();
4010
+ if (!config)
4011
+ throw new Error("no config. Run `blazediff-agent onboard` first.");
4012
+ const manifest = await loadManifest() ?? emptyManifest(configHash(config));
4013
+ const entry = makeEntry({
4014
+ id,
4015
+ url: opts.url,
4016
+ viewport: parseViewport(opts.viewport),
4017
+ mask: parseMaskList(opts.mask),
4018
+ waitFor: parseWaitFor(opts.waitFor),
4019
+ fullPage: opts.fullPage,
4020
+ harnesses: opts.harness?.map((name) => ({ name })),
4021
+ createdBy: opts.createdBy
4022
+ });
4023
+ await saveManifest(addOrReplaceEntry(manifest, entry));
4024
+ out.emit(
4025
+ { ok: true, entry },
4026
+ out.isTTY() ? `manifest: added ${id} (${entry.url})` : "."
4027
+ );
4028
+ });
4029
+ cmd.command("remove <id>").action(async (id) => {
4030
+ const manifest = await loadManifest();
4031
+ if (!manifest) throw new Error("no manifest");
4032
+ await saveManifest(removeEntry(manifest, id));
4033
+ out.emit({ ok: true, removed: id }, `manifest: removed ${id}`);
4034
+ });
4035
+ cmd.command("list").action(async () => {
4036
+ const manifest = await loadManifest();
4037
+ if (!manifest) {
4038
+ out.emit({ entries: [] }, "no manifest");
4039
+ return;
4040
+ }
4041
+ out.emit(
4042
+ { entries: manifest.entries },
4043
+ manifest.entries.map((e) => `${e.id.padEnd(30)} ${e.url}`).join("\n") || "no entries"
4044
+ );
4045
+ });
4046
+ }
4047
+ async function ask(question) {
4048
+ const rl = promises$1.createInterface({ input: process.stdin, output: process.stderr });
4049
+ try {
4050
+ return (await rl.question(question)).trim();
4051
+ } finally {
4052
+ rl.close();
4053
+ }
4054
+ }
4055
+ async function promptChoice(question, choices, defaultIndex = 0) {
4056
+ if (choices.length === 0) throw new Error("promptChoice: no choices");
4057
+ const lines = [
4058
+ question,
4059
+ ...choices.map(
4060
+ (c, i) => ` [${i + 1}] ${c.label}${c.hint ? ` ${c.hint}` : ""}`
4061
+ ),
4062
+ ""
4063
+ ];
4064
+ process.stderr.write(`${lines.join("\n")}`);
4065
+ const answer = await ask(`Choice (default ${defaultIndex + 1}): `);
4066
+ if (!answer) return choices[defaultIndex].value;
4067
+ const idx = Number(answer);
4068
+ if (!Number.isInteger(idx) || idx < 1 || idx > choices.length) {
4069
+ throw new Error(`invalid choice "${answer}"; expected 1-${choices.length}`);
4070
+ }
4071
+ return choices[idx - 1].value;
4072
+ }
4073
+ async function promptYesNo(question, defaultYes = true) {
4074
+ const suffix = defaultYes ? "(Y/n)" : "(y/N)";
4075
+ const answer = (await ask(`${question} ${suffix} `)).toLowerCase();
4076
+ if (!answer) return defaultYes;
4077
+ return answer === "y" || answer === "yes";
4078
+ }
4079
+
3999
4080
  // src/introspect/framework.ts
4000
4081
  var SIGNALS = [
4001
4082
  ["next", ["next"]],
@@ -4014,21 +4095,21 @@ function detectFramework(pkg) {
4014
4095
  return "unknown";
4015
4096
  }
4016
4097
  async function readPackageJson(cwd = process.cwd()) {
4017
- const file = path27__default.default.join(cwd, "package.json");
4098
+ const file = path26__default.default.join(cwd, "package.json");
4018
4099
  if (!fs.existsSync(file)) return null;
4019
4100
  return JSON.parse(await promises.readFile(file, "utf8"));
4020
4101
  }
4021
4102
  function detectPackageManager(cwd = process.cwd()) {
4022
4103
  let dir = cwd;
4023
- const { root } = path27__default.default.parse(dir);
4104
+ const { root } = path26__default.default.parse(dir);
4024
4105
  while (true) {
4025
- if (fs.existsSync(path27__default.default.join(dir, "pnpm-lock.yaml"))) return "pnpm";
4026
- if (fs.existsSync(path27__default.default.join(dir, "bun.lockb")) || fs.existsSync(path27__default.default.join(dir, "bun.lock")))
4106
+ if (fs.existsSync(path26__default.default.join(dir, "pnpm-lock.yaml"))) return "pnpm";
4107
+ if (fs.existsSync(path26__default.default.join(dir, "bun.lockb")) || fs.existsSync(path26__default.default.join(dir, "bun.lock")))
4027
4108
  return "bun";
4028
- if (fs.existsSync(path27__default.default.join(dir, "yarn.lock"))) return "yarn";
4029
- if (fs.existsSync(path27__default.default.join(dir, "package-lock.json"))) return "npm";
4109
+ if (fs.existsSync(path26__default.default.join(dir, "yarn.lock"))) return "yarn";
4110
+ if (fs.existsSync(path26__default.default.join(dir, "package-lock.json"))) return "npm";
4030
4111
  if (dir === root) return "npm";
4031
- dir = path27__default.default.dirname(dir);
4112
+ dir = path26__default.default.dirname(dir);
4032
4113
  }
4033
4114
  }
4034
4115
  var DEFAULT_PORTS = {
@@ -4103,8 +4184,38 @@ async function introspectPackage(cwd = process.cwd()) {
4103
4184
  };
4104
4185
  }
4105
4186
 
4106
- // src/cli/commands/init.ts
4107
- async function buildConfig(opts) {
4187
+ // src/onboard/config.ts
4188
+ var NO_DEV_SCRIPT_ERROR = "no package.json with a dev/start script in cwd. Pass --url <baseUrl> or --dev-command <cmd>.";
4189
+ async function chooseDevScript(candidates, opts, interactive) {
4190
+ if (candidates.length === 1) return candidates[0];
4191
+ if (opts.devScript) {
4192
+ const match = candidates.find((c) => c.name === opts.devScript);
4193
+ if (!match) {
4194
+ const names = candidates.map((c) => c.name).join(", ");
4195
+ throw new Error(
4196
+ `--dev-script "${opts.devScript}" not found among candidates: ${names}`
4197
+ );
4198
+ }
4199
+ return match;
4200
+ }
4201
+ if (interactive) {
4202
+ return promptChoice(
4203
+ "Multiple dev scripts found. Which one starts your app?",
4204
+ candidates.map((c) => ({
4205
+ label: c.name,
4206
+ value: c,
4207
+ hint: `(${c.command})`
4208
+ }))
4209
+ );
4210
+ }
4211
+ const chosen = candidates[0];
4212
+ process.stderr.write(
4213
+ `picked dev script "${chosen.name}" (${chosen.command}); override with --dev-script <name>
4214
+ `
4215
+ );
4216
+ return chosen;
4217
+ }
4218
+ async function buildConfig(opts, { interactive }) {
4108
4219
  if (opts.url) {
4109
4220
  if (opts.devCommand || opts.port || opts.devScript) {
4110
4221
  throw new Error(
@@ -4127,27 +4238,9 @@ async function buildConfig(opts) {
4127
4238
  }
4128
4239
  const pkg = await introspectPackage();
4129
4240
  if (!pkg) {
4130
- throw new Error(
4131
- "no package.json with a dev/start script in cwd. Pass --url <baseUrl> or --dev-command <cmd>."
4132
- );
4133
- }
4134
- let chosen = pkg.candidates[0];
4135
- if (pkg.candidates.length > 1) {
4136
- if (!opts.devScript) {
4137
- const names = pkg.candidates.map((c) => `${c.name} (${c.command})`).join(", ");
4138
- throw new Error(
4139
- `multiple dev-script candidates: ${names}. Pass --dev-script <name> or --dev-command <cmd>.`
4140
- );
4141
- }
4142
- const match = pkg.candidates.find((c) => c.name === opts.devScript);
4143
- if (!match) {
4144
- const names = pkg.candidates.map((c) => c.name).join(", ");
4145
- throw new Error(
4146
- `--dev-script "${opts.devScript}" not found among candidates: ${names}`
4147
- );
4148
- }
4149
- chosen = match;
4241
+ throw new Error(NO_DEV_SCRIPT_ERROR);
4150
4242
  }
4243
+ const chosen = await chooseDevScript(pkg.candidates, opts, interactive);
4151
4244
  const port = opts.port ? parsePort(opts.port) : chosen.port;
4152
4245
  return {
4153
4246
  devServer: {
@@ -4160,107 +4253,40 @@ async function buildConfig(opts) {
4160
4253
  baseUrl: `http://127.0.0.1:${port}`
4161
4254
  };
4162
4255
  }
4163
- function registerInit(program, out) {
4164
- program.command("init").description("write .blazediff/config.json and .gitignore").option("--force", "overwrite existing config").option(
4165
- "--url <baseUrl>",
4166
- "point at an already-running server / external URL"
4167
- ).option("--dev-command <cmd>", "override detected dev-server command").option("--port <n>", "override detected port").option(
4168
- "--dev-script <name>",
4169
- "select a dev script by name when multiple candidates exist"
4170
- ).action(async (opts) => {
4171
- const existing = await loadConfig();
4172
- if (existing && !opts.force) {
4173
- await ensureGitignore(process.cwd());
4174
- out.emit(
4175
- {
4176
- ok: true,
4177
- created: false,
4178
- config: existing,
4179
- configHash: configHash(existing)
4180
- },
4181
- `config exists at ${paths().config} (use --force to overwrite)`
4182
- );
4183
- return;
4184
- }
4185
- const built = await buildConfig(opts);
4186
- const config = existing?.judge ? { ...built, judge: existing.judge } : built;
4187
- await saveConfig(config);
4256
+ async function ensureConfig(opts, out) {
4257
+ const existing = await loadConfig();
4258
+ if (existing && !opts.force) {
4188
4259
  await ensureGitignore(process.cwd());
4189
- const human = config.devServer ? `wrote ${paths().config}
4190
- baseUrl: ${config.baseUrl}
4191
- dev: ${config.devServer.command} (port ${config.devServer.port})` : `wrote ${paths().config}
4192
- baseUrl: ${config.baseUrl}
4193
- external server (no devServer managed)`;
4194
- out.emit(
4195
- { ok: true, created: true, config, configHash: configHash(config) },
4196
- human
4197
- );
4260
+ return { config: existing, created: false };
4261
+ }
4262
+ const built = await buildConfig(opts, {
4263
+ interactive: out.isTTY() && !out.isJson()
4198
4264
  });
4265
+ const config = existing?.judge ? { ...built, judge: existing.judge } : built;
4266
+ await saveConfig(config);
4267
+ await ensureGitignore(process.cwd());
4268
+ return { config, created: true };
4199
4269
  }
4200
-
4201
- // src/cli/commands/manifest.ts
4202
- function registerManifest(program, out) {
4203
- const cmd = program.command("manifest").description("manage .blazediff/manifest.json");
4204
- cmd.command("add <id>").requiredOption("--url <url>").option("--viewport <WxH>", "viewport", "1280x800").option("--mask <selectors>", "selectors", "").option("--wait-for <list>", "wait list", "networkidle,fonts").option("--no-full-page", "viewport-only (default: full page)").option(
4205
- "--harness <name>",
4206
- "harness to attach (repeatable; resolves to .blazediff/harnesses/<name>.js). Use the capture JSON to pass params.",
4207
- (value, prev = []) => [...prev, value]
4208
- ).option("--created-by <agent|human>", "provenance", "agent").action(async (id, opts) => {
4209
- const config = await loadConfig();
4210
- if (!config)
4211
- throw new Error("no config. Run `blazediff-agent init` first.");
4212
- const manifest = await loadManifest() ?? emptyManifest(configHash(config));
4213
- const entry = makeEntry({
4214
- id,
4215
- url: opts.url,
4216
- viewport: parseViewport(opts.viewport),
4217
- mask: parseMaskList(opts.mask),
4218
- waitFor: parseWaitFor(opts.waitFor),
4219
- fullPage: opts.fullPage,
4220
- harnesses: opts.harness?.map((name) => ({ name })),
4221
- createdBy: opts.createdBy
4222
- });
4223
- await saveManifest(addOrReplaceEntry(manifest, entry));
4224
- out.emit(
4225
- { ok: true, entry },
4226
- out.isTTY() ? `manifest: added ${id} (${entry.url})` : "."
4227
- );
4228
- });
4229
- cmd.command("remove <id>").action(async (id) => {
4230
- const manifest = await loadManifest();
4231
- if (!manifest) throw new Error("no manifest");
4232
- await saveManifest(removeEntry(manifest, id));
4233
- out.emit({ ok: true, removed: id }, `manifest: removed ${id}`);
4234
- });
4235
- cmd.command("list").action(async () => {
4236
- const manifest = await loadManifest();
4237
- if (!manifest) {
4238
- out.emit({ entries: [] }, "no manifest");
4239
- return;
4240
- }
4241
- out.emit(
4242
- { entries: manifest.entries },
4243
- manifest.entries.map((e) => `${e.id.padEnd(30)} ${e.url}`).join("\n") || "no entries"
4244
- );
4245
- });
4270
+ function configSummary(config) {
4271
+ return config.devServer ? `${paths().config} (baseUrl ${config.baseUrl}, dev: ${config.devServer.command} :${config.devServer.port})` : `${paths().config} (external baseUrl ${config.baseUrl})`;
4246
4272
  }
4247
4273
  var SKILL_FILES = ["SKILL.md", "JUDGING.md", "MASKING.md"];
4248
4274
  var cachedDir = null;
4249
4275
  var cachedFiles = null;
4250
4276
  function moduleDir() {
4251
- return path27.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.js', document.baseURI).href))));
4277
+ return path26.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.js', document.baseURI).href))));
4252
4278
  }
4253
4279
  function resolveSkillDir() {
4254
4280
  if (cachedDir !== null) return cachedDir;
4255
4281
  const here = moduleDir();
4256
4282
  const candidates = [
4257
- path27.join(here, ".."),
4258
- path27.join(here, "..", ".."),
4259
- path27.join(here, "..", "..", "..", "skill", "blazediff"),
4260
- path27.join(here, "..", "..", "..", "..", "skill", "blazediff")
4283
+ path26.join(here, ".."),
4284
+ path26.join(here, "..", ".."),
4285
+ path26.join(here, "..", "..", "..", "skill", "blazediff"),
4286
+ path26.join(here, "..", "..", "..", "..", "skill", "blazediff")
4261
4287
  ];
4262
4288
  for (const dir of candidates) {
4263
- if (fs.existsSync(path27.join(dir, "SKILL.md"))) {
4289
+ if (fs.existsSync(path26.join(dir, "SKILL.md"))) {
4264
4290
  cachedDir = dir;
4265
4291
  return cachedDir;
4266
4292
  }
@@ -4272,8 +4298,8 @@ function resolveSkillDir() {
4272
4298
  function loadSkillFiles() {
4273
4299
  if (cachedFiles !== null) return cachedFiles;
4274
4300
  const dir = resolveSkillDir();
4275
- cachedFiles = SKILL_FILES.filter((name) => fs.existsSync(path27.join(dir, name))).map(
4276
- (name) => ({ name, content: fs.readFileSync(path27.join(dir, name), "utf8") })
4301
+ cachedFiles = SKILL_FILES.filter((name) => fs.existsSync(path26.join(dir, name))).map(
4302
+ (name) => ({ name, content: fs.readFileSync(path26.join(dir, name), "utf8") })
4277
4303
  );
4278
4304
  return cachedFiles;
4279
4305
  }
@@ -4300,11 +4326,11 @@ var STACKS = {
4300
4326
  kind: "skill-install",
4301
4327
  judge: "host",
4302
4328
  detect: (cwd) => someExists([
4303
- path27.join(cwd, ".claude"),
4304
- path27.join(cwd, "CLAUDE.md"),
4305
- path27.join(cwd, "AGENTS.md")
4329
+ path26.join(cwd, ".claude"),
4330
+ path26.join(cwd, "CLAUDE.md"),
4331
+ path26.join(cwd, "AGENTS.md")
4306
4332
  ]),
4307
- target: (cwd) => path27.join(cwd, ".claude", "skills", "blazediff", "SKILL.md"),
4333
+ target: (cwd) => path26.join(cwd, ".claude", "skills", "blazediff", "SKILL.md"),
4308
4334
  format: "skill-file",
4309
4335
  scope: "project"
4310
4336
  },
@@ -4314,11 +4340,11 @@ var STACKS = {
4314
4340
  kind: "skill-install",
4315
4341
  judge: "host",
4316
4342
  detect: (cwd) => someExists([
4317
- path27.join(cwd, "AGENTS.md"),
4318
- path27.join(cwd, ".codex"),
4319
- path27.join(os.homedir(), ".codex")
4343
+ path26.join(cwd, "AGENTS.md"),
4344
+ path26.join(cwd, ".codex"),
4345
+ path26.join(os.homedir(), ".codex")
4320
4346
  ]),
4321
- target: () => path27.join(os.homedir(), ".codex", "skills", "blazediff", "SKILL.md"),
4347
+ target: () => path26.join(os.homedir(), ".codex", "skills", "blazediff", "SKILL.md"),
4322
4348
  format: "skill-file",
4323
4349
  scope: "user"
4324
4350
  },
@@ -4327,8 +4353,8 @@ var STACKS = {
4327
4353
  label: "Cursor",
4328
4354
  kind: "skill-install",
4329
4355
  judge: "host",
4330
- detect: (cwd) => someExists([path27.join(cwd, ".cursor"), path27.join(cwd, ".cursorrules")]),
4331
- target: (cwd) => path27.join(cwd, ".cursor", "rules", "blazediff.mdc"),
4356
+ detect: (cwd) => someExists([path26.join(cwd, ".cursor"), path26.join(cwd, ".cursorrules")]),
4357
+ target: (cwd) => path26.join(cwd, ".cursor", "rules", "blazediff.mdc"),
4332
4358
  format: "cursor-rule",
4333
4359
  scope: "project"
4334
4360
  },
@@ -4400,7 +4426,7 @@ async function writeIfChanged(target, content, force) {
4400
4426
  const exists = stat3 !== null;
4401
4427
  if (isSymlink) {
4402
4428
  await promises.unlink(target);
4403
- await promises.mkdir(path27.dirname(target), { recursive: true });
4429
+ await promises.mkdir(path26.dirname(target), { recursive: true });
4404
4430
  await promises.writeFile(target, content, "utf8");
4405
4431
  return "updated";
4406
4432
  }
@@ -4409,7 +4435,7 @@ async function writeIfChanged(target, content, force) {
4409
4435
  if (current === content) return "unchanged";
4410
4436
  if (!force) return "skipped-exists";
4411
4437
  }
4412
- await promises.mkdir(path27.dirname(target), { recursive: true });
4438
+ await promises.mkdir(path26.dirname(target), { recursive: true });
4413
4439
  await promises.writeFile(target, content, "utf8");
4414
4440
  return exists ? "updated" : "created";
4415
4441
  }
@@ -4431,10 +4457,10 @@ async function installStack(stack, cwd, opts = {}) {
4431
4457
  const status = await writeIfChanged(target, content, opts.force);
4432
4458
  return { stack, path: target, status };
4433
4459
  }
4434
- const targetDir = path27.dirname(target);
4460
+ const targetDir = path26.dirname(target);
4435
4461
  const statuses = [];
4436
4462
  for (const file of files) {
4437
- const filePath = path27.join(targetDir, file.name);
4463
+ const filePath = path26.join(targetDir, file.name);
4438
4464
  const status = await writeIfChanged(
4439
4465
  filePath,
4440
4466
  ensureTrailingNewline(file.content),
@@ -4444,109 +4470,6 @@ async function installStack(stack, cwd, opts = {}) {
4444
4470
  }
4445
4471
  return { stack, path: target, status: combineStatuses(statuses) };
4446
4472
  }
4447
-
4448
- // src/cli/commands/onboard.ts
4449
- function suggestOtherStacks(installed) {
4450
- const missing = CODING_AGENT_STACKS.filter((s) => !installed.includes(s));
4451
- if (missing.length === 0) return "";
4452
- const labels = missing.map((s) => STACKS[s].label).join(" / ");
4453
- const ids = missing.join(",");
4454
- return `
4455
- Also use ${labels}? Run: blazediff-agent onboard --stack ${ids}`;
4456
- }
4457
- async function promptForStacks() {
4458
- const rl = promises$1.createInterface({
4459
- input: process.stdin,
4460
- output: process.stderr
4461
- });
4462
- try {
4463
- const lines = [
4464
- "No coding-agent stack detected. Which one(s) do you use?",
4465
- ...CODING_AGENT_STACKS.map(
4466
- (id, i) => ` [${i + 1}] ${STACKS[id].label.padEnd(16)} ${STACKS[id].target?.(process.cwd()) ?? ""}`
4467
- ),
4468
- " [a] all three coding agents",
4469
- ` [l] ${STACKS.local.label.padEnd(16)} local judge, no coding agent (Moondream + Qwen)`,
4470
- ""
4471
- ];
4472
- process.stderr.write(`${lines.join("\n")}`);
4473
- const answer = (await rl.question("Choice (1/2/3/a/l): ")).trim().toLowerCase();
4474
- if (!answer) throw new Error("no stack selected; aborting");
4475
- if (answer === "a" || answer === "all") return [...CODING_AGENT_STACKS];
4476
- if (answer === "l" || answer === "local") return ["local"];
4477
- const idx = Number(answer);
4478
- if (!Number.isInteger(idx) || idx < 1 || idx > CODING_AGENT_STACKS.length) {
4479
- throw new Error(
4480
- `invalid choice "${answer}"; expected 1-${CODING_AGENT_STACKS.length}, "a", or "l"`
4481
- );
4482
- }
4483
- return [CODING_AGENT_STACKS[idx - 1]];
4484
- } finally {
4485
- rl.close();
4486
- }
4487
- }
4488
- function humanizeResults(results) {
4489
- const lines = results.map((r) => {
4490
- const info = STACKS[r.stack];
4491
- if (r.status === "configured") {
4492
- return ` ${info.label.padEnd(16)} configured local judge (model downloads on first check)`;
4493
- }
4494
- const verb = r.status === "created" ? "wrote" : r.status === "updated" ? "updated" : r.status === "unchanged" ? "unchanged" : "skipped (exists; pass --force to overwrite)";
4495
- const scopeTag = info.scope === "user" ? " [user-global]" : "";
4496
- return ` ${info.label.padEnd(16)} ${verb}: ${r.path}${scopeTag}`;
4497
- });
4498
- const installed = results.map((r) => r.stack);
4499
- const hint = installed.includes("local") ? "" : suggestOtherStacks(installed);
4500
- return ["BlazeDiff playbook installed:", ...lines].join("\n") + hint;
4501
- }
4502
- async function persistJudge(judge, cwd) {
4503
- const existing = await loadConfig(cwd);
4504
- const config = { ...existing ?? { devServer: null }, judge };
4505
- await saveConfig(config, cwd);
4506
- }
4507
- function registerOnboard(program, out) {
4508
- program.command("onboard").description(
4509
- "install the BlazeDiff playbook for your stack in cwd. Auto-detects Claude Code (.claude/), Codex (AGENTS.md), and Cursor (.cursor/). Use --stack local for a local (Moondream + Qwen) judge. Prompts on TTY when none detected."
4510
- ).option(
4511
- "--stack <list>",
4512
- 'comma-separated stack ids, or "all". valid: claude,codex,cursor,all,local (local cannot be combined)'
4513
- ).option(
4514
- "--force",
4515
- "overwrite existing playbook files (idempotent without --force only when content matches)"
4516
- ).action(async (opts) => {
4517
- const cwd = process.cwd();
4518
- let targets;
4519
- if (opts.stack) {
4520
- targets = parseStackList(opts.stack);
4521
- } else {
4522
- const detected = detectStacks(cwd);
4523
- if (detected.length > 0) {
4524
- targets = detected;
4525
- } else if (out.isTTY() && !out.isJson()) {
4526
- targets = await promptForStacks();
4527
- } else {
4528
- throw new Error(
4529
- "no coding-agent stack detected in cwd. pass --stack <claude|codex|cursor|all|local> explicitly."
4530
- );
4531
- }
4532
- }
4533
- const results = [];
4534
- for (const t of targets) {
4535
- results.push(await installStack(t, cwd, { force: opts.force }));
4536
- }
4537
- const judge = targets.includes("local") ? "local" : "host";
4538
- await persistJudge(judge, cwd);
4539
- out.emit(
4540
- {
4541
- ok: true,
4542
- detected: detectStacks(cwd),
4543
- judge,
4544
- installed: results
4545
- },
4546
- humanizeResults(results)
4547
- );
4548
- });
4549
- }
4550
4473
  var execFileP = util.promisify(child_process.execFile);
4551
4474
  async function isPortOpen(port, host = "127.0.0.1") {
4552
4475
  return new Promise((resolve) => {
@@ -4600,7 +4523,7 @@ async function startServer(opts) {
4600
4523
  const cwd = opts.cwd ?? process.cwd();
4601
4524
  const logPath = opts.logPath ?? paths(cwd).serverLog;
4602
4525
  const pidPath = opts.pidPath ?? paths(cwd).serverPid;
4603
- await promises.mkdir(path27__default.default.dirname(logPath), { recursive: true });
4526
+ await promises.mkdir(path26__default.default.dirname(logPath), { recursive: true });
4604
4527
  if (await isPortOpen(opts.port)) {
4605
4528
  const discoveredPid = await findPidByPort(opts.port);
4606
4529
  if (discoveredPid) {
@@ -4712,7 +4635,198 @@ function installSignalHandlers(child) {
4712
4635
  process.on("exit", cleanup);
4713
4636
  }
4714
4637
 
4715
- // src/cli/commands/reset.ts
4638
+ // src/cli/commands/onboard.ts
4639
+ async function promptForStacks() {
4640
+ const choices = [
4641
+ ...CODING_AGENT_STACKS.map((id) => ({
4642
+ label: STACKS[id].label,
4643
+ value: [id],
4644
+ hint: STACKS[id].target?.(process.cwd()) ?? ""
4645
+ })),
4646
+ { label: "All three coding agents", value: [...CODING_AGENT_STACKS] },
4647
+ {
4648
+ label: STACKS.local.label,
4649
+ value: ["local"],
4650
+ hint: "local judge, no coding agent"
4651
+ }
4652
+ ];
4653
+ return promptChoice("Which coding agent(s) do you use?", choices);
4654
+ }
4655
+ async function resolveStacks(opts, interactive) {
4656
+ if (opts.stack) return parseStackList(opts.stack);
4657
+ const detected = detectStacks(process.cwd());
4658
+ if (detected.length > 0) return detected;
4659
+ if (interactive) return promptForStacks();
4660
+ return [];
4661
+ }
4662
+ async function ensureBrowsers(opts, interactive) {
4663
+ const status = await installBrowsers({ check: true });
4664
+ if (status.installed) return { installed: true, skipped: false };
4665
+ const shouldInstall = opts.yes || !interactive || await promptYesNo("Chromium is not installed. Install it now?", true);
4666
+ if (!shouldInstall) return { installed: false, skipped: true };
4667
+ const result = await installBrowsers();
4668
+ return { installed: result.installed, skipped: false };
4669
+ }
4670
+ function routeId(path30) {
4671
+ const slug = path30.replace(/^\/+|\/+$/g, "").replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "");
4672
+ return slug || "home";
4673
+ }
4674
+ function toCaptureRoutes(routes) {
4675
+ const seen = /* @__PURE__ */ new Set();
4676
+ const out = [];
4677
+ for (const r of routes) {
4678
+ if (r.auth) continue;
4679
+ let id = routeId(new URL(r.url, "http://x").pathname);
4680
+ while (seen.has(id)) id = `${id}-2`;
4681
+ seen.add(id);
4682
+ out.push({ id, url: r.url });
4683
+ }
4684
+ return out;
4685
+ }
4686
+ async function captureBaselines(config, baseUrl) {
4687
+ const cwd = process.cwd();
4688
+ const port = config.devServer?.port;
4689
+ let startedByUs = false;
4690
+ if (config.devServer && port && !await isPortOpen(port)) {
4691
+ await startServer({
4692
+ command: config.devServer.command,
4693
+ port,
4694
+ readyTimeoutMs: config.devServer.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS
4695
+ });
4696
+ startedByUs = true;
4697
+ }
4698
+ try {
4699
+ const discovered = await discover({ baseUrl });
4700
+ const routes = toCaptureRoutes(discovered);
4701
+ if (routes.length === 0) return { captured: 0, routes: 0 };
4702
+ const report = await runCaptures({
4703
+ baseUrl,
4704
+ routes,
4705
+ mode: "baseline",
4706
+ writeManifest: true
4707
+ });
4708
+ return { captured: report.succeeded, routes: routes.length };
4709
+ } finally {
4710
+ await closeBrowser();
4711
+ if (startedByUs && port) await stopServer(cwd, port);
4712
+ }
4713
+ }
4714
+ async function persistJudge(judge, cwd) {
4715
+ const existing = await loadConfig(cwd);
4716
+ const config = { ...existing ?? { devServer: null }, judge };
4717
+ await saveConfig(config, cwd);
4718
+ }
4719
+ function suggestOtherStacks(installed) {
4720
+ if (installed.includes("local")) return "";
4721
+ const missing = CODING_AGENT_STACKS.filter((s) => !installed.includes(s));
4722
+ if (missing.length === 0) return "";
4723
+ const labels = missing.map((s) => STACKS[s].label).join(" / ");
4724
+ return ` also use ${labels}? run: blazediff-agent onboard --stack ${missing.join(",")}`;
4725
+ }
4726
+ function humanizeInstall(results) {
4727
+ return results.map((r) => {
4728
+ const info = STACKS[r.stack];
4729
+ if (r.status === "configured") {
4730
+ return ` ${info.label}: configured local judge (models download on first check)`;
4731
+ }
4732
+ const verb = r.status === "created" ? "wrote" : r.status === "updated" ? "updated" : r.status === "unchanged" ? "unchanged" : "skipped (exists; --force to overwrite)";
4733
+ const scope = info.scope === "user" ? " [user-global]" : "";
4734
+ return ` ${info.label}: ${verb} ${r.path}${scope}`;
4735
+ });
4736
+ }
4737
+ function registerOnboard(program, out) {
4738
+ program.command("onboard").description(
4739
+ "interactive setup: write .blazediff/config.json, install Chromium, install the BlazeDiff playbook for your stack (Claude Code / Codex / Cursor, or --stack local for a Moondream + Qwen judge), and optionally capture baselines."
4740
+ ).option(
4741
+ "--stack <list>",
4742
+ 'comma-separated stack ids, or "all". valid: claude,codex,cursor,all,local (local cannot be combined)'
4743
+ ).option("--force", "overwrite existing config and playbook files").option(
4744
+ "--url <baseUrl>",
4745
+ "point at an already-running server / external URL"
4746
+ ).option("--dev-command <cmd>", "override detected dev-server command").option("--port <n>", "override detected port").option(
4747
+ "--dev-script <name>",
4748
+ "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) => {
4750
+ const cwd = process.cwd();
4751
+ const interactive = out.isTTY() && !out.isJson();
4752
+ const lines = [];
4753
+ let config = null;
4754
+ let created = false;
4755
+ try {
4756
+ const res = await ensureConfig(opts, out);
4757
+ config = res.config;
4758
+ created = res.created;
4759
+ lines.push(
4760
+ created ? `wrote ${configSummary(config)}` : `config exists: ${configSummary(config)} (--force to rewrite)`
4761
+ );
4762
+ } catch (err) {
4763
+ if (err instanceof Error && err.message === NO_DEV_SCRIPT_ERROR) {
4764
+ lines.push(
4765
+ "config: skipped (no dev script detected; pass --url or --dev-command)"
4766
+ );
4767
+ } else {
4768
+ throw err;
4769
+ }
4770
+ }
4771
+ let chromium2 = {
4772
+ installed: true,
4773
+ skipped: true
4774
+ };
4775
+ if (opts.browsers === false) {
4776
+ lines.push("chromium: skipped (--no-browsers)");
4777
+ } else {
4778
+ chromium2 = await ensureBrowsers(opts, interactive);
4779
+ lines.push(
4780
+ chromium2.installed ? "chromium ready" : "chromium not installed (capture/check will fail until `blazediff-agent browsers install`)"
4781
+ );
4782
+ }
4783
+ const targets = await resolveStacks(opts, interactive);
4784
+ const installed = [];
4785
+ for (const t of targets) {
4786
+ installed.push(await installStack(t, cwd, { force: opts.force }));
4787
+ }
4788
+ let judge = config?.judge ?? "host";
4789
+ if (targets.length === 0) {
4790
+ lines.push(
4791
+ "playbook: no coding-agent stack detected (pass --stack <claude|codex|cursor|all|local> to install)"
4792
+ );
4793
+ } else {
4794
+ judge = targets.includes("local") ? "local" : "host";
4795
+ await persistJudge(judge, cwd);
4796
+ lines.push("playbook:");
4797
+ lines.push(...humanizeInstall(installed));
4798
+ lines.push(suggestOtherStacks(installed.map((r) => r.stack)));
4799
+ }
4800
+ let capture = null;
4801
+ const canCapture = opts.capture !== false && chromium2.installed && !chromium2.skipped && Boolean(config?.baseUrl);
4802
+ const wantCapture = canCapture && (opts.yes || interactive && await promptYesNo(
4803
+ "Discover routes & capture baselines now?",
4804
+ true
4805
+ ));
4806
+ if (wantCapture && config?.baseUrl) {
4807
+ capture = await captureBaselines(config, config.baseUrl);
4808
+ lines.push(
4809
+ capture.captured > 0 ? `captured ${capture.captured}/${capture.routes} baselines` : "no routes discovered \u2014 capture manually with `capture --stdin --mode baseline`"
4810
+ );
4811
+ }
4812
+ lines.push(
4813
+ capture && capture.captured > 0 ? "\u2192 next: blazediff-agent check" : "\u2192 next: blazediff-agent discover | capture --stdin --mode baseline"
4814
+ );
4815
+ out.emit(
4816
+ {
4817
+ ok: true,
4818
+ created,
4819
+ config,
4820
+ chromium: chromium2,
4821
+ detected: detectStacks(cwd),
4822
+ judge,
4823
+ installed,
4824
+ captured: capture
4825
+ },
4826
+ lines.filter(Boolean).join("\n")
4827
+ );
4828
+ });
4829
+ }
4716
4830
  async function stopTrackedServer() {
4717
4831
  const config = await loadConfig();
4718
4832
  if (!config?.devServer) return { stopped: false };
@@ -4725,7 +4839,7 @@ async function stopTrackedServer() {
4725
4839
  }
4726
4840
  function registerReset(program, out) {
4727
4841
  program.command("reset").description(
4728
- "wipe .blazediff/ entirely - config, manifest, baselines, actual, judgments, summary, pid/log (stops the dev server first if one is tracked). Re-run /blazediff or `init` afterward to start from scratch."
4842
+ "wipe .blazediff/ entirely - config, manifest, baselines, actual, judgments, summary, pid/log (stops the dev server first if one is tracked). Re-run /blazediff or `onboard` afterward to start from scratch."
4729
4843
  ).option("--yes", "do not prompt; required when stdin is a TTY").action(async (opts) => {
4730
4844
  const root = paths().root;
4731
4845
  if (!fs.existsSync(root)) {
@@ -4824,14 +4938,14 @@ function recountReport(report) {
4824
4938
  }
4825
4939
  async function approveEntry(id, cwd = process.cwd()) {
4826
4940
  const p = paths(cwd);
4827
- const actualPng = path27__default.default.join(p.actual, `${id}.png`);
4941
+ const actualPng = path26__default.default.join(p.actual, `${id}.png`);
4828
4942
  if (!fs.existsSync(actualPng)) return null;
4829
4943
  await promises.mkdir(p.baselines, { recursive: true });
4830
- await promises.copyFile(actualPng, path27__default.default.join(p.baselines, `${id}.png`));
4944
+ await promises.copyFile(actualPng, path26__default.default.join(p.baselines, `${id}.png`));
4831
4945
  await Promise.all([
4832
4946
  promises.rm(actualPng, { force: true }),
4833
- promises.rm(path27__default.default.join(p.actual, `${id}.diff.png`), { force: true }),
4834
- promises.rm(path27__default.default.join(p.judgments, id), { recursive: true, force: true })
4947
+ promises.rm(path26__default.default.join(p.actual, `${id}.diff.png`), { force: true }),
4948
+ promises.rm(path26__default.default.join(p.judgments, id), { recursive: true, force: true })
4835
4949
  ]);
4836
4950
  const report = await readReport(cwd);
4837
4951
  const result = report?.results.find((r) => r.id === id);
@@ -4858,10 +4972,10 @@ async function rejectEntry(id, cwd = process.cwd()) {
4858
4972
  action: "investigate"
4859
4973
  };
4860
4974
  const p = paths(cwd);
4861
- const dir = path27__default.default.join(p.judgments, id);
4975
+ const dir = path26__default.default.join(p.judgments, id);
4862
4976
  await promises.mkdir(dir, { recursive: true });
4863
4977
  await promises.writeFile(
4864
- path27__default.default.join(dir, "verdict.json"),
4978
+ path26__default.default.join(dir, "verdict.json"),
4865
4979
  `${JSON.stringify({ id, verdict, rationale: "rejected via review" }, null, 2)}
4866
4980
  `,
4867
4981
  "utf8"
@@ -4880,7 +4994,7 @@ async function rejectEntry(id, cwd = process.cwd()) {
4880
4994
 
4881
4995
  // src/review/server.ts
4882
4996
  var execFileP2 = util.promisify(child_process.execFile);
4883
- var CLIENT_DIR = path27__default.default.join(__dirname, "review", "client");
4997
+ var CLIENT_DIR = path26__default.default.join(__dirname, "review", "client");
4884
4998
  var CONTENT_TYPES = {
4885
4999
  ".html": "text/html; charset=utf-8",
4886
5000
  ".js": "text/javascript; charset=utf-8",
@@ -4907,7 +5021,7 @@ function sendJson(res, status, body) {
4907
5021
  res.end(payload);
4908
5022
  }
4909
5023
  function streamFile(res, file) {
4910
- const type = CONTENT_TYPES[path27__default.default.extname(file)] ?? "application/octet-stream";
5024
+ const type = CONTENT_TYPES[path26__default.default.extname(file)] ?? "application/octet-stream";
4911
5025
  res.writeHead(200, { "content-type": type });
4912
5026
  fs.createReadStream(file).on("error", () => {
4913
5027
  if (!res.headersSent) res.writeHead(500);
@@ -4956,7 +5070,7 @@ async function buildRunMeta(cwd) {
4956
5070
  const baseSha = baseRef ? await gitText(cwd, ["rev-parse", "--short", baseRef]) : "";
4957
5071
  const baseline = baseRef ? `${baseRef} @ ${baseSha}`.replace(/ @ $/, "") : "";
4958
5072
  return {
4959
- name: path27__default.default.basename(cwd),
5073
+ name: path26__default.default.basename(cwd),
4960
5074
  baseline,
4961
5075
  candidate,
4962
5076
  threshold: DEFAULT_THRESHOLD,
@@ -4965,9 +5079,9 @@ async function buildRunMeta(cwd) {
4965
5079
  }
4966
5080
  function imageFile(cwd, kind, id) {
4967
5081
  const p = paths(cwd);
4968
- const file = kind === "baseline" ? path27__default.default.join(p.baselines, `${id}.png`) : kind === "actual" ? path27__default.default.join(p.actual, `${id}.png`) : path27__default.default.join(p.actual, `${id}.diff.png`);
4969
- const resolved = path27__default.default.resolve(file);
4970
- if (!resolved.startsWith(path27__default.default.resolve(p.root) + path27__default.default.sep)) return null;
5082
+ const file = kind === "baseline" ? path26__default.default.join(p.baselines, `${id}.png`) : kind === "actual" ? path26__default.default.join(p.actual, `${id}.png`) : path26__default.default.join(p.actual, `${id}.diff.png`);
5083
+ const resolved = path26__default.default.resolve(file);
5084
+ if (!resolved.startsWith(path26__default.default.resolve(p.root) + path26__default.default.sep)) return null;
4971
5085
  return resolved;
4972
5086
  }
4973
5087
  async function handleApi(req, res, cwd, url) {
@@ -5024,11 +5138,11 @@ async function handleApi(req, res, cwd, url) {
5024
5138
  }
5025
5139
  async function serveStatic(res, pathname) {
5026
5140
  const rel = pathname === "/" ? "index.html" : pathname.replace(/^\/+/, "");
5027
- const candidate = path27__default.default.resolve(CLIENT_DIR, rel);
5028
- const inside = candidate.startsWith(path27__default.default.resolve(CLIENT_DIR) + path27__default.default.sep);
5141
+ const candidate = path26__default.default.resolve(CLIENT_DIR, rel);
5142
+ const inside = candidate.startsWith(path26__default.default.resolve(CLIENT_DIR) + path26__default.default.sep);
5029
5143
  let file = candidate;
5030
5144
  if (!inside || !fs.existsSync(candidate) || !await isFile(candidate)) {
5031
- file = path27__default.default.join(CLIENT_DIR, "index.html");
5145
+ file = path26__default.default.join(CLIENT_DIR, "index.html");
5032
5146
  }
5033
5147
  if (!fs.existsSync(file)) {
5034
5148
  res.writeHead(500, { "content-type": "text/plain" });
@@ -5133,9 +5247,9 @@ async function cleanupAfterRewrite(rewrittenIds, scopeAll) {
5133
5247
  return;
5134
5248
  }
5135
5249
  const perId = rewrittenIds.flatMap((id) => [
5136
- promises.rm(path27__default.default.join(p.actual, `${id}.png`), { force: true }),
5137
- promises.rm(path27__default.default.join(p.actual, `${id}.diff.png`), { force: true }),
5138
- promises.rm(path27__default.default.join(p.judgments, id), { recursive: true, force: true })
5250
+ promises.rm(path26__default.default.join(p.actual, `${id}.png`), { force: true }),
5251
+ promises.rm(path26__default.default.join(p.actual, `${id}.diff.png`), { force: true }),
5252
+ promises.rm(path26__default.default.join(p.judgments, id), { recursive: true, force: true })
5139
5253
  ]);
5140
5254
  await Promise.all([
5141
5255
  ...perId,
@@ -5173,7 +5287,7 @@ async function resolveTargets(manifest, ids, opts) {
5173
5287
  const names = await promises.readdir(judgmentsDir);
5174
5288
  const failed = /* @__PURE__ */ new Set();
5175
5289
  for (const name of names) {
5176
- const full = path27__default.default.join(judgmentsDir, name);
5290
+ const full = path26__default.default.join(judgmentsDir, name);
5177
5291
  if (fs.statSync(full).isDirectory()) failed.add(name);
5178
5292
  }
5179
5293
  return failed;
@@ -5242,7 +5356,7 @@ function registerServeStatus(program, out) {
5242
5356
  const config = await loadConfig();
5243
5357
  if (!config) {
5244
5358
  throw new Error(
5245
- "no .blazediff/config.json. Run `blazediff-agent init` first."
5359
+ "no .blazediff/config.json. Run `blazediff-agent onboard` first."
5246
5360
  );
5247
5361
  }
5248
5362
  if (!config.devServer) {
@@ -5289,14 +5403,14 @@ function extractCwdArg(argv) {
5289
5403
  function applyCwdFromArgv() {
5290
5404
  const value = extractCwdArg(process.argv.slice(2));
5291
5405
  if (!value) return;
5292
- const resolved = path27__default.default.resolve(value);
5406
+ const resolved = path26__default.default.resolve(value);
5293
5407
  if (fs.existsSync(resolved)) {
5294
5408
  process.chdir(resolved);
5295
5409
  return;
5296
5410
  }
5297
- const cwdBase = path27__default.default.basename(process.cwd());
5298
- const inputBase = path27__default.default.basename(value);
5299
- const doubled = cwdBase && inputBase && cwdBase === inputBase && resolved.endsWith(path27__default.default.join(cwdBase, cwdBase));
5411
+ const cwdBase = path26__default.default.basename(process.cwd());
5412
+ const inputBase = path26__default.default.basename(value);
5413
+ const doubled = cwdBase && inputBase && cwdBase === inputBase && resolved.endsWith(path26__default.default.join(cwdBase, cwdBase));
5300
5414
  if (doubled) {
5301
5415
  throw new Error(
5302
5416
  `--cwd "${value}" resolves to ${resolved} which does not exist. Looks like you may already be inside that directory - re-run with --cwd as an absolute path, or from the parent.`
@@ -5336,10 +5450,10 @@ function makeOutput(getRootOpts) {
5336
5450
  function envFiles(cwd) {
5337
5451
  const root = paths(cwd).root;
5338
5452
  return [
5339
- path27__default.default.join(root, ".env.local"),
5340
- path27__default.default.join(root, ".env"),
5341
- path27__default.default.join(cwd, ".env.local"),
5342
- path27__default.default.join(cwd, ".env")
5453
+ path26__default.default.join(root, ".env.local"),
5454
+ path26__default.default.join(root, ".env"),
5455
+ path26__default.default.join(cwd, ".env.local"),
5456
+ path26__default.default.join(cwd, ".env")
5343
5457
  ];
5344
5458
  }
5345
5459
  function parse(content) {
@@ -5388,7 +5502,6 @@ function buildProgram() {
5388
5502
  const program = new commander.Command().name("blazediff-agent").description("Agentic visual regression for BlazeDiff").version(package_default.version).option("-C, --cwd <path>", "operate on a different directory").option("--json", "emit JSON to stdout where applicable").option("--quiet", "suppress non-error output");
5389
5503
  const out = makeOutput(() => program.opts());
5390
5504
  registerOnboard(program, out);
5391
- registerInit(program, out);
5392
5505
  registerDiscover(program, out);
5393
5506
  registerServeStatus(program, out);
5394
5507
  registerCapture(program, out);