@capybara-hq/kernel 0.1.0-rc.146 → 0.1.0-rc.147

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 (168) hide show
  1. package/dist/admin/extensions.controller.d.ts +0 -11
  2. package/dist/admin/extensions.controller.js +0 -28
  3. package/dist/admin/health.service.d.ts +25 -1
  4. package/dist/admin/health.service.js +50 -18
  5. package/dist/audit/full-access.d.ts +78 -0
  6. package/dist/audit/full-access.js +283 -0
  7. package/dist/automations/automations.service.d.ts +1 -0
  8. package/dist/automations/automations.service.js +3 -1
  9. package/dist/automations/calendar.js +3 -1
  10. package/dist/automations/grant-rules.d.ts +2 -1
  11. package/dist/automations/grant-rules.js +8 -1
  12. package/dist/automations/unattended.d.ts +13 -1
  13. package/dist/automations/unattended.js +13 -1
  14. package/dist/catalog/admin-catalog.controller.d.ts +8 -0
  15. package/dist/catalog/admin-catalog.controller.js +8 -2
  16. package/dist/catalog/admin-catalog.schemas.d.ts +10 -0
  17. package/dist/catalog/admin-catalog.schemas.js +8 -1
  18. package/dist/catalog/catalog-content.d.ts +6 -0
  19. package/dist/catalog/catalog-scope.service.d.ts +22 -2
  20. package/dist/catalog/catalog-scope.service.js +27 -3
  21. package/dist/catalog/catalog.service.js +19 -2
  22. package/dist/catalog/marketplaces.service.d.ts +1 -1
  23. package/dist/catalog/org-catalog.service.d.ts +8 -1
  24. package/dist/catalog/org-catalog.service.js +36 -3
  25. package/dist/catalog/platform-components.js +3 -2
  26. package/dist/catalog/platform-import-update.d.ts +2 -0
  27. package/dist/catalog/platform-import-update.js +8 -1
  28. package/dist/catalog/plugin-connectors.d.ts +11 -0
  29. package/dist/catalog/plugin-connectors.js +33 -0
  30. package/dist/catalog/plugin-import.d.ts +35 -15
  31. package/dist/catalog/plugin-import.js +110 -35
  32. package/dist/catalog/plugin-install.js +6 -0
  33. package/dist/catalog/provenance.d.ts +2 -0
  34. package/dist/catalog/provenance.js +5 -1
  35. package/dist/config/auto-approve.d.ts +16 -0
  36. package/dist/config/auto-approve.js +24 -0
  37. package/dist/config/capacity-presets.d.ts +243 -0
  38. package/dist/config/capacity-presets.js +195 -0
  39. package/dist/config/env.d.ts +2 -1
  40. package/dist/config/env.js +6 -1
  41. package/dist/config/load.js +15 -0
  42. package/dist/config/schema.d.ts +46 -9
  43. package/dist/config/schema.js +154 -30
  44. package/dist/ctx/net.d.ts +5 -1
  45. package/dist/ctx/net.js +62 -12
  46. package/dist/db/kernel-schema.d.ts +31 -0
  47. package/dist/db/migrator.js +0 -36
  48. package/dist/dial-in/routes.js +1 -1
  49. package/dist/erasure/org-batches.js +1 -6
  50. package/dist/erasure/org-catalog.js +6 -2
  51. package/dist/erasure/org-rules.js +1 -0
  52. package/dist/erasure/org-worker.js +0 -13
  53. package/dist/errors.d.ts +6 -0
  54. package/dist/errors.js +6 -0
  55. package/dist/extensions/admin-ops.d.ts +14 -1
  56. package/dist/extensions/admin-ops.js +30 -3
  57. package/dist/extensions/admin-view.d.ts +21 -1
  58. package/dist/extensions/admin-view.js +43 -0
  59. package/dist/extensions/bootstrap-packages.d.ts +5 -0
  60. package/dist/extensions/bootstrap-packages.js +1 -1
  61. package/dist/extensions/bootstrap-review.d.ts +251 -0
  62. package/dist/extensions/bootstrap-review.js +676 -0
  63. package/dist/extensions/bootstrap.d.ts +21 -1
  64. package/dist/extensions/bootstrap.js +72 -2
  65. package/dist/extensions/cli.d.ts +6 -0
  66. package/dist/extensions/cli.js +4 -0
  67. package/dist/extensions/enabled.d.ts +3 -0
  68. package/dist/extensions/extensions.module.js +9 -0
  69. package/dist/extensions/full-access-disclosure.d.ts +15 -0
  70. package/dist/extensions/full-access-disclosure.js +57 -0
  71. package/dist/extensions/grant-epoch.d.ts +5 -0
  72. package/dist/extensions/grant-epoch.js +9 -0
  73. package/dist/extensions/host.d.ts +71 -2
  74. package/dist/extensions/host.js +293 -27
  75. package/dist/extensions/installs.d.ts +18 -0
  76. package/dist/extensions/installs.js +28 -0
  77. package/dist/extensions/isolated/admission.d.ts +17 -2
  78. package/dist/extensions/isolated/admission.js +15 -7
  79. package/dist/extensions/isolated/authorization.d.ts +8 -2
  80. package/dist/extensions/isolated/authorization.js +11 -3
  81. package/dist/extensions/isolated/broker.d.ts +3 -0
  82. package/dist/extensions/isolated/broker.js +50 -14
  83. package/dist/extensions/isolated/configured-package.d.ts +5 -0
  84. package/dist/extensions/isolated/configured-package.js +2 -0
  85. package/dist/extensions/isolated/lanes.d.ts +44 -3
  86. package/dist/extensions/isolated/lanes.js +263 -80
  87. package/dist/extensions/isolated/metrics.d.ts +146 -0
  88. package/dist/extensions/isolated/metrics.js +304 -0
  89. package/dist/extensions/isolated/revision.d.ts +7 -1
  90. package/dist/extensions/isolated/revision.js +26 -5
  91. package/dist/extensions/isolated/rpc.d.ts +5 -0
  92. package/dist/extensions/isolated/rpc.js +7 -2
  93. package/dist/extensions/isolated/sandbox.d.ts +23 -0
  94. package/dist/extensions/isolated/sandbox.js +50 -0
  95. package/dist/extensions/isolated/status.d.ts +79 -0
  96. package/dist/extensions/isolated/status.js +216 -0
  97. package/dist/extensions/isolated/tier.d.ts +127 -2
  98. package/dist/extensions/isolated/tier.js +266 -7
  99. package/dist/extensions/isolated/usage.d.ts +134 -0
  100. package/dist/extensions/isolated/usage.js +322 -0
  101. package/dist/extensions/lifecycle.d.ts +42 -2
  102. package/dist/extensions/lifecycle.js +100 -4
  103. package/dist/extensions/org-config.js +11 -0
  104. package/dist/extensions/package.d.ts +14 -0
  105. package/dist/extensions/package.js +23 -0
  106. package/dist/extensions/permissions.controller.d.ts +35 -0
  107. package/dist/extensions/permissions.controller.js +98 -0
  108. package/dist/extensions/permissions.schemas.d.ts +288 -0
  109. package/dist/extensions/permissions.schemas.js +96 -0
  110. package/dist/extensions/permissions.service.d.ts +116 -0
  111. package/dist/extensions/permissions.service.js +428 -0
  112. package/dist/extensions/realm-retirement.d.ts +65 -0
  113. package/dist/extensions/realm-retirement.js +150 -0
  114. package/dist/extensions/revision-approvals.d.ts +58 -3
  115. package/dist/extensions/revision-approvals.js +135 -14
  116. package/dist/extensions/revision-review.d.ts +144 -0
  117. package/dist/extensions/revision-review.js +297 -0
  118. package/dist/extensions/revocation.js +3 -0
  119. package/dist/extensions/state.module.js +12 -0
  120. package/dist/git/run-end.d.ts +35 -7
  121. package/dist/git/run-end.js +87 -38
  122. package/dist/http/api.module.js +2 -0
  123. package/dist/identity/audit.d.ts +2 -1
  124. package/dist/identity/audit.js +4 -17
  125. package/dist/index.d.ts +4 -0
  126. package/dist/index.js +4 -0
  127. package/dist/infra/config/kernel-config.service.d.ts +6 -0
  128. package/dist/infra/config/kernel-config.service.js +21 -0
  129. package/dist/infra/outbox/registry.d.ts +13 -0
  130. package/dist/infra/outbox/registry.js +8 -0
  131. package/dist/lifecycle/kernel-lifecycle.d.ts +25 -1
  132. package/dist/lifecycle/kernel-lifecycle.js +73 -18
  133. package/dist/net/private-endpoint-preflight.d.ts +159 -0
  134. package/dist/net/private-endpoint-preflight.js +417 -0
  135. package/dist/net/private-endpoints.d.ts +68 -0
  136. package/dist/net/private-endpoints.js +164 -0
  137. package/dist/net/public-address.d.ts +14 -0
  138. package/dist/net/public-address.js +15 -1
  139. package/dist/net/safe-fetch.d.ts +2 -1
  140. package/dist/net/safe-fetch.js +10 -3
  141. package/dist/overrides.d.ts +4 -0
  142. package/dist/overrides.js +2 -0
  143. package/dist/packages/official-publisher.d.ts +26 -1
  144. package/dist/packages/official-publisher.js +48 -1
  145. package/dist/packages/provenance.d.ts +11 -0
  146. package/dist/packages/provenance.js +24 -0
  147. package/dist/platform/exclusions.js +4 -4
  148. package/dist/platform/ops/automations.ops.js +1 -1
  149. package/dist/platform/ops/catalog-admin.ops.js +25 -4
  150. package/dist/platform/ops/extension-permissions.ops.d.ts +11 -0
  151. package/dist/platform/ops/extension-permissions.ops.js +159 -0
  152. package/dist/platform/platform-ops.module.d.ts +2 -1
  153. package/dist/platform/platform-ops.module.js +2 -0
  154. package/dist/platform/route-schemas.js +2 -0
  155. package/dist/retention/purge-batch.js +10 -14
  156. package/dist/runtime/maintenance.d.ts +4 -2
  157. package/dist/runtime/maintenance.js +16 -3
  158. package/dist/runtime/run-finish.d.ts +3 -3
  159. package/dist/runtime/run-finish.js +7 -3
  160. package/dist/sandbox/permission-availability.d.ts +17 -2
  161. package/dist/sandbox/permission-availability.js +22 -1
  162. package/dist/sandbox/permission-facts.js +7 -1
  163. package/dist/tools/builtins/sandbox/common.js +2 -0
  164. package/dist/tools/pipeline.d.ts +2 -1
  165. package/dist/tools/pipeline.js +7 -2
  166. package/package.json +4 -3
  167. package/src/migrations/0238_extension_usage.sql +40 -0
  168. package/src/migrations/0239_extension_replica_isolation.sql +28 -0
