@sema-agent/settings-schema 33.0.0 → 34.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 (50) hide show
  1. package/CHANGELOG.md +525 -0
  2. package/README.md +151 -17
  3. package/conformance/VERSION +1 -1
  4. package/dist/api/wire-scalars.d.ts +3 -2
  5. package/dist/api/wire-scalars.js +3 -2
  6. package/dist/atomic-write.d.ts +59 -0
  7. package/dist/atomic-write.js +303 -1
  8. package/dist/cli.d.ts +6 -3
  9. package/dist/cli.js +16 -4
  10. package/dist/config-dir-migration.d.ts +4 -3
  11. package/dist/config-dir-migration.js +36 -21
  12. package/dist/config-fns.d.ts +60 -14
  13. package/dist/config-fns.js +48 -13
  14. package/dist/conformance/index.d.ts +1 -0
  15. package/dist/conformance/index.js +2 -0
  16. package/dist/conformance/warnings.d.ts +1 -1
  17. package/dist/conformance/warnings.js +3 -3
  18. package/dist/conformance/web-admin-credential-lock.d.ts +17 -0
  19. package/dist/conformance/web-admin-credential-lock.js +346 -0
  20. package/dist/cross-session.d.ts +2 -2
  21. package/dist/declared-capture.js +1 -1
  22. package/dist/fleet.d.ts +125 -7
  23. package/dist/fleet.js +138 -3
  24. package/dist/hooks-config.d.ts +12 -4
  25. package/dist/hooks-config.js +28 -11
  26. package/dist/index.js +2 -2
  27. package/dist/local-load.d.ts +66 -1
  28. package/dist/local-load.js +123 -39
  29. package/dist/mcp-request-entry.d.ts +24 -5
  30. package/dist/mcp-request-entry.js +57 -17
  31. package/dist/node.d.ts +1 -0
  32. package/dist/node.js +2 -0
  33. package/dist/read-sentences.d.ts +16 -4
  34. package/dist/read-sentences.js +34 -12
  35. package/dist/safety-merge-spec.d.ts +5 -5
  36. package/dist/safety-merge-spec.js +5 -3
  37. package/dist/settings-units.d.ts +35 -1
  38. package/dist/settings-units.js +51 -16
  39. package/dist/types.d.ts +9 -9
  40. package/dist/types.js +27 -8
  41. package/dist/ui-language.d.ts +3 -1
  42. package/dist/ui-language.js +3 -1
  43. package/dist/web-admin-credential.d.ts +14 -1
  44. package/dist/web-admin-credential.js +15 -1
  45. package/docs/API-SURFACE.md +52 -5
  46. package/docs/CONFORMANCE.md +19 -2
  47. package/docs/CONSUMER-INTEGRATION.md +140 -11
  48. package/llms-full.txt +40 -10
  49. package/llms.txt +16 -7
  50. package/package.json +1 -1
@@ -5,9 +5,9 @@
5
5
  * author is settings-core, web-admin maintains the formalized artifact here (this package), the axis VALUE domains
6
6
  * are core's (@sema-agent/core SAFETY_AXIS_VOCABULARY — validated by a dev-only conformance test, never a runtime
7
7
  * import). The settings-document UNIT table — which keys of a settings file carry a merge contract, where each sits,
8
- * which category below it maps into, and how its raw value reads — is published by this package too, as
8
+ * which category below it maps into, how its raw value reads, and who reads it — is published by this package too, as
9
9
  * `SETTINGS_UNITS` (`./settings-units.ts`, 14.6.0): a consumer reads it instead of keeping a key→category map of its
10
- * own for those ten units. Not every row here has a unit: for example the http-hook allowlist keys (`./http-hook-allowlists` keys and
10
+ * own for those units. Not every row here has a unit: for example the http-hook allowlist keys (`./http-hook-allowlists` keys and
11
11
  * reads them itself, with its own malformed-value reading) and the `webSearch` section (30.1.0; its key is published by
12
12
  * `./web-search-section` as `WEB_SEARCH_SECTION_KEYS`, and this package has no reading of its shape) — see the `./settings-units`
13
13
  * header. THIS file is the category spec every unit cites — no second copy of the law.
@@ -186,8 +186,8 @@ export interface ResolvedMemberAdmission {
186
186
  /** WHERE the category is enforced (STRENGTH) — MUST stay in lockstep with `EffectiveKey.enforcement` (types.ts).
187
187
  * gate=data-plane engine, server=control-plane/TOB boundary, resolver=merger correctness, client=UI only. */
188
188
  export declare const SpecEnforcement: z.ZodEnum<{
189
- gate: "gate";
190
189
  server: "server";
190
+ gate: "gate";
191
191
  resolver: "resolver";
192
192
  client: "client";
193
193
  }>;
@@ -294,8 +294,8 @@ export declare const MergeCategorySpec: z.ZodObject<{
294
294
  rule: z.ZodLiteral<"numericLower">;
295
295
  }, z.core.$strip>], "rule">;
296
296
  enforcement: z.ZodEnum<{
297
- gate: "gate";
298
297
  server: "server";
298
+ gate: "gate";
299
299
  resolver: "resolver";
300
300
  client: "client";
301
301
  }>;
@@ -607,7 +607,7 @@ export declare const SAFETY_MERGE_SPEC: {
607
607
  };
608
608
  readonly enforcement: "client";
609
609
  readonly fail: "open";
610
- readonly seam: "shell-only (theme/keybindings/statusLine) — never touches the engine";
610
+ readonly seam: "host-written preferences (theme / keybindings / statusLine / output style / UI language) — whether a key reaches the engine is its SETTINGS_UNITS row's `reader`, not this row";
611
611
  };
