@sema-agent/settings-schema 31.0.1 → 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 (65) hide show
  1. package/CHANGELOG.md +894 -0
  2. package/README.md +88 -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/atomic-write.d.ts +4 -1
  11. package/dist/atomic-write.js +15 -2
  12. package/dist/center-refs.d.ts +1 -1
  13. package/dist/center-refs.js +1 -1
  14. package/dist/config-d-file.d.ts +22 -4
  15. package/dist/config-d-file.js +12 -3
  16. package/dist/config-document-refusal.d.ts +13 -2
  17. package/dist/config-document-refusal.js +2 -0
  18. package/dist/config-fns.d.ts +14 -3
  19. package/dist/config-fns.js +49 -12
  20. package/dist/config-root-documents.js +1 -1
  21. package/dist/conformance/contract-adapter.js +18 -1
  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/file-store.js +2 -2
  29. package/dist/fleet.d.ts +5 -5
  30. package/dist/fleet.js +4 -3
  31. package/dist/hooks-config.d.ts +47 -23
  32. package/dist/hooks-config.js +93 -134
  33. package/dist/hooks.d.ts +26 -22
  34. package/dist/hooks.js +17 -8
  35. package/dist/host-path.d.ts +9 -5
  36. package/dist/host-path.js +9 -20
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.js +3 -1
  39. package/dist/ip-address.d.ts +19 -0
  40. package/dist/ip-address.js +28 -0
  41. package/dist/loopback.d.ts +3 -11
  42. package/dist/loopback.js +11 -12
  43. package/dist/mcp-request-entry.js +4 -6
  44. package/dist/migration-receipt.d.ts +1 -1
  45. package/dist/migration-receipt.js +1 -1
  46. package/dist/one-time-migrations.d.ts +1 -1
  47. package/dist/one-time-migrations.js +257 -62
  48. package/dist/plain-json-object.d.ts +5 -8
  49. package/dist/plain-json-object.js +5 -8
  50. package/dist/record-seat.d.ts +35 -0
  51. package/dist/record-seat.js +97 -0
  52. package/dist/reserved-member-name.d.ts +8 -3
  53. package/dist/reserved-member-name.js +10 -3
  54. package/dist/retired-envs.js +13 -2
  55. package/dist/safety-merge-spec.d.ts +11 -3
  56. package/dist/safety-merge-spec.js +3 -2
  57. package/dist/types.d.ts +404 -112
  58. package/dist/types.js +132 -73
  59. package/docs/API-SURFACE.md +25 -6
  60. package/docs/CC-DIVERGENCE.md +11 -2
  61. package/docs/CONFORMANCE.md +2 -2
  62. package/docs/CONSUMER-INTEGRATION.md +177 -6
  63. package/llms-full.txt +35 -21
  64. package/llms.txt +12 -8
  65. package/package.json +7 -6
@@ -16,7 +16,7 @@
16
16
  * 句尾出路按文档类({@link documentWayOut}),从不回显文件原文。
17
17
  */
18
18
  import path from "node:path";
19
- import { readTextIfPresent, readTextIfPresentSync } from "./atomic-write.js";
19
+ import { isDanglingSymlinkError, readTextIfPresent, readTextIfPresentSync } from "./atomic-write.js";
20
20
  import { refuseRetiredDomain, sanitizeZodError } from "./config-fns.js";
21
21
  import { MAX_HASH_DEPTH, stableHash } from "./hash.js";
22
22
  import { UNINSPECTABLE, guardedSafeParse, ownElementsOf, ownEntriesOf } from "./own-key-read.js";
@@ -49,6 +49,15 @@ function documentWayOut(name) {
49
49
  return name === REMOTE_EXEC_DOCUMENT ? "delete it for the host default, or write a valid remoteExec spec" : "delete it for the domain default, or write a valid object";
50
50
  }
51
51
  const messageOf = (thrown) => (thrown instanceof Error ? thrown.message : String(thrown));
52
+ /** `io` 拒的类词 —— **唯一铸点**(31.1.0):抛出物是本包悬空链接判官抛的那只错(按对象身份问 `isDanglingSymlinkError`,`./atomic-write`)⇒ 悬空;其余一切抛出物(系统错、运行时自己抛的错、抛出的不是 `Error` 的值)⇒ `read_error` —— 这个词只说「读那一下抛了错、而且不是悬空判官抛的」,不说「是操作系统给的」。
53
+ * 按抛出物的**身份**判,不读句子(句子是给人看的,措辞可以改;句子一样的别的错也不算)。 */
54
+ export function configDocumentIoKindOf(thrown) {
55
+ return isDanglingSymlinkError(thrown) ? "dangling_symlink" : "read_error";
56
+ }
57
+ /** 一份被拒读数 → 拒单里的一条(`FileConfigStore.read()` 的拒单只经这一只渲染):`{ document, reason, error }`,`io` 的拒带读数的类词 `ioKind`。 */
58
+ export function configDocumentRefusalOf(document, reading) {
59
+ return reading.reason === "io" ? { document, reason: "io", ioKind: reading.ioKind, error: reading.error } : { document, reason: reading.reason, error: reading.error };
60
+ }
52
61
  /** 一份文档在内容版本的哈希里比快照的根深一层(快照 = `{ <文档名>: 文档 }`),所以文档自己最深嵌 {@link MAX_HASH_DEPTH} − 1 层(文档的根 = 第 0 层)——
53
62
  * 再深一层,整棵目录的版本就算不出(16.0.0 之前它在算版本那一步抛,把已经收集的拒一并丢掉;现在它是这一份文档的文件层拒,别的拒照列)。 */
54
63
  const MAX_CONFIG_D_DOCUMENT_DEPTH = MAX_HASH_DEPTH - 1;
@@ -157,10 +166,10 @@ function configDValueFlaw(name, value, label) {
157
166
  return { reason: "not_object", error: new Error(`${label} must be a JSON object (got ${kind}) — ${documentWayOut(name)}`) };
158
167
  }
