@sema-agent/settings-schema 21.0.0 → 23.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 (35) hide show
  1. package/CHANGELOG.md +198 -0
  2. package/README.md +54 -1
  3. package/conformance/VERSION +1 -1
  4. package/conformance/cases/c01-entry-salvage-then-typo/expected.json +2 -32
  5. package/conformance/cases/c01-entry-salvage-then-typo/meta.json +1 -1
  6. package/conformance/cases/c03-literal-dotted-top-key/expected.json +14 -16
  7. package/conformance/cases/c03-literal-dotted-top-key/meta.json +1 -1
  8. package/conformance/cases/c11-unicode-unknown-keys/expected.json +1 -1
  9. package/conformance/cases/c24-valid-entries-with-unknown-keys/expected.json +3 -24
  10. package/conformance/cases/c24-valid-entries-with-unknown-keys/meta.json +1 -1
  11. package/conformance/cases/c28-large-document-over-1mb/expected.json +1 -1
  12. package/conformance/cases/c34-skills-content-vs-manifest/expected.json +38 -16
  13. package/conformance/cases/c34-skills-content-vs-manifest/input.json +5 -0
  14. package/conformance/cases/c34-skills-content-vs-manifest/meta.json +1 -1
  15. package/conformance/cases/c42-s792-unknown-key-secret-redacted/expected.json +27 -14
  16. package/conformance/cases/c42-s792-unknown-key-secret-redacted/input.json +6 -0
  17. package/conformance/cases/c42-s792-unknown-key-secret-redacted/meta.json +1 -1
  18. package/conformance/cases/c76-projects-entry-salvage-nested/expected.json +9 -15
  19. package/conformance/cases/c76-projects-entry-salvage-nested/meta.json +1 -1
  20. package/conformance/cases/cli03-credential-pasted-into-unknown-key/expected.json +3 -18
  21. package/conformance/cases/cli03-credential-pasted-into-unknown-key/meta.json +1 -1
  22. package/conformance/cases/t03-prototype-name-key-not-swallowed/expected.json +3 -31
  23. package/conformance/cases/t03-prototype-name-key-not-swallowed/meta.json +1 -1
  24. package/conformance/cases/t04-secret-literal-never-in-warning-value/expected.json +3 -34
  25. package/conformance/cases/t04-secret-literal-never-in-warning-value/meta.json +1 -1
  26. package/conformance/cases/z02-every-domain-unknown-key/expected.json +1 -1
  27. package/dist/config-fns.d.ts +62 -23
  28. package/dist/config-fns.js +333 -102
  29. package/dist/tier-words.d.ts +1 -1
  30. package/dist/tier-words.js +1 -1
  31. package/docs/CONFORMANCE.md +8 -5
  32. package/docs/CONSUMER-INTEGRATION.md +54 -2
  33. package/llms-full.txt +3 -2
  34. package/llms.txt +9 -5
  35. package/package.json +1 -1
@@ -304,17 +304,19 @@ function outgoingSegment(seg) {
304
304
  }
305
305
  /**
306
306
  * 一条条目为什么被丢 —— **机读原因**的闭集(S-1295)。词与**丢弃点**一一对应:`DroppedEntry` 只有一个铸点
307
- * (`droppedEntry`),它的上游判据(`judgeEntry`)按「谁判、判成什么样」分三种丢法,每种一个词,没有 other 兜底:
307
+ * (`droppedEntry`),它的上游判据(`judgeKey` / {@link judgeEntry})按「谁判、判成什么样」分四种丢法,每种一个词,没有 other 兜底:
308
308
  * - `entry-schema-invalid` —— 条目(数组元素 / Record 的值)没过它自己的条目 schema;
309
309
  * - `entry-key-invalid` —— Record 的**键**没过键 schema(键先判:键坏的条目不再算值);
310
- * - `entry-unreadable` —— 判的过程抛了(病态访问器 / Proxy 陷阱;文案可能带秘密,所以只留一句中性话,见 {@link judgeEntry})。
310
+ * - `entry-unreadable` —— 判的过程抛了(病态访问器 / Proxy 陷阱;文案可能带秘密,所以只留一句中性话,见 {@link judgeAgainst});
311
+ * - `entry-unknown-key` —— 条目过了它的 schema,但**体内有键被剥**(schema 不认识、也不在 {@link EXTENSION_NAMESPACES} 里;22.0.0)。
312
+ * 剥掉后照装,装上的就不是运维写的那一条:拼错的收紧键(`allowtools`)被剥 = 那一条放宽,前瞻键被剥 = 写了没到。
311
313
  *
312
314
  * 为什么是词而不是 `error` 句:句子随 zod 小版本改字、可经脱敏,拿它当判据就是拿实现当契约;wire 上也不许有自由文本。
313
315
  * 这张表由 `test/dropped-entry-reason-code-s1295.test.ts` 的两格咬住:穷举 `switch`(给表加词而不补臂 ⇒ `tsc` 红,门 = `npm run typecheck`)与
314
316
  * 满射格(每个词至少有一个真丢弃点触发它 = 没有死词;每个被丢条目的词都在表里 = 没有无词的丢弃点)。
315
317
  * 读路径上剔条目的只有 `salvageEntries` 这一处(11.0.0 起 hosts 的读侧夹紧臂已retired),所以本表覆盖读路径上每一条被丢的条目。
316
318
  */
317
- export const DROPPED_ENTRY_REASON_CODES = ["entry-schema-invalid", "entry-key-invalid", "entry-unreadable"];
319
+ export const DROPPED_ENTRY_REASON_CODES = ["entry-schema-invalid", "entry-key-invalid", "entry-unreadable", "entry-unknown-key"];
318
320
  /** 可披露身份与出门坐标段的**长度上界**(一只常量,两处用:{@link DISCLOSABLE_IDENTITY_RE} 的上限、{@link outgoingSegment}
319
321
  * 的「超长不扫描」界)。与 web-admin 读侧名长上限 256 对齐。 */
320
322
  const DISCLOSABLE_IDENTITY_MAX = 256;
@@ -416,14 +418,41 @@ const NO_ENTRIES_DROPPED = Object.freeze({});
416
418
  function unreadableDomainError(domain) {
417
419
  return new TypeError(`invalid "${domain}" config (a value could not be read during validation)`);
418
420
  }
419
- /** 一条条目的 parse —— 坏就返回它的判决(脱敏错误 + 闭集词)。`rejectedAs` = 调用点在集合里的位置赋予「schema 没过」的那个词
421
+ /** 「判的过程抛了」的那一个判决:同一原因(校验时值读不出)一种错类 —— 与 `domain-defaulted` 告警的 error 同为 TypeError;只留一句中性话。 */
422
+ const unreadableEntryVerdict = () => ({ error: new TypeError("entry could not be read during validation"), reasonCode: "entry-unreadable" });
423
+ /** 一个值对一张 schema 的严判 —— 不过就返回它的判决(脱敏错误 + 闭集词)。`rejectedAs` = 调用点在集合里的位置赋予「schema 没过」的那个词
420
424
  * (条目 / Record 值 ⇒ `entry-schema-invalid`;Record 键 ⇒ `entry-key-invalid`);判的过程抛了则恒为 `entry-unreadable`,与位置无关。
421
425
  * 恶意 getter/Proxy 在遍历中抛错时**绝不**外泄其文案(可能带 secret,与 parseDomain 的 R13 同纪律),只留一句中性话。 */
