@sema-agent/settings-schema 27.2.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 (72) hide show
  1. package/CHANGELOG.md +423 -0
  2. package/README.md +7 -0
  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.js +14 -13
  36. package/dist/hooks-config.d.ts +12 -12
  37. package/dist/hooks-config.js +16 -15
  38. package/dist/hooks.d.ts +5 -5
  39. package/dist/hooks.js +17 -16
  40. package/dist/http-hook-allowlists.js +2 -1
  41. package/dist/index.js +1 -1
  42. package/dist/mcp-request-entry.js +2 -1
  43. package/dist/mcp-server-policy.js +3 -2
  44. package/dist/migration-receipt.d.ts +1 -1
  45. package/dist/migration-receipt.js +3 -2
  46. package/dist/one-time-migrations.js +3 -2
  47. package/dist/own-key-read.d.ts +3 -1
  48. package/dist/plain-json-object.d.ts +6 -3
  49. package/dist/plain-json-object.js +6 -3
  50. package/dist/portable-domains.js +4 -3
  51. package/dist/reserved-member-name.d.ts +1 -1
  52. package/dist/reserved-member-name.js +3 -2
  53. package/dist/resolve-roster.js +3 -2
  54. package/dist/retired-envs.js +3 -6
  55. package/dist/safety-merge-spec.d.ts +11 -4
  56. package/dist/safety-merge-spec.js +5 -4
  57. package/dist/secret-scan.js +1 -1
  58. package/dist/settings-sources.js +6 -5
  59. package/dist/settings-units.js +3 -2
  60. package/dist/types.d.ts +9 -9
  61. package/dist/types.js +27 -26
  62. package/dist/ui-language.js +4 -3
  63. package/dist/url-credential.js +4 -3
  64. package/dist/url-shape.d.ts +1 -1
  65. package/dist/url-shape.js +5 -4
  66. package/dist/web-admin-credential.js +2 -1
  67. package/dist/web-admin-env.d.ts +1 -1
  68. package/dist/web-admin-env.js +4 -3
  69. package/docs/CONSUMER-INTEGRATION.md +22 -2
  70. package/llms-full.txt +3 -2
  71. package/llms.txt +2 -1
  72. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 车道表({@link EXECUTION_LANES})的两只**派生索引** + 「迁移能搬哪些逃生口键」的**一张**表,供 `types.ts`(写闸)与 `one-time-migrations.ts`(一次性迁移 SS-M12)同读。
3
3
  * 本模块是包内私有的:不进 `package.json` 的 `exports`(与 `secret-scan.ts` 同一姿势),主桶也不取它的任何名字 —— 索引、表、谓词是本包的实现细节,消费方只拿车道表本身。
4
- * (必需坐标算不算「缺」的唯一判官 `isBlankCoordinate` 不在这里:它住在零依赖的叶模块 `./execution-lanes`,包根与 `./execution-lanes` 子路径是同一只。)
4
+ * (必需坐标算不算「缺」的唯一判官 `isBlankCoordinate` 不在这里:它住在叶模块 `./execution-lanes`(只 import 包内私有的零 import 叶 `./deep-freeze`),包根与 `./execution-lanes` 子路径是同一只。)
5
5
  * 索引只从表派生,不另存任何词:表改了,这里跟着变。
6
6
  *
7
7
  * ## 迁移指路(7.0.1;11.0.0 起指路句住 `retired-form.ts`;16.0.0 起指路点名**哪一条**迁移)
@@ -10,6 +10,7 @@
10
10
  * 它们的保留名拒句只点名唯一写位。
11
11
  */
12
12
  import { EXECUTION_LANES } from "./execution-lanes.js";
13
+ import { deepFreeze } from "./deep-freeze.js";
13
14
  /** 一条车道的表行。词表与表行由 `execution-lanes.ts` 的 `satisfies Record<ExecutionLane, …>` 一一对应 ——
14
15
  * 找不到 = 本包自身的不变量坏了(不是输入错),所以抛。 */
