@sema-agent/settings-schema 31.1.0 → 33.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 (68) hide show
  1. package/CHANGELOG.md +917 -0
  2. package/README.md +103 -19
  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/cli.d.ts +4 -1
  13. package/dist/cli.js +8 -3
  14. package/dist/config-dir-migration.d.ts +17 -1
  15. package/dist/config-dir-migration.js +89 -31
  16. package/dist/config-fns.d.ts +31 -4
  17. package/dist/config-fns.js +180 -24
  18. package/dist/config-root-documents.js +1 -1
  19. package/dist/conformance/contract-adapter.js +18 -1
  20. package/dist/conformance/warnings.d.ts +1 -1
  21. package/dist/conformance/warnings.js +8 -2
  22. package/dist/declared-capture.d.ts +1 -1
  23. package/dist/declared-capture.js +5 -1
  24. package/dist/device-lane-knobs.d.ts +57 -0
  25. package/dist/device-lane-knobs.js +127 -0
  26. package/dist/execution-lanes.d.ts +3 -1
  27. package/dist/execution-lanes.js +3 -1
  28. package/dist/fleet.d.ts +5 -5
  29. package/dist/fleet.js +4 -3
  30. package/dist/hooks-config.d.ts +47 -23
  31. package/dist/hooks-config.js +93 -134
  32. package/dist/hooks.d.ts +26 -22
  33. package/dist/hooks.js +17 -8
  34. package/dist/host-path.d.ts +9 -5
  35. package/dist/host-path.js +9 -20
  36. package/dist/index.d.ts +2 -0
  37. package/dist/index.js +2 -0
  38. package/dist/ip-address.d.ts +19 -0
  39. package/dist/ip-address.js +28 -0
  40. package/dist/loopback.d.ts +3 -11
  41. package/dist/loopback.js +11 -12
  42. package/dist/mcp-request-entry.js +4 -6
  43. package/dist/migration-receipt.d.ts +1 -1
  44. package/dist/migration-receipt.js +1 -1
  45. package/dist/one-time-migrations.d.ts +1 -1
  46. package/dist/one-time-migrations.js +257 -62
  47. package/dist/plain-json-object.d.ts +5 -8
  48. package/dist/plain-json-object.js +5 -8
  49. package/dist/read-sentences.d.ts +66 -0
  50. package/dist/read-sentences.js +85 -0
  51. package/dist/record-seat.d.ts +35 -0
  52. package/dist/record-seat.js +97 -0
  53. package/dist/reserved-member-name.d.ts +8 -3
  54. package/dist/reserved-member-name.js +10 -3
  55. package/dist/retired-envs.js +10 -0
  56. package/dist/retired-form.d.ts +2 -0
  57. package/dist/retired-form.js +4 -0
  58. package/dist/safety-merge-spec.d.ts +11 -3
  59. package/dist/safety-merge-spec.js +3 -2
  60. package/dist/types.d.ts +405 -113
  61. package/dist/types.js +135 -76
  62. package/docs/API-SURFACE.md +25 -6
  63. package/docs/CC-DIVERGENCE.md +11 -2
  64. package/docs/CONFORMANCE.md +4 -4
  65. package/docs/CONSUMER-INTEGRATION.md +185 -6
  66. package/llms-full.txt +35 -20
  67. package/llms.txt +15 -8
  68. package/package.json +7 -6
