@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38

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 (351) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -2
  3. package/dist/admin/admin.module.js +9 -5
  4. package/dist/admin/audit-log.service.d.ts +51 -0
  5. package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
  6. package/dist/admin/audit.controller.d.ts +18 -6
  7. package/dist/admin/audit.controller.js +36 -6
  8. package/dist/admin/audit.schemas.d.ts +9 -1
  9. package/dist/admin/audit.schemas.js +22 -2
  10. package/dist/admin/org-network.controller.d.ts +30 -0
  11. package/dist/admin/org-network.controller.js +77 -0
  12. package/dist/admin/org-network.schemas.d.ts +16 -0
  13. package/dist/admin/org-network.schemas.js +27 -0
  14. package/dist/admin/org-network.service.d.ts +41 -0
  15. package/dist/admin/org-network.service.js +101 -0
  16. package/dist/admin/outbox-dead.controller.d.ts +4 -6
  17. package/dist/admin/outbox-dead.controller.js +9 -6
  18. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  19. package/dist/admin/outbox-dead.schemas.js +25 -1
  20. package/dist/admin/outbox-dead.service.d.ts +16 -7
  21. package/dist/admin/outbox-dead.service.js +34 -10
  22. package/dist/admin/overview.service.d.ts +3 -3
  23. package/dist/admin/overview.service.js +0 -1
  24. package/dist/agents/agent-lookup.js +2 -10
  25. package/dist/agents/agents.service.js +9 -20
  26. package/dist/agents/definition.d.ts +3 -51
  27. package/dist/agents/definition.js +4 -254
  28. package/dist/agents/org-templates.js +2 -6
  29. package/dist/agents/readiness.controller.d.ts +4 -12
  30. package/dist/agents/readiness.controller.js +4 -12
  31. package/dist/agents/readiness.service.d.ts +23 -11
  32. package/dist/agents/readiness.service.js +31 -14
  33. package/dist/agents/templates.d.ts +0 -6
  34. package/dist/agents/templates.js +8 -34
  35. package/dist/background/store.d.ts +2 -0
  36. package/dist/background/store.js +3 -1
  37. package/dist/background/wake-rules.js +2 -1
  38. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  39. package/dist/catalog/admin-catalog.controller.js +1 -2
  40. package/dist/catalog/appearance.service.js +1 -3
  41. package/dist/catalog/catalog-content.d.ts +1 -1
  42. package/dist/catalog/catalog-content.js +1 -4
  43. package/dist/catalog/catalog-items.js +3 -3
  44. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  45. package/dist/catalog/catalog-scope.service.js +22 -73
  46. package/dist/catalog/cli.d.ts +0 -11
  47. package/dist/catalog/cli.js +0 -20
  48. package/dist/catalog/component-scope.service.js +0 -2
  49. package/dist/catalog/component-state.js +2 -2
  50. package/dist/catalog/install-status.d.ts +6 -0
  51. package/dist/catalog/install-status.js +6 -0
  52. package/dist/catalog/job-ids.d.ts +0 -4
  53. package/dist/catalog/job-ids.js +0 -4
  54. package/dist/catalog/marketplaces.service.d.ts +1 -1
  55. package/dist/catalog/org-catalog.service.d.ts +2 -0
  56. package/dist/catalog/org-catalog.service.js +8 -3
  57. package/dist/catalog/org-extension-switch.d.ts +7 -2
  58. package/dist/catalog/org-extension-switch.js +56 -9
  59. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  60. package/dist/catalog/org-plugin-uploads.js +9 -27
  61. package/dist/catalog/owned-items.js +1 -3
  62. package/dist/catalog/platform-import-update.js +1 -1
  63. package/dist/catalog/plugin-import.d.ts +15 -13
  64. package/dist/catalog/plugin-import.js +21 -30
  65. package/dist/catalog/plugin-install.d.ts +3 -43
  66. package/dist/catalog/plugin-install.js +8 -150
  67. package/dist/catalog/plugin-package.d.ts +5 -10
  68. package/dist/catalog/plugin-package.js +12 -33
  69. package/dist/catalog/plugin-upgrade.js +5 -4
  70. package/dist/catalog/scope-jobs.d.ts +34 -34
  71. package/dist/catalog/scope-jobs.js +50 -37
  72. package/dist/catalog/scope-orgs.d.ts +1 -1
  73. package/dist/catalog/scope-orgs.js +1 -2
  74. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  75. package/dist/catalog/scope-sync-workers.js +18 -6
  76. package/dist/catalog/scope-sync.d.ts +56 -59
  77. package/dist/catalog/scope-sync.js +96 -166
  78. package/dist/catalog/unshare.d.ts +3 -4
  79. package/dist/catalog/unshare.js +5 -8
  80. package/dist/channels/job-ids.d.ts +2 -6
  81. package/dist/channels/job-ids.js +2 -6
  82. package/dist/channels/outbound.d.ts +1 -1
  83. package/dist/channels/outbound.js +1 -1
  84. package/dist/channels/supervisor.d.ts +2 -3
  85. package/dist/channels/supervisor.js +2 -3
  86. package/dist/client/client-access.service.js +1 -1
  87. package/dist/config/env.js +19 -1
  88. package/dist/config/load.d.ts +0 -6
  89. package/dist/config/load.js +8 -27
  90. package/dist/config/schema.d.ts +54 -47
  91. package/dist/config/schema.js +198 -42
  92. package/dist/conversations/attachments.service.d.ts +10 -3
  93. package/dist/conversations/attachments.service.js +49 -16
  94. package/dist/conversations/conversations.controller.d.ts +0 -39
  95. package/dist/conversations/conversations.controller.js +0 -39
  96. package/dist/conversations/event-log.js +4 -1
  97. package/dist/conversations/events.d.ts +71 -46
  98. package/dist/conversations/events.js +124 -112
  99. package/dist/conversations/media-types.d.ts +25 -0
  100. package/dist/conversations/media-types.js +38 -0
  101. package/dist/conversations/queue.d.ts +3 -1
  102. package/dist/conversations/queue.service.js +9 -2
  103. package/dist/conversations/titles.js +6 -0
  104. package/dist/ctx/create-ctx.d.ts +8 -1
  105. package/dist/ctx/create-ctx.js +13 -3
  106. package/dist/ctx/net.d.ts +50 -0
  107. package/dist/ctx/net.js +67 -0
  108. package/dist/ctx/secrets.d.ts +24 -7
  109. package/dist/ctx/secrets.js +97 -30
  110. package/dist/db/kernel-schema.d.ts +27 -6
  111. package/dist/devices/devices.service.js +2 -1
  112. package/dist/errors.d.ts +10 -2
  113. package/dist/errors.js +10 -2
  114. package/dist/evals/reconstruct.d.ts +4 -17
  115. package/dist/evals/reconstruct.js +13 -53
  116. package/dist/evals/recorded-tools.d.ts +0 -27
  117. package/dist/evals/recorded-tools.js +2 -92
  118. package/dist/evals/run-replay.d.ts +1 -6
  119. package/dist/evals/run-replay.js +10 -17
  120. package/dist/evals/sets.service.d.ts +17 -5
  121. package/dist/evals/sets.service.js +33 -12
  122. package/dist/evals/snapshot.d.ts +1 -2
  123. package/dist/evals/snapshot.js +4 -17
  124. package/dist/extensions/admin-ops.d.ts +6 -1
  125. package/dist/extensions/admin-ops.js +17 -4
  126. package/dist/extensions/admin-view.d.ts +7 -4
  127. package/dist/extensions/admin-view.js +27 -21
  128. package/dist/extensions/bootstrap.js +0 -1
  129. package/dist/extensions/cli.js +0 -1
  130. package/dist/extensions/extensions.module.js +3 -0
  131. package/dist/extensions/host.d.ts +9 -4
  132. package/dist/extensions/host.js +14 -8
  133. package/dist/extensions/installs.d.ts +1 -3
  134. package/dist/extensions/instance.d.ts +0 -2
  135. package/dist/extensions/instance.js +0 -3
  136. package/dist/extensions/org-config.d.ts +4 -4
  137. package/dist/extensions/org-config.js +13 -22
  138. package/dist/extensions/package.d.ts +6 -6
  139. package/dist/extensions/package.js +3 -7
  140. package/dist/extensions/permission-view.d.ts +2 -4
  141. package/dist/extensions/plugin-items.d.ts +21 -1
  142. package/dist/extensions/plugin-items.js +28 -0
  143. package/dist/extensions/sync.js +5 -10
  144. package/dist/extensions/unavailable.js +0 -1
  145. package/dist/http/api.module.js +4 -1
  146. package/dist/identity/audit.d.ts +0 -12
  147. package/dist/identity/audit.js +0 -27
  148. package/dist/identity/auth.controller.js +5 -9
  149. package/dist/identity/cookies.d.ts +4 -9
  150. package/dist/identity/cookies.js +8 -32
  151. package/dist/identity/initial-passwords.d.ts +1 -1
  152. package/dist/identity/initial-passwords.js +1 -2
  153. package/dist/identity/sessions.d.ts +0 -6
  154. package/dist/identity/sessions.js +0 -18
  155. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  156. package/dist/inbox/platform-inbox.service.js +56 -6
  157. package/dist/index.d.ts +4 -2
  158. package/dist/index.js +4 -2
  159. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  160. package/dist/infra/cli/master-key-rewrap.js +24 -0
  161. package/dist/infra/config/kernel-config.service.js +0 -17
  162. package/dist/infra/database/transaction-host.d.ts +32 -1
  163. package/dist/infra/database/transaction-host.js +30 -4
  164. package/dist/infra/database/xact-lock.d.ts +16 -0
  165. package/dist/infra/database/xact-lock.js +28 -1
  166. package/dist/infra/health/health.controller.js +8 -0
  167. package/dist/infra/health/process-fault.d.ts +16 -0
  168. package/dist/infra/health/process-fault.js +49 -0
  169. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  170. package/dist/infra/lifecycle/process-guards.js +12 -3
  171. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  172. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  173. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  174. package/dist/infra/outbox/outbox.service.js +22 -26
  175. package/dist/infra/outbox/registry.d.ts +15 -7
  176. package/dist/infra/outbox/registry.js +39 -23
  177. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  178. package/dist/models/enablement.d.ts +5 -6
  179. package/dist/models/enablement.js +7 -14
  180. package/dist/net/public-address.d.ts +21 -1
  181. package/dist/net/public-address.js +56 -10
  182. package/dist/net/safe-fetch.d.ts +4 -1
  183. package/dist/net/safe-fetch.js +15 -4
  184. package/dist/orgs/directory-sync.js +2 -0
  185. package/dist/orgs/members.service.js +5 -0
  186. package/dist/orgs/network-allowances.service.d.ts +79 -0
  187. package/dist/orgs/network-allowances.service.js +371 -0
  188. package/dist/orgs/offboarding.d.ts +3 -1
  189. package/dist/orgs/offboarding.js +9 -2
  190. package/dist/orgs/org-lock.d.ts +28 -2
  191. package/dist/orgs/org-lock.js +59 -4
  192. package/dist/orgs/orgs.controller.d.ts +11 -2
  193. package/dist/orgs/orgs.controller.js +19 -3
  194. package/dist/orgs/orgs.module.d.ts +3 -2
  195. package/dist/orgs/orgs.module.js +6 -2
  196. package/dist/orgs/orgs.schemas.d.ts +12 -0
  197. package/dist/orgs/orgs.schemas.js +5 -0
  198. package/dist/orgs/orgs.service.js +6 -1
  199. package/dist/orgs/settings.controller.d.ts +3 -2
  200. package/dist/orgs/settings.service.d.ts +59 -14
  201. package/dist/orgs/settings.service.js +102 -20
  202. package/dist/overrides.d.ts +7 -7
  203. package/dist/overrides.js +4 -4
  204. package/dist/packages/tgz.d.ts +0 -2
  205. package/dist/packages/tgz.js +0 -2
  206. package/dist/platform/exclusions.js +0 -5
  207. package/dist/platform/operation.js +1 -1
  208. package/dist/platform/ops/admin.ops.d.ts +2 -2
  209. package/dist/platform/ops/admin.ops.js +9 -6
  210. package/dist/platform/ops/agents.ops.js +1 -1
  211. package/dist/platform/ops/connectors.ops.js +46 -1
  212. package/dist/platform/ops/evals.ops.js +1 -64
  213. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  214. package/dist/platform/ops/inbox.ops.js +16 -3
  215. package/dist/platform/ops/org-plugins.ops.js +1 -1
  216. package/dist/platform/ops/orgs.ops.d.ts +11 -3
  217. package/dist/platform/ops/orgs.ops.js +139 -5
  218. package/dist/platform/ops/outbox.ops.js +5 -5
  219. package/dist/platform/route-schemas.js +3 -0
  220. package/dist/roles/worker-role.d.ts +2 -3
  221. package/dist/roles/worker-role.js +3 -13
  222. package/dist/runtime/checkpointer.d.ts +3 -0
  223. package/dist/runtime/checkpointer.js +7 -4
  224. package/dist/runtime/context/build.d.ts +56 -18
  225. package/dist/runtime/context/build.js +143 -50
  226. package/dist/runtime/context/compaction.d.ts +1 -3
  227. package/dist/runtime/context/compaction.js +42 -8
  228. package/dist/runtime/context/run-context.js +1 -2
  229. package/dist/runtime/context/skills.d.ts +27 -56
  230. package/dist/runtime/context/skills.js +42 -114
  231. package/dist/runtime/context/tool-changes.d.ts +3 -3
  232. package/dist/runtime/context/tool-changes.js +6 -16
  233. package/dist/runtime/hook-calls.d.ts +6 -6
  234. package/dist/runtime/hook-calls.js +7 -7
  235. package/dist/runtime/langgraph-loop.js +9 -3
  236. package/dist/runtime/maintenance.d.ts +3 -11
  237. package/dist/runtime/maintenance.js +5 -20
  238. package/dist/runtime/model-call.d.ts +5 -0
  239. package/dist/runtime/model-call.js +48 -36
  240. package/dist/runtime/providers.d.ts +33 -35
  241. package/dist/runtime/providers.js +64 -109
  242. package/dist/runtime/run-context.service.js +7 -22
  243. package/dist/runtime/run-deletion.d.ts +6 -0
  244. package/dist/runtime/run-deletion.js +39 -16
  245. package/dist/runtime/run-execution.d.ts +56 -3
  246. package/dist/runtime/run-execution.js +81 -11
  247. package/dist/runtime/run-finish.js +2 -1
  248. package/dist/runtime/run-liveness.d.ts +11 -0
  249. package/dist/runtime/run-liveness.js +19 -0
  250. package/dist/runtime/run-orphan-check.job.js +2 -1
  251. package/dist/runtime/run-queue.js +8 -16
  252. package/dist/runtime/run-worker.d.ts +2 -2
  253. package/dist/runtime/run-worker.js +8 -6
  254. package/dist/runtime/step-log.d.ts +5 -0
  255. package/dist/runtime/step-log.js +9 -4
  256. package/dist/runtime/subagents/definition.d.ts +16 -20
  257. package/dist/runtime/subagents/definition.js +27 -27
  258. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  259. package/dist/runtime/subagents/dispatch.js +17 -3
  260. package/dist/runtime/subagents/org-agents.js +1 -2
  261. package/dist/runtime/subagents/preamble.d.ts +3 -2
  262. package/dist/runtime/subagents/preamble.js +3 -2
  263. package/dist/runtime/subagents/render.d.ts +1 -2
  264. package/dist/runtime/subagents/render.js +1 -2
  265. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  266. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  267. package/dist/runtime/subagents/template-skills.js +76 -0
  268. package/dist/runtime/waits.js +3 -1
  269. package/dist/schedules/effective-settings.d.ts +9 -3
  270. package/dist/schedules/effective-settings.js +5 -4
  271. package/dist/schedules/fire.js +11 -0
  272. package/dist/schedules/scheduled-tasks.service.js +5 -0
  273. package/dist/schedules/unattended.d.ts +2 -0
  274. package/dist/schedules/unattended.js +6 -1
  275. package/dist/skills/agent-skills.service.js +1 -2
  276. package/dist/skills/catalog.d.ts +1 -3
  277. package/dist/skills/catalog.js +1 -3
  278. package/dist/skills/conversation-catalog.d.ts +1 -2
  279. package/dist/skills/conversation-catalog.js +1 -2
  280. package/dist/skills/usable.js +2 -3
  281. package/dist/storage/storage.service.js +9 -1
  282. package/dist/tools/approvals.service.js +2 -4
  283. package/dist/tools/builtin-names.d.ts +2 -9
  284. package/dist/tools/builtin-names.js +4 -13
  285. package/dist/tools/builtins/sandbox/bash.js +3 -3
  286. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  287. package/dist/tools/builtins/sandbox/common.js +8 -115
  288. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  289. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  290. package/dist/tools/builtins/sandbox/glob.js +1 -3
  291. package/dist/tools/builtins/sandbox/grep.js +3 -5
  292. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  293. package/dist/tools/builtins/sandbox/index.js +10 -5
  294. package/dist/tools/builtins/sandbox/read.js +3 -2
  295. package/dist/tools/builtins/tool-search.d.ts +4 -7
  296. package/dist/tools/builtins/tool-search.js +6 -10
  297. package/dist/tools/connector-account-policies.d.ts +30 -3
  298. package/dist/tools/connector-account-policies.js +54 -7
  299. package/dist/tools/connector-content.js +1 -0
  300. package/dist/tools/connectors.controller.d.ts +24 -11
  301. package/dist/tools/connectors.controller.js +35 -6
  302. package/dist/tools/connectors.schemas.d.ts +14 -1
  303. package/dist/tools/connectors.schemas.js +14 -2
  304. package/dist/tools/connectors.service.d.ts +22 -0
  305. package/dist/tools/connectors.service.js +65 -6
  306. package/dist/tools/drift.d.ts +6 -2
  307. package/dist/tools/drift.js +10 -5
  308. package/dist/tools/git-push-policy.d.ts +4 -1
  309. package/dist/tools/git-push-policy.js +3 -1
  310. package/dist/tools/info.d.ts +1 -7
  311. package/dist/tools/info.js +5 -18
  312. package/dist/tools/job-ids.d.ts +0 -4
  313. package/dist/tools/job-ids.js +1 -6
  314. package/dist/tools/pipeline.d.ts +4 -10
  315. package/dist/tools/pipeline.js +17 -62
  316. package/dist/tools/policy.d.ts +6 -2
  317. package/dist/tools/policy.js +14 -12
  318. package/dist/tools/registry.js +1 -5
  319. package/dist/ui/views.d.ts +5 -5
  320. package/dist/ui/views.js +10 -16
  321. package/package.json +3 -3
  322. package/src/migrations/0137_audit_org_idx.sql +5 -0
  323. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  324. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  325. package/src/migrations/0140_retire_history_forms.sql +148 -0
  326. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  327. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  328. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  329. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  330. package/src/migrations/0145_org_network_allowances.sql +12 -0
  331. package/dist/admin/platform-audit.service.d.ts +0 -41
  332. package/dist/conversations/job-ids.d.ts +0 -6
  333. package/dist/conversations/job-ids.js +0 -6
  334. package/dist/extensions/job-ids.d.ts +0 -6
  335. package/dist/extensions/job-ids.js +0 -6
  336. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  337. package/dist/infra/queue/retired-schedulers.js +0 -9
  338. package/dist/orgs/job-ids.d.ts +0 -8
  339. package/dist/orgs/job-ids.js +0 -8
  340. package/dist/runtime/context/legacy-text.d.ts +0 -22
  341. package/dist/runtime/context/legacy-text.js +0 -37
  342. package/dist/runtime/job-ids.d.ts +0 -10
  343. package/dist/runtime/job-ids.js +0 -10
  344. package/dist/runtime/retired-schedulers.d.ts +0 -7
  345. package/dist/runtime/retired-schedulers.js +0 -31
  346. package/dist/storage/job-ids.d.ts +0 -6
  347. package/dist/storage/job-ids.js +0 -6
  348. package/dist/tools/legacy-data.d.ts +0 -34
  349. package/dist/tools/legacy-data.js +0 -76
  350. package/dist/tools/legacy-keys.d.ts +0 -51
  351. package/dist/tools/legacy-keys.js +0 -114
