@nac3/runtime 2.3.0-alpha.2 → 2.3.1

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/SPEC.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # NAC3 -- Native Agent Contract
2
2
 
3
- **Version:** 2.3.0-alpha.1 (preview; payload-bearing actions land here)
4
- **Status:** v2.2.x stable + v2.3 preview
3
+ **Version:** 2.3.0
4
+ **Status:** Stable (npm `@nac3/runtime@2.3.0`)
5
+ **Benchmark:** 600 runs across 5 models x 3 protocols -- [results](./benchmark/)
5
6
  **License:** Apache-2.0
6
- **Editor:** Yujin (rpaforce.com)
7
+ **Editor:** Yujin (yujin.app)
8
+ **RFCs in flight:** see [/rfcs/](./rfcs/) for V24-04 (snapshot versioning, enforcement opt-in in 2.3.0) and V24-05 (authority, draft for 2.4).
7
9
 
8
10
  ---
9
11
 
@@ -69,9 +71,10 @@ Every agent-resolvable element carries `data-nac-id`. The id is:
69
71
  - **A dotted path** (e.g. `deals.list.row.42.actions.delete`).
70
72
  Dots separate semantic levels; the runtime does not interpret
71
73
  them, but humans and LLMs do.
72
- - **Globally unique within a `data-nac-plugin` scope.** Two
73
- different plugins MAY share an id; the runtime resolves by
74
- `(plugin, id)` pair.
74
+ - **Globally unique within a `(data-nac-plugin, data-nac-plugin-id)`
75
+ instance scope.** Two different plugins MAY share an id; the
76
+ runtime resolves by `(plugin, plugin_instance_id, id)` pair.
77
+ See sec 7.4 for the plugin slug uniqueness contract.
75
78
  - **Stable across re-renders.** Frameworks that produce a new id
76
79
  per render (random hashes, instance counters) break the contract.
77
80
  - **Stable across UI redesigns.** A button moves from the toolbar
@@ -196,7 +199,7 @@ Promise). Returns an unbinder. Use this instead of raw
196
199
  `addEventListener('click', ...)` whenever the host supports it;
197
200
  brownfield code can still emit the event manually as before.
198
201
 
199
- ### 5.1.3 Field editor (v2.3 preview)
202
+ ### 5.1.3 Field editor (v2.3)
200
203
 
201
204
  `NAC.edit_field(nac_id)` opens a modal that lets a user (or an
202
205
  agent on their behalf) edit any text field with Word-style tools:
@@ -222,8 +225,9 @@ NAC-3 callable verbs:
222
225
  Esc closes (cancel). Ctrl/Cmd+Enter saves. Click on overlay
223
226
  backdrop cancels.
224
227
 
225
- Spec sec 13 will formalise the contract in v2.3; the v2.2 runtime
226
- ships a working reference impl so adopters can wire it today.
228
+ The v2.3 runtime ships a working reference impl and the contract is
229
+ stable. The 600-run benchmark exercises `ai_correct_syntax` + `save`
230
+ under the V23_EDITOR_fix_monitor task.
227
231
  Available on any field via:
228
232
 
229
233
  ```js
@@ -232,151 +236,6 @@ NAC.edit_field('invoice.client_name');
232
236
  NAC.click_by_verb('myplugin', 'edit_field', { nac_id: 'invoice.client_name' });
233
237
  ```
234
238
 
