@capybara-hq/kernel 0.1.0-rc.142 → 0.1.0-rc.144

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 (238) hide show
  1. package/dist/admin/admin-agents.controller.d.ts +3 -5
  2. package/dist/admin/admin-agents.controller.js +1 -1
  3. package/dist/admin/admin-connectors.controller.d.ts +3 -5
  4. package/dist/admin/admin-connectors.controller.js +1 -1
  5. package/dist/admin/admin-items.schemas.d.ts +6 -6
  6. package/dist/admin/admin-items.schemas.js +5 -9
  7. package/dist/admin/admin.controller.d.ts +18 -12
  8. package/dist/admin/admin.controller.js +29 -15
  9. package/dist/admin/admin.schemas.d.ts +12 -3
  10. package/dist/admin/admin.schemas.js +17 -6
  11. package/dist/agents/admin-agents.d.ts +10 -8
  12. package/dist/agents/admin-agents.js +13 -9
  13. package/dist/agents/agents.module.js +3 -0
  14. package/dist/agents/agents.service.js +1 -1
  15. package/dist/agents/org-templates.d.ts +3 -1
  16. package/dist/agents/org-templates.js +7 -3
  17. package/dist/agents/pending-connector-requests.d.ts +10 -4
  18. package/dist/agents/pending-connector-requests.js +29 -7
  19. package/dist/automations/automations.controller.d.ts +9 -5
  20. package/dist/automations/automations.controller.js +21 -4
  21. package/dist/automations/automations.schemas.d.ts +19 -0
  22. package/dist/automations/automations.schemas.js +9 -0
  23. package/dist/automations/automations.service.d.ts +25 -8
  24. package/dist/automations/automations.service.js +40 -34
  25. package/dist/automations/events/acceptance.d.ts +6 -1
  26. package/dist/automations/events/acceptance.js +30 -11
  27. package/dist/automations/store.d.ts +17 -0
  28. package/dist/automations/store.js +35 -0
  29. package/dist/catalog/admin-catalog.controller.d.ts +64 -2
  30. package/dist/catalog/admin-catalog.controller.js +17 -0
  31. package/dist/catalog/catalog-import.module.js +3 -0
  32. package/dist/catalog/catalog-scope.service.d.ts +3 -1
  33. package/dist/catalog/catalog-scope.service.js +11 -7
  34. package/dist/catalog/catalog.module.js +3 -0
  35. package/dist/catalog/catalog.service.d.ts +3 -1
  36. package/dist/catalog/catalog.service.js +8 -4
  37. package/dist/catalog/cli.js +2 -2
  38. package/dist/catalog/component-promotion.d.ts +3 -1
  39. package/dist/catalog/component-promotion.js +7 -3
  40. package/dist/catalog/component-scope.service.d.ts +3 -1
  41. package/dist/catalog/component-scope.service.js +7 -3
  42. package/dist/catalog/enable-requests.d.ts +10 -8
  43. package/dist/catalog/enable-requests.js +40 -21
  44. package/dist/catalog/marketplaces.service.d.ts +1 -1
  45. package/dist/catalog/owned-items.d.ts +3 -1
  46. package/dist/catalog/owned-items.js +13 -9
  47. package/dist/catalog/platform-components.d.ts +6 -1
  48. package/dist/catalog/platform-components.js +9 -3
  49. package/dist/catalog/plugin-connectors.d.ts +8 -4
  50. package/dist/catalog/plugin-connectors.js +12 -6
  51. package/dist/catalog/plugin-import.d.ts +3 -1
  52. package/dist/catalog/plugin-import.js +14 -5
  53. package/dist/catalog/plugin-install.d.ts +3 -1
  54. package/dist/catalog/plugin-install.js +8 -4
  55. package/dist/catalog/plugin-package.js +2 -1
  56. package/dist/catalog/plugin-upgrade.d.ts +3 -1
  57. package/dist/catalog/plugin-upgrade.js +8 -4
  58. package/dist/catalog/request-hints.d.ts +19 -0
  59. package/dist/catalog/request-hints.js +34 -0
  60. package/dist/catalog/request-rules.d.ts +9 -5
  61. package/dist/catalog/request-rules.js +16 -9
  62. package/dist/catalog/requests.service.d.ts +3 -1
  63. package/dist/catalog/requests.service.js +28 -9
  64. package/dist/catalog/scope-orgs.d.ts +2 -1
  65. package/dist/catalog/scope-orgs.js +2 -2
  66. package/dist/catalog/scope-sync.d.ts +3 -1
  67. package/dist/catalog/scope-sync.js +12 -2
  68. package/dist/catalog/scope-writer.d.ts +6 -3
  69. package/dist/catalog/scope-writer.js +28 -10
  70. package/dist/catalog/unshare.d.ts +3 -2
  71. package/dist/catalog/unshare.js +4 -4
  72. package/dist/client/client-access.service.js +29 -1
  73. package/dist/config/schema.d.ts +12 -0
  74. package/dist/config/schema.js +56 -0
  75. package/dist/ctx/create-ctx.d.ts +2 -19
  76. package/dist/ctx/create-ctx.js +3 -93
  77. package/dist/ctx/durable-relay.d.ts +2 -5
  78. package/dist/ctx/durable-relay.js +56 -29
  79. package/dist/db/extension-handoff-schema.js +5 -0
  80. package/dist/db/kernel-schema.d.ts +74 -0
  81. package/dist/db/migrator.js +36 -0
  82. package/dist/erasure/account-batches.js +2 -0
  83. package/dist/erasure/account-residual.js +1 -0
  84. package/dist/erasure/org-catalog.js +8 -3
  85. package/dist/erasure/org-rules.js +1 -0
  86. package/dist/evals/evals.schemas.d.ts +15 -5
  87. package/dist/evals/evals.schemas.js +17 -10
  88. package/dist/evals/runs.controller.d.ts +4 -12
  89. package/dist/evals/runs.controller.js +14 -11
  90. package/dist/evals/runs.service.d.ts +29 -25
  91. package/dist/evals/runs.service.js +73 -61
  92. package/dist/evals/trajectory.controller.d.ts +10 -6
  93. package/dist/evals/trajectory.controller.js +11 -4
  94. package/dist/evals/trajectory.service.d.ts +17 -9
  95. package/dist/evals/trajectory.service.js +52 -35
  96. package/dist/extensions/admin-ops.d.ts +6 -1
  97. package/dist/extensions/admin-ops.js +21 -7
  98. package/dist/extensions/blobs.d.ts +2 -0
  99. package/dist/extensions/blobs.js +11 -0
  100. package/dist/extensions/deployment-config.d.ts +6 -1
  101. package/dist/extensions/deployment-config.js +13 -2
  102. package/dist/extensions/enabled.d.ts +5 -0
  103. package/dist/extensions/extensions.module.js +3 -0
  104. package/dist/extensions/grant-epoch.d.ts +108 -0
  105. package/dist/extensions/grant-epoch.js +214 -0
  106. package/dist/extensions/host.d.ts +29 -9
  107. package/dist/extensions/host.js +148 -42
  108. package/dist/extensions/instance.d.ts +3 -3
  109. package/dist/extensions/instance.js +1 -1
  110. package/dist/extensions/isolated/authorization.d.ts +54 -2
  111. package/dist/extensions/isolated/authorization.js +148 -35
  112. package/dist/extensions/isolated/child-session.js +0 -1
  113. package/dist/extensions/isolated/revision.js +1 -1
  114. package/dist/extensions/org-config.d.ts +3 -1
  115. package/dist/extensions/org-config.js +13 -4
  116. package/dist/extensions/org-overrides.d.ts +6 -1
  117. package/dist/extensions/org-overrides.js +13 -2
  118. package/dist/extensions/package-digest.job.d.ts +34 -0
  119. package/dist/extensions/package-digest.job.js +121 -0
  120. package/dist/extensions/package.js +10 -6
  121. package/dist/extensions/permission-set.d.ts +14 -78
  122. package/dist/extensions/permission-set.js +17 -143
  123. package/dist/extensions/permission-view.d.ts +13 -1
  124. package/dist/extensions/permission-view.js +20 -0
  125. package/dist/extensions/registry.js +4 -1
  126. package/dist/extensions/resolve.d.ts +7 -8
  127. package/dist/extensions/resolve.js +7 -8
  128. package/dist/extensions/revision-approvals.d.ts +167 -0
  129. package/dist/extensions/revision-approvals.js +353 -0
  130. package/dist/extensions/revision-grants.d.ts +197 -0
  131. package/dist/extensions/revision-grants.js +584 -0
  132. package/dist/extensions/state.module.js +12 -1
  133. package/dist/identity/accounts.d.ts +10 -4
  134. package/dist/identity/accounts.js +18 -5
  135. package/dist/inbox/inbox-items.service.d.ts +6 -1
  136. package/dist/inbox/inbox-items.service.js +29 -10
  137. package/dist/inbox/inbox.module.js +3 -0
  138. package/dist/inbox/inbox.service.d.ts +3 -1
  139. package/dist/inbox/inbox.service.js +9 -2
  140. package/dist/inbox/org-notices.d.ts +4 -3
  141. package/dist/inbox/org-notices.js +9 -6
  142. package/dist/inbox/platform-inbox.service.d.ts +3 -1
  143. package/dist/inbox/platform-inbox.service.js +11 -3
  144. package/dist/inbox/platform-notices.d.ts +3 -2
  145. package/dist/inbox/platform-notices.js +10 -4
  146. package/dist/infra/config/kernel-config.service.js +4 -1
  147. package/dist/infra/database/extension-effect-key-lock.js +7 -0
  148. package/dist/infra/paging/paged-read.d.ts +34 -4
  149. package/dist/infra/paging/paged-read.js +38 -1
  150. package/dist/invalidation/audiences.d.ts +32 -0
  151. package/dist/invalidation/audiences.js +43 -0
  152. package/dist/invalidation/hints.d.ts +6 -0
  153. package/dist/invalidation/hints.js +7 -1
  154. package/dist/invalidation/invalidation-hints.d.ts +12 -1
  155. package/dist/invalidation/invalidation-hints.js +46 -5
  156. package/dist/invalidation/invalidation-hints.module.d.ts +2 -0
  157. package/dist/invalidation/invalidation-hints.module.js +4 -1
  158. package/dist/invalidation/me-stream.d.ts +1 -11
  159. package/dist/invalidation/me-stream.js +12 -41
  160. package/dist/invalidation/org-intent-bridge.d.ts +18 -0
  161. package/dist/invalidation/org-intent-bridge.js +46 -0
  162. package/dist/models/enablement.d.ts +3 -1
  163. package/dist/models/enablement.js +25 -5
  164. package/dist/orgs/invitations.controller.d.ts +4 -7
  165. package/dist/orgs/invitations.controller.js +8 -5
  166. package/dist/orgs/invitations.service.d.ts +17 -3
  167. package/dist/orgs/invitations.service.js +35 -13
  168. package/dist/orgs/members.service.d.ts +35 -0
  169. package/dist/orgs/members.service.js +52 -3
  170. package/dist/orgs/offboarding.d.ts +3 -1
  171. package/dist/orgs/offboarding.js +7 -3
  172. package/dist/orgs/orgs.controller.d.ts +11 -4
  173. package/dist/orgs/orgs.controller.js +25 -5
  174. package/dist/orgs/orgs.module.js +3 -0
  175. package/dist/orgs/orgs.schemas.d.ts +14 -0
  176. package/dist/orgs/orgs.schemas.js +19 -2
  177. package/dist/orgs/orgs.service.d.ts +24 -2
  178. package/dist/orgs/orgs.service.js +47 -4
  179. package/dist/orgs/security-settings.service.d.ts +14 -6
  180. package/dist/orgs/security-settings.service.js +18 -13
  181. package/dist/orgs/settings.controller.d.ts +7 -4
  182. package/dist/platform/exclusions.js +15 -0
  183. package/dist/platform/ops/accounts.ops.js +7 -16
  184. package/dist/platform/ops/admin-items.ops.js +7 -7
  185. package/dist/platform/ops/automations.ops.js +6 -4
  186. package/dist/platform/ops/evals.ops.js +30 -15
  187. package/dist/platform/ops/org-settings.ops.js +2 -2
  188. package/dist/platform/ops/orgs.ops.js +44 -27
  189. package/dist/push/delivery.d.ts +3 -1
  190. package/dist/push/delivery.js +7 -3
  191. package/dist/push/push-processor.js +8 -1
  192. package/dist/roles/worker.module.js +3 -0
  193. package/dist/runtime/step-log.d.ts +1 -1
  194. package/dist/runtime/step-log.js +5 -4
  195. package/dist/runtime/stream-limit.d.ts +13 -0
  196. package/dist/runtime/stream-limit.js +40 -0
  197. package/dist/runtime/stream.controller.d.ts +2 -0
  198. package/dist/runtime/stream.controller.js +2 -0
  199. package/dist/runtime/stream.d.ts +1 -0
  200. package/dist/runtime/stream.js +15 -6
  201. package/dist/sandbox/permission-authority.module.js +6 -1
  202. package/dist/sandbox/permission-transitions.d.ts +3 -1
  203. package/dist/sandbox/permission-transitions.js +17 -2
  204. package/dist/setup/kernel-checks.d.ts +3 -3
  205. package/dist/setup/kernel-checks.js +4 -4
  206. package/dist/setup/setup-check-registry.d.ts +16 -5
  207. package/dist/setup/setup-check-registry.js +11 -3
  208. package/dist/setup/setup-checks.service.d.ts +1 -2
  209. package/dist/setup/setup-checks.service.js +7 -6
  210. package/dist/skills/agent-skills.service.d.ts +6 -1
  211. package/dist/skills/agent-skills.service.js +12 -3
  212. package/dist/skills/changes.service.d.ts +6 -1
  213. package/dist/skills/changes.service.js +11 -3
  214. package/dist/skills/conversation-catalog.d.ts +3 -0
  215. package/dist/skills/conversation-catalog.js +2 -0
  216. package/dist/skills/skills.module.js +3 -0
  217. package/dist/skills/skills.service.d.ts +3 -1
  218. package/dist/skills/skills.service.js +8 -4
  219. package/dist/tools/admin-connectors.d.ts +10 -8
  220. package/dist/tools/admin-connectors.js +12 -10
  221. package/dist/tools/approvals.service.d.ts +12 -1
  222. package/dist/tools/approvals.service.js +36 -9
  223. package/dist/tools/builtins/automations.d.ts +1 -1
  224. package/dist/tools/builtins/automations.js +1 -1
  225. package/dist/tools/connectors.service.d.ts +3 -1
  226. package/dist/tools/connectors.service.js +29 -7
  227. package/dist/tools/tools.module.js +3 -0
  228. package/dist/ui/admin-ui.controller.d.ts +3 -1
  229. package/dist/ui/admin-ui.controller.js +3 -1
  230. package/dist/ui/ui-stream.d.ts +2 -0
  231. package/dist/ui/ui-stream.js +20 -6
  232. package/dist/ui/views.controller.d.ts +4 -2
  233. package/dist/ui/views.controller.js +4 -2
  234. package/package.json +3 -3
  235. package/src/migrations/0234_extension_grant_epoch.sql +141 -0
  236. package/src/migrations/0235_extension_revision_grants.sql +166 -0
  237. package/src/migrations/0236_paged_table_idx.sql +33 -0
  238. package/src/migrations/0237_extension_handoff_health.sql +18 -0
