@capybara-hq/kernel 0.1.0-rc.77 → 0.1.0-rc.78

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 (228) hide show
  1. package/bootstrap.json +6 -6
  2. package/dist/admin/outbox-dead.service.js +4 -1
  3. package/dist/agents/admin-agents.js +2 -0
  4. package/dist/agents/agent-lookup.js +4 -0
  5. package/dist/agents/agent-profile.service.js +3 -0
  6. package/dist/agents/agents.service.js +7 -0
  7. package/dist/agents/org-templates.js +1 -0
  8. package/dist/agents/pending-connector-requests.js +6 -0
  9. package/dist/agents/pending-connectors.service.js +2 -0
  10. package/dist/agents/readiness.service.d.ts +9 -3
  11. package/dist/agents/readiness.service.js +3 -3
  12. package/dist/agents/templates.js +1 -0
  13. package/dist/background/finish.js +3 -0
  14. package/dist/background/stop.js +2 -0
  15. package/dist/background/store.js +44 -0
  16. package/dist/background/tasks.service.js +3 -2
  17. package/dist/background/wake-rules.js +1 -0
  18. package/dist/catalog/admin-catalog.controller.d.ts +6 -0
  19. package/dist/catalog/admin-catalog.controller.js +13 -0
  20. package/dist/catalog/catalog-content.d.ts +6 -0
  21. package/dist/catalog/catalog-content.js +1 -0
  22. package/dist/catalog/catalog-items.js +4 -0
  23. package/dist/catalog/catalog-scope.service.js +4 -1
  24. package/dist/catalog/component-promotion.js +2 -0
  25. package/dist/catalog/component-scope.controller.d.ts +9 -15
  26. package/dist/catalog/component-scope.controller.js +14 -9
  27. package/dist/catalog/component-scope.service.js +5 -0
  28. package/dist/catalog/component-state.js +2 -0
  29. package/dist/catalog/marketplaces.service.d.ts +6 -1
  30. package/dist/catalog/marketplaces.service.js +8 -3
  31. package/dist/catalog/org-catalog.controller.d.ts +9 -0
  32. package/dist/catalog/org-catalog.controller.js +18 -0
  33. package/dist/catalog/org-catalog.schemas.d.ts +2 -4
  34. package/dist/catalog/org-catalog.schemas.js +2 -3
  35. package/dist/catalog/org-catalog.service.d.ts +10 -1
  36. package/dist/catalog/org-catalog.service.js +34 -23
  37. package/dist/catalog/org-extension-switch.d.ts +3 -10
  38. package/dist/catalog/org-extension-switch.js +14 -60
  39. package/dist/catalog/org-extension.controller.d.ts +6 -7
  40. package/dist/catalog/org-extension.controller.js +4 -4
  41. package/dist/catalog/org-extension.schemas.d.ts +1 -2
  42. package/dist/catalog/org-extension.schemas.js +1 -3
  43. package/dist/catalog/owned-items.js +10 -1
  44. package/dist/catalog/ownership.js +2 -0
  45. package/dist/catalog/plugin-import.js +8 -0
  46. package/dist/catalog/plugin-install.d.ts +1 -4
  47. package/dist/catalog/plugin-install.js +11 -12
  48. package/dist/catalog/plugin-upgrade.js +4 -1
  49. package/dist/catalog/request-rules.js +6 -0
  50. package/dist/catalog/requests.service.js +4 -0
  51. package/dist/catalog/scope-orgs.js +1 -0
  52. package/dist/catalog/scope-sync.d.ts +8 -5
  53. package/dist/catalog/scope-sync.js +21 -23
  54. package/dist/catalog/unshare.js +3 -0
  55. package/dist/channels/connections.service.js +1 -0
  56. package/dist/channels/inbound.js +1 -0
  57. package/dist/channels/jobs.js +1 -0
  58. package/dist/channels/outbound.js +6 -0
  59. package/dist/channels/supervisor.js +1 -0
  60. package/dist/channels/threads.js +1 -0
  61. package/dist/client/client-reports.service.js +1 -0
  62. package/dist/config/fields.js +20 -4
  63. package/dist/conversations/access.js +1 -0
  64. package/dist/conversations/attachments.service.js +16 -4
  65. package/dist/conversations/conversations.service.js +17 -3
  66. package/dist/conversations/event-log.js +2 -0
  67. package/dist/conversations/events.d.ts +1 -0
  68. package/dist/conversations/events.js +3 -1
  69. package/dist/conversations/files.js +3 -2
  70. package/dist/conversations/permission-profiles.service.js +1 -0
  71. package/dist/conversations/prompt-suggestions.js +2 -0
  72. package/dist/conversations/queue.js +8 -0
  73. package/dist/conversations/queue.service.js +6 -2
  74. package/dist/conversations/source.js +2 -0
  75. package/dist/conversations/titles.js +10 -2
  76. package/dist/conversations/tree.js +6 -0
  77. package/dist/db/kernel-schema.d.ts +3 -1
  78. package/dist/devices/conversation-devices.js +3 -0
  79. package/dist/devices/device-projects.service.js +2 -0
  80. package/dist/devices/devices.service.js +5 -0
  81. package/dist/devices/legacy-cleanup.job.js +5 -2
  82. package/dist/dial-in/handlers.js +2 -0
  83. package/dist/dial-in/machines.js +11 -2
  84. package/dist/dial-in/targets.d.ts +0 -2
  85. package/dist/dial-in/targets.js +0 -10
  86. package/dist/errors.d.ts +0 -1
  87. package/dist/errors.js +0 -1
  88. package/dist/evals/budget.js +14 -1
  89. package/dist/evals/run-replay.js +4 -0
  90. package/dist/evals/runs.service.js +13 -7
  91. package/dist/evals/sets.service.js +23 -8
  92. package/dist/evals/trajectory.service.d.ts +1 -1
  93. package/dist/evals/trajectory.service.js +1 -0
  94. package/dist/evals/worker.js +5 -1
  95. package/dist/extensions/admin-ops.js +1 -0
  96. package/dist/extensions/admin-view.js +3 -1
  97. package/dist/extensions/bootstrap-packages.d.ts +12 -1
  98. package/dist/extensions/bootstrap-packages.js +49 -9
  99. package/dist/extensions/bootstrap.d.ts +17 -2
  100. package/dist/extensions/bootstrap.js +41 -9
  101. package/dist/extensions/config-json-schema.d.ts +2 -2
  102. package/dist/extensions/config-json-schema.js +1 -3
  103. package/dist/extensions/deployment-config.d.ts +5 -3
  104. package/dist/extensions/deployment-config.js +3 -3
  105. package/dist/extensions/effective-config.d.ts +8 -7
  106. package/dist/extensions/effective-config.js +8 -7
  107. package/dist/extensions/enabled.js +1 -0
  108. package/dist/extensions/host.d.ts +4 -3
  109. package/dist/extensions/host.js +11 -12
  110. package/dist/extensions/instance.d.ts +1 -1
  111. package/dist/extensions/instance.js +17 -2
  112. package/dist/extensions/org-config.d.ts +35 -97
  113. package/dist/extensions/org-config.js +48 -315
  114. package/dist/extensions/org-levels.d.ts +22 -9
  115. package/dist/extensions/org-levels.js +100 -20
  116. package/dist/extensions/org-overrides.d.ts +14 -15
  117. package/dist/extensions/org-overrides.js +20 -20
  118. package/dist/extensions/package.js +1 -1
  119. package/dist/extensions/permission-set.d.ts +1 -3
  120. package/dist/extensions/permission-set.js +3 -7
  121. package/dist/extensions/permission-view.d.ts +3 -1
  122. package/dist/extensions/permission-view.js +5 -4
  123. package/dist/extensions/plugin-icons.d.ts +72 -1
  124. package/dist/extensions/plugin-icons.js +194 -2
  125. package/dist/extensions/point-defaults.d.ts +17 -18
  126. package/dist/extensions/point-defaults.js +25 -28
  127. package/dist/identity/accounts.js +6 -0
  128. package/dist/identity/api-tokens.js +8 -0
  129. package/dist/infra/outbox/outbox.dispatcher.js +4 -1
  130. package/dist/infra/outbox/outbox.service.js +2 -0
  131. package/dist/orgs/directory-sync.d.ts +9 -6
  132. package/dist/orgs/directory-sync.js +15 -12
  133. package/dist/orgs/invitations.service.js +2 -0
  134. package/dist/orgs/members.service.js +2 -0
  135. package/dist/orgs/offboarding.js +2 -0
  136. package/dist/packages/npm.d.ts +9 -1
  137. package/dist/packages/npm.js +37 -5
  138. package/dist/platform/exclusions.js +20 -0
  139. package/dist/platform/ops/admin-items.ops.js +1 -0
  140. package/dist/platform/ops/agents.ops.js +1 -0
  141. package/dist/platform/ops/extensions.ops.d.ts +6 -8
  142. package/dist/platform/ops/extensions.ops.js +18 -97
  143. package/dist/platform/ops/org-plugins.ops.d.ts +3 -6
  144. package/dist/platform/ops/org-plugins.ops.js +14 -65
  145. package/dist/platform/ops/outbox.ops.js +1 -0
  146. package/dist/platform/ops/person-inputs.d.ts +0 -4
  147. package/dist/platform/ops/person-inputs.js +0 -8
  148. package/dist/platform/ops/plugins.ops.d.ts +4 -1
  149. package/dist/platform/ops/plugins.ops.js +27 -34
  150. package/dist/platform/person-fields.d.ts +1 -1
  151. package/dist/platform/person-fields.js +1 -1
  152. package/dist/platform/sealed-reveals.js +2 -0
  153. package/dist/push/recipients.js +9 -2
  154. package/dist/runtime/permission-context.service.js +1 -0
  155. package/dist/runtime/plugin-context.service.js +1 -0
  156. package/dist/runtime/project/knowledge.service.js +1 -0
  157. package/dist/runtime/run-context.service.js +1 -0
  158. package/dist/runtime/run-deletion.js +4 -0
  159. package/dist/runtime/run-execution.js +2 -0
  160. package/dist/runtime/run-finish.js +3 -0
  161. package/dist/runtime/run-jobs.js +3 -0
  162. package/dist/runtime/run-orphan-check.job.js +7 -0
  163. package/dist/runtime/run-queue.js +21 -2
  164. package/dist/runtime/run-worker.js +5 -0
  165. package/dist/runtime/step-log.js +1 -0
  166. package/dist/runtime/subagents/child.js +2 -0
  167. package/dist/runtime/subagents/deliveries.js +3 -0
  168. package/dist/runtime/subagents/dispatch.js +5 -1
  169. package/dist/runtime/subagents/messages.js +2 -0
  170. package/dist/runtime/subagents/org-agents.d.ts +1 -1
  171. package/dist/runtime/subagents/org-agents.js +2 -1
  172. package/dist/runtime/usage-report-jobs.js +1 -0
  173. package/dist/runtime/usage-report.js +3 -0
  174. package/dist/runtime/waits.js +5 -0
  175. package/dist/sandbox/cloud-permission-snapshot.js +9 -3
  176. package/dist/sandbox/device-reports.js +3 -0
  177. package/dist/sandbox/legacy-retirement.js +5 -1
  178. package/dist/sandbox/managed-device-context.js +1 -0
  179. package/dist/sandbox/modes.d.ts +5 -2
  180. package/dist/sandbox/modes.js +8 -4
  181. package/dist/sandbox/network-grants.js +2 -0
  182. package/dist/sandbox/operation-intents.js +58 -0
  183. package/dist/sandbox/operation-reconcile.job.js +2 -0
  184. package/dist/sandbox/permission-authority-lock.js +12 -6
  185. package/dist/sandbox/permission-call-grants.js +6 -0
  186. package/dist/sandbox/permission-ceiling-writes.js +5 -0
  187. package/dist/sandbox/permission-config-publication.js +5 -0
  188. package/dist/sandbox/permission-instance-writes.js +4 -0
  189. package/dist/sandbox/permission-runtime-reports.js +10 -1
  190. package/dist/sandbox/permission-transitions.js +3 -0
  191. package/dist/sandbox/review/review.service.js +8 -5
  192. package/dist/sandbox/sandbox.service.d.ts +14 -0
  193. package/dist/sandbox/sandbox.service.js +195 -29
  194. package/dist/sandbox/unreachable.js +4 -1
  195. package/dist/schedules/fire.js +9 -3
  196. package/dist/schedules/pause.js +2 -0
  197. package/dist/schedules/run-tracker.js +16 -1
  198. package/dist/schedules/scheduled-tasks.service.js +4 -2
  199. package/dist/schedules/store.js +8 -0
  200. package/dist/schedules/unattended.js +4 -0
  201. package/dist/setup/setup-checks.service.d.ts +1 -10
  202. package/dist/setup/setup-checks.service.js +19 -29
  203. package/dist/shares/share-open.service.js +1 -0
  204. package/dist/shares/shares.service.js +2 -0
  205. package/dist/skills/agent-skills.service.d.ts +1 -1
  206. package/dist/skills/agent-skills.service.js +13 -2
  207. package/dist/skills/catalog.js +3 -0
  208. package/dist/skills/changes.service.js +10 -2
  209. package/dist/skills/conversation-catalog.js +1 -0
  210. package/dist/skills/skills.service.js +4 -0
  211. package/dist/tools/approvals.service.js +40 -0
  212. package/dist/tools/builtins/schedules.js +11 -6
  213. package/dist/tools/builtins/web/fetch.js +1 -1
  214. package/dist/tools/builtins/web/search.js +1 -1
  215. package/dist/tools/connector-account-policies.js +3 -0
  216. package/dist/tools/connectors.controller.d.ts +20 -8
  217. package/dist/tools/connectors.controller.js +30 -12
  218. package/dist/tools/connectors.service.d.ts +8 -0
  219. package/dist/tools/connectors.service.js +21 -1
  220. package/dist/tools/drift.js +5 -0
  221. package/dist/tools/git-push-policy.js +3 -0
  222. package/dist/tools/oauth/flow.js +1 -0
  223. package/dist/tools/outputs.js +2 -0
  224. package/dist/tools/permission-approval-jobs.js +3 -0
  225. package/dist/tools/pipeline.js +2 -0
  226. package/dist/tools/policy.js +3 -0
  227. package/dist/tools/questions.service.js +13 -0
  228. package/package.json +3 -3
