@nac3/runtime 2.3.0-alpha.2 → 2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,123 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.3.0 -- 2026-05-13 (stable)
4
+
5
+ NAC3 v2.3.0 is the first stable release of the payload-bearing
6
+ contract. Everything in 2.3.0-alpha.1 and 2.3.0-alpha.2 is rolled
7
+ in; the alpha tags are deprecated. New in stable (beyond the alpha
8
+ preview):
9
+
10
+ ### New primitives
11
+
12
+ - **`NAC.invoke(action_id, payload, opts?)`** -- payload-bearing
13
+ action. Dispatches `nac:action:requested`, awaits the host's
14
+ `nac:action:succeeded` / `:failed` with the same `request_id`.
15
+ Default timeout 30 s. (Promoted from 2.3.0-alpha.1.)
16
+ - **`NAC.utter(action_id, {text, lang?, voice?})`** -- ergonomic
17
+ shortcut for `verb='utter'`. (Promoted from 2.3.0-alpha.1.)
18
+ - **`NAC.bindTab(el, handler, ctx, opts?)`** -- tab companion to
19
+ `bindAction`. Emits `nac:tab:activated` / `:activation_failed`
20
+ for you. Sister of v2.2's `bindAction`.
21
+ - **`NAC.edit_field(nac_id)`** -- field editor primitive promoted
22
+ from preview to GA. Selection, replace, AI syntax correction,
23
+ save/cancel verbs. Modal mounts the `nac_editor` plugin
24
+ idempotently with all 10 locales.
25
+
26
+ ### Shadow DOM resolution (F1 + F6)
27
+
28
+ - **Open shadow DOM**: the runtime walks `el.shadowRoot`
29
+ recursively up to depth 10. Any element with `data-nac-id`
30
+ inside an open shadow root is now resolvable by `NAC.click`,
31
+ `NAC.fill`, `NAC.invoke`, etc. with no glue code.
32
+ - **Closed shadow DOM**: voluntary exposure contract. A
33
+ component MAY expose a `nac3` getter on the host element
34
+ implementing `query(selector)` (mandatory),
35
+ `queryAll(selector)` (recommended), and `describe()` (optional).
36
+ The runtime delegates to those methods.
37
+ - **Error events** for closed shadow:
38
+ - `nac:shadow_blocked` -- emitted once per host with
39
+ `detail.reason` in `'exposure_threw'`, `'not_exposed'`.
40
+ - `nac:shadow_protocol_violation` -- emitted when an exposed
41
+ method returns a non-Element value.
42
+ - All events use `composed: true` so they correctly cross shadow
43
+ boundaries to document-level listeners.
44
+
45
+ ### Auth-aware capabilities (F7)
46
+
47
+ - Manifest entries MAY declare `requires_capability: 'verb_slug'`
48
+ at the element level or per `action.verb`. Array values use
49
+ OR semantics ("at least one cap matches passes").
50
+ - `NAC.setCapabilities([...])`, `NAC.grantCapability(cap)`,
51
+ `NAC.revokeCapability(cap)`, `NAC.userCapabilities()` manage
52
+ the user's capability set.
53
+ - `NAC.click` and `NAC.invoke` gate against the set before
54
+ dispatch. Missing cap -> reject with `code='capability_required'`
55
+ + emit `nac:command:rejected`.
56
+
57
+ ### Strict validation default (F3)
58
+
59
+ - `NAC.STRICT_VALIDATION` default flipped from `false` to **`true`**
60
+ in v2.3 stable, per the v2.2 migration promise.
61
+ `NAC.register` now throws `code='strict_validation'` on
62
+ `manifest_role_unknown` / `tab_id_manifest_role_drift` /
63
+ `manifest_dom_role_mismatch` findings.
64
+ - Opt-out: set `NAC.STRICT_VALIDATION = false` BEFORE any
65
+ `register()` call in your bootstrap. See
66
+ `guides/MIGRATION_v2.2_to_v2.3.md` for the playbook.
67
+
68
+ ### Hotfix carryover from alpha.2
69
+
70
+ - `NAC.invoke` does NOT reject with `code='disabled'` on elements
71
+ with `disabled` or `aria-disabled='true'`. `invoke` is a logical
72
+ payload-bearing request, not a synthetic click. `NAC.click` still
73
+ rejects on disabled (click semantics preserved). Pinned down by
74
+ test v23-invoke.mjs T7/T8/T9 so the relaxation cannot silently
75
+ regress.
76
+
77
+ ### Test surface
78
+
79
+ `npm test` now chains 7 suites (75+ assertions):
80
+ smoke, v22, v23-invoke, v23-shadow, v23-capabilities, v23-editor,
81
+ v23-interop. Plus 5 stage suites + live Playwright E2E
82
+ (`atlas-pro-v23-utter-e2e.mjs` 16/16 GREEN against the deployed
83
+ demo).
84
+
85
+ ### Spec text
86
+
87
+ SPEC.md updated:
88
+ - Section 5.1.4 -- `NAC.invoke` + `NAC.utter` final wording.
89
+ - Section 5.1.5 -- Shadow DOM resolution (open, cap 10).
90
+ - Section 5.1.6 -- Closed shadow DOM exposure API (voluntary).
91
+ - Section 5.1.7 -- Auth-aware capabilities.
92
+ - Section 13 -- `edit_field` promoted from preview to GA.
93
+
94
+ ### Reference adopters
95
+
96
+ - Atlas Pro voice ad (`ads-demo/atlas-pro/`) -- production live,
97
+ uses `NAC.utter` + payload schema.
98
+ - React demo (`packages/nac-react-demo/`) -- adopts payload-bearing
99
+ pattern for the chat-to-todos flow.
100
+ - Angular demo (`packages/nac-angular-demo/`) -- mirror of React.
101
+ - Web Component demos: `example-v23-shadow-open.html` and
102
+ `example-v23-shadow-closed.html`.
103
+
104
+ ## 2.3.0-alpha.2 -- 2026-05-13 (superseded by 2.3.0)
105
+
106
+ Hotfix on top of 2.3.0-alpha.1:
107
+
108
+ - `NAC.invoke` no longer rejects with `code='disabled'` when the
109
+ target element has `disabled` or `aria-disabled='true'` set. The
110
+ `disabled` HTML attribute is a click-event UX guard; `invoke` is
111
+ a logical payload-bearing request, not a synthetic click. Hosts
112
+ that need to refuse an invoke based on UI state should do it in
113
+ their `nac:action:requested` listener and emit
114
+ `nac:action:failed` with a meaningful code. This was hitting the
115
+ Atlas Pro mic which gets `disabled = true` during /parse +
116
+ /tts processing, blocking subsequent NAC.utter calls from
117
+ external agents mid-conversation. Reproduced in the video-gen
118
+ pipeline (every turn after the demo's first state-transition).
119
+ - Bumped CLI version + smoke test assertions to match.
120
+
3
121
  ## 2.3.0-alpha.1 -- 2026-05-12
4
122
 
5
123
  ### New: payload-bearing actions via `NAC.invoke` + `NAC.utter`
package/SPEC.md CHANGED
@@ -196,7 +196,7 @@ Promise). Returns an unbinder. Use this instead of raw
196
196
  `addEventListener('click', ...)` whenever the host supports it;
