@nac3/runtime 2.6.0 → 2.9.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/nac.cjs CHANGED
@@ -7,7 +7,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7
7
  =====================================================================
8
8
 
9
9
  AUTHORITATIVE VERSION CONSTANT: see the global.NAC export at the
10
- bottom of this file. `version: '2.6.0', spec_version: '2.6'`
10
+ bottom of this file. `version: '2.9.0', spec_version: '2.9'`
11
11
  is the normative declaration. The dated changelog sections below are
12
12
  historical notes; if they ever drift from the export, the export
13
13
  wins.
@@ -314,6 +314,12 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
314
314
 
315
315
  if (global.NAC && global.NAC.__nac_v1_installed) return;
316
316
 
317
+ /* The tier this runtime declares when a host does not override it.
318
+ ONE declaration: the versioning gate and the NAC export both read
319
+ it. See the long note at the `conformance_tier` export for why a
320
+ tier is not a level, and RFC V24-04 sec 6 for the vocabulary. */
321
+ const DEFAULT_CONFORMANCE_TIER = 'NAC-3-versioned';
322
+
317
323
  /* ---------- Errors ---------------------------------------------- */
318
324
 
319
325
  function NacError(code, message, extra) {
@@ -324,6 +330,29 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
324
330
  return e;
325
331
  }
326
332
 
333
+ /* 2.7.0 (SPEC sec 19.3) -- fail closed where there is no document.
334
+
335
+ The DOM primitives of sections 1-14 address NODES: they resolve a
336
+ name by querying the document. Called where no document exists --
337
+ Node, a worker, an SSR build, a screenless assistant -- they used
338
+ to throw a raw "ReferenceError: document is not defined" from
339
+ whatever line happened to touch it first, which tells the caller
340
+ nothing about the contract and is not a code anybody can branch
341
+ on. validate_global was worse: it returned {ok: true} for a tree
342
+ that does not exist, which is a false green.
343
+
344
+ So they refuse by name. The headless profile (sec 19) is the other
345
+ half of the same rule: a surface with no document is reached
346
+ through the extension contract (sec 15), never through these. */
347
+ function _nac_requireDocument(where) {
348
+ if (typeof document !== 'undefined' && document) return;
349
+ throw NacError('no_document',
350
+ 'NAC.' + where + ': no document in this context, so there is no node to resolve. ' +
351
+ 'Reach a declared surface through the extension contract -- NAC.call / NAC.read / ' +
352
+ 'NAC.subscribe (SPEC sec 15) -- and see the headless profile (SPEC sec 19).',
353
+ { primitive: where });
354
+ }
355
+
327
356
  /* ================================================================
328
357
  v2.5 / RFC V24-01: Plugin slug uniqueness gate (spec sec 7.4)
329
358
  ================================================================
@@ -719,13 +748,58 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
719
748
  over the canonical bytes, truncated to the leading 128 bits
720
749
  (16 bytes), encoded as 32 lowercase hex chars. */
721
750
 