@@ -8,6 +8,7 @@ import { HostServiceAccess } from "../device-access/host-services.js";
8
8
  import { ErasureWorker } from "../erasure/worker.js";
9
9
  import { BlobObjects } from "../files/blob-objects.js";
10
10
  import { FileLibraryHashJob } from "../files/hash-job.js";
11
+ import { GitRunEnd } from "../git/run-end.js";
11
12
  import { KernelDb } from "../infra/database/kernel-db.js";
12
13
  import { ScheduledRuns } from "../infra/schedule/scheduled-runs.js";
13
14
  import type { KernelLogger } from "../log.js";
@@ -38,7 +39,7 @@ export declare const MAINTENANCE_CONCURRENCY = 5;
38
39
  * `platform-icon-delete` →
39
40
  * {@link PlatformIconObjects}, `device-conversation-notice` → {@link ConversationNoticeDelivery},
40
41
  * `idle-compaction` → {@link IdleCompactionJob}, `device-loopback-refresh` → {@link LoopbackGrants}, `device-host-services-stop` →
41
- * {@link HostServiceAccess}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
42
+ * {@link HostServiceAccess}, `git-fetch-audit` → {@link GitRunEnd}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
42
43
  * such as `sandbox-suspend-idle`) runs that job's body once ({@link ScheduledRuns.runNow}), as the
