@capybara-hq/kernel 0.1.0-rc.143 → 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 (122) 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/automations/automations.controller.d.ts +9 -5
  14. package/dist/automations/automations.controller.js +21 -4
  15. package/dist/automations/automations.schemas.d.ts +19 -0
  16. package/dist/automations/automations.schemas.js +9 -0
  17. package/dist/automations/automations.service.d.ts +25 -8
  18. package/dist/automations/automations.service.js +40 -34
  19. package/dist/automations/store.d.ts +17 -0
  20. package/dist/automations/store.js +35 -0
  21. package/dist/catalog/admin-catalog.controller.d.ts +64 -2
  22. package/dist/catalog/admin-catalog.controller.js +17 -0
  23. package/dist/catalog/cli.js +2 -2
  24. package/dist/catalog/marketplaces.service.d.ts +1 -1
  25. package/dist/catalog/plugin-package.js +2 -1
  26. package/dist/client/client-access.service.js +29 -1
  27. package/dist/config/schema.d.ts +9 -0
  28. package/dist/config/schema.js +26 -0
  29. package/dist/ctx/create-ctx.d.ts +2 -19
  30. package/dist/ctx/create-ctx.js +3 -93
  31. package/dist/ctx/durable-relay.d.ts +2 -5
  32. package/dist/ctx/durable-relay.js +56 -29
  33. package/dist/db/extension-handoff-schema.js +5 -0
  34. package/dist/db/kernel-schema.d.ts +74 -0
  35. package/dist/erasure/account-batches.js +2 -0
  36. package/dist/erasure/account-residual.js +1 -0
  37. package/dist/erasure/org-catalog.js +8 -3
  38. package/dist/erasure/org-rules.js +1 -0
  39. package/dist/evals/evals.schemas.d.ts +15 -5
  40. package/dist/evals/evals.schemas.js +17 -10
  41. package/dist/evals/runs.controller.d.ts +4 -12
  42. package/dist/evals/runs.controller.js +14 -11
  43. package/dist/evals/runs.service.d.ts +29 -25
  44. package/dist/evals/runs.service.js +73 -61
  45. package/dist/evals/trajectory.controller.d.ts +10 -6
  46. package/dist/evals/trajectory.controller.js +11 -4
  47. package/dist/evals/trajectory.service.d.ts +17 -9
  48. package/dist/evals/trajectory.service.js +52 -35
  49. package/dist/extensions/admin-ops.js +4 -3
  50. package/dist/extensions/blobs.d.ts +2 -0
  51. package/dist/extensions/blobs.js +11 -0
  52. package/dist/extensions/enabled.d.ts +5 -0
  53. package/dist/extensions/grant-epoch.d.ts +108 -0
  54. package/dist/extensions/grant-epoch.js +214 -0
  55. package/dist/extensions/host.d.ts +29 -9
  56. package/dist/extensions/host.js +148 -42
  57. package/dist/extensions/instance.d.ts +3 -3
  58. package/dist/extensions/instance.js +1 -1
  59. package/dist/extensions/isolated/authorization.d.ts +54 -2
  60. package/dist/extensions/isolated/authorization.js +148 -35
  61. package/dist/extensions/isolated/child-session.js +0 -1
  62. package/dist/extensions/isolated/revision.js +1 -1
  63. package/dist/extensions/package-digest.job.d.ts +34 -0
  64. package/dist/extensions/package-digest.job.js +121 -0
  65. package/dist/extensions/package.js +10 -6
  66. package/dist/extensions/permission-set.d.ts +14 -78
  67. package/dist/extensions/permission-set.js +17 -143
  68. package/dist/extensions/permission-view.d.ts +13 -1
  69. package/dist/extensions/permission-view.js +20 -0
  70. package/dist/extensions/registry.js +4 -1
  71. package/dist/extensions/resolve.d.ts +7 -8
  72. package/dist/extensions/resolve.js +7 -8
  73. package/dist/extensions/revision-approvals.d.ts +167 -0
  74. package/dist/extensions/revision-approvals.js +353 -0
  75. package/dist/extensions/revision-grants.d.ts +197 -0
  76. package/dist/extensions/revision-grants.js +584 -0
  77. package/dist/extensions/state.module.js +12 -1
  78. package/dist/identity/accounts.d.ts +10 -4
  79. package/dist/identity/accounts.js +18 -5
  80. package/dist/infra/database/extension-effect-key-lock.js +7 -0
  81. package/dist/infra/paging/paged-read.d.ts +34 -4
  82. package/dist/infra/paging/paged-read.js +38 -1
  83. package/dist/orgs/invitations.controller.d.ts +4 -7
  84. package/dist/orgs/invitations.controller.js +8 -5
  85. package/dist/orgs/invitations.service.d.ts +17 -3
  86. package/dist/orgs/invitations.service.js +35 -13
  87. package/dist/orgs/members.service.d.ts +35 -0
  88. package/dist/orgs/members.service.js +52 -3
  89. package/dist/orgs/orgs.controller.d.ts +11 -4
  90. package/dist/orgs/orgs.controller.js +25 -5
  91. package/dist/orgs/orgs.schemas.d.ts +14 -0
  92. package/dist/orgs/orgs.schemas.js +19 -2
  93. package/dist/orgs/orgs.service.d.ts +21 -1
  94. package/dist/orgs/orgs.service.js +40 -1
  95. package/dist/orgs/security-settings.service.d.ts +14 -6
  96. package/dist/orgs/security-settings.service.js +18 -13
  97. package/dist/orgs/settings.controller.d.ts +7 -4
  98. package/dist/platform/exclusions.js +15 -0
  99. package/dist/platform/ops/accounts.ops.js +7 -16
  100. package/dist/platform/ops/admin-items.ops.js +7 -7
  101. package/dist/platform/ops/automations.ops.js +6 -4
  102. package/dist/platform/ops/evals.ops.js +30 -15
  103. package/dist/platform/ops/org-settings.ops.js +2 -2
  104. package/dist/platform/ops/orgs.ops.js +44 -27
  105. package/dist/roles/worker.module.js +3 -0
  106. package/dist/runtime/step-log.d.ts +1 -1
  107. package/dist/runtime/step-log.js +5 -4
  108. package/dist/setup/kernel-checks.d.ts +3 -3
  109. package/dist/setup/kernel-checks.js +4 -4
  110. package/dist/setup/setup-check-registry.d.ts +16 -5
  111. package/dist/setup/setup-check-registry.js +11 -3
  112. package/dist/setup/setup-checks.service.d.ts +1 -2
  113. package/dist/setup/setup-checks.service.js +7 -6
  114. package/dist/tools/admin-connectors.d.ts +10 -8
  115. package/dist/tools/admin-connectors.js +12 -10
  116. package/dist/tools/builtins/automations.d.ts +1 -1
  117. package/dist/tools/builtins/automations.js +1 -1
  118. package/package.json +3 -3
  119. package/src/migrations/0234_extension_grant_epoch.sql +141 -0
  120. package/src/migrations/0235_extension_revision_grants.sql +166 -0
  121. package/src/migrations/0236_paged_table_idx.sql +33 -0
  122. package/src/migrations/0237_extension_handoff_health.sql +18 -0