197
197
  brownfield code can still emit the event manually as before.
198
198
 
199
- ### 5.1.3 Field editor (v2.3 preview)
199
+ ### 5.1.3 Field editor (v2.3)
200
200
 
201
201
  `NAC.edit_field(nac_id)` opens a modal that lets a user (or an
202
202
  agent on their behalf) edit any text field with Word-style tools:
@@ -232,7 +232,7 @@ NAC.edit_field('invoice.client_name');
232
232
  NAC.click_by_verb('myplugin', 'edit_field', { nac_id: 'invoice.client_name' });
233
233
  ```
234
234
 
235
- ### 5.1.4 Action payload + invoke (v2.3 preview)
235
+ ### 5.1.4 Action payload + invoke (v2.3)
236
236
 
237
237
  NAC v2.2 actions are click-and-go: an agent triggers `NAC.click(id)`
238
238
  or `NAC.click_by_verb(plugin, verb)` and the host runs whatever it
@@ -314,12 +314,26 @@ NAC.register({
314
314
  });
315
315
  ```
316
316
 
317
- `payload_schema` is informational in v2.3-alpha. Agents MAY
317
+ `payload_schema` is informational in v2.3 stable. Agents MAY
318
318
  validate before sending; runtimes MAY enforce it when
319
319
  `STRICT_VALIDATION` is `true`. Schemas are intentionally simple