@@ -160,6 +160,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
160
160
  .selectFrom("sandbox_operation_intents")
161
161
  .selectAll()
162
162
  .where("operation_id", "=", id)
163
+ .where("org_id", "=", ctx.orgId)
163
164
  .executeTakeFirst();
164
165
  if (previous) {
165
166
  this.assertIdentity(previous, ctx, instance, method, hash);
@@ -249,6 +250,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
249
250
  updated_at: new Date(),
250
251
  })
251
252
  .where("operation_id", "=", id)
253
+ .where("org_id", "=", ctx.orgId)
252
254
  .where("state", "=", "pending")
253
255
  .execute();
254
256
  const row = await this.read(id);
@@ -406,6 +408,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
406
408
  .selectFrom("sandbox_operation_intents")
407
409
  .selectAll()
408
410
  .where("operation_id", "=", id)
411
+ .where("org_id", "=", initial.org_id)
409
412
  .forUpdate()
410
413
  .executeTakeFirstOrThrow();
411
414
  if (row.org_id !== ctx.orgId ||
@@ -431,11 +434,14 @@ let SandboxOperationIntents = class SandboxOperationIntents {
431
434
  .updateTable("sandbox_operation_intents")
432
435
  .set({ state: "dispatching", updated_at: new Date() })
433
436
  .where("operation_id", "=", id)
437
+ .where("org_id", "=", row.org_id)
434
438
  .execute();
435
439
  return { ...row, state: "dispatching" };
436
440
  }
437
441
  async claimBrowse(ctx, id) {
438
442
  await this.locks.acquire({ orgId: ctx.orgId, deviceId: ctx.deviceId }, { kind: "admit" });
443
+ // org-filter: org_id is compared with ctx.orgId right below (denied on a mismatch); the id is
444
+ // the one admitBrowse returned to the kernel caller
439
445
  const row = await this.db
440
446
  .selectFrom("sandbox_operation_intents")
441
447
  .selectAll()
@@ -454,6 +460,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
454
460
  .updateTable("sandbox_operation_intents")
455
461
  .set({ state: "dispatching", updated_at: new Date() })
456
462
  .where("operation_id", "=", id)
463
+ .where("org_id", "=", row.org_id)
457
464
  .execute();
458
465
  return { ...row, state: "dispatching" };
459
466
  }
@@ -471,6 +478,9 @@ let SandboxOperationIntents = class SandboxOperationIntents {
471
478
  throw new SandboxOperationOutcomeUnknownError("The recorded operation belongs to another instance; do not repeat it");
472
479
  }
473
480
  async read(id) {
481
+ // org-filter: operation ids are kernel-minted (operationIdFor over the run claim, or a random
482
+ // scope id) and reach here only from the tool worker, the sandbox lifecycle and the kernel's
483
+ // reconcile and revoke jobs; no route or tool input names one
474
484
  return this.db
475
485
  .selectFrom("sandbox_operation_intents")
476
486
  .selectAll()
@@ -485,6 +495,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
485
495
  .selectFrom("sandbox_operation_intents")
486
496
  .selectAll()
487
497
  .where("operation_id", "=", id)
498
+ .where("org_id", "=", initial.org_id)
488
499
  .forUpdate()
489
500
  .executeTakeFirstOrThrow();
490
501
  if (r.state === "revoked") {
@@ -517,6 +528,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
517
528
  .updateTable("sandbox_operation_intents")
518
529
  .set({ state: "admitted", updated_at: new Date() })
519
530
  .where("operation_id", "=", id)
531
+ .where("org_id", "=", r.org_id)
520
532
  .execute();
521
533
  await this.outbox.add({
522
534
  queue: "cap-kernel-maintenance",
@@ -536,6 +548,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
536
548
  .selectFrom("sandbox_operation_intents")
537
549
  .selectAll()
538
550
  .where("operation_id", "=", id)
551
+ .where("org_id", "=", initial.org_id)
539
552
  .forUpdate()
540
553
  .executeTakeFirstOrThrow();
541
554
  if (r.state === "completed" || r.state === "background-running")
@@ -559,6 +572,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
559
572
  .updateTable("sandbox_operation_intents")
560
573
  .set({ state: "revoked", outcome_unknown: false, updated_at: new Date() })
561
574
  .where("operation_id", "=", id)
575
+ .where("org_id", "=", r.org_id)
562
576
  .execute();
563
577
  return { ...r, state: "revoked", outcome_unknown: false };
564
578
  }
@@ -572,6 +586,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
572
586
  updated_at: new Date(),
573
587
  })
574
588
  .where("operation_id", "=", id)
589
+ .where("org_id", "=", r.org_id)
575
590
  .execute();
576
591
  return {
577
592
  ...r,
@@ -630,6 +645,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
630
645
  stopping_at: null,
631
646
  })
632
647
  .where("id", "=", b.taskId)
648
+ .where("org_id", "=", r.org_id)
633
649
  .where("operation_id", "=", r.operation_id)
634
650
  .where("launch_state", "=", "pending")
635
651
  .where("status", "=", "running")
@@ -652,6 +668,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
652
668
  .selectFrom("sandbox_operation_intents")
653
669
  .selectAll()
654
670
  .where("operation_id", "=", id)
671
+ .where("org_id", "=", initial.org_id)
655
672
  .forUpdate()
656
673
  .executeTakeFirstOrThrow();
657
674
  const ref = parseSandboxExecutionRef(result);
@@ -666,6 +683,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
666
683
  .selectFrom("background_tasks")
667
684
  .selectAll()
668
685
  .where("operation_id", "=", id)
686
+ .where("org_id", "=", r.org_id)
669
687
  .forUpdate()
670
688
  .executeTakeFirst();
671
689
  if (!task || task.instance_id !== instanceId)
@@ -690,6 +708,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
690
708
  updated_at: new Date(),
691
709
  })
