@sema-agent/settings-schema 34.1.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 +398 -0
- package/README.md +64 -32
- 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/atomic-write.js +1 -1
- package/dist/catalog-manages.js +2 -2
- 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/env-model-table.d.ts +3 -3
- package/dist/env-model-table.js +5 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- 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/retired-envs.js +5 -0
- package/dist/safety-merge-spec.d.ts +21 -0
- 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 +44 -2
- package/dist/types.js +70 -2
- package/docs/API-SURFACE.md +23 -11
- package/docs/CC-DIVERGENCE.md +2 -1
- package/docs/CONFORMANCE.md +3 -3
- package/docs/CONSUMER-INTEGRATION.md +106 -11
- package/llms-full.txt +35 -12
- package/llms.txt +14 -5
- package/package.json +3 -3
|
@@ -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",
|
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() {
|
|
@@ -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
|
|
@@ -10,8 +10,8 @@ export type SchedulerWhen = {
|
|
|
10
10
|
delaySec: number;
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
* A persisted scheduled record (durable across restarts). Required: id/scope/prompt/when/createdMs.
|
|
14
|
-
*
|
|
13
|
+
* A persisted scheduled record (durable across restarts). Required: id/scope/prompt/when/createdMs. Unknown fields are
|
|
14
|
+
* preserved on round-trip; every DECLARED member is judged by `isSchedulerRecord` (declaring one adds its row there — the table is exhaustive over this type).
|
|
15
15
|
*/
|
|
16
16
|
export interface SchedulerRecord {
|
|
17
17
|
id: string;
|
|
@@ -24,6 +24,11 @@ export interface SchedulerRecord {
|
|
|
24
24
|
label?: string;
|
|
25
25
|
createdMs: number;
|
|
26
26
|
nextRunMs?: number;
|
|
27
|
+
/** 记录生命周期。今天的写者写两词之一:`"durable"`(缺席同读)/ `"session"`(读口的过期清理只认这一词)。
|
|
28
|
+
* 型对别的串开放:判官只判它在场时是串,不判是哪个词 —— 较新写者写下的词原样读出(前向兼容,不丢不改);读者按词判,已知两词之外由读者自己处置。 */
|
|
29
|
+
lifetime?: 'durable' | 'session' | (string & {});
|
|
30
|
+
/** 调度模式。今天的写者写两词之一:`"task"` / `"session-wakeup"`(本包的读口不读这一键)。型对别的串开放,理由与 `lifetime` 同。 */
|
|
31
|
+
mode?: 'task' | 'session-wakeup' | (string & {});
|
|
27
32
|
}
|
|
28
33
|
/**
|
|
29
34
|
* The store ABSTRACTION the two sides depend on (writer saves, reader loads). The `@sema-agent/settings-schema/node`
|
|
@@ -34,16 +39,22 @@ export interface SchedulerStore {
|
|
|
34
39
|
load(): SchedulerStoreRead;
|
|
35
40
|
save(records: SchedulerRecord[]): void;
|
|
36
41
|
}
|
|
37
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* The ONE record judge, two rules: ① **the judge is the type** — every declared member ({@link RECORD_MEMBERS}, `when` by its arm {@link WHEN_MEMBER}) that is
|
|
44
|
+
* present holds its declared type (strings are strings, numbers are numbers), the required ones are present; a member written as `undefined` reads as absent;
|
|
45
|
+
* ② **the element is plain JSON data and every number anywhere in it is finite** ({@link isFiniteJsonData}: declared members, unknown fields and their nesting alike).
|
|
46
|
+
* Unknown fields are otherwise free and preserved. 35.0.0: before, only the required members' `typeof` — a record whose `lifetime` was `{}`, whose `createdMs`
|
|
47
|
+
* was `1e400`, or whose custom field nested a `1e400` passed, was read as the declared type, and its non-finite number turned into `null` on the next write.
|
|
48
|
+
*/
|
|
38
49
|
export declare function isSchedulerRecord(v: unknown): v is SchedulerRecord;
|
|
39
|
-
/** 一条会话链上的记录过期多久算「永驻孤儿」:`lifetime: "session"` ∧ `sessionId`
|
|
50
|
+
/** 一条会话链上的记录过期多久算「永驻孤儿」:`lifetime: "session"` ∧ `sessionId` 是非空串 ∧ `nextRunMs` 在场(是数)且已过去这么久 ⇒ 读口丢弃并告警(7 天)。 */
|
|
40
51
|
export declare const STALE_SESSION_RECORD_MS: number;
|
|
41
52
|
/** {@link parseSchedulerStore} 对它读到的数据**做了什么**(而不是逐字读)。闭集 —— 新 `kind` 是联合加员(穷举 `switch` 的消费方
|
|
42
53
|
* 会编译红,那就是通知)。`index` = 记录在原数组里的下标(对照源文件用)。
|
|
43
54
|
* - `unreadable-file` — 整份文件不是 JSON / 不是数组:读出零条记录。**不是**「空店」:{@link mutateSchedulerStore} 遇它拒写
|
|
44
55
|
* (否则下一次保存会把盘上那份读不懂的数据整份覆盖掉)。
|
|
45
|
-
* - `malformed-record` — 这一条没过 {@link isSchedulerRecord},丢弃;`record` = 原值(未校验,诊断用)。
|
|
46
|
-
* - `stale-session-record` — 会话链上的记录(`lifetime: "session"` ∧ `sessionId`
|
|
56
|
+
* - `malformed-record` — 这一条没过 {@link isSchedulerRecord}(缺必填成员、声明成员不是声明的型、元素里任何一处的数不是有限数 —— 例 `1e400` 解析出的 `Infinity`,自定义字段里的也算 —— 或元素读不成纯 JSON 数据),丢弃;`record` = 原值(未校验,诊断用)。
|
|
57
|
+
* - `stale-session-record` — 会话链上的记录(`lifetime: "session"` ∧ `sessionId` 是非空串)而 `nextRunMs` 在场、已过去 ≥ {@link STALE_SESSION_RECORD_MS}:
|
|
47
58
|
* 它的会话没走到收割(无常驻 daemon 的车道 / 崩溃),再留着就是永驻。丢弃,不另起写 —— 下一个写者落盘。
|
|
48
59
|
* **只认显式的 `"session"`**:`lifetime` 缺席读作 durable;durable 记录带着来源 sessionId
|
|
49
60
|
* 是合法形,daemon 停机一周后的 cron 照样是用户的任务,不许当孤儿丢。
|
|
@@ -68,6 +79,10 @@ export interface SchedulerStoreRead {
|
|
|
68
79
|
readonly records: SchedulerRecord[];
|
|
69
80
|
readonly warnings: SchedulerParseWarning[];
|
|
70
81
|
}
|
|
82
|
+
/** 一次文件读的结果:{@link SchedulerStoreRead} 加上文件当时是否缺席(`absent`:路径不存在 ⇒ `true`;文件存在,含空数组 `[]` 或非数组坏内容 ⇒ `false`)。 */
|
|
83
|
+
export type SchedulerStoreFileRead = SchedulerStoreRead & {
|
|
84
|
+
readonly absent: boolean;
|
|
85
|
+
};
|
|
71
86
|
/** 读口的入参:`nowMs` 由调用方给(本包不读墙钟),判 {@link STALE_SESSION_RECORD_MS}。 */
|
|
72
87
|
export interface SchedulerReadOptions {
|
|
73
88
|
readonly nowMs: number;
|
package/dist/scheduler-store.js
CHANGED
|
@@ -8,44 +8,125 @@
|
|
|
8
8
|
* - ABSTRACT: this module is the type + the parse/serialize FORMAT + the `SchedulerStore` interface. It has
|
|
9
9
|
* ZERO runtime IO and ZERO deps (no `@sema-agent/*`, no `node:*`) so it lives in the browser-safe barrel.
|
|
10
10
|
* The concrete filesystem binding is `@sema-agent/settings-schema/node` (`loadSchedulerStore`/`saveSchedulerStore`).
|
|
11
|
-
* - EXTENSIBLE: `parseSchedulerStore` is FORWARD-COMPATIBLE — it validates
|
|
12
|
-
* PRESERVES unknown fields, so a newer writer can add fields
|
|
13
|
-
* round-trip.
|
|
11
|
+
* - EXTENSIBLE: `parseSchedulerStore` is FORWARD-COMPATIBLE — it validates the declared members (each present one
|
|
12
|
+
* holds its declared type) and that every number anywhere in the element is finite (see `isSchedulerRecord`), and PRESERVES unknown fields, so a newer writer can add fields
|
|
13
|
+
* without an older reader dropping them on round-trip. A new optional `SchedulerRecord` field is additive for the
|
|
14
|
+
* type; judging it is a validation change for the records already on disk that carry that key.
|
|
14
15
|
* - CONTRACTUAL: `when` is an inlined structural union kept byte-compatible with core `ScheduledIntent['when']`
|
|
15
16
|
* but NOT imported — the contract stands alone, independent of the engine.
|
|
16
17
|
*
|
|
17
18
|
* 🔴 `principal` is pinned by the writer from Runner-held ctx (never the model); persisted opaquely, passed
|
|
18
19
|
* through to `runTask` unchanged by the daemon (no privilege escalation).
|
|
19
20
|
*/
|
|
20
|
-
import { ownDeclaredValueOf } from './own-key-read.js';
|
|
21
|
+
import { captureJson, ownDeclaredValueOf, ownRow } from './own-key-read.js';
|
|
21
22
|
import { isJsonArray, isPlainJsonObject } from './plain-json-object.js';
|
|
22
23
|
import { isSessionLifetime } from './scheduler-lifetime.js';
|
|
23
|
-
|
|
24
|
+
const isText = (value) => typeof value === 'string';
|
|
25
|
+
const isNumber = (value) => typeof value === 'number';
|
|
26
|
+
/**
|
|
27
|
+
* 记录的第二条律:**整条元素是纯 JSON 数据,其中任何一处的数都是有限数** —— 声明成员、判官不认识的自定义字段、嵌套的对象与数组一视同仁。
|
|
28
|
+
* 为什么:JSON 里超出双精度范围的数(`1e400`)解析成 `±Infinity`,写回时成 `null`;读得进、写不回的值留在记录里,别人一次无关的写之后条目还在、值却变了。
|
|
29
|
+
* 读法是包里的整树快照(`captureJson`,严归类:对象的自有串键 / 数组的下标是访问器或不可枚举、类实例、环 ⇒ 读不成纯数据 ⇒ 不是记录,getter 一次都不调),判在快照上:
|
|
30
|
+
* · 叶子只许 JSON 的值 —— 串、有限数、布尔、`null`(`bigint` / `symbol` / 函数写不回;`-0` 是有限数,写回成 `0`,与 `0` 是同一个 JSON 数);
|
|
31
|
+
* · 对象成员的值是 `undefined` ⇒ 当缺席(写回时这一键不在,与读它时同答);数组的洞与数组里的 `undefined` 写回成 `null` ⇒ 不是记录;
|
|
32
|
+
* · 数组上的非下标键不是成员(与校验器解析数组、`JSON.stringify` 同 —— 它们本来就不写回);
|
|
33
|
+
* · 共享的子树(同一只容器从两条路径可达)只走一次 —— 快照保留共享引用,按容器身份去重,遍历是线性的。
|
|
34
|
+
*/
|
|
35
|
+
function isFiniteJsonData(v) {
|
|
36
|
+
const copy = captureJson(v);
|
|
37
|
+
if (!copy.ok)
|
|
38
|
+
return false;
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
const stack = [copy.value];
|
|
41
|
+
while (stack.length > 0) {
|
|
42
|
+
const node = stack.pop();
|
|
43
|
+
if (node === null || typeof node === 'string' || typeof node === 'boolean')
|
|
44
|
+
continue;
|
|
45
|
+
if (typeof node === 'number') {
|
|
46
|
+
if (Number.isFinite(node))
|
|
47
|
+
continue;
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
// containers: shapes are asked of the seat (the snapshot's copies are plain objects / ordinary arrays)
|
|
51
|
+
if (isJsonArray(node)) {
|
|
52
|
+
if (seen.has(node))
|
|
53
|
+
continue;
|
|
54
|
+
seen.add(node);
|
|
55
|
+
// a hole stays a hole in the snapshot, an `undefined` element stays `undefined` — both are written back as `null`
|
|
56
|
+
for (let i = 0; i < node.length; i++) {
|
|
57
|
+
if (!(i in node) || node[i] === undefined)
|
|
58
|
+
return false;
|
|
59
|
+
stack.push(node[i]);
|
|
60
|
+
}
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (isPlainJsonObject(node)) {
|
|
64
|
+
if (seen.has(node))
|
|
65
|
+
continue;
|
|
66
|
+
seen.add(node);
|
|
67
|
+
// own enumerable data members only (the snapshot has no accessors, no inherited values); an `undefined` member reads as absent
|
|
68
|
+
for (const child of Object.values(node))
|
|
69
|
+
if (child !== undefined)
|
|
70
|
+
stack.push(child);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
return false; // bigint, symbol, undefined, anything else: not a value JSON writes back as itself
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
/** `SchedulerRecord` 除 `when` 外的每一只声明成员 —— **按型穷举**(型上多一只成员而这里没有它的行 ⇒ 编译红;`required` 由型的可选性定)。 */
|
|
78
|
+
const RECORD_MEMBERS = {
|
|
79
|
+
id: { required: true, holds: isText },
|
|
80
|
+
scope: { required: true, holds: isText },
|
|
81
|
+
principal: { required: false, holds: isText },
|
|
82
|
+
sessionId: { required: false, holds: isText },
|
|
83
|
+
prompt: { required: true, holds: isText },
|
|
84
|
+
label: { required: false, holds: isText },
|
|
85
|
+
createdMs: { required: true, holds: isNumber },
|
|
86
|
+
nextRunMs: { required: false, holds: isNumber },
|
|
87
|
+
lifetime: { required: false, holds: isText },
|
|
88
|
+
mode: { required: false, holds: isText },
|
|
89
|
+
};
|
|
90
|
+
/** `when` 每一臂的那一只成员与它的判 —— 按 `SchedulerWhen` 的臂穷举(多一臂而这里没有 ⇒ 编译红)。 */
|
|
91
|
+
const WHEN_MEMBER = {
|
|
92
|
+
cron: ['expr', isText],
|
|
93
|
+
at: ['atMs', isNumber],
|
|
94
|
+
delay: ['delaySec', isNumber],
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The ONE record judge, two rules: ① **the judge is the type** — every declared member ({@link RECORD_MEMBERS}, `when` by its arm {@link WHEN_MEMBER}) that is
|
|
98
|
+
* present holds its declared type (strings are strings, numbers are numbers), the required ones are present; a member written as `undefined` reads as absent;
|
|
99
|
+
* ② **the element is plain JSON data and every number anywhere in it is finite** ({@link isFiniteJsonData}: declared members, unknown fields and their nesting alike).
|
|
100
|
+
* Unknown fields are otherwise free and preserved. 35.0.0: before, only the required members' `typeof` — a record whose `lifetime` was `{}`, whose `createdMs`
|
|
101
|
+
* was `1e400`, or whose custom field nested a `1e400` passed, was read as the declared type, and its non-finite number turned into `null` on the next write.
|
|
102
|
+
*/
|
|
24
103
|
export function isSchedulerRecord(v) {
|
|
25
104
|
if (!isPlainJsonObject(v))
|
|
26
105
|
return false;
|
|
27
106
|
// a type guard, so every field is read STRICTLY from the record's own keys (own, enumerable, data — the kernel's `ownDeclaredValueOf`): an inherited field is absent
|
|
28
107
|
// (a polluted `Object.prototype.prompt` is not a prompt the record carries); an accessor / hidden field, or one that cannot be read ⇒ not a record — no getter is called,
|
|
29
108
|
// so what the caller reads from the record next is what was judged
|
|
30
|
-
const
|
|
109
|
+
const holds = (o, key, member) => {
|
|
31
110
|
const read = ownDeclaredValueOf(o, key);
|
|
32
|
-
|
|
111
|
+
if (!read.ok)
|
|
112
|
+
return false;
|
|
113
|
+
return read.value === undefined ? !member.required : member.holds(read.value);
|
|
33
114
|
};
|
|
34
|
-
|
|
115
|
+
for (const [key, member] of Object.entries(RECORD_MEMBERS))
|
|
116
|
+
if (!holds(v, key, member))
|
|
117
|
+
return false;
|
|
118
|
+
const w = ownDeclaredValueOf(v, 'when');
|
|
119
|
+
if (!w.ok || !isPlainJsonObject(w.value))
|
|
120
|
+
return false;
|
|
121
|
+
const kind = ownDeclaredValueOf(w.value, 'kind');
|
|
122
|
+
if (!kind.ok || typeof kind.value !== 'string')
|
|
35
123
|
return false;
|
|
36
|
-
const
|
|
37
|
-
if (!
|
|
124
|
+
const arm = ownRow(WHEN_MEMBER, kind.value);
|
|
125
|
+
if (arm === undefined || !holds(w.value, arm[0], { required: true, holds: arm[1] }))
|
|
38
126
|
return false;
|
|
39
|
-
|
|
40
|
-
if (kind === 'cron')
|
|
41
|
-
return typeof field(w, 'expr') === 'string';
|
|
42
|
-
if (kind === 'at')
|
|
43
|
-
return typeof field(w, 'atMs') === 'number';
|
|
44
|
-
if (kind === 'delay')
|
|
45
|
-
return typeof field(w, 'delaySec') === 'number';
|
|
46
|
-
return false;
|
|
127
|
+
return isFiniteJsonData(v);
|
|
47
128
|
}
|
|
48
|
-
/** 一条会话链上的记录过期多久算「永驻孤儿」:`lifetime: "session"` ∧ `sessionId`
|
|
129
|
+
/** 一条会话链上的记录过期多久算「永驻孤儿」:`lifetime: "session"` ∧ `sessionId` 是非空串 ∧ `nextRunMs` 在场(是数)且已过去这么久 ⇒ 读口丢弃并告警(7 天)。 */
|
|
49
130
|
export const STALE_SESSION_RECORD_MS = 7 * 24 * 60 * 60 * 1000;
|
|
50
131
|
/**
|
|
51
132
|
* Parse the durable store from its serialized form. FORWARD-COMPATIBLE: well-formed records keep ALL their fields (incl.
|
package/dist/settings-units.d.ts
CHANGED
|
@@ -92,6 +92,15 @@ export declare const SETTINGS_UNITS: {
|
|
|
92
92
|
readonly reader: "shell";
|
|
93
93
|
readonly sources: readonly ["userSettings"];
|
|
94
94
|
};
|
|
95
|
+
readonly autoMemoryEnabled: {
|
|
96
|
+
readonly path: readonly ["autoMemoryEnabled"];
|
|
97
|
+
readonly category: "autoMemory";
|
|
98
|
+
readonly reads: "member";
|
|
99
|
+
readonly member: "autoMemoryEnabled";
|
|
100
|
+
readonly reading: "boolean";
|
|
101
|
+
readonly reader: "engine";
|
|
102
|
+
readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
|
|
103
|
+
};
|
|
95
104
|
};
|
|
96
105
|
export type SettingsUnitName = keyof typeof SETTINGS_UNITS;
|
|
97
106
|
/** The comparator of one unit — or, for a `members` unit, of one DECLARED member of it: `whole` ⇒ the category's `tighten`;
|
package/dist/settings-units.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* Every resolver of a settings file (the shell reads it for each of its sources; a profile loader is a second projection) and every
|
|
6
6
|
* writer of one reads THIS table instead of keeping a key→category map, a value judge or a reader list of its own for these units.
|
|
7
7
|
* Unit names: the shell's established ten, then `semaUiLanguage` — the UI-language key, named by its key and placed by its declaration
|
|
8
|
-
* (`UI_LANGUAGE_SETTING` in `./ui-language`: the row's `path`, `category` and `sources` are read from there, not written twice)
|
|
9
|
-
*
|
|
8
|
+
* (`UI_LANGUAGE_SETTING` in `./ui-language`: the row's `path`, `category` and `sources` are read from there, not written twice) — and
|
|
9
|
+
* `autoMemoryEnabled`, the auto-memory switch, mapped to its `autoMemory` member row. The two permission-mode kill-switches map to
|
|
10
|
+
* their own `killSwitches` member rows (the table has no managed-only floor for them).
|
|
10
11
|
*
|
|
11
12
|
* Who reads a unit (`reader`, on every row; the closed set {@link SETTINGS_UNIT_READERS}):
|
|
12
13
|
* · `shell` — the value changes only the host's own interface and never reaches the engine, wherever the engine runs — so a writer
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
*
|
|
22
23
|
* Which settings sources carry a unit (`sources`, on every row; words of `SETTINGS_SOURCES`): a unit is read only from the sources its row
|
|
23
24
|
* lists — a value of the unit in any other source is not read (neither admitted nor refused: that source does not carry the key) — and inside
|
|
24
|
-
* them `layerAdmission(source, workspace, category, …)` answers as for every category. Every unit
|
|
25
|
+
* them `layerAdmission(source, workspace, category, …)` answers as for every category. Every unit except `semaUiLanguage` is carried by every source
|
|
25
26
|
* (their `sources` IS `SETTINGS_SOURCES`); `semaUiLanguage` only by `UI_LANGUAGE_SETTING.source` (the user's settings), read from there.
|
|
26
27
|
*
|
|
27
28
|
* NOT in this table: the two http-hook allowlist keys (`allowedHttpHookUrls` / `httpHookAllowedEnvVars`). They carry a merge contract
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
* How a unit is addressed (`reads`):
|
|
39
40
|
* · `whole` — the unit's value is one value under its category: compared by the category's `tighten`
|
|
40
41
|
* (the only thing a category's `tighten` answers — safety-merge-spec header);
|
|
41
|
-
* · `member` — the unit IS one declared member of its category (the two kill-switches): compared by that member's comparator;
|
|
42
|
+
* · `member` — the unit IS one declared member of its category (the two kill-switches and `autoMemoryEnabled`): compared by that member's comparator;
|
|
42
43
|
* · `members` — the unit is an object of declared members (`permissions`, `sandbox`): every question names ONE declared member,
|
|
43
44
|
* compared and read by that member's row ({@link memberTighten}; its value class `boolPole` / `list`). The unit's whole
|
|
44
45
|
* value and its undeclared members have no comparator and no reading here — asking is a RangeError.
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
* · `nonEmptyString` — a non-empty string;
|
|
54
55
|
* · `uiLanguage` — a word of `UI_LANGUAGE_VALUES`, exactly as written: no case folding, no locale-tag folding (`"zh-CN"`, `"EN"`, `" en"`
|
|
55
56
|
* are `unreadable`). The one judge is `readUiLanguage` (`./ui-language`); this reading delegates to it;
|
|
57
|
+
* · `boolean` — a boolean (`true` or `false`), strictly: no string spelling (`"disable"`, `"true"`, `"false"`) is rewritten;
|
|
56
58
|
* and a member's value class: `boolPole` ⇒ a boolean, `list` ⇒ the `stringList` reading.
|
|
57
59
|
* Everything else is `unreadable` — no default arm. Two laws for every unit: `undefined` and JSON `null` are `unreadable` (absence
|
|
58
60
|
* is not a value; "an absent landing spot takes the write" is the loader's business, before it calls the reader), and the reader
|
|
@@ -68,11 +70,11 @@
|
|
|
68
70
|
* it are already tables, and neither is carried by the reading (a reading has no `direction`: a `whole` unit has no direction source, so the field
|
|
69
71
|
* could only be optional and every consumer would still branch on its absence — and it would be a second reader of a member row's `direction`):
|
|
70
72
|
* the member's direction is `memberAdmission(category, member).direction`, and the category's failure direction is `SAFETY_MERGE_SPEC[category].fail`.
|
|
71
|
-
* For a member of a category whose `fail` is `closed` (today every category that declares members: `permissions`, `sandboxNetwork`, `killSwitches`):
|
|
73
|
+
* For a member of a category whose `fail` is `closed` (today every category that declares members: `permissions`, `sandboxNetwork`, `killSwitches`, `autoMemory`):
|
|
72
74
|
* · a `loosen` member — the caller MAY drop it (dropping grants less), loudly: it says which member of which layer was dropped and why;
|
|
73
75
|
* · a `tighten` member — the caller must NOT drop it and must NOT read it as absent: it keeps the member and answers on ITS surface with the
|
|
74
|
-
* strictest answer it has (the rules surface refuses every call it cannot place; a kill-switch counts as ON; a sandbox switch
|
|
75
|
-
* pole), because dropping a tighten member reads a restriction its author wrote — in a form the contract cannot place — as no restriction at all;
|
|
76
|
+
* strictest answer it has (the rules surface refuses every call it cannot place; a kill-switch counts as ON; a sandbox switch or `autoMemoryEnabled`
|
|
77
|
+
* takes its strict pole), because dropping a tighten member reads a restriction its author wrote — in a form the contract cannot place — as no restriction at all;
|
|
76
78
|
* the contract cannot tell what it was meant to forbid, and the strictest answer is the only one that cannot be looser than what the author meant.
|
|
77
79
|
* The package enforces nothing here (the surfaces are the consumers'); what it pins is that both inputs exist for every such member and that every
|
|
78
80
|
* out-of-domain value reads `unreadable` without throwing. Not covered, and not settled here: the `whole` units (`permissionMode`, `additionalDirectories`,
|
|
@@ -104,6 +106,7 @@ export const SETTINGS_UNITS = deepFreeze({
|
|
|
104
106
|
outputStyle: { path: ["outputStyle"], category: "ui", reads: "whole", reading: "nonEmptyString", reader: "engine", sources: SETTINGS_SOURCES },
|
|
105
107
|
// the key, its category and the one source that carries it are the declaration's (`UI_LANGUAGE_SETTING`); the computed key keeps the literal type
|
|
106
108
|
[UI_LANGUAGE_SETTING.key]: { path: [UI_LANGUAGE_SETTING.key], category: UI_LANGUAGE_SETTING.category, reads: "whole", reading: "uiLanguage", reader: "shell", sources: [UI_LANGUAGE_SETTING.source] },
|
|
109
|
+
autoMemoryEnabled: { path: ["autoMemoryEnabled"], category: "autoMemory", reads: "member", member: "autoMemoryEnabled", reading: "boolean", reader: "engine", sources: SETTINGS_SOURCES },
|
|
107
110
|
});
|
|
108
111
|
/** The one place a unit + optional member resolves to what is being asked about — the row and its comparator. Fail-closed
|
|
109
112
|
* and loud on every misaddressing: an unknown unit (own-property lookup — `"__proto__"` is unknown, not Object.prototype),
|
|
@@ -204,6 +207,8 @@ function shapedReading(unit, row, rule, raw) {
|
|
|
204
207
|
const layer = readUiLanguage(raw);
|
|
205
208
|
return layer.ok && layer.value !== undefined ? { ok: true, value: raw } : UNREADABLE;
|
|
206
209
|
}
|
|
210
|
+
case "boolean":
|
|
211
|
+
return typeof raw === "boolean" ? { ok: true, value: raw } : UNREADABLE;
|
|
207
212
|
default: {
|
|
208
213
|
const unknown = row.reading;
|
|
209
214
|
throw new RangeError(`SETTINGS_UNITS: unit '${unit}' has an unknown reading '${String(unknown)}'`);
|