@nac3/runtime 2.5.0-alpha.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1017 -841
- package/README.md +145 -145
- package/SPEC.md +1761 -1371
- package/contract-head.json +16 -0
- package/dist/cli-levels.json +214 -0
- package/dist/cli-url.mjs +751 -0
- package/dist/cli.js +232 -38
- package/dist/nac-chat-client.d.ts +5 -75
- package/dist/nac-v2-extensions.d.ts +71 -68
- package/dist/nac.browser.js +375 -29
- package/dist/nac.cjs +375 -29
- package/dist/nac.d.ts +140 -34
- package/dist/nac.mjs +375 -29
- package/package.json +19 -19
package/dist/nac.mjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : {});
|
|
3
3
|
/* =====================================================================
|
|
4
4
|
NAC3 (Native Agent Contract v3) -- reference JavaScript runtime.
|
|
5
|
-
Spec:
|
|
6
|
-
|
|
5
|
+
Spec: SPEC.md (repo root). Public docs: yujin.app/nac-spec/.
|
|
6
|
+
Apache-2.0 License -- Pablo Adrian Kuschniroff + Sumi, 2026.
|
|
7
7
|
=====================================================================
|
|
8
8
|
|
|
9
9
|
AUTHORITATIVE VERSION CONSTANT: see the global.NAC export at the
|
|
10
|
-
bottom of this file. `version: '2.
|
|
11
|
-
the normative declaration. The dated changelog sections below are
|
|
10
|
+
bottom of this file. `version: '2.5.0', spec_version: '2.5'`
|
|
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.
|
|
14
14
|
|
|
@@ -1137,7 +1137,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
1137
1137
|
|
|
1138
1138
|
function _candidateLabel(el) {
|
|
1139
1139
|
/* Best-effort human label for a DOM element. Used in
|
|
1140
|
-
candidates[].label so voice/
|
|
1140
|
+
candidates[].label so voice/assistive can re-prompt. */
|
|
1141
1141
|
if (!el) return '';
|
|
1142
1142
|
const al = el.getAttribute && el.getAttribute('aria-label');
|
|
1143
1143
|
if (al) return String(al).trim();
|
|
@@ -2363,11 +2363,34 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2363
2363
|
fields[], tabs[], kpis[], rows.cells[], breadcrumbs[], etc. */
|
|
2364
2364
|
function _collectManifestIds(m) {
|
|
2365
2365
|
const out = [];
|
|
2366
|
+
/* v2.5 fix (audit N-33): the CANONICAL manifest shape is
|
|
2367
|
+
`elements: [{ id, role, ... }]` -- that is what section 4
|
|
2368
|
+
documents, what every demo ships and what the rest of this
|
|
2369
|
+
runtime reads (see _capabilityFor, which walks
|
|
2370
|
+
m.elements.concat(m.tabs) by `.id`). This collector used to
|
|
2371
|
+
read ONLY the legacy groups below, keyed by `nac_id`, so for
|
|
2372
|
+
a manifest written the documented way it returned an empty
|
|
2373
|
+
list. Everything built on top went quietly wrong in the same
|
|
2374
|
+
direction: validate_global() reported total_ids = 0, called
|
|
2375
|
+
every declared element an orphan, could never report a
|
|
2376
|
+
duplicate, an unmounted id or a convention violation, and
|
|
2377
|
+
still answered ok = true. A validator that cannot see the
|
|
2378
|
+
manifest is not a lenient validator, it is a green light
|
|
2379
|
+
with nothing behind it. Both shapes are read now; the legacy
|
|
2380
|
+
groups stay because manifests in the wild still use them. */
|
|
2381
|
+
const elems = (m && m.elements) || [];
|
|
2382
|
+
elems.forEach(function (e) {
|
|
2383
|
+
if (e && e.id) out.push(String(e.id));
|
|
2384
|
+
});
|
|
2366
2385
|
const groups = ['actions', 'fields', 'tabs', 'kpis', 'charts'];
|
|
2367
2386
|
groups.forEach(function (g) {
|
|
2368
2387
|
const arr = (m && m[g]) || [];
|
|
2369
2388
|
arr.forEach(function (x) {
|
|
2389
|
+
/* tabs are declared with `.id` in the canonical shape and
|
|
2390
|
+
with `.nac_id` in the legacy one; take whichever is there
|
|
2391
|
+
instead of choosing a winner. */
|
|
2370
2392
|
if (x && x.nac_id) out.push(String(x.nac_id));
|
|
2393
|
+
else if (x && x.id) out.push(String(x.id));
|
|
2371
2394
|
});
|
|
2372
2395
|
});
|
|
2373
2396
|
if (m && m.rows && Array.isArray(m.rows.cells)) {
|
|
@@ -2384,7 +2407,14 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2384
2407
|
}
|
|
2385
2408
|
});
|
|
2386
2409
|
}
|
|
2387
|
-
|
|
2410
|
+
/* Unique: an id declared in two shapes of the SAME manifest is one
|
|
2411
|
+
id, not a cross-plugin duplicate. */
|
|
2412
|
+
const seen = Object.create(null);
|
|
2413
|
+
return out.filter(function (id) {
|
|
2414
|
+
if (seen[id]) return false;
|
|
2415
|
+
seen[id] = true;
|
|
2416
|
+
return true;
|
|
2417
|
+
});
|
|
2388
2418
|
}
|
|
2389
2419
|
|
|
2390
2420
|
function unregister(slug) {
|
|
@@ -3489,23 +3519,45 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
3489
3519
|
_focusElement(el);
|
|
3490
3520
|
const ft = el.getAttribute('data-nac-field-type');
|
|
3491
3521
|
|
|
3522
|
+
/* The native property setter, or null when this host has no such
|
|
3523
|
+
constructor (audit N-44).
|
|
3524
|
+
|
|
3525
|
+
Every call site below already had a fallback -- `el.value = v`
|
|
3526
|
+
when the descriptor has no setter -- and the fallback was
|
|
3527
|
+
UNREACHABLE in the only environment it was written for. The guard
|
|
3528
|
+
tested the descriptor and the expression reached through
|
|
3529
|
+
`window.HTMLInputElement.prototype` to produce it, so on a host
|
|
3530
|
+
with a partial DOM (a test shim, an SSR or headless context --
|
|
3531
|
+
the paths this runtime claims to support) fill() threw
|
|
3532
|
+
`Cannot read properties of undefined (reading 'prototype')`
|
|
3533
|
+
before any fallback could run. Worse than the crash: the thrown
|
|
3534
|
+
value is a raw TypeError with no `code`, so a caller relying on
|
|
3535
|
+
the error contract gets nothing it can branch on.
|
|
3536
|
+
|
|
3537
|
+
A real browser is unaffected: the constructors always exist,
|
|
3538
|
+
the descriptor is found, and the native setter is used exactly
|
|
3539
|
+
as before -- which is what keeps React's controlled inputs
|
|
3540
|
+
working. */
|
|
3541
|
+
const _nativeSetter = function (ctorName, prop) {
|
|
3542
|
+
var ctor = (typeof window !== 'undefined') ? window[ctorName] : undefined;
|
|
3543
|
+
if (!ctor || !ctor.prototype) return null;
|
|
3544
|
+
var d = Object.getOwnPropertyDescriptor(ctor.prototype, prop);
|
|
3545
|
+
return (d && d.set) ? d.set : null;
|
|
3546
|
+
};
|
|
3547
|
+
|
|
3492
3548
|
if (ft === 'checkbox' || ft === 'radio') {
|
|
3493
3549
|
/* React tracks `checked` similarly to `value`; use the native
|
|
3494
3550
|
setter so controlled checkboxes/radios update state. */
|
|
3495
|
-
var nativeCheckedSetter =
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
if (nativeCheckedSetter && nativeCheckedSetter.set) {
|
|
3499
|
-
nativeCheckedSetter.set.call(el, !!value);
|
|
3551
|
+
var nativeCheckedSetter = _nativeSetter('HTMLInputElement', 'checked');
|
|
3552
|
+
if (nativeCheckedSetter) {
|
|
3553
|
+
nativeCheckedSetter.call(el, !!value);
|
|
3500
3554
|
} else {
|
|
3501
3555
|
el.checked = !!value;
|
|
3502
3556
|
}
|
|
3503
3557
|
} else if (el.tagName === 'SELECT') {
|
|
3504
|
-
var nativeSelectSetter =
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
if (nativeSelectSetter && nativeSelectSetter.set) {
|
|
3508
|
-
nativeSelectSetter.set.call(el, String(value));
|
|
3558
|
+
var nativeSelectSetter = _nativeSetter('HTMLSelectElement', 'value');
|
|
3559
|
+
if (nativeSelectSetter) {
|
|
3560
|
+
nativeSelectSetter.call(el, String(value));
|
|
3509
3561
|
} else {
|
|
3510
3562
|
el.value = String(value);
|
|
3511
3563
|
}
|
|
@@ -3517,13 +3569,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
3517
3569
|
tracks the original property setter on HTMLInputElement.prototype.
|
|
3518
3570
|
Use the native setter so React's onChange receives the new value
|
|
3519
3571
|
and updates its state. Works on plain DOM inputs unchanged. */
|
|
3520
|
-
var
|
|
3521
|
-
?
|
|
3522
|
-
|
|
3523
|
-
|
|
3572
|
+
var nativeValueSetter = _nativeSetter(
|
|
3573
|
+
(el.tagName === 'TEXTAREA') ? 'HTMLTextAreaElement' : 'HTMLInputElement',
|
|
3574
|
+
'value'
|
|
3575
|
+
);
|
|
3524
3576
|
var newVal = String(value == null ? '' : value);
|
|
3525
|
-
if (nativeValueSetter
|
|
3526
|
-
nativeValueSetter.
|
|
3577
|
+
if (nativeValueSetter) {
|
|
3578
|
+
nativeValueSetter.call(el, newVal);
|
|
3527
3579
|
} else {
|
|
3528
3580
|
el.value = newVal;
|
|
3529
3581
|
}
|
|
@@ -4630,16 +4682,36 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4630
4682
|
DOM that belong to no manifest?" The per-plugin validate(slug)
|
|
4631
4683
|
cannot see across boundaries; this one can.
|
|
4632
4684
|
|
|
4633
|
-
Returns
|
|
4685
|
+
Returns an OBJECT OF NAMED BUCKETS -- not a flat array of
|
|
4686
|
+
findings. Every item of every bucket carries `code` and
|
|
4687
|
+
`severity` since 2.5.0 (audit N-14), so a CI integration can
|
|
4688
|
+
gate on a code without parsing a message:
|
|
4634
4689
|
{
|
|
4635
4690
|
ok: boolean,
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4691
|
+
has_errors: boolean,
|
|
4692
|
+
duplicates: [{code nac_id_duplicate_across_plugins,
|
|
4693
|
+
severity error, nac_id, plugins:[...]}],
|
|
4694
|
+
orphans: [{code nac_id_orphan_in_dom, severity warn,
|
|
4695
|
+
nac_id, in_dom:true, in_manifest:false,
|
|
4696
|
+
plugin_root:?}],
|
|
4697
|
+
unmounted: [{code nac_id_declared_not_mounted,
|
|
4698
|
+
severity warn, nac_id, in_manifest:true,
|
|
4699
|
+
in_dom:false, plugin}],
|
|
4700
|
+
convention_violations:
|
|
4701
|
+
[{code nac_id_missing_plugin_prefix,
|
|
4702
|
+
severity warn, nac_id, plugin, hint}],
|
|
4703
|
+
plugin_instance_violations:
|
|
4704
|
+
[{code duplicate_plugin_no_instance_id,
|
|
4705
|
+
severity error, slug, ...}],
|
|
4706
|
+
tolerated: [{kind, nac_id, until, original}],
|
|
4640
4707
|
plugin_count, total_ids,
|
|
4641
4708
|
timestamp
|
|
4642
4709
|
}
|
|
4710
|
+
The five codes are published, with their severity and what to do
|
|
4711
|
+
about each, in api/latest/findings.json. (The code names above are
|
|
4712
|
+
written unquoted on purpose: the catalogue generator greps the
|
|
4713
|
+
emission shape out of this file, and a comment is not an
|
|
4714
|
+
emission.)
|
|
4643
4715
|
|
|
4644
4716
|
A NAC-3 codebase that wants drift to be a CI blocker should run
|
|
4645
4717
|
this in addition to the per-plugin validate(slug) loop. */
|
|
@@ -4678,6 +4750,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4678
4750
|
ids.forEach(function (id) {
|
|
4679
4751
|
if (id.indexOf(slug + '.') !== 0 && id !== slug) {
|
|
4680
4752
|
out.convention_violations.push({
|
|
4753
|
+
/* v2.5 / audit N-14: every finding of this validator carries
|
|
4754
|
+
a code from the published catalogue, so section 12 promise
|
|
4755
|
+
4 ("the validate_global finding codes will not be reused")
|
|
4756
|
+
covers a real set instead of an empty one. The code is the
|
|
4757
|
+
stable identity; the message is not. */
|
|
4758
|
+
code: 'nac_id_missing_plugin_prefix',
|
|
4759
|
+
severity: 'warn',
|
|
4681
4760
|
nac_id: id, plugin: slug,
|
|
4682
4761
|
hint: 'expected prefix "' + slug + '."',
|
|
4683
4762
|
});
|
|
@@ -4689,7 +4768,11 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4689
4768
|
/* Duplicates: any id that appears in 2+ manifests. */
|
|
4690
4769
|
for (const id in idIndex) {
|
|
4691
4770
|
if (idIndex[id].length >= 2) {
|
|
4692
|
-
out.duplicates.push({
|
|
4771
|
+
out.duplicates.push({
|
|
4772
|
+
code: 'nac_id_duplicate_across_plugins',
|
|
4773
|
+
severity: 'error',
|
|
4774
|
+
nac_id: id, plugins: idIndex[id].slice(),
|
|
4775
|
+
});
|
|
4693
4776
|
}
|
|
4694
4777
|
}
|
|
4695
4778
|
|
|
@@ -4710,6 +4793,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4710
4793
|
severity for the caller to decide. */
|
|
4711
4794
|
const root = el.closest('[data-nac-plugin]');
|
|
4712
4795
|
out.orphans.push({
|
|
4796
|
+
code: 'nac_id_orphan_in_dom',
|
|
4797
|
+
severity: 'warn',
|
|
4713
4798
|
nac_id: id,
|
|
4714
4799
|
in_dom: true,
|
|
4715
4800
|
in_manifest: false,
|
|
@@ -4723,6 +4808,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4723
4808
|
for (const id in idIndex) {
|
|
4724
4809
|
if (!inDom[id]) {
|
|
4725
4810
|
out.unmounted.push({
|
|
4811
|
+
code: 'nac_id_declared_not_mounted',
|
|
4812
|
+
severity: 'warn',
|
|
4726
4813
|
nac_id: id, in_manifest: true, in_dom: false,
|
|
4727
4814
|
plugin: idIndex[id][0],
|
|
4728
4815
|
});
|
|
@@ -7591,11 +7678,251 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7591
7678
|
}
|
|
7592
7679
|
}
|
|
7593
7680
|
|
|
7681
|
+
/* ================================================================
|
|
7682
|
+
v2.5 Block C -- RFC V25-03: assistive labels (narrate)
|
|
7683
|
+
================================================================
|
|
7684
|
+
|
|
7685
|
+
NAC.narrate(plugin, nac_id) -> string
|
|
7686
|
+
Canonical human-readable label for any nac_id in the plugin's
|
|
7687
|
+
DOM. Priority order:
|
|
7688
|
+
1. aria-label (a11y-first)
|
|
7689
|
+
2. visible text (the human reading the chrome)
|
|
7690
|
+
3. data-nac-label (author override)
|
|
7691
|
+
4. nac_id (worst case)
|
|
7692
|
+
|
|
7693
|
+
For elements where the visible text leaks child-interactive
|
|
7694
|
+
content (eg a button containing an icon and a label), narrate
|
|
7695
|
+
prefers the FIRST text node directly under the element so the
|
|
7696
|
+
spoken output stays focused.
|
|
7697
|
+
|
|
7698
|
+
Returns null only if the element cannot be found (unknown
|
|
7699
|
+
nac_id or unknown plugin). Empty/whitespace labels collapse to
|
|
7700
|
+
the next priority tier. */
|
|
7701
|
+
|
|
7702
|
+
function _v25c_visibleText(el) {
|
|
7703
|
+
if (!el) return '';
|
|
7704
|
+
/* Collect text directly under el, excluding nested elements that
|
|
7705
|
+
are themselves nac-addressable (those have their own narrate
|
|
7706
|
+
resolution). */
|
|
7707
|
+
let out = '';
|
|
7708
|
+
for (let n = el.firstChild; n; n = n.nextSibling) {
|
|
7709
|
+
if (n.nodeType === 3 /* TEXT_NODE */) {
|
|
7710
|
+
out += n.nodeValue || '';
|
|
7711
|
+
} else if (n.nodeType === 1 /* ELEMENT_NODE */) {
|
|
7712
|
+
/* Skip nested nac-addressable subtrees -- they have their
|
|
7713
|
+
own label. */
|
|
7714
|
+
if (n.getAttribute && n.getAttribute('data-nac-id')) continue;
|
|
7715
|
+
/* Recurse into non-addressable children (typical: icon
|
|
7716
|
+
<span> + text). */
|
|
7717
|
+
out += _v25c_visibleText(n);
|
|
7718
|
+
}
|
|
7719
|
+
}
|
|
7720
|
+
return out.replace(/\s+/g, ' ').trim();
|
|
7721
|
+
}
|
|
7722
|
+
|
|
7723
|
+
function narrate(plugin, nac_id) {
|
|
7724
|
+
if (typeof nac_id !== 'string' || !nac_id) return null;
|
|
7725
|
+
/* Scope by plugin if provided -- look only inside [data-nac-plugin=plugin]
|
|
7726
|
+
subtree. If plugin is omitted, fall back to global search. */
|
|
7727
|
+
let root = document;
|
|
7728
|
+
if (plugin) {
|
|
7729
|
+
const pluginRoot = document.querySelector('[data-nac-plugin="' + plugin + '"]');
|
|
7730
|
+
if (!pluginRoot) return null;
|
|
7731
|
+
root = pluginRoot;
|
|
7732
|
+
}
|
|
7733
|
+
/* Use attribute selector with CSS-safe escape via JSON.stringify
|
|
7734
|
+
to avoid injection when nac_id contains weird chars. */
|
|
7735
|
+
const safeId = '"' + String(nac_id).replace(/["\\]/g, '\\$&') + '"';
|
|
7736
|
+
const el = root.querySelector('[data-nac-id=' + safeId + ']');
|
|
7737
|
+
if (!el) return null;
|
|
7738
|
+
/* 1. aria-label */
|
|
7739
|
+
const aria = el.getAttribute('aria-label');
|
|
7740
|
+
if (aria && aria.trim()) return aria.trim();
|
|
7741
|
+
/* 2. visible text (direct + nested non-addressable) */
|
|
7742
|
+
const vis = _v25c_visibleText(el);
|
|
7743
|
+
if (vis) return vis;
|
|
7744
|
+
/* 3. data-nac-label */
|
|
7745
|
+
const explicit = el.getAttribute('data-nac-label');
|
|
7746
|
+
if (explicit && explicit.trim()) return explicit.trim();
|
|
7747
|
+
/* 4. nac_id fallback */
|
|
7748
|
+
return nac_id;
|
|
7749
|
+
}
|
|
7750
|
+
|
|
7751
|
+
/* ================================================================
|
|
7752
|
+
v2.5 Block B -- RFC V25-02: tree navigation
|
|
7753
|
+
================================================================
|
|
7754
|
+
|
|
7755
|
+
NAC.context(plugin) -> { breadcrumb: [{nac_id, label}, ...] }
|
|
7756
|
+
Walks up from document.activeElement through ancestor nac-id
|
|
7757
|
+
elements within the plugin subtree. Empty array when nothing
|
|
7758
|
+
focused inside the plugin.
|
|
7759
|
+
|
|
7760
|
+
NAC.tree(plugin, rootId?) -> [{nac_id, label, opens?, leaf?}, ...]
|
|
7761
|
+
Enumerates the IMMEDIATE addressable children of rootId (or the
|
|
7762
|
+
plugin root when rootId is omitted). "Immediate" means: there
|
|
7763
|
+
are no other nac-id elements between them and the start. Each
|
|
7764
|
+
entry reports the data-nac-opens target slug (if any) and a
|
|
7765
|
+
boolean leaf flag (data-nac-leaf attribute present).
|
|
7766
|
+
|
|
7767
|
+
Both functions delegate label resolution to narrate(). */
|
|
7768
|
+
|
|
7769
|
+
function _v25b_pluginRoot(plugin) {
|
|
7770
|
+
if (!plugin) return null;
|
|
7771
|
+
return document.querySelector('[data-nac-plugin="' + plugin + '"]');
|
|
7772
|
+
}
|
|
7773
|
+
|
|
7774
|
+
function context(plugin) {
|
|
7775
|
+
const out = { breadcrumb: [] };
|
|
7776
|
+
const root = _v25b_pluginRoot(plugin);
|
|
7777
|
+
if (!root) return out;
|
|
7778
|
+
const active = document.activeElement;
|
|
7779
|
+
if (!active || !root.contains(active)) return out;
|
|
7780
|
+
/* Walk up; collect each ancestor that owns a data-nac-id. Stop
|
|
7781
|
+
at the plugin root inclusive (root itself may not carry a
|
|
7782
|
+
nac-id -- in that case we just stop there). */
|
|
7783
|
+
let cur = active;
|
|
7784
|
+
while (cur && cur !== root.parentElement) {
|
|
7785
|
+
const id = cur.getAttribute && cur.getAttribute('data-nac-id');
|
|
7786
|
+
if (id) {
|
|
7787
|
+
out.breadcrumb.unshift({ nac_id: id, label: narrate(plugin, id) });
|
|
7788
|
+
}
|
|
7789
|
+
if (cur === root) break;
|
|
7790
|
+
cur = cur.parentElement;
|
|
7791
|
+
}
|
|
7792
|
+
return out;
|
|
7793
|
+
}
|
|
7794
|
+
|
|
7795
|
+
function _v25b_isImmediate(start, node) {
|
|
7796
|
+
/* True if `node` has no OTHER nac-id ancestor between itself and
|
|
7797
|
+
`start`. Excludes node === start and ancestors above start. */
|
|
7798
|
+
let p = node.parentElement;
|
|
7799
|
+
while (p && p !== start) {
|
|
7800
|
+
if (p.getAttribute && p.getAttribute('data-nac-id')) return false;
|
|
7801
|
+
p = p.parentElement;
|
|
7802
|
+
}
|
|
7803
|
+
return true;
|
|
7804
|
+
}
|
|
7805
|
+
|
|
7806
|
+
/* ================================================================
|
|
7807
|
+
v2.5 Block D -- RFC V25-04: effect detection (expect + diff)
|
|
7808
|
+
================================================================
|
|
7809
|
+
|
|
7810
|
+
NAC.expect(plugin, statePath, value, opts?) -> Promise
|
|
7811
|
+
Polls NAC.read(plugin, statePath) until the returned value
|
|
7812
|
+
satisfies the comparator (default ===) or the timeout fires.
|
|
7813
|
+
Resolves with the resolved value on match.
|
|
7814
|
+
Rejects with NacError('timeout', ...) on deadline.
|
|
7815
|
+
Read failures are retried until the deadline (treated as
|
|
7816
|
+
"the state is not yet observable").
|
|
7817
|
+
|
|
7818
|
+
opts:
|
|
7819
|
+
timeout_ms default 5000
|
|
7820
|
+
poll_ms default 100
|
|
7821
|
+
comparator default (cur, want) => cur === want
|
|
7822
|
+
receives (current, expected) and returns boolean
|
|
7823
|
+
|
|
7824
|
+
NAC.diff(plugin, statePath, actionFn) -> Promise<{before, after, changed}>
|
|
7825
|
+
Reads state, awaits actionFn(), reads state again, returns
|
|
7826
|
+
both snapshots + a `changed` boolean (JSON-stringify compare).
|
|
7827
|
+
Read failures collapse to undefined and changed is computed
|
|
7828
|
+
on the stringified pair (so undefined vs value still flags).
|
|
7829
|
+
|
|
7830
|
+
Both delegate to NAC.read() so they inherit V25-01's full
|
|
7831
|
+
fallback-chain semantics for free. */
|
|
7832
|
+
|
|
7833
|
+
function expect(plugin, statePath, value, opts) {
|
|
7834
|
+
opts = opts || {};
|
|
7835
|
+
const timeout = (typeof opts.timeout_ms === 'number') ? opts.timeout_ms : 5000;
|
|
7836
|
+
const pollMs = (typeof opts.poll_ms === 'number') ? opts.poll_ms : 100;
|
|
7837
|
+
const cmp = (typeof opts.comparator === 'function')
|
|
7838
|
+
? opts.comparator
|
|
7839
|
+
: function (cur, want) { return cur === want; };
|
|
7840
|
+
const deadline = Date.now() + timeout;
|
|
7841
|
+
return new Promise(function (resolve, reject) {
|
|
7842
|
+
function tick() {
|
|
7843
|
+
read(plugin, statePath).then(function (cur) {
|
|
7844
|
+
let matches = false;
|
|
7845
|
+
try { matches = !!cmp(cur, value); }
|
|
7846
|
+
catch (_) { matches = false; }
|
|
7847
|
+
if (matches) { resolve(cur); return; }
|
|
7848
|
+
if (Date.now() >= deadline) {
|
|
7849
|
+
reject(_v25_buildNacError('timeout',
|
|
7850
|
+
'NAC.expect: state "' + statePath + '" did not match within ' +
|
|
7851
|
+
timeout + 'ms (last value: ' + JSON.stringify(cur) + ')'));
|
|
7852
|
+
return;
|
|
7853
|
+
}
|
|
7854
|
+
setTimeout(tick, pollMs);
|
|
7855
|
+
}, function (_err) {
|
|
7856
|
+
if (Date.now() >= deadline) {
|
|
7857
|
+
reject(_v25_buildNacError('timeout',
|
|
7858
|
+
'NAC.expect: state "' + statePath + '" unreadable + timeout'));
|
|
7859
|
+
return;
|
|
7860
|
+
}
|
|
7861
|
+
setTimeout(tick, pollMs);
|
|
7862
|
+
});
|
|
7863
|
+
}
|
|
7864
|
+
tick();
|
|
7865
|
+
});
|
|
7866
|
+
}
|
|
7867
|
+
|
|
7868
|
+
function diff(plugin, statePath, actionFn) {
|
|
7869
|
+
function safeRead() {
|
|
7870
|
+
return read(plugin, statePath).then(
|
|
7871
|
+
function (v) { return v; },
|
|
7872
|
+
function () { return undefined; }
|
|
7873
|
+
);
|
|
7874
|
+
}
|
|
7875
|
+
return safeRead().then(function (before) {
|
|
7876
|
+
const act = (typeof actionFn === 'function')
|
|
7877
|
+
? Promise.resolve(actionFn())
|
|
7878
|
+
: Promise.resolve();
|
|
7879
|
+
return act.then(function () {
|
|
7880
|
+
return safeRead().then(function (after) {
|
|
7881
|
+
let changed;
|
|
7882
|
+
try {
|
|
7883
|
+
changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
7884
|
+
} catch (_) {
|
|
7885
|
+
changed = before !== after;
|
|
7886
|
+
}
|
|
7887
|
+
return { before: before, after: after, changed: changed };
|
|
7888
|
+
});
|
|
7889
|
+
});
|
|
7890
|
+
});
|
|
7891
|
+
}
|
|
7892
|
+
|
|
7893
|
+
function tree(plugin, rootId) {
|
|
7894
|
+
const pluginRoot = _v25b_pluginRoot(plugin);
|
|
7895
|
+
if (!pluginRoot) return [];
|
|
7896
|
+
let start = pluginRoot;
|
|
7897
|
+
if (rootId) {
|
|
7898
|
+
const safeId = '"' + String(rootId).replace(/["\\]/g, '\\$&') + '"';
|
|
7899
|
+
const found = pluginRoot.querySelector('[data-nac-id=' + safeId + ']');
|
|
7900
|
+
if (!found) return [];
|
|
7901
|
+
start = found;
|
|
7902
|
+
}
|
|
7903
|
+
const candidates = start.querySelectorAll('[data-nac-id]');
|
|
7904
|
+
const out = [];
|
|
7905
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
7906
|
+
const k = candidates[i];
|
|
7907
|
+
if (!_v25b_isImmediate(start, k)) continue;
|
|
7908
|
+
const id = k.getAttribute('data-nac-id');
|
|
7909
|
+
const entry = {
|
|
7910
|
+
nac_id: id,
|
|
7911
|
+
label: narrate(plugin, id),
|
|
7912
|
+
};
|
|
7913
|
+
const opens = k.getAttribute('data-nac-opens');
|
|
7914
|
+
if (opens) entry.opens = opens;
|
|
7915
|
+
if (k.hasAttribute('data-nac-leaf')) entry.leaf = true;
|
|
7916
|
+
out.push(entry);
|
|
7917
|
+
}
|
|
7918
|
+
return out;
|
|
7919
|
+
}
|
|
7920
|
+
|
|
7594
7921
|
/* ---------- Install -------------------------------------------- */
|
|
7595
7922
|
|
|
7596
7923
|
global.NAC = {
|
|
7597
7924
|
__nac_v1_installed: true,
|
|
7598
|
-
version: '2.5.0
|
|
7925
|
+
version: '2.5.0',
|
|
7599
7926
|
spec_version: '2.5',
|
|
7600
7927
|
/* v2.2.0 (V22-01) -- strict validation toggle. When true,
|
|
7601
7928
|
NAC.register throws on findings (manifest_role_unknown,
|
|
@@ -7846,6 +8173,25 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7846
8173
|
read: read,
|
|
7847
8174
|
subscribe: subscribe,
|
|
7848
8175
|
unsubscribe: unsubscribe,
|
|
8176
|
+
/* v2.5 Block C -- assistive labels (SPEC.md sec 17 / RFC V25-03).
|
|
8177
|
+
Canonical human-readable label resolution for screen readers,
|
|
8178
|
+
TTS, voice flows, audit logs. Priority order: aria-label >
|
|
8179
|
+
visible text > data-nac-label > nac_id fallback. */
|
|
8180
|
+
narrate: narrate,
|
|
8181
|
+
/* v2.5 Block B -- tree navigation (SPEC.md sec 16 / RFC V25-02).
|
|
8182
|
+
context(plugin) returns the focused node's breadcrumb;
|
|
8183
|
+
tree(plugin, rootId?) enumerates navigable children.
|
|
8184
|
+
data-nac-opens declares parent->child relationships; data-nac-leaf
|
|
8185
|
+
marks terminals. Companion to narrate for chrome-driven walks. */
|
|
8186
|
+
context: context,
|
|
8187
|
+
tree: tree,
|
|
8188
|
+
/* v2.5 Block D -- effect detection (SPEC.md sec 18 / RFC V25-04).
|
|
8189
|
+
Closes the "silent damage" gap for assistive callers: the agent
|
|
8190
|
+
confirms the EFFECT of an action, not just that the command was
|
|
8191
|
+
emitted. expect() polls until a state matches; diff() snapshots
|
|
8192
|
+
around an action. Both compose with NAC.read() / V25-01 surface. */
|
|
8193
|
+
expect: expect,
|
|
8194
|
+
diff: diff,
|
|
7849
8195
|
};
|
|
7850
8196
|
|
|
7851
8197
|
/* v2.2.1: guard browser-only init so this module is importable in
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nac3/runtime",
|
|
3
|
-
"version": "2.5.0
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Native Agent Contract -- spec + reference runtime that lets web UIs be driven by AI agents, voice runners, and accessibility tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nac",
|
|
@@ -58,29 +58,29 @@
|
|
|
58
58
|
},
|
|
59
59
|
"files": [
|
|
60
60
|
"dist/",
|
|
61
|
-
"src/",
|
|
62
61
|
"README.md",
|
|
63
62
|
"LICENSE",
|
|
64
63
|
"SPEC.md",
|
|
65
|
-
"CHANGELOG.md"
|
|
64
|
+
"CHANGELOG.md",
|
|
65
|
+
"contract-head.json"
|
|
66
66
|
],
|
|
67
67
|
"scripts": {
|
|
68
|
-
"build":
|
|
69
|
-
"test":
|
|
70
|
-
"test:smoke":
|
|
71
|
-
"test:v22":
|
|
72
|
-
"test:v23":
|
|
73
|
-
"test:v23-shadow":
|
|
74
|
-
"test:v23-caps":
|
|
75
|
-
"test:v23-editor":
|
|
76
|
-
"test:v23-interop":
|
|
77
|
-
"test:stage2":
|
|
78
|
-
"test:stage7":
|
|
79
|
-
"test:stage8":
|
|
80
|
-
"test:stage9":
|
|
81
|
-
"test:stage10":
|
|
82
|
-
"test:stage11":
|
|
83
|
-
"prepublishOnly": "npm run build && npm test"
|
|
68
|
+
"build": "node ./build.mjs",
|
|
69
|
+
"test": "node ./test/smoke.mjs && node ./test/v22.mjs && node ./test/v23-invoke.mjs && node ./test/v23-shadow.mjs && node ./test/v23-capabilities.mjs && node ./test/v23-editor.mjs && node ./test/v23-interop.mjs && node ./test/stage2-disambiguation.mjs && node ./test/stage7-strict-resolution.mjs && node ./test/stage8-plugin-extension.mjs && node ./test/stage9-sync-plugin.mjs && node ./test/stage10-authority-sudo.mjs && node ./test/stage11-plugin-id-dedup.mjs && node ./test/stage12-snapshot-versioning.mjs",
|
|
70
|
+
"test:smoke": "node ./test/smoke.mjs",
|
|
71
|
+
"test:v22": "node ./test/v22.mjs",
|
|
72
|
+
"test:v23": "node ./test/v23-invoke.mjs",
|
|
73
|
+
"test:v23-shadow": "node ./test/v23-shadow.mjs",
|
|
74
|
+
"test:v23-caps": "node ./test/v23-capabilities.mjs",
|
|
75
|
+
"test:v23-editor": "node ./test/v23-editor.mjs",
|
|
76
|
+
"test:v23-interop": "node ./test/v23-interop.mjs",
|
|
77
|
+
"test:stage2": "node ./test/stage2-disambiguation.mjs",
|
|
78
|
+
"test:stage7": "node ./test/stage7-strict-resolution.mjs",
|
|
79
|
+
"test:stage8": "node ./test/stage8-plugin-extension.mjs",
|
|
80
|
+
"test:stage9": "node ./test/stage9-sync-plugin.mjs",
|
|
81
|
+
"test:stage10": "node ./test/stage10-authority-sudo.mjs",
|
|
82
|
+
"test:stage11": "node ./test/stage11-plugin-id-dedup.mjs",
|
|
83
|
+
"prepublishOnly": "npm run build && node ../scripts/check-version-coherence.mjs && npm test"
|
|
84
84
|
},
|
|
85
85
|
"engines": {
|
|
86
86
|
"node": ">=18"
|