159
168
  /** 在场却读不出的读数:词 `io`(非 `ENOENT` 的 fs 错误,以及悬空的符号链接 —— 文档本身或 `config.d` 目录:内核跟链接读到 `ENOENT`,但条目在场;句子是 `danglingSymlinkSentence`(`./atomic-write`)那一句,
160
- * 与目录迁移的读口同一句)。`thrown` 是读文本抛的那个错原样,指纹取整句的哈希。异步 / 同步两条读口共用。 */
169
+ * 与目录迁移的读口同一句),类词由 {@link configDocumentIoKindOf} 按抛出物铸(31.1.0)。`thrown` 是读文本抛的那个错原样,指纹取整句的哈希。异步 / 同步两条读口共用。 */
161
170
  function refusedIo(thrown) {
162
171
  const error = messageOf(thrown);
163
- return { status: "refused", reason: "io", error, thrown, fingerprint: stableHash(error) };
172
+ return { status: "refused", reason: "io", ioKind: configDocumentIoKindOf(thrown), error, thrown, fingerprint: stableHash(error) };
164
173
  }
165
174
  /** 读文本之后的读数(异步 / 同步两条读口共用,**判官只此一处**):没有文本(路径上没有任何条目)⇒ 缺席;有 ⇒ {@link judgeConfigDTextReading}。 */
166
175
  function readingOfText(name, file, text) {
@@ -16,8 +16,14 @@
16
16
  * 此前它在算版本那一步抛,已经收集的拒一并丢掉);第六个 `retired_domain` 是墓碑(retired 域文档带事实);
17
17
  * · `error`:契约的整句,与旧出口抛出来的那一句逐字同(`empty` / `invalid_json` / `not_object` / `too_deep` 的句子点名文件的真实路径与形,从不回显文件原文;`io` 是 fs 错误的原话 ——
18
18
  * 有的带真实路径(如 EACCES 的 `open '<路径>'`)、有的不带(EISDIR),要认是哪份文档读 `document`;调用方把 `error` 送出进程前自己脱敏);
19
+ * · `ioKind`(31.1.0,只在 `io` 的拒上):**读那一下抛的错是谁的** —— 闭集词 {@link CONFIG_DOCUMENT_IO_KINDS}:`dangling_symlink` = 本包自己的悬空链接判官抛的(文档本身或 `config.d` 目录是一条
20
+ * 链接在、目标不在的符号链接;`error` 是那一句悬空句,里面有链接指向的目标路径)· `read_error` = 读那一下抛了错、而且不是悬空判官抛的 —— 多数是操作系统给的(权限、路径是目录、
21
+ * `config.d` 是文件、成环的链接、I/O 错 ……;`error` 是那个错的原话),也包括运行时自己抛的错等其余抛出物;**不含**悬空链接 —— 这与根级决定文档读数的 `unreadable`〔`EnvModelsDecision.kind`,它含悬空链接〕是两件事,
22
+ * 所以键叫 `ioKind`、词叫 `read_error`:这只子类的键与词都不与根级两只读数〔决定文档读数 `EnvModelsDecision`、迁移标记读数 `MigrationMarker`〕的判别键(`kind`)和判别词同名)。
23
+ * 词按**抛出物是哪一只判官的错**铸,不读句子 —— 要说「为什么」又不许抄 `error` 原文的读者(拒启句、日志的机读格)读它。
24
+ * 系统给的 errno 不进这张表(那是 `error` 原话里的事实,不是第二张 errno 分类表)。本包铸的每一条 `io` 拒都带它、别的拒都不带;公开型上它是文件层那一臂的可选键,只为按 31.0.0 写的消费方不因加键编译红;
19
25
  * · 墓碑拒的 `document` 恒是 retired 域名(26.0.0 起不再另带 `migration`:改写存量的一次性迁移到期删了,那一格没有来源)。
20
- * 词表是闭集:消费方用 `switch (refusal.reason)` 穷举,加词 ⇒ 它们编译红(这是通知)。
26
+ * 词表是闭集:消费方用 `switch (refusal.reason)` / 按 `reason === "io"` 收窄后 `switch (refusal.ioKind)` 穷举(公开型上键可选:手写的拒可以不带,收窄后还有 `undefined` 那一臂),加词 ⇒ 它们编译红(这是通知)。
21
27
  */
22
28
  import type { LocalReadDomain } from "./portable-domains.js";
23
29
  import type { RetiredDomainName } from "./types.js";
