@blazediff/agent 0.10.1 → 0.11.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
@@ -51,7 +51,7 @@ var treeKill__default = /*#__PURE__*/_interopDefault(treeKill);
51
51
 
52
52
  // package.json
53
53
  var package_default = {
54
- version: "0.10.1"};
54
+ version: "0.11.0"};
55
55
  var FROZEN_NOW = Date.UTC(2025, 0, 1, 0, 0, 0);
56
56
  var STABILITY_CSS = `
57
57
  *,*::before,*::after{
@@ -4791,53 +4791,64 @@ async function ensureConfig(opts, out) {
4791
4791
  function configSummary(config) {
4792
4792
  return config.devServer ? `${paths().config} (baseUrl ${config.baseUrl}, dev: ${config.devServer.command} :${config.devServer.port})` : `${paths().config} (external baseUrl ${config.baseUrl})`;
4793
4793
  }
4794
- var SKILL_FILES = ["SKILL.md", "JUDGING.md", "MASKING.md"];
4795
- var cachedDir = null;
4796
- var cachedFiles = null;
4794
+ var SKILLS = ["blazediff", "image-compare"];
4795
+ var NOT_A_SKILL_FILE = "INSTALL.md";
4796
+ var cachedRoot = null;
4797
+ var cachedFiles = /* @__PURE__ */ new Map();
4797
4798
  function moduleDir() {
4798
4799
  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))));
4799
4800
  }
4800
- function resolveSkillDir() {
4801
- if (cachedDir !== null) return cachedDir;
4801
+ function resolveSkillsRoot() {
4802
+ if (cachedRoot !== null) return cachedRoot;
4802
4803
  const here = moduleDir();
4803
4804
  const candidates = [
4804
- path26.join(here, ".."),
4805
- path26.join(here, "..", ".."),
4806
- path26.join(here, "..", "..", "..", "skill", "blazediff"),
4807
- path26.join(here, "..", "..", "..", "..", "skill", "blazediff")
4805
+ path26.join(here, "..", "skills"),
4806
+ path26.join(here, "..", "..", "skills"),
4807
+ path26.join(here, "..", "..", "..", "skill"),
4808
+ path26.join(here, "..", "..", "..", "..", "skill")
4808
4809
  ];
4809
4810
  for (const dir of candidates) {
4810
- if (fs.existsSync(path26.join(dir, "SKILL.md"))) {
4811
- cachedDir = dir;
4812
- return cachedDir;
4811
+ if (fs.existsSync(path26.join(dir, SKILLS[0], "SKILL.md"))) {
4812
+ cachedRoot = dir;
4813
+ return cachedRoot;
4813
4814
  }
4814
4815
  }
4815
4816
  throw new Error(
4816
- `could not locate bundled SKILL.md (looked in: ${candidates.join(", ")}). reinstall @blazediff/agent.`
4817
+ `could not locate bundled skills (looked in: ${candidates.join(", ")}). reinstall @blazediff/agent.`
4817
4818
  );
4818
4819
  }
4819
- function loadSkillFiles() {
4820
- if (cachedFiles !== null) return cachedFiles;
4821
- const dir = resolveSkillDir();
4822
- cachedFiles = SKILL_FILES.filter((name) => fs.existsSync(path26.join(dir, name))).map(
4823
- (name) => ({ name, content: fs.readFileSync(path26.join(dir, name), "utf8") })
4824
- );
4825
- return cachedFiles;
4820
+ function skillFileOrder(a, b) {
4821
+ if (a === "SKILL.md") return -1;
4822
+ if (b === "SKILL.md") return 1;
4823
+ return a.localeCompare(b);
4824
+ }
4825
+ function loadSkillFiles(skill) {
4826
+ const cached = cachedFiles.get(skill);
4827
+ if (cached !== void 0) return cached;
4828
+ const dir = path26.join(resolveSkillsRoot(), skill);
4829
+ const files = fs.readdirSync(dir).filter((name) => name.endsWith(".md") && name !== NOT_A_SKILL_FILE).sort(skillFileOrder).map((name) => ({ name, content: fs.readFileSync(path26.join(dir, name), "utf8") }));
4830
+ cachedFiles.set(skill, files);
4831
+ return files;
4832
+ }
4833
+ function frontmatterBounds(lines) {
4834
+ if (!lines[0]?.startsWith("---")) return -1;
4835
+ for (let i = 1; i < lines.length; i++) {
4836
+ if (lines[i]?.startsWith("---")) return i;
4837
+ }
4838
+ return -1;
4826
4839
  }
4827
4840
  function skillBodyOnly(content) {
4828
4841
  const lines = content.split("\n");
4829
- if (lines[0]?.startsWith("---")) {
4830
- let end = -1;
4831
- for (let i = 1; i < lines.length; i++) {
4832
- if (lines[i]?.startsWith("---")) {
4833
- end = i;
4834
- break;
4835
- }
4836
- }
4837
- if (end > 0)
4838
- return lines.slice(end + 1).join("\n").trimStart();
4839
- }
4840
- return content;
4842
+ const end = frontmatterBounds(lines);
4843
+ if (end <= 0) return content;
4844
+ return lines.slice(end + 1).join("\n").trimStart();
4845
+ }
4846
+ function skillDescription(content) {
4847
+ const lines = content.split("\n");
4848
+ const end = frontmatterBounds(lines);
4849
+ if (end <= 0) return "";
4850
+ const line = lines.slice(1, end).find((l) => l.startsWith("description:"));
4851
+ return line ? line.slice("description:".length).trim() : "";
4841
4852
  }
4842
4853
  var someExists = (paths2) => paths2.some((p) => fs.existsSync(p));
4843
4854
  var STACKS = {
@@ -4851,7 +4862,7 @@ var STACKS = {
4851
4862
  path26.join(cwd, "CLAUDE.md"),
4852
4863
  path26.join(cwd, "AGENTS.md")
4853
4864
  ]),
4854
- target: (cwd) => path26.join(cwd, ".claude", "skills", "blazediff", "SKILL.md"),
4865
+ target: (cwd, skill) => path26.join(cwd, ".claude", "skills", skill, "SKILL.md"),
4855
4866
  format: "skill-file",
4856
4867
  scope: "project"
4857
4868
  },
@@ -4865,7 +4876,7 @@ var STACKS = {
4865
4876
  path26.join(cwd, ".codex"),
4866
4877
  path26.join(os.homedir(), ".codex")
4867
4878
  ]),
4868
- target: () => path26.join(os.homedir(), ".codex", "skills", "blazediff", "SKILL.md"),
4879
+ target: (_cwd, skill) => path26.join(os.homedir(), ".codex", "skills", skill, "SKILL.md"),
4869
4880
  format: "skill-file",
4870
4881
  scope: "user"
4871
4882
  },
@@ -4875,7 +4886,7 @@ var STACKS = {
4875
4886
  kind: "skill-install",
4876
4887
  judge: "host",
4877
4888
  detect: (cwd) => someExists([path26.join(cwd, ".cursor"), path26.join(cwd, ".cursorrules")]),
4878
- target: (cwd) => path26.join(cwd, ".cursor", "rules", "blazediff.mdc"),
4889
+ target: (cwd, skill) => path26.join(cwd, ".cursor", "rules", `${skill}.mdc`),
4879
4890
  format: "cursor-rule",
4880
4891
  scope: "project"
4881
4892
  },
@@ -4926,7 +4937,7 @@ function renderCursorRule(files) {
4926
4937
  const body = skillBodyOnly(skill).trim();
4927
4938
  const frontmatter = [
4928
4939
  "---",
4929
- 'description: "Run, author, or update BlazeDiff visual regression tests. Trigger on visual test, screenshot regression, blazediff, /blazediff."',
4940
+ `description: ${JSON.stringify(skillDescription(skill))}`,
4930
4941
  "alwaysApply: false",
4931
4942
  "---",
4932
4943
  ""
@@ -4966,30 +4977,36 @@ function combineStatuses(statuses) {
4966
4977
  if (statuses.some((s) => s === "updated")) return "updated";
4967
4978
  return "unchanged";
4968
4979
  }
4969
- async function installStack(stack, cwd, opts = {}) {
4970
- const info = STACKS[stack];
4971
- if (info.kind === "local-judge") {
4972
- return { stack, status: "configured" };
4973
- }
4974
- const target = info.target(cwd);
4975
- const files = loadSkillFiles();
4980
+ async function installSkill(stack, info, skill, cwd, force) {
4981
+ const target = info.target(cwd, skill);
4982
+ const files = loadSkillFiles(skill);
4976
4983
  if (info.format === "cursor-rule") {
4977
- const content = renderCursorRule(files);
4978
- const status = await writeIfChanged(target, content, opts.force);
4979
- return { stack, path: target, status };
4984
+ const status = await writeIfChanged(target, renderCursorRule(files), force);
4985
+ return { stack, skill, path: target, status };
4980
4986
  }
4981
4987
  const targetDir = path26.dirname(target);
4982
4988
  const statuses = [];
4983
4989
  for (const file of files) {
4984
- const filePath = path26.join(targetDir, file.name);
4985
- const status = await writeIfChanged(
4986
- filePath,
4987
- ensureTrailingNewline(file.content),
4988
- opts.force
4990
+ statuses.push(
4991
+ await writeIfChanged(
4992
+ path26.join(targetDir, file.name),
4993
+ ensureTrailingNewline(file.content),
4994
+ force
4995
+ )
4989
4996
  );
4990
- statuses.push(status);
4991
4997
  }
4992
- return { stack, path: target, status: combineStatuses(statuses) };
4998
+ return { stack, skill, path: target, status: combineStatuses(statuses) };
4999
+ }
5000
+ async function installStack(stack, cwd, opts = {}) {
5001
+ const info = STACKS[stack];
5002
+ if (info.kind === "local-judge") {
5003
+ return [{ stack, status: "configured" }];
5004
+ }
5005
+ const results = [];
5006
+ for (const skill of SKILLS) {
5007
+ results.push(await installSkill(stack, info, skill, cwd, opts.force));
5008
+ }
5009
+ return results;
4993
5010
  }
4994
5011
 
4995
5012
  // src/cli/commands/onboard.ts
@@ -4998,7 +5015,7 @@ async function promptForStacks() {
4998
5015
  ...CODING_AGENT_STACKS.map((id) => ({
4999
5016
  label: STACKS[id].label,
5000
5017
  value: [id],
5001
- hint: STACKS[id].target?.(process.cwd()) ?? ""
5018
+ hint: STACKS[id].target?.(process.cwd(), SKILLS[0]) ?? ""
5002
5019
  })),
5003
5020
  { label: "All three coding agents", value: [...CODING_AGENT_STACKS] },
5004
5021
  {
@@ -5092,7 +5109,7 @@ function humanizeInstall(results) {
5092
5109
  }
5093
5110
  const verb = r.status === "created" ? "wrote" : r.status === "updated" ? "updated" : r.status === "unchanged" ? "unchanged" : "skipped (exists; --force to overwrite)";
5094
5111
  const scope = info.scope === "user" ? " [user-global]" : "";
5095
- return ` ${info.label}: ${verb} ${r.path}${scope}`;
5112
+ return ` ${info.label} /${r.skill}: ${verb} ${r.path}${scope}`;
5096
5113
  });
5097
5114
  }
5098
5115
  function registerOnboard(program, out) {
@@ -5157,7 +5174,7 @@ function registerOnboard(program, out) {
5157
5174
  const targets = await resolveStacks(opts, interactive);
5158
5175
  const installed = [];
5159
5176
  for (const t of targets) {
5160
- installed.push(await installStack(t, cwd, { force: opts.force }));
5177
+ installed.push(...await installStack(t, cwd, { force: opts.force }));
5161
5178
  }
5162
5179
  let judge = config?.judge ?? "host";
5163
5180
  if (targets.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazediff/agent",
3
- "version": "0.10.1",
3
+ "version": "0.11.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": {
@@ -21,9 +21,7 @@
21
21
  },
22
22
  "files": [
23
23
  "dist",
24
- "SKILL.md",
25
- "JUDGING.md",
26
- "MASKING.md"
24
+ "skills"
27
25
  ],
28
26
  "keywords": [
29
27
  "visual-regression",
@@ -49,7 +47,7 @@
49
47
  "tree-kill": "^1.2.2",
50
48
  "zod": "^3.25.32",
51
49
  "@blazediff/core-native": "6.0.0",
52
- "@blazediff/interpret-native": "6.1.0"
50
+ "@blazediff/interpret-native": "6.2.0"
53
51
  },
54
52
  "peerDependencies": {
55
53
  "@huggingface/transformers": "^4.2.0"
@@ -74,11 +72,11 @@
74
72
  },
75
73
  "scripts": {
76
74
  "typecheck": "tsc --noEmit",
77
- "prebuild": "node -e \"const {readdirSync,copyFileSync}=require('node:fs');for(const f of readdirSync('../../skill/blazediff'))if(f.endsWith('.md')&&f!=='INSTALL.md')copyFileSync('../../skill/blazediff/'+f,f)\"",
75
+ "prebuild": "node scripts/copy-skills.mjs",
78
76
  "build": "tsup && vite build",
79
77
  "dev": "tsup --watch",
80
78
  "dev:client": "vite",
81
- "clean": "rm -rf dist SKILL.md JUDGING.md MASKING.md",
79
+ "clean": "rm -rf dist skills",
82
80
  "test": "vitest run --passWithNoTests"
83
81
  }
84
82
  }
@@ -7,6 +7,8 @@ description: Run, author, or update BlazeDiff visual regression tests. Trigger o
7
7
 
8
8
  CLI binary is `blazediff-agent` (the name `blazediff` belongs to the cargo image-diff binary).
9
9
 
10
+ **Not this skill:** comparing two image files already on disk ("what changed between these two PNGs", "did this render drift") → use the `image-compare` skill. This skill is for capturing a running app and managing baselines; it owns `.blazediff/`.
11
+
10
12
  Sibling files in this skill directory — read on demand:
11
13
  - `JUDGING.md` — judging ambiguous diffs (`pendingJudgments > 0`) + zsh-safe shell loops for writing verdicts.
12
14
  - `MASKING.md` — picking selectors, mass-masking shared noise across routes, applying masks.
@@ -0,0 +1,183 @@
1
+ ---
2
+ name: image-compare
3
+ description: Compare two image files on disk and report what changed, region by region. Trigger on "what changed between these two images", "diff these PNGs", "did this render drift", "compare screenshots/exports/renders".
4
+ ---
5
+
6
+ # image-compare
7
+
8
+ Two image files in, a verdict out. No baselines, no manifest, no browser.
9
+
10
+ CLI binary is `blazediff-cli` (`npm i -g @blazediff/cli`).
11
+
12
+ **Not this skill:** capturing a running app, managing baselines, or re-running a
13
+ visual regression suite → use the `blazediff` skill instead (it owns
14
+ `.blazediff/`, `blazediff-agent`, and the check/rewrite loop). If the working
15
+ directory has a `.blazediff/manifest.json` and the user is asking about *routes*
16
+ rather than *files*, you are in the wrong skill.
17
+
18
+ ## Be terse
19
+ - Pass `--json` on every call; parse fields. Do not echo CLI output.
20
+ - Never send whole images to a model when `interpret` has located the regions —
21
+ see **Send crops, not pages** below. This is the point of the skill.
22
+ - One final summary line: `N regions | <severity> | <one-clause verdict>`.
23
+
24
+ ## Pick the command by the question
25
+
26
+ | The user is asking | Command | Read from it |
27
+ |---|---|---|
28
+ | "what changed?" / "describe the differences" | `interpret` | `regions[]` — bbox, changeType, position |
29
+ | "are these identical?" | `core-native` | `different pixels` (0 = byte-identical after decode) |
30
+ | "how different, perceptually?" | `ssim` | SSIM score, 1.0 = identical |
31
+ | "did quality degrade?" (compression, resize, generative output) | `msssim` | multi-scale score, 1.0 = identical |
32
+ | "where are the structural differences?" | `gmsd -o map.png` | deviation, **0.0 = identical** |
33
+
34
+ `interpret` is the default. The others answer *how much*; only `interpret`
35
+ answers *what*.
36
+
37
+ ```
38
+ blazediff-cli interpret a.png b.png --json
39
+ ```
40
+
41
+ Exit codes: `0` no regions, `1` regions found, `2` error. Safe to branch on.
42
+
43
+ ### Picking `--source`
44
+ - `pixel` (default) — pixel-aligned renders: screenshots, PNG exports, chart
45
+ renders, PDF rasterizations. Anything produced twice by the same renderer.
46
+ - `ms-ssim` / `ssim` — images with resampling or compression noise: JPEGs,
47
+ camera captures, generative-model output, anything that went through a
48
+ lossy round-trip. Per-pixel deltas are everywhere in these, so `pixel`
49
+ returns one giant region; the metric sources threshold a similarity map
50
+ instead. Their boxes are coarser (map-grid resolution), but the pixel counts
51
+ inside them are still exact.
52
+
53
+ Add `-a` when the pair is text-heavy and the only differences are antialiasing
54
+ fringes. Raise `-t` (default 0.1) when the renderer has known per-run jitter.
55
+
56
+ ## Reading the result
57
+
58
+ ```jsonc
59
+ {
60
+ "summary": "Moderate visual change detected (1.87% of image, 4 regions).",
61
+ "severity": "medium", // low | medium | high
62
+ "diffCount": 30421, // changed pixels
63
+ "diffPercentage": 1.87,
64
+ "totalRegions": 4,
65
+ "width": 1328, "height": 1228,
66
+ "regions": [{ "bbox": {...}, "changeType": "...", "position": "...", "shape": "...",
67
+ "pixelCount": 0, "percentage": 0, "confidence": 0 /* + stats blocks */ }]
68
+ }
69
+ ```
70
+
71
+ `changeType` — `addition`, `deletion`, `content-change`, `color-change`,
72
+ `shift`, `rendering-noise`.
73
+ `position` — `top-left`…`bottom-right`, `top`/`bottom`/`left`/`right`/`center`.
74
+ `shape` — `solid-region`, `mixed-region`, `contour-frame`, `sparse-distributed`,
75
+ `edge-dominated`.
76
+
77
+ Each region also carries `chroma`, `colorDelta`, `gradient`, `shapeStats`, and
78
+ `signals` blocks. **Do not put these in your context or forward them to a
79
+ model** — they are classifier inputs, not answers. Project each region down to
80
+ `{changeType, position, bbox, percentage}` before you reason about it. The full
81
+ JSON for a 4-region diff is ~7.5 KB; the projection is ~200 tokens.
82
+
83
+ Interpreting `changeType`:
84
+ - `rendering-noise` — subpixel/antialiasing jitter. Report as "no meaningful
85
+ change" unless the user is specifically hunting rendering differences.
86
+ - `color-change` with `signals.lowColorDelta` and `gradient.edgeCorrelation`
87
+ near 1.0 — same content, recoloured. Theme change, not content change.
88
+ - `shift` — content moved, not edited. Say what moved and by roughly how much;
89
+ don't describe it as added and removed.
90
+ - `addition` / `deletion` / `content-change` — genuine content differences.
91
+ These are the ones worth cropping and reading.
92
+
93
+ ## Send crops, not pages
94
+
95
+ When the user wants each change *described* (not just located), crop the
96
+ regions and send only those. Never send the two full images.
97
+
98
+ Two reasons, and the second matters more than the first:
99
+
100
+ 1. **Cost.** A pair of full-page screenshots is thousands of visual tokens, and
101
+ nearly all of them show pixels that are identical in both images.
102
+ 2. **Legibility.** Claude downscales any image that exceeds the model's limits.
103
+ A full-page screenshot gets crushed by ~6×, which destroys the exact detail
104
+ you are trying to compare — and images over 8000 px on an edge are rejected
105
+ outright.
106
+
107
+ Measured on this repo's fixtures (Claude Opus 5, high-resolution tier:
108
+ 2576 px max edge, 4784 max visual tokens; cost is `⌈w/28⌉ × ⌈h/28⌉` per image):
109
+
110
+ | | **A**: `fixtures/page` — 3598×16384 page, 2 regions, 0.09% px | **B**: `fixtures/blazediff/3` — 1328×1228, 4 regions, 1.87% px |
111
+ |---|---|---|
112
+ | Both full images, as-is | **rejected** — 16384 px exceeds the 8000 px limit | 2112 ×2 = **4224** tokens |
113
+ | Both pre-resized to fit | 566×2576 → 1932 ×2 = **3864** tokens — but the 711×104 changed region is now **112×16 px**, and the 212×42 one is **33×7 px**. Unreadable. | n/a, already fits |
114
+ | Crops + projected region JSON | 408 + ~128 = **536** | 1178 + ~206 = **1384** |
115
+ | | **7.2× cheaper, at native resolution** | **3.1× cheaper (−67%)** |
116
+
117
+ The saving scales with how little of the image changed, which for real diffs is
118
+ almost always "very little". Case A changed 0.09% of its pixels; sending both
119
+ pages would have spent ~99.9% of the budget on identical content.
120
+
121
+ ### The crop step
122
+
123
+ Pad each bbox by 32 px so the change has surrounding context, clamp to the image
124
+ bounds, and crop the **same box from both images** — the pair only reads as a
125
+ before/after if the framing is identical.
126
+
127
+ ```bash
128
+ # one region, both sides. x/y/w/h come from regions[i].bbox, padded and clamped.
129
+ node -e '
130
+ const sharp = require("sharp"), [src, out, x, y, w, h] = process.argv.slice(1);
131
+ sharp(src).extract({left:+x, top:+y, width:+w, height:+h}).toFile(out);
132
+ ' "$SRC" "$OUT" "$X" "$Y" "$W" "$H"
133
+ ```
134
+
135
+ `sharp` ships with `@blazediff/cli` via `@blazediff/codec-sharp`. If it does not
136
+ resolve (global install, no local `node_modules`), fall back to `sips -c` on
137
+ macOS or `magick crop` where ImageMagick is present.
138
+
139
+ Then send, per region, in one message: the region's projected JSON, its before
140
+ crop, its after crop. Label them — `Region 1 (content-change, bottom): before /
141
+ after` — so follow-up questions can name a region without resending anything.
142
+
143
+ ### When not to crop
144
+
145
+ Send the full (resized) pair instead when any of these hold:
146
+
147
+ - `totalRegions` is 0 — nothing to crop; answer from the metric score.
148
+ - The regions cover most of the frame (`diffPercentage` above ~25%, or one
149
+ region spanning most of the bbox area). A full-frame rewrite is best read
150
+ whole.
151
+ - Summed crop tokens exceed the full-pair cost. With many small scattered
152
+ regions, per-crop 28-px padding overhead adds up — compute both, pick the
153
+ smaller.
154
+ - The question is about *layout* or *global composition* rather than local
155
+ content. Crops destroy spatial relationships between regions.
156
+
157
+ ## Answering
158
+
159
+ Lead with the verdict, then the regions, in the user's terms:
160
+
161
+ ```
162
+ 4 regions changed (medium).
163
+ 1. content-change, bottom (590×479 at 356,651) — <what the crops show>
164
+ 2. addition, right (95×154 at 992,614) — <what the crops show>
165
+ ...
166
+ ```
167
+
168
+ If every region is `rendering-noise`, say the images are visually equivalent and
169
+ give the SSIM score as backing. Don't manufacture a difference to report.
170
+
171
+ ## Failure modes
172
+
173
+ - **Different dimensions** — `interpret` requires matching sizes. Say so and
174
+ ask whether to resize or compare a common crop; don't silently resize, since
175
+ that changes what "different" means.
176
+ - **`pixel` returns one region covering everything** — the pair has resampling
177
+ or compression noise. Re-run with `--source ms-ssim`.
178
+ - **Huge `diffCount` but the images look the same** — check for an alpha or
179
+ colour-profile difference; compare with `ssim` (structure-only) to confirm.
180
+ - **`gmsd` output labels are inverted** — the CLI prints
181
+ `(0=different, 1=identical)` and a `similarity: N%` line, but GMSD is a
182
+ *deviation*: identical images score `0.000000`. Read the number as distance,
183
+ and ignore the printed label.
File without changes
File without changes