235
- ### 5.1.4 Action payload + invoke (v2.3 preview)
236
-
237
- NAC v2.2 actions are click-and-go: an agent triggers `NAC.click(id)`
238
- or `NAC.click_by_verb(plugin, verb)` and the host runs whatever it
239
- does. This works for verb-and-state actions (`save`, `cancel`,
240
- `submit`, `delete`) but collapses when an action needs **data**
241
- from the agent -- `utter(text)`, `search(query)`,
242
- `send_message(body)`, `upload(file)`, `schedule(date)`,
243
- `translate(text, target_lang)`. The host has no way to receive
244
- the agent's payload via a synthetic click.
245
-
246
- v2.3 closes this gap. The contract is additive: click-style
247
- verbs continue to work unchanged.
248
-
249
- ```ts
250
- NAC.invoke(action_id: string, payload: object, opts?: { timeout?: number })
251
- : Promise<{ok: true, request_id: string, ack: object|null}>
252
-
253
- NAC.utter(action_id: string,
254
- opts: { text: string, lang?: string, voice?: string, metadata?: object })
255
- : Promise<{ok: true, request_id: string, ack: object|null}>
256
- ```
257
-
258
- `NAC.invoke` dispatches a `nac:action:requested` `CustomEvent`
259
- on the host element (bubbles to document) with:
260
-
261
- ```ts
262
- detail: {
263
- action_id: string, // canonical nac_id of the host element
264
- verb: string, // payload.verb || el's data-nac-action
265
- payload: object, // arbitrary, action-specific
266
- plugin: string|null,
267
- request_id: string, // correlation token assigned by the runtime
268
- ts: number, // Date.now()
269
- }
270
- ```
271
-
272
- The host listens for `nac:action:requested`, processes the
273
- payload, and emits `nac:action:succeeded` (or `nac:action:failed`)
274
- with the same `request_id` in the detail. The runtime correlates
275
- by `request_id` and resolves the agent's Promise.
276
-
277
- Default timeout is **30 seconds** (vs 5 s for click). Override
278
- with `opts.timeout`. On timeout, the Promise rejects with
279
- `NacError('timeout', ...)`. As with click, a timeout means real
280
- failure: callers MUST treat it as such unless they have side-
281
- effect proof via another channel.
282
-
283
- `NAC.utter(id, opts)` is the ergonomic shortcut for the most
284
- common payload-bearing verb. It is equivalent to:
285
-
286
- ```js
287
- NAC.invoke(id, { verb: 'utter', text: opts.text, lang: opts.lang });
288
- ```
289
-
290
- #### Manifest declaration
291
-
292
- A payload-bearing action declares its payload schema in the
293
- manifest entry for traceability and tooling:
294
-
295
- ```js
296
- NAC.register({
297
- plugin_slug: 'atlas_pro_ad',
298
- version: '2.1.0',
299
- nac_version: '2.3',
300
- elements: [
301
- { id: 'atlas_pro_ad.mic', role: 'action',
302
- actions: [
303
- { verb: 'listen' },
304
- { verb: 'utter',
305
- payload_schema: {
306
- text: { type: 'string', required: true, max: 4000 },
307
- lang: { type: 'string',
308
- enum: ['en','es','pt','fr','it','de','ja','zh','hi','ar'] }
309
- },
310
- label_i18n: { es:'Decir', en:'Utter', /* ... 10 locales */ } }
311
- ],
312
- label_i18n: { /* ... */ } }
313
- ]
314
- });
315
- ```
316
-
317
- `payload_schema` is informational in v2.3-alpha. Agents MAY
318
- validate before sending; runtimes MAY enforce it when
319
- `STRICT_VALIDATION` is `true`. Schemas are intentionally simple
320
- (JSON-Schema-shaped subset) so a runtime can validate without
321
- shipping a full JSON-Schema validator. v2.4 will formalise the
322
- schema grammar.
323
-
324
- #### Conformance: hosts that support invoke MUST
325
-
326
- 1. Declare `actions[].payload_schema` in the manifest entry.
327
- 2. Listen for `nac:action:requested` (or use a generic listener
328
- that filters by `detail.action_id` + `detail.verb`).
329
- 3. Emit `nac:action:succeeded` -- with `detail.request_id`
330
- echoed back -- after processing, or `nac:action:failed`
331
- (with `detail.error` code) on failure.
332
- 4. NEVER emit a `:succeeded` event with a `request_id` they did
333
- not receive (prevents cross-talk between concurrent invocations).
334
-
335
- Hosts that do NOT support invoke continue to operate normally
336
- under `NAC.click()` and `NAC.click_by_verb()`. Agents that call
337
- `NAC.invoke()` against a host without an `actions[].payload_schema`
338
- entry will still receive a `request_id` but the runtime cannot
339
- guarantee delivery; the timeout fires after 30 s.
340
-
341
- #### Why this matters
342
-
343
- The full agentic surface stops being "list of buttons" and
344
- becomes "list of buttons + structured inputs". A voice ad becomes
345
- NAC.invoke-able. A search bar becomes NAC.invoke-able. A
346
- file upload becomes NAC.invoke-able. Same protocol, same
347
- provenance, same ack semantics.
348
-
349
- The first reference adopter is **Atlas Pro** -- its
350
- `atlas_pro_ad.mic` element declares both `listen` (click-only,
351
- existing) and `utter` (payload-bearing) verbs. The same
352
- `/parse` + `/tts` conversational loop drives in either case;
353
- agents that have STT call `listen`, agents that have their own
354
- language model call `utter`.
355
-
356
- #### Forward modalities (anticipated, no spec change required)
357
-
358
- `invoke` is intentionally modality-agnostic so future input
359
- families plug in without breaking the contract:
360
-
361
- | Modality | Verb (sketch) | Payload (sketch) |
362
- |----------|-----------------------|--------------------------------------------------|
363
- | Text | `utter` | `{text, lang?}` |
364
- | Search | `search` | `{query, scope?, limit?}` |
365
- | File | `upload` | `{filename, mime, data_url \| stream_id}` |
366
- | Image | `analyze_image` | `{image_url \| data_url, prompt?}` |
367
- | Video | `analyze_stream` | `{stream_url, frame_window_ms?, return?}` |
368
- | Schedule | `schedule` | `{datetime, duration_min, attendees?}` |
369
- | Code | `apply_diff` | `{file_path, unified_diff}` |
370
- | Voice | `transcribe` | `{audio_url \| data_url, lang?}` |
371
-
372
- Each modality follows the same `nac:action:requested` ->
373
- `nac:action:succeeded` / `:failed` event protocol, the same
374
- `request_id` correlation, the same timeout semantics. The
375
- runtime stays small; the verb vocabulary grows by convention
376
- between hosts and agents. Ergonomic shortcuts (`NAC.utter`,
377
- `NAC.search`, `NAC.watch`, etc.) can be added later without
378
- re-spec because each is a thin wrapper over `invoke`.
379
-
380
239
  ### 5.1.2 Strict validation flag (v2.2)
