blastproof 0.23.0 → 0.25.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
@@ -77,7 +77,7 @@ Three questions. The first one decides most cases.
77
77
 
78
78
  **A hard requirement, not a preference.** blastproof finds elements the way a screen reader does — by role, by label, by visible text. That is what removes selectors and survives redesigns. The cost is that there is deliberately no CSS or XPath fallback, so anything the accessibility tree cannot describe cannot be driven at all.
79
79
 
80
- The name is matched **exactly first**, then by substring if nothing matches exactly — so a control named `Add` is found even when `Add New` sits above it. When several controls answer to the same name, the first one on the page wins. Give each control an accessible name no other control on the page shares; a page that cannot offer one cannot be driven unambiguously, and no matching rule fixes that.
80
+ The agent acts on the element it read, not on a search for its name. Each element in the snapshot it reads carries a ref, and an action names that ref: two controls called `Delete` are two different targets, and `Add` is never mistaken for `Add New`. If the role and name the agent gives do not match the element the ref points at, the action is refused rather than performed. A ref is valid only for the snapshot it came from, so nothing like a selector is ever stored.
81
81
 
82
82
  | works | cannot be driven |
83
83
  | --- | --- |
@@ -299,9 +299,32 @@ export ANTHROPIC_API_KEY=...
299
299
  node dist/cli.js run
