@capybara-hq/kernel 0.1.0-rc.135 → 0.1.0-rc.137

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 (242) hide show
  1. package/dist/admin/admin.module.js +3 -0
  2. package/dist/admin/audit-log.service.d.ts +96 -12
  3. package/dist/admin/audit-log.service.js +508 -44
  4. package/dist/admin/audit-targets.d.ts +17 -0
  5. package/dist/admin/audit-targets.js +84 -0
  6. package/dist/admin/audit.controller.d.ts +12 -9
  7. package/dist/admin/audit.controller.js +29 -8
  8. package/dist/admin/audit.schemas.d.ts +20 -4
  9. package/dist/admin/audit.schemas.js +42 -17
  10. package/dist/admin/health.service.d.ts +2 -2
  11. package/dist/admin/health.service.js +6 -2
  12. package/dist/agents/templates.js +3 -10
  13. package/dist/app.d.ts +3 -1
  14. package/dist/app.js +1 -0
  15. package/dist/automations/automations.service.js +4 -5
  16. package/dist/catalog/catalog-content.d.ts +1 -1
  17. package/dist/catalog/catalog-content.js +17 -22
  18. package/dist/catalog/catalog-items.d.ts +5 -10
  19. package/dist/catalog/catalog-items.js +27 -51
  20. package/dist/catalog/catalog-scope.service.d.ts +4 -2
  21. package/dist/catalog/catalog-scope.service.js +105 -141
  22. package/dist/catalog/catalog.module.js +2 -0
  23. package/dist/catalog/catalog.service.d.ts +3 -3
  24. package/dist/catalog/catalog.service.js +33 -8
  25. package/dist/catalog/cli.js +17 -0
  26. package/dist/catalog/component-promotion.js +8 -4
  27. package/dist/catalog/component-scope.service.d.ts +3 -1
  28. package/dist/catalog/component-scope.service.js +101 -140
  29. package/dist/catalog/component-state.d.ts +10 -8
  30. package/dist/catalog/component-state.js +42 -30
  31. package/dist/catalog/dependency-edges.d.ts +25 -0
  32. package/dist/catalog/dependency-edges.js +125 -0
  33. package/dist/catalog/install-status.d.ts +2 -3
  34. package/dist/catalog/install-status.js +2 -3
  35. package/dist/catalog/marketplaces.service.d.ts +1 -1
  36. package/dist/catalog/org-catalog.service.d.ts +3 -1
  37. package/dist/catalog/org-catalog.service.js +33 -94
  38. package/dist/catalog/org-intent.d.ts +43 -0
  39. package/dist/catalog/org-intent.js +184 -0
  40. package/dist/catalog/owned-items.d.ts +1 -1
  41. package/dist/catalog/owned-items.js +9 -29
  42. package/dist/catalog/ownership.d.ts +2 -3
  43. package/dist/catalog/ownership.js +10 -28
  44. package/dist/catalog/platform-components.d.ts +3 -1
  45. package/dist/catalog/platform-components.js +9 -1
  46. package/dist/catalog/plugin-import.js +12 -16
  47. package/dist/catalog/plugin-install.d.ts +3 -4
  48. package/dist/catalog/plugin-install.js +25 -49
  49. package/dist/catalog/plugin-upgrade.d.ts +2 -2
  50. package/dist/catalog/plugin-upgrade.js +18 -34
  51. package/dist/catalog/request-rules.js +20 -8
  52. package/dist/catalog/scope-orgs.js +2 -7
  53. package/dist/catalog/scope-state.d.ts +6 -6
  54. package/dist/catalog/scope-state.js +24 -43
  55. package/dist/catalog/scope-sync.d.ts +0 -2
  56. package/dist/catalog/scope-sync.js +11 -39
  57. package/dist/catalog/scope-writer.d.ts +78 -0
  58. package/dist/catalog/scope-writer.js +181 -0
  59. package/dist/catalog/unshare.js +8 -41
  60. package/dist/channels/connections.service.js +6 -6
  61. package/dist/channels/supervisor.js +3 -7
  62. package/dist/client/client-access.service.js +2 -12
  63. package/dist/config/schema.d.ts +6 -0
  64. package/dist/config/schema.js +29 -1
  65. package/dist/conversations/access.d.ts +15 -7
  66. package/dist/conversations/access.js +59 -10
  67. package/dist/conversations/conversation-agent.d.ts +18 -0
  68. package/dist/conversations/conversation-agent.js +23 -0
  69. package/dist/conversations/conversation-ref.d.ts +3 -2
  70. package/dist/conversations/conversation-ref.js +6 -1
  71. package/dist/conversations/conversations.controller.d.ts +28 -5
  72. package/dist/conversations/conversations.controller.js +99 -10
  73. package/dist/conversations/conversations.module.js +10 -0
  74. package/dist/conversations/conversations.schemas.d.ts +6 -0
  75. package/dist/conversations/conversations.schemas.js +15 -0
  76. package/dist/conversations/conversations.service.d.ts +125 -21
  77. package/dist/conversations/conversations.service.js +260 -90
  78. package/dist/conversations/event-log.d.ts +9 -1
  79. package/dist/conversations/event-log.js +2 -0
  80. package/dist/conversations/events.d.ts +57 -0
  81. package/dist/conversations/events.js +73 -1
  82. package/dist/conversations/external/external-calls.d.ts +75 -0
  83. package/dist/conversations/external/external-calls.js +91 -0
  84. package/dist/conversations/external/external-calls.processor.d.ts +45 -0
  85. package/dist/conversations/external/external-calls.processor.js +144 -0
  86. package/dist/conversations/external/external-conversations.service.d.ts +266 -0
  87. package/dist/conversations/external/external-conversations.service.js +1138 -0
  88. package/dist/conversations/external/external.schemas.d.ts +63 -0
  89. package/dist/conversations/external/external.schemas.js +52 -0
  90. package/dist/conversations/external/token.d.ts +6 -0
  91. package/dist/conversations/external/token.js +6 -0
  92. package/dist/conversations/permission-profile-store.d.ts +4 -1
  93. package/dist/conversations/permission-profiles.controller.d.ts +33 -9
  94. package/dist/conversations/permission-profiles.controller.js +86 -6
  95. package/dist/conversations/prompt-suggestions.js +2 -1
  96. package/dist/conversations/queue.js +2 -1
  97. package/dist/conversations/titles.js +4 -3
  98. package/dist/ctx/create-ctx.d.ts +9 -2
  99. package/dist/ctx/create-ctx.js +47 -62
  100. package/dist/ctx/guard-db.d.ts +6 -0
  101. package/dist/ctx/guard-db.js +55 -0
  102. package/dist/db/extension-handoff-schema.d.ts +1 -1
  103. package/dist/db/extension-handoff-schema.js +48 -10
  104. package/dist/db/extension-schema-transfer.js +5 -2
  105. package/dist/db/kernel-schema.d.ts +42 -5
  106. package/dist/device-access/host-services.d.ts +2 -2
  107. package/dist/device-access/host-services.js +8 -8
  108. package/dist/device-access/person-handles.d.ts +16 -7
  109. package/dist/device-access/person-handles.js +14 -9
  110. package/dist/devices/conversation-devices.d.ts +5 -0
  111. package/dist/devices/conversation-devices.js +16 -0
  112. package/dist/erasure/org-catalog.js +2 -2
  113. package/dist/erasure/org-rules.js +5 -0
  114. package/dist/errors.d.ts +34 -0
  115. package/dist/errors.js +34 -0
  116. package/dist/evals/snapshot.js +3 -1
  117. package/dist/evals/trajectory.service.d.ts +2 -2
  118. package/dist/evals/trajectory.service.js +11 -7
  119. package/dist/extensions/admin-ops.d.ts +9 -5
  120. package/dist/extensions/admin-ops.js +52 -8
  121. package/dist/extensions/admin-view.js +1 -4
  122. package/dist/extensions/bootstrap.js +4 -1
  123. package/dist/extensions/cli.js +1 -0
  124. package/dist/extensions/effective-config.js +1 -4
  125. package/dist/extensions/enabled.d.ts +23 -29
  126. package/dist/extensions/enabled.js +141 -62
  127. package/dist/extensions/extensions.module.js +3 -0
  128. package/dist/extensions/host.d.ts +71 -45
  129. package/dist/extensions/host.js +454 -128
  130. package/dist/extensions/installs.d.ts +9 -0
  131. package/dist/extensions/installs.js +23 -0
  132. package/dist/extensions/isolated/admission.d.ts +10 -0
  133. package/dist/extensions/isolated/admission.js +206 -0
  134. package/dist/extensions/isolated/authorization.d.ts +37 -0
  135. package/dist/extensions/isolated/authorization.js +146 -0
  136. package/dist/extensions/isolated/broker.d.ts +15 -0
  137. package/dist/extensions/isolated/broker.js +452 -0
  138. package/dist/extensions/isolated/child-protocol.d.ts +84 -0
  139. package/dist/extensions/isolated/child-protocol.js +21 -0
  140. package/dist/extensions/isolated/child-registration.d.ts +22 -0
  141. package/dist/extensions/isolated/child-registration.js +152 -0
  142. package/dist/extensions/isolated/child-session.d.ts +6 -0
  143. package/dist/extensions/isolated/child-session.js +343 -0
  144. package/dist/extensions/isolated/child-streams.d.ts +4 -0
  145. package/dist/extensions/isolated/child-streams.js +142 -0
  146. package/dist/extensions/isolated/child.d.ts +1 -0
  147. package/dist/extensions/isolated/child.js +10 -0
  148. package/dist/extensions/isolated/configured-package.d.ts +15 -0
  149. package/dist/extensions/isolated/configured-package.js +73 -0
  150. package/dist/extensions/isolated/lanes.d.ts +100 -0
  151. package/dist/extensions/isolated/lanes.js +699 -0
  152. package/dist/extensions/isolated/postgres-gate.d.ts +14 -0
  153. package/dist/extensions/isolated/postgres-gate.js +255 -0
  154. package/dist/extensions/isolated/revision.d.ts +32 -0
  155. package/dist/extensions/isolated/revision.js +358 -0
  156. package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
  157. package/dist/extensions/isolated/rpc-frame.js +193 -0
  158. package/dist/extensions/isolated/rpc.d.ts +66 -0
  159. package/dist/extensions/isolated/rpc.js +314 -0
  160. package/dist/extensions/isolated/sandbox.d.ts +35 -0
  161. package/dist/extensions/isolated/sandbox.js +372 -0
  162. package/dist/extensions/isolated/tier.d.ts +6 -0
  163. package/dist/extensions/isolated/tier.js +45 -0
  164. package/dist/extensions/ledger.d.ts +1 -1
  165. package/dist/extensions/lifecycle-topics.d.ts +1 -0
  166. package/dist/extensions/lifecycle-topics.js +1 -0
  167. package/dist/extensions/lifecycle.d.ts +3 -1
  168. package/dist/extensions/lifecycle.js +32 -5
  169. package/dist/extensions/locks.d.ts +2 -0
  170. package/dist/extensions/locks.js +7 -0
  171. package/dist/extensions/org-config.d.ts +17 -27
  172. package/dist/extensions/org-config.js +114 -129
  173. package/dist/extensions/permission-view.d.ts +3 -1
  174. package/dist/extensions/permission-view.js +4 -1
  175. package/dist/extensions/plugin-guides.d.ts +5 -10
  176. package/dist/extensions/plugin-guides.js +18 -37
  177. package/dist/extensions/plugin-icons.d.ts +3 -21
  178. package/dist/extensions/plugin-icons.js +9 -44
  179. package/dist/extensions/plugin-items.d.ts +10 -30
  180. package/dist/extensions/plugin-items.js +32 -73
  181. package/dist/extensions/point-defaults.d.ts +13 -21
  182. package/dist/extensions/point-defaults.js +32 -72
  183. package/dist/extensions/point-serving.d.ts +56 -0
  184. package/dist/extensions/point-serving.js +120 -0
  185. package/dist/extensions/source-intent.d.ts +14 -0
  186. package/dist/extensions/source-intent.js +77 -0
  187. package/dist/inbox/inbox-items.service.d.ts +11 -0
  188. package/dist/inbox/inbox-items.service.js +39 -0
  189. package/dist/index.d.ts +2 -1
  190. package/dist/index.js +2 -1
  191. package/dist/infra/database/database.module.js +6 -1
  192. package/dist/infra/database/kernel-db.d.ts +3 -1
  193. package/dist/infra/database/kernel-db.js +4 -0
  194. package/dist/infra/outbox/registry.d.ts +70 -0
  195. package/dist/infra/outbox/registry.js +44 -0
  196. package/dist/infra/paging/paged-read.d.ts +56 -0
  197. package/dist/infra/paging/paged-read.js +78 -0
  198. package/dist/infra/queue/queue-names.d.ts +1 -1
  199. package/dist/infra/queue/queue-names.js +1 -0
  200. package/dist/kernel.d.ts +3 -2
  201. package/dist/kernel.js +21 -2
  202. package/dist/kernel.module.js +4 -0
  203. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  204. package/dist/lifecycle/kernel-lifecycle.js +22 -12
  205. package/dist/lifecycle/tokens.d.ts +8 -0
  206. package/dist/lifecycle/tokens.js +2 -0
  207. package/dist/orgs/directory-sync.js +1 -4
  208. package/dist/platform/exclusions.js +10 -0
  209. package/dist/platform/ops/admin.ops.js +14 -3
  210. package/dist/platform/ops/conversations.ops.d.ts +8 -1
  211. package/dist/platform/ops/conversations.ops.js +52 -14
  212. package/dist/platform/ops/orgs.ops.js +13 -3
  213. package/dist/plugin-reads/plugin-reads.service.js +4 -1
  214. package/dist/push/recipients.js +5 -2
  215. package/dist/retention/worker.js +2 -1
  216. package/dist/roles/worker-role.d.ts +3 -1
  217. package/dist/roles/worker-role.js +8 -2
  218. package/dist/roles/worker.module.js +3 -0
  219. package/dist/runtime/context/build.js +8 -0
  220. package/dist/runtime/context/compaction.js +7 -0
  221. package/dist/runtime/idle-arm.js +3 -1
  222. package/dist/runtime/idle-compaction.js +2 -1
  223. package/dist/runtime/run-finish.js +2 -1
  224. package/dist/runtime/run-jobs.js +2 -1
  225. package/dist/runtime/run-queue.js +4 -2
  226. package/dist/runtime/run-worker.js +5 -2
  227. package/dist/runtime/stream.js +10 -0
  228. package/dist/runtime/usage-report.js +2 -1
  229. package/dist/runtime/waits.js +2 -1
  230. package/dist/setup/setup-checks.service.js +3 -2
  231. package/dist/skills/usable.js +41 -30
  232. package/dist/themes/theme-state.js +3 -3
  233. package/dist/tools/approvals.service.js +6 -2
  234. package/dist/tools/builtins/skill-load.js +3 -2
  235. package/dist/tools/registry.d.ts +1 -1
  236. package/dist/tools/registry.js +1 -1
  237. package/dist/tools/tool-watch.service.js +3 -1
  238. package/package.json +3 -3
  239. package/src/migrations/0227_external_conversations.sql +33 -0
  240. package/src/migrations/0228_extension_org_switches.sql +56 -0
  241. package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
  242. package/src/migrations/0230_audit_filter_idx.sql +18 -0