320
320
  (JSON-Schema-shaped subset) so a runtime can validate without
321
321
  shipping a full JSON-Schema validator. v2.4 will formalise the
322
- schema grammar.
322
+ schema grammar and turn enforcement into a default.
323
+
324
+ #### Disabled-state semantics (v2.3 hotfix from alpha.2)
325
+
326
+ `NAC.invoke` does NOT reject when the target element has
327
+ `disabled` or `aria-disabled='true'` set. The `disabled` HTML
328
+ attribute is a UX click guard; `invoke` is a logical
329
+ payload-bearing request, not a synthetic click. Hosts that need
330
+ to refuse an invoke based on UI state MUST do it in their
331
+ `nac:action:requested` listener and emit `nac:action:failed`
332
+ with a meaningful error code.
333
+
334
+ `NAC.click`, by contrast, STILL rejects on disabled elements
335
+ (click semantics preserved). Test coverage:
336
+ `packages/nac/test/v23-invoke.mjs` T7/T8/T9.
323
337
 
324
338
  #### Conformance: hosts that support invoke MUST
325
339
 
@@ -377,11 +391,285 @@ between hosts and agents. Ergonomic shortcuts (`NAC.utter`,
377
391
  `NAC.search`, `NAC.watch`, etc.) can be added later without
378
392
  re-spec because each is a thin wrapper over `invoke`.
379
393
 
