@blazediff/agent 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,27 +24,26 @@ Visual regression testing your coding agent can judge. Discovers routes, screens
24
24
  npm install --save-dev @blazediff/agent
25
25
  ```
26
26
 
27
- First run prompts to install bundled Chromium.
28
-
29
27
  ## Quickstart
30
28
 
31
29
  ```bash
32
- blazediff-agent init # write .blazediff/config.json
33
- blazediff-agent browsers install # ensure chromium
34
- echo '[{"id":"home","url":"/"}]' \
35
- | blazediff-agent capture --stdin --mode baseline
36
- blazediff-agent check --judge host # CI
37
- blazediff-agent rewrite home # accept intentional change
30
+ blazediff-agent onboard # interactive: config + chromium + playbook + baselines
31
+ blazediff-agent check --judge host # CI: re-capture, diff, judge
32
+ blazediff-agent rewrite home # accept an intentional change
38
33
  ```
39
34
 
40
- Commit `.blazediff/` (config + manifest + baselines). All commands accept `--json`.
35
+ `onboard` writes `.blazediff/config.json`, installs bundled Chromium, installs the
36
+ playbook for your coding agent, and offers to capture baselines on the spot. The
37
+ second command (`check`, or `capture` if you declined the baseline offer) starts
38
+ capturing. Commit `.blazediff/` (config + manifest + baselines). All commands
39
+ accept `--json`; under `--json`/CI, `onboard` runs non-interactively (no prompts,
40
+ no capture) — a scriptable config + chromium step.
41
41
 
42
42
  ## Commands
43
43
 
44
44
  <table>
45
45
  <tr><th width="200">Command</th><th>Description</th></tr>
46
- <tr><td><code>onboard</code></td><td>Install the playbook for your stack: Claude Code / Codex / Cursor, or <code>local</code> for a local (Moondream + Qwen) judge</td></tr>
47
- <tr><td><code>init</code></td><td>Detect framework, write <code>.blazediff/config.json</code></td></tr>
46
+ <tr><td><code>onboard</code></td><td>Interactive setup: write <code>.blazediff/config.json</code>, install Chromium, install the playbook for your stack (Claude Code / Codex / Cursor, or <code>local</code> for a Moondream + Qwen judge), and optionally capture baselines</td></tr>
48
47
  <tr><td><code>discover</code></td><td>BFS-crawl routes from <code>baseUrl</code></td></tr>
49
48
  <tr><td><code>capture --stdin</code></td><td>Screenshot routes from stdin JSON, write baselines/actuals</td></tr>
50
49
  <tr><td><code>check</code></td><td>Re-capture, diff against baseline, emit <code>CheckReport</code>. Judge backend defaults to <code>config.judge</code> (set by <code>onboard</code>), overridable with <code>--judge host|none|local</code>. <code>--judge host</code> suspends on the first ambiguous entry (<code>--apply-judgments</code> resumes once verdicts are written); <code>--judge local</code> judges inline with local models (Moondream describes, Qwen classifies) — no host round-trip.</td></tr>
@@ -59,15 +58,21 @@ Commit `.blazediff/` (config + manifest + baselines). All commands accept `--jso
59
58
 
60
59
  Pass `--cwd <abs-path>` to target a sub-package in a monorepo.
61
60
 
62
- ## Onboarding
61
+ ## Onboard options
62
+
63
+ `onboard` auto-detects your coding agent; override or scope the playbook with `--stack`:
63
64
 
64
65
  ```bash
65
- blazediff-agent onboard # auto-detect coding-agent stack
66
66
  blazediff-agent onboard --stack codex # explicit
67
67
  blazediff-agent onboard --stack all # claude + codex + cursor
68
68
  blazediff-agent onboard --stack local # local judge, no host agent (Moondream + Qwen)
69
+ blazediff-agent onboard --no-browsers --no-capture # config + playbook only
69
70
  ```
70
71
 
72
+ Other flags: `--url <baseUrl>` (external/running server), `--dev-command <cmd>` /
73
+ `--port <n>` / `--dev-script <name>` (override detection), `--yes` (accept prompts),
74
+ `--force` (rewrite config + playbook).
75
+
71
76
  For coding-agent stacks, writes the playbook and sets `config.judge: "host"`:
72
77
  - Claude Code → `<project>/.claude/skills/blazediff/SKILL.md`
73
78
  - Codex → `~/.codex/skills/blazediff/SKILL.md`