381
240
 
382
241
  `NAC.STRICT_VALIDATION` (boolean, default `false` in v2.2). When
@@ -554,6 +413,66 @@ See `SECURITY.md` for the full threat model. Short version:
554
413
  - NAC3 does not protect against a malicious agent running with
555
414
  user-level access. Such an agent can do anything the user can.
556
415
 
416
+ ### 7.4 Plugin slug uniqueness (v2.4)
417
+
418
+ A `data-nac-plugin="<slug>"` attribute identifies a plugin
419
+ **instance** in the DOM. The runtime resolves
420
+ `(plugin, nac_id)` pairs against these scopes, so the host MUST
421
+ guarantee unambiguous resolution.
422
+
423
+ **Rules.**
424
+
425
+ 1. A given plugin slug MAY appear on more than one DOM root
426
+ simultaneously (a "list view + side panel" combo for the same
427
+ plugin family, a topbar mirror of an action that also lives in
428
+ the body, etc).
429
+ 2. **When the slug appears more than once, every root carrying it
430
+ MUST also carry a unique `data-nac-plugin-id` attribute.** The
431
+ pair `(data-nac-plugin, data-nac-plugin-id)` is the canonical
432
+ instance key.
433
+ 3. A single-root slug MAY omit `data-nac-plugin-id`; in that case
434
+ `(slug, null)` is the instance key.
435
+
436
+ **Runtime enforcement (v2.4).**
437
+
438
+ - The constructor `NAC.register(manifest)` rejects the call
439
+ synchronously with `NacError('duplicate_plugin_no_instance_id',
440
+ ...)` when the DOM already contains multiple roots with the
441
+ registered slug and any of them omits / duplicates
442
+ `data-nac-plugin-id`.
443
+ - A boot-time pass (`nac:dom-ready` listener installed by the
444
+ runtime) performs the same check across every `[data-nac-plugin]`
445
+ root in the document. On the first violation it dispatches
446
+ `nac:fatal` with `code='duplicate_plugin_no_instance_id'`,
447
+ inserts a visible red banner at the top of `<body>`, and
448
+ throws. The runtime then refuses every subsequent
449
+ `describe`/`click`/`click_by_verb`/`tab` call.
450
+ - `NAC.click_by_verb` resolves verbs against the manifest first.
451
+ When the manifest does not declare a top-level `actions[]` and
452
+ the runtime falls back to DOM scanning, the scan iterates
453
+ **every** `[data-nac-plugin="<slug>"]` root (not just the
454
+ first), matching the first descendant `[data-nac-action="<verb>"]`
455
+ it finds.
456
+ - `NAC.validate_global()` continues to emit
457
+ `duplicate_plugin_no_instance_id` as a structured finding for CI
458
+ pipelines that prefer non-fatal reporting.
459
+
460
+ **Migration from v2.3.**
461
+
462
+ The boot-time throw is enabled by default in v2.4. Authors who
463
+ need a one-release migration window can set
464
+ `NAC.HARD_DEDUP = false` before the runtime's
465
+ `DOMContentLoaded` listener fires. The flag is removed in v2.5.
466
+
467
+ **Why "throw" not "warn".**
468
+
469
+ Multiple roots sharing a slug without instance ids make every
470
+ `(plugin, nac_id)` lookup first-match-wins by document order.
471
+ That is non-deterministic across DOM rearrangements (drag-drop
472
+ sorts, conditional render order, framework re-mounts) and the
473
+ agent has no way to know which root won. v2.3 surfaced this only
474
+ through opt-in lint; v2.4 makes it a build-time gate.
475
+
557
476
  ---
558
477
 
559
478
  ## 8. Conformance levels
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // NAC CLI v2.3.0-alpha.2
2
+ // NAC CLI v2.2.1
3
3
  // Usage:
4
4
  // nac validate <url-or-dir> [--severity=error|warn|info]
5
5
  // nac --version
@@ -18,7 +18,7 @@ const args = process.argv.slice(2);
18
18
  const cmd = args[0];
19
19
 
20
20
  function showHelp() {
21
- console.log('NAC CLI v2.3.0-alpha.2');
21
+ console.log('NAC CLI v2.2.1');
22
22
  console.log('');
23
23
  console.log('Usage:');
24
24
  console.log(' nac validate <url-or-dir> [--severity=error|warn|info]');
@@ -27,7 +27,7 @@ function showHelp() {
27
27
  }
28
28
 
29
29
  function showVersion() {
30
- console.log('@nac3/runtime CLI 2.3.0-alpha.2 (Native Agent Contract v2.3)');
30
+ console.log('@nac3/runtime CLI 2.2.1 (Native Agent Contract v2.2)');
31
31
  }
32
32
 
33
33
  if (!cmd || cmd === '--help' || cmd === '-h') { showHelp(); process.exit(0); }