692
710
  .where("operation_id", "=", id)
711
+ .where("org_id", "=", r.org_id)
693
712
  .execute();
694
713
  await this.db
695
714
  .updateTable("background_tasks")
@@ -699,6 +718,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
699
718
  sandbox_created_at: new Date(Number(r.instance_generation)),
700
719
  })
701
720
  .where("id", "=", task.id)
721
+ .where("org_id", "=", r.org_id)
702
722
  .execute();
703
723
  return "acknowledged";
704
724
  }
@@ -713,6 +733,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
713
733
  updated_at: new Date(),
714
734
  })
715
735
  .where("operation_id", "=", id)
736
+ .where("org_id", "=", r.org_id)
716
737
  .execute();
717
738
  await this.db
718
739
  .updateTable("background_tasks")
@@ -725,6 +746,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
725
746
  stopping_at: null,
726
747
  })
727
748
  .where("id", "=", task.id)
749
+ .where("org_id", "=", r.org_id)
728
750
  .where("launch_state", "in", ["dispatched", "cancel-pending"])
729
751
  .execute();
730
752
  await this.outbox.add({
@@ -751,6 +773,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
751
773
  .selectFrom("sandbox_operation_intents")
752
774
  .selectAll()
753
775
  .where("operation_id", "=", id)
776
+ .where("org_id", "=", initial.org_id)
754
777
  .forUpdate()
755
778
  .executeTakeFirstOrThrow();
756
779
  if (r.method !== "backgroundStart" ||
@@ -761,6 +784,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
761
784
  .selectFrom("background_tasks")
762
785
  .selectAll()
763
786
  .where("operation_id", "=", id)
787
+ .where("org_id", "=", r.org_id)
764
788
  .forUpdate()
765
789
  .executeTakeFirst();
766
790
  if (!task) {
@@ -774,6 +798,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
774
798
  .updateTable("sandbox_operation_intents")
775
799
  .set({ execution_id: executionId, outcome_unknown: true, updated_at: new Date() })
776
800
  .where("operation_id", "=", id)
801
+ .where("org_id", "=", r.org_id)
777
802
  .execute();
778
803
  return { ...r, execution_id: executionId, outcome_unknown: true };
779
804
  }
@@ -796,6 +821,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
796
821
  cancel_requested_at: sql `COALESCE(cancel_requested_at, now())`,
797
822
  })
798
823
  .where("id", "=", task.id)
824
+ .where("org_id", "=", r.org_id)
799
825
  .execute();
800
826
  return false;
801
827
  }