@@ -0,0 +1,163 @@
1
+ -- No compatibility before 0.1.0 (design review 2026-11-16, maintainer ruling): migration 0139
2
+ -- rewrote release-candidate tool keys in agent versions and templates, but a sub-agent's definition
3
+ -- frozen at dispatch is a copy the kernel reads again on every follow-up and in eval replays. Those
4
+ -- copies get the same rewrite once, here, with the org of the conversation (or eval case) holding
5
+ -- them:
6
+ -- - the log: `subagent_started.payload.definition` in `conversation_events`;
7
+ -- - eval case snapshots: `definitions` (each version's definition), `subagent.definition`, and the
8
+ -- `subagent_started` events among `events`.
9
+ -- The functions are 0139's, copied (pg_temp functions live only for this file's session). Keys in
10
+ -- the current format are never touched. Idempotent: a second run changes nothing.
11
+ --
12
+ -- Cost: one pass over the `subagent_started` rows of `conversation_events` and over `eval_cases`,
13
+ -- done once; release-candidate-sized tables, as earlier event rewrites (0105, 0142) assumed.
14
+
15
+ -- The current key(s) of `k` in org `org` (NULL for a platform template: no connector of its own).
16
+ CREATE OR REPLACE FUNCTION pg_temp.rc_tool_keys(k text, org text) RETURNS text[]
17
+ LANGUAGE sql STABLE AS $fn$
18
+ SELECT CASE
19
+ WHEN k IN ('skill_write', 'SkillWrite') THEN ARRAY[]::text[]
20
+ WHEN k IN ('sandbox_bash', 'sandbox_read', 'sandbox_write', 'sandbox_edit', 'sandbox_glob',
21
+ 'sandbox_grep', 'sandbox_deliver', 'skill_load', 'ask_user', 'read_tool_output',
22
+ 'tool_search', 'agent') THEN ARRAY[CASE k
23
+ WHEN 'sandbox_bash' THEN 'Bash' WHEN 'sandbox_read' THEN 'Read'
24
+ WHEN 'sandbox_write' THEN 'Write' WHEN 'sandbox_edit' THEN 'Edit'
25
+ WHEN 'sandbox_glob' THEN 'Glob' WHEN 'sandbox_grep' THEN 'Grep'
26
+ WHEN 'sandbox_deliver' THEN 'Deliver' WHEN 'skill_load' THEN 'Skill'
27
+ WHEN 'ask_user' THEN 'AskUserQuestion' WHEN 'read_tool_output' THEN 'ReadToolOutput'
28
+ WHEN 'tool_search' THEN 'ToolSearch' ELSE 'Agent' END]
29
+ WHEN k ~ '^[a-z0-9][a-z0-9_-]*__.' AND k !~ '^(mcp|plugin)__' THEN (
30
+ SELECT CASE
31
+ WHEN s.c AND NOT s.e THEN ARRAY['mcp__' || k]
32
+ WHEN s.e AND NOT s.c THEN ARRAY['plugin__' || k]
33
+ WHEN s.c AND s.e THEN ARRAY['mcp__' || k, 'plugin__' || k]
34
+ ELSE ARRAY[k]
35
+ END
36
+ FROM (
37
+ SELECT
38
+ EXISTS (SELECT 1 FROM connectors c
39
+ WHERE c.org_id = org AND c.deleted_at IS NULL
40
+ AND c.slug = split_part(k, '__', 1)) AS c,
41
+ split_part(k, '__', 1) IN (
42
+ SELECT name FROM extension_installs UNION SELECT name FROM extension_name_owners) AS e
43
+ ) s)
44
+ ELSE ARRAY[k]
45
+ END
46
+ $fn$;
47
+
48
+ -- A list of tool keys (a template's `tools` allowlist, `widen` false, or `disallowedTools`, `widen`
49
+ -- true) in current keys, in order, without repeats; other values as they are.
50
+ CREATE OR REPLACE FUNCTION pg_temp.rc_key_list(l jsonb, org text, widen boolean) RETURNS jsonb
51
+ LANGUAGE sql STABLE AS $fn$
52
+ SELECT CASE WHEN jsonb_typeof(l) IS DISTINCT FROM 'array' THEN l ELSE coalesce((
53
+ SELECT jsonb_agg(d.v ORDER BY d.pos) FROM (
54
+ SELECT DISTINCT ON (n.v) n.v, n.pos FROM (
55
+ SELECT x.ord * 10 + 1 AS pos, x.e AS v
56
+ FROM jsonb_array_elements(l) WITH ORDINALITY AS x(e, ord)
57
+ WHERE jsonb_typeof(x.e) <> 'string'
58
+ UNION ALL
59
+ SELECT x.ord * 10 + u.i, to_jsonb(u.key)
60
+ FROM jsonb_array_elements(l) WITH ORDINALITY AS x(e, ord)
61
+ CROSS JOIN LATERAL (SELECT pg_temp.rc_tool_keys(x.e #>> '{}', org) AS ks) s
62
+ CROSS JOIN LATERAL unnest(
63
+ CASE WHEN widen OR cardinality(s.ks) <= 1 THEN s.ks ELSE ARRAY[x.e #>> '{}'] END
64
+ ) WITH ORDINALITY AS u(key, i)
65
+ WHERE jsonb_typeof(x.e) = 'string'
66
+ ) n
67
+ ORDER BY n.v, n.pos
68
+ ) d), '[]'::jsonb) END
69
+ $fn$;
70
+
71
+ -- `toolPolicies` in current keys: keys that become one keep the stricter policy; a key with two
72
+ -- candidates keeps only an ask / deny, on both.
73
+ CREATE OR REPLACE FUNCTION pg_temp.rc_policies(p jsonb, org text) RETURNS jsonb
74
+ LANGUAGE sql STABLE AS $fn$
75
+ SELECT CASE WHEN jsonb_typeof(p) IS DISTINCT FROM 'object' THEN p ELSE coalesce((
76
+ SELECT jsonb_object_agg(t.key, t.v) FROM (
77
+ SELECT DISTINCT ON (nk) nk AS key, e.value AS v
78
+ FROM jsonb_each(p) AS e
79
+ CROSS JOIN LATERAL (SELECT pg_temp.rc_tool_keys(e.key, org) AS ks) s
80
+ CROSS JOIN LATERAL unnest(s.ks) AS nk
81
+ WHERE cardinality(s.ks) = 1 OR e.value IN ('"ask"'::jsonb, '"deny"'::jsonb)
82
+ ORDER BY nk,
83
+ CASE e.value WHEN '"deny"'::jsonb THEN 0 WHEN '"ask"'::jsonb THEN 1 ELSE 2 END
84
+ ) t), '{}'::jsonb) END
85
+ $fn$;
86
+
87
+ -- A template-shaped value (an agent template, an inline sub-agent, an agent definition's own
88
+ -- `toolPolicies`) in current keys.
89
+ CREATE OR REPLACE FUNCTION pg_temp.rc_template(t jsonb, org text) RETURNS jsonb
90
+ LANGUAGE sql STABLE AS $fn$
91
+ SELECT CASE WHEN jsonb_typeof(t) IS DISTINCT FROM 'object' THEN t ELSE t
92
+ || CASE WHEN t ? 'tools'
93
+ THEN jsonb_build_object('tools', pg_temp.rc_key_list(t -> 'tools', org, false))
94
+ ELSE '{}'::jsonb END
95
+ || CASE WHEN t ? 'disallowedTools'
96
+ THEN jsonb_build_object('disallowedTools',
97
+ pg_temp.rc_key_list(t -> 'disallowedTools', org, true))
98
+ ELSE '{}'::jsonb END
99
+ || CASE WHEN t ? 'toolPolicies'
100
+ THEN jsonb_build_object('toolPolicies', pg_temp.rc_policies(t -> 'toolPolicies', org))
101
+ ELSE '{}'::jsonb END
102
+ END
103
+ $fn$;
104
+
105
+ -- An agent definition or an agent template in current keys: its own keys and those of its inline
106
+ -- sub-agent templates.
107
+ CREATE OR REPLACE FUNCTION pg_temp.rc_definition(d jsonb, org text) RETURNS jsonb
108
+ LANGUAGE sql STABLE AS $fn$
109
+ SELECT pg_temp.rc_template(d, org) || CASE
110
+ WHEN jsonb_typeof(d -> 'subagents' -> 'inline') = 'array' THEN jsonb_build_object(
111
+ 'subagents',
112
+ jsonb_set(d -> 'subagents', '{inline}', (
113
+ SELECT coalesce(jsonb_agg(pg_temp.rc_template(x.e, org) ORDER BY x.ord), '[]'::jsonb)
114
+ FROM jsonb_array_elements(d -> 'subagents' -> 'inline') WITH ORDINALITY AS x(e, ord))))
115
+ ELSE '{}'::jsonb
116
+ END
117
+ $fn$;
118
+
119
+ -- capybara:allow-destructive rewrites rc tool keys in place; no kernel version reads them any more
120
+ UPDATE conversation_events e
121
+ SET payload = jsonb_set(e.payload, '{definition}',
122
+ pg_temp.rc_definition(e.payload -> 'definition', c.org_id))
123
+ FROM conversations c
124
+ WHERE c.id = e.conversation_id AND e.type = 'subagent_started'
125
+ AND jsonb_typeof(e.payload -> 'definition') = 'object'
126
+ AND pg_temp.rc_definition(e.payload -> 'definition', c.org_id) <> e.payload -> 'definition';
127
+
128
+ -- A case snapshot `s` of org `org` in current keys.
129
+ CREATE OR REPLACE FUNCTION pg_temp.rc_snapshot(s jsonb, org text) RETURNS jsonb
130
+ LANGUAGE sql STABLE AS $fn$
131
+ SELECT s
132
+ || CASE WHEN jsonb_typeof(s -> 'definitions') = 'object' THEN jsonb_build_object(
133
+ 'definitions', (
134
+ SELECT coalesce(jsonb_object_agg(d.key, pg_temp.rc_definition(d.value, org)), '{}'::jsonb)
135
+ FROM jsonb_each(s -> 'definitions') AS d))
136
+ ELSE '{}'::jsonb END
137
+ || CASE WHEN jsonb_typeof(s -> 'subagent' -> 'definition') = 'object' THEN jsonb_build_object(
138
+ 'subagent', jsonb_set(s -> 'subagent', '{definition}',
139
+ pg_temp.rc_definition(s -> 'subagent' -> 'definition', org)))
140
+ ELSE '{}'::jsonb END
141
+ || CASE WHEN jsonb_typeof(s -> 'events') = 'array' THEN jsonb_build_object(
142
+ 'events', (
143
+ SELECT coalesce(jsonb_agg(CASE
144
+ WHEN x.e ->> 'type' = 'subagent_started'
145
+ AND jsonb_typeof(x.e -> 'payload' -> 'definition') = 'object'
146
+ THEN jsonb_set(x.e, '{payload,definition}',
147
+ pg_temp.rc_definition(x.e -> 'payload' -> 'definition', org))
148
+ ELSE x.e END ORDER BY x.ord), '[]'::jsonb)
149
+ FROM jsonb_array_elements(s -> 'events') WITH ORDINALITY AS x(e, ord)))
150
+ ELSE '{}'::jsonb END
151
+ $fn$;
152
+
153
+ -- capybara:allow-destructive rewrites rc tool keys in place; no kernel version reads them any more
154
+ UPDATE eval_cases
155
+ SET snapshot = pg_temp.rc_snapshot(snapshot, org_id)
156
+ WHERE jsonb_typeof(snapshot) = 'object' AND pg_temp.rc_snapshot(snapshot, org_id) <> snapshot;
157
+
158
+ DROP FUNCTION IF EXISTS pg_temp.rc_snapshot(jsonb, text);
159
+ DROP FUNCTION IF EXISTS pg_temp.rc_definition(jsonb, text);
160
+ DROP FUNCTION IF EXISTS pg_temp.rc_template(jsonb, text);
161
+ DROP FUNCTION IF EXISTS pg_temp.rc_policies(jsonb, text);
162
+ DROP FUNCTION IF EXISTS pg_temp.rc_key_list(jsonb, text, boolean);
163
+ DROP FUNCTION IF EXISTS pg_temp.rc_tool_keys(text, text);
@@ -0,0 +1,12 @@
1
+ -- Internal endpoints a super admin lets one org's extension requests reach (plugin safe fetch spec):
2
+ -- `ctx.net.fetch` made for the org may connect to a private address only when the target matches
3
+ -- one of these entries. `entry` is a hostname, a `*.domain` wildcard, an IP, a CIDR, or an origin
4
+ -- `http(s)://host:port` (validated and normalized by the kernel, `orgs/network-allowances.service.ts`).
5
+ CREATE TABLE IF NOT EXISTS org_network_allowances (
6
+ id uuid PRIMARY KEY,
7
+ org_id text NOT NULL REFERENCES orgs(id) ON DELETE CASCADE,
8
+ entry text NOT NULL,
9
+ created_by text REFERENCES accounts(id) ON DELETE SET NULL,
10
+ created_at timestamptz NOT NULL DEFAULT now(),
11
+ UNIQUE (org_id, entry)
12
+ );
@@ -1,41 +0,0 @@
1
- import { KernelDb } from "../infra/database/kernel-db.js";
2
- /**
3
- * One platform-level audit event (admin overview spec §5.2, §9): who, what, on what and when, and
4
- * two flags. Never the event's `detail` (it may carry config field names or ids); a deleted actor
5
- * account reads as its id with a null name and email; `actor` is null for the kernel itself.
6
- */
7
- export interface PlatformAuditEvent {
8
- /** The event id (a bigserial, as a decimal string); also the keyset cursor. */
9
- id: string;
10
- at: string;
11
- actor: {
12
- id: string;
13
- name: string | null;
14
- email: string | null;
15
- } | null;
16
- /** Done with a personal access token. */
17
- viaToken: boolean;
18
- /** Done through the Platform tool by the actor's own agent (`detail.via === "agent"`). */
19
- viaAgent: boolean;
20
- /** The action; a legacy name is mapped through {@link LEGACY_AUDIT_ACTIONS}. */
21
- action: string;
22
- target: string | null;
23
- }
24
- /** A page of {@link PlatformAuditEvent}s; `next` is the `after` of the next page, null at the end. */
25
- export interface PlatformAuditPage {
26
- events: PlatformAuditEvent[];
27
- next: string | null;
28
- }
29
- /**
30
- * Reads the platform-level audit log: events with no org (`org_id IS NULL`, decision D3), newest
31
- * first by id, keyset paged (`audit_events_platform_idx`). Read-only and not audited (D5).
32
- */
33
- export declare class PlatformAuditService {
34
- private readonly kdb;
35
- constructor(kdb: KernelDb);
36
- /** `limit` events with an id below `after` (from the newest without it); one extra row tells `next`. */
37
- list(q: {
38
- after?: string | undefined;
39
- limit: number;
40
- }): Promise<PlatformAuditPage>;
41
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the attachment cleanup had before becoming `@LockedCron` /
3
- * `@LockedInterval` jobs (retired at worker start, `RETIRED_SCHEDULER_IDS`). A leaf module.
4
- */
5
- /** The retired BullMQ repeatable scheduler of the cleanup (removed from Redis at worker start). */
6
- export declare const ATTACHMENT_CLEANUP_SCHEDULER_ID = "attachment-cleanup-hourly";
@@ -1,6 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the attachment cleanup had before becoming `@LockedCron` /
3
- * `@LockedInterval` jobs (retired at worker start, `RETIRED_SCHEDULER_IDS`). A leaf module.
4
- */
5
- /** The retired BullMQ repeatable scheduler of the cleanup (removed from Redis at worker start). */
6
- export const ATTACHMENT_CLEANUP_SCHEDULER_ID = "attachment-cleanup-hourly";
@@ -1,6 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the plugins reconcile had before becoming `@LockedCron` /
3
- * `@LockedInterval` jobs (retired at worker start, `RETIRED_SCHEDULER_IDS`). A leaf module.
4
- */
5
- /** The BullMQ repeatable scheduler the job had before it became `@LockedInterval` (retired). */
6
- export declare const PLUGINS_RECONCILE_SCHEDULER_ID = "plugins-reconcile-every";
@@ -1,6 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the plugins reconcile had before becoming `@LockedCron` /
3
- * `@LockedInterval` jobs (retired at worker start, `RETIRED_SCHEDULER_IDS`). A leaf module.
4
- */
5
- /** The BullMQ repeatable scheduler the job had before it became `@LockedInterval` (retired). */
6
- export const PLUGINS_RECONCILE_SCHEDULER_ID = "plugins-reconcile-every";
@@ -1,7 +0,0 @@
1
- import type { Queue } from "bullmq";
2
- /**
3
- * Removes job schedulers that no job uses any more (fixed-period jobs that became `@LockedCron` /
4
- * `@LockedInterval` jobs leave their old BullMQ schedulers in Redis on an upgraded deployment).
5
- * Idempotent; replicas may race.
6
- */
7
- export declare function removeRetiredSchedulers(queue: Pick<Queue, "removeJobScheduler">, ids: readonly string[]): Promise<void>;
@@ -1,9 +0,0 @@
1
- /**
2
- * Removes job schedulers that no job uses any more (fixed-period jobs that became `@LockedCron` /
3
- * `@LockedInterval` jobs leave their old BullMQ schedulers in Redis on an upgraded deployment).
4
- * Idempotent; replicas may race.
5
- */
6
- export async function removeRetiredSchedulers(queue, ids) {
7
- for (const id of ids)
8
- await queue.removeJobScheduler(id);
9
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the offboarding sweep and the directory scan had before
3
- * becoming `@LockedCron` jobs (retired at worker start, `RETIRED_SCHEDULER_IDS`). A leaf module.
4
- */
5
- /** The offboarding sweep's old scheduler (every 10 minutes). */
6
- export declare const OFFBOARD_SWEEP_SCHEDULER_ID = "offboard-sweep-every-10m";
7
- /** The directory scan's old scheduler (hourly). */
8
- export declare const DIRECTORY_SCAN_SCHEDULER_ID = "directory-scan-hourly";
@@ -1,8 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the offboarding sweep and the directory scan had before
3
- * becoming `@LockedCron` jobs (retired at worker start, `RETIRED_SCHEDULER_IDS`). A leaf module.
4
- */
5
- /** The offboarding sweep's old scheduler (every 10 minutes). */
6
- export const OFFBOARD_SWEEP_SCHEDULER_ID = "offboard-sweep-every-10m";
7
- /** The directory scan's old scheduler (hourly). */
8
- export const DIRECTORY_SCAN_SCHEDULER_ID = "directory-scan-hourly";
@@ -1,22 +0,0 @@
1
- import type { SkillTexts } from "./skills.js";
2
- /**
3
- * The system texts of a request as the release candidates rendered them, naming the old builtins
4
- * (`skill_load`, `tool_search`). FROZEN: verbatim copies from `main` at 02b9634b
5
- * (`runtime/context/skills.ts`, `tools/builtins/tool-search.ts`); never edit them. A request whose
6
- * tools hold an old builtin key (a recording made before the rename) is rebuilt with these, so it
7
- * reconstructs with no `system_hash` drift (tool naming spec §10). `check:terms` exempts this file.
8
- *
9
- * The skills texts (`skills.ts`) naming `skill_load`.
10
- */
11
- export declare const LEGACY_SKILL_TEXTS: SkillTexts;
12
- /** The tool catalog header (`tools/builtins/tool-search.ts` `CATALOG_HEADER`) naming `tool_search`. */
13
- export declare const LEGACY_CATALOG_HEADER: string;
14
- /**
15
- * Was this request's tool list recorded before the rename? True when one of its tool keys is a
16
- * release-candidate builtin name (the run's tools, as the request carries them). Every request
17
- * that renders one of these texts offers the tool it names (`skill_load` whenever the log has a
18
- * skills catalog or an invocation, `tool_search` with a tool catalog), so the tools decide it.
19
- */
20
- export declare function usesLegacyToolNames(tools: readonly {
21
- key: string;
22
- }[]): boolean;
@@ -1,37 +0,0 @@
1
- import { isLegacyBuiltinKey } from "../../tools/legacy-keys.js";
2
- /**
3
- * The system texts of a request as the release candidates rendered them, naming the old builtins
4
- * (`skill_load`, `tool_search`). FROZEN: verbatim copies from `main` at 02b9634b
5
- * (`runtime/context/skills.ts`, `tools/builtins/tool-search.ts`); never edit them. A request whose
6
- * tools hold an old builtin key (a recording made before the rename) is rebuilt with these, so it
7
- * reconstructs with no `system_hash` drift (tool naming spec §10). `check:terms` exempts this file.
8
- *
9
- * The skills texts (`skills.ts`) naming `skill_load`.
10
- */
11
- export const LEGACY_SKILL_TEXTS = Object.freeze({
12
- skillsCatalogHeader: "Skills are available in this conversation. A skill is a set of instructions, sometimes with " +
13
- "scripts or other files, for a specific kind of task. When a task matches a skill's description, " +
14
- "call skill_load with the skill's name to read its instructions before you start; do not guess " +
15
- "what a skill says. Available skills:",
16
- newSkills: "New skills (call skill_load with the name to use one):",
17
- updatedSkills: "Updated skills (call skill_load again before relying on earlier instructions):",
18
- currentSkills: "Skills available in this conversation now (this replaces any earlier list of skills; call " +
19
- "skill_load with a name to read a skill's instructions):",
20
- invokedSkills: (names) => `Skills the user invoked earlier in this conversation: ${names.join(", ")}. Call skill_load with a name to read its instructions again.`,
21
- pinnedSkillsHeader: "Pinned skills: the owner of this agent pinned these skills, so their instructions apply " +
22
- "throughout this conversation. Follow them without calling skill_load; call skill_load " +
23
- "only to copy a pinned skill's files into the sandbox.",
24
- });
25
- /** The tool catalog header (`tools/builtins/tool-search.ts` `CATALOG_HEADER`) naming `tool_search`. */
26
- export const LEGACY_CATALOG_HEADER = "More tools are available but not loaded. To use one, first call tool_search with keywords; " +
27
- "it returns the full definitions and loads the matching tools for your next step. " +
28
- "Calling a tool that is not loaded returns an error. Tool catalog:";
29
- /**
30
- * Was this request's tool list recorded before the rename? True when one of its tool keys is a
31
- * release-candidate builtin name (the run's tools, as the request carries them). Every request
32
- * that renders one of these texts offers the tool it names (`skill_load` whenever the log has a
33
- * skills catalog or an invocation, `tool_search` with a tool catalog), so the tools decide it.
34
- */
35
- export function usesLegacyToolNames(tools) {
36
- return tools.some((t) => isLegacyBuiltinKey(t.key));
37
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the runtime's fixed-period jobs had before they became
3
- * `@LockedCron` jobs: an upgraded deployment still has them in Redis, so the
4
- * worker removes them at start (`RETIRED_SCHEDULER_IDS`). A leaf module: the maintenance worker
5
- * imports it without the runtime's providers.
6
- */
7
- /** The wait sweep's old scheduler (every 10 minutes). */
8
- export declare const WAIT_SWEEP_SCHEDULER_ID = "wait-sweep-every-10m";
9
- /** The usage sweeper's old scheduler (every minute). */
10
- export declare const USAGE_SWEEP_SCHEDULER_ID = "usage-report-sweep-every";
@@ -1,10 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the runtime's fixed-period jobs had before they became
3
- * `@LockedCron` jobs: an upgraded deployment still has them in Redis, so the
4
- * worker removes them at start (`RETIRED_SCHEDULER_IDS`). A leaf module: the maintenance worker
5
- * imports it without the runtime's providers.
6
- */
7
- /** The wait sweep's old scheduler (every 10 minutes). */
8
- export const WAIT_SWEEP_SCHEDULER_ID = "wait-sweep-every-10m";
9
- /** The usage sweeper's old scheduler (every minute). */
10
- export const USAGE_SWEEP_SCHEDULER_ID = "usage-report-sweep-every";
@@ -1,7 +0,0 @@
1
- /**
2
- * Job scheduler ids of the maintenance queue's fixed-period jobs before they became `@LockedCron` /
3
- * `@LockedInterval` jobs: an upgraded deployment still has them in Redis, so a starting worker
4
- * role removes them (else BullMQ keeps firing a job no handler knows). Each id
5
- * comes from its domain's leaf `job-ids.ts`, so this module imports no domain code.
6
- */
7
- export declare const RETIRED_SCHEDULER_IDS: readonly string[];
@@ -1,31 +0,0 @@
1
- import { MARKETPLACES_REFRESH_SCHEDULER_ID, PLUGIN_STAGING_CLEANUP_SCHEDULER_ID, } from "../catalog/job-ids.js";
2
- import { GATEWAY_CHECK_SCHEDULER_ID } from "../channels/job-ids.js";
3
- import { ATTACHMENT_CLEANUP_SCHEDULER_ID } from "../conversations/job-ids.js";
4
- import { PLUGINS_RECONCILE_SCHEDULER_ID } from "../extensions/job-ids.js";
5
- import { DIRECTORY_SCAN_SCHEDULER_ID, OFFBOARD_SWEEP_SCHEDULER_ID } from "../orgs/job-ids.js";
6
- import { SANDBOX_DESTROY_SCHEDULER_ID, SANDBOX_SUSPEND_SCHEDULER_ID } from "../sandbox/job-ids.js";
7
- import { STORAGE_PURGE_SCHEDULER_ID } from "../storage/job-ids.js";
8
- import { DRIFT_SCHEDULER_ID, OUTPUT_CLEANUP_SCHEDULER_ID } from "../tools/job-ids.js";
9
- import { USAGE_SWEEP_SCHEDULER_ID, WAIT_SWEEP_SCHEDULER_ID } from "./job-ids.js";
10
- /**
11
- * Job scheduler ids of the maintenance queue's fixed-period jobs before they became `@LockedCron` /
12
- * `@LockedInterval` jobs: an upgraded deployment still has them in Redis, so a starting worker
13
- * role removes them (else BullMQ keeps firing a job no handler knows). Each id
14
- * comes from its domain's leaf `job-ids.ts`, so this module imports no domain code.
15
- */
16
- export const RETIRED_SCHEDULER_IDS = [
17
- STORAGE_PURGE_SCHEDULER_ID,
18
- DIRECTORY_SCAN_SCHEDULER_ID,
19
- OFFBOARD_SWEEP_SCHEDULER_ID,
20
- PLUGINS_RECONCILE_SCHEDULER_ID,
21
- MARKETPLACES_REFRESH_SCHEDULER_ID,
22
- PLUGIN_STAGING_CLEANUP_SCHEDULER_ID,
23
- DRIFT_SCHEDULER_ID,
24
- OUTPUT_CLEANUP_SCHEDULER_ID,
25
- ATTACHMENT_CLEANUP_SCHEDULER_ID,
26
- WAIT_SWEEP_SCHEDULER_ID,
27
- USAGE_SWEEP_SCHEDULER_ID,
28
- GATEWAY_CHECK_SCHEDULER_ID,
29
- SANDBOX_SUSPEND_SCHEDULER_ID,
30
- SANDBOX_DESTROY_SCHEDULER_ID,
31
- ];
@@ -1,6 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the storage purge had before becoming `@LockedCron` /
3
- * `@LockedInterval` jobs (retired at worker start, `RETIRED_SCHEDULER_IDS`). A leaf module.
4
- */
5
- /** The maintenance job scheduler id it had before it became a cron (retired at worker start). */
6
- export declare const STORAGE_PURGE_SCHEDULER_ID = "storage-org-purge-hourly";
@@ -1,6 +0,0 @@
1
- /**
2
- * The maintenance job scheduler ids the storage purge had before becoming `@LockedCron` /
3
- * `@LockedInterval` jobs (retired at worker start, `RETIRED_SCHEDULER_IDS`). A leaf module.
4
- */
5
- /** The maintenance job scheduler id it had before it became a cron (retired at worker start). */
6
- export const STORAGE_PURGE_SCHEDULER_ID = "storage-org-purge-hourly";
@@ -1,34 +0,0 @@
1
- import { type AgentDefinition } from "../agents/definition.js";
2
- import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
- import type { KernelLogger } from "../log.js";
4
- import { type LegacyScope } from "./legacy-keys.js";
5
- /**
6
- * Stored release-candidate tool keys (tool naming spec §8): the scope that reads an rc
7
- * `<x>__<tool>` key in an org, the stored-definition readers that use it, and the startup notice
8
- * for the rows migration 0063 could not map. No in-process state: each call reads PostgreSQL.
9
- */
10
- /**
11
- * What an rc `<x>__<tool>` key can name in `orgId`: the org's live connector slugs and the
12
- * deployment's extension names (installed ones and config-declared ones, which claim their name
13
- * in `extension_name_owners`). Migration 0063 reads the same two sources.
14
- */
15
- export declare function loadLegacyScope(db: KernelSchemaDb, orgId: string): Promise<LegacyScope>;
16
- /**
17
- * A stored agent definition of `orgId` with every rc key it can map read as the current key
18
- * ({@link normalizeStoredDefinition}); the scope is read only when the definition holds an rc
19
- * `<x>__<tool>` key.
20
- */
21
- export declare function normalizeStoredDefinitionIn(db: KernelSchemaDb, orgId: string, def: unknown): Promise<AgentDefinition>;
22
- /** A stored agent template (or any template-shaped value) of `orgId` in current keys. */
23
- export declare function normalizeTemplateIn<T>(db: KernelSchemaDb, orgId: string, t: T): Promise<T>;
24
- /**
25
- * Rows still holding an rc tool key after migration 0063: grants and pending approvals and
26
- * questions it could not map (an ambiguous or unknown `<x>__<tool>`). Read-only.
27
- */
28
- export declare function countLegacyToolKeys(db: KernelSchemaDb): Promise<number>;
29
- /**
30
- * The startup notice (spec §8.2): one WARN `tools.legacy_key_unmapped` with the count of rows
31
- * still holding an rc key, only when there are any. A grant that no longer matches stops applying
32
- * (the person is asked again), so this is a notice, not a failure.
33
- */
34
- export declare function warnLegacyToolKeys(db: KernelSchemaDb, log: Pick<KernelLogger, "warn">): Promise<void>;
@@ -1,76 +0,0 @@
1
- import { sql } from "kysely";
2
- import { needsLegacyScope, normalizeStoredDefinition, normalizeToolKeys, } from "../agents/definition.js";
3
- import { LEGACY_BUILTINS } from "./legacy-keys.js";
4
- /**
5
- * Stored release-candidate tool keys (tool naming spec §8): the scope that reads an rc
6
- * `<x>__<tool>` key in an org, the stored-definition readers that use it, and the startup notice
7
- * for the rows migration 0063 could not map. No in-process state: each call reads PostgreSQL.
8
- */
9
- /**
10
- * What an rc `<x>__<tool>` key can name in `orgId`: the org's live connector slugs and the
11
- * deployment's extension names (installed ones and config-declared ones, which claim their name
12
- * in `extension_name_owners`). Migration 0063 reads the same two sources.
13
- */
14
- export async function loadLegacyScope(db, orgId) {
15
- const [connectors, installs, owners] = await Promise.all([
16
- db
17
- .selectFrom("connectors")
18
- .select(["id", "slug"])
19
- .where("org_id", "=", orgId)
20
- .where("deleted_at", "is", null)
21
- .execute(),
22
- db.selectFrom("extension_installs").select("name").execute(),
23
- db.selectFrom("extension_name_owners").select("name").execute(),
24
- ]);
25
- return {
26
- connectorSlugs: new Set(connectors.map((r) => r.slug)),
27
- connectorSlugById: new Map(connectors.map((r) => [r.id, r.slug])),
28
- extensionNames: new Set([...installs, ...owners].map((r) => r.name)),
29
- };
30
- }
31
- /**
32
- * A stored agent definition of `orgId` with every rc key it can map read as the current key
33
- * ({@link normalizeStoredDefinition}); the scope is read only when the definition holds an rc
34
- * `<x>__<tool>` key.
35
- */
36
- export async function normalizeStoredDefinitionIn(db, orgId, def) {
37
- return normalizeStoredDefinition(def, needsLegacyScope(def) ? await loadLegacyScope(db, orgId) : undefined);
38
- }
39
- /** A stored agent template (or any template-shaped value) of `orgId` in current keys. */
40
- export async function normalizeTemplateIn(db, orgId, t) {
41
- return normalizeToolKeys(t, needsLegacyScope(t) ? await loadLegacyScope(db, orgId) : undefined);
42
- }
43
- /**
44
- * The SQL test for an rc key, the predicate of migration 0063's partial indexes (so the count
45
- * below reads only those, nearly empty, indexes): an old builtin name, or `<x>__<tool>` not in the
46
- * current `mcp__` / `plugin__` format.
47
- */
48
- const legacyKeySql = (col) => sql `(${col} = ANY (ARRAY[${sql.join(Object.keys(LEGACY_BUILTINS).map((k) => sql.lit(k)))}]::text[]) OR (${col} ~ '^[a-z0-9][a-z0-9_-]*__.' AND ${col} !~ '^(mcp|plugin)__'))`;
49
- /**
50
- * Rows still holding an rc tool key after migration 0063: grants and pending approvals and
51
- * questions it could not map (an ambiguous or unknown `<x>__<tool>`). Read-only.
52
- */
53
- export async function countLegacyToolKeys(db) {
54
- const r = await sql `
55
- SELECT
56
- (SELECT count(*) FROM capybara.tool_grants WHERE ${legacyKeySql(sql.ref("tool_key"))})
57
- + (SELECT count(*) FROM capybara.conversation_tool_grants
58
- WHERE ${legacyKeySql(sql.ref("tool_key"))})
59
- + (SELECT count(*) FROM capybara.approvals
60
- WHERE status = 'pending' AND ${legacyKeySql(sql.ref("tool_key"))})
61
- + (SELECT count(*) FROM capybara.questions
62
- WHERE status = 'pending' AND ${legacyKeySql(sql.raw("(spec->>'toolKey')"))})
63
- AS n
64
- `.execute(db);
65
- return Number(r.rows[0]?.n ?? 0);
66
- }
67
- /**
68
- * The startup notice (spec §8.2): one WARN `tools.legacy_key_unmapped` with the count of rows
69
- * still holding an rc key, only when there are any. A grant that no longer matches stops applying
70
- * (the person is asked again), so this is a notice, not a failure.
71
- */
72
- export async function warnLegacyToolKeys(db, log) {
73
- const count = await countLegacyToolKeys(db);
74
- if (count > 0)
75
- log.warn("tools.legacy_key_unmapped", { count });
76
- }
@@ -1,51 +0,0 @@
1
- import { type BuiltinName } from "./builtin-names.js";
2
- /**
3
- * The release-candidate builtin tool names (tool naming spec §8.1). FROZEN: it describes the names
4
- * of the 0.1.0 release candidates and never grows. Old keys stay in logs, recordings and stored
5
- * configuration; this map is how the kernel reads them. `check:terms` exempts this file.
6
- */
7
- export interface LegacyBuiltin {
8
- /** The new name. */
9
- name: BuiltinName;
10
- /** Old parameter name -> new parameter name (only the renamed ones). */
11
- params: Readonly<Record<string, string>>;
12
- /** New parameters whose value is in milliseconds where the old one was in seconds (× 1000). */
13
- msParams?: readonly string[];
14
- }
15
- export declare const LEGACY_BUILTINS: Readonly<Record<string, LegacyBuiltin>>;
16
- /** Is `key` a release-candidate builtin name? */
17
- export declare const isLegacyBuiltinKey: (key: string) => boolean;
18
- /** What a connector slug / extension name can be, to read an old `<x>__<tool>` key. */
19
- export interface LegacyScope {
20
- connectorSlugs: ReadonlySet<string>;
21
- extensionNames: ReadonlySet<string>;
22
- /**
23
- * Connector id -> slug, for reading a stored definition's connector refs when a key is
24
- * ambiguous (a slug that is also an extension name); optional.
25
- */
26
- connectorSlugById?: ReadonlyMap<string, string>;
27
- }
28
- /**
29
- * Is `key` an rc `<x>__<tool>` key, which only a {@link LegacyScope} can map? Keys in the current
30
- * format (`mcp__…`, `plugin__…`) never are.
31
- */
32
- export declare const isLegacyPrefixedKey: (key: string) => boolean;
33
- /**
34
- * The current key of a release-candidate key: a builtin by the frozen map; `<x>__<tool>` becomes
35
- * `mcp__x__tool` when `x` is only a connector slug in `scope`, `plugin__x__tool` when only an
36
- * extension name, else null (ambiguous, unknown, or not an old key; a key in the current format
37
- * is never mapped again).
38
- */
39
- export declare function legacyToolKey(key: string, scope?: LegacyScope): string | null;
40
- /** The input of an old builtin call in the current parameter names (seconds -> milliseconds). */
41
- export declare function legacyToolInput(oldKey: string, input: unknown): unknown;
42
- /** The model-visible hint for a call to an old builtin key; null for any other key. */
43
- export declare function legacyHint(key: string): string | null;
44
- /**
45
- * The current key(s) an rc key stands for, to name in a refusal when a definition is saved with
46
- * it: a builtin's new name; for `<x>__<tool>`, the candidates among `known` (the agent's tool
47
- * keys), else both `mcp__<x>__<tool>` and `plugin__<x>__<tool>`. Empty when `key` is no rc key.
48
- */
49
- export declare function legacyKeyCandidates(key: string, known?: ReadonlySet<string>): string[];
50
- /** The refusal text for saving rc key `key` (null when it is none): names the new key(s). */
51
- export declare function legacyKeySaveText(key: string, known?: ReadonlySet<string>): string | null;