@sema-agent/settings-schema 27.2.0 → 29.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 (221) hide show
  1. package/CHANGELOG.md +753 -0
  2. package/README.md +88 -12
  3. package/conformance/VERSION +1 -1
  4. package/conformance/cases/c01-entry-salvage-then-typo/expected.json +1 -1
  5. package/conformance/cases/c02-hosts-clamp-stacked/expected.json +1 -1
  6. package/conformance/cases/c03-literal-dotted-top-key/expected.json +1 -1
  7. package/conformance/cases/c04-all-bad-collection-not-salvaged/expected.json +1 -1
  8. package/conformance/cases/c07-hooks-is-not-a-config-domain/expected.json +1 -1
  9. package/conformance/cases/c08-limits-unknown-carried-64/expected.json +1 -1
  10. package/conformance/cases/c09-limits-unknown-carried-65/expected.json +1 -1
  11. package/conformance/cases/c10-record-key-secret-redacted-twice/expected.json +1 -1
  12. package/conformance/cases/c11-unicode-unknown-keys/expected.json +1 -1
  13. package/conformance/cases/c12-prototype-name-top-keys/expected.json +1 -1
  14. package/conformance/cases/c13-models-field-null/expected.json +1 -1
  15. package/conformance/cases/c14-models-field-empty-array/expected.json +1 -1
  16. package/conformance/cases/c15-models-field-number/expected.json +1 -1
  17. package/conformance/cases/c18-wire-envelope-not-an-object/expected.json +1 -1
  18. package/conformance/cases/c19-wire-envelope-no-version/expected.json +1 -1
  19. package/conformance/cases/c21-governance-empty-object-wins/expected.json +1 -1
  20. package/conformance/cases/c23-mixed-validity-models/expected.json +1 -1
  21. package/conformance/cases/c24-valid-entries-with-unknown-keys/expected.json +1 -1
  22. package/conformance/cases/c25-published-roundtrip-zero-warnings/expected.json +1 -1
  23. package/conformance/cases/c26-hosts-array-1024/expected.json +1 -1
  24. package/conformance/cases/c27-hosts-array-1025/expected.json +1 -1
  25. package/conformance/cases/c28-large-document-over-1mb/expected.json +1 -1
  26. package/conformance/cases/c29-salvage-then-domain-refine-fails/expected.json +1 -1
  27. package/conformance/cases/c30-version-triple-a-first/expected.json +1 -1
  28. package/conformance/cases/c31-version-triple-b-changed/expected.json +1 -1
  29. package/conformance/cases/c32-version-triple-a-restored/expected.json +1 -1
  30. package/conformance/cases/c33-limits-nested-carried-key/expected.json +1 -1
  31. package/conformance/cases/c34-skills-content-vs-manifest/expected.json +1 -1
  32. package/conformance/cases/c36-skills-entry-without-content/expected.json +1 -1
  33. package/conformance/cases/c38-remote-exec-is-a-non-domain-file/expected.json +1 -1
  34. package/conformance/cases/c39-hidden-file-in-config-d/expected.json +1 -1
  35. package/conformance/cases/c40-s712-identity-only-what-reads-out/expected.json +1 -1
  36. package/conformance/cases/c41-s792-encoded-pem-identity/expected.json +1 -1
  37. package/conformance/cases/c42-s792-unknown-key-secret-redacted/expected.json +1 -1
  38. package/conformance/cases/c43-s792-form-and-deep-encoded-pem/expected.json +1 -1
  39. package/conformance/cases/c44-s792-utf8-escape-glued-token/expected.json +1 -1
  40. package/conformance/cases/c45-s792-identity-bounds-and-decode-depth/expected.json +1 -1
  41. package/conformance/cases/c46-s811-host-name-url-userinfo-withheld/expected.json +1 -1
  42. package/conformance/cases/c47-s811-roles-key-url-userinfo-withheld/expected.json +1 -1
  43. package/conformance/cases/c48-s935-model-headers-transported/expected.json +1 -1
  44. package/conformance/cases/c49-s935-model-headers-secret-entry-dropped/expected.json +1 -1
  45. package/conformance/cases/c50-s784-lane-host-legal/expected.json +1 -1
  46. package/conformance/cases/c51-s784-lane-e2b-legal/expected.json +1 -1
  47. package/conformance/cases/c52-s784-lane-k8s-legal/expected.json +1 -1
  48. package/conformance/cases/c53-s784-lane-ssh-legal/expected.json +1 -1
  49. package/conformance/cases/c54-s784-lane-adb-legal/expected.json +1 -1
  50. package/conformance/cases/c55-s784-lane-local-docker-legal/expected.json +1 -1
  51. package/conformance/cases/c56-s784-lane-device-legal/expected.json +1 -1
  52. package/conformance/cases/c57-s784-g1-enabled-no-lane/expected.json +1 -1
  53. package/conformance/cases/c58-s784-g2-multitenant-host/expected.json +1 -1
  54. package/conformance/cases/c59-s784-g3-k8s-missing-image/expected.json +1 -1
  55. package/conformance/cases/c60-s784-g3-e2b-missing-key/expected.json +1 -1
  56. package/conformance/cases/c61-s784-g3-other-lane-key/expected.json +1 -1
  57. package/conformance/cases/c62-s784-g7a-session-tidb/expected.json +1 -1
  58. package/conformance/cases/c63-s784-host-two-replicas/expected.json +1 -1
  59. package/conformance/cases/c64-s784-multitenant-local-store/expected.json +1 -1
  60. package/conformance/cases/c65-s784-pg-without-db/expected.json +1 -1
  61. package/conformance/cases/c66-s784-memory-backend-mismatch/expected.json +1 -1
  62. package/conformance/cases/c67-s784-retired-field-loud/expected.json +1 -1
  63. package/conformance/cases/c68-s784-device-local-store/expected.json +1 -1
  64. package/conformance/cases/c69-deep-encoded-token-past-every-reading/expected.json +1 -1
  65. package/conformance/cases/c70-rewritten-token-in-front-of-encoded-pem-header/expected.json +1 -1
  66. package/conformance/cases/c71-one-scanner-write-reads-display-forms/expected.json +1 -1
  67. package/conformance/cases/c72-dangling-reference-write-seat-refuses/expected.json +1 -1
  68. package/conformance/cases/c73-projects-extended-registration-reads/expected.json +1 -1
  69. package/conformance/cases/c74-projects-over-bound-refused/expected.json +3 -72
  70. package/conformance/cases/c75-projects-patch-remote-uniqueness/expected.json +3 -72
  71. package/conformance/cases/c76-projects-entry-salvage-nested/expected.json +1 -1
  72. package/conformance/cases/c77-prompts-center-artifact-carried/expected.json +1 -1
  73. package/conformance/cases/c78-prompts-empty-bindings-refused/expected.json +1 -1
  74. package/conformance/cases/c79-prompts-bad-worker-artifact-not-salvaged/expected.json +1 -1
  75. package/conformance/cases/c80-prompts-wire-v2-verbatim/expected.json +1 -1
  76. package/conformance/cases/c81-prompts-declaration-bindings-refused/expected.json +1 -1
  77. package/conformance/cases/c82-prompts-v1-catalog-refused/expected.json +1 -1
  78. package/conformance/cases/c83-prompts-bad-overlay-not-salvaged/expected.json +1 -1
  79. package/conformance/cases/c84-sandbox-git-block-carried-verbatim/expected.json +1 -1
  80. package/conformance/cases/c85-sandbox-git-refused-block-still-carried/expected.json +1 -1
  81. package/conformance/cases/c86-a2a-peers-legal/expected.json +1 -1
  82. package/conformance/cases/c87-a2a-credential-refs-not-partially-salvaged/expected.json +1 -1
  83. package/conformance/cases/c88-projects-content-attestation-carried/expected.json +1 -1
  84. package/conformance/cases/c89-projects-content-attestation-malformed/expected.json +1 -1
  85. package/conformance/cases/c90-mcp-assertion-credential-carried/expected.json +143 -0
  86. package/conformance/cases/c90-mcp-assertion-credential-carried/input.json +30 -0
  87. package/conformance/cases/c90-mcp-assertion-credential-carried/meta.json +6 -0
  88. package/conformance/cases/c91-mcp-assertion-header-retired-entry-dropped/expected.json +105 -0
  89. package/conformance/cases/c91-mcp-assertion-header-retired-entry-dropped/input.json +27 -0
  90. package/conformance/cases/c91-mcp-assertion-header-retired-entry-dropped/meta.json +6 -0
  91. package/conformance/cases/c92-mcp-principal-header-with-assertion-dropped/expected.json +105 -0
  92. package/conformance/cases/c92-mcp-principal-header-with-assertion-dropped/input.json +31 -0
  93. package/conformance/cases/c92-mcp-principal-header-with-assertion-dropped/meta.json +6 -0
  94. package/conformance/cases/c93-mcp-header-refs-with-credentials-dropped/expected.json +105 -0
  95. package/conformance/cases/c93-mcp-header-refs-with-credentials-dropped/input.json +33 -0
  96. package/conformance/cases/c93-mcp-header-refs-with-credentials-dropped/meta.json +6 -0
  97. package/conformance/cases/c94-mcp-credentials-env-kind-dropped/expected.json +105 -0
  98. package/conformance/cases/c94-mcp-credentials-env-kind-dropped/input.json +32 -0
  99. package/conformance/cases/c94-mcp-credentials-env-kind-dropped/meta.json +6 -0
  100. package/conformance/cases/c95-mcp-credentials-audience-not-connector-id-dropped/expected.json +105 -0
  101. package/conformance/cases/c95-mcp-credentials-audience-not-connector-id-dropped/input.json +30 -0
  102. package/conformance/cases/c95-mcp-credentials-audience-not-connector-id-dropped/meta.json +6 -0
  103. package/conformance/cases/c96-mcp-credentials-extra-member-dropped/expected.json +105 -0
  104. package/conformance/cases/c96-mcp-credentials-extra-member-dropped/input.json +31 -0
  105. package/conformance/cases/c96-mcp-credentials-extra-member-dropped/meta.json +6 -0
  106. package/conformance/cases/cc01-mcp-toolfaces-non-object/expected.json +1 -1
  107. package/conformance/cases/cc02-mcp-source-key-is-transported/expected.json +1 -1
  108. package/conformance/cases/cc03-model-compat-unknown-subkey/expected.json +1 -1
  109. package/conformance/cases/cli01-model-name-nfc-vs-nfd/expected.json +1 -1
  110. package/conformance/cases/cli02-control-and-zero-width-chars/expected.json +1 -1
  111. package/conformance/cases/cli03-credential-pasted-into-unknown-key/expected.json +1 -1
  112. package/conformance/cases/cli04-env-value-with-newline/expected.json +1 -1
  113. package/conformance/cases/cli05-long-and-prefix-colliding-names/expected.json +1 -1
  114. package/conformance/cases/t01-absent-domain-key-not-null/expected.json +1 -1
  115. package/conformance/cases/t03-prototype-name-key-not-swallowed/expected.json +1 -1
  116. package/conformance/cases/t04-secret-literal-never-in-warning-value/expected.json +1 -1
  117. package/conformance/cases/z01-every-domain-empty-object/expected.json +1 -1
  118. package/conformance/cases/z02-every-domain-unknown-key/expected.json +1 -1
  119. package/dist/api/auth-bridge.js +4 -3
  120. package/dist/api/auth.js +6 -5
  121. package/dist/api/credentials.js +14 -15
  122. package/dist/api/lifecycle-events.d.ts +266 -0
  123. package/dist/api/lifecycle-events.js +169 -0
  124. package/dist/api/pull-token.js +2 -1
  125. package/dist/api/scopes.js +5 -4
  126. package/dist/api/wire-scalars.d.ts +13 -0
  127. package/dist/api/wire-scalars.js +15 -0
  128. package/dist/atomic-write.d.ts +4 -0
  129. package/dist/atomic-write.js +26 -3
  130. package/dist/center-refs.js +3 -2
  131. package/dist/config-d-file.d.ts +1 -1
  132. package/dist/config-dir-io.d.ts +1 -1
  133. package/dist/config-dir-io.js +3 -2
  134. package/dist/config-document-refusal.d.ts +5 -5
  135. package/dist/config-document-refusal.js +2 -1
  136. package/dist/config-fns.d.ts +5 -5
  137. package/dist/config-fns.js +17 -16
  138. package/dist/config-root-documents.d.ts +1 -1
  139. package/dist/config-root-documents.js +4 -3
  140. package/dist/config-root-node.d.ts +1 -1
  141. package/dist/config-root-node.js +5 -3
  142. package/dist/conformance/corpus.d.ts +1 -1
  143. package/dist/conformance/derive.d.ts +16 -8
  144. package/dist/conformance/derive.js +41 -24
  145. package/dist/conformance/index.d.ts +1 -1
  146. package/dist/conformance/index.js +1 -1
  147. package/dist/conformance/run.js +8 -9
  148. package/dist/conformance/types.js +4 -3
  149. package/dist/connector-authorize-url.d.ts +23 -0
  150. package/dist/connector-authorize-url.js +129 -0
  151. package/dist/connector-id.d.ts +23 -0
  152. package/dist/connector-id.js +27 -0
  153. package/dist/cross-domain.js +6 -5
  154. package/dist/cross-session.js +3 -2
  155. package/dist/deep-freeze.d.ts +26 -0
  156. package/dist/deep-freeze.js +69 -0
  157. package/dist/default-model.js +2 -1
  158. package/dist/device-relay.d.ts +1 -1
  159. package/dist/device-relay.js +1 -1
  160. package/dist/env-model-table.js +2 -1
  161. package/dist/execution-lane-index.d.ts +1 -1
  162. package/dist/execution-lane-index.js +5 -4
  163. package/dist/execution-lanes.d.ts +2 -2
  164. package/dist/execution-lanes.js +18 -17
  165. package/dist/file-edit.d.ts +44 -0
  166. package/dist/file-edit.js +70 -1
  167. package/dist/file-store.d.ts +12 -7
  168. package/dist/file-store.js +72 -59
  169. package/dist/fleet.js +14 -13
  170. package/dist/hooks-config.d.ts +12 -12
  171. package/dist/hooks-config.js +16 -15
  172. package/dist/hooks.d.ts +20 -10
  173. package/dist/hooks.js +30 -19
  174. package/dist/http-hook-allowlists.js +2 -1
  175. package/dist/index.d.ts +4 -0
  176. package/dist/index.js +6 -2
  177. package/dist/mcp-entry-credential.d.ts +47 -0
  178. package/dist/mcp-entry-credential.js +73 -0
  179. package/dist/mcp-request-entry.d.ts +32 -13
  180. package/dist/mcp-request-entry.js +106 -59
  181. package/dist/mcp-server-policy.js +3 -2
  182. package/dist/migration-receipt.d.ts +3 -3
  183. package/dist/migration-receipt.js +4 -3
  184. package/dist/one-time-migrations.d.ts +2 -2
  185. package/dist/one-time-migrations.js +75 -57
  186. package/dist/own-key-read.d.ts +3 -1
  187. package/dist/plain-json-object.d.ts +6 -3
  188. package/dist/plain-json-object.js +6 -3
  189. package/dist/portable-domains.d.ts +18 -12
  190. package/dist/portable-domains.js +21 -15
  191. package/dist/reserved-member-name.d.ts +1 -1
  192. package/dist/reserved-member-name.js +3 -2
  193. package/dist/resolve-roster.js +3 -2
  194. package/dist/retired-envs.js +3 -6
  195. package/dist/retired-role-words.d.ts +1 -1
  196. package/dist/retired-role-words.js +4 -6
  197. package/dist/safety-merge-spec.d.ts +11 -4
  198. package/dist/safety-merge-spec.js +5 -4
  199. package/dist/scheduler-store-node.d.ts +5 -2
  200. package/dist/scheduler-store-node.js +8 -5
  201. package/dist/secret-scan.js +1 -1
  202. package/dist/settings-sources.js +6 -5
  203. package/dist/settings-units.js +3 -2
  204. package/dist/sha256.d.ts +5 -0
  205. package/dist/sha256.js +7 -0
  206. package/dist/skills-manifest.js +2 -2
  207. package/dist/types.d.ts +89 -19
  208. package/dist/types.js +57 -65
  209. package/dist/ui-language.js +4 -3
  210. package/dist/url-credential.js +4 -3
  211. package/dist/url-shape.d.ts +1 -1
  212. package/dist/url-shape.js +5 -4
  213. package/dist/web-admin-credential.js +2 -1
  214. package/dist/web-admin-env.d.ts +1 -1
  215. package/dist/web-admin-env.js +4 -3
  216. package/docs/API-SURFACE.md +47 -7
  217. package/docs/CONFORMANCE.md +6 -4
  218. package/docs/CONSUMER-INTEGRATION.md +131 -6
  219. package/llms-full.txt +46 -24
  220. package/llms.txt +27 -13
  221. package/package.json +3 -2