@@ -810,6 +836,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
810
836
  updated_at: new Date(),
811
837
  })
812
838
  .where("operation_id", "=", r.operation_id)
839
+ .where("org_id", "=", r.org_id)
813
840
  .execute();
814
841
  await this.outbox.add({
815
842
  queue: "cap-kernel-maintenance",
@@ -832,6 +859,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
832
859
  .selectFrom("sandbox_operation_intents")
833
860
  .selectAll()
834
861
  .where("operation_id", "=", id)
862
+ .where("org_id", "=", initial.org_id)
835
863
  .forUpdate()
836
864
  .executeTakeFirstOrThrow();
837
865
  if (r.state !== "admitted")
@@ -849,6 +877,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
849
877
  .selectFrom("sandbox_operation_intents")
850
878
  .selectAll()
851
879
  .where("operation_id", "=", id)
880
+ .where("org_id", "=", initial.org_id)
852
881
  .where("execution_id", "=", executionId)
853
882
  .where("state", "=", "started-or-unknown")
854
883
  .forUpdate()
@@ -862,6 +891,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
862
891
  .updateTable("sandbox_operation_intents")
863
892
  .set({ state: "completed", result: payload, outcome_unknown: false, updated_at: new Date() })
864
893
  .where("operation_id", "=", r.operation_id)
894
+ .where("org_id", "=", r.org_id)
865
895
  .execute();
866
896
  await this.db
867
897
  .updateTable("background_tasks")
@@ -873,6 +903,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
873
903
  stopping_at: null,
874
904
  })
