@capybara-hq/kernel 0.1.0-rc.143 → 0.1.0-rc.145

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 (134) 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 +30 -11
  12. package/dist/agents/admin-agents.js +51 -16
  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/marketplace-fetch.d.ts +2 -0
  25. package/dist/catalog/marketplace-fetch.js +7 -2
  26. package/dist/catalog/marketplaces.service.d.ts +1 -1
  27. package/dist/catalog/plugin-package.js +2 -1
  28. package/dist/client/client-access.service.js +29 -1
  29. package/dist/config/schema.d.ts +9 -0
  30. package/dist/config/schema.js +26 -0
  31. package/dist/ctx/create-ctx.d.ts +2 -19
  32. package/dist/ctx/create-ctx.js +3 -93
  33. package/dist/ctx/durable-relay.d.ts +2 -5
  34. package/dist/ctx/durable-relay.js +56 -29
  35. package/dist/db/extension-handoff-schema.js +5 -0
  36. package/dist/db/kernel-schema.d.ts +74 -0
  37. package/dist/erasure/account-batches.js +2 -0
  38. package/dist/erasure/account-residual.js +1 -0
  39. package/dist/erasure/org-catalog.js +8 -3
  40. package/dist/erasure/org-rules.js +1 -0
  41. package/dist/errors.d.ts +1 -1
  42. package/dist/errors.js +2 -2
  43. package/dist/evals/evals.schemas.d.ts +15 -5
  44. package/dist/evals/evals.schemas.js +17 -10
  45. package/dist/evals/runs.controller.d.ts +4 -12
  46. package/dist/evals/runs.controller.js +14 -11
  47. package/dist/evals/runs.service.d.ts +29 -25
  48. package/dist/evals/runs.service.js +73 -61
  49. package/dist/evals/trajectory.controller.d.ts +10 -6
  50. package/dist/evals/trajectory.controller.js +11 -4
  51. package/dist/evals/trajectory.service.d.ts +17 -9
  52. package/dist/evals/trajectory.service.js +52 -35
  53. package/dist/extensions/admin-ops.js +4 -3
  54. package/dist/extensions/blobs.d.ts +2 -0
  55. package/dist/extensions/blobs.js +11 -0
  56. package/dist/extensions/enabled.d.ts +5 -0
  57. package/dist/extensions/grant-epoch.d.ts +108 -0
  58. package/dist/extensions/grant-epoch.js +214 -0
  59. package/dist/extensions/host.d.ts +30 -10
  60. package/dist/extensions/host.js +162 -43
  61. package/dist/extensions/instance.d.ts +3 -3
  62. package/dist/extensions/instance.js +1 -1
  63. package/dist/extensions/isolated/authorization.d.ts +54 -2
  64. package/dist/extensions/isolated/authorization.js +148 -35
  65. package/dist/extensions/isolated/child-session.js +0 -1
  66. package/dist/extensions/isolated/revision.js +1 -1
  67. package/dist/extensions/isolated/tier.d.ts +14 -0
  68. package/dist/extensions/isolated/tier.js +27 -0
  69. package/dist/extensions/package-digest.job.d.ts +34 -0
  70. package/dist/extensions/package-digest.job.js +121 -0
  71. package/dist/extensions/package.js +10 -6
  72. package/dist/extensions/permission-set.d.ts +14 -78
  73. package/dist/extensions/permission-set.js +17 -143
  74. package/dist/extensions/permission-view.d.ts +13 -1
  75. package/dist/extensions/permission-view.js +20 -0
  76. package/dist/extensions/publisher-proof.job.d.ts +39 -0
  77. package/dist/extensions/publisher-proof.job.js +160 -0
  78. package/dist/extensions/registry.js +4 -1
  79. package/dist/extensions/resolve.d.ts +7 -8
  80. package/dist/extensions/resolve.js +7 -8
  81. package/dist/extensions/revision-approvals.d.ts +167 -0
  82. package/dist/extensions/revision-approvals.js +353 -0
  83. package/dist/extensions/revision-grants.d.ts +197 -0
  84. package/dist/extensions/revision-grants.js +584 -0
  85. package/dist/extensions/state.module.js +12 -1
  86. package/dist/identity/accounts.d.ts +10 -4
  87. package/dist/identity/accounts.js +18 -5
  88. package/dist/infra/database/extension-effect-key-lock.js +7 -0
  89. package/dist/infra/paging/paged-read.d.ts +34 -4
  90. package/dist/infra/paging/paged-read.js +38 -1
  91. package/dist/orgs/invitations.controller.d.ts +4 -7
  92. package/dist/orgs/invitations.controller.js +8 -5
  93. package/dist/orgs/invitations.service.d.ts +17 -3
  94. package/dist/orgs/invitations.service.js +35 -13
  95. package/dist/orgs/members.service.d.ts +35 -0
  96. package/dist/orgs/members.service.js +52 -3
  97. package/dist/orgs/orgs.controller.d.ts +11 -4
  98. package/dist/orgs/orgs.controller.js +25 -5
  99. package/dist/orgs/orgs.schemas.d.ts +14 -0
  100. package/dist/orgs/orgs.schemas.js +19 -2
  101. package/dist/orgs/orgs.service.d.ts +21 -1
  102. package/dist/orgs/orgs.service.js +40 -1
  103. package/dist/orgs/security-settings.service.d.ts +14 -6
  104. package/dist/orgs/security-settings.service.js +18 -13
  105. package/dist/orgs/settings.controller.d.ts +7 -4
  106. package/dist/packages/official-publisher.d.ts +5 -0
  107. package/dist/packages/official-publisher.js +24 -3
  108. package/dist/packages/provenance.d.ts +6 -0
  109. package/dist/packages/provenance.js +26 -9
  110. package/dist/platform/exclusions.js +15 -0
  111. package/dist/platform/ops/accounts.ops.js +7 -16
  112. package/dist/platform/ops/admin-items.ops.js +8 -8
  113. package/dist/platform/ops/automations.ops.js +6 -4
  114. package/dist/platform/ops/evals.ops.js +30 -15
  115. package/dist/platform/ops/org-settings.ops.js +2 -2
  116. package/dist/platform/ops/orgs.ops.js +44 -27
  117. package/dist/roles/worker.module.js +6 -0
  118. package/dist/runtime/step-log.d.ts +1 -1
  119. package/dist/runtime/step-log.js +5 -4
  120. package/dist/setup/kernel-checks.d.ts +3 -3
  121. package/dist/setup/kernel-checks.js +4 -4
  122. package/dist/setup/setup-check-registry.d.ts +16 -5
  123. package/dist/setup/setup-check-registry.js +11 -3
  124. package/dist/setup/setup-checks.service.d.ts +1 -2
  125. package/dist/setup/setup-checks.service.js +7 -6
  126. package/dist/tools/admin-connectors.d.ts +10 -8
  127. package/dist/tools/admin-connectors.js +12 -10
  128. package/dist/tools/builtins/automations.d.ts +1 -1
  129. package/dist/tools/builtins/automations.js +1 -1
  130. package/package.json +3 -3
  131. package/src/migrations/0234_extension_grant_epoch.sql +141 -0
  132. package/src/migrations/0235_extension_revision_grants.sql +166 -0
  133. package/src/migrations/0236_paged_table_idx.sql +33 -0
  134. package/src/migrations/0237_extension_handoff_health.sql +18 -0
