@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
@@ -1,13 +1,15 @@
1
1
  /**
2
- * FileConfigStore — a local, single-machine config source for the TOC desktop/CLI. Reads the PORTABLE domains
2
+ * FileConfigStore — a local, single-machine config source for the TOC desktop/CLI. Reads the LOCAL-READ domains ({@link LOCAL_READ_DOMAINS})
3
3
  * from `<root>/config.d/<domain>.json` (one file per domain, each = exactly that domain's zod object) and
4
4
  * resolves them into an {@link EffectiveConfig} via the SAME pure `buildEffective`/`parseDomain` the server
5
5
  * stores use. Implements ONLY the narrow {@link ConfigReader} (3 methods) — no publish/RBAC/worker-status.
6
6
  *
7
7
  * LOCAL FILE LAYOUT (the TOC owns the root, e.g. `~/.ai-agent/` or a project-local `.ai-agent/`):
8
- * <root>/config.d/<domain>.json for every domain in {@link PORTABLE_DOMAINS} — that constant is the
8
+ * <root>/config.d/<domain>.json for every domain in {@link LOCAL_READ_DOMAINS} — that constant is the
9
9
  * AUTHORITY; do NOT hand-copy the list here (the hand-written enumeration that used to sit
10
10
  * on this line silently missed `prompts` for three releases — 对抗复审 复审 round2 F5).
11
+ * It is {@link PORTABLE_DOMAINS} plus `projects`: the local set answers "which documents does this store read",
12
+ * the portable set answers "which domains travel in a bundle" — two questions, two constants.
11
13
  * <root>/.env secret VALUES (KEY=value) — the ONLY file holding secrets; gitignored, never read here.
12
14
  *
13
15
  * Rules:
@@ -17,25 +19,28 @@
17
19
  * "absent/defaults" the file must be missing, not empty. A valid `{}` object IS a set domain (→ defaults).
18
20
  * - `read()` (16.0.0) is the ONE read that answers both ways: the effective config + its read warnings as data when every
19
21
  * document reads, or the typed refusal list of the whole directory + its version when one does not — every document read once.
20
- * - Non-portable domains are OMITTED on a single machine and resolve to their schema defaults (`{workers:[]}`
21
- * etc.) — no stubbing needed. 逐域为什么被排除见 {@link NON_PORTABLE_DOMAIN_REASONS}(禁裸排除)。
22
+ * - Domains outside the local-read set (`workers` / `hosts` / `systems` / `entitlement`) are OMITTED on a single machine and resolve to their schema defaults (`{workers:[]}`
23
+ * etc.) — no stubbing needed; their files are named by an `"unread-config-file"` warning. 逐域为什么被排除见 {@link NON_PORTABLE_DOMAIN_REASONS}(禁裸排除)。
22
24
  * - A RETIRED domain's file (`config.d/runtime.json`, see `RETIRED_DOMAINS`) is read only for its tombstone: carrying facts ⇒
23
25
  * every read entry (`getDomain`, `getEffective` — and so `exportBundle`) throws `RetiredDomainError` (`refuseRetiredDomainFiles`, shared with `readBundle`) (the sentence names where the facts live today — `governance` and `limits`); `{}` carries nothing and is left alone. It is never an "unread file".
24
26
  * - The JSON files only ever carry env-NAMEs (the ENV_NAME boundary holds locally too); `.env` holds values.
25
- * - `getVersion()` = a stable content hash of all portable files → a u53 number, so a consumer's
26
- * "skip re-apply if version unchanged" works locally. `getEffective().updatedAt` = the max file mtime,
27
+ * - `getVersion()` = a stable content hash of all local-read files (and the retired domains' tombstone documents) → a u53 number, so a consumer's
28
+ * "skip re-apply if version unchanged" works locally. It is the one content version of the tree: `read()` carries the same number
29
+ * (one file-level snapshot; a refused document joins as its fingerprint, never as absence), and so does `getEffective().version`
30
+ * whenever that read returns. `getEffective().updatedAt` = the max file mtime,
27
31
  * passed EXPLICITLY into buildEffective (the determinism refactor) so identical files ⇒ identical bytes.
28
32
  */
29
33
  import { readdir, stat } from "node:fs/promises";
30
34
  import path from "node:path";
31
35
  import { RetiredDomainError, buildEffective, DOMAIN_READ_FALLBACK, parseDomainLoud, refuseRetiredDomain } from "./config-fns.js";
32
36
  import { RETIRED_DOMAIN_NAMES, configDPath, configDVersionOf, corruptDocumentRaw, readConfigDFile, readConfigDFileReading, refuseRetiredDomainFiles } from "./config-d-file.js";
33
- import { PORTABLE_DOMAINS } from "./portable-domains.js";
37
+ import { LOCAL_READ_DOMAINS } from "./portable-domains.js";
34
38
  import { REMOTE_EXEC_DOCUMENT } from "./remote-exec.js";
35
39
  import { isDomainName, isRetiredDomainName } from "./types.js";
36
40
  import { deepFreeze } from "./deep-freeze.js";