875
905
  .where("operation_id", "=", r.operation_id)
906
+ .where("org_id", "=", r.org_id)
876
907
  .where("launch_state", "=", from)
877
908
  .where("status", "=", "running")
878
909
  .execute();
@@ -890,6 +921,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
890
921
  .selectFrom("sandbox_operation_intents")
891
922
  .selectAll()
892
923
  .where("operation_id", "=", id)
924
+ .where("org_id", "=", initial.org_id)
893
925
  .forUpdate()
894
926
  .executeTakeFirstOrThrow();
895
927
  if (r.method !== "backgroundStart")
@@ -898,6 +930,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
898
930
  .selectFrom("background_tasks")
899
931
  .selectAll()
900
932
  .where("operation_id", "=", id)
933
+ .where("org_id", "=", r.org_id)
901
934
  .forUpdate()
902
935
  .executeTakeFirst();
903
936
  if (r.state === "pending" || r.state === "admitted") {
@@ -905,6 +938,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
905
938
  .updateTable("sandbox_operation_intents")
906
939
  .set({ state: "revoked", outcome_unknown: false, updated_at: new Date() })
907
940
  .where("operation_id", "=", id)
941
+ .where("org_id", "=", r.org_id)
908
942
  .execute();
909
943
  if (task?.launch_state === "pending")
910
944
  await this.db
@@ -917,6 +951,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
917
951
  stopping_at: null,
918
952
  })
919
953
  .where("id", "=", task.id)
954
+ .where("org_id", "=", r.org_id)
920
955
  .where("status", "=", "running")
921
956
  .execute();
922
957
  return;
@@ -946,6 +981,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
946
981
  stopping_at: null,
947
982
  })
948
983
  .where("id", "=", task.id)
984
+ .where("org_id", "=", r.org_id)
949
985
  .execute();
950
986
  }
951
987
  /** The recorded input of an operation (for a same-identity retry only). */
@@ -958,6 +994,8 @@ let SandboxOperationIntents = class SandboxOperationIntents {
958
994
  * retention expiry job settles what is never resolved.
959
995
  */
960
996
  async deferBackgroundRecovery(id) {
997
+ // org-filter: by the kernel-minted operation id of the reconcile job's payload (written by this
998
+ // service), not caller input
961
999
  const row = await this.db
962
1000
  .updateTable("sandbox_operation_intents")
963
1001
  .set((eb) => ({ reconcile_attempt: eb("reconcile_attempt", "+", 1), updated_at: new Date() }))
@@ -999,6 +1037,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
999
1037
  .selectFrom("sandbox_operation_intents")
1000
1038
  .selectAll()
1001
1039
  .where("operation_id", "=", id)
1040
+ .where("org_id", "=", initial.org_id)
1002
1041
  .where("execution_id", "=", executionId)
1003
1042
  .where("state", "in", ["dispatching", "started-or-unknown"])
1004
1043
  .forUpdate()
@@ -1022,6 +1061,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1022
1061
  stopping_at: null,
1023
1062
  })
1024
1063
  .where("operation_id", "=", id)
1064
+ .where("org_id", "=", row.org_id)
1025
1065
  .where("launch_state", "=", "dispatched")
1026
1066
  .where("status", "=", "running")
1027
1067
  .execute();
@@ -1033,6 +1073,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1033
1073
  .updateTable("sandbox_operation_intents")
1034
1074
  .set({ state: "completed", result: payload, outcome_unknown: false, updated_at: new Date() })
1035
1075
  .where("operation_id", "=", id)
1076
+ .where("org_id", "=", row.org_id)
1036
1077
  .execute();
1037
1078
  }
1038
1079
  async result(row) {
@@ -1044,6 +1085,8 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1044
1085
  * (without `executionId`: the orphan cleanup of the reconcile job).
1045
1086
  */
1046
1087
  async unknown(id, executionId) {
1088
+ // org-filter: by the kernel-minted operation id held by its dispatcher or the reconcile job,
1089
+ // not caller input
1047
1090
  let q = this.db
1048
1091
  .updateTable("sandbox_operation_intents")
1049
1092
  .set({ state: "started-or-unknown", outcome_unknown: true, updated_at: new Date() })
@@ -1062,6 +1105,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1062
1105
  .selectFrom("sandbox_operation_intents")
1063
1106
  .selectAll()
1064
1107
  .where("operation_id", "=", id)
1108
+ .where("org_id", "=", initial.org_id)
1065
1109
  .forUpdate()
1066
1110
  .executeTakeFirstOrThrow();
1067
1111
  this.assertIdentity(r, ctx, instance, method, permissionScopeHash({ method, inputDigest: describeOperationPayload(input).digest }));
@@ -1081,6 +1125,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1081
1125
  .selectFrom("background_tasks")
1082
1126
  .selectAll()
1083
1127
  .where("operation_id", "=", id)
1128
+ .where("org_id", "=", r.org_id)
1084
1129
  .forUpdate()
1085
1130
  .executeTakeFirst();
1086
1131
  if (!task)
@@ -1101,6 +1146,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1101
1146
  updated_at: new Date(),
1102
1147
  })