@@ -0,0 +1,127 @@
1
+ /**
2
+ * device 车道两只**可选**坐标的值文法 —— 唯一判官:`DEVICE_MAX_PREAUTH_PER_REMOTE`(设备 WS 未鉴权握手的每来源上限)与 `DEVICE_TRUSTED_PROXY_CIDRS`
3
+ * (那只上限的帽键信谁的转发头)。纯函数,浏览器安全:只 import 包内私有的零 import 叶 `./deep-freeze` 与 `./ip-address`。
4
+ *
5
+ * ## 规则(一条)
6
+ * 一个车道坐标的值只有一只判官:写闸(`WorkerSpec` 的 `runtime.execution.coords`)与管理面表单调同一只;引擎起服改读它 —— 读 env 之后把原文交给它、
7
+ * 用它交回的**读数**(值或拒因),不再自己解析 —— 是服务端提货本包这一版那一步的事,在那之前服务端起服仍用它自己的解析器。交读数而不只交拒因词,是为了让读者手里没有第二份解析。`undefined` 与空串都是「未设」(引擎用它的缺省);
8
+ * 别的空白不是未设,是坏值。句子各自铸:本模块出规则句与拒因词,写闸铸「`coords.<键> <规则句> — found: <拒因>`」,引擎铸它自己的拒启句。
9
+ *
10
+ * ## 地址
11
+ * 名单里的地址读包里唯一那份地址文法(`./ip-address` 的 `readIpAddress`;包根导出它的族 `ipFamilyOf`):IPv4 = 四段十进制 0–255、不带前导零;IPv6 = WHATWG URL 的
12
+ * IPv6 主机解析器认的文本(先限字符集,再交解析器)。这份文法本来就不收 zone id(`%…`:不在字符集里,接口名对别的主机没有意义);名单多的是一只专门的拒因词 `zone-id` —— 判文法之前先认出带 `%` 的项,把拒因说成 zone id,而不是笼统的 `not-cidr`。
13
+ *
14
+ * 安全轴(名单配宽 = 名单里的来源能改帽键):歧义一律拒,不收下当「差不多」。
15
+ */
16
+ import { deepFreeze } from "./deep-freeze.js";
17
+ import { readIpAddress } from "./ip-address.js";
18
+ // ── DEVICE_MAX_PREAUTH_PER_REMOTE ─────────────────────────────────────────────────────────────────────
19
+ /** 「每来源这一层关掉」的那个字面值。只认这一种拼法。 */
20
+ const PREAUTH_OFF = "off";
21
+ /** 这只坐标的拒因(闭集;词序 = 判序):`not-a-cap` = 不是正十进制整数、也不是 `off`;`unsafe-integer` = 是一串数字,但超出安全整数(读成的已不是写下的那个数)。 */
22
+ export const DEVICE_MAX_PREAUTH_PER_REMOTE_FLAWS = deepFreeze(["not-a-cap", "unsafe-integer"]);
23
+ /** 规则句(不含值):写闸的拒句、表单的提示读这一句。 */
24
+ export const DEVICE_MAX_PREAUTH_PER_REMOTE_RULE = `must be a positive whole number in decimal (no sign, no leading zero, no blanks, at most ${Number.MAX_SAFE_INTEGER}) or the literal "${PREAUTH_OFF}" ` +
25
+ `(the per-remote pre-auth layer disabled); the empty string leaves it unset`;
26
+ /** 读一个值(env 原文或写闸的坐标值;`undefined` = 没写)。 */
27
+ export function readDeviceMaxPreAuthPerRemote(value) {
28
+ if (value === undefined || value === "")
29
+ return { ok: true, cap: undefined };
30
+ if (value === PREAUTH_OFF)
31
+ return { ok: true, cap: PREAUTH_OFF };
32
+ if (!/^[1-9][0-9]*$/.test(value))
33
+ return { ok: false, flaw: "not-a-cap" };
34
+ const n = Number(value);
35
+ return Number.isSafeInteger(n) ? { ok: true, cap: n } : { ok: false, flaw: "unsafe-integer" };
36
+ }
37
+ // ── DEVICE_TRUSTED_PROXY_CIDRS ────────────────────────────────────────────────────────────────────────
38
+ /**
39
+ * 名单一项的拒因(闭集;词序 = 判序):`empty` = 项是空的(多余 / 连续的逗号,或整个值只有空白)—— 多半是拼接事故,收下会让人以为某条还在;
40
+ * `zone-id` = 带 `%…`;`not-cidr` = 不是「地址[/十进制前缀]」(主机名、前缀越界、两道斜杠、前缀里有别的字符、IPv4 段带前导零 …);
41
+ * `all-sources` = 这一项装下某一族的**每个**来源 —— 信任它们的转发头,等于每个客户端自报帽键:前缀 0(两族都是),或装下整段 IPv4 映射地址 `::ffff:0:0/96`
42
+ * 的 IPv6 网络(引擎拿读数建的地址集合拿 IPv4 来源比 IPv6 规则时按映射形比,这样一项就信了每个 IPv4 来源);
43
+ * `host-bits` = 前缀之后还有为 1 的位 —— 是想信整块还是信一台?两条出路都交出。
44
+ */
45
+ export const TRUSTED_PROXY_CIDR_FLAWS = deepFreeze(["empty", "zone-id", "not-cidr", "all-sources", "host-bits"]);
46
+ /** 规则句(不含值)。 */
47
+ export const DEVICE_TRUSTED_PROXY_CIDRS_RULE = "must be a comma-separated list of your own reverse proxies as IPv4 / IPv6 networks (address/prefix with a decimal prefix, or a bare address for one host; " +
48
+ "spaces and tabs around an item are ignored) — no empty item, no interface zone id (%…), no hostname, no network that holds every source of a family " +
49
+ "(a zero-length prefix, or an IPv6 network holding the whole IPv4-mapped range ::ffff:0:0/96), no host bits set past the prefix " +
50
+ "(write the network address of the block, or the host's own address with a full-length prefix); the empty string leaves it unset (no forwarded-for header is read)";
51
+ /** 读一个值(env 原文或写闸的坐标值;`undefined` = 没写)。 */
52
+ export function readDeviceTrustedProxyCidrs(value) {
53
+ if (value === undefined || value === "")
54
+ return { ok: true, cidrs: undefined };
55
+ const texts = value.split(",").map((item) => item.replace(/^[ \t]+|[ \t]+$/g, ""));
56
+ const cidrs = [];
57
+ const items = [];
58
+ texts.forEach((text, i) => {
59
+ const r = readTrustedProxyCidr(text);
60
+ if ("flaw" in r)
61
+ items.push({ item: i + 1, of: texts.length, text, ...r });
62
+ else
63
+ cidrs.push(r);
64
+ });
65
+ return items.length > 0 ? { ok: false, items } : { ok: true, cidrs };
66
+ }
67
+ /** 名单的一项(已剥两侧 SP / HTAB)。判序 = {@link TRUSTED_PROXY_CIDR_FLAWS} 的词序。 */
68
+ function readTrustedProxyCidr(text) {
69
+ if (text === "")
70
+ return { flaw: "empty" };
71
+ if (text.includes("%"))
72
+ return { flaw: "zone-id" };
73
+ const slash = text.indexOf("/");
74
+ const written = slash < 0 ? text : text.slice(0, slash);
75
+ const ip = readIpAddress(written);
76
+ if (ip === undefined)
77
+ return { flaw: "not-cidr" };
78
+ const family = ip.family;
79
+ const max = family === 6 ? 128 : 32;
80
+ const prefixText = slash < 0 ? String(max) : text.slice(slash + 1);
81
+ if (!/^[0-9]+$/.test(prefixText) || Number(prefixText) > max)
82
+ return { flaw: "not-cidr" };
83
+ const prefix = Number(prefixText);
84
+ const bytes = addressBytes(ip);
85
+ if (holdsEverySource(bytes, prefix, family))
86
+ return { flaw: "all-sources" };
87
+ const address = ip.text;
88
+ const masked = bytes.map((b, i) => b & maskByte(prefix, i));
89
+ if (masked.some((b, i) => b !== bytes[i]))
90
+ return { flaw: "host-bits", block: `${networkText(masked, family)}/${prefix}`, host: `${address}/${max}` };
91
+ return { text: `${address}/${prefix}`, address, prefix, family: family === 6 ? "ipv6" : "ipv4" };
92
+ }
93
+ /** IPv4 映射地址段 `::ffff:0:0/96` 的网络字节。 */
94
+ const IPV4_MAPPED_NETWORK = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0];
95
+ const IPV4_MAPPED_PREFIX = 96;
96
+ /** 网络 `bytes/prefix` 装不装下某一族的每个来源:前缀 0;或(IPv6)前缀不长于映射段、且在前缀之内与映射段的网络逐位同 —— 装下整段 `::ffff:0:0/96`。 */
97
+ function holdsEverySource(bytes, prefix, family) {
98
+ if (prefix === 0)
99
+ return true;
100
+ if (family !== 6 || prefix > IPV4_MAPPED_PREFIX)
101
+ return false;
102
+ return IPV4_MAPPED_NETWORK.every((b, i) => (b & maskByte(prefix, i)) === (bytes[i] & maskByte(prefix, i)));
103
+ }
104
+ /** 地址的字节(IPv4 四个,IPv6 十六个),读规范文本。 */
105
+ function addressBytes(ip) {
106
+ if (ip.family === 4)
107
+ return ip.text.split(".").map(Number);
108
+ const [left = "", right] = ip.text.split("::");
109
+ const l = left === "" ? [] : left.split(":");
110
+ const r = right === undefined || right === "" ? [] : right.split(":");
111
+ const groups = [...l, ...Array(8 - l.length - r.length).fill("0"), ...r].map((g) => parseInt(g, 16));
112
+ return groups.flatMap((g) => [g >> 8, g & 255]);
113
+ }
114
+ /** 前缀 `prefix` 在第 `index` 个字节上的掩码。 */
115
+ function maskByte(prefix, index) {
116
+ const bits = Math.max(0, Math.min(8, prefix - index * 8));
117
+ return (0xff << (8 - bits)) & 255;
118
+ }
119
+ /** 字节 ⇒ 规范的网络地址文本(IPv4 点分,IPv6 压缩小写)。 */
120
+ function networkText(bytes, family) {
121
+ if (family === 4)
122
+ return bytes.join(".");
123
+ const groups = [];
124
+ for (let i = 0; i < 16; i += 2)
125
+ groups.push(((bytes[i] << 8) | bytes[i + 1]).toString(16));
126
+ return readIpAddress(groups.join(":")).text;
127
+ }
@@ -154,7 +154,9 @@ declare const LANE_ROWS: {
154
154
  /** server `config.ts` :4055 臂 + `parseDevicePreAuthPerRemoteEnv` :871 / `parseDeviceEnrollTokenTtlEnv` :857;`execution-lane-caps.ts` :327
155
155
  * `supported`(发起者自己的设备)。16.0.0:`DEVICE_RELAY_URL`(设备拨哪里)是**必需**坐标 —— 引擎的 device 臂缺它即拒启
156
156
  * (`parseDeviceRelayUrlEnv`;此前它是 device 臂读而本表漏登记的键),值只有两种:ws(s) 绝对 URL 或字面 `none`(值的文法见 `./device-relay`)。
157
- * 17.1.0:`DEVICE_TRUSTED_PROXY_CIDRS`(可选)= 设备 WS 未鉴权握手 per-remote 帽键的可信代理名单(CIDR 闭集,缺省空 = 不读任何代理头);值文法由引擎起服判。 */
157
+ * 17.1.0:`DEVICE_TRUSTED_PROXY_CIDRS`(可选)= 设备 WS 未鉴权握手 per-remote 帽键的可信代理名单(CIDR 闭集,缺省空 = 不读任何代理头)。
158
+ * 它与 `DEVICE_MAX_PREAUTH_PER_REMOTE` 的值文法只有一只判官,住本包(`./device-lane-knobs`:`readDeviceTrustedProxyCidrs` / `readDeviceMaxPreAuthPerRemote`,交读数);
159
+ * 写闸读它。引擎起服改读它是服务端提货本包那一步的事 —— 在那之前,服务端起服仍是它自己的解析器。 */
158
160
  readonly device: {
159
161
  readonly tenantSeparation: "supported";
160
162
  readonly tenantSeparationBasis: "principal-binding";
@@ -151,7 +151,9 @@ const LANE_ROWS = {
151
151
  /** server `config.ts` :4055 臂 + `parseDevicePreAuthPerRemoteEnv` :871 / `parseDeviceEnrollTokenTtlEnv` :857;`execution-lane-caps.ts` :327
152
152
  * `supported`(发起者自己的设备)。16.0.0:`DEVICE_RELAY_URL`(设备拨哪里)是**必需**坐标 —— 引擎的 device 臂缺它即拒启
153
153
  * (`parseDeviceRelayUrlEnv`;此前它是 device 臂读而本表漏登记的键),值只有两种:ws(s) 绝对 URL 或字面 `none`(值的文法见 `./device-relay`)。
154
- * 17.1.0:`DEVICE_TRUSTED_PROXY_CIDRS`(可选)= 设备 WS 未鉴权握手 per-remote 帽键的可信代理名单(CIDR 闭集,缺省空 = 不读任何代理头);值文法由引擎起服判。 */
154
+ * 17.1.0:`DEVICE_TRUSTED_PROXY_CIDRS`(可选)= 设备 WS 未鉴权握手 per-remote 帽键的可信代理名单(CIDR 闭集,缺省空 = 不读任何代理头)。
155
+ * 它与 `DEVICE_MAX_PREAUTH_PER_REMOTE` 的值文法只有一只判官,住本包(`./device-lane-knobs`:`readDeviceTrustedProxyCidrs` / `readDeviceMaxPreAuthPerRemote`,交读数);
156
+ * 写闸读它。引擎起服改读它是服务端提货本包那一步的事 —— 在那之前,服务端起服仍是它自己的解析器。 */
155
157
  device: {
156
158
  tenantSeparation: "supported",
157
159
  tenantSeparationBasis: "principal-binding",
package/dist/fleet.d.ts CHANGED
@@ -240,8 +240,8 @@ export type ModelPlaneRefusalCode = z.infer<typeof ModelPlaneRefusalCode>;
240
240
  * under `config.model_route_refused` the verdict is the engine's route judge's, relayed by the server — the engine's own code for it
241
241
  * stays outside this wire (see {@link MODEL_ENTRY_REFUSAL_CODES}). A name that
242
242
  * cannot ride out is treated as NAMELESS — the engine leaves it out of this map entirely (not keyed, not counted). The
243
- * ONE predicate is `isReportableRefusalName(name)` (main barrel): this schema can carry the key (non-empty; `__proto__`
244
- * is silently dropped by the record, so it cannot) AND `isDisclosableIdentity(name)` (an identifier in the closed allowlist
243
+ * ONE predicate is `isReportableRefusalName(name)` (main barrel): this schema can carry the key (non-empty, and not a
244
+ * reserved member name — `__proto__` / `constructor` / `prototype` make the record seat refuse the whole signal) AND `isDisclosableIdentity(name)` (an identifier in the closed allowlist
245
245
  * `DISCLOSABLE_IDENTITY_RE` — `A-Z a-z 0-9 . _ : / @ + -`, 1–256 chars — AND not secret-shaped, a URL userinfo included; the
246
246
  * rule the dropped-entry identity on read warnings already uses, 6.3.0). A producer calls it before keying; this schema deliberately
247
247
  * does not re-judge secrecy (see the 6.2.0 notes).
@@ -262,7 +262,7 @@ export type ModelPlaneRefusalCode = z.infer<typeof ModelPlaneRefusalCode>;
262
262
  * required) — one spelling at each level.
263
263
  */
264
264
  export declare const ModelRefusalsWire: z.ZodObject<{
265
- entries: z.ZodRecord<z.ZodString, z.ZodString>;
265
+ entries: z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>>;
266
266
  plane: z.ZodOptional<z.ZodString>;
267
267
  }, z.core.$strip>;
268
268
  export type ModelRefusalsWire = z.infer<typeof ModelRefusalsWire>;
@@ -438,7 +438,7 @@ export declare const InstanceAnnouncement: z.ZodObject<{
438
438
  version: z.ZodString;
439
439
  heartbeatMs: z.ZodDefault<z.ZodNumber>;
440
440
  modelRefusals: z.ZodCatch<z.ZodOptional<z.ZodObject<{
441
- entries: z.ZodRecord<z.ZodString, z.ZodString>;
441
+ entries: z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>>;
442
442
  plane: z.ZodOptional<z.ZodString>;
443
443
  }, z.core.$strip>>>;
444
444
  engineSignal: z.ZodCatch<z.ZodOptional<z.ZodObject<{
@@ -487,7 +487,7 @@ export declare const InstanceRegistration: z.ZodObject<{
487
487
  version: z.ZodString;
488
488
  heartbeatMs: z.ZodDefault<z.ZodNumber>;
489
489
  modelRefusals: z.ZodCatch<z.ZodOptional<z.ZodObject<{
490
- entries: z.ZodRecord<z.ZodString, z.ZodString>;
490
+ entries: z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>>;
491
491
  plane: z.ZodOptional<z.ZodString>;
492
492
  }, z.core.$strip>>>;
493
493
  engineSignal: z.ZodCatch<z.ZodOptional<z.ZodObject<{
package/dist/fleet.js CHANGED
@@ -24,6 +24,7 @@ import { parseDeclared } from "./declared-capture.js";
24
24
  import { dataDescriptor, isolatedObject, readDeclaredKey, ownValueOf } from "./own-key-read.js";
25
25
  import { isPlainJsonObject } from "./plain-json-object.js";
26
26
  import { buildQuotedIssue } from "./quoted-issue.js";
27
+ import { recordOf } from "./record-seat.js";
27
28
  import { deepFreeze } from "./deep-freeze.js";
28
29
  // ── Web-admin's fleet endpoints (paths, one spelling) ─────────────────────────────────────────────────────
29
30
  /**
@@ -303,8 +304,8 @@ export const ModelPlaneRefusalCode = z.enum(MODEL_PLANE_REFUSAL_CODES);
303
304
  * under `config.model_route_refused` the verdict is the engine's route judge's, relayed by the server — the engine's own code for it
304
305
  * stays outside this wire (see {@link MODEL_ENTRY_REFUSAL_CODES}). A name that
305
306
  * cannot ride out is treated as NAMELESS — the engine leaves it out of this map entirely (not keyed, not counted). The
306
- * ONE predicate is `isReportableRefusalName(name)` (main barrel): this schema can carry the key (non-empty; `__proto__`
307
- * is silently dropped by the record, so it cannot) AND `isDisclosableIdentity(name)` (an identifier in the closed allowlist
307
+ * ONE predicate is `isReportableRefusalName(name)` (main barrel): this schema can carry the key (non-empty, and not a
308
+ * reserved member name — `__proto__` / `constructor` / `prototype` make the record seat refuse the whole signal) AND `isDisclosableIdentity(name)` (an identifier in the closed allowlist
308
309
  * `DISCLOSABLE_IDENTITY_RE` — `A-Z a-z 0-9 . _ : / @ + -`, 1–256 chars — AND not secret-shaped, a URL userinfo included; the
309
310
  * rule the dropped-entry identity on read warnings already uses, 6.3.0). A producer calls it before keying; this schema deliberately
310
311
  * does not re-judge secrecy (see the 6.2.0 notes).
@@ -326,7 +327,7 @@ export const ModelPlaneRefusalCode = z.enum(MODEL_PLANE_REFUSAL_CODES);
326
327
  */
327
328
  export const ModelRefusalsWire = z
328
329
  .object({
329
- entries: z.record(z.string().min(1), z.string().min(1)),
330
+ entries: recordOf(z.string().min(1), z.string().min(1)),
330
331
  plane: z.string().min(1).optional(),
331
332
  })
332
333
  .refine((s) => Object.keys(s.entries).length > 0 || s.plane !== undefined, buildQuotedIssue `an empty model-refusals signal is not a signal — omit the key instead (absent ⇔ no reportable refusals)`);
@@ -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,12 +44,20 @@
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.
@@ -74,7 +82,7 @@ export type HookEntryType = (typeof HOOK_ENTRY_TYPES)[number];
74
82
  * 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
75
83
  * 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.
76
84
  * 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.
77
- * The classifier reads this set through a closure-private projection that the compiler ties to it in both directions.
85
+ * The classifier reads this set itself (a registered name of its closure).
78
86
  */
79
87
  export declare const HOOK_ON_FAILURE_WORDS: readonly ["continue", "block"];
80
88
  /** One word of {@link HOOK_ON_FAILURE_WORDS}. */
@@ -93,14 +101,29 @@ export type HookCloud = (typeof HOOK_CLOUD_WORDS)[number];
93
101
  /**
94
102
  * A plugin option value that names a stored credential instead of carrying it (31.0.0): the `vault` kind of the engine primitives' credential reference, and ONLY that kind — an `env`,
95
103
  * `handle` or `assertion` reference is never taken from a hook entry (an environment name would read any variable of the process that resolves it, a handle names someone else's
96
- * credential, an assertion is minted by the deployment). Judged by the primitives' `readCredentialRef` itself (the classifier calls it — no second reading of its own here) and
97
- * accepted when it reads a `vault` reference; this type is that kind of the primitives' `CredentialRef`.
104
+ * credential, an assertion is minted by the deployment). Judged by {@link readHookPluginOptionRef} — the one reading, which asks the primitives' `readCredentialRef` and takes a `vault`
105
+ * reference only; this type is that kind of the primitives' `CredentialRef`.
98
106
  * FORM ONLY: who may resolve the entry, and whether anything does, are the consumers' — this package judges the shape. A runner that cannot resolve a reference refuses the hook:
99
107
  * it never runs it with the reference standing in for the value.
100
108
  */
101
109
  export type HookPluginOptionRef = Extract<CredentialRef, {
102
110
  readonly kind: "vault";
103
111
  }>;
112
+ /**
113
+ * 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.
114
+ * 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
115
+ * `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
116
+ * `{ 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
117
+ * 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 —
118
+ * it is the option's own value, and the classifier takes a string before it asks this.
119
+ * 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
120
+ * 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'
121
+ * 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
122
+ * whether anything does, are the callers'.
123
+ * 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
124
+ * to the primitives' export — never to a copy of it.
125
+ */
126
+ export declare function readHookPluginOptionRef(value: unknown): HookPluginOptionRef | undefined;
104
127
  /**
105
128
  * The plugin context a `command` entry carries (field `plugin`, 31.0.0 — before 31.0.0 the key was not a contract field and was stripped): the plugin the hook belongs to.
106
129
  * · `name` — the plugin's name: a non-empty string with no NUL byte;
@@ -255,8 +278,7 @@ declare const HOOK_SHELLS: readonly ["bash", "powershell"];
255
278
  /**
256
279
  * 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
257
280
  * 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.
258
- * 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
259
- * that an export expression reaches — would not be copyable. It reads {@link HOOK_ENTRY_FIELDS_READ}, annotated with this table's type.
281
+ * 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.
260
282
  * · command: `args` = exec form (CC `cli309.js:252382`: when present — `[]` included — `command` is an executable spawned directly with these arguments, no shell; the mere
261
283
  * presence of `args` is the switch), `shell` (see above), `async` = run in background without blocking, `asyncRewake` = background + wake the model on exit 2,
262
284
  * `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
@@ -265,7 +287,7 @@ declare const HOOK_SHELLS: readonly ["bash", "powershell"];
265
287
  * (the plugin context: {@link HookPluginContext}; a bad one is a bad piece);
266
288
  * · prompt / agent: `prompt` ($ARGUMENTS = the hook input JSON), `model`; prompt only: `continueOnBlock` = the `continue` value of the `decision: "block"` the entry produces when its
267
289
  * verdict is not ok (CC default false: the turn ends);
268
- * · http: `url`, `headers` (values may reference $NAMEs listed in `allowedEnvVars` — env-NAME interpolation only, the config never carries a
290
+ * · 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
269
291
  * secret value; `interpolateHookEnvVars` is the one reading), `allowedEnvVars`, `onFailure` (the other schema CC gives it to), `cloud` (the other schema CC gives it to);
270
292
  * · mcp_tool: `server` (an already-configured MCP server's name), `tool`, `input` (the tool's arguments; string values may interpolate
271
293
  * `${path}` from the hook input JSON — CC 2.1.296 semantics, the runner's business).
@@ -316,7 +338,7 @@ export declare const HOOK_ENTRY_FIELDS: {
316
338
  readonly timeout: "seconds?";
317
339
  readonly statusMessage: "string?";
318
340
  readonly once: "boolean?";
319
- readonly url: "text";
341
+ readonly url: "url";
320
342
  readonly headers: "stringRecord?";
321
343
  readonly allowedEnvVars: "stringList?";
322
344
  readonly onFailure: "onFailure?";
@@ -333,7 +355,7 @@ export declare const HOOK_ENTRY_FIELDS: {
333
355
  };
334
356
  /** The type of {@link HOOK_ENTRY_FIELDS}: per entry type, field name → field kind (literal types). */
335
357
  export type HookEntryFields = typeof HOOK_ENTRY_FIELDS;
336
- type HookFieldBaseValue<B> = B extends "text" | "nonEmpty" | "string" ? string : B extends "shell" ? (typeof HOOK_SHELLS)[number] : B extends "onFailure" ? HookOnFailure : B extends "any" ? unknown : B extends "boolean" ? boolean : B extends "seconds" ? number : B extends "stringRecord" ? Record<string, string> : B extends "stringList" | "argv" ? string[] : B extends "record" ? Record<string, unknown> : B extends "plugin" ? HookPluginContext : never;
358
+ type HookFieldBaseValue<B> = B extends "text" | "url" | "nonEmpty" | "string" ? string : B extends "shell" ? (typeof HOOK_SHELLS)[number] : B extends "onFailure" ? HookOnFailure : B extends "any" ? unknown : B extends "boolean" ? boolean : B extends "seconds" ? number : B extends "stringRecord" ? Record<string, string> : B extends "stringList" | "argv" ? string[] : B extends "record" ? Record<string, unknown> : B extends "plugin" ? HookPluginContext : never;
337
359
  type HookFieldValue<K> = K extends `${infer B}?` ? HookFieldBaseValue<B> : HookFieldBaseValue<K>;
338
360
  type Flat<O> = {
339
361
  [K in keyof O]: O[K];
@@ -435,11 +457,13 @@ export type HooksClassification = {
435
457
  * Rejections and drops are listed in document order.
436
458
  *
437
459
  * COPYING THIS FUNCTION (client-core's generator, or any consumer that emits it as source): its free names besides JavaScript built-ins are its
438
- * REGISTERED names — {@link HOOK_EVENTS}, {@link pluginOptionKeysProblem} and `isAbsoluteHostPath` (this package's runtime exports) and `readCredentialRef`
439
- * (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
440
- * it names (the generator injects each as a registered value, it does not re-declare it; `pluginOptionKeysProblem` in turn registers {@link pluginOptionEnvName}).
441
- * 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
442
- * `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.
460
+ * REGISTERED names (the file header lists them: five exports of this module — `readHookPluginOptionRef` among them, not the primitives' `readCredentialRef`, which it registers
461
+ * 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
462
+ * injects each as a registered value, it does not re-declare it; `pluginOptionKeysProblem` in turn registers {@link pluginOptionEnvName}, and `readHookPluginOptionRef` registers
463
+ * `readCredentialRef`).
464
+ * 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
465
+ * 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
466
+ * what an entry may carry; a copied judgement is a second reading that drifts from its owner unseen.
443
467
  * The module-private declarations the closure uses (the `HOOK_*` constants and `hook*` helpers below the classifier line) are copied with it;
444
468
  * the hooks-classify test file (group ⑤) pins that the free names are exactly these.
445
469
  */