@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.
Files changed (76) hide show
  1. package/CHANGELOG.md +648 -0
  2. package/README.md +86 -39
  3. package/conformance/VERSION +1 -1
  4. package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/expected.json +101 -0
  5. package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/input.json +28 -0
  6. package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/meta.json +6 -0
  7. package/conformance/cases/c101-a2a-inside-incomplete-dropped/expected.json +113 -0
  8. package/conformance/cases/c101-a2a-inside-incomplete-dropped/input.json +38 -0
  9. package/conformance/cases/c101-a2a-inside-incomplete-dropped/meta.json +6 -0
  10. package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/expected.json +85 -0
  11. package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/input.json +34 -0
  12. package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/meta.json +6 -0
  13. package/conformance/cases/c103-mcp-caller-meta-declared/expected.json +106 -0
  14. package/conformance/cases/c103-mcp-caller-meta-declared/input.json +28 -0
  15. package/conformance/cases/c103-mcp-caller-meta-declared/meta.json +6 -0
  16. package/conformance/cases/c98-a2a-registration-keys-carried/expected.json +163 -0
  17. package/conformance/cases/c98-a2a-registration-keys-carried/input.json +42 -0
  18. package/conformance/cases/c98-a2a-registration-keys-carried/meta.json +6 -0
  19. package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/expected.json +100 -0
  20. package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/input.json +23 -0
  21. package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/meta.json +6 -0
  22. package/dist/a2a-peer-identity.d.ts +116 -0
  23. package/dist/a2a-peer-identity.js +182 -0
  24. package/dist/api/credentials.d.ts +94 -14
  25. package/dist/api/credentials.js +33 -8
  26. package/dist/atomic-write.d.ts +9 -3
  27. package/dist/atomic-write.js +14 -6
  28. package/dist/catalog-manages.js +2 -2
  29. package/dist/config-d-file.d.ts +0 -3
  30. package/dist/config-d-file.js +1 -6
  31. package/dist/config-dir-migration.js +0 -1
  32. package/dist/config-document-refusal.d.ts +1 -1
  33. package/dist/config-fns.d.ts +21 -8
  34. package/dist/config-fns.js +16 -3
  35. package/dist/config-root-documents.d.ts +3 -54
  36. package/dist/config-root-documents.js +24 -21
  37. package/dist/config-root-node.d.ts +2 -96
  38. package/dist/config-root-node.js +15 -163
  39. package/dist/conformance/warnings.js +1 -1
  40. package/dist/conformance/web-admin-credential-lock.js +3 -2
  41. package/dist/cross-session.d.ts +2 -2
  42. package/dist/env-model-table.d.ts +3 -3
  43. package/dist/env-model-table.js +5 -5
  44. package/dist/fleet.d.ts +5 -5
  45. package/dist/index.d.ts +3 -1
  46. package/dist/index.js +3 -1
  47. package/dist/mcp-request-entry.d.ts +19 -0
  48. package/dist/mcp-request-entry.js +15 -13
  49. package/dist/migration-receipt.d.ts +9 -11
  50. package/dist/migration-receipt.js +4 -5
  51. package/dist/node.d.ts +3 -3
  52. package/dist/node.js +3 -3
  53. package/dist/one-time-migrations.d.ts +3 -4
  54. package/dist/one-time-migrations.js +3 -28
  55. package/dist/plugin-id-segment.d.ts +15 -0
  56. package/dist/plugin-id-segment.js +15 -0
  57. package/dist/plugin-settings.d.ts +61 -0
  58. package/dist/plugin-settings.js +111 -0
  59. package/dist/retired-envs.js +5 -0
  60. package/dist/safety-merge-spec.d.ts +23 -2
  61. package/dist/safety-merge-spec.js +13 -0
  62. package/dist/scheduler-store-node.d.ts +14 -11
  63. package/dist/scheduler-store-node.js +22 -34
  64. package/dist/scheduler-store.d.ts +21 -6
  65. package/dist/scheduler-store.js +100 -19
  66. package/dist/settings-units.d.ts +9 -0
  67. package/dist/settings-units.js +12 -7
  68. package/dist/types.d.ts +53 -4
  69. package/dist/types.js +79 -4
  70. package/docs/API-SURFACE.md +51 -11
  71. package/docs/CC-DIVERGENCE.md +2 -1
  72. package/docs/CONFORMANCE.md +4 -4
  73. package/docs/CONSUMER-INTEGRATION.md +158 -13
  74. package/llms-full.txt +47 -18
  75. package/llms.txt +18 -7
  76. package/package.json +7 -3