1103
1148
  .where("operation_id", "=", id)
1149
+ .where("org_id", "=", r.org_id)
1104
1150
  .execute();
1105
1151
  return {
1106
1152
  ...r,
@@ -1120,6 +1166,8 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1120
1166
  }
1121
1167
  /** Keep the consumed ID/hash and cleanup obligations; expired bytes cannot authorize replay. */
1122
1168
  async expirePayload(id) {
1169
+ // org-filter: by the kernel-minted operation id of the expiry job's payload (written by this
1170
+ // service), not caller input
1123
1171
  const expired = await this.db
1124
1172
  .updateTable("sandbox_operation_intents")
1125
1173
  .set({ input: "null", result: JSON.stringify({ $expired: true }), updated_at: new Date() })
@@ -1140,6 +1188,8 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1140
1188
  if (!tokens.length)
1141
1189
  return;
1142
1190
  // the device's org, as every intent outbox row carries it: the org's deletion removes them
1191
+ // org-filter: reads the device's own org for the outbox rows; deviceId is the lifecycle
1192
+ // holder's leased device, not caller input
1143
1193
  const device = await this.db
1144
1194
  .selectFrom("devices")
1145
1195
  .select("org_id")
@@ -1180,6 +1230,8 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1180
1230
  }
1181
1231
  /** Revokes the device's intents `where` selects and owes each its exact revoke job. */
1182
1232
  async revokeMatching(deviceId, where) {
1233
+ // org-filter: reads the device's own org to lock its subject; deviceId is the lifecycle
1234
+ // holder's leased device, not caller input
1183
1235
  const device = await this.db
1184
1236
  .selectFrom("devices")
1185
1237
  .select("org_id")
@@ -1192,6 +1244,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1192
1244
  .updateTable("sandbox_operation_intents")
1193
1245
  .set({ state: "revoked", outcome_unknown: true, updated_at: new Date() })
1194
1246
  .where("device_id", "=", deviceId)
1247
+ .where("org_id", "=", device.org_id)
1195
1248
  .where(where)
1196
1249
  .returning(["operation_id", "method"])
1197
1250
  .execute();
@@ -1210,6 +1263,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1210
1263
  stopping_at: null,
1211
1264
  })
1212
1265
  .where("operation_id", "in", starts)
1266
+ .where("org_id", "=", device.org_id)
1213
1267
  .where("status", "=", "running")
1214
1268
  .where("execution_ref", "is", null)
1215
1269
  .where("launch_state", "in", ["pending", "dispatched", "cancel-pending"])
@@ -1229,6 +1283,8 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1229
1283
  * launched background start is left to its exact stop by the revoke job.
1230
1284
  */
1231
1285
  async owedRevocations(deviceId, instance, limit) {
1286
+ // org-filter: by the leased device of the lifecycle holder (SandboxService under its exclusive
1287
+ // lease), not caller input
1232
1288
  const rows = await this.db
1233
1289
  .selectFrom("sandbox_operation_intents")
1234
1290
  .select(["operation_id", "deadline"])
@@ -1277,6 +1333,8 @@ let SandboxOperationIntents = class SandboxOperationIntents {
1277
1333
  });
1278
1334
  }