300
300
  ```
301
301
 
302
+ ### How often a verdict is wrong
303
+
304
+ A merge gate is judged by two numbers. A **false PASS** is a test that passes on an app with the bug it exists to catch. A **false FAIL** is a test that fails on a correct app. `npm run eval:reliability` measures both. It runs the suite above on the demo app as it is, and each test on **mutants**: copies of the app with one bug seeded. A *literal* mutant changes the value a step quotes. A *subtle* one reproduces the shape of a wrong verdict this project has already had, such as the right value in the wrong place, or a success message with no success behind it.
305
+
306
+ | | `claude-haiku-4.5` | `gpt-6-luna` |
307
+ | --- | --- | --- |
308
+ | false FAIL, correct app (40 test runs) | 0 (≤ 8.8%) | 0 (≤ 8.8%) |
309
+ | false PASS, literal bugs (30) | 0 (≤ 11.4%) | 0 (≤ 11.4%) |
310
+ | false PASS, subtle bugs (20) | 0 (≤ 16.1%) | 0 (≤ 16.1%) |
311
+
312
+ The bounds are 95% upper bounds: zero errors in 40 runs means "below about 9%", not "never". The first run of this table found a false PASS on Haiku, 2 subtle runs in 20. The confirmation showed order `#BP-1002`, another paragraph mentioned `#BP-1001` as a previous order, and a step checking for `#BP-1001` *in the confirmation* passed. That was fixed in the judge ([#147](https://github.com/hamc/blastproof/issues/147)), and this is the run after the fix.
313
+
314
+ The demo app is small and well labelled, so these numbers flatter. Expect a real application to do worse. The point of this table is that it can be reproduced, and that every change claiming better verdicts has to move it.
315
+
316
+ The same benchmark over seven more models, and why it chose the OpenAI and Ollama defaults, is in [Choosing a model](./docs/configuration.md#choosing-a-model).
317
+
318
+ Measured 2026-10-07 on `main` after 0.23.0 with #147's fix, 5 samples, through OpenRouter. To reproduce:
319
+
320
+ ```bash
321
+ npm run build
322
+ EVAL_MODELS=anthropic/claude-haiku-4.5,openai/gpt-6-luna npm run eval:reliability
323
+ ```
324
+
302
325
  ## Development
303
326
 
304
- Built with AI assistance using spec-driven development: every change began as a written proposal with its design rationale, and those documents are kept rather than discarded. `openspec/` holds the reasoning behind each decision, including the alternatives that were rejected and why — start at [`AGENTS.md`](./AGENTS.md) for architecture, conventions and the contribution workflow. Open work lives in [issues](https://github.com/hamc/blastproof/issues).
327
+ Built with AI assistance using spec-driven development: every change began as a written proposal with its design rationale, and those documents are kept rather than discarded. `openspec/` holds the reasoning behind each decision, including the alternatives that were rejected and why — start at [`AGENTS.md`](./AGENTS.md) for architecture, conventions and the contribution workflow. Open work lives in [issues](https://github.com/hamc/blastproof/issues). Where it is heading is on the [roadmap](https://github.com/users/hamc/projects/2): those issues grouped by horizon (now, next, later) and theme, with no dates.
305
328
 
306
329
  ```bash
307
330
  npm install && npm run build && npm test
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/runner/snapshot.ts
4
+ var DEFAULT_MAX_LINES = 200;
5
+ function indentOf(line) {
6
+ return line.length - line.trimStart().length;
7
+ }
8
+ function trimSnapshot(snapshotYaml, maxLines = DEFAULT_MAX_LINES) {
9
+ let lines = snapshotYaml.split("\n").filter((line) => line.trim().length > 0);
10
+ for (let pass = 0; pass < 5; pass++) {
11
+ const kept = [];
12
+ let removed = 0;
13
+ for (let i = 0; i < lines.length; i++) {
14
+ const line = lines[i];
15
+ const isContainer = line.trimEnd().endsWith(":");
16
+ if (isContainer) {
17
+ const next = lines[i + 1];
18
+ const hasChildren = next !== void 0 && indentOf(next) > indentOf(line);
19
+ if (!hasChildren) {
20
+ removed++;
21
+ continue;
22
+ }
23
+ }
24
+ kept.push(line);
25
+ }
26
+ lines = kept;
27
+ if (removed === 0) break;
28
+ }
29
+ if (lines.length > maxLines) {
30
+ lines = [...lines.slice(0, maxLines), `- ... (snapshot truncated after ${maxLines} lines)`];
31
+ }
32
+ return lines.join("\n");
33
+ }
34
+ async function captureSnapshot(page, options = {}) {
35
+ const raw = await page.locator("body").ariaSnapshot({ mode: "ai" });
36
+ return `url: ${page.url()}
37
+ ${trimSnapshot(raw.replace(/ \[cursor=pointer\]/g, ""), options.maxLines)}`;
38
+ }
39
+ var REF_MARKER = / \[ref=[A-Za-z0-9_-]+\]/g;
40
+ function withoutRefs(snapshot) {
41
+ return snapshot.replace(REF_MARKER, "");
42
+ }
43
+ function unquote(value) {
44
+ const trimmed = value.trim();
45
+ if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
46
+ return trimmed.slice(1, -1).replace(/\\(["\\])/g, "$1");
47
+ }
48
+ if (trimmed.length >= 2 && trimmed.startsWith("'") && trimmed.endsWith("'")) {
49
+ return trimmed.slice(1, -1).replace(/''/g, "'");
50
+ }
51
+ return trimmed;
52
+ }
53
+ var ELEMENT_LINE = /^\s*- ([a-z][a-zA-Z]*)(?: ("(?:[^"\\]|\\.)*"))?((?: \[[^\]]*\])*)(?::(?: (.*))?)?$/;
54
+ function indexRefs(snapshot) {
55
+ const index = /* @__PURE__ */ new Map();
56
+ for (const raw of snapshot.split("\n")) {
57
+ const quoted = /^(\s*- )'((?:[^']|'')*)'(:.*)?$/.exec(raw);
58
+ const line = quoted ? `${quoted[1]}${quoted[2].replace(/''/g, "'")}${quoted[3] ?? ""}` : raw;
59
+ const match = ELEMENT_LINE.exec(line);
60
+ if (!match) continue;
61
+ const ref = /\[ref=([A-Za-z0-9_-]+)\]/.exec(match[3] ?? "")?.[1];
62
+ if (!ref) continue;
63
+ const element = { role: match[1] };
64
+ if (match[2] !== void 0) element.name = unquote(match[2]);
65
+ if (match[4] !== void 0 && match[4].trim() !== "") element.text = unquote(match[4]);
66
+ index.set(ref, element);
67
+ }
68
+ return index;
69
+ }
70
+
71
+ export {
72
+ trimSnapshot,
73
+ captureSnapshot,
74
+ withoutRefs,
75
+ indexRefs
76
+ };
77
+ //# sourceMappingURL=chunk-RA4N57HA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runner/snapshot.ts"],"sourcesContent":["import type { Page } from 'playwright';\n\nexport interface SnapshotOptions {\n /** Maximum number of snapshot lines sent to the LLM. Default 200. */\n maxLines?: number;\n}\n\nconst DEFAULT_MAX_LINES = 200;\n\nfunction indentOf(line: string): number {\n return line.length - line.trimStart().length;\n}\n\n/**\n * Trims an aria snapshot: drops empty containers (e.g. `- group:` with no children)\n * and caps the line count. Pure function, exported for tests.\n */\nexport function trimSnapshot(snapshotYaml: string, maxLines: number = DEFAULT_MAX_LINES): string {\n let lines = snapshotYaml.split('\\n').filter((line) => line.trim().length > 0);\n\n // Removing empty containers can empty their parents; iterate until stable (bounded).\n for (let pass = 0; pass < 5; pass++) {\n const kept: string[] = [];\n let removed = 0;\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!;\n const isContainer = line.trimEnd().endsWith(':');\n if (isContainer) {\n const next = lines[i + 1];\n const hasChildren = next !== undefined && indentOf(next) > indentOf(line);\n if (!hasChildren) {\n removed++;\n continue;\n }\n }\n kept.push(line);\n }\n lines = kept;\n if (removed === 0) break;\n }\n\n if (lines.length > maxLines) {\n lines = [...lines.slice(0, maxLines), `- ... (snapshot truncated after ${maxLines} lines)`];\n }\n return lines.join('\\n');\n}\n\n/**\n * Captures the current page as a compact accessibility snapshot (design D1),\n * prefixed with the page URL so the model can reason about navigation.\n *\n * Always in AI mode (design act-on-the-element-the-model-read, D3): every\n * element carries the `[ref=…]` an action names it by, and a plain\n * `ariaSnapshot()` invalidates the refs of the last AI-mode one, measured. The\n * `[cursor=pointer]` marker it adds is dropped: it is about the mouse, not the\n * element, and it was most of the growth that was not a ref.\n */\nexport async function captureSnapshot(page: Page, options: SnapshotOptions = {}): Promise<string> {\n const raw = await page.locator('body').ariaSnapshot({ mode: 'ai' });\n return `url: ${page.url()}\\n${trimSnapshot(raw.replace(/ \\[cursor=pointer\\]/g, ''), options.maxLines)}`;\n}\n\nconst REF_MARKER = / \\[ref=[A-Za-z0-9_-]+\\]/g;\n\n/**\n * The snapshot as a reader that chooses no element sees it: the judge and the\n * planner (design act-on-the-element-the-model-read, D3). Refs are ids, not\n * page content, and the judge corpus's stored snapshots have none.\n */\nexport function withoutRefs(snapshot: string): string {\n return snapshot.replace(REF_MARKER, '');\n}\n\n/** What the snapshot line holding a ref shows about its element. */\nexport interface SnapshotElement {\n role: string;\n /** The accessible name, unquoted; absent when the line has none. */\n name?: string;\n /** Inline text after the colon (`- generic [ref=e4]: Promo code`), unquoted. */\n text?: string;\n}\n\n/** Undoes YAML double-quote escaping, the form a name containing `\"` is printed in. */\nfunction unquote(value: string): string {\n const trimmed = value.trim();\n if (trimmed.length >= 2 && trimmed.startsWith('\"') && trimmed.endsWith('\"')) {\n return trimmed.slice(1, -1).replace(/\\\\([\"\\\\])/g, '$1');\n }\n if (trimmed.length >= 2 && trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\")) {\n return trimmed.slice(1, -1).replace(/''/g, \"'\");\n }\n return trimmed;\n}\n\n// `- role \"name\" [attr] [ref=x] [attr]: inline text`, every part after the role optional.\nconst ELEMENT_LINE =\n /^\\s*- ([a-z][a-zA-Z]*)(?: (\"(?:[^\"\\\\]|\\\\.)*\"))?((?: \\[[^\\]]*\\])*)(?::(?: (.*))?)?$/;\n\n/**\n * Each ref in a snapshot, with the role and name its line shows (design\n * act-on-the-element-the-model-read, D2). Read from the snapshot text the model\n * was given, masked as it was, so what is checked and recorded is what the\n * model read and no secret enters the record.\n */\nexport function indexRefs(snapshot: string): Map<string, SnapshotElement> {\n const index = new Map<string, SnapshotElement>();\n for (const raw of snapshot.split('\\n')) {\n // YAML single-quotes a whole entry whose text holds `: `, as in\n // `- 'heading \"Notes on file: 1\" [level=2] [ref=e16]'`.\n const quoted = /^(\\s*- )'((?:[^']|'')*)'(:.*)?$/.exec(raw);\n const line = quoted ? `${quoted[1]}${quoted[2]!.replace(/''/g, \"'\")}${quoted[3] ?? ''}` : raw;\n const match = ELEMENT_LINE.exec(line);\n if (!match) continue;\n const ref = /\\[ref=([A-Za-z0-9_-]+)\\]/.exec(match[3] ?? '')?.[1];\n if (!ref) continue;\n const element: SnapshotElement = { role: match[1]! };\n if (match[2] !== undefined) element.name = unquote(match[2]);\n if (match[4] !== undefined && match[4].trim() !== '') element.text = unquote(match[4]);\n index.set(ref, element);\n }\n return index;\n}\n"],"mappings":";;;AAOA,IAAM,oBAAoB;AAE1B,SAAS,SAAS,MAAsB;AACtC,SAAO,KAAK,SAAS,KAAK,UAAU,EAAE;AACxC;AAMO,SAAS,aAAa,cAAsB,WAAmB,mBAA2B;AAC/F,MAAI,QAAQ,aAAa,MAAM,IAAI,EAAE,OAAO,CAAC,SAAS,KAAK,KAAK,EAAE,SAAS,CAAC;AAG5E,WAAS,OAAO,GAAG,OAAO,GAAG,QAAQ;AACnC,UAAM,OAAiB,CAAC;AACxB,QAAI,UAAU;AACd,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,YAAM,OAAO,MAAM,CAAC;AACpB,YAAM,cAAc,KAAK,QAAQ,EAAE,SAAS,GAAG;AAC/C,UAAI,aAAa;AACf,cAAM,OAAO,MAAM,IAAI,CAAC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