@capybara-hq/kernel 0.1.0-rc.76 → 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 (230) 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 +36 -4
  100. package/dist/extensions/bootstrap.js +103 -16
  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/skill-load.d.ts +10 -9
  214. package/dist/tools/builtins/skill-load.js +15 -19
  215. package/dist/tools/builtins/web/fetch.js +1 -1
  216. package/dist/tools/builtins/web/search.js +1 -1
  217. package/dist/tools/connector-account-policies.js +3 -0
  218. package/dist/tools/connectors.controller.d.ts +20 -8
  219. package/dist/tools/connectors.controller.js +30 -12
  220. package/dist/tools/connectors.service.d.ts +8 -0
  221. package/dist/tools/connectors.service.js +21 -1
  222. package/dist/tools/drift.js +5 -0
  223. package/dist/tools/git-push-policy.js +3 -0
  224. package/dist/tools/oauth/flow.js +1 -0
  225. package/dist/tools/outputs.js +2 -0
  226. package/dist/tools/permission-approval-jobs.js +3 -0
  227. package/dist/tools/pipeline.js +2 -0
  228. package/dist/tools/policy.js +3 -0
  229. package/dist/tools/questions.service.js +13 -0
  230. package/package.json +3 -3
@@ -140,6 +140,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
140
140
  (await t
141
141
  .selectFrom("conversations")
142
142
  .select("id")
143
+ .where("org_id", "=", tr.org_id)
143
144
  .where("scheduled_task_id", "=", tr.task_id)
144
145
  .where("create_request_id", "=", tr.id)
145
146
  .executeTakeFirst())?.id;
@@ -157,6 +158,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
157
158
  .updateTable("scheduled_task_runs")
158
159
  .set({ status: "running", run_id: run.id, conversation_id: conv })
159
160
  .where("id", "=", tr.id)
161
+ .where("org_id", "=", tr.org_id)
160
162
  .execute();
161
163
  if (!RUN_TERMINAL.has(run.status))
162
164
  return true;
@@ -176,6 +178,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
176
178
  .selectFrom("conversations")
177
179
  .select("consumed_seq")
178
180
  .where("id", "=", conv)
181
+ .where("org_id", "=", tr.org_id)
179
182
  .executeTakeFirst();
180
183
  // posted, its run still to be created (`ensureRun`)
181
184
  if (c === undefined || Number(message.seq) > Number(c.consumed_seq))
@@ -193,6 +196,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
193
196
  .updateTable("scheduled_task_runs")
194
197
  .set({ status: "skipped", skip_reason: "removed", fired_at: null })
195
198
  .where("id", "=", tr.id)
199
+ .where("org_id", "=", tr.org_id)
196
200
  .where("status", "=", "pending")
197
201
  .execute();
198
202
  return false;
@@ -228,6 +232,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
228
232
  ...(failed && { error: error ?? "The run failed" }),
229
233
  })
230
234
  .where("id", "=", tr.id)
235
+ .where("org_id", "=", tr.org_id)
231
236
  .execute();
232
237
  await this.push.oweScheduleRun(tr.id, tr.org_id);
233
238
  if (tr.trial)
@@ -237,6 +242,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
237
242
  .updateTable("scheduled_tasks")
238
243
  .set({ consecutive_failures: 0 })
239
244
  .where("id", "=", tr.task_id)
245
+ .where("org_id", "=", tr.org_id)
240
246
  .where("consecutive_failures", "!=", 0)
241
247
  .execute();
242
248
  return;
@@ -245,6 +251,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
245
251
  .updateTable("scheduled_tasks")
246
252
  .set({ consecutive_failures: sql `consecutive_failures + 1` })
247
253
  .where("id", "=", tr.task_id)
254
+ .where("org_id", "=", tr.org_id)
248
255
  .where("deleted_at", "is", null)
249
256
  .returning("consecutive_failures")
250
257
  .executeTakeFirst();
@@ -266,7 +273,10 @@ __decorate([
266
273
  Transactional({ propagation: "mandatory" })
267
274
  ], ScheduledTaskRunTracker.prototype, "failStartIn", null);