1279
1335
  async acknowledgeRevocation(id) {
1336
+ // org-filter: by the kernel-minted operation id of the revoke job's payload (written by this
1337
+ // service), not caller input
1280
1338
  await this.db
1281
1339
  .updateTable("sandbox_operation_intents")
1282
1340
  .set({ revoke_acknowledged: true, updated_at: new Date() })
@@ -109,6 +109,7 @@ let SandboxOperationReconcileJob = class SandboxOperationReconcileJob {
109
109
  .selectFrom("device_instances")
110
110
  .select("provider")
111
111
  .where("device_id", "=", claimed.device_id)
112
+ .where("org_id", "=", claimed.org_id)
112
113
  .executeTakeFirst();
113
114
  const entry = this.providers.forDevice(claimed.provider);
114
115
  if (!Number.isSafeInteger(generation) ||
@@ -186,6 +187,7 @@ let SandboxOperationReconcileJob = class SandboxOperationReconcileJob {
186
187
  .selectFrom("device_instances")
187
188
  .select(["provider", "handle", "created_at"])
188
189
  .where("device_id", "=", row.device_id)
190
+ .where("org_id", "=", row.org_id)
189
191
  .executeTakeFirst();
190
192
  // Do not use a new instance as proof that the old execution was cleaned up.
191
193
  if (!instance?.handle ||
@@ -104,15 +104,21 @@ let PermissionAuthorityLock = class PermissionAuthorityLock {
104
104
  claims.set(item.key, item.mode);
105
105
  }
106
106
  if (subject.deviceId) {
107
- const row = await this.db
108
- .selectFrom("devices")
109
- .select("org_id")
110
- .where("id", "=", subject.deviceId)
111
- .executeTakeFirst();
112
- if (!row || row.org_id !== subject.orgId)
107
+ const orgId = subject.orgId;
108
+ const row = orgId === undefined
109
+ ? undefined
110
+ : await this.db
111
+ .selectFrom("devices")
112
+ .select("org_id")
113
+ .where("id", "=", subject.deviceId)
114
+ .where("org_id", "=", orgId)
115
+ .executeTakeFirst();
116
+ if (!row || row.org_id !== orgId)
113
117
  throw new ApiError("device.not_found", "Device not found");
114
118
  }
115
119
  if (subject.rootConversationId) {
120
+ // org-filter: reads org_id and compares below: another org's conversation must fail, not
121
+ // read as an absent id that a root write may reserve
116
122
  const row = await this.db
117
123
  .selectFrom("conversations")
118
124
  .select("org_id")
@@ -260,6 +260,7 @@ let PermissionCallGrants = class PermissionCallGrants {
260
260
  .selectFrom("permission_call_grants")
261
261
  .selectAll()
262
262
  .where("binding_hash", "=", bindingHash)
263
+ .where("org_id", "=", b.orgId)
263
264
  .executeTakeFirstOrThrow();
264
265
  if (permissionScopeHash(bindingOfGrant(row)) !== bindingHash ||
265
266
  row.expansion_hash !== expansionHash ||
@@ -282,6 +283,7 @@ let PermissionCallGrants = class PermissionCallGrants {
282
283
  .selectFrom("approvals")
283
284
  .selectAll()
284
285
  .where("id", "=", decision.approvalId)
286
+ .where("org_id", "=", b.orgId)
285
287
  .executeTakeFirst();
286
288
  if (approval?.status !== "approved" ||
287
289
  approval.kind !== "command" ||
@@ -321,6 +323,7 @@ let PermissionCallGrants = class PermissionCallGrants {
321
323
  .selectFrom("permission_call_grants")
322
324
  .selectAll()
323
325
  .where("binding_hash", "=", hash)
326
+ .where("org_id", "=", binding.orgId)
324
327
  .executeTakeFirst();
325
328
  if (!row || permissionScopeHash(bindingOfGrant(row)) !== hash)
326
329
  return null;
@@ -343,6 +346,8 @@ let PermissionCallGrants = class PermissionCallGrants {
343
346
  }
344
347
  /** Starting authority belongs to this admitted exec, never to another call or native method. */
345
348
  async forExecution(operationId, deviceId, method, scope, input) {
349
+ // org-filter: operationId is the kernel-minted id of an admitted operation scope (never tool
350
+ // input), and the row must also match deviceId below
346
351
  const intent = await this.db
347
352
  .selectFrom("sandbox_operation_intents")
348
353
  .selectAll()
@@ -379,6 +384,7 @@ let PermissionCallGrants = class PermissionCallGrants {
379
384
  .selectFrom("permission_call_grants")
380
385
  .selectAll()
381
386
  .where("id", "=", intent.permission_grant_id)
387
+ .where("org_id", "=", intent.org_id)
382
388
  .executeTakeFirstOrThrow();
383
389
  const admittedScope = intent.scope;
384
390
  if (!("profileRevision" in admittedScope) ||
@@ -53,6 +53,8 @@ let PermissionCeilingWrites = class PermissionCeilingWrites {
53
53
  })))
54
54
  .execute();
55
55
  if (deviceIds.length) {
56
+ // org-filter: platform-level writer under the exclusive platform lock: the devices whose
57
+ // Full reach changed may lie in any org, each root is reset in its own org
56
58
  const roots = await this.db
57
59
  .selectFrom("conversations")
58
60
  .selectAll()
@@ -131,12 +133,14 @@ let PermissionCeilingWrites = class PermissionCeilingWrites {
131
133
  updated_at: new Date(),
132
134
  })
133
135
  .where("operation_id", "=", row.operation_id)
136
+ .where("org_id", "=", row.org_id)
134
137
  .execute();
135
138
  if (row.state === "background-running")
136
139
  await this.db
137
140
  .updateTable("background_tasks")
138
141
  .set({ launch_state: "cancel-pending", cancel_requested_at: new Date() })
139
142
  .where("operation_id", "=", row.operation_id)
143
+ .where("org_id", "=", row.org_id)
140
144
  .where("launch_state", "=", "acknowledged")
141
145
  .execute();
142
146
  await this.outbox.add({
@@ -157,6 +161,7 @@ let PermissionCeilingWrites = class PermissionCeilingWrites {
157
161
  permission_revision: revision,
158
162
  })
159
163
  .where("id", "=", root.id)
164
+ .where("org_id", "=", root.org_id)
160
165
  .execute();
161
166
  await this.transitions.recordLocked({
162
167
  orgId: root.org_id,
@@ -320,6 +320,8 @@ let PermissionConfigPublication = class PermissionConfigPublication {
320
320
  // a B1 snapshot an older replica wrote after migration 0167 becomes the device's own network
321
321
  // at every activation, before anything reads it (as 0165 and 0167 copy it: never wider)
322
322
  await copyCloudSnapshotNetworks(this.db.db);
323
+ // org-filter: platform publication under the platform write lock: pins devices of every org,
324
+ // each judged against its own org's settings
323
325
  if (pinDevices) {
324
326
  const stored = await readStoredDeviceSandbox(this.db.db, this.log, configuredCeiling);
325
327
  const view = resolveDeviceSandboxSettings(configuredView(projection), stored);
@@ -403,6 +405,7 @@ let PermissionConfigPublication = class PermissionConfigPublication {
403
405
  const orgs = await this.db.selectFrom("orgs").select(["id", "settings"]).execute();
404
406
  const settings = new Map(orgs.map((org) => [org.id, orgDeviceSandboxOf(org.settings).deviceNetwork]));
405
407
  // the kill switch lifted is a widening for every device (closing it only narrows)
408
+ // org-filter: platform publication: the kill switch is deployment-wide, every org's devices
406
409
  if (before.egress === "none" && next.egress !== "none")
407
410
  await this.ceilings.invalidateDeviceConsentUnderPlatform((await this.db.selectFrom("devices").select("id").execute()).map((device) => device.id));
408
411
  // a network ceiling narrowed to the allowlist, or closed by the kill switch, takes running
@@ -482,6 +485,7 @@ export { PermissionConfigPublication };
482
485
  * permission locks), so the publication must never hold the platform lock while it waits for a
483
486
  * device row.
484
487
  */
488
+ // org-filter: platform publication: locks the devices of every org that follow their org
485
489
  export async function lockDevicesFollowingTheirOrg(db) {
486
490
  await db
487
491
  .selectFrom("devices")
@@ -497,6 +501,7 @@ export async function lockDevicesFollowingTheirOrg(db) {
497
501
  * stays that allowlist, an empty or unreadable one ran closed and becomes `none`; an open snapshot
498
502
  * follows the org. Idempotent: only rows still following the org are written.
499
503
  */
504
+ // org-filter: deployment-wide idempotent copy (migrations 0165/0167, publication) over every org
500
505
  export async function copyCloudSnapshotNetworks(db) {
501
506
  const readable = sql `jsonb_typeof(outer_network -> 'hosts') = 'array'
502
507
  AND NOT EXISTS (
@@ -54,6 +54,7 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
54
54
  .selectFrom("device_instances")
55
55
  .select(["generation", "permission_roots"])
56
56
  .where("device_id", "=", deviceId)
57
+ .where("org_id", "=", orgId)
57
58
  .forUpdate()
58
59
  .executeTakeFirst();
59
60
  if (!row || row.generation !== generation)
@@ -74,6 +75,7 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
74
75
  generation: generation + 1,
75
76
  })
76
77
  .where("device_id", "=", deviceId)
78
+ .where("org_id", "=", orgId)
77
79
  .where("generation", "=", generation)
78
80
  .returning("created_at")
79
81
  .executeTakeFirst();
@@ -171,6 +173,8 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
171
173
  .execute();
172
174
  return next;
173
175
  }
176
+ // org-filter: only reached from commitHandle, which locked this device row by its org first;
177
+ // the mark must count every recorded generation of the device
174
178
  async initialHighWater(deviceId) {
175
179
  const [instance, intents, tasks, reports] = await Promise.all([
176
180
  this.db
@@ -92,6 +92,8 @@ export function supportOf(value) {
92
92
  }
93
93
  }
94
94
  /** The revision of the device's stored report (`devices.report`), or null when none is stored. */
95
+ // org-filter: device-id helper; every caller (PermissionFacts, SandboxService) first read this
96
+ // device with its org filter, so the id is already proven to be the caller's org
95
97
  async function storedReportRevision(db, deviceId) {
96
98
  const row = await db
97
99
  .selectFrom("devices")
@@ -145,6 +147,8 @@ export async function readRuntimeReport(db, deviceId, provider, version) {
145
147
  * current, which names the installed evidence) and the support it recorded (null unless it is
146
148
  * current), whatever availability that support gives.
147
149
  */
150
+ // org-filter: device-id helper; every caller (PermissionFacts, SandboxService) first read this
151
+ // device with its org filter, so the id is already proven to be the caller's org
148
152
  export async function readCurrentReport(db, deviceId, provider, version) {
149
153
  const unprobed = {
150
154
  availability: unprobedPermissionAvailability(),
@@ -215,6 +219,8 @@ export async function readCurrentReport(db, deviceId, provider, version) {
215
219
  * applied limits) but no current report is recorded for it (none yet, or one recorded under an
216
220
  * earlier report revision). Database reads only.
217
221
  */
222
+ // org-filter: device-id helper; every caller (PermissionFacts, SandboxService) first read this
223
+ // device with its org filter, so the id is already proven to be the caller's org
218
224
  export async function reportOwed(db, deviceId, provider, version) {
219
225
  if (!version)
220
226
  return false;
@@ -320,7 +326,10 @@ __decorate([
320
326
  Transactional({ propagation: "mandatory" })
321
327
  ], PermissionRuntimeReports.prototype, "clearSupport", null);
322
328
  PermissionRuntimeReports = __decorate([
323
- Injectable(),
329
+ Injectable()
330
+ // org-filter: every write asserts the device authority writer lock held exclusively, which
331
+ // PermissionAuthorityLock.acquire grants only after checking the device belongs to the subject org
332
+ ,
324
333
  __param(0, Inject(KernelDb)),
325
334
  __param(1, Inject(TransactionHost)),
326
335
  __param(2, Inject(PermissionAuthorityLock))
@@ -62,6 +62,7 @@ let PermissionTransitions = class PermissionTransitions {
62
62
  .selectFrom("conversations")
63
63
  .select("id")
64
64
  .where("id", "=", change.rootConversationId)
65
+ .where("org_id", "=", change.orgId)
65
66
  .unionAll((q) => q
66
67
  .selectFrom("conversations as c")
67
68
  .innerJoin("tree", "tree.id", "c.parent_conversation_id")
@@ -70,6 +71,7 @@ let PermissionTransitions = class PermissionTransitions {
70
71
  .selectFrom("conversations")
71
72
  .select("id")
72
73
  .where("id", "in", (q) => q.selectFrom("tree").select("id"))
74
+ .where("org_id", "=", change.orgId)
73
75
  .orderBy("id")
74
76
  .forUpdate()
75
77
  .execute();
@@ -111,6 +113,7 @@ let PermissionTransitions = class PermissionTransitions {
111
113
  superseded_reason: change.reason,
112
114
  })
113
115
  .where("id", "=", card.id)
116
+ .where("org_id", "=", orgId)
114
117
  .execute();
115
118
  const cardEvents = await this.events.appendIn(card.conversation_id, [
116
119
  {