@sema-agent/settings-schema 28.0.0 → 30.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 (179) hide show
  1. package/CHANGELOG.md +431 -0
  2. package/README.md +94 -14
  3. package/conformance/VERSION +1 -1
  4. package/conformance/cases/c01-entry-salvage-then-typo/expected.json +2 -2
  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 +3 -3
  53. package/conformance/cases/c58-s784-g2-multitenant-host/expected.json +3 -3
  54. package/conformance/cases/c59-s784-g3-k8s-missing-image/expected.json +3 -3
  55. package/conformance/cases/c60-s784-g3-e2b-missing-key/expected.json +3 -3
  56. package/conformance/cases/c61-s784-g3-other-lane-key/expected.json +3 -3
  57. package/conformance/cases/c62-s784-g7a-session-tidb/expected.json +3 -3
  58. package/conformance/cases/c63-s784-host-two-replicas/expected.json +3 -3
  59. package/conformance/cases/c64-s784-multitenant-local-store/expected.json +3 -3
  60. package/conformance/cases/c65-s784-pg-without-db/expected.json +3 -3
  61. package/conformance/cases/c66-s784-memory-backend-mismatch/expected.json +3 -3
  62. package/conformance/cases/c67-s784-retired-field-loud/expected.json +3 -3
  63. package/conformance/cases/c68-s784-device-local-store/expected.json +3 -3
  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 +2 -2
  72. package/conformance/cases/c77-prompts-center-artifact-carried/expected.json +1 -1
  73. package/conformance/cases/c78-prompts-empty-bindings-refused/expected.json +2 -2
  74. package/conformance/cases/c78-prompts-empty-bindings-refused/meta.json +1 -1
  75. package/conformance/cases/c79-prompts-bad-worker-artifact-not-salvaged/expected.json +1 -1
  76. package/conformance/cases/c80-prompts-wire-v2-verbatim/expected.json +1 -1
  77. package/conformance/cases/c81-prompts-declaration-bindings-refused/expected.json +2 -2
  78. package/conformance/cases/c82-prompts-v1-catalog-refused/expected.json +2 -2
  79. package/conformance/cases/c83-prompts-bad-overlay-not-salvaged/expected.json +1 -1
  80. package/conformance/cases/c84-sandbox-git-block-carried-verbatim/expected.json +1 -1
  81. package/conformance/cases/c85-sandbox-git-refused-block-still-carried/expected.json +1 -1
  82. package/conformance/cases/c86-a2a-peers-legal/expected.json +1 -1
  83. package/conformance/cases/c87-a2a-credential-refs-not-partially-salvaged/expected.json +1 -1
  84. package/conformance/cases/c88-projects-content-attestation-carried/expected.json +1 -1
  85. package/conformance/cases/c89-projects-content-attestation-malformed/expected.json +1 -1
  86. package/conformance/cases/c90-mcp-assertion-credential-carried/expected.json +143 -0
  87. package/conformance/cases/c90-mcp-assertion-credential-carried/input.json +30 -0
  88. package/conformance/cases/c90-mcp-assertion-credential-carried/meta.json +6 -0
  89. package/conformance/cases/c91-mcp-assertion-header-retired-entry-dropped/expected.json +105 -0
  90. package/conformance/cases/c91-mcp-assertion-header-retired-entry-dropped/input.json +27 -0
  91. package/conformance/cases/c91-mcp-assertion-header-retired-entry-dropped/meta.json +6 -0
  92. package/conformance/cases/c92-mcp-principal-header-with-assertion-dropped/expected.json +105 -0
  93. package/conformance/cases/c92-mcp-principal-header-with-assertion-dropped/input.json +31 -0
  94. package/conformance/cases/c92-mcp-principal-header-with-assertion-dropped/meta.json +6 -0
  95. package/conformance/cases/c93-mcp-header-refs-with-credentials-dropped/expected.json +105 -0
  96. package/conformance/cases/c93-mcp-header-refs-with-credentials-dropped/input.json +33 -0
  97. package/conformance/cases/c93-mcp-header-refs-with-credentials-dropped/meta.json +6 -0
  98. package/conformance/cases/c94-mcp-credentials-env-kind-dropped/expected.json +105 -0
  99. package/conformance/cases/c94-mcp-credentials-env-kind-dropped/input.json +32 -0
  100. package/conformance/cases/c94-mcp-credentials-env-kind-dropped/meta.json +6 -0
  101. package/conformance/cases/c95-mcp-credentials-audience-not-connector-id-dropped/expected.json +105 -0
  102. package/conformance/cases/c95-mcp-credentials-audience-not-connector-id-dropped/input.json +30 -0
  103. package/conformance/cases/c95-mcp-credentials-audience-not-connector-id-dropped/meta.json +6 -0
  104. package/conformance/cases/c96-mcp-credentials-extra-member-dropped/expected.json +105 -0
  105. package/conformance/cases/c96-mcp-credentials-extra-member-dropped/input.json +31 -0
  106. package/conformance/cases/c96-mcp-credentials-extra-member-dropped/meta.json +6 -0
  107. package/conformance/cases/cc01-mcp-toolfaces-non-object/expected.json +1 -1
  108. package/conformance/cases/cc02-mcp-source-key-is-transported/expected.json +1 -1
  109. package/conformance/cases/cc03-model-compat-unknown-subkey/expected.json +1 -1
  110. package/conformance/cases/cli01-model-name-nfc-vs-nfd/expected.json +1 -1
  111. package/conformance/cases/cli02-control-and-zero-width-chars/expected.json +1 -1
  112. package/conformance/cases/cli03-credential-pasted-into-unknown-key/expected.json +1 -1
  113. package/conformance/cases/cli04-env-value-with-newline/expected.json +1 -1
  114. package/conformance/cases/cli04-env-value-with-newline/meta.json +1 -1
  115. package/conformance/cases/cli05-long-and-prefix-colliding-names/expected.json +1 -1
  116. package/conformance/cases/t01-absent-domain-key-not-null/expected.json +1 -1
  117. package/conformance/cases/t01-absent-domain-key-not-null/meta.json +1 -1
  118. package/conformance/cases/t03-prototype-name-key-not-swallowed/expected.json +1 -1
  119. package/conformance/cases/t04-secret-literal-never-in-warning-value/expected.json +1 -1
  120. package/conformance/cases/t04-secret-literal-never-in-warning-value/meta.json +1 -1
  121. package/conformance/cases/z01-every-domain-empty-object/expected.json +1 -1
  122. package/conformance/cases/z01-every-domain-empty-object/meta.json +1 -1
  123. package/conformance/cases/z02-every-domain-unknown-key/expected.json +1 -1
  124. package/dist/api/credentials.js +5 -7
  125. package/dist/api/lifecycle-events.d.ts +266 -0
  126. package/dist/api/lifecycle-events.js +169 -0
  127. package/dist/api/wire-scalars.d.ts +13 -0
  128. package/dist/api/wire-scalars.js +15 -0
  129. package/dist/atomic-write.d.ts +4 -0
  130. package/dist/atomic-write.js +26 -3
  131. package/dist/config-d-file.d.ts +1 -1
  132. package/dist/config-document-refusal.d.ts +4 -4
  133. package/dist/config-fns.d.ts +4 -2
  134. package/dist/config-fns.js +1 -1
  135. package/dist/config-root-documents.d.ts +1 -1
  136. package/dist/config-root-node.js +2 -1
  137. package/dist/conformance/corpus.d.ts +1 -1
  138. package/dist/conformance/derive.d.ts +13 -5
  139. package/dist/conformance/derive.js +37 -21
  140. package/dist/conformance/index.d.ts +1 -1
  141. package/dist/conformance/index.js +1 -1
  142. package/dist/conformance/run.js +8 -9
  143. package/dist/connector-authorize-url.d.ts +23 -0
  144. package/dist/connector-authorize-url.js +129 -0
  145. package/dist/connector-id.d.ts +23 -0
  146. package/dist/connector-id.js +27 -0
  147. package/dist/file-edit.d.ts +44 -0
  148. package/dist/file-edit.js +70 -1
  149. package/dist/file-store.d.ts +12 -7
  150. package/dist/file-store.js +72 -59
  151. package/dist/hooks.d.ts +15 -5
  152. package/dist/hooks.js +13 -3
  153. package/dist/index.d.ts +4 -0
  154. package/dist/index.js +5 -1
  155. package/dist/mcp-entry-credential.d.ts +47 -0
  156. package/dist/mcp-entry-credential.js +73 -0
  157. package/dist/mcp-request-entry.d.ts +32 -13
  158. package/dist/mcp-request-entry.js +104 -58
  159. package/dist/migration-receipt.d.ts +2 -2
  160. package/dist/migration-receipt.js +2 -2
  161. package/dist/one-time-migrations.d.ts +1 -1
  162. package/dist/one-time-migrations.js +68 -91
  163. package/dist/portable-domains.d.ts +18 -12
  164. package/dist/portable-domains.js +17 -12
  165. package/dist/retired-role-words.d.ts +1 -1
  166. package/dist/retired-role-words.js +4 -6
  167. package/dist/scheduler-store-node.d.ts +5 -2
  168. package/dist/scheduler-store-node.js +8 -5
  169. package/dist/sha256.d.ts +5 -0
  170. package/dist/sha256.js +7 -0
  171. package/dist/skills-manifest.js +2 -2
  172. package/dist/types.d.ts +80 -10
  173. package/dist/types.js +37 -44
  174. package/docs/API-SURFACE.md +47 -7
  175. package/docs/CONFORMANCE.md +6 -4
  176. package/docs/CONSUMER-INTEGRATION.md +147 -4
  177. package/llms-full.txt +45 -24
  178. package/llms.txt +27 -14
  179. package/package.json +3 -2
