@sema-agent/settings-schema 31.1.0 → 32.0.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +753 -0
  2. package/README.md +79 -17
  3. package/conformance/VERSION +1 -1
  4. package/conformance/cases/c97-roles-own-proto-key-entry-dropped/expected.json +105 -0
  5. package/conformance/cases/c97-roles-own-proto-key-entry-dropped/input.json +26 -0
  6. package/conformance/cases/c97-roles-own-proto-key-entry-dropped/meta.json +6 -0
  7. package/dist/api/auth.d.ts +1 -1
  8. package/dist/api/feedback.d.ts +3 -3
  9. package/dist/api/feedback.js +3 -2
  10. package/dist/center-refs.d.ts +1 -1
  11. package/dist/center-refs.js +1 -1
  12. package/dist/config-fns.d.ts +14 -3
  13. package/dist/config-fns.js +49 -12
  14. package/dist/config-root-documents.js +1 -1
  15. package/dist/conformance/contract-adapter.js +18 -1
  16. package/dist/declared-capture.d.ts +1 -1
  17. package/dist/declared-capture.js +5 -1
  18. package/dist/device-lane-knobs.d.ts +57 -0
  19. package/dist/device-lane-knobs.js +127 -0
  20. package/dist/execution-lanes.d.ts +3 -1
  21. package/dist/execution-lanes.js +3 -1
  22. package/dist/fleet.d.ts +5 -5
  23. package/dist/fleet.js +4 -3
  24. package/dist/hooks-config.d.ts +47 -23
  25. package/dist/hooks-config.js +93 -134
  26. package/dist/hooks.d.ts +26 -22
  27. package/dist/hooks.js +17 -8
  28. package/dist/host-path.d.ts +9 -5
  29. package/dist/host-path.js +9 -20
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.js +2 -0
  32. package/dist/ip-address.d.ts +19 -0
  33. package/dist/ip-address.js +28 -0
  34. package/dist/loopback.d.ts +3 -11
  35. package/dist/loopback.js +11 -12
  36. package/dist/mcp-request-entry.js +4 -6
  37. package/dist/migration-receipt.d.ts +1 -1
  38. package/dist/migration-receipt.js +1 -1
  39. package/dist/one-time-migrations.d.ts +1 -1
  40. package/dist/one-time-migrations.js +257 -62
  41. package/dist/plain-json-object.d.ts +5 -8
  42. package/dist/plain-json-object.js +5 -8
  43. package/dist/record-seat.d.ts +35 -0
  44. package/dist/record-seat.js +97 -0
  45. package/dist/reserved-member-name.d.ts +8 -3
  46. package/dist/reserved-member-name.js +10 -3
  47. package/dist/retired-envs.js +10 -0
  48. package/dist/safety-merge-spec.d.ts +11 -3
  49. package/dist/safety-merge-spec.js +3 -2
  50. package/dist/types.d.ts +404 -112
  51. package/dist/types.js +132 -73
  52. package/docs/API-SURFACE.md +23 -6
  53. package/docs/CC-DIVERGENCE.md +11 -2
  54. package/docs/CONFORMANCE.md +2 -2
  55. package/docs/CONSUMER-INTEGRATION.md +157 -6
  56. package/llms-full.txt +31 -18
  57. package/llms.txt +11 -7
  58. package/package.json +7 -6
@@ -7,7 +7,7 @@
7
7
  * below ({@link HooksConfig}, {@link HookMatcherEntry}, {@link HookEntry} and the per-type five) are its PROJECTIONS — accepted ⇔ the
8
8
  * classifier says `"loaded"`, the parsed value is what it loaded, each issue is one of its pieces (code + coordinate). There is no second
9
9
  * statement of what a valid hook entry is: the per-type field table {@link HOOK_ENTRY_FIELDS} (exported) is what the entry TYPES are derived from at
10
- * compile time, and the classifier reads its closure-private projection of it ({@link HOOK_ENTRY_FIELDS_READ}, tied to the table's type — see there).
10
+ * compile time and what the classifier reads at run time (a registered name of its closure — see SELF-CONTAINED below).
11
11
  *
12
12
  * GRANULARITY = CC 2.1.296 (`cli296.js:237470`, `Yy` → `on`): four levels of piece — the `hooks` key, an event, a matcher, an entry.
13
13
  * · Outside the guard events, a bad piece is DROPPED alone (the rest of the document — its `permissions.deny`, its `env` — still applies).
@@ -32,10 +32,10 @@
32
32
  * (it is why the piece is rejected rather than dropped).
33
33
  *
34
34
  * CC 2.1.296 DIVERGENCES (the ones LISTED there are each in the stricter direction — a document CC would load may be rejected here, never the reverse): listed once,
35
- * in `docs/CC-DIVERGENCE.md` (section "hooks classifier", H1–H8) — the whole-subtree guard-sign scan is the first of them. The entry field table
35
+ * in `docs/CC-DIVERGENCE.md` (section "hooks classifier", H1–H9) — the whole-subtree guard-sign scan is the first of them. The entry field table
36
36
  * ({@link HOOK_ENTRY_FIELDS}) carries EVERY key CC's five hook-entry schemas carry (`cli309.js:252382`), so no key CC judges is stripped here unjudged. That is a statement about
37
- * which KEYS are read; the VALUE forms are the field kinds' (H7 lists where they judge more than CC does), with one known place where a kind judges LESS than CC: an `http` entry's `url`
38
- * is read as a non-empty string where CC checks URL syntax (not closed yet — see CHANGELOG 20.0.0, "已知限制").
37
+ * which KEYS are read; the VALUE forms are the field kinds' (H7 lists where they judge more than CC does; H9 is the `url` kind: CC trims the string before it checks URL syntax,
38
+ * this package checks it both as written and trimmed, and carries it as written).
39
39
  * One column is this contract's own, not CC's (H8): a `command` entry's `plugin` ({@link HookPluginContext}, 31.0.0) — CC reads a plugin hook's context from where the plugin sits, so its
