@blazediff/agent 0.2.0 → 0.3.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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { Page } from 'playwright';
2
1
  import { BoundingBox, InterpretResult } from '@blazediff/core-native';
2
+ import { Page, Browser, BrowserContext } from 'playwright';
3
3
 
4
4
  type VerdictLabel = "regression-likely" | "intentional-likely" | "noise-likely" | "ambiguous";
5
5
  type VerdictAction = "investigate" | "rewrite-if-intended" | "ignore-or-rewrite";
@@ -11,6 +11,33 @@ interface Verdict {
11
11
  }
12
12
 
13
13
  declare const STABILITY_HOOKS_VERSION = 1;
14
+ /**
15
+ * Context handed to a harness. `params` is intentionally generic — a harness
16
+ * author types it to whatever the harness needs (e.g. `{ persona: string }`
17
+ * for a login harness). `screenshot(name)` emits a named sub-screenshot that
18
+ * becomes its own baseline entry (`<entryId>__<name>`).
19
+ */
20
+ interface HarnessContext<P = Record<string, unknown>> {
21
+ page: Page;
22
+ browser: Browser;
23
+ context: BrowserContext;
24
+ params: P;
25
+ screenshot(name: string): Promise<void>;
26
+ }
27
+ /**
28
+ * A pluggable script run before/around a screenshot. `setup` harnesses run
29
+ * before navigation (establish session, e.g. login); `interact` harnesses run
30
+ * after the base screenshot and may drive the page + emit named screenshots.
31
+ */
32
+ interface Harness<P = Record<string, unknown>> {
33
+ phase?: "setup" | "interact";
34
+ run(ctx: HarnessContext<P>): Promise<void>;
35
+ }
36
+ /** Per-entry reference to a harness file under `.blazediff/harnesses/<name>.js`. */
37
+ interface HarnessRef {
38
+ name: string;
39
+ params?: Record<string, unknown>;
40
+ }
14
41
  interface RegionSummary {
15
42
  bbox: BoundingBox;
16
43
  pixelCount: number;
@@ -31,10 +58,13 @@ interface ManifestEntry {
31
58
  id: string;
32
59
  url: string;
33
60
  viewport: Viewport;
34
- auth: null | string;
61
+ harnesses?: HarnessRef[];
35
62
  waitFor: WaitFor[];
36
63
  mask: string[];
37
64
  fullPage?: boolean;
65
+ /** Set on sub-entries produced by a harness `screenshot(name)` call. */
66
+ parent?: string;
67
+ derived?: boolean;
38
68
  baselinePath: string;
39
69
  captureHash: string;
40
70
  createdBy: "agent" | "human";
@@ -52,16 +82,11 @@ interface DevServerConfig {
52
82
  cwd?: string;
53
83
  readyTimeoutMs?: number;
54
84
  }
55
- interface AgentAuthConfig {
56
- harness: string;
57
- loginUrl: string;
58
- }
59
85
  interface AgentConfig {
60
86
  devServer: DevServerConfig | null;
61
87
  framework?: string;
62
88
  packageManager?: "npm" | "pnpm" | "yarn" | "bun";
63
89
  baseUrl?: string;
64
- auth?: AgentAuthConfig;
65
90
  }
66
91
  interface CaptureOptions {
67
92
  id: string;
@@ -100,16 +125,24 @@ interface CheckResult {
100
125
  message?: string;
101
126
  }
102
127
 
128
+ interface SubCapture {
129
+ name: string;
130
+ outputPath: string;
131
+ bytes: number;
132
+ }
103
133
  interface CaptureResult {
104
134
  id: string;
105
135
  outputPath: string;
106
136
  mode: "baseline" | "actual";
107
137
  bytes: number;
138
+ subCaptures?: SubCapture[];
108
139
  }
109
- interface CaptureAuth {
110
- hook: (page: Page) => Promise<void>;
140
+ /** A harness paired with the params to run it with, resolved by the caller. */
141
+ interface ResolvedHarness {
142
+ harness: Harness;
143
+ params: Record<string, unknown>;
111
144
  }
112
- declare function captureScreenshot(baseUrl: string, opts: CaptureOptions, cwd?: string, auth?: CaptureAuth): Promise<CaptureResult>;
145
+ declare function captureScreenshot(baseUrl: string, opts: CaptureOptions, cwd?: string, harnesses?: ResolvedHarness[]): Promise<CaptureResult>;
113
146
 
114
147
  interface BrowsersInstallOptions {
115
148
  check?: boolean;
@@ -128,7 +161,7 @@ interface CaptureRouteInput {
128
161
  viewport?: Viewport;
129
162
  waitFor?: WaitFor[];
130
163
  fullPage?: boolean;
131
- auth?: null | string;
164
+ harnesses?: (string | HarnessRef)[];
132
165
  mode?: "baseline" | "actual";
133
166
  }
134
167
  interface RunCapturesOptions {
@@ -146,6 +179,7 @@ interface CaptureRouteResult {
146
179
  ok: boolean;
147
180
  outputPath?: string;
148
181
  bytes?: number;
182
+ subCaptures?: string[];
149
183
  error?: string;
150
184
  }
151
185
  interface RunCapturesReport {
@@ -188,6 +222,15 @@ interface DiscoverOptions {
188
222
  }
189
223
  declare function discover(opts: DiscoverOptions): Promise<DiscoveredRoute[]>;
190
224
 
225
+ /**
226
+ * Load env files (`.blazediff/.env[.local]` then `.env[.local]`) into
227
+ * `process.env` so harnesses can read secrets (e.g. `BLAZEDIFF_AUTH_*`) without
228
+ * the user exporting them by hand. Real environment variables always win, and
229
+ * `.blazediff/` files take precedence over the project-root ones. Returns the
230
+ * files actually applied.
231
+ */
232
+ declare function loadEnvFiles(cwd?: string): string[];
233
+
191
234
  interface JudgeInput {
192
235
  entry: ManifestEntry;
193
236
  baselinePath: string;
@@ -301,6 +344,28 @@ interface ResumeOptions {
301
344
  declare function resumeGraph(opts: ResumeOptions): Promise<CheckReport>;
302
345
  declare function runCheck(opts: CheckOptions): Promise<CheckReport>;
303
346
 
347
+ declare class HarnessError extends Error {
348
+ readonly cause?: unknown | undefined;
349
+ constructor(message: string, cause?: unknown | undefined);
350
+ }
351
+ /**
352
+ * Resolve a harness reference to an absolute file path. A bare `name` resolves
353
+ * to `.blazediff/harnesses/<name>.js` (preferring `.mjs` if present); an
354
+ * explicit relative/absolute path is honored as-is.
355
+ */
356
+ declare function resolveHarnessFile(name: string, cwd: string): string;
357
+ /**
358
+ * Load a harness module. Harnesses are ESM `.js`/`.mjs` files that
359
+ * default-export a {@link Harness}. The module is cached by absolute path.
360
+ */
361
+ declare function loadHarness(harnessFile: string): Promise<Harness>;
362
+ /**
363
+ * Safety check for login harnesses: confirms the page left the login URL and no
364
+ * visible password input remains. Exported so generated auth harnesses can call
365
+ * it without the framework special-casing auth.
366
+ */
367
+ declare function assertLeftLoginPage(page: Page, loginUrl: string): Promise<void>;
368
+
304
369
  declare function loadManifest(cwd?: string): Promise<Manifest | null>;
305
370
  declare function saveManifest(manifest: Manifest, cwd?: string): Promise<void>;
306
371
 
@@ -308,6 +373,8 @@ declare const paths: (cwd?: string) => {
308
373
  root: string;
309
374
  config: string;
310
375
  manifest: string;
376
+ harnesses: string;
377
+ authHarness: string;
311
378
  baselines: string;
312
379
  actual: string;
313
380
  judgments: string;
@@ -318,4 +385,4 @@ declare const paths: (cwd?: string) => {
318
385
  serverPid: string;
319
386
  };
320
387
 
321
- export { type AgentAuthConfig, type AgentConfig, type ApplyJudgmentsResult, type BrowsersInstallOptions, type BrowsersInstallResult, type CaptureOptions, type CaptureRouteInput, type CaptureRouteResult, type CheckOptions, type CheckReport, type CheckResult, type DevServerConfig, type DiffOptions, type DiffOutcome, type DiscoveredRoute, type Judge, type JudgeBackend, type JudgeInput, type JudgeOutput, type JudgmentRequest, type JudgmentRequestRegion, type Manifest, type ManifestEntry, type RegionSummary, type ResumeMap, type ResumeOptions, type RunCapturesOptions, type RunCapturesReport, type RunEvent, type RunOptions, STABILITY_HOOKS_VERSION, type Verdict, type VerdictAction, type VerdictLabel, type Viewport, type WaitFor, type WaitForSelector, applyJudgments, captureScreenshot, configHash, diffEntry, discover, installBrowsers, loadConfig, loadManifest, paths, resolveBaseUrl, resolveJudge, resumeGraph, runCaptures, runCheck, runGraph, saveConfig, saveManifest, threadIdFor };
388
+ export { type AgentConfig, type ApplyJudgmentsResult, type BrowsersInstallOptions, type BrowsersInstallResult, type CaptureOptions, type CaptureRouteInput, type CaptureRouteResult, type CheckOptions, type CheckReport, type CheckResult, type DevServerConfig, type DiffOptions, type DiffOutcome, type DiscoveredRoute, type Harness, type HarnessContext, HarnessError, type HarnessRef, type Judge, type JudgeBackend, type JudgeInput, type JudgeOutput, type JudgmentRequest, type JudgmentRequestRegion, type Manifest, type ManifestEntry, type RegionSummary, type ResumeMap, type ResumeOptions, type RunCapturesOptions, type RunCapturesReport, type RunEvent, type RunOptions, STABILITY_HOOKS_VERSION, type Verdict, type VerdictAction, type VerdictLabel, type Viewport, type WaitFor, type WaitForSelector, applyJudgments, assertLeftLoginPage, captureScreenshot, configHash, diffEntry, discover, installBrowsers, loadConfig, loadEnvFiles, loadHarness, loadManifest, paths, resolveBaseUrl, resolveHarnessFile, resolveJudge, resumeGraph, runCaptures, runCheck, runGraph, saveConfig, saveManifest, threadIdFor };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Page } from 'playwright';
2
1
  import { BoundingBox, InterpretResult } from '@blazediff/core-native';
2
+ import { Page, Browser, BrowserContext } from 'playwright';
3
3
 
4
4
  type VerdictLabel = "regression-likely" | "intentional-likely" | "noise-likely" | "ambiguous";
5
5
  type VerdictAction = "investigate" | "rewrite-if-intended" | "ignore-or-rewrite";
@@ -11,6 +11,33 @@ interface Verdict {
11
11
  }
12
12
 
13
13
  declare const STABILITY_HOOKS_VERSION = 1;
14
+ /**
15
+ * Context handed to a harness. `params` is intentionally generic — a harness
16
+ * author types it to whatever the harness needs (e.g. `{ persona: string }`
17
+ * for a login harness). `screenshot(name)` emits a named sub-screenshot that
18
+ * becomes its own baseline entry (`<entryId>__<name>`).
19
+ */
20
+ interface HarnessContext<P = Record<string, unknown>> {
21
+ page: Page;
22
+ browser: Browser;
23
+ context: BrowserContext;
24
+ params: P;
25
+ screenshot(name: string): Promise<void>;
26
+ }
27
+ /**
28
+ * A pluggable script run before/around a screenshot. `setup` harnesses run
29
+ * before navigation (establish session, e.g. login); `interact` harnesses run
30
+ * after the base screenshot and may drive the page + emit named screenshots.
31
+ */
32
+ interface Harness<P = Record<string, unknown>> {
33
+ phase?: "setup" | "interact";
34
+ run(ctx: HarnessContext<P>): Promise<void>;
35
+ }
36
+ /** Per-entry reference to a harness file under `.blazediff/harnesses/<name>.js`. */
37
+ interface HarnessRef {
38
+ name: string;
39
+ params?: Record<string, unknown>;
40
+ }
14
41
  interface RegionSummary {
15
42
  bbox: BoundingBox;
16
43
  pixelCount: number;
@@ -31,10 +58,13 @@ interface ManifestEntry {
31
58
  id: string;
32
59
  url: string;
33
60
  viewport: Viewport;
34
- auth: null | string;
61
+ harnesses?: HarnessRef[];
35
62
  waitFor: WaitFor[];
36
63
  mask: string[];
37
64
  fullPage?: boolean;
65
+ /** Set on sub-entries produced by a harness `screenshot(name)` call. */
66
+ parent?: string;
67
+ derived?: boolean;
38
68
  baselinePath: string;
39
69
  captureHash: string;
40
70
  createdBy: "agent" | "human";
@@ -52,16 +82,11 @@ interface DevServerConfig {
52
82
  cwd?: string;
53
83
  readyTimeoutMs?: number;
54
84
  }
55
- interface AgentAuthConfig {
56
- harness: string;
57
- loginUrl: string;
58
- }
59
85
  interface AgentConfig {
60
86
  devServer: DevServerConfig | null;
61
87
  framework?: string;
62
88
  packageManager?: "npm" | "pnpm" | "yarn" | "bun";
63
89
  baseUrl?: string;
64
- auth?: AgentAuthConfig;
65
90
  }
66
91
  interface CaptureOptions {
67
92
  id: string;
@@ -100,16 +125,24 @@ interface CheckResult {
100
125
  message?: string;
101
126
  }
102
127
 
128
+ interface SubCapture {
129
+ name: string;
130
+ outputPath: string;
131
+ bytes: number;
132
+ }
103
133
  interface CaptureResult {
104
134
  id: string;
105
135
  outputPath: string;
106
136
  mode: "baseline" | "actual";
107
137
  bytes: number;
138
+ subCaptures?: SubCapture[];
108
139
  }
109
- interface CaptureAuth {
110
- hook: (page: Page) => Promise<void>;
140
+ /** A harness paired with the params to run it with, resolved by the caller. */
141
+ interface ResolvedHarness {
142
+ harness: Harness;
143
+ params: Record<string, unknown>;
111
144
  }
112
- declare function captureScreenshot(baseUrl: string, opts: CaptureOptions, cwd?: string, auth?: CaptureAuth): Promise<CaptureResult>;
145
+ declare function captureScreenshot(baseUrl: string, opts: CaptureOptions, cwd?: string, harnesses?: ResolvedHarness[]): Promise<CaptureResult>;
113
146
 
114
147
  interface BrowsersInstallOptions {
115
148
  check?: boolean;
@@ -128,7 +161,7 @@ interface CaptureRouteInput {
128
161
  viewport?: Viewport;
129
162
  waitFor?: WaitFor[];
130
163
  fullPage?: boolean;
131
- auth?: null | string;
164
+ harnesses?: (string | HarnessRef)[];
132
165
  mode?: "baseline" | "actual";
133
166
  }
134
167
  interface RunCapturesOptions {
@@ -146,6 +179,7 @@ interface CaptureRouteResult {
146
179
  ok: boolean;
147
180
  outputPath?: string;
148
181
  bytes?: number;
182
+ subCaptures?: string[];
149
183
  error?: string;
150
184
  }
151
185
  interface RunCapturesReport {
@@ -188,6 +222,15 @@ interface DiscoverOptions {
188
222
  }
189
223
  declare function discover(opts: DiscoverOptions): Promise<DiscoveredRoute[]>;
190
224
 
225
+ /**
226
+ * Load env files (`.blazediff/.env[.local]` then `.env[.local]`) into
227
+ * `process.env` so harnesses can read secrets (e.g. `BLAZEDIFF_AUTH_*`) without
228
+ * the user exporting them by hand. Real environment variables always win, and
229
+ * `.blazediff/` files take precedence over the project-root ones. Returns the
230
+ * files actually applied.
231
+ */
232
+ declare function loadEnvFiles(cwd?: string): string[];
233
+
191
234
  interface JudgeInput {
192
235
  entry: ManifestEntry;
193
236
  baselinePath: string;
@@ -301,6 +344,28 @@ interface ResumeOptions {
301
344
  declare function resumeGraph(opts: ResumeOptions): Promise<CheckReport>;
302
345
  declare function runCheck(opts: CheckOptions): Promise<CheckReport>;
303
346
 
347
+ declare class HarnessError extends Error {
348
+ readonly cause?: unknown | undefined;
349
+ constructor(message: string, cause?: unknown | undefined);
350
+ }
351
+ /**
352
+ * Resolve a harness reference to an absolute file path. A bare `name` resolves
353
+ * to `.blazediff/harnesses/<name>.js` (preferring `.mjs` if present); an
354
+ * explicit relative/absolute path is honored as-is.
355
+ */
356
+ declare function resolveHarnessFile(name: string, cwd: string): string;
357
+ /**
358
+ * Load a harness module. Harnesses are ESM `.js`/`.mjs` files that
359
+ * default-export a {@link Harness}. The module is cached by absolute path.
360
+ */
361
+ declare function loadHarness(harnessFile: string): Promise<Harness>;
362
+ /**
363
+ * Safety check for login harnesses: confirms the page left the login URL and no
364
+ * visible password input remains. Exported so generated auth harnesses can call
365
+ * it without the framework special-casing auth.
366
+ */
367
+ declare function assertLeftLoginPage(page: Page, loginUrl: string): Promise<void>;
368
+
304
369
  declare function loadManifest(cwd?: string): Promise<Manifest | null>;
305
370
  declare function saveManifest(manifest: Manifest, cwd?: string): Promise<void>;
306
371
 
@@ -308,6 +373,8 @@ declare const paths: (cwd?: string) => {
308
373
  root: string;
309
374
  config: string;
310
375
  manifest: string;
376
+ harnesses: string;
377
+ authHarness: string;
311
378
  baselines: string;
312
379
  actual: string;
313
380
  judgments: string;
@@ -318,4 +385,4 @@ declare const paths: (cwd?: string) => {
318
385
  serverPid: string;
319
386
  };
320
387
 
321
- export { type AgentAuthConfig, type AgentConfig, type ApplyJudgmentsResult, type BrowsersInstallOptions, type BrowsersInstallResult, type CaptureOptions, type CaptureRouteInput, type CaptureRouteResult, type CheckOptions, type CheckReport, type CheckResult, type DevServerConfig, type DiffOptions, type DiffOutcome, type DiscoveredRoute, type Judge, type JudgeBackend, type JudgeInput, type JudgeOutput, type JudgmentRequest, type JudgmentRequestRegion, type Manifest, type ManifestEntry, type RegionSummary, type ResumeMap, type ResumeOptions, type RunCapturesOptions, type RunCapturesReport, type RunEvent, type RunOptions, STABILITY_HOOKS_VERSION, type Verdict, type VerdictAction, type VerdictLabel, type Viewport, type WaitFor, type WaitForSelector, applyJudgments, captureScreenshot, configHash, diffEntry, discover, installBrowsers, loadConfig, loadManifest, paths, resolveBaseUrl, resolveJudge, resumeGraph, runCaptures, runCheck, runGraph, saveConfig, saveManifest, threadIdFor };
388
+ export { type AgentConfig, type ApplyJudgmentsResult, type BrowsersInstallOptions, type BrowsersInstallResult, type CaptureOptions, type CaptureRouteInput, type CaptureRouteResult, type CheckOptions, type CheckReport, type CheckResult, type DevServerConfig, type DiffOptions, type DiffOutcome, type DiscoveredRoute, type Harness, type HarnessContext, HarnessError, type HarnessRef, type Judge, type JudgeBackend, type JudgeInput, type JudgeOutput, type JudgmentRequest, type JudgmentRequestRegion, type Manifest, type ManifestEntry, type RegionSummary, type ResumeMap, type ResumeOptions, type RunCapturesOptions, type RunCapturesReport, type RunEvent, type RunOptions, STABILITY_HOOKS_VERSION, type Verdict, type VerdictAction, type VerdictLabel, type Viewport, type WaitFor, type WaitForSelector, applyJudgments, assertLeftLoginPage, captureScreenshot, configHash, diffEntry, discover, installBrowsers, loadConfig, loadEnvFiles, loadHarness, loadManifest, paths, resolveBaseUrl, resolveHarnessFile, resolveJudge, resumeGraph, runCaptures, runCheck, runGraph, saveConfig, saveManifest, threadIdFor };