@@ -1,6 +1,6 @@
1
1
  import { skillDisabled } from "../agents/definition.js";
2
2
  import { componentOn, platformBuiltin } from "../catalog/component-state.js";
3
- import { LIVE_INSTALL_STATUSES } from "../catalog/install-status.js";
3
+ import { orgUsable } from "../catalog/org-intent.js";
4
4
  /** The `source` prefix of a platform skill version in a snapshot or an invocation record. */
5
5
  export const PLATFORM_SOURCE = "platform:";
6
6
  /** The snapshot `source` of a platform skill version stored at `prefix` (in `deployment/`). */
@@ -41,14 +41,25 @@ async function platformRowsOn(db, orgId, ids) {
41
41
  "c.owner_org_id as item_owner",
42
42
  "p.owner_org_id",
43
43
  "p.shareable",
44
+ orgUsable(db, orgId, eb.ref("p.catalog_item_id")).as("plugin_usable"),
44
45
  eb
45
- .exists(eb
46
- .selectFrom("plugin_installs as a")
47
- .select("a.id")
48
- .whereRef("a.item_id", "=", "p.catalog_item_id")
49
- .where("a.org_id", "=", orgId)
50
- .where("a.status", "in", [...LIVE_INSTALL_STATUSES]))
51
- .as("installed"),
46
+ .or([
47
+ eb.exists(eb
48
+ .selectFrom("catalog_item_org_switches as ps")
49
+ .select("ps.item_id")
50
+ .whereRef("ps.item_id", "=", "p.catalog_item_id")
51
+ .where("ps.org_id", "=", orgId)
52
+ .where("ps.enabled", "=", true)),
53
+ eb.and([
54
+ eb("c.scope", "=", "named"),
55
+ eb.exists(eb
56
+ .selectFrom("catalog_item_scope_orgs as pl")
57
+ .select("pl.item_id")
58
+ .whereRef("pl.item_id", "=", "p.catalog_item_id")
59
+ .where("pl.org_id", "=", orgId)),
60
+ ]),
61
+ ])
62
+ .as("plugin_associated"),
52
63
  eb
53
64
  .exists(eb
54
65
  .selectFrom("component_scope_orgs as l")
@@ -69,28 +80,28 @@ async function platformRowsOn(db, orgId, ids) {
69
80
  .where("p.disabled", "=", false);
70
81
  if (ids !== undefined)
71
82
  q = q.where("p.id", "in", [...ids]);
72
- // the share gate (ruling P3-1, as `usableBy` in catalog/ownership.ts): another org's skill
73
- // while its owner shares it, or while this org is associated with it (listed, its plugin
74
- // installed here, or switched on here: an org keeps what it has when sharing stops, P3-16)
75
- const gate = (r) => r.owner_org_id === null ||
76
- r.owner_org_id === orgId ||
77
- r.shareable ||
78
- Boolean(r.listed) ||
79
- Boolean(r.installed) ||
80
- r.switch === true;
81
- // the predicate of component scope (catalog/component-state.ts); `disabled` is filtered above
82
- return (await q.execute()).filter((r) => gate(r) &&
83
- componentOn({ scopeMode: r.scope_mode, scope: r.scope, disabled: false, itemId: r.catalog_item_id }, r.catalog_item_id === null
84
- ? null
85
- : {
86
- live: r.item_id !== null,
87
- disabled: r.item_disabled === true,
88
- builtin: platformBuiltin({ builtin: r.item_builtin, owner_org_id: r.item_owner }),
89
- // the plugin's own scope and list do not decide whether a component is on
90
- scope: "optional",
91
- listed: false,
92
- installed: Boolean(r.installed),
93
- }, Boolean(r.listed), r.switch ?? null));
83
+ // A foreign skill stays available after unsharing only through an explicit association.
84
+ // The parent plugin's implicit defaults cannot grant access to another org's skill.
85
+ return (await q.execute()).filter((r) => {
86
+ const admitted = r.owner_org_id === null ||
87
+ r.owner_org_id === orgId ||
88
+ r.shareable ||
89
+ Boolean(r.listed) ||
90
+ (r.plugin_usable && Boolean(r.plugin_associated)) ||
91
+ r.switch === true;
92
+ return (admitted &&
93
+ componentOn({ scopeMode: r.scope_mode, scope: r.scope, disabled: false, itemId: r.catalog_item_id }, r.catalog_item_id === null
94
+ ? null
95
+ : {
96
+ live: r.item_id !== null,
97
+ disabled: r.item_disabled === true,
98
+ builtin: platformBuiltin({ builtin: r.item_builtin, owner_org_id: r.item_owner }),
99
+ // the plugin's own scope and list do not decide whether a component is on
100
+ scope: "optional",
101
+ listed: false,
102
+ usable: r.plugin_usable,
103
+ }, Boolean(r.listed), r.switch ?? null));
104
+ });
94
105
  }
95
106
  /**
96
107
  * The ids among `ids` of the platform skills on in the org (see {@link platformOn}), whatever the
@@ -154,7 +154,7 @@ export async function themesOnIn(db, orgId) {
154
154
  const comps = await loadComponents(db, "theme");
155
155
  if (comps.length === 0)
156
156
  return [];
157
- const st = await loadScopeState(db, "theme", comps);
157
+ const st = await loadScopeState(db, "theme", comps, orgId);
158
158
  return comps.filter((c) => onIn(st, c, orgId));
159
159
  }
160
160
  /**
@@ -251,7 +251,7 @@ export async function assertPlatformDefaultEligible(db, id) {
251
251
  export async function assertThemeOnIn(db, orgId, id) {
252
252
  await lockThemeShared(db, id);
253
253
  const [c] = await loadComponents(db, "theme", { ids: [id] });
254
- const st = c && (await loadScopeState(db, "theme", [c]));
254
+ const st = c && (await loadScopeState(db, "theme", [c], orgId));
255
255
  if (!c || !st || !onIn(st, c, orgId))
256
256
  throw themeNotAvailable(id, "in this organization");
257
257
  }
@@ -260,7 +260,7 @@ export async function themeOnIn(db, orgId, id) {
260
260
  const [c] = await loadComponents(db, "theme", { ids: [id] });
261
261
  if (!c)
262
262
  return false;
263
- return onIn(await loadScopeState(db, "theme", [c]), c, orgId);
263
+ return onIn(await loadScopeState(db, "theme", [c], orgId), c, orgId);
264
264
  }
265
265
  /** Whether theme `id` is on in at least one of the person's live orgs. */
266
266
  export async function themeOnForAccount(db, accountId, id) {
@@ -15,6 +15,7 @@ import { normalizeStoredDefinition } from "../agents/definition.js";
15
15
  import { GIT_GRANT_SPEC_HASH, gitGrantRefusal, gitPushGrantKey, grantRefusalOf, NETWORK_GRANT_PREFIX, NETWORK_GRANT_SPEC_HASH, networkGrantRefusal, normalizeGitRepo, } from "../automations/grant-rules.js";
16
16
  import { AutomationStore } from "../automations/store.js";
17
17
  import { unattendedRunOf, unattendedTaskRunOf } from "../automations/unattended.js";
18
+ import { agentIdOf } from "../conversations/conversation-agent.js";
18
19
  import { EventLog } from "../conversations/event-log.js";
19
20
  import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, SECURE_INPUT_MAX_FIELDS, } from "../conversations/events.js";
20
21
  import { ConversationLeakCheck } from "../conversations/leak-check.js";
@@ -1675,7 +1676,8 @@ let ApprovalsService = class ApprovalsService {
1675
1676
  .values({
1676
1677
  org_id: orgId,
1677
1678
  account_id: before.requestedFor,
1678
- agent_id: ctx.agent_id,
1679
+ // a run's conversation always has an agent (an external one has no runs)
1680
+ agent_id: agentIdOf(ctx),
1679
1681
  tool_key: before.toolKey,
1680
1682
  spec_hash: hash,
1681
1683
  connector_id: connectorId,
@@ -2432,7 +2434,9 @@ let ApprovalsService = class ApprovalsService {
2432
2434
  "conversations.parent_conversation_id",
2433
2435
  ])
2434
2436
  .where("runs.id", "in", [...new Set(recs.map((r) => r.runId))])
2435
- .execute();
2437
+ .execute()
2438
+ // a run's conversation always has an agent (an external one has no runs)
2439
+ .then((rows) => rows.map((r) => ({ ...r, agent_id: agentIdOf(r) })));
2436
2440
  const ctx = new Map(ctxRows.map((r) => [r.id, r]));
2437
2441
  // a sub-agent's approval links to the root conversation of its tree (agent map spec §7)
2438
2442
  const roots = new Map();
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { parseSkillMd, renderSkillBody, SKILL_ENTRY_FILE, SKILL_INVOCATION_LIMITS, SKILLS_SANDBOX_ROOT, skillDigest, skillInvocation, skillSandboxDir, skillSandboxPath, ToolError, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
3
3
  import { sql } from "kysely";
4
4
  import { normalizeStoredDefinition } from "../../agents/definition.js";
5
+ import { agentIdOf } from "../../conversations/conversation-agent.js";
5
6
  import { ApiError } from "../../errors.js";
6
7
  import { callableProjectSkills, projectSkillName, projectSkillOf, } from "../../runtime/context/project-root.js";
7
8
  import { latestInvocation } from "../../runtime/context/skills.js";
@@ -292,7 +293,7 @@ async function runAgent(db, ctx) {
292
293
  .where("conversations.org_id", "=", ctx.orgId)
293
294
  .executeTakeFirst();
294
295
  return row
295
- ? { agentId: row.agent_id, definition: normalizeStoredDefinition(row.definition) }
296
+ ? { agentId: agentIdOf(row), definition: normalizeStoredDefinition(row.definition) }
296
297
  : undefined;
297
298
  }
298
299
  /**
@@ -323,7 +324,7 @@ async function invocationScope(db, ctx) {
323
324
  .executeTakeFirst();
324
325
  return row
325
326
  ? {
326
- agentId: row.agent_id,
327
+ agentId: agentIdOf(row),
327
328
  definition: normalizeStoredDefinition(row.definition),
328
329
  conversationId: dispatch.parentConversationId,
329
330
  }
@@ -359,7 +359,7 @@ export interface AgentTools {
359
359
  * - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
360
360
  * says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
361
361
  * - extension tools: every tool registered by an extension loaded on this replica and enabled in
362
- * the org (`extension_org_configs.enabled`; required bootstrap plugins and builtin plugins'
362
+ * the org (required bootstrap plugins and builtin plugins'
363
363
  * extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
364
364
  * org did not switch off (§7: the org's switch wins);
365
365
  * - connector tools: every enabled tool of every live, active, `ready` connector of the org
@@ -110,7 +110,7 @@ const builtinTool = (b, spec) => ({
110
110
  * - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
111
111
  * says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
112
112
  * - extension tools: every tool registered by an extension loaded on this replica and enabled in
113
- * the org (`extension_org_configs.enabled`; required bootstrap plugins and builtin plugins'
113
+ * the org (required bootstrap plugins and builtin plugins'
114
114
  * extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
115
115
  * org did not switch off (§7: the org's switch wins);
116
116
  * - connector tools: every enabled tool of every live, active, `ready` connector of the org
@@ -11,6 +11,7 @@ import { parseToolKey } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable, Optional } from "@nestjs/common";
12
12
  import { DelayedError } from "bullmq";
13
13
  import { sql } from "kysely";
14
+ import { agentIdOf } from "../conversations/conversation-agent.js";
14
15
  import { EffectiveConfigs } from "../extensions/effective-config.js";
15
16
  import { isExtensionEnabled } from "../extensions/enabled.js";
16
17
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -151,7 +152,8 @@ let ToolWatchService = class ToolWatchService {
151
152
  ...extensionCallContext({
152
153
  orgId: row.org_id,
153
154
  accountId: row.trigger_account_id,
154
- agentId: row.agent_id,
155
+ // a question belongs to a run: its conversation has an agent (an external one has none)
156
+ agentId: agentIdOf(row),
155
157
  conversationId: row.conversation_id,
156
158
  rootConversationId,
157
159
  runId: row.run_id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.135",
3
+ "version": "0.1.0-rc.137",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -70,7 +70,7 @@
70
70
  "yaml": "^2.9.1",
71
71
  "yauzl": "3.4.0",
72
72
  "zod": "^4.6.7",
73
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.99"
73
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.100"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -82,7 +82,7 @@
82
82
  "@types/yauzl": "3.4.0",
83
83
  "pg-cursor": "^2.22.1",
84
84
  "ws": "^8.22.0",
85
- "@capybara-hq/testing": "0.1.0-rc.55"
85
+ "@capybara-hq/testing": "0.1.0-rc.57"
86
86
  },
87
87
  "scripts": {
88
88
  "build": "tsc -b"
@@ -0,0 +1,33 @@
1
+ -- External conversations (local agents spec 2026-12-01, Part 2): a conversation the person holds
2
+ -- with a `conversation-target@1` target (a local agent on their device). The kernel mirrors it and
3
+ -- never runs it, so it has no agent.
4
+ -- - kind gains 'external'; agent_id becomes nullable: null exactly for 'external', which names its
5
+ -- target in `external` ({ extension, targetKey, label }) instead (one CHECK).
6
+ -- - external_state: what the target last reported (running / waiting / idle / ended).
7
+ -- - external_delivered_seq: the highest `external_user_message.deliverySeq` handed to the target;
8
+ -- -1 (written only by the kernel) marks a conversation whose `start` was dropped after its retries.
9
+ -- Additive only: the new columns have a default or are nullable and the CHECKs admit every
10
+ -- existing row, so a running older version keeps working during a rolling upgrade (it never
11
+ -- writes 'external' and always writes an agent).
12
+ -- The widened kind CHECK is re-added NOT VALID: the old CHECK implies the new one, so existing
13
+ -- rows need no scan. The shape CHECK is new, so it is added NOT VALID and then validated: the scan
14
+ -- proves every existing row (all of them have an agent and no target) fits it.
15
+
16
+ -- capybara:allow-destructive the CHECK is re-added with one more allowed value in the same transaction
17
+ ALTER TABLE conversations DROP CONSTRAINT IF EXISTS conversations_kind_check;
18
+ ALTER TABLE conversations ADD CONSTRAINT conversations_kind_check
19
+ CHECK (kind IN ('chat', 'eval', 'subagent', 'external')) NOT VALID;
20
+
21
+ ALTER TABLE conversations ALTER COLUMN agent_id DROP NOT NULL;
22
+ ALTER TABLE conversations ADD COLUMN IF NOT EXISTS external jsonb;
23
+ ALTER TABLE conversations ADD COLUMN IF NOT EXISTS external_state text NOT NULL DEFAULT 'idle'
24
+ CONSTRAINT conversations_external_state_check
25
+ CHECK (external_state IN ('running', 'waiting', 'idle', 'ended'));
26
+ ALTER TABLE conversations ADD COLUMN IF NOT EXISTS external_delivered_seq bigint NOT NULL DEFAULT 0;
27
+
28
+ ALTER TABLE conversations DROP CONSTRAINT IF EXISTS conversations_external_shape;
29
+ ALTER TABLE conversations ADD CONSTRAINT conversations_external_shape CHECK (
30
+ kind = 'external' AND agent_id IS NULL AND external IS NOT NULL
31
+ OR kind <> 'external' AND agent_id IS NOT NULL AND external IS NULL
32
+ ) NOT VALID;
33
+ ALTER TABLE conversations VALIDATE CONSTRAINT conversations_external_shape;
@@ -0,0 +1,56 @@
1
+ -- Apply with all old kernel roles stopped. This release reads and writes only these switches.
2
+ -- capybara:allow-destructive the wider check immediately replaces the previous kind constraint
3
+ ALTER TABLE component_org_switches DROP CONSTRAINT IF EXISTS component_org_switches_kind_check;
4
+ ALTER TABLE component_org_switches ADD CONSTRAINT component_org_switches_kind_check
5
+ CHECK (kind IN ('skill', 'agent_template', 'connector_template', 'theme', 'extension'));
6
+
7
+ CREATE INDEX IF NOT EXISTS component_org_switches_extension_org_idx
8
+ ON component_org_switches (org_id, component_id) WHERE kind = 'extension';
9
+
10
+ WITH sources AS (
11
+ SELECT name AS plugin, catalog_item_id AS item_id
12
+ FROM extension_installs
13
+ WHERE catalog_item_id IS NOT NULL
14
+ UNION
15
+ SELECT plugin, item_id FROM extension_catalog_sources
16
+ )
17
+ INSERT INTO component_org_switches (kind, component_id, org_id, enabled, updated_by, updated_at)
18
+ SELECT 'extension', old.plugin, old.org_id, old.enabled, old.updated_by, old.updated_at
19
+ FROM extension_org_configs AS old
20
+ JOIN orgs AS org ON org.id = old.org_id AND org.deleted_at IS NULL
21
+ CROSS JOIN LATERAL (
22
+ SELECT count(*) AS all_sources,
23
+ count(*) FILTER (WHERE item.deleted_at IS NULL) AS live_sources,
24
+ bool_or(item.builtin AND item.owner_org_id IS NULL) FILTER (WHERE item.deleted_at IS NULL) AS builtin,
25
+ bool_or(install.id IS NOT NULL) FILTER (WHERE item.deleted_at IS NULL) AS installed,
26
+ bool_and(
27
+ NOT item.disabled
28
+ AND (
29
+ item.owner_org_id IS NULL OR item.owner_org_id = old.org_id OR (
30
+ item.shareable AND EXISTS (
31
+ SELECT 1 FROM catalog_item_versions AS published
32
+ WHERE published.item_id = item.id AND published.version = item.latest_version
33
+ AND published.applied_at IS NOT NULL
34
+ )
35
+ )
36
+ )
37
+ AND (item.scope <> 'named' OR listed.item_id IS NOT NULL)
38
+ ) FILTER (WHERE item.deleted_at IS NULL) AS authorized
39
+ FROM sources AS source
40
+ JOIN catalog_items AS item ON item.id = source.item_id
41
+ LEFT JOIN catalog_item_scope_orgs AS listed
42
+ ON listed.item_id = item.id AND listed.org_id = old.org_id
43
+ LEFT JOIN plugin_installs AS install
44
+ ON install.item_id = item.id AND install.org_id = old.org_id AND install.status = 'installed'
45
+ WHERE source.plugin = old.plugin
46
+ ) AS scope
47
+ WHERE NOT EXISTS (
48
+ SELECT 1 FROM extension_installs AS install WHERE install.name = old.plugin AND install.required
49
+ )
50
+ AND NOT coalesce(scope.builtin, false)
51
+ AND (
52
+ (scope.live_sources = 1 AND scope.installed AND NOT old.enabled)
53
+ OR (scope.all_sources = 0 AND old.enabled)
54
+ OR (scope.live_sources > 1 AND scope.authorized AND old.enabled)
55
+ )
56
+ ON CONFLICT (kind, component_id, org_id) DO NOTHING;
@@ -0,0 +1,17 @@
1
+ -- A deployment projection of the selected catalog versions. The kernel populates it with
2
+ -- its catalog SemVer resolver before starting the new roles.
3
+ CREATE TABLE IF NOT EXISTS catalog_dependency_edges (
4
+ item_id uuid NOT NULL,
5
+ item_version text NOT NULL,
6
+ dependency_name text NOT NULL,
7
+ -- Empty for a declared dependency, otherwise the stable connector template ID.
8
+ template_id text NOT NULL DEFAULT '',
9
+ dependency_item_id uuid,
10
+ dependency_version text,
11
+ PRIMARY KEY (item_id, dependency_name, template_id),
12
+ CHECK ((dependency_item_id IS NULL) = (dependency_version IS NULL))
13
+ );
14
+
15
+ CREATE INDEX IF NOT EXISTS catalog_dependency_edges_reverse_idx
16
+ ON catalog_dependency_edges (dependency_item_id, dependency_version, item_id)
17
+ WHERE dependency_item_id IS NOT NULL;
@@ -0,0 +1,18 @@
1
+ -- The audit log's actor filter and actor options (table pagination spec §3): one org's (or, with
2
+ -- org_id IS NULL, the platform's) events by one account, newest first, and the distinct accounts
3
+ -- and tokens that acted, read by a skip scan. The indexes are not partial on org_id, so the same
4
+ -- index serves `org_id = $1` and `org_id IS NULL`. The time filter needs no new index: 0003's
5
+ -- audit_events_org_at_idx (org_id, at DESC) is not partial either and serves both scopes.
6
+ -- Plain CREATE INDEX: the migrator runs each file in a transaction.
7
+ CREATE INDEX IF NOT EXISTS audit_events_actor_idx
8
+ ON audit_events (org_id, actor_account_id, id DESC);
9
+
10
+ -- Events done with an access token (a small share of the log): the token filter and the token
11
+ -- options.
12
+ CREATE INDEX IF NOT EXISTS audit_events_token_idx
13
+ ON audit_events (org_id, actor_token_id, id DESC) WHERE actor_token_id IS NOT NULL;
14
+
15
+ -- The object filter (q): a target id matched exactly, or against the ids a name semi-join finds,
16
+ -- within the scope, newest first.
17
+ CREATE INDEX IF NOT EXISTS audit_events_target_idx
18
+ ON audit_events (org_id, target, id DESC);