@sema-agent/settings-schema 28.0.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 (173) hide show
  1. package/CHANGELOG.md +330 -0
  2. package/README.md +81 -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/credentials.js +5 -7
  120. package/dist/api/lifecycle-events.d.ts +266 -0
  121. package/dist/api/lifecycle-events.js +169 -0
  122. package/dist/api/wire-scalars.d.ts +13 -0
  123. package/dist/api/wire-scalars.js +15 -0
  124. package/dist/atomic-write.d.ts +4 -0
  125. package/dist/atomic-write.js +26 -3
  126. package/dist/config-d-file.d.ts +1 -1
  127. package/dist/config-document-refusal.d.ts +4 -4
  128. package/dist/config-fns.d.ts +1 -1
  129. package/dist/config-root-documents.d.ts +1 -1
  130. package/dist/config-root-node.js +2 -1
  131. package/dist/conformance/corpus.d.ts +1 -1
  132. package/dist/conformance/derive.d.ts +13 -5
  133. package/dist/conformance/derive.js +36 -20
  134. package/dist/conformance/index.d.ts +1 -1
  135. package/dist/conformance/index.js +1 -1
  136. package/dist/conformance/run.js +8 -9
  137. package/dist/connector-authorize-url.d.ts +23 -0
  138. package/dist/connector-authorize-url.js +129 -0
  139. package/dist/connector-id.d.ts +23 -0
  140. package/dist/connector-id.js +27 -0
  141. package/dist/file-edit.d.ts +44 -0
  142. package/dist/file-edit.js +70 -1
  143. package/dist/file-store.d.ts +12 -7
  144. package/dist/file-store.js +70 -58
  145. package/dist/hooks.d.ts +15 -5
  146. package/dist/hooks.js +13 -3
  147. package/dist/index.d.ts +4 -0
  148. package/dist/index.js +5 -1
  149. package/dist/mcp-entry-credential.d.ts +47 -0
  150. package/dist/mcp-entry-credential.js +73 -0
  151. package/dist/mcp-request-entry.d.ts +32 -13
  152. package/dist/mcp-request-entry.js +104 -58
  153. package/dist/migration-receipt.d.ts +2 -2
  154. package/dist/migration-receipt.js +2 -2
  155. package/dist/one-time-migrations.d.ts +2 -2
  156. package/dist/one-time-migrations.js +72 -55
  157. package/dist/portable-domains.d.ts +18 -12
  158. package/dist/portable-domains.js +17 -12
  159. package/dist/retired-role-words.d.ts +1 -1
  160. package/dist/retired-role-words.js +4 -6
  161. package/dist/scheduler-store-node.d.ts +5 -2
  162. package/dist/scheduler-store-node.js +8 -5
  163. package/dist/sha256.d.ts +5 -0
  164. package/dist/sha256.js +7 -0
  165. package/dist/skills-manifest.js +2 -2
  166. package/dist/types.d.ts +80 -10
  167. package/dist/types.js +30 -39
  168. package/docs/API-SURFACE.md +47 -7
  169. package/docs/CONFORMANCE.md +6 -4
  170. package/docs/CONSUMER-INTEGRATION.md +109 -4
  171. package/llms-full.txt +44 -23
  172. package/llms.txt +26 -13
  173. package/package.json +3 -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)}`);
@@ -21,6 +21,50 @@ export declare function domainFilePath(root: string, domain: DomainName): string
21
21
  * leaves a half-written config.d/<domain>.json; a new file takes the contract-document mode (0o644), an existing one keeps its own.
22
22
  * VALIDATES first (throws on invalid — never persists garbage); persists the parsed + defaulted value so the file is canonical. */
23
23
  export declare function writeDomainFile<K extends DomainName>(root: string, domain: K, value: unknown): Promise<DomainConfig[K]>;
24
+ /** The answer of {@link writeDomainFileIf} — a closed, discriminated union on `status` (switch over it exhaustively):
25
+ * · `written` — the file's bytes matched the expected digest and the new document was written; `value` is the parsed + defaulted document that was written, `digest` is the digest of the bytes now on disk
26
+ * (feed it straight back as the next call's `expected`, no re-read needed). `lockLeft` is present only when the write landed but the lock file could not be removed afterwards: it names that file
27
+ * (every later conditional write answers `locked` until it is deleted); a failed clean-up never replaces the outcome;
28
+ * · `stale` — the file's bytes did not match: nothing was written, not a byte of the file changed. `current` is the digest of the bytes on disk now, or `null` when the file is not there
29
+ * (re-read, re-apply the change on top of what is there, and call again);
30
+ * · `locked` — the lock file is held: nothing was written and the file was not read. `lock` is the lock file's absolute path. A lock left behind by a writer that crashed is never taken over
31
+ * (there is no safe way to tell it from a live holder): delete the file named by `lock` once no writer is running, its text is the holder's pid. */
32
+ export type ConditionalWriteResult<K extends DomainName> = {
33
+ readonly status: "written";
34
+ readonly value: DomainConfig[K];
35
+ readonly digest: string;
36
+ readonly lockLeft?: string;
37
+ } | {
38
+ readonly status: "stale";
39
+ readonly current: string | null;
40
+ } | {
41
+ readonly status: "locked";
42
+ readonly lock: string;
43
+ };
44
+ /** WRITE a domain file ATOMICALLY **only if it still holds what the caller read** — the compare-and-write form of {@link writeDomainFile}, for read-modify-write callers whose edit must not overwrite a change
45
+ * made after their read (a lost update).
46
+ *
47
+ * `expected` is the digest of the file's **bytes** as the caller read them — every byte, whatever it decodes to — in the package's one digest spelling (`sha256:<64 lowercase hex>`, minted by
48
+ * `contentDigest` from `@sema-agent/settings-schema/sha256`, which takes the `Buffer` that `readFile` returned), or `null` when the file was absent. Anything else is a `TypeError` (a malformed digest
49
+ * would never match and be mistaken for a concurrent change). Digest the bytes you PARSED — read the file once, digest that `Buffer` and parse `buffer.toString("utf8")` — never a second read.
50
+ * (For a file that is valid UTF-8 the digest of its decoded text is the same digest, so a caller that digests the text it read is right too; a text decoded from bytes that are not valid UTF-8 has lost
51
+ * those bytes — each bad sequence became U+FFFD — and digests differently from the file.)
52
+ *
53
+ * Order (the same checks as {@link writeDomainFile} come first, so a refused write never takes a lock or touches a byte): the name guard → the `expected` form → the whole-document verdict
54
+ * (`parseDomain`; throws on a value the contract refuses, the same sentence as the unconditional writer) → create `config.d` if it is missing → take the lock → re-read the file under the lock →
55
+ * compare digests → write atomically (the package's one atomic writer: same directory, same mode rules, a symbolic link is written through) → remove the lock. Removal is attempted on every path that
56
+ * took the lock, success or failure; a failure after the lock is thrown as it is, and a failure to remove the lock never replaces the outcome (see `lockLeft` in {@link ConditionalWriteResult}).
57
+ *
58
+ * The lock is the hidden file `.<file>.lock` beside the file that is actually written — for a plain `config.d/<domain>.json` that is `config.d/.<domain>.json.lock`; when the domain file is a symbolic
59
+ * link it sits beside the link's real target, so two roots whose links point at one real file share one lock. Created exclusively (the package's existing create-only-if-absent primitive — the same
60
+ * one the root-level decision document uses), holding the writer's pid. A held lock answers `locked` and nothing else happens; there is no wait and no retry, the caller decides. The hidden,
61
+ * non-`.json` name keeps it out of every `config.d` scan.
62
+ *
63
+ * What it does NOT do: the lock and the digest coordinate callers of THIS function. An unconditional {@link writeDomainFile}, `writeBundle`, the directory migration or a hand edit takes no lock and can still land between
64
+ * this call's re-read and its write; the only protection against those is that the compare happens under the lock, microseconds before the rename.
65
+ *
66
+ * Resolves `{ status: "written" | "stale" | "locked", … }` ({@link ConditionalWriteResult}); rejects on invalid input, an unreadable file and file-system failures. */
67
+ export declare function writeDomainFileIf<K extends DomainName>(root: string, domain: K, value: unknown, expected: string | null): Promise<ConditionalWriteResult<K>>;
24
68
  export interface RequiredEnvName {
25
69
  envName: string;
26
70
  refs: {
package/dist/file-edit.js CHANGED
@@ -5,11 +5,13 @@
5
5
  *
6
6
  * Validation uses the SAME zod schemas as the server's parseDomain → identical rules on both sides.
7
7
  */
8
+ import { unlinkSync } from "node:fs";
8
9
  import { mkdir } from "node:fs/promises";
9
10
  import path from "node:path";
10
- import { writeFileAtomic } from "./atomic-write.js";
11
+ import { createFileExclusive, readBytesIfPresent, resolveSymlinkTarget, writeFileAtomic } from "./atomic-write.js";
11
12
  import { emptyDocument, guardedSafeParse } from "./own-key-read.js";
12
13
  import { collectEnvRefs } from "./secret-refs.js";
14
+ import { SHA256_DIGEST_RE, contentDigest } from "./sha256.js";
13
15
  import { REMOTE_EXEC_DOCUMENT, RemoteExecSpec } from "./remote-exec.js";
14
16
  import { configDDocumentText } from "./config-d-file.js";
15
17
  import { buildQuotedIssue, fixed } from "./quoted-issue.js";
@@ -69,6 +71,73 @@ export async function writeDomainFile(root, domain, value) {
69
71
  writeFileAtomic(path.join(dir, `${domain}.json`), configDDocumentText(parsed), "config-document");
70
72
  return parsed;
71
73
  }
74
+ /** Remove the lock this call created: `true` = it is gone (an already-missing lock counts — someone cleaned it), `false` = it could not be removed and is still there. Never throws: a clean-up failure
75
+ * must not replace the outcome it follows (a landed write, or the error that ended the call); a lock left behind is reported by the result (`lockLeft`) and by every later call (`locked`). */
76
+ function releaseLock(lock) {
77
+ try {
78
+ unlinkSync(lock);
79
+ return true;
80
+ }
81
+ catch (e) {
82
+ return e.code === "ENOENT";
83
+ }
84
+ }
85
+ /** WRITE a domain file ATOMICALLY **only if it still holds what the caller read** — the compare-and-write form of {@link writeDomainFile}, for read-modify-write callers whose edit must not overwrite a change
86
+ * made after their read (a lost update).
87
+ *
88
+ * `expected` is the digest of the file's **bytes** as the caller read them — every byte, whatever it decodes to — in the package's one digest spelling (`sha256:<64 lowercase hex>`, minted by
89
+ * `contentDigest` from `@sema-agent/settings-schema/sha256`, which takes the `Buffer` that `readFile` returned), or `null` when the file was absent. Anything else is a `TypeError` (a malformed digest
90
+ * would never match and be mistaken for a concurrent change). Digest the bytes you PARSED — read the file once, digest that `Buffer` and parse `buffer.toString("utf8")` — never a second read.
91
+ * (For a file that is valid UTF-8 the digest of its decoded text is the same digest, so a caller that digests the text it read is right too; a text decoded from bytes that are not valid UTF-8 has lost
92
+ * those bytes — each bad sequence became U+FFFD — and digests differently from the file.)
93
+ *
94
+ * Order (the same checks as {@link writeDomainFile} come first, so a refused write never takes a lock or touches a byte): the name guard → the `expected` form → the whole-document verdict
95
+ * (`parseDomain`; throws on a value the contract refuses, the same sentence as the unconditional writer) → create `config.d` if it is missing → take the lock → re-read the file under the lock →
96
+ * compare digests → write atomically (the package's one atomic writer: same directory, same mode rules, a symbolic link is written through) → remove the lock. Removal is attempted on every path that
97
+ * took the lock, success or failure; a failure after the lock is thrown as it is, and a failure to remove the lock never replaces the outcome (see `lockLeft` in {@link ConditionalWriteResult}).
98
+ *
99
+ * The lock is the hidden file `.<file>.lock` beside the file that is actually written — for a plain `config.d/<domain>.json` that is `config.d/.<domain>.json.lock`; when the domain file is a symbolic
100
+ * link it sits beside the link's real target, so two roots whose links point at one real file share one lock. Created exclusively (the package's existing create-only-if-absent primitive — the same
101
+ * one the root-level decision document uses), holding the writer's pid. A held lock answers `locked` and nothing else happens; there is no wait and no retry, the caller decides. The hidden,
102
+ * non-`.json` name keeps it out of every `config.d` scan.
103
+ *
104
+ * What it does NOT do: the lock and the digest coordinate callers of THIS function. An unconditional {@link writeDomainFile}, `writeBundle`, the directory migration or a hand edit takes no lock and can still land between
105
+ * this call's re-read and its write; the only protection against those is that the compare happens under the lock, microseconds before the rename.
106
+ *
107
+ * Resolves `{ status: "written" | "stale" | "locked", … }` ({@link ConditionalWriteResult}); rejects on invalid input, an unreadable file and file-system failures. */
108
+ export async function writeDomainFileIf(root, domain, value, expected) {
109
+ assertDomainName(domain); // a stray non-domain key fails LOUD + clear, as in writeDomainFile
110
+ if (expected !== null && !(typeof expected === "string" && SHA256_DIGEST_RE.test(expected))) {
111
+ throw new TypeError(`writeDomainFileIf: \`expected\` must be null (the file was absent when read) or a "sha256:<64 lowercase hex>" digest of the text that was read, not ${expected === undefined ? "undefined" : typeof expected === "string" ? "another string" : `a ${typeof expected}`}`);
112
+ }
113
+ const parsed = parseDomain(domain, value); // the one whole-document verdict, before any lock or byte
114
+ const dir = path.join(root, "config.d");
115
+ const file = path.join(dir, `${domain}.json`);
116
+ await mkdir(dir, { recursive: true });
117
+ const real = resolveSymlinkTarget(file); // the file that is actually written (a link is followed; a dangling link throws the package's one sentence, before any lock)
118
+ const lock = path.join(path.dirname(real), `.${path.basename(real)}.lock`); // keyed by the real destination: aliases of one file share one lock
119
+ if (createFileExclusive(lock, `${process.pid}\n`, "config-document") === "present")
120
+ return { status: "locked", lock }; // not ours: never touched
121
+ let outcome;
122
+ try {
123
+ const present = await readBytesIfPresent(file, [dir]); // under the lock; the raw bytes (no decoding); the one absence rule (a dangling link is loud, not absent)
124
+ const current = present === undefined ? null : contentDigest(present);
125
+ if (current !== expected) {
126
+ outcome = { status: "stale", current };
127
+ }
128
+ else {
129
+ const text = configDDocumentText(parsed);
130
+ writeFileAtomic(file, text, "config-document");
131
+ outcome = { status: "written", value: parsed, digest: contentDigest(text) };
132
+ }
133
+ }
134
+ finally {
135
+ const released = releaseLock(lock); // never throws: the error in flight (if any) stays the error
136
+ if (outcome?.status === "written" && !released)
137
+ outcome = { ...outcome, lockLeft: lock };
138
+ }
139
+ return outcome;
140
+ }
72
141
  /** LIST every env-NAME the current local config requires (across models/workers/mcp/a2a + the
73
142
  * remote-exec backend), marking which are MISSING from the resolved env — the TOC "you still need to set
74
143
  * these secrets" panel. Reuses collectEnvRefs for the domain side, then appends the remoteExec secret refs. */