@@ -87,11 +87,12 @@ let StepLog = class StepLog {
87
87
  }
88
88
  return { written, toSeq: fresh.length > 0 ? Math.max(...fresh.map((e) => e.seq)) : null };
89
89
  }
90
- /** Appends events with their audit row (a hook denial). */
90
+ /** Appends events with an audit row for a newly recorded denial. */
91
91
  async appendAudited(conversationId, events, entry) {
92
- const out = await this.eventLog.appendIn(conversationId, events);
93
- await audit(this.kdb.db, entry);
94
- return out;
92
+ const result = await this.eventLog.appendInReport(conversationId, events);
93
+ if (result.fresh.some(Boolean))
94
+ await audit(this.kdb.db, entry);
95
+ return result.events;
95
96
  }
96
97
  /**
97
98
  * Appends a `model_call` with the tool definitions its request sent, stored by fingerprint in
@@ -60,9 +60,9 @@ export declare function connectionActiveResult(row: {
60
60
  lastError: string | null;
61
61
  } | undefined, secrets: readonly string[]): SetupCheckResult;
62
62
  /**
63
- * Registers the kernel checks on module init (static code, the same on every replica). Each reads
64
- * only the target the service resolved (ids of the caller's org, after authorization) and never
65
- * writes; `capybara:oauth-token-endpoint` is the only one that leaves the kernel (§10.6).
63
+ * Registers read-only kernel checks on every replica. Deployment checks need no org target.
64
+ * Org checks receive the authorized target resolved by the service.
65
+ * `capybara:oauth-token-endpoint` is the only one that leaves the kernel (§10.6).
66
66
  */