@@ -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. Optional
14
- * fields are additive — a future field is a non-breaking extension (readers preserve unknown fields on round-trip).
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
- /** Structural validation of one record (required fields + a well-formed `when`). Unknown fields are allowed. */
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` 在场 ∧ `nextRunMs` 已过去这么久 ⇒ 读口丢弃并告警(7 天)。 */
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` 在场)而 `nextRunMs` 已过去 ≥ {@link STALE_SESSION_RECORD_MS}:
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;
@@ -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 only the required shape and
12
- * PRESERVES unknown fields, so a newer writer can add fields without an older reader dropping them on
13
- * round-trip. New optional `SchedulerRecord` fields are additive (no breaking change).
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
- /** Structural validation of one record (required fields + a well-formed `when`). Unknown fields are allowed. */
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 field = (o, key) => {
109
+ const holds = (o, key, member) => {
31
110
  const read = ownDeclaredValueOf(o, key);
32
- return read.ok ? read.value : undefined;
111
+ if (!read.ok)
112
+ return false;
113
+ return read.value === undefined ? !member.required : member.holds(read.value);
33
114
  };
34
- if (typeof field(v, 'id') !== 'string' || typeof field(v, 'scope') !== 'string' || typeof field(v, 'prompt') !== 'string' || typeof field(v, 'createdMs') !== 'number')
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 w = field(v, 'when');
37
- if (!isPlainJsonObject(w))
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
- const kind = field(w, 'kind');
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` 在场 ∧ `nextRunMs` 已过去这么久 ⇒ 读口丢弃并告警(7 天)。 */
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.
@@ -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`;
@@ -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). The two
9
- * permission-mode kill-switches map to their own `killSwitches` member rows (the table has no managed-only floor for them).
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 the shell established is carried by every source
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 takes its strict
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)}'`);
package/dist/types.d.ts CHANGED
@@ -17,6 +17,7 @@
17
17
  * `ENV_NAME` schema (regex) on every `*Env` field — a pasted secret value is rejected, not just discouraged.
18
18
  */
19
19
  import { z } from "zod";
20
+ import { PLUGIN_ID_SEGMENT_REGEX } from "./plugin-id-segment.js";
20
21
  /** A private-key PEM header (`-----BEGIN [RSA |EC |OPENSSH |ENCRYPTED ]PRIVATE KEY`), unanchored — the ONE definition
21
22
  * of that shape, read ANYWHERE in a string by BOTH sides of the one scanner: the validation detector {@link containsSecretToken}
22
23
  * (`scanForSecret`, 10.0.0) and the display redactor `redactSecrets` (config-fns) — on the same normalized forms since 11.0.0. {@link SECRET_LITERAL_RE} is also composed from it (anchored, as one of its branches — the exported per-token
@@ -844,10 +845,16 @@ export type EntitlementRuntimeCaps = z.output<z.ZodObject<typeof RUNTIME_CAP_FIE
844
845
  * without an entry is a COMPILE error (no silent wrong-direction merge) — so its keys are also the cap list: iterate
845
846
  * `Object.keys(RUNTIME_CAP_STRICT)` to visit every live cap. */
846
847
  export declare const RUNTIME_CAP_STRICT: Readonly<Record<keyof EntitlementRuntimeCaps, boolean>>;