15
16
  export function laneRowOf(lane) {
@@ -19,17 +20,17 @@ export function laneRowOf(lane) {
19
20
  return row;
20
21
  }
21
22
  /** 车道 env 名 → 归属。四栏两两不交、跨车道不交(`test/execution-lanes-7.0.0.test.ts` 钉),所以每个名恰好一个归属。 */
22
- export const LANE_ENV_OWNER = new Map(EXECUTION_LANES.flatMap((r) => {
23
+ export const LANE_ENV_OWNER = deepFreeze(new Map(EXECUTION_LANES.flatMap((r) => {
23
24
  const own = (names, secret, required) => names.map((k) => [k, { lane: r.lane, secret, required }]);
24
25
  return [...own(r.requiredEnv, false, true), ...own(r.optionalEnv, false, false), ...own(r.requiredSecretEnv, true, true), ...own(r.optionalSecretEnv, true, false)];
25
- }));
26
+ })));
26
27
  /** 一个车道 env 名在 WorkerSpec 里的**唯一写位**(保留键的拒因指路用它)。 */
27
28
  export function laneEnvSeat(name, owner) {
28
29
  return `runtime.execution.${owner.secret ? "secretRefs" : "coords"}.${name}`;
29
30
  }
30
31
  /** 7.0.0 之后才登记进车道表、而登记之前引擎就已在读的车道 env 名 → 改写它的迁移(只增不减;每有一个,在这里写一行)。16.0.0:`DEVICE_RELAY_URL`(device 行的必需坐标;
31
32
  * 此前 device 臂就读它而表漏登记,7.0.0–15.x 的写闸把它当普通 env 收下)→ SS-M12。登记之前没有任何已发引擎读过的新键(17.1.0 `DEVICE_TRUSTED_PROXY_CIDRS`)没有存量旧形可搬,不进本表。 */
32
- export const LATE_LANE_ENV_KEYS = lateLaneEnvKeys([["DEVICE_RELAY_URL", Object.freeze({ migration: "SS-M12", before: "16.0.0", onRow: "a row that declares runtime.execution" })]]);
33
+ export const LATE_LANE_ENV_KEYS = deepFreeze(lateLaneEnvKeys([["DEVICE_RELAY_URL", { migration: "SS-M12", before: "16.0.0", onRow: "a row that declares runtime.execution" }]]));
33
34
  /** 建 {@link LATE_LANE_ENV_KEYS}:每一行的名字必须在车道表里(载入时验,名字拼错 ⇒ 包载入即抛,不静默成一条永不命中的行)。 */
34
35
  function lateLaneEnvKeys(rows) {
35
36
  for (const [name] of rows) {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * 执行车道 + 存储后端的**词表正本**(7.0.0,M-R2 WorkerSpec 结构块)。纯数据常量,外加三只纯判官函数(退役车道词的拒句 `retiredLaneWordRefusal`、
3
- * 车道坐标的空白判官 `isBlankCoordinate`、车道表合法性的唯一判官 `laneSetFlaws`〔18.0.0〕),零依赖(叶模块:本文件不 import 任何东西,`types.ts` 反过来引它)。
3
+ * 车道坐标的空白判官 `isBlankCoordinate`、车道表合法性的唯一判官 `laneSetFlaws`〔18.0.0〕),叶模块(本文件只 import 包内私有的零 import 叶 `./deep-freeze`〔全包闭集常量唯一的冻结入口〕,`types.ts` 反过来引它)。
4
4
  *
5
5
  * ## 为什么在这里
6
6
  * 车道词、每条车道读哪些 env、哪条车道分租户、存储后端词 —— 这几张表以前在四处各抄一份(引擎的能力表、
@@ -190,7 +190,7 @@ export declare const EXECUTION_LANES: readonly ExecutionLaneRow[];
190
190
  * 写闸对所有车道、所有必需坐标同判这一只;本地文件契约 `RemoteExecSpec`(`config.d/remote-exec.json`)的每个非空串字段(镜像 / 命名空间 / 主机 / 路径 / …)问的也是这一只(16.0.0 起:同一个部署声明在两处说,「空白」不再有两种读法);它只判「是不是空白」,不 trim 值、不管值的格式(格式不在这一条的范围:`" sandboxes "` 不是空白)。
191
191
  * 它只答「这个值是不是空白」,不管这个键是必需还是可选:据它**拒不拒**一个坐标,由调用方按键的必需 / 可选决定 —— 写闸只对必需坐标据它拒;个别可选坐标上空串有语义(如 `K8S_RUNTIME_CLASS` 的空串 = 不用 Kata),可选坐标的空串照收。
192
192
  *
193
- * 住在这个零依赖的叶模块里:包根(`export *`)与 `./execution-lanes` 子路径是**同一个函数对象** —— 只想问这一个问题的消费方走子路径,不必冷载入整只契约包桶;
193
+ * 住在这个叶模块里(它只 import 包内私有的零 import 叶 `./deep-freeze`):包根(`export *`)与 `./execution-lanes` 子路径是**同一个函数对象** —— 只想问这一个问题的消费方走子路径,不必冷载入整只契约包桶;
194
194
  * 车道表的派生索引与写闸也从这里 import,全包只有这一处函数体。
195
195
  */
196
196
  export declare function isBlankCoordinate(value: string): boolean;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * 执行车道 + 存储后端的**词表正本**(7.0.0,M-R2 WorkerSpec 结构块)。纯数据常量,外加三只纯判官函数(退役车道词的拒句 `retiredLaneWordRefusal`、
3
- * 车道坐标的空白判官 `isBlankCoordinate`、车道表合法性的唯一判官 `laneSetFlaws`〔18.0.0〕),零依赖(叶模块:本文件不 import 任何东西,`types.ts` 反过来引它)。
3
+ * 车道坐标的空白判官 `isBlankCoordinate`、车道表合法性的唯一判官 `laneSetFlaws`〔18.0.0〕),叶模块(本文件只 import 包内私有的零 import 叶 `./deep-freeze`〔全包闭集常量唯一的冻结入口〕,`types.ts` 反过来引它)。
4
4
  *
5
5
  * ## 为什么在这里
6
6
  * 车道词、每条车道读哪些 env、哪条车道分租户、存储后端词 —— 这几张表以前在四处各抄一份(引擎的能力表、
@@ -44,10 +44,11 @@
44
44
  * (`REMOTE_EXEC=remote-docker` 起服即拒;远端 docker 守护进程今天的真形 = `local-docker` + `DOCKER_HOST`)。
45
45
  * 它在退役词墓碑 {@link RETIRED_LANE_WORDS} 里:读到即拒,拒句带出路。
46
46
  */
47
+ import { deepFreeze } from "./deep-freeze.js";
47
48
  /** 可声明的执行车道闭集(= 引擎 `REMOTE_EXEC` 收的词,逐字同序;18.0.0 尾插 `none`)。 */
48
- export const EXECUTION_LANE_WORDS = ["host", "e2b", "k8s", "ssh", "adb", "local-docker", "device", "none"];
49
- export const RETIRED_LANE_WORDS = Object.freeze([
50
- Object.freeze(["remote-docker", "local-docker", "point it at the remote docker daemon with DOCKER_HOST (in a worker spec: runtime.execution.coords.DOCKER_HOST)"]),
49
+ export const EXECUTION_LANE_WORDS = deepFreeze(["host", "e2b", "k8s", "ssh", "adb", "local-docker", "device", "none"]);
50
+ export const RETIRED_LANE_WORDS = deepFreeze([
51
+ ["remote-docker", "local-docker", "point it at the remote docker daemon with DOCKER_HOST (in a worker spec: runtime.execution.coords.DOCKER_HOST)"],
51
52
  ]);
52
53
  /** 一个车道值是不是退役词:是 ⇒ 带出路的整句;否(现行词、不认识的词、非串)⇒ `undefined`。纯函数。 */
53
54
  export function retiredLaneWordRefusal(word) {
@@ -56,11 +57,11 @@ export function retiredLaneWordRefusal(word) {
56
57
  }
57
58
  /** 车道分不分租户(引擎能力表的 `tenantSeparation` 位,两档,没有「不表态」)。
58
59
  * `supported` = 每个租户的命令落在各自的目标上;`single-user-only` = 所有任务落同一个共享目标 ⇒ 只许单用户 worker。 */
59
- export const TENANT_SEPARATION_WORDS = ["supported", "single-user-only"];
60
+ export const TENANT_SEPARATION_WORDS = deepFreeze(["supported", "single-user-only"]);
60
61
  /** 分租户车道**凭什么**分租户(三档):`isolation` = 每个任务一只隔离的目标(microVM / pod / 容器);`principal-binding` = 目标绑在
61
62
  * 发起者身上(设备 ↔ principal 绑定),目标本身不隔离;`no-execution-target`(18.0.0)= 根本没有执行目标(工具没有执行环境),也就没有跨租户共享的目标 ——
62
63
  * 这一档还带一条集合规则:含这档车道的车道表只能有它这一项(判官 {@link laneSetFlaws} 读这一列)。只有 `tenantSeparation: "supported"` 的车道有依据。 */
63
- export const TENANT_SEPARATION_BASES = ["isolation", "principal-binding", "no-execution-target"];
64
+ export const TENANT_SEPARATION_BASES = deepFreeze(["isolation", "principal-binding", "no-execution-target"]);
64
65
  /** 逐车道一行。`satisfies Record<ExecutionLane, …>` = 词表加词而这里不加行 ⇒ 编译红。 */
65
66
  const LANE_ROWS = {
66
67
  /** server `config.ts` :4014 臂(无必需键);`execution-lane-caps.ts` :209 `single-user-only`(所有任务落 worker 宿主)。 */
@@ -189,18 +190,18 @@ function isStandaloneLane(lane) {
189
190
  /** 独占车道,按词表次序(从依据列现算)。 */
190
191
  const STANDALONE_LANES = EXECUTION_LANE_WORDS.filter(isStandaloneLane);
191
192
  /** 车道表(次序 = {@link EXECUTION_LANE_WORDS})。整张表深冻结 —— 它是唯一正本,消费方拿到的不许被改。 */
192
- export const EXECUTION_LANES = Object.freeze(EXECUTION_LANE_WORDS.map((lane) => {
193
+ export const EXECUTION_LANES = deepFreeze(EXECUTION_LANE_WORDS.map((lane) => {
193
194
  const row = LANE_ROWS[lane];
194
195
  const tenancy = row.tenantSeparation === "supported" ? { tenantSeparation: row.tenantSeparation, tenantSeparationBasis: row.tenantSeparationBasis } : { tenantSeparation: row.tenantSeparation };
195
- return Object.freeze({
196
+ return {
196
197
  lane,
197
198
  ...tenancy,
198
199
  singleReplica: row.singleReplica,
199
- requiredEnv: Object.freeze([...row.requiredEnv]),
200
- requiredSecretEnv: Object.freeze([...row.requiredSecretEnv]),
201
- optionalEnv: Object.freeze([...row.optionalEnv]),
202
- optionalSecretEnv: Object.freeze([...row.optionalSecretEnv]),
203
- });
200
+ requiredEnv: [...row.requiredEnv],
201
+ requiredSecretEnv: [...row.requiredSecretEnv],
202
+ optionalEnv: [...row.optionalEnv],
203
+ optionalSecretEnv: [...row.optionalSecretEnv],
204
+ };
204
205
  }));
205
206
  /**
206
207
  * 车道坐标的**唯一判官**:一个必需坐标「未设 / 空串 / 只含空白」一律算缺。本函数判其中的后两种,且只看**已经有的字符串值**:空串,或只含空白(`String.prototype.trim` 认的空白:空格 / 制表 / 换行 / 不换行空格 / 字节序标记 …)⇒ `true`;
@@ -208,7 +209,7 @@ export const EXECUTION_LANES = Object.freeze(EXECUTION_LANE_WORDS.map((lane) =>
208
209
  * 写闸对所有车道、所有必需坐标同判这一只;本地文件契约 `RemoteExecSpec`(`config.d/remote-exec.json`)的每个非空串字段(镜像 / 命名空间 / 主机 / 路径 / …)问的也是这一只(16.0.0 起:同一个部署声明在两处说,「空白」不再有两种读法);它只判「是不是空白」,不 trim 值、不管值的格式(格式不在这一条的范围:`" sandboxes "` 不是空白)。
209
210
  * 它只答「这个值是不是空白」,不管这个键是必需还是可选:据它**拒不拒**一个坐标,由调用方按键的必需 / 可选决定 —— 写闸只对必需坐标据它拒;个别可选坐标上空串有语义(如 `K8S_RUNTIME_CLASS` 的空串 = 不用 Kata),可选坐标的空串照收。
210
211
  *
211
- * 住在这个零依赖的叶模块里:包根(`export *`)与 `./execution-lanes` 子路径是**同一个函数对象** —— 只想问这一个问题的消费方走子路径,不必冷载入整只契约包桶;
212
+ * 住在这个叶模块里(它只 import 包内私有的零 import 叶 `./deep-freeze`):包根(`export *`)与 `./execution-lanes` 子路径是**同一个函数对象** —— 只想问这一个问题的消费方走子路径,不必冷载入整只契约包桶;
212
213
  * 车道表的派生索引与写闸也从这里 import,全包只有这一处函数体。
213
214
  */
214
215
  export function isBlankCoordinate(value) {
@@ -254,10 +255,10 @@ export function laneSetFlaws(lanes) {
254
255
  return flaws;
255
256
  }
256
257
  /** 存储后端(→ `DB_BACKEND`)。= server `src/config-types.ts` `DB_BACKEND_WORDS`(:67)逐字同序。 */
257
- export const STORE_BACKENDS = ["mysql", "pg", "local", "memory"];
258
+ export const STORE_BACKENDS = deepFreeze(["mysql", "pg", "local", "memory"]);
258
259
  /** session 店(→ `SESSION_BACKEND`)。= server `src/config.ts` :1760 `enumEnv("SESSION_BACKEND", …)` 的词表逐字同序
259
260
  * (`tidb` 不在集内:引擎见之拒启)。 */
260
- export const SESSION_BACKENDS = ["memory", "mysql", "auto"];
261
+ export const SESSION_BACKENDS = deepFreeze(["memory", "mysql", "auto"]);
261
262
  /** 记忆持久面方言(→ `MEMORY_ENGINE_BACKEND`)。16.0.0:MySQL 族那一只叫 `mysql`(此前 `tidb` —— 同一只 SQL 店有店词 `mysql` 与方言 `tidb` 两个字;
262
263
  * 收成一个字,与 {@link STORE_BACKENDS} 同字;硬破坏,`tidb` 读写两面拒、指路一次性迁移 SS-M12)。次序 file → pg → mysql。 */
263
- export const MEMORY_ENGINE_BACKENDS = ["file", "pg", "mysql"];
264
+ export const MEMORY_ENGINE_BACKENDS = deepFreeze(["file", "pg", "mysql"]);
@@ -33,6 +33,7 @@ import { RETIRED_DOMAIN_NAMES, configDPath, configDVersionOf, corruptDocumentRaw
33
33
  import { PORTABLE_DOMAINS } from "./portable-domains.js";
34
34
  import { REMOTE_EXEC_DOCUMENT } from "./remote-exec.js";
35
35
  import { isDomainName, isRetiredDomainName } from "./types.js";
36
+ import { deepFreeze } from "./deep-freeze.js";
36
37
  // 便携域表的定义住在纯叶 ./portable-domains.ts(14.6.0;零 node 依赖,主桶模块可 import);这里原名转出口,`./node` 子路径逐名不变。
37
38
  export { NON_PORTABLE_DOMAIN_REASONS, PORTABLE_DOMAINS } from "./portable-domains.js";
38
39
  /** `config.d/` 里**合法存在但不是域文档**的文件名(不进 `"unread-config-file"` 告警)。`remote-exec`
@@ -41,7 +42,7 @@ export { NON_PORTABLE_DOMAIN_REASONS, PORTABLE_DOMAINS } from "./portable-domain
41
42
  *
42
43
  * **导出**(3.0.0):一致性门的语料派生要按同一张表给本地腿的文件分类(域文件 / 专用文件 / 忽略),
43
44
  * 手抄一份必漂 —— 漂了的那一天,门会把一个合法的 `remote-exec.json` 报成未知文件。 */
44
- export const NON_DOMAIN_CONFIG_FILES = new Set([`${REMOTE_EXEC_DOCUMENT}.json`]);
45
+ export const NON_DOMAIN_CONFIG_FILES = deepFreeze(new Set([`${REMOTE_EXEC_DOCUMENT}.json`]));
45
46
  export class FileConfigStore {
46
47
  root;
47
48
  opts;
package/dist/fleet.js CHANGED
@@ -24,6 +24,7 @@ import { parseDeclared } from "./declared-capture.js";
24
24
  import { dataDescriptor, isolatedObject, readDeclaredKey, ownValueOf } from "./own-key-read.js";
25
25
  import { isPlainJsonObject } from "./plain-json-object.js";
26
26
  import { buildQuotedIssue } from "./quoted-issue.js";
27
+ import { deepFreeze } from "./deep-freeze.js";
27
28
  // ── Web-admin's fleet endpoints (paths, one spelling) ─────────────────────────────────────────────────────
28
29
  /**
29
30
  * Web-admin's `/api/fleet/*` endpoints that are addressed from outside web-admin, relative to its origin. ONE spelling: whoever
@@ -41,13 +42,13 @@ import { buildQuotedIssue } from "./quoted-issue.js";
41
42
  * with the URL-encoded host id); the other values have none and are the path itself. A prefix router (an Ingress rule) takes the
42
43
  * template up to its first `{`.
43
44
  */
44
- export const FLEET_PATHS = {
45
+ export const FLEET_PATHS = deepFreeze({
45
46
  instances: "/api/fleet/instances",
46
47
  usage: "/api/fleet/usage",
47
48
  quotaLeases: "/api/fleet/leases",
48
49
  servingLease: "/api/fleet/live/serving-lease",
49
50
  hostPlanner: "/api/fleet/live/host-planner/{host}",
50
- };
51
+ });
51
52
  /**
52
53
  * The LIVENESS group — the fleet endpoints a web-admin answers without its readiness gate and without its config-governance gates
53
54
  * (they read no config domain and take service credentials only), so that a web-admin whose management face is refused never turns
@@ -60,11 +61,11 @@ export const FLEET_PATHS = {
60
61
  * `@sema-agent/settings-schema/fleet-paths.json` is `{ "FLEET_PATHS": …, "FLEET_LIVE_PATHS": … }`, written from these values at
61
62
  * build time — never edited by hand.
62
63
  */
63
- export const FLEET_LIVE_PATHS = [FLEET_PATHS.instances, FLEET_PATHS.servingLease, FLEET_PATHS.hostPlanner];
64
+ export const FLEET_LIVE_PATHS = deepFreeze([FLEET_PATHS.instances, FLEET_PATHS.servingLease, FLEET_PATHS.hostPlanner]);
64
65
  // ── Domain 1: drain protocol (graceful rolling update — the ground every form stands on) ──────────────────
65
66
  /** Lifecycle of a draining instance. `running`→`draining` on the stop signal; `drained` once in-flight hits
66
67
  * zero (clean) or the grace deadline forces the issue. Exit always follows `drained`. */
67
- export const DRAIN_PHASES = ["running", "draining", "drained"];
68
+ export const DRAIN_PHASES = deepFreeze(["running", "draining", "drained"]);
68
69
  /** Shipped default (server 1.96.0): generous by design — the only unrecoverable loss on restart is the
69
70
  * interactive turn currently streaming, so we wait long rather than cut short. Deployments override via
70
71
  * DRAIN_GRACE_MS; web-admin overrides per-worker through the worker spec. */
@@ -137,7 +138,7 @@ const Generation = z.string().refine(isCanonicalGeneration, buildQuotedIssue `a
137
138
  * Only a fleet member says it: an engine without a generation has no lease and carries no `leaseState` at all (there is no
138
139
  * fifth word for "not a member" — absence is that).
139
140
  */
140
- export const LEASE_STATES = ["none", "granted", "expired", "denied"];
141
+ export const LEASE_STATES = deepFreeze(["none", "granted", "expired", "denied"]);
141
142
  export const LeaseState = z.enum(LEASE_STATES);
142
143
  /**
143
144
  * "This instance must restart to apply config" — the engine's OWN observation (S-741), defined ONCE. It is part of the engine's
@@ -266,18 +267,18 @@ function readSignalBody(body, pick, schema) {
266
267
  * reads as unset (it falls back down the role chain and the engine says so once) — no reading refuses a model plane for it, so it was never
267
268
  * an engine group refusal. A reader still holding it gets it dropped by {@link readModelRefusals} like any code outside the set.
268
269
  */
269
- export const MODEL_ENTRY_REFUSAL_CODES = ["config.model_no_brain", "config.model_entry_invalid", "config.model_route_refused"];
270
+ export const MODEL_ENTRY_REFUSAL_CODES = deepFreeze(["config.model_no_brain", "config.model_entry_invalid", "config.model_route_refused"]);
270
271
  export const ModelEntryRefusalCode = z.enum(MODEL_ENTRY_REFUSAL_CODES);
271
272
  /** The env-model-table confirmation gate's group-refusal code (see {@link MODEL_PLANE_REFUSAL_CODES}). */
272
273
  export const CATALOG_REPLACES_ENV_MODELS_CODE = "config.catalog_replaces_env_models";
273
- export const MODEL_PLANE_REFUSAL_CODES = [
274
+ export const MODEL_PLANE_REFUSAL_CODES = deepFreeze([
274
275
  "config.default_model_missing",
275
276
  "config.model_refused_name_minted",
276
277
  "config.model_route_endpoint_missing",
277
278
  "config.gateway_fallback_without_primary",
278
279
  CATALOG_REPLACES_ENV_MODELS_CODE,
279
280
  "config.model_catalog_refused",
280
- ];
281
+ ]);
281
282
  export const ModelPlaneRefusalCode = z.enum(MODEL_PLANE_REFUSAL_CODES);
282
283
  /**
283
284
  * "This instance does not serve part (or all) of the model catalog it was handed" — the engine's OWN per-host verdict
@@ -445,7 +446,7 @@ export const InstanceHealth = z
445
446
  * - `observer-not-ready` — the reconciler's own observation vetoes it (stored rows only; the SECOND source, AND-merged).
446
447
  * - `draining` — the engine says it is draining.
447
448
  * - `not-ready` — the engine says it is not ready. */
448
- export const NOT_ROUTABLE_CODES = ["no-engine-signal", "stale", "observer-not-ready", "draining", "not-ready"];
449
+ export const NOT_ROUTABLE_CODES = deepFreeze(["no-engine-signal", "stale", "observer-not-ready", "draining", "not-ready"]);
449
450
  const notRoutable = (code) => {
450
451
  switch (code) {
451
452
  case "no-engine-signal":
@@ -652,7 +653,7 @@ export const ServingLeaseRequest = z.object({
652
653
  * - `retired` — web-admin has retired this instance (or the worker it belongs to).
653
654
  * Only {@link ServingLeaseResponse}'s `denied` arm carries a reason; `unknown` has none, by shape.
654
655
  */
655
- export const SERVING_LEASE_DENIED_REASONS = ["superseded", "retired"];
656
+ export const SERVING_LEASE_DENIED_REASONS = deepFreeze(["superseded", "retired"]);
656
657
  export const ServingLeaseDeniedReason = z.enum(SERVING_LEASE_DENIED_REASONS);
657
658
  const ServingLeaseGranted = z.object({ verdict: z.literal("granted"), ttlMs: INTEGER.positive() });
658
659
  const ServingLeaseDenied = z.object({ verdict: z.literal("denied"), reason: ServingLeaseDeniedReason });
@@ -691,7 +692,7 @@ const ServingLeaseDeniedRead = z.object({
691
692
  const ServingLeaseReadFace = z.discriminatedUnion("verdict", [ServingLeaseGranted, ServingLeaseDeniedRead, ServingLeaseUnknown]);
692
693
  /** The verdict words as a runtime list. `satisfies` bites a word the union does not have; the converse (a union arm missing
693
694
  * from this list) is pinned by a test that reads the union's discriminators. */
694
- export const SERVING_LEASE_VERDICTS = ["granted", "denied", "unknown"];
695
+ export const SERVING_LEASE_VERDICTS = deepFreeze(["granted", "denied", "unknown"]);
695
696
  /** Web-admin side: the request body of a serving-lease renewal. Shape mismatch / non-object / throwing accessor ⇒ `undefined`,
696
697
  * never throws (same guarded reader as every other read in this file). */
697
698
  export function readServingLeaseRequest(body) {
@@ -830,7 +831,7 @@ export const DrainRequest = z.object({
830
831
  });
831
832
  /** What a drain request leaves the engine in: `draining` — this call put it into draining; `already_draining` — it already was
832
833
  * (the same action repeated), and the receipt reports the first call's facts. */
833
- export const DRAIN_RECEIPT_STATES = ["draining", "already_draining"];
834
+ export const DRAIN_RECEIPT_STATES = deepFreeze(["draining", "already_draining"]);
834
835
  export const DrainReceiptState = z.enum(DRAIN_RECEIPT_STATES);
835
836
  /** The drain endpoint's answer: the engine's draining fact ({@link EngineDraining} — the same object {@link EngineSignal}
836
837
  * carries as `draining`, extended, not copied) plus how this call found the engine. */
@@ -844,7 +845,7 @@ export function readDrainReceipt(body) {
844
845
  return readSignalBody(body, WHOLE_BODY, DrainReceipt);
845
846
  }
846
847
  // ── Domain 3: dispatch policy (traffic + failover + LB — three domains, one gateway) ──────────────────────
847
- export const DISPATCH_STRATEGIES = ["round-robin", "least-inflight", "consistent-hash"];
848
+ export const DISPATCH_STRATEGIES = deepFreeze(["round-robin", "least-inflight", "consistent-hash"]);
848
849
  /** Per-worker dispatch policy (web-admin-configured; the gateway is OPTIONAL — D3: TOC/self-maintained TOB go
849
850
  * direct, sema-managed fleets route through /api/dispatch). Strategy is an enum on purpose: a new LB
850
851
  * algorithm is a new value, not a new skeleton. */
@@ -108,8 +108,8 @@ declare const HOOK_SHELLS: readonly ["bash", "powershell"];
108
108
  * The row order also decides which field an already-bad entry names (the first wrong one), so a column added later goes at the TAIL of its row (after the shared fields): adding one never
109
109
  * moves an answer the table already gave.
110
110
  */
111
- export declare const HOOK_ENTRY_FIELDS: Readonly<{
112
- command: Readonly<{
111
+ export declare const HOOK_ENTRY_FIELDS: {
112
+ readonly command: {
113
113
  readonly rewakeMessage: "nonEmpty?";
114
114
  readonly rewakeSummary: "nonEmpty?";
115
115
  readonly cloud: "any?";
@@ -123,8 +123,8 @@ export declare const HOOK_ENTRY_FIELDS: Readonly<{
123
123
  readonly async: "boolean?";
124
124
  readonly asyncRewake: "boolean?";
125
125
  readonly onFailure: "onFailure?";
126
- }>;
127
- prompt: Readonly<{
126
+ };
127
+ readonly prompt: {
128
128
  readonly continueOnBlock: "boolean?";
129
129
  readonly if: "string?";
130
130
  readonly timeout: "seconds?";
@@ -132,16 +132,16 @@ export declare const HOOK_ENTRY_FIELDS: Readonly<{
132
132
  readonly once: "boolean?";
133
133
  readonly prompt: "text";
134
134
  readonly model: "string?";
135
- }>;
136
- agent: Readonly<{
135
+ };
136
+ readonly agent: {
137
137
  readonly if: "string?";
138
138
  readonly timeout: "seconds?";
139
139
  readonly statusMessage: "string?";
140
140
  readonly once: "boolean?";
141
141
  readonly prompt: "text";
142
142
  readonly model: "string?";
143
- }>;
144
- http: Readonly<{
143
+ };
144
+ readonly http: {
145
145
  readonly cloud: "any?";
146
146
  readonly if: "string?";
147
147
  readonly timeout: "seconds?";
@@ -151,8 +151,8 @@ export declare const HOOK_ENTRY_FIELDS: Readonly<{
151
151
  readonly headers: "stringRecord?";
152
152
  readonly allowedEnvVars: "stringList?";
153
153
  readonly onFailure: "onFailure?";
154
- }>;
155
- mcp_tool: Readonly<{
154
+ };
155
+ readonly mcp_tool: {
156
156
  readonly if: "string?";
157
157
  readonly timeout: "seconds?";
158
158
  readonly statusMessage: "string?";
@@ -160,8 +160,8 @@ export declare const HOOK_ENTRY_FIELDS: Readonly<{
160
160
  readonly server: "string";
161
161
  readonly tool: "string";
162
162
  readonly input: "record?";
163
- }>;
164
- }>;
163
+ };
164
+ };
165
165
  /** The type of {@link HOOK_ENTRY_FIELDS}: per entry type, field name → field kind (literal types). */
166
166
  export type HookEntryFields = typeof HOOK_ENTRY_FIELDS;
167
167
  type HookFieldBaseValue<B> = B extends "text" | "nonEmpty" | "string" ? string : B extends "shell" ? (typeof HOOK_SHELLS)[number] : B extends "onFailure" ? HookOnFailure : B extends "any" ? unknown : B extends "boolean" ? boolean : B extends "seconds" ? number : B extends "stringRecord" ? Record<string, string> : B extends "stringList" | "argv" ? string[] : B extends "record" ? Record<string, unknown> : never;
@@ -51,6 +51,7 @@
51
51
  import { z } from "zod";
52
52
  import { isPlainJsonObject } from "./plain-json-object.js";
53
53
  import { buildQuotedIssue, fixed } from "./quoted-issue.js";
54
+ import { deepFreeze } from "./deep-freeze.js";
54
55
  // ── event vocabulary ───────────────────────────────────────────────────────────────────────────────────────
55
56
  // The two halves below are where each word came from (CC 2.1.198's own table, then the later additions) — provenance for the
56
57
  // reader of this file, not a contract: they are module-private, and the ONE exported closed set is {@link HOOK_EVENTS}.
@@ -97,7 +98,7 @@ const CC_198_HOOK_EVENTS = [
97
98
  */
98
99
  const POST_198_HOOK_EVENTS = ["CwdChanged", "FileChanged", "MessageDisplay", "DirectoryAdded", "PreModelSwitch", "PostModelSwitch"];
99
100
  /** The full 33-event contract set = CC 198's 27 + the 6 post-198 events — the one exported closed set of hook event names. */
100
- export const HOOK_EVENTS = [...CC_198_HOOK_EVENTS, ...POST_198_HOOK_EVENTS];
101
+ export const HOOK_EVENTS = deepFreeze([...CC_198_HOOK_EVENTS, ...POST_198_HOOK_EVENTS]);
101
102
  /** The guard events (CC 2.1.296 `SV`): their hooks may guard the permissions declared beside them — see the file header. */
102
103
  const HOOK_GUARD_EVENTS = ["PreToolUse", "PermissionRequest"];
103
104
  // ── entry vocabulary and the one field table ───────────────────────────────────────────────────────────────
@@ -107,7 +108,7 @@ const HOOK_GUARD_EVENTS = ["PreToolUse", "PermissionRequest"];
107
108
  * `mcp_tool` (call a tool on an already-configured MCP server). An entry of another type is a bad piece — and in a guard event that rejects
108
109
  * the whole document, which is why `test/upstream-drift.test.ts` ①b holds this set against the CC anchor snapshot.
109
110
  */
110
- export const HOOK_ENTRY_TYPES = ["command", "prompt", "agent", "http", "mcp_tool"];
111
+ export const HOOK_ENTRY_TYPES = deepFreeze(["command", "prompt", "agent", "http", "mcp_tool"]);
111
112
  /**
112
113
  * The `onFailure` closed set (CC `cli309.js:252382`, `onFailure:At()`): what a FAILURE of the hook does — it could not start (a missing script), timed out, exited with a code other
113
114
  * than 0 or 2, or printed JSON that is invalid or fails validation. `continue` (CC's default when the key is absent; this package does not fill it in — an absent key stays absent): the
@@ -115,7 +116,7 @@ export const HOOK_ENTRY_TYPES = ["command", "prompt", "agent", "http", "mcp_tool
115
116
  * CARRIED, not executed here: a consumer that reads `block` executes it or refuses it — ignoring it makes a guard that cannot start let the action through.
116
117
  * The classifier reads this set through a closure-private projection that the compiler ties to it in both directions.
117
118
  */
118
- export const HOOK_ON_FAILURE_WORDS = ["continue", "block"];
119
+ export const HOOK_ON_FAILURE_WORDS = deepFreeze(["continue", "block"]);
119
120
  /**
120
121
  * The words CC gives `cloud` (CC `cli309.js:252382`, `cloud:B(["device","skip"]).optional().catch("skip")`, marked `@internal` there): where this hook may run when a cloud session is driven from the
121
122
  * machine that holds the settings. `device`: offer it to the cloud session and run it on the device even when its script sits where the cloud session can write; `skip`: never offer it to cloud
@@ -124,7 +125,7 @@ export const HOOK_ON_FAILURE_WORDS = ["continue", "block"];
124
125
  * value — {@link classifyHooksConfig} carries whatever is written, as written (it neither judges it, nor folds it to `skip`, nor strips it), and folding to `skip` is the reader's. Carried by `command` and
125
126
  * `http` entries. CARRIED, not executed here.
126
127
  */
127
- export const HOOK_CLOUD_WORDS = ["device", "skip"];
128
+ export const HOOK_CLOUD_WORDS = deepFreeze(["device", "skip"]);
128
129
  /** `shell` values: 'bash' = the user's $SHELL family; 'powershell' = pwsh. Default bash. */
129
130
  const HOOK_SHELLS = ["bash", "powershell"];
130
131
  /** The classifier's reading of {@link HOOK_ON_FAILURE_WORDS}. The classifier is copied as source by consumers' generators, so its closure cannot read an exported name (its one free name
@@ -159,8 +160,8 @@ const HOOK_ENTRY_COMMON_FIELDS = { if: "string?", timeout: "seconds?", statusMes
159
160
  * The row order also decides which field an already-bad entry names (the first wrong one), so a column added later goes at the TAIL of its row (after the shared fields): adding one never
160
161
  * moves an answer the table already gave.
161
162
  */
162
- export const HOOK_ENTRY_FIELDS = Object.freeze({
163
- command: Object.freeze({
163
+ export const HOOK_ENTRY_FIELDS = deepFreeze({
164
+ command: {
164
165
  command: "text",
165
166
  args: "argv?",
166
167
  shell: "shell?",
@@ -171,11 +172,11 @@ export const HOOK_ENTRY_FIELDS = Object.freeze({
171
172
  rewakeMessage: "nonEmpty?",
172
173
  rewakeSummary: "nonEmpty?",
173
174
  cloud: "any?",
174
- }),
175
- prompt: Object.freeze({ prompt: "text", model: "string?", ...HOOK_ENTRY_COMMON_FIELDS, continueOnBlock: "boolean?" }),
176
- agent: Object.freeze({ prompt: "text", model: "string?", ...HOOK_ENTRY_COMMON_FIELDS }),
177
- http: Object.freeze({ url: "text", headers: "stringRecord?", allowedEnvVars: "stringList?", onFailure: "onFailure?", ...HOOK_ENTRY_COMMON_FIELDS, cloud: "any?" }),
178
- mcp_tool: Object.freeze({ server: "string", tool: "string", input: "record?", ...HOOK_ENTRY_COMMON_FIELDS }),
175
+ },
176
+ prompt: { prompt: "text", model: "string?", ...HOOK_ENTRY_COMMON_FIELDS, continueOnBlock: "boolean?" },
177
+ agent: { prompt: "text", model: "string?", ...HOOK_ENTRY_COMMON_FIELDS },
178
+ http: { url: "text", headers: "stringRecord?", allowedEnvVars: "stringList?", onFailure: "onFailure?", ...HOOK_ENTRY_COMMON_FIELDS, cloud: "any?" },
179
+ mcp_tool: { server: "string", tool: "string", input: "record?", ...HOOK_ENTRY_COMMON_FIELDS },
179
180
  });
180
181
  /** The classifier's reading of {@link HOOK_ENTRY_FIELDS}. Same reason and same form as {@link HOOK_ON_FAILURE_ACCEPTED}: the classifier closure cannot read the exported table, so this
181
182
  * is its closure-private projection, spelled out in full (no shared piece with the exported table) and annotated with the exported table's type — a row, a field or a field kind that
@@ -204,7 +205,7 @@ const HOOK_ENTRY_FIELDS_READ = {
204
205
  };
205
206
  // ── classification vocabulary ──────────────────────────────────────────────────────────────────────────────
206
207
  /** What happened to a document's hooks: all loaded / loaded with pieces dropped / the document rejected (nothing in it applies). */
207
- export const HOOKS_CLASSIFICATION_OUTCOMES = ["loaded", "loaded-partial", "rejected"];
208
+ export const HOOKS_CLASSIFICATION_OUTCOMES = deepFreeze(["loaded", "loaded-partial", "rejected"]);
208
209
  /**
209
210
  * Why a piece was DROPPED (closed; one word per level of piece, no `other`):
210
211
  * · `hooks-not-object` — `hooks` is null / a scalar / an array holding only scalars ⇒ the whole `hooks` key goes;
@@ -213,7 +214,7 @@ export const HOOKS_CLASSIFICATION_OUTCOMES = ["loaded", "loaded-partial", "rejec
213
214
  * · `matcher-invalid` — a matcher that is not an object, whose `matcher` is not a string or whose `hooks` is not an array (non-guard event);
214
215
  * · `entry-invalid` — an entry that is not an object, has no / an unknown `type`, or a field outside its kind (non-guard event).
215
216
  */
216
- export const HOOKS_DROPPED_PIECE_CODES = ["hooks-not-object", "unknown-event", "event-not-array", "matcher-invalid", "entry-invalid"];
217
+ export const HOOKS_DROPPED_PIECE_CODES = deepFreeze(["hooks-not-object", "unknown-event", "event-not-array", "matcher-invalid", "entry-invalid"]);
217
218
  /**
218
219
  * Why the document was REJECTED (closed; each is "a guard may be in this piece"):
219
220
  * · `guard-outside-hooks` — a guard sign outside `hooks` (top level, under another key, or the document itself matcher-shaped), or the document could not be read at all (path `[]`);
@@ -223,14 +224,14 @@ export const HOOKS_DROPPED_PIECE_CODES = ["hooks-not-object", "unknown-event", "
223
224
  * · `guard-matcher-invalid` — a bad matcher in a guard event, or a matcher holding a sign (in any event);
224
225
  * · `guard-entry-invalid` — a bad entry in a guard event, or an entry holding a sign (in any event).
225
226
  */
226
- export const HOOKS_REJECTION_CODES = [
227
+ export const HOOKS_REJECTION_CODES = deepFreeze([
227
228
  "guard-outside-hooks",
228
229
  "hooks-is-matcher",
229
230
  "guard-under-unknown-event",
230
231
  "guard-event-not-array",
231
232
  "guard-matcher-invalid",
232
233
  "guard-entry-invalid",
233
- ];
234
+ ]);
234
235
  /** The value's shape — six words: `plain` is a JSON object (not null, not an array, prototype null or a prototype whose own prototype is null: any realm's `Object.prototype`),
235
236
  * `uninspectable` is a value whose shape cannot be read at all (a proxy that has been revoked, a throwing `getPrototypeOf` trap). This function IS `./plain-json-object`'s `jsonShapeOf`, character for
236
237
  * character: the classifier is copied as source by consumers' generators, so its closure cannot import — the package has this one second copy, and the test is what keeps it from drifting. */
package/dist/hooks.d.ts CHANGED
@@ -268,8 +268,8 @@ export type AssistantTurnError = z.infer<typeof AssistantTurnError>;
268
268
  /** SessionEnd `reason` values (CC EXIT_REASONS). */
269
269
  export declare const SESSION_EXIT_REASONS: readonly ["clear", "resume", "logout", "prompt_input_exit", "other", "bypass_permissions_disabled"];
270
270
  export declare const SessionExitReason: z.ZodEnum<{
271
- other: "other";
272
271
  clear: "clear";
272
+ other: "other";
273
273
  resume: "resume";
274
274
  logout: "logout";
275
275
  prompt_input_exit: "prompt_input_exit";
@@ -417,8 +417,8 @@ export declare const SessionEndHookInput: z.ZodObject<{
417
417
  agent_type: z.ZodOptional<z.ZodString>;
418
418
  hook_event_name: z.ZodLiteral<"SessionEnd">;
419
419
  reason: z.ZodEnum<{
420
- other: "other";
421
420
  clear: "clear";
421
+ other: "other";
422
422
  resume: "resume";
423
423
  logout: "logout";
424
424
  prompt_input_exit: "prompt_input_exit";
@@ -800,8 +800,8 @@ export declare const FileChangedHookInput: z.ZodObject<{
800
800
  hook_event_name: z.ZodLiteral<"FileChanged">;
801
801
  file_path: z.ZodString;
802
802
  event: z.ZodEnum<{
803
- change: "change";
804
803
  add: "add";
804
+ change: "change";
805
805
  unlink: "unlink";
806
806
  }>;
807
807
  }, z.core.$strip>;
@@ -1027,8 +1027,8 @@ export declare const HookInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
1027
1027
  agent_type: z.ZodOptional<z.ZodString>;
1028
1028
  hook_event_name: z.ZodLiteral<"SessionEnd">;
1029
1029
  reason: z.ZodEnum<{
1030
- other: "other";
1031
1030
  clear: "clear";
1031
+ other: "other";
1032
1032
  resume: "resume";
1033
1033
  logout: "logout";
1034
1034
  prompt_input_exit: "prompt_input_exit";
@@ -1385,8 +1385,8 @@ export declare const HookInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
1385
1385
  hook_event_name: z.ZodLiteral<"FileChanged">;
1386
1386
  file_path: z.ZodString;
1387
1387
  event: z.ZodEnum<{
1388
- change: "change";
1389
1388
  add: "add";
1389
+ change: "change";
1390
1390
  unlink: "unlink";
1391
1391
  }>;
1392
1392
  }, z.core.$strip>, z.ZodObject<{
package/dist/hooks.js CHANGED
@@ -42,6 +42,7 @@
42
42
  import { z } from "zod";
43
43
  import { HOOK_EVENTS } from "./hooks-config.js";
44
44
  import { INTEGER } from "./integer.js";
45
+ import { deepFreeze } from "./deep-freeze.js";
45
46
  export * from "./hooks-config.js";
46
47
  // ── event set ──────────────────────────────────────────────────────────────────────────────────────────
47
48
  // The ONE closed set of hook event names is {@link HOOK_EVENTS} (`./hooks-config`, re-exported above; drift-gated against CC).
@@ -63,7 +64,7 @@ export const HookOwner = z.enum(["engine", "shell"]);
63
64
  * contract than a member's row does not know the member is engine-owned. A consumer that routes by this set must not keep its own
64
65
  * table of "which member joined at which version".
65
66
  */
66
- export const ENGINE_OWNED_HOOK_EVENTS = [
67
+ export const ENGINE_OWNED_HOOK_EVENTS = deepFreeze([
67
68
  "PreToolUse",
68
69
  "PostToolUse",
69
70
  "PostToolUseFailure",
@@ -74,9 +75,9 @@ export const ENGINE_OWNED_HOOK_EVENTS = [
74
75
  "StopFailure",
75
76
  "UserPromptSubmit",
76
77
  "PermissionDenied",
77
- ];
78
+ ]);
78
79
  /** owner per event — single owner; the non-owner side never fires it (dedup rule). */
79
- export const HOOK_EVENT_OWNER = Object.fromEntries(HOOK_EVENTS.map((e) => [e, ENGINE_OWNED_HOOK_EVENTS.includes(e) ? "engine" : "shell"]));
80
+ export const HOOK_EVENT_OWNER = deepFreeze(Object.fromEntries(HOOK_EVENTS.map((e) => [e, ENGINE_OWNED_HOOK_EVENTS.includes(e) ? "engine" : "shell"])));
80
81
  /**
81
82
  * The first version of THIS package whose {@link ENGINE_OWNED_HOOK_EVENTS} carried each member — the contract version from which a peer that
82
83
  * embeds this package treats the event as engine-owned (the server reports its embedded version as `settingsContract.version` on
@@ -91,7 +92,7 @@ export const HOOK_EVENT_OWNER = Object.fromEntries(HOOK_EVENTS.map((e) => [e, EN
91
92
  *
92
93
  * Frozen: every reader in a process shares it. Read it through {@link engineOwnsHookEventAt}; do not compare against it by hand.
93
94
  */
94
- export const ENGINE_OWNED_HOOK_EVENT_SINCE = Object.freeze({
95
+ export const ENGINE_OWNED_HOOK_EVENT_SINCE = deepFreeze({
95
96
  PreToolUse: "1.0.0",
96
97
  PostToolUse: "1.0.0",
97
98
  PostToolUseFailure: "1.0.0",
@@ -138,7 +139,7 @@ export function engineOwnsHookEventAt(event, contractVersion) {
138
139
  * ignored for the event; every entry matches). Ported from the shell's getMatchingHooks switch. HOW the matcher is read
139
140
  * against that field is {@link hookMatcherSelects} (the one reading).
140
141
  */
141
- export const HOOK_EVENT_MATCHER_FIELD = {
142
+ export const HOOK_EVENT_MATCHER_FIELD = deepFreeze({
142
143
  PreToolUse: "tool_name",
143
144
  PostToolUse: "tool_name",
144
145
  PostToolUseFailure: "tool_name",
@@ -174,7 +175,7 @@ export const HOOK_EVENT_MATCHER_FIELD = {
174
175
  // matcher can scope a hook to "only when switching TO this model".
175
176
  PreModelSwitch: "to_model",
176
177
  PostModelSwitch: "to_model",
177
- };
178
+ });
178
179
  // ── shared enums (CC-verbatim) ─────────────────────────────────────────────────────────────────────────
179
180
  export const PermissionBehavior = z.enum(["allow", "deny", "ask"]);
180
181
  export const PermissionMode = z.enum(["default", "acceptEdits", "bypassPermissions", "plan", "dontAsk"]);
@@ -209,14 +210,14 @@ export const AssistantTurnError = z.enum([
209
210
  "max_output_tokens",
210
211
  ]);
211
212
  /** SessionEnd `reason` values (CC EXIT_REASONS). */
212
- export const SESSION_EXIT_REASONS = [
213
+ export const SESSION_EXIT_REASONS = deepFreeze([
213
214
  "clear",
214
215
  "resume",
215
216
  "logout",
216
217
  "prompt_input_exit",
217
218
  "other",
218
219
  "bypass_permissions_disabled",
219
- ];
220
+ ]);
220
221
  export const SessionExitReason = z.enum(SESSION_EXIT_REASONS);
221
222
  // ── per-event input payloads (CC-verbatim field names: hook_event_name / session_id / cwd + extras) ────
222
223
  /**
@@ -388,7 +389,7 @@ export const ElicitationResultHookInput = BaseHookInput.extend({
388
389
  action: z.enum(["accept", "decline", "cancel"]),
389
390
  content: z.record(z.string(), z.unknown()).optional(),
390
391
  });
391
- export const CONFIG_CHANGE_SOURCES = ["user_settings", "project_settings", "local_settings", "policy_settings", "skills"];
392
+ export const CONFIG_CHANGE_SOURCES = deepFreeze(["user_settings", "project_settings", "local_settings", "policy_settings", "skills"]);
392
393
  export const ConfigChangeHookInput = BaseHookInput.extend({
393
394
  hook_event_name: z.literal("ConfigChange"),
394
395
  source: z.enum(CONFIG_CHANGE_SOURCES),
@@ -402,8 +403,8 @@ export const WorktreeRemoveHookInput = BaseHookInput.extend({
402
403
  hook_event_name: z.literal("WorktreeRemove"),
403
404
  worktree_path: z.string(),
404
405
  });
405
- export const INSTRUCTIONS_LOAD_REASONS = ["session_start", "nested_traversal", "path_glob_match", "include", "compact"];
406
- export const INSTRUCTIONS_MEMORY_TYPES = ["User", "Project", "Local", "Managed"];
406
+ export const INSTRUCTIONS_LOAD_REASONS = deepFreeze(["session_start", "nested_traversal", "path_glob_match", "include", "compact"]);
407
+ export const INSTRUCTIONS_MEMORY_TYPES = deepFreeze(["User", "Project", "Local", "Managed"]);
407
408
  export const InstructionsLoadedHookInput = BaseHookInput.extend({
408
409
  hook_event_name: z.literal("InstructionsLoaded"),
409
410
  file_path: z.string(),
@@ -438,7 +439,7 @@ export const MessageDisplayHookInput = BaseHookInput.extend({
438
439
  delta: z.string(),
439
440
  });
440
441
  /** How a directory joined the session working set: the `/add-dir` slash command or repo-root registration. */
441
- export const DIRECTORY_ADDED_SOURCES = ["slash_command", "register_repo_root"];
442
+ export const DIRECTORY_ADDED_SOURCES = deepFreeze(["slash_command", "register_repo_root"]);
442
443
  /**
443
444
  * Fired after a directory joins the session's working set (CC 2.1.219; agent-types hooks.d.ts:582-586 —
444
445
  * `directory` is the absolute path). Shell-owned; matcher ignored; no hookSpecificOutput arm upstream.
@@ -454,10 +455,10 @@ export const DirectoryAddedHookInput = BaseHookInput.extend({
454
455
  * set_model), while `PostModelSwitch` also reports changes nobody requested (`auto` = automatic fallback,
455
456
  * `resume` = model restored while resuming a session) — those have no "before" to gate.
456
457
  */
457
- export const MODEL_SWITCH_SOURCES = {
458
+ export const MODEL_SWITCH_SOURCES = deepFreeze({
458
459
  pre: ["command", "picker", "sdk"],
459
460
  post: ["command", "picker", "sdk", "auto", "resume"],
460
- };
461
+ });
461
462
  /** The fields both model-switch events carry (CC-verbatim): the models, what was asked for, and the
462
463
  * cache-forfeit estimate a hook needs to decide whether the switch is worth it. */
463
464
  const ModelSwitchFields = {
@@ -648,12 +649,12 @@ export const HookOutput = z.union([AsyncHookOutput, SyncHookOutput]);
648
649
  // `prompt` / `agent` / `http` / `mcp_tool` hook types are part of the config contract (`HOOK_ENTRY_TYPES`); a runner
649
650
  // may phase them in after `command` — config validity is not phased (`classifyHooksConfig` is the one reading of it).
650
651
  /** Env names the hook runner injects into a command hook's environment (CC-parity). */
651
- export const HOOK_INJECTED_ENV = [
652
+ export const HOOK_INJECTED_ENV = deepFreeze([
652
653
  /** Absolute path of the project/workspace root. */
653
654
  "CLAUDE_PROJECT_DIR",
654
655
  /** SessionStart only: file a hook may append `KEY=value` lines to, persisted into the session env. */
655
656
  "CLAUDE_ENV_FILE",
656
- ];
657
+ ]);
657
658
  /** Default per-hook timeout when an entry does not set one (seconds; CC default). */
658
659
  export const DEFAULT_HOOK_TIMEOUT_SECONDS = 60;
659
660
  /** The characters a matcher may consist of to be read as a NAME LIST rather than a regex. */