@sema-agent/settings-schema 20.0.0 → 22.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.
- package/CHANGELOG.md +159 -0
- package/README.md +48 -1
- package/conformance/VERSION +1 -1
- package/conformance/cases/c01-entry-salvage-then-typo/expected.json +2 -32
- package/conformance/cases/c01-entry-salvage-then-typo/meta.json +1 -1
- package/conformance/cases/c03-literal-dotted-top-key/expected.json +14 -16
- package/conformance/cases/c03-literal-dotted-top-key/meta.json +1 -1
- package/conformance/cases/c11-unicode-unknown-keys/expected.json +1 -1
- package/conformance/cases/c24-valid-entries-with-unknown-keys/expected.json +3 -24
- package/conformance/cases/c24-valid-entries-with-unknown-keys/meta.json +1 -1
- package/conformance/cases/c28-large-document-over-1mb/expected.json +1 -1
- package/conformance/cases/c34-skills-content-vs-manifest/expected.json +38 -16
- package/conformance/cases/c34-skills-content-vs-manifest/input.json +5 -0
- package/conformance/cases/c34-skills-content-vs-manifest/meta.json +1 -1
- package/conformance/cases/c42-s792-unknown-key-secret-redacted/expected.json +27 -14
- package/conformance/cases/c42-s792-unknown-key-secret-redacted/input.json +6 -0
- package/conformance/cases/c42-s792-unknown-key-secret-redacted/meta.json +1 -1
- package/conformance/cases/c76-projects-entry-salvage-nested/expected.json +9 -15
- package/conformance/cases/c76-projects-entry-salvage-nested/meta.json +1 -1
- package/conformance/cases/cli03-credential-pasted-into-unknown-key/expected.json +3 -18
- package/conformance/cases/cli03-credential-pasted-into-unknown-key/meta.json +1 -1
- package/conformance/cases/t03-prototype-name-key-not-swallowed/expected.json +3 -31
- package/conformance/cases/t03-prototype-name-key-not-swallowed/meta.json +1 -1
- package/conformance/cases/t04-secret-literal-never-in-warning-value/expected.json +3 -34
- package/conformance/cases/t04-secret-literal-never-in-warning-value/meta.json +1 -1
- package/conformance/cases/z02-every-domain-unknown-key/expected.json +1 -1
- package/dist/config-fns.d.ts +40 -16
- package/dist/config-fns.js +295 -79
- package/dist/retired-envs.js +2 -0
- package/dist/tier-words.d.ts +1 -1
- package/dist/tier-words.js +1 -1
- package/docs/CONFORMANCE.md +8 -5
- package/docs/CONSUMER-INTEGRATION.md +41 -2
- package/llms-full.txt +3 -2
- package/llms.txt +8 -5
- package/package.json +1 -1
package/dist/config-fns.js
CHANGED
|
@@ -304,17 +304,19 @@ function outgoingSegment(seg) {
|
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
306
306
|
* 一条条目为什么被丢 —— **机读原因**的闭集(S-1295)。词与**丢弃点**一一对应:`DroppedEntry` 只有一个铸点
|
|
307
|
-
* (`droppedEntry`),它的上游判据(`judgeEntry
|
|
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
|
|
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
|
-
/**
|
|
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
|
|
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 {
|
|
426
|
-
return judged.value.success ?
|
|
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
|
-
*
|
|
460
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
472
|
-
|
|
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
|
|
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 :
|
|
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,
|
|
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,
|
|
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
|
-
|
|
766
|
-
|
|
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
|
-
|
|
769
|
-
|
|
770
|
-
|
|
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
|
-
|
|
773
|
-
|
|
774
|
-
|
|
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
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
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
|
-
|
|
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.
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
910
|
-
*
|
|
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
|
|
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 =
|
|
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) =>
|
|
1134
|
+
const { parsed, salvage } = salvageThenParse(DOMAIN_SCHEMAS[domain], domain, raw, (doc) => parseForView(domain, doc), unreadable);
|
|
931
1135
|
if (onWarning) {
|
|
932
|
-
// 坐标律(S-323b)
|
|
933
|
-
//
|
|
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,
|
|
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 /
|
|
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 {
|
|
@@ -1019,8 +1224,14 @@ export const DOMAIN_READ_FALLBACK = {
|
|
|
1019
1224
|
/** Per-domain ENTRY-SALVAGE policy (12.3.0, S-1494) — may the view-face domain reader ({@link parseDomainSalvaged}) drop single bad
|
|
1020
1225
|
* entries (an array element, a Record value, and — recursively — a bad entry inside a surviving entry) and read the rest?
|
|
1021
1226
|
* **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
|
-
*
|
|
1227
|
+
* `"salvage"` = drop each bad entry, name it (`entry-dropped`, coordinate + identity + reason word), keep the rest. A bad entry is one that
|
|
1228
|
+
* 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
|
|
1229
|
+
* (`entry-unknown-key`): loading it stripped would load something other than what the operator wrote (a misspelt narrowing key widens
|
|
1230
|
+
* that entry). The view face reads the whole document by the same rule, so a collection whose entries ALL carry unknown keys is not
|
|
1231
|
+
* loaded stripped either (zero survivors ⇒ the domain is unreadable ⇒ {@link DOMAIN_READ_FALLBACK}). An unknown key outside every entry
|
|
1232
|
+
* (domain top level, a top-level plain object field) is still stripped and named (`unknown-keys-dropped`).
|
|
1233
|
+
* `"none"` = never drop a single entry: the first bad entry makes the whole domain unreadable. An unknown key inside an entry of such a
|
|
1234
|
+
* domain is stripped and named, as before 22.0.0 — those domains drop nothing, so the strip warning is the reader's signal.
|
|
1024
1235
|
* A `satisfies Record<DomainName,…>` forces every FUTURE domain to answer this explicitly (compile error until classified).
|
|
1025
1236
|
*
|
|
1026
1237
|
* **View face only.** The document face never salvages: `parseDomain` / `validateDomain` / `writeDomainFile` judge the whole
|
|
@@ -1221,13 +1432,18 @@ const isWireCarriedDomain = (k) => WIRE_CARRIED_DOMAINS.includes(k);
|
|
|
1221
1432
|
* 缺席 ⇒ 按包自己造的空文档判(`COPY_PROTOTYPE`,读不到污染值)。告警交回给调用方发。
|
|
1222
1433
|
*/
|
|
1223
1434
|
function readSkillsManifest(raw) {
|
|
1224
|
-
|
|
1435
|
+
// 整份判与视图面域读同一条律(22.0.0;skills 是逐条丢弃域,清单是它的线上形):过 schema,且清单条目体内没有被剥的键 —— 有 ⇒ 走逐条抢救,带未知键的条目丢它自己。
|
|
1436
|
+
const parse = (doc) => {
|
|
1437
|
+
const parsed = strictParse(SkillsManifestSchema, "skills", doc);
|
|
1438
|
+
refuseEntryHeldStrippedKeys("skills", SkillsManifestSchema, doc, parsed, "skills");
|
|
1439
|
+
return parsed;
|
|
1440
|
+
};
|
|
1225
1441
|
try {
|
|
1226
1442
|
return { skills: parse(raw ?? emptyDocument()), warnings: [] };
|
|
1227
1443
|
}
|
|
1228
1444
|
catch (unreadable) {
|
|
1229
1445
|
try {
|
|
1230
|
-
const { parsed, salvage } = salvageThenParse(SkillsManifestSchema, raw, parse, unreadable);
|
|
1446
|
+
const { parsed, salvage } = salvageThenParse(SkillsManifestSchema, "skills", raw, parse, unreadable);
|
|
1231
1447
|
return { skills: parsed, warnings: salvage.dropped.map((d) => entryDroppedWarning("skills", d)) };
|
|
1232
1448
|
}
|
|
1233
1449
|
catch {
|
package/dist/retired-envs.js
CHANGED
|
@@ -77,6 +77,8 @@ export const RETIRED_ENVS = [
|
|
|
77
77
|
["UNATTENDED_PERMISSION_MODE", "since server 7.109.0 the unattended legs (leader workers and their repair legs, run-local, and their durable resumes) always run permissionMode \"default\" with an approver that answers by ask class: a machine answers only \"ordinary\" asks, and every other class goes to the leg's approver seat (run-local's terminal prompt) or parks / is refused — there is no mode to choose", "removed"],
|
|
78
78
|
// 执行车道总开关:每个部署都点名自己的车道之后它恒真(「点名了没有」只剩一个答者 REMOTE_EXEC),留着 = 两个键答一个问题;「没有执行环境」也是一个声明(REMOTE_EXEC=none)。
|
|
79
79
|
["REQUIRE_EXECUTION_LANE", "REMOTE_EXEC", "replaced", "every deployment names its execution lane; REMOTE_EXEC=none declares one with no execution environment"],
|
|
80
|
+
// 沙箱车道的 LSP 桥整只删除:e2b / k8s 车道本来就不挂 LSP,这个旋钮没有可 rename 的目标。host 车道的开关是另一个键 LSP_HOST_ENABLED(缺省开,活旋钮,不在本表)。
|
|
81
|
+
["LSP_ENABLED", "the sandbox-lane LSP bridge was removed (e2b / k8s lanes mount no LSP); unset it — the host lane's switch is LSP_HOST_ENABLED", "removed"],
|
|
80
82
|
];
|
|
81
83
|
// 冻结:拿到导出的人改不了拒启判据(读拒句的与投影 wire 的是同一个数组对象)。
|
|
82
84
|
for (const row of RETIRED_ENVS)
|
package/dist/tier-words.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare function tierLadderFrom<S extends TierWord>(tier: S): LadderFrom<
|
|
|
27
27
|
* · 档位词 ⇒ 它的梯({@link tierLadderFrom})上第一个有绑定的档;摘完没有任何绑定 ⇒ 只认目录键;
|
|
28
28
|
* · CC 档位别名 ⇒ 经它对应的档位;`best` ⇒ 档序里第一个有绑定的档;别的词 ⇒ 落不到。
|
|
29
29
|
* `has` = 调用方的「这个名是目录里一条可服务(启用)的条目」;`tiers` = `resolveActiveTiers` 的读数(原表,未摘)—— 它的键只有五个档位词
|
|
30
|
-
* (档位组的绑定表在 schema
|
|
30
|
+
* (档位组的绑定表在 schema 里只收这五个键;带别的键的档位组在视图面整组丢 —— 22.0.0,文档面照旧剥键),所以只按档位词读表。
|
|
31
31
|
*/
|
|
32
32
|
export declare function landCatalogWord(word: string, has: (name: string) => boolean, tiers: Readonly<Partial<Record<TierWord, string>>> | undefined): string | undefined;
|
|
33
33
|
export {};
|
package/dist/tier-words.js
CHANGED
|
@@ -20,7 +20,7 @@ const isTierWord = (word) => TIER_ORDER.includes(word);
|
|
|
20
20
|
* · 档位词 ⇒ 它的梯({@link tierLadderFrom})上第一个有绑定的档;摘完没有任何绑定 ⇒ 只认目录键;
|
|
21
21
|
* · CC 档位别名 ⇒ 经它对应的档位;`best` ⇒ 档序里第一个有绑定的档;别的词 ⇒ 落不到。
|
|
22
22
|
* `has` = 调用方的「这个名是目录里一条可服务(启用)的条目」;`tiers` = `resolveActiveTiers` 的读数(原表,未摘)—— 它的键只有五个档位词
|
|
23
|
-
* (档位组的绑定表在 schema
|
|
23
|
+
* (档位组的绑定表在 schema 里只收这五个键;带别的键的档位组在视图面整组丢 —— 22.0.0,文档面照旧剥键),所以只按档位词读表。
|
|
24
24
|
*/
|
|
25
25
|
export function landCatalogWord(word, has, tiers) {
|
|
26
26
|
if (has(word))
|
package/docs/CONFORMANCE.md
CHANGED
|
@@ -100,14 +100,17 @@ expect(report.ok).toBe(true);
|
|
|
100
100
|
多重集 `refIssues`,金样同存同比(坐标不同 ⇒ diff;句子不比)。都过 ⇒ `effective` = 文档集里每个键 → 受理后的域文档(**只含提交的键,
|
|
101
101
|
不补缺席域**;空集受理成 `{}`),告警面 = ① 铸的剥键 / 承运告警(11.0.0 起不再恒空),元数据回报 harness 注入的那一份。
|
|
102
102
|
- **律**(金样逐条核,`test/conformance-strict-write-8.0.0.test.ts`):严写**拒** ⇔ 文档集里有不是域名的键 ∨ 读腿整条拒 ∨
|
|
103
|
-
|
|
103
|
+
读腿在提交的某个域上抢救过**坏条目**(`entry-dropped` / `domain-defaulted` / `hosts-grandfathered`);否则严写**受理**,受理形 =
|
|
104
104
|
读腿 effective 里那几格,告警面 = 读腿在提交域上铸的剥键 / 承运告警(两腿同一只判据铸);另有悬空引用一臂(律只推 roster → 模型目录
|
|
105
105
|
这一类,今天语料里只有这一类)。读腿只剥键 / 只承运的地方严写照样受理 —— 那是解析自己的语义,不是抢救。
|
|
106
|
-
|
|
106
|
+
22.0.0 起两腿在「条目只多带未知键」上分开:读腿丢那一条(`entry-unknown-key`),文档面剥键受理。律对此一臂:这种丢弃不算抢救;
|
|
107
|
+
受理形删掉那几处坐标上的条目 = 读腿那一格,且那里装着读腿点名的同一条(身份对得上);每处坐标下严写至少剥了一个键;严写告警面减去这些条目内的键
|
|
108
|
+
= 读腿的剥键 / 承运告警。零幸存者(整域缺省)且全因未知键的 case,冻结的 `domain-defaulted` 不带理由,手登在测试里(一行一条理由、反向核)。
|
|
109
|
+
今天 101 条语料:44 受理(其中 6 条读腿丢了带未知键的条目)、57 拒(读腿抢救过坏条目的 32 条;读腿整条拒的 17 条;带非域名键的 7 条;悬空引用的 1 条)。
|
|
107
110
|
- **为什么不派生**:严写结局不是读结局的一种表示变换(读腿抢救处严写拒);从 `domains` 期望派生会让一份金样的错同时改写两条腿。
|
|
108
111
|
每条 case 的严写金样显式入库、各自冻结,`why` 写在金样旁边。
|
|
109
112
|
- **负控**(`test/conformance-mutation.test.ts` 第十一靶):把 `parseDomainLoud` 换成读腿的宽松解析 ⇒ 严写腿**恰好**红在读腿抢救过的
|
|
110
|
-
那
|
|
113
|
+
那 38 条上(32 条金样拒、宽松受理;6 条金样受理、宽松读丢了带未知键的条目 ⇒ 受理形不同);把非域名键静默跳过 ⇒ 恰好红在那 7 条上。
|
|
111
114
|
|
|
112
115
|
## 2. 报告形
|
|
113
116
|
|
|
@@ -216,7 +219,7 @@ sema-test 的读数,是本仓自己重跑 `node scripts/conformance-historical.m
|
|
|
216
219
|
| id | 影响的腿 | 动了什么 |
|
|
217
220
|
|---|---|---|
|
|
218
221
|
| `T1-wire-carried-domains` | wire | `buildEffective` 恒物化每个域;wire 对承运表 `WIRE_CARRIED_DOMAINS`(`prompts`、`a2a`)按**在场性**挂回 —— 线上读口不编造生产方没发的域:缺席进缺席出;在场时 `prompts` 是**未解析的原文档**,`a2a` 是域腿读数。**由常量派生,不手抄域名**;覆盖律要求表里每个域都有语料让两腿在它上面真的分开 |
|
|
219
|
-
| `T2-skills-representation` | wire | 域形带 `content`,wire 形带 `contentHash`(manifest);判据 schema 随表示走,于是 wire 腿**没有** skills 的剥键告警 |
|
|
222
|
+
| `T2-skills-representation` | wire | 域形带 `content`,wire 形带 `contentHash`(manifest);判据 schema 随表示走,于是 wire 腿**没有** skills 的剥键告警(22.0.0 起条目体内的未知键两腿同读:带它的那一条被丢,`entry-dropped` / `entry-unknown-key`) |
|
|
220
223
|
| `T3-non-portable-domains` | local-root | `config.d/` 只读 `PORTABLE_DOMAINS`;其余域取 schema 默认 + `unread-config-file{non-portable-domain}`。**由常量派生,不手抄域名** |
|
|
221
224
|
| `T4-unknown-top-level-key` | wire + local-root | wire 是 open-world,不认识的顶层键**逐字承运**;`domains` 腿按域名取文档故无声;local-root 报 `unread-config-file{not-a-domain}` |
|
|
222
225
|
| `T5-file-layer-first` | local-root | `config.d/<域>.json` 必须是 JSON **对象**(空文件 / `null` / 数组 / 标量一律 fail-closed),这一层在域解析**之前** |
|
|
@@ -242,7 +245,7 @@ sema-test 的读数,是本仓自己重跑 `node scripts/conformance-historical.m
|
|
|
242
245
|
会在告警面报 `missing` / `extra`;**消费方自己入库的语料**(例:web-admin `test/conformance/cases/wa05-*` 在
|
|
243
246
|
被丢的 skills 条目上断言 `entry-dropped`)提货时要按新读数重新加冕 —— additive 字段让旧金样少一个键,
|
|
244
247
|
是提货成本,不是读法分歧。`reasonCode`(10.1.0:为什么丢的机读闭集词)同理在投影里 —— 语料里 `entry-key-invalid` /
|
|
245
|
-
`entry-schema-invalid` 由 JSON 表达得出;`entry-unreadable`(判的过程抛了)需要病态访问器,JSON 表达不出,由
|
|
248
|
+
`entry-schema-invalid` / `entry-unknown-key`(22.0.0,c03 / c76)由 JSON 表达得出;`entry-unreadable`(判的过程抛了)需要病态访问器,JSON 表达不出,由
|
|
246
249
|
`test/dropped-entry-reason-code-s1295.test.ts` 看着;web-admin 自有语料同样要在提货时按新读数重新加冕。
|
|
247
250
|
- **多重集**而不是集合:同一 kind 在同一域上发两次是有信息的,去重会把「报了两条」读成「报了一条」。
|
|
248
251
|
- 一条告警**内部**的集合字段(`keys` / `droppedNames`)同样按**袋**比:它们的顺序来自文档枚举次序,契约
|