612
612
  readonly org: {
613
613
  readonly mergeShape: "replace";
@@ -5,9 +5,9 @@
5
5
  * author is settings-core, web-admin maintains the formalized artifact here (this package), the axis VALUE domains
6
6
  * are core's (@sema-agent/core SAFETY_AXIS_VOCABULARY — validated by a dev-only conformance test, never a runtime
7
7
  * import). The settings-document UNIT table — which keys of a settings file carry a merge contract, where each sits,
8
- * which category below it maps into, and how its raw value reads — is published by this package too, as
8
+ * which category below it maps into, how its raw value reads, and who reads it — is published by this package too, as
9
9
  * `SETTINGS_UNITS` (`./settings-units.ts`, 14.6.0): a consumer reads it instead of keeping a key→category map of its
10
- * own for those ten units. Not every row here has a unit: for example the http-hook allowlist keys (`./http-hook-allowlists` keys and
10
+ * own for those units. Not every row here has a unit: for example the http-hook allowlist keys (`./http-hook-allowlists` keys and
11
11
  * reads them itself, with its own malformed-value reading) and the `webSearch` section (30.1.0; its key is published by
12
12
  * `./web-search-section` as `WEB_SEARCH_SECTION_KEYS`, and this package has no reading of its shape) — see the `./settings-units`
13
13
  * header. THIS file is the category spec every unit cites — no second copy of the law.
@@ -436,7 +436,9 @@ export const SAFETY_MERGE_SPEC = deepFreeze({
436
436
  envSecret: { mergeShape: "replace", minTrust: "global", tighten: { rule: "none" }, enforcement: "resolver", fail: "closed", seam: "§7 secret-ref resolution" },
437
437
  memoryScopes: { mergeShape: "concat", minTrust: "global", tighten: { rule: "none" }, enforcement: "client", fail: "open", seam: "MemoryEngine" },
438
438
  autoCompaction: { mergeShape: "replace", minTrust: "session", tighten: { rule: "none" }, enforcement: "client", fail: "open", seam: "compaction config" },
439
- ui: { mergeShape: "replace", minTrust: "local", tighten: { rule: "none" }, enforcement: "client", fail: "open", seam: "shell-only (theme/keybindings/statusLine) — never touches the engine" },
439
+ // Display string only. Whether a key of this category reaches the engine is that key's fact, not the category's (`outputStyle` is folded into
440
+ // the engine's system prompt, `semaUiLanguage` never leaves the host) — it is the `reader` of the key's SETTINGS_UNITS row, and the seam points there.
441
+ ui: { mergeShape: "replace", minTrust: "local", tighten: { rule: "none" }, enforcement: "client", fail: "open", seam: "host-written preferences (theme / keybindings / statusLine / output style / UI language) — whether a key reaches the engine is its SETTINGS_UNITS row's `reader`, not this row" },
440
442
  org: { mergeShape: "replace", minTrust: "managed", tighten: { rule: "none" }, enforcement: "server", fail: "closed", seam: "web-admin → governanceBaseline (SSO/SCIM/audit/budget, TOB-only)" },
441
443
  // 13.0.0 (U3 [10538]) — the http hook allowlists `allowedHttpHookUrls` / `httpHookAllowedEnvVars`. Every ADMITTED layer's list must
442
444
  // pass (layers INTERSECT: a lower layer can only narrow, never add a URL the managed list lacks — CC concatenates, which lets it);
@@ -1,27 +1,38 @@
1
1
  import { type TightenRule } from "./safety-merge-spec.js";
2
- /** The settings-document units (see the file header). `path` is the unit's place in a settings document. */
2
+ /** Who reads a unit — the closed set of the `reader` word every unit row carries (the file header defines each word). Declaration order is not a rank. */
3
+ export declare const SETTINGS_UNIT_READERS: readonly ["shell", "engine"];
4
+ export type SettingsUnitReader = (typeof SETTINGS_UNIT_READERS)[number];
5
+ /** The settings-document units (see the file header). `path` is the unit's place in a settings document; `reader` is who reads it; `sources` are the settings sources that carry it. */
3
6
  export declare const SETTINGS_UNITS: {
4
7
  readonly permissions: {
5
8
  readonly path: readonly ["permissions"];
6
9
  readonly category: "permissions";
7
10
  readonly reads: "members";
11
+ readonly reader: "engine";
12
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
8
13
  };
9
14
  readonly permissionMode: {
10
15
  readonly path: readonly ["permissions", "defaultMode"];
11
16
  readonly category: "permissionMode";
12
17
  readonly reads: "whole";
13
18
  readonly reading: "permissionMode";
19
+ readonly reader: "engine";
20
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
14
21
  };
15
22
  readonly additionalDirectories: {
16
23
  readonly path: readonly ["permissions", "additionalDirectories"];
17
24
  readonly category: "sandboxNetwork";
18
25
  readonly reads: "whole";
19
26
  readonly reading: "stringList";
27
+ readonly reader: "engine";
28
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
20
29
  };
21
30
  readonly sandbox: {
22
31
  readonly path: readonly ["sandbox"];
23
32
  readonly category: "sandboxNetwork";
24
33
  readonly reads: "members";
34
+ readonly reader: "engine";
35
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
25
36
  };
26
37
  readonly disableBypassPermissionsMode: {
27
38
  readonly path: readonly ["permissions", "disableBypassPermissionsMode"];
@@ -29,6 +40,8 @@ export declare const SETTINGS_UNITS: {
29
40
  readonly reads: "member";
30
41
  readonly member: "disableBypassPermissionsMode";
31
42
  readonly reading: "killSwitch";
43
+ readonly reader: "engine";
44
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
32
45
  };
33
46
  readonly disableAutoMode: {
34
47
  readonly path: readonly ["permissions", "disableAutoMode"];
@@ -36,30 +49,48 @@ export declare const SETTINGS_UNITS: {
36
49
  readonly reads: "member";
37
50
  readonly member: "disableAutoMode";
38
51
  readonly reading: "killSwitch";
52
+ readonly reader: "engine";
53
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
39
54
  };
40
55
  readonly hooks: {
41
56
  readonly path: readonly ["hooks"];
42
57
  readonly category: "hooks";
43
58
  readonly reads: "whole";
44
59
  readonly reading: "hooks";
60
+ readonly reader: "engine";
61
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
45
62
  };
46
63
  readonly env: {
47
64
  readonly path: readonly ["env"];
48
65
  readonly category: "env";
49
66
  readonly reads: "whole";
50
67
  readonly reading: "envMap";
68
+ readonly reader: "engine";
69
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
51
70
  };
52
71
  readonly model: {
53
72
  readonly path: readonly ["model"];
54
73
  readonly category: "model";
55
74
  readonly reads: "whole";
56
75
  readonly reading: "nonEmptyString";
76
+ readonly reader: "engine";
77
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
57
78
  };
58
79
  readonly outputStyle: {
59
80
  readonly path: readonly ["outputStyle"];
60
81
  readonly category: "ui";
61
82
  readonly reads: "whole";
62
83
  readonly reading: "nonEmptyString";
84
+ readonly reader: "engine";
85
+ readonly sources: readonly ["userSettings", "projectSettings", "localSettings", "flagSettings", "policySettings", "foreignProjectSettings"];
86
+ };
87
+ readonly semaUiLanguage: {
88
+ readonly path: readonly ["semaUiLanguage"];
89
+ readonly category: "ui";
90
+ readonly reads: "whole";
91
+ readonly reading: "uiLanguage";
92
+ readonly reader: "shell";
93
+ readonly sources: readonly ["userSettings"];
63
94
  };
64
95
  };
65
96
  export type SettingsUnitName = keyof typeof SETTINGS_UNITS;
@@ -75,6 +106,9 @@ export declare function unitTighten(unit: SettingsUnitName, member?: string): Ti
75
106
  * are `"manual"` ⇒ `"default"` (permissionMode) and `"disable"` ⇒ `true` (kill-switches); `"bypassPermissions"` is `launch_only`.
76
107
  * The last step of every reading is the unit comparator's own domain: whatever reads, compares (file header).
77
108
  * Addressing is {@link unitTighten}'s (same RangeErrors: a `members` unit needs a declared member, …).
109
+ * A WRITER judges the value it is about to write with this same call, and reads the written layer back with it: the refusal word is the reading's
110
+ * `reason` (a UI language outside its closed set ⇒ `unreadable`), so a host's inbound gate and this package answer with one word. This package writes
111
+ * no settings file; the write itself, its receipt and where the layer lives are the host's.
78
112
  * `unreadable` on a `member` / `members` unit is NOT absence, and the reading carries no direction: what the caller does with it depends on the member's
79
113
  * `memberAdmission(category, member).direction` (`loosen` ⇒ may be dropped, loudly; `tighten` ⇒ must be kept and answered strictest on its own surface) —
80
114
  * see WHEN A MEMBER DOES NOT READ in the file header.
@@ -1,9 +1,28 @@
1
1
  /**
2
2
  * SETTINGS UNITS (14.6.0) — the settings-document unit table: which keys of a settings file carry a merge contract, where each
3
- * sits in the document, which {@link SAFETY_MERGE_SPEC} category it maps into, and how its raw value READS. Every resolver of a
4
- * settings file (the shell reads it for each of its sources; a profile loader is a second projection) reads THIS table instead of
5
- * keeping a key→category map of its own for these ten units. Unit names are the shell's established ten; the two permission-mode
6
- * kill-switches map to their own `killSwitches` member rows (the table has no managed-only floor for them).
3
+ * sits in the document, which {@link SAFETY_MERGE_SPEC} category it maps into, how its raw value READS, who reads it (`reader`) and
4
+ * which settings sources carry it (`sources`).
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
+ * 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
+ * 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).
10
+ *
11
+ * Who reads a unit (`reader`, on every row; the closed set {@link SETTINGS_UNIT_READERS}):
12
+ * · `shell` — the value changes only the host's own interface and never reaches the engine, wherever the engine runs — so a writer
13
+ * of a write set made only of `shell` units needs no question about the engine at all;
14
+ * · `engine` — the conservative answer for everything else: the value can change what the engine does (the engine reads it, or a host
15
+ * folds it into the engine's request — a model, a permission rule, an output style folded into the system prompt). Whether
16
+ * a write to one particular settings file reaches one particular engine depends on how that host feeds its engine (a host
17
+ * may read the local file and forward the value to an engine that runs elsewhere): ask the host, not this table.
18
+ * It is a fact about each KEY, never about a category: `outputStyle` and `semaUiLanguage` share the `ui` category and have different
19
+ * readers. A unit has one reader for all of its value: a `members` unit's members share it, and `hooks` is `engine` although some of its
20
+ * events run in the shell — which event belongs to whom is `HOOK_EVENT_OWNER` (`./hooks`), the finer reading, not a second reader here.
21
+ *
22
+ * 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
+ * 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
+ * (their `sources` IS `SETTINGS_SOURCES`); `semaUiLanguage` only by `UI_LANGUAGE_SETTING.source` (the user's settings), read from there.
7
26
  *
8
27
  * NOT in this table: the two http-hook allowlist keys (`allowedHttpHookUrls` / `httpHookAllowedEnvVars`). They carry a merge contract
9
28
  * too (the `httpHookAllowlists` category of {@link SAFETY_MERGE_SPEC}) but are keyed and read by `./http-hook-allowlists` on its own
@@ -32,6 +51,8 @@
32
51
  * · `hooks` — what the one hooks judge (`classifyHooksConfig`) classifies as `loaded`;
33
52
  * · `envMap` — a plain object whose keys are non-empty and whose values are all strings;
34
53
  * · `nonEmptyString` — a non-empty string;
54
+ * · `uiLanguage` — a word of `UI_LANGUAGE_VALUES`, exactly as written: no case folding, no locale-tag folding (`"zh-CN"`, `"EN"`, `" en"`
55
+ * are `unreadable`). The one judge is `readUiLanguage` (`./ui-language`); this reading delegates to it;
35
56
  * and a member's value class: `boolPole` ⇒ a boolean, `list` ⇒ the `stringList` reading.
36
57
  * Everything else is `unreadable` — no default arm. Two laws for every unit: `undefined` and JSON `null` are `unreadable` (absence
37
58
  * is not a value; "an absent landing spot takes the write" is the loader's business, before it calls the reader), and the reader
@@ -55,7 +76,7 @@
55
76
  * 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.
56
77
  * 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
57
78
  * out-of-domain value reads `unreadable` without throwing. Not covered, and not settled here: the `whole` units (`permissionMode`, `additionalDirectories`,
58
- * `hooks`, `env`, `model`, `outputStyle`) have no direction column; whether "unreadable = absent" closes for them depends on the order of the
79
+ * `hooks`, `env`, `model`, `outputStyle`, `semaUiLanguage`) have no direction column; whether "unreadable = absent" closes for them depends on the order of the
59
80
  * unit's own value domain, which is a design question of its own.
60
81
  * The env DOCUMENT's literal grammar (boolean words, csv + empty-set sentinel, a "≤ 0 means off" cap) is not here: it belongs to
61
82
  * the engine's env catalog, whose one implementation is the server's.
@@ -65,18 +86,24 @@ import { captureJson, captureStringArray, ownEntriesOf } from "./own-key-read.js
65
86
  import { isPlainJsonObject } from "./plain-json-object.js";
66
87
  import { SAFETY_MERGE_SPEC, resolveMemberTighten, tightenVerdict } from "./safety-merge-spec.js";
67
88
  import { deepFreeze } from "./deep-freeze.js";
68
- /** The settings-document units (see the file header). `path` is the unit's place in a settings document. */
89
+ import { SETTINGS_SOURCES } from "./settings-sources.js";
90
+ import { UI_LANGUAGE_SETTING, readUiLanguage } from "./ui-language.js";
91
+ /** Who reads a unit — the closed set of the `reader` word every unit row carries (the file header defines each word). Declaration order is not a rank. */
92
+ export const SETTINGS_UNIT_READERS = deepFreeze(["shell", "engine"]);
93
+ /** The settings-document units (see the file header). `path` is the unit's place in a settings document; `reader` is who reads it; `sources` are the settings sources that carry it. */
69
94
  export const SETTINGS_UNITS = deepFreeze({
70
- permissions: { path: ["permissions"], category: "permissions", reads: "members" },
71
- permissionMode: { path: ["permissions", "defaultMode"], category: "permissionMode", reads: "whole", reading: "permissionMode" },
72
- additionalDirectories: { path: ["permissions", "additionalDirectories"], category: "sandboxNetwork", reads: "whole", reading: "stringList" },
73
- sandbox: { path: ["sandbox"], category: "sandboxNetwork", reads: "members" },
74
- disableBypassPermissionsMode: { path: ["permissions", "disableBypassPermissionsMode"], category: "killSwitches", reads: "member", member: "disableBypassPermissionsMode", reading: "killSwitch" },
75
- disableAutoMode: { path: ["permissions", "disableAutoMode"], category: "killSwitches", reads: "member", member: "disableAutoMode", reading: "killSwitch" },
76
- hooks: { path: ["hooks"], category: "hooks", reads: "whole", reading: "hooks" },
77
- env: { path: ["env"], category: "env", reads: "whole", reading: "envMap" },
78
- model: { path: ["model"], category: "model", reads: "whole", reading: "nonEmptyString" },
79
- outputStyle: { path: ["outputStyle"], category: "ui", reads: "whole", reading: "nonEmptyString" },
95
+ permissions: { path: ["permissions"], category: "permissions", reads: "members", reader: "engine", sources: SETTINGS_SOURCES },
96
+ permissionMode: { path: ["permissions", "defaultMode"], category: "permissionMode", reads: "whole", reading: "permissionMode", reader: "engine", sources: SETTINGS_SOURCES },
97
+ additionalDirectories: { path: ["permissions", "additionalDirectories"], category: "sandboxNetwork", reads: "whole", reading: "stringList", reader: "engine", sources: SETTINGS_SOURCES },
98
+ sandbox: { path: ["sandbox"], category: "sandboxNetwork", reads: "members", reader: "engine", sources: SETTINGS_SOURCES },
99
+ disableBypassPermissionsMode: { path: ["permissions", "disableBypassPermissionsMode"], category: "killSwitches", reads: "member", member: "disableBypassPermissionsMode", reading: "killSwitch", reader: "engine", sources: SETTINGS_SOURCES },
100
+ disableAutoMode: { path: ["permissions", "disableAutoMode"], category: "killSwitches", reads: "member", member: "disableAutoMode", reading: "killSwitch", reader: "engine", sources: SETTINGS_SOURCES },
101
+ hooks: { path: ["hooks"], category: "hooks", reads: "whole", reading: "hooks", reader: "engine", sources: SETTINGS_SOURCES },
102
+ env: { path: ["env"], category: "env", reads: "whole", reading: "envMap", reader: "engine", sources: SETTINGS_SOURCES },
103
+ model: { path: ["model"], category: "model", reads: "whole", reading: "nonEmptyString", reader: "engine", sources: SETTINGS_SOURCES },
104
+ outputStyle: { path: ["outputStyle"], category: "ui", reads: "whole", reading: "nonEmptyString", reader: "engine", sources: SETTINGS_SOURCES },
105
+ // 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
+ [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] },
80
107
  });
81
108
  /** The one place a unit + optional member resolves to what is being asked about — the row and its comparator. Fail-closed
82
109
  * and loud on every misaddressing: an unknown unit (own-property lookup — `"__proto__"` is unknown, not Object.prototype),
@@ -172,6 +199,11 @@ function shapedReading(unit, row, rule, raw) {
172
199
  return isEnvMap(raw) ? { ok: true, value: raw } : UNREADABLE;
173
200
  case "nonEmptyString":
174
201
  return typeof raw === "string" && raw.length > 0 ? { ok: true, value: raw } : UNREADABLE;
202
+ case "uiLanguage": {
203
+ // the one judge of the closed set is the declaration's reader; `undefined` / `null` never get here (absence is refused before the shape half)
204
+ const layer = readUiLanguage(raw);
205
+ return layer.ok && layer.value !== undefined ? { ok: true, value: raw } : UNREADABLE;
206
+ }
175
207
  default: {
176
208
  const unknown = row.reading;
177
209
  throw new RangeError(`SETTINGS_UNITS: unit '${unit}' has an unknown reading '${String(unknown)}'`);
@@ -185,6 +217,9 @@ function shapedReading(unit, row, rule, raw) {
185
217
  * are `"manual"` ⇒ `"default"` (permissionMode) and `"disable"` ⇒ `true` (kill-switches); `"bypassPermissions"` is `launch_only`.
186
218
  * The last step of every reading is the unit comparator's own domain: whatever reads, compares (file header).
187
219
  * Addressing is {@link unitTighten}'s (same RangeErrors: a `members` unit needs a declared member, …).
220
+ * A WRITER judges the value it is about to write with this same call, and reads the written layer back with it: the refusal word is the reading's
221
+ * `reason` (a UI language outside its closed set ⇒ `unreadable`), so a host's inbound gate and this package answer with one word. This package writes
222
+ * no settings file; the write itself, its receipt and where the layer lives are the host's.
188
223
  * `unreadable` on a `member` / `members` unit is NOT absence, and the reading carries no direction: what the caller does with it depends on the member's
189
224
  * `memberAdmission(category, member).direction` (`loosen` ⇒ may be dropped, loudly; `tighten` ⇒ must be kept and answered strictest on its own surface) —
190
225
  * see WHEN A MEMBER DOES NOT READ in the file header.
package/dist/types.d.ts CHANGED
@@ -1413,8 +1413,8 @@ export declare const CollabTopology: z.ZodEnum<{
1413
1413
  }>;
1414
1414
  export type CollabTopology = z.infer<typeof CollabTopology>;
1415
1415
  export declare const CollabFinalizerType: z.ZodEnum<{
1416
- summarize: "summarize";
1417
1416
  none: "none";
1417
+ summarize: "summarize";
1418
1418
  judge: "judge";
1419
1419
  vote: "vote";
1420
1420
  fuse: "fuse";
@@ -1469,8 +1469,8 @@ declare const CollabTemplate: z.ZodObject<{
1469
1469
  }, z.core.$strip>;
1470
1470
  finalizer: z.ZodObject<{
1471
1471
  type: z.ZodEnum<{
1472
- summarize: "summarize";
1473
1472
  none: "none";
1473
+ summarize: "summarize";
1474
1474
  judge: "judge";
1475
1475
  vote: "vote";
1476
1476
  fuse: "fuse";
@@ -1530,8 +1530,8 @@ export declare const CollabConfig: z.ZodObject<{
1530
1530
  }, z.core.$strip>;
1531
1531
  finalizer: z.ZodObject<{
1532
1532
  type: z.ZodEnum<{
1533
- summarize: "summarize";
1534
1533
  none: "none";
1534
+ summarize: "summarize";
1535
1535
  judge: "judge";
1536
1536
  vote: "vote";
1537
1537
  fuse: "fuse";
@@ -2008,8 +2008,8 @@ export interface SkillsManifest {
2008
2008
  * legal hash scheme. */
2009
2009
  export declare const SkillsManifestSchema: z.ZodObject<{
2010
2010
  skills: z.ZodPrefault<z.ZodArray<z.ZodObject<{
2011
- name: z.ZodString;
2012
2011
  enabled: z.ZodDefault<z.ZodBoolean>;
2012
+ name: z.ZodString;
2013
2013
  notes: z.ZodOptional<z.ZodString>;
2014
2014
  description: z.ZodDefault<z.ZodString>;
2015
2015
  rosters: z.ZodPrefault<z.ZodArray<z.ZodString>>;
@@ -2958,8 +2958,8 @@ export declare const DOMAIN_SCHEMAS: {
2958
2958
  }, z.core.$strip>;
2959
2959
  finalizer: z.ZodObject<{
2960
2960
  type: z.ZodEnum<{
2961
- summarize: "summarize";
2962
2961
  none: "none";
2962
+ summarize: "summarize";
2963
2963
  judge: "judge";
2964
2964
  vote: "vote";
2965
2965
  fuse: "fuse";
@@ -3576,9 +3576,9 @@ export declare const SettingSource: z.ZodDiscriminatedUnion<[z.ZodObject<{
3576
3576
  }, z.core.$strip>, z.ZodObject<{
3577
3577
  axis: z.ZodLiteral<"principal">;
3578
3578
  via: z.ZodEnum<{
3579
+ role: "role";
3579
3580
  tier: "tier";
3580
3581
  override: "override";
3581
- role: "role";
3582
3582
  "worker-base": "worker-base";
3583
3583
  }>;
3584
3584
  id: z.ZodString;
@@ -3608,9 +3608,9 @@ export declare const EffectiveKey: z.ZodObject<{
3608
3608
  }, z.core.$strip>, z.ZodObject<{
3609
3609
  axis: z.ZodLiteral<"principal">;
3610
3610
  via: z.ZodEnum<{
3611
+ role: "role";
3611
3612
  tier: "tier";
3612
3613
  override: "override";
3613
- role: "role";
3614
3614
  "worker-base": "worker-base";
3615
3615
  }>;
3616
3616
  id: z.ZodString;
@@ -3619,8 +3619,8 @@ export declare const EffectiveKey: z.ZodObject<{
3619
3619
  }, z.core.$strip>], "axis">;
3620
3620
  locked: z.ZodBoolean;
3621
3621
  enforcement: z.ZodEnum<{
3622
- gate: "gate";
3623
3622
  server: "server";
3623
+ gate: "gate";
3624
3624
  resolver: "resolver";
3625
3625
  client: "client";
3626
3626
  }>;
@@ -3642,9 +3642,9 @@ export declare const EffectiveKey: z.ZodObject<{
3642
3642
  }, z.core.$strip>, z.ZodObject<{
3643
3643
  axis: z.ZodLiteral<"principal">;
3644
3644
  via: z.ZodEnum<{
3645
+ role: "role";
3645
3646
  tier: "tier";
3646
3647
  override: "override";
3647
- role: "role";
3648
3648
  "worker-base": "worker-base";
3649
3649
  }>;
3650
3650
  id: z.ZodString;
package/dist/types.js CHANGED
@@ -1940,12 +1940,14 @@ function retiredEnvIssue(rec, ctx) {
1940
1940
  // ── 7.0.0 M-R2:`runtime.execution` / `runtime.store` 两个结构块 ─────────────────────────────────────────────
1941
1941
  // 词表只有一个正本(`execution-lanes.ts` 的导出表):本包写闸(`WorkerSpec.safeParse`)、web-admin 渲染器、引擎起服三处读同一张表。
1942
1942
  // 拒因都在 zod issue 里(`path` 指到要改的字段、`message` 带出路)—— schema 本身是唯一判据,不另导出拒因函数。
1943
- /** 一个非密字面值(车道坐标 / SQL 坐标):≤2048,不像密钥(与 `env` 逃生口同一条判据 —— 密钥走 env-NAME 引用)。 */
1944
- const nonSecretLiteral = (minLength) => z
1945
- .string()
1946
- .min(minLength)
1947
- .max(2048)
1948
- .refine((s) => !containsSecretToken(s), buildQuotedIssue `looks like a literal secret — a credential goes in a secretRefs field as an env-NAME, never a value here`);
1943
+ /** 一个非密字面值的字数上界(车道坐标 / SQL 坐标 / `env` 逃生口):唯一一份数。 */
1944
+ const NON_SECRET_LITERAL_MAX = 2048;
1945
+ /** 非密字面值的第二条判据:不像密钥(密钥走 env-NAME 引用;与 `env` 逃生口同一条判据)。这句拒句只铸在这一处(源码门要求 `.refine` 的第二参数是 `buildQuotedIssue` 标签模板)。 */
1946
+ const asNonSecretLiteral = (text) => text.refine((s) => !containsSecretToken(s), buildQuotedIssue `looks like a literal secret — a credential goes in a secretRefs field as an env-NAME, never a value here`);
1947
+ /** 一个非密字面值(SQL 坐标):≤{@link NON_SECRET_LITERAL_MAX},不像密钥。 */
1948
+ const nonSecretLiteral = (minLength) => asNonSecretLiteral(z.string().min(minLength).max(NON_SECRET_LITERAL_MAX));
1949
+ /** 车道坐标的值:不像密钥。字数上界**不在这里** —— 它在 `ExecutionBlock` 按键判(那里才知道是哪一个坐标:句子点名坐标并给出路,不是 zod 的泛话 `Too big`),同一个 {@link NON_SECRET_LITERAL_MAX}。 */
1950
+ const coordinateLiteral = asNonSecretLiteral(z.string().min(0));
1949
1951
  /**
1950
1952
  * 可信代理名单一个坏项的拒因片语(进写闸拒句「found:」那一段,整段是定文):**只有位置数与闭集拒因词** —— 参数的型就是这条不变式(`item` / `of` 是数,
1951
1953
  * `flaw` 是拒因闭集的型),名单项的文本(配置里的值)没有参数可进来。逐项的结构化读数是判官交的那一份(`readDeviceTrustedProxyCidrs` 的 `items`),
@@ -2083,7 +2085,7 @@ const ExecutionBlock = z
2083
2085
  .object({
2084
2086
  lane: retiredKey("runtime.execution.lane", { retiredIn: "16.0.0", now: "runtime.execution.lanes (an ordered lane set; the first one is the default)", migration: "SS-M12" }),
2085
2087
  lanes: DeclaredLanes,
2086
- coords: recordOf(ENV_NAME, nonSecretLiteral(0)).prefault({}),
2088
+ coords: recordOf(ENV_NAME, coordinateLiteral).prefault({}),
2087
2089
  secretRefs: LaneSecretRefs.prefault({}),
2088
2090
  })
2089
2091
  .superRefine((x, ctx) => {
@@ -2112,6 +2114,23 @@ const ExecutionBlock = z
2112
2114
  }
2113
2115
  return true;
2114
2116
  };
2117
+ // 字数上界按键判(值 schema 不带上界:句子要点名是哪一个坐标,值 schema 不知道自己的键),且**先于**下面所有按键归属 / 文法的判:长度是它自己的一条拒因,不被别的拒因挡住、也不替它们收声 ——
2118
+ // 条数与此前(值 schema 上的 `.max()`)相同,与键归属 / 文法两类之间的次序也相同:一只坐标可以同时报长度与键归属 / 文法,所有长度条在前、这两类在后。长度条仍排在值 schema 的各条拒因(像密钥、环境变量名格式)之后 —— 已知的边。
2119
+ // 字数按 Unicode 码点量({@link withinCodePoints},与此前 zod 的上界检查同一把尺 —— 一个非 BMP 字符算一个;句子里的字数也按码点数,不按 UTF-16 码元)。
2120
+ // issue 的机读码 / `origin` / `maximum` 与此前 zod 的上界检查给的逐一相同(只有 `message` 换成点名坐标、给出路的句子);句子只带字数,不回显值。
2121
+ for (const [key, value] of Object.entries(x.coords)) {
2122
+ if (withinCodePoints(NON_SECRET_LITERAL_MAX)(value))
2123
+ continue;
2124
+ ctx.addIssue({
2125
+ code: "too_big",
2126
+ origin: "string",
2127
+ maximum: NON_SECRET_LITERAL_MAX,
2128
+ inclusive: true,
2129
+ input: value,
2130
+ path: ["coords", key],
2131
+ ...buildQuotedIssue `coords.${key} is ${[...value].length} characters long — a coordinate value is at most ${fixed(String(NON_SECRET_LITERAL_MAX))} characters; shorten it`,
2132
+ });
2133
+ }
2115
2134
  for (const [key, value] of Object.entries(x.coords)) {
2116
2135
  if (!judgeKey("coords", key))
2117
2136
  continue;
@@ -2276,7 +2295,7 @@ const WorkerSpecObject = z.object({
2276
2295
  * secret 名…)被拒,防 env 改路由/关鉴权/遮蔽密钥(council);墓碑表 `RETIRED_ENVS` 里的旧名被拒(引擎见之拒启;空串 = 未设,同引擎)。
2277
2296
  * 可覆盖非保留键(如 LOG_LEVEL)。hash-included(改它重建)。
2278
2297
  */
2279
- env: recordOf(ENV_NAME, z.string().max(2048))
2298
+ env: recordOf(ENV_NAME, z.string().max(NON_SECRET_LITERAL_MAX))
2280
2299
  .superRefine((rec, ctx) => {
2281
2300
  retiredEnvIssue(rec, ctx);
2282
2301
  for (const [k, v] of Object.entries(rec)) {
@@ -3,7 +3,9 @@
3
3
  * (CC 的 `language` 键是后者;两个事实不共用一个键)。形照 `cross-session.ts` 的片段契约:导出值闭集 + 一层的读器。纯、浏览器安全。
4
4
  *
5
5
  * - 键 `semaUiLanguage`(沿用终端已写的键,cli `src/sema/i18n/languageStore.ts`,已存值零迁移);作用源 = 用户设置;合并类 = `ui`
6
- * (`SAFETY_MERGE_SPEC.ui`,`enforcement: "client"`,壳侧、不进引擎)。
6
+ * (`SAFETY_MERGE_SPEC.ui`,`enforcement: "client"`)。
7
+ * - 写侧单元 = 单元表 `SETTINGS_UNITS` 的 `semaUiLanguage` 一行(`./settings-units`):它的键名、类目与读自的源(`sources`)从本文件的 {@link UI_LANGUAGE_SETTING} 取,
8
+ * 读法 `uiLanguage` 委托本文件的 {@link readUiLanguage}(判值只有这一只判官);「谁读」只记在那一行的 `reader`(`shell`:只改宿主自己的界面,不进引擎)。
7
9
  * - 合法值闭集 {@link UI_LANGUAGE_VALUES} = `en` / `zh`。
8
10
  * - 缺席或不合法 ⇒ 跟宿主 locale。读器**不猜**:不把 `zh-CN` 折成 `zh`、不按大小写折 —— locale 标签到这两个词的映射是宿主读 locale 时的事,
9
11
  * 不是读设置时的事。
@@ -3,7 +3,9 @@
3
3
  * (CC 的 `language` 键是后者;两个事实不共用一个键)。形照 `cross-session.ts` 的片段契约:导出值闭集 + 一层的读器。纯、浏览器安全。
4
4
  *
5
5
  * - 键 `semaUiLanguage`(沿用终端已写的键,cli `src/sema/i18n/languageStore.ts`,已存值零迁移);作用源 = 用户设置;合并类 = `ui`
6
- * (`SAFETY_MERGE_SPEC.ui`,`enforcement: "client"`,壳侧、不进引擎)。
6
+ * (`SAFETY_MERGE_SPEC.ui`,`enforcement: "client"`)。
7
+ * - 写侧单元 = 单元表 `SETTINGS_UNITS` 的 `semaUiLanguage` 一行(`./settings-units`):它的键名、类目与读自的源(`sources`)从本文件的 {@link UI_LANGUAGE_SETTING} 取,
8
+ * 读法 `uiLanguage` 委托本文件的 {@link readUiLanguage}(判值只有这一只判官);「谁读」只记在那一行的 `reader`(`shell`:只改宿主自己的界面,不进引擎)。
7
9
  * - 合法值闭集 {@link UI_LANGUAGE_VALUES} = `en` / `zh`。
8
10
  * - 缺席或不合法 ⇒ 跟宿主 locale。读器**不猜**:不把 `zh-CN` 折成 `zh`、不按大小写折 —— locale 标签到这两个词的映射是宿主读 locale 时的事,
9
11
  * 不是读设置时的事。
@@ -17,7 +17,9 @@
17
17
  * 声明面(本文件尾段):凭证的二选一判官 {@link judgeWebAdminCredentialDeclaration},读 env 名表 {@link WEB_ADMIN_ENV}
18
18
  * (`./web-admin-env`,八键)里的 `token` / `tokenFile` 两键。
19
19
  *
20
- * 纯契约:零 IO(读文件、写文件、续签都是消费方的事),browser-safe,与本包其余部分同一条纯度律。
20
+ * 单写者锁(文件尾段):协议常量 {@link WEB_ADMIN_CREDENTIAL_FILE_LOCK} 与锁名 {@link webAdminCredentialLockName} 在这里;按它们取锁的原语要读写文件系统,在 `./node`。
21
+ *
22
+ * 纯契约:零 IO(读文件、写文件、续签都是消费方的事;写文件时取锁调 `./node` 的那一只原语),browser-safe,与本包其余部分同一条纯度律。
21
23
  */
22
24
  import { z } from "zod";
23
25
  /** 信封 `kind` 的闭集今只有一员(`SEALED_BOX_ALG` 同式的字面常量:schema 的字面与读方的比较都引它)。 */
@@ -94,3 +96,14 @@ export type WebAdminCredentialDeclaration = {
94
96
  * 只读这一对键,别的 env(另一份凭证的那一对也在内)一概不看。判哪一份由调用方说 —— 没有缺省。
95
97
  */
96
98
  export declare function judgeWebAdminCredentialDeclaration(env: Readonly<Record<string, string | undefined>>, credential: WebAdminCredential): WebAdminCredentialDeclaration;
99
+ /**
100
+ * 凭证文件单写者锁的**协议常量** —— 同一只凭证文件的每个写者(引擎的续签写回、壳的登录 / 刷新 / 登出)读同一个数,所以它是常量、不是部署旋钮。
101
+ *
102
+ * · `staleMs` —— 锁文件的 mtime 早于「现在」这么久,才当崩溃残留收走;mtime 在未来(时钟回拨)= 新鲜。成立的前提是**持锁段只做同步的本机 IO**
103
+ * (一次读 + 一次改名或删除,亚毫秒):把网络调用、等待、再取别的锁放进持锁段的写者,10 s 后会被别的写者当残留挪走。
104
+ */
105
+ export declare const WEB_ADMIN_CREDENTIAL_FILE_LOCK: {
106
+ readonly staleMs: 10000;
107
+ };
108
+ /** 凭证文件的锁文件名:`.<真文件名>.lock`,建在**真目标**(软链解到底的那只文件)所在目录里。入参是真目标的文件名(不带目录)。 */
109
+ export declare function webAdminCredentialLockName(realBasename: string): string;
@@ -17,7 +17,9 @@
17
17
  * 声明面(本文件尾段):凭证的二选一判官 {@link judgeWebAdminCredentialDeclaration},读 env 名表 {@link WEB_ADMIN_ENV}
18
18
  * (`./web-admin-env`,八键)里的 `token` / `tokenFile` 两键。
19
19
  *
20
- * 纯契约:零 IO(读文件、写文件、续签都是消费方的事),browser-safe,与本包其余部分同一条纯度律。
20
+ * 单写者锁(文件尾段):协议常量 {@link WEB_ADMIN_CREDENTIAL_FILE_LOCK} 与锁名 {@link webAdminCredentialLockName} 在这里;按它们取锁的原语要读写文件系统,在 `./node`。
21
+ *
22
+ * 纯契约:零 IO(读文件、写文件、续签都是消费方的事;写文件时取锁调 `./node` 的那一只原语),browser-safe,与本包其余部分同一条纯度律。
21
23
  */
22
24
  import { z } from "zod";
23
25
  import { looksLikeJwt } from "./api/auth-bridge.js";
@@ -149,3 +151,15 @@ export function judgeWebAdminCredentialDeclaration(env, credential) {
149
151
  return { from: "env", token };
150
152
  return { from: "absent" };
151
153
  }
154
+ // ── 凭证文件的单写者锁:协议常量(纯数据;取锁原语在 `./node` 的 `tryWebAdminCredentialFileLock`)──────────────────────────────
155
+ /**
156
+ * 凭证文件单写者锁的**协议常量** —— 同一只凭证文件的每个写者(引擎的续签写回、壳的登录 / 刷新 / 登出)读同一个数,所以它是常量、不是部署旋钮。
157
+ *
158
+ * · `staleMs` —— 锁文件的 mtime 早于「现在」这么久,才当崩溃残留收走;mtime 在未来(时钟回拨)= 新鲜。成立的前提是**持锁段只做同步的本机 IO**
159
+ * (一次读 + 一次改名或删除,亚毫秒):把网络调用、等待、再取别的锁放进持锁段的写者,10 s 后会被别的写者当残留挪走。
160
+ */
161
+ export const WEB_ADMIN_CREDENTIAL_FILE_LOCK = deepFreeze({ staleMs: 10_000 });
162
+ /** 凭证文件的锁文件名:`.<真文件名>.lock`,建在**真目标**(软链解到底的那只文件)所在目录里。入参是真目标的文件名(不带目录)。 */
163
+ export function webAdminCredentialLockName(realBasename) {
164
+ return `.${realBasename}.lock`;
165
+ }