@@ -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}$/;
@@ -0,0 +1,23 @@
1
+ /** 授权地址准入的查询参数名(闭集;起步只有 `intent`)。 */
2
+ export declare const CONNECTOR_AUTHORIZE_QUERY: readonly ["intent"];
3
+ export type ConnectorAuthorizeQueryName = (typeof CONNECTOR_AUTHORIZE_QUERY)[number];
4
+ /** 授权地址的瑕疵词(闭集;判序 = 本数组序)。 */
5
+ export declare const CONNECTOR_AUTHORIZE_URL_FLAWS: readonly ["not-http-url", "userinfo", "fragment", "not-https", "origin-mismatch", "path-not-start-route", "query-name-not-admitted", "query-name-repeated", "intent-missing"];
6
+ export type ConnectorAuthorizeUrlFlaw = (typeof CONNECTOR_AUTHORIZE_URL_FLAWS)[number];
7
+ /** 一台连接器的授权地址绑定的两件事:管理面的基址、被问的那一台连接器。 */
8
+ export interface ConnectorAuthorizeBinding {
9
+ readonly webUrl: string;
10
+ readonly connectorId: string;
11
+ }
12
+ /**
13
+ * 铸一台连接器的授权地址。`webUrl` = 管理面的 https 基址(无 userinfo / query / fragment;可带路径前缀;尾斜杠折掉);`connectorId` 过连接器 id 判官;
14
+ * `intent` 必填(非空、良构 UTF-16 的串,`encodeURIComponent` 编码;含孤立代理项 ⇒ 同为 `TypeError`)。坏输入一律抛 `TypeError`,不铸半截地址。产物对 {@link connectorAuthorizeUrlFlaws} 恒零瑕疵。
15
+ */
16
+ export declare function connectorAuthorizeUrlOf(webUrl: string, connectorId: string, query: {
17
+ readonly intent: string;
18
+ }): string;
19
+ /**
20
+ * 判一个授权地址:`[]` = 零瑕疵;否则按判序交回瑕疵词(见文件头的律)。`binding` 是这一次被问的管理面与连接器 —— 它坏是调用方用错(抛 `TypeError`),不是地址坏。
21
+ * `raw` 不是串 ⇒ `["not-http-url"]`。
22
+ */
23
+ export declare function connectorAuthorizeUrlFlaws(raw: string, binding: ConnectorAuthorizeBinding): readonly ConnectorAuthorizeUrlFlaw[];
@@ -0,0 +1,129 @@
1
+ /**
2
+ * 托管连接器的**授权地址**(29.0.0):拼装函数 {@link connectorAuthorizeUrlOf} 与它的瑕疵判官 {@link connectorAuthorizeUrlFlaws} —— 一处定义路由形与参数名
3
+ * (纯函数、零 I/O、浏览器安全)。地址形:
4
+ *
5
+ * <webUrl 去尾斜杠>/api/v1/connectors/<连接器 id>/oauth/start?intent=<intent>
6
+ *
7
+ * 路由属于管理面(它的 start 路由先验 `intent`,对不上就停在说明页);谁要给用户一个「去授权这台连接器」的地址 —— 铸口、对端座、文档 —— 调拼装函数,不按地址形手拼。
8
+ * 收到一个地址、要决定「能不能把它交给用户」的一方(对端座造「需授权」答复之前)问判官:它与拼装函数同包同源,拼装的产物恒零瑕疵。
9
+ *
10
+ * ## 判官的律(一条)
11
+ * **一个授权地址只在「是这一台连接器在这个管理面上的 start 路由、只带准入的参数、恰带一枚非空 `intent`」时零瑕疵。** 改写者能动的只剩 `intent` 的值。
12
+ * 瑕疵词闭集 {@link CONNECTOR_AUTHORIZE_URL_FLAWS},判序 = 表序:形(`not-http-url` / `userinfo` / `fragment`,问包内唯一的 URL 形判官)· `not-https` ·
13
+ * `origin-mismatch`(主机与端口 ≠ 管理面基址的;scheme 只由 `not-https` 说,一词一事)· `path-not-start-route`(路径 ≠ 这一台连接器的 start 路由,连接器 id 按字节比)· `query-name-not-admitted` /
14
+ * `query-name-repeated`(参数名闭集 {@link CONNECTOR_AUTHORIZE_QUERY})· `intent-missing`(缺席或空串)。形就不对(不是 http(s) URL)时只交形的词,其余不判。
15
+ * 答案只有词,不含值的任何片段(地址里的 `intent` 是一枚令牌)。
16
+ * 判官的绑定(`webUrl` / `connectorId`)与拼装的参数(`query.intent`)**只认自有键**({@link ownArgOf}):只靠继承可见的值当作没给 —— 被污染的原型给不出受信的绑定。
17
+ */
18
+ import { CONNECTOR_ID_RULE, isConnectorId } from "./connector-id.js";
19
+ import { deepFreeze } from "./deep-freeze.js";
20
+ import { ownValueOf } from "./own-key-read.js";
21
+ import { jsonShapeOf } from "./plain-json-object.js";
22
+ import { httpUrlFlaws, httpUrlRule, pathBaseUrlFlaws } from "./url-shape.js";
23
+ /** 授权地址准入的查询参数名(闭集;起步只有 `intent`)。 */
24
+ export const CONNECTOR_AUTHORIZE_QUERY = deepFreeze(["intent"]);
25
+ /** 授权地址的瑕疵词(闭集;判序 = 本数组序)。 */
26
+ export const CONNECTOR_AUTHORIZE_URL_FLAWS = deepFreeze([
27
+ "not-http-url",
28
+ "userinfo",
29
+ "fragment",
30
+ "not-https",
31
+ "origin-mismatch",
32
+ "path-not-start-route",
33
+ "query-name-not-admitted",
34
+ "query-name-repeated",
35
+ "intent-missing",
36
+ ]);
37
+ /**
38
+ * 调用方交来的参数袋(判官的绑定、拼装的 `query`)上的一个成员 —— **只认自有键**(本包的自有键读法 `ownValueOf`):只靠继承可见(含 `Object.prototype` 被污染成数据值)、缺席、
39
+ * 读不出、袋本身不是对象 ⇒ 当作没给(`undefined`;随后的判法照常抛 `TypeError`)。被污染的原型因此不能替调用方给出一个「受信的」绑定。
40
+ */
41
+ function ownArgOf(bag, key) {
42
+ const shape = jsonShapeOf(bag); // 形状只问座位(总、不抛);穷举 switch:座位加一个词这里编译红
43
+ switch (shape) {
44
+ case "plain":
45
+ case "non_plain_object":
46
+ case "array": {
47
+ const read = ownValueOf(bag, key);
48
+ return read.ok ? read.value : undefined;
49
+ }
50
+ case "null":
51
+ case "primitive":
52
+ case "uninspectable":
53
+ return undefined;
54
+ default: {
55
+ const unhandled = shape;
56
+ throw new Error(`ownArgOf: unhandled shape ${String(unhandled)}`);
57
+ }
58
+ }
59
+ }
60
+ /** 管理面基址 → 路由前缀(规范形,尾斜杠折掉)。基址必须是 https、可拼路径的干净基址(无 userinfo / query / fragment;可带路径前缀);否则抛(用错了,不是地址坏)。 */
61
+ function webBaseOf(fn, webUrl) {
62
+ if (typeof webUrl !== "string")
63
+ throw new TypeError(`${fn}: webUrl must be a string (an absolute https URL)`);
64
+ const flaws = pathBaseUrlFlaws(webUrl);
65
+ if (flaws.length > 0)
66
+ throw new TypeError(`${fn}: webUrl ${httpUrlRule(flaws[0])}`);
67
+ const base = new URL(webUrl);
68
+ if (base.protocol !== "https:")
69
+ throw new TypeError(`${fn}: webUrl must be an https URL (the authorization address is handed to a user's browser)`);
70
+ return base;
71
+ }
72
+ function connectorIdOf(fn, connectorId) {
73
+ if (!isConnectorId(connectorId))
74
+ throw new TypeError(`${fn}: connectorId ${CONNECTOR_ID_RULE}`);
75
+ return connectorId;
76
+ }
77
+ /** 这一台连接器的 start 路由路径(基址的路径前缀 + 路由;连接器 id 是 unreserved 字符,原样进路径段)。 */
78
+ function startRoutePath(base, connectorId) {
79
+ return `${base.pathname.replace(/\/+$/, "")}/api/v1/connectors/${connectorId}/oauth/start`;
80
+ }
81
+ /**
82
+ * 铸一台连接器的授权地址。`webUrl` = 管理面的 https 基址(无 userinfo / query / fragment;可带路径前缀;尾斜杠折掉);`connectorId` 过连接器 id 判官;
83
+ * `intent` 必填(非空、良构 UTF-16 的串,`encodeURIComponent` 编码;含孤立代理项 ⇒ 同为 `TypeError`)。坏输入一律抛 `TypeError`,不铸半截地址。产物对 {@link connectorAuthorizeUrlFlaws} 恒零瑕疵。
84
+ */
85
+ export function connectorAuthorizeUrlOf(webUrl, connectorId, query) {
86
+ const fn = "connectorAuthorizeUrlOf";
87
+ const base = webBaseOf(fn, webUrl);
88
+ const id = connectorIdOf(fn, connectorId);
89
+ const intent = ownArgOf(query, "intent");
90
+ if (typeof intent !== "string" || intent.length === 0)
91
+ throw new TypeError(`${fn}: intent is required (a non-empty string)`);
92
+ let encoded;
93
+ try {
94
+ encoded = encodeURIComponent(intent);
95
+ }
96
+ catch {
97
+ throw new TypeError(`${fn}: intent must be well-formed text (it holds a lone surrogate)`);
98
+ }
99
+ return `${base.origin}${startRoutePath(base, id)}?intent=${encoded}`;
100
+ }
101
+ /**
102
+ * 判一个授权地址:`[]` = 零瑕疵;否则按判序交回瑕疵词(见文件头的律)。`binding` 是这一次被问的管理面与连接器 —— 它坏是调用方用错(抛 `TypeError`),不是地址坏。
103
+ * `raw` 不是串 ⇒ `["not-http-url"]`。
104
+ */
105
+ export function connectorAuthorizeUrlFlaws(raw, binding) {
106
+ const fn = "connectorAuthorizeUrlFlaws";
107
+ const base = webBaseOf(fn, ownArgOf(binding, "webUrl"));
108
+ const id = connectorIdOf(fn, ownArgOf(binding, "connectorId"));
109
+ if (typeof raw !== "string")
110
+ return ["not-http-url"];
111
+ const shape = httpUrlFlaws(raw, ["userinfo", "fragment"]);
112
+ if (shape.includes("not-http-url"))
113
+ return shape;
114
+ const u = new URL(raw);
115
+ const names = [...u.searchParams.keys()];
116
+ const intents = u.searchParams.getAll("intent");
117
+ const present = {
118
+ "not-http-url": false,
119
+ userinfo: shape.includes("userinfo"),
120
+ fragment: shape.includes("fragment"),
121
+ "not-https": u.protocol !== "https:",
122
+ "origin-mismatch": u.host !== base.host,
123
+ "path-not-start-route": u.pathname !== startRoutePath(base, id),
124
+ "query-name-not-admitted": names.some((n) => !CONNECTOR_AUTHORIZE_QUERY.includes(n)),
125
+ "query-name-repeated": new Set(names).size !== names.length,
126
+ "intent-missing": intents.length === 0 || (intents.length === 1 && intents[0] === ""),
127
+ };
128
+ return CONNECTOR_AUTHORIZE_URL_FLAWS.filter((flaw) => present[flaw]);
129
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 连接器 id(29.0.0)—— 一台托管连接器在部署登记册里的名字。纯函数、零 I/O、浏览器安全(外部的值依赖只有 zod;包内只用叶子模块 `./quoted-issue`)。
3
+ *
4
+ * ## 律(一条)
5
+ * **一个连接器 id 只有一种拼法、一只判官。** 同一个 id 同时是三处的值:MCP http 条目断言引用的 `audience`(断言的受众,原样使用、不翻译)、
6
+ * 授权地址路由里的连接器路径段(`./connector-authorize-url`)、部署登记册的行名 —— 三处都问 {@link isConnectorId},不各写一份形。
7
+ *
8
+ * ## 形
9
+ * DNS label:1–{@link CONNECTOR_ID_MAX} 个字符,只许小写 `a`–`z`、数字与 `-`,首尾必须是字母或数字(`a.b` / `a_b` / `a-` / `-a` / 大写 / 空串 / 64 字符都不是)。
10
+ * 比较按字节:这些字符都是 ASCII,且都在 RFC 3986 的 unreserved 集里 ⇒ `encodeURIComponent(id) === id`,放进路径段不变形、按字节比就是按值比。
11
+ * 不折大小写、不去空白、不做任何规范化 —— 判官拒掉的形在别处也不会被「修」成合法的 id。
12
+ * 「一个 id 删了不再复用」是登记册一方的不变式,本包只判形。
13
+ */
14
+ import { z } from "zod";
15
+ /** 连接器 id 的最长长度(字符;DNS label 的上界)。 */
16
+ export declare const CONNECTOR_ID_MAX = 63;
17
+ /** 规则句(拒句里用;只说规则,不回显值)。 */
18
+ export declare const CONNECTOR_ID_RULE = "must be a connector id: a DNS label of 1-63 characters \u2014 lowercase a-z, digits and '-', starting and ending with a letter or digit";
19
+ /** 这是不是一个连接器 id(总:非串答 `false`,不抛)。 */
20
+ export declare function isConnectorId(v: unknown): v is string;
21
+ /** 连接器 id 的 zod 形:就是 {@link isConnectorId},拒句 = {@link CONNECTOR_ID_RULE}(固定句,铸点是包内唯一的 `buildQuotedIssue`:规则句整句进模板、没有值位)。 */
22
+ export declare const ConnectorId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
23
+ export type ConnectorId = z.infer<typeof ConnectorId>;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 连接器 id(29.0.0)—— 一台托管连接器在部署登记册里的名字。纯函数、零 I/O、浏览器安全(外部的值依赖只有 zod;包内只用叶子模块 `./quoted-issue`)。
3
+ *
4
+ * ## 律(一条)
5
+ * **一个连接器 id 只有一种拼法、一只判官。** 同一个 id 同时是三处的值:MCP http 条目断言引用的 `audience`(断言的受众,原样使用、不翻译)、
6
+ * 授权地址路由里的连接器路径段(`./connector-authorize-url`)、部署登记册的行名 —— 三处都问 {@link isConnectorId},不各写一份形。
7
+ *
8
+ * ## 形
9
+ * DNS label:1–{@link CONNECTOR_ID_MAX} 个字符,只许小写 `a`–`z`、数字与 `-`,首尾必须是字母或数字(`a.b` / `a_b` / `a-` / `-a` / 大写 / 空串 / 64 字符都不是)。
10
+ * 比较按字节:这些字符都是 ASCII,且都在 RFC 3986 的 unreserved 集里 ⇒ `encodeURIComponent(id) === id`,放进路径段不变形、按字节比就是按值比。
11
+ * 不折大小写、不去空白、不做任何规范化 —— 判官拒掉的形在别处也不会被「修」成合法的 id。
12
+ * 「一个 id 删了不再复用」是登记册一方的不变式,本包只判形。
13
+ */
14
+ import { z } from "zod";
15
+ import { buildQuotedIssue, fixed } from "./quoted-issue.js";
16
+ /** 连接器 id 的最长长度(字符;DNS label 的上界)。 */
17
+ export const CONNECTOR_ID_MAX = 63;
18
+ /** 形的唯一表示:由 {@link CONNECTOR_ID_MAX} 铸(首尾各一个字母数字,中间至多 `MAX - 2` 个)。 */
19
+ const CONNECTOR_ID_FORM = new RegExp(`^[a-z0-9](?:[a-z0-9-]{0,${CONNECTOR_ID_MAX - 2}}[a-z0-9])?$`);
20
+ /** 规则句(拒句里用;只说规则,不回显值)。 */
21
+ export const CONNECTOR_ID_RULE = `must be a connector id: a DNS label of 1-${CONNECTOR_ID_MAX} characters — lowercase a-z, digits and '-', starting and ending with a letter or digit`;
22
+ /** 这是不是一个连接器 id(总:非串答 `false`,不抛)。 */
23
+ export function isConnectorId(v) {
24
+ return typeof v === "string" && CONNECTOR_ID_FORM.test(v);
25
+ }
26
+ /** 连接器 id 的 zod 形:就是 {@link isConnectorId},拒句 = {@link CONNECTOR_ID_RULE}(固定句,铸点是包内唯一的 `buildQuotedIssue`:规则句整句进模板、没有值位)。 */
27
+ export const ConnectorId = z.string().refine(isConnectorId, buildQuotedIssue `${fixed(CONNECTOR_ID_RULE)}`);
@@ -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;
@@ -0,0 +1,69 @@
1
+ const SET_MUTATORS = ["add", "delete", "clear"];
2
+ const MAP_MUTATORS = ["set", "delete", "clear"];
3
+ /** The Sets and Maps whose mutators are already guarded: freezing a collection that two tables share, or freezing a frozen constant again, is a no-op rather than a redefine error. */
4
+ const GUARDED = new WeakSet();
5
+ const refuse = (what) => () => {
6
+ throw new TypeError(`${what}: the object is frozen`);
7
+ };
8
+ function freezeGraph(value, seen) {
9
+ if (typeof value !== "object" || value === null || seen.has(value))
10
+ return;
11
+ seen.add(value);
12
+ const collection = value instanceof Set ? "Set" : value instanceof Map ? "Map" : undefined;
13
+ if (collection === undefined && !Array.isArray(value)) {
14
+ const proto = Object.getPrototypeOf(value);
15
+ if (proto !== Object.prototype && proto !== null)
16
+ return; // another prototype = someone else's object (zod schema, class instance, RegExp, Date …): not ours to freeze
17
+ }
18
+ // Every own data property: an array's elements, a table's entries, and anything attached to a Set / Map / array object itself (non-enumerable and symbol keys included).
19
+ for (const key of Reflect.ownKeys(value)) {
20
+ const d = Object.getOwnPropertyDescriptor(value, key);
21
+ if (d !== undefined && "value" in d)
22
+ freezeGraph(d.value, seen);
23
+ }
24
+ if (value instanceof Set)
25
+ for (const member of value)
26
+ freezeGraph(member, seen);
27
+ else if (value instanceof Map) {
28
+ for (const [k, v] of value) {
29
+ freezeGraph(k, seen);
30
+ freezeGraph(v, seen);
31
+ }
32
+ }
33
+ if (collection !== undefined && !GUARDED.has(value)) {
34
+ for (const name of collection === "Set" ? SET_MUTATORS : MAP_MUTATORS) {
35
+ Object.defineProperty(value, name, { value: refuse(`${collection}.${name}`), writable: false, enumerable: false, configurable: false });
36
+ }
37
+ GUARDED.add(value);
38
+ }
39
+ Object.freeze(value);
40
+ }
41
+ /**
42
+ * THE one freezer of every closed-set constant this package exports (package-private: not in the barrel, not on any subpath).
43
+ *
44
+ * 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
45
+ * `push` / `sort` / assign into it, every other reader's closed set changes with it, while the declared type says `readonly`.
46
+ * So every exported container is frozen at its definition, all the way down, through this one function: the shallow
47
+ * `Object.freeze` of an outer array leaves its rows writable, and a `Set` is not stopped by `Object.freeze` at all.
48
+ *
49
+ * What it freezes — containers of data, reached through plain data properties:
50
+ * · arrays and plain objects (prototype `Object.prototype` or `null`): `Object.freeze`, after their members;
51
+ * · `Set` / `Map`: `Object.freeze` plus own, non-writable mutators (`add` / `delete` / `clear`, `set` / `delete` / `clear`) that throw a
52
+ * `TypeError`, after their members (a Map's keys and values both) and after any property attached to the collection object itself.
53
+ * What it leaves alone: functions, RegExps (stateful by design), symbols, primitives, and any object with another prototype (a zod
54
+ * 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.
55
+ * Cycles are walked once; freezing the same collection twice (two tables sharing it) is a no-op the second time.
56
+ * The argument is returned (the same reference), typed as itself, so a declaration keeps the exact type it was written with.
57
+ *
58
+ * What a write does afterwards: an array method (`push` / `sort` / `splice` …) and a Set / Map method throw a `TypeError` in any caller;
59
+ * 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)
60
+ * and is silently ignored in a sloppy-mode script — either way the constant keeps its value.
61
+ * 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
62
+ * `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.
63
+ *
64
+ * `test/closed-set-exports-frozen.test.ts` walks every export of every subpath and fails, by name, on any container this missed.
65
+ */
66
+ export function deepFreeze(value) {
67
+ freezeGraph(value, new WeakSet());
68
+ return value;
69
+ }
@@ -1,8 +1,9 @@
1
1
  import { resolveActiveTiers } from "./config-fns.js";
2
2
  import { tierLadderFrom } from "./tier-words.js";
3
+ import { deepFreeze } from "./deep-freeze.js";
3
4
  /** core 对 `default` 角色的档语义:从它的缺省档 `pro` 起**只向低档**扫 —— pro → flash → lite,绝不向上抓 max / ultra
4
5
  * (core `ROLE_TIER_DEFAULTS.default` + `DEFAULT_TIER_ORDER`;档序只在 `./tier-words` 一处,这里按起点派生;对拍钉对 devDependency 里精确钉住的那一版 core)。 */
5
- export const DEFAULT_ROLE_TIER_LADDER = tierLadderFrom("pro");
6
+ export const DEFAULT_ROLE_TIER_LADDER = deepFreeze(tierLadderFrom("pro"));
6
7
  /**
7
8
  * 缺省模型由 `roles.default` 的形分两路(一条规则:点名的走命名链,不点名的交回引擎):
8
9
  * · `{select}` ⇒ `{ kind: "select", select }`(见 {@link CatalogDefaultModel});
@@ -1,5 +1,5 @@
1
1
  /**
2
- * device 车道的设备入口 `DEVICE_RELAY_URL` 的**值文法** —— 唯一判官(16.0.0)。纯函数,浏览器安全;只 import 零依赖的 URL 形判官模块。
2
+ * device 车道的设备入口 `DEVICE_RELAY_URL` 的**值文法** —— 唯一判官(16.0.0)。纯函数,浏览器安全;只 import URL 形判官模块 `./url-shape`(它自己只 import 包内私有的零 import 叶 `./deep-freeze`)。
3
3
  *
4
4
  * ## 规则(一条)
5
5
  * 设备拨哪里是部署的必填声明,合法值只有两种:
@@ -1,5 +1,5 @@
1
1
  /**
2
- * device 车道的设备入口 `DEVICE_RELAY_URL` 的**值文法** —— 唯一判官(16.0.0)。纯函数,浏览器安全;只 import 零依赖的 URL 形判官模块。
2
+ * device 车道的设备入口 `DEVICE_RELAY_URL` 的**值文法** —— 唯一判官(16.0.0)。纯函数,浏览器安全;只 import URL 形判官模块 `./url-shape`(它自己只 import 包内私有的零 import 叶 `./deep-freeze`)。
3
3
  *
4
4
  * ## 规则(一条)
5
5
  * 设备拨哪里是部署的必填声明,合法值只有两种:
@@ -26,8 +26,9 @@ import { landCatalogWord } from "./tier-words.js";
26
26
  import { stableStringify } from "./hash.js";
27
27
  import { captureJson, dataDescriptor, isolatedObject } from "./own-key-read.js";
28
28
  import { ROSTER_CHEAP_ROLES, ROSTER_PRIMARY_ROLES } from "./resolve-roster.js";
29
+ import { deepFreeze } from "./deep-freeze.js";
29
30
  /** env 模型表的键名(闭集)。 */
30
- export const ENV_MODEL_TABLE_KEYS = { mainId: "MODEL_ID", cheapId: "MODEL_CHEAP_ID", verifier: "MODEL_VERIFIER", codeRoles: "MODEL_CODE_ROLES" };
31
+ export const ENV_MODEL_TABLE_KEYS = deepFreeze({ mainId: "MODEL_ID", cheapId: "MODEL_CHEAP_ID", verifier: "MODEL_VERIFIER", codeRoles: "MODEL_CODE_ROLES" });
31
32
  /** env 表里主模型的别名键(角色底的 `default` 绑它;引擎 env 表的条目键 = 这个别名 + 主 id + cheap id)。 */
32
33
  export const DEFAULT_MODEL_KEY = "default";
33
34
  /** cheap 槽铸出来的 id(不铸 ⇒ `undefined`)。 */
@@ -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 起指路点名**哪一条**迁移)
@@ -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"]);