722
- function _hashIsEffectivelyVisible(el) {
723
- /* Cheap visibility check: offsetParent + style.display +
724
- style.visibility + aria-hidden. */
751
+ /* ONE definition of "visible" (TF-A12).
752
+
753
+ Until 2.7.0 there were two, both published, and they disagreed:
754
+
755
+ _hashIsEffectivelyVisible fed the `visible` key of the
756
+ concurrency hash. Looked at
757
+ aria-hidden and offsetParent. Did
758
+ NOT look at opacity.
759
+ _isVisible fed the `visible` key the AGENT
760
+ reads from a state snapshot. Looked
761
+ at opacity. Did NOT look at
762
+ aria-hidden.
763
+
764
+ So an element with `opacity: 0` was visible to one and invisible
765
+ to the other, and one with `aria-hidden="true"` was the reverse.
766
+ Two answers to one word, in one runtime, both shipped -- and the
767
+ word is load-bearing twice over: an agent decides whether to act
768
+ on an element by it, and the optimistic-concurrency gate decides
769
+ whether the page moved under the agent by it.
770
+
771
+ There was a third difference, and it was a crash rather than a
772
+ disagreement: _isVisible reached el.ownerDocument.defaultView
773
+ .getComputedStyle with NO GUARD, while this one checked for
774
+ window.getComputedStyle first. In an environment without a
775
+ defaultView -- a detached document, a server-side render, a test
776
+ harness -- one threw and the other did not.
777
+
778
+ THE DECISION, and the reasoning rather than just the outcome. The
779
+ union is the right answer, and specifically the agent's question
780
+ is the one that governs: "can this be perceived and acted on?"
781
+ Every one of the five conditions below answers no to it.
782
+ aria-hidden belongs in it because NAC3 sits next to the
783
+ accessibility tree and an element explicitly removed from that
784
+ tree is not something an agent may act on. opacity: 0 belongs in
785
+ it because a user cannot see it.
786
+
787
+ The hash gets the same predicate, which makes it slightly
788
+ stricter: a control fading to opacity 0 now changes the hash.
789
+ That is more correct for a concurrency check, not less -- it IS a
790
+ change in the observable state, which is exactly what the hash
791
+ exists to notice.
792
+
793
+ Cheap first, expensive last: the attribute and the layout box are
794
+ free, getComputedStyle is not. */
795
+ function _isPerceivable(el) {
725
796
  if (!el || el.nodeType !== 1) return false;
797
+ /* 1. explicitly removed from the accessibility tree */
726
798
  if (el.getAttribute && el.getAttribute('aria-hidden') === 'true') return false;
799
+ /* 2. not laid out. position:fixed legitimately has no
800
+ offsetParent, so a zero-sized rect is what decides, not the
801
+ null parent on its own. */
727
802
  if (typeof el.offsetParent === 'object' && el.offsetParent === null) {
728
- /* position:fixed escapes offsetParent=null. Use rect fallback. */
729
803
  if (typeof el.getBoundingClientRect === 'function') {
730
804
  const r = el.getBoundingClientRect();
731
805
  if (r.width === 0 && r.height === 0) return false;
@@ -733,13 +807,35 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
733
807
  return false;
734
808
  }
735
809
  }
736
- if (typeof window !== 'undefined' && window.getComputedStyle) {
737
- const cs = window.getComputedStyle(el);
738
- if (cs && (cs.display === 'none' || cs.visibility === 'hidden')) return false;
810
+ /* 3. a zero-sized box, however it got that way */
811
+ if (typeof el.getBoundingClientRect === 'function') {
812
+ const r = el.getBoundingClientRect();
813
+ if (r.width === 0 && r.height === 0) return false;
814
+ }
815
+ /* 4..5. display / visibility / opacity, if anyone can tell us.
816
+ GUARDED on both paths: the document's own view first, the
817
+ global second, and neither is assumed to exist. Returning true
818
+ when nothing can be computed is deliberate -- an element we
819
+ cannot measure is reported as present rather than silently
820
+ vanishing from a snapshot. */
821
+ const view = (el.ownerDocument && el.ownerDocument.defaultView)
822
+ || (typeof window !== 'undefined' ? window : null);
823
+ if (view && typeof view.getComputedStyle === 'function') {
824
+ const cs = view.getComputedStyle(el);
825
+ if (cs && (cs.display === 'none' || cs.visibility === 'hidden' || cs.opacity === '0')) {
826
+ return false;
827
+ }
739
828
  }
740
829
  return true;
741
830
  }
742
831
 
832
+ /* Kept as a name because the hash code reads better with it, and
833
+ because a reader looking for the old function should land on the
834
+ explanation above rather than on nothing. */
835
+ function _hashIsEffectivelyVisible(el) {
836
+ return _isPerceivable(el);
837
+ }
838
+
743
839
  function _hashReadValue(el) {
744
840
  if (!el || el.nodeType !== 1) return null;
745
841
  const tag = (el.tagName || '').toLowerCase();
@@ -1019,7 +1115,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
1019
1115
  and a runtime that declares NAC-3 must NOT silently honor any
1020
1116
  expected_*. */
1021
1117
  const tier = (typeof window !== 'undefined' && window.NAC &&
1022
- window.NAC.conformance_tier) || 'NAC-3-versioned';
1118
+ window.NAC.conformance_tier) || DEFAULT_CONFORMANCE_TIER;
1023
1119
  if (tier === 'NAC-3' && hasAny) {
1024
1120
  throw NacError('feature_not_supported',
1025
1121
  'Runtime tier is NAC-3 (non-versioned); expected_* parameters are not honored.',
@@ -1226,6 +1322,26 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
1226
1322
  of identical warnings per session. Key by (event_type, field).
1227
1323
  Reset by calling NAC.__resetLegacyWarnDedup() (test-only). */
1228
1324
  const _legacyWarnSeen = Object.create(null);
1325
+ /* 2.7.0 (TF-A03) -- THE REMOVAL PROMISE IS WITHDRAWN, and this
1326
+ message is where it was being made. It said "Will be removed in
1327
+ v2.0" to every adopter's console; v2.0 shipped, so did 2.1
1328
+ through 2.6, and the fields are all still here. A promise that
1329
+ outlives three majors is not a deprecation, it is noise that
1330
+ teaches authors to ignore the warning.
1331
+
1332
+ It is withdrawn rather than kept and honoured because the fields
1333
+ are LOAD-BEARING, which no document noticed: the event matcher
1334
+ that decides whether an event belongs to an element READS
1335
+ from_nac_id / target_nac_id / over_nac_id / nac_id / id /
1336
+ step_id as resolution keys (see _eventMatchesElement below).
1337
+ Removing them would not retire six lines, it would silently
1338
+ break wait_for() and assert_event_fired() on any host that
1339
+ emits only the alias -- which is exactly the shape of host the
1340
+ aliases exist for.
1341
+
1342
+ So: the alias stays, the canonical is still the one to write,
1343
+ and the warning says that without naming a version it cannot
1344
+ keep. Decision D-12, owner delegation of 2026-11-24. */
1229
1345
  function _legacyWarn(eventType, field, canonical) {
1230
1346
  const key = eventType + '::' + field;
1231
1347
  if (_legacyWarnSeen[key]) return;
@@ -1233,7 +1349,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
1233
1349
  if (typeof console !== 'undefined' && console.warn) {
1234
1350
  console.warn('[NAC] legacy_event_field: ' + eventType +
1235
1351
  ' detail.' + field + ' is a legacy alias. Use detail.' +
1236
- canonical + ' instead. Will be removed in v2.0.');
1352
+ canonical + ' instead. The alias is frozen, not scheduled ' +
1353
+ 'for removal: the event matcher resolves it (SPEC 7.4, ' +
1354
+ 'decision D-12).');
1237
1355
  }
1238
1356
  }
1239
1357
 
@@ -1514,6 +1632,60 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
1514
1632
  return null;
1515
1633
  }
1516
1634
 
1635
+ /* 2.7.0 -- `undrivable_until`, the declaration of a gated surface.
1636
+
1637
+ THE DEFECT IT ANSWERS, measured on this project's own landing page
1638
+ on 2026-11-25 with the probe that 2.7.0 added:
1639
+ `validate_global({probe: true})` reported seven
1640
+ nac_id_declared_not_reachable findings -- chat.lang, chat.tts,
1641
+ chat.mic, chat.voice.always_on, chat.log, chat.input, chat.send.
1642
+ All seven are real, all seven are declared, and all seven live
1643
+ inside a panel that stays behind `aria-hidden="true"` until
1644
+ somebody opens it.
1645
+
1646
+ Before this field the protocol had no way to say that, so the two
1647
+ parties both lost. An AGENT read a manifest advertising seven
1648
+ addressable ids, called click() on one of them and got
1649
+ NacError('hidden') with nothing to do about it -- the surface
1650
+ exists, is declared, and the one thing it needed to know (open the
1651
+ panel first) was the one thing nobody wrote down. And an AUTHOR
1652
+ with a legitimately gated panel had no honest way to reach
1653
+ conformance level 3, which asks for zero findings: the only moves
1654
+ available were to stop declaring the surface (worse for the agent)
1655
+ or to stop painting it until opened (a rewrite of the widget).
1656
+
1657
+ So an element may now declare the id that opens it:
1658
+
1659
+ { id: 'chat.mic', role: 'action',
1660
+ undrivable_until: 'nac_landing.chat.toggle' }
1661
+
1662
+ and three things follow. The probe stops calling it a defect and
1663
+ reports it in its own `gated` bucket, which is NOT a finding.
1664
+ click() still refuses it while it is hidden -- the element really
1665
+ is unreachable, and failing closed is the whole point -- but the
1666
+ rejection now NAMES the gate, so the agent's next move is in the
1667
+ error it just got. And the declaration is checked: a gate that is
1668
+ not declared, not mounted, or itself unreachable is an ERROR, a
1669
+ harder finding than the warn it replaces. A promised way in that
1670
+ does not open is worse than no promise, because an agent will
1671
+ wait for it.
1672
+
1673
+ Fail-closed by construction: no field means no change, for every
1674
+ page already published. */
1675
+ function _resolveGate(nac_id) {
1676
+ for (const slug in _manifests) {
1677
+ const m = _manifests[slug];
1678
+ if (!m) continue;
1679
+ const all = (m.elements || []).concat(m.tabs || []);
1680
+ for (let i = 0; i < all.length; i++) {
1681
+ const e = all[i];
1682
+ if (!e || e.id !== nac_id) continue;
1683
+ return e.undrivable_until ? String(e.undrivable_until) : null;
1684
+ }
1685
+ }
1686
+ return null;
1687
+ }
1688
+
1517
1689
  function _hasCapability(cap) {
1518
1690
  if (!cap) return true;
1519
1691
  if (Array.isArray(cap)) {
@@ -1567,9 +1739,135 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
1567
1739
  'draggable', 'drop-target',
1568
1740
  /* Tolerated for legacy buttons that just need to be clickable
1569
1741
  without contract. Falls back to action behaviour at runtime. */
1570
- 'button'
1742
+ 'button',
1743
+
1744
+ /* ---- v2.8.0: the surface vocabulary (SPEC.md 1.2) ------------
1745
+ THE DEFECT THIS CLOSES. Measured on this tree on 2026-11-25:
1746
+ the normative table declared 20 roles, the tree USED 67, and
1747
+ 52 of those were declared nowhere -- not here, not in the
1748
+ spec table, not in the click completion map. Every one of
1749
+ them had been written into a page by somebody who needed the
1750
+ word, and the protocol's answer was to treat it as `action`
1751
+ and wait five seconds for an event that role never emits.
1752
+
1753
+ This Set is the runtime's half of the contract and section 1
1754
+ of SPEC.md is the document's half. They are hand-written in
1755
+ two places on purpose -- the runtime must refuse an unknown
1756
+ role with no network and no spec file at hand -- and from
1757
+ 2.8.0 scripts/check-role-registries.mjs refuses the build
1758
+ when the two halves disagree. Before that gate existed the
1759
+ two lists had already drifted once (the spec table carried
1760
+ draggable / drop-target for four minor versions while the
1761
+ lint's copy did not), so this is not a hypothetical. */
1762
+
1763
+ /* Maps. The interior is drawn, not marked up. */
1764
+ 'map', 'map-layer', 'map-marker',
1765
+ /* Charts: chart-series is the operable part, chart-point the
1766
+ readable one. */
1767
+ 'chart', 'chart-series', 'chart-point',
1768
+ 'calendar', 'calendar-event',
1769
+ /* tree-children exists as a role because a collapsed subtree is
1770
+ IN the DOM and not operable, and that is the distinction an
1771
+ agent has to be able to make. */
1772
+ 'tree', 'tree-node', 'tree-children',
1773
+ 'timeline', 'timeline-item',
1774
+ 'carousel', 'carousel-slide',
1775
+ /* Live regions. One-to-one with ARIA on purpose. `feedback` is
1776
+ narrower than `status` and is what NAC.read_feedback() reads. */
1777
+ 'status', 'log', 'toast', 'toast-region', 'banner', 'feedback',
1778
+ /* Overlays. `modal` is the general case of `confirm-dialog`. */
1779
+ 'modal', 'drawer', 'bottom-sheet',
1780
+ /* Controls whose value is not their text: these are what tell an
1781
+ agent to resolve through options() instead of typing. */
1782
+ 'combobox', 'listbox', 'slider', 'richtext',
1783
+ /* The containers of controls that were already declared. */
1784
+ 'tablist', 'tabpanel', 'stepper', 'accordion-section',
1785
+ 'breadcrumb', 'pagination-control',
1786
+ /* Identity, and the state of the interface itself. `skeleton`
1787
+ means NOT LOADED YET and `empty-state` means NOTHING HERE,
1788
+ AND THAT IS NOT AN ERROR -- the difference between waiting,
1789
+ moving on, and reporting a problem. */
1790
+ 'avatar', 'presence-indicator', 'skeleton', 'empty-state',
1791
+ /* Structure. Every one of these is consumed by something: three
1792
+ are queried by this runtime, `list` hosts reorder(), and
1793
+ `canvas` is the door section 15.12 assigned to that surface. */
1794
+ 'list', 'row', 'menu', 'label', 'value', 'paragraph', 'canvas',
1795
+
1796
+ /* ---- v2.9.0: the document vocabulary (SPEC.md 1.2) ----------
1797
+ THE DEFECT THIS CLOSES, and it was this project's own site.
1798
+ Measured 2026-11-27 with the PUBLISHED validator over the
1799
+ whole tree: 45 677 elements across 526 pages carried a role
1800
+ the specification did not declare, and they were not written
1801
+ by hand -- a single producer emits them,
1802
+ scripts/build-spec-html.mjs, which renders the normative text
1803
+ itself as a NAC3 page. So the document that declares the
1804
+ vocabulary was being served marked up in words it did not
1805
+ declare, 354 times per page.
1806
+
1807
+ Why declaring them is the right half of the fix rather than
1808
+ un-painting them: these are document structure, and under
1809
+ section 19 reading a document is a capability, not a side
1810
+ effect of having a screen. An agent with no screen navigates
1811
+ prose by heading; code says the text inside must be read
1812
+ verbatim rather than paraphrased. list and paragraph were
1813
+ already declared, so list-item and heading missing was half a
1814
+ family, which is why the count was in the tens of thousands.
1815
+
1816
+ All five are read-only: they go in _CLICK_NO_EVENT_ROLES
1817
+ below, never in the click family map, because putting a
1818
+ read-only role in that map would make click() promise a
1819
+ completion nobody emits. */
1820
+ 'heading', 'list-item', 'code', 'code-inline', 'note'
1571
1821
  ]);
1572
1822
 
1823
+ /* ---- Declared aliases (SPEC.md 1.5) ---------------------------
1824
+ Seven spellings this tree had grown for roles that already had a
1825
+ name. They are RESOLVED, not rejected: a spelling that ever
1826
+ worked keeps working (section 12 promise 2), and the migration
1827
+ of a tree is a decision its owner makes one page at a time, not
1828
+ something an upgrade imposes.
1829
+
1830
+ Resolution happens in _canonicalRole() below, before anything
1831
+ else in the runtime looks at a role -- so an alias reaches the
1832
+ known-role check, the click completion map and the manifest
1833
+ validator already spelled canonically. The static lint reports
1834
+ them as `dom_role_legacy_spelling` at severity warn, which is
1835
+ how a tree gets migrated deliberately.
1836
+
1837
+ NOT in this table, measured and kept as roles of their own:
1838
+ `feedback` (NAC.read_feedback() filters on it), `label`, `row`,
1839
+ `toast`, `toast-region` and `banner` (this runtime queries each
1840
+ of them by selector). A role the implementation reads is part
1841
+ of the contract whether the document said so or not. */
1842
+ const _ROLE_ALIASES = {
1843
+ 'treenode': 'tree-node',
1844
+ 'timeline-entry': 'timeline-item',
1845
+ 'input': 'field',
1846
+ 'textbox': 'field',
1847
+ 'panel': 'region',
1848
+ 'fab': 'action',
1849
+ 'dropzone': 'drop-target'
1850
+ };
1851
+
1852
+ /* Roles registered at runtime by a host (NAC.register_role, v2.8).
1853
+ Kept apart from _KNOWN_ROLES_V22 so introspection can always
1854
+ say which half of the vocabulary a role came from: the protocol
1855
+ or this page. */
1856
+ const _REGISTERED_ROLES = new Map();
1857
+
1858
+ function _canonicalRole(role) {
1859
+ if (!role) return role;
1860
+ const r = String(role);
1861
+ return Object.prototype.hasOwnProperty.call(_ROLE_ALIASES, r)
1862
+ ? _ROLE_ALIASES[r]
1863
+ : r;
1864
+ }
1865
+
1866
+ function _roleIsKnown(role) {
1867
+ const r = _canonicalRole(role);
1868
+ return _KNOWN_ROLES_V22.has(r) || _REGISTERED_ROLES.has(r);
1869
+ }
1870
+
1573
1871
  function _v22Emit(severity, code, nac_id, message, detail) {
1574
1872
  const fn = severity === 'error'
1575
1873
  ? (typeof console !== 'undefined' && console.error ? console.error.bind(console) : null)
@@ -1593,7 +1891,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
1593
1891
  if (!id) return; /* spec-level error caught elsewhere */
1594
1892
 
1595
1893
  /* Check 1: role enumeration. */
1596
- if (role && !_KNOWN_ROLES_V22.has(role)) {
1894
+ if (role && !_roleIsKnown(role)) {
1597
1895
  findings.push({
1598
1896
  code: 'manifest_role_unknown',
1599
1897
  nac_id: id,
@@ -1602,6 +1900,26 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
1602
1900
  detail: { plugin: slug, source: source, role: role }
1603
1901
  });
1604
1902
  }
1903
+ /* v2.8.0: a declared alias (SPEC.md 1.5) is legal, and is
1904
+ REPORTED WITHOUT JOINING `findings` -- emitted straight at
1905
+ warn severity instead.
1906
+
1907
+ That distinction is the whole point, and the first draft of
1908
+ this block got it wrong: every entry of `findings` is emitted
1909
+ as an error AND makes register() throw under
1910
+ STRICT_VALIDATION, which has been the default since 2.3. So
1911
+ pushing this one would have meant that a page using a spelling
1912
+ v2.8 declares legal stops registering at all on upgrade --
1913
+ breaking exactly the adopter the alias table exists to
1914
+ protect, in the same release that promised not to. The suite
1915
+ that caught it is runtime/test/role-vocabulary.mjs. */
1916
+ if (role && role !== _canonicalRole(role)) {
1917
+ _v22Emit('warn', 'manifest_role_legacy_spelling', id,
1918
+ 'plugin "' + slug + '" id="' + id + '" uses the legacy role spelling "' +
1919
+ role + '"; the canonical role is "' + _canonicalRole(role) +
1920
+ '" (SPEC.md 1.5). The alias resolves, so nothing is broken today.',
1921
+ { plugin: slug, source: source, role: role, canonical: _canonicalRole(role) });
1922
+ }
1605
1923
 
1606
1924
  /* Check 2: tab-id naming convention -- id like "tab.X" MUST
1607
1925
  have role 'tab'. Catches the role drift class that broke
@@ -2113,10 +2431,60 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2113
2431
  _emitAck('nac_editor.delete_selection');
2114
2432
  }
2115
2433
  async function aiCorrectSyntax() {
2116
- status.textContent = 'asking AI...';
2117
2434
  const original = textarea.value;
2435
+
2436
+ /* OFF UNTIL THE HOST SAYS WHERE (TF-A11).
2437
+
2438
+ What this did before 2.7.0: it POSTed the ENTIRE contents of
2439
+ the edited textarea to
2440
+
2441
+ (window.NacChat && window.NacChat._endpoint)
2442
+ || '/crm/api/v1/yujin/nac-demo'
2443
+
2444
+ -- a default nobody on the host side had declared. The matter
2445
+ is narrower than it first looks and worth stating precisely:
2446
+ the path is RELATIVE, so the request went to the host's own
2447
+ origin, not to a third party. This was never a leak to
2448
+ yujin.app from an adopter's page.
2449
+
2450
+ It was still wrong, for two reasons that survive that
2451
+ correction:
2452
+
2453
+ 1. a library does not get to send the user's text anywhere,
2454
+ not even to the host's own server, without the host
2455
+ asking. The host may have no handler on that path, may
2456
+ log request bodies, may be under a data-handling
2457
+ agreement that says what leaves the browser. That is the
2458
+ host's call to make and it was made for them.
2459
+ 2. the only way to change it lived in ANOTHER FILE. An
2460
+ adopter who loads js/nac.js alone -- the documented way
2461
+ to get the runtime -- had no handle to redirect it and no
2462
+ way to switch it off.
2463
+
2464
+ So the endpoint is now declared, and on THIS file's export so
2465
+ loading the runtime alone is enough:
2466
+
2467
+ NAC.editor_ai_endpoint = '/my/own/handler';
2468
+
2469
+ With nothing declared and no chat client loaded, nothing is
2470
+ sent and the control says so. The action stays declared in the
2471
+ manifest and the button stays bound: an agent that invokes it
2472
+ gets an honest "not configured" instead of the control
2473
+ vanishing from the contract between one page and the next.
2474
+ NacChat's endpoint is still honoured when the host loaded the
2475
+ chat client, because that IS the host declaring one. */
2476
+ const endpoint = (global.NAC && global.NAC.editor_ai_endpoint)
2477
+ || (window.NacChat && window.NacChat._endpoint)
2478
+ || null;
2479
+ if (!endpoint) {
2480
+ status.textContent = 'AI correction is not configured: set NAC.editor_ai_endpoint'
2481
+ + ' to the handler that should receive the text. Nothing was sent.';
2482
+ _emitAck('nac_editor.ai_correct_syntax');
2483
+ return;
2484
+ }
2485
+
2486
+ status.textContent = 'asking AI...';
2118
2487
  try {
2119
- const endpoint = (window.NacChat && window.NacChat._endpoint) || '/crm/api/v1/yujin/nac-demo';
2120
2488
  const resp = await fetch(endpoint, {
2121
2489
  method: 'POST',
2122
2490
  headers: { 'Content-Type': 'application/json' },
@@ -2206,18 +2574,37 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2206
2574
  let manifest;
2207
2575
  if (typeof arg1 === 'string' && arg2 && typeof arg2 === 'object') {
2208
2576
  manifest = arg2;
2209
- if (!manifest.plugin_slug) manifest.plugin_slug = arg1;
2210
2577
  } else {
2211
2578
  manifest = arg1;
2212
2579
  }
2213
2580
  if (!manifest || typeof manifest !== 'object') {
2214
2581
  throw NacError('invalid', 'manifest object required');
2215
2582
  }
2583
+ /* 2.7.0 (sec 7.2): the signed body is the manifest AS THE HOST
2584
+ BUILT IT. Snapshot it here, before the three defaults below
2585
+ change the bytes -- a host that signs {plugin_slug, elements}
2586
+ and calls register('invoice', m) would otherwise sign one
2587
+ object and have the runtime verify another, and the failure
2588
+ would look like a bad secret. */
2589
+ const _signedBody = (manifest.provenance && manifest.provenance.signature)
2590
+ ? _manifestCanonicalString(manifest)
2591
+ : null;
2592
+ if (typeof arg1 === 'string' && arg2 === manifest && !manifest.plugin_slug) {
2593
+ manifest.plugin_slug = arg1;
2594
+ }
2216
2595
  const slug = String(manifest.plugin_slug || '').trim();
2217
2596
  if (!slug) throw NacError('invalid', 'manifest.plugin_slug required');
2218
2597
  if (!manifest.version) manifest.version = '1.0.0';
2219
2598
  if (!manifest.nac_version) manifest.nac_version = '1.0';
2220
2599
 
2600
+ /* 2.7.0 (sec 7.2, TF-A17): manifest authenticity. Throws when a
2601
+ provenance.signature is present and no registered tenant secret
2602
+ matches it; records what it could tell either way, so a
2603
+ validator can ask NAC.manifest_provenance(slug) instead of
2604
+ assuming. No secret registered = no check and no change for
2605
+ every adopter who never set one. */
2606
+ _recordManifestProvenance(slug, manifest, _signedBody);
2607
+
2221
2608
  /* v2.5 / RFC V24-01 -- synchronous slug uniqueness gate.
2222
2609
  Throws NacError('duplicate_plugin_no_instance_id', ...) when
2223
2610
  the DOM already contains multiple roots for this slug and any
@@ -2420,6 +2807,12 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2420
2807
  function unregister(slug) {
2421
2808
  delete _manifests[slug];
2422
2809
  delete _instances[slug];
2810
+ /* 2.7.0 (sec 7.2): the authenticity record is about the manifest
2811
+ that WAS registered. Leaving it behind would let a validator
2812
+ read "verified" for a plugin that is no longer mounted. */
2813
+ if (typeof _manifestProvenance !== 'undefined') {
2814
+ delete _manifestProvenance[slug];
2815
+ }
2423
2816
  }
2424
2817
 
2425
2818
  function manifest(slug) {
@@ -2451,17 +2844,24 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2451
2844
  in one atomic step. Single source of truth for OCC. */
2452
2845
  function syncPlugin(arg1, arg2) {
2453
2846
  let m;
2847
+ let twoArg = false;
2454
2848
  if (typeof arg1 === 'string' && arg2 && typeof arg2 === 'object') {
2455
2849
  /* (slug, manifest) form -- match register's calling convention. */
2456
2850
  m = Object.assign({}, arg2);
2457
- if (!m.plugin_slug) m.plugin_slug = arg1;
2851
+ twoArg = true;
2852
+ /* 2.7.0 (sec 7.2): plugin_slug used to be injected HERE, which
2853
+ changed the bytes of a signed manifest before register() could
2854
+ hash them -- a host that signed {elements} and called
2855
+ syncPlugin('invoice', m) got a signature_mismatch that looked
2856
+ like a wrong secret. register() injects it now, after taking
2857
+ its snapshot, and both call forms go through that one place. */
2458
2858
  } else if (arg1 && typeof arg1 === 'object') {
2459
2859
  m = arg1;
2460
2860
  } else {
2461
2861
  throw NacError('invalid',
2462
2862
  'syncPlugin: requires (manifest) or (slug, manifest)');
2463
2863
  }
2464
- const slug = m.plugin_slug;
2864
+ const slug = m.plugin_slug || (twoArg ? arg1 : null);
2465
2865
  if (!slug || typeof slug !== 'string') {
2466
2866
  throw NacError('invalid',
2467
2867
  'syncPlugin: manifest.plugin_slug required (non-empty string)');
@@ -2477,7 +2877,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2477
2877
  /* Delegate to register() so validation + storage code-path stays
2478
2878
  exactly one place. If register throws (strict validation), the
2479
2879
  prior entry is GONE -- caller's responsibility to handle. */
2480
- register(m);
2880
+ if (twoArg) register(arg1, m); else register(m);
2481
2881
  /* Bump V24-04 OCC version on REPLACE only. First-add is a normal
2482
2882
  register: the boot tree_version already reflects the new plugin
2483
2883
  and subscribers do not need to refresh anything that did not
@@ -2528,7 +2928,14 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2528
2928
 
2529
2929
  Provenance on document:
2530
2930
  nac:authority:requested / :granted / :denied / :revoked / :expired
2531
- nac:action:confirmed / :rejected */
2931
+ nac:action:confirmed
2932
+
2933
+ (2.8.0: this comment used to name `nac:action:rejected` as well.
2934
+ No call site produces it -- the comment was the only place that
2935
+ name existed, which is the same defect as an event the spec names
2936
+ and the runtime never emits, one layer in. Found by
2937
+ scripts/check-event-vocabulary.mjs, which now refuses both
2938
+ directions.) */
2532
2939
 
2533
2940
  const _V25_SCOPE_RANK = { low: 1, medium: 2, high: 3 };
2534
2941
  const _v25_authority_grants = new Map();
@@ -2788,10 +3195,12 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2788
3195
  }
2789
3196
 
2790
3197
  function _allElements() {
3198
+ _nac_requireDocument('find');
2791
3199
  return _deepQueryAll('[data-nac-id]', document, 0);
2792
3200
  }
2793
3201
 
2794
3202
  function _activePlugin() {
3203
+ _nac_requireDocument('find');
2795
3204
  /* Most recently mounted plugin with state=ready wins. Falls back
2796
3205
  to topmost plugin root in the DOM order. */
2797
3206
  const plugins = Array.prototype.slice.call(
@@ -2902,17 +3311,18 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2902
3311
  return null;
2903
3312
  }
2904
3313
 
3314
+ /* The agent-facing `visible`. One predicate with the hash since
3315
+ 2.7.0 -- see the long note on _isPerceivable for why the two used
3316
+ to disagree and which way the disagreement was settled. This also
3317
+ stops throwing in an environment with no defaultView. */
2905
3318
  function _isVisible(el) {
2906
- if (!el || !el.getBoundingClientRect) return false;
2907
- const r = el.getBoundingClientRect();
2908
- if (r.width === 0 && r.height === 0) return false;
2909
- const cs = el.ownerDocument.defaultView.getComputedStyle(el);
2910
- return cs.display !== 'none' && cs.visibility !== 'hidden' && cs.opacity !== '0';
3319
+ return _isPerceivable(el);
2911
3320
  }
2912
3321
 
2913
3322
  /* ---------- Public read API ------------------------------------- */
2914
3323
 
2915
3324
  function describe() {
3325
+ _nac_requireDocument('describe');
2916
3326
  const plugins = Array.prototype.slice.call(
2917
3327
  document.querySelectorAll('[data-nac-plugin]')
2918
3328
  ).map(function (root) {
@@ -2981,6 +3391,152 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2981
3391
  });
2982
3392
  }
2983
3393
 
3394
+ /* ---- NAC.register_role(name, spec) (v2.8.0, SPEC.md 1.4) ------
3395
+ THE PROBLEM THIS SOLVES. The nineteen pieces of work that built
3396
+ the v2.8 vocabulary all shared one assumption: that adding a
3397
+ role means editing the protocol. Six layers, two of them
3398
+ published, one of them in nine languages. That is why the 52
3399
+ undeclared roles of 2026-11-25 existed at all -- somebody
3400
+ needed a word, the only door open was writing it into the HTML
3401
+ and hoping nobody looked, and for four years nobody did,
3402
+ because no rule compared the markup against the vocabulary.
3403
+
3404
+ So the vocabulary gets a door. A host declares a role at
3405
+ runtime, with the completion events it answers with, and from
3406
+ that moment:
3407
+ - the manifest validator accepts it instead of reporting
3408
+ manifest_role_unknown,
3409
+ - click() waits for ITS events instead of falling back to the
3410
+ action family and timing out at five seconds,
3411
+ - describe() / roles() report where it came from.
3412
+
3413
+ THE HARD PART, and how it is answered. A registered role exists
3414
+ only while the page is loaded, and the static lint runs with no
3415
+ page -- reading files. A role registered in JavaScript is
3416
+ invisible to it, so the lint would report a page as wrong for
3417
+ using a role that page itself declares. The answer is NOT to
3418
+ make the lint execute the page (a validator that runs the code
3419
+ it is validating has stopped being a validator). It is a second
3420
+ declaration the lint CAN read: a `nac3.roles.json` next to the
3421
+ markup, with the same shape as this argument. Two declarations
3422
+ of one fact is exactly the producer/consumer asymmetry this
3423
+ release spent its time removing, so it is not left to good
3424
+ intentions: `npx nac3 lint` reports role_registration_undeclared
3425
+ when a page calls register_role for a role its
3426
+ nac3.roles.json does not carry, and role_registration_orphan in
3427
+ the other direction.
3428
+
3429
+ WHAT IT REFUSES, and why each refusal is not negotiable:
3430
+ - a canonical role (SPEC.md 1.1 / 1.2). A page cannot
3431
+ redefine `action`: an agent that trusted the protocol's
3432
+ meaning of a canonical role would be reading a different
3433
+ contract on every page. This is the whole value of a closed
3434
+ vocabulary and a registry does not get to open it.
3435
+ - a declared alias (SPEC.md 1.5). Same reason, one level down.
3436
+ - a name that is not /^[a-z][a-z0-9-]*$/. Ids are opaque and
3437
+ roles are not: a role is compared, printed and published.
3438
+ - an event name that is not `nac:*`. A completion event that
3439
+ does not belong to this protocol cannot be waited for by
3440
+ anything that speaks it.
3441
+ Re-registering the SAME role with the SAME spec is idempotent
3442
+ and returns ok -- a page that registers on every render must not
3443
+ fail on the second one. Re-registering with a DIFFERENT spec
3444
+ throws: that is the one case where silence would leave two
3445
+ meanings for one word, which is where this release started. */
3446
+ function register_role(name, spec) {
3447
+ const raw = String(name == null ? '' : name);
3448
+ if (!/^[a-z][a-z0-9-]*$/.test(raw)) {
3449
+ throw NacError('invalid_role',
3450
+ 'register_role: "' + raw + '" is not a legal role name. A role is lowercase'
3451
+ + ' letters, digits and hyphens, starting with a letter (SPEC.md 1.4).');
3452
+ }
3453
+ if (_KNOWN_ROLES_V22.has(raw)) {
3454
+ throw NacError('role_is_canonical',
3455
+ 'register_role: "' + raw + '" is a canonical role of SPEC.md section 1 and cannot be'
3456
+ + ' redefined. An agent relies on a canonical role meaning the same thing on every'
3457
+ + ' page; a page that could change it would be publishing a different protocol.');
3458
+ }
3459
+ if (Object.prototype.hasOwnProperty.call(_ROLE_ALIASES, raw)) {
3460
+ throw NacError('role_is_alias',
3461
+ 'register_role: "' + raw + '" is a declared alias of "' + _ROLE_ALIASES[raw] +
3462
+ '" (SPEC.md 1.5) and cannot be redefined.');
3463
+ }
3464
+ spec = spec || {};
3465
+ const events = Array.isArray(spec.events) ? spec.events.slice(0, 2) : [];
3466
+ for (const ev of events) {
3467
+ if (typeof ev !== 'string' || ev.indexOf('nac:') !== 0) {
3468
+ throw NacError('invalid_role',
3469
+ 'register_role("' + raw + '"): completion event "' + String(ev) + '" is not a NAC3'
3470
+ + ' event name. A completion event must be nac:<family>:<name> so anything that'
3471
+ + ' speaks this protocol can wait for it (SPEC.md 6.4).');
3472
+ }
3473
+ }
3474
+ const entry = {
3475
+ role: raw,
3476
+ events: events,
3477
+ clickable: events.length > 0,
3478
+ describes: (typeof spec.describes === 'string') ? spec.describes : null,
3479
+ plugin: (typeof spec.plugin === 'string') ? spec.plugin : null,
3480
+ source: 'registered'
3481
+ };
3482
+ const prior = _REGISTERED_ROLES.get(raw);
3483
+ if (prior) {
3484
+ /* Idempotent on an identical re-registration: a page that
3485
+ registers its roles on every render must not fail on the
3486
+ second render. Different spec, same name -> throw, because
3487
+ that is two meanings for one word. */
3488
+ if (JSON.stringify(prior) === JSON.stringify(entry)) {
3489
+ return { ok: true, role: raw, already: true };
3490
+ }
3491
+ throw NacError('role_conflict',
3492
+ 'register_role("' + raw + '"): already registered with a different definition.'
3493
+ + ' Prior events=[' + prior.events.join(', ') + '], new events=[' +
3494
+ events.join(', ') + ']. Two definitions of one role is the drift this'
3495
+ + ' registry exists to prevent.');
3496
+ }
3497
+ _REGISTERED_ROLES.set(raw, entry);
3498
+ try {
3499
+ document.dispatchEvent(new CustomEvent('nac:role_registered', {
3500
+ detail: { role: raw, events: events, clickable: entry.clickable,
3501
+ describes: entry.describes, plugin: entry.plugin },
3502
+ bubbles: true
3503
+ }));
3504
+ } catch (_) { /* headless (section 19): no document to dispatch on */ }
3505
+ return { ok: true, role: raw, already: false };
3506
+ }
3507
+
3508
+ /* NAC.roles() -- the vocabulary, with the provenance of every
3509
+ word. Built so a consumer never has to ask which half of the
3510
+ contract a role came from: `canonical` is the protocol,
3511
+ `registered` is this page, `aliases` is what resolves to what.
3512
+ Published as data for the same reason section 1 is: a list a
3513
+ consumer has to reconstruct from prose is a list that rots. */
3514
+ function roles() {
3515
+ const registered = [];
3516
+ _REGISTERED_ROLES.forEach(function (v) { registered.push(v); });
3517
+ const click_events = {};
3518
+ for (const r in _CLICK_EVENT_FAMILY) {
3519
+ if (Object.prototype.hasOwnProperty.call(_CLICK_EVENT_FAMILY, r)) {
3520
+ click_events[r] = _CLICK_EVENT_FAMILY[r].slice();
3521
+ }
3522
+ }
3523
+ return {
3524
+ spec_version: '2.9',
3525
+ canonical: Array.from(_KNOWN_ROLES_V22),
3526
+ aliases: Object.assign({}, _ROLE_ALIASES),
3527
+ registered: registered,
3528
+ click_events: click_events,
3529
+ no_click_event: Array.from(_CLICK_NO_EVENT_ROLES)
3530
+ };
3531
+ }
3532
+
3533
+ /* NAC.canonical_role(role) -- what a spelling means. One line, and
3534
+ it exists because every consumer that compares a role to a
3535
+ constant needs the same answer this runtime gives itself. */
3536
+ function canonical_role(role) {
3537
+ return _canonicalRole(role);
3538
+ }
3539
+
2984
3540
  function snapshot_state() {
2985
3541
  const errs = _allElements()
2986
3542
  .filter(function (el) {
@@ -3144,7 +3700,11 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
3144
3700
  const _CLICK_EVENT_FAMILY = {
3145
3701
  'action': ['nac:action:succeeded', 'nac:action:failed'],
3146
3702
  'option': ['nac:field:changed'],
3147
- 'tab': ['nac:tab:activated'],
3703
+ /* v2.8.0: the failure half. nac:tab:activation_failed has been
3704
+ emitted since v2.2 and was not in this map, so click() on a
3705
+ tab whose activation was REFUSED waited out its full timeout
3706
+ instead of rejecting the moment the refusal arrived. */
3707
+ 'tab': ['nac:tab:activated', 'nac:tab:activation_failed'],
3148
3708
  'breadcrumb-item': ['nac:breadcrumb:navigated'],
3149
3709
  'accordion-toggle': ['nac:accordion:expanded', 'nac:accordion:collapsed'],
3150
3710
  'step': ['nac:step:advanced'],
@@ -3165,8 +3725,106 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
3165
3725
  column_nac_id and filter_nac_id as nac_id matches. */
3166
3726
  'sort-control': ['nac:table:sort_changed'],
3167
3727
  'filter-control': ['nac:table:filter_changed'],
3728
+ /* v2.7.0: `button` made EXPLICIT. SPEC.md section 1 says the
3729
+ runtime treats this role as `action`, and it did -- but only by
3730
+ falling through the `||` below, which is indistinguishable from
3731
+ a role nobody thought about. The fallback was right for this one
3732
+ role and wrong for the other eight, and nothing told them
3733
+ apart. Declaring it costs one line and removes the ambiguity
3734
+ that let the other eight hide. */
3735
+ 'button': ['nac:action:succeeded', 'nac:action:failed'],
3736
+
3737
+ /* ---- v2.8.0: the twelve clickable surface roles -------------
3738
+ Each line removes one five-second timeout that blamed the
3739
+ page. The runtime ALREADY emitted every event named here --
3740
+ nac:map:marker_selected has existed since 2.5 -- so the
3741
+ defect was never that the signal was missing: it was that
3742
+ click() did not know the signal belonged to that role, took
3743
+ the `|| _CLICK_EVENT_FAMILY['action']` fallback below, waited
3744
+ for nac:action:succeeded, heard nothing and reported that the
3745
+ WIDGET had not acknowledged. The project paid this twice
3746
+ before (v1.6.4 for `field`, v1.6.6 for `sort-control`, both
3747
+ comments above) and both times fixed one role instead of the
3748
+ class. These twelve are the class.
3749
+
3750
+ Where two events existed for the same thing, the canonical
3751
+ one is here and the other stays emitted (SPEC.md 6.4). */
3752
+ 'map-marker': ['nac:map:marker_selected'],
3753
+ 'map-layer': ['nac:map:layer_toggled'],
3754
+ 'chart-series': ['nac:chart:series_toggled'],
3755
+ 'calendar-event': ['nac:calendar:event_selected'],
3756
+ 'tree-node': ['nac:tree:selected'],
3757
+ 'carousel-slide': ['nac:carousel:slide_changed'],
3758
+ 'toast': ['nac:toast:dismissed'],
3759
+ 'banner': ['nac:banner:dismissed'],
3760
+ 'combobox': ['nac:field:changed'],
3761
+ 'listbox': ['nac:field:changed'],
3762
+ 'slider': ['nac:slider:value_changed'],
3763
+ 'richtext': ['nac:richtext:format_applied'],
3168
3764
  };
3169
3765
 
3766
+ /* The canonical roles that have NO completion event of their own,
3767
+ declared rather than left to the fallback.
3768
+
3769
+ THE DEFECT THIS CLOSES (TF-A14). _CLICK_EVENT_FAMILY knew 11 of
3770
+ the 20 canonical roles of SPEC.md section 1, and click() on
3771
+ anything else took `|| _CLICK_EVENT_FAMILY['action']` -- so it
3772
+ waited for nac:action:succeeded, heard nothing, timed out after
3773
+ five seconds and reported that the WIDGET had not acked. An agent
3774
+ doing exactly what the protocol tells it to do about one of these
3775
+ roles paid five seconds and got a message blaming the page.
3776
+
3777
+ And it is not hypothetical. The comments above record the same
3778
+ shape twice already: v1.6.4 for `field`, v1.6.6 for
3779
+ `sort-control`. Both were found by someone watching a click hang.
3780
+
3781
+ These nine are STRUCTURAL -- a plugin, a section, a region, a
3782
+ navigation landmark, a data-table host, a confirm dialog -- or
3783
+ are driven by their own verb rather than by click: a draggable and
3784
+ a drop target are what drag_drop() moves. None of them has a
3785
+ completion event in the protocol, so there is nothing for click()
3786
+ to wait for.
3787
+
3788
+ WHAT DOES NOT CHANGE, on purpose: click() still clicks them and
3789
+ still listens for the action family, because a host is free to
3790
+ make a region clickable and emit nac:action:succeeded, and that
3791
+ works today. Refusing outright would break those hosts for the
3792
+ sake of a tidier error. What changes is that the TIMEOUT now says
3793
+ what actually happened instead of blaming the widget -- see the
3794
+ rejection in click(). */
3795
+ const _CLICK_NO_EVENT_ROLES = new Set([
3796
+ 'plugin', 'section', 'region', 'navigation', 'data-table',
3797
+ 'confirm-dialog', 'draggable', 'drop-target',
3798
+
3799
+ /* ---- v2.8.0 ------------------------------------------------
3800
+ Thirty-three more, and declaring them is the whole point: a
3801
+ role in this Set gets a timeout message that says "this role
3802
+ has no completion event in the protocol", and a role in
3803
+ NEITHER map gets "no completion event is declared for this
3804
+ role" -- which is the protocol admitting a gap instead of
3805
+ blaming the widget. Until 2.8.0 these thirty-three were in
3806
+ neither map and were indistinguishable from a typo.
3807
+
3808
+ Why each is here rather than in the family map above: four
3809
+ are structural hosts (map, chart, calendar, tree, timeline,
3810
+ carousel, list), six are containers whose CONTROL carries the
3811
+ event (tablist, tabpanel, stepper, accordion-section,
3812
+ breadcrumb, pagination-control, toast-region), and the rest
3813
+ are read-only. Putting a read-only role in the family map
3814
+ would make click() promise a completion nobody emits, which
3815
+ is worse than the omission it would be fixing. */
3816
+ 'map', 'chart', 'chart-point', 'calendar',
3817
+ 'tree', 'tree-children', 'timeline', 'timeline-item',
3818
+ 'carousel', 'status', 'log', 'toast-region', 'feedback',
3819
+ 'modal', 'drawer', 'bottom-sheet',
3820
+ 'tablist', 'tabpanel', 'stepper', 'accordion-section',
3821
+ 'breadcrumb', 'pagination-control',
3822
+ 'avatar', 'presence-indicator', 'skeleton', 'empty-state',
3823
+ 'list', 'row', 'menu', 'label', 'value', 'paragraph', 'canvas',
3824
+ /* v2.9.0: the five document roles. Read-only, every one. */
3825
+ 'heading', 'list-item', 'code', 'code-inline', 'note',
3826
+ ]);
3827
+
3170
3828
  /* v1.6.4: field types whose click() act on a value (toggle).
3171
3829
  For these, the runtime synthesises nac:field:changed after
3172
3830
  el.click() so an automation runner sees a deterministic
@@ -3236,15 +3894,52 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
3236
3894
  var rect = el.getBoundingClientRect();
3237
3895
  hiddenByLayout = (rect.width === 0 && rect.height === 0);
3238
3896
  }
3239
- if (hiddenByAria || hiddenByLayout) {
3897
+ /* 2.7.0: the ANCESTOR reasons too, through the same function the
3898
+ probe uses.
3899
+
3900
+ Found on 2026-11-25 by the suite written for undrivable_until.
3901
+ The two checks above read the element ITSELF, while
3902
+ validate_global's probe reads `closest('[aria-hidden="true"]')`,
3903
+ `closest('[inert]')` and the computed style -- so the two
3904
+ disagreed about a button inside a hidden PANEL, which is the
3905
+ commonest shape there is. And section 10.1 publishes the
3906
+ agreement as a fact: the unreachable bucket is "exactly what
3907
+ NAC.click() refuses with NacError('hidden')". It was not. The
3908
+ probe called the seven chat ids of this project's own landing
3909
+ page unreachable and click() would have fired into the closed
3910
+ panel, where the host handler never runs and the agent waits out
3911
+ the five-second completion timeout for a click nobody could
3912
+ see -- the silent damage, arriving as a timeout instead of a
3913
+ reason. _probeUnreachable IS the definition now, for the verb
3914
+ and for the validator, so a disagreement between them is not
3915
+ expressible. Decided rather than registered because the
3916
+ normative text already promised this behaviour and the code was
3917
+ the half that was wrong (working agreement rule 10; the owner
3918
+ delegated the call for this session on 2026-11-25). */
3919
+ var hiddenByAncestor = _probeUnreachable(el);
3920
+ if (hiddenByAria || hiddenByLayout || hiddenByAncestor) {
3921
+ /* 2.7.0: if the manifest declared what opens this element, the
3922
+ rejection carries it. The refusal itself does not change --
3923
+ the element is hidden and clicking it would be a lie -- but an
3924
+ agent that gets "open nac_landing.chat.toggle first" has its
3925
+ next move, and one that gets "is not visible" has nothing.
3926
+ That gap was measured on this project's own landing page:
3927
+ seven declared ids behind a closed panel. */
3928
+ var gateId = _resolveGate(nac_id);
3929
+ var msg = 'Element ' + nac_id + ' is not visible'
3930
+ + (gateId ? ': it is declared undrivable until "' + gateId
3931
+ + '" is operated -- do that first, then retry' : '');
3240
3932
  _emitCommandRejected({
3241
3933
  command_method: 'click',
3242
3934
  command_target: nac_id,
3243
3935
  reason: 'hidden',
3244
- message: 'Element ' + nac_id + ' is not visible',
3936
+ message: msg,
3937
+ gate: gateId || undefined,
3245
3938
  source: (opts && opts.source) || undefined,
3246
3939
  });
3247
- throw NacError('hidden', 'Element ' + nac_id + ' is not visible');
3940
+ var hiddenErr = NacError('hidden', msg);
3941
+ if (gateId) hiddenErr.gate = gateId;
3942
+ throw hiddenErr;
3248
3943
  }
3249
3944
  /* v1.9.0 ARIA preflight (sec 7.3.3): inert ancestor + aria-busy
3250
3945
  block click before the host handler runs. Disabled is already
@@ -3273,8 +3968,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
3273
3968
  await _resolveVersionExpectations(opts, el);
3274
3969
  }
3275
3970
  }
3276
- const role = el.getAttribute('data-nac-role') || 'action';
3277
- const family = _CLICK_EVENT_FAMILY[role] || _CLICK_EVENT_FAMILY['action'];
3971
+ /* v2.8.0: resolve a declared alias (SPEC.md 1.5) BEFORE picking
3972
+ the family, so a page that still writes `treenode` gets the
3973
+ tree-node completion event instead of the action fallback. */
3974
+ const role = _canonicalRole(el.getAttribute('data-nac-role') || 'action');
3975
+ const family = _CLICK_EVENT_FAMILY[role]
3976
+ || (_REGISTERED_ROLES.has(role) && _REGISTERED_ROLES.get(role).events)
3977
+ || _CLICK_EVENT_FAMILY['action'];
3278
3978
  /* The first event in each family is the "success" signal; if a
3279
3979
  second entry exists it is the "failure" signal. Some families
3280
3980
  (option, tab, breadcrumb, step, pagination) have no failure
@@ -3285,8 +3985,19 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
3285
3985
  const successEvents = [family[0]];
3286
3986
  const failureEvents = family.length > 1 ? [family[1]] : [];
3287
3987
  if (role !== 'action') {
3288
- successEvents.push('nac:action:succeeded');
3289
- failureEvents.push('nac:action:failed');
3988
+ /* Deduplicated since 2.7.0. A role with no family of its own
3989
+ falls back to the action family above and then had it pushed
3990
+ again, so the timeout message read "did not emit any of
3991
+ [nac:action:succeeded, nac:action:succeeded,
3992
+ nac:action:failed, nac:action:failed]" -- which makes a reader
3993
+ hunt for two contracts where there is one. Harmless to the
3994
+ listeners, confusing in the one place anybody reads. */
3995
+ if (successEvents.indexOf('nac:action:succeeded') < 0) {
3996
+ successEvents.push('nac:action:succeeded');
3997
+ }
3998
+ if (failureEvents.indexOf('nac:action:failed') < 0) {
3999
+ failureEvents.push('nac:action:failed');
4000
+ }
3290
4001
  }
3291
4002
  /* v1.6.5: cache plugin slug + option value/text BEFORE el.click()
3292
4003
  fires. The host's click handler may DETACH el from the DOM
@@ -3332,10 +4043,28 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
3332
4043
  if (settled) return;
3333
4044
  settled = true;
3334
4045
  cleanup();
4046
+ /* Say WHY nothing arrived (TF-A14). The old message named the
4047
+ events and the elapsed time, which reads as "the widget did
4048
+ not ack" -- and for a role with no completion event in the
4049
+ protocol that is the wrong diagnosis in the one case where
4050
+ the runtime already knows the answer. Five seconds and a
4051
+ misattributed failure, per control. */
4052
+ const knownFamily = Object.prototype.hasOwnProperty.call(_CLICK_EVENT_FAMILY, role);
4053
+ let why = '';
4054
+ if (_CLICK_NO_EVENT_ROLES.has(role)) {
4055
+ why = ' -- role "' + role + '" has no completion event in NAC3: it is structural, or'
4056
+ + ' it is driven by its own verb (a draggable and a drop-target are what drag_drop()'
4057
+ + ' moves). If this control is meant to be clickable, have its handler emit'
4058
+ + ' nac:action:succeeded (NAC.bindAction does it for you).';
4059
+ } else if (!knownFamily) {
4060
+ why = ' -- role "' + role + '" is not one of the canonical roles of SPEC.md section 1,'
4061
+ + ' so this runtime waited for the action family by default. Declare a canonical'
4062
+ + ' role, or emit nac:action:succeeded from the handler.';
4063
+ }
3335
4064
  reject(NacError('timeout',
3336
4065
  'click(' + nac_id + ', role=' + role + ') did not emit any of [' +
3337
4066
  successEvents.concat(failureEvents).join(', ') + '] within ' +
3338
- timeout_ms + 'ms'));
4067
+ timeout_ms + 'ms' + why));
3339
4068
  }, timeout_ms);
3340
4069
  successEvents.forEach(function (n) { document.addEventListener(n, onSucceeded); });
3341
4070
  failureEvents.forEach(function (n) { document.addEventListener(n, onFailed); });
@@ -3404,7 +4133,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
3404
4133
  d.stepper_id === nac_id || d.carousel_id === nac_id ||
3405
4134
  d.timeline_id === nac_id || d.option_id === nac_id ||
3406
4135
  d.table_id === nac_id ||
3407
- /* v1.6.x legacy aliases (deprecated, removed in v2.0). */
4136
+ /* v1.6.x legacy aliases. NOT deprecated-with-a-date any
4137
+ more (D-12, 2026-11-24): these six are RESOLUTION KEYS
4138
+ -- this is the code that reads them -- so the v2.0
4139
+ removal the comment used to announce would have broken
4140
+ event resolution for any host emitting only an alias.
4141
+ Frozen: they resolve for good, the canonical field is
4142
+ still the one to emit. */
3408
4143
  d.nac_id === nac_id || d.from_nac_id === nac_id ||
3409
4144
  d.target_nac_id === nac_id || d.id === nac_id ||
3410
4145
  d.column_nac_id === nac_id || d.filter_nac_id === nac_id ||
@@ -4714,13 +5449,63 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4714
5449
  emission.)
4715
5450
 
4716
5451
  A NAC-3 codebase that wants drift to be a CI blocker should run
4717
- this in addition to the per-plugin validate(slug) loop. */
4718
- function validate_global() {
5452
+ this in addition to the per-plugin validate(slug) loop.
5453
+
5454
+ THE opts ARGUMENT (2.7.0, audit N-35 / TF-A16). SPEC.md section
5455
+ 5.2 has published the signature as
5456
+ validate_global(opts?: {probe?: boolean}) since 2.5, and section
5457
+ 8 keys two conformance levels on it: level 2 wants
5458
+ validate_global({probe: false}) with zero error findings, level 3
5459
+ wants validate_global({probe: true}) with zero findings of ANY
5460
+ severity. This function TOOK NO ARGUMENTS. Passing {probe:true}
5461
+ was accepted and ignored, so the level 3 check was the level 2
5462
+ check with a stricter threshold and the word "probe" meant
5463
+ nothing -- measured while building the reference validator, and
5464
+ written into scripts/contract-api.meta.json as the reason no tool
5465
+ could decide that requirement.
5466
+
5467
+ What probing IS, now that it is defined: the static half of this
5468
+ validator compares two LISTS -- the manifests and the ids present
5469
+ in the DOM. It never asks whether a declared element can actually
5470
+ be reached, so the two failures an agent hits most do not appear
5471
+ in the report:
5472
+
5473
+ ambiguous the same nac_id is on 2+ DOM nodes under ONE
5474
+ manifest. find() takes the first, so click()
5475
+ silently operates on whichever node the document
5476
+ happens to list first. The duplicates bucket does
5477
+ NOT cover this: it compares manifests to each
5478
+ other, not the DOM to itself.
5479
+ unreachable the element is mounted but an agent cannot touch
5480
+ it -- an aria-hidden or inert ancestor, or a box
5481
+ that is not displayed. click() would reject it
5482
+ with NacError('hidden'), so the manifest declares
5483
+ a surface the protocol cannot operate.
5484
+
5485
+ Both buckets exist in the report ALWAYS, and are empty unless
5486
+ probe is true: a consumer reading the shape does not have to
5487
+ branch on the argument, and a caller who never passes opts gets
5488
+ exactly the report 2.5 gave them. Probing reads the DOM and
5489
+ reads computed style; it clicks nothing and mutates nothing. */
5490
+ function validate_global(opts) {
5491
+ _nac_requireDocument('validate_global');
5492
+ const probe = !!(opts && opts.probe);
4719
5493
  const out = {
4720
5494
  ok: true,
5495
+ probed: probe,
4721
5496
  duplicates: [],
4722
5497
  orphans: [],
4723
5498
  unmounted: [],
5499
+ ambiguous: [],
5500
+ unreachable: [],
5501
+ /* 2.7.0: declared-and-gated surfaces. This bucket is NOT a
5502
+ findings bucket -- an element that declares what opens it is
5503
+ keeping the contract, not breaking it -- and like the two
5504
+ probe buckets above it is always present and empty unless the
5505
+ caller asked to probe. It is reported because an agent reading
5506
+ the validation output is exactly who needs to know that four
5507
+ of these ids need a panel opened first. */
5508
+ gated: [],
4724
5509
  convention_violations: [],
4725
5510
  /* v2.5 / RFC V24-01: plugin slug uniqueness findings live in
4726
5511
  their own bucket so CI integrations can gate on them
@@ -4780,12 +5565,15 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4780
5565
  - if not in idIndex, it is an orphan.
4781
5566
  - track DOM-side seen ids to compute unmounted = manifest \ DOM. */
4782
5567
  const inDom = Object.create(null);
5568
+ const domNodes = Object.create(null);
4783
5569
  if (typeof document !== 'undefined') {
4784
5570
  const all = document.querySelectorAll('[data-nac-id]');
4785
5571
  Array.prototype.forEach.call(all, function (el) {
4786
5572
  const id = el.getAttribute('data-nac-id');
4787
5573
  if (!id) return;
4788
5574
  inDom[id] = true;
5575
+ if (!domNodes[id]) domNodes[id] = [];
5576
+ domNodes[id].push(el);
4789
5577
  if (!idIndex[id]) {
4790
5578
  /* Orphan in DOM but not in any manifest. Note: tabs
4791
5579
  frequently are declared in DOM-only because the host
@@ -4816,6 +5604,80 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4816
5604
  }
4817
5605
  }
4818
5606
 
5607
+ /* 2.7.0: the probe pass (opts.probe). Only declared ids are
5608
+ probed: an id nothing declares is already reported as an
5609
+ orphan, and a brownfield page full of them is the normal case
5610
+ this validator was built to tolerate. */
5611
+ if (probe && typeof document !== 'undefined') {
5612
+ for (const id in idIndex) {
5613
+ const nodes = domNodes[id] || [];
5614
+ if (nodes.length >= 2) {
5615
+ out.ambiguous.push({
5616
+ code: 'nac_id_ambiguous_in_dom',
5617
+ severity: 'error',
5618
+ nac_id: id, count: nodes.length,
5619
+ plugin: idIndex[id][0],
5620
+ hint: 'find() resolves the first match, so which element an '
5621
+ + 'agent operates depends on document order',
5622
+ });
5623
+ }
5624
+ if (nodes.length === 1) {
5625
+ const why = _probeUnreachable(nodes[0]);
5626
+ if (why) {
5627
+ /* 2.7.0: a surface that DECLARES what opens it is not a
5628
+ defect -- it is a gated surface, and the agent now has
5629
+ its next move. The declaration is only honoured when the
5630
+ gate itself holds up; see _resolveGate. */
5631
+ const gate = _resolveGate(id);
5632
+ const gateNodes = gate ? (domNodes[gate] || []) : [];
5633
+ /* The four ways a declared gate fails to be a way in. They
5634
+ are separate values because they are separate fixes: one
5635
+ is a manifest that forgot the gate, one is a view that
5636
+ has not mounted it, one is an id on two nodes -- where
5637
+ find() picks by document order, so "operate the gate"
5638
+ does not name one thing -- and one is a gate behind its
5639
+ own closed container. */
5640
+ const gateBad = !gate ? null
5641
+ : (!idIndex[gate] ? 'gate_not_declared'
5642
+ : (gateNodes.length === 0 ? 'gate_not_mounted'
5643
+ : (gateNodes.length >= 2 ? 'gate_ambiguous'
5644
+ : (_probeUnreachable(gateNodes[0]) ? 'gate_not_reachable'
5645
+ : null))));
5646
+ if (gate && !gateBad) {
5647
+ out.gated.push({
5648
+ code: 'nac_id_undrivable_until_gate',
5649
+ severity: 'info',
5650
+ nac_id: id, reason: why, gate: gate,
5651
+ plugin: idIndex[id][0],
5652
+ hint: 'declared as undrivable until "' + gate + '" is operated; '
5653
+ + 'click() refuses it until then and says so',
5654
+ });
5655
+ } else if (gate) {
5656
+ out.unreachable.push({
5657
+ code: 'nac_id_undrivable_gate_unusable',
5658
+ severity: 'error',
5659
+ nac_id: id, reason: why, gate: gate, gate_problem: gateBad,
5660
+ plugin: idIndex[id][0],
5661
+ hint: 'undrivable_until names "' + gate + '", and that gate is '
5662
+ + gateBad.replace(/_/g, ' ') + ' -- a promised way in that '
5663
+ + 'does not open is worse than none, an agent waits for it',
5664
+ });
5665
+ } else {
5666
+ out.unreachable.push({
5667
+ code: 'nac_id_declared_not_reachable',
5668
+ severity: 'warn',
5669
+ nac_id: id, reason: why,
5670
+ plugin: idIndex[id][0],
5671
+ hint: 'click() would reject this id with NacError(hidden). If the '
5672
+ + 'surface is gated on purpose, declare undrivable_until with '
5673
+ + 'the id that opens it',
5674
+ });
5675
+ }
5676
+ }
5677
+ }
5678
+ }
5679
+ }
5680
+
4819
5681
  /* v1.6.1: tolerated_violations support. Hosts retiring historic
4820
5682
  findings incrementally can register a tolerated set via
4821
5683
  NAC.set_validation_tolerance({tolerated:[...]}); each finding
@@ -4833,7 +5695,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4833
5695
  const k = String(t.kind || '') + '::' + String(t.nac_id || '');
4834
5696
  tolSet[k] = t.until || true;
4835
5697
  });
4836
- ['duplicates', 'orphans', 'unmounted', 'convention_violations'].forEach(function (kind) {
5698
+ ['duplicates', 'orphans', 'unmounted', 'ambiguous', 'unreachable',
5699
+ 'convention_violations'].forEach(function (kind) {
4837
5700
  const kept = [];
4838
5701
  out[kind].forEach(function (item) {
4839
5702
  const k = kind + '::' + item.nac_id;
@@ -4850,15 +5713,49 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4850
5713
  });
4851
5714
  }
4852
5715
 
4853
- out.ok = !out.duplicates.length;
5716
+ /* 2.7.0: ambiguous joins duplicates in the hard-error gate. Both
5717
+ mean the same thing to an agent -- an id that does not resolve
5718
+ to one element -- and the bucket is empty unless the caller
5719
+ asked to probe, so a 2.5 caller sees the same booleans. */
5720
+ out.ok = !out.duplicates.length && !out.ambiguous.length;
4854
5721
  /* v1.6.1: explicit has_errors flag for CI integration. Drift
4855
5722
  findings (duplicates) are hard-errors per spec sec 7.3.2;
4856
5723
  orphans + unmounted + convention_violations stay informative
4857
5724
  unless the host explicitly opts in via tolerance config. */
4858
- out.has_errors = out.duplicates.length > 0;
5725
+ out.has_errors = out.duplicates.length > 0 || out.ambiguous.length > 0;
4859
5726
  return out;
4860
5727
  }
4861
5728
 
5729
+ /* Why an element a manifest declares cannot be operated, or null.
5730
+ The three reasons are the ones click() itself refuses on, so the
5731
+ probe and the verb agree: a probe that reported something click()
5732
+ accepts, or missed something it rejects, would be worse than no
5733
+ probe. Everything is in a try: a host whose getComputedStyle
5734
+ throws gets a report without this bucket, not an exception out of
5735
+ a validator. */
5736
+ function _probeUnreachable(el) {
5737
+ if (!el) return null;
5738
+ try {
5739
+ if (el.closest && el.closest('[aria-hidden="true"]')) return 'aria_hidden';
5740
+ } catch (_) {}
5741
+ try {
5742
+ if (el.closest && el.closest('[inert]')) return 'inert_ancestor';
5743
+ } catch (_) {}
5744
+ try {
5745
+ const view = (el.ownerDocument && el.ownerDocument.defaultView)
5746
+ || (typeof window !== 'undefined' ? window : null);
5747
+ if (view && typeof view.getComputedStyle === 'function') {
5748
+ const st = view.getComputedStyle(el);
5749
+ if (st) {
5750
+ if (st.display === 'none') return 'not_displayed';
5751
+ if (st.visibility === 'hidden') return 'not_displayed';
5752
+ if (String(st.opacity) === '0') return 'not_displayed';
5753
+ }
5754
+ }
5755
+ } catch (_) {}
5756
+ return null;
5757
+ }
5758
+
4862
5759
  /* v1.6.1: tolerance config storage + setter. The shape:
4863
5760
  {
4864
5761
  tolerated: [
@@ -4889,14 +5786,51 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4889
5786
  are wrapped automatically when no resolver is set. */
4890
5787
  const _optionResolvers = Object.create(null);
4891
5788
 
5789
+ /* The resolver key, which has to be INJECTIVE (TF-A05).
5790
+
5791
+ It used to be:
5792
+
5793
+ String(plugin || '') + '::' + String(field_id || '')
5794
+
5795
+ and that collided in two independent ways:
5796
+
5797
+ 1. `String(x || '')` maps undefined, null, '', 0 and false all
5798
+ onto the empty string, so a resolver registered with no
5799
+ plugin and one registered with plugin '' were the same entry
5800
+ -- the second silently replaced the first.
5801
+ 2. '::' as a separator with nothing escaping it: ('a::b', 'c')
5802
+ and ('a', 'b::c') both produce 'a::b::c'. SPEC.md does not
5803
+ restrict the characters of a field_id, so a '::' inside one
5804
+ is legal, and two different fields could share a resolver.
5805
+
5806
+ The length prefix makes the split unambiguous: knowing how long
5807
+ the plugin part is, there is exactly one way to read the key back.
5808
+ The separator stays for readability in a debugger, but nothing
5809
+ depends on it being unique any more. */
4892
5810
  function _resolverKey(plugin, field_id) {
4893
- return String(plugin || '') + '::' + String(field_id || '');
5811
+ const p = plugin == null ? '' : String(plugin);
5812
+ const f = field_id == null ? '' : String(field_id);
5813
+ return p.length + ':' + p + '::' + f;
4894
5814
  }
4895
5815
 
4896
5816
  function set_options_resolver(plugin, field_id, fn) {
4897
5817
  if (typeof fn !== 'function') {
4898
5818
  throw NacError('invalid', 'resolver fn required');
4899
5819
  }
5820
+ /* And refuse the empty case outright rather than keying on ''.
5821
+ A resolver with no plugin or no field is a programming error,
5822
+ and before this it was an error that looked like success until
5823
+ something else overwrote the entry. The sibling guard above
5824
+ already throws for a missing fn; this is the same shape. */
5825
+ if (plugin == null || String(plugin) === '') {
5826
+ throw NacError('invalid',
5827
+ 'set_options_resolver: plugin is required -- a resolver with no plugin'
5828
+ + ' used to be stored under the empty key, where the next one replaced it');
5829
+ }
5830
+ if (field_id == null || String(field_id) === '') {
5831
+ throw NacError('invalid',
5832
+ 'set_options_resolver: field_id is required -- see the note on plugin');
5833
+ }
4900
5834
  _optionResolvers[_resolverKey(plugin, field_id)] = fn;
4901
5835
  }
4902
5836
 
@@ -5679,6 +6613,10 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
5679
6613
  function step_to(stepper_id, n) {
5680
6614
  const steps = _stepperSteps(stepper_id);
5681
6615
  if (!steps.length) throw NacError('stepper_not_found', stepper_id);
6616
+ /* n slots for n steps, 0..n-1: this SELECTS one of the steps that
6617
+ exist. Same limit as reorder(), which also moves within n.
6618
+ drag_drop() bounds to n instead, because inserting into a list
6619
+ of n has n + 1 slots (TF-A07). */
5682
6620
  n = Math.max(0, Math.min(steps.length - 1, Number(n)));
5683
6621
  const prior = step_state(stepper_id).current;
5684
6622
  steps.forEach(function (s, i) {
@@ -6223,6 +7161,15 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6223
7161
  var siblings = Array.prototype.slice.call(list.querySelectorAll(
6224
7162
  '[data-nac-role="draggable"]'));
6225
7163
  var from_index = siblings.indexOf(item);
7164
+ /* Bounded to siblings.length - 1, NOT siblings.length, and the
7165
+ difference from drag_drop() is deliberate (TF-A07): this MOVES
7166
+ an item that is already one of the n, so there are n landing
7167
+ slots, 0..n-1. drag_drop() INSERTS an item the list does not
7168
+ hold yet, so it has n + 1. step_to() selects one of n existing
7169
+ steps: n slots, like here.
7170
+ Three bounds, two limits, one reason -- written at all three
7171
+ sites because it was written at none, and a reader comparing
7172
+ them could not tell a deliberate asymmetry from a slip. */
6226
7173
  var bounded = Math.max(0, Math.min(to_index, siblings.length - 1));
6227
7174
  if (from_index === -1) {
6228
7175
  return Promise.reject(new NacError('invalid',
@@ -6236,13 +7183,36 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6236
7183
  list.insertBefore(item, ref);
6237
7184
  }
6238
7185
  }
7186
+ /* Say whether the index was ACOTADO (TF-A06).
7187
+
7188
+ The old pair was: emit to_index = bounded, resolve { ok: true }.
7189
+ So a consumer asking for index 99 in a list of three got
7190
+ ok: true and no index at all from the promise, and the event
7191
+ reported 2 with nothing marking it as clamped. "I moved it where
7192
+ you asked" and "I moved it as far as it would go" were
7193
+ indistinguishable -- for an agent deciding whether its plan
7194
+ worked, those are different answers.
7195
+
7196
+ requested_index and bounded are ADDITIVE: to_index still means
7197
+ what it meant, so nothing reading it breaks. */
7198
+ var wasBounded = bounded !== to_index;
6239
7199
  _emit('nac:list:reordered', {
6240
- list_id: list_id,
6241
- item_id: item_id,
6242
- from_index: from_index,
6243
- to_index: bounded,
7200
+ list_id: list_id,
7201
+ item_id: item_id,
7202
+ from_index: from_index,
7203
+ to_index: bounded,
7204
+ requested_index: to_index,
7205
+ bounded: wasBounded,
7206
+ });
7207
+ return Promise.resolve({
7208
+ ok: true,
7209
+ list_id: list_id,
7210
+ item_id: item_id,
7211
+ from_index: from_index,
7212
+ to_index: bounded,
7213
+ requested_index: to_index,
7214
+ bounded: wasBounded,
6244
7215
  });
6245
- return Promise.resolve({ ok: true });
6246
7216
  }
6247
7217
 
6248
7218
  /* ---------- v1.6.2: drag_drop (implements spec sec 13.4) -------- */
@@ -6342,6 +7312,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6342
7312
 
6343
7313
  source.setAttribute('data-nac-state', 'dragging');
6344
7314
  /* v1.7.0: emit canonical source_id + legacy from_nac_id alias.
7315
+ The alias is frozen, not pending removal (D-12): the matcher
7316
+ resolves events by it.
6345
7317
  Plugin scope from the source's data-nac-plugin ancestor so
6346
7318
  sec 6.2.1 universal base (plugin + plugin_instance_id) is
6347
7319
  satisfied. v1.7 round 3 conformance FAILed without these. */
@@ -6354,11 +7326,34 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6354
7326
  };
6355
7327
  _emit('nac:drag:started', Object.assign({}, dragPluginCtx, {
6356
7328
  source_id: source_nac_id,
6357
- from_nac_id: source_nac_id, /* legacy, removed v2.0 */
7329
+ from_nac_id: source_nac_id, /* legacy alias, frozen (D-12) */
6358
7330
  }));
6359
7331
 
6360
- /* Tiny delay so the focus pulse is observable before the DOM
6361
- move settles. Mirrors the demo's existing UX. */
7332
+ /* The settle delay, now the HOST's choice (TF-A02).
7333
+
7334
+ Why it exists: a focus pulse on the source is only visible to a
7335
+ human reviewer if the DOM move waits for it. The 80 ms was this
7336
+ repository's demo UX, hard-coded into the library -- so every
7337
+ adopter paid it, including the ones with no reviewer watching
7338
+ and the ones driving a thousand moves in a test.
7339
+
7340
+ The DEFAULT STAYS 80. Dropping it to zero would change the
7341
+ timing of every existing adopter's drop for the sake of
7342
+ tidiness, and a host that liked the pulse would lose it without
7343
+ asking. What changes is that it can now be set:
7344
+
7345
+ NAC.drag_drop(a, b, { settle_ms: 0 }) per call
7346
+ NAC.drag_settle_ms = 0 per host
7347
+
7348
+ opts wins over the global, and the global defaults to the
7349
+ historical 80. Zero is honoured -- `|| 80` would have silently
7350
+ turned the useful value back into the default, which is the
7351
+ usual way an option like this ends up not working. */
7352
+ var settleMs = (opts && typeof opts.settle_ms === 'number')
7353
+ ? Math.max(0, opts.settle_ms)
7354
+ : ((global.NAC && typeof global.NAC.drag_settle_ms === 'number')
7355
+ ? Math.max(0, global.NAC.drag_settle_ms)
7356
+ : 80);
6362
7357
  return new Promise(function (resolve, reject) {
6363
7358
  setTimeout(function () {
6364
7359
  try {
@@ -6366,17 +7361,66 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6366
7361
  _emit('nac:drag:over', Object.assign({}, dragPluginCtx, {
6367
7362
  source_id: source_nac_id, /* v1.7.0 canonical */
6368
7363
  target_id: target_nac_id, /* v1.7.0 canonical */
6369
- from_nac_id: source_nac_id, /* legacy, drop v2.0 */
6370
- over_nac_id: target_nac_id, /* legacy, drop v2.0 */
7364
+ from_nac_id: source_nac_id, /* legacy, frozen D-12 */
7365
+ over_nac_id: target_nac_id, /* legacy, frozen D-12 */
6371
7366
  }));
6372
- /* Remove any "drop here" placeholder the demo stages. */
6373
- var empty = target.querySelector('.ne-drag-empty');
6374
- if (empty) empty.parentNode.removeChild(empty);
7367
+ /* Remove a "drop here" placeholder, IF THE HOST DECLARED ONE.
7368
+
7369
+ TF-A01. Until 2.7.0 this line was:
7370
+
7371
+ var empty = target.querySelector('.ne-drag-empty');
7372
+ if (empty) empty.parentNode.removeChild(empty);
7373
+
7374
+ -- the runtime deleting a node out of the host's document
7375
+ because of a CSS class name that belongs to THIS
7376
+ repository's demo (css/example.css, js/example.js). The
7377
+ class is real here; what was never real is the agreement.
7378
+ Nothing obliges an adopter to avoid `ne-drag-empty`, and
7379
+ an adopter who happens to use it for anything else lost
7380
+ the element on the first drop, silently, with no way to
7381
+ switch it off.
7382
+
7383
+ A library may not reach into a document it did not write
7384
+ on a convention it invented. So the default is now to
7385
+ remove NOTHING, and a host that wants placeholder removal
7386
+ asks for it, in the idiom the rest of the protocol uses --
7387
+ an attribute on the element that owns the contract:
7388
+
7389
+ <ul data-nac-role="drop-target"
7390
+ data-nac-drop-placeholder=".ne-drag-empty">
7391
+
7392
+ NAC.drop_placeholder_selector is the tree-wide default for
7393
+ a host that wants it everywhere; it is null, and the
7394
+ per-target attribute wins over it. The selector is only
7395
+ ever queried INSIDE the target, so a host cannot be made
7396
+ to delete something elsewhere in its page by accident. */
7397
+ var placeholderSel = target.getAttribute('data-nac-drop-placeholder')
7398
+ || (global.NAC && global.NAC.drop_placeholder_selector) || null;
7399
+ if (placeholderSel) {
7400
+ var stale = target.querySelectorAll(placeholderSel);
7401
+ for (var pi = 0; pi < stale.length; pi++) {
7402
+ if (stale[pi].parentNode) stale[pi].parentNode.removeChild(stale[pi]);
7403
+ }
7404
+ }
6375
7405
  /* Optional to_index for ordered drop-targets; otherwise
6376
7406
  append at end. */
6377
7407
  if (typeof opts.to_index === 'number') {
6378
7408
  var siblings = Array.prototype.slice.call(
6379
7409
  target.querySelectorAll('[data-nac-role="draggable"]'));
7410
+ /* Bounded to siblings.length, NOT siblings.length - 1, and
7411
+ the difference from reorder() is deliberate (TF-A07).
7412
+
7413
+ This is an INSERT into a list the item is not in yet, so
7414
+ a list of n items has n + 1 landing slots: before each
7415
+ of the n, plus after the last. reorder() MOVES an item
7416
+ that is already among the n, so it has n slots, and
7417
+ bounds to n - 1. step_to() selects one of n existing
7418
+ steps: also n - 1.
7419
+
7420
+ Three bounds, two limits, one reason -- written down
7421
+ here because it was not, and a reader comparing the
7422
+ three had no way to tell a deliberate asymmetry from a
7423
+ copy-paste slip. */
6380
7424
  var bounded = Math.max(0, Math.min(opts.to_index, siblings.length));
6381
7425
  var ref = siblings[bounded] || null;
6382
7426
  if (ref) target.insertBefore(source, ref);
@@ -6389,8 +7433,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6389
7433
  _emit('nac:drag:dropped', Object.assign({}, dragPluginCtx, {
6390
7434
  source_id: source_nac_id, /* v1.7.0 canonical */
6391
7435
  target_id: target_nac_id, /* v1.7.0 canonical */
6392
- from_nac_id: source_nac_id, /* legacy, drop v2.0 */
6393
- target_nac_id: target_nac_id, /* legacy, drop v2.0 */
7436
+ from_nac_id: source_nac_id, /* legacy, frozen D-12 */
7437
+ target_nac_id: target_nac_id, /* legacy, frozen D-12 */
6394
7438
  value: opts.value !== undefined ? opts.value : null,
6395
7439
  }));
6396
7440
  resolve({ ok: true, source: source_nac_id, target: target_nac_id });
@@ -6399,7 +7443,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6399
7443
  target.setAttribute('data-nac-state', 'idle');
6400
7444
  _emit('nac:drag:cancelled', Object.assign({}, dragPluginCtx, {
6401
7445
  source_id: source_nac_id, /* v1.7.0 canonical */
6402
- from_nac_id: source_nac_id, /* legacy, drop v2.0 */
7446
+ from_nac_id: source_nac_id, /* legacy, frozen D-12 */
6403
7447
  reason: 'aborted',
6404
7448
  error: err && err.message ? err.message : String(err),
6405
7449
  }));
@@ -6417,7 +7461,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6417
7461
  reject(err instanceof Error ? err :
6418
7462
  new NacError('invalid', String(err)));
6419
7463
  }
6420
- }, 80);
7464
+ }, settleMs);
6421
7465
  });
6422
7466
  }
6423
7467
 
@@ -6871,6 +7915,413 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6871
7915
  return hex;
6872
7916
  }
6873
7917
 
7918
+ /* ---------- 2.7.0: manifest authenticity (sec 7.2) ------------
7919
+
7920
+ WHAT THIS CLOSES. Section 7.2 has published, since 1.9, a worked
7921
+ example of an HMAC-signed manifest: set the tenant secret, pass a
7922
+ provenance block to register(), and "the runtime computes the
7923
+ expected HMAC over a stable serialisation of the manifest
7924
+ (excluding the signature itself) and rejects manifests whose
7925
+ signature does not match". None of that existed. sign_provenance /
7926
+ verify_provenance (above) sign an EVENT's detail.source and have
7927
+ never looked at a manifest, and register() stored whatever object
7928
+ it was handed. So conformance level 3 -- whose first requirement
7929
+ is "carries HMAC-signed manifests" -- could not be asserted by any
7930
+ tool, which is the measured finding audit N-36 / PND-045 records
7931
+ and what scripts/contract-api.meta.json says in the note on that
7932
+ requirement: "the runtime exposes no manifest verification at all
7933
+ ... which is why no tool can assert level 3 today".
7934
+
7935
+ WHY A HAND-WRITTEN SHA-256 AND NOT SubtleCrypto. Because
7936
+ register() is SYNCHRONOUS and throws -- that is its whole
7937
+ contract, and STRICT_VALIDATION made it a hard gate in 2.3.
7938
+ crypto.subtle.sign returns a Promise, so a register() built on it
7939
+ could only verify AFTER returning: the manifest would already be
7940
+ live, the host would already have gone on to click things, and the
7941
+ rejection would arrive as a console message in a later tick. That
7942
+ is silent damage with extra steps. A synchronous digest is ~70
7943
+ lines, has fixed test vectors anybody can check (FIPS 180-4 for
7944
+ the digest, RFC 4231 for the HMAC -- both are in
7945
+ runtime/test/manifest-hmac.mjs), needs no DOM, no network and no
7946
+ Node built-in, and lets the signature be refused at the only
7947
+ moment where refusing costs nothing.
7948
+
7949
+ WHAT IT DOES NOT DO, said plainly: it does not make a manifest
7950
+ trustworthy. The secret lives in the page, so an agent with
7951
+ user-level access reads it (sec 7.3 says exactly this). What it
7952
+ buys is the multi-tenant case 7.2 names -- tenant A cannot hand
7953
+ tenant B's host a manifest it did not sign -- and an answer to
7954
+ "can anything here say it verified this?" that is not "no". */
7955
+
7956
+ const _SHA256_K = [
7957
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
7958
+ 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
7959
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
7960
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
7961
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
7962
+ 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
7963
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
7964
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
7965
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
7966
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
7967
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
7968
+ 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
7969
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
7970
+ 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
7971
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
7972
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
7973
+ ];
7974
+
7975
+ function _rotr32(x, n) { return ((x >>> n) | (x << (32 - n))) >>> 0; }
7976
+
7977
+ /* UTF-8 bytes without TextEncoder, so the digest works in any host
7978
+ that can run the rest of this file (old WebViews included). */
7979
+ function _utf8Bytes(str) {
7980
+ str = String(str);
7981
+ if (typeof TextEncoder !== 'undefined') {
7982
+ return new TextEncoder().encode(str);
7983
+ }
7984
+ const out = [];
7985
+ for (let i = 0; i < str.length; i++) {
7986
+ let c = str.charCodeAt(i);
7987
+ if (c < 0x80) { out.push(c); continue; }
7988
+ if (c < 0x800) {
7989
+ out.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
7990
+ continue;
7991
+ }
7992
+ if (c >= 0xd800 && c <= 0xdbff && i + 1 < str.length) {
7993
+ const lo = str.charCodeAt(i + 1);
7994
+ if (lo >= 0xdc00 && lo <= 0xdfff) {
7995
+ c = 0x10000 + ((c - 0xd800) << 10) + (lo - 0xdc00);
7996
+ i++;
7997
+ out.push(0xf0 | (c >> 18), 0x80 | ((c >> 12) & 0x3f),
7998
+ 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
7999
+ continue;
8000
+ }
8001
+ }
8002
+ out.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f),
8003
+ 0x80 | (c & 0x3f));
8004
+ }
8005
+ return new Uint8Array(out);
8006
+ }
8007
+
8008
+ /* SHA-256 over bytes -> Uint8Array(32). FIPS 180-4. */
8009
+ function _sha256Bytes(bytes) {
8010
+ const H = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
8011
+ 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
8012
+ const len = bytes.length;
8013
+ const padded = new Uint8Array((Math.floor((len + 8) / 64) + 1) * 64);
8014
+ padded.set(bytes);
8015
+ padded[len] = 0x80;
8016
+ const n = padded.length;
8017
+ const hiBits = Math.floor(len / 536870912); /* (len * 8) >> 32 */
8018
+ const loBits = (len * 8) >>> 0;
8019
+ padded[n - 8] = (hiBits >>> 24) & 0xff;
8020
+ padded[n - 7] = (hiBits >>> 16) & 0xff;
8021
+ padded[n - 6] = (hiBits >>> 8) & 0xff;
8022
+ padded[n - 5] = hiBits & 0xff;
8023
+ padded[n - 4] = (loBits >>> 24) & 0xff;
8024
+ padded[n - 3] = (loBits >>> 16) & 0xff;
8025
+ padded[n - 2] = (loBits >>> 8) & 0xff;
8026
+ padded[n - 1] = loBits & 0xff;
8027
+ const w = new Array(64);
8028
+ for (let off = 0; off < n; off += 64) {
8029
+ for (let i = 0; i < 16; i++) {
8030
+ const j = off + i * 4;
8031
+ w[i] = ((padded[j] << 24) | (padded[j + 1] << 16)
8032
+ | (padded[j + 2] << 8) | padded[j + 3]) >>> 0;
8033
+ }
8034
+ for (let i = 16; i < 64; i++) {
8035
+ const x = w[i - 15], y = w[i - 2];
8036
+ const s0 = (_rotr32(x, 7) ^ _rotr32(x, 18) ^ (x >>> 3)) >>> 0;
8037
+ const s1 = (_rotr32(y, 17) ^ _rotr32(y, 19) ^ (y >>> 10)) >>> 0;
8038
+ w[i] = (((w[i - 16] + s0) >>> 0) + ((w[i - 7] + s1) >>> 0)) >>> 0;
8039
+ }
8040
+ let a = H[0], b = H[1], c = H[2], d = H[3];
8041
+ let e = H[4], f = H[5], g = H[6], h = H[7];
8042
+ for (let i = 0; i < 64; i++) {
8043
+ const S1 = (_rotr32(e, 6) ^ _rotr32(e, 11) ^ _rotr32(e, 25)) >>> 0;
8044
+ const ch = ((e & f) ^ (~e & g)) >>> 0;
8045
+ const t1 = (((h + S1) >>> 0) + ((ch + _SHA256_K[i]) >>> 0)
8046
+ + w[i]) >>> 0;
8047
+ const S0 = (_rotr32(a, 2) ^ _rotr32(a, 13) ^ _rotr32(a, 22)) >>> 0;
8048
+ const maj = ((a & b) ^ (a & c) ^ (b & c)) >>> 0;
8049
+ const t2 = (S0 + maj) >>> 0;
8050
+ h = g; g = f; f = e; e = (d + t1) >>> 0;
8051
+ d = c; c = b; b = a; a = (t1 + t2) >>> 0;
8052
+ }
8053
+ H[0] = (H[0] + a) >>> 0; H[1] = (H[1] + b) >>> 0;
8054
+ H[2] = (H[2] + c) >>> 0; H[3] = (H[3] + d) >>> 0;
8055
+ H[4] = (H[4] + e) >>> 0; H[5] = (H[5] + f) >>> 0;
8056
+ H[6] = (H[6] + g) >>> 0; H[7] = (H[7] + h) >>> 0;
8057
+ }
8058
+ const out = new Uint8Array(32);
8059
+ for (let i = 0; i < 8; i++) {
8060
+ out[i * 4] = (H[i] >>> 24) & 0xff;
8061
+ out[i * 4 + 1] = (H[i] >>> 16) & 0xff;
8062
+ out[i * 4 + 2] = (H[i] >>> 8) & 0xff;
8063
+ out[i * 4 + 3] = H[i] & 0xff;
8064
+ }
8065
+ return out;
8066
+ }
8067
+
8068
+ function _bytesToHex(arr) {
8069
+ let hex = '';
8070
+ for (let i = 0; i < arr.length; i++) {
8071
+ const b = arr[i].toString(16);
8072
+ hex += b.length === 1 ? '0' + b : b;
8073
+ }
8074
+ return hex;
8075
+ }
8076
+
8077
+ /* HMAC-SHA256, synchronous. RFC 2104 / tested against RFC 4231. */
8078
+ function _hmacSha256Hex(secret, message) {
8079
+ const BLOCK = 64;
8080
+ let key = _utf8Bytes(secret);
8081
+ if (key.length > BLOCK) key = _sha256Bytes(key);
8082
+ const k0 = new Uint8Array(BLOCK);
8083
+ k0.set(key);
8084
+ const msg = _utf8Bytes(message);
8085
+ const inner = new Uint8Array(BLOCK + msg.length);
8086
+ const outer = new Uint8Array(BLOCK + 32);
8087
+ for (let i = 0; i < BLOCK; i++) {
8088
+ inner[i] = k0[i] ^ 0x36;
8089
+ outer[i] = k0[i] ^ 0x5c;
8090
+ }
8091
+ inner.set(msg, BLOCK);
8092
+ outer.set(_sha256Bytes(inner), BLOCK);
8093
+ return _bytesToHex(_sha256Bytes(outer));
8094
+ }
8095
+
8096
+ /* Stable serialisation: keys sorted at every depth, undefined
8097
+ dropped, so two hosts that build the same manifest in a different
8098
+ key order sign the same bytes. */
8099
+ function _stableStringify(v) {
8100
+ if (v === undefined) return 'null';
8101
+ if (v === null || typeof v !== 'object') return JSON.stringify(v);
8102
+ if (Array.isArray(v)) {
8103
+ const items = [];
8104
+ for (let i = 0; i < v.length; i++) items.push(_stableStringify(v[i]));
8105
+ return '[' + items.join(',') + ']';
8106
+ }
8107
+ const keys = Object.keys(v).filter(function (k) {
8108
+ return v[k] !== undefined && typeof v[k] !== 'function';
8109
+ }).sort();
8110
+ const parts = keys.map(function (k) {
8111
+ return JSON.stringify(k) + ':' + _stableStringify(v[k]);
8112
+ });
8113
+ return '{' + parts.join(',') + '}';
8114
+ }
8115
+
8116
+ /* The signed body: the whole manifest, with provenance.signature
8117
+ removed and everything else of the provenance block KEPT -- the
8118
+ signature covers signed_at and signed_by, so a replay cannot
8119
+ relabel who signed it or when. */
8120
+ function _manifestCanonicalString(m) {
8121
+ const clone = {};
8122
+ Object.keys(m).forEach(function (k) {
8123
+ if (k === 'provenance') return;
8124
+ clone[k] = m[k];
8125
+ });
8126
+ if (m.provenance && typeof m.provenance === 'object') {
8127
+ const p = {};
8128
+ Object.keys(m.provenance).forEach(function (k) {
8129
+ if (k === 'signature') return;
8130
+ p[k] = m.provenance[k];
8131
+ });
8132
+ clone.provenance = p;
8133
+ }
8134
+ return _stableStringify(clone);
8135
+ }
8136
+
8137
+ /* Tenant secrets for MANIFEST verification. Separate store from the
8138
+ extensions module's event-provenance secrets, and deliberately so:
8139
+ register() lives in this file and cannot reach into that closure.
8140
+ NAC.set_provenance_secret (extensions) FORWARDS here, so the
8141
+ example published in section 7.2 works exactly as written. */
8142
+ let _manifestSecrets = [];
8143
+
8144
+ function set_manifest_secret(s) {
8145
+ if (typeof s === 'string') _manifestSecrets = [s];
8146
+ else if (Array.isArray(s)) _manifestSecrets = s.slice();
8147
+ else if (s == null) _manifestSecrets = [];
8148
+ else {
8149
+ throw NacError('invalid',
8150
+ 'NAC.set_manifest_secret expects a string, an array of strings, or null');
8151
+ }
8152
+ return _manifestSecrets.length;
8153
+ }
8154
+
8155
+ /* NAC.sign_manifest(manifest, secret?) -> hex signature.
8156
+ Sign the object you are about to hand to register(): the digest
8157
+ covers it as you built it, BEFORE register() fills in its
8158
+ defaults (version, nac_version, plugin_slug from the two-argument
8159
+ form), which is why register() takes its snapshot first. */
8160
+ function sign_manifest(manifest, secret) {
8161
+ if (!manifest || typeof manifest !== 'object') {
8162
+ throw NacError('invalid', 'NAC.sign_manifest: manifest object required');
8163
+ }
8164
+ const key = (secret != null) ? secret : _manifestSecrets[0];
8165
+ if (typeof key !== 'string' || !key) {
8166
+ throw NacError('invalid',
8167
+ 'NAC.sign_manifest: no secret. Pass one, or call NAC.set_manifest_secret first');
8168
+ }
8169
+ return _hmacSha256Hex(key, _manifestCanonicalString(manifest));
8170
+ }
8171
+
8172
+ /* NAC.verify_manifest(manifest, secret?) -> boolean.
8173
+ Constant-time compare against every registered secret, so a
8174
+ tenant rotating a secret can hold both for the window. */
8175
+ function verify_manifest(manifest, secret) {
8176
+ if (!manifest || typeof manifest !== 'object') return false;
8177
+ const prov = manifest.provenance;
8178
+ if (!prov || typeof prov !== 'object' || !prov.signature) return false;
8179
+ const keys = (secret != null) ? [secret] : _manifestSecrets;
8180
+ if (!keys.length) return false;
8181
+ const body = _manifestCanonicalString(manifest);
8182
+ const provided = String(prov.signature);
8183
+ let any = false;
8184
+ for (let i = 0; i < keys.length; i++) {
8185
+ if (typeof keys[i] !== 'string' || !keys[i]) continue;
8186
+ const expected = _hmacSha256Hex(keys[i], body);
8187
+ if (provided.length !== expected.length) continue;
8188
+ let diff = 0;
8189
+ for (let j = 0; j < provided.length; j++) {
8190
+ diff |= provided.charCodeAt(j) ^ expected.charCodeAt(j);
8191
+ }
8192
+ if (diff === 0) any = true;
8193
+ }
8194
+ return any;
8195
+ }
8196
+
8197
+ /* What register() recorded about each manifest's provenance, so a
8198
+ validator on the page can ask instead of guessing. Shape:
8199
+ { signed, verified, reason, signed_by, signed_at }
8200
+ verified is true / false / null, and null is not a synonym for
8201
+ false: it means NOBODY COULD TELL (no secret registered). A tool
8202
+ that reports level 3 off this MUST treat null as unverified. */
8203
+ const _manifestProvenance = Object.create(null);
8204
+
8205
+ function manifest_provenance(slug) {
8206
+ if (slug === undefined) {
8207
+ const out = {};
8208
+ Object.keys(_manifestProvenance).forEach(function (k) {
8209
+ out[k] = Object.assign({}, _manifestProvenance[k]);
8210
+ });
8211
+ return out;
8212
+ }
8213
+ const rec = _manifestProvenance[String(slug)];
8214
+ return rec ? Object.assign({}, rec) : null;
8215
+ }
8216
+
8217
+ /* Called from register() with the canonical string captured BEFORE
8218
+ any default was applied. Throws when a signature is present and a
8219
+ secret says it is wrong; stays silent when there is no signature
8220
+ (section 7.2: a manifest MAY carry a provenance block) or no
8221
+ secret (nothing to check against, and an adopter who never set
8222
+ one must keep working exactly as before). */
8223
+ function _recordManifestProvenance(slug, manifest, canonical) {
8224
+ const prov = manifest && manifest.provenance;
8225
+ if (!prov || typeof prov !== 'object' || !prov.signature) {
8226
+ _manifestProvenance[slug] = {
8227
+ signed: false, verified: null, reason: 'no_provenance_block',
8228
+ signed_by: (prov && prov.signed_by) || null,
8229
+ signed_at: (prov && prov.signed_at) || null,
8230
+ };
8231
+ return;
8232
+ }
8233
+ if (!_manifestSecrets.length) {
8234
+ _manifestProvenance[slug] = {
8235
+ signed: true, verified: null, reason: 'no_secret_registered',
8236
+ signed_by: prov.signed_by || null,
8237
+ signed_at: prov.signed_at || null,
8238
+ };
8239
+ return;
8240
+ }
8241
+ const provided = String(prov.signature);
8242
+ let ok = false;
8243
+ for (let i = 0; i < _manifestSecrets.length; i++) {
8244
+ const key = _manifestSecrets[i];
8245
+ if (typeof key !== 'string' || !key) continue;
8246
+ const expected = _hmacSha256Hex(key, canonical);
8247
+ if (provided.length !== expected.length) continue;
8248
+ let diff = 0;
8249
+ for (let j = 0; j < provided.length; j++) {
8250
+ diff |= provided.charCodeAt(j) ^ expected.charCodeAt(j);
8251
+ }
8252
+ if (diff === 0) ok = true;
8253
+ }
8254
+ if (!ok) {
8255
+ delete _manifestProvenance[slug];
8256
+ throw NacError('invalid',
8257
+ 'manifest "' + slug + '" carries a provenance.signature that does not '
8258
+ + 'match the HMAC of its body under any registered tenant secret '
8259
+ + '(SPEC.md sec 7.2). Either the manifest was altered after signing, '
8260
+ + 'or it was signed for another tenant.');
8261
+ }
8262
+ _manifestProvenance[slug] = {
8263
+ signed: true, verified: true, reason: 'verified',
8264
+ signed_by: prov.signed_by || null,
8265
+ signed_at: prov.signed_at || null,
8266
+ };
8267
+ }
8268
+
8269
+ /* ---------- 2.7.0: NAC.set_source (sec 15.7) ------------------
8270
+
8271
+ Section 15.7 has published, since 2.5, that source on
8272
+ nac:plugin:invoked / :read / :event "defaults to 'agent'; hosts
8273
+ that wrap the runtime in a user-facing UI MAY override via the
8274
+ existing NAC.set_source(...) mechanism (sec 7)". The mechanism
8275
+ was not existing: there were zero occurrences of set_source in
8276
+ js/, so every dispatch from a host where a HUMAN pressed the
8277
+ button was sealed source:'agent', trusted:false, and an auditor
8278
+ reading the log could not tell the two apart (D-09).
8279
+
8280
+ It is an ATTESTATION BY THE HOST, not a measurement, and the
8281
+ threat model (7.3) already says an agent with user-level access
8282
+ can do anything the user can -- including calling this. What it
8283
+ buys is the honest case: a host with a confirmation UI in front
8284
+ of the dispatch can say so, and every change of the claim emits
8285
+ nac:source_changed so the override is itself in the log. */
8286
+
8287
+ let _dispatchSource = { source: 'agent', trusted: false };
8288
+
8289
+ function set_source(src) {
8290
+ let next;
8291
+ if (src == null) {
8292
+ next = { source: 'agent', trusted: false };
8293
+ } else if (typeof src === 'string') {
8294
+ if (!src.trim()) {
8295
+ throw NacError('invalid', 'NAC.set_source: source string must not be empty');
8296
+ }
8297
+ next = { source: src, trusted: false };
8298
+ } else if (typeof src === 'object') {
8299
+ const label = src.source !== undefined ? src.source : src.type;
8300
+ if (typeof label !== 'string' || !label.trim()) {
8301
+ throw NacError('invalid',
8302
+ 'NAC.set_source: {source} must be a non-empty string');
8303
+ }
8304
+ next = { source: label, trusted: !!src.trusted };
8305
+ } else {
8306
+ throw NacError('invalid',
8307
+ 'NAC.set_source expects a string, {source, trusted}, or null to reset');
8308
+ }
8309
+ const prev = _dispatchSource;
8310
+ _dispatchSource = next;
8311
+ try {
8312
+ document.dispatchEvent(new CustomEvent('nac:source_changed', {
8313
+ detail: {
8314
+ source: next.source, trusted: next.trusted,
8315
+ previous_source: prev.source, previous_trusted: prev.trusted,
8316
+ },
8317
+ bubbles: true, composed: true,
8318
+ }));
8319
+ } catch (_) { /* no document: the setter still took effect */ }
8320
+ return Object.assign({}, next);
8321
+ }
8322
+
8323
+ function get_source() { return Object.assign({}, _dispatchSource); }
8324
+
6874
8325
  /* ---------- v1.9.0: recommended_remediation (sec 6.2.30) ----- */
6875
8326
 
6876
8327
  const _REMEDIATION_BY_REASON = {
@@ -6950,6 +8401,34 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6950
8401
  'emitter-listen': true,
6951
8402
  };
6952
8403
 
8404
+ /* 2.7.0 (SPEC sec 19.1) -- which of those nine backends reach their
8405
+ surface WITHOUT a document. This is the whole predicate of the
8406
+ headless profile, and it is a property of the implementation, not
8407
+ an opinion: sdk-call walks a registered API handle or the global
8408
+ object, and emitter-listen subscribes to a library's own emitter.
8409
+ Neither ever calls document.querySelector. The other six do, which
8410
+ is why they are absent from this table.
8411
+
8412
+ 'inherits' means the binding is DOM-free exactly when every state
8413
+ path it observes is: synthetic-poll only calls read() on the state
8414
+ paths it declares. */
8415
+ const _V25_DOM_FREE_BACKENDS = {
8416
+ 'sdk-call': true,
8417
+ 'emitter-listen': true,
8418
+ 'synthetic-poll': 'inherits',
8419
+ };
8420
+
8421
+ /* Why each DOM-requiring backend needs one -- named, so the refusal a
8422
+ declared-headless manifest gets says what to change (sec 19.1). */
8423
+ const _V25_DOM_REASON = {
8424
+ 'postmessage': 'posts to the contentWindow of an iframe matched by a CSS selector',
8425
+ 'postmessage-listen': 'filters window.message by the iframe a CSS selector matches',
8426
+ 'script-bridge': 'posts to the contentWindow of an iframe matched by a CSS selector',
8427
+ 'dom-mirror': 'reads a DOM element matched by a CSS selector',
8428
+ 'same-origin-window': 'reads into the contentWindow of an iframe matched by a CSS selector',
8429
+ 'synthetic-mutation': 'observes DOM mutations with a MutationObserver',
8430
+ };
8431
+
6953
8432
  /* The closed list of NacError codes the plugin contract raises
6954
8433
  (SPEC.md sec 15.9), plus the namespace a plugin uses for a code
6955
8434
  of its own (v2.6, RFC V26-01 hook E-6). Before this, `call` lifted
@@ -6968,6 +8447,16 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6968
8447
  'state_unreadable': true,
6969
8448
  'timeout': true,
6970
8449
  'invalid': true,
8450
+ /* 2.7.0 (sec 19.3 / 19.4). no_document: a DOM primitive was called
8451
+ where there is no document, so there is nothing to resolve --
8452
+ raised instead of the raw ReferenceError the reference runtime
8453
+ used to let through. provenance_unobservable: a plugin that
8454
+ declares headless: true was called with no document AND no event
8455
+ sink, so its nac:plugin:* row would be dropped; refused before
8456
+ the effect, because a surface nobody can audit is the silent
8457
+ damage this protocol exists to remove. */
8458
+ 'no_document': true,
8459
+ 'provenance_unobservable': true,
6971
8460
  };
6972
8461
  const _V25_PLUGIN_CODE_PREFIX = 'plugin.';
6973
8462
 
@@ -7176,6 +8665,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7176
8665
  }
7177
8666
 
7178
8667
  function _v25_backend_dom_mirror(binding /*, args*/) {
8668
+ const miss = _v25_noDocument('dom-mirror');
8669
+ if (miss) return Promise.reject(miss);
7179
8670
  const sel = binding.selector;
7180
8671
  if (!sel) return Promise.reject(new Error('dom-mirror requires `selector` string'));
7181
8672
  const el = document.querySelector(sel);
@@ -7200,6 +8691,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7200
8691
  /* postmessage (verb): post a structured message to the iframe.contentWindow
7201
8692
  of the target. `values` literal + `values_from_args` forward keys. */
7202
8693
  function _v25_backend_postmessage(binding, args) {
8694
+ const miss = _v25_noDocument('postmessage');
8695
+ if (miss) return Promise.reject(miss);
7203
8696
  const sel = binding.target;
7204
8697
  if (!sel) return Promise.reject(new Error('postmessage requires `target` selector'));
7205
8698
  const iframe = document.querySelector(sel);
@@ -7236,6 +8729,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7236
8729
  flag the test sets explicitly; in real browsers the property access
7237
8730
  throws a DOMException SecurityError which we map the same way. */
7238
8731
  function _v25_backend_same_origin_window(binding /*, args*/) {
8732
+ const miss = _v25_noDocument('same-origin-window');
8733
+ if (miss) return Promise.reject(miss);
7239
8734
  const sel = binding.target;
7240
8735
  if (!sel) return Promise.reject(new Error('same-origin-window requires `target`'));
7241
8736
  const iframe = document.querySelector(sel);
@@ -7280,6 +8775,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7280
8775
  CallPythonScript pattern; generalises to any app that exposes a
7281
8776
  RPC channel over postMessage. */
7282
8777
  function _v25_backend_script_bridge(binding, args) {
8778
+ const miss = _v25_noDocument('script-bridge');
8779
+ if (miss) return Promise.reject(miss);
7283
8780
  const sel = binding.target;
7284
8781
  if (!sel) return Promise.reject(new Error('script-bridge requires `target`'));
7285
8782
  const iframe = document.querySelector(sel);
@@ -7397,6 +8894,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7397
8894
  fall back to synthetic-poll for those cases (declared, not
7398
8895
  implicit). */
7399
8896
  function _v25_subscribe_synthetic_mutation(plugin, event_path, binding, cb) {
8897
+ const miss = _v25_noDocument('synthetic-mutation');
8898
+ if (miss) throw miss;
7400
8899
  if (typeof MutationObserver === 'undefined') {
7401
8900
  throw new Error('synthetic-mutation requires MutationObserver in scope');
7402
8901
  }
@@ -7655,6 +9154,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7655
9154
  on the host window, filter by source iframe + MessageId, run the
7656
9155
  extractor, fire the user callback. Returns a teardown closure. */
7657
9156
  function _v25_subscribe_postmessage_listen(plugin, event_path, binding, cb) {
9157
+ const miss = _v25_noDocument('postmessage-listen');
9158
+ if (miss) throw miss;
7658
9159
  const sel = binding.source;
7659
9160
  const wantMsgId = binding.message;
7660
9161
  if (!wantMsgId) throw new Error('postmessage-listen requires `message`');
@@ -7800,6 +9301,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7800
9301
  const events = manifest.events || {};
7801
9302
  _v25_validateText(manifest.label, 'manifest "' + slug + '"', 'label');
7802
9303
  _v25_validateText(manifest.hint, 'manifest "' + slug + '"', 'hint');
9304
+ /* 2.7.0 (sec 19.1) -- headless is a boolean or it is absent. A
9305
+ string "true" is a typo that would silently leave the plugin
9306
+ outside the profile, so it is refused rather than coerced. */
9307
+ if (manifest.headless !== undefined && typeof manifest.headless !== 'boolean') {
9308
+ const e = new Error('manifest "' + slug + '": headless must be a boolean when declared');
9309
+ e.code = 'invalid'; throw e;
9310
+ }
7803
9311
  /* Verbs: single binding each, backend in vocabulary. */
7804
9312
  for (const vp in verbs) {
7805
9313
  const b = verbs[vp];
@@ -7859,6 +9367,28 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7859
9367
  e.code = 'invalid'; throw e;
7860
9368
  }
7861
9369
  }
9370
+ /* 2.7.0 (sec 19.1) -- a manifest that DECLARES the headless
9371
+ profile has to be in it. Checked here, at register time, so the
9372
+ adopter learns on the bench instead of discovering it on a
9373
+ device with no screen: every binding must reach its surface
9374
+ without a document, and the refusal names the ones that do not. */
9375
+ if (manifest.headless === true) {
9376
+ const need = _v25_domRequired({
9377
+ verbs: verbs, state: states, events: events,
9378
+ });
9379
+ if (need.length) {
9380
+ const first = need[0];
9381
+ const e = new Error('manifest "' + slug + '" declares headless: true but ' +
9382
+ need.length + ' binding' + (need.length === 1 ? '' : 's') + ' need' +
9383
+ (need.length === 1 ? 's' : '') + ' a document. First: ' + first.kind + ' "' +
9384
+ first.path + '" -- ' + first.why + '. Declare a DOM-free backend (sdk-call, ' +
9385
+ 'emitter-listen, or synthetic-poll over DOM-free state) or drop the ' +
9386
+ 'declaration (SPEC sec 19.1).');
9387
+ e.code = 'invalid';
9388
+ e.dom_required = need;
9389
+ throw e;
9390
+ }
9391
+ }
7862
9392
  }
7863
9393
 
7864
9394
  function registerPlugin(slug, manifest) {
@@ -7868,6 +9398,10 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7868
9398
  slug: slug,
7869
9399
  label: manifest.label != null ? manifest.label : null,
7870
9400
  hint: manifest.hint != null ? manifest.hint : null,
9401
+ /* 2.7.0 (sec 19.1) -- the headless profile is DECLARED, never
9402
+ inferred. Absent means false, which is every manifest ever
9403
+ written before today. */
9404
+ headless: manifest.headless === true,
7871
9405
  verbs: manifest.verbs || {},
7872
9406
  state: manifest.state || {},
7873
9407
  events: manifest.events || {},
@@ -7902,6 +9436,10 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7902
9436
  slug: entry.slug,
7903
9437
  label: entry.label != null ? entry.label : null,
7904
9438
  hint: entry.hint != null ? entry.hint : null,
9439
+ /* 2.7.0 (sec 19.1): an agent that discovers a plugin learns
9440
+ from the descriptor whether it needs a page -- the same
9441
+ question NAC.profile answers in full. */
9442
+ headless: !!entry.headless,
7905
9443
  verbs: [],
7906
9444
  state: [],
7907
9445
  events: [],
@@ -7981,6 +9519,192 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7981
9519
  return _v25_describeEntry(_v25_plugins[slug]);
7982
9520
  }
7983
9521
 
9522
+ /* ================================================================
9523
+ 19. Headless profile -- the manifest as the surface (v2.7)
9524
+ ================================================================
9525
+
9526
+ Owner decision D-26 (2026-11-25). Sections 1-14 address nodes and
9527
+ section 15 addresses a surface a node cannot reach. Neither says
9528
+ what happens when there is no document AT ALL -- a screenless
9529
+ assistant, an IVR, a voice device, a worker. The answer is that the
9530
+ extension contract already IS a capability interface: a plugin
9531
+ whose every binding is DOM-free is operable with no document, and
9532
+ plugins() + describePlugin() are the resolution surface, because
9533
+ they read the manifest and never the page.
9534
+
9535
+ What was missing was not routing. It was three things:
9536
+
9537
+ 1. Nothing DECLARED it, so neither an agent nor the adopter could
9538
+ tell a manifest that needs a page from one that does not.
9539
+ profile() answers it from the manifest, mechanically.
9540
+ 2. Provenance was silently LOST. Until 2.7.0 the emit helper
9541
+ below did document.dispatchEvent inside a try/catch, so with
9542
+ no document every nac:plugin:* row vanished and the call
9543
+ still reported success -- the exact silent damage section 7
9544
+ exists to prevent. setEventSink gives the same events the
9545
+ same shapes over a bus that is not the DOM.
9546
+ 3. A DOM primitive crashed with a ReferenceError instead of
9547
+ refusing by name. _nac_requireDocument (sec 19.3) fixed that.
9548
+
9549
+ Nothing here is a new primitive and nothing here is implicit: a
9550
+ manifest written against 2.5 or 2.6 keeps working untouched, and
9551
+ the only way into the profile is to declare headless: true. */
9552
+
9553
+ /* The non-DOM provenance bus. Additive: when a document exists the
9554
+ events still go to it, so installing a sink in a browser gives an
9555
+ audit log without changing a single consumer. */
9556
+ let _v25_event_sink = null;
9557
+ const _v25_prov_stats = { to_document: 0, to_sink: 0, dropped: 0, sink_errors: 0 };
9558
+
9559
+ function setEventSink(fn) {
9560
+ if (fn !== null && fn !== undefined && typeof fn !== 'function') {
9561
+ throw _v25_buildNacError('invalid',
9562
+ 'NAC.setEventSink: expects a function or null');
9563
+ }
9564
+ _v25_event_sink = (typeof fn === 'function') ? fn : null;
9565
+ return _v25_event_sink;
9566
+ }
9567
+
9568
+ function eventSink() { return _v25_event_sink; }
9569
+
9570
+ /* Is a provenance row observable by anybody at all right now? Two
9571
+ buses, and the answer is the OR of them. */
9572
+ function _v25_provObservable() {
9573
+ const hasDoc = (typeof document !== 'undefined' && !!document && !!document.dispatchEvent);
9574
+ return hasDoc || !!_v25_event_sink;
9575
+ }
9576
+
9577
+ function provenanceStatus() {
9578
+ return {
9579
+ document: (typeof document !== 'undefined' && !!document && !!document.dispatchEvent),
9580
+ sink: !!_v25_event_sink,
9581
+ observable: _v25_provObservable(),
9582
+ to_document: _v25_prov_stats.to_document,
9583
+ to_sink: _v25_prov_stats.to_sink,
9584
+ /* A row nobody received. Counted instead of swallowed: outside
9585
+ the headless profile the runtime does not refuse the call, so
9586
+ the loss has to be READABLE or it is still silent. */
9587
+ dropped: _v25_prov_stats.dropped,
9588
+ /* A sink that threw. The row is gone and the call is not undone;
9589
+ what the runtime owes the caller is the count, not a retry. */
9590
+ sink_errors: _v25_prov_stats.sink_errors,
9591
+ };
9592
+ }
9593
+
9594
+ function _v25_noDocument(backend) {
9595
+ if (typeof document !== 'undefined' && document) return null;
9596
+ return _v25_buildNacError('no_document',
9597
+ 'backend "' + backend + '" needs a document: it ' +
9598
+ (_V25_DOM_REASON[backend] || 'reads the DOM') +
9599
+ '. With no document there is nothing to reach -- declare a DOM-free ' +
9600
+ 'backend (sdk-call, emitter-listen) or run this plugin where a document exists ' +
9601
+ '(SPEC sec 19.1).',
9602
+ { backend: backend });
9603
+ }
9604
+
9605
+ /* Classify ONE binding. Returns null when it is DOM-free, or the row
9606
+ that goes into profile().dom_required when it is not. */
9607
+ function _v25_bindingDomNeed(kind, path, binding, entry, seen) {
9608
+ const backend = (binding && binding.backend) || null;
9609
+ const free = backend ? _V25_DOM_FREE_BACKENDS[backend] : undefined;
9610
+ if (free === true) return null;
9611
+ if (free === 'inherits') {
9612
+ /* synthetic-poll is DOM-free exactly when every state path it
9613
+ observes is. Recursion is depth-guarded: a manifest may name
9614
+ the same state from two events. */
9615
+ const observe = Array.isArray(binding.observe) ? binding.observe : [];
9616
+ for (let i = 0; i < observe.length; i++) {
9617
+ const sp = observe[i];
9618
+ const key = 'state:' + sp;
9619
+ if (seen[key]) continue;
9620
+ seen[key] = true;
9621
+ const chain = (entry.state && entry.state[sp]) || null;
9622
+ if (!chain || !chain.length) {
9623
+ return { kind: kind, path: path, backend: backend, observes: sp,
9624
+ why: 'observes the state path "' + sp + '", which this manifest does not declare' };
9625
+ }
9626
+ for (let j = 0; j < chain.length; j++) {
9627
+ const need = _v25_bindingDomNeed('state', sp, chain[j], entry, seen);
9628
+ if (need) {
9629
+ return { kind: kind, path: path, backend: backend, observes: sp,
9630
+ why: 'observes the state path "' + sp + '", which needs a document: ' + need.why };
9631
+ }
9632
+ }
9633
+ }
9634
+ return null;
9635
+ }
9636
+ return {
9637
+ kind: kind, path: path, backend: backend,
9638
+ why: backend
9639
+ ? 'the ' + backend + ' backend ' + (_V25_DOM_REASON[backend] || 'reads the DOM')
9640
+ : 'the binding declares no backend',
9641
+ };
9642
+ }
9643
+
9644
+ /* Every binding of a plugin that would need a document. The state
9645
+ chain is checked WHOLE and not just its first link: a chain whose
9646
+ fallback is a dom-mirror works in a browser and degrades to
9647
+ nothing without one, which is a declaration error in a profile
9648
+ whose entire claim is that no page is needed. */
9649
+ function _v25_domRequired(entry) {
9650
+ const out = [];
9651
+ const seen = {};
9652
+ const verbPaths = Object.keys(entry.verbs || {}).sort();
9653
+ for (let i = 0; i < verbPaths.length; i++) {
9654
+ const need = _v25_bindingDomNeed('verb', verbPaths[i], entry.verbs[verbPaths[i]], entry, seen);
9655
+ if (need) out.push(need);
9656
+ }
9657
+ const statePaths = Object.keys(entry.state || {}).sort();
9658
+ for (let i = 0; i < statePaths.length; i++) {
9659
+ const chain = entry.state[statePaths[i]] || [];
9660
+ for (let j = 0; j < chain.length; j++) {
9661
+ const need = _v25_bindingDomNeed('state', statePaths[i], chain[j], entry, seen);
9662
+ if (need) { need.binding_index = j; out.push(need); }
9663
+ }
9664
+ }
9665
+ const eventPaths = Object.keys(entry.events || {}).sort();
9666
+ for (let i = 0; i < eventPaths.length; i++) {
9667
+ const need = _v25_bindingDomNeed('event', eventPaths[i], entry.events[eventPaths[i]], entry, seen);
9668
+ if (need) out.push(need);
9669
+ }
9670
+ return out;
9671
+ }
9672
+
9673
+ /* The public predicate. Answers for ANY registered plugin, declared
9674
+ or not: an agent can discover that a manifest written without the
9675
+ profile in mind happens to be operable with no page. */
9676
+ function profile(slug) {
9677
+ if (typeof slug !== 'string' || !slug) {
9678
+ throw _v25_buildNacError('invalid', 'NAC.profile: slug must be a non-empty string');
9679
+ }
9680
+ const entry = _v25_plugins[slug];
9681
+ if (!entry) {
9682
+ throw _v25_buildNacError('plugin_not_registered',
9683
+ 'NAC.profile: plugin "' + slug + '" not registered');
9684
+ }
9685
+ const dom_required = _v25_domRequired(entry);
9686
+ return {
9687
+ slug: slug,
9688
+ declared_headless: !!entry.headless,
9689
+ headless: dom_required.length === 0,
9690
+ dom_required: _v25_copy(dom_required) || [],
9691
+ };
9692
+ }
9693
+
9694
+ /* The gate the profile buys: inside it, an unobservable call is
9695
+ refused BEFORE the effect. Outside it nothing changes -- which is
9696
+ why the profile is opt-in and not inferred. */
9697
+ function _v25_provGate(op, plugin, entry) {
9698
+ if (!entry || !entry.headless) return null;
9699
+ if (_v25_provObservable()) return null;
9700
+ return _v25_buildNacError('provenance_unobservable',
9701
+ 'NAC.' + op + ': plugin "' + plugin + '" declares headless: true and there is ' +
9702
+ 'neither a document nor an event sink, so its nac:plugin:* row would be dropped. ' +
9703
+ 'Install one with NAC.setEventSink(fn) before driving a headless surface ' +
9704
+ '(SPEC sec 19.4).',
9705
+ { plugin: plugin });
9706
+ }
9707
+
7984
9708
  /* Provenance emit helper -- the kind is one of 'invoked', 'read',
7985
9709
  'event'. Detail shape per SPEC.md sec 15.7. */
7986
9710
  function _v25_emitProvenance(kind, plugin, path, backend, request_id, ok, error, duration_ms, extra) {
@@ -7988,8 +9712,11 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7988
9712
  plugin: plugin,
7989
9713
  backend: backend || null,
7990
9714
  request_id: request_id,
7991
- source: 'agent',
7992
- trusted: false,
9715
+ /* 2.7.0 (TF-A19): sec 15.7 publishes 'agent' as the DEFAULT and
9716
+ an override through NAC.set_source. _dispatchSource holds
9717
+ exactly that default until a host says otherwise. */
9718
+ source: _dispatchSource.source,
9719
+ trusted: _dispatchSource.trusted,
7993
9720
  duration_ms: duration_ms,
7994
9721
  ok: !!ok,
7995
9722
  error: error || null,
@@ -8000,9 +9727,29 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8000
9727
  if (extra) {
8001
9728
  for (const k in extra) detail[k] = extra[k];
8002
9729
  }
9730
+ /* 2.7.0 (sec 19.4): TWO buses, and a row that reached neither is
9731
+ COUNTED. Before this the dispatch was a lone try/catch, so with
9732
+ no document the row disappeared and nothing anywhere said so. */
9733
+ const type = 'nac:plugin:' + kind;
9734
+ let delivered = false;
8003
9735
  try {
8004
- document.dispatchEvent(new CustomEvent('nac:plugin:' + kind, { detail: detail, bubbles: true }));
8005
- } catch (_) { /* if document lacks dispatch, swallow */ }
9736
+ document.dispatchEvent(new CustomEvent(type, { detail: detail, bubbles: true }));
9737
+ delivered = true;
9738
+ _v25_prov_stats.to_document++;
9739
+ } catch (_) { /* no document, or a document without dispatchEvent */ }
9740
+ if (_v25_event_sink) {
9741
+ try {
9742
+ _v25_event_sink({ type: type, detail: detail });
9743
+ delivered = true;
9744
+ _v25_prov_stats.to_sink++;
9745
+ } catch (_) {
9746
+ /* A sink that throws is a host defect. The effect already
9747
+ happened, so the runtime does not undo it and does not
9748
+ retry -- it counts the loss where a caller can read it. */
9749
+ _v25_prov_stats.sink_errors++;
9750
+ }
9751
+ }
9752
+ if (!delivered) _v25_prov_stats.dropped++;
8006
9753
  }
8007
9754
 
8008
9755
  function _v25_buildNacError(code, message, extra) {
@@ -8024,6 +9771,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8024
9771
  _v25_emitProvenance('invoked', plugin, verb_path, null, request_id, false, err.message, Date.now() - t0);
8025
9772
  return Promise.reject(err);
8026
9773
  }
9774
+ const gated = _v25_provGate('call', plugin, _v25_plugins[plugin]);
9775
+ if (gated) return Promise.reject(gated);
8027
9776
  const binding = _v25_plugins[plugin].verbs[verb_path];
8028
9777
  if (!binding) {
8029
9778
  const err = _v25_buildNacError('verb_not_declared',
@@ -8076,6 +9825,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8076
9825
  _v25_emitProvenance('read', plugin, state_path, null, request_id, false, err.message, Date.now() - t0);
8077
9826
  return Promise.reject(err);
8078
9827
  }
9828
+ const gated = _v25_provGate('read', plugin, _v25_plugins[plugin]);
9829
+ if (gated) return Promise.reject(gated);
8079
9830
  const chain = _v25_plugins[plugin].state[state_path];
8080
9831
  if (!chain) {
8081
9832
  const err = _v25_buildNacError('state_not_declared',
@@ -8145,6 +9896,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8145
9896
  throw _v25_buildNacError('plugin_not_registered',
8146
9897
  'NAC.subscribe: plugin "' + plugin + '" not registered');
8147
9898
  }
9899
+ const gated = _v25_provGate('subscribe', plugin, _v25_plugins[plugin]);
9900
+ if (gated) throw gated;
8148
9901
  const binding = _v25_plugins[plugin].events[event_path];
8149
9902
  if (!binding) {
8150
9903
  throw _v25_buildNacError('event_not_declared',
@@ -8230,6 +9983,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8230
9983
  }
8231
9984
 
8232
9985
  function narrate(plugin, nac_id) {
9986
+ _nac_requireDocument('narrate');
8233
9987
  if (typeof nac_id !== 'string' || !nac_id) return null;
8234
9988
  /* Scope by plugin if provided -- look only inside [data-nac-plugin=plugin]
8235
9989
  subtree. If plugin is omitted, fall back to global search. */
@@ -8242,7 +9996,27 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8242
9996
  /* Use attribute selector with CSS-safe escape via JSON.stringify
8243
9997
  to avoid injection when nac_id contains weird chars. */
8244
9998
  const safeId = '"' + String(nac_id).replace(/["\\]/g, '\\$&') + '"';
8245
- const el = root.querySelector('[data-nac-id=' + safeId + ']');
9999
+ /* The ROOT ITSELF counts (fixed 2.7.0, found by the first test
10000
+ this verb ever had).
10001
+
10002
+ querySelector searches DESCENDANTS, so when `plugin` was given
10003
+ and the asked-for id belonged to the plugin root -- the usual
10004
+ case, since a root normally carries both data-nac-plugin and
10005
+ data-nac-id -- narrate returned null. A plugin could not narrate
10006
+ itself.
10007
+
10008
+ It showed up through context(), whose breadcrumb walks up to and
10009
+ including the root and labels each entry with narrate(): the
10010
+ FIRST entry of every breadcrumb came back with label: null. An
10011
+ assistive consumer reading that breadcrumb aloud started with
10012
+ nothing. */
10013
+ let el = null;
10014
+ if (root !== document && root.getAttribute
10015
+ && root.getAttribute('data-nac-id') === String(nac_id)) {
10016
+ el = root;
10017
+ } else {
10018
+ el = root.querySelector('[data-nac-id=' + safeId + ']');
10019
+ }
8246
10020
  if (!el) return null;
8247
10021
  /* 1. aria-label */
8248
10022
  const aria = el.getAttribute('aria-label');
@@ -8281,6 +10055,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8281
10055
  }
8282
10056
 
8283
10057
  function context(plugin) {
10058
+ _nac_requireDocument('context');
8284
10059
  const out = { breadcrumb: [] };
8285
10060
  const root = _v25b_pluginRoot(plugin);
8286
10061
  if (!root) return out;
@@ -8339,6 +10114,28 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8339
10114
  Both delegate to NAC.read() so they inherit V25-01's full
8340
10115
  fallback-chain semantics for free. */
8341
10116
 
10117
+ /* A value rendered for a human, that cannot throw. JSON.stringify
10118
+ fails on a cycle and on a DOM node it returns '{}', neither of
10119
+ which helps a reader; a DOM node is named by what it is. */
10120
+ function _v25_renderValue(v) {
10121
+ if (v === undefined) return 'undefined';
10122
+ if (v === null) return 'null';
10123
+ if (typeof v === 'string') return JSON.stringify(v);
10124
+ if (typeof v === 'number' || typeof v === 'boolean') return String(v);
10125
+ if (v && v.nodeType === 1 && typeof v.getAttribute === 'function') {
10126
+ const id = v.getAttribute('data-nac-id');
10127
+ return '<' + String(v.tagName || 'element').toLowerCase()
10128
+ + (id ? ' data-nac-id="' + id + '"' : '') + '>'
10129
+ + ' -- a DOM element: the binding has no `extract`, so it resolved the node itself';
10130
+ }
10131
+ try {
10132
+ const out = JSON.stringify(v);
10133
+ return out === undefined ? String(v) : out;
10134
+ } catch (e) {
10135
+ return '[unserialisable ' + (typeof v) + ': ' + (e && e.message ? e.message : 'cycle') + ']';
10136
+ }
10137
+ }
10138
+
8342
10139
  function expect(plugin, statePath, value, opts) {
8343
10140
  opts = opts || {};
8344
10141
  const timeout = (typeof opts.timeout_ms === 'number') ? opts.timeout_ms : 5000;
@@ -8355,9 +10152,23 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8355
10152
  catch (_) { matches = false; }
8356
10153
  if (matches) { resolve(cur); return; }
8357
10154
  if (Date.now() >= deadline) {
10155
+ /* The last value is rendered DEFENSIVELY (fixed 2.7.0,
10156
+ found by the first test this verb ever had).
10157
+
10158
+ It used to be a bare JSON.stringify(cur), and `cur` is
10159
+ whatever the host's state binding returned -- a
10160
+ dom-mirror binding with no extractor returns the ELEMENT
10161
+ itself, and app state can hold a reference cycle. On
10162
+ either of those, expect() threw a TypeError out of its
10163
+ own timeout path instead of rejecting with the timeout
10164
+ it promises, so the caller got "Converting circular
10165
+ structure to JSON" from inside a verb that was supposed
10166
+ to tell them their state never matched.
10167
+ An error path that can itself throw is worse than a
10168
+ vague message. */
8358
10169
  reject(_v25_buildNacError('timeout',
8359
10170
  'NAC.expect: state "' + statePath + '" did not match within ' +
8360
- timeout + 'ms (last value: ' + JSON.stringify(cur) + ')'));
10171
+ timeout + 'ms (last value: ' + _v25_renderValue(cur) + ')'));
8361
10172
  return;
8362
10173
  }
8363
10174
  setTimeout(tick, pollMs);
@@ -8400,6 +10211,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8400
10211
  }
8401
10212
 
8402
10213
  function tree(plugin, rootId) {
10214
+ _nac_requireDocument('tree');
8403
10215
  const pluginRoot = _v25b_pluginRoot(plugin);
8404
10216
  if (!pluginRoot) return [];
8405
10217
  let start = pluginRoot;
@@ -8431,8 +10243,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8431
10243
 
8432
10244
  global.NAC = {
8433
10245
  __nac_v1_installed: true,
8434
- version: '2.6.0',
8435
- spec_version: '2.6',
10246
+ version: '2.9.0',
10247
+ spec_version: '2.9',
8436
10248
  /* v2.2.0 (V22-01) -- strict validation toggle. When true,
8437
10249
  NAC.register throws on findings (manifest_role_unknown,
8438
10250
  tab_id_manifest_role_drift, manifest_dom_role_mismatch).
@@ -8446,7 +10258,18 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8446
10258
  on the first slug uniqueness violation; the boot-time pass
8447
10259
  paints a red banner + dispatches nac:fatal. Set false BEFORE
8448
10260
  any register() call to opt out for a single migration window.
8449
- The flag is removed in v2.6 (enforcement becomes unconditional). */
10261
+
10262
+ 2.7.0 (TF-A13) -- "The flag is removed in v2.6 (enforcement
10263
+ becomes unconditional)" is what this comment said while running
10264
+ INSIDE 2.6 with the flag present and consulted in four places.
10265
+ The removal is WITHDRAWN (D-13, owner delegation of
10266
+ 2026-11-24), for two measured reasons: a host that set it false
10267
+ to get through a migration would start throwing on upgrade with
10268
+ no code change of its own -- the plainest form of breaking an
10269
+ adopter -- and the escape hatch is load-bearing in this
10270
+ repository too (runtime/test/stage11-plugin-id-dedup.mjs drives
10271
+ the opt-out path). The hatch is PERMANENT. What stays true is
10272
+ the default: enforcement is on unless a host says otherwise. */
8450
10273
  HARD_DEDUP: true,
8451
10274
  /* registry */
8452
10275
  register: register,
@@ -8475,10 +10298,64 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8475
10298
  verb (click/fill/select/invoke/tab/tab_by_label) honours the
8476
10299
  gate, so STRICT_VERSIONING default flips to true: callers
8477
10300
  MUST pass at least one expected_* or set STRICT_VERSIONING
8478
- =false explicitly. Removed in v2.6 (becomes unconditional). */
10301
+ =false explicitly.
10302
+
10303
+ 2.7.0 (TF-A13) -- "Removed in v2.6 (becomes unconditional)" was
10304
+ written here and is withdrawn (D-13, owner delegation of
10305
+ 2026-11-24), same reasoning as HARD_DEDUP above and one more
10306
+ that is specific to this one: made unconditional, every caller
10307
+ of every mutating verb MUST carry an expected_* snapshot, so an
10308
+ adopter driving click() without optimistic concurrency stops
10309
+ working on upgrade. The flag is PERMANENT and the default stays
10310
+ true. runtime/test/stage12-snapshot-versioning.mjs drives both
10311
+ sides of it. */
8479
10312
  STRICT_VERSIONING: true,
8480
10313
  eager_hashing: false,
8481
- conformance_tier: 'NAC-3-versioned',
10314
+ /* v2.4 (RFC V24-04 sec 5.11) -- the runtime's self-described tier.
10315
+
10316
+ A TIER IS NOT A LEVEL, and that distinction is the whole point
10317
+ of this comment. There are two taxonomies in this project and
10318
+ their names look alike:
10319
+
10320
+ - a conformance TIER is what the RUNTIME supports, and the
10321
+ vocabulary is RFC V24-04 sec 6: 'NAC-3' (no versioning),
10322
+ 'NAC-3-versioned' (honours expected_*), 'NAC-3-strict'. An
10323
+ agent reads it at boot to decide what it may send.
10324
+ - a conformance LEVEL is what a PAGE achieves, and the
10325
+ vocabulary is SPEC.md sec 8. `nac validate <url> --drive`
10326
+ reports one.
10327
+
10328
+ The published catalogue has said so in machine-readable form
10329
+ since 2.5.0 (audit N-29: until then api/ published this field as
10330
+ `type: "string"` and not its values, so a machine could see the
10331
+ field with no way to learn that 'NAC-3-versioned' is not a level
10332
+ name). The runtime export itself said nothing, which left the
10333
+ clarification only where a human was least likely to be
10334
+ reading. Now it is next to the value.
10335
+
10336
+ DEFAULT_CONFORMANCE_TIER is read, not retyped: the tier reject
10337
+ in the versioning gate used to carry its own copy of this
10338
+ string literal, which is audit N-17's shape in miniature. */
10339
+ conformance_tier: DEFAULT_CONFORMANCE_TIER,
10340
+ /* v2.7.0 (TF-A01). The selector drag_drop() removes from INSIDE a
10341
+ drop target before dropping. null = remove nothing, which is
10342
+ the default because a library may not delete a node out of a
10343
+ document it did not write. A target can override it with
10344
+ data-nac-drop-placeholder, which wins over this. */
10345
+ drop_placeholder_selector: null,
10346
+ /* v2.7.0 (TF-A02). The settle delay of drag_drop(), in ms. 80 is
10347
+ what this repository's demo UX needed and what every adopter
10348
+ paid; it stays the default so no existing drop changes timing,
10349
+ and opts.settle_ms overrides it per call. */
10350
+ drag_settle_ms: 80,
10351
+ /* v2.7.0 (TF-A11). Where the editor's "fix my grammar" control
10352
+ POSTs the text being edited. null = the feature is off and
10353
+ nothing is sent; the control reports that instead of guessing a
10354
+ path. It lives on THIS export on purpose: the only way to
10355
+ change it used to be a field of nac-chat-client.js, so an
10356
+ adopter loading the runtime alone could neither redirect it nor
10357
+ switch it off. */
10358
+ editor_ai_endpoint: null,
8482
10359
  markHydrationComplete: markHydrationComplete,
8483
10360
  versionHistory: versionHistory,
8484
10361
  /* v2.3 preview (V23-02): introspection helper that returns the
@@ -8517,6 +10394,10 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8517
10394
  list: list,
8518
10395
  find: find,
8519
10396
  read_feedback: read_feedback,
10397
+ /* v2.8.0 -- the role vocabulary, and the door into it. */
10398
+ roles: roles,
10399
+ canonical_role: canonical_role,
10400
+ register_role: register_role,
8520
10401
  snapshot_state: snapshot_state,
8521
10402
  /* write */
8522
10403
  click: click,
@@ -8658,6 +10539,17 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8658
10539
  /* v1.9.0 -- provenance authenticity (sec 6.2.1) */
8659
10540
  sign_provenance: sign_provenance,
8660
10541
  verify_provenance: verify_provenance,
10542
+ /* 2.7.0 -- manifest authenticity (sec 7.2). set_manifest_secret
10543
+ is the core entry point; NAC.set_provenance_secret in the
10544
+ extensions module forwards here so the example published in
10545
+ 7.2 works as written. */
10546
+ set_manifest_secret: set_manifest_secret,
10547
+ sign_manifest: sign_manifest,
10548
+ verify_manifest: verify_manifest,
10549
+ manifest_provenance: manifest_provenance,
10550
+ /* 2.7.0 -- dispatch provenance override (sec 15.7) */
10551
+ set_source: set_source,
10552
+ get_source: get_source,
8661
10553
  /* v1.9.0 -- recommended remediation (sec 6.2.30) */
8662
10554
  recommended_remediation: recommended_remediation,
8663
10555
  /* v1.2 -- error codes */
@@ -8690,6 +10582,16 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8690
10582
  window (a React ref, a library instance held in a closure). */
8691
10583
  plugins: plugins,
8692
10584
  describePlugin: describePlugin,
10585
+ /* v2.7 -- the headless profile (SPEC.md sec 19 / decision D-26).
10586
+ profile() says whether a registered plugin needs a document at
10587
+ all; setEventSink() carries the nac:plugin:* family over a bus
10588
+ that is not the DOM, so a screenless host keeps its provenance;
10589
+ provenanceStatus() makes the delivery -- and any loss --
10590
+ readable instead of swallowed. */
10591
+ profile: profile,
10592
+ setEventSink: setEventSink,
10593
+ eventSink: eventSink,
10594
+ provenanceStatus: provenanceStatus,
8693
10595
  registerApiHandle: registerApiHandle,
8694
10596
  unregisterApiHandle: unregisterApiHandle,
8695
10597
  apiHandles: apiHandles,