@mizchi/vlmkit-core 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/heatmap.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { VrtDiff, VrtSnapshot, DiffRegion, DiffRegionType, DiffReport, ShiftRegion } from "./types.ts";
1
+ import type { VrtDiff, VrtSnapshot, DiffRegion, DiffRegionType, DiffReport, ShiftRegion, DiffRegionColor, DiffRegionColorSample, DiffRegionColorPair } from "./types.ts";
2
2
  import { type PngData, cropImage, decodePng, encodePng } from "./png-utils.ts";
3
+ import { estimateRegionShift } from "./region-shift.ts";
3
4
 
4
5
  // ---- Shared diff pipeline ----
5
6
 
@@ -75,6 +76,8 @@ export async function compareScreenshots(
75
76
 
76
77
  const r = await runPixelDiff(snapshot.baselinePath, snapshot.screenshotPath, snapshot.testId, opts);
77
78
  const regions = detectDiffRegions(r.diffOutput, r.width, r.height);
79
+ attachRegionColorSamples(regions, r.resizedBaseline, r.resizedCurrent);
80
+ attachRegionShiftEstimates(regions, r.resizedBaseline, r.resizedCurrent);
78
81
 
79
82
  return {
80
83
  snapshot,
@@ -176,6 +179,157 @@ function detectDiffRegions(
176
179
  return regions;
177
180
  }
178
181
 
182
+ function attachRegionColorSamples(
183
+ regions: DiffRegion[],
184
+ baseline: PngData,
185
+ current: PngData,
186
+ ): void {
187
+ for (const region of regions) {
188
+ const sample = sampleRegionColorSample(baseline, current, region);
189
+ if (sample) region.colorSample = sample;
190
+ }
191
+ }
192
+
193
+ function attachRegionShiftEstimates(
194
+ regions: DiffRegion[],
195
+ baseline: PngData,
196
+ current: PngData,
197
+ ): void {
198
+ for (const region of regions) {
199
+ if (region.regionType === "edge") continue;
200
+ const shift = estimateRegionShift(baseline, current, region);
201
+ if (shift) region.shift = shift;
202
+ }
203
+ }
204
+
205
+ /** Fraction of a region's opaque pixels below which the change counts as
206
+ * "sparse" (thin glyphs, a minority recolor) and a peak pixel is worth
207
+ * surfacing alongside the mean. */
208
+ const SPARSE_CHANGE_RATIO = 0.5;
209
+ /** Per-channel mean delta above which a pixel counts as actually changed,
210
+ * matching `diff region`'s sampleBboxColorPair gate. */
211
+ const CHANGED_PIXEL_DELTA = 1;
212
+
213
+ interface ColorAccumulator {
214
+ br: number;
215
+ bg: number;
216
+ bb: number;
217
+ cr: number;
218
+ cg: number;
219
+ cb: number;
220
+ n: number;
221
+ }
222
+
223
+ function makeColorAccumulator(): ColorAccumulator {
224
+ return { br: 0, bg: 0, bb: 0, cr: 0, cg: 0, cb: 0, n: 0 };
225
+ }
226
+
227
+ function meanPair(acc: ColorAccumulator): DiffRegionColorPair {
228
+ const baseline = roundColor(acc.br / acc.n, acc.bg / acc.n, acc.bb / acc.n);
229
+ const current = roundColor(acc.cr / acc.n, acc.cg / acc.n, acc.cb / acc.n);
230
+ return { baseline, current, distance: Math.round(rgbDistance(baseline, current)) };
231
+ }
232
+
233
+ function roundColor(r: number, g: number, b: number): DiffRegionColor {
234
+ const ri = Math.round(r);
235
+ const gi = Math.round(g);
236
+ const bi = Math.round(b);
237
+ return { r: ri, g: gi, b: bi, hex: toHex(ri, gi, bi) };
238
+ }
239
+
240
+ /**
241
+ * Sample a region's color pair from the pixels that actually differ.
242
+ *
243
+ * A region-wide median (the old behaviour) reflects the unchanged majority
244
+ * and reads as "no change" on exactly the regions that changed in a minority
245
+ * of their pixels — e.g. a dark background recolor hidden behind dominant
246
+ * white form inputs (A/B v3 draft 10). We accumulate only pixels whose
247
+ * baseline↔current per-channel delta clears CHANGED_PIXEL_DELTA, falling back
248
+ * to every opaque pixel when nothing clears the gate.
249
+ *
250
+ * When the changed pixels are sparse, the mean is still dominated by
251
+ * antialiasing blends, so we additionally surface the single highest-delta
252
+ * pixel pair as `peak` (draft 11).
253
+ */
254
+ export function sampleRegionColorSample(
255
+ baseline: PngData,
256
+ current: PngData,
257
+ region: { x: number; y: number; width: number; height: number },
258
+ ): DiffRegionColorSample | undefined {
259
+ const left = Math.max(0, region.x);
260
+ const top = Math.max(0, region.y);
261
+ const right = Math.min(baseline.width, current.width, region.x + region.width);
262
+ const bottom = Math.min(baseline.height, current.height, region.y + region.height);
263
+ if (right <= left || bottom <= top) return undefined;
264
+
265
+ const all = makeColorAccumulator();
266
+ const changed = makeColorAccumulator();
267
+ let peakDelta = -1;
268
+ let peakBaseline: DiffRegionColor | undefined;
269
+ let peakCurrent: DiffRegionColor | undefined;
270
+
271
+ for (let y = top; y < bottom; y++) {
272
+ for (let x = left; x < right; x++) {
273
+ const bi = (y * baseline.width + x) * 4;
274
+ const ci = (y * current.width + x) * 4;
275
+ if (baseline.data[bi + 3]! === 0 || current.data[ci + 3]! === 0) continue;
276
+ const br = baseline.data[bi]!;
277
+ const bg = baseline.data[bi + 1]!;
278
+ const bb = baseline.data[bi + 2]!;
279
+ const cr = current.data[ci]!;
280
+ const cg = current.data[ci + 1]!;
281
+ const cb = current.data[ci + 2]!;
282
+ all.br += br; all.bg += bg; all.bb += bb;
283
+ all.cr += cr; all.cg += cg; all.cb += cb;
284
+ all.n++;
285
+
286
+ const delta = (Math.abs(br - cr) + Math.abs(bg - cg) + Math.abs(bb - cb)) / 3;
287
+ if (delta > CHANGED_PIXEL_DELTA) {
288
+ changed.br += br; changed.bg += bg; changed.bb += bb;
289
+ changed.cr += cr; changed.cg += cg; changed.cb += cb;
290
+ changed.n++;
291
+ if (delta > peakDelta) {
292
+ peakDelta = delta;
293
+ peakBaseline = { r: br, g: bg, b: bb, hex: toHex(br, bg, bb) };
294
+ peakCurrent = { r: cr, g: cg, b: cb, hex: toHex(cr, cg, cb) };
295
+ }
296
+ }
297
+ }
298
+ }
299
+
300
+ if (all.n === 0) return undefined;
301
+
302
+ const source = changed.n > 0 ? changed : all;
303
+ const sample: DiffRegionColorSample = meanPair(source);
304
+
305
+ // The peak only adds signal when the mean is unreliable — i.e. the change
306
+ // is sparse and the peak names a different color than the averaged-out mean.
307
+ if (
308
+ changed.n > 0
309
+ && peakBaseline
310
+ && peakCurrent
311
+ && changed.n < all.n * SPARSE_CHANGE_RATIO
312
+ && (peakBaseline.hex !== sample.baseline.hex || peakCurrent.hex !== sample.current.hex)
313
+ ) {
314
+ sample.peak = {
315
+ baseline: peakBaseline,
316
+ current: peakCurrent,
317
+ distance: Math.round(rgbDistance(peakBaseline, peakCurrent)),
318
+ };
319
+ }
320
+
321
+ return sample;
322
+ }
323
+
324
+ function toHex(r: number, g: number, b: number): string {
325
+ const hex = (value: number) => value.toString(16).padStart(2, "0");
326
+ return `#${hex(r)}${hex(g)}${hex(b)}`;
327
+ }
328
+
329
+ function rgbDistance(a: DiffRegionColor, b: DiffRegionColor): number {
330
+ return Math.sqrt((a.r - b.r) ** 2 + (a.g - b.g) ** 2 + (a.b - b.b) ** 2);
331
+ }
332
+
179
333
  /**
180
334
  * Classify a diff region based on its shape relative to the image width.
181
335
  * - "edge": thin lines (height <= 2 or width <= 2)
@@ -77,7 +77,7 @@ export function resizePngBuffer(pngBuffer: Buffer, options: ResizeOptions = {}):
77
77
  }
78
78
 
79
79
  /** Read dimensions from PNG IHDR chunk (no full decode needed) */
80
- function readPngDimensions(buf: Buffer): { width: number; height: number } {
80
+ export function readPngDimensions(buf: Buffer): { width: number; height: number } {
81
81
  // PNG header: 8-byte signature, then IHDR chunk: 4-byte length, 4-byte type, 4-byte width, 4-byte height
82
82
  if (buf.length >= 24 && buf[0] === 0x89 && buf[1] === 0x50) {
83
83
  return { width: buf.readUInt32BE(16), height: buf.readUInt32BE(20) };
package/src/index.ts CHANGED
@@ -44,15 +44,12 @@ export {
44
44
  detectWhiteout,
45
45
  detectEmptyContent,
46
46
  } from "./heatmap.ts";
47
- export { runPngDiff } from "./png-diff.ts";
48
47
  export { findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba } from "./heatmap-regions.ts";
49
48
  export {
50
49
  createScopedVrtDiff,
51
50
  normalizeVrtDiffRegions,
52
51
  normalizeVrtDiffRegionPixels,
53
52
  } from "./diff-regions.ts";
54
- export { classifyRegion } from "./region-classify.ts";
55
- export { findShiftOrigins } from "./shift-origin.ts";
56
53
 
57
54
  // ---- Layout / typography ----
58
55
  export {
@@ -62,7 +59,6 @@ export {
62
59
  compareRowTypography,
63
60
  computeRowGapDeltas,
64
61
  } from "./text-rows.ts";
65
- export { findGridSuggestions } from "./grid-ratio.ts";
66
62
 
67
63
  // ---- PNG IO ----
68
64
  export {
@@ -87,6 +83,10 @@ export {
87
83
  diffPositionStylesAcrossViewports,
88
84
  } from "./dom-position-styles.ts";
89
85
  export { diffComputedStyles } from "./computed-style-diff.ts";
86
+ export {
87
+ diffAuthoredStyles,
88
+ aggregateAuthoredStyleByViewport,
89
+ } from "./authored-style-diff.ts";
90
90
 
91
91
  // ---- A11y diff ----
92
92
  export {
@@ -99,10 +99,7 @@ export {
99
99
  LANDMARK_ROLES,
100
100
  } from "./a11y-semantic.ts";
101
101
 
102
- // ---- Semantic / quality ----
103
- export { classifyVisualDiff } from "./visual-semantic.ts";
104
- export { runQualityChecks } from "./quality.ts";
105
-
106
102
  // ---- Public config constants ----
107
103
  export { RESOLUTION_PRESETS } from "./image-resize.ts";
108
104
  export { TRACKED_PROPERTIES } from "./computed-style-capture.ts";
105
+ export { AUTHORED_PROPERTIES } from "./authored-style-capture.ts";
package/src/png-utils.ts CHANGED
@@ -27,6 +27,36 @@ export function cropImage(img: PngData, w: number, h: number): PngData {
27
27
  return { width: w, height: h, data };
28
28
  }
29
29
 
30
+ /**
31
+ * Crop an arbitrary rectangle out of an image.
32
+ *
33
+ * Unlike {@link cropImage} (which only clips the top-left common region),
34
+ * this extracts a region at an arbitrary (x, y) offset. The rectangle is
35
+ * clamped to the image bounds, so the returned crop may be smaller than
36
+ * requested when the region overruns an edge (or off the top-left).
37
+ */
38
+ export function cropRegion(
39
+ img: PngData,
40
+ x: number,
41
+ y: number,
42
+ w: number,
43
+ h: number,
44
+ ): PngData {
45
+ const x0 = Math.max(0, Math.min(Math.floor(x), img.width));
46
+ const y0 = Math.max(0, Math.min(Math.floor(y), img.height));
47
+ const x1 = Math.max(x0, Math.min(Math.floor(x + w), img.width));
48
+ const y1 = Math.max(y0, Math.min(Math.floor(y + h), img.height));
49
+ const cw = x1 - x0;
50
+ const ch = y1 - y0;
51
+ const data = new Uint8Array(cw * ch * 4);
52
+ for (let row = 0; row < ch; row++) {
53
+ const srcOffset = ((y0 + row) * img.width + x0) * 4;
54
+ const dstOffset = row * cw * 4;
55
+ data.set(img.data.subarray(srcOffset, srcOffset + cw * 4), dstOffset);
56
+ }
57
+ return { width: cw, height: ch, data };
58
+ }
59
+
30
60
  /**
31
61
  * Read a PNG file and return RGBA pixel data.
32
62
  */
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Per-region translation detection.
3
+ *
4
+ * Both A/B validation runs (2026-06-05 / 06-06) showed agents
5
+ * misreading position shifts as color changes: the diff region for a
6
+ * moved element samples near-identical colors on both sides
7
+ * ("#ffffff -> #ffffff") and the semantic classifier falls back to
8
+ * `element-added`. This module estimates whether a diff region is
9
+ * better explained by a translation, using mean-subtracted normalized
10
+ * cross-correlation of luminance profiles per axis — the same idea as
11
+ * `detectBandShifts`, applied to a single region.
12
+ */
13
+ import type { PngData } from "./png-utils.ts";
14
+
15
+ export interface RegionShiftEstimate {
16
+ /** Content moved by +dx px horizontally in current (vs baseline). */
17
+ dx: number;
18
+ /** Content moved by +dy px vertically in current (vs baseline). */
19
+ dy: number;
20
+ /** 0..1; correlation peak strength of the dominant axis. */
21
+ confidence: number;
22
+ }
23
+
24
+ interface RegionRect {
25
+ x: number;
26
+ y: number;
27
+ width: number;
28
+ height: number;
29
+ }
30
+
31
+ const MIN_REGION_EDGE = 8;
32
+ const MIN_PEAK = 0.6;
33
+ /** The shifted-lag peak must beat the zero-lag correlation by this much. */
34
+ const MIN_PEAK_ADVANTAGE = 0.15;
35
+
36
+ export function estimateRegionShift(
37
+ baseline: PngData,
38
+ current: PngData,
39
+ region: RegionRect,
40
+ maxOffset = 64,
41
+ ): RegionShiftEstimate | null {
42
+ if (region.width < MIN_REGION_EDGE || region.height < MIN_REGION_EDGE) return null;
43
+ const width = Math.min(baseline.width, current.width);
44
+ const height = Math.min(baseline.height, current.height);
45
+
46
+ const x0 = clamp(region.x - maxOffset, 0, width);
47
+ const x1 = clamp(region.x + region.width + maxOffset, 0, width);
48
+ const y0 = clamp(region.y, 0, height);
49
+ const y1 = clamp(region.y + region.height, 0, height);
50
+ const yw0 = clamp(region.y - maxOffset, 0, height);
51
+ const yw1 = clamp(region.y + region.height + maxOffset, 0, height);
52
+ const xr0 = clamp(region.x, 0, width);
53
+ const xr1 = clamp(region.x + region.width, 0, width);
54
+ if (x1 <= x0 || y1 <= y0 || yw1 <= yw0 || xr1 <= xr0) return null;
55
+
56
+ const horizontal = bestLag(
57
+ columnProfile(baseline, x0, x1, y0, y1),
58
+ columnProfile(current, x0, x1, y0, y1),
59
+ maxOffset,
60
+ );
61
+ const vertical = bestLag(
62
+ rowProfile(baseline, xr0, xr1, yw0, yw1),
63
+ rowProfile(current, xr0, xr1, yw0, yw1),
64
+ maxOffset,
65
+ );
66
+
67
+ const dx = acceptAxis(horizontal) ? horizontal.lag : 0;
68
+ const dy = acceptAxis(vertical) ? vertical.lag : 0;
69
+ if (dx === 0 && dy === 0) return null;
70
+
71
+ const confidences: number[] = [];
72
+ if (dx !== 0) confidences.push(horizontal.peak);
73
+ if (dy !== 0) confidences.push(vertical.peak);
74
+ return {
75
+ dx,
76
+ dy,
77
+ confidence: Number(Math.max(...confidences).toFixed(3)),
78
+ };
79
+ }
80
+
81
+ interface LagResult {
82
+ lag: number;
83
+ peak: number;
84
+ zeroLag: number;
85
+ flat: boolean;
86
+ }
87
+
88
+ function acceptAxis(result: LagResult): boolean {
89
+ return !result.flat
90
+ && result.lag !== 0
91
+ && result.peak >= MIN_PEAK
92
+ && result.peak - result.zeroLag >= MIN_PEAK_ADVANTAGE;
93
+ }
94
+
95
+ /**
96
+ * Find the lag maximizing normalized cross-correlation between two
97
+ * mean-subtracted profiles. Positive lag = current content sits at a
98
+ * higher coordinate than baseline (moved right / down).
99
+ */
100
+ function bestLag(base: Float64Array, curr: Float64Array, maxOffset: number): LagResult {
101
+ const a = meanSubtract(base);
102
+ const b = meanSubtract(curr);
103
+ if (a.flat || b.flat) return { lag: 0, peak: 0, zeroLag: 0, flat: true };
104
+
105
+ let bestLag = 0;
106
+ let bestVal = -Infinity;
107
+ let zeroVal = 0;
108
+ const n = Math.min(a.values.length, b.values.length);
109
+ const limit = Math.min(maxOffset, n - 1);
110
+ for (let lag = -limit; lag <= limit; lag++) {
111
+ let dot = 0;
112
+ let normA = 0;
113
+ let normB = 0;
114
+ for (let i = 0; i < n; i++) {
115
+ const j = i + lag;
116
+ if (j < 0 || j >= n) continue;
117
+ dot += a.values[i]! * b.values[j]!;
118
+ normA += a.values[i]! * a.values[i]!;
119
+ normB += b.values[j]! * b.values[j]!;
120
+ }
121
+ if (normA === 0 || normB === 0) continue;
122
+ const val = dot / Math.sqrt(normA * normB);
123
+ if (lag === 0) zeroVal = val;
124
+ if (val > bestVal) {
125
+ bestVal = val;
126
+ bestLag = lag;
127
+ }
128
+ }
129
+ if (!Number.isFinite(bestVal)) return { lag: 0, peak: 0, zeroLag: 0, flat: true };
130
+ return { lag: bestLag, peak: bestVal, zeroLag: zeroVal, flat: false };
131
+ }
132
+
133
+ function meanSubtract(profile: Float64Array): { values: Float64Array; flat: boolean } {
134
+ let sum = 0;
135
+ for (const v of profile) sum += v;
136
+ const mean = sum / profile.length;
137
+ const values = new Float64Array(profile.length);
138
+ let variance = 0;
139
+ for (let i = 0; i < profile.length; i++) {
140
+ values[i] = profile[i]! - mean;
141
+ variance += values[i]! * values[i]!;
142
+ }
143
+ return { values, flat: variance / profile.length < 1 };
144
+ }
145
+
146
+ function columnProfile(img: PngData, x0: number, x1: number, y0: number, y1: number): Float64Array {
147
+ const profile = new Float64Array(x1 - x0);
148
+ for (let x = x0; x < x1; x++) {
149
+ let sum = 0;
150
+ for (let y = y0; y < y1; y++) sum += lumaAt(img, x, y);
151
+ profile[x - x0] = sum / (y1 - y0);
152
+ }
153
+ return profile;
154
+ }
155
+
156
+ function rowProfile(img: PngData, x0: number, x1: number, y0: number, y1: number): Float64Array {
157
+ const profile = new Float64Array(y1 - y0);
158
+ for (let y = y0; y < y1; y++) {
159
+ let sum = 0;
160
+ for (let x = x0; x < x1; x++) sum += lumaAt(img, x, y);
161
+ profile[y - y0] = sum / (x1 - x0);
162
+ }
163
+ return profile;
164
+ }
165
+
166
+ function lumaAt(img: PngData, x: number, y: number): number {
167
+ const i = (y * img.width + x) * 4;
168
+ return 0.299 * img.data[i]! + 0.587 * img.data[i + 1]! + 0.114 * img.data[i + 2]!;
169
+ }
170
+
171
+ function clamp(value: number, min: number, max: number): number {
172
+ return Math.max(min, Math.min(max, value));
173
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Append-only run ledger for agent-loop tools.
3
+ *
4
+ * Every measurement invocation (`build page`, the dynamic gates,
5
+ * `verify markup`) appends one JSONL line to `.vlmkit/run-ledger.jsonl`
6
+ * under the working directory. This turns the "rounds" KPI from an agent
7
+ * self-report into an auditable record: a verifier can check that the
8
+ * agent actually re-measured after each fix, and how the headline numbers
9
+ * moved round by round (see docs/knowledge.md "Markup Agent KPI" — round
10
+ * counts were self-reported and unreliable in 5/5 S5 runs).
11
+ *
12
+ * Writes are best-effort: a ledger failure must never break the tool run.
13
+ * Opt out with VLMKIT_NO_LEDGER=1 (e.g. CI bulk runs).
14
+ */
15
+ import { appendFileSync, mkdirSync } from "node:fs";
16
+ import { join } from "node:path";
17
+
18
+ export interface RunLedgerEntry {
19
+ /** Tool name, e.g. "build-page", "check-breakpoints", "verify-markup". */
20
+ tool: string;
21
+ /** Primary input (attempt HTML or URL). */
22
+ source: string;
23
+ /** Secondary input (target PNG, manifest, ...) when applicable. */
24
+ target?: string;
25
+ /** Headline numbers, tool-specific but flat (matched/missing/extra/status/diffRatio...). */
26
+ headline: Record<string, string | number | boolean | null>;
27
+ }
28
+
29
+ export function appendRunLedger(entry: RunLedgerEntry, cwd = process.cwd()): void {
30
+ if (process.env.VLMKIT_NO_LEDGER === "1") return;
31
+ try {
32
+ const dir = join(cwd, ".vlmkit");
33
+ mkdirSync(dir, { recursive: true });
34
+ const line = JSON.stringify({ ts: new Date().toISOString(), ...entry });
35
+ appendFileSync(join(dir, "run-ledger.jsonl"), line + "\n");
36
+ } catch {
37
+ // Best-effort by design.
38
+ }
39
+ }
package/src/text-rows.ts CHANGED
@@ -21,6 +21,8 @@ import { PNG } from "pngjs";
21
21
  import { readFile } from "node:fs/promises";
22
22
 
23
23
  export interface TextRow {
24
+ /** Optional OCR/debug text when a caller can supply it. Pixel extraction does not infer this. */
25
+ text?: string;
24
26
  /** Y-coordinate of the row's vertical center. */
25
27
  yCenter: number;
26
28
  /** Top y of the run of dark rows (inclusive). */
package/src/types.ts CHANGED
@@ -78,6 +78,53 @@ export interface DiffRegion {
78
78
  height: number;
79
79
  diffPixelCount: number;
80
80
  regionType?: DiffRegionType;
81
+ colorSample?: DiffRegionColorSample;
82
+ /** Translation estimate when the region is better explained by movement than recolor. */
83
+ shift?: DiffRegionShift;
84
+ /** Deterministic DOM hit-test result for this region's bbox (diff png --elements-*). */
85
+ selectorCandidate?: DiffRegionSelectorCandidate;
86
+ }
87
+
88
+ export interface DiffRegionShift {
89
+ /** Content moved by +dx px horizontally in current (vs baseline). */
90
+ dx: number;
91
+ /** Content moved by +dy px vertically in current (vs baseline). */
92
+ dy: number;
93
+ confidence: number;
94
+ }
95
+
96
+ export interface DiffRegionSelectorCandidate {
97
+ selector: string;
98
+ confidence: "high" | "medium" | "low";
99
+ path: string;
100
+ tag: string;
101
+ regionCoverage: number;
102
+ elementCoverage: number;
103
+ }
104
+
105
+ export interface DiffRegionColor {
106
+ r: number;
107
+ g: number;
108
+ b: number;
109
+ hex: string;
110
+ }
111
+
112
+ export interface DiffRegionColorPair {
113
+ baseline: DiffRegionColor;
114
+ current: DiffRegionColor;
115
+ /** Euclidean RGB distance between baseline and current. */
116
+ distance: number;
117
+ }
118
+
119
+ export interface DiffRegionColorSample extends DiffRegionColorPair {
120
+ /**
121
+ * The single differing pixel with the largest baseline↔current channel
122
+ * delta, attached when the differing pixels are sparse (thin glyphs, a
123
+ * minority background recolor). The region mean is dominated by
124
+ * antialiasing blends or the unchanged majority; this peak approximates
125
+ * the glyph / edge core color the mean blurs away (A/B v3 draft 11).
126
+ */
127
+ peak?: DiffRegionColorPair;
81
128
  }
82
129
 
83
130
  export interface ShiftRegion {
@@ -231,6 +278,10 @@ export type SpecCheckType =
231
278
  | "no-error-state"
232
279
  | "text-visible"
233
280
  | "element-count"
281
+ | "heading-hierarchy"
282
+ | "aria-relationships"
283
+ | "color-contrast"
284
+ | "responsive-layout"
234
285
  | "nl-assertion";
235
286
 
236
287
  // ---- Introspect Output ----
@@ -255,6 +306,10 @@ export interface PageIntrospection {
255
306
  interactiveCount: number;
256
307
  unlabeledCount: number;
257
308
  headingLevels: number[];
309
+ contrastSampleCount?: number;
310
+ contrastFailureCount?: number;
311
+ responsiveSnapshotCount?: number;
312
+ responsiveIssueCount?: number;
258
313
  };
259
314
  /** Auto-inferred invariants */
260
315
  suggestedInvariants: SpecInvariant[];
@@ -337,6 +392,8 @@ export interface AgentContext {
337
392
  export interface A11yNode {
338
393
  role: string;
339
394
  name: string;
395
+ id?: string;
396
+ attributes?: Record<string, string | number | boolean | null | undefined>;
340
397
  level?: number;
341
398
  value?: string;
342
399
  description?: string;
@@ -345,6 +402,13 @@ export interface A11yNode {
345
402
  expanded?: boolean;
346
403
  pressed?: boolean | "mixed";
347
404
  selected?: boolean;
405
+ ariaLabelledBy?: string | string[];
406
+ ariaLabeledBy?: string | string[];
407
+ ariaDescribedBy?: string | string[];
408
+ ariaControls?: string | string[];
409
+ ariaOwns?: string | string[];
410
+ ariaDetails?: string | string[];
411
+ ariaActiveDescendant?: string | string[];
348
412
  children?: A11yNode[];
349
413
  }
350
414
 
@@ -390,6 +454,7 @@ export type VisualChangeType =
390
454
  | "text-change"
391
455
  | "color-change"
392
456
  | "layout-shift"
457
+ | "reflow"
393
458
  | "element-added"
394
459
  | "element-removed"
395
460
  | "icon-change";