@booki-aui/readiness 0.2.3 → 0.2.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @booki/readiness
2
2
 
3
+ ## 0.2.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#171](https://github.com/Walgermo/booki/pull/171) [`99d0d1c`](https://github.com/Walgermo/booki/commit/99d0d1c582b19048f88c2c2929b62825b2e9cc8b) Thanks [@Walgermo](https://github.com/Walgermo)! - `IconButton`: an icon button named by what it does. `label` is required ("Delete line 2"); it is the button's accessible name and tooltip, so an agent presses it by those words and a screen reader says them, and the icon is hidden. Pass any icon, such as `<TrashIcon />` from `@booki-aui/icons/react`; `showLabel` adds the label as visible text. It is ui-sdk's Button underneath, so `data-agent-confirm` and pending states work as on any button. Readiness now calls a nameless icon-only button that and points to `IconButton`, and flags a Booki icon shown at a size other than 16 or 20 px (minor, 1 point).
8
+
9
+ ## 0.2.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [#157](https://github.com/Walgermo/booki/pull/157) [`67b9c9b`](https://github.com/Walgermo/booki/commit/67b9c9bc2226a48de5729fd620aa3a921a2bf1a5) Thanks [@Walgermo](https://github.com/Walgermo)! - `snapshot-values` checks a value read from a document (`{ value, confidence }`, a supplier invoice's fields) by the amount or date it holds instead of rejecting the wrapper. Bridge coverage lets a grid cell with `aria-readonly="false"` override its read-only grid, so an editable cell the bridge leaves out is reported.
14
+
15
+ - [#151](https://github.com/Walgermo/booki/pull/151) [`6d56262`](https://github.com/Walgermo/booki/commit/6d562622bbafec1c3b5a1d421c5ce1a6631b1e43) Thanks [@Walgermo](https://github.com/Walgermo)! - The audit and the conformance suite judge fewer things wrong:
16
+
17
+ - A WebMCP snapshot tool that answers in plain text, not a list of controls, is no longer read as an empty list, so the page's fields are not each counted missing from it.
18
+ - A read-only field (native `readOnly` on a text input or textarea, or inside `aria-readonly="true"`) is not counted as missing from the bridge: no one can change it.
19
+ - A page with no fields or charts is measured when something else was found (a focusable cell, an ungated posting button) or when it registers WebMCP tools of its own, so `--fail-under` judges its score instead of "no score".
20
+ - A WebMCP tool registered again with the same object and a new signal stays when the older signal aborts.
21
+ - `approveUnderRule`, a canonical agent action, is not reported as a person-only action.
22
+ - `server-person-only` asks as an agent that holds the roles granting the permission, and checks that a person with the same roles is let through; a new `serverActor` option gives those roles (default `[permission]`). A permission it cannot verify is reported as such, not passed.
23
+ - `snapshot-secrets` no longer reads an amount in minor units as a bank account number; `snapshot-values` checks nested lists (a voucher's lines) and a date control's `value`; `recording-agent` accepts one attributed event per change.
24
+
3
25
  ## 0.2.3
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -151,6 +151,7 @@ The target takes these options, all optional:
151
151
  | `closedList` | `{ step, valid }`: a bad value and every valid choice its refusal must name (4.3). |
152
152
  | `personOnly` | Steps only a person may take, which the agent must be refused (5.1). |
153
153
  | `server` | Your write gate, `(actor, permission) => { status }`, asked for each person-only permission as an agent and once unsigned (5.1, 7.3). |
154
+ | `serverActor` | `(permission) => { id, roles }`: an actor your `server` would otherwise let do that permission. The person-only check asks as an agent with these roles and as a person with them (default roles: `[permission]`). |
154
155
  | `normalizeEvent` | Maps your bridge's event to `{ source, actor }` when it is not that shape already (6.1). |
155
156
 
156
157
  The checks, with the section each enforces:
@@ -159,14 +160,14 @@ The checks, with the section each enforces:
159
160
  | --- | --- | --- | --- |
160
161
  | `bridge-shape` | 2 | MUST | `snapshot`, `act` and `subscribe` are functions, and `snapshot` returns an array. |
161
162
  | `snapshot-named` | 3.1 | MUST | Every component has a `ref`, `component`, `label` and string `actions`; labels are unique. |
162
- | `snapshot-values` | 3.2 | MUST | Minor-unit values are integers or `null`; dates are `YYYY-MM-DD` or `null`. |
163
- | `snapshot-secrets` | 3.5 | MUST | The snapshot holds none of the literal `secrets` and no secret pattern (the same finder as the audit). |
163
+ | `snapshot-values` | 3.2 | MUST | Minor-unit values are integers or `null`; dates (and a date control's `value`) are `YYYY-MM-DD` or `null`, at every level, lists included. |
164
+ | `snapshot-secrets` | 3.5 | MUST | The snapshot holds none of the literal `secrets` and no secret pattern (the same finder as the audit; amounts in minor units are not read as account numbers). |
164
165
  | `act-never-throws` | 4.5 | MUST | `act()` refuses an unknown ref and an unknown action with `ok: false` and a message, without throwing. |
165
166
  | `amount-minor-only` | 4.2 | MUST | `setMinor` refuses fractions and formatted text. |
166
167
  | `closed-list` | 4.3 | MUST | A bad value for a closed list is refused, and the refusal names every valid choice. |
167
- | `person-only-not-offered` | 5.1 | MUST | No action named as a person's decision (approve, sign off, …) is offered, and `personOnly` steps are refused. |
168
- | `recording-agent` | 6.1 | MUST | The `drive` step records exactly one event whose actor starts with `agent:`. |
169
- | `server-person-only` | 5.1 | MUST | The `server` refuses an agent for every person-only permission. |
168
+ | `person-only-not-offered` | 5.1 | MUST | No action named as a person's decision (approve, sign off, …) is offered, and `personOnly` steps are refused. `approveUnderRule`, which runs only under a company rule, is not one. |
169
+ | `recording-agent` | 6.1 | MUST | The `drive` step records at least one agent event (one per change), and every one has an actor that starts with `agent:`. |
170
+ | `server-person-only` | 5.1 | MUST | The `server` refuses an agent holding the granting roles (`serverActor`) for every person-only permission, and lets a person with the same roles through. A permission whose person is refused too is listed as not verified; when none can be verified, the check skips. |
170
171
  | `refusal-names-valid` | 12.2 | MUST | A refusal for an unknown ref names the controls that exist, and a refusal for an unknown action names the valid actions. |
171
172
  | `server-unsigned` | 7.3 | SHOULD | An unsigned request to the `server` gets 401. |
172
173
 
@@ -210,8 +211,9 @@ Each check names the Agent Contract section it enforces.
210
211
  | Fields that share one name | §3.1, §4.1 | Two or more fields of one role with the same name (one finding per group): the agent has to count. | 2 / 8 |
211
212
  | Field missing from the bridge | §3.1, §4.1 | On a page whose bridge has a snapshot: a named field a person can use (textbox, searchbox, combobox, listbox, spinbutton, checkbox, radio group, switch, slider) that no bridge entry covers, so an agent on the bridge cannot operate it. A field is covered when its name equals an entry's `label`, or when it sits inside the element of a bridge component: ui-sdk marks a component's root with `data-slot="<component>"` and its other parts with `data-slot="<component>-<part>"`, so the outermost such element of each kind counts. When the page has more of those elements than the snapshot has entries of that kind, only one named by an entry's label counts. A radio is covered by its group's name and reported once, as the group. Disabled fields, fields inside `data-agent-hidden` and the hidden inputs above are skipped, and the check does not run when the snapshot was cut short (a `more` entry). | 5 / 30 |
212
213
  | Focusable element that is not a control | §3.1, §4.1 | An element with `tabindex` ≥ 0 that the tree calls a cell or plain text, such as a grid cell that opens an editor on click. | 3 / 12 |
213
- | Button without a name | §3.1, §4.1 | A button whose name is empty. | 3 / 12 |
214
+ | Button without a name | §3.1, §4.1 | A button whose name is empty. One that shows only an icon (an SVG, an image or an icon font) is called an icon-only button, and the report points to `IconButton` from `@booki-aui/react`, whose `label` is required. | 3 / 12 |
214
215
  | Button named by an icon font | §3.1, §4.1 | A button whose name is an icon ligature (`close`, `content_copy`, `more_vert`, any snake_case word), or any single lowercase word drawn in an icon font. | 2 / 10 |
216
+ | Icon at a size it is not drawn for | §3.1 | A Booki icon (`svg[data-icon]` from `@booki-aui/icons`) shown at a size other than 16 or 20 px, where its lines blur. It changes nothing an agent reads. | 1 / 3 |
215
217
  | Figures only in pixels | §3.3 | A canvas or SVG chart, visible to the agent, whose name, description, fallback content and the table in its figure hold fewer than two numbers. Icons (small, inside a button or link, or fewer than three shapes) and `aria-hidden` charts are skipped. | 10 / 30 |
216
218
  | Irreversible button without a gate | §5.2 | A button or link that posts, pays, sends, approves, creates, submits, releases or signs (Bokfør, Opprett, Godkjenn, Betal, Send, Attester, Signer, Overfør, Post, Pay, Approve, Submit, Release, Sign off, …) with no `data-agent-confirm` on it or an ancestor, and no `confirm` on its bridge button. | 10 / 20 |
217
219
  | Secret readable by the agent | §3.5 | A Norwegian account number (mod 11), an IBAN (mod 97), a KID next to the word KID (mod 10 or 11), a US routing number next to "routing" (ABA) or a card number next to "card"/"kort" (Luhn) in the accessibility snapshot or the bridge's snapshot. Only numbers with valid check digits count, so amounts, dates and invoice numbers do not. A value inside `data-agent-secret` on a page with a bridge is redacted by the bridge and not reported. | 8 / 16 |
@@ -248,7 +250,9 @@ no controls and the page has no fields or charts for the other checks to judge.
248
250
  A page without a bridge but with fields is still scored (and gets
249
251
  `bridge-missing`). A bridge with no controls on a page that has fields of its
250
252
  own is scored too: each field is reported as `field-not-on-bridge`, so it is
251
- not a pass. When nothing is there to judge, the tool prints `no score` instead of a figure, the HTML report says the same,
253
+ not a pass. So is a page with no fields or charts where a check still found
254
+ something (a focusable cell, an ungated posting button), or that registers
255
+ WebMCP tools of its own. When nothing is there to judge, the tool prints `no score` instead of a figure, the HTML report says the same,
252
256
  and the JSON report has `measured: false`, `grade: "not measured"` and a
253
257
  `notMeasured` text. `score` stays in the JSON so its shape does not change,
254
258
  but it is not a pass. With `--fail-under`, an unmeasured page exits with code 1.
@@ -1,5 +1,5 @@
1
1
  // src/person-action.ts
2
- var PERSON_ACTION = /^(approve|reject|escalate|release|sign[_-]?off|finali[sz]e|submit|closePeriod|lockPeriod|dispose)/i;
2
+ var PERSON_ACTION = /^(?!approveUnderRule$)(approve|reject|escalate|release|sign[_-]?off|finali[sz]e|submit|closePeriod|lockPeriod|dispose)/i;
3
3
 
4
4
  // src/secrets.ts
5
5
  var digits = (value) => value.replace(/\D/g, "");
@@ -2,7 +2,7 @@ import {
2
2
  PERSON_ACTION,
3
3
  SECRET_LABEL,
4
4
  findSecrets
5
- } from "./chunk-5SCOA3ZP.js";
5
+ } from "./chunk-PRRNS5HS.js";
6
6
 
7
7
  // src/rules.ts
8
8
  var RULES = {
@@ -112,6 +112,17 @@ var RULES = {
112
112
  points: 2,
113
113
  cap: 10
114
114
  },
115
+ "icon-size": {
116
+ id: "icon-size",
117
+ title: "Icon at a size it is not drawn for",
118
+ contract: "\xA73.1 (presentation)",
119
+ severity: "minor",
120
+ why: "Booki's icons are drawn for 16 and 20 px. In between, their lines fall between pixels and blur, so a status icon beside a figure reads as a smudge. It does not change what an agent reads, which is why it costs little.",
121
+ fix: "Show the icon at size={16} or size={20}, and let the button or row around it take the space.",
122
+ booki: "size={16 | 20} on any @booki-aui/icons component",
123
+ points: 1,
124
+ cap: 3
125
+ },
115
126
  "chart-pixels-only": {
116
127
  id: "chart-pixels-only",
117
128
  title: "Figures only in pixels",
@@ -248,25 +259,31 @@ function inPage(fn) {
248
259
  }
249
260
  var INIT_SCRIPT = `(() => {
250
261
  const tools = [];
262
+ // The current registration of each name: an abort removes the tool only while its registration is current.
263
+ const current = new Map();
251
264
  Object.defineProperty(globalThis, "__readinessTools", { value: tools, configurable: true });
265
+ const remove = (name) => { const i = tools.findIndex((t) => t.name === name); if (i >= 0) tools.splice(i, 1); current.delete(name); };
252
266
  const add = (tool) => {
253
- if (!tool || typeof tool !== "object") return;
267
+ if (!tool || typeof tool !== "object") return null;
254
268
  const i = tools.findIndex((t) => t.name === tool.name);
255
269
  if (i >= 0) tools.splice(i, 1, tool); else tools.push(tool);
270
+ const token = {};
271
+ current.set(tool.name, token);
272
+ return token;
256
273
  };
257
274
  const context = {
258
275
  registerTool(tool, options) {
259
276
  const signal = options && options.signal;
260
277
  if (signal && signal.aborted) return Promise.resolve();
261
- add(tool);
262
- if (signal && typeof signal.addEventListener === "function") {
263
- signal.addEventListener("abort", () => { const i = tools.indexOf(tool); if (i >= 0) tools.splice(i, 1); }, { once: true });
278
+ const token = add(tool);
279
+ if (token && signal && typeof signal.addEventListener === "function") {
280
+ signal.addEventListener("abort", () => { if (current.get(tool.name) === token) remove(tool.name); }, { once: true });
264
281
  }
265
282
  return Promise.resolve();
266
283
  },
267
- unregisterTool(name) { const i = tools.findIndex((t) => t.name === name); if (i >= 0) tools.splice(i, 1); return Promise.resolve(); },
268
- provideContext(value) { tools.length = 0; for (const tool of (value && value.tools) || []) add(tool); return Promise.resolve(); },
269
- clearContext() { tools.length = 0; return Promise.resolve(); },
284
+ unregisterTool(name) { remove(name); return Promise.resolve(); },
285
+ provideContext(value) { tools.length = 0; current.clear(); for (const tool of (value && value.tools) || []) add(tool); return Promise.resolve(); },
286
+ clearContext() { tools.length = 0; current.clear(); return Promise.resolve(); },
270
287
  };
271
288
  try { if (!document.modelContext) Object.defineProperty(document, "modelContext", { value: context, configurable: true }); } catch {}
272
289
  try { if (!navigator.modelContext) Object.defineProperty(navigator, "modelContext", { value: context, configurable: true }); } catch {}
@@ -345,6 +362,23 @@ function describeElement(element2) {
345
362
  );
346
363
  });
347
364
  };
365
+ const glyph = (el) => {
366
+ const family = getComputedStyle(el).fontFamily;
367
+ const classes = typeof el.className === "string" ? el.className : "";
368
+ return iconPattern.test(family) || /(^|\s)(material-(icons|symbols)[\w-]*|icon[\w-]*|[\w-]+-icon|fa|fa-[\w-]+|glyphicon[\w-]*)(\s|$)/i.test(classes);
369
+ };
370
+ const labelText = (el) => {
371
+ let text = "";
372
+ for (const node of el.childNodes) {
373
+ if (node.nodeType === 3) text += node.textContent ?? "";
374
+ else if (node.nodeType === 1) {
375
+ const child = node;
376
+ if (child.getAttribute("aria-hidden") === "true" || glyph(child)) continue;
377
+ text += labelText(child);
378
+ }
379
+ }
380
+ return text;
381
+ };
348
382
  const html = (el) => {
349
383
  const copy = el.cloneNode(true);
350
384
  const text = copy.outerHTML.replace(/\s+/g, " ");
@@ -376,6 +410,7 @@ function describeElement(element2) {
376
410
  confirm: confirmHost ? confirmHost.getAttribute("data-agent-confirm") || "(marked)" : null,
377
411
  secret: element2.closest("[data-agent-secret]") !== null,
378
412
  iconFont: usesIconFont(element2),
413
+ iconOnly: !clean(labelText(element2)) && (element2.querySelector("svg, img") !== null || usesIconFont(element2)),
379
414
  disabled: element2.disabled === true || element2.getAttribute("aria-disabled") === "true",
380
415
  hidden: hiddenFromPeople(element2)
381
416
  };
@@ -436,21 +471,27 @@ async function readBridge() {
436
471
  try {
437
472
  return toList(JSON.parse(text));
438
473
  } catch {
439
- return [];
474
+ return null;
440
475
  }
441
476
  }
442
477
  }
443
- return [];
478
+ return null;
444
479
  };
445
480
  try {
446
481
  if (typeof g.agent?.snapshot === "function") {
447
- const components = toList(await g.agent.snapshot());
448
- return { source: "window.agent", components, tools, snapshotRead: true, error: null };
482
+ const list = toList(await g.agent.snapshot());
483
+ return {
484
+ source: "window.agent",
485
+ components: list ?? [],
486
+ tools,
487
+ snapshotRead: list !== null,
488
+ error: null
489
+ };
449
490
  }
450
491
  const snapshotTool = (g.__readinessTools ?? []).find((tool) => tool.name === "snapshot");
451
492
  if (snapshotTool?.execute) {
452
- const components = toList(await snapshotTool.execute({}));
453
- return { source: "webmcp", components, tools, snapshotRead: true, error: null };
493
+ const list = toList(await snapshotTool.execute({}));
494
+ return { source: "webmcp", components: list ?? [], tools, snapshotRead: list !== null, error: null };
454
495
  }
455
496
  return { source: tools.length ? "webmcp" : null, components: [], tools, snapshotRead: false, error: null };
456
497
  } catch (error) {
@@ -499,7 +540,28 @@ function bridgeCoverage(element2, entries) {
499
540
  const name = host ? nameOf(host) : "";
500
541
  if (host && name) group = { name, covered: allLabels.has(norm(name)) || inside(host) };
501
542
  }
502
- return { inRoot: inside(element2), agentHidden: element2.closest("[data-agent-hidden]") !== null, group };
543
+ const textLike = element2.tagName === "TEXTAREA" || element2.tagName === "INPUT" && !["checkbox", "radio", "file", "range", "color", "hidden", "button", "submit", "reset", "image"].includes(
544
+ element2.type
545
+ );
546
+ const readOnly = textLike && element2.readOnly === true || element2.closest("[aria-readonly]")?.getAttribute("aria-readonly") === "true";
547
+ return {
548
+ inRoot: inside(element2),
549
+ agentHidden: element2.closest("[data-agent-hidden]") !== null,
550
+ readOnly,
551
+ group
552
+ };
553
+ }
554
+ function findOffSizeIcons() {
555
+ const drawn = [16, 20];
556
+ const out = [];
557
+ for (const svg of document.querySelectorAll("svg[data-icon]")) {
558
+ const box = svg.getBoundingClientRect();
559
+ if (box.width <= 1 || box.height <= 1) continue;
560
+ const size = Math.round(box.width * 10) / 10;
561
+ if (drawn.includes(size)) continue;
562
+ out.push({ name: svg.getAttribute("data-icon") ?? "", size, html: svg.outerHTML.slice(0, 160) });
563
+ }
564
+ return out;
503
565
  }
504
566
  function findFocusableNonControls() {
505
567
  const native = "a[href], button, input, select, textarea, summary, details, iframe, audio, video, [contenteditable=''], [contenteditable=true]";
@@ -585,6 +647,7 @@ var DESCRIBE = inPage(describeElement);
585
647
  var READ_BRIDGE = inPage(readBridge);
586
648
  var FIND_FOCUSABLE = inPage(findFocusableNonControls);
587
649
  var FIND_CHARTS = inPage(findCharts);
650
+ var FIND_OFF_SIZE_ICONS = inPage(findOffSizeIcons);
588
651
  var ONLY_IN_SECRETS = inPage(onlyInSecrets);
589
652
  var BRIDGE_COVERAGE = inPage(bridgeCoverage);
590
653
  var BROKEN_NAME = /\[object \w+\]|\bundefined\b|\bnull\b|\bNaN\b/;
@@ -787,7 +850,8 @@ async function check(page, url = page.url()) {
787
850
  if (!name || BROKEN_NAME.test(name) || node.flags.includes("disabled") || !node.ref) continue;
788
851
  if (labels.has(norm(name))) continue;
789
852
  const coverage = await page.locator(`aria-ref=${node.ref}`).evaluate(BRIDGE_COVERAGE, entries, { timeout: 2e3 }).catch(() => null);
790
- if (!coverage || coverage.inRoot || coverage.agentHidden || coverage.group?.covered) continue;
853
+ if (!coverage || coverage.inRoot || coverage.agentHidden || coverage.readOnly || coverage.group?.covered)
854
+ continue;
791
855
  const group = coverage.group;
792
856
  if (group) {
793
857
  if (seenGroups.has(norm(group.name))) continue;
@@ -828,7 +892,12 @@ async function check(page, url = page.url()) {
828
892
  const name = node.name.trim();
829
893
  if (node.role === "button" && !name) {
830
894
  const info = await describe(page, node);
831
- findings.push({ rule: "button-unnamed", message: "A button with no name.", element: element(node, info) });
895
+ findings.push({
896
+ rule: "button-unnamed",
897
+ message: info?.iconOnly ? "An icon-only button with no name." : "A button with no name.",
898
+ element: element(node, info),
899
+ booki: info?.iconOnly ? 'IconButton from @booki-aui/react: label is required ("Delete line 2")' : void 0
900
+ });
832
901
  continue;
833
902
  }
834
903
  if (node.role !== "link") {
@@ -856,6 +925,13 @@ async function check(page, url = page.url()) {
856
925
  }
857
926
  }
858
927
  }
928
+ for (const icon of await page.evaluate(FIND_OFF_SIZE_ICONS)) {
929
+ findings.push({
930
+ rule: "icon-size",
931
+ message: `The "${icon.name}" icon is shown at ${icon.size} px; it is drawn for 16 and 20.`,
932
+ element: { role: "img", name: icon.name, html: icon.html }
933
+ });
934
+ }
859
935
  const charts = await page.evaluate(FIND_CHARTS);
860
936
  const chartLocator = page.locator("canvas, svg");
861
937
  for (const chart of charts) {
@@ -930,7 +1006,7 @@ async function check(page, url = page.url()) {
930
1006
  for (const control of controls) control.label = redact(control.label);
931
1007
  const title = await page.title();
932
1008
  const result = score(findings);
933
- const measured = bridge.components > 0 || fields.length > 0 || charts.length > 0;
1009
+ const measured = bridge.components > 0 || ownTools.length > 0 || fields.length > 0 || charts.length > 0 || findings.some((f) => f.rule !== "bridge-missing");
934
1010
  return {
935
1011
  tool: { name: "@booki-aui/readiness", version: VERSION },
936
1012
  url,
@@ -997,8 +1073,10 @@ function toConsole(report) {
997
1073
  out.push(
998
1074
  `${sevMark(rule.severity)} ${bold(rule.title)} ${dim(`(${rule.contract}) \u2212${d.points}`)} \xD7${list.length}`
999
1075
  );
1000
- for (const f of list.slice(0, 6))
1076
+ for (const f of list.slice(0, 6)) {
1001
1077
  out.push(` ${f.message}${f.element?.selector ? dim(` ${f.element.selector}`) : ""}`);
1078
+ if (f.booki && f.booki !== rule.booki) out.push(` ${dim("Booki:")} ${f.booki}`);
1079
+ }
1002
1080
  if (list.length > 6) out.push(dim(` \u2026 and ${list.length - 6} more`));
1003
1081
  out.push(` ${dim("Fix:")} ${rule.fix}`);
1004
1082
  if (rule.booki) out.push(` ${dim("Booki:")} ${rule.booki}`);
package/dist/cli.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  toConsole,
5
5
  toHtml,
6
6
  toJson
7
- } from "./chunk-OLKBQ7N4.js";
8
- import "./chunk-5SCOA3ZP.js";
7
+ } from "./chunk-SCZED25V.js";
8
+ import "./chunk-PRRNS5HS.js";
9
9
 
10
10
  // src/cli.ts
11
11
  import { writeFileSync } from "fs";
@@ -31,6 +31,15 @@ type ConformanceTarget = {
31
31
  personOnly?: ActStep[];
32
32
  /** Your server's write gate; asked for every permission in section 5.1 as an agent. */
33
33
  server?: (actor: ServerActor | null, permission: string) => ServerAnswer | Promise<ServerAnswer>;
34
+ /**
35
+ * The id and roles of an actor your server would otherwise let do `permission`. The
36
+ * person-only check asks as an agent with them (refused) and as a person with them (let
37
+ * through). Default: roles `[permission]`.
38
+ */
39
+ serverActor?: (permission: string) => {
40
+ id: string;
41
+ roles: string[];
42
+ };
34
43
  /** Map your bridge's event to {source, actor}; default is identity. */
35
44
  normalizeEvent?: (raw: unknown) => BridgeEvent;
36
45
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PERSON_ACTION,
3
3
  findSecrets
4
- } from "./chunk-5SCOA3ZP.js";
4
+ } from "./chunk-PRRNS5HS.js";
5
5
  import {
6
6
  PERSON_ONLY_PERMISSIONS
7
7
  } from "./chunk-IZ57MB25.js";
@@ -24,6 +24,9 @@ var isNamed = (value) => typeof value === "string" && value.length > 0;
24
24
  var isMinorKey = (key) => key === "minor" || key.endsWith("Minor");
25
25
  var isDateKey = (key) => key === "date" || key.endsWith("Date");
26
26
  var DATE = /^\d{4}-\d{2}-\d{2}$/;
27
+ var isExtracted = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && "value" in value && typeof value.confidence === "number";
28
+ var DATE_COMPONENTS = /* @__PURE__ */ new Set(["financial-date", "field-date"]);
29
+ var AMOUNT_COMPONENTS = /* @__PURE__ */ new Set(["amount-field", "field-amount"]);
27
30
  var checks = [
28
31
  {
29
32
  id: "bridge-shape",
@@ -66,22 +69,27 @@ var checks = [
66
69
  run: async (target) => {
67
70
  const snap = await components(target);
68
71
  const bad = [];
69
- for (const c of snap) {
70
- for (const [key, value] of Object.entries(c)) {
71
- if (isMinorKey(key) && !(value === null || Number.isInteger(value))) {
72
- bad.push(`${c.ref}.${key}=${JSON.stringify(value)}`);
73
- }
74
- if (isDateKey(key) && !(value === null || typeof value === "string" && DATE.test(value))) {
75
- bad.push(`${c.ref}.${key}=${JSON.stringify(value)}`);
76
- }
77
- if (value !== null && typeof value === "object" && !Array.isArray(value)) {
78
- for (const [inner, innerValue] of Object.entries(value)) {
79
- if (isMinorKey(inner) && !(innerValue === null || Number.isInteger(innerValue))) {
80
- bad.push(`${c.ref}.${key}.${inner}=${JSON.stringify(innerValue)}`);
81
- }
82
- }
83
- }
72
+ const visit = (value, path, key, dateValue) => {
73
+ if ((isMinorKey(key) || isDateKey(key)) && isExtracted(value)) {
74
+ visit(value.value, `${path}.value`, key, false);
75
+ return;
76
+ }
77
+ if (isMinorKey(key) && !(value === null || Number.isInteger(value)))
78
+ bad.push(`${path}=${JSON.stringify(value)}`);
79
+ const isDate = value === null || typeof value === "string" && DATE.test(value);
80
+ if (isDateKey(key) && !isDate || dateValue && !isDate && value !== "") {
81
+ bad.push(`${path}=${JSON.stringify(value)}`);
84
82
  }
83
+ if (Array.isArray(value)) value.forEach((item, i) => visit(item, `${path}[${i}]`, "", false));
84
+ else if (value !== null && typeof value === "object") {
85
+ for (const [inner, innerValue] of Object.entries(value))
86
+ visit(innerValue, `${path}.${inner}`, inner, false);
87
+ }
88
+ };
89
+ for (const c of snap) {
90
+ const dateControl = DATE_COMPONENTS.has(c.component) || c.kind === "date";
91
+ for (const [key, value] of Object.entries(c))
92
+ visit(value, `${c.ref}.${key}`, key, dateControl && key === "value");
85
93
  }
86
94
  if (bad.length > 0) {
87
95
  return fail(`Minor-unit values must be integers or null, dates YYYY-MM-DD or null: ${bad.join("; ")}.`);
@@ -98,7 +106,13 @@ var checks = [
98
106
  const json = JSON.stringify(snap);
99
107
  const literal = (target.secrets ?? []).filter((s) => typeof s === "string" && s.length > 0);
100
108
  const leaked = literal.filter((s) => json.includes(s));
101
- const found = findSecrets(json).map((hit) => hit.kind);
109
+ const withoutAmounts = snap.map(
110
+ (c) => JSON.stringify(
111
+ c,
112
+ (key, value) => typeof value === "number" && (isMinorKey(key) || key === "value" && AMOUNT_COMPONENTS.has(c.component)) ? null : value
113
+ )
114
+ );
115
+ const found = findSecrets(`[${withoutAmounts.join(",")}]`).map((hit) => hit.kind);
102
116
  if (leaked.length > 0 || found.length > 0) {
103
117
  const parts = [];
104
118
  if (leaked.length > 0) parts.push(`${leaked.length} literal secret(s)`);
@@ -242,14 +256,13 @@ var checks = [
242
256
  return fail(`The drive step was not performed: ${result?.error?.message ?? "no message"}.`);
243
257
  }
244
258
  const agentEvents = events.filter((e) => e.source === "agent");
245
- if (agentEvents.length !== 1) {
246
- return fail(`Expected exactly one agent event for the drive step, got ${agentEvents.length}.`);
247
- }
248
- const [event] = agentEvents;
249
- if (typeof event.actor !== "string" || !event.actor.startsWith("agent:")) {
250
- return fail(`The agent event has actor ${JSON.stringify(event.actor)}; it must start with "agent:".`);
259
+ if (agentEvents.length === 0) return fail("The drive step recorded no agent event.");
260
+ const unattributed = agentEvents.find((e) => typeof e.actor !== "string" || !e.actor.startsWith("agent:"));
261
+ if (unattributed) {
262
+ return fail(`An agent event has actor ${JSON.stringify(unattributed.actor)}; it must start with "agent:".`);
251
263
  }
252
- return pass(`One agent event recorded with actor ${event.actor}.`);
264
+ const actors = [...new Set(agentEvents.map((e) => e.actor))].join(", ");
265
+ return pass(`${agentEvents.length} agent event(s) recorded, each with an agent actor (${actors}).`);
253
266
  } finally {
254
267
  if (typeof unsubscribe === "function") unsubscribe();
255
268
  }
@@ -261,17 +274,28 @@ var checks = [
261
274
  level: "MUST",
262
275
  run: async (target) => {
263
276
  if (!target.server) return skip("No server gate was given.");
264
- const actor = { kind: "agent", id: "conformance", roles: ["owner"] };
265
277
  const notRefused = [];
278
+ const unverified = [];
266
279
  for (const permission of PERSON_ONLY_PERMISSIONS) {
267
- const answer = await target.server(actor, permission);
268
- if (answer?.status !== 403) notRefused.push(`${permission} (${answer?.status})`);
280
+ const fixture = target.serverActor?.(permission) ?? { id: "conformance", roles: [permission] };
281
+ const answer = await target.server({ kind: "agent", ...fixture }, permission);
282
+ if (answer?.status !== 403) {
283
+ notRefused.push(`${permission} (${answer?.status})`);
284
+ continue;
285
+ }
286
+ const person = await target.server({ kind: "person", ...fixture }, permission);
287
+ const status = person?.status;
288
+ if (!(typeof status === "number" && status >= 200 && status < 300))
289
+ unverified.push(`${permission} (${status})`);
269
290
  }
270
291
  if (notRefused.length > 0) {
271
292
  return fail(`The server did not refuse an agent for: ${notRefused.join(", ")}.`);
272
293
  }
294
+ const verified = PERSON_ONLY_PERMISSIONS.length - unverified.length;
295
+ const note = unverified.length > 0 ? ` Not verified, because a person with the same roles was refused too (give serverActor the roles that grant each): ${unverified.join(", ")}.` : "";
296
+ if (verified === 0) return skip(`No person-only permission could be verified.${note}`);
273
297
  return pass(
274
- `The server refuses an agent with 403 for all ${PERSON_ONLY_PERMISSIONS.length} person-only permissions.`
298
+ `The server refuses an agent with 403, and lets a person with the same roles through, for ${verified} of ${PERSON_ONLY_PERMISSIONS.length} person-only permissions.${note}`
275
299
  );
276
300
  }
277
301
  },
package/dist/index.d.ts CHANGED
@@ -18,6 +18,8 @@ type ElementInfo = {
18
18
  secret: boolean;
19
19
  /** The element or a descendant uses an icon font, by family or class. */
20
20
  iconFont: boolean;
21
+ /** The element shows only an icon (an svg, img or icon font) and no text of its own. */
22
+ iconOnly: boolean;
21
23
  disabled: boolean;
22
24
  /**
23
25
  * Out of reach of a person and an agent: aria-hidden or inert on it or an
@@ -32,7 +34,7 @@ type ElementInfo = {
32
34
  * enforces (spec/agent-contract.md), why it matters to an agent, the fix, and
33
35
  * how much it can take off the score.
34
36
  */
35
- type RuleId = "bridge-missing" | "bridge-unnamed-control" | "bridge-person-action" | "field-unnamed" | "field-broken-name" | "field-ambiguous" | "field-not-on-bridge" | "focusable-without-role" | "button-unnamed" | "button-icon-name" | "chart-pixels-only" | "irreversible-ungated" | "secret-visible" | "snapshot-size";
37
+ type RuleId = "bridge-missing" | "bridge-unnamed-control" | "bridge-person-action" | "field-unnamed" | "field-broken-name" | "field-ambiguous" | "field-not-on-bridge" | "focusable-without-role" | "button-unnamed" | "button-icon-name" | "icon-size" | "chart-pixels-only" | "irreversible-ungated" | "secret-visible" | "snapshot-size";
36
38
  type Severity = "critical" | "serious" | "moderate" | "minor";
37
39
  type Rule = {
38
40
  id: RuleId;
@@ -99,8 +101,9 @@ type Report = {
99
101
  score: number;
100
102
  grade: "ready" | "partly ready" | "not ready" | "not measured";
101
103
  /**
102
- * False when the bridge has no controls and the page has no fields or charts:
103
- * the form may not be open yet, so
104
+ * False when the bridge has no controls or tools of the page's own, the page has
105
+ * no fields or charts, and nothing but the missing bridge was found: the form
106
+ * may not be open yet, so
104
107
  * `score` rests on almost nothing and `grade` is "not measured".
105
108
  */
106
109
  measured: boolean;
@@ -164,7 +167,12 @@ declare function audit(input: string, options?: AuditOptions): Promise<Report>;
164
167
  /** Checks an open page. Exposed for callers that drive their own browser. */
165
168
  declare function check(page: Page, url?: string): Promise<Report>;
166
169
 
167
- /** Action names that approve, release or finalize: a person's, never offered to an agent. */
170
+ /**
171
+ * Action names that approve, release or finalize: a person's, never offered to an agent.
172
+ *
173
+ * `approveUnderRule` is not one: it is a canonical agent action (spec/agent-contract.md),
174
+ * run only under a company rule the ERP set and recorded as that rule's.
175
+ */
168
176
  declare const PERSON_ACTION: RegExp;
169
177
 
170
178
  type Scored = {
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  toConsole,
14
14
  toHtml,
15
15
  toJson
16
- } from "./chunk-OLKBQ7N4.js";
16
+ } from "./chunk-SCZED25V.js";
17
17
  import {
18
18
  PERSON_ACTION,
19
19
  findSecrets,
@@ -22,7 +22,7 @@ import {
22
22
  isKontonummer,
23
23
  isLuhn,
24
24
  isRoutingNumber
25
- } from "./chunk-5SCOA3ZP.js";
25
+ } from "./chunk-PRRNS5HS.js";
26
26
  export {
27
27
  IRREVERSIBLE,
28
28
  PERSON_ACTION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@booki-aui/readiness",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Agent readiness check for accounting screens: what stops an AI agent on a page, scored 0-100 against the Agent Contract, with fixes.",
5
5
  "type": "module",
6
6
  "license": "MIT",