37
- // 便携域表的定义住在纯叶 ./portable-domains.ts(14.6.0;零 node 依赖,主桶模块可 import);这里原名转出口,`./node` 子路径逐名不变。
38
- export { NON_PORTABLE_DOMAIN_REASONS, PORTABLE_DOMAINS } from "./portable-domains.js";
41
+ // 域集合表的定义住在纯叶 ./portable-domains.ts(14.6.0;零 node 依赖,主桶模块可 import);这里原名转出口,`./node` 子路径逐名不变。
42
+ // 便携域集(搬运义:bundle 的默认集)与本地读取域集(本地读取义:本文件读哪些域)是两只常量 —— 本文件里按「读」枚举的各处读后者,不读前者。
43
+ export { LOCAL_READ_DOMAINS, NON_PORTABLE_DOMAIN_REASONS, PORTABLE_DOMAINS } from "./portable-domains.js";
39
44
  /** `config.d/` 里**合法存在但不是域文档**的文件名(不进 `"unread-config-file"` 告警)。`remote-exec`
40
45
  * 不是 `DOMAIN_SCHEMAS` 成员(resolver 不读它),按 service 表决住在这个目录,由 loadRemoteExec 读
41
46
  * ——**它有自己的校验路径**(读盘与域文档同一只 `config.d` 文档读法,值判是 `RemoteExecSpec`),所以既不是「未知文件」也不是「域文件」。
@@ -63,9 +68,9 @@ export class FileConfigStore {
63
68
  * file (nothing at the path — ENOENT and not a dangling symlink) → undefined = the domain is ABSENT (the ONLY way to mean "use defaults"); a present file that is EMPTY/whitespace-only,
64
69
  * or parses to anything but a JSON OBJECT, is CORRUPT → throw, FAIL CLOSED (an empty present file is a half-write/truncation, NOT
65
70
  * "absent": treating it as absent would silently DROP a published domain — e.g. a truncated governance.json drops its
66
- * commandPolicy/autonomy guardrails). This also keeps getVersion in lock-step with getEffective/getDomain: stableStringify collapses
67
- * `undefined` (absent) and `null` to the SAME bytes, so an empty/null file that resolved to undefined would hash IDENTICALLY to
68
- * "domain absent" and a version-gated poller would skip a change getEffective/getDomain actually FAIL on. R17 + R(0.1.27 整体复审). */
71
+ * commandPolicy/autonomy guardrails). The version never reads a corrupt file as absence either: stableStringify collapses
72
+ * `undefined` (absent) and `null` to the SAME bytes, so the version snapshot ({@link #snapshot}) puts a refused document in as its
73
+ * fingerprint sentinel — a version-gated poller sees the change that getEffective/getDomain FAIL on. R17 + R(0.1.27 整体复审). */
69
74
  async #readDomainRaw(domain) {
70
75
  return readConfigDFile(this.root, domain); // the shared reader guards the name (configDPath)
71
76
  }
@@ -77,7 +82,7 @@ export class FileConfigStore {
77
82
  * 闭集 —— 文件在、进程跑、限额还是 env 老值,**零告警**(「域缺席」与「文件不存在」在下游逐字同形)。
78
83
  * 修法方向是**响亮,不是收紧**:未登记文件照旧不读(拒收会让一个无害的散落文件打死整个部署),但必须
79
84
  * 说出来。两类分开报,因为处置不同:`not-a-domain` = 名字打错 / 消费方开了本包还不认识的域(要来本包
80
- * 登记);`non-portable-domain` = 域认识但单机 lane 刻意不读(理由见 {@link NON_PORTABLE_DOMAIN_REASONS})。
85
+ * 登记);`non-portable-domain` = 域认识但本地读取集({@link LOCAL_READ_DOMAINS})刻意不含它(workers / hosts / systems / entitlement;理由见 {@link NON_PORTABLE_DOMAIN_REASONS};`projects` 不在此列 —— 它在本地读取集里,被读)。
81
86
  *
82
87
  * 只在挂了 `onWarning` 时才 readdir —— 没接通道的调用方不该为一条没人听的警告付 IO(诚实登记:
83
88
  * 因此本门的响亮程度取决于消费方接不接这个座)。忽略:隐藏文件(含 file-edit 原子写的 `.<域>.json.*.tmp`
@@ -106,7 +111,7 @@ export class FileConfigStore {
106
111
  if (name.startsWith(".") || !name.endsWith(".json") || NON_DOMAIN_CONFIG_FILES.has(name))
107
112
  continue;
108
113
  const base = name.slice(0, -".json".length);
109
- if (PORTABLE_DOMAINS.includes(base))
114
+ if (LOCAL_READ_DOMAINS.includes(base))
110
115
  continue; // 真被读的域
111
116
  if (isRetiredDomainName(base))
112
117
  continue; // retired 域:由墓碑判(带事实 ⇒ getEffective 抛),不是「没人读的文件」
@@ -116,19 +121,48 @@ export class FileConfigStore {
116
121
  }
117
122
  return out;
118
123
  }
119
- /** Raw (unparsed) values for every PORTABLE domain and every retired domain (the latter for the tombstone), keyed by
120
- * name (absent → undefined). Both feed the version hash: a retired file appearing / changing flips `getEffective`
121
- * between a refusal and a read, so a version-gated poller must see it. */
122
- async #readAllRaw() {
123
- const out = {};
124
- await Promise.all([...PORTABLE_DOMAINS, ...RETIRED_DOMAIN_NAMES].map(async (d) => { out[d] = await this.#readDomainRaw(d); }));
125
- return out;
124
+ /**
125
+ * 整棵目录的**一次文件层读数**(retired 域的墓碑文档 + 全部本地读取域,每份只读一次)—— 内容版本的入参与拒单都出自它,`read()` 与 `getVersion()` 读这同一只:
126
+ * · 版本入参 `raws`:在场 ⇒ 原文解析后的值;缺席 ⇒ `undefined`;在文件层被拒 ⇒ 那份坏文档的指纹哨兵(`corruptDocumentRaw`:绝不与缺席同数,坏内容变了换数)。
127
+ * retired 域文档进版本:它出现 / 变了,读的结局就在拒与读之间翻,按版本轮询的消费方必须看得到。
128
+ * · `refusals`:文件层的拒(次序 = 读的次序:retired 域在前,本地读取域按 `LOCAL_READ_DOMAINS`)+ 带事实的墓碑。
129
+ */
130
+ async #snapshot() {
131
+ const documents = [...RETIRED_DOMAIN_NAMES, ...LOCAL_READ_DOMAINS];
132
+ const readings = await Promise.all(documents.map((d) => readConfigDFileReading(this.root, d)));
133
+ const raws = {};
134
+ const refusals = [];
135
+ documents.forEach((document, i) => {
136
+ const reading = readings[i];
137
+ switch (reading.status) {
138
+ case "absent":
139
+ raws[document] = undefined;
140
+ return;
141
+ case "refused":
142
+ raws[document] = corruptDocumentRaw(reading);
143
+ refusals.push({ document, reason: reading.reason, error: reading.error });
144
+ return;
145
+ case "present":
146
+ raws[document] = reading.value;
147
+ if (isRetiredDomainName(document)) {
148
+ const tombstone = tombstoneOf(document, reading.value);
149
+ if (tombstone !== undefined)
150
+ refusals.push(tombstone);
151
+ }
152
+ return;
153
+ default: {
154
+ const unhandled = reading;
155
+ throw new Error(`FileConfigStore: unhandled reading ${String(unhandled)}`);
156
+ }
157
+ }
158
+ });
159
+ return { raws, refusals };
126
160
  }
127
- /** The max mtime (ISO) across the present portable files, or the epoch when none exist — so `updatedAt`
161
+ /** The max mtime (ISO) across the present local-read files, or the epoch when none exist — so `updatedAt`
128
162
  * is deterministic for a given set of files (not the wall clock). */
129
163
  async #maxMtimeIso() {
130
164
  let maxMs = 0;
131
- await Promise.all(PORTABLE_DOMAINS.map(async (d) => {
165
+ await Promise.all(LOCAL_READ_DOMAINS.map(async (d) => {
132
166
  try {
133
167
  const s = await stat(this.domainPath(d));
134
168
  if (s.mtimeMs > maxMs)
@@ -146,7 +180,8 @@ export class FileConfigStore {
146
180
  * `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
147
181
  * domain → parsed with defaults. A present file that is empty or whitespace-only (a half-write) throws as a corrupt file,
148
182
  * as do bad JSON, a non-object, an unreadable file and one nested too deep (the same reading as getEffective / readBundle).
149
- * (getEffective still fills defaults for absent domains; getDomain is the per-domain "was this ever set?" probe.) */
183
+ * (getEffective still fills defaults for absent domains; getDomain is the per-domain "was this ever set?" probe.)
184
+ * 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. */
150
185
  async getDomain(domain) {
151
186
  await refuseRetiredDomainFiles(this.root); // every read entry asks the tombstone first (exportBundle reads through here)
152
187
  const raw = await this.#readDomainRaw(domain);
@@ -167,7 +202,7 @@ export class FileConfigStore {
167
202
  if (opts?.tolerant !== true) {
168
203
  const [retired] = await Promise.all([refuseRetiredDomainFiles(this.root), this.#warnUnreadFiles()]); // 两条读法同一门(0.19.0)
169
204
  const raws = { ...retired };
170
- await Promise.all(PORTABLE_DOMAINS.map(async (d) => { raws[d] = await this.#readDomainRaw(d); }));
205
+ await Promise.all(LOCAL_READ_DOMAINS.map(async (d) => { raws[d] = await this.#readDomainRaw(d); }));
171
206
  const updatedAt = await this.#maxMtimeIso();
172
207
  return buildEffective(this.#versionOf(raws), (d) => raws[d], updatedAt, this.opts.onWarning);
173
208
  }
@@ -178,7 +213,7 @@ export class FileConfigStore {
178
213
  const raws = { ...retired };
179
214
  const hashRaws = { ...retired };
180
215
  const domainErrors = [];
181
- await Promise.all(PORTABLE_DOMAINS.map(async (d) => {
216
+ await Promise.all(LOCAL_READ_DOMAINS.map(async (d) => {
182
217
  // 与严读同一只文件读法(读数):被拒的读数交 `thrown`(gate 域原样抛)或 `error` 句(其余域单列进 domainErrors)—— 坏文件的指纹就是这一次读到的字节,不是事后的第二次读。
183
218
  const reading = await readConfigDFileReading(this.root, d);
184
219
  if (reading.status !== "refused") {
@@ -198,46 +233,23 @@ export class FileConfigStore {
198
233
  return { effective, domainErrors };
199
234
  }
200
235
  /** Stable version number for the current files: same files ⇒ same number ⇒ a consumer's "skip re-apply if
201
- * version unchanged" works locally too. */
236
+ * version unchanged" works locally too. It is the number `read()` carries for the same tree (one snapshot reading, {@link #snapshot}) ——
237
+ * 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
238
+ * fingerprint sentinel, never as absence. Shape (schema) does not enter the version: a gated domain that reads but fails its schema has a
239
+ * version here while `read()` / `getEffective()` throw for it. */
202
240
  async getVersion() {
203
- return this.#versionOf(await this.#readAllRaw());
241
+ return this.#versionOf((await this.#snapshot()).raws);
204
242
  }
205
243
  /**
206
- * **单读口**(16.0.0):一次读整棵 `config.d`(全部便携域 + retired 域的墓碑文档,每份只读一次),交一个结局({@link FileConfigRead})——
244
+ * **单读口**(16.0.0):一次读整棵 `config.d`(全部本地读取域 + retired 域的墓碑文档,每份只读一次),交一个结局({@link FileConfigRead})——
207
245
  * · 每份文档在文件层都读得进 ⇒ `effective`:与严读 `getEffective()` 逐位同;读侧告警交成数据(没人读的文件 + 装配告警,不经 `onWarning`);
208
246
  * · 有文档在文件层被拒(空 / 坏 JSON / 不是对象 / 读不出 / 过深;带事实的 retired 域文档是墓碑拒,带迁移编号)⇒ `refused`:整棵目录的拒单与这一次读到的内容版本。
209
247
  * 严读与 `readBundle` 读的是同一只文件读法(`./config-d-file` 的读数)—— 同一种坏形同一个词、同一句话;区别只在渲染:严读遇到第一份坏文档就抛,本方法把整个目录读完、逐份交出。
210
- * 文件层之外的拒(读得出、过不了门控域的 schema)照严读抛 —— 那是判形,不在拒单里。拒单、版本、effective、告警都出自这一次读到的字节:没有「先抛、再重探」的第二次读。
248
+ * 文件层之外的拒(读得出、过不了门控域的 schema)照严读抛 —— 那是判形,不在拒单里;判形不进版本,那棵树的版本 `getVersion()` 照答。拒单、版本、effective、告警都出自这一次读到的字节:没有「先抛、再重探」的第二次读。
249
+ * 版本与 `getVersion()` 是同一个数(同一只快照读法 {@link #snapshot})。
211
250
  */
212
251
  async read() {
213
- const documents = [...RETIRED_DOMAIN_NAMES, ...PORTABLE_DOMAINS];
214
- const [readings, unread] = await Promise.all([Promise.all(documents.map((d) => readConfigDFileReading(this.root, d))), this.#unreadFiles()]);
215
- const raws = {};
216
- const refusals = [];
217
- documents.forEach((document, i) => {
218
- const reading = readings[i];
219
- switch (reading.status) {
220
- case "absent":
221
- raws[document] = undefined;
222
- return;
223
- case "refused":
224
- raws[document] = corruptDocumentRaw(reading);
225
- refusals.push({ document, reason: reading.reason, error: reading.error });
226
- return;
227
- case "present":
228
- raws[document] = reading.value;
229
- if (isRetiredDomainName(document)) {
230
- const tombstone = tombstoneOf(document, reading.value);
231
- if (tombstone !== undefined)
232
- refusals.push(tombstone);
233
- }
234
- return;
235
- default: {
236
- const unhandled = reading;
237
- throw new Error(`FileConfigStore.read: unhandled reading ${String(unhandled)}`);
238
- }
239
- }
240
- });
252
+ const [{ raws, refusals }, unread] = await Promise.all([this.#snapshot(), this.#unreadFiles()]);
241
253
  const version = this.#versionOf(raws);
242
254
  if (refusals.length > 0)
243
255
  return { kind: "refused", refusals, version, warnings: unread };
package/dist/hooks.d.ts CHANGED
@@ -2193,14 +2193,23 @@ export type HookMatcherForm = "literal" | "regex" | "invalid";
2193
2193
  * For a caller that must route matchers before evaluating them (run the literal ones inline, give the regex ones a deadline).
2194
2194
  */
2195
2195
  export declare function hookMatcherForm(matcher: string | undefined): HookMatcherForm;
2196
- /** One reference in a header value that {@link interpolateHookEnvVars} replaced with the empty string —— what the caller records. */
2196
+ /**
2197
+ * Why {@link interpolateHookEnvVars} expanded a reference to the empty string instead of a value (closed set; table order = the order the reading judges in):
2198
+ * · `"not-allowed"` —— the name is not in the hook's `allowedEnvVars` (its env value is not read);
2199
+ * · `"credential"` —— the name is a credential variable, which no list releases;
2200
+ * · `"unset"` —— the name is released, but `env` has no value for it (the entry is absent or `undefined`). An env value that is the empty string is a value: it expands to empty and is not listed.
2201
+ * A consumer that switches over the reason exhaustively gets a compile error when a word is added.
2202
+ */
2203
+ export declare const HOOK_ENV_BLANK_REASONS: readonly ["not-allowed", "credential", "unset"];
2204
+ export type HookEnvBlankReason = (typeof HOOK_ENV_BLANK_REASONS)[number];
2205
+ /** One reference in a header value that {@link interpolateHookEnvVars} expanded to the empty string for want of a released value —— what the caller records. */
2197
2206
  export interface HookEnvBlank {
2198
2207
  /** The header (its name, as keyed in the input) whose value held the reference. */
2199
2208
  readonly header: string;
2200
2209
  /** The variable name as written in the reference. The value is never part of this record. */
2201
2210
  readonly name: string;
2202
- /** `"not-allowed"` —— the name is not in the hook's `allowedEnvVars`. `"credential"` —— the name is a credential variable, which no list releases. */
2203
- readonly reason: "not-allowed" | "credential";
2211
+ /** Why the reference expanded to the empty string ({@link HOOK_ENV_BLANK_REASONS}). */
2212
+ readonly reason: HookEnvBlankReason;
2204
2213
  }
2205
2214
  /** What {@link interpolateHookEnvVars} returns: the headers as they go on the wire + the references it blanked. */
2206
2215
  export interface HookEnvInterpolation {
@@ -2214,12 +2223,13 @@ export interface HookEnvInterpolation {
2214
2223
  *
2215
2224
  * · only header **values** are read (header names are never touched);
2216
2225
  * · a reference is `$NAME` or `${NAME}` with NAME = `[A-Z_][A-Z0-9_]*`; anything else (lower case, a digit first, `${}`, an unclosed `${`) is plain text;
2217
- * · a name in `allowedEnvVars` ⇒ the env value (`""` when `env` has none —— expanded to empty, not listed in `blanked`);
2226
+ * · a name in `allowedEnvVars` ⇒ the env value; `""` when `env` has none, listed in `blanked` (`reason: "unset"`) —— an env value that is `""` is a value, expanded and not listed;
2218
2227
  * · a name **not** in `allowedEnvVars` ⇒ `""`, listed in `blanked` (`reason: "not-allowed"`); its env value is not read;
2219
2228
  * · a credential variable ({@link HOOK_ENV_CREDENTIAL_NAMES}'s closed set) ⇒ `""` even when the list names it, listed in `blanked` (`reason: "credential"`);
2220
2229
  * · CR / LF / NUL are removed from every resulting header value, references or not.
2230
+ * So `blanked` lists every reference that expanded to `""` for want of a released value, each with its reason; the header bytes do not depend on it.
2221
2231
  *
2222
- * The caller decides what to do with `blanked` (a debug line per entry is what CC writes); the headers are final either way.
2232
+ * The caller decides what to do with `blanked` (CC writes a debug line for a not-allowed or credential reference); the headers are final either way.
2223
2233
  * Pure: no I/O, no logging, no global env —— `env` is the caller's view (`process.env` at the call site). Inputs are not modified.
2224
2234
  */
2225
2235
  export declare function interpolateHookEnvVars(headers: Readonly<Record<string, string>>, allowedEnvVars: readonly string[], env: Readonly<Record<string, string | undefined>>): HookEnvInterpolation;
package/dist/hooks.js CHANGED
@@ -742,6 +742,15 @@ export function hookMatcherForm(matcher) {
742
742
  }
743
743
  }
744
744
  }
745
+ // ── http hook header env interpolation ───────────────────────────────────────────────────────────
746
+ /**
747
+ * Why {@link interpolateHookEnvVars} expanded a reference to the empty string instead of a value (closed set; table order = the order the reading judges in):
748
+ * · `"not-allowed"` —— the name is not in the hook's `allowedEnvVars` (its env value is not read);
749
+ * · `"credential"` —— the name is a credential variable, which no list releases;
750
+ * · `"unset"` —— the name is released, but `env` has no value for it (the entry is absent or `undefined`). An env value that is the empty string is a value: it expands to empty and is not listed.
751
+ * A consumer that switches over the reason exhaustively gets a compile error when a word is added.
752
+ */
753
+ export const HOOK_ENV_BLANK_REASONS = deepFreeze(["not-allowed", "credential", "unset"]);
745
754
  /** `${NAME}` or `$NAME`, NAME = `[A-Z_][A-Z0-9_]*` —— upper-case names only (lower-case and digit-led spellings are not references). */
746
755
  const HOOK_ENV_REFERENCE = /\$\{([A-Z_][A-Z0-9_]*)\}|\$([A-Z_][A-Z0-9_]*)/g;
747
756
  /** CR, LF and NUL never reach a header value (header injection through an env value or a configured template). */
@@ -790,12 +799,13 @@ const HOOK_ENV_CREDENTIAL_NAMES = new Set([
790
799
  *
791
800
  * · only header **values** are read (header names are never touched);
792
801
  * · a reference is `$NAME` or `${NAME}` with NAME = `[A-Z_][A-Z0-9_]*`; anything else (lower case, a digit first, `${}`, an unclosed `${`) is plain text;
793
- * · a name in `allowedEnvVars` ⇒ the env value (`""` when `env` has none —— expanded to empty, not listed in `blanked`);
802
+ * · a name in `allowedEnvVars` ⇒ the env value; `""` when `env` has none, listed in `blanked` (`reason: "unset"`) —— an env value that is `""` is a value, expanded and not listed;
794
803
  * · a name **not** in `allowedEnvVars` ⇒ `""`, listed in `blanked` (`reason: "not-allowed"`); its env value is not read;
795
804
  * · a credential variable ({@link HOOK_ENV_CREDENTIAL_NAMES}'s closed set) ⇒ `""` even when the list names it, listed in `blanked` (`reason: "credential"`);
796
805
  * · CR / LF / NUL are removed from every resulting header value, references or not.
806
+ * So `blanked` lists every reference that expanded to `""` for want of a released value, each with its reason; the header bytes do not depend on it.
797
807
  *
798
- * The caller decides what to do with `blanked` (a debug line per entry is what CC writes); the headers are final either way.
808
+ * The caller decides what to do with `blanked` (CC writes a debug line for a not-allowed or credential reference); the headers are final either way.
799
809
  * Pure: no I/O, no logging, no global env —— `env` is the caller's view (`process.env` at the call site). Inputs are not modified.
800
810
  */
801
811
  export function interpolateHookEnvVars(headers, allowedEnvVars, env) {
@@ -816,7 +826,7 @@ export function interpolateHookEnvVars(headers, allowedEnvVars, env) {
816
826
  return blank(name, "not-allowed");
817
827
  if (HOOK_ENV_CREDENTIAL_NAMES.has(name))
818
828
  return blank(name, "credential");
819
- return env[name] ?? "";
829
+ return env[name] ?? blank(name, "unset");
820
830
  });
821
831
  return [header, expanded.replace(HOOK_HEADER_FORBIDDEN, "")];
822
832
  });
package/dist/index.d.ts CHANGED
@@ -35,6 +35,7 @@ export * from "./api/scopes.js";
35
35
  export * from "./api/pull-token.js";
36
36
  export * from "./api/feedback.js";
37
37
  export * from "./api/credentials.js";
38
+ export * from "./api/lifecycle-events.js";
38
39
  export * from "./sandbox-git.js";
39
40
  export * from "./web-admin-env.js";
40
41
  export * from "./web-admin-credential.js";
@@ -47,5 +48,8 @@ export * from "./mcp-server-policy.js";
47
48
  export * from "./ui-language.js";
48
49
  export * from "./control-and-bidi.js";
49
50
  export * from "./mcp-request-entry.js";
51
+ export * from "./connector-id.js";
52
+ export * from "./mcp-entry-credential.js";
53
+ export * from "./connector-authorize-url.js";
50
54
  export { REMOTE_MCP_SERVER_NAME_PREFIX } from "./mcp-server-name.js";
51
55
  export * from "./center-refs.js";
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ export * from "./api/scopes.js"; // multi-tenant scope contract: /api/v1/scopes*
35
35
  export * from "./api/pull-token.js"; // scope-bound token FORM + minting rule (one rule, token families are data: WORKER_PULL_TOKEN) + claimed-binding reader + verifier (re-mint + constant-time compare), pure-JS HMAC-SHA256, browser-safe
36
36
  export * from "./api/feedback.js"; // /bug report wire contract: FeedbackSubmitRequest (POST body) + FeedbackWire / FeedbackListResponse + the two caps, pure/browser-safe
37
37
  export * from "./api/credentials.js"; // 14.7.0: the credential port's `sandbox_git` wire (barrel only, no subpath): SandboxGitCredentialRequest / CredentialHandleAnswer / CredentialResolveRequest / SandboxGitCredentialAnswer (per-origin SandboxGitOriginAnswer) / SandboxGitCredentialRefusal + the three word tables (SANDBOX_GIT_ORIGIN_VERDICTS → _STATES / _REASONS, SANDBOX_GIT_REFUSALS → _ERRORS, SANDBOX_GIT_PERMANENCE), pure/browser-safe
38
+ export * from "./api/lifecycle-events.js"; // 29.0.0: the user-lifecycle-event wire (barrel only, no subpath): PRINCIPAL_LIFECYCLE_EVENT_KINDS (five words) + PrincipalLifecycleEvent (unknown keys stripped, discriminated by `kind`; the two `membership.*` arms carry `scope`) + PrincipalLifecycleEventPage { events, head, next } + LIFECYCLE_PAGE_REFUSALS (four words → status; 410 bodies carry `head`) / LifecyclePageRefusal + the reconcile pair PrincipalReconcileRequest (1–PRINCIPAL_RECONCILE_MAX_ITEMS) / PrincipalReconcileAnswer (PrincipalStanding, discriminated by `standing`), pure/browser-safe
38
39
  export * from "./sandbox-git.js"; // 14.7.0: the sandbox git plane's origin form (isSandboxGitOrigin — a string equal to its own WHATWG origin) + the `sandboxGit` effective-config block (SandboxGitConfig: origins ≤ 16, each { origin, connectUrl }), pure/browser-safe
39
40
  export * from "./web-admin-env.js"; // WEB_ADMIN_ENV — every env name an engine reads to reach web-admin (one table; a leaf module), pure/browser-safe
40
41
  export * from "./web-admin-credential.js"; // S-698 web-admin credential FILE contract: WebAdminCredentialEnvelope (user-session envelope, strict) + parseWebAdminCredentialFile (bare / envelope / unreadable — the one discrimination law) + judgeWebAdminCredentialDeclaration(env, credential) (pick-exactly-one over the credential's WEB_ADMIN_ENV pair; WEB_ADMIN_CREDENTIALS = access | assertion), pure/browser-safe
@@ -46,7 +47,10 @@ export * from "./http-hook-allowlists.js"; // 13.0.0 (U3): allowedHttpHookUrls /
46
47
  export * from "./mcp-server-policy.js"; // 13.0.0 (U6): mcpServerPolicyVerdict → McpPolicyBlock{name, list, rule, target, written, sources} (structure, no sentence; target judged expanded, echoed only as written), pure/browser-safe
47
48
  export * from "./ui-language.js"; // 13.0.0 (S-1592): the UI-language settings fragment (semaUiLanguage, en | zh, category ui, user settings) + readUiLanguage, pure/browser-safe
48
49
  export * from "./control-and-bidi.js"; // the one-line echo strip set (C0 + DEL + the 12 Bidi_Control code points) — CONTROL_AND_BIDI_CHARS (the class, as regex source text) + stripControlAndBidi / hasControlOrBidi, pure/browser-safe
49
- export * from "./mcp-request-entry.js"; // 14.0.0: the request-plane MCP entry judges (isUsableWireName / isContentOriginWord / readMcpIdentityHeaders / readRequestMcpTransport + the value-shape describers) — one reading for the service legs and the shell pre-check, pure/browser-safe
50
+ export * from "./mcp-request-entry.js"; // 14.0.0: the request-plane MCP entry judges (isUsableWireName / isContentOriginWord / readRequestMcpTransport + the value-shape describers; 29.0.0: the request keys it refuses by name, MCP_REQUEST_KEY_REFUSALS) — one reading for the service legs and the shell pre-check, pure/browser-safe
51
+ export * from "./connector-id.js"; // 29.0.0: the connector id (ConnectorId / isConnectorId / CONNECTOR_ID_MAX / CONNECTOR_ID_RULE — a DNS label, compared by bytes), pure/browser-safe
52
+ export * from "./mcp-entry-credential.js"; // 29.0.0: the MCP http entry's credential reference (McpEntryCredential / MCP_ENTRY_CREDENTIAL_KINDS — read once by the engine primitives' readCredentialRef), pure/browser-safe
53
+ export * from "./connector-authorize-url.js"; // 29.0.0: the hosted connector authorization address (connectorAuthorizeUrlOf / connectorAuthorizeUrlFlaws / CONNECTOR_AUTHORIZE_QUERY / CONNECTOR_AUTHORIZE_URL_FLAWS — one route form, the assembler and its judge in one module), pure/browser-safe
50
54
  export { REMOTE_MCP_SERVER_NAME_PREFIX } from "./mcp-server-name.js"; // the MCP server-name prefix reserved for the remote MCP servers a device executor offers (mount name = prefix + the executor's server name); the predicate and its sentence stay package-private — the request plane's MCP name judges (isUsableMcpServerName / describeBadMcpServerName) read them; the config plane's McpServerSpec.name accepts the prefix (refusing it would be a validation tightening — a major), pure/browser-safe
51
55
  export * from "./center-refs.js"; // resolveCenterRefs(refs, lookup) — THE center-roster reference resolver: one verdict word per member (missing_name / not_a_string / read_threw, CENTER_REF_FAULTS), one whole verdict (resolved / unresolved / refs_unreadable, CENTER_REFS_VERDICTS); the refs record is read by the public readPlainStringRecord, the lookup is the caller's, it reads no process.env; pure/browser-safe
52
56
  // NOTE: the Node-fs-backed helpers (FileConfigStore + the file editor) are NOT in this barrel — they pull
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 配置面 MCP http 条目的凭据引用 `transport.credentials`(29.0.0)—— 纯函数、零 I/O、浏览器安全。
3
+ *
4
+ * ## 律(一条)
5
+ * **一条托管连接器条目「它是什么形」只有一个事实:`transport.credentials`。** 引用的合法性只有一只判官 —— 引擎原语包的 `readCredentialRef`
6
+ * (本包不自带第二份读法:读一次,沿用它交回的冻结副本);本包在它之上只加两格自己的事实:准入的种类(闭集 {@link MCP_ENTRY_CREDENTIAL_KINDS},
7
+ * 今天只有 `assertion`)与 `audience` 的取值域(连接器 id,`./connector-id`)。断言的头名归引擎(`MCP_ASSERTION_HEADER`),条目不说它。
8
+ *
9
+ * ## `audience` 的义
10
+ * 条目引用里的 `audience` 就是连接器 id,原样作断言的受众:铸断言的一方把它原样写进断言,托管连接器以同一个 id 启动(它做严格的串比较),
11
+ * 两边对的是同一个只有一种拼法的值。发往哪里归 `url`(必填,不变)。
12
+ *
13
+ * ## 拒句
14
+ * 按问题说形,不回显值:引用里的串(audience、成员名、种类词)都是调用方写的;句子只点名本包与原语包自己的词(种类闭集里的词、成员名表里的名)。
15
+ */
16
+ import { type CredentialRef } from "@sema-agent/primitives";
17
+ import { z } from "zod";
18
+ /** 配置面 MCP http 条目准入的凭据引用种类(闭集;原语包种类表的子集)。 */
19
+ export declare const MCP_ENTRY_CREDENTIAL_KINDS: readonly ["assertion"];
20
+ export type McpEntryCredentialKind = (typeof MCP_ENTRY_CREDENTIAL_KINDS)[number];
21
+ /** 一只准入的凭据引用 = 原语包引用里种类在 {@link MCP_ENTRY_CREDENTIAL_KINDS} 内的那几臂。 */
22
+ export type McpEntryCredential = Extract<CredentialRef, {
23
+ kind: McpEntryCredentialKind;
24
+ }>;
25
+ /**
26
+ * `transport.credentials` 的 zod 形:输入与产物都是 {@link McpEntryCredential};判法就是 {@link readMcpEntryCredential}(原语包读一次 + 准入种类 + 连接器 id),
27
+ * 产物是原语包交回的冻结副本(不是调用方的对象)。
28
+ */
29
+ export declare const McpEntryCredential: z.ZodPipe<z.ZodType<{
30
+ readonly kind: "assertion";
31
+ readonly audience: string;
32
+ }, {
33
+ readonly kind: "assertion";
34
+ readonly audience: string;
35
+ }, z.core.$ZodTypeInternals<{
36
+ readonly kind: "assertion";
37
+ readonly audience: string;
38
+ }, {
39
+ readonly kind: "assertion";
40
+ readonly audience: string;
41
+ }>>, z.ZodTransform<{
42
+ readonly kind: "assertion";
43
+ readonly audience: string;
44
+ }, {
45
+ readonly kind: "assertion";
46
+ readonly audience: string;
47
+ }>>;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 配置面 MCP http 条目的凭据引用 `transport.credentials`(29.0.0)—— 纯函数、零 I/O、浏览器安全。
3
+ *
4
+ * ## 律(一条)
5
+ * **一条托管连接器条目「它是什么形」只有一个事实:`transport.credentials`。** 引用的合法性只有一只判官 —— 引擎原语包的 `readCredentialRef`
6
+ * (本包不自带第二份读法:读一次,沿用它交回的冻结副本);本包在它之上只加两格自己的事实:准入的种类(闭集 {@link MCP_ENTRY_CREDENTIAL_KINDS},
7
+ * 今天只有 `assertion`)与 `audience` 的取值域(连接器 id,`./connector-id`)。断言的头名归引擎(`MCP_ASSERTION_HEADER`),条目不说它。
8
+ *
9
+ * ## `audience` 的义
10
+ * 条目引用里的 `audience` 就是连接器 id,原样作断言的受众:铸断言的一方把它原样写进断言,托管连接器以同一个 id 启动(它做严格的串比较),
11
+ * 两边对的是同一个只有一种拼法的值。发往哪里归 `url`(必填,不变)。
12
+ *
13
+ * ## 拒句
14
+ * 按问题说形,不回显值:引用里的串(audience、成员名、种类词)都是调用方写的;句子只点名本包与原语包自己的词(种类闭集里的词、成员名表里的名)。
15
+ */
16
+ import { readCredentialRef } from "@sema-agent/primitives";
17
+ import { z } from "zod";
18
+ import { CONNECTOR_ID_RULE, isConnectorId } from "./connector-id.js";
19
+ import { deepFreeze } from "./deep-freeze.js";
20
+ import { buildQuotedIssue, fixed } from "./quoted-issue.js";
21
+ /** 配置面 MCP http 条目准入的凭据引用种类(闭集;原语包种类表的子集)。 */
22
+ export const MCP_ENTRY_CREDENTIAL_KINDS = deepFreeze(["assertion"]);
23
+ /** 原语包读法的一处问题 → 句子(只点名原语包自己的成员名与种类词;调用方写的种类 / 多余成员名不回显)。穷举:原语包加一个问题词而这里不补 ⇒ 编译红。 */
24
+ function problemSentence(p) {
25
+ switch (p.reason) {
26
+ case "not_a_record":
27
+ return 'must be a credential reference: a plain object with a "kind" member';
28
+ case "unknown_kind":
29
+ return 'names a "kind" that is not a credential reference kind';
30
+ case "missing_field":
31
+ return `is missing its "${p.field}" member${p.kind === undefined ? "" : ` (a "${p.kind}" reference)`}`;
32
+ case "extra_field":
33
+ return `carries a member a "${p.kind}" reference does not have`;
34
+ case "bad_value":
35
+ return `has a "${p.field}" member of the wrong form (a non-empty data string, no control characters, no leading or trailing whitespace)`;
36
+ default: {
37
+ const unhandled = p;
38
+ throw new Error(`problemSentence: unhandled credential reference problem ${String(unhandled.reason)}`);
39
+ }
40
+ }
41
+ }
42
+ const isAdmittedKind = (kind) => MCP_ENTRY_CREDENTIAL_KINDS.includes(kind);
43
+ /**
44
+ * 读一只条目凭据引用:原语包读一次,种类过准入闭集,断言臂的 `audience` 过连接器 id 判官;交回的是原语包的冻结副本。从不抛。
45
+ * 拒句经 `buildQuotedIssue` 铸(包内 custom issue 的唯一铸点):句子里的每个词都是本包与原语包自己的(种类词、成员名、规则句),整句进模板、没有值位;调用方写的值一个不进句子。
46
+ */
47
+ function readMcpEntryCredential(value) {
48
+ const read = readCredentialRef(value);
49
+ if (!read.ok)
50
+ return { ok: false, issue: buildQuotedIssue `transport.credentials ${fixed(problemSentence(read.problem))}` };
51
+ const ref = read.ref;
52
+ if (!isAdmittedKind(ref.kind)) {
53
+ const admitted = MCP_ENTRY_CREDENTIAL_KINDS.map((k) => `"${k}"`).join(", ");
54
+ return { ok: false, issue: buildQuotedIssue `transport.credentials of kind "${fixed(ref.kind)}" is not admitted on an MCP http entry — the admitted kind is ${fixed(admitted)}` };
55
+ }
56
+ const credential = ref;
57
+ if (!isConnectorId(credential.audience))
58
+ return { ok: false, issue: buildQuotedIssue `transport.credentials.audience ${fixed(CONNECTOR_ID_RULE)}` };
59
+ return { ok: true, credential };
60
+ }
61
+ /** `transport.credentials` 的输入位:不跑任何检查的类型化 any(输入与产物同型 {@link McpEntryCredential});判法全在它后面的 transform(原语包读一次)。 */
62
+ const CREDENTIAL_INPUT = z.any();
63
+ /**
64
+ * `transport.credentials` 的 zod 形:输入与产物都是 {@link McpEntryCredential};判法就是 {@link readMcpEntryCredential}(原语包读一次 + 准入种类 + 连接器 id),
65
+ * 产物是原语包交回的冻结副本(不是调用方的对象)。
66
+ */
67
+ export const McpEntryCredential = CREDENTIAL_INPUT.transform((value, ctx) => {
68
+ const read = readMcpEntryCredential(value);
69
+ if (read.ok)
70
+ return read.credential;
71
+ ctx.addIssue({ code: "custom", ...read.issue });
72
+ return z.NEVER;
73
+ });
@@ -44,20 +44,23 @@ export declare function isContentOriginWord(v: unknown): v is McpContentOrigin;
44
44
  /** 坏内容出处值的**可打印**摘要:串 ⇒ 引号形的回显({@link quotedCallerText}:剥控制与双向字符、截 64 字);非串只说种类。 */
45
45
  export declare function describeBadContentOrigin(v: unknown): string;
46
46
  /**
47
- * 一份 http 传输上两个身份头(`principalHeader` / `assertionHeader`)的读法:字符串才收;**`principalHeader` 胜** —— 它在场(不论值形)时
48
- * `assertionHeader` 不收。所以读后的形**结构上不可能同带两键**;同设(一份声明给出两个答案)由调用方在读之前对**原始**传输判(判的是写了什么,不是读后留下什么)。
47
+ * 请求面读器**点名拒**的键的**原因词**(闭集,29.0.0)—— 与「表外未知键」分得开的那一类:读器认得这把键,知道它为什么不在请求面上。
48
+ * · `key_retired`:`transport.assertionHeader`(http)—— 29.0.0 退役:托管连接器的断言是部署的声明(配置面的 `transport.credentials`),头名归引擎,请求不说它;
49
+ * · `credentials_not_carried`:`transport.credentials`(两种传输)—— 请求面不承载凭据引用:引擎原语包的准入表(`CREDENTIAL_REF_TRUST`)对请求面拒 `env` / `handle` / `assertion`,
50
+ * 其余种类本版请求面也没有座位;引用是部署一侧的声明。
51
+ * 读到这两把键之一(自有键、值不是 `undefined`)⇒ 硬坏形({@link RequestMcpTransportRead} 的 `ok:false`),`issue.refusal` = 这里的词、`issue.path` 点名那把键、`issue.reason` 是原因句(不回显值)。
52
+ * 只靠继承可见 ⇒ 不读、不拒,进 `lost` 点名 —— 与身份头同一条律({@link axisKeyOf})。
53
+ * 判序 = 读序:`kind` 之后先读这两把键(其余键一个都还没读)—— 一条带着点名拒的键的条目,不论别处坏不坏、读不读得出,都读成这一类;两把都在 ⇒ `assertionHeader` 先。
54
+ * 消费方按词分派、不读句子;多一个词而穷尽 `switch` 不补 ⇒ 编译红。
49
55
  */
50
- export declare function readMcpIdentityHeaders(transport: Record<string, unknown>): {
51
- principalHeader?: string;
52
- assertionHeader?: string;
53
- };
56
+ export declare const MCP_REQUEST_KEY_REFUSALS: readonly ["key_retired", "credentials_not_carried"];
57
+ export type McpRequestKeyRefusal = (typeof MCP_REQUEST_KEY_REFUSALS)[number];
54
58
  /**
55
59
  * 请求面一条 MCP 条目的传输形。与引擎传输形的关系逐键一句(处置表,对拍 = 上游漂移门 ⑧):
56
60
  * · `kind` / `command` / `args` / `url` / `principalHeader` —— 与引擎同键同型;
57
61
  * · `env` / `headers` —— 请求带来的**字面件**:引擎的声明不带值(一台服务器的凭据头 / 子进程环境由部署的对端座每次发送时答),
58
62
  * 所以这两把键交给引擎之前由消费方从声明里拿走、按它自己的对端座答;
59
- * · `assertionHeader` —— 本包承载,引擎的 http 传输没有这个座(交给引擎之前由消费方剥掉);
60
- * · 引擎的 `credentials`(不透明的凭据引用)—— 请求面不收:读器不读它。
63
+ * · 引擎的 `credentials`(不透明的凭据引用)—— 请求面不承载:在场 ⇒ 读器点名拒(`credentials_not_carried`,{@link MCP_REQUEST_KEY_REFUSALS})。
61
64
  */
62
65
  export type RequestMcpTransport = {
63
66
  kind: "stdio";
@@ -69,7 +72,6 @@ export type RequestMcpTransport = {
69
72
  url: string;
70
73
  headers?: Record<string, string>;
71
74
  principalHeader?: string;
72
- assertionHeader?: string;
73
75
  };
74
76
  /**
75
77
  * 条目内一处坏形:`path` = 条目内的键路径(`transport.url`),`reason` = 判官的原因句(只说形与词表,不回显值)。
@@ -80,14 +82,17 @@ export type RequestMcpTransport = {
80
82
  * · `member_name_reserved`:有成员叫保留名({@link RESERVED_MEMBER_NAMES}:`__proto__` / `constructor` / `prototype`)。值是串 ⇒ 只剔它、其余照交,每个一条、`path` 是成员级(`transport.env.__proto__`);
81
83
  * 成员的值也不是串(或读不出)⇒ 整张记录不交,`path` 是键级,句子一次说全两件事 —— 名坏优先、值坏并列,所以词仍是 `member_name_reserved`。
82
84
  * `member` 是成员名的**回显形**(剥控制与双向字符、截 64 字加 `…`),可直接进日志与句子,不是回查原对象的键。其余的坏形(`args` / `url` / `principalHeader` / ……)两格都不带。
85
+ *
86
+ * `refusal` 只在**点名拒**的硬坏形上(闭集词 {@link MCP_REQUEST_KEY_REFUSALS}):读器认得这把键、知道它为什么不在请求面上 —— 消费方据它把「已退役 / 不承载的键」与「表外未知键」分开处置。
83
87
  */
84
88
  export interface McpEntryKeyIssue {
85
89
  readonly path: string;
86
90
  readonly reason: string;
87
91
  readonly member?: string;
88
92
  readonly fault?: PlainStringRecordFault;
93
+ readonly refusal?: McpRequestKeyRefusal;
89
94
  }
90
- /** {@link readRequestMcpTransport} 的结果:`ok:false` = 硬坏形(这条 server 无从挂载);`ok:true` 的 `lost` = 读器**丢掉**的可选子键(server 照挂、少一个声明)。 */
95
+ /** {@link readRequestMcpTransport} 的结果:`ok:false` = 硬坏形(这条 server 无从挂载;`issue.refusal` 在场 = 读器点名拒的键,见 {@link MCP_REQUEST_KEY_REFUSALS});`ok:true` 的 `lost` = 读器**丢掉**的可选子键(server 照挂、少一个声明)。 */
91
96
  export type RequestMcpTransportRead = {
92
97
  ok: true;
93
98
  transport: RequestMcpTransport;
@@ -98,12 +103,12 @@ export type RequestMcpTransportRead = {
98
103
  };
99
104
  /**
100
105
  * 请求面 `transport` 的**唯一读器**:读器投影 transport 用它,发送前 / 受理时的判形读它报的 `lost` —— 同一只函数两个消费点,「读器丢了什么」与「门拒什么」不可能分岔。
101
- * · 硬坏形(`transport` 不是对象 / `kind` 出闭集 / stdio 缺 `command` / http 的 `url` 不是 http(s))⇒ `ok:false`,`path` 是读器点名的键路径;
106
+ * · 硬坏形(`transport` 不是对象 / `kind` 出闭集 / 点名拒的键在场({@link MCP_REQUEST_KEY_REFUSALS},先于其余键判)/ stdio 缺 `command` / http 的 `url` 不是 http(s))⇒ `ok:false`,`path` 是读器点名的键路径;
102
107
  * · 软坏形(`args` 不是串数组 / `env` `headers` 不是纯数据的串记录 / `principalHeader` 非串)⇒ 读器**丢这个键**(重放存量提交体时的升级前读法),并把它记进 `lost`
103
- * (受理新提交的门据它响亮拒)。`assertionHeader` 不在 `lost` 里:两个身份头的键组合与 `assertionHeader` 的值形由调用方在读之前对原始传输判。
108
+ * (受理新提交的门据它响亮拒);身份 / 凭据轴上的键({@link AXIS_KEYS}:`principalHeader` / `assertionHeader` / `credentials`)只靠继承可见 ⇒ 不读值、不拒、进 `lost` 点名;
104
109
  * · `env` / `headers` 只收**纯数据**的记录({@link readPlainStringRecord}):必须是朴素 JSON 对象(`./plain-json-object` 的判据;`Map`、`Set`、类实例整张不收),每个自有成员的值都是串;
105
110
  * 交出的是**副本**(不是调用方的对象,改原对象不影响读后的形)。名叫保留名({@link RESERVED_MEMBER_NAMES})的成员不进副本、每个单独记进 `lost`。
106
- * 坏形的 `lost` 条目带机读位(见 {@link McpEntryKeyIssue})。
111
+ * 坏形的 `lost` 条目带机读位(见 {@link McpEntryKeyIssue})。这两键的读法与诊断就是公开读口 {@link readRequestStringRecord} 以 `transport.env` / `transport.headers` 为坐标的读数。
107
112
  * url 的拒句不回显值:它常规地带凭据(userinfo)。
108
113
  */
109
114
  export declare function readRequestMcpTransport(t: unknown): RequestMcpTransportRead;
@@ -137,3 +142,17 @@ export type PlainStringRecordRead = {
137
142
  * 名叫保留名而值也坏的成员,句子一次说全两件事(名坏在前、值坏并列):调用方照值改完再撞第二条是两步才改对。
138
143
  */
139
144
  export declare function readPlainStringRecord(v: unknown): PlainStringRecordRead;
145
+ /** {@link readRequestStringRecord} 的读数:`record` = 交出去的纯数据副本(缺席或不交 ⇒ `undefined`);`issues` = 这份记录在坐标上的诊断(零条或多条,形见 {@link McpEntryKeyIssue})。 */
146
+ export interface RequestStringRecordRead {
147
+ readonly record: Record<string, string> | undefined;
148
+ readonly issues: readonly McpEntryKeyIssue[];
149
+ }
150
+ /**
151
+ * 请求面一份「名 → 串」记录的**带坐标读法** —— 公开读口:传输读器读 `transport.env` / `transport.headers` 就是它的两次调用;消费方读自己的「名 → 串」记录
152
+ * (A2A 对端的 `headers` 一类)调同一只,诊断与 MCP 传输同形同句,不另拼原因句。`path` = 这份记录在调用方载荷里的坐标(原样进诊断,不解析)。从不抛。
153
+ * · 缺席(`undefined`)⇒ 不交、零条;
154
+ * · 记录不交({@link readPlainStringRecord} 答 `ok:false`)⇒ 恰一条,`path` 是坐标本身,`reason` = `must be a plain object of string values — ` + 读数的 `detail`,
155
+ * `fault` 与(坏在某个成员时)`member` 取自读数;
156
+ * · 交 ⇒ 纯数据副本;名叫保留名({@link RESERVED_MEMBER_NAMES})的成员不进副本,每个一条:`path` = `<坐标>.<名>`、`member` = 名、`fault` = `member_name_reserved`。
157
+ */
158
+ export declare function readRequestStringRecord(path: string, raw: unknown): RequestStringRecordRead;