@sema-agent/settings-schema 34.0.0 → 35.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +648 -0
- package/README.md +86 -39
- package/conformance/VERSION +1 -1
- package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/expected.json +101 -0
- package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/input.json +28 -0
- package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/meta.json +6 -0
- package/conformance/cases/c101-a2a-inside-incomplete-dropped/expected.json +113 -0
- package/conformance/cases/c101-a2a-inside-incomplete-dropped/input.json +38 -0
- package/conformance/cases/c101-a2a-inside-incomplete-dropped/meta.json +6 -0
- package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/expected.json +85 -0
- package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/input.json +34 -0
- package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/meta.json +6 -0
- package/conformance/cases/c103-mcp-caller-meta-declared/expected.json +106 -0
- package/conformance/cases/c103-mcp-caller-meta-declared/input.json +28 -0
- package/conformance/cases/c103-mcp-caller-meta-declared/meta.json +6 -0
- package/conformance/cases/c98-a2a-registration-keys-carried/expected.json +163 -0
- package/conformance/cases/c98-a2a-registration-keys-carried/input.json +42 -0
- package/conformance/cases/c98-a2a-registration-keys-carried/meta.json +6 -0
- package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/expected.json +100 -0
- package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/input.json +23 -0
- package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/meta.json +6 -0
- package/dist/a2a-peer-identity.d.ts +116 -0
- package/dist/a2a-peer-identity.js +182 -0
- package/dist/api/credentials.d.ts +94 -14
- package/dist/api/credentials.js +33 -8
- package/dist/atomic-write.d.ts +9 -3
- package/dist/atomic-write.js +14 -6
- package/dist/catalog-manages.js +2 -2
- package/dist/config-d-file.d.ts +0 -3
- package/dist/config-d-file.js +1 -6
- package/dist/config-dir-migration.js +0 -1
- package/dist/config-document-refusal.d.ts +1 -1
- package/dist/config-fns.d.ts +21 -8
- package/dist/config-fns.js +16 -3
- package/dist/config-root-documents.d.ts +3 -54
- package/dist/config-root-documents.js +24 -21
- package/dist/config-root-node.d.ts +2 -96
- package/dist/config-root-node.js +15 -163
- package/dist/conformance/warnings.js +1 -1
- package/dist/conformance/web-admin-credential-lock.js +3 -2
- package/dist/cross-session.d.ts +2 -2
- package/dist/env-model-table.d.ts +3 -3
- package/dist/env-model-table.js +5 -5
- package/dist/fleet.d.ts +5 -5
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/mcp-request-entry.d.ts +19 -0
- package/dist/mcp-request-entry.js +15 -13
- package/dist/migration-receipt.d.ts +9 -11
- package/dist/migration-receipt.js +4 -5
- package/dist/node.d.ts +3 -3
- package/dist/node.js +3 -3
- package/dist/one-time-migrations.d.ts +3 -4
- package/dist/one-time-migrations.js +3 -28
- package/dist/plugin-id-segment.d.ts +15 -0
- package/dist/plugin-id-segment.js +15 -0
- package/dist/plugin-settings.d.ts +61 -0
- package/dist/plugin-settings.js +111 -0
- package/dist/retired-envs.js +5 -0
- package/dist/safety-merge-spec.d.ts +23 -2
- package/dist/safety-merge-spec.js +13 -0
- package/dist/scheduler-store-node.d.ts +14 -11
- package/dist/scheduler-store-node.js +22 -34
- package/dist/scheduler-store.d.ts +21 -6
- package/dist/scheduler-store.js +100 -19
- package/dist/settings-units.d.ts +9 -0
- package/dist/settings-units.js +12 -7
- package/dist/types.d.ts +53 -4
- package/dist/types.js +79 -4
- package/docs/API-SURFACE.md +51 -11
- package/docs/CC-DIVERGENCE.md +2 -1
- package/docs/CONFORMANCE.md +4 -4
- package/docs/CONSUMER-INTEGRATION.md +158 -13
- package/llms-full.txt +47 -18
- package/llms.txt +18 -7
- package/package.json +7 -3
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { deepFreeze } from "./deep-freeze.js";
|
|
2
2
|
/** 本版登记的一次性迁移 id(闭集;每个 id 在 `ONE_TIME_MIGRATIONS` 登记表里恰一行)。收据只许这些 id。 */
|
|
3
|
-
export const ONE_TIME_MIGRATION_IDS = deepFreeze(["SS-
|
|
3
|
+
export const ONE_TIME_MIGRATION_IDS = deepFreeze(["SS-M12", "SS-M13", "SS-M14"]);
|
|
4
4
|
/**
|
|
5
5
|
* 一条收据说迁移**对一个坐标做了什么**(闭集,每词一义):
|
|
6
6
|
* - `moved` — 值搬到新位(`to`),义不变;
|
|
7
7
|
* - `rewritten` — 同一坐标上的值换成今天的生效读法(例:15.x worker 行的记忆方言词 `tidb` ⇒ `mysql`);
|
|
8
8
|
* - `dropped-inert` — 删掉;今天的读法本就不让它生效(例:不声明那条车道的行上的车道键、mcp 条目上从没有读者的 `authForm` / `entryKind`);
|
|
9
|
-
* - `refused` — 不改:要改就得替运维猜(或旧文档今天本就读不进);原样留着,读侧照旧响亮拒,`reason`
|
|
10
|
-
*
|
|
11
|
-
* 升级前「管模型面的目录整表顶替 env 模型」的读法,写成 `replaced`;不存在才建)。
|
|
9
|
+
* - `refused` — 不改:要改就得替运维猜(或旧文档今天本就读不进);原样留着,读侧照旧响亮拒,`reason` 说为什么。
|
|
10
|
+
* (35.0.0 起没有 `minted`:唯一铸它的 SS-M11 窗关删了。)
|
|
12
11
|
*/
|
|
13
|
-
export const MIGRATION_APPLIED_AS = deepFreeze(["moved", "rewritten", "dropped-inert", "refused"
|
|
12
|
+
export const MIGRATION_APPLIED_AS = deepFreeze(["moved", "rewritten", "dropped-inert", "refused"]);
|
package/dist/node.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export { tryWebAdminCredentialFileLock, type WebAdminCredentialLockHeld, type We
|
|
|
14
14
|
export { migrateConfigDirectory, migrateConfigDocuments, // 14.5.0:同一段「迁 → 整域终判」的同步口(入参是已有的存量文档,无 io)—— 目录形调的就是它的内核
|
|
15
15
|
type ConfigDirectoryDocument, type ConfigDirectoryIo, type ConfigDirectoryMigration, type ConfigDirectoryRefusal, type ConfigDocumentsMigration, type MigrateConfigDirectoryOptions, type MigrateConfigDocumentsOptions, } from "./config-dir-migration.js";
|
|
16
16
|
export { nodeConfigDirectoryIo } from "./config-dir-io.js";
|
|
17
|
-
export {
|
|
18
|
-
|
|
19
|
-
type ConfigRootIo, type EnvModelsDecisionWrite,
|
|
17
|
+
export { nodeConfigRootIo, readEnvModelsDecision, readEnvModelsDecisionSync, // 同步孪生:同一个字节读法 / 缺席律 / 答案表(壳在同步具名锁里写模型池要在锁里读决定)
|
|
18
|
+
writeEnvModelsDecision, writeEnvModelsDecisionSync, // 同步孪生:同一份写计划 + 同一对同步原子写原语
|
|
19
|
+
type ConfigRootIo, type EnvModelsDecisionWrite, } from "./config-root-node.js";
|
package/dist/node.js
CHANGED
|
@@ -17,7 +17,7 @@ export { tryWebAdminCredentialFileLock } from "./atomic-write.js";
|
|
|
17
17
|
export { migrateConfigDirectory, migrateConfigDocuments, // 14.5.0:同一段「迁 → 整域终判」的同步口(入参是已有的存量文档,无 io)—— 目录形调的就是它的内核
|
|
18
18
|
} from "./config-dir-migration.js";
|
|
19
19
|
export { nodeConfigDirectoryIo } from "./config-dir-io.js"; // 上面那只函数的真 I/O 绑定:node:fs + 本包唯一的原子写器(config-document 模式规则)
|
|
20
|
-
// 配置根上的决定文档(config.env-models.json)
|
|
21
|
-
export {
|
|
22
|
-
|
|
20
|
+
// 配置根上的决定文档(config.env-models.json)的唯一读者与唯一写函数(读写各有同步孪生;名字与闭集答案表在包根)。显式列名。
|
|
21
|
+
export { nodeConfigRootIo, readEnvModelsDecision, readEnvModelsDecisionSync, // 同步孪生:同一个字节读法 / 缺席律 / 答案表(壳在同步具名锁里写模型池要在锁里读决定)
|
|
22
|
+
writeEnvModelsDecision, writeEnvModelsDecisionSync, // 同步孪生:同一份写计划 + 同一对同步原子写原语
|
|
23
23
|
} from "./config-root-node.js";
|
|
@@ -8,10 +8,9 @@ export interface OneTimeMigrationWindow {
|
|
|
8
8
|
readonly id: OneTimeMigrationId;
|
|
9
9
|
/** 旧形在读侧的待遇(闭集,每词一义;「读写两面遇旧形一律响亮拒,迁移还在时拒句点名迁移 id、窗关删码后止于今天的位」这条律的例外只在这一格里写):
|
|
10
10
|
* · `refused` — 读写两面拒,拒句点名本行 id(经 `migrationSignpost` 铸;钉:每个 `refused` 行的 id 在 `src/` 至少一处铸点,
|
|
11
|
-
* 且非 `refused` 行零铸点)
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
readonly oldForm: "refused" | "read-as-default";
|
|
11
|
+
* 且非 `refused` 行零铸点)。
|
|
12
|
+
* (35.0.0 起只剩这一词:`read-as-default` —— 旧形是一份文档的缺席、读者按缺省读 —— 只给 SS-M11 用过,随它删。再登记一条不拒旧形的迁移,先在这里加回一词并写明它的义。) */
|
|
13
|
+
readonly oldForm: "refused";
|
|
15
14
|
/** 引入这条迁移的版本。 */
|
|
16
15
|
readonly introducedIn: string;
|
|
17
16
|
/** 该版本在 npm 上的发布日(UTC 日历日 YYYY-MM-DD)。`null` = 未发布形,由抬 `package.json` 到 `introducedIn` 的发布准备提交回填。 */
|
|
@@ -20,13 +20,10 @@
|
|
|
20
20
|
* (数组读里陷阱抛出的值原样出来,不是包里那一句);「不适用」只给形状(不是对象 / 不是数组 / 不是朴素对象 / 有洞的数组 —— 迁移只改它点名的键,读不懂的容器形不替调用方改,原样留给读面判)。三只小件各管一件:{@link snapshotOf}(对象容器 ⇒ 一份读数)· {@link rowsOf}(数组容器 ⇒ 按下标读一次的副本)·
|
|
21
21
|
* {@link objectFrom}(读数 ⇒ 新对象);步只许经它们读调用方的容器。JSON 解析出来的文档(纯数据)读不出也没有访问器,所以每一步的结果与读法无关;只有 JS 调用方交来的非纯数据会碰到抛。
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* 而「缺席」本身没有形可认 —— 所以它不归上面的律,另有三条:① 它读 env、碰文件系统,住 `./node`(`migrateEnvModelsDecision`),不在下面的纯函数入口里;
|
|
26
|
-
* ② 它靠**按 id 一份的运行记录**(`config.migration.SS-M11.json`,「不存在才建」)跑恰一次,建成运行记录的进程是本根唯一的执行者;
|
|
27
|
-
* ③ 它的旧形待遇是 `read-as-default`(缺席按读者的缺省 `kept` 读,没有拒句可点名)。窗、删法与删后由谁接住照样只写在登记表那一行。
|
|
23
|
+
* (35.0.0 起没有第二种机制:唯一一条「在配置根上铸一次事实」的迁移 SS-M11 —— 在 `config.env-models.json` 缺席处铸 `replaced`、靠运行记录跑恰一次 —— 窗关删了,
|
|
24
|
+
* 它的收据词 `minted` 与旧形待遇词 `read-as-default` 随它删;决定缺席 ≡ `kept`,由读者自己的判官说后果与出路。)
|
|
28
25
|
*
|
|
29
|
-
* ## 入口(
|
|
26
|
+
* ## 入口(纯函数:不读环境、不读墙钟、不改入参、**不抬任何版本号**)
|
|
30
27
|
* · {@link migrateStoredDocuments} —— 一组**存储文档**(域名 → 文档;还有本机的 `remote-exec` —— `config.d/remote-exec.json`:它是 `config.d`
|
|
31
28
|
* 能放的一份文档,所以照收,今天没有一步改写它)。一个 scope 的全部草稿、一个 principal 层(个人 models / mcp / skills / plugins)、回滚史里的一条单域行,各调一次。缺的域 = 不动
|
|
32
29
|
* (26.0.0 起没有一步要知道「缺席的域是从未设过还是没给」:那只问题的唯一读者 SS-M1 到期删了,`coverage` 选项随它删)。
|
|
@@ -52,28 +49,6 @@ import { deepFreeze } from "./deep-freeze.js";
|
|
|
52
49
|
export { MIGRATION_APPLIED_AS, ONE_TIME_MIGRATION_IDS } from "./migration-receipt.js";
|
|
53
50
|
/** 一次性迁移登记表 —— 本族各条窗的**唯一属主**。别处只写「窗见 `ONE_TIME_MIGRATIONS` 登记表」。 */
|
|
54
51
|
export const ONE_TIME_MIGRATIONS = deepFreeze([
|
|
55
|
-
{
|
|
56
|
-
id: "SS-M11",
|
|
57
|
-
oldForm: "read-as-default",
|
|
58
|
-
introducedIn: "14.8.0",
|
|
59
|
-
releasedOn: "2026-10-27",
|
|
60
|
-
removableAfter: "2026-11-26",
|
|
61
|
-
rewrites: "nothing stored is rewritten — the config root's env-model-table decision is minted once (migrateEnvModelsDecision, ./node): when the run " +
|
|
62
|
-
"marker config.migration.SS-M11.json is absent (a marker that does not read counts as run), the decision and whether config.d/models.json " +
|
|
63
|
-
"manages the model plane (catalogManagesModelPlane) are read first; then the marker is created exclusively — the one process that creates " +
|
|
64
|
-
"it is the only one that may mint on this root, any other stops for good — and that minter creates {\"envModels\":\"replaced\"} " +
|
|
65
|
-
"exclusively only when the decision it read before the election is absent and the catalog manages the model plane (whether an env model " +
|
|
66
|
-
"table is declared does not matter: the env only names the replaced env models) — the reading before the decision existed (a managing " +
|
|
67
|
-
"catalog replaced the env model table). Outcomes: minted / exists (only EEXIST) / failed (errno + a manual way out); an interruption after the marker is " +
|
|
68
|
-
"never retried. An absent root is created owner-only, holding only the marker; config.d is never created",
|
|
69
|
-
removal: "the next major after the window: delete migrateEnvModelsDecision (the SS-M11 body), this row, SS-M11 from ONE_TIME_MIGRATION_IDS, the " +
|
|
70
|
-
"`minted` receipt word and the `read-as-default` oldForm word; the marker then has no reader — readMigrationMarker and the marker's " +
|
|
71
|
-
"entry in CONFIG_ROOT_DOCUMENTS go with it (a marker left on disk is inert)",
|
|
72
|
-
afterRemoval: "an absent decision reads as kept — the reading the group-refusal code config.catalog_replaces_env_models is for: this package exports " +
|
|
73
|
-
"that code constant and the decision document for the engine to read, enforcing it is the engine's side, and the engine does not " +
|
|
74
|
-
"refuse on it today. Where the engine refuses, the way out is to write config.env-models.json = {\"envModels\":\"replaced\"} in the " +
|
|
75
|
-
"config root; no signpost in this package",
|
|
76
|
-
},
|
|
77
52
|
{
|
|
78
53
|
id: "SS-M12",
|
|
79
54
|
oldForm: "refused",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 包内私有(不进 exports 表、不进主桶):**插件 id 一段的文法** —— 全包唯一的定义,**零 import 的叶**。
|
|
3
|
+
*
|
|
4
|
+
* 一个插件 id `<名>@<市场>` 的两半(名、市场)读同一条文法:字母或数字起头,后接字母 / 数字 / `.` / `_` / `-`,不分大小写。
|
|
5
|
+
* 三处读它:`PluginSpec.name`、`PluginSource` 的 marketplace 臂(都在 `./types`),与插件 id 的读法 `readPluginId`(`./plugin-settings`)。
|
|
6
|
+
* 对 `readPluginId` 只有它的 ① 形(`<名>@<市场>`)是「两半各读同一条文法」;② 形(带 scope 的 npm 来源 id `@<scope>/<包名>@npm`)的名是整个带 scope 的包名(含 `@` 与 `/`),
|
|
7
|
+
* 它的两段读的是「全小写名段」判法(同一只正则再加「没有大写字母」;那只判法在 `./plugin-settings` 里,不在本文件)—— 所以 ② 形读出的名不是合法的 `PluginSpec.name`。
|
|
8
|
+
* 它住在叶上而不是 `./types` 里,是因为 `./plugin-settings` 是给宿主冷读设置用的纯读法子路径:为一只正则冷载入整张 zod 模式表,等于把「纯读法」说成半句。
|
|
9
|
+
* 公开名 `PLUGIN_ID_SEGMENT_REGEX` 经 `./types`(与包根)**原名转出**,转出的就是这一只对象;句子常量不出包。
|
|
10
|
+
*
|
|
11
|
+
* 正则无 `g` / `y` 标志:同一只对象被几处共用、被反复 `test`,不带 `lastIndex` 的记忆。
|
|
12
|
+
*/
|
|
13
|
+
export declare const PLUGIN_ID_SEGMENT_REGEX: RegExp;
|
|
14
|
+
/** 一段不过 {@link PLUGIN_ID_SEGMENT_REGEX} 时 zod 拒句的那一句(`PluginSpec.name` 与 `PluginSource` 的 marketplace 臂读同一句,文字只在这里一处)。 */
|
|
15
|
+
export declare const PLUGIN_ID_SEGMENT_SENTENCE = "letters/digits/._- , no spaces";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 包内私有(不进 exports 表、不进主桶):**插件 id 一段的文法** —— 全包唯一的定义,**零 import 的叶**。
|
|
3
|
+
*
|
|
4
|
+
* 一个插件 id `<名>@<市场>` 的两半(名、市场)读同一条文法:字母或数字起头,后接字母 / 数字 / `.` / `_` / `-`,不分大小写。
|
|
5
|
+
* 三处读它:`PluginSpec.name`、`PluginSource` 的 marketplace 臂(都在 `./types`),与插件 id 的读法 `readPluginId`(`./plugin-settings`)。
|
|
6
|
+
* 对 `readPluginId` 只有它的 ① 形(`<名>@<市场>`)是「两半各读同一条文法」;② 形(带 scope 的 npm 来源 id `@<scope>/<包名>@npm`)的名是整个带 scope 的包名(含 `@` 与 `/`),
|
|
7
|
+
* 它的两段读的是「全小写名段」判法(同一只正则再加「没有大写字母」;那只判法在 `./plugin-settings` 里,不在本文件)—— 所以 ② 形读出的名不是合法的 `PluginSpec.name`。
|
|
8
|
+
* 它住在叶上而不是 `./types` 里,是因为 `./plugin-settings` 是给宿主冷读设置用的纯读法子路径:为一只正则冷载入整张 zod 模式表,等于把「纯读法」说成半句。
|
|
9
|
+
* 公开名 `PLUGIN_ID_SEGMENT_REGEX` 经 `./types`(与包根)**原名转出**,转出的就是这一只对象;句子常量不出包。
|
|
10
|
+
*
|
|
11
|
+
* 正则无 `g` / `y` 标志:同一只对象被几处共用、被反复 `test`,不带 `lastIndex` 的记忆。
|
|
12
|
+
*/
|
|
13
|
+
export const PLUGIN_ID_SEGMENT_REGEX = /^[a-z0-9][a-z0-9._-]*$/i;
|
|
14
|
+
/** 一段不过 {@link PLUGIN_ID_SEGMENT_REGEX} 时 zod 拒句的那一句(`PluginSpec.name` 与 `PluginSource` 的 marketplace 臂读同一句,文字只在这里一处)。 */
|
|
15
|
+
export const PLUGIN_ID_SEGMENT_SENTENCE = "letters/digits/._- , no spaces";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件 id `<名>@<市场>` 的**市场位**上四个哨兵词(闭集):这些「市场」不是真有一份市场目录,而是标出这个插件**从哪儿来**。
|
|
3
|
+
* - `inline` —— 命令行指定目录载入的插件;
|
|
4
|
+
* - `skills-dir` —— 技能目录里的插件;
|
|
5
|
+
* - `synced` —— 从云端同步来的插件;
|
|
6
|
+
* - `builtin` —— 内置插件。
|
|
7
|
+
* `<名>@skills-dir` 是**合法 id**(名段、市场段都过名段文法,{@link readPluginId} 照常读出)。
|
|
8
|
+
* 参照读到哪一步:四词与「逐字严格相等比较」都读自参照(读码);词表不加不减。
|
|
9
|
+
* 注意:参照的托管策略表里另有一个同名的 `skills-dir` 策略哨兵 —— 那是**另一处**的词(策略来源的种类),不在本表、本版不读。
|
|
10
|
+
*/
|
|
11
|
+
export declare const PLUGIN_MARKETPLACE_SENTINELS: readonly ["inline", "skills-dir", "synced", "builtin"];
|
|
12
|
+
export type PluginMarketplaceSentinel = (typeof PLUGIN_MARKETPLACE_SENTINELS)[number];
|
|
13
|
+
/** 一个值是不是四个哨兵词之一。逐字严格相等(区分大小写,不裁剪、不规范化);非串一律 `false`,不抛。 */
|
|
14
|
+
export declare function isPluginMarketplaceSentinel(v: unknown): v is PluginMarketplaceSentinel;
|
|
15
|
+
/** {@link readPluginId} 读出的 id:名与市场两半。 */
|
|
16
|
+
export interface PluginId {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly marketplace: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 读一个插件 id。两条文法,答同一只形 `{ name, marketplace }`:
|
|
22
|
+
* ① **`<名>@<市场>`**:恰一个 `@`,两半各过名段文法 `PLUGIN_ID_SEGMENT_REGEX`(定义在包内私有的零 import 叶 `./plugin-id-segment`,`./types` 与包根原名转出;`PluginSpec.name` 与 `PluginSource` 的市场名读的是同一只对象);
|
|
23
|
+
* ② **`@<scope>/<包名>@npm`**(带 scope 的 npm 来源 id):名 = 整个带 scope 的包名(含开头的 `@` 与 `/`),市场 = `npm`。包名两段各是**全小写**名段、恰一个 `/`、整串不含 `..`。
|
|
24
|
+
* 不带 scope 的 npm 来源 id(`pkg@npm`)就是 ① 的一例(同一个答案),没有单列。
|
|
25
|
+
* 非串 / 两条文法都不过 ⇒ `undefined`(总:不抛,撤销的 Proxy 一类也只是非串)。不裁剪、不规范化(`@npm` 区分大小写)。
|
|
26
|
+
* 答案是**新造的、深冻的**。市场位上的哨兵词(`<名>@skills-dir` 等)照常读出,要不要当哨兵由调用方再问 {@link isPluginMarketplaceSentinel}。
|
|
27
|
+
*
|
|
28
|
+
* 参照读到哪一步(读自解出的语料 cli321.js 第 276223 行,行内列号为字符偏移,读码;没有对真实二进制核):
|
|
29
|
+
* - 参照的 id 判官 = 「`^ar@ar$` 或 `<npm 包名>@npm`」(列 56648 起);`ar` = `[A-Za-z0-9][-A-Za-z0-9._]*`,与 `PLUGIN_ID_SEGMENT_REGEX` 同一字符集;
|
|
30
|
+
* - npm 包名判官(列 24754 起):整串不含 `..` 与 `//`,且是带 scope 的 `@<小写名段>/<小写名段>` 或不带 scope 的 `<小写名段>`(小写名段 = `[a-z0-9][a-z0-9-._]*`);「`<npm 包名>@npm`」= 以 `@npm` 结尾且前半过它(`Cb = "npm"`,列 6859);
|
|
31
|
+
* - 参照把这样的 id 拆成 名 = 最后一个 `@` 之前的整段、市场 = `npm`(列 63291);
|
|
32
|
+
* - 本读法的 ② 与它逐格同判:不带 scope 的那一形被 ① 收下(答案一样),`//` 被「恰一个 `/`」挡掉。参照里 `pkg@pip` / `@github` 一类其他来源类市场名按 ① 读,不特判。
|
|
33
|
+
* 另:参照自己读 `enabledPlugins` 的键时不因 id 形坏而丢条目,本读法比参照读键更严 —— 读不出的 id 怎么处置由宿主定。
|
|
34
|
+
*/
|
|
35
|
+
export declare function readPluginId(v: unknown): PluginId | undefined;
|
|
36
|
+
/** {@link EnabledPluginsValue} 的判别词(闭集,四臂):`on` · `off` · `versions` · `unreadable`。 */
|
|
37
|
+
export declare const ENABLED_PLUGINS_VALUE_KINDS: readonly ["on", "off", "versions", "unreadable"];
|
|
38
|
+
export type EnabledPluginsValueKind = (typeof ENABLED_PLUGINS_VALUE_KINDS)[number];
|
|
39
|
+
/** {@link readEnabledPluginsValue} 的答案(判别键 `kind`,四臂)。 */
|
|
40
|
+
export type EnabledPluginsValue = {
|
|
41
|
+
readonly kind: "on";
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: "off";
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "versions";
|
|
46
|
+
readonly constraints: readonly string[];
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: "unreadable";
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 读 `enabledPlugins` 里**一个键的值**(键本身是 {@link readPluginId} 的事):
|
|
52
|
+
* - `true` ⇒ `{ kind: "on" }`;`false` ⇒ `{ kind: "off" }`;
|
|
53
|
+
* - 字符串数组 ⇒ `{ kind: "versions", constraints }`(`constraints` 是**新造的冻结副本**,事后改入参不影响答案);
|
|
54
|
+
* - 其余一切(串 `"true"`、`null`、`undefined`、数、对象、含非串元素的数组、读不出的对象 —— 撤销的 Proxy、访问器下标、稀疏数组)⇒ `{ kind: "unreadable" }`。
|
|
55
|
+
* 总(不抛),答案每次新造、深冻。**不定**与中心层 `plugins[].enabled` 的组合,**不定**缺席时的缺省 —— 入参就是一个值,缺席的键到不了这里。
|
|
56
|
+
*
|
|
57
|
+
* 参照读到哪一步:`true` / `false` / 字符串数组三形读自参照(读码;「数组」「字符串」两个构造器的身份按邻近用法推断,没有逐个追到定义)。参照的 schema 层对数组
|
|
58
|
+
* **不细判元素**:空数组、空串元素都收,不判每条是不是合法的版本范围。**本读法同读法** —— 数组只问「是不是字符串数组」,
|
|
59
|
+
* 每条约束怎么解释(范围 / 标签 / 精确版本)与「空数组算不算启用」是消费方的事;参照的更细判法(下游怎么用这些串)未核。
|
|
60
|
+
*/
|
|
61
|
+
export declare function readEnabledPluginsValue(v: unknown): EnabledPluginsValue;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件设置的三只纯读法:设置里 `enabledPlugins` 一个键的**值**怎么读({@link readEnabledPluginsValue})、插件 id `<名>@<市场>` 怎么拆({@link readPluginId})、
|
|
3
|
+
* id 市场位上的哨兵词是哪几个({@link PLUGIN_MARKETPLACE_SENTINELS} / {@link isPluginMarketplaceSentinel})。纯函数、零 `node:` 依赖、浏览器安全。
|
|
4
|
+
*
|
|
5
|
+
* ## 为什么在这里
|
|
6
|
+
* 插件创建面(共用库、终端)要读参照形的 `enabledPlugins` 值与插件 id,各宿主此前各写一份 —— 一个事实多个读者各自判。三只读法就是那一份:**只读值,不定合并**。
|
|
7
|
+
*
|
|
8
|
+
* ## 分工(消费方读法,不是新规则)
|
|
9
|
+
* - 中心层 `plugins[].enabled` 是部署层的供给闸;设置层的 `enabledPlugins` 是各设置源每一层各自的开关。**两层怎么组合不在本包。**
|
|
10
|
+
* 下面这句是给宿主的现行做法,不是本模块的行为(本模块不实现、不校验它,也不回答「最终启用与否」):
|
|
11
|
+
* 组合读法到货之前,同时读中心 `plugins` 与本机设置文件的宿主**只照中心层答**,不自己拼 —— 自己拼出来的是第二个来源。
|
|
12
|
+
* - 本模块不读任何文档、不碰合并顺序、不定缺席时的缺省(缺席的键根本到不了这里:读法的入参是一个值)。
|
|
13
|
+
* - 托管策略表(`strictKnownMarketplaces` / `blockedMarketplaces`)与它的哨兵臂、`pluginConfigs` / `extraKnownMarketplaces` 的条目形,都不在本模块;
|
|
14
|
+
* 策略读不出时的处置、`unreadable` / `undefined` 之后怎么办,也都是宿主的事。
|
|
15
|
+
*
|
|
16
|
+
* ## 参照
|
|
17
|
+
* 三只读法的形取自参照(CC 的设置读法)。那是**读自解出语料的线索、没有对真实二进制核**;每一条下面标了参照到哪一步。
|
|
18
|
+
* 参照读到哪一步、哪里没核,逐只写在各导出的 JSDoc 里。
|
|
19
|
+
*/
|
|
20
|
+
import { captureStringArray } from "./own-key-read.js";
|
|
21
|
+
import { deepFreeze } from "./deep-freeze.js";
|
|
22
|
+
import { PLUGIN_ID_SEGMENT_REGEX } from "./plugin-id-segment.js";
|
|
23
|
+
// ── 市场位上的哨兵词 ────────────────────────────────────────────────────────────────────────────────
|
|
24
|
+
/**
|
|
25
|
+
* 插件 id `<名>@<市场>` 的**市场位**上四个哨兵词(闭集):这些「市场」不是真有一份市场目录,而是标出这个插件**从哪儿来**。
|
|
26
|
+
* - `inline` —— 命令行指定目录载入的插件;
|
|
27
|
+
* - `skills-dir` —— 技能目录里的插件;
|
|
28
|
+
* - `synced` —— 从云端同步来的插件;
|
|
29
|
+
* - `builtin` —— 内置插件。
|
|
30
|
+
* `<名>@skills-dir` 是**合法 id**(名段、市场段都过名段文法,{@link readPluginId} 照常读出)。
|
|
31
|
+
* 参照读到哪一步:四词与「逐字严格相等比较」都读自参照(读码);词表不加不减。
|
|
32
|
+
* 注意:参照的托管策略表里另有一个同名的 `skills-dir` 策略哨兵 —— 那是**另一处**的词(策略来源的种类),不在本表、本版不读。
|
|
33
|
+
*/
|
|
34
|
+
export const PLUGIN_MARKETPLACE_SENTINELS = deepFreeze(["inline", "skills-dir", "synced", "builtin"]);
|
|
35
|
+
/** 一个值是不是四个哨兵词之一。逐字严格相等(区分大小写,不裁剪、不规范化);非串一律 `false`,不抛。 */
|
|
36
|
+
export function isPluginMarketplaceSentinel(v) {
|
|
37
|
+
return typeof v === "string" && PLUGIN_MARKETPLACE_SENTINELS.includes(v);
|
|
38
|
+
}
|
|
39
|
+
/** 来源类市场名里的 `npm`:id 市场位上是它时,名位可以是带 scope 的 npm 包名(见 {@link readPluginId})。它不是哨兵词,不在 {@link PLUGIN_MARKETPLACE_SENTINELS} 里。 */
|
|
40
|
+
const NPM_MARKETPLACE = "npm";
|
|
41
|
+
const NPM_ID_SUFFIX = `@${NPM_MARKETPLACE}`;
|
|
42
|
+
/** 一个名段是不是**全小写**的名段(npm 包名只收小写:名段文法本身不分大小写,这里再要求没有大写字母)。 */
|
|
43
|
+
const isLowercaseSegment = (part) => PLUGIN_ID_SEGMENT_REGEX.test(part) && part === part.toLowerCase();
|
|
44
|
+
/**
|
|
45
|
+
* 是不是**带 scope 的** npm 包名 `@<scope>/<名>`:`@`,一个全小写名段(scope),恰一个 `/`,一个全小写名段(包名);整串不含 `..`。
|
|
46
|
+
* 不带 scope 的 npm 包名没有单列:它本身就是一个名段,走 {@link readPluginId} 的一般文法(同一个答案)。
|
|
47
|
+
*/
|
|
48
|
+
function isScopedNpmPackageName(s) {
|
|
49
|
+
if (!s.startsWith("@") || s.includes(".."))
|
|
50
|
+
return false;
|
|
51
|
+
const slash = s.indexOf("/");
|
|
52
|
+
if (slash < 0 || s.indexOf("/", slash + 1) >= 0)
|
|
53
|
+
return false;
|
|
54
|
+
return isLowercaseSegment(s.slice(1, slash)) && isLowercaseSegment(s.slice(slash + 1));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 读一个插件 id。两条文法,答同一只形 `{ name, marketplace }`:
|
|
58
|
+
* ① **`<名>@<市场>`**:恰一个 `@`,两半各过名段文法 `PLUGIN_ID_SEGMENT_REGEX`(定义在包内私有的零 import 叶 `./plugin-id-segment`,`./types` 与包根原名转出;`PluginSpec.name` 与 `PluginSource` 的市场名读的是同一只对象);
|
|
59
|
+
* ② **`@<scope>/<包名>@npm`**(带 scope 的 npm 来源 id):名 = 整个带 scope 的包名(含开头的 `@` 与 `/`),市场 = `npm`。包名两段各是**全小写**名段、恰一个 `/`、整串不含 `..`。
|
|
60
|
+
* 不带 scope 的 npm 来源 id(`pkg@npm`)就是 ① 的一例(同一个答案),没有单列。
|
|
61
|
+
* 非串 / 两条文法都不过 ⇒ `undefined`(总:不抛,撤销的 Proxy 一类也只是非串)。不裁剪、不规范化(`@npm` 区分大小写)。
|
|
62
|
+
* 答案是**新造的、深冻的**。市场位上的哨兵词(`<名>@skills-dir` 等)照常读出,要不要当哨兵由调用方再问 {@link isPluginMarketplaceSentinel}。
|
|
63
|
+
*
|
|
64
|
+
* 参照读到哪一步(读自解出的语料 cli321.js 第 276223 行,行内列号为字符偏移,读码;没有对真实二进制核):
|
|
65
|
+
* - 参照的 id 判官 = 「`^ar@ar$` 或 `<npm 包名>@npm`」(列 56648 起);`ar` = `[A-Za-z0-9][-A-Za-z0-9._]*`,与 `PLUGIN_ID_SEGMENT_REGEX` 同一字符集;
|
|
66
|
+
* - npm 包名判官(列 24754 起):整串不含 `..` 与 `//`,且是带 scope 的 `@<小写名段>/<小写名段>` 或不带 scope 的 `<小写名段>`(小写名段 = `[a-z0-9][a-z0-9-._]*`);「`<npm 包名>@npm`」= 以 `@npm` 结尾且前半过它(`Cb = "npm"`,列 6859);
|
|
67
|
+
* - 参照把这样的 id 拆成 名 = 最后一个 `@` 之前的整段、市场 = `npm`(列 63291);
|
|
68
|
+
* - 本读法的 ② 与它逐格同判:不带 scope 的那一形被 ① 收下(答案一样),`//` 被「恰一个 `/`」挡掉。参照里 `pkg@pip` / `@github` 一类其他来源类市场名按 ① 读,不特判。
|
|
69
|
+
* 另:参照自己读 `enabledPlugins` 的键时不因 id 形坏而丢条目,本读法比参照读键更严 —— 读不出的 id 怎么处置由宿主定。
|
|
70
|
+
*/
|
|
71
|
+
export function readPluginId(v) {
|
|
72
|
+
if (typeof v !== "string")
|
|
73
|
+
return undefined;
|
|
74
|
+
if (v.endsWith(NPM_ID_SUFFIX)) {
|
|
75
|
+
const packageName = v.slice(0, v.length - NPM_ID_SUFFIX.length);
|
|
76
|
+
if (isScopedNpmPackageName(packageName))
|
|
77
|
+
return deepFreeze({ name: packageName, marketplace: NPM_MARKETPLACE });
|
|
78
|
+
}
|
|
79
|
+
const at = v.indexOf("@");
|
|
80
|
+
if (at < 0 || v.indexOf("@", at + 1) >= 0)
|
|
81
|
+
return undefined;
|
|
82
|
+
const name = v.slice(0, at);
|
|
83
|
+
const marketplace = v.slice(at + 1);
|
|
84
|
+
if (!PLUGIN_ID_SEGMENT_REGEX.test(name) || !PLUGIN_ID_SEGMENT_REGEX.test(marketplace))
|
|
85
|
+
return undefined;
|
|
86
|
+
return deepFreeze({ name, marketplace });
|
|
87
|
+
}
|
|
88
|
+
// ── `enabledPlugins` 的值 ──────────────────────────────────────────────────────────────────────────
|
|
89
|
+
/** {@link EnabledPluginsValue} 的判别词(闭集,四臂):`on` · `off` · `versions` · `unreadable`。 */
|
|
90
|
+
export const ENABLED_PLUGINS_VALUE_KINDS = deepFreeze(["on", "off", "versions", "unreadable"]);
|
|
91
|
+
/**
|
|
92
|
+
* 读 `enabledPlugins` 里**一个键的值**(键本身是 {@link readPluginId} 的事):
|
|
93
|
+
* - `true` ⇒ `{ kind: "on" }`;`false` ⇒ `{ kind: "off" }`;
|
|
94
|
+
* - 字符串数组 ⇒ `{ kind: "versions", constraints }`(`constraints` 是**新造的冻结副本**,事后改入参不影响答案);
|
|
95
|
+
* - 其余一切(串 `"true"`、`null`、`undefined`、数、对象、含非串元素的数组、读不出的对象 —— 撤销的 Proxy、访问器下标、稀疏数组)⇒ `{ kind: "unreadable" }`。
|
|
96
|
+
* 总(不抛),答案每次新造、深冻。**不定**与中心层 `plugins[].enabled` 的组合,**不定**缺席时的缺省 —— 入参就是一个值,缺席的键到不了这里。
|
|
97
|
+
*
|
|
98
|
+
* 参照读到哪一步:`true` / `false` / 字符串数组三形读自参照(读码;「数组」「字符串」两个构造器的身份按邻近用法推断,没有逐个追到定义)。参照的 schema 层对数组
|
|
99
|
+
* **不细判元素**:空数组、空串元素都收,不判每条是不是合法的版本范围。**本读法同读法** —— 数组只问「是不是字符串数组」,
|
|
100
|
+
* 每条约束怎么解释(范围 / 标签 / 精确版本)与「空数组算不算启用」是消费方的事;参照的更细判法(下游怎么用这些串)未核。
|
|
101
|
+
*/
|
|
102
|
+
export function readEnabledPluginsValue(v) {
|
|
103
|
+
if (v === true)
|
|
104
|
+
return deepFreeze({ kind: "on" });
|
|
105
|
+
if (v === false)
|
|
106
|
+
return deepFreeze({ kind: "off" });
|
|
107
|
+
const constraints = captureStringArray(v, "strict");
|
|
108
|
+
if (constraints !== undefined)
|
|
109
|
+
return deepFreeze({ kind: "versions", constraints });
|
|
110
|
+
return deepFreeze({ kind: "unreadable" });
|
|
111
|
+
}
|
package/dist/retired-envs.js
CHANGED
|
@@ -33,6 +33,8 @@ export const RETIRED_ENV_REFUSAL_CODE = "config.env_key_retired";
|
|
|
33
33
|
const OA_REMOVED = "the OA scenario was removed in 5.0.0";
|
|
34
34
|
/** 调度两只旧旋钮共用的理由句(一句话说清变成了什么、怎么写;会原样进拒启句,所以不带点分版本号)。 */
|
|
35
35
|
const SCHEDULER_RESIDENT_WHY = "whether anything fires due scheduled records is now one declaration instead of a per-capability opt-out: write SCHEDULER_RESIDENT_TRIGGER=true when a resident process (the terminal's interactive screen) fires them, and leave it unset when none does — then the scheduling tools are not mounted at all";
|
|
36
|
+
/** 沙箱直传用户文件通道删除后的理由句(原样进拒启句,不带点分版本号)。 */
|
|
37
|
+
const SEND_USER_FILE_SANDBOX_PUT_ENDPOINT_WHY = "the sandbox direct-upload lane this endpoint configured was removed: files a task sends to the user are now read through the engine's read permission and uploaded by the server itself. Delete this variable; no replacement is needed. Object-store permissions that existed only for sandbox direct uploads can be dropped";
|
|
36
38
|
const negativeAliasWhy = (old, positive) => `negative-name alias retired in server 3.0.0 — unset it; the polarity is inverted: ${old}=true is ${positive}=false (the positive name defaults on)`;
|
|
37
39
|
export const RETIRED_ENVS = deepFreeze([
|
|
38
40
|
["TIDB_HOST", "MYSQL_HOST", "renamed"],
|
|
@@ -103,6 +105,9 @@ export const RETIRED_ENVS = deepFreeze([
|
|
|
103
105
|
// 理由句只说为什么换成一只声明、不带点分版本号(会原样进拒启句;与 SESSION_BOX_ENGINE_FRAMES / LSP_ENABLED / STREAM_APPROVAL_ENABLED / MODEL_DEGRADE_REACTIVE 同约定;两行逐字同一句):版本事实写在这里与 CHANGELOG。
|
|
104
106
|
["SCHEDULER_SESSION_WAKEUP", "SCHEDULER_RESIDENT_TRIGGER", "replaced", SCHEDULER_RESIDENT_WHY],
|
|
105
107
|
["SCHEDULER_SESSION_LIFETIME", "SCHEDULER_RESIDENT_TRIGGER", "replaced", SCHEDULER_RESIDENT_WHY],
|
|
108
|
+
// 沙箱直传用户文件的通道已删除:任务发给用户的文件改为经引擎读权限由服务端直接读取并上传,不再走沙箱直传端点,没有替代变量名。
|
|
109
|
+
// 理由句不带点分版本号(原样进拒启句),与上面各行同约定。
|
|
110
|
+
["SEND_USER_FILE_SANDBOX_PUT_ENDPOINT", SEND_USER_FILE_SANDBOX_PUT_ENDPOINT_WHY, "removed"],
|
|
106
111
|
]);
|
|
107
112
|
/** 墓碑表 → wire 投影(纯数据)。**同一张表、同序**;族是闭集,穷举 switch(加一族不写这里 ⇒ 编译红)。 */
|
|
108
113
|
export function buildRetiredEnvWire() {
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
import { z } from "zod";
|
|
69
69
|
/** How values from different layers/principals combine for a category. */
|
|
70
70
|
export declare const MergeShape: z.ZodEnum<{
|
|
71
|
-
replace: "replace";
|
|
72
71
|
concat: "concat";
|
|
72
|
+
replace: "replace";
|
|
73
73
|
denyFirst: "denyFirst";
|
|
74
74
|
runAll: "runAll";
|
|
75
75
|
overrideByName: "overrideByName";
|
|
@@ -262,8 +262,8 @@ export type TightenVerdict = (typeof TIGHTEN_VERDICTS)[number];
|
|
|
262
262
|
export declare function tightenVerdict(rule: TightenRule, existing: unknown, candidate: unknown): TightenVerdict;
|
|
263
263
|
export declare const MergeCategorySpec: z.ZodObject<{
|
|
264
264
|
mergeShape: z.ZodEnum<{
|
|
265
|
-
replace: "replace";
|
|
266
265
|
concat: "concat";
|
|
266
|
+
replace: "replace";
|
|
267
267
|
denyFirst: "denyFirst";
|
|
268
268
|
runAll: "runAll";
|
|
269
269
|
overrideByName: "overrideByName";
|
|
@@ -668,6 +668,27 @@ export declare const SAFETY_MERGE_SPEC: {
|
|
|
668
668
|
readonly fail: "closed";
|
|
669
669
|
readonly seam: "settings.webSearch (one section, taken whole from one layer) → request settings.webSearch";
|
|
670
670
|
};
|
|
671
|
+
readonly autoMemory: {
|
|
672
|
+
readonly mergeShape: "replace";
|
|
673
|
+
readonly minTrust: "global";
|
|
674
|
+
readonly tighten: {
|
|
675
|
+
readonly rule: "boolStricter";
|
|
676
|
+
readonly strict: false;
|
|
677
|
+
};
|
|
678
|
+
readonly enforcement: "resolver";
|
|
679
|
+
readonly fail: "closed";
|
|
680
|
+
readonly seam: "auto-memory switch (autoMemoryEnabled = false disables reading and writing auto-memory; enforced at the settings resolver)";
|
|
681
|
+
readonly members: {
|
|
682
|
+
readonly autoMemoryEnabled: {
|
|
683
|
+
readonly direction: "tighten";
|
|
684
|
+
readonly minTrust: "global";
|
|
685
|
+
readonly boolPole: {
|
|
686
|
+
readonly strict: false;
|
|
687
|
+
readonly minTrust: "local";
|
|
688
|
+
};
|
|
689
|
+
};
|
|
690
|
+
};
|
|
691
|
+
};
|
|
671
692
|
};
|
|
672
693
|
export type SafetyMergeCategory = keyof typeof SAFETY_MERGE_SPEC;
|
|
673
694
|
/** The members a category declares, as a CLOSED SET TYPE: `"allow" | "deny" | "ask"` for `permissions`, `never` for
|
|
@@ -485,6 +485,19 @@ export const SAFETY_MERGE_SPEC = deepFreeze({
|
|
|
485
485
|
mergeShape: "replace", minTrust: "project", tighten: { rule: "none" }, enforcement: "resolver", fail: "closed",
|
|
486
486
|
seam: `settings.${WEB_SEARCH_SECTION_KEYS[0]} (one section, taken whole from one layer) → request settings.${WEB_SEARCH_SECTION_KEYS[0]}`,
|
|
487
487
|
},
|
|
488
|
+
// The auto-memory switch `autoMemoryEnabled` (boolean; `false` disables reading from and writing to auto-memory).
|
|
489
|
+
// TIGHTEN-ONLY FROM EVERY LAYER: disabling auto-memory (`false`) narrows what a session reads/writes, so any settings-file
|
|
490
|
+
// layer may set it (strict pole `false` at `"local"`, the lowest settings-file tier); `true`, a non-boolean or a valueless
|
|
491
|
+
// query sits at the row floor `"global"` (user / flag / policy only — never admitted from repository-controllable layers,
|
|
492
|
+
// and a pre-boolPole consumer withholds both poles from repository layers, fail-closed). Merged `replace` + `boolStricter`
|
|
493
|
+
// with `strict: false`: once any admitted layer sets `false`, no other layer can re-enable it.
|
|
494
|
+
autoMemory: {
|
|
495
|
+
mergeShape: "replace", minTrust: "global", tighten: { rule: "boolStricter", strict: false }, enforcement: "resolver", fail: "closed",
|
|
496
|
+
seam: "auto-memory switch (autoMemoryEnabled = false disables reading and writing auto-memory; enforced at the settings resolver)",
|
|
497
|
+
members: {
|
|
498
|
+
autoMemoryEnabled: { direction: "tighten", minTrust: "global", boolPole: { strict: false, minTrust: "local" } },
|
|
499
|
+
},
|
|
500
|
+
},
|
|
488
501
|
});
|
|
489
502
|
/** Own-property table lookup. The category union is compile-time only; a JavaScript or deserialized caller can
|
|
490
503
|
* hand in `"__proto__"` / `"constructor"` / `"toString"`, which a bare index resolves through Object.prototype
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { type SchedulerParseWarning, type SchedulerReadOptions, type SchedulerRecord, type SchedulerStore, type
|
|
1
|
+
import { type SchedulerParseWarning, type SchedulerReadOptions, type SchedulerRecord, type SchedulerStore, type SchedulerStoreFileRead } from './scheduler-store.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* a whole file that is not a JSON array reads as zero records + `unreadable-file` — NOT as an empty store (writers must go
|
|
8
|
-
* through {@link mutateSchedulerStore}, which refuses to write over it).
|
|
3
|
+
* 读调度店文件:读法与读数见 {@link storeFileReadOf} —— 路径不在 ⇒ `absent: true`、零条零告警;店路径是悬空符号链接 ⇒ 原样抛那一句(不吞、不重包;
|
|
4
|
+
* 句子与写器同一句);其余读失败(`EACCES` / `EIO` / `EISDIR` / …)原样抛。路径是指向真文件的符号链接 ⇒ 读真文件(写器写的也是真文件)。
|
|
5
|
+
* 解析告警随 `warnings` 返回({@link parseSchedulerStore});整份文件不是 JSON 数组时读作零条记录 + `unreadable-file`,
|
|
6
|
+
* 写者须经 {@link mutateSchedulerStore}(遇它拒写)。
|
|
9
7
|
*/
|
|
10
|
-
export declare function loadSchedulerStore(path: string, opts: SchedulerReadOptions):
|
|
8
|
+
export declare function loadSchedulerStore(path: string, opts: SchedulerReadOptions): SchedulerStoreFileRead;
|
|
11
9
|
/**
|
|
12
10
|
* Persist ATOMICALLY: create the parent if it is missing, then the package's one atomic writer (`./atomic-write`: a uniquely-named `.tmp`
|
|
13
11
|
* sibling, then `rename` over the target — atomic on POSIX, so a concurrent reader never sees a partial file). The file mode
|
|
@@ -26,7 +24,9 @@ export declare function saveSchedulerStore(path: string, records: SchedulerRecor
|
|
|
26
24
|
* 消费方改调 `createFileSchedulerStore`(改名是硬 breaking:消费方的 tsc 红 / 运行期 undefined 就是通知本身)。 */
|
|
27
25
|
export declare function createFileSchedulerStore(path: string, opts: {
|
|
28
26
|
now: () => number;
|
|
29
|
-
}): SchedulerStore
|
|
27
|
+
}): Omit<SchedulerStore, 'load'> & {
|
|
28
|
+
load(): SchedulerStoreFileRead;
|
|
29
|
+
};
|
|
30
30
|
/** Outcome of {@link mutateSchedulerStore}. `conflict_exhausted` = a concurrent writer kept changing the file
|
|
31
31
|
* faster than the bounded replays; nothing was written on that final attempt (earlier attempts never wrote).
|
|
32
32
|
* `unreadable_file` = the file on disk is not a JSON array: `fn` never ran and nothing was written (writing would replace
|
|
@@ -55,7 +55,8 @@ export type SchedulerStoreMutation = ({
|
|
|
55
55
|
* load→filter→save — the naked sequence is a lost-update race: two writers load the same base
|
|
56
56
|
* array, mutate independently, and the later `save` silently reverts the earlier one.
|
|
57
57
|
*
|
|
58
|
-
* Optimistic concurrency
|
|
58
|
+
* Optimistic concurrency with no envelope / sidecar / lock file (the on-disk format stays the plain array; the TEXT is not preserved —
|
|
59
|
+
* the commit rewrites the whole array via `serializeSchedulerStore`, and records the read dropped are not written back):
|
|
59
60
|
* 1. read the RAW file text and keep it as the base witness (missing file ⇒ empty witness);
|
|
60
61
|
* 2. run `fn(records)` — MUST be pure/replayable; return the next records array, or `null` to
|
|
61
62
|
* abort with no write (e.g. "nothing to do" discovered under the latest base);
|
|
@@ -73,7 +74,9 @@ export type SchedulerStoreMutation = ({
|
|
|
73
74
|
* above). A base file that is not a JSON array ⇒ `unreadable_file`, no write. `nowMs` is the caller's clock (the read drops
|
|
74
75
|
* session-pinned records that went stale — see `parseSchedulerStore`).
|
|
75
76
|
*/
|
|
76
|
-
export declare function mutateSchedulerStore(path: string, fn: (records: SchedulerRecord[]
|
|
77
|
+
export declare function mutateSchedulerStore(path: string, fn: (records: SchedulerRecord[], base: {
|
|
78
|
+
readonly absent: boolean;
|
|
79
|
+
}) => SchedulerRecord[] | null, opts: {
|
|
77
80
|
nowMs: number;
|
|
78
81
|
retries?: number;
|
|
79
82
|
}): SchedulerStoreMutation;
|
|
@@ -6,29 +6,25 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Store path = caller-supplied; both sides agree on `SEMA_CONFIG_DIR` → `~/.sema/scheduled_tasks.json`.
|
|
8
8
|
*/
|
|
9
|
-
import { readFileSync } from 'node:fs';
|
|
10
9
|
import { dirname } from 'node:path';
|
|
11
|
-
import { ensureOwnerOnlyDirectory, writeFileAtomic } from './atomic-write.js';
|
|
10
|
+
import { ensureOwnerOnlyDirectory, readTextIfPresentSync, writeFileAtomic } from './atomic-write.js';
|
|
12
11
|
import { parseSchedulerStore, serializeSchedulerStore } from './scheduler-store.js';
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
* 店文件的一次读数 —— **只此一只铸法**({@link loadSchedulerStore} 与 {@link mutateSchedulerStore} 共用):文本由包里那只同步读口
|
|
14
|
+
* `readTextIfPresentSync` 读(「文件不在 / 悬空软链」只在它的缺席尾判一次:路径上没有条目 ⇒ `undefined`;悬空软链 ⇒ 抛那一句悬空句;别的读失败原样抛)。
|
|
15
|
+
* `undefined` ⇒ `{ records: [], warnings: [], absent: true }`;读到文本 ⇒ `{ ...parseSchedulerStore(text, opts), absent: false }`(文件是 `[]` 或非数组坏内容时 `absent` 也是 `false`)。
|
|
16
|
+
*/
|
|
17
|
+
function storeFileReadOf(text, opts) {
|
|
18
|
+
return text === undefined ? { records: [], warnings: [], absent: true } : { ...parseSchedulerStore(text, opts), absent: false };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 读调度店文件:读法与读数见 {@link storeFileReadOf} —— 路径不在 ⇒ `absent: true`、零条零告警;店路径是悬空符号链接 ⇒ 原样抛那一句(不吞、不重包;
|
|
22
|
+
* 句子与写器同一句);其余读失败(`EACCES` / `EIO` / `EISDIR` / …)原样抛。路径是指向真文件的符号链接 ⇒ 读真文件(写器写的也是真文件)。
|
|
23
|
+
* 解析告警随 `warnings` 返回({@link parseSchedulerStore});整份文件不是 JSON 数组时读作零条记录 + `unreadable-file`,
|
|
24
|
+
* 写者须经 {@link mutateSchedulerStore}(遇它拒写)。
|
|
20
25
|
*/
|
|
21
26
|
export function loadSchedulerStore(path, opts) {
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
text = readFileSync(path, 'utf-8');
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
if (e.code === 'ENOENT')
|
|
28
|
-
return { records: [], warnings: [] };
|
|
29
|
-
throw e;
|
|
30
|
-
}
|
|
31
|
-
return parseSchedulerStore(text, opts);
|
|
27
|
+
return storeFileReadOf(readTextIfPresentSync(path), opts);
|
|
32
28
|
}
|
|
33
29
|
/**
|
|
34
30
|
* Persist ATOMICALLY: create the parent if it is missing, then the package's one atomic writer (`./atomic-write`: a uniquely-named `.tmp`
|
|
@@ -62,7 +58,8 @@ export function createFileSchedulerStore(path, opts) {
|
|
|
62
58
|
* load→filter→save — the naked sequence is a lost-update race: two writers load the same base
|
|
63
59
|
* array, mutate independently, and the later `save` silently reverts the earlier one.
|
|
64
60
|
*
|
|
65
|
-
* Optimistic concurrency
|
|
61
|
+
* Optimistic concurrency with no envelope / sidecar / lock file (the on-disk format stays the plain array; the TEXT is not preserved —
|
|
62
|
+
* the commit rewrites the whole array via `serializeSchedulerStore`, and records the read dropped are not written back):
|
|
66
63
|
* 1. read the RAW file text and keep it as the base witness (missing file ⇒ empty witness);
|
|
67
64
|
* 2. run `fn(records)` — MUST be pure/replayable; return the next records array, or `null` to
|
|
68
65
|
* abort with no write (e.g. "nothing to do" discovered under the latest base);
|
|
@@ -82,27 +79,18 @@ export function createFileSchedulerStore(path, opts) {
|
|
|
82
79
|
*/
|
|
83
80
|
export function mutateSchedulerStore(path, fn, opts) {
|
|
84
81
|
const maxRetries = Math.max(0, opts.retries ?? 5);
|
|
85
|
-
const rawOf = () => {
|
|
86
|
-
try {
|
|
87
|
-
return readFileSync(path, 'utf-8');
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
if (e.code === 'ENOENT')
|
|
91
|
-
return null; // missing file — parse side treats as []
|
|
92
|
-
throw e; // non-ENOENT (EACCES/EIO/EISDIR/…) must NOT collapse to "missing" — that would hand fn a fake
|
|
93
|
-
// empty baseline and the subsequent save() would overwrite real on-disk data with just fn's additions.
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
82
|
for (let attempt = 0;; attempt++) {
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
// the read's absence law is the package's one (`readTextIfPresentSync`): a read failure that is not absence (EACCES/EIO/EISDIR/a dangling link…) throws —
|
|
84
|
+
// it must NOT collapse to "missing": that would hand fn a fake empty baseline and the save below would overwrite real on-disk data with just fn's additions
|
|
85
|
+
const baseRaw = readTextIfPresentSync(path);
|
|
86
|
+
const base = storeFileReadOf(baseRaw, { nowMs: opts.nowMs });
|
|
99
87
|
const { warnings } = base;
|
|
100
88
|
if (warnings.some((w) => w.kind === 'unreadable-file'))
|
|
101
89
|
return { ok: false, reason: 'unreadable_file', warnings };
|
|
102
|
-
const next = fn(base.records);
|
|
90
|
+
const next = fn(base.records, { absent: base.absent });
|
|
103
91
|
if (next === null)
|
|
104
92
|
return { ok: false, reason: 'aborted', warnings };
|
|
105
|
-
if (
|
|
93
|
+
if (readTextIfPresentSync(path) !== baseRaw) {
|
|
106
94
|
if (attempt >= maxRetries)
|
|
107
95
|
return { ok: false, reason: 'conflict_exhausted', retries: attempt, warnings };
|
|
108
96
|
continue; // a concurrent writer landed between our read and commit intent — replay on the new base
|