380
- ### 5.1.2 Strict validation flag (v2.2)
394
+ ### 5.1.5 Shadow DOM resolution -- open roots (v2.3)
395
+
396
+ The runtime resolves `data-nac-id` references through open
397
+ shadow roots recursively. A page can mount Web Components
398
+ using `attachShadow({mode:'open'})`, place
399
+ `data-nac-*` attributes on elements inside the shadow tree,
400
+ and any NAC3 caller (`NAC.click`, `NAC.fill`, `NAC.invoke`,
401
+ etc.) resolves the target transparently.
402
+
403
+ #### Resolution algorithm
404
+
405
+ For a selector `S` (typically `[data-nac-id="..."]`) against a
406
+ root `R` (typically `document`):
407
+
408
+ 1. `R.querySelector(S)` -> if non-null, return immediately.
409
+ 2. For every descendant `el` of `R`:
410
+ - If `el.shadowRoot` is non-null (i.e. open shadow root):
411
+ recurse with `R := el.shadowRoot`, depth +1.
412
+ - Else if `el.nac3` is an object exposing a `query` method,
413
+ delegate (see sec 5.1.6).
414
+ 3. The recursion is **depth-capped at 10 levels**. Targets
415
+ deeper than 10 are unreachable; the caller receives
416
+ `code='not_found'`. The cap exists to prevent pathological
417
+ walks; in practice no production codebase nests more than
418
+ 3-4 shadow levels.
419
+ 4. The walk is breadth-of-DOM-order: siblings before nested
420
+ shadows. First match wins.
421
+
422
+ #### Event propagation
423
+
424
+ Events emitted by hosts inside shadow roots MUST set
425
+ `composed: true` for document-level listeners to receive them.
426
+ The NAC3 runtime emits all its own events with `composed:true`
427
+ already; host code that emits manual `nac:*` events is
428
+ responsible for the same. Without `composed:true` the event
429
+ stops at the shadow boundary and the runtime's correlation
430
+ machinery never sees it.
431
+
432
+ #### Author responsibility
433
+
434
+ The component author needs to:
435
+
436
+ 1. Place `data-nac-id`, `data-nac-role`, `data-nac-action` on
437
+ operable elements inside the shadow root.
438
+ 2. Set `composed:true` on any custom event the host emits to
439
+ signal a NAC3 contract (`nac:action:succeeded`,
440
+ `nac:field:changed`, etc.).
441
+ 3. Avoid `<slot>` for elements that need to be
442
+ shadow-isolated -- slotted nodes live in light DOM and are
443
+ resolved there instead.
444
+
445
+ No manifest hint or runtime opt-in is required for open shadow
446
+ roots; the resolution is automatic.
447
+
448
+ #### Reference implementation
449
+
450
+ The reference runtime exposes two internal helpers,
451
+ `_deepQuery(selector, root)` and
452
+ `_deepQueryAll(selector, root)`, that perform the walk. Public
453
+ helpers `NAC.click`, `NAC.fill`, `NAC.invoke`,
454
+ `NAC.describe`, etc. all go through the deep variants.
455
+
456
+ #### Demos and tests
457
+
458
+ - `example-v23-shadow-open.php` -- 1-, 2-, and 3-level nested
459
+ open shadow demos.
460
+ - `packages/nac/test/v23-shadow.mjs` T1-T3, T10 -- unit
461
+ coverage including depth cap.
462
+
463
+ ### 5.1.6 Shadow DOM resolution -- closed roots, voluntary exposure (v2.3)
464
+
465
+ Closed shadow roots (`attachShadow({mode:'closed'})`) are
466
+ opaque from outside the component author's code -- a browser
467
+ security boundary, not a NAC3 decision. NAC3 cannot reach
468
+ inside unless the component author voluntarily exposes a
469
+ queriable surface via the contract below.
470
+
471
+ #### The `el.nac3` interface contract
472
+
473
+ A custom element MAY expose an interface object on its host
474
+ via a getter named `nac3`:
475
+
476
+ ```ts
477
+ interface NAC3HostInterface {
478
+ query(selector: string): Element | null; // MANDATORY
479
+ queryAll(selector: string): Element[]; // RECOMMENDED
480
+ describe?(): Array<{ // OPTIONAL
481
+ id: string;
482
+ role: string;
483
+ action?: string;
484
+ label?: string;
485
+ }>;
486
+ }
487
+ ```
488
+
489
+ Components opt in by implementing the getter. Components that
490
+ do NOT opt in remain inaccessible to NAC3 callers (their
491
+ internals stay private, as the browser intends).
492
+
493
+ #### Resolution semantics
494
+
495
+ During `_deepQuery(selector)`, for every visited element `el`
496
+ with `el.shadowRoot === null`:
497
+
498
+ 1. If `typeof el.nac3 === 'object'` and `el.nac3.query` is a
499
+ function, the runtime calls `el.nac3.query(selector)`:
500
+ - Return value is an Element -> resolved.
501
+ - Return value is `null` -> not a match in this shadow.
502
+ - Return value is anything else -> emit
503
+ `nac:shadow_protocol_violation` (once per host) and skip.
504
+ - Throws -> emit `nac:shadow_blocked` (reason
505
+ `'exposure_threw'`, once per host) and skip.
506
+ 2. Else if `el.hasAttribute('data-nac-shadow') === true` and
507
+ the attribute value is `'closed'` AND there is no `nac3`
508
+ interface present, the runtime emits `nac:shadow_blocked`
509
+ (reason `'not_exposed'`, once per host). Author opt-in to
510
+ the "I am a deliberately closed component" debug signal.
511
+ 3. Else: the element is treated as a normal light-DOM
512
+ element with no shadow root.
513
+
514
+ #### Error event detail shapes
515
+
516
+ `nac:shadow_blocked` detail:
517
+
518
+ ```ts
519
+ {
520
+ host: Element, // the closed-shadow host
521
+ reason: 'exposure_threw' | 'not_exposed',
522
+ ts: number // Date.now()
523
+ }
524
+ ```
525
+
526
+ `nac:shadow_protocol_violation` detail:
527
+
528
+ ```ts
529
+ {
530
+ host: Element,
531
+ message: string, // diagnostic message
532
+ value_snapshot: string, // truncated value preview
533
+ ts: number
534
+ }
535
+ ```
536
+
537
+ Both events bubble (`bubbles: true`) and cross shadow
538
+ boundaries (`composed: true`). Dedup is per-host via a
539
+ WeakSet kept by the runtime; the same host emits each event
540
+ **at most once per page load**.
541
+
542
+ #### Why voluntary
543
+
544
+ The browser enforces closed-shadow opacity. Even if NAC3
545
+ defined a non-voluntary mechanism, the browser would prevent
546
+ it. Voluntary exposure puts the component author in full
547
+ control of what their public surface looks like for agents.
548
+
549
+ The cost is per-component opt-in; the benefit is that
550
+ NAC3-compliant agents work against design systems with closed
551
+ shadow components (Salesforce Lightning, some GitHub Primer
552
+ components, security-sensitive widgets) without per-component
553
+ adapter code.
554
+
555
+ #### Demos and tests
556
+
557
+ - `example-v23-shadow-closed.php` -- positive
558
+ (`<todo-card-closed-exposed>`) and negative
559
+ (`<todo-card-closed-blind>`) side-by-side with verdict
560
+ panels + live event log.
561
+ - `packages/nac/test/v23-shadow.mjs` T4-T9 -- unit coverage
562
+ for every error event family plus dedup semantics.
563
+ - `guides/SHADOW_DOM_CLOSED.md` -- authoring guide.
564
+
565
+ ### 5.1.7 Auth-aware capabilities (v2.3)
566
+
567
+ NAC3 v2.3 lets the manifest declare per-action capability
568
+ requirements that gate `NAC.click` and `NAC.invoke` before
569
+ dispatch. The agent receives a fast rejection
570
+ (`code='capability_required'`) instead of a round-trip that
571
+ fails server-side.
572
+
573
+ #### Manifest declaration
574
+
575
+ A capability requirement attaches at the element level or at
576
+ the verb level. Verb-level wins if both are present.
577
+
578
+ ```js
579
+ NAC.register({
580
+ plugin_slug: 'fin',
581
+ version: '1.0.0',
582
+ nac_version: '2.3',
583
+ elements: [
584
+ // Element-level (covers all verbs on this id).
585
+ { id: 'fin.invoice.delete', role: 'action',
586
+ requires_capability: 'finance.delete_invoice',
587
+ actions: [{ verb: 'delete' }] },
588
+
589
+ // Verb-level (more granular).
590
+ { id: 'fin.invoice.edit', role: 'action',
591
+ actions: [
592
+ { verb: 'edit',
593
+ requires_capability: 'finance.edit_invoice' },
594
+ { verb: 'view',
595
+ /* no capability -> always allowed */ }
596
+ ] },
597
+
598
+ // Array value: OR semantics.
599
+ // ("at least one of these capabilities matches")
600
+ { id: 'fin.invoice.approve', role: 'action',
601
+ requires_capability: ['finance.approve',
602
+ 'finance.admin'],
603
+ actions: [{ verb: 'approve' }] }
604
+ ]
605
+ });
606
+ ```
607
+
608
+ For AND semantics ("user needs ALL of these caps"), declare
609
+ each via separate gated actions or compose at the host level
610
+ in the `nac:action:requested` listener.
611
+
612
+ #### Public API
613
+
614
+ ```ts
615
+ NAC.setCapabilities(caps: string | string[] | null): void
616
+ NAC.grantCapability(cap: string): void
617
+ NAC.revokeCapability(cap: string): void
618
+ NAC.userCapabilities(): string[]
619
+ ```
620
+
621
+ `setCapabilities` replaces the entire set (use for login /
622
+ session refresh). `grantCapability` / `revokeCapability` are
623
+ incremental. `userCapabilities` returns a snapshot array.
624
+ `setCapabilities(null)` clears the set.
625
+
626
+ Hosts call these whenever the user's role changes. The set
627
+ lives in the runtime; no manifest reload is required.
628
+
629
+ #### Gate semantics
630
+
631
+ Before dispatch, `NAC.click(id)` and `NAC.invoke(id, payload)`
632
+ look up the matching manifest entry (element + verb), read
633
+ `requires_capability`, and call `_hasCapability`:
634
+
635
+ - No requirement declared -> allow.
636
+ - Requirement declared, current set satisfies it -> allow.
637
+ - Requirement declared, current set does NOT satisfy -> reject
638
+ with `NacError('capability_required', ...)` AND emit
639
+ `nac:command:rejected` with `detail.reason='capability_required'`.
381
640
 