@@ -26,10 +32,15 @@ export declare const CONFIG_DOCUMENT_REFUSAL_REASONS: readonly ["empty", "invali
26
32
  export type ConfigDocumentRefusalReason = (typeof CONFIG_DOCUMENT_REFUSAL_REASONS)[number];
27
33
  /** 能被拒的 `config.d` 文档:本地读取域({@link LocalReadDomain})的文档,或retired 域的文档(读它只为墓碑)。 */
28
34
  export type ConfigDocumentName = LocalReadDomain | RetiredDomainName;
29
- /** 被拒的一份文档(按 `reason` 判别):`{ document, reason, error }`;墓碑拒的文档名恒是 retired 域名。 */
35
+ /** `io` 拒的类词(31.1.0;闭集,词序冻结、尾插加词):读那一下抛的错是谁的 —— 本包的悬空链接判官抛的(`dangling_symlink`),还是别的一切抛出物(`read_error`:多数是操作系统给的,不含悬空链接)。见文件头 `ioKind` 一条。 */
36
+ export declare const CONFIG_DOCUMENT_IO_KINDS: readonly ["dangling_symlink", "read_error"];
37
+ export type ConfigDocumentIoKind = (typeof CONFIG_DOCUMENT_IO_KINDS)[number];
38
+ /** 被拒的一份文档(按 `reason` 判别):`{ document, reason, error }`,文件层那一臂多一个可选的类词 `ioKind`(31.1.0:本包只在 `reason: "io"` 时铸它);墓碑拒的文档名恒是 retired 域名。
39
+ * 文件层仍是**一臂**(与 31.0.0 同形,只多一个可选键):用变量拼出五词联合 `reason` 的写法照常合型。「`io` 恒带、别的恒不带」的严格关联在本包的铸点型上,不在这个公开型上。 */
30
40
  export type ConfigDocumentRefusal = {
31
41
  readonly document: ConfigDocumentName;
32
42
  readonly reason: Exclude<ConfigDocumentRefusalReason, "retired_domain">;
43
+ readonly ioKind?: ConfigDocumentIoKind;
33
44
  readonly error: string;
34
45
  } | {
35
46
  readonly document: RetiredDomainName;
@@ -1,3 +1,5 @@
1
1
  import { deepFreeze } from "./deep-freeze.js";
2
2
  /** 文件层拒一份文档的闭集词:五个文件层成因 + 墓碑(恒在末位)。墓碑那个词就是 `RetiredDomainError.code`(一个词,不立第二个名)。 */
3
3
  export const CONFIG_DOCUMENT_REFUSAL_REASONS = deepFreeze(["empty", "invalid_json", "not_object", "io", "too_deep", "retired_domain"]);
4
+ /** `io` 拒的类词(31.1.0;闭集,词序冻结、尾插加词):读那一下抛的错是谁的 —— 本包的悬空链接判官抛的(`dangling_symlink`),还是别的一切抛出物(`read_error`:多数是操作系统给的,不含悬空链接)。见文件头 `ioKind` 一条。 */
5
+ export const CONFIG_DOCUMENT_IO_KINDS = deepFreeze(["dangling_symlink", "read_error"]);
@@ -179,6 +179,18 @@ export declare class RetiredDomainError extends Error {
179
179
  readonly code: "retired_domain";
180
180
  constructor(domain: RetiredDomainName);
181
181
  }
182
+ /**
183
+ * 一次**跨域读**(`buildEffective` / `readEffectiveWire` / `FileConfigStore` 的 `read()` 与 `getEffective()`)里,一个门控域({@link DOMAIN_READ_FALLBACK} 判 `"throw"`)
184
+ * 整域读不进 —— 读者要知道**是哪个域**、**判官为什么拒**:`domain` 是那个域;`cause` 是判官的原拒,原样(整份严判没过 = 脱敏后的 ZodError;校验途中读不出 =
185
+ * 一句中性 TypeError;逐条丢弃域里条目体内有被剥的键且救不活 = `unrecognized_keys` 的 ZodError)。`message` 点名域并接原拒的句子 —— 原拒已脱敏,这里不读任何
186
+ * 脱敏之前的东西;原拒的句子读不出 ⇒ 只留点名域的前半句。
187
+ * 铸点只有一处(视图面读的整域档位,{@link readViewOr})。单域读口(`parseDomain` / `parseDomainLoud` / `parseDomainSalvaged`)照抛原拒 —— 调用方自己点了域;
188
+ * 目录域整域读不进不抛:回落默认 + 一条 `domain-defaulted`,告警的 `error` 就是这里的 `cause`,告警自带 `domain`。retired 域的墓碑拒是另一件事({@link RetiredDomainError})。
189
+ */
190
+ export declare class DomainReadRefusedError extends Error {
191
+ readonly domain: DomainName;
192
+ constructor(domain: DomainName, cause: unknown);
193
+ }
182
194
  /** 墓碑判一次:`raw` 是retired 域 `domain` 的文档,带事实 ⇒ 抛 {@link RetiredDomainError}。 */
183
195
  export declare function refuseRetiredDomain(domain: RetiredDomainName, raw: unknown): void;
184
196
  /** Validate + fill defaults for a domain payload (or the schema's empty default when absent/invalid). */
@@ -291,8 +303,7 @@ export declare const DISCLOSABLE_IDENTITY_RE: RegExp;
291
303
  export declare function isDisclosableIdentity(v: string): boolean;
292
304
  /** S-768 —— 「一个目录条目名能不能当 {@link ModelRefusalsWire} `entries` 的键」的**唯一**判据;引擎铸键前只调这一只,
293
305
  * 不过 ⇒ 按无名处置(不进键、不计数)。两条律的合取,不手抄任何一条:
294
- * ① 这只 schema **自己载得住**这个键 —— 就地拿 schema 判(空串不过键规则;`__proto__` 这类名被 zod 的 record 静默丢掉,
295
- * 载不住),不写名单;
306
+ * ① 这只 schema **自己载得住**这个键 —— 就地拿 schema 判(空串不过键规则;保留成员名让记录座位拒掉整只信号,载不住),不写名单;
296
307
  * ② {@link isDisclosableIdentity}(不是白名单闭形里的标识符,或是秘密形 ⇒ 不出门)。
297
308
  * 非字符串 ⇒ false。住在本文件而不是 `./fleet`:`fleet.ts` 被 `types.ts` 引,它再引本文件会成环。 */
298
309
  export declare function isReportableRefusalName(name: string): boolean;
@@ -740,7 +751,7 @@ export declare function buildEffective(version: number, getRaw: StoredDocumentRe
740
751
  * type-asserting it(0.12.0,[2281] 裁B:「两个契约共用一个拼写不是一个被检查的契约」——拼写副本要在
741
752
  * 消费端被真校验)。ONE judgment, two legs: every known domain goes through the SAME `parseDomain` +
742
753
  * {@link DOMAIN_READ_FALLBACK} policy as {@link buildEffective}(catalog 域坏形 → schema default + warning;
743
- * gate 域坏形 → throw,caller 的整包 catch 决定回落),including the retired-domain tombstone — DELEGATED to
754
+ * gate 域坏形 → throw {@link DomainReadRefusedError}(点名域,原拒在 `cause`),caller 的整包 catch 决定回落),including the retired-domain tombstone — DELEGATED to
744
755
  * buildEffective, not re-implemented(单判据双腿消费,§M4)。A retired domain on the wire (an older web-admin still
745
756
  * ships `runtime`) is judged by the same tombstone: carrying facts ⇒ {@link RetiredDomainError}; `{}` (what an older
746
757
  * web-admin materialises for an unset domain) carries nothing and is dropped from the result — it never rides through as
@@ -24,6 +24,7 @@ import { isJsonArray, isPlainJsonObject, jsonShapeOf } from "./plain-json-object
24
24
  import { carriesUserinfo, secretScanForms } from "./secret-scan.js"; // package-private normalization (both scanners read it) + the userinfo judgement (not in the barrel)
25
25
  import { sha256Hex } from "./sha256.js";
26
26
  import { unwrapSchema } from "./zod-unwrap.js"; // package-private: the ONE reading of zod's wrapper layers (salvage + the one-time migrations share it)
27
+ import { RECORD_MEMBER_NAME } from "./record-seat.js"; // package-private: a Record key named by a reserved member name is refused — the same issue as the record seat's own guard
27
28
  import { DOMAIN_SCHEMAS, InfraCostRates, LimitsConfig, PRIVATE_KEY_PEM_HEADER, RETIRED_DOMAINS, SkillsManifestSchema, WIRE_CARRIED_DOMAINS, containsSecretToken, isDomainName, isRetiredDomainName, renderQuotedSentence, retiredDomainSentence } from "./types.js";
28
29
  import { deepFreeze } from "./deep-freeze.js";
29
30
  /** Redact secret-shaped tokens from a validation MESSAGE — a zod error echoes the offending value (e.g.
@@ -331,6 +332,28 @@ export class RetiredDomainError extends Error {
331
332
  this.name = "RetiredDomainError";
332
333
  }
333
334
  }
335
+ /**
336
+ * 一次**跨域读**(`buildEffective` / `readEffectiveWire` / `FileConfigStore` 的 `read()` 与 `getEffective()`)里,一个门控域({@link DOMAIN_READ_FALLBACK} 判 `"throw"`)
337
+ * 整域读不进 —— 读者要知道**是哪个域**、**判官为什么拒**:`domain` 是那个域;`cause` 是判官的原拒,原样(整份严判没过 = 脱敏后的 ZodError;校验途中读不出 =
338
+ * 一句中性 TypeError;逐条丢弃域里条目体内有被剥的键且救不活 = `unrecognized_keys` 的 ZodError)。`message` 点名域并接原拒的句子 —— 原拒已脱敏,这里不读任何
339
+ * 脱敏之前的东西;原拒的句子读不出 ⇒ 只留点名域的前半句。
340
+ * 铸点只有一处(视图面读的整域档位,{@link readViewOr})。单域读口(`parseDomain` / `parseDomainLoud` / `parseDomainSalvaged`)照抛原拒 —— 调用方自己点了域;
341
+ * 目录域整域读不进不抛:回落默认 + 一条 `domain-defaulted`,告警的 `error` 就是这里的 `cause`,告警自带 `domain`。retired 域的墓碑拒是另一件事({@link RetiredDomainError})。
342
+ */
343
+ export class DomainReadRefusedError extends Error {
344
+ domain;
345
+ constructor(domain, cause) {
346
+ super(domainReadRefusedSentence(domain, cause), { cause });
347
+ this.domain = domain;
348
+ this.name = "DomainReadRefusedError";
349
+ }
350
+ }
351
+ /** {@link DomainReadRefusedError} 的句子:点名域 + 原拒的句子(原拒是本包铸的、已脱敏的错;读它的 `message` 在安全检视里 —— 读不出就只留前半句,不转述别的)。 */
352
+ function domainReadRefusedSentence(domain, cause) {
353
+ const head = `config domain "${domain}" could not be read`;
354
+ const said = inspect(() => (cause instanceof Error ? cause.message : undefined));
355
+ return said.ok && typeof said.value === "string" ? `${head}: ${said.value}` : head;
356
+ }
334
357
  /** 一份retired 域文档**带不带事实**:缺席与 `{}` 不带(没有可丢的东西,读者不理会);其余一切(含 `null` / 非对象 / 有键的对象)都带 ⇒ 拒。 */
335
358
  function carriesFacts(raw) {
336
359
  if (raw === undefined)
@@ -456,8 +479,7 @@ export function isDisclosableIdentity(v) {
456
479
  }
457
480
  /** S-768 —— 「一个目录条目名能不能当 {@link ModelRefusalsWire} `entries` 的键」的**唯一**判据;引擎铸键前只调这一只,
458
481
  * 不过 ⇒ 按无名处置(不进键、不计数)。两条律的合取,不手抄任何一条:
459
- * ① 这只 schema **自己载得住**这个键 —— 就地拿 schema 判(空串不过键规则;`__proto__` 这类名被 zod 的 record 静默丢掉,
460
- * 载不住),不写名单;
482
+ * ① 这只 schema **自己载得住**这个键 —— 就地拿 schema 判(空串不过键规则;保留成员名让记录座位拒掉整只信号,载不住),不写名单;
461
483
  * ② {@link isDisclosableIdentity}(不是白名单闭形里的标识符,或是秘密形 ⇒ 不出门)。
462
484
  * 非字符串 ⇒ false。住在本文件而不是 `./fleet`:`fleet.ts` 被 `types.ts` 引,它再引本文件会成环。 */
463
485
  export function isReportableRefusalName(name) {
@@ -538,10 +560,15 @@ function judgeAgainst(schema, value, rejectedAs) {
538
560
  return { ok: false, verdict: unreadableEntryVerdict() };
539
561
  return judged.value.success ? { ok: true, value: judged.value.data } : { ok: false, verdict: { error: judged.value.error, reasonCode: rejectedAs } };
540
562
  }
541
- /** Record 的一个键的判决(键先判:键坏的条目不再算值,也不下钻)。 */
563
+ /** Record 的一个键的判决(键先判:键坏的条目不再算值,也不下钻)。先问成员名律({@link RECORD_MEMBER_NAME}:名叫保留成员名 ⇒ 坏键 —— 与记录座位的守卫同一条 issue,
564
+ * 座位整份拒的那一格在这里就是这一格丢;键 schema 宽的集合不会把它放过去、再让整份重判拒掉),再问记录自己的键 schema。 */
542
565
  function judgeKey(keySchema, key) {
543
- const judged = judgeAgainst(keySchema, key, "entry-key-invalid");
544
- return judged.ok ? undefined : judged.verdict;
566
+ for (const schema of [RECORD_MEMBER_NAME, keySchema]) {
567
+ const judged = judgeAgainst(schema, key, "entry-key-invalid");
568
+ if (!judged.ok)
569
+ return judged.verdict;
570
+ }
571
+ return undefined;
545
572
  }
546
573
  /** 一条条目(数组元素 / Record 值)的判决 —— **条目好 ⇔ 它过自己的 schema,且体内没有键被剥**(22.0.0;一条判据,不分域、不分键)。
547
574
  * 被剥的键 = 原文有、schema 读数里没有的键({@link strippedKeysUnder}:对象逐键、数组同长逐下标,不读 zod 内省),{@link EXTENSION_NAMESPACES}
@@ -1232,20 +1259,30 @@ function readView(seat, raw, onWarning) {
1232
1259
  return readDomainDocument(seat.domain, raw, onWarning, (doc) => parseForView(seat, doc), (unreadable) => parseSalvaged(seat, raw, unreadable, onWarning));
1233
1260
  }
1234
1261
  /**
1235
- * 视图面读一份文档,**读不进时按 {@link DOMAIN_READ_FALLBACK} 答**:`"throw"` ⇒ 原错抛出;`"default"` ⇒ schema 默认 + 一条 `domain-defaulted`。
1262
+ * 视图面读一份文档,**读不进时按 {@link DOMAIN_READ_FALLBACK} 答**:`"throw"` ⇒ 抛 {@link DomainReadRefusedError}(`domain` = 这个域,`cause` = 判官的原拒);
1263
+ * `"default"` ⇒ schema 默认 + 一条 `domain-defaulted`(`error` = 同一个原拒)。这里是那只错的唯一铸点。
1236
1264
  * `buildEffective` 的每个域与 `readEffectiveWire` 的 skills 清单都经这一只 —— 两张表各问一次,同一个域在每条读腿上同一个答案(24.0.0 前清单是单列一臂,
1237
1265
  * 恒逐条抢救、恒默认化,不读这两张表)。好文档的路径一字不动。
1266
+ *
1267
+ * 「读不进」只问判官:读这一份文档时发的告警先收在本地,判完、在 `try` 之外按原序交给 `onWarning` —— 消费方回调自己抛的错原样穿出,不包成域读拒、
1268
+ * 不把一份读得进的文档默认化(此前回调的错也被这里接住:门控域原样再抛,目录域被读成整域读不进)。没读进的文档不交半路的告警(一个域一个结论)。
1238
1269
  */
1239
1270
  function readViewOr(seat, raw, onWarning) {
1271
+ const held = [];
1272
+ let read;
1240
1273
  try {
1241
- return readView(seat, raw, onWarning);
1274
+ read = readView(seat, raw, onWarning === undefined ? undefined : (w) => void held.push(w));
1242
1275
  }
1243
- catch (e) {
1276
+ catch (refusal) {
1244
1277
  if (DOMAIN_READ_FALLBACK[seat.domain] === "throw")
1245
- throw e;
1246
- onWarning?.({ domain: seat.domain, kind: "domain-defaulted", error: e });
1278
+ throw new DomainReadRefusedError(seat.domain, refusal);
1279
+ onWarning?.({ domain: seat.domain, kind: "domain-defaulted", error: refusal });
1247
1280
  return strictParse(seat.schema, seat.domain, emptyDocument()); // schema default — always valid
1248
1281
  }
1282
+ if (onWarning !== undefined)
1283
+ for (const w of held)
1284
+ onWarning(w);
1285
+ return read;
1249
1286
  }
1250
1287
  /**
1251
1288
  * 视图面的**整份判官**(22.0.0):整份严判(缺席 —— 只有 `undefined` —— 按空文档判,与 {@link parseDomain} 同一条),外加 —— 在逐条丢弃域
@@ -1473,7 +1510,7 @@ export function buildEffective(version, getRaw, updatedAt, onWarning) {
1473
1510
  refuseRetiredDomain(retired, getRaw(retired));
1474
1511
  // 每个域同一只读法(12.3.0 起;24.0.0 起 wire 上的 skills 清单也是这一只):{@link readViewOr} —— 视图面读(整域 parse → 按 DOMAIN_ENTRY_SALVAGE
1475
1512
  // 逐条抢救 → 未知键告警)读不进 ⇒ 只剩**整域读不进**这一个问题,答案只看 DOMAIN_READ_FALLBACK(决策表与逐域理由见那张表):
1476
- // `"throw"` ⇒ 原错抛出;`"default"` ⇒ schema 默认 + `domain-defaulted`。哪个域走哪一档不写在下面的行上,行只说「读这个域」。
1513
+ // `"throw"` ⇒ 抛 DomainReadRefusedError(点名域,原拒在 `cause`);`"default"` ⇒ schema 默认 + `domain-defaulted`。哪个域走哪一档不写在下面的行上,行只说「读这个域」。
1477
1514
  // 好配置的路径一字不动(同一次严判,同一份字节)。
1478
1515
  const parseOr = (domain, raw) => readViewOr(domainSeat(domain), raw, onWarning);
1479
1516
  return {
@@ -1508,7 +1545,7 @@ export function buildEffective(version, getRaw, updatedAt, onWarning) {
1508
1545
  * type-asserting it(0.12.0,[2281] 裁B:「两个契约共用一个拼写不是一个被检查的契约」——拼写副本要在
1509
1546
  * 消费端被真校验)。ONE judgment, two legs: every known domain goes through the SAME `parseDomain` +
1510
1547
  * {@link DOMAIN_READ_FALLBACK} policy as {@link buildEffective}(catalog 域坏形 → schema default + warning;
1511
- * gate 域坏形 → throw,caller 的整包 catch 决定回落),including the retired-domain tombstone — DELEGATED to
1548
+ * gate 域坏形 → throw {@link DomainReadRefusedError}(点名域,原拒在 `cause`),caller 的整包 catch 决定回落),including the retired-domain tombstone — DELEGATED to
1512
1549
  * buildEffective, not re-implemented(单判据双腿消费,§M4)。A retired domain on the wire (an older web-admin still
1513
1550
  * ships `runtime`) is judged by the same tombstone: carrying facts ⇒ {@link RetiredDomainError}; `{}` (what an older
1514
1551
  * web-admin materialises for an unset domain) carries nothing and is dropped from the result — it never rides through as
@@ -47,7 +47,7 @@ const digestOf = (bytes) => toHex(sha256Digest(bytes)).slice(0, 16);
47
47
  const textOf = (bytes) => new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
48
48
  /**
49
49
  * 一个 JSON 值若是「恰好这一个自有键」的纯对象 ⇒ 那个键的值;否则(多一个键 —— 含 `JSON.parse` 铸出的自有 `__proto__` 键 —— 少一个键、不是纯对象)⇒ `undefined`。
50
- * 两份文档的形都是 strict 的,判在这里一处;不交给 zod 的 strict:它对自有 `__proto__` 键的处置随版本变(4.4.x 跳过它、4.6.x 拒它),本包的 zod 区间两端答案会不同。
50
+ * 两份文档的形都是 strict 的,判在这里一处;不交给 zod 的 strict:它对自有 `__proto__` 键的处置随版本变(4.4.x 跳过它、4.6.x 拒它;32.0.0 起声明的区间已不含 4.4.x,判仍在这里一处,不依赖 zod 的处置)。
51
51
  * 文档是 `JSON.parse` 的产物,自有键都是可枚举数据属性,`Object.keys` 就是它的全部键。
52
52
  */
53
53
  function soleOwnValue(v, key) {
@@ -54,11 +54,28 @@ const isZodLike = (e) => {
54
54
  /** 内容哈希那一层拒绝的自述 —— `stableStringify` 的深度闸是**本包自己**抛的、也只有它会抛这一句;
55
55
  * 适配器给自家流水线分层,认得自家那句话是合理的(消费方的适配器认它自己那几层的错)。 */
56
56
  const HASH_STAGE_MARK = "stableStringify:";
57
+ /** 分层看的是**判官的原拒**:跨域读口的域读拒(`DomainReadRefusedError`,32.0.0 起)把原拒放在 `cause` —— 鸭子判它的 `name`(不用 `instanceof`:historical 模式下旧版 dist
58
+ * 是另一份类;旧版直接抛原拒,读到的就是它自己)。两次成员读都经检视内核;读不出 ⇒ 按抛出物本身分层。 */
59
+ const judgedRefusalOf = (e) => {
60
+ const name = inspect(() => e.name);
61
+ if (!name.ok || name.value !== "DomainReadRefusedError")
62
+ return e;
63
+ const cause = inspect(() => e.cause);
64
+ return cause.ok ? cause.value : e;
65
+ };
57
66
  const reject = (e, fallback) => {
58
67
  const diagnostics = e instanceof Error ? e.message : String(e);
59
- const stage = isZodLike(e) ? "validate" : diagnostics.startsWith(HASH_STAGE_MARK) ? "hash" : fallback;
68
+ const judged = judgedRefusalOf(e);
69
+ // 抛出物本身就是原拒 ⇒ 用上面那一句(不再问第二次原型);原拒在 `cause` ⇒ 读它的句子经检视内核,读不出就当没有句子(落这条腿的缺省层)
70
+ const judgedText = judged === e ? diagnostics : textOf(judged);
71
+ const stage = isZodLike(judged) ? "validate" : judgedText.startsWith(HASH_STAGE_MARK) ? "hash" : fallback;
60
72
  return { outcome: "rejected", stage, diagnostics };
61
73
  };
74
+ /** 原拒的句子(只用来认 {@link HASH_STAGE_MARK});读不出 ⇒ 空串。 */
75
+ const textOf = (v) => {
76
+ const read = inspect(() => (v instanceof Error ? v.message : String(v)));
77
+ return read.ok && typeof read.value === "string" ? read.value : "";
78
+ };
62
79
  /**
63
80
  * 入口的**运行期拒**(fail-closed):四条腿的入口一条都不许落在**这份正在跑的**契约包自己的构建产物里,
64
81
  * 缺席也不行。判别式与拒绝句来自 `./entry-origin.js`,这里只负责「拒」这个动作 —— 以及**按形分派**:
@@ -17,7 +17,7 @@
17
17
  * **门 = 闭集白名单**(`admit`,每只 schema 第一次进来时走一遍整棵 schema 树,通过的记下;递归 schema 按「节点 × 位置」只判一次):只放行**与 zod 同答**(判决与数据,对 JSON 输入)的节点种类
18
18
  * —— 每一种都按 zod 4.4 / 4.6 的读法推过、有对 zod 逐例比判决与数据的钉;反例搜索不是穷举,找到不同答的形就从放行单拿掉 ——
19
19
  * 叶子(不跑用户函数、没有子 schema)· 不跑看得见输入的函数的包装层(`optional` / `nullable` / `default` / `prefault`)· 后处理 `.transform(f)`(`f` 看到的是里面那只 schema 的输出,两边同一份)·
20
- * 对象(声明键不是符号、也不叫寻常对象从 `Object.prototype` 继承来的名字 —— zod 在原值上读到继承的成员,投影读成缺席)· 判别联合(不带 `unionFallback`)· 普通 / 互斥联合 · `record` · 数组 ·
20
+ * 对象(声明键不是符号、也不叫寻常对象从 `Object.prototype` 继承来的名字 —— zod 在原值上读到继承的成员,投影读成缺席)· 判别联合(不带 `unionFallback`)· 普通 / 互斥联合 · `record`(包里的每一只都是记录座位 —— 输入侧是座位守卫本身的管道,按守卫函数的身份认:守卫只按自有名读成员,在深拷副本上与在原值上同答)· 数组 ·
21
21
  * 投影走到的位置上的 `unknown` / `any`。对象 / 数组 / record 上挂的检查(refine / superRefine / 长度 …)看到的是 zod 自己铸的新输出,两边同一份。
22
22
  * 其余一律**响亮拒**(抛 `parseDeclared: unsupported schema shape — …`;这是包自己的 schema 选错了读法,不是调用方的值读不出):`.catch`(兜底函数看到整个原值 —— zod ≥ 4.6 交 `ctx.input`)·
23
23
  * 输入侧变换(`z.preprocess`、字段位上单独的 `z.transform`、两侧都是 schema 的管道)· `z.custom`(谓词看到的是副本)· 深拷节点之下的 `unknown` / `any`(副本会进输出;passthrough 对象同因)·
@@ -17,7 +17,7 @@
17
17
  * **门 = 闭集白名单**(`admit`,每只 schema 第一次进来时走一遍整棵 schema 树,通过的记下;递归 schema 按「节点 × 位置」只判一次):只放行**与 zod 同答**(判决与数据,对 JSON 输入)的节点种类
18
18
  * —— 每一种都按 zod 4.4 / 4.6 的读法推过、有对 zod 逐例比判决与数据的钉;反例搜索不是穷举,找到不同答的形就从放行单拿掉 ——
19
19
  * 叶子(不跑用户函数、没有子 schema)· 不跑看得见输入的函数的包装层(`optional` / `nullable` / `default` / `prefault`)· 后处理 `.transform(f)`(`f` 看到的是里面那只 schema 的输出,两边同一份)·
20
- * 对象(声明键不是符号、也不叫寻常对象从 `Object.prototype` 继承来的名字 —— zod 在原值上读到继承的成员,投影读成缺席)· 判别联合(不带 `unionFallback`)· 普通 / 互斥联合 · `record` · 数组 ·
20
+ * 对象(声明键不是符号、也不叫寻常对象从 `Object.prototype` 继承来的名字 —— zod 在原值上读到继承的成员,投影读成缺席)· 判别联合(不带 `unionFallback`)· 普通 / 互斥联合 · `record`(包里的每一只都是记录座位 —— 输入侧是座位守卫本身的管道,按守卫函数的身份认:守卫只按自有名读成员,在深拷副本上与在原值上同答)· 数组 ·
21
21
  * 投影走到的位置上的 `unknown` / `any`。对象 / 数组 / record 上挂的检查(refine / superRefine / 长度 …)看到的是 zod 自己铸的新输出,两边同一份。
22
22
  * 其余一律**响亮拒**(抛 `parseDeclared: unsupported schema shape — …`;这是包自己的 schema 选错了读法,不是调用方的值读不出):`.catch`(兜底函数看到整个原值 —— zod ≥ 4.6 交 `ctx.input`)·
23
23
  * 输入侧变换(`z.preprocess`、字段位上单独的 `z.transform`、两侧都是 schema 的管道)· `z.custom`(谓词看到的是副本)· 深拷节点之下的 `unknown` / `any`(副本会进输出;passthrough 对象同因)·
@@ -28,6 +28,7 @@ import { z } from "zod";
28
28
  import { NOT_PLAIN_DATA, NO_PRIOR_READS, UNINSPECTABLE, captureJson, dataDescriptor, inspect, isolatedObject, readDeclaredKey } from "./own-key-read.js";
29
29
  import { jsonShapeOf } from "./plain-json-object.js";
30
30
  import { unwrapOnce } from "./zod-unwrap.js";
31
+ import { isRecordSeat } from "./record-seat.js";
31
32
  const failed = (sentence) => ({ ok: false, sentence });
32
33
  /** 判语的句子(只在这里拼一次)。 */
33
34
  const unsupportedShape = (what) => `parseDeclared: unsupported schema shape — ${what}`;
@@ -157,6 +158,9 @@ function admitAt(schema, at, seen) {
157
158
  case "catch":
158
159
  return "`.catch` (its fallback sees the caller's whole value — zod ≥ 4.6 hands it `ctx.input`; a projection changes what it sees)";
159
160
  case "pipe":
161
+ // 记录座位(`./record-seat`,按守卫函数的身份认):输入侧的守卫只按自有名读成员,而记录在这里恒是整份深拷 —— 副本保留自有 `__proto__`、拒隐藏 / 访问器成员,守卫在副本上与在原值上同答
162
+ if (isRecordSeat(inner))
163
+ return admitAt(inner.out, at, seen);
160
164
  return `a pipe the projection does not pass through — an input-side \`z.preprocess(f, …)\` or \`a.pipe(b)\` (the function / the second schema would see a projection or a copy, not what zod sees), or wrappers nested deeper than ${WRAPPER_BOUND} layers`;
161
165
  case "transform":
162
166
  return "a bare `z.transform(f)` (an input-side function: it would see the projection, not the caller's value)";
@@ -0,0 +1,57 @@
1
+ /** 这只坐标的拒因(闭集;词序 = 判序):`not-a-cap` = 不是正十进制整数、也不是 `off`;`unsafe-integer` = 是一串数字,但超出安全整数(读成的已不是写下的那个数)。 */
2
+ export declare const DEVICE_MAX_PREAUTH_PER_REMOTE_FLAWS: readonly ["not-a-cap", "unsafe-integer"];
3
+ export type DeviceMaxPreAuthPerRemoteFlaw = (typeof DEVICE_MAX_PREAUTH_PER_REMOTE_FLAWS)[number];
4
+ /** 读数:`cap` = 那个数 / `"off"` / `undefined`(未设,引擎用它的缺省);或一个拒因。 */
5
+ export type DeviceMaxPreAuthPerRemoteReading = {
6
+ readonly ok: true;
7
+ readonly cap: number | "off" | undefined;
8
+ } | {
9
+ readonly ok: false;
10
+ readonly flaw: DeviceMaxPreAuthPerRemoteFlaw;
11
+ };
12
+ /** 规则句(不含值):写闸的拒句、表单的提示读这一句。 */
13
+ export declare const DEVICE_MAX_PREAUTH_PER_REMOTE_RULE: string;
14
+ /** 读一个值(env 原文或写闸的坐标值;`undefined` = 没写)。 */
15
+ export declare function readDeviceMaxPreAuthPerRemote(value: string | undefined): DeviceMaxPreAuthPerRemoteReading;
16
+ /**
17
+ * 名单一项的拒因(闭集;词序 = 判序):`empty` = 项是空的(多余 / 连续的逗号,或整个值只有空白)—— 多半是拼接事故,收下会让人以为某条还在;
18
+ * `zone-id` = 带 `%…`;`not-cidr` = 不是「地址[/十进制前缀]」(主机名、前缀越界、两道斜杠、前缀里有别的字符、IPv4 段带前导零 …);
19
+ * `all-sources` = 这一项装下某一族的**每个**来源 —— 信任它们的转发头,等于每个客户端自报帽键:前缀 0(两族都是),或装下整段 IPv4 映射地址 `::ffff:0:0/96`
20
+ * 的 IPv6 网络(引擎拿读数建的地址集合拿 IPv4 来源比 IPv6 规则时按映射形比,这样一项就信了每个 IPv4 来源);
21
+ * `host-bits` = 前缀之后还有为 1 的位 —— 是想信整块还是信一台?两条出路都交出。
22
+ */
23
+ export declare const TRUSTED_PROXY_CIDR_FLAWS: readonly ["empty", "zone-id", "not-cidr", "all-sources", "host-bits"];
24
+ export type TrustedProxyCidrFlaw = (typeof TRUSTED_PROXY_CIDR_FLAWS)[number];
25
+ /** 名单里合格的一项:`text` = 规范文本(`地址/前缀`,IPv6 压缩小写);`address` = 规范形的网络地址;`prefix` = 十进制前缀;`family` = 族。 */
26
+ export interface TrustedProxyCidr {
27
+ readonly text: string;
28
+ readonly address: string;
29
+ readonly prefix: number;
30
+ readonly family: "ipv4" | "ipv6";
31
+ }
32
+ /** 名单里坏的一项:第几项(从 1 起)/ 共几项 / 那一项剥掉两侧空格与制表符之后的文本 / 拒因;`host-bits` 另带两条出路(整块的网络写法、那一台的主机写法)。 */
33
+ export type TrustedProxyCidrItemFlaw = {
34
+ readonly item: number;
35
+ readonly of: number;
36
+ readonly text: string;
37
+ readonly flaw: Exclude<TrustedProxyCidrFlaw, "host-bits">;
38
+ } | {
39
+ readonly item: number;
40
+ readonly of: number;
41
+ readonly text: string;
42
+ readonly flaw: "host-bits";
43
+ readonly block: string;
44
+ readonly host: string;
45
+ };
46
+ /** 读数:合格 ⇒ 规范后的项(`undefined` = 未设,不读任何代理头);有坏项 ⇒ 每个坏项按项序一条。 */
47
+ export type TrustedProxyCidrsReading = {
48
+ readonly ok: true;
49
+ readonly cidrs: readonly TrustedProxyCidr[] | undefined;
50
+ } | {
51
+ readonly ok: false;
52
+ readonly items: readonly TrustedProxyCidrItemFlaw[];
53
+ };
54
+ /** 规则句(不含值)。 */
55
+ export declare const DEVICE_TRUSTED_PROXY_CIDRS_RULE: string;
56
+ /** 读一个值(env 原文或写闸的坐标值;`undefined` = 没写)。 */
57
+ export declare function readDeviceTrustedProxyCidrs(value: string | undefined): TrustedProxyCidrsReading;
@@ -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",
@@ -33,7 +33,7 @@
33
33
  import { readdir, stat } from "node:fs/promises";
34
34
  import path from "node:path";
35
35
  import { RetiredDomainError, buildEffective, DOMAIN_READ_FALLBACK, parseDomainLoud, refuseRetiredDomain } from "./config-fns.js";
36
- import { RETIRED_DOMAIN_NAMES, configDPath, configDVersionOf, corruptDocumentRaw, readConfigDFile, readConfigDFileReading, refuseRetiredDomainFiles } from "./config-d-file.js";
36
+ import { RETIRED_DOMAIN_NAMES, configDPath, configDVersionOf, configDocumentRefusalOf, corruptDocumentRaw, readConfigDFile, readConfigDFileReading, refuseRetiredDomainFiles } from "./config-d-file.js";
37
37
  import { LOCAL_READ_DOMAINS } from "./portable-domains.js";
38
38
  import { REMOTE_EXEC_DOCUMENT } from "./remote-exec.js";
39
39
  import { isDomainName, isRetiredDomainName } from "./types.js";
@@ -141,7 +141,7 @@ export class FileConfigStore {
141
141
  return;
142
142
  case "refused":
143
143
  raws[document] = corruptDocumentRaw(reading);
144
- refusals.push({ document, reason: reading.reason, error: reading.error });
144
+ refusals.push(configDocumentRefusalOf(document, reading)); // `io` 的拒带读数的类词(31.1.0)
145
145
  return;
146
146
  case "present":
147
147
  raws[document] = reading.value;
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<{