@sema-agent/settings-schema 27.1.0 → 28.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 (73) hide show
  1. package/CHANGELOG.md +505 -0
  2. package/README.md +17 -1
  3. package/conformance/VERSION +1 -1
  4. package/dist/api/auth-bridge.js +4 -3
  5. package/dist/api/auth.js +6 -5
  6. package/dist/api/credentials.js +9 -8
  7. package/dist/api/pull-token.js +2 -1
  8. package/dist/api/scopes.js +5 -4
  9. package/dist/center-refs.js +3 -2
  10. package/dist/config-dir-io.d.ts +1 -1
  11. package/dist/config-dir-io.js +3 -2
  12. package/dist/config-document-refusal.d.ts +1 -1
  13. package/dist/config-document-refusal.js +2 -1
  14. package/dist/config-fns.d.ts +4 -4
  15. package/dist/config-fns.js +17 -16
  16. package/dist/config-root-documents.js +4 -3
  17. package/dist/config-root-node.d.ts +1 -1
  18. package/dist/config-root-node.js +3 -2
  19. package/dist/conformance/derive.d.ts +3 -3
  20. package/dist/conformance/derive.js +6 -5
  21. package/dist/conformance/types.js +4 -3
  22. package/dist/cross-domain.js +6 -5
  23. package/dist/cross-session.js +3 -2
  24. package/dist/deep-freeze.d.ts +26 -0
  25. package/dist/deep-freeze.js +69 -0
  26. package/dist/default-model.js +2 -1
  27. package/dist/device-relay.d.ts +1 -1
  28. package/dist/device-relay.js +1 -1
  29. package/dist/env-model-table.js +2 -1
  30. package/dist/execution-lane-index.d.ts +1 -1
  31. package/dist/execution-lane-index.js +5 -4
  32. package/dist/execution-lanes.d.ts +2 -2
  33. package/dist/execution-lanes.js +18 -17
  34. package/dist/file-store.js +2 -1
  35. package/dist/fleet.d.ts +20 -4
  36. package/dist/fleet.js +32 -16
  37. package/dist/hooks-config.d.ts +12 -12
  38. package/dist/hooks-config.js +16 -15
  39. package/dist/hooks.d.ts +5 -5
  40. package/dist/hooks.js +17 -16
  41. package/dist/http-hook-allowlists.js +2 -1
  42. package/dist/index.js +1 -1
  43. package/dist/mcp-request-entry.js +2 -1
  44. package/dist/mcp-server-policy.js +3 -2
  45. package/dist/migration-receipt.d.ts +1 -1
  46. package/dist/migration-receipt.js +3 -2
  47. package/dist/one-time-migrations.js +3 -2
  48. package/dist/own-key-read.d.ts +3 -1
  49. package/dist/plain-json-object.d.ts +6 -3
  50. package/dist/plain-json-object.js +6 -3
  51. package/dist/portable-domains.js +4 -3
  52. package/dist/reserved-member-name.d.ts +1 -1
  53. package/dist/reserved-member-name.js +3 -2
  54. package/dist/resolve-roster.js +3 -2
  55. package/dist/retired-envs.js +3 -6
  56. package/dist/safety-merge-spec.d.ts +11 -4
  57. package/dist/safety-merge-spec.js +5 -4
  58. package/dist/secret-scan.js +1 -1
  59. package/dist/settings-sources.js +6 -5
  60. package/dist/settings-units.js +3 -2
  61. package/dist/types.d.ts +9 -9
  62. package/dist/types.js +27 -26
  63. package/dist/ui-language.js +4 -3
  64. package/dist/url-credential.js +4 -3
  65. package/dist/url-shape.d.ts +1 -1
  66. package/dist/url-shape.js +5 -4
  67. package/dist/web-admin-credential.js +2 -1
  68. package/dist/web-admin-env.d.ts +1 -1
  69. package/dist/web-admin-env.js +4 -3
  70. package/docs/CONSUMER-INTEGRATION.md +48 -3
  71. package/llms-full.txt +5 -3
  72. package/llms.txt +4 -2
  73. package/package.json +1 -1
package/dist/api/auth.js CHANGED
@@ -37,17 +37,18 @@
37
37
  */
38
38
  import { z } from "zod";
39
39
  import { INTEGER } from "../integer.js";
40
+ import { deepFreeze } from "../deep-freeze.js";
40
41
  // ── endpoint paths + protocol constants (shipped values) ─────────────────────────────────────────────────
41
42
  // 3.0.0(S-321):这些常量与纯函数 2026-07-27 曾被拆去 `./api/wire` 子路径(给「零依赖客户端运行时直取」
42
43
  // 留的门),四个消费仓自始至终零 import —— 死出口连同它的拆分一起删,常量回到它们的契约原处。
43
44
  /** The five auth endpoints, relative to web-admin origin. */
44
- export const AUTH_V1_PATHS = {
45
+ export const AUTH_V1_PATHS = deepFreeze({
45
46
  deviceCode: "/api/v1/auth/device/code",
46
47
  deviceToken: "/api/v1/auth/device/token",
47
48
  deviceApprove: "/api/v1/auth/device/approve",
48
49
  tokenRefresh: "/api/v1/auth/token/refresh",
49
50
  logout: "/api/v1/auth/logout",
50
- };
51
+ });
51
52
  /** The RFC 8628 grant_type the device token endpoint requires. */
52
53
  export const DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
53
54
  /** Minimum seconds between token-endpoint polls (RFC 8628 `interval`); polling faster → `slow_down`. */
@@ -59,7 +60,7 @@ export const ACCESS_TOKEN_TTL_SECONDS = 60 * 60;
59
60
  /** Refresh-grant lifetime (seconds) — 30d SLIDING: every rotation opens a fresh 30d window. */
60
61
  export const REFRESH_TOKEN_TTL_SECONDS = 30 * 24 * 60 * 60;
61
62
  /** Every error code the /api/v1/auth/* endpoints answer (HTTP 400 unless noted). */