@@ -2,7 +2,7 @@ import { type EffectiveReadWarning } from "./config-fns.js";
2
2
  import type { ConfigDocumentRefusal } from "./config-document-refusal.js";
3
3
  import type { ConfigReader } from "./reader.js";
4
4
  import { type DomainConfig, type DomainName, type EffectiveConfig, type RetiredDomainName } from "./types.js";
5
- export { NON_PORTABLE_DOMAIN_REASONS, PORTABLE_DOMAINS, type PortableDomain } from "./portable-domains.js";
5
+ export { LOCAL_READ_DOMAINS, NON_PORTABLE_DOMAIN_REASONS, PORTABLE_DOMAINS, type LocalReadDomain, type PortableDomain } from "./portable-domains.js";
6
6
  /** `config.d/` 里**合法存在但不是域文档**的文件名(不进 `"unread-config-file"` 告警)。`remote-exec`
7
7
  * 不是 `DOMAIN_SCHEMAS` 成员(resolver 不读它),按 service 表决住在这个目录,由 loadRemoteExec 读
8
8
  * ——**它有自己的校验路径**(读盘与域文档同一只 `config.d` 文档读法,值判是 `RemoteExecSpec`),所以既不是「未知文件」也不是「域文件」。
@@ -30,7 +30,7 @@ export type FileConfigRead =
30
30
  readonly effective: EffectiveConfig;
31
31
  readonly warnings: readonly EffectiveReadWarning[];
32
32
  }
33
- /** 至少一份文档在文件层被拒:`refusals` = 整棵目录的拒单(次序确定:retired 域文档在前,按墓碑表的声明次序;便携域按 `PORTABLE_DOMAINS` 的次序);
33
+ /** 至少一份文档在文件层被拒:`refusals` = 整棵目录的拒单(次序确定:retired 域文档在前,按墓碑表的声明次序;本地读取域按 `LOCAL_READ_DOMAINS` 的次序);
34
34
  * `version` = 这一次读到的整棵目录的内容版本(被拒的文档以坏文档的指纹参与 —— 与宽容读的坏文件哨兵同一只:同样的坏内容同一个数、坏内容变了换数、
35
35
  * 绝不与「文件缺席」同数);`warnings` = 没人读的文件(装配没有发生)。 */