43
44
  * maintenance handlers did when those jobs were schedulers on this queue: an operator's or a
44
45
  * test's one-off run, not a second schedule (decision R23 of the Nest kernel spec). Any other
@@ -69,7 +70,8 @@ export declare class MaintenanceProcessor extends WorkerHost<Worker> {
69
70
  private readonly hostServices;
70
71
  private readonly retention;
71
72
  private readonly erasure;
72
- constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem" | "revokeDeadHolder">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, automations: Pick<AutomationFirer, "fire" | "settle">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke" | "settleResumeProof">, blobObjects: Pick<BlobObjects, "deleteBlob" | "deleteStaging" | "releaseFile">, hashing: Pick<FileLibraryHashJob, "dispatch" | "runOrgBatch">, platformIcons: Pick<PlatformIconObjects, "deleteObject">, notices: Pick<ConversationNoticeDelivery, "attempt">, triggers: Pick<TriggerDispatcher, "dispatch">, coalescer: Pick<EventCoalescer, "flush">, idleCompaction: Pick<IdleCompactionJob, "fire">, db: KernelDb, loopback: Pick<LoopbackGrants, "refresh">, hostServices: Pick<HostServiceAccess, "deliverOwedStops">, retention: Pick<RetentionWorker, "run">, erasure: Pick<ErasureWorker, "run">);
73
+ private readonly gitRunEnd;
74
+ constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem" | "revokeDeadHolder">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, automations: Pick<AutomationFirer, "fire" | "settle">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke" | "settleResumeProof">, blobObjects: Pick<BlobObjects, "deleteBlob" | "deleteStaging" | "releaseFile">, hashing: Pick<FileLibraryHashJob, "dispatch" | "runOrgBatch">, platformIcons: Pick<PlatformIconObjects, "deleteObject">, notices: Pick<ConversationNoticeDelivery, "attempt">, triggers: Pick<TriggerDispatcher, "dispatch">, coalescer: Pick<EventCoalescer, "flush">, idleCompaction: Pick<IdleCompactionJob, "fire">, db: KernelDb, loopback: Pick<LoopbackGrants, "refresh">, hostServices: Pick<HostServiceAccess, "deliverOwedStops">, retention: Pick<RetentionWorker, "run">, erasure: Pick<ErasureWorker, "run">, gitRunEnd: Pick<GitRunEnd, "writeFetchSummaries">);
73
75
  process(job: Job, token?: string): Promise<void>;