@@ -25,7 +25,9 @@ import { type UiArrangementSlot, type UiContributionItem, UiViews } from "./view
25
25
  * `ctx.ui.verifyEmbedToken` accepts only for a `platform.page` contribution while the account is
26
26
  * still an active super admin;
27
27
  * - `GET /api/v1/admin/ui/stream`: the platform refresh SSE (`event: ui`, topic `platform-ui`),
28
- * super admin re-checked on the `runtime.sseRecheckMs` interval.
28
+ * super admin re-checked on the `runtime.sseRecheckMs` interval. Over
29
+ * `runtime.platformUiStreamMaxPerAccount`, the oldest of the account's platform UI streams on
30
+ * this replica ends with `event: closed` and `data: {"reason":"superseded"}`.
29
31
  * A contribution in any other slot is 404 `ui.not_found`, the same as one that does not exist.
30
32
  */
31
33
  export declare class AdminUiController {
@@ -44,7 +44,9 @@ class AdminUiQueryBodyDto extends createZodDto(PlatformQueryBody, "AdminUiQueryB
44
44
  * `ctx.ui.verifyEmbedToken` accepts only for a `platform.page` contribution while the account is
45
45
  * still an active super admin;
46
46
  * - `GET /api/v1/admin/ui/stream`: the platform refresh SSE (`event: ui`, topic `platform-ui`),
47
- * super admin re-checked on the `runtime.sseRecheckMs` interval.
47
+ * super admin re-checked on the `runtime.sseRecheckMs` interval. Over
48
+ * `runtime.platformUiStreamMaxPerAccount`, the oldest of the account's platform UI streams on
49
+ * this replica ends with `event: closed` and `data: {"reason":"superseded"}`.
48
50
  * A contribution in any other slot is 404 `ui.not_found`, the same as one that does not exist.
49
51
  */
50
52
  let AdminUiController = class AdminUiController {
@@ -41,6 +41,8 @@ export declare const ORG_STREAM_MIN_ROLE: OrgRole;
41
41
  */
42
42
  export declare class OrgUiStreams {
43
43
  private readonly active;
44
+ private readonly orgLimit;
45
+ private readonly platformLimit;
44
46
  /** Set by {@link closeAll}: streams opened afterwards end as soon as they begin. */
45
47
  private closing;
46
48
  private readonly d;
@@ -16,6 +16,7 @@ import { GracefulShutdown } from "../infra/lifecycle/graceful-shutdown.service.j
16
16
  import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
17
17
  import { roleAtLeast } from "../orgs/roles.js";
18
18
  import { endedStream, } from "../runtime/stream.js";
19
+ import { PerAccountStreamLimit, SUPERSEDED_FRAME } from "../runtime/stream-limit.js";
19
20
  import { isUiBusMessage, orgUiTopic, PLATFORM_UI_TOPIC, uiFrame } from "./registry.js";
20
21
  /** The log field naming the stream: its org, or the platform scope. */
21
22
  const whereOf = (p) => p.scope === "platform" ? { scope: "platform" } : { orgId: p.orgId };
@@ -76,6 +77,8 @@ const MAX_BACKLOG_BYTES = 1024 * 1024;
76
77
  */
77
78
  let OrgUiStreams = class OrgUiStreams {
78
79
  active = new Set();
80
+ orgLimit = new PerAccountStreamLimit();
81
+ platformLimit = new PerAccountStreamLimit();
79
82
  /** Set by {@link closeAll}: streams opened afterwards end as soon as they begin. */
80
83
  closing = false;
81
84
  d;
@@ -105,7 +108,8 @@ let OrgUiStreams = class OrgUiStreams {
105
108
  throw new ApiError(denied, "Access denied");
106
109
  if (this.closing)
107
110
  return endedStream(out);
108
- const conn = new OrgUiConnection(this.d, p, out, () => this.active.delete(conn));
111
+ const limit = p.scope === "platform" ? this.platformLimit : this.orgLimit;
112
+ const conn = new OrgUiConnection(this.d, p, out, limit, () => this.active.delete(conn));
109
113
  this.active.add(conn);
110
114
  try {
111
115
  await conn.subscribe();
@@ -150,11 +154,13 @@ class OrgUiConnection {
150
154
  rechecking = false;
151
155
  unsubscribe;
152
156
  timers = [];
153
- constructor(d, p, out, onClosed) {
157
+ slot;
158
+ constructor(d, p, out, limit, onClosed) {
154
159
  this.d = d;
155
160
  this.p = p;
156
161
  this.out = out;
157
162
  this.onClosed = onClosed;
163
+ this.slot = limit.register(p.viewerAccountId, () => this.close("end", SUPERSEDED_FRAME));
158
164
  }
159
165
  async subscribe() {
160
166
  const topic = this.p.scope === "platform" ? PLATFORM_UI_TOPIC : orgUiTopic(this.p.orgId);
@@ -169,16 +175,21 @@ class OrgUiConnection {
169
175
  this.unsubscribe = un;
170
176
  }
171
177
  begin() {
172
- if (this.closed)
178
+ if (this.closed || this.begun)
173
179
  return;
174
180
  this.begun = true;
175
- const { sseHeartbeatMs, sseRecheckMs } = this.d.config.get().runtime;
181
+ const runtime = this.d.config.get().runtime;
182
+ const { sseHeartbeatMs, sseRecheckMs } = runtime;
183
+ this.slot.begin(this.p.scope === "platform"
184
+ ? runtime.platformUiStreamMaxPerAccount
185
+ : runtime.orgUiStreamMaxPerAccount);
176
186
  this.timers.push(setInterval(() => this.write(": ping\n\n"), sseHeartbeatMs), setInterval(() => void this.recheck(), sseRecheckMs));
177
187
  }
178
- close(mode = "end") {
188
+ close(mode = "end", finalFrame) {
179
189
  if (this.closed)
180
190
  return;
181
191
  this.closed = true;
192
+ this.slot.close();
182
193
  for (const t of this.timers)
183
194
  clearInterval(t);
184
195
  this.timers = [];
@@ -189,8 +200,11 @@ class OrgUiConnection {
189
200
  try {
190
201
  if (mode === "abort")
191
202
  this.out.abort();
192
- else
203
+ else {
204
+ if (finalFrame !== undefined)
205
+ this.out.write(finalFrame);
193
206
  this.out.end();
207
+ }
194
208
  }
195
209
  catch {
196
210
  // 连接已断开
@@ -33,8 +33,10 @@ export declare const embedSrc: (plugin: string, path: string) => string;
33
33
  * §4.1), gated like the component's view; 404 `ui.query_not_found`, 413
34
34
  * `ui.query_params_too_large`, 502 `ui.query_failed` / `ui.query_result_too_large`, 504
35
35
  * `ui.query_timeout` (10 s);
36
- * - `GET /api/v1/orgs/:orgId/ui/stream`:组织级刷新 SSE(`event: ui`,`data: {"plugin","contribution"}`),
37
- * member and above;
36
+ * - `GET /api/v1/orgs/:orgId/ui/stream`: org refresh SSE (`event: ui`,
37
+ * `data: {"plugin","contribution"}`), member and above. Over `runtime.orgUiStreamMaxPerAccount`,
38
+ * the oldest of the account's org UI streams on this replica ends with `event: closed` and
39
+ * `data: {"reason":"superseded"}`;
38
40
  * - `POST /api/v1/orgs/:orgId/ui/embeds/:plugin/:id/token` (`{ conversationId?, agentId?, fileId? }`,
39
41
  * `{ fileId }` alone for a library file's previewer, or for a skill file's previewer
40
42
  * `{ skillId, version?, path }`)
@@ -56,8 +56,10 @@ class UiEmbedTokenBodyDto extends createZodDto(EmbedTokenBody, "UiEmbedTokenBody
56
56
  * §4.1), gated like the component's view; 404 `ui.query_not_found`, 413
57
57
  * `ui.query_params_too_large`, 502 `ui.query_failed` / `ui.query_result_too_large`, 504
58
58
  * `ui.query_timeout` (10 s);
59
- * - `GET /api/v1/orgs/:orgId/ui/stream`:组织级刷新 SSE(`event: ui`,`data: {"plugin","contribution"}`),
60
- * member and above;
59
+ * - `GET /api/v1/orgs/:orgId/ui/stream`: org refresh SSE (`event: ui`,
60
+ * `data: {"plugin","contribution"}`), member and above. Over `runtime.orgUiStreamMaxPerAccount`,
61
+ * the oldest of the account's org UI streams on this replica ends with `event: closed` and
62
+ * `data: {"reason":"superseded"}`;
61
63
  * - `POST /api/v1/orgs/:orgId/ui/embeds/:plugin/:id/token` (`{ conversationId?, agentId?, fileId? }`,
62
64
  * `{ fileId }` alone for a library file's previewer, or for a skill file's previewer
63
65
  * `{ skillId, version?, path }`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.142",
3
+ "version": "0.1.0-rc.144",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -70,7 +70,7 @@
70
70
  "yaml": "^2.9.1",
71
71
  "yauzl": "3.4.0",
72
72
  "zod": "^4.6.7",
73
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.101"
73
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.102"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -82,7 +82,7 @@
82
82
  "@types/yauzl": "3.4.0",
83
83
  "pg-cursor": "^2.22.1",
84
84
  "ws": "^8.22.0",
85
- "@capybara-hq/testing": "0.1.0-rc.59"
85
+ "@capybara-hq/testing": "0.1.0-rc.60"
86
86
  },
87
87
  "scripts": {
88
88
  "build": "tsc -b"
@@ -0,0 +1,141 @@
1
+ -- Grant epoch (isolation capacity spec 2026-12-04, "Required change: grant epoch"; plan task
2
+ -- 1.1a). One deployment-wide counter that advances in the transaction of every committed change
3
+ -- to a table the isolated grant check reads (`readIsolatedGrant`, `enabledExtensionsQuery`).
4
+ -- The triggered tables are exactly the tables that check reads; a test compiles the check and
5
+ -- fails when it reads a table without this trigger (grant-epoch-writers.test.ts).
6
+ -- Every replica reads it once per second; a changed epoch makes every cached isolated grant
7
+ -- stale, so a revocation reaches a replica that missed the bus hint within the 5 s bound.
8
+ --
9
+ -- The row has no org_id: it is deployment state, so no RLS policy applies.
10
+ --
11
+ -- Creating the triggers takes a SHARE ROW EXCLUSIVE lock on each of the 12 tables (orgs among
12
+ -- them) for a moment. The lock wait is bounded so a busy table fails the migration instead of
13
+ -- queueing writers behind it.
14
+ SET LOCAL lock_timeout = '5s';
15
+ CREATE TABLE IF NOT EXISTS extension_grant_epoch (
16
+ id smallint PRIMARY KEY DEFAULT 1 CHECK (id = 1),
17
+ epoch bigint NOT NULL DEFAULT 0,
18
+ changed_at timestamptz NOT NULL DEFAULT now()
19
+ );
20
+
21
+ INSERT INTO extension_grant_epoch (id) VALUES (1) ON CONFLICT (id) DO NOTHING;
22
+
23
+ -- Bumps at most once per transaction, at commit time. The trigger is a deferred constraint
24
+ -- trigger, so the row lock on the single epoch row is taken only while the transaction commits:
25
+ -- concurrent writers queue for a moment at commit instead of holding the lock across their
26
+ -- statements, and a writer never waits on the epoch row while holding locks another writer at
27
+ -- commit needs (no deadlock). A future deferred foreign key or other deferred trigger on these
28
+ -- tables would run at commit too and could change that lock order: review it against this one.
29
+ -- The transaction-local setting holds the current transaction id, so repeated bumps of a bulk
30
+ -- write are skipped and a stale value left on a pooled session can never suppress a bump; a
31
+ -- rolled-back savepoint undoes the setting together with its queued trigger events.
32
+ -- A REPEATABLE READ or SERIALIZABLE writer to these tables now also updates the epoch row at
33
+ -- commit, so it fails with 40001 when another writer committed a bump after its snapshot and must
34
+ -- retry (no current writer is exposed; see the writing-kernel-api skill).
35
+ -- The trigger arguments name audit columns the grant check never reads (a test asserts that): an
36
+ -- update that changes only those, such as the `ON DELETE SET NULL` cascade of an account erasure,
37
+ -- does not bump, so it neither revalidates grants nor conflicts with a serializable writer.
38
+ -- Over-fencing (a change that grants rather than revokes) only costs a revalidation.
39
+ CREATE OR REPLACE FUNCTION bump_extension_grant_epoch() RETURNS trigger
40
+ LANGUAGE plpgsql
41
+ SET search_path = capybara, pg_temp
42
+ AS $$
43
+ BEGIN
44
+ IF TG_OP = 'UPDATE' AND (to_jsonb(NEW) - TG_ARGV) = (to_jsonb(OLD) - TG_ARGV) THEN
45
+ RETURN NULL;
46
+ END IF;
47
+ IF current_setting('capybara.grant_epoch_bumped', true) IS DISTINCT FROM txid_current()::text THEN
48
+ PERFORM set_config('capybara.grant_epoch_bumped', txid_current()::text, true);
49
+ UPDATE extension_grant_epoch SET epoch = epoch + 1, changed_at = now() WHERE id = 1;
50
+ END IF;
51
+ RETURN NULL;
52
+ END
53
+ $$;
54
+
55
+ DROP TRIGGER IF EXISTS grant_epoch ON extension_installs;
56
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON extension_installs
57
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch('installed_at', 'installed_by', 'updated_at', 'updated_by');
58
+
59
+ DROP TRIGGER IF EXISTS grant_epoch ON extension_permission_snapshots;
60
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON extension_permission_snapshots
61
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch('approved_at', 'approved_by');
62
+
63
+ DROP TRIGGER IF EXISTS grant_epoch ON extension_catalog_sources;
64
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON extension_catalog_sources
65
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch('created_at');
66
+
67
+ DROP TRIGGER IF EXISTS grant_epoch ON catalog_items;
68
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON catalog_items
69
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch('created_at', 'created_by', 'updated_at');
70
+
71
+ DROP TRIGGER IF EXISTS grant_epoch ON catalog_item_versions;
72
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON catalog_item_versions
73
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch('imported_at', 'imported_by');
74
+
75
+ DROP TRIGGER IF EXISTS grant_epoch ON catalog_item_scope_orgs;
76
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON catalog_item_scope_orgs
77
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch();
78
+
79
+ DROP TRIGGER IF EXISTS grant_epoch ON catalog_item_org_switches;
80
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON catalog_item_org_switches
81
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch('updated_at', 'updated_by');
82
+
83
+ DROP TRIGGER IF EXISTS grant_epoch ON catalog_dependency_edges;
84
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON catalog_dependency_edges
85
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch();
86
+
87
+ DROP TRIGGER IF EXISTS grant_epoch ON component_org_switches;
88
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON component_org_switches
89
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch('updated_at', 'updated_by');
90
+
91
+ DROP TRIGGER IF EXISTS grant_epoch ON component_scope_orgs;
92
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON component_scope_orgs
93
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch();
94
+
95
+ DROP TRIGGER IF EXISTS grant_epoch ON platform_connector_templates;
96
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON platform_connector_templates
97
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch('created_at', 'updated_at');
98
+
99
+ -- The check reads only `orgs.id` and `orgs.deleted_at`: org deletion bumps, a rename does not.
100
+ DROP TRIGGER IF EXISTS grant_epoch ON orgs;
101
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER UPDATE OF deleted_at OR DELETE ON orgs
102
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch();
103
+
104
+ -- TRUNCATE fires no row triggers: a statement trigger bumps right away (no runtime code truncates
105
+ -- these tables; it covers operators and tests).
106
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON extension_installs;
107
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON extension_installs
108
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
109
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON extension_permission_snapshots;
110
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON extension_permission_snapshots
111
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
112
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON extension_catalog_sources;
113
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON extension_catalog_sources
114
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
115
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON catalog_items;
116
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON catalog_items
117
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
118
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON catalog_item_versions;
119
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON catalog_item_versions
120
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
121
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON catalog_item_scope_orgs;
122
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON catalog_item_scope_orgs
123
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
124
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON catalog_item_org_switches;
125
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON catalog_item_org_switches
126
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
127
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON catalog_dependency_edges;
128
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON catalog_dependency_edges
129
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
130
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON component_org_switches;
131
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON component_org_switches
132
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
133
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON component_scope_orgs;
134
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON component_scope_orgs
135
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
136
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON platform_connector_templates;
137
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON platform_connector_templates
138
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
139
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON orgs;
140
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON orgs
141
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
@@ -0,0 +1,166 @@
1
+ -- Revision grants (extension permission model spec 2026-12-04, "Revision grants and enforcement
2
+ -- cutover"; plan task 1.2a). An admin approval binds to one exact package revision:
3
+ -- (plugin, version, sha512). sha512 is the lowercase hex digest of the package archive, the same
4
+ -- form `sha512Hex` gives for npm integrity.
5
+ --
6
+ -- A revision can be reviewed again after its grant was revoked or retired: each review is a new
7
+ -- generation, the old rows stay as history, and at most one generation per revision is live
8
+ -- (approved or partially revoked).
9
+ --
10
+ -- Expand only. Until the enforcing cutover (plan task 1.5a) the legacy
11
+ -- `extension_permission_snapshots` keep governing admission (shadow mode), and nothing here
12
+ -- refuses a start, load or call. Inherited databases get the new columns empty.
13
+ --
14
+ -- Creating the triggers and the foreign keys takes short locks on extension_installs,
15
+ -- extension_packages, accounts and orgs. The lock wait is bounded so a busy table fails the
16
+ -- migration instead of queueing writers.
17
+ SET LOCAL lock_timeout = '5s';
18
+
19
+ CREATE TABLE IF NOT EXISTS extension_revision_grants (
20
+ plugin text NOT NULL,
21
+ version text NOT NULL,
22
+ sha512 text NOT NULL CHECK (sha512 ~ '^[0-9a-f]{128}$'),
23
+ generation integer NOT NULL CHECK (generation > 0),
24
+ -- The canonical permission keys of the reviewed surface, sorted and unique. Full access for a
25
+ -- realm is the kernel-generated key `execution.full-access:<realm>`, revocable on its own.
26
+ keys jsonb NOT NULL CHECK (jsonb_typeof(keys) = 'array'),
27
+ -- The reviewed bilingual purpose rows, one per key: [{ "key", "zh", "en" }], sorted by key.
28
+ purposes jsonb NOT NULL CHECK (jsonb_typeof(purposes) = 'array'),
29
+ -- sha256 hex of the canonical encoding of `purposes`: continuity compares exact strings.
30
+ purposes_digest text NOT NULL CHECK (purposes_digest ~ '^[0-9a-f]{64}$'),
31
+ -- The forcing keys each granted full-access realm covers:
32
+ -- { "server": ["host.no-isolation", ...], "browser": [...], "device": [...] }; {} for none.
33
+ realms jsonb NOT NULL DEFAULT '{}'
34
+ CHECK (jsonb_typeof(realms) = 'object' AND realms - 'server' - 'browser' - 'device' = '{}'::jsonb),
35
+ review_hash text NOT NULL CHECK (review_hash <> ''),
36
+ -- The maximum org scope the approver granted; `named` lists its orgs in
37
+ -- extension_revision_grant_orgs.
38
+ approval_scope text NOT NULL CHECK (approval_scope IN ('all', 'optional', 'named')),
39
+ -- How this grant was made: an admin review, an operator through config or the CLI, automatic
40
+ -- approval outside production, or continuity from a previous grant.
41
+ source text NOT NULL
42
+ CHECK (source IN ('review', 'operator_config', 'operator_cli', 'auto', 'continuity')),
43
+ -- The approving authority exercised; a continuity grant carries its source grant's authority.
44
+ authority text NOT NULL CHECK (authority IN ('super_admin', 'operator', 'auto')),
45
+ CHECK (
46
+ (source = 'review' AND authority = 'super_admin')
47
+ OR (source IN ('operator_config', 'operator_cli') AND authority = 'operator')
48
+ OR (source = 'auto' AND authority = 'auto')
49
+ OR source = 'continuity'
50
+ ),
51
+ -- The verified publisher identity (issuer, identity, repository, workflow), or NULL.
52
+ publisher jsonb CHECK (publisher IS NULL OR jsonb_typeof(publisher) = 'object'),
53
+ publisher_evidence text NOT NULL CHECK (publisher_evidence IN ('verified', 'pin_only', 'none')),
54
+ CHECK ((publisher_evidence = 'verified') = (publisher IS NOT NULL)),
55
+ -- The grant this one continued (source `continuity`).
56
+ continued_version text,
57
+ continued_sha512 text,
58
+ continued_generation integer,
59
+ CHECK (
60
+ (continued_version IS NULL) = (continued_sha512 IS NULL)
61
+ AND (continued_version IS NULL) = (continued_generation IS NULL)
62
+ ),
63
+ CHECK ((source = 'continuity') = (continued_version IS NOT NULL)),
64
+ state text NOT NULL DEFAULT 'approved'
65
+ CHECK (state IN ('approved', 'partially_revoked', 'revoked', 'retired')),
66
+ -- Keys withdrawn by revocation; the reviewed rows above never change.
67
+ disabled_keys jsonb NOT NULL DEFAULT '[]'
68
+ CHECK (jsonb_typeof(disabled_keys) = 'array' AND keys @> disabled_keys),
69
+ -- Keys no longer needed (a full-access realm whose forcing reasons all went away). Retirement is
70
+ -- not revocation, and a later loss of isolation does not restore a retired key.
71
+ retired_keys jsonb NOT NULL DEFAULT '[]'
72
+ CHECK (jsonb_typeof(retired_keys) = 'array' AND keys @> retired_keys),
73
+ -- Forcing keys retired per realm ({ "server": ["host.no-isolation"] }), e.g. once the supervisor
74
+ -- became available while another forcing key still applies.
75
+ retired_forcing jsonb NOT NULL DEFAULT '{}'
76
+ CHECK (jsonb_typeof(retired_forcing) = 'object'
77
+ AND retired_forcing - 'server' - 'browser' - 'device' = '{}'::jsonb),
78
+ -- A retired forcing key is one of its realm's own.
79
+ CHECK (coalesce(realms -> 'server', '[]') @> coalesce(retired_forcing -> 'server', '[]')
80
+ AND coalesce(realms -> 'browser', '[]') @> coalesce(retired_forcing -> 'browser', '[]')
81
+ AND coalesce(realms -> 'device', '[]') @> coalesce(retired_forcing -> 'device', '[]')),
82
+ CHECK (state <> 'approved' OR disabled_keys = '[]'::jsonb),
83
+ CHECK (state <> 'partially_revoked' OR disabled_keys <> '[]'::jsonb),
84
+ approved_by text REFERENCES accounts(id) ON DELETE SET NULL,
85
+ approved_at timestamptz NOT NULL DEFAULT now(),
86
+ state_changed_by text REFERENCES accounts(id) ON DELETE SET NULL,
87
+ state_changed_at timestamptz,
88
+ PRIMARY KEY (plugin, version, sha512, generation),
89
+ FOREIGN KEY (plugin, continued_version, continued_sha512, continued_generation)
90
+ REFERENCES extension_revision_grants (plugin, version, sha512, generation)
91
+ );
92
+
93
+ -- At most one live generation per revision.
94
+ CREATE UNIQUE INDEX IF NOT EXISTS extension_revision_grants_live_uq
95
+ ON extension_revision_grants (plugin, version, sha512)
96
+ WHERE state IN ('approved', 'partially_revoked');
97
+
98
+ -- The orgs of a `named` approval scope. Deleting an org removes its rows.
99
+ CREATE TABLE IF NOT EXISTS extension_revision_grant_orgs (
100
+ plugin text NOT NULL,
101
+ version text NOT NULL,
102
+ sha512 text NOT NULL,
103
+ generation integer NOT NULL,
104
+ org_id text NOT NULL REFERENCES orgs(id) ON DELETE CASCADE,
105
+ PRIMARY KEY (plugin, version, sha512, generation, org_id),
106
+ FOREIGN KEY (plugin, version, sha512, generation)
107
+ REFERENCES extension_revision_grants (plugin, version, sha512, generation) ON DELETE CASCADE
108
+ );
109
+ CREATE INDEX IF NOT EXISTS extension_revision_grant_orgs_org_idx
110
+ ON extension_revision_grant_orgs (org_id);
111
+
112
+ -- The 0224 form: the uncorrelated settings reads become InitPlans, read once per statement.
113
+ DROP POLICY IF EXISTS org_scope ON extension_revision_grant_orgs;
114
+ CREATE POLICY org_scope ON extension_revision_grant_orgs
115
+ USING (rls_admits(org_id, (SELECT rls_scope_unrestricted()),
116
+ (SELECT pg_catalog.current_setting('capybara.org_id', true))))
117
+ WITH CHECK (rls_admits(org_id, (SELECT rls_scope_unrestricted()),
118
+ (SELECT pg_catalog.current_setting('capybara.org_id', true))));
119
+ ALTER TABLE extension_revision_grant_orgs ENABLE ROW LEVEL SECURITY, FORCE ROW LEVEL SECURITY;
120
+
121
+ -- The approved revision of an install references the grant generation it was promoted under
122
+ -- (its state is read at admission); a candidate may exist without any grant.
123
+ ALTER TABLE extension_installs ADD COLUMN IF NOT EXISTS approved_version text;
124
+ ALTER TABLE extension_installs ADD COLUMN IF NOT EXISTS approved_sha512 text;
125
+ ALTER TABLE extension_installs ADD COLUMN IF NOT EXISTS approved_generation integer;
126
+ ALTER TABLE extension_installs ADD COLUMN IF NOT EXISTS candidate_version text;
127
+ ALTER TABLE extension_installs ADD COLUMN IF NOT EXISTS candidate_sha512 text;
128
+ ALTER TABLE extension_installs DROP CONSTRAINT IF EXISTS extension_installs_approved_revision_check;
129
+ ALTER TABLE extension_installs ADD CONSTRAINT extension_installs_approved_revision_check
130
+ CHECK ((approved_version IS NULL) = (approved_sha512 IS NULL)
131
+ AND (approved_version IS NULL) = (approved_generation IS NULL));
132
+ ALTER TABLE extension_installs DROP CONSTRAINT IF EXISTS extension_installs_candidate_revision_check;
133
+ ALTER TABLE extension_installs ADD CONSTRAINT extension_installs_candidate_revision_check
134
+ CHECK ((candidate_version IS NULL) = (candidate_sha512 IS NULL)
135
+ AND (candidate_sha512 IS NULL OR candidate_sha512 ~ '^[0-9a-f]{128}$'));
136
+ ALTER TABLE extension_installs DROP CONSTRAINT IF EXISTS extension_installs_approved_revision_fkey;
137
+ ALTER TABLE extension_installs ADD CONSTRAINT extension_installs_approved_revision_fkey
138
+ FOREIGN KEY (name, approved_version, approved_sha512, approved_generation)
139
+ REFERENCES extension_revision_grants (plugin, version, sha512, generation);
140
+
141
+ -- The sha512 of each stored package, so a grant resolves without re-hashing the blob. Filled at
142
+ -- ingest and backfilled for older packages by plan task 1.2b; NULL until then.
143
+ ALTER TABLE extension_packages ADD COLUMN IF NOT EXISTS sha512 text;
144
+ ALTER TABLE extension_packages DROP CONSTRAINT IF EXISTS extension_packages_sha512_check;
145
+ ALTER TABLE extension_packages ADD CONSTRAINT extension_packages_sha512_check
146
+ CHECK (sha512 IS NULL OR sha512 ~ '^[0-9a-f]{128}$');
147
+
148
+ -- Grant state transitions advance the grant epoch (migration 0234) at commit, so replicas drop
149
+ -- cached decisions within the 5 s bound once the grant check reads these tables (plan task
150
+ -- 1.2b). extension_installs already carries the trigger; its new revision columns are not audit
151
+ -- columns, so promotions and candidate changes bump too.
152
+ DROP TRIGGER IF EXISTS grant_epoch ON extension_revision_grants;
153
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON extension_revision_grants
154
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW
155
+ EXECUTE FUNCTION bump_extension_grant_epoch('approved_by', 'approved_at', 'state_changed_by', 'state_changed_at');
156
+
157
+ DROP TRIGGER IF EXISTS grant_epoch ON extension_revision_grant_orgs;
158
+ CREATE CONSTRAINT TRIGGER grant_epoch AFTER INSERT OR UPDATE OR DELETE ON extension_revision_grant_orgs
159
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bump_extension_grant_epoch();
160
+
161
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON extension_revision_grants;
162
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON extension_revision_grants
163
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
164
+ DROP TRIGGER IF EXISTS grant_epoch_truncate ON extension_revision_grant_orgs;
165
+ CREATE TRIGGER grant_epoch_truncate AFTER TRUNCATE ON extension_revision_grant_orgs
166
+ FOR EACH STATEMENT EXECUTE FUNCTION bump_extension_grant_epoch();
@@ -0,0 +1,33 @@
1
+ -- Page-number reads of the server-paged tables (table pagination
2
+ -- spec §2.3): each orders by a stable key ending in the id, and these indexes serve that order
3
+ -- (the count stops at 10,001 rows, the offset at 10,000).
4
+ -- Plain CREATE INDEX: the migrator runs each file in a transaction.
5
+
6
+ -- The platform's accounts, newest first.
7
+ CREATE INDEX IF NOT EXISTS accounts_created_idx ON accounts (created_at DESC, id DESC);
8
+
9
+ -- Every org's live agents and connectors, newest first (the super admin's lists, across orgs
10
+ -- unless an org filter is given).
11
+ CREATE INDEX IF NOT EXISTS agents_created_idx
12
+ ON agents (created_at DESC, id DESC) WHERE deleted_at IS NULL;
13
+ CREATE INDEX IF NOT EXISTS connectors_created_idx
14
+ ON connectors (created_at DESC, id DESC) WHERE deleted_at IS NULL;
15
+
16
+ -- An org's conversations of one kind, last active first (the trajectory list of an org admin;
17
+ -- one agent's list uses conversations_agent_idx).
18
+ CREATE INDEX IF NOT EXISTS conversations_org_kind_updated_idx
19
+ ON conversations (org_id, kind, updated_at DESC, id DESC);
20
+
21
+ -- An org's members by join time, its invitations newest first, and its live automations newest
22
+ -- first (the members, invitations and automations pages; one creator's automations use
23
+ -- automations_account_idx). An eval set's runs use eval_runs_set_idx (set_id, created_at DESC).
24
+ CREATE INDEX IF NOT EXISTS memberships_org_joined_idx
25
+ ON memberships (org_id, created_at, account_id);
26
+ CREATE INDEX IF NOT EXISTS invitations_org_created_idx
27
+ ON invitations (org_id, created_at DESC, id DESC);
28
+ CREATE INDEX IF NOT EXISTS automations_org_created_idx
29
+ ON automations (org_id, created_at DESC, id) WHERE deleted_at IS NULL;
30
+
31
+ -- The platform's live orgs, newest first (the super admin's orgs list).
32
+ CREATE INDEX IF NOT EXISTS orgs_created_idx
33
+ ON orgs (created_at DESC, id DESC) WHERE deleted_at IS NULL;
@@ -0,0 +1,18 @@
1
+ -- Retain provisioned handoffs after unload and record a missing-table transition once.
2
+ CREATE TABLE IF NOT EXISTS extension_handoff_tables (
3
+ schema_name text PRIMARY KEY,
4
+ missing boolean NOT NULL DEFAULT false
5
+ );
6
+
7
+ INSERT INTO extension_handoff_tables (schema_name)
8
+ SELECT n.nspname FROM pg_catalog.pg_class c
9
+ JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
10
+ WHERE c.relname = '_capybara_effect_handoff' AND c.relkind = 'r'
11
+ AND n.nspname ~ '^plugin_[a-z][a-z0-9_]{1,40}$'
12
+ ON CONFLICT DO NOTHING;
13
+
14
+ CREATE TABLE IF NOT EXISTS extension_admission_refusals (
15
+ plugin text NOT NULL,
16
+ sha256 text NOT NULL,
17
+ PRIMARY KEY (plugin, sha256)
18
+ );