@sema-agent/settings-schema 25.1.0 → 26.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 +319 -0
- package/README.md +65 -33
- package/conformance/VERSION +1 -1
- package/conformance/cases/c27-hosts-array-1025/meta.json +1 -1
- package/conformance/cases/c48-s935-model-headers-transported/expected.json +18 -68
- package/conformance/cases/c48-s935-model-headers-transported/meta.json +1 -1
- package/conformance/cases/c67-s784-retired-field-loud/meta.json +1 -1
- package/conformance/cases/c77-prompts-center-artifact-carried/expected.json +5 -5
- package/conformance/cases/c77-prompts-center-artifact-carried/input.json +2 -2
- package/conformance/cases/c79-prompts-bad-worker-artifact-not-salvaged/expected.json +1 -1
- package/conformance/cases/c79-prompts-bad-worker-artifact-not-salvaged/input.json +3 -3
- package/conformance/cases/c80-prompts-wire-v2-verbatim/expected.json +1 -1
- package/conformance/cases/c80-prompts-wire-v2-verbatim/input.json +1 -1
- package/conformance/cases/c82-prompts-v1-catalog-refused/expected.json +1 -1
- package/conformance/cases/c82-prompts-v1-catalog-refused/input.json +1 -1
- package/conformance/cases/c83-prompts-bad-overlay-not-salvaged/expected.json +1 -1
- package/conformance/cases/c83-prompts-bad-overlay-not-salvaged/input.json +1 -1
- package/dist/cli.d.ts +7 -7
- package/dist/cli.js +11 -19
- package/dist/config-dir-io.js +3 -14
- package/dist/config-dir-migration.d.ts +1 -4
- package/dist/config-dir-migration.js +16 -22
- package/dist/config-document-refusal.d.ts +2 -3
- package/dist/config-fns.d.ts +3 -4
- package/dist/config-fns.js +4 -6
- package/dist/conformance/run.js +89 -29
- package/dist/conformance/types.d.ts +65 -39
- package/dist/execution-lane-index.d.ts +8 -19
- package/dist/execution-lane-index.js +6 -27
- package/dist/file-store.js +2 -3
- package/dist/fleet.d.ts +10 -47
- package/dist/fleet.js +13 -40
- package/dist/fs-failure.d.ts +5 -10
- package/dist/fs-failure.js +4 -8
- package/dist/hooks.d.ts +41 -6
- package/dist/hooks.js +68 -4
- package/dist/migration-receipt.d.ts +12 -14
- package/dist/migration-receipt.js +5 -7
- package/dist/node.js +1 -1
- package/dist/one-time-migrations.d.ts +9 -24
- package/dist/one-time-migrations.js +30 -796
- package/dist/remote-exec.js +2 -3
- package/dist/retired-envs.js +2 -0
- package/dist/retired-form.d.ts +12 -11
- package/dist/retired-form.js +12 -8
- package/dist/sandbox-git.d.ts +1 -1
- package/dist/sandbox-git.js +3 -3
- package/dist/scheduler-lifetime.d.ts +1 -1
- package/dist/scheduler-lifetime.js +1 -1
- package/dist/scheduler-store.d.ts +4 -29
- package/dist/scheduler-store.js +21 -14
- package/dist/types.d.ts +13 -19
- package/dist/types.js +75 -110
- package/dist/web-admin-credential.d.ts +2 -2
- package/dist/web-admin-credential.js +4 -4
- package/dist/worker-row-verdict.d.ts +1 -1
- package/dist/worker-row-verdict.js +1 -1
- package/dist/workers-rows.d.ts +2 -2
- package/dist/workers-rows.js +2 -2
- package/dist/zod-unwrap.d.ts +1 -1
- package/dist/zod-unwrap.js +1 -1
- package/docs/API-SURFACE.md +11 -12
- package/docs/CONFORMANCE.md +25 -13
- package/docs/CONSUMER-INTEGRATION.md +54 -27
- package/llms-full.txt +24 -22
- package/llms.txt +20 -14
- package/package.json +1 -1
- package/dist/runtime-lift-targets.d.ts +0 -7
- package/dist/runtime-lift-targets.js +0 -7
- package/dist/scheduler-store-migration.d.ts +0 -14
- package/dist/scheduler-store-migration.js +0 -14
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* ## 律(一条,写在最前:什么变少了)
|
|
5
5
|
* **读路径上零抬升臂。** 旧形只有一种去处:这里登记的一次性迁移把它改写成新形(调用方写回、幂等、登记窗);读写两面遇旧形一律
|
|
6
|
-
*
|
|
6
|
+
* 响亮拒,迁移还在时拒句点名迁移 id、窗关删码后止于今天的位(墓碑:retired 域 `RETIRED_DOMAINS` / 域 schema 里的retired 键墓碑字段 / 拒句尾的迁移指路)。11.0.0 之前,同样的
|
|
7
7
|
* 旧形由读路径上五只常驻臂每次读都抬一遍(治理三闸从 `runtime` 抬升、未知键扫描为 `runtime` 豁免、hosts 夹紧、调度店 durable 键重铸、
|
|
8
|
-
* workers 6.x 读时抬升),窗口只写在散文里、几个 major 都没关上。现在常驻臂 0
|
|
9
|
-
*
|
|
8
|
+
* workers 6.x 读时抬升),窗口只写在散文里、几个 major 都没关上。现在常驻臂 0 只;最后一只读时改写(调度店 durable 键重铸)26.0.0 到期删了,
|
|
9
|
+
* 读路径上不再有任何改写。
|
|
10
10
|
*
|
|
11
11
|
* **迁移只认形、不认义**:每一步的输入形在新契约下非法、输出形合法 ⇒ 重跑恒等,新写入的数据永远不会被当成旧数据再改一次,不需要版本围栏;
|
|
12
|
-
* 同一串字节换意思的改动一律**换表示**(SS-M6 因此是「`atModelAllowlist` → `atMention`」换字段,而不是翻 `[]` 的义)。
|
|
12
|
+
* 同一串字节换意思的改动一律**换表示**(11.0.0 的 SS-M6 因此是「`atModelAllowlist` → `atMention`」换字段,而不是翻 `[]` 的义)。
|
|
13
13
|
*
|
|
14
14
|
* ## 第二种机制:在配置根上铸一次事实(只有 SS-M11)
|
|
15
15
|
* 上面的「只认形」律管的是**改写存储文档**的迁移。SS-M11 不改写任何存储形:它在一份文档**缺席**处铸一份部署决定(配置根的 `config.env-models.json`,收据词 `minted`),
|
|
@@ -18,14 +18,13 @@
|
|
|
18
18
|
* ③ 它的旧形待遇是 `read-as-default`(缺席按读者的缺省 `kept` 读,没有拒句可点名)。窗、删法与删后由谁接住照样只写在登记表那一行。
|
|
19
19
|
*
|
|
20
20
|
* ## 入口(纯函数:不读环境、不读墙钟、不改入参、**不抬任何版本号**;SS-M11 除外,见上一节)
|
|
21
|
-
* · {@link migrateStoredDocuments} —— 一组**存储文档**(域名 → 文档;还有本机的 `remote-exec` —— `config.d/remote-exec.json
|
|
22
|
-
*
|
|
23
|
-
* `
|
|
21
|
+
* · {@link migrateStoredDocuments} —— 一组**存储文档**(域名 → 文档;还有本机的 `remote-exec` —— `config.d/remote-exec.json`:它是 `config.d`
|
|
22
|
+
* 能放的一份文档,所以照收,今天没有一步改写它)。一个 scope 的全部草稿、一个 principal 层(个人 models / mcp / skills / plugins)、回滚史里的一条单域行,各调一次。缺的域 = 不动
|
|
23
|
+
* (26.0.0 起没有一步要知道「缺席的域是从未设过还是没给」:那只问题的唯一读者 SS-M1 到期删了,`coverage` 选项随它删)。
|
|
24
24
|
* · {@link migrateEffectiveSnapshot} —— 一份**冻结的 effective**(发布快照、回滚历史里的整份快照、引擎的 last-known-good 文件)。改写规则
|
|
25
25
|
* 与草稿同(零语义变 ⇒ 不越过发布审批:改的是表示,不是已批准的内容);不从草稿重建;`version` / `updatedAt` 与其余信封键原样。
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* (retired 域)从结果里消失 —— 调用方据此判「哪份要写回、哪份要删」。**版本号归调用方**:草稿版本(待审的发布申请据它判「草稿动没动」)、
|
|
26
|
+
* 每条改动出一张 {@link MigrationReceipt}(闭集 `appliedAs` 词,只点名坐标、不带值);**没改的文档原样(同一引用)返回**,结果的文档集
|
|
27
|
+
* 与入参相同 —— 调用方据此判「哪份要写回」(26.0.0 起没有一步移除或新建文档;目录迁移对移除响亮抛)。**版本号归调用方**:草稿版本(待审的发布申请据它判「草稿动没动」)、
|
|
29
28
|
* 快照的 `version` / `globalRevision` 一概不动 —— 迁移改的是表示,要不要因此抬版本是调用方的决定,本包不替它做。
|
|
30
29
|
*
|
|
31
30
|
* ## 窗(规则写在这里一次,日期只在登记表)
|
|
@@ -34,116 +33,16 @@
|
|
|
34
33
|
* 回填。到期门 `test/one-time-migration-window-gate.test.ts`:今天晚于 `removableAfter` ⇒ 红(点名 `removal`);`package.json` ≥
|
|
35
34
|
* `introducedIn` 而两格仍 `null` ⇒ 红(回填门)。删码之后存量若还带旧形,由那一行 `afterRemoval` 点名的**既有**响亮臂接住。
|
|
36
35
|
*/
|
|
37
|
-
import { z } from "zod";
|
|
38
36
|
import { outgoingPath, redactSecrets } from "./config-fns.js";
|
|
39
|
-
import { LANE_ENV_OWNER, LATE_LANE_ENV_KEYS
|
|
40
|
-
import {
|
|
41
|
-
import { INTEGER } from "./integer.js";
|
|
42
|
-
import { NOT_PLAIN_DATA, UNINSPECTABLE, UninspectableError, captureJson, dataDescriptor, emptyDocument, inspect, ownEntriesOf, ownOrThrow, readDeclaredKey, sentenceOfMinted } from "./own-key-read.js";
|
|
37
|
+
import { LANE_ENV_OWNER, LATE_LANE_ENV_KEYS } from "./execution-lane-index.js";
|
|
38
|
+
import { NOT_PLAIN_DATA, UNINSPECTABLE, UninspectableError, captureJson, dataDescriptor, emptyDocument, ownEntriesOf, ownOrThrow, readDeclaredKey, sentenceOfMinted } from "./own-key-read.js";
|
|
43
39
|
import { isJsonArray, isPlainJsonObject, jsonShapeOf } from "./plain-json-object.js";
|
|
44
|
-
import { RUNTIME_LIFT_TARGETS } from "./runtime-lift-targets.js";
|
|
45
40
|
import { RETIRED_ROLE_WORDS } from "./retired-role-words.js";
|
|
46
|
-
import {
|
|
47
|
-
import { DOMAIN_SCHEMAS, HOSTS_ARRAY_MAX, HOST_NAME_MAX, NON_SECRET_URL, isDomainName, isRetiredDomainName } from "./types.js";
|
|
41
|
+
import { isDomainName, isRetiredDomainName } from "./types.js";
|
|
48
42
|
import { workerRowVerdict } from "./worker-row-verdict.js";
|
|
49
|
-
import { unwrapSchema } from "./zod-unwrap.js";
|
|
50
43
|
export { MIGRATION_APPLIED_AS, ONE_TIME_MIGRATION_IDS } from "./migration-receipt.js";
|
|
51
|
-
export { migrateSchedulerRecords } from "./scheduler-store-migration.js";
|
|
52
|
-
// ── 登记表 ─────────────────────────────────────────────────────────────────────────────────────────────
|
|
53
|
-
/** wire 删码位的 id(闭集;`W` = wire):没有存储形要改写、没有收据,与数据迁移同表登记只为让「什么时候删、删什么、删后谁接住」只写一处。 */
|
|
54
|
-
export const WIRE_RETIREMENT_IDS = ["SS-W1"];
|
|
55
44
|
/** 一次性迁移登记表 —— 本族各条窗的**唯一属主**。别处只写「窗见 `ONE_TIME_MIGRATIONS` 登记表」。 */
|
|
56
45
|
export const ONE_TIME_MIGRATIONS = [
|
|
57
|
-
{
|
|
58
|
-
id: "SS-M1",
|
|
59
|
-
oldForm: "refused",
|
|
60
|
-
introducedIn: "11.0.0",
|
|
61
|
-
releasedOn: "2026-10-10",
|
|
62
|
-
removableAfter: "2026-11-09",
|
|
63
|
-
rewrites: "the retired `runtime` domain document: the governance trio (autonomy / commandPolicy / approvalRequire) moves into `governance` when that domain " +
|
|
64
|
-
"was never set (else it is dropped — the set governance won); each of the five limit keys moves into `limits` when `limits` lacks it (else it is " +
|
|
65
|
-
"dropped — limits won); keys the runtime schema never read are dropped; then the runtime document is removed. Needs the whole scope " +
|
|
66
|
-
"(coverage \"scope\"); a partial set without both governance and limits is refused",
|
|
67
|
-
removal: "the next major after the window: delete the SS-M1 step (its private 10.x runtime schema included) and the `coverage` option of migrateStoredDocuments (SS-M1 is its only " +
|
|
68
|
-
"reader); RETIRED_DOMAINS stays — the SS-M1 clause leaves its sentence",
|
|
69
|
-
afterRemoval: "the RETIRED_DOMAINS tombstone (permanent): parseDomain / buildEffective / readEffectiveWire / FileConfigStore / readBundle refuse a runtime document that carries " +
|
|
70
|
-
"facts (RetiredDomainError). A rollback-history row that holds only a runtime document cannot be migrated on its own — rolling back to it is refused " +
|
|
71
|
-
"by the same tombstone (unrecoverable by design)",
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
id: "SS-M2",
|
|
75
|
-
oldForm: "refused",
|
|
76
|
-
introducedIn: "11.0.0",
|
|
77
|
-
releasedOn: "2026-10-10",
|
|
78
|
-
removableAfter: "2026-11-09",
|
|
79
|
-
rewrites: "hosts: an entry whose name is longer than 63 characters is removed, and an array over 1024 entries keeps its first 1024 — exactly what the " +
|
|
80
|
-
"read-side clamp did on every read since 0.8.1",
|
|
81
|
-
removal: "the next major after the window: delete the SS-M2 step; the two hosts bound messages lose their SS-M2 clause",
|
|
82
|
-
afterRemoval: "the hosts schema bounds (read and write): an over-long name drops its entry on read (`entry-dropped`), an over-long array degrades the hosts " +
|
|
83
|
-
"domain to its default (`domain-defaulted`)",
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
id: "SS-M3",
|
|
87
|
-
oldForm: "rewritten-on-read",
|
|
88
|
-
introducedIn: "11.0.0",
|
|
89
|
-
releasedOn: "2026-10-10",
|
|
90
|
-
removableAfter: "2026-11-09",
|
|
91
|
-
rewrites: "scheduler store: a durable record (lifetime not \"session\") still keyed by its session chain gets scope := principal ?? \"default\". Lazy-on-read: " +
|
|
92
|
-
"parseSchedulerStore applies it and the next writer persists it (a separate migration write would only add a competing writer) — the one read-time " +
|
|
93
|
-
"rewrite left in the package",
|
|
94
|
-
removal: "the next major after the window: delete scheduler-store-migration.ts, its call in parseSchedulerStore and the `one-time-migration` arm of SchedulerParseWarning",
|
|
95
|
-
afterRemoval: "no loud arm: a durable record still stored under its old session key is never found by its durable key (the job looks gone) — stated here " +
|
|
96
|
-
"instead of keeping a compatibility read",
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
id: "SS-M4",
|
|
100
|
-
oldForm: "refused",
|
|
101
|
-
introducedIn: "11.0.0",
|
|
102
|
-
releasedOn: "2026-10-10",
|
|
103
|
-
removableAfter: "2026-11-09",
|
|
104
|
-
rewrites: "workers: a 6.x row (env.REMOTE_EXEC + lane keys, runtime.sessionBackend / memoryBackend / db, coords.tidb*, secretRefs.tidbPasswordEnv, store " +
|
|
105
|
-
"keys in env) is rewritten into runtime.execution + runtime.store — since 16.0.0 straight into the 16.0.0 form: the lane lands as " +
|
|
106
|
-
"runtime.execution.lanes [<lane>], and env MEMORY_ENGINE_BACKEND \"tidb\" lands as store.memory.backend \"mysql\"; a row the step would have to guess for, or that still " +
|
|
107
|
-
"does not read after the rewrite, is refused and kept verbatim (readWorkersRows holds it on read). Runs last, in one workers-row step with SS-M12 (SS-M12's " +
|
|
108
|
-
"rewrite first, then this one's): the row is judged once, after both and after every other step's rewrite (SS-M7's fragment strip included)",
|
|
109
|
-
removal: "the next major after the window: delete the SS-M4 step; the 6.x tombstone fields of WorkerSpec and the reserved-env signpost stay — their SS-M4 clause goes",
|
|
110
|
-
afterRemoval: "the 6.x tombstone fields of WorkerSpec and the reserved-env refusal (permanent): a residual 6.x row is held by readWorkersRows, never rewritten",
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
id: "SS-M5",
|
|
114
|
-
oldForm: "refused",
|
|
115
|
-
introducedIn: "11.0.0",
|
|
116
|
-
releasedOn: "2026-10-10",
|
|
117
|
-
removableAfter: "2026-11-09",
|
|
118
|
-
rewrites: "models: an entry carrying both sealedApiKey and apiKeyEnv loses apiKeyEnv (the sealed key won — the effective reading before 11.0.0)",
|
|
119
|
-
removal: "the next major after the window: delete the SS-M5 step; the ModelEntry one-key rule loses its SS-M5 clause",
|
|
120
|
-
afterRemoval: "the ModelEntry one-key rule (permanent): a residual dual-key entry is dropped on read (`entry-dropped`) and refused on write",
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
id: "SS-M6",
|
|
124
|
-
oldForm: "refused",
|
|
125
|
-
introducedIn: "11.0.0",
|
|
126
|
-
releasedOn: "2026-10-10",
|
|
127
|
-
removableAfter: "2026-11-09",
|
|
128
|
-
rewrites: "models / rosters: atModelAllowlist → atMention by shape — [] → {mode:\"all\"}, a non-empty list → {mode:\"only\",models}; an absent key stays " +
|
|
129
|
-
"absent (the global default is all, a roster inherits); a document carrying both keys is refused (the step does not pick a winner)",
|
|
130
|
-
removal: "the next major after the window: delete the SS-M6 step; the atModelAllowlist tombstone fields stay — their SS-M6 clause goes",
|
|
131
|
-
afterRemoval: "the atModelAllowlist tombstone fields (permanent): a residual list is refused on read and write (models: the domain degrades to its default; " +
|
|
132
|
-
"rosters: the scope fails to read)",
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
id: "SS-M7",
|
|
136
|
-
oldForm: "refused",
|
|
137
|
-
introducedIn: "11.0.0",
|
|
138
|
-
releasedOn: "2026-10-10",
|
|
139
|
-
removableAfter: "2026-11-09",
|
|
140
|
-
rewrites: "every NON_SECRET_URL seat in a domain document (derived from the domain schemas, not listed by hand — today models.models[].baseUrl, " +
|
|
141
|
-
"mcp.servers[].transport.url, a2a.peers[].url, a2a.peers[].cardUrl, execution.sessionMirror.engineUrl, workers.workers[].coords.gitApiBaseUrl): `#` and everything after it are removed " +
|
|
142
|
-
"(a fragment never goes on the wire); the same walk covers config.d/remote-exec.json, derived from its schema the same way " +
|
|
143
|
-
"(today the k8s apiUrl and s3Snapshot.endpoint) — the command-line migrate reads and rewrites it as one more document",
|
|
144
|
-
removal: "the next major after the window: delete the SS-M7 step and its schema walk; the NON_SECRET_URL fragment rule loses its SS-M7 clause",
|
|
145
|
-
afterRemoval: "the NON_SECRET_URL shape judge, which refuses a fragment (`#` included) on read and write",
|
|
146
|
-
},
|
|
147
46
|
{
|
|
148
47
|
id: "SS-M8",
|
|
149
48
|
oldForm: "refused",
|
|
@@ -157,19 +56,6 @@ export const ONE_TIME_MIGRATIONS = [
|
|
|
157
56
|
afterRemoval: "the retired role-word tombstone (permanent): a residual roles.team / roles.synthesize is refused on read and write (read: the entry is dropped " +
|
|
158
57
|
"when other roles survive, else models degrades to its default; rosters: the scope fails to read)",
|
|
159
58
|
},
|
|
160
|
-
{
|
|
161
|
-
id: "SS-M9",
|
|
162
|
-
oldForm: "refused",
|
|
163
|
-
introducedIn: "11.0.0",
|
|
164
|
-
releasedOn: "2026-10-10",
|
|
165
|
-
removableAfter: "2026-11-09",
|
|
166
|
-
rewrites: "models: the structural `default` key → `roles.default = {model}` by what the default model was before 11.0.0 (the server's default " +
|
|
167
|
-
"resolution read `default` first, and the main task ran it): `roles.default` absent ⇒ moved there; the same name already there ⇒ " +
|
|
168
|
-
"moved (the duplicate goes); a different `roles.default` ⇒ that one is dropped as shadowed and `default` moves in; a `default` that is " +
|
|
169
|
-
"not a non-empty string is refused (it does not read today either)",
|
|
170
|
-
removal: "the next major after the window: delete the SS-M9 step; the models.default tombstone field stays — its SS-M9 clause goes",
|
|
171
|
-
afterRemoval: "the models.default tombstone field (permanent): a residual key is refused on read and write (the models domain degrades to its default)",
|
|
172
|
-
},
|
|
173
59
|
{
|
|
174
60
|
id: "SS-M10",
|
|
175
61
|
oldForm: "refused",
|
|
@@ -217,36 +103,19 @@ export const ONE_TIME_MIGRATIONS = [
|
|
|
217
103
|
"it does not (dropped-inert: the engine reads it only on the device lane). Refused and kept verbatim (readWorkersRows holds it on read): a row carrying both " +
|
|
218
104
|
"lane and lanes, a DEVICE_RELAY_URL on a row that declares the device lane but sets it from a host secret (secretEnv: the value cannot be read) or writes it " +
|
|
219
105
|
"both in env and in coords, and a row that still does not read after the rewrite — a device row with no DEVICE_RELAY_URL among them (a required coordinate " +
|
|
220
|
-
"since 16.0.0; the step does not guess between a URL and \"none\"). Runs
|
|
221
|
-
"
|
|
106
|
+
"since 16.0.0; the step does not guess between a URL and \"none\"). Runs last, after every pure-rewrite step: this step's rewrite, then one judgement " +
|
|
107
|
+
"of the row (a refusal of that judgement is filed under SS-M12)",
|
|
222
108
|
removal: "the next major after the window: delete the SS-M12 step; the runtime.execution.lane tombstone field, the memory-backend refusal for \"tidb\" and the " +
|
|
223
109
|
"reserved-env signpost for DEVICE_RELAY_URL stay — their SS-M12 clause goes",
|
|
224
110
|
afterRemoval: "the runtime.execution.lane tombstone field, the memory-backend refusal for \"tidb\" and the reserved-env refusal for DEVICE_RELAY_URL (permanent): a residual " +
|
|
225
111
|
"15.x row is refused on write and held by readWorkersRows on read, never rewritten",
|
|
226
112
|
},
|
|
227
|
-
{
|
|
228
|
-
// 一条 wire 位的删码登记,不是数据迁移(id 在 WIRE_RETIREMENT_IDS,不在收据闭集)。
|
|
229
|
-
id: "SS-W1",
|
|
230
|
-
oldForm: "not-stored",
|
|
231
|
-
introducedIn: "11.0.0",
|
|
232
|
-
releasedOn: "2026-10-10",
|
|
233
|
-
removableAfter: "2026-11-09",
|
|
234
|
-
rewrites: "nothing stored: the flat engine-state dialect of the fleet wire — InstanceHealth.draining / InstanceHealth.drainingSince and " +
|
|
235
|
-
"InstanceAnnouncement.ready / InstanceAnnouncement.draining / InstanceAnnouncement.restart / InstanceAnnouncement.generation / " +
|
|
236
|
-
"InstanceAnnouncement.leaseState / InstanceAnnouncement.leaseUntil (and the same flat keys /health passes through untyped) — stays on " +
|
|
237
|
-
"both shapes for its contraction window: engines keep sending it for readers that predate the engine signal, and no reader in this " +
|
|
238
|
-
"package reads it (the engine's state is read only from EngineSignal under ENGINE_SIGNAL_KEY)",
|
|
239
|
-
removal: "the next major after the window: delete the flat engine-state dialect from InstanceHealth and InstanceAnnouncement and this row; " +
|
|
240
|
-
"engines stop sending it in the same wave",
|
|
241
|
-
afterRemoval: "a body that still carries the flat keys is read exactly as today: the heartbeat shape strips them, /health passes them through " +
|
|
242
|
-
"untyped, and no judge reads them — an engine that does not carry EngineSignal is no-engine-signal, never routable",
|
|
243
|
-
},
|
|
244
113
|
];
|
|
245
114
|
/**
|
|
246
115
|
* 迁移一组存储文档(见文件头「入口」)。纯函数;没改的文档原样返回;**不抬任何版本号**(结果里没有版本 —— 那是调用方的)。
|
|
247
116
|
* 重跑恒等:第二次跑零改动,只剩第一次就 `refused` 的那几张收据(那些坐标原样留着,读侧照旧拒)。
|
|
248
117
|
*/
|
|
249
|
-
export function migrateStoredDocuments(docs
|
|
118
|
+
export function migrateStoredDocuments(docs) {
|
|
250
119
|
const docsShape = jsonShapeOf(docs);
|
|
251
120
|
switch (docsShape) {
|
|
252
121
|
case "plain":
|
|
@@ -263,15 +132,6 @@ export function migrateStoredDocuments(docs, opts) {
|
|
|
263
132
|
throw new Error(`migrateStoredDocuments: unhandled shape ${String(unhandled)}`);
|
|
264
133
|
}
|
|
265
134
|
}
|
|
266
|
-
switch (opts.coverage) {
|
|
267
|
-
case "scope":
|
|
268
|
-
case "partial":
|
|
269
|
-
break;
|
|
270
|
-
default: {
|
|
271
|
-
const unhandled = opts.coverage;
|
|
272
|
-
throw new TypeError(`migrateStoredDocuments: coverage must be "scope" or "partial" (got ${JSON.stringify(unhandled)})`);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
135
|
// 工作副本是**隔离原型**(`COPY_PROTOTYPE`,没有继承来的成员)的袋(它的读没有继承可说:`Object.prototype.models` 被污染成数据值时,`out.models` 不会读到一份「存储文档」),文档集只读一次(每个域文档一个值);
|
|
276
136
|
// 之后每一步对文档里固定键的读都经内核的自有键读(`ownOrThrow`),读不出的存储文档 ⇒ 下面那一处统一抛 TypeError(带全包唯一那一句)—— 迁移本来就是抛的读口,不另造失败臂
|
|
277
137
|
const entries = ownEntriesOf(docs);
|
|
@@ -281,19 +141,10 @@ export function migrateStoredDocuments(docs, opts) {
|
|
|
281
141
|
for (const [k, v] of entries.value)
|
|
282
142
|
Object.defineProperty(out, k, dataDescriptor(v));
|
|
283
143
|
const receipts = [];
|
|
284
|
-
// 步序的律:纯改写步在前,拿新 schema 终判改写结果的 workers 行步最后 ——
|
|
285
|
-
// fragment)不会先被它拒掉(否则一跑 refused、二跑才过:既不是一次完成,也不幂等)。同一条律落到行内:一行可以同时带 SS-M12 认的形(7.0+ 的单值车道)
|
|
286
|
-
// 与 SS-M4 认的形(6.x 的店字段),所以两只迁移在**一步**里按行做 —— SS-M12 先改(7.0+ 行 env 里的晚登记车道键 `DEVICE_RELAY_URL` 在 SS-M4 眼里是
|
|
287
|
-
// 「新旧两形并存」,先由 SS-M12 归位),SS-M4 再改,改完**判一次**;各判各的会互相卡死(一只判「另一只的形还在」而拒)。
|
|
144
|
+
// 步序的律:纯改写步在前,拿新 schema 终判改写结果的 workers 行步最后 —— 它判的是**全部**改写之后的行(否则一跑 refused、二跑才过:既不是一次完成,也不幂等)。
|
|
288
145
|
try {
|
|
289
|
-
stepRuntimeDomain(out, opts.coverage, receipts);
|
|
290
|
-
stepHostsBounds(out, receipts);
|
|
291
|
-
stepModelKeyOneOf(out, receipts);
|
|
292
|
-
stepAtMention(out, receipts);
|
|
293
146
|
stepRetiredRoleWords(out, receipts);
|
|
294
|
-
stepModelsDefault(out, receipts);
|
|
295
147
|
stepPromptsAxes(out, receipts);
|
|
296
|
-
stepUrlFragments(out, receipts);
|
|
297
148
|
stepWorkersRows(out, receipts);
|
|
298
149
|
}
|
|
299
150
|
catch (e) {
|
|
@@ -305,8 +156,7 @@ export function migrateStoredDocuments(docs, opts) {
|
|
|
305
156
|
return { docs: { ...out }, receipts }; // 交出去的是寻常对象(隔离原型的袋只是工作副本)
|
|
306
157
|
}
|
|
307
158
|
/**
|
|
308
|
-
* 迁移一份冻结的 effective(见文件头「入口」):域键过与 {@link migrateStoredDocuments}
|
|
309
|
-
* 都物化了),其余键(`version` / `updatedAt` / wire 上的 `skills` 清单形 …)原样。键序保持;被移除的retired 域不在;effective 没改 ⇒ 同一引用。
|
|
159
|
+
* 迁移一份冻结的 effective(见文件头「入口」):域键过与 {@link migrateStoredDocuments} 同一组步,其余键(`version` / `updatedAt` / wire 上的 `skills` 清单形 …)原样。键序保持;被移除的retired 域不在;effective 没改 ⇒ 同一引用。
|
|
310
160
|
* 不是对象 ⇒ 原样返回(判形是读者的事)。
|
|
311
161
|
*/
|
|
312
162
|
export function migrateEffectiveSnapshot(effective) {
|
|
@@ -335,7 +185,7 @@ export function migrateEffectiveSnapshot(effective) {
|
|
|
335
185
|
for (const [k, v] of entriesOfEffective)
|
|
336
186
|
if (isDomainName(k) || isRetiredDomainName(k))
|
|
337
187
|
Object.defineProperty(docs, k, dataDescriptor(v));
|
|
338
|
-
const m = migrateStoredDocuments(docs
|
|
188
|
+
const m = migrateStoredDocuments(docs);
|
|
339
189
|
const changed = Object.keys(docs).some((k) => !Object.prototype.hasOwnProperty.call(m.docs, k) || m.docs[k] !== docs[k]) || Object.keys(m.docs).some((k) => !Object.prototype.hasOwnProperty.call(docs, k));
|
|
340
190
|
if (!changed)
|
|
341
191
|
return { effective, receipts: m.receipts };
|
|
@@ -387,381 +237,12 @@ function moved(migration, document, path, to) {
|
|
|
387
237
|
function refused(migration, document, path, reason) {
|
|
388
238
|
return { migration, document, path: outgoingPath(path), appliedAs: "refused", reason: redactSecrets(reason) };
|
|
389
239
|
}
|
|
390
|
-
// ── SS-M1:retired `runtime` 域 ────────────────────────────────────────────────────────────────────────────
|
|
391
|
-
/** 10.x 的 runtime 域 schema(迁移私有:判「这份 runtime 文档迁移前读不读得进」—— 读不进的文档今天就让整个 scope 读不出,没有生效读法可保)。 */
|
|
392
|
-
const RUNTIME_10X = z.object({
|
|
393
|
-
rateLimitPerMin: INTEGER.nonnegative().optional(),
|
|
394
|
-
maxTaskCostUsd: z.number().finite().nonnegative().optional(),
|
|
395
|
-
maxTaskTokens: INTEGER.nonnegative().optional(),
|
|
396
|
-
maxPrincipalCostUsd: z.number().finite().nonnegative().optional(),
|
|
397
|
-
costQuotaWindowSec: INTEGER.positive().optional(),
|
|
398
|
-
});
|
|
399
|
-
const GOVERNANCE_TRIO = ["autonomy", "commandPolicy", "approvalRequire"];
|
|
400
|
-
const LIMIT_KEYS = ["rateLimitPerMin", "maxTaskCostUsd", "maxTaskTokens", "maxPrincipalCostUsd", "costQuotaWindowSec"];
|
|
401
|
-
function stepRuntimeDomain(out, coverage, receipts) {
|
|
402
|
-
if (!Object.prototype.hasOwnProperty.call(out, "runtime"))
|
|
403
|
-
return;
|
|
404
|
-
const raw = ownOrThrow(out, "runtime");
|
|
405
|
-
if (raw === undefined)
|
|
406
|
-
return;
|
|
407
|
-
const refuse = (reason) => void receipts.push(refused("SS-M1", "runtime", [], reason));
|
|
408
|
-
if (isPlainJsonObject(raw) && Object.keys(raw).length === 0) {
|
|
409
|
-
delete out.runtime;
|
|
410
|
-
receipts.push(receipt("SS-M1", "runtime", [], "dropped-inert"));
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
if (!isPlainJsonObject(raw))
|
|
414
|
-
return refuse("the stored runtime document is not a JSON object — the scope does not read today either; fix it by hand");
|
|
415
|
-
if (coverage === "partial" && !RUNTIME_LIFT_TARGETS.every((target) => has(out, target))) {
|
|
416
|
-
return refuse("a runtime document migrates only together with its scope's governance and limits documents (coverage \"scope\") — on its own there is no telling whether governance was ever set");
|
|
417
|
-
}
|
|
418
|
-
const parsed = RUNTIME_10X.safeParse(raw);
|
|
419
|
-
if (!parsed.success)
|
|
420
|
-
return refuse("the stored runtime document does not read under the 10.x runtime schema — the scope does not read today either; fix it by hand");
|
|
421
|
-
const limitsRaw = ownOrThrow(out, "limits");
|
|
422
|
-
if (limitsRaw !== undefined && !isPlainJsonObject(limitsRaw))
|
|
423
|
-
return refuse("the scope's limits document is not a JSON object — the scope does not read today either; fix limits first");
|
|
424
|
-
const trio = GOVERNANCE_TRIO.filter((k) => has(raw, k) && ownOrThrow(raw, k) !== undefined);
|
|
425
|
-
if (trio.length > 0) {
|
|
426
|
-
// 迁移前的读法:governance 域**从未设过**(店里没有这份文档)⇒ 读侧从 runtime 抬升三闸;设过 ⇒ 设过的那份赢,runtime 上的三闸从未生效。
|
|
427
|
-
if (ownOrThrow(out, "governance") === undefined) {
|
|
428
|
-
out.governance = Object.fromEntries(trio.map((k) => [k, ownOrThrow(raw, k)]));
|
|
429
|
-
for (const k of trio)
|
|
430
|
-
receipts.push(moved("SS-M1", "runtime", [k], { document: "governance", path: [k] }));
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
for (const k of trio)
|
|
434
|
-
receipts.push(receipt("SS-M1", "runtime", [k], "dropped-shadowed"));
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
const limitKeys = LIMIT_KEYS.filter((k) => parsed.data[k] !== undefined);
|
|
438
|
-
if (limitKeys.length > 0) {
|
|
439
|
-
// 迁移前的读法(消费方):`limits` 有这一键 ⇒ limits 赢;没有 ⇒ 读 runtime 上的值。
|
|
440
|
-
const limits = isPlainJsonObject(limitsRaw) ? { ...limitsRaw } : {};
|
|
441
|
-
let added = false;
|
|
442
|
-
for (const k of limitKeys) {
|
|
443
|
-
if (Object.prototype.hasOwnProperty.call(limits, k))
|
|
444
|
-
receipts.push(receipt("SS-M1", "runtime", [k], "dropped-shadowed"));
|
|
445
|
-
else {
|
|
446
|
-
limits[k] = parsed.data[k];
|
|
447
|
-
added = true;
|
|
448
|
-
receipts.push(moved("SS-M1", "runtime", [k], { document: "limits", path: [k] }));
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
if (added)
|
|
452
|
-
out.limits = limits;
|
|
453
|
-
}
|
|
454
|
-
const handled = new Set([...trio, ...limitKeys]);
|
|
455
|
-
for (const k of Object.keys(raw))
|
|
456
|
-
if (!handled.has(k))
|
|
457
|
-
receipts.push(receipt("SS-M1", "runtime", [k], "dropped-inert")); // runtime schema 从未读过的键
|
|
458
|
-
delete out.runtime;
|
|
459
|
-
}
|
|
460
|
-
// ── SS-M2:hosts 超界 ───────────────────────────────────────────────────────────────────────────────────
|
|
461
|
-
function stepHostsBounds(out, receipts) {
|
|
462
|
-
const doc = ownOrThrow(out, "hosts");
|
|
463
|
-
if (!isPlainJsonObject(doc))
|
|
464
|
-
return;
|
|
465
|
-
const hostRows = ownOrThrow(doc, "hosts");
|
|
466
|
-
if (!isJsonArray(hostRows))
|
|
467
|
-
return;
|
|
468
|
-
const rows = hostRows;
|
|
469
|
-
let kept = [];
|
|
470
|
-
const dropped = [];
|
|
471
|
-
rows.forEach((row, index) => {
|
|
472
|
-
const name = isPlainJsonObject(row) ? ownOrThrow(row, "name") : undefined;
|
|
473
|
-
if (typeof name === "string" && name.length > HOST_NAME_MAX)
|
|
474
|
-
dropped.push(index);
|
|
475
|
-
else
|
|
476
|
-
kept.push({ row, index });
|
|
477
|
-
});
|
|
478
|
-
if (kept.length > HOSTS_ARRAY_MAX) {
|
|
479
|
-
for (const { index } of kept.slice(HOSTS_ARRAY_MAX))
|
|
480
|
-
dropped.push(index);
|
|
481
|
-
kept = kept.slice(0, HOSTS_ARRAY_MAX);
|
|
482
|
-
}
|
|
483
|
-
if (dropped.length === 0)
|
|
484
|
-
return;
|
|
485
|
-
for (const index of dropped.sort((a, b) => a - b))
|
|
486
|
-
receipts.push(receipt("SS-M2", "hosts", ["hosts", index], "dropped-inert"));
|
|
487
|
-
out.hosts = { ...doc, hosts: kept.map((k) => k.row) };
|
|
488
|
-
}
|
|
489
|
-
// ── SS-M4:workers 6.x 行 ───────────────────────────────────────────────────────────────────────────────
|
|
490
|
-
/** 6.x 删除项:`[容器, 键]`。 */
|
|
491
|
-
const SIX_X_STORE_FIELDS = [
|
|
492
|
-
["runtime", "sessionBackend"],
|
|
493
|
-
["runtime", "memoryBackend"],
|
|
494
|
-
["runtime", "db"],
|
|
495
|
-
["coords", "tidbHost"],
|
|
496
|
-
["coords", "tidbPort"],
|
|
497
|
-
["coords", "tidbUser"],
|
|
498
|
-
["secretRefs", "tidbPasswordEnv"],
|
|
499
|
-
];
|
|
500
|
-
/** 引擎 `MEMORY_ENGINE` 的两族词(比较前 trim + 小写)。 */
|
|
501
|
-
const MEMORY_ENGINE_ON_WORDS = ["on", "true", "1", "yes", "enabled"];
|
|
502
|
-
const MEMORY_ENGINE_OFF_WORDS = ["off", "false", "0", "no", "disabled"];
|
|
503
|
-
/** 引擎 `MYSQL_PORT` 的缺省 —— 旧形没写端口时引擎连的就是它。 */
|
|
504
|
-
const MYSQL_DEFAULT_PORT = 3306;
|
|
505
|
-
const isLaneWord = (v) => typeof v === "string" && EXECUTION_LANE_WORDS.some((w) => w === v);
|
|
506
|
-
const isStoreWord = (v) => typeof v === "string" && STORE_BACKENDS.some((w) => w === v);
|
|
507
|
-
/** 6.x 引擎收的 `MEMORY_ENGINE_BACKEND` 词 → 今天的词(16.0.0 起 MySQL 族那一只叫 `mysql`,与店词同字)。键 = 6.x 引擎的闭集(它见 `mysql` 拒启)。 */
|
|
508
|
-
const SIX_X_MEMORY_BACKEND = new Map([
|
|
509
|
-
["file", "file"],
|
|
510
|
-
["pg", "pg"],
|
|
511
|
-
["tidb", "mysql"],
|
|
512
|
-
]);
|
|
513
|
-
/** 拒因里只点名形如词的值(短、小写);其余一律不回显(值可能是粘错位置的凭据)。 */
|
|
514
|
-
const describeWord = (v) => (typeof v === "string" && /^[a-z0-9][a-z0-9-]{0,31}$/.test(v) ? `"${v}"` : "(value not shown)");
|
|
515
|
-
const UNCHANGED = { kind: "unchanged" };
|
|
516
|
-
/**
|
|
517
|
-
* 一行的 6.x 改写。规则(每个旧键恰好一种去处):车道 —— `env.REMOTE_EXEC` 是车道词 ⇒ `runtime.execution.lanes`(一元表),同车道的 env 键 ⇒ `coords`、
|
|
518
|
-
* 同车道的 `secretEnv` 密钥 ⇒ `secretRefs`;别车道的键与 `REQUIRE_EXECUTION_LANE` ⇒ 丢(引擎只读被点名车道那一臂);enabled 且无车道 ⇒ 拒
|
|
519
|
-
* (不替运维猜车道)。店 —— `sessionBackend` ⇒ `store.session`(`tidb` ⇒ `mysql`);`memoryBackend` ⇒ 丢(从未到达引擎);`coords.tidb*` +
|
|
520
|
-
* `runtime.db` ⇒ `store.db`(缺端口 ⇒ 3306),`tidbPasswordEnv` ⇒ `dbPasswordEnv`;无 host ⇒ `store.backend = local`;env 里的
|
|
521
|
-
* `DB_BACKEND` / `MEMORY_ENGINE` / `MEMORY_ENGINE_BACKEND` ⇒ 搬进 `store`(方言 `tidb` ⇒ `mysql`)。表达不了 ⇒ 拒:值写错了栏、不认识的词、新旧两形并存、
|
|
522
|
-
* `DB_BACKEND=pg` 配 MySQL 族坐标。不是 6.x 形的行(没有任何旧键,该有的块都在)⇒ 不动 —— 它读不读得进是 `readWorkersRows` 的事。
|
|
523
|
-
*/
|
|
524
|
-
function migrateWorkerRow(row) {
|
|
525
|
-
const refuse = (field, reason) => ({ kind: "refused", field, reason });
|
|
526
|
-
// ① 判「这一行要不要迁」只做**浅读**:行上的固定键、`env` / `secretEnv` / `runtime` / `coords` / `secretRefs` 这几块的键名与在场(自有键,读不出 ⇒ 抛)—— 不碰别的字段,更不整行深拷:
|
|
527
|
-
// 没有 6.x 键的行(绝大多数)一个字段都不动,所以一份合法的、哪个别的字段嵌了多深的存量文档都不会因为这一步抛(v14.6.0 的答案);拒因也都是浅读给得出的,不必先拷。
|
|
528
|
-
const peek = (o, k) => (isPlainJsonObject(o) ? ownOrThrow(o, k) : undefined);
|
|
529
|
-
const keysOfRec = (rec) => {
|
|
530
|
-
if (!isPlainJsonObject(rec))
|
|
531
|
-
return [];
|
|
532
|
-
const keys = inspect(() => Object.keys(rec));
|
|
533
|
-
if (!keys.ok)
|
|
534
|
-
throw new UninspectableError();
|
|
535
|
-
return keys.value;
|
|
536
|
-
};
|
|
537
|
-
const enabled = peek(row, "enabled") !== false;
|
|
538
|
-
const rawEnv = peek(row, "env");
|
|
539
|
-
const rawSecretEnv = peek(row, "secretEnv");
|
|
540
|
-
const rawRuntime = peek(row, "runtime");
|
|
541
|
-
const rawSecretRefs = peek(row, "secretRefs");
|
|
542
|
-
const laneKeysOf = (rec) => keysOfRec(rec).filter(isLaneEnvKey);
|
|
543
|
-
const storeKeysOf = (rec) => (isPlainJsonObject(rec) ? STORE_ENV_KEYS.filter((k) => has(rec, k)) : []);
|
|
544
|
-
const envLaneKeys = laneKeysOf(rawEnv);
|
|
545
|
-
const secretLaneKeys = laneKeysOf(rawSecretEnv);
|
|
546
|
-
const envStoreKeys = storeKeysOf(rawEnv);
|
|
547
|
-
const secretStoreKeys = storeKeysOf(rawSecretEnv);
|
|
548
|
-
const oldStoreFields = SIX_X_STORE_FIELDS.filter(([c, k]) => has(peek(row, c), k));
|
|
549
|
-
const hasExecution = has(rawRuntime, "execution");
|
|
550
|
-
const hasStore = has(rawRuntime, "store");
|
|
551
|
-
const laneTouched = envLaneKeys.length + secretLaneKeys.length > 0;
|
|
552
|
-
const storeTouched = oldStoreFields.length + envStoreKeys.length + secretStoreKeys.length > 0;
|
|
553
|
-
if (!laneTouched && !storeTouched)
|
|
554
|
-
return UNCHANGED; // 没有任何 6.x 键:不是本步的形
|
|
555
|
-
if (hasExecution && laneTouched) {
|
|
556
|
-
return refuse(["runtime", "execution"], `declares runtime.execution AND execution-lane keys in env / secretEnv (${[...envLaneKeys, ...secretLaneKeys].join(", ")}) — keep one form; the migration does not pick a winner`);
|
|
557
|
-
}
|
|
558
|
-
// 新形的店字段有两处:`runtime.store` 与 `secretRefs.dbPasswordEnv`。任一在场 ∧ 还有旧店字段 ⇒ 两形并存,不挑赢家。
|
|
559
|
-
const newStoreFields = [...(hasStore ? ["runtime.store"] : []), ...(has(rawSecretRefs, "dbPasswordEnv") ? ["secretRefs.dbPasswordEnv"] : [])];
|
|
560
|
-
if (newStoreFields.length > 0 && storeTouched) {
|
|
561
|
-
const old = [...oldStoreFields.map(([c, k]) => `${c}.${k}`), ...envStoreKeys.map((k) => `env.${k}`), ...secretStoreKeys.map((k) => `secretEnv.${k}`)];
|
|
562
|
-
return refuse(["runtime", "store"], `declares the 7.0.0 store fields (${newStoreFields.join(", ")}) AND 6.x store fields (${old.join(", ")}) — keep one form; the migration does not pick a winner`);
|
|
563
|
-
}
|
|
564
|
-
const secretStoreKey = secretStoreKeys[0];
|
|
565
|
-
if (secretStoreKey !== undefined)
|
|
566
|
-
return refuse(["secretEnv", secretStoreKey], `${secretStoreKey} is set from a host secret — the migration cannot read it; declare runtime.store by hand`);
|
|
567
|
-
if (has(rawSecretEnv, "REMOTE_EXEC"))
|
|
568
|
-
return refuse(["secretEnv", "REMOTE_EXEC"], "the execution lane is set from a host secret — the migration cannot read it; declare runtime.execution.lanes by hand");
|
|
569
|
-
const needLane = !hasExecution && (enabled || laneTouched);
|
|
570
|
-
const needStore = !hasStore && (enabled || storeTouched);
|
|
571
|
-
// 收尾要问「原来的 env / secretEnv 有没有键」:在拷之前、浅读里问好
|
|
572
|
-
const envHadKeys = keysOfRec(rawEnv).length > 0;
|
|
573
|
-
const secretEnvHadKeys = keysOfRec(rawSecretEnv).length > 0;
|
|
574
|
-
// ② 只有**要改写的行**才拍快照:整行的自有键深副本(隔离原型,值只从每个成员那一份描述符里取,没有字面深度上限 —— JSON 往返能成的都拷得出);下面对 `env` / `coords` / `runtime` / `secretRefs` 里固定键的读
|
|
575
|
-
// 都读在副本上,没写的键不会被 `Object.prototype` 上被污染的同名数据值填上(那会把污染值写进改写后的存储行)。坏形只有三种:读不出 / 环 / 非纯数据 ⇒ 抛(迁移本来就抛,上一层统一成 TypeError)
|
|
576
|
-
const working = captureJson(row);
|
|
577
|
-
if (!working.ok)
|
|
578
|
-
throw new UninspectableError(working.sentence);
|
|
579
|
-
const w = working.value;
|
|
580
|
-
const runtime = isPlainJsonObject(w.runtime) ? w.runtime : emptyDocument();
|
|
581
|
-
w.runtime = runtime;
|
|
582
|
-
const env = isPlainJsonObject(w.env) ? w.env : emptyDocument();
|
|
583
|
-
const secretEnv = isPlainJsonObject(w.secretEnv) ? w.secretEnv : emptyDocument();
|
|
584
|
-
const coords = isPlainJsonObject(w.coords) ? w.coords : emptyDocument();
|
|
585
|
-
const secretRefs = isPlainJsonObject(w.secretRefs) ? w.secretRefs : emptyDocument();
|
|
586
|
-
const dropped = [];
|
|
587
|
-
const drop = (container, slot, key) => {
|
|
588
|
-
delete container[key];
|
|
589
|
-
dropped.push([slot, key]);
|
|
590
|
-
};
|
|
591
|
-
// ── 车道
|
|
592
|
-
if (needLane) {
|
|
593
|
-
const rx = env.REMOTE_EXEC;
|
|
594
|
-
if (rx === undefined || rx === "") {
|
|
595
|
-
if (enabled) {
|
|
596
|
-
return refuse(["env", "REMOTE_EXEC"], `an enabled worker names no execution lane (env.REMOTE_EXEC is unset) — it boots with no hands and still reports tasks completed. ` +
|
|
597
|
-
`The migration does not guess a lane: set runtime.execution.lanes (${EXECUTION_LANE_WORDS.join(" | ")}) by hand, or disable the worker`);
|
|
598
|
-
}
|
|
599
|
-
for (const k of envLaneKeys)
|
|
600
|
-
drop(env, "env", k); // 停用且没点名车道 ⇒ 每个车道键都是惰性的
|
|
601
|
-
for (const k of secretLaneKeys)
|
|
602
|
-
drop(secretEnv, "secretEnv", k);
|
|
603
|
-
}
|
|
604
|
-
else {
|
|
605
|
-
if (!isLaneWord(rx)) {
|
|
606
|
-
return refuse(["env", "REMOTE_EXEC"], `env.REMOTE_EXEC ${describeWord(rx)} is not an execution lane (${EXECUTION_LANE_WORDS.join(" | ")}) — the engine refuses to start with it; set runtime.execution.lanes by hand`);
|
|
607
|
-
}
|
|
608
|
-
const lane = rx;
|
|
609
|
-
const laneCoords = emptyDocument();
|
|
610
|
-
const laneSecretRefs = emptyDocument();
|
|
611
|
-
for (const k of envLaneKeys) {
|
|
612
|
-
if (k === "REMOTE_EXEC") {
|
|
613
|
-
delete env[k];
|
|
614
|
-
continue;
|
|
615
|
-
}
|
|
616
|
-
const owner = LANE_ENV_OWNER.get(k);
|
|
617
|
-
if (owner === undefined || owner.lane !== lane) {
|
|
618
|
-
drop(env, "env", k); // REQUIRE_EXECUTION_LANE(声明了车道就恒渲 true)与别车道的键(引擎只读被点名那一臂)
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
const v = env[k];
|
|
622
|
-
if (owner.secret) {
|
|
623
|
-
return refuse(["env", k], `${k} is a secret of lane "${lane}" but env carries it as a literal value — the migration does not move a value into a secret slot: put it in the host secret source and reference it from runtime.execution.secretRefs.${k}`);
|
|
624
|
-
}
|
|
625
|
-
if (typeof v !== "string")
|
|
626
|
-
return refuse(["env", k], `env.${k} is not a string`);
|
|
627
|
-
laneCoords[k] = v;
|
|
628
|
-
delete env[k];
|
|
629
|
-
}
|
|
630
|
-
for (const k of secretLaneKeys) {
|
|
631
|
-
const owner = LANE_ENV_OWNER.get(k);
|
|
632
|
-
if (owner === undefined || owner.lane !== lane) {
|
|
633
|
-
drop(secretEnv, "secretEnv", k);
|
|
634
|
-
continue;
|
|
635
|
-
}
|
|
636
|
-
const v = secretEnv[k];
|
|
637
|
-
if (!owner.secret) {
|
|
638
|
-
return refuse(["secretEnv", k], `${k} is a non-secret coordinate of lane "${lane}" but is set from a host secret — the migration cannot read the value; write it in runtime.execution.coords.${k} by hand`);
|
|
639
|
-
}
|
|
640
|
-
if (typeof v !== "string")
|
|
641
|
-
return refuse(["secretEnv", k], `secretEnv.${k} is not a string`);
|
|
642
|
-
laneSecretRefs[k] = v;
|
|
643
|
-
delete secretEnv[k];
|
|
644
|
-
}
|
|
645
|
-
runtime.execution = { lanes: [lane], coords: laneCoords, secretRefs: laneSecretRefs };
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
// ── 店
|
|
649
|
-
if (needStore) {
|
|
650
|
-
if (Object.hasOwn(runtime, "memoryBackend"))
|
|
651
|
-
drop(runtime, "runtime", "memoryBackend"); // 从未到达引擎
|
|
652
|
-
const sessionRaw = runtime.sessionBackend;
|
|
653
|
-
const host = coords.tidbHost;
|
|
654
|
-
const hostSet = typeof host === "string" && host !== "";
|
|
655
|
-
const dbBackendRaw = env.DB_BACKEND;
|
|
656
|
-
const dbBackendSet = dbBackendRaw !== undefined && dbBackendRaw !== "";
|
|
657
|
-
const named = hostSet || dbBackendSet || sessionRaw === "tidb";
|
|
658
|
-
const sqlCoordFields = [
|
|
659
|
-
[runtime, "runtime", "db"],
|
|
660
|
-
[coords, "coords", "tidbHost"],
|
|
661
|
-
[coords, "coords", "tidbPort"],
|
|
662
|
-
[coords, "coords", "tidbUser"],
|
|
663
|
-
[secretRefs, "secretRefs", "tidbPasswordEnv"],
|
|
664
|
-
];
|
|
665
|
-
if (!enabled && !named) {
|
|
666
|
-
// 停用、旧形没点名任何店 ⇒ 不替它发明一个;旧字段全是惰性的
|
|
667
|
-
if (Object.hasOwn(runtime, "sessionBackend"))
|
|
668
|
-
drop(runtime, "runtime", "sessionBackend");
|
|
669
|
-
for (const [c, slot, k] of sqlCoordFields)
|
|
670
|
-
if (Object.hasOwn(c, k))
|
|
671
|
-
drop(c, slot, k);
|
|
672
|
-
for (const k of STORE_ENV_KEYS)
|
|
673
|
-
if (Object.hasOwn(env, k))
|
|
674
|
-
drop(env, "env", k);
|
|
675
|
-
}
|
|
676
|
-
else {
|
|
677
|
-
let session;
|
|
678
|
-
if (sessionRaw === undefined)
|
|
679
|
-
session = "auto"; // 6.x 的缺省
|
|
680
|
-
else if (sessionRaw === "tidb")
|
|
681
|
-
session = "mysql";
|
|
682
|
-
else if (sessionRaw === "memory" || sessionRaw === "auto")
|
|
683
|
-
session = sessionRaw;
|
|
684
|
-
else
|
|
685
|
-
return refuse(["runtime", "sessionBackend"], `runtime.sessionBackend ${describeWord(sessionRaw)} is not a 6.x session backend (tidb | memory | auto)`);
|
|
686
|
-
delete runtime.sessionBackend;
|
|
687
|
-
let backend;
|
|
688
|
-
if (dbBackendSet) {
|
|
689
|
-
if (!isStoreWord(dbBackendRaw))
|
|
690
|
-
return refuse(["env", "DB_BACKEND"], `env.DB_BACKEND ${describeWord(dbBackendRaw)} is not a store backend (${STORE_BACKENDS.join(" | ")}) — the engine refuses to start with it`);
|
|
691
|
-
backend = dbBackendRaw;
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
backend = hostSet || sessionRaw === "tidb" ? "mysql" : "local";
|
|
695
|
-
}
|
|
696
|
-
delete env.DB_BACKEND;
|
|
697
|
-
const sqlCoordsPresent = sqlCoordFields.filter(([c, , k]) => Object.hasOwn(c, k));
|
|
698
|
-
const store = emptyDocument();
|
|
699
|
-
store.backend = backend;
|
|
700
|
-
store.session = session;
|
|
701
|
-
if (backend === "mysql") {
|
|
702
|
-
if (hostSet) {
|
|
703
|
-
const port = coords.tidbPort;
|
|
704
|
-
store.db = {
|
|
705
|
-
host,
|
|
706
|
-
port: port === undefined ? MYSQL_DEFAULT_PORT : port,
|
|
707
|
-
...(Object.hasOwn(coords, "tidbUser") ? { user: coords.tidbUser } : {}),
|
|
708
|
-
...(Object.hasOwn(runtime, "db") ? { database: runtime.db } : {}),
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
if (Object.hasOwn(secretRefs, "tidbPasswordEnv"))
|
|
712
|
-
secretRefs.dbPasswordEnv = secretRefs.tidbPasswordEnv;
|
|
713
|
-
for (const [c, , k] of sqlCoordsPresent)
|
|
714
|
-
delete c[k];
|
|
715
|
-
}
|
|
716
|
-
else if (backend === "pg") {
|
|
717
|
-
if (sqlCoordsPresent.length > 0) {
|
|
718
|
-
return refuse(["env", "DB_BACKEND"], `env.DB_BACKEND=pg but the SQL coordinates are the MySQL family (coords.tidb* / runtime.db / secretRefs.tidbPasswordEnv, rendered as MYSQL_*) — the migration does not move a MySQL server's coordinates onto pg; declare runtime.store by hand`);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
else {
|
|
722
|
-
for (const [c, slot, k] of sqlCoordsPresent)
|
|
723
|
-
drop(c, slot, k); // 非 SQL 店:SQL 坐标是「声明不用」的惰性件
|
|
724
|
-
}
|
|
725
|
-
const memory = emptyDocument();
|
|
726
|
-
const engineRaw = env.MEMORY_ENGINE;
|
|
727
|
-
if (engineRaw !== undefined) {
|
|
728
|
-
const word = typeof engineRaw === "string" ? engineRaw.trim().toLowerCase() : undefined;
|
|
729
|
-
if (word !== undefined && MEMORY_ENGINE_ON_WORDS.includes(word))
|
|
730
|
-
memory.engine = "on";
|
|
731
|
-
else if (word !== undefined && MEMORY_ENGINE_OFF_WORDS.includes(word))
|
|
732
|
-
memory.engine = "off";
|
|
733
|
-
else if (word !== "")
|
|
734
|
-
return refuse(["env", "MEMORY_ENGINE"], "env.MEMORY_ENGINE is not an on/off word — the engine refuses to start with it");
|
|
735
|
-
delete env.MEMORY_ENGINE;
|
|
736
|
-
}
|
|
737
|
-
const memoryBackendRaw = env.MEMORY_ENGINE_BACKEND;
|
|
738
|
-
if (memoryBackendRaw !== undefined) {
|
|
739
|
-
const today = typeof memoryBackendRaw === "string" ? SIX_X_MEMORY_BACKEND.get(memoryBackendRaw) : undefined;
|
|
740
|
-
if (today === undefined) {
|
|
741
|
-
return refuse(["env", "MEMORY_ENGINE_BACKEND"], `env.MEMORY_ENGINE_BACKEND ${describeWord(memoryBackendRaw)} is not a 6.x memory backend (${[...SIX_X_MEMORY_BACKEND.keys()].join(" | ")}) — the engine refused to start with it`);
|
|
742
|
-
}
|
|
743
|
-
memory.backend = today;
|
|
744
|
-
delete env.MEMORY_ENGINE_BACKEND;
|
|
745
|
-
}
|
|
746
|
-
if (Object.keys(memory).length > 0)
|
|
747
|
-
store.memory = memory;
|
|
748
|
-
runtime.store = store;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
// 被搬空的 env / secretEnv 整键去掉(它们是可选字段;留一个 `{}` 只是噪声)
|
|
752
|
-
if (isPlainJsonObject(w.env) && Object.keys(env).length === 0 && envHadKeys)
|
|
753
|
-
delete w.env;
|
|
754
|
-
if (isPlainJsonObject(w.secretEnv) && Object.keys(secretEnv).length === 0 && secretEnvHadKeys)
|
|
755
|
-
delete w.secretEnv;
|
|
756
|
-
// 改写后的行还没判:终判在 workers 行步(两只迁移的改写都做完之后判一次,见 `stepWorkersRows`)。
|
|
757
|
-
return { kind: "rewritten", row: w, dropped };
|
|
758
|
-
}
|
|
759
240
|
/** SS-M12 认的晚登记车道键(16.0.0 那一批;表在 `execution-lane-index.ts`,这里只取归 SS-M12 的那几个)。 */
|
|
760
241
|
const SS_M12_ENV_KEYS = [...LATE_LANE_ENV_KEYS].filter(([, m]) => m.migration === "SS-M12").map(([k]) => k);
|
|
761
242
|
/**
|
|
762
243
|
* 一行的 15.x 改写(规则见登记表 SS-M12 行)。只认 7.0+ 行上的三种形 —— `runtime.execution.lane`、`runtime.store.memory.backend: "tidb"`、带 `runtime.execution` 的行
|
|
763
244
|
* 逃生口里的晚登记车道键 —— 逐字段改,每改一处一张收据。先浅读判要不要迁(没有这三种形的行一个字段都不动、不拷);要迁才拍快照改副本。
|
|
764
|
-
*
|
|
245
|
+
* 改完的行不在这里判:读侧那一只(`workerRowVerdict`)在 workers 行步里判一次(`stepWorkersRows`)。
|
|
765
246
|
*/
|
|
766
247
|
function migrateWorkerRow15(row) {
|
|
767
248
|
const refuse = (field, reason) => ({ kind: "refused", field, reason });
|
|
@@ -831,15 +312,14 @@ function migrateWorkerRow15(row) {
|
|
|
831
312
|
delete w[slot]; // 被搬空的逃生口整键去掉(可选字段;留一个 `{}` 只是噪声)
|
|
832
313
|
}
|
|
833
314
|
}
|
|
834
|
-
//
|
|
315
|
+
// 改写后的行还没判:终判在 workers 行步(见 `stepWorkersRows`)。
|
|
835
316
|
return { kind: "rewritten", row: w, changes };
|
|
836
317
|
}
|
|
837
318
|
/**
|
|
838
|
-
* workers 行步:SS-M12
|
|
839
|
-
*
|
|
840
|
-
* ·
|
|
841
|
-
* ·
|
|
842
|
-
* · 读得进 ⇒ 写回寻常对象(工作副本隔离原型,只是副本),收据按迁移序:SS-M12 的逐字段收据,再 SS-M4 的 `rewritten` + `dropped-inert`。
|
|
319
|
+
* workers 行步:SS-M12 按行改写(7.0+ 的形),改完用读侧那一只(`workerRowVerdict`)**判一次**。
|
|
320
|
+
* · 形上就改不了(两形并存、值写错了栏……)⇒ 拒收据,行原样;
|
|
321
|
+
* · 改完读不进 ⇒ 一张拒收据(SS-M12 名下),原文留盘(读口 `readWorkersRows` 扣下它);
|
|
322
|
+
* · 读得进 ⇒ 写回寻常对象(工作副本隔离原型,只是副本),逐字段收据。
|
|
843
323
|
*/
|
|
844
324
|
function stepWorkersRows(out, receipts) {
|
|
845
325
|
const doc = ownOrThrow(out, "workers");
|
|
@@ -859,103 +339,24 @@ function stepWorkersRows(out, receipts) {
|
|
|
859
339
|
receipts.push(refused("SS-M12", "workers", at(r12.field), r12.reason));
|
|
860
340
|
return;
|
|
861
341
|
}
|
|
862
|
-
|
|
863
|
-
if (r4.kind === "refused") {
|
|
864
|
-
receipts.push(refused("SS-M4", "workers", at(r4.field), r4.reason));
|
|
342
|
+
if (r12.kind === "unchanged")
|
|
865
343
|
return;
|
|
866
|
-
|
|
867
|
-
if (r12.kind === "unchanged" && r4.kind === "unchanged")
|
|
868
|
-
return;
|
|
869
|
-
const final = r4.kind === "rewritten" ? r4.row : r12.row;
|
|
870
|
-
const verdict = workerRowVerdict(final, "migrated");
|
|
344
|
+
const verdict = workerRowVerdict(r12.row, "migrated");
|
|
871
345
|
if (verdict !== undefined) {
|
|
872
|
-
receipts.push(refused(
|
|
346
|
+
receipts.push(refused("SS-M12", "workers", at(verdict.field), verdict.reason));
|
|
873
347
|
return;
|
|
874
348
|
}
|
|
875
|
-
const written = captureJson(
|
|
349
|
+
const written = captureJson(r12.row, "ordinary"); // 交出去的是寻常对象(隔离原型的深副本只是工作副本)
|
|
876
350
|
if (!written.ok)
|
|
877
351
|
throw new UninspectableError(written.sentence);
|
|
878
352
|
next ??= [...rows];
|
|
879
353
|
next[index] = written.value;
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
receipts.push(c.appliedAs === "moved" ? moved("SS-M12", "workers", at(c.path), { document: "workers", path: at(c.to) }) : receipt("SS-M12", "workers", at(c.path), c.appliedAs));
|
|
883
|
-
}
|
|
884
|
-
if (r4.kind === "rewritten") {
|
|
885
|
-
receipts.push(receipt("SS-M4", "workers", ["workers", index], "rewritten"));
|
|
886
|
-
for (const field of r4.dropped)
|
|
887
|
-
receipts.push(receipt("SS-M4", "workers", at(field), "dropped-inert"));
|
|
888
|
-
}
|
|
354
|
+
for (const c of r12.changes)
|
|
355
|
+
receipts.push(c.appliedAs === "moved" ? moved("SS-M12", "workers", at(c.path), { document: "workers", path: at(c.to) }) : receipt("SS-M12", "workers", at(c.path), c.appliedAs));
|
|
889
356
|
});
|
|
890
357
|
if (next !== undefined)
|
|
891
358
|
out.workers = { ...doc, workers: next };
|
|
892
359
|
}
|
|
893
|
-
// ── SS-M5:模型钥匙二选一 ──────────────────────────────────────────────────────────────────────────────
|
|
894
|
-
function stepModelKeyOneOf(out, receipts) {
|
|
895
|
-
const doc = ownOrThrow(out, "models");
|
|
896
|
-
if (!isPlainJsonObject(doc))
|
|
897
|
-
return;
|
|
898
|
-
const modelRows = ownOrThrow(doc, "models");
|
|
899
|
-
if (!isJsonArray(modelRows))
|
|
900
|
-
return;
|
|
901
|
-
const rows = modelRows;
|
|
902
|
-
let next;
|
|
903
|
-
rows.forEach((row, index) => {
|
|
904
|
-
if (!(has(row, "sealedApiKey") && has(row, "apiKeyEnv")))
|
|
905
|
-
return;
|
|
906
|
-
const r = row;
|
|
907
|
-
if (ownOrThrow(r, "sealedApiKey") === undefined || ownOrThrow(r, "apiKeyEnv") === undefined)
|
|
908
|
-
return;
|
|
909
|
-
next ??= [...rows];
|
|
910
|
-
next[index] = without(r, "apiKeyEnv");
|
|
911
|
-
receipts.push(receipt("SS-M5", "models", ["models", index, "apiKeyEnv"], "dropped-shadowed"));
|
|
912
|
-
});
|
|
913
|
-
if (next !== undefined)
|
|
914
|
-
out.models = { ...doc, models: next };
|
|
915
|
-
}
|
|
916
|
-
// ── SS-M6:atModelAllowlist → atMention ────────────────────────────────────────────────────────────────
|
|
917
|
-
/** 一个位上的 `atModelAllowlist` 按形改写;读不进的旧值(不是字符串数组)/ 两形并存 ⇒ 拒。返回改后的对象或 `undefined`(没改)。 */
|
|
918
|
-
function rewriteAtMention(holder, document, at, receipts) {
|
|
919
|
-
if (!Object.prototype.hasOwnProperty.call(holder, "atModelAllowlist"))
|
|
920
|
-
return undefined;
|
|
921
|
-
const list = ownOrThrow(holder, "atModelAllowlist");
|
|
922
|
-
if (Object.prototype.hasOwnProperty.call(holder, "atMention")) {
|
|
923
|
-
receipts.push(refused("SS-M6", document, [...at, "atModelAllowlist"], "both atModelAllowlist and atMention are set — keep one; the migration does not pick a winner"));
|
|
924
|
-
return undefined;
|
|
925
|
-
}
|
|
926
|
-
if (!isJsonArray(list) || !list.every((n) => typeof n === "string")) {
|
|
927
|
-
receipts.push(refused("SS-M6", document, [...at, "atModelAllowlist"], "atModelAllowlist is not a list of model names — it does not read today either; fix it by hand"));
|
|
928
|
-
return undefined;
|
|
929
|
-
}
|
|
930
|
-
const atMention = list.length === 0 ? { mode: "all" } : { mode: "only", models: [...list] };
|
|
931
|
-
receipts.push(moved("SS-M6", document, [...at, "atModelAllowlist"], { document, path: [...at, "atMention"] }));
|
|
932
|
-
return { ...without(holder, "atModelAllowlist"), atMention };
|
|
933
|
-
}
|
|
934
|
-
function stepAtMention(out, receipts) {
|
|
935
|
-
const modelsDoc = ownOrThrow(out, "models");
|
|
936
|
-
if (isPlainJsonObject(modelsDoc)) {
|
|
937
|
-
const next = rewriteAtMention(modelsDoc, "models", [], receipts);
|
|
938
|
-
if (next !== undefined)
|
|
939
|
-
out.models = next;
|
|
940
|
-
}
|
|
941
|
-
const rosters = ownOrThrow(out, "rosters");
|
|
942
|
-
const rosterRows = isPlainJsonObject(rosters) ? ownOrThrow(rosters, "rosters") : undefined;
|
|
943
|
-
if (isPlainJsonObject(rosters) && isJsonArray(rosterRows)) {
|
|
944
|
-
const rows = rosterRows;
|
|
945
|
-
let next;
|
|
946
|
-
rows.forEach((row, index) => {
|
|
947
|
-
if (!isPlainJsonObject(row))
|
|
948
|
-
return;
|
|
949
|
-
const r = rewriteAtMention(row, "rosters", ["rosters", index], receipts);
|
|
950
|
-
if (r === undefined)
|
|
951
|
-
return;
|
|
952
|
-
next ??= [...rows];
|
|
953
|
-
next[index] = r;
|
|
954
|
-
});
|
|
955
|
-
if (next !== undefined)
|
|
956
|
-
out.rosters = { ...rosters, rosters: next };
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
360
|
// ── SS-M8:退役的角色词 ────────────────────────────────────────────────────────────────────────────────
|
|
960
361
|
/** 一个 `roles` 图上的退役角色词键删掉(值不论 —— 没有角色读它);逐键一张 `dropped-inert` 收据。返回改后的图或 `undefined`(没改 / 不是对象:判形是读者的事)。 */
|
|
961
362
|
function withoutRetiredRoles(roles, document, at, receipts) {
|
|
@@ -996,27 +397,6 @@ function stepRetiredRoleWords(out, receipts) {
|
|
|
996
397
|
out.rosters = { ...rosters, rosters: next };
|
|
997
398
|
}
|
|
998
399
|
}
|
|
999
|
-
// ── SS-M9:models.default → roles.default ──────────────────────────────────────────────────────────────
|
|
1000
|
-
/** 迁移前「缺省模型是谁」的生效读法 = server 的缺省解析以结构键 `default` 为第一级,主任务真跑它(N-7 两答复现:`default` = A、`roles.default`
|
|
1001
|
-
* = B 时主任务跑 A,core 的 `default` 角色解到 B)。所以并过去的是 `default` 的值:`roles.default` 缺席 ⇒ 搬入;同名 ⇒ 搬入(重复的那一份
|
|
1002
|
-
* 消失);异名 ⇒ 原 `roles.default` 作「被压过」删掉、`default` 搬入。`default` 不是非空串 ⇒ 拒(今天它让整个 models 域读不进,不替运维猜)。 */
|
|
1003
|
-
function stepModelsDefault(out, receipts) {
|
|
1004
|
-
const doc = ownOrThrow(out, "models");
|
|
1005
|
-
if (!isPlainJsonObject(doc) || !Object.prototype.hasOwnProperty.call(doc, "default"))
|
|
1006
|
-
return;
|
|
1007
|
-
const name = ownOrThrow(doc, "default");
|
|
1008
|
-
if (typeof name !== "string" || name === "") {
|
|
1009
|
-
receipts.push(refused("SS-M9", "models", ["default"], "models.default is not a catalog name — it does not read today either; fix it by hand"));
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
const docRoles = ownOrThrow(doc, "roles");
|
|
1013
|
-
const roles = isPlainJsonObject(docRoles) ? docRoles : emptyDocument();
|
|
1014
|
-
const prior = ownOrThrow(roles, "default");
|
|
1015
|
-
if (prior !== undefined && !(isPlainJsonObject(prior) && ownOrThrow(prior, "model") === name))
|
|
1016
|
-
receipts.push(receipt("SS-M9", "models", ["roles", "default"], "dropped-shadowed"));
|
|
1017
|
-
receipts.push(moved("SS-M9", "models", ["default"], { document: "models", path: ["roles", "default"] }));
|
|
1018
|
-
out.models = { ...without(doc, "default"), roles: { ...roles, default: { model: name } } };
|
|
1019
|
-
}
|
|
1020
400
|
// ── SS-M10:prompts 两轴退役 ───────────────────────────────────────────────────────────────────────────
|
|
1021
401
|
/** 14.0.0 的 prompts 域只装中心 artifact;13.x 的两轴键是墓碑。迁移只做只认形的那一件:空的 `bindings: []`(13.x 每份文档恒物化的默认值,
|
|
1022
402
|
* 从不下发任何内容)删掉。非空 `bindings` / 不是数组的 `bindings` / `catalog` 一律 refused、原样留着 —— 声明要经中心的卡编译器才编得成
|
|
@@ -1043,149 +423,3 @@ function stepPromptsAxes(out, receipts) {
|
|
|
1043
423
|
if (next !== doc)
|
|
1044
424
|
out.prompts = next;
|
|
1045
425
|
}
|
|
1046
|
-
// ── SS-M7:URL fragment ────────────────────────────────────────────────────────────────────────────────
|
|
1047
|
-
/** SS-M7 走查的文档 → 它的 schema(座位从 schema 派生的那一只来源):配置域按 `DOMAIN_SCHEMAS`,`remote-exec` 按 `RemoteExecSpec`;别的文档没有 URL 座位。 */
|
|
1048
|
-
function urlSeatSchemaOf(document) {
|
|
1049
|
-
if (isDomainName(document))
|
|
1050
|
-
return DOMAIN_SCHEMAS[document];
|
|
1051
|
-
if (document === REMOTE_EXEC_DOCUMENT)
|
|
1052
|
-
return RemoteExecSpec;
|
|
1053
|
-
return undefined;
|
|
1054
|
-
}
|
|
1055
|
-
/** 这只(已展开的)schema 是不是一个 `NON_SECRET_URL` 座位:就是它,或是「先归一、再交给它」的管道(`z.string().trim().pipe(NON_SECRET_URL)`)。 */
|
|
1056
|
-
function isUrlSeat(s) {
|
|
1057
|
-
return s === NON_SECRET_URL || (s instanceof z.ZodPipe && unwrapSchema(s.out) === NON_SECRET_URL);
|
|
1058
|
-
}
|
|
1059
|
-
/**
|
|
1060
|
-
* 顺着域 schema 走文档,在每个 URL 座位上剥 fragment。座位由 schema 派生(不手抄座位表):对象逐键、数组逐元素、Record 逐值、
|
|
1061
|
-
* 判别联合按判别值取那一支、普通联合只认「某一支是 URL 座位」的字符串值(对象值不进普通联合 —— 哪一支说了算猜不出,不猜)。
|
|
1062
|
-
* 写时复制:没改 ⇒ 原引用。
|
|
1063
|
-
*/
|
|
1064
|
-
function stripFragments(schema, value, path, onStrip, depth = 0) {
|
|
1065
|
-
if (depth > 32)
|
|
1066
|
-
return value;
|
|
1067
|
-
const s = unwrapSchema(schema);
|
|
1068
|
-
if (isUrlSeat(s)) {
|
|
1069
|
-
if (typeof value !== "string")
|
|
1070
|
-
return value;
|
|
1071
|
-
const hash = value.indexOf("#");
|
|
1072
|
-
if (hash < 0)
|
|
1073
|
-
return value;
|
|
1074
|
-
onStrip(path);
|
|
1075
|
-
return value.slice(0, hash);
|
|
1076
|
-
}
|
|
1077
|
-
if (s instanceof z.ZodDiscriminatedUnion) {
|
|
1078
|
-
if (!isPlainJsonObject(value))
|
|
1079
|
-
return value;
|
|
1080
|
-
const disc = s._zod.def.discriminator;
|
|
1081
|
-
for (const option of s.options) {
|
|
1082
|
-
const o = unwrapSchema(option);
|
|
1083
|
-
if (!(o instanceof z.ZodObject))
|
|
1084
|
-
continue;
|
|
1085
|
-
const lit = unwrapSchema(o.shape[disc]);
|
|
1086
|
-
if (lit instanceof z.ZodLiteral && lit.values.has(ownOrThrow(value, disc)))
|
|
1087
|
-
return stripFragments(o, value, path, onStrip, depth + 1);
|
|
1088
|
-
}
|
|
1089
|
-
return value;
|
|
1090
|
-
}
|
|
1091
|
-
if (s instanceof z.ZodUnion) {
|
|
1092
|
-
if (typeof value !== "string")
|
|
1093
|
-
return value;
|
|
1094
|
-
for (const option of s.options)
|
|
1095
|
-
if (isUrlSeat(unwrapSchema(option)))
|
|
1096
|
-
return stripFragments(option, value, path, onStrip, depth + 1);
|
|
1097
|
-
return value;
|
|
1098
|
-
}
|
|
1099
|
-
if (s instanceof z.ZodObject) {
|
|
1100
|
-
if (!isPlainJsonObject(value))
|
|
1101
|
-
return value;
|
|
1102
|
-
let next;
|
|
1103
|
-
for (const [k, fieldSchema] of Object.entries(s.shape)) {
|
|
1104
|
-
if (!Object.prototype.hasOwnProperty.call(value, k))
|
|
1105
|
-
continue;
|
|
1106
|
-
const held = ownOrThrow(value, k);
|
|
1107
|
-
const v = stripFragments(fieldSchema, held, [...path, k], onStrip, depth + 1);
|
|
1108
|
-
if (v !== held)
|
|
1109
|
-
(next ??= { ...value })[k] = v;
|
|
1110
|
-
}
|
|
1111
|
-
return next ?? value;
|
|
1112
|
-
}
|
|
1113
|
-
if (s instanceof z.ZodArray) {
|
|
1114
|
-
if (!isJsonArray(value))
|
|
1115
|
-
return value;
|
|
1116
|
-
let next;
|
|
1117
|
-
value.forEach((el, i) => {
|
|
1118
|
-
const v = stripFragments(s.element, el, [...path, i], onStrip, depth + 1);
|
|
1119
|
-
if (v !== el)
|
|
1120
|
-
(next ??= [...value])[i] = v;
|
|
1121
|
-
});
|
|
1122
|
-
return next ?? value;
|
|
1123
|
-
}
|
|
1124
|
-
if (s instanceof z.ZodRecord) {
|
|
1125
|
-
if (!isPlainJsonObject(value))
|
|
1126
|
-
return value;
|
|
1127
|
-
let next;
|
|
1128
|
-
for (const [k, el] of Object.entries(value)) {
|
|
1129
|
-
const v = stripFragments(s._zod.def.valueType, el, [...path, k], onStrip, depth + 1);
|
|
1130
|
-
if (v !== el)
|
|
1131
|
-
(next ??= { ...value })[k] = v;
|
|
1132
|
-
}
|
|
1133
|
-
return next ?? value;
|
|
1134
|
-
}
|
|
1135
|
-
return value;
|
|
1136
|
-
}
|
|
1137
|
-
/** SS-M7 走查的全部 URL 座位的坐标模式(派生;数组 / Record 位写 `*`;域文档以域名起头,`remote-exec.json` 以 `remote-exec` 起头)—— 迁移不用它,
|
|
1138
|
-
* 它给钉与说明看「今天派生出哪些座位」。 */
|
|
1139
|
-
export function urlSeatPatterns() {
|
|
1140
|
-
const out = [];
|
|
1141
|
-
const walk = (schema, path, depth) => {
|
|
1142
|
-
if (depth > 32)
|
|
1143
|
-
return;
|
|
1144
|
-
const s = unwrapSchema(schema);
|
|
1145
|
-
if (isUrlSeat(s))
|
|
1146
|
-
return void out.push(path.join("."));
|
|
1147
|
-
if (s instanceof z.ZodDiscriminatedUnion) {
|
|
1148
|
-
const disc = s._zod.def.discriminator;
|
|
1149
|
-
for (const option of s.options) {
|
|
1150
|
-
const o = unwrapSchema(option);
|
|
1151
|
-
if (!(o instanceof z.ZodObject))
|
|
1152
|
-
continue;
|
|
1153
|
-
const lit = unwrapSchema(o.shape[disc]);
|
|
1154
|
-
const word = lit instanceof z.ZodLiteral ? [...lit.values].join("|") : "?";
|
|
1155
|
-
walk(o, [...path.slice(0, -1), `${path[path.length - 1] ?? ""}{${disc}=${word}}`], depth + 1);
|
|
1156
|
-
}
|
|
1157
|
-
return;
|
|
1158
|
-
}
|
|
1159
|
-
if (s instanceof z.ZodUnion) {
|
|
1160
|
-
if (s.options.some((o) => isUrlSeat(unwrapSchema(o))))
|
|
1161
|
-
out.push(path.join("."));
|
|
1162
|
-
return;
|
|
1163
|
-
}
|
|
1164
|
-
if (s instanceof z.ZodObject) {
|
|
1165
|
-
for (const [k, f] of Object.entries(s.shape))
|
|
1166
|
-
walk(f, [...path, k], depth + 1);
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
if (s instanceof z.ZodArray)
|
|
1170
|
-
return walk(s.element, [...path, "*"], depth + 1);
|
|
1171
|
-
if (s instanceof z.ZodRecord)
|
|
1172
|
-
return walk(s._zod.def.valueType, [...path, "*"], depth + 1);
|
|
1173
|
-
};
|
|
1174
|
-
for (const [d, schema] of Object.entries(DOMAIN_SCHEMAS))
|
|
1175
|
-
walk(schema, [d], 0);
|
|
1176
|
-
walk(RemoteExecSpec, [REMOTE_EXEC_DOCUMENT], 0);
|
|
1177
|
-
return out;
|
|
1178
|
-
}
|
|
1179
|
-
function stepUrlFragments(out, receipts) {
|
|
1180
|
-
for (const d of Object.keys(out)) {
|
|
1181
|
-
const schema = urlSeatSchemaOf(d);
|
|
1182
|
-
if (schema === undefined)
|
|
1183
|
-
continue;
|
|
1184
|
-
const doc = out[d];
|
|
1185
|
-
if (doc === undefined)
|
|
1186
|
-
continue;
|
|
1187
|
-
const next = stripFragments(schema, doc, [], (path) => receipts.push(receipt("SS-M7", d, path, "rewritten")));
|
|
1188
|
-
if (next !== doc)
|
|
1189
|
-
out[d] = next;
|
|
1190
|
-
}
|
|
1191
|
-
}
|