382
- `NAC.STRICT_VALIDATION` (boolean, default `false` in v2.2). When
383
- `true`, `NAC.register()` throws an `Error` with `code='strict_validation'`
384
- and a `findings` array on any of:
641
+ The gate runs AFTER `not_found` / `disabled` / `hidden` checks
642
+ on `click` so the most specific failure surfaces. On `invoke`,
643
+ the gate runs before the request event fires (the host never
644
+ sees an unauthorised attempt).
645
+
646
+ #### Why this matters
647
+
648
+ Without the gate, an agent calling `NAC.click('finance.delete')`
649
+ either succeeds (no auth gate at all -> security hole) or
650
+ fails server-side with a 403 several seconds later. With the
651
+ gate, the agent learns synchronously that it lacks the
652
+ capability and can react appropriately (request a different
653
+ flow, ask for elevation, surface the constraint to the user).
654
+
655
+ This complements -- it does not replace -- server-side
656
+ authorisation. Hosts MUST still enforce permissions on the
657
+ server. The client gate is a UX optimisation and an
658
+ intent-level signal, not a security boundary.
659
+
660
+ #### Demos and tests
661
+
662
+ - `packages/nac/test/v23-capabilities.mjs` -- 17 assertions
663
+ covering set/get, grant/revoke, click gate, invoke gate,
664
+ verb-level vs element-level resolution, OR semantics,
665
+ null-clear, invalid-input rejection, regression for
666
+ unguarded actions.
667
+
668
+ ### 5.1.2 Strict validation flag (v2.2; default-flipped in v2.3)
669
+
670
+ `NAC.STRICT_VALIDATION` (boolean). When `true`, `NAC.register()`
671
+ throws an `Error` with `code='strict_validation'` and a
672
+ `findings` array on any of:
385
673
 