74
76
  /** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
75
77
  start(): void;
@@ -27,6 +27,8 @@ import { ErasureWorker, ErasureWorkerModule } from "../erasure/worker.js";
27
27
  import { BLOB_DELETE_JOB, BlobObjects, BlobObjectsModule, FILE_RELEASE_JOB, FILE_STAGING_DELETE_JOB, } from "../files/blob-objects.js";
28
28
  import { FILE_LIBRARY_HASH_JOB, FILE_LIBRARY_HASH_ORG_JOB, FileLibraryHashJob, } from "../files/hash-job.js";
29
29
  import { FileLibraryJobsModule } from "../files/library-jobs.module.js";
30
+ import { GitModule } from "../git/git.module.js";
31
+ import { GIT_FETCH_AUDIT_JOB, GitRunEnd } from "../git/run-end.js";
30
32
  import { KernelDb } from "../infra/database/kernel-db.js";
31
33
  import { asPlatform, withOrgScope } from "../infra/database/org-scope.js";
32
34
  import { configuredProcessor } from "../infra/queue/configured-processor.js";
@@ -75,7 +77,7 @@ export const MAINTENANCE_CONCURRENCY = 5;
75
77
  * `platform-icon-delete` →
76
78
  * {@link PlatformIconObjects}, `device-conversation-notice` → {@link ConversationNoticeDelivery},
77
79
  * `idle-compaction` → {@link IdleCompactionJob}, `device-loopback-refresh` → {@link LoopbackGrants}, `device-host-services-stop` →
78
- * {@link HostServiceAccess}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
80
+ * {@link HostServiceAccess}, `git-fetch-audit` → {@link GitRunEnd}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
79
81
  * such as `sandbox-suspend-idle`) runs that job's body once ({@link ScheduledRuns.runNow}), as the
80
82
  * maintenance handlers did when those jobs were schedulers on this queue: an operator's or a
81
83
  * test's one-off run, not a second schedule (decision R23 of the Nest kernel spec). Any other
@@ -106,7 +108,8 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
106
108
  hostServices;
107
109
  retention;
108
110
  erasure;
109
- constructor(permissionApprovals, waits, sandbox, drift, directory, deletion, offboarding, runs, automations, scheduled, log, operations, blobObjects, hashing, platformIcons, notices, triggers, coalescer, idleCompaction, db, loopback, hostServices, retention, erasure) {
111
+ gitRunEnd;
112
+ constructor(permissionApprovals, waits, sandbox, drift, directory, deletion, offboarding, runs, automations, scheduled, log, operations, blobObjects, hashing, platformIcons, notices, triggers, coalescer, idleCompaction, db, loopback, hostServices, retention, erasure, gitRunEnd) {
110
113
  super();
111
114
  this.permissionApprovals = permissionApprovals;
112
115
  this.waits = waits;
@@ -132,6 +135,7 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
132
135
  this.hostServices = hostServices;
133
136
  this.retention = retention;
134
137
  this.erasure = erasure;
138
+ this.gitRunEnd = gitRunEnd;
135
139
  }
136
140
  process(job, token) {
137
141
  return runJob(MAINTENANCE_QUEUE_NAME, job, () => this.dispatch(job, token), {
@@ -322,6 +326,12 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
322
326
  await this.inOwnerScope(job, resolveRunOrg(this.db.db, data.runId, data.conversationId), (orgId) => this.idleCompaction.fire({ ...data, orgId }));
323
327
  return;
324
328
  }
329
+ // a finished run's `git.fetch` summaries, owed by its terminal transaction (git spec §9)
330
+ case GIT_FETCH_AUDIT_JOB: {
331
+ const { runId } = job.data;
332
+ await this.inOwnerScope(job, resolveRunOrg(this.db.db, runId), () => this.gitRunEnd.writeFetchSummaries(runId));
333
+ return;
334
+ }
325
335
  default:
326
336
  if (await this.scheduled.runNow(job.name))
327
337
  return;
@@ -369,7 +379,8 @@ MaintenanceProcessor = __decorate([
369
379
  __param(20, Inject(LoopbackGrants)),
370
380
  __param(21, Inject(HostServiceAccess)),
371
381
  __param(22, Inject(RetentionWorker)),
372
- __param(23, Inject(ErasureWorker))
382
+ __param(23, Inject(ErasureWorker)),
383
+ __param(24, Inject(GitRunEnd))
373
384
  ], MaintenanceProcessor);
374
385
  export { MaintenanceProcessor };
375
386
  /**
@@ -408,6 +419,8 @@ MaintenanceModule = __decorate([
408
419
  ConversationNoticesModule,
409
420
  // a switched-off extension's host services stop
410
421
  ExtensionDeviceAccessModule,
422
+ // a finished run's git fetch summaries
423
+ GitModule,
411
424
  QueueModule.registerQueue(MAINTENANCE_QUEUE_NAME),
412
425
  ],
413
426
  providers: [
@@ -54,7 +54,7 @@ export declare class RunFinish {
54
54
  readonly txHost: TransactionHost;
55
55
  /** An automation's run follows its kernel run's end in the same transaction (spec §6). */