62
- export const OAUTH_ERROR_CODES = [
63
+ export const OAUTH_ERROR_CODES = deepFreeze([
63
64
  /** device/token: the user has not approved (or denied) the handshake yet — keep polling. */
64
65
  "authorization_pending",
65
66
  /** device/token: polling faster than `interval` — RFC 8628 §3.5: ADD 5 seconds to the interval. */
@@ -77,11 +78,11 @@ export const OAUTH_ERROR_CODES = [
77
78
  "invalid_grant",
78
79
  /** SSO not configured on web-admin (HTTP 503) — a deployment problem, not a client one. */
79
80
  "server_error",
80
- ];
81
+ ]);
81
82
  /** Handshake states a consent-screen lookup can see. (`approved` rows vanish once exchanged/consumed.)
82
83
  * `denied` is contract-reserved for an explicit deny button (pairs with the `access_denied` poll error);
83
84
  * the shipped M1 store carries pending|approved only — adding deny later is implementation, not schema. */
84
- export const DEVICE_AUTH_STATUSES = ["pending", "approved", "denied"];
85
+ export const DEVICE_AUTH_STATUSES = deepFreeze(["pending", "approved", "denied"]);
85
86
  // ── auth: pure client-side helpers(api/auth.ts 原件)────────────────────────────────────────────────────
86
87
  /**
87
88
  * Canonicalize a human-typed user code to the wire shape "XXXX-XXXX": uppercase, dashes/spaces optional.
@@ -25,13 +25,14 @@ import { INTEGER } from "../integer.js";
25
25
  import { buildQuotedIssue } from "../quoted-issue.js";
26
26
  import { SANDBOX_GIT_MAX_ORIGINS, SandboxGitOrigin, SandboxGitOriginList } from "../sandbox-git.js";
27
27
  import { PRINCIPAL_MAX_LENGTH, PrincipalIncarnation } from "./auth-bridge.js";
28
+ import { deepFreeze } from "../deep-freeze.js";
28
29
  // ── 逐 origin 判定序表 ─────────────────────────────────────────────────────────────────────────────────────────────
29
30
  /**
30
31
  * 逐 origin 判定序表(11 行,序即判定序)。每行 `{ state, reason? }`:命中这一行的 origin 的应答是这个状态与这个原因。
31
32
  * 条件(各行什么事实命中)见 `docs/CONSUMER-INTEGRATION.md` 的判定序表;`active` 是兜底行(行 `active` 且刷新不成问题),没有原因。
32
33
  * 加一行 / 改序都是改契约:状态词、原因词、应答臂的原因值域、类型全部随这一张表走。
33
34
  */
34
- export const SANDBOX_GIT_ORIGIN_VERDICTS = [
35
+ export const SANDBOX_GIT_ORIGIN_VERDICTS = deepFreeze([
35
36
  { state: "insecure_transport", reason: "not_https" },
36
37
  { state: "not_offered", reason: "not_in_registry" },
37
38
  { state: "not_connected", reason: "no_row" },
@@ -43,11 +44,11 @@ export const SANDBOX_GIT_ORIGIN_VERDICTS = [
43
44
  { state: "needs_reauth", reason: "refresh_rejected" },
44
45
  { state: "temporarily_unavailable", reason: "refresh_unavailable" },
45
46
  { state: "active" },
46
- ];
47
+ ]);
47
48
  /** 状态词表:判定序表里状态首次出现的次序。 */
48
- export const SANDBOX_GIT_ORIGIN_STATES = [...new Set(SANDBOX_GIT_ORIGIN_VERDICTS.map((v) => v.state))];
49
+ export const SANDBOX_GIT_ORIGIN_STATES = deepFreeze([...new Set(SANDBOX_GIT_ORIGIN_VERDICTS.map((v) => v.state))]);
49
50
  /** 原因词表:判定序表里原因出现的次序(= 判定序)。 */
50
- export const SANDBOX_GIT_ORIGIN_REASONS = SANDBOX_GIT_ORIGIN_VERDICTS.flatMap((v) => ("reason" in v ? [v.reason] : []));
51
+ export const SANDBOX_GIT_ORIGIN_REASONS = deepFreeze(SANDBOX_GIT_ORIGIN_VERDICTS.flatMap((v) => ("reason" in v ? [v.reason] : [])));
51
52
  /** 判定序表里某个状态下的原因词,按表序。 */
52
53
  function reasonsOf(state) {
53
54
  return SANDBOX_GIT_ORIGIN_VERDICTS.flatMap((v) => (v.state === state && "reason" in v ? [v.reason] : []));
@@ -120,12 +121,12 @@ export const SandboxGitCredentialAnswer = z.object({
120
121
  });
121
122
  // ── 整次拒答 ───────────────────────────────────────────────────────────────────────────────────────────────────────
122
123
  /** `permanence` 两词:`terminal` = 不按定时重试;`transient` = 退避重试。 */
123
- export const SANDBOX_GIT_PERMANENCE = ["terminal", "transient"];
124
+ export const SANDBOX_GIT_PERMANENCE = deepFreeze(["terminal", "transient"]);
124
125
  /**
125
126
  * 整次拒答词 → 它的 HTTP 状态集(中心答这个词时用其一)与 `permanence`。**一个错误词的 permanence 是固定的**,拒体里再带一份只为让收方不必查表 ——
126
127
  * 两处不一致就是畸形应答({@link SandboxGitCredentialRefusal} 拒)。收方怎么处置某个词(例如哪些 terminal 可由用户动作恢复)是收方的状态机,不在这里。
127
128
  */
128
- export const SANDBOX_GIT_REFUSALS = {
129
+ export const SANDBOX_GIT_REFUSALS = deepFreeze({
129
130
  caller_not_admitted: { statuses: [401, 403], permanence: "terminal" },
130
131
  scope_mismatch: { statuses: [403], permanence: "terminal" },
131
132
  incarnation_mismatch: { statuses: [403], permanence: "terminal" },
@@ -136,9 +137,9 @@ export const SANDBOX_GIT_REFUSALS = {
136
137
  vault_frozen: { statuses: [503], permanence: "terminal" },
137
138
  handle_invalid: { statuses: [401], permanence: "transient" },
138
139
  vault_unavailable: { statuses: [503], permanence: "transient" },
139
- };
140
+ });
140
141
  /** 整次拒答词表(运行期;表的键,按表序)。 */
141
- export const SANDBOX_GIT_REFUSAL_ERRORS = Object.keys(SANDBOX_GIT_REFUSALS);
142
+ export const SANDBOX_GIT_REFUSAL_ERRORS = deepFreeze(Object.keys(SANDBOX_GIT_REFUSALS));
142
143
  /** 整次拒答的体:`{ error, permanence, message }`。`message` 是中心的诊断句(收方不据它判,可为空串)。 */
143
144
  export const SandboxGitCredentialRefusal = z
144
145
  .object({
@@ -18,8 +18,9 @@
18
18
  */
19
19
  import { hmacSha256Hex } from "../sha256-core.js";
20
20
  import { GLOBAL_SCOPE, SCOPE_ID_REGEX } from "./scopes.js";
21
+ import { deepFreeze } from "../deep-freeze.js";
21
22
  /** worker 拉取令牌族(`WEB_ADMIN_ENV.token` 的值)。 */
22
- export const WORKER_PULL_TOKEN = { v1Prefix: "wpt_", v2Prefix: "wpt2_", macTag: "worker-pull" };
23
+ export const WORKER_PULL_TOKEN = deepFreeze({ v1Prefix: "wpt_", v2Prefix: "wpt2_", macTag: "worker-pull" });
23
24
  /** worker 名能不能进帧:非空、不带 `_`(帧的分隔符)。 */
24
25
  const framableWorker = (worker) => worker.length > 0 && !worker.includes("_");
25
26
  /**
@@ -49,20 +49,21 @@ import { buildQuotedIssue, fixed } from "../quoted-issue.js";
49
49
  import { USER_ROLES } from "../config-fns.js";
50
50
  import { ownDeclaredValueOf } from "../own-key-read.js";
51
51
  import { ACCESS_TOKEN_TTL_SECONDS } from "./auth.js";
52
+ import { deepFreeze } from "../deep-freeze.js";
52
53
  // ── constants ────────────────────────────────────────────────────────────────────────────────────────────
53
54
  /** The reserved default scope. Always exists. */
54
55
  export const GLOBAL_SCOPE = "global";
55
56
  /** Scope ids that can never be created (or deleted) through the API. */
56
- export const RESERVED_SCOPE_IDS = [GLOBAL_SCOPE];
57
+ export const RESERVED_SCOPE_IDS = deepFreeze([GLOBAL_SCOPE]);
57
58
  /** Slug shape for scope ids: lowercase alphanumeric + inner dashes, 1–64 chars, no leading/trailing dash. */
58
59
  export const SCOPE_ID_REGEX = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
59
60
  /** The scope endpoints, relative to web-admin origin. `members` needs the scope id — use scopeMembersPath. */
60
- export const SCOPES_V1_PATHS = {
61
+ export const SCOPES_V1_PATHS = deepFreeze({
61
62
  /** GET (list) + POST (create). */
62
63
  scopes: "/api/v1/scopes",
63
64
  /** POST — mint a new access token bound to another scope. */
64
65
  authScope: "/api/v1/auth/scope",
65
- };
66
+ });
66
67
  /** The JWT claim carrying the token's active scope. Every minted access token carries it; a token without it is refused on read
67
68
  * ({@link readTokenScope}). */
68
69
  export const SCOPE_CLAIM = "scope";
@@ -223,7 +224,7 @@ export function canSwitchScope(memberships, instanceRole, targetScope) {
223
224
  return memberships.some((m) => m.scopeId === targetScope);
224
225
  }
225
226
  /** Why {@link readTokenScope} refuses — a CLOSED set (one word today). */
226
- export const TOKEN_SCOPE_REFUSALS = ["scope_claim_missing"];
227
+ export const TOKEN_SCOPE_REFUSALS = deepFreeze(["scope_claim_missing"]);
227
228
  /**
228
229
  * Read the active scope off verified JWT claims — the ONE reader. A non-empty string `scope` claim ⇒ `{ scope }`; a claim that is
229
230
  * missing, empty or not a string ⇒ `{ refused: "scope_claim_missing" }` (the reader answers 401). There is no default scope here:
@@ -28,10 +28,11 @@
28
28
  */
29
29
  import { readPlainStringRecord } from "./mcp-request-entry.js";
30
30
  import { dataDescriptor, inspect } from "./own-key-read.js";
31
+ import { deepFreeze } from "./deep-freeze.js";
31
32
  /** 一个成员没解到的**原因词**,闭集,三个:`missing_name`(查找函数答 `undefined` —— 变量没设)· `not_a_string`(答了别的种类)· `read_threw`(查找函数抛了)。消费方按词分派,穷尽 `switch`,不读句子(本口没有句子)。 */
32
- export const CENTER_REF_FAULTS = ["missing_name", "not_a_string", "read_threw"];
33
+ export const CENTER_REF_FAULTS = deepFreeze(["missing_name", "not_a_string", "read_threw"]);
33
34
  /** 整台结论的词,闭集,三个:`resolved` · `unresolved`(有成员没解到)· `refs_unreadable`(引用表读不出)。 */
34
- export const CENTER_REFS_VERDICTS = ["resolved", "unresolved", "refs_unreadable"];
35
+ export const CENTER_REFS_VERDICTS = deepFreeze(["resolved", "unresolved", "refs_unreadable"]);
35
36
  /** 问一次 `lookup(ref)` 并判成一个词。抛了 ⇒ `read_threw`(经内核的检视口,不另包 `try`);答 `undefined` ⇒ `missing_name`;答串 ⇒ 解到;答别的 ⇒ `not_a_string`。 */
36
37
  function answerOf(ref, lookup) {
37
38
  const asked = inspect(() => lookup(ref));
@@ -1,2 +1,2 @@
1
1
  import type { ConfigDirectoryIo } from "./config-dir-migration.js";
2
- export declare const nodeConfigDirectoryIo: ConfigDirectoryIo;
2
+ export declare const nodeConfigDirectoryIo: Readonly<ConfigDirectoryIo>;
@@ -6,8 +6,9 @@
6
6
  */
7
7
  import { readdir, readFile } from "node:fs/promises";
8
8
  import { resolveSymlinkTarget, writeFileAtomic } from "./atomic-write.js";
9
- export const nodeConfigDirectoryIo = {
9
+ import { deepFreeze } from "./deep-freeze.js";
10
+ export const nodeConfigDirectoryIo = deepFreeze({
10
11
  readDir: async (path) => readdir(resolveSymlinkTarget(path)),
11
12
  readFile: async (path) => readFile(resolveSymlinkTarget(path), "utf8"),
12
13
  writeFileAtomic: async (path, text) => writeFileAtomic(path, text, "config-document"), // the files this migration writes are config.d domain documents
13
- };
14
+ });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 契约的文件层拒一份 `config.d` 文档时交出的**类型化拒**(15.2.0)。纯数据与类型,零 node 依赖、零运行期 import —— 词表在包根,读目录的口(`FileConfigStore.read()`,16.0.0)在 `./node`。
2
+ * 契约的文件层拒一份 `config.d` 文档时交出的**类型化拒**(15.2.0)。纯数据与类型,零 node 依赖,运行期只 import 包内私有的零 import 叶 `./deep-freeze` —— 词表在包根,读目录的口(`FileConfigStore.read()`,16.0.0)在 `./node`。
3
3
  *
4
4
  * ## 为什么
5
5
  * 文件层读一份文档只有抛一句话的出口:句子不带结构化的文档名,也分不出「空 / 坏 JSON / 不是对象 / 读不出」;并发读时一次只抛第一个到达的坏文档;
@@ -1,2 +1,3 @@
1
+ import { deepFreeze } from "./deep-freeze.js";
1
2
  /** 文件层拒一份文档的闭集词:五个文件层成因 + 墓碑(恒在末位)。墓碑那个词就是 `RetiredDomainError.code`(一个词,不立第二个名)。 */
2
- export const CONFIG_DOCUMENT_REFUSAL_REASONS = ["empty", "invalid_json", "not_object", "io", "too_deep", "retired_domain"];
3
+ export const CONFIG_DOCUMENT_REFUSAL_REASONS = deepFreeze(["empty", "invalid_json", "not_object", "io", "too_deep", "retired_domain"]);
@@ -44,7 +44,7 @@ export interface WorkerLifecycleRecord {
44
44
  }
45
45
  /** RBAC roles, hierarchical: viewer < editor < publisher < admin. */
46
46
  export type UserRole = "viewer" | "editor" | "publisher" | "admin";
47
- export declare const ROLE_RANK: Record<UserRole, number>;
47
+ export declare const ROLE_RANK: Readonly<Record<UserRole, number>>;
48
48
  export declare const USER_ROLES: readonly UserRole[];
49
49
  /** True if `role` is at least `min` in the hierarchy (e.g. publisher satisfies editor). */
50
50
  export declare function roleAtLeast(role: UserRole, min: UserRole): boolean;
@@ -57,7 +57,7 @@ export declare function isRole(v: unknown): v is UserRole;
57
57
  * {@link writeRoleFor}, which also looks at WHICH fields a write changes ({@link DOMAIN_FIELD_WRITE_ROLE}).
58
58
  */
59
59
  export declare const DEFAULT_DOMAIN_WRITE_ROLE: UserRole;
60
- export declare const DOMAIN_WRITE_ROLE: Partial<Record<DomainName, UserRole>>;
60
+ export declare const DOMAIN_WRITE_ROLE: Readonly<Partial<Record<DomainName, UserRole>>>;
61
61
  /**
62
62
  * The per-field write roles of a domain whose document is a record of entries: ONE role for each field of an entry, exhaustive for the entry's
63
63
  * shape (the table is `satisfies`-checked against the entry type, so a field added to the entry without a role is a compile error — a new field
@@ -72,7 +72,7 @@ export interface DomainFieldWriteRoles {
72
72
  * one row per domain, an absent row means "the floor decides" — read only through {@link writeRoleFor}; the changed fields come from
73
73
  * {@link changedWriteFields} (the one place that diffs two documents against this table).
74
74
  */
75
- export declare const DOMAIN_FIELD_WRITE_ROLE: Partial<Record<DomainName, DomainFieldWriteRoles>>;
75
+ export declare const DOMAIN_FIELD_WRITE_ROLE: Readonly<Partial<Record<DomainName, DomainFieldWriteRoles>>>;
76
76
  /**
77
77
  * The minimum role to make a write that changes exactly `changedFields` in `domain`: the HIGHEST of the domain's floor ({@link DOMAIN_WRITE_ROLE},
78
78
  * else {@link DEFAULT_DOMAIN_WRITE_ROLE}) and the role of each changed field ({@link DOMAIN_FIELD_WRITE_ROLE}). `[]` = a write that changes no
@@ -554,7 +554,7 @@ export interface ExtensionNamespaceRule {
554
554
  readonly owner: string;
555
555
  readonly since: string;
556
556
  }
557
- export declare const EXTENSION_NAMESPACES: Partial<Record<DomainName, ReadonlyArray<ExtensionNamespaceRule>>>;
557
+ export declare const EXTENSION_NAMESPACES: Readonly<Partial<Record<DomainName, ReadonlyArray<ExtensionNamespaceRule>>>>;
558
558
  /** 该键是否落在 {@link EXTENSION_NAMESPACES} 登记的扩展命名空间里(⇒ 不是未知键)。**分段匹配**:`at` 对
559
559
  * 父路径的段(长度相等 ∧ 逐段——{@link ANY_INDEX} 匹配任一**数字**段,字符串段逐字相等;顶层 = `[]`),`key` 对键名
560
560
  * 本身——键名里可以含 `.`(`semaX.foo` 是一个键不是两层),段形让这件事不必再靠文法猜;前缀契约就是前缀
@@ -25,6 +25,7 @@ import { carriesUserinfo, secretScanForms } from "./secret-scan.js"; // package-
25
25
  import { sha256Hex } from "./sha256.js";
26
26
  import { unwrapSchema } from "./zod-unwrap.js"; // package-private: the ONE reading of zod's wrapper layers (salvage + the one-time migrations share it)
27
27
  import { DOMAIN_SCHEMAS, InfraCostRates, LimitsConfig, PRIVATE_KEY_PEM_HEADER, RETIRED_DOMAINS, SkillsManifestSchema, WIRE_CARRIED_DOMAINS, containsSecretToken, isDomainName, isRetiredDomainName, renderQuotedSentence, retiredDomainSentence } from "./types.js";
28
+ import { deepFreeze } from "./deep-freeze.js";
28
29
  /** Redact secret-shaped tokens from a validation MESSAGE — a zod error echoes the offending value (e.g.
29
30
  * `received 'sk-live-…'`), so a secret pasted into the WRONG field would leak via the error string. Redacts
30
31
  * space-spanning auth credentials (`Bearer <token>`) FIRST (the token pass can't see across the space), then
@@ -153,8 +154,8 @@ function sanitizeIssueValue(v, depth) {
153
154
  }
154
155
  }
155
156
  }
156
- export const ROLE_RANK = { viewer: 0, editor: 1, publisher: 2, admin: 3 };
157
- export const USER_ROLES = ["viewer", "editor", "publisher", "admin"];
157
+ export const ROLE_RANK = deepFreeze({ viewer: 0, editor: 1, publisher: 2, admin: 3 });
158
+ export const USER_ROLES = deepFreeze(["viewer", "editor", "publisher", "admin"]);
158
159
  /** True if `role` is at least `min` in the hierarchy (e.g. publisher satisfies editor). */
159
160
  export function roleAtLeast(role, min) {
160
161
  return ROLE_RANK[role] >= ROLE_RANK[min];
@@ -170,7 +171,7 @@ export function isRole(v) {
170
171
  * {@link writeRoleFor}, which also looks at WHICH fields a write changes ({@link DOMAIN_FIELD_WRITE_ROLE}).
171
172
  */
172
173
  export const DEFAULT_DOMAIN_WRITE_ROLE = "editor";
173
- export const DOMAIN_WRITE_ROLE = {
174
+ export const DOMAIN_WRITE_ROLE = deepFreeze({
174
175
  skills: "publisher",
175
176
  mcp: "publisher",
176
177
  // plugins are an EXECUTABLE surface (commands/hooks/MCP ride in via the materialized plugin) — the same
@@ -205,7 +206,7 @@ export const DOMAIN_WRITE_ROLE = {
205
206
  // carry its credentials — the same executable-surface + credential-reference profile as mcp, so the same raised gate.
206
207
  // Written out (not left to the default) because the default would be the WRONG answer here.
207
208
  a2a: "publisher",
208
- };
209
+ });
209
210
  /**
210
211
  * `projects`: a registration's identity fields are an index and stay with the floor (`editor`); its CONTENT fields are what the project hands
211
212
  * to the agent — `goal` and `notes` ride into the system prompt, `contextItems` carries folder / file entries the task's workspace and
@@ -235,9 +236,9 @@ const PROJECT_FIELD_WRITE_ROLE = {
235
236
  * one row per domain, an absent row means "the floor decides" — read only through {@link writeRoleFor}; the changed fields come from
236
237
  * {@link changedWriteFields} (the one place that diffs two documents against this table).
237
238
  */
238
- export const DOMAIN_FIELD_WRITE_ROLE = {
239
+ export const DOMAIN_FIELD_WRITE_ROLE = deepFreeze({
239
240
  projects: { entries: "projects", fields: PROJECT_FIELD_WRITE_ROLE },
240
- };
241
+ });
241
242
  /**
242
243
  * The minimum role to make a write that changes exactly `changedFields` in `domain`: the HIGHEST of the domain's floor ({@link DOMAIN_WRITE_ROLE},
243
244
  * else {@link DEFAULT_DOMAIN_WRITE_ROLE}) and the role of each changed field ({@link DOMAIN_FIELD_WRITE_ROLE}). `[]` = a write that changes no
@@ -424,7 +425,7 @@ function outgoingSegment(seg) {
424
425
  * 满射格(每个词至少有一个真丢弃点触发它 = 没有死词;每个被丢条目的词都在表里 = 没有无词的丢弃点)。
425
426
  * 读路径上剔条目的只有 `salvageEntries` 这一处(11.0.0 起 hosts 的读侧夹紧臂已retired),所以本表覆盖读路径上每一条被丢的条目。
426
427
  */
427
- export const DROPPED_ENTRY_REASON_CODES = ["entry-schema-invalid", "entry-key-invalid", "entry-unreadable", "entry-unknown-key"];
428
+ export const DROPPED_ENTRY_REASON_CODES = deepFreeze(["entry-schema-invalid", "entry-key-invalid", "entry-unreadable", "entry-unknown-key"]);
428
429
  /** 可披露身份与出门坐标段的**长度上界**(一只常量,两处用:{@link DISCLOSABLE_IDENTITY_RE} 的上限、{@link outgoingSegment}
429
430
  * 的「超长不扫描」界)。与 web-admin 读侧名长上限 256 对齐。 */
430
431
  const DISCLOSABLE_IDENTITY_MAX = 256;
@@ -521,7 +522,7 @@ function droppedEntry(path, verdict, entry) {
521
522
  return identity === undefined ? base : { ...base, identity };
522
523
  }
523
524
  /** 一次「什么都没丢」的抢救的位移表(冻结的共享空表 —— {@link rebaseWarningPaths} 对它恒等)。 */
524
- const NO_ENTRIES_DROPPED = Object.freeze({});
525
+ const NO_ENTRIES_DROPPED = deepFreeze({});
525
526
  /** 一个域的校验过程抛了(恶意 getter / Proxy 陷阱 / 校验器自己对怪形值做类型转换)⇒ 给调用方的那一句中性话:不带抛出值的文案(可能带 secret),类是 `TypeError`(调用方给的值读不出是调用方的错)。 */
526
527
  function unreadableDomainError(domain) {
527
528
  return new TypeError(`invalid "${domain}" config (a value could not be read during validation)`);
@@ -763,13 +764,13 @@ export function statusRowsToPrune(rows, opts) {
763
764
  * (给联合加一条新臂,实测这三处各红一条,`satisfies` 那行零诊断);而「新 kind 三处都处置了、却忘了登记
764
765
  * 进本表」这半条缝,由 `test/warning-projection-derived-4.0.0.test.ts` 的闭集格看着(本表 == 从 AST 解出的
765
766
  * 臂集,逐字同集同序)。 */
766
- export const WARNING_KINDS = [
767
+ export const WARNING_KINDS = deepFreeze([
767
768
  "domain-defaulted",
768
769
  "unknown-keys-dropped",
769
770
  "unknown-keys-carried",
770
771
  "entry-dropped",
771
772
  "unread-config-file",
772
- ];
773
+ ]);
773
774
  /**
774
775
  * 一条告警 → 它的投影。**闭集穷举**:新 kind 不在这里表态就编译红(#157 的闭集纪律);而字段级的对齐由
775
776
  * {@link WarningProjection} 的派生保证 —— 少铸一个字段,这里就是编译红。
@@ -922,9 +923,9 @@ const DROP_SCAN_MAX_KEYS = 64;
922
923
  * 这两件事零二义,而且字面 `"#"` 仍然是一个可登记的普通段。类型上也不塌:`readonly (string | "#")[]`
923
924
  * 会被 TS 收成 `readonly string[]`(写错通配不编译红),`readonly (string | typeof ANY_INDEX)[]` 不会。 */
924
925
  export const ANY_INDEX = Symbol("settings-schema/any-index");
925
- export const EXTENSION_NAMESPACES = {
926
+ export const EXTENSION_NAMESPACES = deepFreeze({
926
927
  models: [{ at: ["models", ANY_INDEX], key: /^sema[A-Z]/, owner: "cli", since: "shell key census design/cli-190c (2026-08-26)" }],
927
- };
928
+ });
928
929
  /** 该键是否落在 {@link EXTENSION_NAMESPACES} 登记的扩展命名空间里(⇒ 不是未知键)。**分段匹配**:`at` 对
929
930
  * 父路径的段(长度相等 ∧ 逐段——{@link ANY_INDEX} 匹配任一**数字**段,字符串段逐字相等;顶层 = `[]`),`key` 对键名
930
931
  * 本身——键名里可以含 `.`(`semaX.foo` 是一个键不是两层),段形让这件事不必再靠文法猜;前缀契约就是前缀
@@ -1354,7 +1355,7 @@ function announceUnknownKeys(domain, raw, parsed, emit) {
1354
1355
  * strictly better); WORSE, the claim write face is read-modify-write — reading a defaulted-empty
1355
1356
  * ledger and writing it back would CLOBBER existing registrations down to one entry (data loss,
1356
1357
  * one layer beyond the rosters "放权" rationale). */
1357
- export const DOMAIN_READ_FALLBACK = {
1358
+ export const DOMAIN_READ_FALLBACK = deepFreeze({
1358
1359
  models: "default",
1359
1360
  rosters: "throw",
1360
1361
  skills: "throw", // 24.0.0:空 skills = 被中心按名覆盖的出厂技能全部回位(带回它们自己的 allow 名单),不是 fail-closed;与 DOMAIN_ENTRY_SALVAGE 的 none 同一理由
@@ -1378,7 +1379,7 @@ export const DOMAIN_READ_FALLBACK = {
1378
1379
  limits: "throw",
1379
1380
  // a2a(18.0.0):能力目录(同 mcp)—— 整域读不进 ⇒ 空名册 = 不拨任何对端(能力消失,fail-closed;没有闸因此丢掉)。
1380
1381
  a2a: "default",
1381
- };
1382
+ });
1382
1383
  /** Per-domain ENTRY-SALVAGE policy (12.3.0, S-1494) — may the view-face domain reader ({@link parseDomainSalvaged}) drop single bad
1383
1384
  * entries (an array element, a Record value, and — recursively — a bad entry inside a surviving entry) and read the rest?
1384
1385
  * **One question only**: what happens when the domain stays unreadable after that is {@link DOMAIN_READ_FALLBACK}'s question.
@@ -1439,7 +1440,7 @@ export const DOMAIN_READ_FALLBACK = {
1439
1440
  * - a2a: SALVAGE (18.0.0) — the peer roster is a capability catalog like mcp: a dropped peer is one remote agent fewer. A peer's
1440
1441
  * credential references (`headerRefs`) are a value collection: a bad reference drops the whole peer, never the reference
1441
1442
  * alone (a peer kept with half of its credentials is the wrong failure direction). */
1442
- export const DOMAIN_ENTRY_SALVAGE = {
1443
+ export const DOMAIN_ENTRY_SALVAGE = deepFreeze({
1443
1444
  models: "salvage", // 留:条目 = 一个目录模型(及 `roles` 里的一个角色覆盖);缺席 = 少一个模型 / 一个角色回落到缺省 —— 选路变了,可达面没变(被引用的模型缺席 ⇒ 引用悬空 ⇒ 整域缺省,既有律)
1444
1445
  rosters: "none", // 收:条目 = 一台 worker 的模型名册;缺席 ⇒ 该 worker 回落到整份目录 = 放宽
1445
1446
  skills: "none", // 收:条目 = 按名覆盖出厂技能的中心技能(带它自己的工具 allow / deny 名单);缺席 = 同名出厂技能回位(带回它的 allow 名单、丢掉中心的 deny 名单)= 放宽
@@ -1457,7 +1458,7 @@ export const DOMAIN_ENTRY_SALVAGE = {
1457
1458
  prompts: "none", // 收:条目受 digest 约束;缺席 = digest 不再成立,或范围文本替换掉某台 worker 的 artifact(是替换不是收窄)
1458
1459
  limits: "none", // 收:条目 = 已发布上限的一行;缺席 = 发布的天花板变了(本域是这些上限的唯一发布位)
1459
1460
  a2a: "salvage", // 留:条目 = 一个出站对端;缺席 = 少一个对端(凭据引用是值集合、整体判;名字占位同 mcp,见 CHANGELOG 已知限制)
1460
- };
1461
+ });
1461
1462
  /**
1462
1463
  * Merge every domain into the effective config a consumer pulls. Shared by all store impls.
1463
1464
  * `updatedAt` is REQUIRED (the determinism refactor — the original store.ts defaulted it to the wall clock,
@@ -1,5 +1,6 @@
1
1
  import { isPlainJsonObject } from "./plain-json-object.js";
2
2
  import { sha256Digest, toHex } from "./sha256-core.js";
3
+ import { deepFreeze } from "./deep-freeze.js";
3
4
  /** 配置根上的 env 模型表决定文档的名字(文件 `<根>/config.env-models.json`)。 */
4
5
  export const ENV_MODELS_DOCUMENT = "config.env-models";
5
6
  /** 运行记录文档名的前缀(包内:名字 = 前缀 + 迁移 id,文件 = 名字 + `.json`)。 */
@@ -12,15 +13,15 @@ export const migrationMarkerDocument = (id) => `${MIGRATION_MARKER_PREFIX}${id}`
12
13
  * 常规文件、有大小上界)—— 一条律、两张名单(`config.d` 读回面一张,本张一张);`config.d` 不在时也照判。
13
14
  * `<根>/.env` **不在**这张名单:引擎今天的目录信任判官只判 `config.d` 与它的读回面,不判 `.env`(秘密值文件,本包的文件仓库不读它);本名单只登记引擎会读的根级文档。
14
15
  */
15
- export const CONFIG_ROOT_DOCUMENTS = [ENV_MODELS_DOCUMENT, migrationMarkerDocument("SS-M11")];
16
+ export const CONFIG_ROOT_DOCUMENTS = deepFreeze([ENV_MODELS_DOCUMENT, migrationMarkerDocument("SS-M11")]);
16
17
  /** 包内:`id` 是写运行记录的迁移吗(读运行记录之前判:别的 id 没有记录可读,更不许拿它拼路径)。 */
17
18
  export const isMarkedMigrationId = (id) => typeof id === "string" && CONFIG_ROOT_DOCUMENTS.includes(`${MIGRATION_MARKER_PREFIX}${id}`);
18
19
  /** 决定文档里能写的两个词(闭集):`replaced` = 目录管模型面时顶替 env 模型表;`kept` = 不顶替(与缺席同义,运行记录在场之后)。 */
19
- export const ENV_MODELS_DECISIONS = ["replaced", "kept"];
20
+ export const ENV_MODELS_DECISIONS = deepFreeze(["replaced", "kept"]);
20
21
  /** 包内:是不是决定词(闭集,判法只此一只;写函数与读法同调)。 */
21
22
  export const isDecisionWord = (v) => ENV_MODELS_DECISIONS.includes(v);
22
23
  /** 根级文档读不懂的三种原因(闭集):`bad_json` = 空 / 纯空白 / 不是 JSON;`bad_shape` = 是 JSON 但不是这份文档的形;`io` = 字节读不出(权限 —— 可信属主的 0000 文件读恒 `EACCES`,是持久的 —— 不是常规文件、悬空链接、瞬时读错)。 */
23
- export const ROOT_DOCUMENT_UNREADABLE_REASONS = ["bad_json", "bad_shape", "io"];
24
+ export const ROOT_DOCUMENT_UNREADABLE_REASONS = deepFreeze(["bad_json", "bad_shape", "io"]);
24
25
  /**
25
26
  * 一份决定读数的**身份**(带标签的一种拼法):`absent` / `d:<digest>`(有字节的四臂)/ `io:<errno>`。服务端的本地配置腿读这份决定时,「每份内容只告警一次」的去重键与本地 etag 的贡献都取它 ——
26
27
  * 来自同一次读,不再开文件(那就是第二个读者)。
@@ -13,7 +13,7 @@ export interface ConfigRootIo {
13
13
  ensureDirectory(dir: string): Promise<"created" | "present">;
14
14
  }
15
15
  /** 真文件系统的绑定:读先过本包的符号链接判法(链接 ⇒ 它指向的真文件;悬空 ⇒ 抛,不是缺席),只读常规文件;写走本包唯一的原子写器。 */
16
- export declare const nodeConfigRootIo: ConfigRootIo;
16
+ export declare const nodeConfigRootIo: Readonly<ConfigRootIo>;
17
17
  /** 配置根上 env 模型表决定的**唯一读者**(闭集答案见 `EnvModelsDecision`;从字节读出的答案带同一次读的 `digest`,io 带 `errno`)。从不抛。 */
18
18
  export declare function readEnvModelsDecision(root: string, io?: ConfigRootIo): Promise<EnvModelsDecision>;
19
19
  /** {@link readEnvModelsDecision} 的**同步孪生**(壳在同步具名锁里写模型池,要在锁里读决定):同一个字节读法、同一个缺席律、同一个答案表;读真文件系统(不收注入座 —— 注入座是异步的)。从不抛。 */
@@ -29,6 +29,7 @@ import { ENV_MODEL_TABLE_KEYS, buildEnvModelBaseline, snapshotEnvModelTable } fr
29
29
  import { FsFailure, fsFailureMessage } from "./fs-failure.js";
30
30
  import { readKey } from "./own-key-read.js";
31
31
  import { jsonShapeOf } from "./plain-json-object.js";
32
+ import { deepFreeze } from "./deep-freeze.js";
32
33
  /** 根级文档 → 原子写器的模式类(穷举:加一份根级文档不补这一行 ⇒ 编译红,逼着为它选一类)。两份现有的根级文档都是契约文档(只带固定词,不带秘密值),与 `config.d` 域文档同属 `config-document`。 */
33
34
  const ROOT_DOCUMENT_CLASS = {
34
35
  [ENV_MODELS_DOCUMENT]: "config-document",
@@ -41,7 +42,7 @@ const notRegularFile = (file) => new Error(`${file} is not a regular file`);
41
42
  const writeRootDocumentSync = (document, file, text) => writeFileAtomic(file, text, ROOT_DOCUMENT_CLASS[document]);
42
43
  const createRootDocumentSync = (document, file, text) => createFileExclusive(file, text, ROOT_DOCUMENT_CLASS[document]);
43
44
  /** 真文件系统的绑定:读先过本包的符号链接判法(链接 ⇒ 它指向的真文件;悬空 ⇒ 抛,不是缺席),只读常规文件;写走本包唯一的原子写器。 */
44
- export const nodeConfigRootIo = {
45
+ export const nodeConfigRootIo = deepFreeze({
45
46
  readFile: async (file) => {
46
47
  const real = resolveSymlinkTarget(file);
47
48
  const st = await stat(real);
@@ -52,7 +53,7 @@ export const nodeConfigRootIo = {
52
53
  writeDocument: async (document, file, text) => writeRootDocumentSync(document, file, text),
53
54
  createDocument: async (document, file, text) => createRootDocumentSync(document, file, text),
54
55
  ensureDirectory: async (dir) => ensureOwnerOnlyDirectory(dir),
55
- };
56
+ });
56
57
  /** {@link nodeConfigRootIo}`.readFile` 的同步孪生(同步读口 {@link readEnvModelsDecisionSync} 用):同一条判法(符号链接 ⇒ 真文件,悬空抛;只读常规文件),只有读字节那一步同步。 */
57
58
  function readRootFileSync(file) {
58
59
  const real = resolveSymlinkTarget(file);
@@ -3,9 +3,9 @@ import type { WarningProjection } from "./warnings.js";
3
3
  import type { LegName, LegInput, RejectStage } from "./types.js";
4
4
  /** 一条登记在案的表示差异。 */
5
5
  export interface DerivationTransform {
6
- id: string;
7
- legs: readonly LegName[];
8
- what: string;
6
+ readonly id: string;
7
+ readonly legs: readonly LegName[];
8
+ readonly what: string;
9
9
  }
10
10
  /** 变换表(本文件头注的机器形;`docs/CONFORMANCE.md` 与 `test/conformance-coverage.test.ts` 都读它)。 */
11
11
  export declare const DERIVATION_TRANSFORMS: readonly DerivationTransform[];
@@ -39,15 +39,16 @@ import { PORTABLE_DOMAINS } from "../portable-domains.js";
39
39
  import { isJsonArray, isPlainJsonObject } from "../plain-json-object.js";
40
40
  import { skillContentHash } from "../skills-manifest.js";
41
41
  import { DOMAINS, WIRE_CARRIED_DOMAINS, isDomainName } from "../types.js";
42
+ import { deepFreeze } from "../deep-freeze.js";
42
43
  /** 变换表(本文件头注的机器形;`docs/CONFORMANCE.md` 与 `test/conformance-coverage.test.ts` 都读它)。 */
43
- export const DERIVATION_TRANSFORMS = [
44
+ export const DERIVATION_TRANSFORMS = deepFreeze([
44
45
  { id: "T1-wire-carried-domains", legs: ["wire"], what: "buildEffective 恒物化每个域;wire 对 WIRE_CARRIED_DOMAINS(prompts / a2a)按在场性挂回(缺席进缺席出;在场时 prompts 是原文档、a2a 是域腿读数)" },
45
46
  { id: "T2-skills-representation", legs: ["wire"], what: "域形 content ↔ wire 形 contentHash(manifest),判据 schema 随表示走;读法与告警同一只" },
46
47
  { id: "T3-non-portable-domains", legs: ["localRoot"], what: "config.d/ 只读 PORTABLE_DOMAINS;其余域取默认 + unread-config-file{non-portable-domain}" },
47
48
  { id: "T4-unknown-top-level-key", legs: ["wire", "localRoot"], what: "wire open-world 逐字承运;domains 腿按域名取文档故无声;local 报 unread-config-file{not-a-domain}" },
48
49
  { id: "T5-file-layer-first", legs: ["localRoot"], what: "config.d/<域>.json 必须是 JSON 对象(空/null/数组/标量 throw),这一层在域解析之前" },
49
50
  { id: "T6-file-name-classification", legs: ["localRoot"], what: "config.d/ 的文件分三类:域文件 / NON_DOMAIN_CONFIG_FILES(remote-exec.json 自带读取与校验路径)/ 隐藏文件与非 .json(忽略);只有剩下的才报 not-a-domain" },
50
- ];
51
+ ]);
51
52
  /**
52
53
  * 每条腿的期望从哪来 —— 闭集表态(`Record<LegName, …>`:新开一条腿不在这里表态 ⇒ 编译红)。
53
54
  *
@@ -56,7 +57,7 @@ export const DERIVATION_TRANSFORMS = [
56
57
  *
57
58
  * 语料加载器与驱动都读这张表(一条规则),不再各自特判某个腿名。
58
59
  */
59
- export const LEG_EXPECTATION = {
60
+ export const LEG_EXPECTATION = deepFreeze({
60
61
  domains: { source: "explicit", why: "真源:domains 腿的期望就是金样本身" },
61
62
  strictWrite: {
62
63
  source: "explicit",
@@ -64,9 +65,9 @@ export const LEG_EXPECTATION = {
64
65
  },
65
66
  wire: { source: "derivable", why: "T1 / T2 / T4" },
66
67
  localRoot: { source: "derivable", why: "T3 / T4 / T5 / T6" },
67
- };
68
+ });
68
69
  /** 非便携域 —— 由 {@link PORTABLE_DOMAINS} 派生,零手抄。 */
69
- export const NON_PORTABLE_DOMAINS = DOMAINS.filter((d) => !PORTABLE_DOMAINS.includes(d));
70
+ export const NON_PORTABLE_DOMAINS = deepFreeze(DOMAINS.filter((d) => !PORTABLE_DOMAINS.includes(d)));
70
71
  /** 一份 `domains` 文档集里,**不是域名**的那些顶层键(T4 的触发面)。 */
71
72
  export const foreignKeysOf = (docs) => Object.keys(docs).filter((k) => !isDomainName(k));
72
73
  /** T2 的**入参**半场:域形的 skills 文档 → wire 形的 manifest 文档。结构变换,不解析 —— 坏形原样传下去,
@@ -1,11 +1,12 @@
1
+ import { deepFreeze } from "../deep-freeze.js";
1
2
  /** 四条腿的名字表(运行期枚举用;与 {@link LegName} 同源 —— 多一员少一员编译红)。 */
2
- export const LEG_NAMES = ["domains", "strictWrite", "wire", "localRoot"];
3
+ export const LEG_NAMES = deepFreeze(["domains", "strictWrite", "wire", "localRoot"]);
3
4
  /** 严写腿因**悬空引用**拒收时的拒绝码(机读;金样与比对都按它)。 */
4
5
  export const REF_INTEGRITY_REJECT_CODE = "ref-integrity";
5
6
  /** {@link RejectStage} 的运行期表(语料校验用;与类型同源)。 */
6
- export const REJECT_STAGES = ["envelope", "parse", "validate", "hash", "store"];
7
+ export const REJECT_STAGES = deepFreeze(["envelope", "parse", "validate", "hash", "store"]);
7
8
  /** {@link LegDeclineReason} 的运行期表(release 门校验用;与类型同源)。 */
8
- export const LEG_DECLINE_REASONS = ["no-production-path"];
9
+ export const LEG_DECLINE_REASONS = deepFreeze(["no-production-path"]);
9
10
  /** 账本 `ref` 的形 —— 一个台账票号:大写字母起头、`-` 分段、带数字,可带一个小数段与至多两个字符的尾缀(`ABC-12`、`ABC-12②`、
10
11
  * `AB-C3`、`XY-7.3`),没有空白。一段散文(「一个设计稿的章节号 — …」)不是票号:查不到、也到不了期。 */
11
12
  export const LEDGER_REF_RULE = /^(?=[^\s]*\d)[A-Z][A-Z0-9]*(?:-[A-Z0-9]+)+(?:\.[0-9]+)?[^\s]{0,2}$/;
@@ -1,18 +1,19 @@
1
1
  import { formatConfigPath } from "./config-fns.js";
2
2
  import { buildQuotedIssue, fixed, renderQuotedSentence } from "./quoted-issue.js";
3
+ import { deepFreeze } from "./deep-freeze.js";
3
4
  /** What a dangling reference failed to find —— the closed set (S-1075, 11.0.0): one word per referenced domain. */
4
- export const REF_ISSUE_KINDS = ["unknown_model", "unknown_roster", "unknown_worker", "unknown_skill", "unknown_mcp", "unknown_plugin"];
5
+ export const REF_ISSUE_KINDS = deepFreeze(["unknown_model", "unknown_roster", "unknown_worker", "unknown_skill", "unknown_mcp", "unknown_plugin"]);
5
6
  /** The domain a {@link RefIssueKind}'s target lives in. */
6
- export const REF_ISSUE_TARGET_DOMAIN = {
7
+ export const REF_ISSUE_TARGET_DOMAIN = deepFreeze({
7
8
  unknown_model: "models",
8
9
  unknown_roster: "rosters",
9
10
  unknown_worker: "workers",
10
11
  unknown_skill: "skills",
11
12
  unknown_mcp: "mcp",
12
13
  unknown_plugin: "plugins",
13
- };
14
+ });
14
15
  /** The domains whose documents carry cross-domain references (by name) —— the referrer side of the judge. */
15
- export const REF_REFERRER_DOMAINS = ["rosters", "workers", "models", "collab", "systems", "entitlement"];
16
+ export const REF_REFERRER_DOMAINS = deepFreeze(["rosters", "workers", "models", "collab", "systems", "entitlement"]);
16
17
  /** The noun a kind's sentence uses for its target. */
17
18
  function refTargetNoun(kind) {
18
19
  switch (kind) {
@@ -91,7 +92,7 @@ export function createSiblingResolver(store, pending) {
91
92
  *
92
93
  * `satisfies` keeps every member a real domain key; a pin checks it equals referrers ∪ targets. {@link RefCheckedDomain} is
93
94
  * DERIVED from this value. */
94
- export const REF_CHECKED_DOMAINS = ["rosters", "workers", "models", "collab", "systems", "entitlement", "skills", "mcp", "plugins"];
95
+ export const REF_CHECKED_DOMAINS = deepFreeze(["rosters", "workers", "models", "collab", "systems", "entitlement", "skills", "mcp", "plugins"]);
95
96
  /** Runtime narrowing to {@link RefCheckedDomain}, same idiom as `isDomainName`: use it instead of hard-coding
96
97
  * the set when filtering an arbitrary domain key (a batch payload's keys, a rollback target). */
97
98
  export function isRefCheckedDomain(d) {
@@ -36,6 +36,7 @@
36
36
  * 「自己读的是引擎那份」。本包不 import 引擎(纯度不变量;引擎只在 devDependency)。
37
37
  */
38
38
  import { z } from "zod";
39
+ import { deepFreeze } from "./deep-freeze.js";
39
40
  // ── crossSessionInbound ────────────────────────────────────────────────────────────────────────────
40
41
  /**
41
42
  * 显式四值,**顺序即收紧秩**(wake < next-turn < hold < refuse):层次解析只许沿此序收紧,永不放宽。
@@ -45,14 +46,14 @@ import { z } from "zod";
45
46
  * `accept` 的配置在本包响亮 `ok:false` / zod 拒 —— 那一格红就是通知;core 只在**自己的**层里把 `accept`
46
47
  * 读成 `next-turn` 并经 `onError` 报一次(core 的旧拼写读表),那是 core 的持久数据窗,不是本包的契约。
47
48
  */
48
- export const CROSS_SESSION_INBOUND_VALUES = ["wake", "next-turn", "hold", "refuse"];
49
+ export const CROSS_SESSION_INBOUND_VALUES = deepFreeze(["wake", "next-turn", "hold", "refuse"]);
49
50
  /** 设置 UI 的「不设」拼写(见头注)——两键共用同一个字面量。 */
50
51
  export const CROSS_SESSION_INBOUND_UNSET = "default";
51
52
  /** 文件层受理面:四个显式值 + `"default"`(未设)。 */
52
53
  export const CrossSessionInboundSetting = z.enum([...CROSS_SESSION_INBOUND_VALUES, CROSS_SESSION_INBOUND_UNSET]);
53
54
  // ── dialogExpiry ───────────────────────────────────────────────────────────────────────────────────
54
55
  /** 四值闭集(CC 逐字)。`"never"` = 不设期限。 */
55
- export const DIALOG_EXPIRY_VALUES = ["60s", "5m", "10m", "never"];
56
+ export const DIALOG_EXPIRY_VALUES = deepFreeze(["60s", "5m", "10m", "never"]);
56
57
  /** 未设时生效的值(CC 缺省)。 */
57
58
  export const DIALOG_EXPIRY_DEFAULT = "5m";
58
59
  /** 文件层受理面:四个值 + `"default"`(未设 ⇒ 落 {@link DIALOG_EXPIRY_DEFAULT})。 */
@@ -0,0 +1,26 @@
1
+ /**
2
+ * THE one freezer of every closed-set constant this package exports (package-private: not in the barrel, not on any subpath).
3
+ *
4
+ * A closed set — a word table, a code list, a limits record, a row table — is shared by every reader in the process. If one module can
5
+ * `push` / `sort` / assign into it, every other reader's closed set changes with it, while the declared type says `readonly`.
6
+ * So every exported container is frozen at its definition, all the way down, through this one function: the shallow
7
+ * `Object.freeze` of an outer array leaves its rows writable, and a `Set` is not stopped by `Object.freeze` at all.
8
+ *
9
+ * What it freezes — containers of data, reached through plain data properties:
10
+ * · arrays and plain objects (prototype `Object.prototype` or `null`): `Object.freeze`, after their members;
11
+ * · `Set` / `Map`: `Object.freeze` plus own, non-writable mutators (`add` / `delete` / `clear`, `set` / `delete` / `clear`) that throw a
12
+ * `TypeError`, after their members (a Map's keys and values both) and after any property attached to the collection object itself.
13
+ * What it leaves alone: functions, RegExps (stateful by design), symbols, primitives, and any object with another prototype (a zod
14
+ * schema, a class instance) — those are the library's or the class's own objects; a table that HOLDS them is frozen, they are not.
15
+ * Cycles are walked once; freezing the same collection twice (two tables sharing it) is a no-op the second time.
16
+ * The argument is returned (the same reference), typed as itself, so a declaration keeps the exact type it was written with.
17
+ *
18
+ * What a write does afterwards: an array method (`push` / `sort` / `splice` …) and a Set / Map method throw a `TypeError` in any caller;
19
+ * a plain assignment (`a[0] = x`, `t.k = v`, `a.length = 0`, `delete t.k`) throws in strict-mode code (ES modules, class bodies, TypeScript output)
20
+ * and is silently ignored in a sloppy-mode script — either way the constant keeps its value.
21
+ * The Set / Map guard stops every write made through the object's own methods (the accidental, in-process kind this exists for); a caller that reaches for
22
+ * `Set.prototype.add.call(set, x)` on purpose still gets through — the engine offers no way to lock a collection's internal slot, and an array or a plain object has no such hole.
23
+ *
24
+ * `test/closed-set-exports-frozen.test.ts` walks every export of every subpath and fails, by name, on any container this missed.
25
+ */
26
+ export declare function deepFreeze<T>(value: T): T;