422
- function judgeEntry(schema, value, rejectedAs) {
426
+ function judgeAgainst(schema, value, rejectedAs) {
423
427
  const judged = guardedSafeParse(() => schema.safeParse(value), sanitizeZodError); // 脱敏也在守护里:issue 读不完(`params` 里会抛的 getter)⇒ 这一条读不出(v14.6.0 同)
424
428
  if (!judged.ok)
425
- return { error: new TypeError("entry could not be read during validation"), reasonCode: "entry-unreadable" }; // 同一原因(校验时值读不出)一种错类:与 `domain-defaulted` 告警的 error 同为 TypeError
426
- return judged.value.success ? undefined : { error: judged.value.error, reasonCode: rejectedAs };
429
+ return { ok: false, verdict: unreadableEntryVerdict() };
430
+ return judged.value.success ? { ok: true, value: judged.value.data } : { ok: false, verdict: { error: judged.value.error, reasonCode: rejectedAs } };
431
+ }
432
+ /** Record 的一个键的判决(键先判:键坏的条目不再算值,也不下钻)。 */
433
+ function judgeKey(keySchema, key) {
434
+ const judged = judgeAgainst(keySchema, key, "entry-key-invalid");
435
+ return judged.ok ? undefined : judged.verdict;
436
+ }
437
+ /** 一条条目(数组元素 / Record 值)的判决 —— **条目好 ⇔ 它过自己的 schema,且体内没有键被剥**(22.0.0;一条判据,不分域、不分键)。
438
+ * 被剥的键 = 原文有、schema 读数里没有的键({@link strippedKeysUnder}:对象逐键、数组同长逐下标,不读 zod 内省),{@link EXTENSION_NAMESPACES}
439
+ * 登记的键不算(按条目在域文档里的原文坐标 `from` 判 —— models 条目上壳写的 `sema*` 是契约,不是拼错)。有 ⇒ `entry-unknown-key`,`error` 是
440
+ * zod 自己的 `.strict()` 会说的那种(每个持键层一条 `unrecognized_keys`,坐标相对条目,见 {@link strippedKeysError})。
441
+ * 比键集的那一遍读原文时抛了(第二次读才抛的访问器)⇒ `entry-unreadable`:决策面不许把读不出当没看见。
442
+ * 只在 {@link salvageEntries} 里调 —— 逐条丢弃只发生在视图面的逐条丢弃域(与 wire 上的 skills 清单);文档面与不逐条丢的域里,条目体内的
443
+ * 未知键照旧剥键 + `unknown-keys-dropped`。 */
444
+ function judgeEntry(element, entry, domain, from) {
445
+ const judged = judgeAgainst(element, entry, "entry-schema-invalid");
446
+ if (!judged.ok)
447
+ return judged.verdict;
448
+ const stripped = inspect(() => strippedKeysUnder(domain, entry, judged.value, from));
449
+ if (!stripped.ok)
450
+ return unreadableEntryVerdict();
451
+ if (stripped.value.length === 0)
452
+ return undefined;
453
+ // 错误的铸造(宿主的错误格式化器、脱敏)也在守护里:抛 ⇒ 这一条读不出(抛出值可能带键名,从不转述)。
454
+ const minted = inspect(() => strippedKeysError(stripped.value, from.length));
455
+ return minted.ok ? { error: minted.value, reasonCode: "entry-unknown-key" } : unreadableEntryVerdict();
427
456
  }
428
457
  /**
429
458
  * 从**schema 自身**派生条目集合(数组字段 / Record 字段),逐条判,坏的丢掉并逐条记账。
@@ -456,22 +485,49 @@ function judgeEntry(schema, value, rejectedAs) {
456
485
  * (`skills[].scenarios` / `mcp.servers[].allowTools` …),抢救成 `[]` 就是把限定范围放成全开。账按文档序排(父条目丢在哪个位置,
457
486
  * 体内的子条目就排在哪个位置)。
458
487
  *
459
- * 边界(如实登记):① 只下钻**条目**(集合的元素 / 值),不下钻顶层的普通对象字段(`models.atMention` 不是条目);② raw 不是
460
- * 纯 JSON 对象、字段值与 schema 形状对不上(schema 说数组、文档给对象)⇒ 原样返回,交给整域档位裁;
488
+ * **条目好坏只有一条判据**({@link judgeEntry};22.0.0):过它自己的 schema,**且体内没有键被剥**。带未知键的条目(拼错的收紧键、比本包新的
489
+ * 写者写的前瞻键)是坏条目,与坏形条目同一条律处置 —— 丢它自己、`entry-dropped` 点名(词 `entry-unknown-key`)、零幸存者不丢、体内的嵌套集合先抢救。
490
+ * 第三个参数 `domain` 说**哪个域的扩展命名空间生效**({@link EXTENSION_NAMESPACES}:models 条目上壳写的 `sema*` 不是未知键);必填 ——
491
+ * 缺了就只能把壳写的每一条目录条目当带未知键丢掉,所以不是域名 ⇒ 响亮拒(TypeError),不替调用方猜。wire 上的 skills 清单传 `"skills"`。
492
+ *
493
+ * 边界(如实登记):① 只下钻**条目**(集合的元素 / 值),不下钻顶层的普通对象字段(`models.atMention` 不是条目 —— 它里面的未知键不让任何条目丢,
494
+ * 照旧剥键 + `unknown-keys-dropped`);② raw 不是纯 JSON 对象、字段值与 schema 形状对不上(schema 说数组、文档给对象)⇒ 原样返回,交给整域档位裁;
461
495
  * ③ 域级判据(重名 / 悬空 ref)不在本函数视野内 —— 丢条目救不了它们,调用方据此回落整域档位;
462
496
  * ④ 只认 `ZodArray` / `ZodRecord` 两种条目集合形 —— 别的形(元组等)不抢救,退回整域档位(保守方向);⑤ 递归深度止于 schema
463
- * (本包没有自引用 schema);`z.lazy` 包着的 schema 不展开(`unwrapSchema` 不认它)⇒ 不下钻,那一条按原样判。
497
+ * (本包没有自引用 schema);`z.lazy` 包着的 schema 不展开(`unwrapSchema` 不认它)⇒ 不下钻,那一条按原样判;⑥ 被剥键的扫描与告警面同一只
498
+ * ({@link visitStripped}),同一个深度上界 —— 逐条丢弃域的 schema 里,能被剥键的那一层最深在第 6 段(collab 槽位成员),在上界之内。
464
499
  */
465
- export function salvageEntries(schema, raw) {
466
- const layer = salvageLayer(schema, raw);
500
+ export function salvageEntries(schema, raw, domain) {
501
+ if (!isDomainName(domain))
502
+ throw new TypeError(`salvageEntries: "${outgoingSegment(String(domain))}" is not a config domain (the third argument names whose extension namespaces apply)`);
503
+ const layer = salvageLayer(schema, raw, domain, []);
467
504
  return { raw: layer.raw, dropped: layer.dropped, keptIndex: keptIndexOf(layer.shifts) };
468
505
  }
469
506
  /** 一层抢救,抢不动就当没抢救(反射 / 访问器抛错:绝不外泄其文案)。最外层与每一条条目体内走的是**同一只** —— 一条条目体内抢不动,
470
- * 只是这一条不下钻、照原样去判,不连坐它所在的那一层。 */
471
- function salvageLayer(schema, raw) {
472
- const layer = inspect(() => salvageLayerUnsafe(schema, raw));
507
+ * 只是这一条不下钻、照原样去判,不连坐它所在的那一层。`origin` = 本层文档在域文档里的**原文**坐标(未脱敏、原下标;最外层 `[]`)——
508
+ * 扩展命名空间按运维写下的段判,出门坐标(脱敏)另由 `outgoingPath` 铸。 */
509
+ function salvageLayer(schema, raw, domain, origin) {
510
+ const layer = inspect(() => salvageLayerUnsafe(schema, raw, domain, origin));
473
511
  return layer.ok ? layer.value : { raw, dropped: [], shifts: [] };
474
512
  }
513
+ /** 「哪些字段是一组条目」的**唯一**派生(逐条抢救 {@link salvageLayerUnsafe} 与视图面判官 {@link entryHeldStrippedKeys} 同读这一只):
514
+ * 根(拆掉包装层后)是对象 ⇒ 它的每个数组 / Record 字段;凭据引用集合(按 schema 身份,见 ATOMIC_SALVAGE)除外 —— 它是一个值,坏一项 ⇒
515
+ * 它所属的条目在上一层整条判不过、整条丢。根不是对象 ⇒ 没有条目集合。只读 schema,不读文档。 */
516
+ function entryCollectionsOf(schema) {
517
+ const root = unwrapSchema(schema);
518
+ if (!(root instanceof z.ZodObject))
519
+ return [];
520
+ return Object.entries(root.shape).flatMap(([field, fieldSchema]) => {
521
+ const collection = unwrapSchema(fieldSchema);
522
+ if (ATOMIC_SALVAGE.has(collection))
523
+ return [];
524
+ if (collection instanceof z.ZodArray)
525
+ return [{ field, isArray: true, element: collection.element, keySchema: undefined }];
526
+ if (collection instanceof z.ZodRecord)
527
+ return [{ field, isArray: false, element: collection.valueType, keySchema: collection.keyType }];
528
+ return []; // 不是条目集合:连读都不读(少触发一次访问器)
529
+ });
530
+ }
475
531
  /** 集合字段的值 → 它的位置表;值的形与 schema 对不上(schema 说数组、文档给对象)⇒ `undefined`(不抢救,交给整域档位)。
476
532
  * 数组走 `forEach`(不是手写 `for (i < value.length)`):它在**进入时**就钉死了长度,而重读 `value.length` 会跟着一个在校验期间
477
533
  * 自我增殖的数组一路跑下去(病态 getter 在 zod 读字段时往同一个数组里再 push 一条)—— 抢救是尽力而为的旁路,绝不许把同步读挂死;
@@ -486,51 +542,39 @@ function collectionSlots(value, isArray) {
486
542
  }
487
543
  return isPlainJsonObject(value) ? Object.entries(value) : undefined;
488
544
  }
489
- function salvageLayerUnsafe(schema, raw) {
545
+ function salvageLayerUnsafe(schema, raw, domain, origin) {
490
546
  const untouched = { raw, dropped: [], shifts: [] };
491
547
  if (!isPlainJsonObject(raw))
492
548
  return untouched;
493
- const root = unwrapSchema(schema);
494
- if (!(root instanceof z.ZodObject))
495
- return untouched;
496
- const shape = root.shape;
497
549
  const dropped = [];
498
550
  const shifts = [];
499
551
  const patch = {};
500
- for (const [field, fieldSchema] of Object.entries(shape)) {
501
- const collection = unwrapSchema(fieldSchema);
502
- // 凭据引用集合(按 schema 身份,见 ATOMIC_SALVAGE)不下钻:它是一个值,坏一项 ⇒ 它所属的条目在上一层整条判不过、整条丢。
503
- if (ATOMIC_SALVAGE.has(collection))
504
- continue;
505
- const isArray = collection instanceof z.ZodArray;
506
- if (!isArray && !(collection instanceof z.ZodRecord))
507
- continue; // 不是条目集合:连读都不读(少触发一次访问器)
552
+ for (const { field, isArray, element, keySchema } of entryCollectionsOf(schema)) {
508
553
  const held = ownValueOf(raw, field); // the field is read from the document's OWN keys (a polluted `Object.prototype.<field>` is not a collection the document holds); unreadable ⇒ nothing to salvage here
509
554
  if (!held.ok)
510
555
  return untouched;
511
556
  const slots = collectionSlots(held.value, isArray);
512
557
  if (slots === undefined)
513
558
  continue;
514
- const element = (collection instanceof z.ZodArray ? collection.element : collection.valueType);
515
- const keySchema = collection instanceof z.ZodRecord ? collection.keyType : undefined;
516
559
  const found = []; // 本字段上账的:本层丢的整条 + 幸存条目体内丢的子条目,按文档序
517
560
  const survivors = []; // 幸存条目(体内抢救过的,是它的抢救形)
518
561
  const innerShifts = [];
519
562
  for (const [address, entry] of slots) {
520
- const at = outgoingPath([field, address]); // 键是用户写的,可能就是一条粘错位置的凭据
563
+ const at = outgoingPath([field, address]); // 出门坐标:键是用户写的,可能就是一条粘错位置的凭据
564
+ const from = [...origin, field, address]; // 原文坐标:扩展命名空间按运维写下的段判
521
565
  // Record 的键先判:键坏的条目不再算值,也不下钻。
522
- const keyVerdict = keySchema === undefined ? undefined : judgeEntry(keySchema, address, "entry-key-invalid");
566
+ const keyVerdict = keySchema === undefined ? undefined : judgeKey(keySchema, address);
523
567
  if (keyVerdict !== undefined) {
524
568
  found.push(droppedEntry(at, keyVerdict, entry));
525
569
  continue;
526
570
  }
527
- const inner = salvageLayer(element, entry); // 先下钻:这一条自己的集合按同一条律抢救
528
- const verdict = judgeEntry(element, inner.raw, "entry-schema-invalid");
571
+ const inner = salvageLayer(element, entry, domain, from); // 先下钻:这一条自己的集合按同一条律抢救
572
+ const verdict = judgeEntry(element, inner.raw, domain, from);
529
573
  if (verdict !== undefined) {
530
574
  // 整条丢 ⇒ 记账行说的是**原文**:身份取原文,判决也取原文的(拒句里的坐标是运维手里那份文档的 —— 抢救形的数组压缩过,
531
575
  // 条目级判据点到体内下标时会报错位;坐标律 S-323b 在 `error` 这一面同样成立)。体内的半路账作废。体内真丢过东西的条目,原文必判不过
532
- // (被丢的子条目本身就过不了它的 schema),`?? verdict` 只为类型。
533
- found.push(droppedEntry(at, inner.raw === entry ? verdict : (judgeEntry(element, entry, "entry-schema-invalid") ?? verdict), entry));
576
+ // (被丢的子条目本身就过不了它的 schema,或者体内带着被剥的键 —— 原文判出的是那一条的词),`?? verdict` 只为类型。
577
+ found.push(droppedEntry(at, inner.raw === entry ? verdict : (judgeEntry(element, entry, domain, from) ?? verdict), entry));
534
578
  continue;
535
579
  }
536
580
  survivors.push([address, inner.raw]);
@@ -655,6 +699,10 @@ export function projectWarning(w) {
655
699
  *
656
700
  * **恒等纪律**:没有任何一条路径真的变了(含 `keptIndex` 为空)⇒ 返回**同一个对象引用**,连 `keys`
657
701
  * 数组也不复制(好数据穿过读路径 byte 不变)。
702
+ *
703
+ * **22.0.0**:本包自己的读路径不再调它 —— 逐条丢弃域里,集合条目体内的被剥键让那一条丢(`entry-unknown-key`),抢救之后压缩过的集合里
704
+ * 再没有可被扫描点名的坐标,剩下的未知键坐标都在条目外、不经任何压缩过的集合({@link parseDomainSalvaged} 第 2 步)。它仍是一只公开的纯函数:
705
+ * 拿 {@link salvageEntries} 的 `keptIndex` 去换算别处铸的坐标的调用方照用。
658
706
  */
659
707
  export function rebaseWarningPaths(w, keptIndex) {
660
708
  switch (w.kind) {
@@ -762,31 +810,168 @@ export function isReservedExtensionKey(domain, parent, key) {
762
810
  const rules = ownRow(EXTENSION_NAMESPACES, domain);
763
811
  return rules !== undefined && rules.some((r) => r.at.length === parent.length && r.at.every((seg, i) => (seg === ANY_INDEX ? typeof parent[i] === "number" : seg === parent[i])) && r.key.test(key));
764
812
  }
765
- function collectDropped(domain, raw, parsed, prefix, depth, acc) {
766
- if (depth > DROP_SCAN_MAX_DEPTH)
813
+ /** 扫描对不上 schema 读数时的那一句(抛给调用方:决策面 ⇒ 读不出,告警面 ⇒ 没看见)。不带任何值。 */
814
+ const UNCOMPARABLE = "a value could not be compared with its schema reading";
815
+ /**
816
+ * 被剥键的**唯一**扫描({@link droppedKeys} 的告警面与 {@link strippedKeysUnder} 的决策面同走这一只):`raw`(住在域文档的 `prefix` 处)与它的
817
+ * schema 读数 `parsed` 逐层比键集,读数是容器的地方原文必须读得成同一种容器 —— 读数是数组 ⇒ 原文是同长的数组,逐下标比;读数是对象 ⇒ 原文是对象,
818
+ * 逐个自有键比(`raw` 有而 `parsed` 没有的键 = 被剥,{@link isReservedExtensionKey} 登记的不算,每个交给 `visit` 一次)。原文与读数是同一个值
819
+ * (schema 原样交回:`unknown` 位)⇒ 这一处之下没有被剥的键。原文是标量 ⇒ 没有可剥的键。
820
+ * **对不上 ⇒ 抛**({@link UNCOMPARABLE}):检视就抛的值(`getPrototypeOf` 陷阱抛的 Proxy)、长度与读数不同的数组(访问器前后两读不一样 —— 它不是「已丢过」:
821
+ * 丢条目的那一层交给本扫描的原文就是压缩过的那一份)、读数是对象而原文是数组 / 反过来。访问器 / 反射抛同样抛给调用方(告警面吞成「没看见」,决策面当「读不出」)。
822
+ * `maxDepth` = 坐标段数上界(`prefix.length` 超过即止):告警面传 {@link DROP_SCAN_MAX_DEPTH}(告警载荷有界,如实登记的边界);决策面不设上界 ——
823
+ * 递归只沿 schema 重建的容器走(同一个值即止),深度由 schema 与自由形值的深度闸定;真深到栈溢出 ⇒ 抛 ⇒ 读不出(不担保)。
824
+ */
825
+ function visitStripped(domain, raw, parsed, prefix, visit, maxDepth) {
826
+ if (raw === parsed)
827
+ return; // schema 原样交回:这一处之下没有被剥的键
828
+ if (prefix.length > maxDepth)
767
829
  return;
768
- if (isJsonArray(raw) && isJsonArray(parsed)) {
769
- // 长度不同 = 整条元素被丢(`entry-dropped` 有自己的警告),不在本判据内,别造重复噪声。
770
- if (raw.length !== parsed.length)
830
+ const shape = jsonShapeOf(parsed);
831
+ switch (shape) {
832
+ case "array": {
833
+ const items = parsed;
834
+ if (!comparableAsArray(raw, items.length))
835
+ return;
836
+ for (let i = 0; i < items.length; i++)
837
+ visitStripped(domain, raw[i], items[i], [...prefix, i], visit, maxDepth);
771
838
  return;
772
- for (let i = 0; i < raw.length; i++)
773
- collectDropped(domain, raw[i], parsed[i], [...prefix, i], depth + 1, acc);
774
- return;
839
+ }
840
+ case "plain": {
841
+ if (!comparableAsObject(raw))
842
+ return;
843
+ const out = parsed;
844
+ for (const k of Object.keys(raw)) {
845
+ if (!Object.prototype.hasOwnProperty.call(out, k)) {
846
+ if (!isReservedExtensionKey(domain, prefix, k))
847
+ visit(prefix, k); // 扩展命名空间:按契约放的键,不是未知键
848
+ continue;
849
+ }
850
+ visitStripped(domain, raw[k], out[k], [...prefix, k], visit, maxDepth);
851
+ }
852
+ return;
853
+ }
854
+ case "non_plain_object":
855
+ case "null":
856
+ case "primitive":
857
+ case "uninspectable":
858
+ return; // 读数不是 schema 铸的容器:没有键可剥
859
+ default: {
860
+ const unhandled = shape;
861
+ throw new TypeError(`visitStripped: unknown shape word ${String(unhandled)}`);
862
+ }
775
863
  }
776
- if (!isPlainJsonObject(raw) || !isPlainJsonObject(parsed))
777
- return;
778
- for (const k of Object.keys(raw)) {
779
- if (!Object.prototype.hasOwnProperty.call(parsed, k)) {
780
- if (isReservedExtensionKey(domain, prefix, k))
781
- continue; // 扩展命名空间:按契约放的键,不是未知键
782
- acc.total += 1;
783
- if (acc.keys.length < DROP_SCAN_MAX_KEYS)
784
- acc.keys.push(outgoingPath([...prefix, k]));
785
- continue;
864
+ }
865
+ /** 读数是 `length` 长的数组时,原文能不能逐下标比:同长数组 ⇒ 能;标量 ⇒ 不必比(没有可剥的键);其余 ⇒ 抛 {@link UNCOMPARABLE}。 */
866
+ function comparableAsArray(raw, length) {
867
+ const shape = jsonShapeOf(raw);
868
+ switch (shape) {
869
+ case "array":
870
+ if (raw.length !== length)
871
+ throw new TypeError(UNCOMPARABLE);
872
+ return true;
873
+ case "null":
874
+ case "primitive":
875
+ return false;
876
+ case "plain":
877
+ case "non_plain_object":
878
+ case "uninspectable":
879
+ throw new TypeError(UNCOMPARABLE);
880
+ default: {
881
+ const unhandled = shape;
882
+ throw new TypeError(`comparableAsArray: unknown shape word ${String(unhandled)}`);
883
+ }
884
+ }
885
+ }
886
+ /** 读数是对象时,原文能不能逐键比:对象(朴素或不朴素,比它的自有键)⇒ 能;标量 ⇒ 不必比;数组 / 检视就抛 ⇒ 抛 {@link UNCOMPARABLE}。 */
887
+ function comparableAsObject(raw) {
888
+ const shape = jsonShapeOf(raw);
889
+ switch (shape) {
890
+ case "plain":
891
+ case "non_plain_object":
892
+ return true;
893
+ case "null":
894
+ case "primitive":
895
+ return false;
896
+ case "array":
897
+ case "uninspectable":
898
+ throw new TypeError(UNCOMPARABLE);
899
+ default: {
900
+ const unhandled = shape;
901
+ throw new TypeError(`comparableAsObject: unknown shape word ${String(unhandled)}`);
786
902
  }
787
- collectDropped(domain, raw[k], parsed[k], [...prefix, k], depth + 1, acc);
788
903
  }
789
904
  }
905
+ /** 决策面:`raw`(住在域文档的 `at` 处)与它的 schema 读数之间被剥的全部键,**不设条数上限、不设深度上限**(告警载荷的两个上限只在 {@link droppedKeys})。抛 ⇒ 抛。 */
906
+ function strippedKeysUnder(domain, raw, parsed, at) {
907
+ const out = [];
908
+ visitStripped(domain, raw, parsed, at, (holder, key) => void out.push({ holder, key }), Number.POSITIVE_INFINITY);
909
+ return out;
910
+ }
911
+ /** 一张空的 strict 对象:任何键在它面前都是未知键。{@link strictRefusalOf} 拿它向 zod 要「这些键是未知键」的那条 issue。 */
912
+ const NO_KEYS_ALLOWED = z.object({}).strict();
913
+ /** 一层被剥的键在 zod 自己的 `.strict()` 面前的读数:一份只装着这些键的对象交给 {@link NO_KEYS_ALLOWED} —— 读不进的那条 issue(码 `unrecognized_keys`、`keys`、
914
+ * 句子,按宿主配置的 zod 语言)与装它的错误(`safeParse` 交出的那一类,是 `Error`)都由 zod 铸,本包不手写第二份。键集非空 ⇒ 恒读不进;
915
+ * 万一读进了(到不了)⇒ 抛,调用方都在「读不出」那一臂上接它(逐条判决 ⇒ 那一层不抢救;整份判决 ⇒ 整份读不进),不退回照装。 */
916
+ function strictRefusalOf(keys) {
917
+ // fromEntries:`__proto__` 作键也是一个自有键(「键就是键」,与上面 Record 键同一条)。错误对象的构造(宿主的错误格式化器在这一步跑)在守护里:抛 ⇒ 读不出。
918
+ const judged = guardedSafeParse(() => NO_KEYS_ALLOWED.safeParse(Object.fromEntries(keys.map((k) => [k, true]))));
919
+ if (!judged.ok)
920
+ throw new TypeError("the unrecognized-keys refusal could not be minted");
921
+ if (judged.value.success)
922
+ throw new TypeError("an empty strict object accepted a non-empty key set");
923
+ return judged.value.error;
924
+ }
925
+ /**
926
+ * 被剥的键 → 它们的(脱敏)错误(抛 ⇒ 抛:调用方在守护里调它,抛 ⇒ 读不出):每个持键层一条 `unrecognized_keys` issue —— zod 自己的 `.strict()` 在那一层会说的那一条({@link strictRefusalOf}),
927
+ * 坐标挪到持键层。坐标从第 `base` 段之后起算:条目判决传条目的坐标段数(issue 坐标相对条目,与 `entry-schema-invalid` 的 issue 同一个起点),
928
+ * 整份判决传 0(从域根起)。出门经 {@link sanitizeZodError}:坐标段与 `keys` 过 {@link outgoingSegment},句子里的原键随之换成出门形 —— 秘密形 / 超长的键名不随错误外流。
929
+ */
930
+ function strippedKeysError(stripped, base) {
931
+ const byHolder = new Map();
932
+ for (const { holder, key } of stripped) {
933
+ const path = holder.slice(base);
934
+ const slot = JSON.stringify(path);
935
+ const group = byHolder.get(slot);
936
+ if (group === undefined)
937
+ byHolder.set(slot, { path: [...path], keys: [key] });
938
+ else
939
+ group.keys.push(key);
940
+ }
941
+ const [error, ...rest] = [...byHolder.values()].map(({ path, keys }) => {
942
+ const refusal = strictRefusalOf(keys);
943
+ refusal.issues.splice(0, refusal.issues.length, ...refusal.issues.map((issue) => ({ ...issue, path: [...path, ...issue.path] })));
944
+ return refusal;
945
+ });
946
+ for (const more of rest)
947
+ error.issues.push(...more.issues); // 第一个持键层的错误装下全部 issue(调用方只在真有被剥键时调:至少一个持键层)
948
+ return sanitizeZodError(error);
949
+ }
950
+ /**
951
+ * 一份已过 schema 的文档里,持键层落在**条目体内**的被剥键(22.0.0;原文坐标,从域根起)。条目 = {@link entryCollectionsOf} 派生的集合的元素 / 值;
952
+ * 持键层在条目体内 ⇔ 它的坐标以 `[集合字段, 地址]` 开头(条目本身、条目的非数组子对象、条目体内的嵌套集合与它们的条目)。
953
+ * 持键层是域根、顶层的普通对象字段(`models.atMention`)、或 Record 集合本身(被剥的是一个 Record 键)⇒ 不在任何条目体内,照旧走剥键告警。抛 ⇒ 抛。
954
+ */
955
+ function entryHeldStrippedKeys(domain, schema, raw, parsed) {
956
+ const fields = new Set(entryCollectionsOf(schema).map((c) => c.field));
957
+ return strippedKeysUnder(domain, raw, parsed, []).filter(({ holder }) => holder.length >= 2 && fields.has(String(holder[0])));
958
+ }
959
+ /**
960
+ * 视图面整份判官的后一半(22.0.0;逐条丢弃域与 wire 上的 skills 清单,见 {@link parseForView} / `readSkillsManifest`):文档已过 schema,但有条目体内的键被剥 ⇒
961
+ * 抛 {@link strippedKeysError}(从域根起的坐标);比键集时读不出 ⇒ 抛 {@link unreadableDomainError}。调用方接住它走逐条抢救(带未知键的条目丢它自己,
962
+ * {@link judgeEntry});救不活(零幸存者、丢了之后引用悬空)⇒ 这就是「整份读不进」的那个原错 —— 不会退回剥键照装。
963
+ */
964
+ function refuseEntryHeldStrippedKeys(domain, schema, raw, parsed, label) {
965
+ const held = inspect(() => entryHeldStrippedKeys(domain, schema, raw, parsed));
966
+ if (!held.ok)
967
+ throw unreadableDomainError(label);
968
+ if (held.value.length === 0)
969
+ return;
970
+ const minted = inspect(() => strippedKeysError(held.value, 0)); // 铸造抛(宿主的错误格式化器)⇒ 整份读不出,抛出值从不转述
971
+ if (!minted.ok)
972
+ throw unreadableDomainError(label);
973
+ throw minted.value;
974
+ }
790
975
  /**
791
976
  * 一份域文档里被域 schema **丢掉的键**(zod 对象默认 `"strip"`),段坐标形({@link ConfigPath})。
792
977
  *
@@ -813,7 +998,11 @@ function collectDropped(domain, raw, parsed, prefix, depth, acc) {
813
998
  function droppedKeys(domain, raw, parsed) {
814
999
  const acc = { keys: [], total: 0 };
815
1000
  try {
816
- collectDropped(domain, raw, parsed, [], 0, acc);
1001
+ visitStripped(domain, raw, parsed, [], (holder, key) => {
1002
+ acc.total += 1;
1003
+ if (acc.keys.length < DROP_SCAN_MAX_KEYS)
1004
+ acc.keys.push(outgoingPath([...holder, key]));
1005
+ }, DROP_SCAN_MAX_DEPTH);
817
1006
  }
818
1007
  catch {
819
1008
  return { keys: [], total: 0 }; // 反射/访问器抛错:告警是尽力而为的审计线,绝不能把解析拖下水,更不能回显其错误文案
@@ -883,7 +1072,7 @@ function carriedUnknownKeys(domain, parsed) {
883
1072
  * 视图面(「这份文档在生效配置里是什么」)是 {@link parseDomainSalvaged}:同一只内部体({@link readDomainDocument}),读不进时多一步逐条抢救。
884
1073
  */
885
1074
  export function parseDomainLoud(domain, raw, onWarning) {
886
- return readDomainDocument(domain, raw, onWarning, (unreadable) => {
1075
+ return readDomainDocument(domain, raw, onWarning, (doc) => parseDomain(domain, doc), (unreadable) => {
887
1076
  throw unreadable;
888
1077
  });
889
1078
  }
@@ -892,27 +1081,42 @@ export function parseDomainLoud(domain, raw, onWarning) {
892
1081
  * `buildEffective` 十六个域一处调它(`parseOr`);管理面要显示「生效配置里这个域是什么」时读它。
893
1082
  *
894
1083
  * 读法:
895
- * 1. 整域 `parseDomain`;过 ⇒ 未知键两条告警按原文档坐标出门,返回 —— 与 {@link parseDomainLoud} 逐字同值同告警(好配置的路径一字不动)。
896
- * 2. 不过,且 {@link DOMAIN_ENTRY_SALVAGE} 判该域 `"salvage"` ⇒ {@link salvageEntries}(递归到嵌套集合);丢了东西 ⇒ 拿压缩后的
897
- * 文档再 `parseDomain` 一次。过 ⇒ 每条被丢条目一条 `entry-dropped`(它们本来就是原文档坐标),其余告警是对压缩文档的诊断,
898
- * 过本层位移表({@link rebaseWarningPaths})回写成原文档坐标(坐标律 S-323b)。
1084
+ * 1. 整份判 {@link parseForView}:`parseDomain`,外加(逐条丢弃域里)「没有条目体内被剥的键」(22.0.0);过 ⇒ 未知键两条告警按原文档坐标出门,
1085
+ * 返回 —— 与 {@link parseDomainLoud} 逐字同值同告警(好配置的路径一字不动;条目体内没有未知键时,两面读数一字不差)。
1086
+ * 2. 不过,且 {@link DOMAIN_ENTRY_SALVAGE} 判该域 `"salvage"` ⇒ {@link salvageEntries}(递归到嵌套集合;坏形条目与带未知键的条目同一条律丢);
1087
+ * 丢了东西 ⇒ 拿压缩后的文档再 {@link parseForView} 一次。过 ⇒ 每条被丢条目一条 `entry-dropped`(它们本来就是原文档坐标),其余告警是对压缩
1088
+ * 文档的诊断。压缩后的文档条目体内已没有被剥的键,所以 `unknown-keys-dropped` 只点名条目外的键(域顶层、顶层对象字段 —— 它们的坐标不经任何
1089
+ * 压缩过的集合,就是原文档坐标;坐标律不再需要位移表)—— 一个未知键只经一条告警说一次(在条目体内 ⇒ `entry-dropped`,在条目外 ⇒ `unknown-keys-dropped`)。
899
1090
  * 3. 其余一切(`"none"` 档、什么都没丢、丢了仍读不进)⇒ **抛第 1 步的原错**,零告警 —— 一个域一个结论:没救活就不留「丢了某条」的半路叙述。
900
- * 整域读不进之后是默认化还是抛,是调用方按 {@link DOMAIN_READ_FALLBACK} 的事(`buildEffective` 的 `parseOr`),本函数不读那张表。
1091
+ * 第 1 步只因条目体内的被剥键而不过、又救不活(零幸存者 / 引用悬空)时,原错是 {@link refuseEntryHeldStrippedKeys} 的 `unrecognized_keys`,
1092
+ * 不退回剥键照装。整域读不进之后是默认化还是抛,是调用方按 {@link DOMAIN_READ_FALLBACK} 的事(`buildEffective` 的 `parseOr`),本函数不读那张表。
901
1093
  *
902
1094
  * 写路径与导出面不调它:`parseDomain` / `validateDomain` / `writeDomainFile` 判整份文档,写入席与 `getDomain` / `exportBundle` 读 {@link parseDomainLoud}。
903
1095
  * 读改写(读存量、改、整份写回)的「现状」也不许读它 —— 抢救读出再写回,被丢的条目就成了删除。
904
1096
  */
905
1097
  export function parseDomainSalvaged(domain, raw, onWarning) {
906
- return readDomainDocument(domain, raw, onWarning, (unreadable) => parseSalvaged(domain, raw, unreadable, onWarning));
1098
+ return readDomainDocument(domain, raw, onWarning, (doc) => parseForView(domain, doc), (unreadable) => parseSalvaged(domain, raw, unreadable, onWarning));
907
1099
  }
908
1100
  /**
909
- * 两面共用的**唯一内部体**:严 parse(`parseDomain`)+ 未知键两条告警。整域读不进时交给 `whenUnreadable`(文档面:抛原错;视图面:逐条抢救)——
910
- * 两个读函数只差这一个入参。告警在 parse 成功之后、`try` 之外发:`onWarning` 自己抛的错不会被当成「文档读不进」。
1101
+ * 视图面的**整份判官**(22.0.0):`parseDomain`,外加 —— 在逐条丢弃域({@link DOMAIN_ENTRY_SALVAGE} 判 `"salvage"`)里 —— 「没有条目体内被剥的键」
1102
+ * ({@link refuseEntryHeldStrippedKeys})。视图面判条目只有一条律({@link judgeEntry}:过 schema 且体内没有键被剥),整份文档也按同一条律判:
1103
+ * 否则零幸存者的集合(一条都救不活 ⇒ 抢救一条不丢)就会剥键照装,正是本律要关掉的那条放宽。
1104
+ * 不逐条丢的域与文档面({@link parseDomainLoud})只用 `parseDomain`:那里一条条目都不丢,条目体内的未知键照旧剥键 + 告警。
911
1105
  */
912
- function readDomainDocument(domain, raw, onWarning, whenUnreadable) {
1106
+ function parseForView(domain, raw) {
1107
+ const parsed = parseDomain(domain, raw);
1108
+ if (DOMAIN_ENTRY_SALVAGE[domain] === "salvage")
1109
+ refuseEntryHeldStrippedKeys(domain, DOMAIN_SCHEMAS[domain], raw, parsed, domain);
1110
+ return parsed;
1111
+ }
1112
+ /**
1113
+ * 两面共用的**唯一内部体**:整份判(`parse`:文档面 `parseDomain`,视图面 {@link parseForView})+ 未知键两条告警。整域读不进时交给 `whenUnreadable`
1114
+ * (文档面:抛原错;视图面:逐条抢救)—— 两个读函数只差这两个入参。告警在判过之后、`try` 之外发:`onWarning` 自己抛的错不会被当成「文档读不进」。
1115
+ */
1116
+ function readDomainDocument(domain, raw, onWarning, parse, whenUnreadable) {
913
1117
  let parsed;
914
1118
  try {
915
- parsed = parseDomain(domain, raw);
1119
+ parsed = parse(raw);
916
1120
  }
917
1121
  catch (unreadable) {
918
1122
  return whenUnreadable(unreadable);
@@ -927,24 +1131,25 @@ function readDomainDocument(domain, raw, onWarning, whenUnreadable) {
927
1131
  function parseSalvaged(domain, raw, unreadable, onWarning) {
928
1132
  if (DOMAIN_ENTRY_SALVAGE[domain] !== "salvage")
929
1133
  throw unreadable;
930
- const { parsed, salvage } = salvageThenParse(DOMAIN_SCHEMAS[domain], raw, (doc) => parseDomain(domain, doc), unreadable);
1134
+ const { parsed, salvage } = salvageThenParse(DOMAIN_SCHEMAS[domain], domain, raw, (doc) => parseForView(domain, doc), unreadable);
931
1135
  if (onWarning) {
932
- // 坐标律(S-323b):一条告警用「铸它的那一层所见文档」的坐标表达;哪一层压缩了文档,哪一层就把从它下方上来的告警回写一次。
933
- // `entry-dropped` 是本层(salvage)铸的,用的就是本层入参那份文档的坐标 ⇒ 原样出门;未知键扫描是对本层**压缩后**文档的诊断 ⇒ 过本层的位移表。
1136
+ // 坐标律(S-323b):一条告警用运维手里那份文档的坐标。`entry-dropped` 是本层(salvage)铸的,用的就是本层入参那份文档的坐标 ⇒ 原样出门;
1137
+ // 未知键扫描是对压缩后文档的诊断,但它报的坐标不经任何压缩过的集合(22.0.0:集合条目体内的被剥键让那一条丢 —— 压缩后的文档条目体内没有被剥的键,
1138
+ // 剩下的都在条目外:域顶层、顶层对象字段)⇒ 它们就是原文档坐标,不需要位移表。
934
1139
  for (const d of salvage.dropped)
935
1140
  onWarning(entryDroppedWarning(domain, d));
936
- announceUnknownKeys(domain, salvage.raw, parsed, (w) => onWarning(rebaseWarningPaths(w, salvage.keptIndex)));
1141
+ announceUnknownKeys(domain, salvage.raw, parsed, onWarning);
937
1142
  }
938
1143
  return parsed;
939
1144
  }
940
1145
  /**
941
1146
  * 逐条抢救的**那一步**(域面 {@link parseSalvaged} 与 wire 面 skills 清单 `readSkillsManifest` 共用 —— 一条律,两个调用点):整份严判已经失败
942
1147
  * (校验不过,或校验过程抛 —— 同一条臂:{@link salvageEntries} 逐条判,抛的那一条记 `entry-unreadable` 丢它自己)之后,丢掉坏条目再严判一次。
943
- * 什么都没丢 / 丢了仍读不进(条目之外还有毛病:重名 / 悬空 ref / 域级判据;或抢救后的文档在重判时读不出)⇒ 抛 `unreadable`(第一次严判的原错)——
944
- * 一个文档一个结论,没救活就不留「丢了某条」的半路叙述。
1148
+ * 什么都没丢 / 丢了仍读不进(条目之外还有毛病:重名 / 悬空 ref / 域级判据;零幸存者的集合里还留着带未知键的条目;或抢救后的文档在重判时读不出)⇒
1149
+ * 抛 `unreadable`(第一次严判的原错)—— 一个文档一个结论,没救活就不留「丢了某条」的半路叙述。`domain` = 哪个域的扩展命名空间生效(见 {@link salvageEntries})。
945
1150
  */
946
- function salvageThenParse(schema, raw, parse, unreadable) {
947
- const salvage = salvageEntries(schema, raw);
1151
+ function salvageThenParse(schema, domain, raw, parse, unreadable) {
1152
+ const salvage = salvageEntries(schema, raw, domain);
948
1153
  if (salvage.dropped.length === 0)
949
1154
  throw unreadable;
950
1155
  try {
@@ -971,8 +1176,12 @@ function announceUnknownKeys(domain, raw, parsed, emit) {
971
1176
  * `"throw"` = keep fail-loud (defaulting would LOOSEN gates or destructively apply — worse than an outage,
972
1177
  * consumers fail-static on last-good). A `satisfies Record<DomainName,…>` forces every FUTURE domain to make
973
1178
  * this call explicitly (compile error until it's classified). Per-domain rationale:
974
- * - models/skills/mcp/plugins/scenarios/systems/collab: additive capability catalogs — empty = the
1179
+ * - models/skills/mcp/systems/collab: additive capability catalogs — empty = the
975
1180
  * capability disappears (fail-closed), no gate is lost.
1181
+ * - scenarios: THROW (23.0.0) — an empty `scenarios` revives every built-in scenario an entry overrode, widening the tool surface of each;
1182
+ * defaulting would hand that to every reader that has no candidate gate. {@link DOMAIN_ENTRY_SALVAGE} judges the domain `"none"` for the same
1183
+ * reason, and a `"none"` domain that then defaulted would be the same loosening one level up (one bad entry ⇒ ALL overrides gone).
1184
+ * - plugins: THROW (23.0.0) — an empty `plugins` drops the hooks (guards among them) the references carried; same reasoning as `scenarios`.
976
1185
  * - hosts: empty host registry = no auto-placement targets (availability-only); self-registration re-lands
977
1186
  * entries as approved:false = 待批 (fail-closed).
978
1187
  * - rosters: THROW — a lost roster makes resolveEffectiveForWorker fall back to the FULL models catalog
@@ -996,8 +1205,8 @@ export const DOMAIN_READ_FALLBACK = {
996
1205
  rosters: "throw",
997
1206
  skills: "default",
998
1207
  mcp: "default",
999
- plugins: "default",
1000
- scenarios: "default",
1208
+ plugins: "throw", // 23.0.0:空 plugins = 引用承运的 hooks(守卫)全缺席,不是 fail-closed;与 DOMAIN_ENTRY_SALVAGE 的 none 同一理由
1209
+ scenarios: "throw", // 23.0.0:空 scenarios = 覆盖过的内建场景全部回位(更宽的工具面),不是 fail-closed;与 DOMAIN_ENTRY_SALVAGE 的 none 同一理由
1001
1210
  systems: "default",
1002
1211
  collab: "default",
1003
1212
  workers: "throw",
@@ -1006,7 +1215,7 @@ export const DOMAIN_READ_FALLBACK = {
1006
1215
  entitlement: "throw",
1007
1216
  execution: "throw",
1008
1217
  projects: "throw",
1009
- // prompts:内容域(scenarios 同类)——坏形→空默认 `{}`(=「不管提示词」:不下发中心层,引擎用内置);fail-closed 由 PUBLISH_MODE
1218
+ // prompts:内容域 ——坏形→空默认 `{}`(=「不管提示词」:不下发中心层,引擎用内置);fail-closed 由 PUBLISH_MODE
1010
1219
  // 发布闸承担,default 不扩权。14.0.0 起墓碑键(`bindings` / `catalog`)也走这一档(读不出 ⇒ 缺省 + domain-defaulted 点名 SS-M10)。
1011
1220
  prompts: "default",
1012
1221
  // limits(0.19.0):THROW —— 本域是成本 / 限流天花板的唯一发布位(11.0.0 起 runtime 域retired)。坏形
@@ -1019,8 +1228,15 @@ export const DOMAIN_READ_FALLBACK = {
1019
1228
  /** Per-domain ENTRY-SALVAGE policy (12.3.0, S-1494) — may the view-face domain reader ({@link parseDomainSalvaged}) drop single bad
1020
1229
  * entries (an array element, a Record value, and — recursively — a bad entry inside a surviving entry) and read the rest?
1021
1230
  * **One question only**: what happens when the domain stays unreadable after that is {@link DOMAIN_READ_FALLBACK}'s question.
1022
- * `"salvage"` = drop each bad entry, name it (`entry-dropped`, coordinate + identity + reason word), keep the rest.
1023
- * `"none"` = never drop a single entry: the first bad entry makes the whole domain unreadable.
1231
+ * `"salvage"` = drop each bad entry, name it (`entry-dropped`, coordinate + identity + reason word), keep the rest. A bad entry is one that
1232
+ * fails its own schema OR (22.0.0) loses a key to the strip inside its body — an unknown key that is not a registered extension key
1233
+ * (`entry-unknown-key`): loading it stripped would load something other than what the operator wrote (a misspelt narrowing key widens
1234
+ * that entry). The view face reads the whole document by the same rule, so a collection whose entries ALL carry unknown keys is not
1235
+ * loaded stripped either (zero survivors ⇒ the domain is unreadable ⇒ {@link DOMAIN_READ_FALLBACK}). An unknown key outside every entry
1236
+ * (domain top level, a top-level plain object field) is still stripped and named (`unknown-keys-dropped`).
1237
+ * `"none"` = never drop a single entry: the first bad entry makes the whole domain unreadable. An unknown key inside an entry of such a
1238
+ * domain is stripped and named, as before 22.0.0 — those domains drop nothing, so the strip warning is the reader's signal.
1239
+ * (23.0.0: `scenarios` and `plugins` joined the seven — their entries' absence widens; see the judgment below.)
1024
1240
  * A `satisfies Record<DomainName,…>` forces every FUTURE domain to answer this explicitly (compile error until classified).
1025
1241
  *
1026
1242
  * **View face only.** The document face never salvages: `parseDomain` / `validateDomain` / `writeDomainFile` judge the whole
@@ -1029,12 +1245,22 @@ export const DOMAIN_READ_FALLBACK = {
1029
1245
  * it back would turn every dropped entry into a deletion — read-modify-write faces read the stored document with the document face.
1030
1246
  *
1031
1247
  * Per-domain rationale:
1032
- * - models/skills/mcp/plugins/scenarios/systems/collab: additive capability / content catalogs — a dropped entry is
1248
+ * - **The judgment (23.0.0)**: `"salvage"` is for a domain whose entry's ABSENCE can only NARROW what is reachable. A domain whose entry's
1249
+ * absence WIDENS — the entry is a restriction, a guard, or an override of a built-in of the same name (its absence revives the built-in) — is `"none"`:
1250
+ * dropping the entry would be the same loosening as stripping its key. The judgment is written on the row (a trailing comment, closed set: a new
1251
+ * domain adds its row AND its judgment).
1252
+ * - models/skills/mcp/systems/collab: capability / content catalogs and grants — a dropped entry is
1033
1253
  * one capability gone (fail-closed). Inside a surviving entry the same holds: the nested collections these entries carry
1034
1254
  * are allowlists / scopings (`allowTools`, `scenarios`, `rosters`, `callsWorkers`, …) where one entry fewer only NARROWS,
1035
1255
  * and the zero-survivor law (never mint an empty collection — several of these read "empty = all") holds at every level.
1256
+ * - scenarios: NONE (23.0.0) — an entry names the tool surface of a scenario, and may carry the name of a built-in scenario (then it OVERRIDES
1257
+ * it, narrowing its tool surface). A dropped entry revives the built-in with its wider surface: the loosening 22.0.0's rule made out of a
1258
+ * misspelt or forward-looking key.
1259
+ * - plugins: NONE (23.0.0) — an entry is the source reference of an executable surface (commands / hooks / MCP); its hooks may be guards
1260
+ * (`PreToolUse` / `PermissionRequest`, see `./hooks-config`). A dropped reference takes the guard with it.
1036
1261
  * - hosts: a dropped host is one placement target fewer; a dropped label makes a host match fewer `placement.requires`.
1037
- * - projects: SALVAGE — a registration absent from the ledger = that project's claim is refused (fail-closed). Throwing the
1262
+ * - projects: SALVAGE — a registration absent from the ledger is one project fewer (the pinned consumer reads a lookup miss as "no
1263
+ * default-scope seed", not as a refused admission: the ledger is an additive registry, not a gate). Throwing the
1038
1264
  * whole domain stops EVERY project of the scope, which protects nothing: one stored registration that a later, tighter
1039
1265
  * schema refuses (12.2.1's UNC judgement on `contextItems[].value`) must not take the scope's other projects with it.
1040
1266
  * Its whenUnreadable stance stays `"throw"` (a ledger that cannot be read at all is never defaulted — see
@@ -1055,23 +1281,23 @@ export const DOMAIN_READ_FALLBACK = {
1055
1281
  * credential references (`headerRefs`) are in {@link ATOMIC_SALVAGE}: a bad reference drops the whole peer, never the reference
1056
1282
  * alone (a peer kept with half of its credentials is the wrong failure direction). */
1057
1283
  export const DOMAIN_ENTRY_SALVAGE = {
1058
- models: "salvage",
1059
- rosters: "none",
1060
- skills: "salvage",
1061
- mcp: "salvage",
1062
- plugins: "salvage",
1063
- scenarios: "salvage",
1064
- systems: "salvage",
1065
- collab: "salvage",
1066
- workers: "none",
1067
- hosts: "salvage",
1068
- governance: "none",
1069
- entitlement: "none",
1070
- execution: "none",
1071
- projects: "salvage",
1072
- prompts: "none",
1073
- limits: "none",
1074
- a2a: "salvage",
1284
+ models: "salvage", // 留:条目 = 一个目录模型(及 `roles` 里的一个角色覆盖);缺席 = 少一个模型 / 一个角色回落到缺省 —— 选路变了,可达面没变(被引用的模型缺席 ⇒ 引用悬空 ⇒ 整域缺省,既有律)
1285
+ rosters: "none", // 收:条目 = 一台 worker 的模型名册;缺席 ⇒ 该 worker 回落到整份目录 = 放宽
1286
+ skills: "salvage", // 留:条目 = 一份下发的技能(含它的工具 allow / deny 名单);缺席 = 少一份技能 —— 已知缺口:同名出厂技能回位、deny 名单坏元素被逐元素剔,收口承诺见 CHANGELOG 已知限制与收口承诺
1287
+ mcp: "salvage", // 留:条目 = 一台工具源;缺席 = 该台不挂载 —— 已知缺口:名字不再被部署占位(请求侧同名注入只在放开的单用户车道),见 CHANGELOG 已知限制
1288
+ plugins: "none", // 收:条目 = 可执行面的来源引用,hooks(含 PreToolUse / PermissionRequest 守卫)随引用走;缺席 = 守卫缺席 = 放宽
1289
+ scenarios: "none", // 收:条目 = 覆盖内建场景名的工具面声明;缺席 = 同名内建(更宽的工具面)复活 = 放宽
1290
+ systems: "salvage", // 留:条目 = 一个外部系统的凭据与可调 worker 名单(授权);缺席 = 少一份授权
1291
+ collab: "salvage", // 留:条目 = 一个协作模板(预算闸随模板走);缺席 = 少一个可选模板,已有的闸一个不松
1292
+ workers: "none", // 收:条目 = 一台 worker 的声明;缺席 = 「不再声明」,对账器会把它撤下(破坏性),它的名册绑定也一并消失
1293
+ hosts: "salvage", // 留:条目 = 一个排布目标;缺席 = 少一个目标(待批 / drain / 停用的条目缺席同样不可排)
1294
+ governance: "none", // 收:条目 = 命令策略行 / 审批要求;缺席 = 护栏静默消失 = 放宽
1295
+ entitlement: "none", // 收:条目 = 档 / 主体 / 绑定 / 预算组;缺席 = 谁能做什么变了(限制、配额、预算成员随条目走)
1296
+ execution: "none", // 收:条目 = 执行车道 / 公钥登记;缺席 = 执行授权的面变了
1297
+ projects: "salvage", // 留:条目 = 一条项目登记(加性登记簿,不是准入门);缺席 = 少一份默认记忆 scope 的种子(消费方查表 miss 不 fail)
1298
+ prompts: "none", // 收:条目受 digest 约束;缺席 = digest 不再成立,或范围文本替换掉某台 worker 的 artifact(是替换不是收窄)
1299
+ limits: "none", // 收:条目 = 已发布上限的一行;缺席 = 发布的天花板变了(本域是这些上限的唯一发布位)
1300
+ a2a: "salvage", // 留:条目 = 一个出站对端;缺席 = 少一个对端(凭据引用整体原子,见 ATOMIC_SALVAGE;名字占位同 mcp,见 CHANGELOG 已知限制)
1075
1301
  };
1076
1302
  /**
1077
1303
  * Merge every domain into the effective config a consumer pulls. Shared by all store impls.
@@ -1221,13 +1447,18 @@ const isWireCarriedDomain = (k) => WIRE_CARRIED_DOMAINS.includes(k);
1221
1447
  * 缺席 ⇒ 按包自己造的空文档判(`COPY_PROTOTYPE`,读不到污染值)。告警交回给调用方发。
1222
1448
  */
1223
1449
  function readSkillsManifest(raw) {
1224
- const parse = (doc) => strictParse(SkillsManifestSchema, "skills", doc);
1450
+ // 整份判与视图面域读同一条律(22.0.0;skills 是逐条丢弃域,清单是它的线上形):过 schema,且清单条目体内没有被剥的键 —— 有 ⇒ 走逐条抢救,带未知键的条目丢它自己。
1451
+ const parse = (doc) => {
1452
+ const parsed = strictParse(SkillsManifestSchema, "skills", doc);
1453
+ refuseEntryHeldStrippedKeys("skills", SkillsManifestSchema, doc, parsed, "skills");
1454
+ return parsed;
1455
+ };
1225
1456
  try {
1226
1457
  return { skills: parse(raw ?? emptyDocument()), warnings: [] };
1227
1458
  }
1228
1459
  catch (unreadable) {
1229
1460
  try {
1230
- const { parsed, salvage } = salvageThenParse(SkillsManifestSchema, raw, parse, unreadable);
1461
+ const { parsed, salvage } = salvageThenParse(SkillsManifestSchema, "skills", raw, parse, unreadable);
1231
1462
  return { skills: parsed, warnings: salvage.dropped.map((d) => entryDroppedWarning("skills", d)) };
1232
1463
  }
1233
1464
  catch {