268
275
  ScheduledTaskRunTracker = __decorate([
269
- Injectable(),
276
+ Injectable()
277
+ // org-filter: kernel-internal (run finish, fire job, settle job): task run ids come from a kernel
278
+ // run's scheduled_task_run_id or from a task run row the caller already holds, never from input
279
+ ,
270
280
  __param(0, Inject(KernelDb)),
271
281
  __param(1, Inject(TransactionHost)),
272
282
  __param(2, Inject(KernelConfigService)),
@@ -279,6 +289,8 @@ export { ScheduledTaskRunTracker };
279
289
  * transaction (`RunQueue.ensureRunIn`, which inserts the run). A task run already linked (a
280
290
  * sub-agent or wake run inheriting the marker) is left alone.
281
291
  */
292
+ // org-filter: the task run id is the kernel-written schedule marker of the run's trigger message
293
+ // (scheduledTaskRunAt), set only through the kernel-internal schedule option, never by a person
282
294
  export async function linkStartedRunIn(t, taskRunId, runId, conversationId) {
283
295
  await t
284
296
  .updateTable("scheduled_task_runs")
@@ -297,6 +309,8 @@ export async function linkStartedRunIn(t, taskRunId, runId, conversationId) {
297
309
  * marker, or null): its task run will never run as the task's, so it becomes `skipped`
298
310
  * (`removed`) in the caller's transaction, and the next tick is not held by the overlap check.
299
311
  */
312
+ // org-filter: the marker is the queued item's stored schedule column, written only through the
313
+ // kernel-internal schedule option of the queue (never from a request body)
300
314
  export async function releaseQueuedTaskRunIn(t, schedule) {
301
315
  const taskRunId = schedule?.taskRunId;
302
316
  if (typeof taskRunId !== "string")
@@ -314,6 +328,7 @@ export async function releaseQueuedTaskRunIn(t, schedule) {
314
328
  * run and the task takes the task row first: the fire job's claim, the run tracker, the scan's
315
329
  * repair (a run finishing while the next tick's claim checks overlap must not deadlock).
316
330
  */
331
+ // org-filter: a row lock by the task id of a task or task run row the kernel caller already holds
317
332
  export async function lockTaskRow(t, taskId) {
318
333
  await t
319
334
  .selectFrom("scheduled_tasks")
@@ -370,7 +370,7 @@ let ScheduledTasksService = class ScheduledTasksService {
370
370
  if (opts.conversationId !== undefined) {
371
371
  tasks = await this.postingInto(orgId, tasks, opts.conversationId);
372
372
  }
373
- return this.withLastRuns(tasks);
373
+ return this.withLastRuns(orgId, tasks);
374
374
  }
375
375
  /**
376
376
  * The calendar between two instants (calendar spec §5): the runs and planned occurrences of the
@@ -445,7 +445,7 @@ let ScheduledTasksService = class ScheduledTasksService {
445
445
  chats.some((c) => c.connection_id === t.chat?.connectionId && c.chat_id === t.chat.chatId));
446
446
  }
447
447
  /** Each task with its latest settled non-trial run, in one query. */
448
- async withLastRuns(plain) {
448
+ async withLastRuns(orgId, plain) {
449
449
  if (plain.length === 0)
450
450
  return [];
451
451
  const tasks = await this.withAccounts(plain);
@@ -453,6 +453,7 @@ let ScheduledTasksService = class ScheduledTasksService {
453
453
  .selectFrom("scheduled_task_runs")
454
454
  .select(["task_id", "status", "skip_reason", "fired_at", "scheduled_for"])
455
455
  .distinctOn("task_id")
456
+ .where("org_id", "=", orgId)
456
457
  .where("task_id", "in", tasks.map((t) => t.id))
457
458
  .where("trial", "=", false)
458
459
  .where("status", "in", ["completed", "failed", "skipped"])
@@ -641,6 +642,7 @@ let ScheduledTasksService = class ScheduledTasksService {
641
642
  .selectFrom("scheduled_task_runs")
642
643
  .select(["task_id", "fired_at", "scheduled_for", "missing_grants", "status", "error"])
643
644
  .distinctOn("task_id")
645
+ .where("org_id", "=", orgId)
644
646
  .where("task_id", "in", ids)
645
647
  .where("trial", "=", false)
646
648
  .where("status", "<>", "skipped")
@@ -147,6 +147,8 @@ let ScheduledTaskStore = class ScheduledTaskStore {
147
147
  return row ? toTask(row) : null;
148
148
  }
149
149
  /** Patches a live task; null when it is missing or deleted. */
150
+ // org-filter: by the id of a task its caller loaded under an org filter (lockManaged / lockTask)
151
+ // or locked in the scan's deployment-wide due sweep
150
152
  async updateTask(t, id, patch) {
151
153
  const row = await t
152
154
  .updateTable("scheduled_tasks")
@@ -158,6 +160,7 @@ let ScheduledTaskStore = class ScheduledTaskStore {
158
160
  return row ? toTask(row) : null;
159
161
  }
160
162
  /** Deletes a task softly: hidden from every read and never due again. */
163
+ // org-filter: by the id of a task its caller locked under an org filter (lockManaged)
161
164
  async softDelete(t, id) {
162
165
  const r = await t
163
166
  .updateTable("scheduled_tasks")
@@ -210,6 +213,7 @@ let ScheduledTaskStore = class ScheduledTaskStore {
210
213
  * rows another transaction holds (`FOR UPDATE SKIP LOCKED`). Call it inside a transaction: the
211
214
  * locks last until it ends.
212
215
  */
216
+ // org-filter: the scan's deployment-wide due-task sweep (LockedCron), each task fired in its own org
213
217
  async lockDue(t, now, limit) {
214
218
  const rows = await t
215
219
  .selectFrom("scheduled_tasks")
@@ -250,6 +254,8 @@ let ScheduledTaskStore = class ScheduledTaskStore {
250
254
  return row ? toRun(row) : null;
251
255
  }
252
256
  /** Patches a task run; null when it does not exist. */
257
+ // org-filter: by task run id for the fire / settle jobs only; the id is the kernel-written job
258
+ // payload or a run row the job already holds, never caller input
253
259
  async updateRun(t, id, patch) {
254
260
  const c = {};
255
261
  if (patch.scheduledFor !== undefined)
@@ -288,6 +294,7 @@ let ScheduledTaskStore = class ScheduledTaskStore {
288
294
  * The task's latest run still `pending` or `running` (the overlap check), other than `exceptId`
289
295
  * (the run being fired); null when none.
290
296
  */
297
+ // org-filter: the fire job's overlap check, by the task id of the run it claimed
291
298
  async latestNonTerminalRun(t, taskId, exceptId) {
292
299
  let q = t
293
300
  .selectFrom("scheduled_task_runs")
@@ -318,6 +325,7 @@ let ScheduledTaskStore = class ScheduledTaskStore {
318
325
  return Number(row.n);
319
326
  }
320
327
  /** A task's runs, latest tick first. */
328
+ // org-filter: by the id of a task its caller read under an org filter (ScheduledTasksService.get)
321
329
  async listRuns(t, taskId, limit) {
322
330
  const rows = await t
323
331
  .selectFrom("scheduled_task_runs")
@@ -42,6 +42,7 @@ export async function scheduledTaskRunAt(t, conversationId, seq) {
42
42
  runId = p.dispatch.parentRunId;
43
43
  }
44
44
  else if (ev.type === "background_task_finished" && typeof p.taskId === "string") {
45
+ // org-filter: the task id is the kernel-written event payload, scoped by its conversation_id
45
46
  const task = await t
46
47
  .selectFrom("background_tasks")
47
48
  .select("run_id")
@@ -165,6 +166,7 @@ export async function taskGrantsRunOf(db, runId) {
165
166
  return null;
166
167
  if (await personJoined(db, runId))
167
168
  return null;
169
+ // org-filter: the task id is read from the kernel run's own scheduled_task_run_id, never input
168
170
  const task = await db
169
171
  .selectFrom("scheduled_tasks")
170
172
  .select(["id", "account_id", "org_id"])
@@ -177,6 +179,8 @@ export async function taskGrantsRunOf(db, runId) {
177
179
  * Appends a key to a task run's `missing_grants` (a tool key, or `connection:<slug>`), once: one
178
180
  * atomic update, so parallel calls of a run and of its sub-agents never lose or repeat a key.
179
181
  */
182
+ // org-filter: callers pass the task run id of the kernel run's own unattended context
183
+ // (PolicyContext.unattended, from runs.scheduled_task_run_id), never a caller-supplied id
180
184
  export async function appendMissingGrant(db, taskRunId, key) {
181
185
  await db
182
186
  .updateTable("scheduled_task_runs")
@@ -2,7 +2,6 @@ import type { Redis } from "ioredis";
2
2
  import { ChannelConnections } from "../channels/connections.service.js";
3
3
  import type { Keyring } from "../ctx/secrets.js";
4
4
  import { EffectiveConfigs } from "../extensions/effective-config.js";
5
- import { OrgExtensionConfigs } from "../extensions/org-config.js";
6
5
  import { PluginGuides } from "../extensions/plugin-guides.js";
7
6
  import { ExtensionRegistry } from "../extensions/registry.js";
8
7
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -57,12 +56,11 @@ export declare class SetupChecksService {
57
56
  private readonly registry;
58
57
  private readonly extensions;
59
58
  private readonly effective;
60
- private readonly orgConfigs;
61
59
  private readonly channels;
62
60
  private readonly credentials;
63
61
  private readonly log;
64
62
  private readonly timeoutMs;
65
- constructor(db: KernelDb, redis: Pick<Redis, "get" | "set" | "pttl" | "mget" | "exists" | "eval">, locks: Pick<LockService, "lease" | "releaseIf" | "takeSlot" | "releaseSlot">, keyring: Keyring, guides: Pick<PluginGuides, "render" | "renderForDeployment">, registry: SetupCheckRegistry, extensions: Pick<ExtensionRegistry, "current">, effective: Pick<EffectiveConfigs, "get">, orgConfigs: Pick<OrgExtensionConfigs, "get">, channels: Pick<ChannelConnections, "checkRevision" | "checkSecrets" | "runtime">, credentials: Pick<Credentials, "checkRevision" | "checkMaterial">, log: Pick<KernelLogger, "warn">, timeoutMs?: number);
63
+ constructor(db: KernelDb, redis: Pick<Redis, "get" | "set" | "pttl" | "mget" | "exists" | "eval">, locks: Pick<LockService, "lease" | "releaseIf" | "takeSlot" | "releaseSlot">, keyring: Keyring, guides: Pick<PluginGuides, "render" | "renderForDeployment">, registry: SetupCheckRegistry, extensions: Pick<ExtensionRegistry, "current">, effective: Pick<EffectiveConfigs, "get">, channels: Pick<ChannelConnections, "checkRevision" | "checkSecrets" | "runtime">, credentials: Pick<Credentials, "checkRevision" | "checkMaterial">, log: Pick<KernelLogger, "warn">, timeoutMs?: number);
66
64
  /**
67
65
  * The cached state of every check of the rendered guide (`GET …/checks`), by check id; nothing
68
66
  * runs. `not_run` without a fresh result for the current input fingerprint; `running` while a
@@ -165,13 +163,6 @@ export declare class SetupChecksService {
165
163
  private material;
166
164
  /** The secret values of the extension's platform and effective deployment config. */
167
165
  private configSecrets;
168
- /**
169
- * The secret values of the extension's org-level config (`config.org`) in the org: the check
170
- * never gets them, but the extension holds them, so a result is redacted by them too. Nothing
171
- * when the plugin has no org config; a read that fails throws (the check is not run: a result
172
- * is never redacted by fewer secrets than the extension holds).
173
- */
174
- private orgConfigSecrets;
175
166
  /** The frozen arguments of a plugin check (the target built field by field). */
176
167
  private pluginArgs;
177
168
  }
@@ -17,7 +17,6 @@ import { canonicalJson } from "../extensions/config-hash.js";
17
17
  import { EffectiveConfigs } from "../extensions/effective-config.js";
18
18
  import { isExtensionEnabled } from "../extensions/enabled.js";
19
19
  import { deepFreeze } from "../extensions/hooks.js";
20
- import { OrgExtensionConfigs } from "../extensions/org-config.js";
21
20
  import { PluginGuides } from "../extensions/plugin-guides.js";
22
21
  import { ExtensionRegistry } from "../extensions/registry.js";
23
22
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -119,12 +118,11 @@ let SetupChecksService = class SetupChecksService {
119
118
  registry;
120
119
  extensions;
121
120
  effective;
122
- orgConfigs;
123
121
  channels;
124
122
  credentials;
125
123
  log;
126
124
  timeoutMs;
127
- constructor(db, redis, locks, keyring, guides, registry, extensions, effective, orgConfigs, channels, credentials, log, timeoutMs = SETUP_CHECK_LIMITS.timeoutMs) {
125
+ constructor(db, redis, locks, keyring, guides, registry, extensions, effective, channels, credentials, log, timeoutMs = SETUP_CHECK_LIMITS.timeoutMs) {
128
126
  this.db = db;
129
127
  this.redis = redis;
130
128
  this.locks = locks;
@@ -133,7 +131,6 @@ let SetupChecksService = class SetupChecksService {
133
131
  this.registry = registry;
134
132
  this.extensions = extensions;
135
133
  this.effective = effective;
136
- this.orgConfigs = orgConfigs;
137
134
  this.channels = channels;
138
135
  this.credentials = credentials;
139
136
  this.log = log;
@@ -401,7 +398,18 @@ let SetupChecksService = class SetupChecksService {
401
398
  if (!(await isExtensionEnabled(this.db.db, orgId, plugin))) {
402
399
  return { state: unknownState(REASONS.disabled(plugin)) };
403
400
  }
404
- const eff = await this.effective.get(orgId, plugin);
401
+ let eff;
402
+ try {
403
+ eff = await this.effective.get(orgId, plugin);
404
+ }
405
+ catch (err) {
406
+ // fail closed: nothing runs and nothing is cached; the error is logged, never echoed
407
+ this.log.warn("setup checks: cannot read the effective config", {
408
+ plugin,
409
+ err: describeCheckError(err, (s) => s),
410
+ });
411
+ return { state: unknownState(REASONS.unavailable) };
412
+ }
405
413
  if (!eff.ok) {
406
414
  return {
407
415
  state: unknownState(eff.notRunning ? REASONS.notRunning(plugin) : REASONS.needsConfig(plugin)),
@@ -525,11 +533,7 @@ let SetupChecksService = class SetupChecksService {
525
533
  const material = await this.material(p, check);
526
534
  if ("result" in material)
527
535
  return material.result;
528
- const secrets = [
529
- ...material.secrets,
530
- ...this.configSecrets(p.plugin, config),
531
- ...(p.orgId === null ? [] : await this.orgConfigSecrets(p.orgId, p.plugin)),
532
- ];
536
+ const secrets = [...material.secrets, ...this.configSecrets(p.plugin, config)];
533
537
  const redact = checkRedactor(secrets);
534
538
  const fields = { plugin: p.plugin, checkId: check.id, orgId: p.orgId };
535
539
  const timeout = AbortSignal.timeout(this.timeoutMs);
@@ -665,19 +669,6 @@ let SetupChecksService = class SetupChecksService {
665
669
  ...(effective === undefined ? [] : secretValues(schema, effective)),
666
670
  ];
667
671
  }
668
- /**
669
- * The secret values of the extension's org-level config (`config.org`) in the org: the check
670
- * never gets them, but the extension holds them, so a result is redacted by them too. Nothing
671
- * when the plugin has no org config; a read that fails throws (the check is not run: a result
672
- * is never redacted by fewer secrets than the extension holds).
673
- */
674
- async orgConfigSecrets(orgId, plugin) {
675
- const schema = this.extensions.current(plugin)?.manifest.config?.org;
676
- if (!schema)
677
- return [];
678
- const c = await this.orgConfigs.get(orgId, plugin);
679
- return c?.config == null ? [] : secretValues(schema, c.config);
680
- }
681
672
  /** The frozen arguments of a plugin check (the target built field by field). */
682
673
  pluginArgs(p, m, config, locale, signal) {
683
674
  if (p.orgId === null) {
@@ -730,12 +721,11 @@ SetupChecksService = __decorate([
730
721
  __param(5, Inject(SetupCheckRegistry)),
731
722
  __param(6, Inject(ExtensionRegistry)),
732
723
  __param(7, Inject(EffectiveConfigs)),
733
- __param(8, Inject(OrgExtensionConfigs)),
734
- __param(9, Inject(ChannelConnections)),
735
- __param(10, Inject(Credentials)),
736
- __param(11, Inject(KERNEL_LOGGER)),
737
- __param(12, Optional()),
738
- __param(12, Inject(SETUP_CHECK_TIMEOUT))
724
+ __param(8, Inject(ChannelConnections)),
725
+ __param(9, Inject(Credentials)),
726
+ __param(10, Inject(KERNEL_LOGGER)),
727
+ __param(11, Optional()),
728
+ __param(11, Inject(SETUP_CHECK_TIMEOUT))
739
729
  ], SetupChecksService);
740
730
  export { SetupChecksService };
741
731
  /** The kernel check's target: ids and the plugin only. */
@@ -260,6 +260,7 @@ let ShareOpenService = class ShareOpenService {
260
260
  .updateTable("file_shares")
261
261
  .set({ last_opened_at: sql `now()` })
262
262
  .where("id", "=", share.id)
263
+ .where("org_id", "=", share.orgId)
263
264
  .execute();
264
265
  await audit(this.db.db, {
265
266
  actorAccountId: share.audience === "internal" ? opened.viewerAccountId : null,
@@ -260,6 +260,7 @@ let SharesService = class SharesService {
260
260
  updated_at: sql `now()`,
261
261
  })
262
262
  .where("id", "=", at.shareId)
263
+ .where("org_id", "=", at.orgId)
263
264
  .execute();
264
265
  if (row.object_key !== null)
265
266
  await this.oweDelete(at.orgId, at.shareId, at.from);
@@ -321,6 +322,7 @@ let SharesService = class SharesService {
321
322
  updated_at: sql `now()`,
322
323
  })
323
324
  .where("id", "=", shareId)
325
+ .where("org_id", "=", orgId)
324
326
  .execute();
325
327
  if (s.object_key !== null)
326
328
  await this.oweDelete(orgId, shareId, s.generation);
@@ -81,7 +81,7 @@ export declare function keyShareOrg(db: KernelDb, orgId: string): Promise<void>;
81
81
  * The cap on new agent skills: at {@link AGENT_SKILLS_MAX} live own skills -> 409
82
82
  * `skill.agent_cap`. Runs in the caller's transaction.
83
83
  */
84
- export declare function assertBelowAgentSkillCap(db: KernelDb, agentId: string): Promise<void>;
84
+ export declare function assertBelowAgentSkillCap(db: KernelDb, orgId: string, agentId: string): Promise<void>;
85
85
  /** Writes a version of an agent skill and points `current_version` at it (creating the skill). */
86
86
  export declare function createAgentSkillVersion(db: KernelDb, v: {
87
87
  orgId: string;
@@ -76,6 +76,8 @@ export async function assertShareableName(db, orgId, name) {
76
76
  * org owns it, `agent_id` is cleared, the agent it came from and its maintainer are recorded.
77
77
  * Its versions stay.
78
78
  */
79
+ // org-filter: skillId is the skill row the caller read with its org filter and locked FOR UPDATE
80
+ // in this same transaction (AgentSkillsService.shareIn, SkillChangesService.decideIn)
79
81
  export async function shareSkillIn(db, v) {
80
82
  await db
81
83
  .updateTable("skills")
@@ -124,10 +126,11 @@ export async function keyShareOrg(db, orgId) {
124
126
  * The cap on new agent skills: at {@link AGENT_SKILLS_MAX} live own skills -> 409
125
127
  * `skill.agent_cap`. Runs in the caller's transaction.
126
128
  */
127
- export async function assertBelowAgentSkillCap(db, agentId) {
129
+ export async function assertBelowAgentSkillCap(db, orgId, agentId) {
128
130
  const skills = await db
129
131
  .selectFrom("skills")
130
132
  .select((eb) => eb.fn.countAll().as("n"))
133
+ .where("org_id", "=", orgId)
131
134
  .where("scope", "=", "agent")
132
135
  .where("agent_id", "=", agentId)
133
136
  .where("deleted_at", "is", null)
@@ -147,6 +150,7 @@ export async function createAgentSkillVersion(db, v) {
147
150
  updated_at: sql `now()`,
148
151
  })
149
152
  .where("id", "=", v.skillId)
153
+ .where("org_id", "=", v.orgId)
150
154
  .execute();
151
155
  }
152
156
  else {
@@ -360,6 +364,7 @@ let AgentSkillsService = class AgentSkillsService {
360
364
  .selectFrom("agents")
361
365
  .select("id")
362
366
  .where("id", "=", agentId)
367
+ .where("org_id", "=", orgId)
363
368
  .where(visibleTo(accountId))
364
369
  .executeTakeFirst();
365
370
  if (!visible)
@@ -452,6 +457,7 @@ let AgentSkillsService = class AgentSkillsService {
452
457
  const proposals = (skillId) => this.db
453
458
  .selectFrom("skill_change_requests")
454
459
  .selectAll()
460
+ .where("org_id", "=", actor.orgId)
455
461
  .where("skill_id", "=", skillId)
456
462
  .where("kind", "=", "version")
457
463
  .where("status", "=", "pending");
@@ -463,6 +469,7 @@ let AgentSkillsService = class AgentSkillsService {
463
469
  .selectFrom("conversations")
464
470
  .select("id")
465
471
  .where("id", "in", convs)
472
+ .where("org_id", "=", actor.orgId)
466
473
  .orderBy("id")
467
474
  .forUpdate()
468
475
  .execute();
@@ -565,7 +572,7 @@ let AgentSkillsService = class AgentSkillsService {
565
572
  if (shared)
566
573
  return this.proposeIn(actor, pkg, manifest, prefix, shared);
567
574
  await this.assertNoUsedOrgSkillNamed(actor, pkg.name);
568
- await assertBelowAgentSkillCap(this.db, actor.agentId);
575
+ await assertBelowAgentSkillCap(this.db, actor.orgId, actor.agentId);
569
576
  }
570
577
  else {
571
578
  // A pending share was for the version the admins review: a new version supersedes it (the
@@ -573,6 +580,7 @@ let AgentSkillsService = class AgentSkillsService {
573
580
  const shares = await this.db
574
581
  .selectFrom("skill_change_requests")
575
582
  .selectAll()
583
+ .where("org_id", "=", actor.orgId)
576
584
  .where("skill_id", "=", existing.id)
577
585
  .where("kind", "=", "share")
578
586
  .where("status", "=", "pending")
@@ -654,6 +662,7 @@ let AgentSkillsService = class AgentSkillsService {
654
662
  .onRef("agent_versions.version", "=", "agents.current_version"))
655
663
  .select("agent_versions.definition")
656
664
  .where("agents.id", "=", actor.agentId)
665
+ .where("agents.org_id", "=", actor.orgId)
657
666
  .executeTakeFirst();
658
667
  const disabledSkills = def === undefined ? [] : (normalizeStoredDefinition(def.definition).disabledSkills ?? []);
659
668
  const used = (await agentSkills(this.db.db, {
@@ -818,6 +827,7 @@ let AgentSkillsService = class AgentSkillsService {
818
827
  const pending = await this.db
819
828
  .selectFrom("skill_change_requests")
820
829
  .select("id")
830
+ .where("org_id", "=", actor.orgId)
821
831
  .where("skill_id", "=", skillId)
822
832
  .where("kind", "=", "share")
823
833
  .where("status", "=", "pending")
@@ -886,6 +896,7 @@ let AgentSkillsService = class AgentSkillsService {
886
896
  const pend = await this.db
887
897
  .selectFrom("skill_change_requests")
888
898
  .selectAll()
899
+ .where("org_id", "=", orgId)
889
900
  .where("agent_id", "=", agentId)
890
901
  .where("status", "=", "pending")
891
902
  .where(sql `proposed_version -> 'manifest' ->> 'name'`, "=", r.name)
@@ -230,6 +230,9 @@ export const skillsCatalogIdemKey = (runId) => `skills_catalog:${runId}`;
230
230
  * `db` is the caller's transaction handle (`KernelDb.db` inside `@Transactional`).
231
231
  * 「读最新 → 推出下一份 → 追加」都在这把锁内,别的写快照的事务(运行开始、技能注册、拒绝时的回退)插不进来。
232
232
  */
233
+ // org-filter: conversationId is the run's own conversation (run start) or one the callers checked
234
+ // in their org first (AgentSkillsService.lockConversation, a request row of the org); this takes
235
+ // the same row lock EventLog.append takes
233
236
  export async function lockLatestCatalog(db, conversationId) {
234
237
  await db
235
238
  .selectFrom("conversations")
@@ -150,6 +150,7 @@ let SkillChangesService = class SkillChangesService {
150
150
  .selectFrom("agents")
151
151
  .select(["owner_account_id", "deleted_at"])
152
152
  .where("id", "=", head.agent_id)
153
+ .where("org_id", "=", orgId)
153
154
  .forNoKeyUpdate()
154
155
  .executeTakeFirst();
155
156
  if (head.kind === "version" && head.requested_in_conversation !== null) {
@@ -157,6 +158,7 @@ let SkillChangesService = class SkillChangesService {
157
158
  .selectFrom("conversations")
158
159
  .select("id")
159
160
  .where("id", "=", head.requested_in_conversation)
161
+ .where("org_id", "=", orgId)
160
162
  .forUpdate()
161
163
  .executeTakeFirst();
162
164
  }
@@ -166,12 +168,14 @@ let SkillChangesService = class SkillChangesService {
166
168
  .selectFrom("skills")
167
169
  .select(["id", "scope", "agent_id", "name", "deleted_at", "current_version"])
168
170
  .where("id", "=", head.skill_id)
171
+ .where("org_id", "=", orgId)
169
172
  .forUpdate()
170
173
  .executeTakeFirst();
171
174
  const req = await this.db
172
175
  .selectFrom("skill_change_requests")
173
176
  .selectAll()
174
177
  .where("id", "=", id)
178
+ .where("org_id", "=", orgId)
175
179
  .forUpdate()
176
180
  .executeTakeFirst();
177
181
  // the row went between the first read and the lock (agent / org hard-deleted) -> 404, not 500
@@ -199,7 +203,7 @@ let SkillChangesService = class SkillChangesService {
199
203
  ...(actorTokenId !== undefined && { actorTokenId }),
200
204
  reason: "stale",
201
205
  });
202
- return { updated: await this.reread(id), drafts, usedOwner: false };
206
+ return { updated: await this.reread(orgId, id), drafts, usedOwner: false };
203
207
  }
204
208
  const p = req.proposed_version;
205
209
  const approved = body.decision === "approve";
@@ -266,6 +270,7 @@ let SkillChangesService = class SkillChangesService {
266
270
  decided_at: sql `now()`,
267
271
  })
268
272
  .where("id", "=", id)
273
+ .where("org_id", "=", orgId)
269
274
  .returningAll()
270
275
  .executeTakeFirstOrThrow();
271
276
  await audit(this.db.db, {
@@ -303,11 +308,12 @@ let SkillChangesService = class SkillChangesService {
303
308
  usedOwner: approved && req.kind === "version" && owner !== undefined,
304
309
  };
305
310
  }
306
- reread(id) {
311
+ reread(orgId, id) {
307
312
  return this.db
308
313
  .selectFrom("skill_change_requests")
309
314
  .selectAll()
310
315
  .where("id", "=", id)
316
+ .where("org_id", "=", orgId)
311
317
  .executeTakeFirstOrThrow();
312
318
  }
313
319
  /**
@@ -366,6 +372,7 @@ let SkillChangesService = class SkillChangesService {
366
372
  "skill_versions.object_prefix",
367
373
  ])
368
374
  .where("skills.id", "=", row.skill_id)
375
+ .where("skills.org_id", "=", orgId)
369
376
  .where("skills.deleted_at", "is", null)
370
377
  .executeTakeFirst();
371
378
  // the request is the current version itself (a share, an approved version): no "before"
@@ -428,6 +435,7 @@ let SkillChangesService = class SkillChangesService {
428
435
  if (rows.length === 0)
429
436
  return [];
430
437
  const agentIds = [...new Set(rows.map((r) => r.agent_id))];
438
+ // org-filter: the agent ids come from request rows the callers read with their org filter
431
439
  const agents = await this.db
432
440
  .selectFrom("agents")
433
441
  .innerJoin("agent_versions", (j) => j
@@ -114,6 +114,7 @@ export async function cancelRequestIn(deps, req, out, how) {
114
114
  .updateTable("skill_change_requests")
115
115
  .set({ status: "cancelled", decided_at: sql `now()` })
116
116
  .where("id", "=", req.id)
117
+ .where("org_id", "=", req.org_id)
117
118
  .execute();
118
119
  await audit(deps.db.db, {
119
120
  actorAccountId: how.actorAccountId,
@@ -300,6 +300,8 @@ const platformSummary = (r) => ({
300
300
  * Skills with their summary columns: the catalog item name (provenance) and the current version's
301
301
  * source format and manifest.
302
302
  */
303
+ // org-filter: a builder only; every caller adds the org filter or narrows to the id of a skill it
304
+ // read or wrote in its org just before
303
305
  const summaryQuery = (db) => db
304
306
  .selectFrom("skills as s")
305
307
  .leftJoin("catalog_items as i", "i.id", "s.catalog_item_id")
@@ -602,6 +604,7 @@ let SkillsService = class SkillsService {
602
604
  updated_at: sql `now()`,
603
605
  })
604
606
  .where("id", "=", id)
607
+ .where("org_id", "=", orgId)
605
608
  .execute();
606
609
  }
607
610
  else {
@@ -685,6 +688,7 @@ let SkillsService = class SkillsService {
685
688
  updated_at: sql `now()`,
686
689
  })
687
690
  .where("id", "=", skillId)
691
+ .where("org_id", "=", orgId)
688
692
  .execute();
689
693
  await this.db
690
694
  .deleteFrom("skill_versions")