package/SKILL.md CHANGED
@@ -56,20 +56,21 @@ When the user asks to wipe blazediff's state and start over (manifest stale beyo
56
56
  - Then re-run the full **authoring** flow below. Do not call `reset` without explicit user request — it discards committed baselines.
57
57
 
58
58
  ## authoring
59
- 1. **Config.**
60
- - User points at a URL ("test https://blazediff.dev", "server's running on :3001") → `blazediff-agent --cwd "$TARGET" init --url <url> --json`.
61
- - Local app, dev script ambiguous or wrong → `init --dev-command "<cmd>" --port <n> --json`.
62
- - Local app, single obvious dev script → `init --json`. On error or ambiguity, the CLI lists candidates; pick one with `--dev-script <name>`.
63
- 2. **Chromium.** `blazediff-agent browsers install --check --json`. If `installed: false`, run `blazediff-agent browsers install`. This uses the bundled playwright — no sudo, no `npx playwright install --with-deps`. (On Linux, OS-level deps for chromium may still need `npx playwright install-deps chromium` if the run fails on missing libs; tell the user.)
64
- 3. **Dev server.** If `config.devServer` is non-null, run `blazediff-agent --cwd "$TARGET" serve-status --detach --json`. **Expect this to wait up to 60s** for the port to open before returning. Do not background or poll it.
65
- 4. **Discover routes.** Prefer reading the router source directly:
59
+ 1. **Setup (config + Chromium).** One `onboard --json` call writes `.blazediff/config.json` and ensures bundled Chromium (no prompts under `--json`; no capture step):
60
+ - User points at a URL ("test https://blazediff.dev", "server's running on :3001") → `blazediff-agent --cwd "$TARGET" onboard --url <url> --json`.
61
+ - Local app, dev script ambiguous or wrong → `onboard --dev-command "<cmd>" --port <n> --json`.
62
+ - Local app, single obvious dev script → `onboard --json`. When multiple dev scripts exist, non-interactive picks the highest-priority one (`dev`); override with `--dev-script <name>`.
63
+
64
+ Chromium uses the bundled playwright — no sudo, no `npx playwright install --with-deps`. (On Linux, OS-level deps may still need `npx playwright install-deps chromium` if a run fails on missing libs; tell the user.) Skip either step with `--no-browsers`.
65
+ 2. **Dev server.** If `config.devServer` is non-null, run `blazediff-agent --cwd "$TARGET" serve-status --detach --json`. **Expect this to wait up to 60s** for the port to open before returning. Do not background or poll it.
66
+ 3. **Discover routes.** Prefer reading the router source directly:
66
67
  - Next.js: `app/**/page.{tsx,jsx,mdx}` + `pages/**/*.{tsx,jsx}` (skip `api/`, `_app`, `_document`, `_error`).
67
68
  - Vite + react-router: parse `<Route path=...>` in `router.{ts,tsx}`.
68
69
  - Remix / SvelteKit / Astro: walk `app/routes` or `src/routes`.
69
70
 
70
71
  If the framework is unknown or the router source is opaque, call `blazediff-agent --cwd "$TARGET" discover --json`. That command does a BFS crawl from the configured `baseUrl` (depth 2, up to 50 routes), reads `.next/routes-manifest.json` if present, and reads `/sitemap.xml`. It's a fallback for when source-walking fails.
71
- 5. **Filter.** Drop `/api/*`, dynamic segments without sample data, redirects/404s. For routes that need login or any pre-screenshot interaction, attach a harness via `harnesses: [...]` on the entry. See **harnesses** below.
72
- 6. **Capture in one call.** Build a JSON array of route entries and pipe it through stdin:
72
+ 4. **Filter.** Drop `/api/*`, dynamic segments without sample data, redirects/404s. For routes that need login or any pre-screenshot interaction, attach a harness via `harnesses: [...]` on the entry. See **harnesses** below.
73
+ 5. **Capture in one call.** Build a JSON array of route entries and pipe it through stdin:
73
74
  ```
74
75
  cat <<'EOF' | blazediff-agent --cwd "$TARGET" capture --stdin --mode baseline --json
75
76
  [
package/dist/cli.js CHANGED
@@ -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.5.0"};
55
55
  var FROZEN_NOW = Date.UTC(2025, 0, 1, 0, 0, 0);
56
56
  var STABILITY_CSS = `