@@ -0,0 +1,266 @@
1
+ /**
2
+ * `api/lifecycle-events` —— 用户生命周期事件的 wire 型(29.0.0):管理面把「一个主体被删 / 被降级 / 被移出空间」这类事实发成一串带序号的事件,
3
+ * 执行面按页拉取、按序号去重,并在启动与游标失效时用「对账」补齐现状。一份 zod,发这些形的一方(管理面)与收这些形的一方(执行面)同 import。纯、浏览器安全。
4
+ *
5
+ * 本模块只有**形与词表**:事件怎么产生与存放、保留多久、页怎么切、`head` 怎么算、鉴权与委托、消费方拿事件做什么(停谁的活),都是各方自己的事,不在这里。
6
+ * 拉取口的查询参数(`after` / `limit`)不是体,本模块不立它们的型;拒词({@link LIFECYCLE_PAGE_REFUSALS})只管游标与分页这四种,
7
+ * 鉴权类的拒答(401 / 403)不在这张表里。
8
+ *
9
+ * ## 解析一律剥未知键(与同目录的凭据 wire 型同一条规则)
10
+ * 对象型里不认识的**键**被剥掉、不进解析结果、不拒 —— 新键恒为加性,发方与收方各自独立升级。**例外只有一个:不认识的 `kind` 值**(事件行的判别键)
11
+ * 响亮地拒,整页随之拒,拒句点名那个词(坐标带它在 `events` 里的下标):`kind` 是闭集,收方悄悄丢掉一条自己不认识的生命周期事件 = 安全面的静默放过。
12
+ * 同理 `standing` / `error` 这两个判别键里不认识的词也拒。
13
+ *
14
+ * ## 事件
15
+ * 一条事件 = 一个按 `kind` 判别的对象。五个 `kind`(闭集 {@link PRINCIPAL_LIFECYCLE_EVENT_KINDS}):
16
+ * · `principal.deleted` —— 主体的 users 行被删;`principalInc` 取被删那一行的。不带 `scope`。
17
+ * · `principal.pending` —— 主体的实例角色从 `admin` 改走,且此刻没有任何空间成员资格。不带 `scope`。
18
+ * · `principal.role_lowered` —— 主体的实例角色从 `admin` 改走,但仍有空间成员资格。不带 `scope`:消费方立即对该主体对账。
19
+ * · `membership.removed` —— 一条空间成员行被删,且该主体不是实例 `admin`。**必带** `scope`。
20
+ * · `membership.role_lowered` —— 一个空间角色跨过 `editor` 底线往下降。**必带** `scope`。
21
+ * 共有成员:`eventId`(非空串;审计与跨库恢复时辨认事件)· `seq`(≥ 1 的安全整数;发方给的单调序号,收方的**去重键**)· `principal`(主体名,界同令牌 `sub`)·
22
+ * `principalInc`(可缺席;化身号,与令牌 `sub_inc` 同一只 {@link PrincipalIncarnation} —— 同一个名字被删后重建是另一个人,靠它分辨)· `at`(毫秒时刻,发方的钟)。
23
+ *
24
+ * ## 页与游标
25
+ * 一页 = `{ events, head, next }`:`events` 按 `seq` 升序(可以是空页);`head` = 发方此刻的头游标(收方「启动与游标失效」时先取它、再对账、再从它起拉);
26
+ * `next` = 下一次拉取带的游标(只进不退)。三个成员都不可缺席;游标是安全整数。
27
+ * 拉取失败的四个词({@link LIFECYCLE_PAGE_REFUSALS}):`cursor_invalid` / `limit_invalid`(400,请求自己不合格)· `cursor_expired`(游标早于发方还保留的最早位置)/
28
+ * `cursor_unknown`(游标晚于发方已知的位置,例如发方的库恢复到更早的备份)(410,拒体带 `head`:收方的重同步程序从它起)。
29
+ * 拒体 = `{ error, permanence, message }`(410 的词再加 `head`),与凭据 wire 的拒体同一种形(码 + 永久性);四个词的永久性都是 `terminal`(同一请求原样重发不会成功)。
30
+ *
31
+ * ## 对账
32
+ * 请求 {@link PrincipalReconcileRequest} = `{ principals: [{ principal, principalInc? }] }`,1 – {@link PRINCIPAL_RECONCILE_MAX_ITEMS} 项;
33
+ * 应答 {@link PrincipalReconcileAnswer} = `{ principals: [...] }`,每项回显请求里的身份元组并按 `standing` 判别:`live`(仍在;`since` 可缺席,只在这一臂)/ `gone`(不在了)。
34
+ * 应答与请求逐项对应(同序同长)是收方要核的事,本形只钉 1 – {@link PRINCIPAL_RECONCILE_MAX_ITEMS} 项。
35
+ */
36
+ import { z } from "zod";
37
+ /**
38
+ * 事件 `kind` 表(包内私有):一词一行 `{ kind, scoped }` —— **每个词只在这里拼一次**;`scoped` = 这一臂**必带** `scope`(`membership.*` 两词),其余臂不带。
39
+ * 词表({@link PRINCIPAL_LIFECYCLE_EVENT_KINDS})、词的类型({@link PrincipalLifecycleEventKind})与事件行联合({@link PrincipalLifecycleEvent})的每一臂都由它派生,没有第二张词表。
40
+ */
41
+ declare const EVENT_KIND_ROWS: readonly [{
42
+ readonly kind: "principal.deleted";
43
+ readonly scoped: false;
44
+ }, {
45
+ readonly kind: "principal.pending";
46
+ readonly scoped: false;
47
+ }, {
48
+ readonly kind: "principal.role_lowered";
49
+ readonly scoped: false;
50
+ }, {
51
+ readonly kind: "membership.removed";
52
+ readonly scoped: true;
53
+ }, {
54
+ readonly kind: "membership.role_lowered";
55
+ readonly scoped: true;
56
+ }];
57
+ type EventKindRows = typeof EVENT_KIND_ROWS;
58
+ /** 表的 `kind` 列(类型面;按元组逐位映射,保住「五个字面量的只读元组」)。 */
59
+ type KindColumn<Rows extends readonly {
60
+ readonly kind: string;
61
+ }[]> = {
62
+ readonly [I in keyof Rows]: Rows[I]["kind"];
63
+ };
64
+ /** 用户生命周期事件的 `kind`(闭集,五个,按表序)。事件行的联合按它判别;`membership.*` 两词的臂必带 `scope`,`principal.*` 三词的臂不带。 */
65
+ export type PrincipalLifecycleEventKind = EventKindRows[number]["kind"];
66
+ /** 用户生命周期事件的 `kind` 词表(运行期;定义处深冻结;表的 `kind` 列,按表序)。 */
67
+ export declare const PRINCIPAL_LIFECYCLE_EVENT_KINDS: KindColumn<EventKindRows>;
68
+ /**
69
+ * 一条用户生命周期事件,按 `kind` 判别;臂由 `kind` 表派生,每词一臂、同序。未知键剥掉(`principal.*` 臂带的 `scope` 也是它那一臂的未知键,同样剥掉);
70
+ * `membership.*` 臂缺 `scope` 拒;**未知的 `kind` 值拒,句子点名那个词**(经 {@link echoCallerText} 回显:剥控制与双向字符、有界)。
71
+ * `kind` 不是字符串 / 缺席时没有词可点,句子是 zod 自己的、不回显值。
72
+ */
73
+ export declare const PrincipalLifecycleEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
74
+ at: z.ZodNumber;
75
+ principal: z.ZodString;
76
+ principalInc: z.ZodOptional<z.ZodString>;
77
+ eventId: z.ZodString;
78
+ seq: z.ZodNumber;
79
+ kind: z.ZodLiteral<"principal.deleted">;
80
+ }, z.core.$strip>, z.ZodObject<{
81
+ at: z.ZodNumber;
82
+ principal: z.ZodString;
83
+ principalInc: z.ZodOptional<z.ZodString>;
84
+ eventId: z.ZodString;
85
+ seq: z.ZodNumber;
86
+ kind: z.ZodLiteral<"principal.pending">;
87
+ }, z.core.$strip>, z.ZodObject<{
88
+ at: z.ZodNumber;
89
+ principal: z.ZodString;
90
+ principalInc: z.ZodOptional<z.ZodString>;
91
+ eventId: z.ZodString;
92
+ seq: z.ZodNumber;
93
+ kind: z.ZodLiteral<"principal.role_lowered">;
94
+ }, z.core.$strip>, z.ZodObject<{
95
+ scope: z.ZodString;
96
+ at: z.ZodNumber;
97
+ principal: z.ZodString;
98
+ principalInc: z.ZodOptional<z.ZodString>;
99
+ eventId: z.ZodString;
100
+ seq: z.ZodNumber;
101
+ kind: z.ZodLiteral<"membership.removed">;
102
+ }, z.core.$strip>, z.ZodObject<{
103
+ scope: z.ZodString;
104
+ at: z.ZodNumber;
105
+ principal: z.ZodString;
106
+ principalInc: z.ZodOptional<z.ZodString>;
107
+ eventId: z.ZodString;
108
+ seq: z.ZodNumber;
109
+ kind: z.ZodLiteral<"membership.role_lowered">;
110
+ }, z.core.$strip>], "kind">;
111
+ export type PrincipalLifecycleEvent = z.infer<typeof PrincipalLifecycleEvent>;
112
+ /**
113
+ * 一页事件:`events`(按 `seq` 升序,可以是空页)· `head`(发方此刻的头游标)· `next`(下一次拉取带的游标,只进不退)。三个成员都不可缺席;未知键剥掉;
114
+ * 页里有一条事件的 `kind` 不认识 ⇒ 整页拒(坐标 `events.<下标>.kind`)。
115
+ * 页的长度上界、`seq` 在页内是否升序、`next` 与最后一条事件的关系都是发方的事,本形不核。
116
+ */
117
+ export declare const PrincipalLifecycleEventPage: z.ZodObject<{
118
+ events: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
119
+ at: z.ZodNumber;
120
+ principal: z.ZodString;
121
+ principalInc: z.ZodOptional<z.ZodString>;
122
+ eventId: z.ZodString;
123
+ seq: z.ZodNumber;
124
+ kind: z.ZodLiteral<"principal.deleted">;
125
+ }, z.core.$strip>, z.ZodObject<{
126
+ at: z.ZodNumber;
127
+ principal: z.ZodString;
128
+ principalInc: z.ZodOptional<z.ZodString>;
129
+ eventId: z.ZodString;
130
+ seq: z.ZodNumber;
131
+ kind: z.ZodLiteral<"principal.pending">;
132
+ }, z.core.$strip>, z.ZodObject<{
133
+ at: z.ZodNumber;
134
+ principal: z.ZodString;
135
+ principalInc: z.ZodOptional<z.ZodString>;
136
+ eventId: z.ZodString;
137
+ seq: z.ZodNumber;
138
+ kind: z.ZodLiteral<"principal.role_lowered">;
139
+ }, z.core.$strip>, z.ZodObject<{
140
+ scope: z.ZodString;
141
+ at: z.ZodNumber;
142
+ principal: z.ZodString;
143
+ principalInc: z.ZodOptional<z.ZodString>;
144
+ eventId: z.ZodString;
145
+ seq: z.ZodNumber;
146
+ kind: z.ZodLiteral<"membership.removed">;
147
+ }, z.core.$strip>, z.ZodObject<{
148
+ scope: z.ZodString;
149
+ at: z.ZodNumber;
150
+ principal: z.ZodString;
151
+ principalInc: z.ZodOptional<z.ZodString>;
152
+ eventId: z.ZodString;
153
+ seq: z.ZodNumber;
154
+ kind: z.ZodLiteral<"membership.role_lowered">;
155
+ }, z.core.$strip>], "kind">>;
156
+ head: z.ZodNumber;
157
+ next: z.ZodNumber;
158
+ }, z.core.$strip>;
159
+ export type PrincipalLifecycleEventPage = z.infer<typeof PrincipalLifecycleEventPage>;
160
+ /**
161
+ * 拉取失败词(游标与分页这一类,四个)→ 它的 HTTP 状态码与永久性。**一个词只有一个状态码、一个永久性**,表是它们的唯一一处:
162
+ * · 400 —— 请求自己不合格:`cursor_invalid`(游标不是合法游标)/ `limit_invalid`(页长不合法);
163
+ * · 410 —— 游标对不上发方的现状,收方要重同步:`cursor_expired`(游标早于发方还保留的最早位置)/ `cursor_unknown`(游标晚于发方已知的位置)。
164
+ * **410 的拒体带 `head`**(收方从它起重新拉);400 的拒体不带。「带不带 `head`」由这一列推出,不另立一张表({@link LifecyclePageRefusal})。
165
+ * 永久性({@link SandboxGitPermanence},词表在凭据 wire 里):四个词都是 `terminal` —— 同一请求原样重发不会成功(400 的要改请求,410 的要先重新同步);拒体里的 `permanence` 必须等于这一行的。
166
+ * 鉴权类的拒答不在这张表里。
167
+ */
168
+ export declare const LIFECYCLE_PAGE_REFUSALS: {
169
+ readonly cursor_invalid: {
170
+ readonly status: 400;
171
+ readonly permanence: "terminal";
172
+ };
173
+ readonly limit_invalid: {
174
+ readonly status: 400;
175
+ readonly permanence: "terminal";
176
+ };
177
+ readonly cursor_expired: {
178
+ readonly status: 410;
179
+ readonly permanence: "terminal";
180
+ };
181
+ readonly cursor_unknown: {
182
+ readonly status: 410;
183
+ readonly permanence: "terminal";
184
+ };
185
+ };
186
+ /** 拉取失败词(闭集,四个)—— 类型由 {@link LIFECYCLE_PAGE_REFUSALS} 派生。 */
187
+ export type LifecyclePageRefusalError = keyof typeof LIFECYCLE_PAGE_REFUSALS;
188
+ /** 拉取失败词表(运行期;表的键,按表序)。 */
189
+ export declare const LIFECYCLE_PAGE_REFUSAL_ERRORS: readonly [LifecyclePageRefusalError, ...LifecyclePageRefusalError[]];
190
+ /**
191
+ * 拉取失败的体,按 `error` 判别(与凭据 wire 的拒体同一种形:码 + 永久性 + 诊断句):
192
+ * · 400 的词:`{ error, permanence, message }`;
193
+ * · 410 的词:`{ error, permanence, message, head }` —— `head` = 发方此刻的头游标(安全整数)。
194
+ * `permanence` 是错误词的函数,必须等于 {@link LIFECYCLE_PAGE_REFUSALS} 里这一行的,两处不一致就是畸形应答(拒)。
195
+ * `message` 是发方的诊断句(收方不据它判,可为空串)。体里不带状态码:状态码是 HTTP 层的,词与状态码的对应只看 {@link LIFECYCLE_PAGE_REFUSALS}。未知键剥掉。
196
+ */
197
+ export declare const LifecyclePageRefusal: z.ZodDiscriminatedUnion<[z.ZodObject<{
198
+ permanence: z.ZodEnum<{
199
+ terminal: "terminal";
200
+ transient: "transient";
201
+ }>;
202
+ message: z.ZodString;
203
+ error: z.ZodEnum<{
204
+ cursor_invalid: "cursor_invalid";
205
+ limit_invalid: "limit_invalid";
206
+ }>;
207
+ }, z.core.$strip>, z.ZodObject<{
208
+ head: z.ZodNumber;
209
+ permanence: z.ZodEnum<{
210
+ terminal: "terminal";
211
+ transient: "transient";
212
+ }>;
213
+ message: z.ZodString;
214
+ error: z.ZodEnum<{
215
+ cursor_expired: "cursor_expired";
216
+ cursor_unknown: "cursor_unknown";
217
+ }>;
218
+ }, z.core.$strip>], "error">;
219
+ export type LifecyclePageRefusal = z.infer<typeof LifecyclePageRefusal>;
220
+ /** 一次对账请求(与应答)里最多几项。 */
221
+ export declare const PRINCIPAL_RECONCILE_MAX_ITEMS = 500;
222
+ /** 对账请求的一项:要问现状的那个身份元组。 */
223
+ export declare const PrincipalReconcileItem: z.ZodObject<{
224
+ principal: z.ZodString;
225
+ principalInc: z.ZodOptional<z.ZodString>;
226
+ }, z.core.$strip>;
227
+ export type PrincipalReconcileItem = z.infer<typeof PrincipalReconcileItem>;
228
+ /** 对账请求:`{ principals }`,1 – {@link PRINCIPAL_RECONCILE_MAX_ITEMS} 项;未知键剥掉。 */
229
+ export declare const PrincipalReconcileRequest: z.ZodObject<{
230
+ principals: z.ZodArray<z.ZodObject<{
231
+ principal: z.ZodString;
232
+ principalInc: z.ZodOptional<z.ZodString>;
233
+ }, z.core.$strip>>;
234
+ }, z.core.$strip>;
235
+ export type PrincipalReconcileRequest = z.infer<typeof PrincipalReconcileRequest>;
236
+ /**
237
+ * 一个主体的现状,按 `standing` 判别;回显请求里的身份元组(`principal`、可缺席的 `principalInc`);未知键剥掉:
238
+ * · `live` —— 仍在;`since`(毫秒时刻,可缺席)**只在这一臂**:这一段「在」的起点;
239
+ * · `gone` —— 不在了;这一臂的形没有 `since`(带了的被剥掉)。
240
+ */
241
+ export declare const PrincipalStanding: z.ZodDiscriminatedUnion<[z.ZodObject<{
242
+ since: z.ZodOptional<z.ZodNumber>;
243
+ principal: z.ZodString;
244
+ principalInc: z.ZodOptional<z.ZodString>;
245
+ standing: z.ZodLiteral<"live">;
246
+ }, z.core.$strip>, z.ZodObject<{
247
+ principal: z.ZodString;
248
+ principalInc: z.ZodOptional<z.ZodString>;
249
+ standing: z.ZodLiteral<"gone">;
250
+ }, z.core.$strip>], "standing">;
251
+ export type PrincipalStanding = z.infer<typeof PrincipalStanding>;
252
+ /** 对账应答:`{ principals }`,每项是一个 {@link PrincipalStanding};1 – {@link PRINCIPAL_RECONCILE_MAX_ITEMS} 项(与请求逐项对应是收方要核的事);未知键剥掉。 */
253
+ export declare const PrincipalReconcileAnswer: z.ZodObject<{
254
+ principals: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
255
+ since: z.ZodOptional<z.ZodNumber>;
256
+ principal: z.ZodString;
257
+ principalInc: z.ZodOptional<z.ZodString>;
258
+ standing: z.ZodLiteral<"live">;
259
+ }, z.core.$strip>, z.ZodObject<{
260
+ principal: z.ZodString;
261
+ principalInc: z.ZodOptional<z.ZodString>;
262
+ standing: z.ZodLiteral<"gone">;
263
+ }, z.core.$strip>], "standing">>;
264
+ }, z.core.$strip>;
265
+ export type PrincipalReconcileAnswer = z.infer<typeof PrincipalReconcileAnswer>;
266
+ export {};
@@ -0,0 +1,169 @@
1
+ /**
2
+ * `api/lifecycle-events` —— 用户生命周期事件的 wire 型(29.0.0):管理面把「一个主体被删 / 被降级 / 被移出空间」这类事实发成一串带序号的事件,
3
+ * 执行面按页拉取、按序号去重,并在启动与游标失效时用「对账」补齐现状。一份 zod,发这些形的一方(管理面)与收这些形的一方(执行面)同 import。纯、浏览器安全。
4
+ *
5
+ * 本模块只有**形与词表**:事件怎么产生与存放、保留多久、页怎么切、`head` 怎么算、鉴权与委托、消费方拿事件做什么(停谁的活),都是各方自己的事,不在这里。
6
+ * 拉取口的查询参数(`after` / `limit`)不是体,本模块不立它们的型;拒词({@link LIFECYCLE_PAGE_REFUSALS})只管游标与分页这四种,
7
+ * 鉴权类的拒答(401 / 403)不在这张表里。
8
+ *
9
+ * ## 解析一律剥未知键(与同目录的凭据 wire 型同一条规则)
10
+ * 对象型里不认识的**键**被剥掉、不进解析结果、不拒 —— 新键恒为加性,发方与收方各自独立升级。**例外只有一个:不认识的 `kind` 值**(事件行的判别键)
11
+ * 响亮地拒,整页随之拒,拒句点名那个词(坐标带它在 `events` 里的下标):`kind` 是闭集,收方悄悄丢掉一条自己不认识的生命周期事件 = 安全面的静默放过。
12
+ * 同理 `standing` / `error` 这两个判别键里不认识的词也拒。
13
+ *
14
+ * ## 事件
15
+ * 一条事件 = 一个按 `kind` 判别的对象。五个 `kind`(闭集 {@link PRINCIPAL_LIFECYCLE_EVENT_KINDS}):
16
+ * · `principal.deleted` —— 主体的 users 行被删;`principalInc` 取被删那一行的。不带 `scope`。
17
+ * · `principal.pending` —— 主体的实例角色从 `admin` 改走,且此刻没有任何空间成员资格。不带 `scope`。
18
+ * · `principal.role_lowered` —— 主体的实例角色从 `admin` 改走,但仍有空间成员资格。不带 `scope`:消费方立即对该主体对账。
19
+ * · `membership.removed` —— 一条空间成员行被删,且该主体不是实例 `admin`。**必带** `scope`。
20
+ * · `membership.role_lowered` —— 一个空间角色跨过 `editor` 底线往下降。**必带** `scope`。
21
+ * 共有成员:`eventId`(非空串;审计与跨库恢复时辨认事件)· `seq`(≥ 1 的安全整数;发方给的单调序号,收方的**去重键**)· `principal`(主体名,界同令牌 `sub`)·
22
+ * `principalInc`(可缺席;化身号,与令牌 `sub_inc` 同一只 {@link PrincipalIncarnation} —— 同一个名字被删后重建是另一个人,靠它分辨)· `at`(毫秒时刻,发方的钟)。
23
+ *
24
+ * ## 页与游标
25
+ * 一页 = `{ events, head, next }`:`events` 按 `seq` 升序(可以是空页);`head` = 发方此刻的头游标(收方「启动与游标失效」时先取它、再对账、再从它起拉);
26
+ * `next` = 下一次拉取带的游标(只进不退)。三个成员都不可缺席;游标是安全整数。
27
+ * 拉取失败的四个词({@link LIFECYCLE_PAGE_REFUSALS}):`cursor_invalid` / `limit_invalid`(400,请求自己不合格)· `cursor_expired`(游标早于发方还保留的最早位置)/
28
+ * `cursor_unknown`(游标晚于发方已知的位置,例如发方的库恢复到更早的备份)(410,拒体带 `head`:收方的重同步程序从它起)。
29
+ * 拒体 = `{ error, permanence, message }`(410 的词再加 `head`),与凭据 wire 的拒体同一种形(码 + 永久性);四个词的永久性都是 `terminal`(同一请求原样重发不会成功)。
30
+ *
31
+ * ## 对账
32
+ * 请求 {@link PrincipalReconcileRequest} = `{ principals: [{ principal, principalInc? }] }`,1 – {@link PRINCIPAL_RECONCILE_MAX_ITEMS} 项;
33
+ * 应答 {@link PrincipalReconcileAnswer} = `{ principals: [...] }`,每项回显请求里的身份元组并按 `standing` 判别:`live`(仍在;`since` 可缺席,只在这一臂)/ `gone`(不在了)。
34
+ * 应答与请求逐项对应(同序同长)是收方要核的事,本形只钉 1 – {@link PRINCIPAL_RECONCILE_MAX_ITEMS} 项。
35
+ */
36
+ import { z } from "zod";
37
+ import { echoCallerText } from "../caller-text-echo.js";
38
+ import { deepFreeze } from "../deep-freeze.js";
39
+ import { ownValueOf } from "../own-key-read.js";
40
+ import { isPlainJsonObject } from "../plain-json-object.js";
41
+ import { buildQuotedIssue } from "../quoted-issue.js";
42
+ import { PrincipalIncarnation } from "./auth-bridge.js";
43
+ import { SANDBOX_GIT_PERMANENCE } from "./credentials.js";
44
+ import { ScopeId } from "./scopes.js";
45
+ import { NonEmptyString, PrincipalString, SafeCount } from "./wire-scalars.js";
46
+ // ── 事件 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
47
+ /**
48
+ * 事件 `kind` 表(包内私有):一词一行 `{ kind, scoped }` —— **每个词只在这里拼一次**;`scoped` = 这一臂**必带** `scope`(`membership.*` 两词),其余臂不带。
49
+ * 词表({@link PRINCIPAL_LIFECYCLE_EVENT_KINDS})、词的类型({@link PrincipalLifecycleEventKind})与事件行联合({@link PrincipalLifecycleEvent})的每一臂都由它派生,没有第二张词表。
50
+ */
51
+ const EVENT_KIND_ROWS = deepFreeze([
52
+ { kind: "principal.deleted", scoped: false },
53
+ { kind: "principal.pending", scoped: false },
54
+ { kind: "principal.role_lowered", scoped: false },
55
+ { kind: "membership.removed", scoped: true },
56
+ { kind: "membership.role_lowered", scoped: true },
57
+ ]);
58
+ /** 用户生命周期事件的 `kind` 词表(运行期;定义处深冻结;表的 `kind` 列,按表序)。 */
59
+ export const PRINCIPAL_LIFECYCLE_EVENT_KINDS = deepFreeze(EVENT_KIND_ROWS.map((row) => row.kind));
60
+ /** 身份元组:主体名 + 可缺席的化身号。事件行、对账请求项、对账应答项都是它 —— 一份定义。 */
61
+ const PrincipalTuple = {
62
+ principal: PrincipalString,
63
+ principalInc: PrincipalIncarnation.optional(),
64
+ };
65
+ /** 事件行的共有成员(`kind` 与 `scope` 由各臂自己带)。 */
66
+ const EventCommon = {
67
+ eventId: NonEmptyString,
68
+ seq: SafeCount.positive(),
69
+ ...PrincipalTuple,
70
+ at: SafeCount,
71
+ };
72
+ /** 不带空间的臂:`{ kind, eventId, seq, principal, principalInc?, at }`。 */
73
+ function plainArm(kind) {
74
+ return z.object({ kind: z.literal(kind), ...EventCommon });
75
+ }
76
+ /** 带空间的臂:在共有成员之上**必带** `scope`({@link ScopeId};保留的 `global` 也是合法空间)。 */
77
+ function scopedArm(kind) {
78
+ return z.object({ kind: z.literal(kind), ...EventCommon, scope: ScopeId });
79
+ }
80
+ /**
81
+ * 一条用户生命周期事件,按 `kind` 判别;臂由 `kind` 表派生,每词一臂、同序。未知键剥掉(`principal.*` 臂带的 `scope` 也是它那一臂的未知键,同样剥掉);
82
+ * `membership.*` 臂缺 `scope` 拒;**未知的 `kind` 值拒,句子点名那个词**(经 {@link echoCallerText} 回显:剥控制与双向字符、有界)。
83
+ * `kind` 不是字符串 / 缺席时没有词可点,句子是 zod 自己的、不回显值。
84
+ */
85
+ export const PrincipalLifecycleEvent = z.discriminatedUnion("kind", EVENT_KIND_ROWS.map((row) => (row.scoped ? scopedArm(row.kind) : plainArm(row.kind))), {
86
+ error: (iss) => {
87
+ if (iss.code !== "invalid_union" || !isPlainJsonObject(iss.input))
88
+ return undefined;
89
+ // `kind` 从输入自己的键读(输入是调用方的对象:继承来的 / 被污染的 `kind` 不是对方写的词;读不出的 Proxy 没有词可点)
90
+ const kind = ownValueOf(iss.input, "kind");
91
+ if (!kind.ok || typeof kind.value !== "string" || kind.value === "")
92
+ return undefined;
93
+ return `unknown lifecycle event kind ${echoCallerText(kind.value)}; the closed set is ${PRINCIPAL_LIFECYCLE_EVENT_KINDS.join(", ")}`; // no quotes: the sentence survives a JSON-rendered issue list verbatim
94
+ },
95
+ });
96
+ // ── 事件页 ─────────────────────────────────────────────────────────────────────────────────────────────────────────
97
+ /**
98
+ * 一页事件:`events`(按 `seq` 升序,可以是空页)· `head`(发方此刻的头游标)· `next`(下一次拉取带的游标,只进不退)。三个成员都不可缺席;未知键剥掉;
99
+ * 页里有一条事件的 `kind` 不认识 ⇒ 整页拒(坐标 `events.<下标>.kind`)。
100
+ * 页的长度上界、`seq` 在页内是否升序、`next` 与最后一条事件的关系都是发方的事,本形不核。
101
+ */
102
+ export const PrincipalLifecycleEventPage = z.object({
103
+ events: z.array(PrincipalLifecycleEvent),
104
+ head: SafeCount,
105
+ next: SafeCount,
106
+ });
107
+ // ── 拉取失败的词与状态码 ─────────────────────────────────────────────────────────────────────────────────────────────
108
+ /** 永久性词表(凭据 wire 的那一张)的 `terminal`:同一请求原样重发不会成功。词只在 `./credentials` 里拼一次,这里取表的首项(次序在那边的钉里)。 */
109
+ const TERMINAL = SANDBOX_GIT_PERMANENCE[0];
110
+ /**
111
+ * 拉取失败词(游标与分页这一类,四个)→ 它的 HTTP 状态码与永久性。**一个词只有一个状态码、一个永久性**,表是它们的唯一一处:
112
+ * · 400 —— 请求自己不合格:`cursor_invalid`(游标不是合法游标)/ `limit_invalid`(页长不合法);
113
+ * · 410 —— 游标对不上发方的现状,收方要重同步:`cursor_expired`(游标早于发方还保留的最早位置)/ `cursor_unknown`(游标晚于发方已知的位置)。
114
+ * **410 的拒体带 `head`**(收方从它起重新拉);400 的拒体不带。「带不带 `head`」由这一列推出,不另立一张表({@link LifecyclePageRefusal})。
115
+ * 永久性({@link SandboxGitPermanence},词表在凭据 wire 里):四个词都是 `terminal` —— 同一请求原样重发不会成功(400 的要改请求,410 的要先重新同步);拒体里的 `permanence` 必须等于这一行的。
116
+ * 鉴权类的拒答不在这张表里。
117
+ */
118
+ export const LIFECYCLE_PAGE_REFUSALS = deepFreeze({
119
+ cursor_invalid: { status: 400, permanence: TERMINAL },
120
+ limit_invalid: { status: 400, permanence: TERMINAL },
121
+ cursor_expired: { status: 410, permanence: TERMINAL },
122
+ cursor_unknown: { status: 410, permanence: TERMINAL },
123
+ });
124
+ /** 拉取失败词表(运行期;表的键,按表序)。 */
125
+ export const LIFECYCLE_PAGE_REFUSAL_ERRORS = deepFreeze(Object.keys(LIFECYCLE_PAGE_REFUSALS));
126
+ /** 表里状态码是 `status` 的词,按表序。 */
127
+ function refusalWordsWith(status) {
128
+ return LIFECYCLE_PAGE_REFUSAL_ERRORS.filter((word) => LIFECYCLE_PAGE_REFUSALS[word].status === status);
129
+ }
130
+ /** 拒体的共有成员:永久性(必须等于表里这一词的,见下面的 `refine`)与诊断句。 */
131
+ const RefusalCommon = {
132
+ permanence: z.enum(SANDBOX_GIT_PERMANENCE),
133
+ message: z.string(),
134
+ };
135
+ /**
136
+ * 拉取失败的体,按 `error` 判别(与凭据 wire 的拒体同一种形:码 + 永久性 + 诊断句):
137
+ * · 400 的词:`{ error, permanence, message }`;
138
+ * · 410 的词:`{ error, permanence, message, head }` —— `head` = 发方此刻的头游标(安全整数)。
139
+ * `permanence` 是错误词的函数,必须等于 {@link LIFECYCLE_PAGE_REFUSALS} 里这一行的,两处不一致就是畸形应答(拒)。
140
+ * `message` 是发方的诊断句(收方不据它判,可为空串)。体里不带状态码:状态码是 HTTP 层的,词与状态码的对应只看 {@link LIFECYCLE_PAGE_REFUSALS}。未知键剥掉。
141
+ */
142
+ export const LifecyclePageRefusal = z
143
+ .discriminatedUnion("error", [
144
+ z.object({ error: z.enum(refusalWordsWith(400)), ...RefusalCommon }),
145
+ z.object({ error: z.enum(refusalWordsWith(410)), ...RefusalCommon, head: SafeCount }),
146
+ ])
147
+ .refine((body) => LIFECYCLE_PAGE_REFUSALS[body.error].permanence === body.permanence, buildQuotedIssue `permanence must be the one the refusal table gives for this error`);
148
+ // ── 对账 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
149
+ /** 一次对账请求(与应答)里最多几项。 */
150
+ export const PRINCIPAL_RECONCILE_MAX_ITEMS = 500;
151
+ /** 对账请求的一项:要问现状的那个身份元组。 */
152
+ export const PrincipalReconcileItem = z.object({ ...PrincipalTuple });
153
+ /** 对账请求:`{ principals }`,1 – {@link PRINCIPAL_RECONCILE_MAX_ITEMS} 项;未知键剥掉。 */
154
+ export const PrincipalReconcileRequest = z.object({
155
+ principals: z.array(PrincipalReconcileItem).min(1).max(PRINCIPAL_RECONCILE_MAX_ITEMS),
156
+ });
157
+ /**
158
+ * 一个主体的现状,按 `standing` 判别;回显请求里的身份元组(`principal`、可缺席的 `principalInc`);未知键剥掉:
159
+ * · `live` —— 仍在;`since`(毫秒时刻,可缺席)**只在这一臂**:这一段「在」的起点;
160
+ * · `gone` —— 不在了;这一臂的形没有 `since`(带了的被剥掉)。
161
+ */
162
+ export const PrincipalStanding = z.discriminatedUnion("standing", [
163
+ z.object({ standing: z.literal("live"), ...PrincipalTuple, since: SafeCount.optional() }),
164
+ z.object({ standing: z.literal("gone"), ...PrincipalTuple }),
165
+ ]);
166
+ /** 对账应答:`{ principals }`,每项是一个 {@link PrincipalStanding};1 – {@link PRINCIPAL_RECONCILE_MAX_ITEMS} 项(与请求逐项对应是收方要核的事);未知键剥掉。 */
167
+ export const PrincipalReconcileAnswer = z.object({
168
+ principals: z.array(PrincipalStanding).min(1).max(PRINCIPAL_RECONCILE_MAX_ITEMS),
169
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `api/wire-scalars` —— 包内私有叶子模块(不在主桶、不在任何子路径):api 各 wire 模块共用的标量形,一处定义、各处引用。
3
+ *
4
+ * 这几只形此前是 `api/credentials` 的模块私有常量;第二个 wire 模块(`api/lifecycle-events`)要同样的形时,不抄第二份 —— 挪到这里,两处 import。
5
+ * 不导出给消费方:消费方要的是 wire 型(`SandboxGitCredentialAnswer` / `PrincipalLifecycleEvent` …),不是这几只积木。纯、浏览器安全。
6
+ */
7
+ import { z } from "zod";
8
+ /** wire 上每个数值位(毫秒时刻、行版本、游标)的形:非负安全整数 —— 包内的整数判据 + 安全整数上界;浮点、负数、超出安全整数的都不是。 */
9
+ export declare const SafeCount: z.ZodNumber;
10
+ /** 非空串:一个不透明标识(行 id、句柄、审计 id …),不 trim、不折叠、不解析。 */
11
+ export declare const NonEmptyString: z.ZodString;
12
+ /** wire 上的主体名:非空串,长度界同令牌 `sub` 的界({@link PRINCIPAL_MAX_LENGTH} —— 引擎的主体门拒更长的)。校验或铸主体名的一方都查这一个值。 */
13
+ export declare const PrincipalString: z.ZodString;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `api/wire-scalars` —— 包内私有叶子模块(不在主桶、不在任何子路径):api 各 wire 模块共用的标量形,一处定义、各处引用。
3
+ *
4
+ * 这几只形此前是 `api/credentials` 的模块私有常量;第二个 wire 模块(`api/lifecycle-events`)要同样的形时,不抄第二份 —— 挪到这里,两处 import。
5
+ * 不导出给消费方:消费方要的是 wire 型(`SandboxGitCredentialAnswer` / `PrincipalLifecycleEvent` …),不是这几只积木。纯、浏览器安全。
6
+ */
7
+ import { z } from "zod";
8
+ import { INTEGER } from "../integer.js";
9
+ import { PRINCIPAL_MAX_LENGTH } from "./auth-bridge.js";
10
+ /** wire 上每个数值位(毫秒时刻、行版本、游标)的形:非负安全整数 —— 包内的整数判据 + 安全整数上界;浮点、负数、超出安全整数的都不是。 */
11
+ export const SafeCount = INTEGER.nonnegative().max(Number.MAX_SAFE_INTEGER);
12
+ /** 非空串:一个不透明标识(行 id、句柄、审计 id …),不 trim、不折叠、不解析。 */
13
+ export const NonEmptyString = z.string().min(1);
14
+ /** wire 上的主体名:非空串,长度界同令牌 `sub` 的界({@link PRINCIPAL_MAX_LENGTH} —— 引擎的主体门拒更长的)。校验或铸主体名的一方都查这一个值。 */
15
+ export const PrincipalString = z.string().min(1).max(PRINCIPAL_MAX_LENGTH);
@@ -19,6 +19,8 @@ export declare function resolveSymlinkTarget(target: string): string;
19
19
  /** 读一份**可以缺席**的 UTF-8 文本 —— `config.d` 文档与 `.env` 的缺席律在 {@link absentUnlessDangling}:读得到 ⇒ 文本;读不出 ⇒ 缺席尾(`ENOENT` 且无座位是悬空链接 ⇒ `undefined`;悬空 ⇒ 抛那一句;别的读不出原样抛)。
20
20
  * 配置根自己是悬空链接(祖先座)不在问的范围内:`dirSeats` 只列文件所在的那一级布局座。 */
21
21
  export declare function readTextIfPresent(file: string, dirSeats?: readonly string[]): Promise<string | undefined>;
22
+ /** 读一份**可以缺席**的文件的**原始字节**:与 {@link readTextIfPresent} 同一个缺席尾(缺席律只此一处),只有读的那一行 I/O 不同 —— 要对**盘上的字节**算摘要的读者(条件写器 `writeDomainFileIf`)用它,不经 UTF-8 解码。 */
23
+ export declare function readBytesIfPresent(file: string, dirSeats?: readonly string[]): Promise<Buffer | undefined>;
22
24
  /** {@link readTextIfPresent} 的同步孪生(壳在同步具名锁里读 `config.d` 文档要它):同一个缺席尾,只有读文本那一行 I/O 不同。 */
23
25
  export declare function readTextIfPresentSync(file: string, dirSeats?: readonly string[]): string | undefined;
24
26
  /** 原子写 `text`(UTF-8)到 `target`(符号链接则写到它指向的真文件,见文件头);模式按 `kind` 在 {@link ATOMIC_FILE_CLASSES} 里的行。父目录须已存在。 */
@@ -47,5 +49,7 @@ export declare function createFileExclusive(target: string, text: string, kind:
47
49
  * 目录不在就建(连同缺的上级):**逐级** mkdir、每建一级立刻 chmod 到 {@link OWNER_ONLY_DIRECTORY_MODE} —— 模式恰是它,不经 umask(umask 0777 下一次性的递归 mkdir 会先建出
48
50
  * 一级 0000 的目录、再也进不去建下一级)。本进程建了 `dir` ⇒ `"created"`;`dir` 已在(或恰被别的进程同时建成)⇒ `"present"`(它的模式一位不动)。
49
51
  * 路径上有一节不是目录 ⇒ 抛。
52
+ * 交来的路径串**原样交内核**、不做任何解法(见文件头「一次操作一条路径串」):调用方交的是它随后要写的那份文件的路径串的 `dirname`,目录与文件于是落在同一处
53
+ * (`链接/..` 由内核按链接目标的物理父目录解,相对路径对进程 cwd 解)。向上找已在的祖先时逐级取 `path.dirname`,每一级的「在不在」都问内核。
50
54
  */
51
55
  export declare function ensureOwnerOnlyDirectory(dir: string): "created" | "present";
@@ -34,6 +34,11 @@
34
34
  * **不受 umask 放宽,也不受 umask 收窄**(前者:`mkdir` 给的 mode 本身就是 0o700,umask 只能清掉位、加不了位;后者:例如 umask 0o277 下 `mkdir` 先出 0o500,紧跟的 `chmod` 把它定回 0o700)。
35
35
  * 这是目录的另一条律,与上面「新建文件经进程 umask」不是同一条律的两个特例;已在的目录一位不动。目录模式与文件模式同在本文件一处定。
36
36
  *
37
+ * ## 一次操作一条路径串
38
+ * 本文件的原语(建目录 {@link ensureOwnerOnlyDirectory}、原子写器、不存在才建、读)**对交来的路径串不做词法归一**:原样交内核(原子写器对「目标是符号链接」的处置见下节 —— 那是对目标文件的解法,不是对这条串的归一),派生只用 `path.dirname` 与只拼接({@link entryIn})。
39
+ * 路径串由拼它的那一面在操作入口定一次,一次操作里建目录、临时文件、`rename` / `link` 的落点都从这一串派生 —— **要建的目录 = 随后要写的那份文件的路径串的 `dirname`**:
40
+ * 调度店 = 调用方给的店路径原样;配置根 = `path.join(根, 文件名)`(配置根的每一个读口与写口一向这么拼)。同一次操作里不出现第二种解法。
41
+ *
37
42
  * ## 写失败(12.0.0;句子归文件系统失败句的唯一铸点)
38
43
  * 三步各一句({@link FsFailure},句子在 `./fs-failure`):临时文件建不出 ⇒ 「cannot write into directory <dir> (<errno>): …」(点名目录 —— 目录不可写时
39
44
  * 文件本身没错);沿用原模式的文件给临时文件设模式失败 ⇒ 「cannot set the mode of <file> (<errno>): …」(点名设模式这一步 —— 文件系统不让改模式,目录没有问题);`rename` 失败 ⇒ 「cannot replace <file> (<errno>): …」(点名真文件)。
@@ -100,6 +105,15 @@ export async function readTextIfPresent(file, dirSeats = []) {
100
105
  return absentUnlessDangling(e, file, dirSeats);
101
106
  }
102
107
  }
108
+ /** 读一份**可以缺席**的文件的**原始字节**:与 {@link readTextIfPresent} 同一个缺席尾(缺席律只此一处),只有读的那一行 I/O 不同 —— 要对**盘上的字节**算摘要的读者(条件写器 `writeDomainFileIf`)用它,不经 UTF-8 解码。 */
109
+ export async function readBytesIfPresent(file, dirSeats = []) {
110
+ try {
111
+ return await readFile(file);
112
+ }
113
+ catch (e) {
114
+ return absentUnlessDangling(e, file, dirSeats);
115
+ }
116
+ }
103
117
  /** {@link readTextIfPresent} 的同步孪生(壳在同步具名锁里读 `config.d` 文档要它):同一个缺席尾,只有读文本那一行 I/O 不同。 */
104
118
  export function readTextIfPresentSync(file, dirSeats = []) {
105
119
  try {
@@ -109,6 +123,13 @@ export function readTextIfPresentSync(file, dirSeats = []) {
109
123
  return absentUnlessDangling(e, file, dirSeats);
110
124
  }
111
125
  }
126
+ /**
127
+ * 目录 `dir`(`path.dirname` 的结果)下名为 `name` 的条目 —— **只拼接,不做词法归一**:路径里的 `链接/..` 留给内核按链接目标的物理父目录解,
128
+ * 与目标路径本身(rename / link 的落点)同一种解法;`path.join` 会先把它消成链接所在的目录,临时文件就落在另一个目录里。
129
+ */
130
+ function entryIn(dir, name) {
131
+ return dir.endsWith(path.sep) ? `${dir}${name}` : `${dir}${path.sep}${name}`;
132
+ }
112
133
  /** 原子写 `text`(UTF-8)到 `target`(符号链接则写到它指向的真文件,见文件头);模式按 `kind` 在 {@link ATOMIC_FILE_CLASSES} 里的行。父目录须已存在。 */
113
134
  export function writeFileAtomic(target, text, kind) {
114
135
  const real = resolveSymlinkTarget(target);
@@ -132,7 +153,7 @@ export function writeFileAtomic(target, text, kind) {
132
153
  }
133
154
  }
134
155
  const dir = path.dirname(real);
135
- const tmp = path.join(dir, `.${path.basename(real)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
156
+ const tmp = entryIn(dir, `.${path.basename(real)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
136
157
  let site = { landing: "dir-create-temp", path: tmp };
137
158
  try {
138
159
  writeFileSync(tmp, text, { encoding: "utf8", mode: kept ?? spec.newMode });
@@ -209,7 +230,7 @@ function writeTempExclusive(tmp, text, mode) {
209
230
  export function createFileExclusive(target, text, kind) {
210
231
  const spec = ATOMIC_FILE_CLASSES[kind];
211
232
  const dir = path.dirname(target);
212
- const tmp = path.join(dir, `.${path.basename(target)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
233
+ const tmp = entryIn(dir, `.${path.basename(target)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
213
234
  try {
214
235
  writeTempExclusive(tmp, text, spec.newMode);
215
236
  }
@@ -244,9 +265,11 @@ export function createFileExclusive(target, text, kind) {
244
265
  * 目录不在就建(连同缺的上级):**逐级** mkdir、每建一级立刻 chmod 到 {@link OWNER_ONLY_DIRECTORY_MODE} —— 模式恰是它,不经 umask(umask 0777 下一次性的递归 mkdir 会先建出
245
266
  * 一级 0000 的目录、再也进不去建下一级)。本进程建了 `dir` ⇒ `"created"`;`dir` 已在(或恰被别的进程同时建成)⇒ `"present"`(它的模式一位不动)。
246
267
  * 路径上有一节不是目录 ⇒ 抛。
268
+ * 交来的路径串**原样交内核**、不做任何解法(见文件头「一次操作一条路径串」):调用方交的是它随后要写的那份文件的路径串的 `dirname`,目录与文件于是落在同一处
269
+ * (`链接/..` 由内核按链接目标的物理父目录解,相对路径对进程 cwd 解)。向上找已在的祖先时逐级取 `path.dirname`,每一级的「在不在」都问内核。
247
270
  */
248
271
  export function ensureOwnerOnlyDirectory(dir) {
249
- const target = path.resolve(dir);
272
+ const target = dir;
250
273
  const missing = [];
251
274
  for (let at = target; !existsSync(at);) {
252
275
  missing.unshift(at);
@@ -48,7 +48,7 @@ export declare function readConfigDFileReading(root: string, name: ConfigDDocume
48
48
  export declare function readConfigDFileReadingSync(root: string, name: ConfigDDocumentName): ConfigDReading;
49
49
  /** 抛出口:读一个 `config.d/<名>.json`:路径上没有任何条目 ⇒ `undefined`;在场 ⇒ 它的值;被拒 ⇒ 抛读数的 `thrown`(见 {@link readConfigDFileReading})。 */
50
50
  export declare function readConfigDFile(root: string, name: ConfigDDocumentName): Promise<Record<string, unknown> | undefined>;
51
- /** 一棵 `config.d` 的原文快照:便携域与 retired 域的文档原文(缺席 ⇒ `undefined`),版本哈希的入参。 */
51
+ /** 一棵 `config.d` 的原文快照:本地读取域与 retired 域的文档原文(缺席 ⇒ `undefined`),版本哈希的入参。 */
52
52
  export type ConfigDRaws = Partial<Record<DomainName | RetiredDomainName, unknown>>;
53
53
  /** 一棵 `config.d` 原文快照的内容版本(稳定的 u53 整数):同样的文档 ⇒ 同一个数。`FileConfigStore` 的 `getVersion()` / `getEffective()` / `read()` 读同一只。 */
54
54
  export declare function configDVersionOf(raws: ConfigDRaws): number;
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * ## 形
12
12
  * 一条拒 = `{ document, reason, error }`:
13
- * · `document`:被拒的文档 —— 便携域名,或 retired 域名(retired 域的文档就以域名相称,墓碑拒的「域」就是这个名字,不另设第二个键);
13
+ * · `document`:被拒的文档 —— 本地读取域名(便携域名或 `projects`),或 retired 域名(retired 域的文档就以域名相称,墓碑拒的「域」就是这个名字,不另设第二个键);
14
14
  * · `reason`:闭集词 {@link CONFIG_DOCUMENT_REFUSAL_REASONS}。文件层五个 —— `empty`(空 / 纯空白:半写、截断)· `invalid_json`(JSON 解析不过)· `not_object`(解析出来不是 JSON 对象:
15
15
  * `null` / 数组 / 数 / 串 / 布尔)· `io`(在场却读不出:权限、路径是目录、I/O 错误、悬空的符号链接〔文档本身或 `config.d` 目录:链接在、目标不在,17.0.0 起;句子点名链接与出路〕;缺席 = 路径上没有任何条目,不是拒)· `too_deep`(16.0.0:嵌套深过整棵目录的内容版本能算的深度 ——
16
16
  * 此前它在算版本那一步抛,已经收集的拒一并丢掉);第六个 `retired_domain` 是墓碑(retired 域文档带事实);
@@ -19,13 +19,13 @@
19
19
  * · 墓碑拒的 `document` 恒是 retired 域名(26.0.0 起不再另带 `migration`:改写存量的一次性迁移到期删了,那一格没有来源)。
20
20
  * 词表是闭集:消费方用 `switch (refusal.reason)` 穷举,加词 ⇒ 它们编译红(这是通知)。
21
21
  */
22
- import type { PortableDomain } from "./portable-domains.js";
22
+ import type { LocalReadDomain } from "./portable-domains.js";
23
23
  import type { RetiredDomainName } from "./types.js";
24
24
  /** 文件层拒一份文档的闭集词:五个文件层成因 + 墓碑(恒在末位)。墓碑那个词就是 `RetiredDomainError.code`(一个词,不立第二个名)。 */
25
25
  export declare const CONFIG_DOCUMENT_REFUSAL_REASONS: readonly ["empty", "invalid_json", "not_object", "io", "too_deep", "retired_domain"];
26
26
  export type ConfigDocumentRefusalReason = (typeof CONFIG_DOCUMENT_REFUSAL_REASONS)[number];
27
- /** 能被拒的 `config.d` 文档:便携域的文档,或retired 域的文档(读它只为墓碑)。 */
28
- export type ConfigDocumentName = PortableDomain | RetiredDomainName;
27
+ /** 能被拒的 `config.d` 文档:本地读取域({@link LocalReadDomain})的文档,或retired 域的文档(读它只为墓碑)。 */
28
+ export type ConfigDocumentName = LocalReadDomain | RetiredDomainName;
29
29
  /** 被拒的一份文档(按 `reason` 判别):`{ document, reason, error }`;墓碑拒的文档名恒是 retired 域名。 */
30
30
  export type ConfigDocumentRefusal = {
31
31
  readonly document: ConfigDocumentName;
@@ -447,12 +447,14 @@ export type EffectiveReadWarning = {
447
447
  identity?: DroppedEntryIdentity;
448
448
  reasonCode?: DroppedEntryReasonCode;
449
449
  }
450
- /** `config.d/` 里存在、但本地读取集**永远不会读**的文件(名字不是域,或是域但不便携)。 */
450
+ /** `config.d/` 里存在、但本地读取集(`LOCAL_READ_DOMAINS`)**永远不会读**的文件:名字不是域(`not-a-domain`),或是域但不在本地读取集里(`not-a-local-read-domain`:今天说的是 workers / hosts / systems / entitlement;`projects` 29.0.0 起在读取集里,被读)。
451
+ * `why` 说的是判据:文件名「是不是域」、再「在不在本地读取集」,判据与这个域能不能随 bundle 搬运(`PORTABLE_DOMAINS`)无关;
452
+ * 本地不读的成文理由目前借用搬运义的 `NON_PORTABLE_DOMAIN_REASONS`(键集含 `projects`、与这里的四个不同)—— 借用,不是这个词的理由表。 */
451
453
  | {
452
454
  kind: "unread-config-file";
453
455
  file: string;
454
456
  domain?: DomainName;
455
- why: "not-a-domain" | "non-portable-domain";
457
+ why: "not-a-domain" | "not-a-local-read-domain";
456
458
  };
457
459
  /** {@link EffectiveReadWarning} 的 `kind` **闭集**(运行期值)。一致性 kit 的覆盖律按它计数,消费方要遍历
458
460
  * 「所有告警种类」也用它 —— 属主在告警联合自己的模块里,`./conformance` 只再导出(4.0.0 前它住在 kit 里,
@@ -1371,7 +1371,7 @@ export const DOMAIN_READ_FALLBACK = deepFreeze({
1371
1371
  execution: "throw",
1372
1372
  projects: "throw",
1373
1373
  // prompts:内容域 ——坏形→空默认 `{}`(=「不管提示词」:不下发中心层,引擎用内置);fail-closed 由 PUBLISH_MODE
1374
- // 发布闸承担,default 不扩权。14.0.0 起墓碑键(`bindings` / `catalog`)也走这一档(读不出 ⇒ 缺省 + domain-defaulted 点名 SS-M10)。
1374
+ // 发布闸承担,default 不扩权。14.0.0 起墓碑键(`bindings` / `catalog`)也走这一档(读不出 ⇒ 缺省 + domain-defaulted 点名该键与出路)。
1375
1375
  prompts: "default",
1376
1376
  // limits(0.19.0):THROW —— 本域是成本 / 限流天花板的唯一发布位(11.0.0 起 runtime 域retired)。坏形
1377
1377
  // 降级成空域 = 中央发布的成本/限流天花板整片蒸发,消费方回自己的 env 底(可能宽得多)= 预算轴放权。