@sema-agent/settings-schema 32.0.0 → 33.1.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 +275 -0
- package/README.md +54 -2
- package/conformance/VERSION +1 -1
- package/dist/api/wire-scalars.d.ts +3 -2
- package/dist/api/wire-scalars.js +3 -2
- package/dist/cli.d.ts +4 -1
- package/dist/cli.js +8 -3
- package/dist/config-dir-migration.d.ts +17 -1
- package/dist/config-dir-migration.js +90 -31
- package/dist/config-fns.d.ts +18 -2
- package/dist/config-fns.js +134 -15
- package/dist/conformance/warnings.d.ts +1 -1
- package/dist/conformance/warnings.js +8 -2
- package/dist/declared-capture.js +1 -1
- package/dist/fleet.d.ts +125 -7
- package/dist/fleet.js +138 -3
- package/dist/read-sentences.d.ts +67 -0
- package/dist/read-sentences.js +86 -0
- package/dist/retired-form.d.ts +2 -0
- package/dist/retired-form.js +4 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.js +3 -3
- package/docs/API-SURFACE.md +26 -4
- package/docs/CONFORMANCE.md +2 -2
- package/docs/CONSUMER-INTEGRATION.md +53 -0
- package/llms-full.txt +6 -3
- package/llms.txt +6 -2
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DroppedEntryIdentity } from "./config-fns.js";
|
|
1
2
|
import { type ConfigDDocumentName } from "./config-d-file.js";
|
|
2
3
|
import { type MigrationReceipt } from "./one-time-migrations.js";
|
|
3
4
|
/** 注入的 I/O(本模块不碰 `node:fs`)。`writeFileAtomic` 必须原子(写临时文件再改名):半写的域文档比旧文档更糟。 */
|
|
@@ -7,13 +8,16 @@ export interface ConfigDirectoryIo {
|
|
|
7
8
|
writeFileAtomic(path: string, text: string): Promise<void>;
|
|
8
9
|
}
|
|
9
10
|
/** 一条拒绝 —— 迁移步的拒(收据 `refused`)与整域终判的拒**同一套形**:`migration`(整域终判拒为 `null`)/ `document` / `path`(相对该域文档,出门形)/ `appliedAs: "refused"` / `reason`。
|
|
10
|
-
* 句子来自本包唯一的脱敏器,坐标段与句子都是出门形、不带值。
|
|
11
|
+
* 句子来自本包唯一的脱敏器,坐标段与句子都是出门形、不带值。
|
|
12
|
+
* `identity`(可缺,加性):坐标落在某一条条目体内(`<集合字段>.<下标>…`)时那一条的身份 —— 连接器 / worker / 模型的名字(只带可披露的名与 id,与读腿告警同一只读法 `readEntryIdentity`),
|
|
13
|
+
* 坐标本身只给下标,运维拿它找到「是哪一条」;坐标不在条目下(域级的键、整份文档)⇒ 键缺席。 */
|
|
11
14
|
export type ConfigDirectoryRefusal = {
|
|
12
15
|
readonly migration: string | null;
|
|
13
16
|
readonly document: string;
|
|
14
17
|
readonly path: string;
|
|
15
18
|
readonly appliedAs: "refused";
|
|
16
19
|
readonly reason: string;
|
|
20
|
+
readonly identity?: DroppedEntryIdentity;
|
|
17
21
|
};
|
|
18
22
|
export type ConfigDirectoryMigration = {
|
|
19
23
|
readonly kind: "unreadable";
|
|
@@ -46,6 +50,18 @@ export interface MigrateConfigDirectoryOptions {
|
|
|
46
50
|
readonly io: ConfigDirectoryIo;
|
|
47
51
|
/** 只判、不写:有改动且整域判得过 ⇒ `pending`。默认 `false`。 */
|
|
48
52
|
readonly check?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* 整域终判判**哪些**文档(可选入参,缺省 = 此前的行为)。**这不是兼容开关** —— 两个调用方问的是两个不同的问题,各自要的是自己那一问的答案:
|
|
55
|
+
* · `"changed"`(缺省)—— 问「**迁移有没有把它改坏**」:只判迁移改过的文档(要写回的那一份必须读得进);迁移没碰的文档读不读得进是读者的事。引擎起服对本地 `config.d`
|
|
56
|
+
* 的迁移问的是这一问:一份陈旧的文档不该挡住同目录里别的文档的迁移(同一个目录里别的可迁文档照迁,陈旧的那份由读腿按它的墓碑 / 档位处置);
|
|
57
|
+
* · `"present"` —— 问「**这个目录现在干不干净**」:在场的**每一份**覆盖面内文档都判(含 retired 域:带事实的墓碑文档读侧拒,这里同拒),判官是文档面那几只
|
|
58
|
+
* (`parseDomain` / `parseRemoteExecDocument` / 墓碑判 `refuseRetiredDomain`,不另写第二份判形)。不过 ⇒ `refused`、一字不写,`refused[]` 点名文档与坐标;迁移没碰的那几份,`reason` 说读腿会怎么处置它与出路;
|
|
59
|
+
* 迁移改过、改完仍判不过的那一份(两个值下都有),`reason` 是判官的原句(`parseDomain` 出门前已脱敏;不带后果与出路、不折行、不剥控制符),出路在整份 `why`(手改后重跑)。命令行 `migrate`(`--check` 与真跑都传它)问的是这一问:运维跑完它不该带着一份文档面判不过的文档上线。
|
|
60
|
+
* 判官是文档面那一只(`parseDomain`),它与读腿(视图面)两个方向上不同,这一问的答案因此不等于「读腿读不读得干净」(已知的边):
|
|
61
|
+
* 比读腿宽(只在逐条丢弃域里:视图面只在那里拒条目体内被剥的键;不逐条丢的域两面都剥键受理、答得一样)—— 条目只因带读侧不认识的键,文档面剥键受理:视图面丢那一条,集合里每一条都这样(零幸存者)时整域退缺省(`models` 读成空目录)/ 整域拒,这一问仍答「干净」;
|
|
62
|
+
* 比读腿严 —— 逐条丢弃域里一条 schema 不过的条目:视图面只丢它、其余照读,这一问答 `refused`。
|
|
63
|
+
*/
|
|
64
|
+
readonly judge?: "changed" | "present";
|
|
49
65
|
}
|
|
50
66
|
export interface MigrateConfigDocumentsOptions {
|
|
51
67
|
/** 覆盖面:调用方读的文档名集 —— 与 {@link MigrateConfigDirectoryOptions.documents} 同一个词、同一个律(覆盖面内没给的文档 = 从未设过;覆盖面外的键不读、不判、不进结果;拼错的名字 ⇒ 抛 `TypeError`)。 */
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
* ## 结果是一个闭集({@link ConfigDirectoryMigration}),调用方穷举
|
|
15
15
|
* · `unreadable` —— 读不了目录 / 某份文件,或某份文档是坏文件(空 / 纯空白 / 坏 JSON / 不是 JSON 对象,与 `FileConfigStore` 同一只判、同一句)。一字不写。
|
|
16
16
|
* · `no-documents`—— 覆盖面内一份文档都没找到;带回目录清单 `entries`(调用方自己判这是「填错了目录」还是「真空的新目录」)。一字不写。
|
|
17
|
-
* · `refused` —— 迁移步拒(收据 `refused`:要猜才改得动的形)
|
|
17
|
+
* · `refused` —— 迁移步拒(收据 `refused`:要猜才改得动的形)**或**整域终判不过(名字 / 路由唯一这类跨行规则只有整域判得出):缺省只判要写回的文档;入参 `judge: "present"` 时在场的每一份文档都判
|
|
18
|
+
* (含迁移不碰的陈旧形:带事实的 retired 域文档、已不迁移的旧键与旧值 —— 文档面判官判不过的,这里同拒)。一字不写。判官是文档面那一只,与读腿(视图面)两个方向上不同:
|
|
19
|
+
* 比读腿宽(只在逐条丢弃域里:视图面只在那里拒条目体内被剥的键;不逐条丢的域两面都剥键受理、答得一样)—— 条目只因带读侧不认识的键:
|
|
20
|
+
* 视图面丢那一条,集合里每一条都这样(零幸存者)时整域退缺省 / 整域拒,文档面剥键受理、这里判得过;
|
|
21
|
+
* 比读腿严 —— 逐条丢弃域里一条 schema 不过的条目:视图面只丢它、其余照读,这里整份拒。
|
|
18
22
|
* · `noop` —— 读到了文档、没有要改的。
|
|
19
23
|
* · `pending` —— `check: true` 且有改动、整域判得过:一字不写。
|
|
20
24
|
* · `applied` —— 已写回改过的文档 —— 中途断掉再跑一次,迁移照样恒等收尾(写过的文档已是新形,再迁零改动)。
|
|
@@ -27,18 +31,23 @@
|
|
|
27
31
|
* 覆盖面、「没改的文档不判」「迁移不许越过覆盖面去写」与目录形逐字同;层的合并(层序 / 覆盖 / 托管锁)不在这里 —— 一层一次调用。
|
|
28
32
|
*/
|
|
29
33
|
import { z } from "zod";
|
|
30
|
-
import { formatConfigPath, parseDomain } from "./config-fns.js";
|
|
34
|
+
import { DOMAIN_ENTRY_SALVAGE, DOMAIN_READ_FALLBACK, formatConfigPath, parseDomain, readEntryIdentityAt, redactSecrets, refuseRetiredDomain } from "./config-fns.js";
|
|
31
35
|
import { configDDocumentText, judgeConfigDText, judgeConfigDValue, parseRemoteExecDocument } from "./config-d-file.js";
|
|
32
36
|
import { fsFailureMessage } from "./fs-failure.js";
|
|
37
|
+
import { stripControlAndBidi } from "./control-and-bidi.js";
|
|
33
38
|
import { isPlainJsonObject } from "./plain-json-object.js";
|
|
34
39
|
import { migrateStoredDocuments } from "./one-time-migrations.js";
|
|
40
|
+
import { issueSentence, readConsequenceSentence } from "./read-sentences.js";
|
|
35
41
|
import { REMOTE_EXEC_DOCUMENT } from "./remote-exec.js";
|
|
36
42
|
import { isDomainName, isRetiredDomainName } from "./types.js";
|
|
37
43
|
const isConfigDirectoryDocument = (name) => isDomainName(name) || isRetiredDomainName(name) || name === REMOTE_EXEC_DOCUMENT;
|
|
38
|
-
/**
|
|
44
|
+
/** 一份文档的整文档终判 —— 读侧那几只判官各读一遍:域过 `parseDomain`,`remote-exec` 过 `loadRemoteExec` 那一只 `parseRemoteExecDocument`,retired 域过墓碑判
|
|
45
|
+
* `refuseRetiredDomain`(带事实 ⇒ 抛 `RetiredDomainError`;今天没有一步改 retired 域的文档,所以只有 `judge: "present"` 会判到它)。 */
|
|
39
46
|
function judgeWholeDocument(name, doc) {
|
|
40
47
|
if (isDomainName(name))
|
|
41
48
|
parseDomain(name, doc);
|
|
49
|
+
else if (isRetiredDomainName(name))
|
|
50
|
+
refuseRetiredDomain(name, doc);
|
|
42
51
|
else if (name === REMOTE_EXEC_DOCUMENT)
|
|
43
52
|
parseRemoteExecDocument(doc);
|
|
44
53
|
}
|
|
@@ -61,42 +70,89 @@ export function reportReceipt(r) {
|
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
}
|
|
73
|
+
/** 一条拒带上它坐标所在条目的身份(有才带键;读法是读腿告警同一只 `readEntryIdentityAt`)。`doc` = 坐标所指的那份文档(迁移步的拒指入参的文档,整域终判的拒指迁移后的文档)。 */
|
|
74
|
+
function withIdentity(refusal, doc, path) {
|
|
75
|
+
const identity = readEntryIdentityAt(doc, path);
|
|
76
|
+
return identity === undefined ? refusal : { ...refusal, identity };
|
|
77
|
+
}
|
|
64
78
|
/** 整域终判的一条拒(issue 来自 `parseDomain`,已过本包唯一的脱敏器 —— 坐标段与句子都是出门形)。 */
|
|
65
79
|
function wholeDomainRefusal(document, path, reason) {
|
|
66
80
|
return { migration: null, document, path: formatConfigPath(path), appliedAs: "refused", reason };
|
|
67
81
|
}
|
|
82
|
+
/** 读腿对这份文档读不进时的处置(按文档名):域 ⇒ 两张读腿表的答案;retired 域 ⇒ 带事实就拒;`remote-exec` ⇒ `loadRemoteExec` 拒。 */
|
|
83
|
+
function consequenceOf(name) {
|
|
84
|
+
if (isDomainName(name))
|
|
85
|
+
return readConsequenceSentence(name, { fallback: DOMAIN_READ_FALLBACK[name], salvage: DOMAIN_ENTRY_SALVAGE[name] });
|
|
86
|
+
if (isRetiredDomainName(name))
|
|
87
|
+
return `the reader refuses the whole "${name}" document while it carries any key`;
|
|
88
|
+
return `the reader refuses the whole ${name} document`;
|
|
89
|
+
}
|
|
68
90
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
91
|
+
* 迁移没碰的文档的一条拒句:判官的原句(已折成一行、剥过一行回显的剥除集)· 读腿会怎么处置它 · 出路。出路只有一条:
|
|
92
|
+
* retired 域的判官原句就是墓碑句,它自带出路(把值手抄到今天的位置、删掉旧文档),这里不再接第二条;别的文档的出路是「在这份文件里手改」。
|
|
93
|
+
* 整句出门前过本包唯一的脱敏器:剥掉隔开的字符可以把两段拼成一个密钥形,脱敏判在剥之后、对最终的那一串做。
|
|
72
94
|
*/
|
|
73
|
-
function
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
function untouchedReason(name, sentence) {
|
|
96
|
+
const parts = isRetiredDomainName(name) ? [sentence, consequenceOf(name)] : [sentence, consequenceOf(name), `fix it in ${name}.json by hand`];
|
|
97
|
+
return redactSecrets(parts.join("; "));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 一份文档的整文档终判的拒(同一套形:每条 issue 一条 `ConfigDirectoryRefusal`,`migration: null`)。`untouched` = 这份文档迁移没碰(只有 `judge: "present"` 才会判到):
|
|
101
|
+
* 它的拒句除判官的原句外,还说读腿会怎么处置它与出路({@link untouchedReason})—— 迁移改过的文档是**我们要写的**那一份,拒句就是判官的原句(整份 `why` 说「手改后重跑」)。
|
|
102
|
+
*/
|
|
103
|
+
function wholeDocumentRefusals(name, doc, untouched) {
|
|
104
|
+
try {
|
|
105
|
+
judgeWholeDocument(name, doc);
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
const found = err instanceof z.ZodError
|
|
110
|
+
? err.issues.map((i) => ({ path: i.path, message: i.message, sentence: issueSentence(i) }))
|
|
111
|
+
: [{ path: [], message: messageOf(err), sentence: issueSentence({ message: messageOf(err) }) }];
|
|
112
|
+
return found.map((i) => withIdentity(wholeDomainRefusal(name, i.path, untouched ? untouchedReason(name, i.sentence) : i.message), doc, i.path));
|
|
77
113
|
}
|
|
78
|
-
|
|
114
|
+
}
|
|
115
|
+
/** 一批拒的**所在**,一行(stderr 用):`<文档>.json (<坐标>)`,同一处只列一次,最多三处。坐标里有用户写的键段:先剥一行回显的剥除集,
|
|
116
|
+
* 剥完再过本包唯一的脱敏器(剥掉隔开的字符可以拼出一个密钥形,判在剥之后)。 */
|
|
117
|
+
function refusedLocations(refused) {
|
|
118
|
+
const seen = [...new Set(refused.map((r) => (r.path === "" ? `${r.document}.json` : `${r.document}.json (${r.path})`)))];
|
|
119
|
+
return redactSecrets(stripControlAndBidi(seen.length <= 3 ? seen.join(", ") : `${seen.slice(0, 3).join(", ")}, …`));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 迁移结果 → 结论。顺序:迁移步拒 → 无改动 ⇒ noop → **整域终判**(`judge: "changed"`:要写回的每个域文档 —— 改过的、新建的;`"present"`:在场的每一份)→ 有改动。整域终判在 `check` 之前:否则同一个目录 `check` 报 pending、
|
|
123
|
+
* 真跑写出一份读侧必拒的文档。`"changed"` 下没改的文件不归这里判(迁移不碰它,它读不读得进是读者的事;引擎起服要的是这一种);`"present"` 下判它们,
|
|
124
|
+
* 文档面判不过 ⇒ 同样 `refused`(命令行:运维跑完 `migrate` 不该带着一份文档面判不过的陈旧文档上线;它与读腿两个方向上的差别见 {@link MigrateConfigDirectoryOptions.judge})。
|
|
125
|
+
*/
|
|
126
|
+
function verdictOf(input, migrated, receipts, judge) {
|
|
127
|
+
const refusedReceipts = receipts.filter((r) => r.appliedAs === "refused");
|
|
128
|
+
const byMigration = refusedReceipts.map((r) => withIdentity(reportReceipt(r), input[r.document], r.path));
|
|
129
|
+
const migrationWhy = `${refusedReceipts.length} coordinate(s) cannot be migrated`;
|
|
130
|
+
// 迁移步拒:`"changed"`(引擎起服)问的是「迁移有没有把它改坏」,答案已经是否,不再往下判;`"present"` 问「这个目录现在干不干净」,下面接着判别的文档,两样并在一份报告里。
|
|
131
|
+
if (refusedReceipts.length > 0 && judge === "changed")
|
|
132
|
+
return { kind: "refused", refused: byMigration, why: `${migrationWhy} (see "refused") — fix them by hand and re-run` };
|
|
133
|
+
if (receipts.length === 0 && judge === "changed")
|
|
79
134
|
return { kind: "noop" };
|
|
80
|
-
const
|
|
135
|
+
const receiptDocuments = new Set(refusedReceipts.map((r) => r.document)); // 文档名按串比(收据上的是闭集 `MigrationDocument`,这里遍历的键是任意串):这些文档的毛病已经在 byMigration 里(要猜才改得动的形),不再判第二遍、不重复报
|
|
136
|
+
const byJudge = [];
|
|
81
137
|
for (const [name, doc] of Object.entries(migrated)) {
|
|
82
|
-
if (
|
|
138
|
+
if (receiptDocuments.has(name))
|
|
83
139
|
continue;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (err instanceof z.ZodError)
|
|
89
|
-
for (const i of err.issues)
|
|
90
|
-
refused.push(wholeDomainRefusal(name, i.path, i.message));
|
|
91
|
-
else
|
|
92
|
-
refused.push(wholeDomainRefusal(name, [], err instanceof Error ? err.message : String(err)));
|
|
93
|
-
}
|
|
140
|
+
const untouched = Object.prototype.hasOwnProperty.call(input, name) && input[name] === doc;
|
|
141
|
+
if (untouched && judge === "changed")
|
|
142
|
+
continue;
|
|
143
|
+
byJudge.push(...wholeDocumentRefusals(name, doc, untouched));
|
|
94
144
|
}
|
|
95
|
-
if (
|
|
96
|
-
const documents = [...new Set(
|
|
97
|
-
|
|
145
|
+
if (byMigration.length > 0 || byJudge.length > 0) {
|
|
146
|
+
const documents = [...new Set(byJudge.map((r) => r.document))];
|
|
147
|
+
const judged = judge === "changed" ? `the migrated ${documents.join(" / ")} document(s) do not read as a whole domain` : `${refusedLocations(byJudge)} do not read as a whole domain`;
|
|
148
|
+
const why = byJudge.length === 0
|
|
149
|
+
? `${migrationWhy} (see "refused") — fix them by hand and re-run`
|
|
150
|
+
: byMigration.length === 0
|
|
151
|
+
? `${judged} (see "refused") — fix them by hand and re-run`
|
|
152
|
+
: `${migrationWhy} and ${judged} (see "refused") — fix them by hand and re-run`;
|
|
153
|
+
return { kind: "refused", refused: [...byMigration, ...byJudge], why };
|
|
98
154
|
}
|
|
99
|
-
return { kind: "changes" };
|
|
155
|
+
return receipts.length === 0 ? { kind: "noop" } : { kind: "changes" };
|
|
100
156
|
}
|
|
101
157
|
const messageOf = (err) => (err instanceof Error ? err.message : String(err));
|
|
102
158
|
/** 覆盖面的名字集(校验在这一处):拼错的名字 ⇒ `TypeError`,不让它悄悄变成「什么都没覆盖」。 */
|
|
@@ -112,7 +168,7 @@ function coveredDocuments(caller, documents) {
|
|
|
112
168
|
/**
|
|
113
169
|
* 「迁 → 整域终判」的内核(语义只此一处):`docs` = 覆盖面内**在场且已判过形**的文档(都是 JSON 对象),`covered` = 覆盖面。目录形读完目录后调它,同步口 {@link migrateConfigDocuments} 判完形后调它。
|
|
114
170
|
*/
|
|
115
|
-
function migrateCovered(caller, docs, covered) {
|
|
171
|
+
function migrateCovered(caller, docs, covered, judge) {
|
|
116
172
|
const read = Object.keys(docs);
|
|
117
173
|
if (read.length === 0)
|
|
118
174
|
return { kind: "no-documents" };
|
|
@@ -128,7 +184,7 @@ function migrateCovered(caller, docs, covered) {
|
|
|
128
184
|
throw new Error(`${caller}: the migration removed document(s) (${dropped.join(", ")}) — this migration never deletes a file; refusing to write`);
|
|
129
185
|
}
|
|
130
186
|
const applied = m.receipts.filter((r) => r.appliedAs !== "refused");
|
|
131
|
-
const verdict = verdictOf(docs, m.docs, m.receipts);
|
|
187
|
+
const verdict = verdictOf(docs, m.docs, m.receipts, judge);
|
|
132
188
|
switch (verdict.kind) {
|
|
133
189
|
case "refused":
|
|
134
190
|
return { kind: "refused", read, docs: m.docs, applied, refused: verdict.refused, why: verdict.why };
|
|
@@ -166,13 +222,16 @@ export function migrateConfigDocuments(docs, opts) {
|
|
|
166
222
|
return { kind: "unreadable", document: name, reason: messageOf(err) };
|
|
167
223
|
}
|
|
168
224
|
}
|
|
169
|
-
return migrateCovered("migrateConfigDocuments", present, covered);
|
|
225
|
+
return migrateCovered("migrateConfigDocuments", present, covered, "changed"); // 同步口问的是「引擎起服那一次迁移之后」(见 `judge: "changed"`):不判迁移没碰的文档
|
|
170
226
|
}
|
|
171
227
|
/**
|
|
172
228
|
* 对 `dir`(一个 `config.d` 目录)的覆盖面内文档跑一次一次性迁移;语义与结果见文件头。`dir` 与目录内文件名的拼接用 `/`。
|
|
173
229
|
*/
|
|
174
230
|
export async function migrateConfigDirectory(dir, opts) {
|
|
175
231
|
const covered = coveredDocuments("migrateConfigDirectory", opts.documents);
|
|
232
|
+
const judge = opts.judge ?? "changed";
|
|
233
|
+
if (judge !== "changed" && judge !== "present")
|
|
234
|
+
throw new TypeError(`migrateConfigDirectory: judge must be "changed" or "present" (got ${JSON.stringify(String(judge))})`);
|
|
176
235
|
const { io } = opts;
|
|
177
236
|
let names;
|
|
178
237
|
try {
|
|
@@ -203,7 +262,7 @@ export async function migrateConfigDirectory(dir, opts) {
|
|
|
203
262
|
return { kind: "unreadable", reason: messageOf(err) };
|
|
204
263
|
}
|
|
205
264
|
}
|
|
206
|
-
const m = migrateCovered("migrateConfigDirectory", docs, covered);
|
|
265
|
+
const m = migrateCovered("migrateConfigDirectory", docs, covered, judge);
|
|
207
266
|
switch (m.kind) {
|
|
208
267
|
case "no-documents":
|
|
209
268
|
return { kind: "no-documents", entries: names };
|
package/dist/config-fns.d.ts
CHANGED
|
@@ -185,7 +185,7 @@ export declare class RetiredDomainError extends Error {
|
|
|
185
185
|
* 一句中性 TypeError;逐条丢弃域里条目体内有被剥的键且救不活 = `unrecognized_keys` 的 ZodError)。`message` 点名域并接原拒的句子 —— 原拒已脱敏,这里不读任何
|
|
186
186
|
* 脱敏之前的东西;原拒的句子读不出 ⇒ 只留点名域的前半句。
|
|
187
187
|
* 铸点只有一处(视图面读的整域档位,{@link readViewOr})。单域读口(`parseDomain` / `parseDomainLoud` / `parseDomainSalvaged`)照抛原拒 —— 调用方自己点了域;
|
|
188
|
-
* 目录域整域读不进不抛:回落默认 + 一条 `domain-defaulted`,告警的 `error`
|
|
188
|
+
* 目录域整域读不进不抛:回落默认 + 一条 `domain-defaulted`,告警的 `error` 与这里的 `cause` 是同一只原拒的 `issues`(另一只对象:同类、同 `issues`,`message` 换成一句话),告警自带 `domain`。retired 域的墓碑拒是另一件事({@link RetiredDomainError})。
|
|
189
189
|
*/
|
|
190
190
|
export declare class DomainReadRefusedError extends Error {
|
|
191
191
|
readonly domain: DomainName;
|
|
@@ -314,6 +314,14 @@ export declare function isReportableRefusalName(name: string): boolean;
|
|
|
314
314
|
* 摘要输入取 `JSON.stringify(name)`:UTF-8 编码会把孤立代理项换成 U+FFFD(`"\ud800"` / `"\ud801"` / `"\ufffd"` 三个不同的名同一串字节),
|
|
315
315
|
* JSON 串形逐个 UTF-16 码元保留(孤立代理项写成转义)—— 不同的名恒是不同的输入。 */
|
|
316
316
|
export declare function withheldNameToken(name: string): string;
|
|
317
|
+
/**
|
|
318
|
+
* 一个坐标落进的那一条**条目**的身份(只带可披露的名与 id,见 {@link DroppedEntryIdentity}):坐标形如 `[<集合字段>, <下标>, …]` 且文档里那一处是数组里的一个条目 ⇒ 读它的身份;
|
|
319
|
+
* 否则(域级的键、整份文档、Record 里的值)⇒ `undefined`。条目身份的读法只有 {@link readEntryIdentity} 一只:`entry-dropped` 的身份由抢救记账时对那一条原文调它;
|
|
320
|
+
* 按坐标找到那一条再调它的,是这一只 —— `domain-defaulted`(抢救账里没有那一条时)与命令行报告的 `refused[]` 说「是哪一条」读它。坐标只给下标,
|
|
321
|
+
* 消费方自己渲染诊断、要点名一条条目时调它(`doc` 是坐标所指的那份文档的原文,`path` 是 {@link ConfigPath}),不另写一份读名字的代码。读文档只走内核的自有成员读;
|
|
322
|
+
* 读不出(含 `path` 不是数组、读它就抛)⇒ `undefined`,从不抛。
|
|
323
|
+
*/
|
|
324
|
+
export declare function readEntryIdentityAt(doc: unknown, path: ConfigPath): DroppedEntryIdentity | undefined;
|
|
317
325
|
/** 抢救造成的**下标位移表**:被压缩过的数组 → 它压缩后每个位置的**原**下标(`kept[j]` = 压缩后第 j 条
|
|
318
326
|
* 在原文档里的下标)。纯数据,无行为。
|
|
319
327
|
*
|
|
@@ -411,10 +419,17 @@ export declare function statusRowsToPrune(rows: {
|
|
|
411
419
|
* 0.19.0 加了两个 kind(additive union member —— 用 `switch` 穷举本类型的消费方需补臂):
|
|
412
420
|
* `"unknown-keys-dropped"` / `"unread-config-file"`,成案见 {@link droppedKeys}(消费方
|
|
413
421
|
* #322:配置写了、进程跑着、值没到,而没有任何一个字说出来)。 */
|
|
414
|
-
export type EffectiveReadWarning =
|
|
422
|
+
export type EffectiveReadWarning =
|
|
423
|
+
/** 整个域读不进、按 schema 缺省读。`error` 与判官的原拒同类、同 `issues`(`ZodError` 的 `issues` 一字不动;仍是 `Error` 的实例、带 `stack`),它的 `message` 是**一句话**(整域按缺省读 · 为什么 · 触发的条目是谁 · 在这份文档里手改),不是多行的 JSON 数组文本。
|
|
424
|
+
* 另有三个可缺的键(加性):`path` = 触发的那一处坐标(原拒的第一条 issue 的坐标,出门形;可以是域级的键,如 `["default"]`);`identity` / `reasonCode` = 触发的**条目**是谁、为什么(坐标落在某个条目体内时才有,
|
|
425
|
+
* 与同一条条目在 `entry-dropped` 上的两键同一读法 —— 零幸存者时只剩这一条告警,身份与原因词就在这里)。三键不进符合性投影({@link projectWarning} 仍是 `{ kind, domain }`):它们是诊断,不是读法。 */
|
|
426
|
+
{
|
|
415
427
|
domain: DomainName;
|
|
416
428
|
kind: "domain-defaulted";
|
|
417
429
|
error: unknown;
|
|
430
|
+
path?: ConfigPath;
|
|
431
|
+
identity?: DroppedEntryIdentity;
|
|
432
|
+
reasonCode?: DroppedEntryReasonCode;
|
|
418
433
|
}
|
|
419
434
|
/** 域文档里那些**不属于该域 schema** 的键:行为照旧(zod 非 strict = 剥掉,前向兼容不动),但点名
|
|
420
435
|
* 说出来。`keys` = 段坐标({@link ConfigPath};`["infraCostRates","toolCalMicroUsd"]` /
|
|
@@ -527,6 +542,7 @@ export declare function projectWarning(w: EffectiveReadWarning): WarningProjecti
|
|
|
527
542
|
* 说的就是这件事。{@link salvageEntries} 铸 `entry-dropped` 时用的是它**入参**那份文档的坐标;若那份文档本身被外层
|
|
528
543
|
* 压缩过,外层照样要回写它一次。今天读路径上只有一个压缩点(11.0.0 起 hosts 的读侧夹紧臂已retired),所以这一臂当下
|
|
529
544
|
* 只对 `keptIndex` 为空的表恒等;把「不动」写成一条臂的性质,就是把「哪一层」这件事错记在了「哪个 kind」上。
|
|
545
|
+
* `domain-defaulted` 的可缺坐标 `path`(33.0.0)同理:在场就回写,缺席就原样。
|
|
530
546
|
*
|
|
531
547
|
* **恒等纪律**:没有任何一条路径真的变了(含 `keptIndex` 为空)⇒ 返回**同一个对象引用**,连 `keys`
|
|
532
548
|
* 数组也不复制(好数据穿过读路径 byte 不变)。
|
package/dist/config-fns.js
CHANGED
|
@@ -20,6 +20,7 @@ import { MODEL_ENTRY_REFUSAL_CODES, ModelRefusalsWire } from "./fleet.js";
|
|
|
20
20
|
import { UNINSPECTABLE, dataDescriptor, emptyDocument, guardedSafeParse, inspect, isAccessorDescriptor, isolatedObject, ownEntriesOf, ownRow, ownValueOf } from "./own-key-read.js";
|
|
21
21
|
import { stableStringify } from "./hash.js";
|
|
22
22
|
import { ownEnabledFlag } from "./catalog-manages.js";
|
|
23
|
+
import { causeText, defaultedDomainSentence, droppedEntrySentence, identityText, issueSentence } from "./read-sentences.js"; // package-private: the one wording of the read-leg diagnostic sentences
|
|
23
24
|
import { isJsonArray, isPlainJsonObject, jsonShapeOf } from "./plain-json-object.js";
|
|
24
25
|
import { carriesUserinfo, secretScanForms } from "./secret-scan.js"; // package-private normalization (both scanners read it) + the userinfo judgement (not in the barrel)
|
|
25
26
|
import { sha256Hex } from "./sha256.js";
|
|
@@ -338,7 +339,7 @@ export class RetiredDomainError extends Error {
|
|
|
338
339
|
* 一句中性 TypeError;逐条丢弃域里条目体内有被剥的键且救不活 = `unrecognized_keys` 的 ZodError)。`message` 点名域并接原拒的句子 —— 原拒已脱敏,这里不读任何
|
|
339
340
|
* 脱敏之前的东西;原拒的句子读不出 ⇒ 只留点名域的前半句。
|
|
340
341
|
* 铸点只有一处(视图面读的整域档位,{@link readViewOr})。单域读口(`parseDomain` / `parseDomainLoud` / `parseDomainSalvaged`)照抛原拒 —— 调用方自己点了域;
|
|
341
|
-
* 目录域整域读不进不抛:回落默认 + 一条 `domain-defaulted`,告警的 `error`
|
|
342
|
+
* 目录域整域读不进不抛:回落默认 + 一条 `domain-defaulted`,告警的 `error` 与这里的 `cause` 是同一只原拒的 `issues`(另一只对象:同类、同 `issues`,`message` 换成一句话),告警自带 `domain`。retired 域的墓碑拒是另一件事({@link RetiredDomainError})。
|
|
342
343
|
*/
|
|
343
344
|
export class DomainReadRefusedError extends Error {
|
|
344
345
|
domain;
|
|
@@ -501,7 +502,8 @@ export function withheldNameToken(name) {
|
|
|
501
502
|
}
|
|
502
503
|
/** 一条被丢条目原文的身份({@link DroppedEntryIdentity} 的**唯一**读法)。只看纯 JSON 对象的**自有数据
|
|
503
504
|
* 属性**;任何反射/陷阱抛错 ⇒ 当作读不出(身份是诊断面的附件,绝不许把抢救拖下水)。`enabled` 读的是「显式停用」的那一只
|
|
504
|
-
* ({@link ownEnabledFlag},`./catalog-manages`):目录管不管模型面的原文判官与这里同一份读法。
|
|
505
|
+
* ({@link ownEnabledFlag},`./catalog-manages`):目录管不管模型面的原文判官与这里同一份读法。
|
|
506
|
+
* 包内私有:公开的读口是按坐标读的 {@link readEntryIdentityAt}。 */
|
|
505
507
|
function readEntryIdentity(entry) {
|
|
506
508
|
try {
|
|
507
509
|
if (!isPlainJsonObject(entry))
|
|
@@ -524,6 +526,28 @@ function readEntryIdentity(entry) {
|
|
|
524
526
|
return undefined;
|
|
525
527
|
}
|
|
526
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* 一个坐标落进的那一条**条目**的身份(只带可披露的名与 id,见 {@link DroppedEntryIdentity}):坐标形如 `[<集合字段>, <下标>, …]` 且文档里那一处是数组里的一个条目 ⇒ 读它的身份;
|
|
531
|
+
* 否则(域级的键、整份文档、Record 里的值)⇒ `undefined`。条目身份的读法只有 {@link readEntryIdentity} 一只:`entry-dropped` 的身份由抢救记账时对那一条原文调它;
|
|
532
|
+
* 按坐标找到那一条再调它的,是这一只 —— `domain-defaulted`(抢救账里没有那一条时)与命令行报告的 `refused[]` 说「是哪一条」读它。坐标只给下标,
|
|
533
|
+
* 消费方自己渲染诊断、要点名一条条目时调它(`doc` 是坐标所指的那份文档的原文,`path` 是 {@link ConfigPath}),不另写一份读名字的代码。读文档只走内核的自有成员读;
|
|
534
|
+
* 读不出(含 `path` 不是数组、读它就抛)⇒ `undefined`,从不抛。
|
|
535
|
+
*/
|
|
536
|
+
export function readEntryIdentityAt(doc, path) {
|
|
537
|
+
const read = inspect(() => {
|
|
538
|
+
if (!isJsonArray(path))
|
|
539
|
+
return undefined;
|
|
540
|
+
const [field, index] = path;
|
|
541
|
+
if (typeof field !== "string" || typeof index !== "number" || !isPlainJsonObject(doc))
|
|
542
|
+
return undefined;
|
|
543
|
+
const collection = ownValueOf(doc, field);
|
|
544
|
+
if (!collection.ok || !isJsonArray(collection.value))
|
|
545
|
+
return undefined;
|
|
546
|
+
const entry = ownValueOf(collection.value, String(index));
|
|
547
|
+
return entry.ok ? readEntryIdentity(entry.value) : undefined;
|
|
548
|
+
});
|
|
549
|
+
return read.ok ? read.value : undefined;
|
|
550
|
+
}
|
|
527
551
|
/** 一条记账行 → 它的 `entry-dropped` 告警。域面({@link buildEffective})与 wire 面(skills manifest)共用
|
|
528
552
|
* 这**一只** —— 告警形只在这里拼,新字段不会在一条腿上漏铸。 */
|
|
529
553
|
function entryDroppedWarning(domain, d) {
|
|
@@ -531,11 +555,47 @@ function entryDroppedWarning(domain, d) {
|
|
|
531
555
|
domain,
|
|
532
556
|
kind: "entry-dropped",
|
|
533
557
|
path: d.path,
|
|
534
|
-
error: d
|
|
558
|
+
error: droppedEntryError(domain, d),
|
|
535
559
|
...(d.reasonCode === undefined ? {} : { reasonCode: d.reasonCode }),
|
|
536
560
|
...(d.identity === undefined ? {} : { identity: d.identity }),
|
|
537
561
|
};
|
|
538
562
|
}
|
|
563
|
+
/** 一条 issue 清单的**每条一句话**(坐标出门形的串 + 句子):`ZodError` 逐条 issue 读(联合取各选项的句子),别的错只有它的 `message`。读不出 ⇒ 空清单(诊断是旁路,不许把读拖下水)。 */
|
|
564
|
+
function pathedSentencesOf(error) {
|
|
565
|
+
const read = inspect(() => {
|
|
566
|
+
if (error instanceof z.ZodError)
|
|
567
|
+
return error.issues.map((i) => ({ path: formatConfigPath(i.path), sentence: issueSentence(i) }));
|
|
568
|
+
if (error instanceof Error)
|
|
569
|
+
return [{ path: "", sentence: issueSentence({ message: error.message }) }];
|
|
570
|
+
return [];
|
|
571
|
+
});
|
|
572
|
+
return read.ok ? read.value : [];
|
|
573
|
+
}
|
|
574
|
+
/** 给一只原拒换上**一句话**的 `message`(单行):`ZodError` ⇒ 同一份 `issues` 的新 `ZodError`(原对象不动 —— 它还在别处用:域读拒的 `cause`、公开的 {@link salvageEntries} 结果),
|
|
575
|
+
* `TypeError` ⇒ 一只新的 `TypeError`;别的错不认识 ⇒ 原样交回。铸不出 ⇒ 原样交回(旁路)。
|
|
576
|
+
* 新铸的 `ZodError` 是 zod 解析失败时交出的那一种(`ZodRealError`:`Error` 的实例、带 `stack`)—— 与原拒同读:按 `instanceof Error` 分流的读者读到的仍是一只错;
|
|
577
|
+
* `ZodError` 这只构造器本身铸的不是 `Error`。
|
|
578
|
+
* 句子出门前过本包唯一的脱敏器({@link redactSecrets}):句子里回显的串(键名、坐标、别人的句子)在铸句时已折成一行、剥掉一行回显的剥除集 ——
|
|
579
|
+
* 剥掉一个隔开的字符可以把两段拼成一个密钥形(`g<U+202E>hp_…` ⇒ `ghp_…`),所以脱敏判在剥之后、对最终的那一串再做一次。 */
|
|
580
|
+
function withSentence(error, sentence) {
|
|
581
|
+
const minted = inspect(() => {
|
|
582
|
+
const outgoing = redactSecrets(sentence);
|
|
583
|
+
if (error instanceof z.ZodError) {
|
|
584
|
+
const sentenced = new z.ZodRealError(error.issues);
|
|
585
|
+
sentenced.message = outgoing;
|
|
586
|
+
if (typeof Error.captureStackTrace === "function")
|
|
587
|
+
Error.captureStackTrace(sentenced, withSentence); // zod 铸错时不采栈(解析口事后补上);这里同样补上,栈头是这一句
|
|
588
|
+
return sentenced;
|
|
589
|
+
}
|
|
590
|
+
return error instanceof TypeError ? new TypeError(outgoing) : error;
|
|
591
|
+
});
|
|
592
|
+
return minted.ok ? minted.value : error;
|
|
593
|
+
}
|
|
594
|
+
/** `entry-dropped` 告警的 `error`:原拒的 `issues` 不动,`message` 是一句话 —— 哪一条、是谁、为什么、其余照常、手改回来({@link droppedEntrySentence})。 */
|
|
595
|
+
function droppedEntryError(domain, d) {
|
|
596
|
+
const sentence = inspect(() => droppedEntrySentence({ domain, entry: `entry ${formatConfigPath(d.path)}`, identity: identityText(d.identity), cause: causeText(pathedSentencesOf(d.error)) }));
|
|
597
|
+
return sentence.ok ? withSentence(d.error, sentence.value) : d.error;
|
|
598
|
+
}
|
|
539
599
|
/** 一条被丢条目的记账行 —— `salvageEntries` 两种集合形(数组 / Record)共用的**唯一**铸点。词随判决来({@link EntryVerdict}),
|
|
540
600
|
* 不在这里另行推断:判的那一刻才知道是哪种丢法。 */
|
|
541
601
|
function droppedEntry(path, verdict, entry) {
|
|
@@ -643,15 +703,25 @@ function judgeEntry(element, entry, domain, from) {
|
|
|
643
703
|
export function salvageEntries(schema, raw, domain) {
|
|
644
704
|
if (!isDomainName(domain))
|
|
645
705
|
throw new TypeError(`salvageEntries: "${outgoingSegment(String(domain))}" is not a config domain (the third argument names whose extension namespaces apply)`);
|
|
706
|
+
const { raw: salvaged, dropped, keptIndex } = salvageLedger(schema, raw, domain);
|
|
707
|
+
return { raw: salvaged, dropped, keptIndex };
|
|
708
|
+
}
|
|
709
|
+
/** 整域读不进时第一次判留下的抢救账,按它抛出去的那只原拒挂着(包内私有的旁路:公开读口抛的仍是原拒、对象与形都不变)。读腿告警 `domain-defaulted` 说「触发的是哪一条」读它,
|
|
710
|
+
* 不把文档再抢救一遍(有状态的 getter 下两遍读到的可以不是同一份)。范围照实:触发的条目在这本账里(条目本身坏)⇒ 身份与原因词都取账上的,不再读文档;
|
|
711
|
+
* 账里没有它(重名、悬空引用这类域级跨行规则把整域拒了)⇒ 身份按坐标回原文读那一条({@link readEntryIdentityAt}),集合字段多读一次。WeakMap:原拒没人留着,账随它一起走。 */
|
|
712
|
+
const LEDGER_OF_REFUSAL = new WeakMap();
|
|
713
|
+
/** 抢救的**完整账**(包内私有):{@link salvageEntries} 的结果,外加 `lost` = 「一个集合里条目全坏、所以一条没丢」的那些条目的记账行(零幸存者律:不凭空造出空集合)。
|
|
714
|
+
* 整域因此读不进时,它们就是病因 —— 读腿告警 `domain-defaulted` 点名其中的身份与原因词读的是这一份;公开的 {@link salvageEntries} 不带它(结果形不变)。 */
|
|
715
|
+
function salvageLedger(schema, raw, domain) {
|
|
646
716
|
const layer = salvageLayer(schema, raw, domain, []);
|
|
647
|
-
return { raw: layer.raw, dropped: layer.dropped, keptIndex: keptIndexOf(layer.shifts) };
|
|
717
|
+
return { raw: layer.raw, dropped: layer.dropped, keptIndex: keptIndexOf(layer.shifts), lost: layer.lost };
|
|
648
718
|
}
|
|
649
719
|
/** 一层抢救,抢不动就当没抢救(反射 / 访问器抛错:绝不外泄其文案)。最外层与每一条条目体内走的是**同一只** —— 一条条目体内抢不动,
|
|
650
720
|
* 只是这一条不下钻、照原样去判,不连坐它所在的那一层。`origin` = 本层文档在域文档里的**原文**坐标(未脱敏、原下标;最外层 `[]`)——
|
|
651
721
|
* 扩展命名空间按运维写下的段判,出门坐标(脱敏)另由 `outgoingPath` 铸。 */
|
|
652
722
|
function salvageLayer(schema, raw, domain, origin) {
|
|
653
723
|
const layer = inspect(() => salvageLayerUnsafe(schema, raw, domain, origin));
|
|
654
|
-
return layer.ok ? layer.value : { raw, dropped: [], shifts: [] };
|
|
724
|
+
return layer.ok ? layer.value : { raw, dropped: [], shifts: [], lost: [] };
|
|
655
725
|
}
|
|
656
726
|
/** 「哪些字段是一组条目」的**唯一**派生(逐条抢救 {@link salvageLayerUnsafe} 与视图面判官 {@link entryHeldStrippedKeys} 同读这一只):
|
|
657
727
|
* 根(拆掉包装层后)是对象 ⇒ 它的每个元素是条目({@link isEntrySchema})的数组 / Record 字段。元素不是条目的集合(值名单、凭据引用)是一个值,
|
|
@@ -694,10 +764,11 @@ function collectionSlots(value, isArray) {
|
|
|
694
764
|
return isPlainJsonObject(value) ? Object.entries(value) : undefined;
|
|
695
765
|
}
|
|
696
766
|
function salvageLayerUnsafe(schema, raw, domain, origin) {
|
|
697
|
-
const untouched = { raw, dropped: [], shifts: [] };
|
|
767
|
+
const untouched = { raw, dropped: [], shifts: [], lost: [] };
|
|
698
768
|
if (!isPlainJsonObject(raw))
|
|
699
769
|
return untouched;
|
|
700
770
|
const dropped = [];
|
|
771
|
+
const lost = [];
|
|
701
772
|
const shifts = [];
|
|
702
773
|
const patch = {};
|
|
703
774
|
for (const { field, isArray, element, keySchema } of entryCollectionsOf(schema)) {
|
|
@@ -735,6 +806,8 @@ function salvageLayerUnsafe(schema, raw, domain, origin) {
|
|
|
735
806
|
innerShifts.push({ at: [...at, ...s.at], kept: s.kept });
|
|
736
807
|
}
|
|
737
808
|
// 零幸存者 ⇒ 没有要抢救的东西(见头注:绝不凭空造出一个空集合);什么都没上账 ⇒ 这个字段原样不动。
|
|
809
|
+
if (survivors.length === 0)
|
|
810
|
+
lost.push(...found); // 全坏的集合:一条不丢(不改 raw),但这些条目就是整域读不进的病因,记在 `lost` 里
|
|
738
811
|
if (survivors.length === 0 || found.length === 0)
|
|
739
812
|
continue;
|
|
740
813
|
dropped.push(...found);
|
|
@@ -746,8 +819,8 @@ function salvageLayerUnsafe(schema, raw, domain, origin) {
|
|
|
746
819
|
shifts.push(...innerShifts);
|
|
747
820
|
}
|
|
748
821
|
if (dropped.length === 0)
|
|
749
|
-
return untouched;
|
|
750
|
-
return { raw: { ...raw, ...patch }, dropped, shifts };
|
|
822
|
+
return lost.length === 0 ? untouched : { raw, dropped: [], shifts: [], lost };
|
|
823
|
+
return { raw: { ...raw, ...patch }, dropped, shifts, lost };
|
|
751
824
|
}
|
|
752
825
|
/** 段坐标记的位移账 → {@link EntryKeptIndex}(键 = 全路径的出门串)。同一个键出现两次只可能是两只被打码成同一串的 Record 键
|
|
753
826
|
* (坐标本身已分不清是谁)⇒ 那个键不登记。什么都没压缩 ⇒ 冻结的共享空表。 */
|
|
@@ -847,6 +920,7 @@ export function projectWarning(w) {
|
|
|
847
920
|
* 说的就是这件事。{@link salvageEntries} 铸 `entry-dropped` 时用的是它**入参**那份文档的坐标;若那份文档本身被外层
|
|
848
921
|
* 压缩过,外层照样要回写它一次。今天读路径上只有一个压缩点(11.0.0 起 hosts 的读侧夹紧臂已retired),所以这一臂当下
|
|
849
922
|
* 只对 `keptIndex` 为空的表恒等;把「不动」写成一条臂的性质,就是把「哪一层」这件事错记在了「哪个 kind」上。
|
|
923
|
+
* `domain-defaulted` 的可缺坐标 `path`(33.0.0)同理:在场就回写,缺席就原样。
|
|
850
924
|
*
|
|
851
925
|
* **恒等纪律**:没有任何一条路径真的变了(含 `keptIndex` 为空)⇒ 返回**同一个对象引用**,连 `keys`
|
|
852
926
|
* 数组也不复制(好数据穿过读路径 byte 不变)。
|
|
@@ -866,8 +940,14 @@ export function rebaseWarningPaths(w, keptIndex) {
|
|
|
866
940
|
const path = rebasePath(w.path, keptIndex);
|
|
867
941
|
return path === w.path ? w : { ...w, path };
|
|
868
942
|
}
|
|
869
|
-
//
|
|
870
|
-
case "domain-defaulted":
|
|
943
|
+
// 33.0.0 起 `domain-defaulted` 可带一只坐标(`path`,触发的那一处):与 `entry-dropped` 同一条律 —— 铸它那一层用的是它入参那份文档的坐标,外层压缩过就回写一次。
|
|
944
|
+
case "domain-defaulted": {
|
|
945
|
+
if (w.path === undefined)
|
|
946
|
+
return w;
|
|
947
|
+
const path = rebasePath(w.path, keptIndex);
|
|
948
|
+
return path === w.path ? w : { ...w, path };
|
|
949
|
+
}
|
|
950
|
+
// 这一臂不带任何坐标:点名的是文件名。
|
|
871
951
|
case "unread-config-file":
|
|
872
952
|
return w;
|
|
873
953
|
default: {
|
|
@@ -1258,9 +1338,40 @@ const SKILLS_MANIFEST_SEAT = { domain: "skills", schema: SkillsManifestSchema };
|
|
|
1258
1338
|
function readView(seat, raw, onWarning) {
|
|
1259
1339
|
return readDomainDocument(seat.domain, raw, onWarning, (doc) => parseForView(seat, doc), (unreadable) => parseSalvaged(seat, raw, unreadable, onWarning));
|
|
1260
1340
|
}
|
|
1341
|
+
/** `a` 是不是 `prefix` 的延伸(逐段相等;空前缀不算 —— 没有坐标就没有条目)。 */
|
|
1342
|
+
const startsWithPath = (path, prefix) => prefix.length > 0 && prefix.length <= path.length && prefix.every((seg, i) => path[i] === seg);
|
|
1343
|
+
/**
|
|
1344
|
+
* 读腿整域读不进、按缺省读时的告警(`domain-defaulted`;唯一铸点,{@link readViewOr} 调它):`error` = 原拒换上一句话的 `message`(整域按缺省读 · 为什么 · 触发的条目是谁 · 在这份文档里手改);
|
|
1345
|
+
* 三个可缺的键说出**触发的是谁** —— `path` = 原拒第一条 issue 的坐标;`identity` = 坐标落进的那一条条目的身份(条目本身没坏、只是域级的跨行规则 —— 重名、悬空引用 —— 把整域拒了,也有);
|
|
1346
|
+
* `reasonCode` = 那一条条目为什么坏(只有条目本身坏才有;域级的毛病没有)。
|
|
1347
|
+
* 条目为什么坏读第一次判留下的抢救账({@link salvageLedger},随原拒带来:丢掉的条目,与零幸存者的集合里那些一条没丢的条目)—— 不把文档再抢救一遍;
|
|
1348
|
+
* 身份先取账上那一行的(条目本身坏 ⇒ 不再读文档),账里没有那一条(域级跨行规则)才按坐标回原文读那一条({@link readEntryIdentityAt},与命令行 `refused[]` 同一只;集合字段多读一次)。
|
|
1349
|
+
* 诊断是旁路 —— 任何一步读不出 ⇒ 少几个键、`error` 原样,从不把读拖下水。
|
|
1350
|
+
*/
|
|
1351
|
+
function domainDefaultedWarning(seat, raw, refusal) {
|
|
1352
|
+
const issues = pathedSentencesOf(refusal);
|
|
1353
|
+
const first = inspect(() => (refusal instanceof z.ZodError ? refusal.issues[0]?.path : undefined));
|
|
1354
|
+
const path = first.ok && first.value !== undefined && first.value.length > 0 ? first.value : undefined;
|
|
1355
|
+
const held = inspect(() => (refusal instanceof Error ? LEDGER_OF_REFUSAL.get(refusal) : undefined));
|
|
1356
|
+
const ledger = held.ok ? held.value : undefined;
|
|
1357
|
+
const culprit = path === undefined || ledger === undefined ? undefined : [...ledger.lost, ...ledger.dropped].find((c) => startsWithPath(path, c.path));
|
|
1358
|
+
const identity = culprit?.identity ?? (path === undefined ? undefined : readEntryIdentityAt(raw, path));
|
|
1359
|
+
const entryPath = culprit?.path ?? (path !== undefined && typeof path[1] === "number" ? path.slice(0, 2) : undefined);
|
|
1360
|
+
const entry = entryPath === undefined || (culprit === undefined && identity === undefined) ? undefined : `entry ${formatConfigPath(entryPath)}`;
|
|
1361
|
+
const who = identityText(identity);
|
|
1362
|
+
const sentence = inspect(() => defaultedDomainSentence({ domain: seat.domain, cause: causeText(issues), culprit: entry === undefined ? undefined : who === undefined ? entry : `${entry}: ${who}` }));
|
|
1363
|
+
return {
|
|
1364
|
+
domain: seat.domain,
|
|
1365
|
+
kind: "domain-defaulted",
|
|
1366
|
+
error: sentence.ok ? withSentence(refusal, sentence.value) : refusal,
|
|
1367
|
+
...(path === undefined ? {} : { path }),
|
|
1368
|
+
...(identity === undefined ? {} : { identity }),
|
|
1369
|
+
...(culprit?.reasonCode === undefined ? {} : { reasonCode: culprit.reasonCode }),
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1261
1372
|
/**
|
|
1262
1373
|
* 视图面读一份文档,**读不进时按 {@link DOMAIN_READ_FALLBACK} 答**:`"throw"` ⇒ 抛 {@link DomainReadRefusedError}(`domain` = 这个域,`cause` = 判官的原拒);
|
|
1263
|
-
* `"default"` ⇒ schema 默认 + 一条 `domain-defaulted`(`error` =
|
|
1374
|
+
* `"default"` ⇒ schema 默认 + 一条 `domain-defaulted`(`error` = 原拒的同类、同 `issues`,`message` 换成一句话,见 {@link domainDefaultedWarning})。这里是那只错的唯一铸点。
|
|
1264
1375
|
* `buildEffective` 的每个域与 `readEffectiveWire` 的 skills 清单都经这一只 —— 两张表各问一次,同一个域在每条读腿上同一个答案(24.0.0 前清单是单列一臂,
|
|
1265
1376
|
* 恒逐条抢救、恒默认化,不读这两张表)。好文档的路径一字不动。
|
|
1266
1377
|
*
|
|
@@ -1276,7 +1387,8 @@ function readViewOr(seat, raw, onWarning) {
|
|
|
1276
1387
|
catch (refusal) {
|
|
1277
1388
|
if (DOMAIN_READ_FALLBACK[seat.domain] === "throw")
|
|
1278
1389
|
throw new DomainReadRefusedError(seat.domain, refusal);
|
|
1279
|
-
onWarning
|
|
1390
|
+
if (onWarning !== undefined)
|
|
1391
|
+
onWarning(domainDefaultedWarning(seat, raw, refusal));
|
|
1280
1392
|
return strictParse(seat.schema, seat.domain, emptyDocument()); // schema default — always valid
|
|
1281
1393
|
}
|
|
1282
1394
|
if (onWarning !== undefined)
|
|
@@ -1337,16 +1449,23 @@ function parseSalvaged(seat, raw, unreadable, onWarning) {
|
|
|
1337
1449
|
* 抛 `unreadable`(第一次严判的原错)—— 一个文档一个结论,没救活就不留「丢了某条」的半路叙述。`domain` = 哪个域的扩展命名空间生效(见 {@link salvageEntries})。
|
|
1338
1450
|
*/
|
|
1339
1451
|
function salvageThenParse(schema, domain, raw, parse, unreadable) {
|
|
1340
|
-
const salvage =
|
|
1452
|
+
const salvage = salvageLedger(schema, raw, domain);
|
|
1341
1453
|
if (salvage.dropped.length === 0)
|
|
1342
|
-
|
|
1454
|
+
return refuseWithLedger(unreadable, salvage);
|
|
1343
1455
|
try {
|
|
1344
1456
|
return { parsed: parse(salvage.raw), salvage };
|
|
1345
1457
|
}
|
|
1346
1458
|
catch {
|
|
1347
|
-
|
|
1459
|
+
return refuseWithLedger(unreadable, salvage);
|
|
1348
1460
|
}
|
|
1349
1461
|
}
|
|
1462
|
+
/** 抛 `unreadable`(第一次严判的原错),抛之前把抢救账挂在它身上(原拒不是 `Error` ⇒ 只抛、不挂:本包铸的原拒都是 `Error`)。 */
|
|
1463
|
+
function refuseWithLedger(unreadable, ledger) {
|
|
1464
|
+
const isError = inspect(() => unreadable instanceof Error);
|
|
1465
|
+
if (isError.ok && isError.value && unreadable instanceof Error)
|
|
1466
|
+
LEDGER_OF_REFUSAL.set(unreadable, ledger);
|
|
1467
|
+
throw unreadable;
|
|
1468
|
+
}
|
|
1350
1469
|
/** 未知键两条告警(剥掉的 / 承运的)—— `raw` 是这次真被 parse 的那份文档,`emit` 决定坐标出门前要不要回写。 */
|
|
1351
1470
|
function announceUnknownKeys(domain, raw, parsed, emit) {
|
|
1352
1471
|
const dropped = droppedKeys(domain, raw, parsed);
|
|
@@ -38,7 +38,7 @@ export declare function diffWarningMultiset(expected: readonly WarningProjection
|
|
|
38
38
|
extra: unknown[];
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
|
-
* 告警面(
|
|
41
|
+
* 告警面(除 `error` 外的每一只键 + `error` 文案 —— 不只是投影:不进投影的诊断键同样出门)里有没有语料自带的秘密。
|
|
42
42
|
*
|
|
43
43
|
* 口径(诚实登记,docs/CONFORMANCE.md 同步写明):扫的是**告警**,不是 effective。effective 里逐字承运
|
|
44
44
|
* 运维自己写下的那份文档是契约(配置就是他写的那份),而告警是**本包自己铸的新文本** —— 一条把秘密
|
|
@@ -111,7 +111,7 @@ function errorText(w) {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
* 告警面(
|
|
114
|
+
* 告警面(除 `error` 外的每一只键 + `error` 文案 —— 不只是投影:不进投影的诊断键同样出门)里有没有语料自带的秘密。
|
|
115
115
|
*
|
|
116
116
|
* 口径(诚实登记,docs/CONFORMANCE.md 同步写明):扫的是**告警**,不是 effective。effective 里逐字承运
|
|
117
117
|
* 运维自己写下的那份文档是契约(配置就是他写的那份),而告警是**本包自己铸的新文本** —— 一条把秘密
|
|
@@ -120,6 +120,12 @@ function errorText(w) {
|
|
|
120
120
|
export function findSecretLeaks(warnings, secrets) {
|
|
121
121
|
if (secrets.length === 0)
|
|
122
122
|
return [];
|
|
123
|
-
|
|
123
|
+
// 投影照旧先算一次:它是闭集穷举(不认识的 kind ⇒ 抛,不静默扫成空);扫的是投影之外还带出门的每一只键
|
|
124
|
+
const hay = warnings.map((w) => `${stableKey(projectWarning(w))}${JOINER}${stableKey(fieldsBesideError(w))}${JOINER}${errorText(w)}`).join(JOINER);
|
|
124
125
|
return secrets.filter((s) => s.length > 0 && hay.includes(s));
|
|
125
126
|
}
|
|
127
|
+
/** 一条告警除 `error` 外的**每一只**键(扫描用,不是投影):投影只留比对用的键(`domain-defaulted` 的 `path` / `identity` / `reasonCode` 是诊断、不进投影),
|
|
128
|
+
* 扫描却要看告警带出门的一切 —— 每个 kind 同一个读法,新加的键不会因为不在投影里就躲过扫描。 */
|
|
129
|
+
function fieldsBesideError(w) {
|
|
130
|
+
return Object.fromEntries(Object.entries(w).filter(([k]) => k !== "error")); // fromEntries(不是逐键赋值):键名不走原型 setter
|
|
131
|
+
}
|
package/dist/declared-capture.js
CHANGED
|
@@ -54,7 +54,7 @@ const shapeOf = (object) => object._zod.def.shape;
|
|
|
54
54
|
const isPlainUnion = (schema) => schema instanceof z.ZodUnion && !(schema instanceof z.ZodDiscriminatedUnion);
|
|
55
55
|
/** 寻常对象从 `Object.prototype` 继承来的成员名(ES 规定的闭集)。声明键叫这些名字时,zod 在调用方的值上 `[[Get]]` 读到继承来的成员,投影把它读成缺席 —— 两边不同答。 */
|
|
56
56
|
const ORDINARY_OBJECT_MEMBERS = new Set(["constructor", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "toLocaleString", "toString", "valueOf", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
|
|
57
|
-
/** 走过白名单门的 schema(按根;fleet
|
|
57
|
+
/** 走过白名单门的 schema(按根;fleet 每次请求都是那几只固定的 schema,不重走)。 */
|
|
58
58
|
const ADMITTED = new WeakSet();
|
|
59
59
|
/** 白名单门(见文件头):整棵 schema 树只含放行的形 ⇒ 记下、交回 `undefined`;否则交回不支持的那一句(见 {@link Refusal})。与 `evaluate` / `snapshotOf` 同一套判据(`isPlainUnion` / `innerOf`)。 */
|
|
60
60
|
function admit(schema) {
|