57
57
  *,*::before,*::after{
@@ -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
@@ -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]));
@@ -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);
@@ -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 };
@@ -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;
@@ -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"]],
@@ -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,89 +4253,22 @@ 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;
@@ -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) => {
@@ -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(path31) {
4671
+ const slug = path31.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)) {
@@ -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) {
@@ -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);
package/dist/index.js CHANGED
@@ -513,7 +513,9 @@ function resolveBaseUrl(config, override) {
513
513
  if (override) return override;
514
514
  if (config?.baseUrl) return config.baseUrl;
515
515
  if (config?.devServer) return `http://127.0.0.1:${config.devServer.port}`;
516
- throw new Error("no baseUrl: pass --base-url or run `blazediff-agent init`");
516
+ throw new Error(
517
+ "no baseUrl: pass --base-url or run `blazediff-agent onboard`"
518
+ );
517
519
  }
518
520
 
519
521
  // src/graph/semaphore.ts
@@ -2024,7 +2026,7 @@ async function reconstructFromDisk(cwd, dirs) {
2024
2026
  const manifest = await loadManifest(cwd);
2025
2027
  if (!manifest) {
2026
2028
  throw new Error(
2027
- `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent init\` first.`
2029
+ `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent onboard\` first.`
2028
2030
  );
2029
2031
  }
2030
2032
  const dirById = new Map(dirs.map((d) => [d.id, d]));
@@ -2068,7 +2070,7 @@ async function applyJudgments(opts = {}) {
2068
2070
  const manifest = await loadManifest(cwd);
2069
2071
  if (!manifest) {
2070
2072
  throw new Error(
2071
- `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent init\` first.`
2073
+ `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent onboard\` first.`
2072
2074
  );
2073
2075
  }
2074
2076
  const dirs = await readJudgmentDirs(paths(cwd).judgments);
@@ -3044,7 +3046,7 @@ async function loadNode(state) {
3044
3046
  const manifest = await loadManifest(state.options.cwd);
3045
3047
  if (!manifest) {
3046
3048
  throw new Error(
3047
- `no manifest found at ${paths(state.options.cwd).manifest}. Run \`blazediff init\` then \`/blazediff\` (or capture manually) first.`
3049
+ `no manifest found at ${paths(state.options.cwd).manifest}. Run \`blazediff-agent onboard\` then \`/blazediff\` (or capture manually) first.`
3048
3050
  );
3049
3051
  }
3050
3052
  return { entries: manifest.entries, manifest };
package/dist/index.mjs CHANGED
@@ -485,7 +485,9 @@ function resolveBaseUrl(config, override) {
485
485
  if (override) return override;
486
486
  if (config?.baseUrl) return config.baseUrl;
487
487
  if (config?.devServer) return `http://127.0.0.1:${config.devServer.port}`;
488
- throw new Error("no baseUrl: pass --base-url or run `blazediff-agent init`");
488
+ throw new Error(
489
+ "no baseUrl: pass --base-url or run `blazediff-agent onboard`"
490
+ );
489
491
  }
490
492
 
491
493
  // src/graph/semaphore.ts
@@ -1996,7 +1998,7 @@ async function reconstructFromDisk(cwd, dirs) {
1996
1998
  const manifest = await loadManifest(cwd);
1997
1999
  if (!manifest) {
1998
2000
  throw new Error(
1999
- `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent init\` first.`
2001
+ `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent onboard\` first.`
2000
2002
  );
2001
2003
  }
2002
2004
  const dirById = new Map(dirs.map((d) => [d.id, d]));
@@ -2040,7 +2042,7 @@ async function applyJudgments(opts = {}) {
2040
2042
  const manifest = await loadManifest(cwd);
2041
2043
  if (!manifest) {
2042
2044
  throw new Error(
2043
- `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent init\` first.`
2045
+ `no manifest at ${paths(cwd).manifest}. Run \`blazediff-agent onboard\` first.`
2044
2046
  );
2045
2047
  }
2046
2048
  const dirs = await readJudgmentDirs(paths(cwd).judgments);
@@ -3016,7 +3018,7 @@ async function loadNode(state) {
3016
3018
  const manifest = await loadManifest(state.options.cwd);
3017
3019
  if (!manifest) {
3018
3020
  throw new Error(
3019
- `no manifest found at ${paths(state.options.cwd).manifest}. Run \`blazediff init\` then \`/blazediff\` (or capture manually) first.`
3021
+ `no manifest found at ${paths(state.options.cwd).manifest}. Run \`blazediff-agent onboard\` then \`/blazediff\` (or capture manually) first.`
3020
3022
  );
3021
3023
  }
3022
3024
  return { entries: manifest.entries, manifest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazediff/agent",
3
- "version": "0.4.0",
3
+ "version": "0.5.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": {