40
40
  * entry schema has no such key and strips one written in a settings file; here the context travels on the entry, and a bad one is a bad piece like any other field's bad value.
41
41
  *
@@ -44,21 +44,28 @@
44
44
  * echoes no values and writes no sentences — the sentences are the consumers' (same law as `DROPPED_ENTRY_REASON_CODES`).
45
45
  *
46
46
  * SELF-CONTAINED. {@link classifyHooksConfig} and the module-private declarations it uses reference nothing outside themselves except their REGISTERED
47
- * names and JavaScript built-ins (no zod): a consumer that copies the function into its own bundle (client-core's generator does, with the private
48
- * declarations it uses) copies one closure and gives the copy's scope each registered name, bound to the runtime export it names — never a copy of it.
49
- * The registered names: {@link HOOK_EVENTS} (the event vocabulary), and the three judgements the `plugin` field needs, each read from its one owner
50
- * (31.0.0): {@link pluginOptionKeysProblem} (this module; it registers {@link pluginOptionEnvName} in turn), `isAbsoluteHostPath` (`./host-path`) and
51
- * `readCredentialRef` (the engine primitives package, the one reader of a credential reference). The closure carries no copy of any of them.
52
- * The hooks-classify test file (group ⑤) holds the registered set exactly; `test/hook-plugin-context-31.0.0.test.ts` S7 holds "no copy".
47
+ * names and JavaScript built-ins (no zod). ONE RULE for every fact the closure reads: it reads it from its one declaration, never from a copy of its own —
48
+ * a registered name is a name this module binds to that declaration (an export of this module, or an import). A consumer that copies the function into its
49
+ * own bundle (client-core's generator does, with the private declarations it uses) copies one closure and gives the copy's scope each registered name, bound
50
+ * to the declaration it names — never a copy of it. The registered names:
51
+ * · exports of this module — {@link HOOK_EVENTS} (the event vocabulary), {@link HOOK_ENTRY_FIELDS} (the field table), {@link HOOK_ON_FAILURE_WORDS} (the
52
+ * `onFailure` words), {@link pluginOptionKeysProblem} (it registers {@link pluginOptionEnvName} in turn) and {@link readHookPluginOptionRef} (the one reading of "is this
53
+ * option value a stored reference"; it registers `readCredentialRef` of the engine primitives package, the one reader of a credential reference, in turn — the closure itself
54
+ * does not call `readCredentialRef`);
55
+ * · imports — `isAbsoluteHostPath` (the engine primitives package: the one judge of "is this a host path"), and
56
+ * `jsonShapeOf` / `isPlainJsonObject` / `isJsonArray` (`./plain-json-object`, the package's one statement of "what shape is this value": a module of the
57
+ * package with no import of its own, not in the package's exports map — a consumer that copies the classifier copies that module once beside it).
58
+ * The built-ins it uses include `URL` (the `url` field kind asks the runtime's WHATWG URL parser) and `Symbol`.
59
+ * The hooks-classify test file (group ⑤) holds the registered set exactly and that the closure reads what it is given; `test/hook-plugin-context-31.0.0.test.ts`
60
+ * S7 holds "no copy" for the `plugin` column's three judgements.
53
61
  *
54
62
  * Input is a settings document as parsed from JSON. Values JSON cannot produce (accessors, class instances, cycles) are not part of the
55
63
  * contract; cycles are tolerated, a throwing accessor propagates.
56
64
  */
57
65
  import { z } from "zod";
58
- import { readCredentialRef } from "@sema-agent/primitives";
59
- import { isAbsoluteHostPath } from "./host-path.js";
66
+ import { isAbsoluteHostPath, readCredentialRef } from "@sema-agent/primitives";
60
67
  import { echoCallerText } from "./caller-text-echo.js";
61
- import { isPlainJsonObject } from "./plain-json-object.js";
68
+ import { isJsonArray, isPlainJsonObject, jsonShapeOf } from "./plain-json-object.js";
62
69
  import { buildQuotedIssue, fixed } from "./quoted-issue.js";
63
70
  import { deepFreeze } from "./deep-freeze.js";
64
71
  // ── event vocabulary ───────────────────────────────────────────────────────────────────────────────────────
@@ -123,7 +130,7 @@ export const HOOK_ENTRY_TYPES = deepFreeze(["command", "prompt", "agent", "http"
123
130
  * than 0 or 2, or printed JSON that is invalid or fails validation. `continue` (CC's default when the key is absent; this package does not fill it in — an absent key stays absent): the
124
131
  * failure is reported and the action goes ahead. `block`: the failure counts as exit code 2, so the action the event guards is blocked. Carried by `command` and `http` entries only.
125
132
  * CARRIED, not executed here: a consumer that reads `block` executes it or refuses it — ignoring it makes a guard that cannot start let the action through.
126
- * The classifier reads this set through a closure-private projection that the compiler ties to it in both directions.
133
+ * The classifier reads this set itself (a registered name of its closure).
127
134
  */
128
135
  export const HOOK_ON_FAILURE_WORDS = deepFreeze(["continue", "block"]);
129
136
  /**
@@ -135,6 +142,24 @@ export const HOOK_ON_FAILURE_WORDS = deepFreeze(["continue", "block"]);
135
142
  * `http` entries. CARRIED, not executed here.
136
143
  */
137
144
  export const HOOK_CLOUD_WORDS = deepFreeze(["device", "skip"]);
145
+ /**
146
+ * THE one reading of "is this value a stored reference this contract takes as a plugin option value": the answer is the reference, or `undefined` — nothing else, and no value makes it throw.
147
+ * The primitives' `readCredentialRef` reads the value (it is the one reader of a credential reference: this package carries no second reading of its own), and of what it reads only a
148
+ * `vault` reference is taken ({@link HookPluginOptionRef}: an `env`, `handle` or `assertion` reference is never taken from a hook entry). A taken value answers a FRESH
149
+ * `{ kind: "vault", entry }` built from that reading — it shares nothing with the value, and it is the copy a loaded entry carries. `undefined` is "not read": the value is not a credential
150
+ * reference, is a reference of another kind, or is a bad `vault` one (an accessor, a member it does not have, bad entry text); there is no finer answer. A string is not a reference —
151
+ * it is the option's own value, and the classifier takes a string before it asks this.
152
+ * ONE GATE for every party that puts this one question to one value: the classifier (it asks it of every option value that is not a string), a sender that decides whether an option value
153
+ * goes out as a reference, a terminal or a server executor that decides whether a value is a reference to resolve. None of them writes the `vault` kind out again or calls the primitives'
154
+ * reader for it — a second statement of "which references this contract takes" is a second reader. FORM ONLY, as {@link HookPluginOptionRef}: who may resolve the reference, and
155
+ * whether anything does, are the callers'.
156
+ * Its one REGISTERED name is the primitives' `readCredentialRef` (no other free name but JavaScript built-ins): a consumer's generator may copy it whole and give the copy that name, bound
157
+ * to the primitives' export — never to a copy of it.
158
+ */
159
+ export function readHookPluginOptionRef(value) {
160
+ const read = readCredentialRef(value);
161
+ return read.ok && read.ref.kind === "vault" ? { kind: "vault", entry: read.ref.entry } : undefined;
162
+ }
138
163
  /**
139
164
  * The first problem with a list of plugin option keys, in key order, or `undefined` when there is none: a key that is not an identifier (`[A-Za-z_][A-Za-z0-9_]*`) ⇒ `not_identifier`;
140
165
  * a key that becomes the same environment variable as an earlier key ({@link pluginOptionEnvName} — for identifiers that is "equal once upper-cased") ⇒ `collision` with the two keys
@@ -350,20 +375,14 @@ export function measureHookPluginContext(plugin) {
350
375
  }
351
376
  /** `shell` values: 'bash' = the user's $SHELL family; 'powershell' = pwsh. Default bash. */
352
377
  const HOOK_SHELLS = ["bash", "powershell"];
353
- /** The classifier's reading of {@link HOOK_ON_FAILURE_WORDS}. The classifier is copied as source by consumers' generators, so its closure reads no exported name but its registered ones
354
- * ({@link HOOK_EVENTS} and the three judgements of the `plugin` column — see the file header): this record is the closure-private projection of the exported set, and the compiler ties the two in both directions — a word added to the set without a row
355
- * here, or a row here that the set does not hold, is a compile error. */
356
- const HOOK_ON_FAILURE_ACCEPTED = { continue: true, block: true };
357
378
  /** Fields every entry type takes: `if` = permission-rule syntax (e.g. "Bash(git *)") evaluated against tool_name/tool_input before the hook
358
379
  * runs (tool events only; shell superset field, CC-compatible); `timeout` = seconds for this entry (default `DEFAULT_HOOK_TIMEOUT_SECONDS`);
359
- * `statusMessage` = spinner status message; `once` = run once, then remove. Read by the exported table below only — the classifier's own
360
- * projection spells these four out per row (it is a closure, see {@link HOOK_ENTRY_FIELDS_READ}). */
380
+ * `statusMessage` = spinner status message; `once` = run once, then remove. Spread into each row of the table below. */
361
381
  const HOOK_ENTRY_COMMON_FIELDS = { if: "string?", timeout: "seconds?", statusMessage: "string?", once: "boolean?" };
362
382
  /**
363
383
  * THE field table of a hook entry, per type — exported, deeply frozen (a consumer that projects "which fields does an entry carry" reads this one object and
364
384
  * cannot change what the others read), and what the entry types below are derived from. Field order = the order a loaded entry's keys come out in.
365
- * The classifier does not read THIS object: it is copied as source by consumers' generators, and a closure that read an exported declaration — or a private one
366
- * that an export expression reaches — would not be copyable. It reads {@link HOOK_ENTRY_FIELDS_READ}, annotated with this table's type.
385
+ * The classifier reads THIS object (a registered name of its closure — see the file header), so what the table says is what is judged: there is no second statement of it.
367
386
  * · command: `args` = exec form (CC `cli309.js:252382`: when present — `[]` included — `command` is an executable spawned directly with these arguments, no shell; the mere
368
387
  * presence of `args` is the switch), `shell` (see above), `async` = run in background without blocking, `asyncRewake` = background + wake the model on exit 2,
369
388
  * `onFailure` (see {@link HOOK_ON_FAILURE_WORDS}), and — CC marks them `@internal` — `rewakeMessage` (the prefix of the system-reminder the model gets when an `asyncRewake` hook exits
@@ -372,7 +391,7 @@ const HOOK_ENTRY_COMMON_FIELDS = { if: "string?", timeout: "seconds?", statusMes
372
391
  * (the plugin context: {@link HookPluginContext}; a bad one is a bad piece);
373
392
  * · prompt / agent: `prompt` ($ARGUMENTS = the hook input JSON), `model`; prompt only: `continueOnBlock` = the `continue` value of the `decision: "block"` the entry produces when its
374
393
  * verdict is not ok (CC default false: the turn ends);
375
- * · http: `url`, `headers` (values may reference $NAMEs listed in `allowedEnvVars` — env-NAME interpolation only, the config never carries a
394
+ * · http: `url` (an absolute URL — the `url` kind), `headers` (values may reference $NAMEs listed in `allowedEnvVars` — env-NAME interpolation only, the config never carries a
376
395
  * secret value; `interpolateHookEnvVars` is the one reading), `allowedEnvVars`, `onFailure` (the other schema CC gives it to), `cloud` (the other schema CC gives it to);
377
396
  * · mcp_tool: `server` (an already-configured MCP server's name), `tool`, `input` (the tool's arguments; string values may interpolate
378
397
  * `${path}` from the hook input JSON — CC 2.1.296 semantics, the runner's business).
@@ -399,35 +418,9 @@ export const HOOK_ENTRY_FIELDS = deepFreeze({
399
418
  },
400
419
  prompt: { prompt: "text", model: "string?", ...HOOK_ENTRY_COMMON_FIELDS, continueOnBlock: "boolean?" },
401
420
  agent: { prompt: "text", model: "string?", ...HOOK_ENTRY_COMMON_FIELDS },
402
- http: { url: "text", headers: "stringRecord?", allowedEnvVars: "stringList?", onFailure: "onFailure?", ...HOOK_ENTRY_COMMON_FIELDS, cloud: "any?" },
421
+ http: { url: "url", headers: "stringRecord?", allowedEnvVars: "stringList?", onFailure: "onFailure?", ...HOOK_ENTRY_COMMON_FIELDS, cloud: "any?" },
403
422
  mcp_tool: { server: "string", tool: "string", input: "record?", ...HOOK_ENTRY_COMMON_FIELDS },
404
423
  });
405
- /** The classifier's reading of {@link HOOK_ENTRY_FIELDS}. Same reason and same form as {@link HOOK_ON_FAILURE_ACCEPTED}: the classifier closure cannot read the exported table, so this
406
- * is its closure-private projection, spelled out in full (no shared piece with the exported table) and annotated with the exported table's type — a row, a field or a field kind that
407
- * the two do not agree on is a compile error in one direction (a missing one) or the other (an extra one). the hook-entry-fields pin under `test/` holds the run-time half: what the
408
- * classifier accepts, requires and orders per type is what the exported table says. */
409
- const HOOK_ENTRY_FIELDS_READ = {
410
- command: {
411
- command: "text",
412
- args: "argv?",
413
- shell: "shell?",
414
- async: "boolean?",
415
- asyncRewake: "boolean?",
416
- onFailure: "onFailure?",
417
- if: "string?",
418
- timeout: "seconds?",
419
- statusMessage: "string?",
420
- once: "boolean?",
421
- rewakeMessage: "nonEmpty?",
422
- rewakeSummary: "nonEmpty?",
423
- cloud: "any?",
424
- plugin: "plugin?",
425
- },
426
- prompt: { prompt: "text", model: "string?", if: "string?", timeout: "seconds?", statusMessage: "string?", once: "boolean?", continueOnBlock: "boolean?" },
427
- agent: { prompt: "text", model: "string?", if: "string?", timeout: "seconds?", statusMessage: "string?", once: "boolean?" },
428
- http: { url: "text", headers: "stringRecord?", allowedEnvVars: "stringList?", onFailure: "onFailure?", if: "string?", timeout: "seconds?", statusMessage: "string?", once: "boolean?", cloud: "any?" },
429
- mcp_tool: { server: "string", tool: "string", input: "record?", if: "string?", timeout: "seconds?", statusMessage: "string?", once: "boolean?" },
430
- };
431
424
  // ── classification vocabulary ──────────────────────────────────────────────────────────────────────────────
432
425
  /** What happened to a document's hooks: all loaded / loaded with pieces dropped / the document rejected (nothing in it applies). */
433
426
  export const HOOKS_CLASSIFICATION_OUTCOMES = deepFreeze(["loaded", "loaded-partial", "rejected"]);
@@ -457,34 +450,10 @@ export const HOOKS_REJECTION_CODES = deepFreeze([
457
450
  "guard-matcher-invalid",
458
451
  "guard-entry-invalid",
459
452
  ]);
460
- /** The value's shape — six words: `plain` is a JSON object (not null, not an array, prototype null or a prototype whose own prototype is null: any realm's `Object.prototype`),
461
- * `uninspectable` is a value whose shape cannot be read at all (a proxy that has been revoked, a throwing `getPrototypeOf` trap). This function IS `./plain-json-object`'s `jsonShapeOf`, character for
462
- * character: the classifier is copied as source by consumers' generators, so its closure cannot import — the package has this one second copy, and the test is what keeps it from drifting. */
463
- function hookShapeOf(v) {
464
- try {
465
- if (v === null)
466
- return "null";
467
- if (Array.isArray(v))
468
- return "array";
469
- if (typeof v === "function")
470
- return "non_plain_object";
471
- if (typeof v !== "object")
472
- return "primitive";
473
- const proto = Object.getPrototypeOf(v);
474
- return proto === null || Object.getPrototypeOf(proto) === null ? "plain" : "non_plain_object";
475
- }
476
- catch {
477
- return "uninspectable"; // 读形状就抛(已撤销的 Proxy 连 `Array.isArray` 都抛、`getPrototypeOf` 陷阱抛):不是「不朴素」,是读不出 —— 读者按最严处置
478
- }
479
- }
480
- /** `./plain-json-object` 的 `isPlainJsonObject`,调各自的形状分类核后逐字同文(闭包里不能 import)。 */
481
- function hookIsRecord(v) {
482
- const shape = hookShapeOf(v);
483
- return shape === "plain";
484
- }
453
+ // The value's shape is `./plain-json-object`'s to say (`jsonShapeOf`, six words; `isPlainJsonObject` = its `plain` word; `isJsonArray` = the total `Array.isArray`) — registered names, read from there.
485
454
  /** Is the value object-like — anything but null / a primitive (arrays, functions and values whose shape cannot be read count). The shape is asked first, never a `typeof` split. */
486
455
  function hookIsObjectLike(v) {
487
- const shape = hookShapeOf(v);
456
+ const shape = jsonShapeOf(v);
488
457
  switch (shape) {
489
458
  case "null":
490
459
  case "primitive":
@@ -500,43 +469,25 @@ function hookIsObjectLike(v) {
500
469
  }
501
470
  }
502
471
  }
503
- /** `./plain-json-object` 的 `isJsonArray`,逐字同文(闭包里不能 import):`Array.isArray` 的总版 —— 已撤销的 Proxy 读不出 ⇒ 不是数组,不抛。 */
504
- function hookIsArray(v) {
505
- try {
506
- return Array.isArray(v);
507
- }
508
- catch {
509
- return false; // 已撤销的 Proxy:读不出 ⇒ 不是数组
510
- }
511
- }
512
- /** `Symbol.iterator` WITHOUT the `Symbol` free name: the classifier closure is copied by consumers' generators whose registered built-ins do not include `Symbol` (a new built-in word
513
- * in the closure is a change they must follow), so the well-known symbol is taken from the one place every realm keeps it — `Array.prototype` is iterable by it. Read once at load;
514
- * a process in which `Array.prototype` has lost its iterator cannot say which objects hold content off their own keys, so the module refuses to load rather than answer "none do". */
515
- const HOOK_ITERATOR_SYMBOL = (() => {
516
- const found = Object.getOwnPropertySymbols(Array.prototype).find((s) => s.description === "Symbol.iterator");
517
- if (found === undefined)
518
- throw new Error("hooks classifier: Array.prototype has no Symbol.iterator");
519
- return found;
520
- })();
521
472
  /** The first own key of `node` (in key order) that names a guard event with a value other than null / undefined / `[]` (CC `ei`). */
522
473
  function hookGuardKeyOf(node) {
523
474
  for (const key of Object.keys(node)) {
524
475
  if (!HOOK_GUARD_EVENTS.includes(key))
525
476
  continue;
526
477
  const value = node[key];
527
- if (value !== null && value !== undefined && !(hookIsArray(value) && value.length === 0))
478
+ if (value !== null && value !== undefined && !(isJsonArray(value) && value.length === 0))
528
479
  return key;
529
480
  }
530
481
  return undefined;
531
482
  }
532
483
  /** Matcher-shaped: `hooks` is a non-empty array, or a single object with `matcher` present beside it or a string `type` inside it. */
533
484
  function hookLooksLikeMatcher(value) {
534
- if (!hookIsRecord(value))
485
+ if (!isPlainJsonObject(value))
535
486
  return false;
536
487
  const inner = Object.hasOwn(value, "hooks") ? value.hooks : undefined;
537
- if (hookIsArray(inner))
488
+ if (isJsonArray(inner))
538
489
  return inner.length > 0;
539
- return hookIsRecord(inner) && (Object.hasOwn(value, "matcher") || (Object.hasOwn(inner, "type") && typeof inner.type === "string"));
490
+ return isPlainJsonObject(inner) && (Object.hasOwn(value, "matcher") || (Object.hasOwn(inner, "type") && typeof inner.type === "string"));
540
491
  }
541
492
  /**
542
493
  * The coordinate of the first guard sign in `root`'s subtree, or undefined: each object answers for itself before its members are searched (its own
@@ -560,7 +511,7 @@ function hookGuardSignIn(root, rootPath, place) {
560
511
  const [node, frame, at] = pending.pop();
561
512
  // the shape is asked BEFORE any `typeof` split: a node whose shape cannot be read — a proxy that has been revoked, of a function target included — cannot be shown free of guard signs
562
513
  // ⇒ reported as a sign at its own coordinate (fail-closed: the document is rejected); no `typeof` gate of the classifier's own stands in front of the seat
563
- const shape = hookShapeOf(node);
514
+ const shape = jsonShapeOf(node);
564
515
  let isList = false;
565
516
  switch (shape) {
566
517
  case "null":
@@ -577,7 +528,7 @@ function hookGuardSignIn(root, rootPath, place) {
577
528
  // an object whose content is supplied by the iteration protocol (a Map, a Set, a generator …) holds that content OFF its own keys: the own-key search below
578
529
  // would find nothing and a guard held inside would vanish with the dropped piece. It cannot be shown free of guard signs ⇒ a sign at its own coordinate (same arm as
579
530
  // "uninspectable"). Every other non-plain object (a class instance, a Date, a function) keeps what it holds on its own keys, searched below.
580
- if (HOOK_ITERATOR_SYMBOL in node)
531
+ if (Symbol.iterator in node)
581
532
  return pathTo(frame, []);
582
533
  break;
583
534
  default: {
@@ -618,11 +569,11 @@ function hookSignKeyOf(at, sign) {
618
569
  }
619
570
  /** The `plugin` field kind: a {@link HookPluginContext} → a fresh copy (member order `name`, `root`, `dataDir`, `options`; absent members stay absent), or `undefined` when the value is
620
571
  * not one — the rules are the ones written on that type, members read once each. The three judgements it needs are their owners', called through the closure's registered names
621
- * (no copy here): `isAbsoluteHostPath` for `root` / `dataDir`, {@link pluginOptionKeysProblem} for the option keys, the primitives' `readCredentialRef` for a value that is not a
622
- * string — accepted when it reads a `vault` reference (an accessor, a record with another member, another kind or bad text are refused there); what is carried is a fresh
623
- * `{ kind: "vault", entry }` built from that reading. */
572
+ * (no copy here): `isAbsoluteHostPath` for `root` / `dataDir`, {@link pluginOptionKeysProblem} for the option keys, {@link readHookPluginOptionRef} for a value that is not a
573
+ * string — accepted when it answers a reference (an accessor, a record with another member, another kind or bad text are refused there); what is carried is the fresh reference it
574
+ * answers. */
624
575
  function hookPluginRead(value) {
625
- if (!hookIsRecord(value))
576
+ if (!isPlainJsonObject(value))
626
577
  return undefined;
627
578
  let name;
628
579
  let root;
@@ -650,7 +601,7 @@ function hookPluginRead(value) {
650
601
  }
651
602
  if (options === undefined)
652
603
  return context;
653
- if (!hookIsRecord(options))
604
+ if (!isPlainJsonObject(options))
654
605
  return undefined;
655
606
  const entries = Object.entries(options);
656
607
  if (pluginOptionKeysProblem(entries.map(([key]) => key)) !== undefined)
@@ -663,10 +614,10 @@ function hookPluginRead(value) {
663
614
  carried.push([key, v]);
664
615
  continue;
665
616
  }
666
- const read = readCredentialRef(v);
667
- if (!read.ok || read.ref.kind !== "vault")
617
+ const ref = readHookPluginOptionRef(v);
618
+ if (ref === undefined)
668
619
  return undefined;
669
- carried.push([key, { kind: "vault", entry: read.ref.entry }]);
620
+ carried.push([key, ref]);
670
621
  }
671
622
  return { ...context, options: Object.fromEntries(carried) };
672
623
  }
@@ -677,6 +628,12 @@ function hookFieldRead(base, value) {
677
628
  switch (base) {
678
629
  case "text":
679
630
  return typeof value === "string" && value.length > 0 && !value.includes("\0") ? { carried: value } : undefined;
631
+ case "url": {
632
+ // THE judge of the `url` kind (one place): a `text` value the WHATWG URL parser reads as an absolute URL as written (that is what is carried) AND with its ends
633
+ // trimmed (that is how the reference implementation reads it — so a url taken here is one the reference takes too); nothing is rewritten
634
+ const text = hookFieldRead("text", value);
635
+ return text !== undefined && URL.canParse(text.carried) && URL.canParse(text.carried.trim()) ? text : undefined;
636
+ }
680
637
  case "nonEmpty":
681
638
  return typeof value === "string" && value.length > 0 ? { carried: value } : undefined;
682
639
  case "string":
@@ -688,16 +645,16 @@ function hookFieldRead(base, value) {
688
645
  case "seconds":
689
646
  return typeof value === "number" && Number.isFinite(value) && value > 0 ? { carried: value } : undefined;
690
647
  case "stringRecord":
691
- return hookIsRecord(value) && Object.values(value).every((v) => typeof v === "string") ? { carried: Object.fromEntries(Object.entries(value)) } : undefined;
648
+ return isPlainJsonObject(value) && Object.values(value).every((v) => typeof v === "string") ? { carried: Object.fromEntries(Object.entries(value)) } : undefined;
692
649
  case "stringList":
693
- if (!hookIsArray(value))
650
+ if (!isJsonArray(value))
694
651
  return undefined;
695
652
  for (let i = 0; i < value.length; i++)
696
653
  if (typeof value[i] !== "string")
697
654
  return undefined;
698
655
  return { carried: value.slice() };
699
656
  case "argv":
700
- if (!hookIsArray(value))
657
+ if (!isJsonArray(value))
701
658
  return undefined;
702
659
  for (let i = 0; i < value.length; i++) {
703
660
  const arg = value[i];
@@ -706,11 +663,11 @@ function hookFieldRead(base, value) {
706
663
  }
707
664
  return { carried: value.slice() };
708
665
  case "onFailure":
709
- return typeof value === "string" && Object.hasOwn(HOOK_ON_FAILURE_ACCEPTED, value) ? { carried: value } : undefined;
666
+ return typeof value === "string" && HOOK_ON_FAILURE_WORDS.includes(value) ? { carried: value } : undefined;
710
667
  case "any":
711
- return { carried: hookIsArray(value) ? value.slice() : hookIsRecord(value) ? Object.fromEntries(Object.entries(value)) : value };
668
+ return { carried: isJsonArray(value) ? value.slice() : isPlainJsonObject(value) ? Object.fromEntries(Object.entries(value)) : value };
712
669
  case "record":
713
- return hookIsRecord(value) ? { carried: Object.fromEntries(Object.entries(value)) } : undefined;
670
+ return isPlainJsonObject(value) ? { carried: Object.fromEntries(Object.entries(value)) } : undefined;
714
671
  case "plugin": {
715
672
  const plugin = hookPluginRead(value);
716
673
  return plugin === undefined ? undefined : { carried: plugin };
@@ -723,12 +680,12 @@ function hookFieldRead(base, value) {
723
680
  }
724
681
  /** One entry → `{ entry }` (its contract fields, in table order, each as {@link hookFieldRead} carries it) or `{ field? }` (the first field that is wrong). */
725
682
  function hookEntryRead(entry) {
726
- if (!hookIsRecord(entry))
683
+ if (!isPlainJsonObject(entry))
727
684
  return {};
728
685
  const type = Object.hasOwn(entry, "type") ? entry.type : undefined;
729
- if (typeof type !== "string" || !Object.hasOwn(HOOK_ENTRY_FIELDS_READ, type))
686
+ if (typeof type !== "string" || !Object.hasOwn(HOOK_ENTRY_FIELDS, type))
730
687
  return { field: "type" };
731
- const fields = HOOK_ENTRY_FIELDS_READ[type];
688
+ const fields = HOOK_ENTRY_FIELDS[type];
732
689
  const out = { type };
733
690
  for (const field of Object.keys(fields)) {
734
691
  const kind = fields[field];
@@ -748,7 +705,7 @@ function hookEntryRead(entry) {
748
705
  }
749
706
  /** One matcher (at `at`, under a guard event or not) → what loads of it, reporting its bad pieces / signs into the two sinks. */
750
707
  function hookMatcherRead(matcher, at, guardEvent, reject, drop) {
751
- if (!hookIsRecord(matcher)) {
708
+ if (!isPlainJsonObject(matcher)) {
752
709
  if (guardEvent || hookGuardSignIn(matcher, at, "matcher") !== undefined)
753
710
  reject("guard-matcher-invalid", at);
754
711
  else
@@ -760,18 +717,18 @@ function hookMatcherRead(matcher, at, guardEvent, reject, drop) {
760
717
  // the rejection's `field` is the matcher's own guard-event key if it has one, else the first member (document order) whose subtree holds a sign —
761
718
  // the order hookGuardSignIn reports
762
719
  const signField = hookGuardKeyOf(matcher) ??
763
- Object.keys(matcher).find((key) => !(key === "hooks" && hookIsArray(entries)) && hookGuardSignIn(matcher[key], [...at, key], "other") !== undefined);
720
+ Object.keys(matcher).find((key) => !(key === "hooks" && isJsonArray(entries)) && hookGuardSignIn(matcher[key], [...at, key], "other") !== undefined);
764
721
  if (signField !== undefined) {
765
722
  reject("guard-matcher-invalid", at, signField);
766
723
  return undefined;
767
724
  }
768
725
  const entrySigns = [];
769
- if (hookIsArray(entries))
726
+ if (isJsonArray(entries))
770
727
  for (let j = 0; j < entries.length; j++)
771
728
  entrySigns.push(hookGuardSignIn(entries[j], [...at, "hooks", j], "other"));
772
729
  const name = Object.hasOwn(matcher, "matcher") ? matcher.matcher : undefined;
773
- const badField = name !== undefined && typeof name !== "string" ? "matcher" : !hookIsArray(entries) ? "hooks" : undefined;
774
- if (badField !== undefined || !hookIsArray(entries)) {
730
+ const badField = name !== undefined && typeof name !== "string" ? "matcher" : !isJsonArray(entries) ? "hooks" : undefined;
731
+ if (badField !== undefined || !isJsonArray(entries)) {
775
732
  if (guardEvent || entrySigns.some((sign) => sign !== undefined))
776
733
  reject("guard-matcher-invalid", at, badField);
777
734
  else
@@ -783,7 +740,7 @@ function hookMatcherRead(matcher, at, guardEvent, reject, drop) {
783
740
  const where = [...at, "hooks", j];
784
741
  const sign = entrySigns[j];
785
742
  if (sign !== undefined) {
786
- reject("guard-entry-invalid", where, hookIsRecord(entries[j]) ? hookSignKeyOf(where, sign) : undefined);
743
+ reject("guard-entry-invalid", where, isPlainJsonObject(entries[j]) ? hookSignKeyOf(where, sign) : undefined);
787
744
  continue;
788
745
  }
789
746
  const read = hookEntryRead(entries[j]);
@@ -798,8 +755,8 @@ function hookMatcherRead(matcher, at, guardEvent, reject, drop) {
798
755
  }
799
756
  /** The `hooks` value → what loads of it (undefined when nothing does), reporting its bad pieces / signs into the two sinks. */
800
757
  function hookBlockRead(hooks, reject, drop) {
801
- if (!hookIsRecord(hooks)) {
802
- if (hookIsArray(hooks) && hooks.some(hookIsObjectLike))
758
+ if (!isPlainJsonObject(hooks)) {
759
+ if (isJsonArray(hooks) && hooks.some(hookIsObjectLike))
803
760
  reject("hooks-is-matcher", ["hooks"]);
804
761
  // an object that is not a readable block (a class instance, a proxy that cannot be inspected) holding — or possibly holding — a guard sign: reject, never drop it (a dropped guard silently disappears)
805
762
  else if (hookGuardSignIn(hooks, ["hooks"], "other") !== undefined)
@@ -817,14 +774,14 @@ function hookBlockRead(hooks, reject, drop) {
817
774
  const value = hooks[event];
818
775
  const at = ["hooks", event];
819
776
  if (!HOOK_EVENTS.includes(event)) {
820
- if (hookGuardSignIn(value, at, hookIsArray(value) ? "matcherList" : "other") !== undefined)
777
+ if (hookGuardSignIn(value, at, isJsonArray(value) ? "matcherList" : "other") !== undefined)
821
778
  reject("guard-under-unknown-event", at);
822
779
  else
823
780
  drop("unknown-event", at);
824
781
  continue;
825
782
  }
826
783
  const guardEvent = HOOK_GUARD_EVENTS.includes(event);
827
- if (!hookIsArray(value)) {
784
+ if (!isJsonArray(value)) {
828
785
  if ((guardEvent && value !== null) || hookGuardSignIn(value, at, "other") !== undefined)
829
786
  reject("guard-event-not-array", at);
830
787
  else
@@ -847,11 +804,13 @@ function hookBlockRead(hooks, reject, drop) {
847
804
  * Rejections and drops are listed in document order.
848
805
  *
849
806
  * COPYING THIS FUNCTION (client-core's generator, or any consumer that emits it as source): its free names besides JavaScript built-ins are its
850
- * REGISTERED names — {@link HOOK_EVENTS}, {@link pluginOptionKeysProblem} and `isAbsoluteHostPath` (this package's runtime exports) and `readCredentialRef`
851
- * (the runtime export of `@sema-agent/primitives`, this package's runtime dependency). The copy's scope must be GIVEN each of them, bound to the export
852
- * it names (the generator injects each as a registered value, it does not re-declare it; `pluginOptionKeysProblem` in turn registers {@link pluginOptionEnvName}).
853
- * Never paste a literal event list or a copied judgement into the generated text: a second event table is one the upstream drift gate (it watches
854
- * `HOOK_EVENTS`) cannot see and goes stale the first time CC adds an event; a copied judgement is a second reading that drifts from its owner unseen.
807
+ * REGISTERED names (the file header lists them: five exports of this module — `readHookPluginOptionRef` among them, not the primitives' `readCredentialRef`, which it registers
808
+ * itself — the primitives' `isAbsoluteHostPath`, and the three shape readings of `./plain-json-object`). The copy's scope must be GIVEN each of them, bound to the declaration it names (the generator
809
+ * injects each as a registered value, it does not re-declare it; `pluginOptionKeysProblem` in turn registers {@link pluginOptionEnvName}, and `readHookPluginOptionRef` registers
810
+ * `readCredentialRef`).
811
+ * Never paste a literal event list, a literal field table or a copied judgement into the generated text: a second event table is one the upstream drift
812
+ * gate (it watches `HOOK_EVENTS`) cannot see and goes stale the first time CC adds an event; a second field table or word list is a second statement of
813
+ * what an entry may carry; a copied judgement is a second reading that drifts from its owner unseen.
855
814
  * The module-private declarations the closure uses (the `HOOK_*` constants and `hook*` helpers below the classifier line) are copied with it;
856
815
  * the hooks-classify test file (group ⑤) pins that the free names are exactly these.
857
816
  */
@@ -874,7 +833,7 @@ function hookClassify(settingsDoc) {
874
833
  dropped.push(field === undefined ? { code, path } : { code, path, field });
875
834
  };
876
835
  let hooks;
877
- if (hookIsRecord(settingsDoc)) {
836
+ if (isPlainJsonObject(settingsDoc)) {
878
837
  const doc = settingsDoc;
879
838
  for (const key of Object.keys(doc)) {
880
839
  const value = doc[key];
@@ -885,7 +844,7 @@ function hookClassify(settingsDoc) {
885
844
  // the document itself written as a matcher: its top-level `matcher` key is the evidence, reported at that key's place
886
845
  const sign = key === "matcher" && hookLooksLikeMatcher(doc)
887
846
  ? [key]
888
- : HOOK_GUARD_EVENTS.includes(key) && value !== null && value !== undefined && !(hookIsArray(value) && value.length === 0)
847
+ : HOOK_GUARD_EVENTS.includes(key) && value !== null && value !== undefined && !(isJsonArray(value) && value.length === 0)
889
848
  ? [key]
890
849
  : hookGuardSignIn(value, [key], "other");
891
850
  if (sign !== undefined)