386
674
  - `manifest_role_unknown` -- entry's role outside the canonical set.
387
675
  - `tab_id_manifest_role_drift` -- id matches `^tab\.` but role
@@ -389,18 +677,38 @@ and a `findings` array on any of:
389
677
  - `manifest_dom_role_mismatch` -- mounted DOM element's
390
678
  `data-nac-role` differs from manifest entry's role.
391
679
 
392
- In v2.3 the default flips to `true`. In v3.0 the flag is removed
393
- (strict is the only mode).
680
+ **Default value:**
681
+
682
+ - **v2.2.x:** `false` (warning-only). Adopters needed a migration
683
+ window.
684
+ - **v2.3.x:** **`true`** (throwing). The migration window closed
685
+ with the v2.2 line. Adopters with drift-laden manifests opt
686
+ out by setting `NAC.STRICT_VALIDATION = false` BEFORE any
687
+ `register()` call.
688
+ - **v3.0:** flag removed (strict is the only mode).
689
+
690
+ See `guides/MIGRATION_v2.2_to_v2.3.md` for the playbook to clean
691
+ up drift findings.
394
692
 
395
693
  All async methods reject with `NacError` whose `code` is one of:
396
694
 
397
695
  - `not_found` -- the named element/role/verb is not in the DOM.
398
696
  - `invalid` -- argument shape is wrong.
697
+ - `disabled` -- element has `disabled` or `aria-disabled='true'`
698
+ (`NAC.click` only; `NAC.invoke` no longer checks per v2.3
699
+ hotfix, see sec 5.1.4).
700
+ - `hidden` -- element is offscreen / `aria-hidden='true'` /
701
+ zero-dimension.
702
+ - `capability_required` -- manifest declared
703
+ `requires_capability` and the current
704
+ `NAC.userCapabilities()` set does not satisfy it (v2.3, see
705
+ sec 5.1.7).
399
706
  - `timeout` -- side effect dispatched but the conformance ack
400
- event did not arrive within 5 seconds. **A timeout means real
401
- failure**: the handler may have hung, the ack was never wired,
402
- a network race occurred. Callers MUST treat timeout as failure
403
- unless they have proof of side effect via another channel.
707
+ event did not arrive within 5 seconds (30 seconds for
708
+ `invoke`). **A timeout means real failure**: the handler may
709
+ have hung, the ack was never wired, a network race occurred.
710
+ Callers MUST treat timeout as failure unless they have proof
711
+ of side effect via another channel.
404
712
 
405
713
  ### 5.2 Introspection
406
714