@@ -9,6 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { z } from "zod";
12
+ import { AdminOrgListQuery } from "../../admin/admin.schemas.js";
12
13
  import { OrgAuditActorsQuery, OrgAuditListQuery } from "../../admin/audit.schemas.js";
13
14
  import { AuditLogService } from "../../admin/audit-log.service.js";
14
15
  import { limitDefaults } from "../../admin/limit-defaults.js";
@@ -23,17 +24,15 @@ import { MemberBudgetBody } from "../../models/budget-policy.js";
23
24
  import { InvitationsService } from "../../orgs/invitations.service.js";
24
25
  import { MembersService } from "../../orgs/members.service.js";
25
26
  import { OrgNetworkAllowances } from "../../orgs/network-allowances.service.js";
26
- import { InvitationCreateBody, InvitationIdParams, MemberParams, MemberRoleBody, networkAllowanceView, OrgUpdateBody, } from "../../orgs/orgs.schemas.js";
27
+ import { InvitationCreateBody, InvitationIdParams, InvitationListQuery, MemberListQuery, MemberParams, MemberRoleBody, networkAllowanceView, OrgUpdateBody, } from "../../orgs/orgs.schemas.js";
27
28
  import { OrgsService } from "../../orgs/orgs.service.js";
28
29
  import { roleAtLeast } from "../../orgs/roles.js";