848
+ /** The bounds of an entitlement tier's free-form fields —— the ONE source of these numbers: {@link EntitlementTier} reads them, and so do
849
+ * console forms and API routes (import this, never copy a number). */
850
+ export declare const ENTITLEMENT_TIER_LIMITS: {
851
+ readonly displayNameMax: 200;
852
+ };
847
853
  /** A named entitlement bundle (a `tier`, or a composable `role`). Bind a `roster` to inherit its model/skill/mcp
848
854
  * visibility for free; explicit allowlists intersect on top. Edit a tier once → re-prices everyone on it. */
849
855
  export declare const EntitlementTier: z.ZodObject<{
850
856
  id: z.ZodString;
857
+ displayName: z.ZodOptional<z.ZodString>;
851
858
  roster: z.ZodOptional<z.ZodString>;
852
859
  models: z.ZodOptional<z.ZodArray<z.ZodString>>;
853
860
  visibleSkills: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -996,6 +1003,7 @@ export declare const EntitlementConfig: z.ZodObject<{
996
1003
  }, z.core.$strip>>;
997
1004
  tiers: z.ZodPrefault<z.ZodArray<z.ZodObject<{
998
1005
  id: z.ZodString;
1006
+ displayName: z.ZodOptional<z.ZodString>;
999
1007
  roster: z.ZodOptional<z.ZodString>;
1000
1008
  models: z.ZodOptional<z.ZodArray<z.ZodString>>;
1001
1009
  visibleSkills: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -1322,6 +1330,8 @@ export declare const ProjectRegistration: z.ZodObject<{
1322
1330
  color: z.ZodOptional<z.ZodString>;
1323
1331
  }, z.core.$strip>;
1324
1332
  export type ProjectRegistration = z.infer<typeof ProjectRegistration>;
1333
+ /** 项目登记簿。`projects` 记录的**条目序是契约事实**:它就是登记簿的展示序,唯一来源 = 文档里的条目次序;写者必须保序({@link applyProjectPatch} 已保序)。
1334
+ * 已知分工:今天的内容版本(`configDVersionOf`(`./config-d-file`))按排序后的键计算,只调换条目次序不会换版本号;今天内容版本看不见条目序;改不改另行设计(改它会让每一份配置文档的内容版本都换一次)。 */
1325
1335
  export declare const ProjectsConfig: z.ZodObject<{
1326
1336
  projects: z.ZodPrefault<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodObject<{
1327
1337
  displayName: z.ZodString;
@@ -2103,6 +2113,7 @@ export declare const McpServerSpec: z.ZodObject<{
2103
2113
  }>>;
2104
2114
  sessionMetaKey: z.ZodOptional<z.ZodUnknown>;
2105
2115
  startupTimeoutMs: z.ZodOptional<z.ZodUnknown>;
2116
+ callerMeta: z.ZodOptional<z.ZodBoolean>;
2106
2117
  source: z.ZodOptional<z.ZodUnknown>;
2107
2118
  toolFaces: z.ZodOptional<z.ZodUnknown>;
2108
2119
  toolAxes: z.ZodOptional<z.ZodUnknown>;
@@ -2155,6 +2166,7 @@ export declare const McpConfig: z.ZodObject<{
2155
2166
  }>>;
2156
2167
  sessionMetaKey: z.ZodOptional<z.ZodUnknown>;
2157
2168
  startupTimeoutMs: z.ZodOptional<z.ZodUnknown>;
2169
+ callerMeta: z.ZodOptional<z.ZodBoolean>;
2158
2170
  source: z.ZodOptional<z.ZodUnknown>;
2159
2171
  toolFaces: z.ZodOptional<z.ZodUnknown>;
2160
2172
  toolAxes: z.ZodOptional<z.ZodUnknown>;
@@ -2172,9 +2184,20 @@ export declare const A2aPeerSpec: z.ZodObject<{
2172
2184
  allowSkills: z.ZodOptional<z.ZodArray<z.ZodString>>;
2173
2185
  scenarios: z.ZodPrefault<z.ZodArray<z.ZodString>>;
2174
2186
  enabled: z.ZodDefault<z.ZodBoolean>;
2187
+ id: z.ZodOptional<z.ZodString>;
2188
+ boundary: z.ZodOptional<z.ZodEnum<{
2189
+ inside: "inside";
2190
+ outside: "outside";
2191
+ }>>;
2192
+ fingerprint: z.ZodOptional<z.ZodString>;
2193
+ ownerTeam: z.ZodOptional<z.ZodString>;
2194
+ displayName: z.ZodOptional<z.ZodString>;
2195
+ askEverySkills: z.ZodOptional<z.ZodArray<z.ZodString>>;
2196
+ preApprovedFor: z.ZodOptional<z.ZodString>;
2175
2197
  }, z.core.$strip>;
2176
2198
  export type A2aPeerSpec = z.infer<typeof A2aPeerSpec>;
2177
- /** `a2a` 域:常驻出站 A2A 对端名册。空名册 = 不拨任何对端;文档缺席(店 / `config.d`)读作空名册。对端名唯一(重名拒,同 mcp)。
2199
+ /** `a2a` 域:常驻出站 A2A 对端名册。空名册 = 不拨任何对端;文档缺席(店 / `config.d`)读作空名册。对端名唯一(重名拒,同 mcp);条目编号 `id`
2200
+ * 在场的也唯一(同一道域判)。
2178
2201
  * 线上(`GET /effective`)缺席不是空名册:读口不补,{@link EffectiveWire} 上 `a2a` 缺席 = 生产方没发这个域(它的契约早于本域),见 {@link WIRE_CARRIED_DOMAINS}。 */
2179
2202
  export declare const A2aConfig: z.ZodObject<{
2180
2203
  peers: z.ZodPrefault<z.ZodArray<z.ZodObject<{
@@ -2186,6 +2209,16 @@ export declare const A2aConfig: z.ZodObject<{
2186
2209
  allowSkills: z.ZodOptional<z.ZodArray<z.ZodString>>;
2187
2210
  scenarios: z.ZodPrefault<z.ZodArray<z.ZodString>>;
2188
2211
  enabled: z.ZodDefault<z.ZodBoolean>;
2212
+ id: z.ZodOptional<z.ZodString>;
2213
+ boundary: z.ZodOptional<z.ZodEnum<{
2214
+ inside: "inside";
2215
+ outside: "outside";
2216
+ }>>;
2217
+ fingerprint: z.ZodOptional<z.ZodString>;
2218
+ ownerTeam: z.ZodOptional<z.ZodString>;
2219
+ displayName: z.ZodOptional<z.ZodString>;
2220
+ askEverySkills: z.ZodOptional<z.ZodArray<z.ZodString>>;
2221
+ preApprovedFor: z.ZodOptional<z.ZodString>;
2189
2222
  }, z.core.$strip>>>;
2190
2223
  }, z.core.$strip>;
2191
2224
  export type A2aConfig = z.infer<typeof A2aConfig>;
@@ -2201,6 +2234,10 @@ export declare const PLUGIN_ORIGIN: z.ZodString;
2201
2234
  /** A full 40-hex git commit SHA — the ONLY pin form the supply-side treats as 钉死 (a branch/tag `version`
2202
2235
  * is a moving ref; only a commit pin makes the materialized bytes reproducible). */
2203
2236
  export declare const GIT_COMMIT_SHA: z.ZodString;
2237
+ /** The grammar of ONE segment of a plugin id (`<name>@<marketplace>`): a letter or digit first, then letters / digits / `.` / `_` / `-`, case-insensitive.
2238
+ * Re-exported here under its own name; the ONE definition is the zero-import leaf `./plugin-id-segment` — the `<name>` half (`PluginSpec.name`), the
2239
+ * `<marketplace>` half (the marketplace arm of `PluginSource`) and the id reader `readPluginId` (`./plugin-settings`) all read that same object. */
2240
+ export { PLUGIN_ID_SEGMENT_REGEX };
2204
2241
  /** WHERE a plugin comes from — two forms (产品拍板: git URL 与 marketplace ref 两形态):
2205
2242
  * - `git`: the plugin lives at a git URL directly (repo root = plugin root).
2206
2243
  * - `marketplace`: the plugin is `<name>@<marketplace>` in a plugin marketplace; `marketplace` is the
@@ -2880,6 +2917,7 @@ export declare const DOMAIN_SCHEMAS: {
2880
2917
  }>>;
2881
2918
  sessionMetaKey: z.ZodOptional<z.ZodUnknown>;
2882
2919
  startupTimeoutMs: z.ZodOptional<z.ZodUnknown>;
2920
+ callerMeta: z.ZodOptional<z.ZodBoolean>;
2883
2921
  source: z.ZodOptional<z.ZodUnknown>;
2884
2922
  toolFaces: z.ZodOptional<z.ZodUnknown>;
2885
2923
  toolAxes: z.ZodOptional<z.ZodUnknown>;
@@ -3180,6 +3218,7 @@ export declare const DOMAIN_SCHEMAS: {
3180
3218
  }, z.core.$strip>>;
3181
3219
  tiers: z.ZodPrefault<z.ZodArray<z.ZodObject<{
3182
3220
  id: z.ZodString;
3221
+ displayName: z.ZodOptional<z.ZodString>;
3183
3222
  roster: z.ZodOptional<z.ZodString>;
3184
3223
  models: z.ZodOptional<z.ZodArray<z.ZodString>>;
3185
3224
  visibleSkills: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -3508,6 +3547,16 @@ export declare const DOMAIN_SCHEMAS: {
3508
3547
  allowSkills: z.ZodOptional<z.ZodArray<z.ZodString>>;
3509
3548
  scenarios: z.ZodPrefault<z.ZodArray<z.ZodString>>;
3510
3549
  enabled: z.ZodDefault<z.ZodBoolean>;
3550
+ id: z.ZodOptional<z.ZodString>;
3551
+ boundary: z.ZodOptional<z.ZodEnum<{
3552
+ inside: "inside";
3553
+ outside: "outside";
3554
+ }>>;
3555
+ fingerprint: z.ZodOptional<z.ZodString>;
3556
+ ownerTeam: z.ZodOptional<z.ZodString>;
3557
+ displayName: z.ZodOptional<z.ZodString>;
3558
+ askEverySkills: z.ZodOptional<z.ZodArray<z.ZodString>>;
3559
+ preApprovedFor: z.ZodOptional<z.ZodString>;
3511
3560
  }, z.core.$strip>>>;
3512
3561
  }, z.core.$strip>;
3513
3562
  };
@@ -3576,9 +3625,9 @@ export declare const SettingSource: z.ZodDiscriminatedUnion<[z.ZodObject<{
3576
3625
  }, z.core.$strip>, z.ZodObject<{
3577
3626
  axis: z.ZodLiteral<"principal">;
3578
3627
  via: z.ZodEnum<{
3579
- role: "role";
3580
3628
  tier: "tier";
3581
3629
  override: "override";
3630
+ role: "role";
3582
3631
  "worker-base": "worker-base";
3583
3632
  }>;
3584
3633
  id: z.ZodString;
@@ -3608,9 +3657,9 @@ export declare const EffectiveKey: z.ZodObject<{
3608
3657
  }, z.core.$strip>, z.ZodObject<{
3609
3658
  axis: z.ZodLiteral<"principal">;
3610
3659
  via: z.ZodEnum<{
3611
- role: "role";
3612
3660
  tier: "tier";
3613
3661
  override: "override";
3662
+ role: "role";
3614
3663
  "worker-base": "worker-base";
3615
3664
  }>;
3616
3665
  id: z.ZodString;
@@ -3642,9 +3691,9 @@ export declare const EffectiveKey: z.ZodObject<{
3642
3691
  }, z.core.$strip>, z.ZodObject<{
3643
3692
  axis: z.ZodLiteral<"principal">;
3644
3693
  via: z.ZodEnum<{
3645
- role: "role";
3646
3694
  tier: "tier";
3647
3695
  override: "override";
3696
+ role: "role";
3648
3697
  "worker-base": "worker-base";
3649
3698
  }>;
3650
3699
  id: z.ZodString;