36
36
  | {
@@ -58,9 +58,10 @@ export declare class FileConfigStore implements ConfigReader {
58
58
  * `has(domain) ? parse : undefined`. Only an ABSENT file (ENOENT with nothing at the path; a dangling symlink is not absence) is absence → undefined. A present `{}` IS a set
59
59
  * domain → parsed with defaults. A present file that is empty or whitespace-only (a half-write) throws as a corrupt file,
60
60
  * as do bad JSON, a non-object, an unreadable file and one nested too deep (the same reading as getEffective / readBundle).
61
- * (getEffective still fills defaults for absent domains; getDomain is the per-domain "was this ever set?" probe.) */
61
+ * (getEffective still fills defaults for absent domains; getDomain is the per-domain "was this ever set?" probe.)
62
+ * A per-domain single read: it does not consult {@link LOCAL_READ_DOMAINS} (the enumerating reads — `getEffective` / `read()` / `getVersion()` — do), so the bundle helpers put the portable-set gate in front of it. */
62
63
  getDomain<K extends DomainName>(domain: K): Promise<DomainConfig[K] | undefined>;
63
- /** All portable domains → EffectiveConfig. The PAYLOAD and its `version` come from ONE raws snapshot (no
64
+ /** All local-read domains → EffectiveConfig. The PAYLOAD and its `version` come from ONE raws snapshot (no
64
65
  * re-read between them — else a concurrent atomic rename could pair payload A with version B and a consumer
65
66
  * would skip the change). `updatedAt` = max file mtime (informational; the content-hash version is the
66
67
  * authoritative change-detector).
@@ -81,14 +82,18 @@ export declare class FileConfigStore implements ConfigReader {
81
82
  tolerant: true;
82
83
  }): Promise<TolerantEffective>;
83
84
  /** Stable version number for the current files: same files ⇒ same number ⇒ a consumer's "skip re-apply if
84
- * version unchanged" works locally too. */
85
+ * version unchanged" works locally too. It is the number `read()` carries for the same tree (one snapshot reading, {@link #snapshot}) ——
86
+ * answered for every tree, including one with a document refused at the file layer (29.0.0; it threw before): that document joins as its
87
+ * fingerprint sentinel, never as absence. Shape (schema) does not enter the version: a gated domain that reads but fails its schema has a
88
+ * version here while `read()` / `getEffective()` throw for it. */
85
89
  getVersion(): Promise<number>;
86
90
  /**
87
- * **单读口**(16.0.0):一次读整棵 `config.d`(全部便携域 + retired 域的墓碑文档,每份只读一次),交一个结局({@link FileConfigRead})——
91
+ * **单读口**(16.0.0):一次读整棵 `config.d`(全部本地读取域 + retired 域的墓碑文档,每份只读一次),交一个结局({@link FileConfigRead})——
88
92
  * · 每份文档在文件层都读得进 ⇒ `effective`:与严读 `getEffective()` 逐位同;读侧告警交成数据(没人读的文件 + 装配告警,不经 `onWarning`);
89
93
  * · 有文档在文件层被拒(空 / 坏 JSON / 不是对象 / 读不出 / 过深;带事实的 retired 域文档是墓碑拒,带迁移编号)⇒ `refused`:整棵目录的拒单与这一次读到的内容版本。
90
94
  * 严读与 `readBundle` 读的是同一只文件读法(`./config-d-file` 的读数)—— 同一种坏形同一个词、同一句话;区别只在渲染:严读遇到第一份坏文档就抛,本方法把整个目录读完、逐份交出。
91
- * 文件层之外的拒(读得出、过不了门控域的 schema)照严读抛 —— 那是判形,不在拒单里。拒单、版本、effective、告警都出自这一次读到的字节:没有「先抛、再重探」的第二次读。
95
+ * 文件层之外的拒(读得出、过不了门控域的 schema)照严读抛 —— 那是判形,不在拒单里;判形不进版本,那棵树的版本 `getVersion()` 照答。拒单、版本、effective、告警都出自这一次读到的字节:没有「先抛、再重探」的第二次读。
96
+ * 版本与 `getVersion()` 是同一个数(同一只快照读法 {@link #snapshot})。
92
97
  */
93
98
  read(): Promise<FileConfigRead>;
94
99
  }