@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/README.md +38 -14
- package/SKILL.md +56 -10
- package/dist/cli.js +598 -397
- package/dist/index.d.mts +79 -12
- package/dist/index.d.ts +79 -12
- package/dist/index.js +429 -191
- package/dist/index.mjs +407 -193
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@blazediff/agent)
|
|
6
|
-
[](https://www.npmjs.com/package/@blazediff/agent)
|
|
5
|
+
[](https://www.npmjs.com/package/@blazediff/agent)
|
|
6
|
+
[](https://www.npmjs.com/package/@blazediff/agent)
|
|
7
7
|
|
|
8
8
|
</div>
|
|
9
9
|
|
|
@@ -51,7 +51,7 @@ Commit `.blazediff/` (config + manifest + baselines). All commands accept `--jso
|
|
|
51
51
|
<tr><td><code>rewrite <id...></code></td><td>Re-baseline existing entries (also <code>--failed</code> / <code>--all</code>). Cleans stale <code>actual/</code>, <code>judgments/</code>, <code>summary.md</code>, <code>checkpoints/</code> for the rewritten ids.</td></tr>
|
|
52
52
|
<tr><td><code>diff <id></code></td><td>Re-diff one entry without re-screenshotting</td></tr>
|
|
53
53
|
<tr><td><code>manifest</code></td><td>Inspect / list manifest entries</td></tr>
|
|
54
|
-
<tr><td><code>auth init</code></td><td>Record a login harness via Playwright codegen, rewrite credentials to env-var refs, write <code>.blazediff/auth.js</code></td></tr>
|
|
54
|
+
<tr><td><code>auth init</code></td><td>Record a login harness via Playwright codegen, rewrite credentials to env-var refs, write <code>.blazediff/harnesses/auth.js</code></td></tr>
|
|
55
55
|
<tr><td><code>serve-status</code></td><td>Start / stop / probe the dev server</td></tr>
|
|
56
56
|
<tr><td><code>browsers install</code></td><td>Install bundled Playwright Chromium</td></tr>
|
|
57
57
|
<tr><td><code>reset --yes</code></td><td>Wipe <code>.blazediff/</code></td></tr>
|
|
@@ -96,23 +96,47 @@ Every non-match routes through the configured judge. With `--judge host` the jud
|
|
|
96
96
|
"devServer": { "command": "pnpm dev", "port": 3000, "readyTimeoutMs": 60000 },
|
|
97
97
|
"framework": "next",
|
|
98
98
|
"packageManager": "pnpm",
|
|
99
|
-
"baseUrl": "http://127.0.0.1:3000"
|
|
100
|
-
"auth": { "harness": ".blazediff/auth.js", "loginUrl": "http://127.0.0.1:3000/login" }
|
|
99
|
+
"baseUrl": "http://127.0.0.1:3000"
|
|
101
100
|
}
|
|
102
101
|
```
|
|
103
102
|
|
|
104
|
-
The `auth` block is added by `blazediff-agent auth init` — omit it on projects without auth-gated routes.
|
|
105
|
-
|
|
106
103
|
`.blazediff/manifest.json` is written by `capture`; don't edit it directly.
|
|
107
104
|
|
|
108
|
-
##
|
|
105
|
+
## Harnesses
|
|
106
|
+
|
|
107
|
+
A harness is a pluggable script in `.blazediff/harnesses/<name>.js`, attached to
|
|
108
|
+
an entry via `harnesses: [{ name, params? }]`. A **setup** harness runs before
|
|
109
|
+
navigation (e.g. login); an **interact** harness (the default) runs after the
|
|
110
|
+
base screenshot and may drive the page and emit extra named screenshots — each
|
|
111
|
+
becomes its own baseline entry (`<id>__<name>`). Harnesses default-export a
|
|
112
|
+
`Harness` and are ESM `.js`/`.mjs` (TypeScript is not auto-transpiled):
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
/** @type {import("@blazediff/agent").Harness} */
|
|
116
|
+
export default {
|
|
117
|
+
async run({ page, screenshot }) {
|
|
118
|
+
await page.getByRole("button", { name: "More options" }).click();
|
|
119
|
+
await screenshot("menu"); // -> baseline "<entry>__menu"
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
```
|
|
109
123
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
`
|
|
115
|
-
|
|
124
|
+
### Auth-protected routes
|
|
125
|
+
|
|
126
|
+
Login is a `phase:"setup"` harness. For a simple form login, the agent writes
|
|
127
|
+
`.blazediff/harnesses/auth.js` directly — a `goto(/login)` → fill from
|
|
128
|
+
`process.env.BLAZEDIFF_AUTH_<PERSONA>_EMAIL` / `..._PASSWORD` → submit → assert it
|
|
129
|
+
left `/login`. No credentials ever live in the file, only env refs. For flows it
|
|
130
|
+
can't author (OAuth/SSO, MFA, captcha), `blazediff-agent auth init` records the
|
|
131
|
+
login interactively via Playwright codegen and rewrites the typed creds to env
|
|
132
|
+
refs.
|
|
133
|
+
|
|
134
|
+
Attach it with `"harnesses": [{ "name": "auth", "params": { "persona": "default" } }]`,
|
|
135
|
+
then put `BLAZEDIFF_AUTH_<PERSONA>_EMAIL` / `..._PASSWORD` in an env file the CLI
|
|
136
|
+
auto-loads from the target dir — `.blazediff/.env[.local]` (blazediff-scoped,
|
|
137
|
+
auto-gitignored) or the project-root `.env[.local]` — or export them. Real env
|
|
138
|
+
wins; `.blazediff/` files beat the root. `check` does the rest.
|
|
139
|
+
Full walkthrough: [Auth-protected routes][auth-docs].
|
|
116
140
|
|
|
117
141
|
[auth-docs]: https://blazediff.dev/docs/agent#auth-protected-routes
|
|
118
142
|
|
package/SKILL.md
CHANGED
|
@@ -68,35 +68,81 @@ When the user asks to wipe blazediff's state and start over (manifest stale beyo
|
|
|
68
68
|
- Remix / SvelteKit / Astro: walk `app/routes` or `src/routes`.
|
|
69
69
|
|
|
70
70
|
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
|
|
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
72
|
6. **Capture in one call.** Build a JSON array of route entries and pipe it through stdin:
|
|
73
73
|
```
|
|
74
74
|
cat <<'EOF' | blazediff-agent --cwd "$TARGET" capture --stdin --mode baseline --json
|
|
75
75
|
[
|
|
76
76
|
{"id":"home","url":"/","mask":[".timestamp"]},
|
|
77
77
|
{"id":"pricing","url":"/pricing"},
|
|
78
|
-
{"id":"dashboard","url":"/dashboard","auth":"default"}
|
|
78
|
+
{"id":"dashboard","url":"/dashboard","harnesses":[{"name":"auth","params":{"persona":"default"}}]}
|
|
79
79
|
]
|
|
80
80
|
EOF
|
|
81
81
|
```
|
|
82
|
-
Entries: `{ id, url, mask?, viewport?, waitFor?, fullPage?,
|
|
82
|
+
Entries: `{ id, url, mask?, viewport?, waitFor?, fullPage?, harnesses?, mode? }`. Only `id` and `url` required. `harnesses` is an ordered list of `{ name, params? }` (or bare `"name"` strings) resolving to `.blazediff/harnesses/<name>.js`. Manifest entries are written automatically (pass `--no-manifest` to skip).
|
|
83
83
|
- `id`: semantic kebab-case (`home`, `pricing`, `docs-getting-started`), not URL slug.
|
|
84
84
|
- `mask`: CSS selectors for unstable regions (timestamps, randomized IDs, avatars, "X ago" times, carousels, third-party iframes). Omit if none. The agent always masks `[data-blazediff-agent-mask]` automatically, so prefer tagging the source element when you can edit it. See `MASKING.md` for full guidance.
|
|
85
85
|
7. **Teardown — ALWAYS run, even on error.** If `config.devServer` is non-null, run `blazediff-agent --cwd "$TARGET" serve-status --kill --json` as the very last step regardless of capture success/failure. The CLI kills by tracked PID first, then falls back to whatever process is listening on the configured port — so it cleans up stale dev servers from prior crashed runs too. If the kill returns `stopped: false`, no server was running; that's fine. Wrap your capture call so this step runs even if capture failed mid-list (shell `trap`, try/finally in the host agent's flow, etc.).
|
|
86
86
|
8. **Final summary line.** Suggest `git add .blazediff/ && git commit`.
|
|
87
87
|
|
|
88
|
-
##
|
|
89
|
-
|
|
88
|
+
## harnesses
|
|
89
|
+
A harness is a pluggable script in `.blazediff/harnesses/<name>.js` attached to an entry via `harnesses: [{ name, params? }]`. There are two phases:
|
|
90
|
+
- **setup** — runs before navigation (establish a session, e.g. login). Login is just a setup harness.
|
|
91
|
+
- **interact** (default) — runs after the base screenshot; drives the page and may emit extra named screenshots.
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
Each harness is an ESM module that default-exports a `Harness`. TypeScript is **not** auto-transpiled — write `.js`/`.mjs` and use the JSDoc `@type` annotation for intellisense:
|
|
94
|
+
```js
|
|
95
|
+
/** @type {import("@blazediff/agent").Harness} */
|
|
96
|
+
export default {
|
|
97
|
+
// phase defaults to "interact": runs AFTER the base screenshot.
|
|
98
|
+
async run({ page, screenshot }) {
|
|
99
|
+
await page.getByRole("button", { name: "More options" }).click();
|
|
100
|
+
await screenshot("menu"); // -> a sub-baseline with id "<entry>__menu"
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
Attach it: `{"id":"weather","url":"/weather","harnesses":["weather-menu"]}`. The base shot `weather` fires automatically; every `screenshot("menu")` becomes its own manifest/baseline/diff entry `weather__menu`.
|
|
105
|
+
|
|
106
|
+
Rules:
|
|
107
|
+
- You may author **interaction** harnesses directly (you know Playwright). Keep them deterministic — prefer role/label/test-id selectors, no `nth-child`. Stability + masks are re-applied before each sub-shot automatically. Screenshot names must be alphanumeric/kebab (no `__`, spaces, or slashes).
|
|
108
|
+
- To re-baseline a multi-shot entry, `rewrite <parent-id>` — it re-runs the harness and regenerates every child.
|
|
109
|
+
|
|
110
|
+
### login harness
|
|
111
|
+
Login is just a `phase:"setup"` harness. Credentials live only in env vars — never in the LLM, manifest, or harness file (the harness references `process.env.BLAZEDIFF_AUTH_*`, nothing else).
|
|
112
|
+
|
|
113
|
+
1. **Already present?** If `.blazediff/harnesses/auth.js` exists, skip to step 4. (Legacy `.blazediff/auth.js` from before the harness change must be regenerated.)
|
|
114
|
+
2. **Author it directly — preferred when creds are available.** If creds are in the env / `.blazediff/.env` (or the user can supply them), **write the harness yourself; do not make the user run `auth init`.** Identify the login form's email / password / submit selectors by reading the `/login` route's source component (prefer `name=` / `type=` / `id=` / role-based selectors; avoid `nth-child`), or by snapshotting the live page. Write `.blazediff/harnesses/auth.js`:
|
|
115
|
+
```js
|
|
116
|
+
/** @type {import("@blazediff/agent").Harness<{ persona?: string }>} */
|
|
117
|
+
export default {
|
|
118
|
+
phase: "setup", // runs before navigation; must NOT call screenshot()
|
|
119
|
+
async run({ page, params }) {
|
|
120
|
+
const upper = (params.persona ?? "default").toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
121
|
+
const email = process.env[`BLAZEDIFF_AUTH_${upper}_EMAIL`];
|
|
122
|
+
const password = process.env[`BLAZEDIFF_AUTH_${upper}_PASSWORD`];
|
|
123
|
+
if (!email || !password) throw new Error(`missing BLAZEDIFF_AUTH_${upper}_EMAIL / _PASSWORD`);
|
|
124
|
+
await page.goto("<LOGIN URL>");
|
|
125
|
+
await page.locator('input[name="email"]').fill(email);
|
|
126
|
+
await page.locator('input[name="password"]').fill(password);
|
|
127
|
+
await Promise.all([
|
|
128
|
+
page.waitForURL((u) => !u.pathname.startsWith("/login")),
|
|
129
|
+
page.getByRole("button", { name: /sign in|log in/i }).click(),
|
|
130
|
+
]);
|
|
131
|
+
if (new URL(page.url()).pathname === new URL("<LOGIN URL>").pathname) {
|
|
132
|
+
throw new Error("login did not leave /login — check selectors/redirect");
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
```
|
|
137
|
+
Never inline real credentials — only `process.env.BLAZEDIFF_AUTH_*` references.
|
|
138
|
+
3. **Fallback: interactive recorder.** Only when you can't reduce login to fill-fields-and-submit — OAuth/SSO, captcha, MFA, multi-step — tell the user to run `blazediff-agent --cwd "$TARGET" auth init --persona default --login-url <login URL>` (opens Playwright codegen; they log in once; typed creds are rewritten to env-var refs and written to `.blazediff/harnesses/auth.js`). You can't drive the recorder yourself.
|
|
139
|
+
4. **Per entry.** Add `{ "name": "auth", "params": { "persona": "<persona>" } }` to the entry's `harnesses` (use `"default"` unless the user specifies otherwise).
|
|
140
|
+
5. **Env vars.** The harness reads `BLAZEDIFF_AUTH_<PERSONA>_EMAIL` / `..._PASSWORD` at capture time. The CLI auto-loads env files from `--cwd`: `.blazediff/.env[.local]` (blazediff-scoped, auto-gitignored) then the project-root `.env[.local]`; real exported env wins, and `.blazediff/` files beat the app root. Drop creds in `.blazediff/.env`. If the user hasn't supplied any, ask for them — don't invent placeholders.
|
|
96
141
|
|
|
97
142
|
## Hard rules
|
|
98
143
|
- Never `--mode baseline` an existing manifest entry without explicit user request.
|
|
99
144
|
- Never edit `.blazediff/manifest.json` directly.
|
|
145
|
+
- Author login and interaction harnesses directly under `.blazediff/harnesses/` when you can (login: simple form, creds via env). Use `auth init` only for flows you can't author (OAuth/SSO/MFA/captcha). Never write real credentials into a harness file — env refs only.
|
|
100
146
|
- In CI (`CI=1` or no TTY), only `check` is allowed.
|
|
101
147
|
- A route that times out is logged once in the result array and skipped — never block the run.
|
|
102
148
|
- Never leave a dev server running after authoring exits. Teardown is mandatory on every exit path (success, capture failure, user interrupt). If you can't run teardown for some reason, tell the user the port number to kill manually.
|