29
30
  import { defineOperation } from "../operation.js";
30
31
  import { PlatformOperations } from "../registry.js";
31
32
  import { SEALED_REVEAL_TTL_MS, SealedReveals } from "../sealed-reveals.js";
32
33
  import { precheckBy, viaAgent } from "./errors.js";
33
- import { Cursor, pageOf, startOf } from "./paging.js";
34
34
  import { roleOf } from "./role.js";
35
35
  import { named, orElse } from "./summary.js";
36
- const PAGE = 50;
37
36
  const OrgId = z.string().min(1).max(100).describe("The org id (orgs.list).");
38
37
  /** The value types of the per-org override records of `PUT /api/v1/admin/settings`. */
39
38
  const OVERRIDES = DEPLOYMENT_SETTINGS_PATCH.shape;
@@ -189,26 +188,33 @@ let OrgsOperations = class OrgsOperations {
189
188
  this.registry.register([
190
189
  defineOperation({
191
190
  id: "orgs.list",
192
- description: "List every org on the platform (super admin), one compact row each: id, name, slug, member count and whether it has limits of its own. Also returns the deployment's default limits. Pages by 50: pass the returned next as params.cursor. Details and limits of one org come from orgs.get.",
193
- input: z.object({ cursor: Cursor.optional() }).strict(),
194
- example: {},
191
+ description: "List the orgs on the platform (super admin), one compact row each: id, name, slug, member count and whether it has limits of its own; newest first. q keeps the orgs whose name or slug contains it. Also returns the deployment's default limits. Paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, page, size and total (capped at 10000, totalCapped true above). Details and limits of one org come from orgs.get.",
192
+ input: AdminOrgListQuery.strict(),
193
+ example: { page: 1, size: 50 },
195
194
  authz: { superAdmin: true },
196
195
  mirrors: ["GET /api/v1/admin/orgs"],
197
- extras: ["cursor"],
198
196
  confirm: "read",
199
197
  run: async (input) => {
200
- const [orgs, s] = await Promise.all([this.orgs.listAll(), this.settings.get()]);
198
+ const [page, s] = await Promise.all([
199
+ this.orgs.page({
200
+ page: input.page,
201
+ size: input.size,
202
+ ...(input.q !== undefined && { q: input.q }),
203
+ }),
204
+ this.settings.get(),
205
+ ]);
201
206
  const own = (id) => id in s.runConcurrencyOverrides ||
202
207
  id in s.sandboxLimitOverrides ||
203
208
  id in s.subagentLimitOverrides;
204
209
  return {
205
- ...pageOf(orgs.map((o) => ({
210
+ ...page,
211
+ items: page.items.map((o) => ({
206
212
  id: o.id,
207
213
  name: o.name,
208
214
  slug: o.slug,
209
215
  memberCount: o.memberCount,
210
216
  ownLimits: own(o.id),
211
- })), startOf(input.cursor), PAGE),
217
+ })),
212
218
  limitDefaults: limitDefaults(this.config),
213
219
  };
214
220
  },
@@ -493,32 +499,43 @@ let OrgsOperations = class OrgsOperations {
493
499
  }),
494
500
  defineOperation({
495
501
  id: "orgs.members",
496
- description: "List the members of this conversation's org, one compact row each: account id, display name, role, email and when they joined. Org admins change roles with orgs.set-member-role and remove members with orgs.remove-member. Pages by 50: pass the returned next as params.cursor.",
497
- input: z.object({ cursor: Cursor.optional() }).strict(),
498
- example: {},
502
+ description: "List the members of this conversation's org, one compact row each: account id, display name, role, email and when they joined, by join time. q keeps the members whose display name or email contains it. Org admins change roles with orgs.set-member-role and remove members with orgs.remove-member. Paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, page, size and total (capped at 10000, totalCapped true above).",
503
+ input: MemberListQuery.strict(),
504
+ example: { page: 1, size: 50 },
499
505
  authz: { orgAction: "org.members.read" },
500
506
  mirrors: ["GET /api/v1/orgs/:orgId/members"],
501
- extras: ["cursor"],
502
507
  confirm: "read",
503
- run: async (input, ctx) => pageOf((await this.members.list(ctx.orgId)).map((m) => ({
504
- id: m.account.id,
505
- name: m.account.displayName,
506
- state: m.role,
507
- email: m.account.email,
508
- joinedAt: m.joinedAt,
509
- ...(m.anonymous && { anonymous: true }),
510
- })), startOf(input.cursor), PAGE),
508
+ run: async (input, ctx) => {
509
+ const page = await this.members.page(ctx.orgId, {
510
+ page: input.page,
511
+ size: input.size,
512
+ ...(input.q !== undefined && { q: input.q }),
513
+ });
514
+ return {
515
+ ...page,
516
+ items: page.items.map((m) => ({
517
+ id: m.account.id,
518
+ name: m.account.displayName,
519
+ state: m.role,
520
+ email: m.account.email,
521
+ joinedAt: m.joinedAt,
522
+ ...(m.anonymous && { anonymous: true }),
523
+ })),
524
+ };
525
+ },
511
526
  }),
512
527
  defineOperation({
513
528
  id: "orgs.invitations",
514
- description: "List the invitations of this conversation's org (org admins), oldest first: id, role, status (pending, accepted, expired or revoked), who created it and when, when it expires. Never the link: an invitation's link is shown only once, to the person who approved its creation.",
515
- input: z.object({ cursor: Cursor.optional() }).strict(),
516
- example: {},
529
+ description: "List the invitations of this conversation's org (org admins), every one ever made, newest first: id, role, status (pending, accepted, expired or revoked), who created it and when, when it expires. Never the link: an invitation's link is shown only once, to the person who approved its creation. Paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, page, size and total (capped at 10000, totalCapped true above).",
530
+ input: InvitationListQuery.strict(),
531
+ example: { page: 1, size: 20 },
517
532
  authz: { orgAction: "org.invitations.manage" },
518
533
  mirrors: ["GET /api/v1/orgs/:orgId/invitations"],
519
- extras: ["cursor"],
520
534
  confirm: "read",
521
- run: async (input, ctx) => pageOf((await this.invitations.list(ctx.orgId)).map(invitationView), startOf(input.cursor), PAGE),
535
+ run: async (input, ctx) => {
536
+ const page = await this.invitations.page(ctx.orgId, input);
537
+ return { ...page, items: page.items.map(invitationView) };
538
+ },
522
539
  }),
523
540
  defineOperation({
524
541
  id: "orgs.invite",
@@ -35,6 +35,8 @@ import { EvalWorkersModule } from "../evals/evals.module.js";
35
35
  import { ExtensionsModule } from "../extensions/extensions.module.js";
36
36
  import { PluginsReconcileJob } from "../extensions/lifecycle.js";
37
37
  import { LifecycleHookWorkersModule } from "../extensions/lifecycle-hooks.js";
38
+ import { PackageDigestBackfillJob } from "../extensions/package-digest.job.js";
39
+ import { PublisherProofRecheckJob } from "../extensions/publisher-proof.job.js";
38
40
  import { BlobSweepModule } from "../files/blob-sweep.job.js";
39
41
  import { FileDraftCleanupJob } from "../files/draft-cleanup.job.js";
40
42
  import { FileLibraryKickoffJob } from "../files/hash-job.js";
@@ -165,6 +167,10 @@ let WorkerModule = WorkerModule_1 = class WorkerModule {
165
167
  AccountAvatarCleanupJob,
166
168
  ClientReportsCron,
167
169
  CatalogJobs,
170
+ // sha512 of packages stored before migration 0235 (extension permission model plan 1.2b)
171
+ PackageDigestBackfillJob,
172
+ // publisher proofs of official revisions imported before they were recorded (rc.165)
173
+ PublisherProofRecheckJob,
168
174
  DirectoryScanJob,
169
175
  PluginsReconcileJob,
170
176
  GatewayCheckJob,
@@ -50,7 +50,7 @@ export declare class StepLog {
50
50
  written: ConversationEvent[];
51
51
  toSeq: number | null;
52
52
  }>;
53
- /** Appends events with their audit row (a hook denial). */
53
+ /** Appends events with an audit row for a newly recorded denial. */
54
54
  appendAudited(conversationId: string, events: AppendEvent[], entry: StepAuditEntry): Promise<ConversationEvent[]>;
55
55
  /**
56
56
  * Appends a `model_call` with the tool definitions its request sent, stored by fingerprint in
@@ -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.145",
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();