56
56
  private readonly taskRuns;
57
- /** The run's git tickets are revoked and its fetch summaries written after the commit. */
57
+ /** The run's git tickets are revoked after the commit (its fetch summaries are owed). */
58
58
  private readonly gitRunEnd;
59
59
  /** The run's end owes the conversation's ensure-run backstop (transactional outbox spec §6). */
60
60
  private readonly outbox;
@@ -65,8 +65,8 @@ export declare class RunFinish {
65
65
  constructor(kdb: KernelDb, eventLog: EventLog, txHost: TransactionHost,
66
66
  /** An automation's run follows its kernel run's end in the same transaction (spec §6). */
67
67
  taskRuns: Pick<AutomationRunTracker, "onRunFinished">,
68
- /** The run's git tickets are revoked and its fetch summaries written after the commit. */
69
- gitRunEnd: Pick<GitRunEnd, "onRunFinished">,
68
+ /** The run's git tickets are revoked after the commit (its fetch summaries are owed). */
69
+ gitRunEnd: Pick<GitRunEnd, "revokeTickets" | "hasFetches">,
70
70
  /** The run's end owes the conversation's ensure-run backstop (transactional outbox spec §6). */
71
71
  outbox: Pick<OutboxService, "add">,
72
72
  /** A finished run's pending approvals are cancelled in its terminal transaction. */
@@ -14,7 +14,7 @@ import { agentIdOf } from "../conversations/conversation-agent.js";
14
14
  import { EventLog } from "../conversations/event-log.js";
15
15
  import { pauseQueueIn } from "../conversations/queue.js";
16
16
  import { oweRunLifecycleFor } from "../extensions/run-lifecycle-owe.js";
17
- import { GitRunEnd } from "../git/run-end.js";
17
+ import { GitRunEnd, oweGitFetchAudit } from "../git/run-end.js";
18
18
  import { afterCommit } from "../infra/database/after-commit.js";
19
19
  import { KernelDb } from "../infra/database/kernel-db.js";
20
20
  import { TransactionHost } from "../infra/database/transaction-host.js";
@@ -44,7 +44,7 @@ let RunFinish = class RunFinish {
44
44
  constructor(kdb, eventLog, txHost,
45
45
  /** An automation's run follows its kernel run's end in the same transaction (spec §6). */
46
46
  taskRuns,
47
- /** The run's git tickets are revoked and its fetch summaries written after the commit. */
47
+ /** The run's git tickets are revoked after the commit (its fetch summaries are owed). */
48
48
  gitRunEnd,
49
49
  /** The run's end owes the conversation's ensure-run backstop (transactional outbox spec §6). */
50
50
  outbox,
@@ -166,7 +166,11 @@ let RunFinish = class RunFinish {
166
166
  }
167
167
  // the terminal status is committed first, then the tickets go (the one place runs end)
168
168
  afterCommit(() => recordRun(a.status));
169
- afterCommit(() => this.gitRunEnd.onRunFinished(a.runId));
169
+ afterCommit(() => this.gitRunEnd.revokeTickets(a.runId));
170
+ // the run's `git.fetch` summaries are audit: owed here, so a crash after the commit keeps them
171
+ if (conv && (await this.gitRunEnd.hasFetches(a.runId))) {
172
+ await oweGitFetchAudit(this.outbox, a.runId, conv.org_id);
173
+ }
170
174
  // a failed or stopped run pauses the queued messages until the person resumes (spec §5.7);
171
175
  // an idle compact run never does (idle compaction spec §5.2, S3): preempted by input, that
172
176
  // input (a queued message among them) goes out next; failed or stopped, its end is not in the
@@ -1,13 +1,17 @@
1
- import { type DeviceProvider, type SandboxPermissionSupport, SandboxPermissionUnsupportedError } from "@capybara-hq/plugin-sdk";
1
+ import { type DeviceProjectReach, type DeviceProvider, type SandboxPermissionSupport, SandboxPermissionUnsupportedError } from "@capybara-hq/plugin-sdk";
2
2
  /**
3
3
  * Why a device cannot run permission-scoped work, for people and for the kernel-rendered admission
4
- * text (ruling R9): an outdated sandbox provider plugin, or a runtime that cannot enforce the
4
+ * text (ruling R9): an outdated sandbox provider plugin, a device program too old to enforce the
5
+ * platform or org project reach ceiling (`device-update`), or a runtime that cannot enforce the
5
6
  * sandbox. The recorded `permission_context` keeps only `{ state, reason }`.
6
7
  */
7
8
  export type PermissionAvailabilityCause = {
8
9
  kind: "provider-outdated";
9
10
  plugin: string;
10
11
  version: string;
12
+ } | {
13
+ kind: "device-update";
14
+ projectReach: DeviceProjectReach;
11
15
  } | {
12
16
  kind: "runtime";
13
17
  };
@@ -61,3 +65,14 @@ export declare function runtimeReportVerdict(report: SandboxPermissionSupport):
61
65
  * the kernel read route).
62
66
  */
63
67
  export declare function deviceWorkAvailability(availability: PermissionAvailability): PermissionAvailability;
68
+ /** The reason a device program too old for the project reach ceiling reads (issue #1240). */
69
+ export declare const DEVICE_UPDATE_REASON = "This device's program cannot enforce the project reach limit; update the device program on its computer and reconnect it";
70
+ /**
71
+ * Device work under the platform or org project reach `ceiling` on a device whose connected
72
+ * program cannot enforce it ({@link projectReachNeedsUpdate}), read from the connection facts the
73
+ * provider recorded with its support: unsupported with the `device-update` cause, so people see
74
+ * the upgrade before admission refuses. Null when the support names no facts (an earlier
75
+ * provider: its own admission still refuses), the ceiling is the default `machine`, or the program
76
+ * or the owner's own reach already keeps work within it.
77
+ */
78
+ export declare function projectReachAvailability(support: SandboxPermissionSupport, ceiling: DeviceProjectReach | undefined): PermissionAvailability | null;
@@ -1,4 +1,4 @@
1
- import { instanceSupported, SandboxPermissionUnsupportedError, } from "@capybara-hq/plugin-sdk";
1
+ import { instanceSupported, projectReachNeedsUpdate, SandboxPermissionUnsupportedError, } from "@capybara-hq/plugin-sdk";
2
2
  /**
3
3
  * Admission's refusal of device work on a device that cannot run permission-scoped operations:
4
4
  * nothing was sent. It extends {@link SandboxPermissionUnsupportedError} (and keeps its name), so
@@ -69,3 +69,24 @@ export function deviceWorkAvailability(availability) {
69
69
  ? availability
70
70
  : { state: "unsupported", reason, cause: { kind: "runtime" } };
71
71
  }
72
+ /** The reason a device program too old for the project reach ceiling reads (issue #1240). */
73
+ export const DEVICE_UPDATE_REASON = "This device's program cannot enforce the project reach limit; update the device program on its computer and reconnect it";
74
+ /**
75
+ * Device work under the platform or org project reach `ceiling` on a device whose connected
76
+ * program cannot enforce it ({@link projectReachNeedsUpdate}), read from the connection facts the
77
+ * provider recorded with its support: unsupported with the `device-update` cause, so people see
78
+ * the upgrade before admission refuses. Null when the support names no facts (an earlier
79
+ * provider: its own admission still refuses), the ceiling is the default `machine`, or the program
80
+ * or the owner's own reach already keeps work within it.
81
+ */
82
+ export function projectReachAvailability(support, ceiling) {
83
+ if (ceiling === undefined || support.projectReach === undefined)
84
+ return null;
85
+ if (!projectReachNeedsUpdate(support.projectReach, ceiling))
86
+ return null;
87
+ return {
88
+ state: "unsupported",
89
+ reason: DEVICE_UPDATE_REASON,
90
+ cause: { kind: "device-update", projectReach: ceiling },
91
+ };
92
+ }
@@ -25,7 +25,7 @@ import { canonicalHostCeiling, deviceListAddRefusal, effectiveDeviceSandbox, hos
25
25
  import { DEFAULT_ALLOWED_PROFILES, effectiveAllowedProfiles, readDeviceSandboxSettings, } from "./device-sandbox-settings.js";
26
26
  import { appliedOf, appliedWider, coversHost, effectiveDevicePolicy, readDeploymentDevicePolicy, readInstanceLimits, } from "./modes.js";
27
27
  import { assertAuthorityHeld } from "./permission-authority-lock.js";
28
- import { deviceWorkAvailability, permissionAvailabilityFor, } from "./permission-availability.js";
28
+ import { deviceWorkAvailability, permissionAvailabilityFor, projectReachAvailability, } from "./permission-availability.js";
29
29
  import { reachNarrowed } from "./permission-ceiling-writes.js";
30
30
  import { readCurrentReport } from "./permission-runtime-reports.js";
31
31
  import { DeviceProviders, servesDialIn } from "./providers.js";
@@ -465,6 +465,12 @@ let PermissionFacts = class PermissionFacts {
465
465
  async scope(orgId, deviceId, projectPath, project) {
466
466
  const { sandbox } = await this.readDevice(orgId, deviceId);
467
467
  let availability = await this.availability(orgId, deviceId);
468
+ if (sandbox.projectReach !== undefined && availability.state === "supported") {
469
+ // the current connection's program cannot enforce the ceiling (issue #1240)
470
+ const update = projectReachAvailability(availability.report, sandbox.projectReach);
471
+ if (update)
472
+ availability = update;
473
+ }
468
474
  if (sandbox.projectReach !== undefined && availability.state === "supported") {
469
475
  try {
470
476
  await this.projectReachAuthority(orgId, deviceId, sandbox.projectReach);
@@ -294,6 +294,8 @@ export { PermissionAdmissionUnavailable };
294
294
  export function admissionUnavailableText(cause) {
295
295
  if (cause.kind === "provider-outdated")
296
296
  return `This device's sandbox plugin (${cause.plugin} ${cause.version}) cannot run device tools under a permission profile, so nothing ran. A super admin updates the plugin on the Plugins page; until then, continue without the device, or ask the user to start a new conversation on another device.`;
297
+ if (cause.kind === "device-update")
298
+ return `This device's program is too old to keep work within the platform or organization's project reach limit (${cause.projectReach}), so nothing ran. Ask the device's owner to update the device program (capybara-device) on that computer and reconnect it; until then, continue without the device.`;
297
299
  return "This device's runtime cannot enforce its sandbox, so nothing ran. Ask the device's owner to update its device program (or a super admin to update its device plugin), or continue without the device.";
298
300
  }
299
301
  /**
@@ -69,7 +69,8 @@ export type ReviewKind = "command" | "write" | "read";
69
69
  export declare const commandDeniedText: (reason: string, kind: ReviewKind) => string;
70
70
  /**
71
71
  * A command (or write, or read) the review held in an unattended run: no one can answer, so it is a
72
- * deny at once — no approval, no grant (P-D3).
72
+ * deny at once — no approval, no grant (P-D3); the task run records the held class
73
+ * (`reviewHoldKey`).
73
74
  */
74
75
  export declare const commandUnattendedText: (reason: string, kind: ReviewKind) => string;
75
76
  /**
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { CARD_BADGE_MAX, CARD_TEXT_MAX, DeviceAccessError, ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable, Optional } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
- import { appendMissingGrant, connectionGrantKey, UNATTENDED_CONNECTION_ERROR, UNATTENDED_ELICITATION_NOTE, UNATTENDED_QUESTION_ERROR, unattendedFails, unattendedRules, unattendedRunOf, } from "../automations/unattended.js";
13
+ import { appendMissingGrant, connectionGrantKey, reviewHoldKey, UNATTENDED_CONNECTION_ERROR, UNATTENDED_ELICITATION_NOTE, UNATTENDED_QUESTION_ERROR, unattendedFails, unattendedRules, unattendedRunOf, } from "../automations/unattended.js";
14
14
  import { backgroundMaxSeconds } from "../background/launch.js";
15
15
  import { ConversationApprovalProfile } from "../conversations/approval-profile.js";
16
16
  import { AttachmentsService } from "../conversations/attachments.service.js";
@@ -118,7 +118,8 @@ export const commandDeniedText = (reason, kind) => kind === "write"
118
118
  : `Command blocked by review: ${reason}. Do the work another way or ask the user to run it.`;
119
119
  /**
120
120
  * A command (or write, or read) the review held in an unattended run: no one can answer, so it is a
121
- * deny at once — no approval, no grant (P-D3).
121
+ * deny at once — no approval, no grant (P-D3); the task run records the held class
122
+ * (`reviewHoldKey`).
122
123
  */
123
124
  export const commandUnattendedText = (reason, kind) => kind === "command"
124
125
  ? `This command needs approval (${reason}), and no one can approve it now; do the work another way or leave it for the person.`
@@ -2149,6 +2150,10 @@ let ToolPipeline = class ToolPipeline {
2149
2150
  const command = kind === "command" ? textField(input, "command") : tool.key;
2150
2151
  if (!attended) {
2151
2152
  const reason = verdict.reason;
2153
+ // an automation's run records the held class on its task run (shown there, never a grant)
2154
+ if (ctx.unattended != null) {
2155
+ await appendMissingGrant(this.deps.db, ctx.unattended.taskRunId, reviewHoldKey(kind));
2156
+ }
2152
2157
  return {
2153
2158
  kind: "result",
2154
2159
  content: commandUnattendedText(reason, kind),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.146",
3
+ "version": "0.1.0-rc.147",
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,10 +70,11 @@
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.103"
73
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.104"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
77
+ "@opentelemetry/exporter-prometheus": "0.223.0",
77
78
  "@opentelemetry/sdk-metrics": "2.12.0",
78
79
  "@types/pg": "^8.23.1",
79
80
  "@types/pg-cursor": "^2.7.2",
@@ -82,7 +83,7 @@
82
83
  "@types/yauzl": "3.4.0",
83
84
  "pg-cursor": "^2.22.1",
84
85
  "ws": "^8.22.0",
85
- "@capybara-hq/testing": "0.1.0-rc.60"
86
+ "@capybara-hq/testing": "0.1.0-rc.61"
86
87
  },
87
88
  "scripts": {
88
89
  "build": "tsc -b"
@@ -0,0 +1,40 @@
1
+ -- Isolated extension usage counters (isolation capacity spec 2026-12-04, §7 "Usage counters";
2
+ -- plan task 1.2c). Each replica counts invocations, busy lane time, stream frames, broker
3
+ -- callbacks by family and ctx.net bytes out and in per (org, plugin) in memory and flushes them every 10 s
4
+ -- as additive upserts into hourly buckets, so concurrent replicas never overwrite each other.
5
+ -- These are capacity and usage-trend counters, not a ledger: a crashed replica loses at most its
6
+ -- unflushed window. Model and storage usage keep their own records and are not repeated here.
7
+ --
8
+ -- One row per (org, plugin, hour, counter). Counter names: invocations, busy_lane_ms,
9
+ -- stream_frames, net_bytes_out, net_bytes_in and broker.<family> (broker.kv, broker.net, ...).
10
+ CREATE TABLE IF NOT EXISTS extension_usage (
11
+ org_id text NOT NULL REFERENCES orgs(id) ON DELETE CASCADE,
12
+ plugin text NOT NULL,
13
+ hour timestamptz NOT NULL CHECK (hour = date_trunc('hour', hour)),
14
+ counter text NOT NULL CHECK (counter ~ '^[a-z_]{1,32}(\.[a-z]{1,16})?$'),
15
+ amount bigint NOT NULL CHECK (amount >= 0),
16
+ PRIMARY KEY (org_id, plugin, hour, counter)
17
+ );
18
+
19
+ -- Deployment-wide saturation views read by time range first.
20
+ CREATE INDEX IF NOT EXISTS extension_usage_hour_idx ON extension_usage (hour, plugin);
21
+
22
+ DROP POLICY IF EXISTS org_scope ON extension_usage;
23
+ CREATE POLICY org_scope ON extension_usage
24
+ USING (rls_admits(org_id, (SELECT rls_scope_unrestricted()),
25
+ (SELECT pg_catalog.current_setting('capybara.org_id', true))))
26
+ WITH CHECK (rls_admits(org_id, (SELECT rls_scope_unrestricted()),
27
+ (SELECT pg_catalog.current_setting('capybara.org_id', true))));
28
+ ALTER TABLE extension_usage ENABLE ROW LEVEL SECURITY, FORCE ROW LEVEL SECURITY;
29
+
30
+ -- Flush batches already applied. A flush whose outcome is unknown (the connection dropped around
31
+ -- the commit) is retried with the same id; the batch row makes the retry a no-op when the first
32
+ -- attempt committed, so a batch never counts twice. Deployment state with no org_id; replicas
33
+ -- delete rows older than a day.
34
+ CREATE TABLE IF NOT EXISTS extension_usage_batches (
35
+ id text PRIMARY KEY,
36
+ flushed_at timestamptz NOT NULL DEFAULT now()
37
+ );
38
+
39
+ CREATE INDEX IF NOT EXISTS extension_usage_batches_flushed_idx
40
+ ON extension_usage_batches (flushed_at);
@@ -0,0 +1,28 @@
1
+ -- Each replica's isolation supervisor readiness and shadow execution placements (extension
2
+ -- permission model plan task 1.4j). The supervisor probe and the 1.3b shadow placements run per
3
+ -- replica; the isolation status route and permission reviews read them deployment-wide, so each
4
+ -- replica writes its row after its probe and convergence, refreshes it with its heartbeat and
5
+ -- deletes it on a clean stop; rows of a replica whose heartbeat went stale are pruned like
6
+ -- extension_replica_status. Deployment-wide state: no org_id, so no row level security.
7
+ CREATE TABLE IF NOT EXISTS extension_replica_isolation (
8
+ replica_id text PRIMARY KEY,
9
+ -- 'available' or 'failing' as the replica's last probe saw it; 'not_configured' for a replica
10
+ -- without extensionHost.isolation (it probes nothing and still records its shadow placements)
11
+ state text NOT NULL CHECK (state IN ('available', 'failing', 'not_configured')),
12
+ -- the first supervisor check that failed, with the kernel's English message
13
+ failed_check text CHECK (
14
+ failed_check IS NULL
15
+ OR failed_check IN ('guard_reachability', 'engine_runtime', 'image', 'postgres_socket')
16
+ ),
17
+ message text,
18
+ CHECK ((state = 'failing') = (failed_check IS NOT NULL)),
19
+ -- the replica's shadow execution placements of its last convergence (1.3b), a JSON array
20
+ shadow jsonb NOT NULL DEFAULT '[]'::jsonb CHECK (jsonb_typeof(shadow) = 'array'),
21
+ http_replica_id text,
22
+ -- when the last probe ran (null when not configured)
23
+ probed_at timestamptz,
24
+ heartbeat_at timestamptz NOT NULL DEFAULT now()
25
+ );
26
+
27
+ CREATE INDEX IF NOT EXISTS extension_replica_isolation_heartbeat_idx
28
+ ON extension_replica_isolation (heartbeat_at);