67
67
  export declare class KernelChecks implements OnModuleInit {
68
68
  private readonly registry;
@@ -144,9 +144,9 @@ export function connectionActiveResult(row, secrets) {
144
144
  return { status: "ok", reason: KERNEL_CHECK_TEXTS.connectionActive };
145
145
  }
146
146
  /**
147
- * Registers the kernel checks on module init (static code, the same on every replica). Each reads
148
- * only the target the service resolved (ids of the caller's org, after authorization) and never
149
- * writes; `capybara:oauth-token-endpoint` is the only one that leaves the kernel (§10.6).
147
+ * Registers read-only kernel checks on every replica. Deployment checks need no org target.
148
+ * Org checks receive the authorized target resolved by the service.
149
+ * `capybara:oauth-token-endpoint` is the only one that leaves the kernel (§10.6).
150
150
  */
151
151
  let KernelChecks = class KernelChecks {
152
152
  registry;
@@ -163,7 +163,7 @@ let KernelChecks = class KernelChecks {
163
163
  }
164
164
  onModuleInit() {
165
165
  const r = this.registry;
166
- r.registerKernel("capybara:public-url", "any", async () => publicUrlCheck(this.config.get()));
166
+ r.registerDeploymentKernel("capybara:public-url", async () => publicUrlCheck(this.config.get()));
167
167
  r.registerKernel("capybara:webhook-public", "channel-connection", async () => webhookPublicCheck(this.config.get()));
168
168
  r.registerKernel("capybara:webhook-received", "channel-connection", (a) => this.webhookReceived(a));
169
169
  r.registerKernel("capybara:connection-active", "channel-connection", (a) => this.connectionActive(a));
@@ -44,13 +44,20 @@ export interface KernelCheckArgs {
44
44
  }
45
45
  /** A kernel check's implementation. */
46
46
  export type KernelCheckRun = (args: KernelCheckArgs) => Promise<SetupCheckResult>;
47
- /** A check found for a guide's `::check` line. */
48
- export type ResolvedSetupCheck = {
49
- source: "kernel";
50
- id: string;
47
+ type KernelCheck = {
48
+ scope: "org";
51
49
  place: SetupGuidePlace | "any";
52
50
  run: KernelCheckRun;
53
51
  } | {
52
+ scope: "deployment";
53
+ place: "any";
54
+ run: () => Promise<SetupCheckResult>;
55
+ };
56
+ /** A check found for a guide's `::check` line. */
57
+ export type ResolvedSetupCheck = ({
58
+ source: "kernel";
59
+ id: string;
60
+ } & KernelCheck) | {
54
61
  source: "plugin";
55
62
  id: string;
56
63
  place: SetupGuidePlace;
@@ -73,8 +80,11 @@ export declare class SetupCheckRegistry {
73
80
  private readonly extensions;
74
81
  private readonly kernel;
75
82
  constructor(extensions: Pick<ExtensionRegistry, "current">);
76
- /** Registers a kernel check; an id twice, a malformed id or an unknown place throws. */
83
+ /** Registers a kernel check that needs an org target. */
77
84
  registerKernel(id: `capybara:${string}`, place: SetupGuidePlace | "any", run: KernelCheckRun): void;
85
+ /** Registers a target-independent kernel check available on platform and org guides. */
86
+ registerDeploymentKernel(id: `capybara:${string}`, run: () => Promise<SetupCheckResult>): void;
87
+ private addKernelCheck;
78
88
  /**
79
89
  * The check behind a guide's `::check <id>` line of `plugin`'s guide: a kernel check for
80
90
  * `capybara:*`, else the plugin's own (null when this replica does not run the extension or the
@@ -84,3 +94,4 @@ export declare class SetupCheckRegistry {
84
94
  /** Whether `plugin` runs on this replica. */
85
95
  running(plugin: string): boolean;
86
96
  }
97
+ export {};
@@ -25,8 +25,16 @@ let SetupCheckRegistry = class SetupCheckRegistry {
25
25
  constructor(extensions) {
26
26
  this.extensions = extensions;
27
27
  }
28
- /** Registers a kernel check; an id twice, a malformed id or an unknown place throws. */
28
+ /** Registers a kernel check that needs an org target. */
29
29
  registerKernel(id, place, run) {
30
+ this.addKernelCheck(id, { scope: "org", place, run });
31
+ }
32
+ /** Registers a target-independent kernel check available on platform and org guides. */
33
+ registerDeploymentKernel(id, run) {
34
+ this.addKernelCheck(id, { scope: "deployment", place: "any", run });
35
+ }
36
+ addKernelCheck(id, check) {
37
+ const { place, run } = check;
30
38
  if (!KERNEL_ID_RE.test(id))
31
39
  throw new Error(`setup check id "${id}" is not capybara:<id>`);
32
40
  if (place !== "any" && !SETUP_GUIDE_PLACES.includes(place)) {
@@ -36,7 +44,7 @@ let SetupCheckRegistry = class SetupCheckRegistry {
36
44
  throw new Error(`setup check "${id}": run must be a function`);
37
45
  if (this.kernel.has(id))
38
46
  throw new Error(`duplicate kernel setup check "${id}"`);
39
- this.kernel.set(id, Object.freeze({ place, run }));
47
+ this.kernel.set(id, Object.freeze(check));
40
48
  }
41
49
  /**
42
50
  * The check behind a guide's `::check <id>` line of `plugin`'s guide: a kernel check for
@@ -46,7 +54,7 @@ let SetupCheckRegistry = class SetupCheckRegistry {
46
54
  resolve(plugin, id) {
47
55
  if (id.startsWith("capybara:")) {
48
56
  const k = this.kernel.get(id);
49
- return k ? { source: "kernel", id, place: k.place, run: k.run } : null;
57
+ return k ? { source: "kernel", id, ...k } : null;
50
58
  }
51
59
  const inst = this.extensions.current(plugin);
52
60
  const c = inst?.setupChecks.get(id);
@@ -78,8 +78,7 @@ export declare class SetupChecksService {
78
78
  * /admin/extensions/:name/guides/:guideId/checks/:checkId/run`, super admins: the route's
79
79
  * guard) with the extension's platform deployment config, `orgId: null`. The cache, single
80
80
  * flight, cooldown and concurrency cap are the org places', keyed by the deployment; the
81
- * per-account limit is shared with every other run. A kernel check (`capybara:*`) does not apply
82
- * here.
81
+ * per-account limit is shared with every other run. Deployment-scoped kernel checks also apply.
83
82
  */
84
83
  deploymentRun(accountId: string, plugin: string, guideId: string, checkId: string, body: {
85
84
  force?: boolean | undefined;
@@ -157,8 +157,7 @@ let SetupChecksService = class SetupChecksService {
157
157
  * /admin/extensions/:name/guides/:guideId/checks/:checkId/run`, super admins: the route's
158
158
  * guard) with the extension's platform deployment config, `orgId: null`. The cache, single
159
159
  * flight, cooldown and concurrency cap are the org places', keyed by the deployment; the
160
- * per-account limit is shared with every other run. A kernel check (`capybara:*`) does not apply
161
- * here.
160
+ * per-account limit is shared with every other run. Deployment-scoped kernel checks also apply.
162
161
  */
163
162
  async deploymentRun(accountId, plugin, guideId, checkId, body) {
164
163
  const p = await this.prepareDeployment(accountId, plugin, guideId, checkId);
@@ -249,9 +248,9 @@ let SetupChecksService = class SetupChecksService {
249
248
  return unknownState(REASONS.unregistered);
250
249
  if (check.place !== "any" && check.place !== p.place)
251
250
  return unknownState(REASONS.otherPlace);
252
- // kernel checks are about an org's targets; the deployment has none
253
- if (check.source === "kernel" && p.orgId === null)
251
+ if (check.source === "kernel" && check.scope === "org" && p.orgId === null) {
254
252
  return unknownState(REASONS.otherPlace);
253
+ }
255
254
  const keys = this.keys(p, checkId);
256
255
  const revision = await this.revision(p, accountScoped(p, checkId));
257
256
  const fingerprint = this.fingerprint(p, revision);
@@ -548,10 +547,12 @@ let SetupChecksService = class SetupChecksService {
548
547
  // the in-flight tracker merges the instance's abort into the signal the check gets
549
548
  () => check.inflight.run(signal, (s) => check.run(this.pluginArgs(p, material, config, locale, s))), () => (check.signal.aborted ? "unloaded" : "timeout"));
550
549
  }
550
+ else if (check.scope === "deployment") {
551
+ answer = await raceSignal(timeout, check.run, () => "timeout");
552
+ }
551
553
  else {
552
- // refused for the deployment before the lock (`runPrepared`)
553
554
  if (p.orgId === null)
554
- throw new Error("a kernel check has no deployment target");
555
+ throw new Error("an org kernel check requires an org target");
555
556
  const signal = timeout;
556
557
  const args = Object.freeze({
557
558
  orgId: p.orgId,
@@ -1,4 +1,5 @@
1
1
  import { KernelDb } from "../infra/database/kernel-db.js";
2
+ import { type Page } from "../infra/paging/paged-read.js";
2
3
  import type { ToolPolicy } from "./registry.js";
3
4
  /** One connector in the super admin's cross-org list (no endpoint, auth or credential). */
4
5
  export interface AdminConnectorRow {
@@ -47,9 +48,10 @@ export interface AdminConnectorQuery {
47
48
  status?: "active" | "disabled" | undefined;
48
49
  /** A case-insensitive substring of the connector name. */
49
50
  q?: string | undefined;
50
- /** The last id of the previous page. */
51
- after?: string | undefined;
52
- limit: number;
51
+ /** The page, 1-based. */
52
+ page: number;
53
+ /** Rows per page: 20, 50 or 100. */
54
+ size: number;
53
55
  }
54
56
  /**
55
57
  * Cross-org reads of connectors for the super admin (spec
@@ -61,11 +63,11 @@ export declare class AdminConnectors {
61
63
  constructor(kdb: KernelDb);
62
64
  private get db();
63
65
  private base;
64
- /** Live connectors of every live org by id, filtered; `next` is the last id when more follow. */
65
- list(q: AdminConnectorQuery): Promise<{
66
- connectors: AdminConnectorRow[];
67
- next: string | null;
68
- }>;
66
+ /**
67
+ * One page of every live org's live connectors, filtered, newest first (`created_at`, then id),
68
+ * by page number without a snapshot (table pagination spec §2.3: connectors are edited in place).
69
+ */
70
+ list(q: AdminConnectorQuery): Promise<Page<AdminConnectorRow>>;
69
71
  /** One live connector of a live org; else `connector.not_found`. */
70
72
  get(connectorId: string): Promise<AdminConnectorDetail>;
71
73
  }
@@ -12,6 +12,7 @@ import { sql } from "kysely";
12
12
  import { ApiError } from "../errors.js";
13
13
  import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
14
14
  import { KernelDb } from "../infra/database/kernel-db.js";
15
+ import { assertReadablePage, cappedCount, PAGED_TOTAL_CAP, pageOf, pageOffset, } from "../infra/paging/paged-read.js";
15
16
  import { endpointView } from "./endpoint.js";
16
17
  const notFound = () => new ApiError("connector.not_found", "Connector not found");
17
18
  /**
@@ -57,8 +58,12 @@ let AdminConnectors = class AdminConnectors {
57
58
  .where("c.deleted_at", "is", null)
58
59
  .where("o.deleted_at", "is", null));
59
60
  }
60
- /** Live connectors of every live org by id, filtered; `next` is the last id when more follow. */
61
+ /**
62
+ * One page of every live org's live connectors, filtered, newest first (`created_at`, then id),
63
+ * by page number without a snapshot (table pagination spec §2.3: connectors are edited in place).
64
+ */
61
65
  async list(q) {
66
+ assertReadablePage(q.page, q.size);
62
67
  let query = this.base();
63
68
  if (q.orgId !== undefined)
64
69
  query = query.where("c.org_id", "=", q.orgId);
@@ -68,17 +73,14 @@ let AdminConnectors = class AdminConnectors {
68
73
  const like = `%${q.q.replace(/[\\%_]/g, (ch) => `\\${ch}`)}%`;
69
74
  query = query.where(sql `c.name ILIKE ${like} ESCAPE '\\'`);
70
75
  }
71
- if (q.after !== undefined)
72
- query = query.where("c.id", ">", q.after);
76
+ const counted = await cappedCount(this.db, query, PAGED_TOTAL_CAP);
73
77
  const rows = await query
74
- .orderBy("c.id")
75
- .limit(q.limit + 1)
78
+ .orderBy("c.created_at", "desc")
79
+ .orderBy("c.id", "desc")
80
+ .offset(pageOffset(q.page, q.size))
81
+ .limit(q.size)
76
82
  .execute();
77
- const page = rows.slice(0, q.limit).map(toRow);
78
- return {
79
- connectors: page,
80
- next: rows.length > q.limit ? (page[page.length - 1]?.id ?? null) : null,
81
- };
83
+ return pageOf(rows.map(toRow), q, counted);
82
84
  }
83
85
  /** One live connector of a live org; else `connector.not_found`. */
84
86
  async get(connectorId) {
@@ -31,7 +31,7 @@ import type { BuiltinTool } from "../registry.js";
31
31
  * the IM chat named by `chat`. The zone is the run's (`run_context`, else the org's, else UTC).
32
32
  */
33
33
  /** The task service as the tools use it (bound at start; null when not loaded here). */
34
- export type AutomationService = Pick<AutomationsService, "create" | "update" | "list" | "remove" | "addGrants" | "removeGrant" | "chatTargets">;
34
+ export type AutomationService = Pick<AutomationsService, "create" | "update" | "listOwn" | "remove" | "addGrants" | "removeGrant" | "chatTargets">;
35
35
  /**
36
36
  * Where the automation tools find the task service: a registration port. `AutomationsModule` imports
37
37
  * `ToolsModule` (its grants resolve the agent's tools through `ToolRegistry`, which lists these
@@ -989,7 +989,7 @@ export function automationTools(deps) {
989
989
  async run(_raw, ctx) {
990
990
  const svc = await service();
991
991
  await liveRole(ctx);
992
- const tasks = await call(() => svc.list(ctx.orgId, { accountId: ctx.accountId }), {});
992
+ const tasks = await call(() => svc.listOwn(ctx.orgId, { accountId: ctx.accountId }), {});
993
993
  if (tasks.length === 0) {
994
994
  return {
995
995
  content: [{ type: "text", text: "The user has no automations in this organization." }],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.143",
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();