@capybara-hq/kernel 0.1.0-rc.35 → 0.1.0-rc.37

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 (311) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -3
  3. package/dist/admin/admin.module.js +6 -6
  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/outbox-dead.controller.d.ts +4 -6
  11. package/dist/admin/outbox-dead.controller.js +9 -6
  12. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  13. package/dist/admin/outbox-dead.schemas.js +25 -1
  14. package/dist/admin/outbox-dead.service.d.ts +16 -7
  15. package/dist/admin/outbox-dead.service.js +34 -10
  16. package/dist/admin/overview.service.d.ts +3 -3
  17. package/dist/admin/overview.service.js +0 -1
  18. package/dist/agents/agent-lookup.js +2 -10
  19. package/dist/agents/agents.module.js +3 -0
  20. package/dist/agents/agents.service.js +9 -20
  21. package/dist/agents/definition.d.ts +3 -51
  22. package/dist/agents/definition.js +4 -254
  23. package/dist/agents/org-templates.js +2 -6
  24. package/dist/agents/readiness.controller.d.ts +8 -19
  25. package/dist/agents/readiness.controller.js +11 -25
  26. package/dist/agents/readiness.service.d.ts +42 -0
  27. package/dist/agents/readiness.service.js +78 -0
  28. package/dist/agents/templates.d.ts +0 -6
  29. package/dist/agents/templates.js +8 -34
  30. package/dist/background/store.d.ts +2 -0
  31. package/dist/background/store.js +3 -1
  32. package/dist/background/wake-rules.js +2 -1
  33. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  34. package/dist/catalog/admin-catalog.controller.js +1 -2
  35. package/dist/catalog/appearance.service.js +1 -3
  36. package/dist/catalog/catalog-content.d.ts +1 -1
  37. package/dist/catalog/catalog-content.js +1 -4
  38. package/dist/catalog/catalog-items.js +3 -3
  39. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  40. package/dist/catalog/catalog-scope.service.js +22 -73
  41. package/dist/catalog/cli.d.ts +0 -11
  42. package/dist/catalog/cli.js +0 -20
  43. package/dist/catalog/component-scope.service.js +0 -2
  44. package/dist/catalog/component-state.js +2 -2
  45. package/dist/catalog/install-status.d.ts +6 -0
  46. package/dist/catalog/install-status.js +6 -0
  47. package/dist/catalog/job-ids.d.ts +0 -4
  48. package/dist/catalog/job-ids.js +0 -4
  49. package/dist/catalog/marketplaces.service.d.ts +1 -1
  50. package/dist/catalog/org-catalog.service.d.ts +2 -0
  51. package/dist/catalog/org-catalog.service.js +8 -3
  52. package/dist/catalog/org-extension-switch.d.ts +7 -2
  53. package/dist/catalog/org-extension-switch.js +56 -9
  54. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  55. package/dist/catalog/org-plugin-uploads.js +9 -27
  56. package/dist/catalog/owned-items.js +1 -3
  57. package/dist/catalog/platform-import-update.js +1 -1
  58. package/dist/catalog/plugin-import.d.ts +15 -13
  59. package/dist/catalog/plugin-import.js +21 -30
  60. package/dist/catalog/plugin-install.d.ts +3 -43
  61. package/dist/catalog/plugin-install.js +8 -150
  62. package/dist/catalog/plugin-package.d.ts +5 -10
  63. package/dist/catalog/plugin-package.js +12 -33
  64. package/dist/catalog/plugin-upgrade.js +5 -4
  65. package/dist/catalog/scope-jobs.d.ts +34 -34
  66. package/dist/catalog/scope-jobs.js +50 -37
  67. package/dist/catalog/scope-orgs.d.ts +1 -1
  68. package/dist/catalog/scope-orgs.js +1 -2
  69. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  70. package/dist/catalog/scope-sync-workers.js +18 -6
  71. package/dist/catalog/scope-sync.d.ts +56 -59
  72. package/dist/catalog/scope-sync.js +96 -166
  73. package/dist/catalog/unshare.d.ts +3 -4
  74. package/dist/catalog/unshare.js +5 -8
  75. package/dist/channels/job-ids.d.ts +2 -6
  76. package/dist/channels/job-ids.js +2 -6
  77. package/dist/channels/outbound.d.ts +1 -1
  78. package/dist/channels/outbound.js +1 -1
  79. package/dist/channels/supervisor.d.ts +2 -3
  80. package/dist/channels/supervisor.js +2 -3
  81. package/dist/client/client-access.service.js +1 -1
  82. package/dist/config/env.js +19 -1
  83. package/dist/config/load.d.ts +0 -6
  84. package/dist/config/load.js +8 -27
  85. package/dist/config/schema.d.ts +53 -47
  86. package/dist/config/schema.js +190 -40
  87. package/dist/conversations/attachments.service.d.ts +10 -3
  88. package/dist/conversations/attachments.service.js +49 -16
  89. package/dist/conversations/conversations.controller.d.ts +0 -39
  90. package/dist/conversations/conversations.controller.js +0 -39
  91. package/dist/conversations/events.d.ts +71 -46
  92. package/dist/conversations/events.js +124 -112
  93. package/dist/conversations/media-types.d.ts +25 -0
  94. package/dist/conversations/media-types.js +38 -0
  95. package/dist/conversations/queue.d.ts +3 -1
  96. package/dist/conversations/queue.service.js +9 -2
  97. package/dist/conversations/titles.js +6 -0
  98. package/dist/ctx/create-ctx.js +1 -2
  99. package/dist/ctx/secrets.d.ts +24 -7
  100. package/dist/ctx/secrets.js +97 -30
  101. package/dist/db/kernel-schema.d.ts +17 -6
  102. package/dist/errors.d.ts +5 -2
  103. package/dist/errors.js +5 -2
  104. package/dist/evals/reconstruct.d.ts +4 -17
  105. package/dist/evals/reconstruct.js +13 -53
  106. package/dist/evals/recorded-tools.d.ts +0 -27
  107. package/dist/evals/recorded-tools.js +2 -92
  108. package/dist/evals/run-replay.d.ts +1 -6
  109. package/dist/evals/run-replay.js +10 -17
  110. package/dist/evals/sets.service.d.ts +17 -5
  111. package/dist/evals/sets.service.js +33 -12
  112. package/dist/evals/snapshot.d.ts +1 -2
  113. package/dist/evals/snapshot.js +4 -17
  114. package/dist/extensions/admin-ops.d.ts +6 -1
  115. package/dist/extensions/admin-ops.js +17 -4
  116. package/dist/extensions/admin-view.d.ts +7 -4
  117. package/dist/extensions/admin-view.js +27 -21
  118. package/dist/extensions/bootstrap.js +0 -1
  119. package/dist/extensions/cli.js +0 -1
  120. package/dist/extensions/host.d.ts +2 -3
  121. package/dist/extensions/host.js +1 -5
  122. package/dist/extensions/installs.d.ts +1 -3
  123. package/dist/extensions/instance.d.ts +0 -2
  124. package/dist/extensions/instance.js +0 -3
  125. package/dist/extensions/org-config.d.ts +4 -4
  126. package/dist/extensions/org-config.js +13 -22
  127. package/dist/extensions/package.d.ts +6 -6
  128. package/dist/extensions/package.js +3 -7
  129. package/dist/extensions/permission-view.d.ts +2 -4
  130. package/dist/extensions/plugin-items.d.ts +21 -1
  131. package/dist/extensions/plugin-items.js +28 -0
  132. package/dist/extensions/sync.js +5 -10
  133. package/dist/extensions/unavailable.js +0 -1
  134. package/dist/http/api.module.js +2 -1
  135. package/dist/identity/audit.d.ts +0 -12
  136. package/dist/identity/audit.js +0 -27
  137. package/dist/identity/auth.controller.js +5 -9
  138. package/dist/identity/cookies.d.ts +4 -9
  139. package/dist/identity/cookies.js +8 -32
  140. package/dist/identity/initial-passwords.d.ts +1 -1
  141. package/dist/identity/initial-passwords.js +1 -2
  142. package/dist/identity/sessions.d.ts +0 -6
  143. package/dist/identity/sessions.js +0 -18
  144. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  145. package/dist/inbox/platform-inbox.service.js +56 -6
  146. package/dist/index.d.ts +4 -2
  147. package/dist/index.js +4 -2
  148. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  149. package/dist/infra/cli/master-key-rewrap.js +24 -0
  150. package/dist/infra/config/kernel-config.service.js +0 -17
  151. package/dist/infra/health/health.controller.js +8 -0
  152. package/dist/infra/health/process-fault.d.ts +16 -0
  153. package/dist/infra/health/process-fault.js +49 -0
  154. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  155. package/dist/infra/lifecycle/process-guards.js +12 -3
  156. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  157. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  158. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  159. package/dist/infra/outbox/outbox.service.js +22 -26
  160. package/dist/infra/outbox/registry.d.ts +15 -7
  161. package/dist/infra/outbox/registry.js +39 -23
  162. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  163. package/dist/models/enablement.d.ts +5 -6
  164. package/dist/models/enablement.js +7 -14
  165. package/dist/orgs/orgs.module.d.ts +2 -2
  166. package/dist/orgs/orgs.module.js +2 -2
  167. package/dist/orgs/settings.controller.d.ts +3 -2
  168. package/dist/orgs/settings.service.d.ts +59 -14
  169. package/dist/orgs/settings.service.js +102 -20
  170. package/dist/overrides.d.ts +3 -7
  171. package/dist/overrides.js +2 -4
  172. package/dist/packages/tgz.d.ts +0 -2
  173. package/dist/packages/tgz.js +0 -2
  174. package/dist/platform/exclusions.js +0 -5
  175. package/dist/platform/operation.js +1 -1
  176. package/dist/platform/ops/admin.ops.d.ts +2 -2
  177. package/dist/platform/ops/admin.ops.js +9 -6
  178. package/dist/platform/ops/agents.ops.d.ts +3 -3
  179. package/dist/platform/ops/agents.ops.js +7 -10
  180. package/dist/platform/ops/connectors.ops.js +46 -1
  181. package/dist/platform/ops/evals.ops.js +1 -64
  182. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  183. package/dist/platform/ops/inbox.ops.js +16 -3
  184. package/dist/platform/ops/org-plugins.ops.js +1 -1
  185. package/dist/platform/ops/orgs.ops.d.ts +5 -3
  186. package/dist/platform/ops/orgs.ops.js +19 -4
  187. package/dist/platform/ops/outbox.ops.js +5 -5
  188. package/dist/roles/worker-role.d.ts +2 -3
  189. package/dist/roles/worker-role.js +3 -13
  190. package/dist/runtime/context/build.d.ts +56 -18
  191. package/dist/runtime/context/build.js +143 -50
  192. package/dist/runtime/context/compaction.d.ts +1 -3
  193. package/dist/runtime/context/compaction.js +42 -8
  194. package/dist/runtime/context/run-context.js +1 -2
  195. package/dist/runtime/context/skills.d.ts +27 -56
  196. package/dist/runtime/context/skills.js +42 -114
  197. package/dist/runtime/context/tool-changes.d.ts +3 -3
  198. package/dist/runtime/context/tool-changes.js +6 -16
  199. package/dist/runtime/hook-calls.d.ts +6 -6
  200. package/dist/runtime/hook-calls.js +7 -7
  201. package/dist/runtime/langgraph-loop.js +1 -0
  202. package/dist/runtime/maintenance.d.ts +3 -11
  203. package/dist/runtime/maintenance.js +5 -20
  204. package/dist/runtime/model-call.d.ts +5 -0
  205. package/dist/runtime/model-call.js +48 -36
  206. package/dist/runtime/providers.d.ts +33 -35
  207. package/dist/runtime/providers.js +64 -109
  208. package/dist/runtime/run-context.service.js +7 -22
  209. package/dist/runtime/run-deletion.d.ts +6 -0
  210. package/dist/runtime/run-deletion.js +39 -16
  211. package/dist/runtime/run-execution.js +4 -3
  212. package/dist/runtime/run-finish.js +2 -1
  213. package/dist/runtime/run-liveness.d.ts +11 -0
  214. package/dist/runtime/run-liveness.js +19 -0
  215. package/dist/runtime/run-orphan-check.job.js +2 -1
  216. package/dist/runtime/run-queue.js +8 -16
  217. package/dist/runtime/run-worker.d.ts +2 -2
  218. package/dist/runtime/run-worker.js +8 -6
  219. package/dist/runtime/subagents/definition.d.ts +16 -20
  220. package/dist/runtime/subagents/definition.js +27 -27
  221. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  222. package/dist/runtime/subagents/dispatch.js +17 -3
  223. package/dist/runtime/subagents/org-agents.js +1 -2
  224. package/dist/runtime/subagents/preamble.d.ts +3 -2
  225. package/dist/runtime/subagents/preamble.js +3 -2
  226. package/dist/runtime/subagents/render.d.ts +1 -2
  227. package/dist/runtime/subagents/render.js +1 -2
  228. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  229. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  230. package/dist/runtime/subagents/template-skills.js +76 -0
  231. package/dist/schedules/effective-settings.d.ts +9 -3
  232. package/dist/schedules/effective-settings.js +5 -4
  233. package/dist/schedules/fire.js +11 -0
  234. package/dist/schedules/scheduled-tasks.service.js +5 -0
  235. package/dist/schedules/unattended.d.ts +2 -0
  236. package/dist/schedules/unattended.js +6 -1
  237. package/dist/skills/agent-skills.service.js +1 -2
  238. package/dist/skills/catalog.d.ts +1 -3
  239. package/dist/skills/catalog.js +1 -3
  240. package/dist/skills/conversation-catalog.d.ts +1 -2
  241. package/dist/skills/conversation-catalog.js +1 -2
  242. package/dist/skills/usable.js +2 -3
  243. package/dist/storage/storage.service.js +9 -1
  244. package/dist/tools/approvals.service.js +2 -4
  245. package/dist/tools/builtin-names.d.ts +2 -9
  246. package/dist/tools/builtin-names.js +4 -13
  247. package/dist/tools/builtins/sandbox/bash.js +3 -3
  248. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  249. package/dist/tools/builtins/sandbox/common.js +8 -115
  250. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  251. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  252. package/dist/tools/builtins/sandbox/glob.js +1 -3
  253. package/dist/tools/builtins/sandbox/grep.js +3 -5
  254. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  255. package/dist/tools/builtins/sandbox/index.js +10 -5
  256. package/dist/tools/builtins/sandbox/read.js +3 -2
  257. package/dist/tools/builtins/tool-search.d.ts +4 -7
  258. package/dist/tools/builtins/tool-search.js +6 -10
  259. package/dist/tools/connector-account-policies.d.ts +30 -3
  260. package/dist/tools/connector-account-policies.js +54 -7
  261. package/dist/tools/connectors.controller.d.ts +24 -11
  262. package/dist/tools/connectors.controller.js +35 -6
  263. package/dist/tools/connectors.schemas.d.ts +14 -1
  264. package/dist/tools/connectors.schemas.js +14 -2
  265. package/dist/tools/connectors.service.d.ts +22 -0
  266. package/dist/tools/connectors.service.js +56 -0
  267. package/dist/tools/drift.d.ts +1 -1
  268. package/dist/tools/drift.js +1 -1
  269. package/dist/tools/git-push-policy.d.ts +4 -1
  270. package/dist/tools/git-push-policy.js +3 -1
  271. package/dist/tools/info.d.ts +1 -7
  272. package/dist/tools/info.js +5 -18
  273. package/dist/tools/job-ids.d.ts +0 -4
  274. package/dist/tools/job-ids.js +1 -6
  275. package/dist/tools/pipeline.d.ts +4 -10
  276. package/dist/tools/pipeline.js +16 -62
  277. package/dist/tools/policy.d.ts +6 -2
  278. package/dist/tools/policy.js +14 -12
  279. package/dist/tools/registry.js +1 -5
  280. package/dist/ui/views.d.ts +5 -5
  281. package/dist/ui/views.js +10 -16
  282. package/package.json +3 -3
  283. package/src/migrations/0137_audit_org_idx.sql +5 -0
  284. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  285. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  286. package/src/migrations/0140_retire_history_forms.sql +148 -0
  287. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  288. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  289. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  290. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  291. package/dist/admin/platform-audit.service.d.ts +0 -41
  292. package/dist/conversations/job-ids.d.ts +0 -6
  293. package/dist/conversations/job-ids.js +0 -6
  294. package/dist/extensions/job-ids.d.ts +0 -6
  295. package/dist/extensions/job-ids.js +0 -6
  296. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  297. package/dist/infra/queue/retired-schedulers.js +0 -9
  298. package/dist/orgs/job-ids.d.ts +0 -8
  299. package/dist/orgs/job-ids.js +0 -8
  300. package/dist/runtime/context/legacy-text.d.ts +0 -22
  301. package/dist/runtime/context/legacy-text.js +0 -37
  302. package/dist/runtime/job-ids.d.ts +0 -10
  303. package/dist/runtime/job-ids.js +0 -10
  304. package/dist/runtime/retired-schedulers.d.ts +0 -7
  305. package/dist/runtime/retired-schedulers.js +0 -31
  306. package/dist/storage/job-ids.d.ts +0 -6
  307. package/dist/storage/job-ids.js +0 -6
  308. package/dist/tools/legacy-data.d.ts +0 -34
  309. package/dist/tools/legacy-data.js +0 -76
  310. package/dist/tools/legacy-keys.d.ts +0 -51
  311. package/dist/tools/legacy-keys.js +0 -114
@@ -0,0 +1,78 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { MODEL_PROVIDER_EXTENSION_POINT_V2, parseExtensionPoint } from "@capybara-hq/plugin-sdk";
11
+ import { Inject, Injectable } from "@nestjs/common";
12
+ import { OrgExtensionConfigs, providesOf, } from "../extensions/org-config.js";
13
+ import { ProviderRegistry } from "../runtime/providers.js";
14
+ import { AgentsService } from "./agents.service.js";
15
+ const MODEL_PROVIDER = parseExtensionPoint(MODEL_PROVIDER_EXTENSION_POINT_V2).name;
16
+ const isModelProvider = (v) => providesOf(v).some((ref) => parseExtensionPoint(ref).name === MODEL_PROVIDER);
17
+ /** The org can fill the config the extension waits for: an org-level or an overridable field. */
18
+ const orgCanConfigure = (v) => v.configurable || v.overrideState !== "none";
19
+ /**
20
+ * What the org admin must do to make `v` usable here, or null when they cannot (or need not). The
21
+ * view comes from the org's extension list, which shows an extension only when it is offered to
22
+ * the org (`offeredToOrg`): not named to other orgs only, not disabled while off.
23
+ */
24
+ function fixOf(v) {
25
+ if (!v.available)
26
+ return null;
27
+ if (!v.enabled)
28
+ return v.switchable && (!v.needsConfig || orgCanConfigure(v)) ? "not_enabled" : null;
29
+ return v.needsConfig && orgCanConfigure(v) ? "needs_config" : null;
30
+ }
31
+ /**
32
+ * Whether the org can run (web-order spec §3.8), the one place it is computed (the readiness
33
+ * route and the `agents.readiness` operation): the web app decides between the shell and the setup
34
+ * layout with it, and the setup checklist sends the org's admins to `/settings/models` while the
35
+ * model step is `org_fixable`. `ready` reads this replica's provider registry (a replica that has
36
+ * not reconciled a just-enabled provider answers otherwise for a moment); the fixable providers
37
+ * come from the org's extension list.
38
+ */
39
+ let ReadinessService = class ReadinessService {
40
+ registry;
41
+ configs;
42
+ agents;
43
+ constructor(registry, configs, agents) {
44
+ this.registry = registry;
45
+ this.configs = configs;
46
+ this.agents = agents;
47
+ }
48
+ async get(orgId, viewer) {
49
+ const [ready, visible] = await Promise.all([
50
+ this.registry.hasProvider(orgId),
51
+ this.agents.listVisible(orgId, viewer),
52
+ ]);
53
+ const fixable = ready ? [] : await this.orgFixable(orgId);
54
+ return {
55
+ modelProvider: ready ? "ready" : fixable.length > 0 ? "org_fixable" : "none",
56
+ orgFixableProviders: fixable,
57
+ agents: visible.length,
58
+ };
59
+ }
60
+ async orgFixable(orgId) {
61
+ const out = [];
62
+ for (const v of await this.configs.list(orgId)) {
63
+ if (!isModelProvider(v))
64
+ continue;
65
+ const reason = fixOf(v);
66
+ if (reason !== null)
67
+ out.push({ provider: v.plugin, reason });
68
+ }
69
+ return out;
70
+ }
71
+ };
72
+ ReadinessService = __decorate([
73
+ Injectable(),
74
+ __param(0, Inject(ProviderRegistry)),
75
+ __param(1, Inject(OrgExtensionConfigs)),
76
+ __param(2, Inject(AgentsService))
77
+ ], ReadinessService);
78
+ export { ReadinessService };
@@ -61,12 +61,6 @@ export interface TemplateRow {
61
61
  }
62
62
  /** The roster type of a template: `<plugin>:<name>`, the bare `<name>` without a plugin. */
63
63
  export declare const templateTypeOf: (plugin: string | null, name: string) => string;
64
- /**
65
- * A stored template definition as the current format reads it: `selectedSkills` (removed with
66
- * skills on by default, spec §6.2) is dropped. Migration 0116 removed it from org-made versions;
67
- * versions written from a plugin package keep it as the package wrote it, so every read drops it.
68
- */
69
- export declare function storedTemplate(definition: unknown): AgentTemplate;
70
64
  /**
71
65
  * The ids among `ids` of the platform templates on in the org (see {@link platformOn}), whatever
72
66
  * the org's own templates are.
@@ -11,15 +11,12 @@ import { randomUUID } from "node:crypto";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
13
  import { componentOn } from "../catalog/component-state.js";
14
+ import { LIVE_INSTALL_STATUSES } from "../catalog/install-status.js";
14
15
  import { ownerOf, ownersOf } from "../catalog/ownership.js";
15
16
  import { KernelDb } from "../infra/database/kernel-db.js";
16
17
  import { canonicalJson } from "../tools/canonical-json.js";
17
- import { loadLegacyScope } from "../tools/legacy-data.js";
18
- import { needsLegacyScope, normalizeToolKeys } from "./definition.js";
19
18
  /** The roster type of a template: `<plugin>:<name>`, the bare `<name>` without a plugin. */
20
19
  export const templateTypeOf = (plugin, name) => plugin ? `${plugin}:${name}` : name;
21
- /** Plugin install statuses that make a plugin on in the org (phase 1, org catalog state). */
22
- const LIVE_INSTALL = ["installing", "installed", "upgrading"];
23
20
  const baseQuery = (db, orgId) => db
24
21
  .selectFrom("agent_templates as t")
25
22
  .innerJoin("agent_template_versions as v", (j) => j.onRef("v.template_id", "=", "t.id").onRef("v.version", "=", "t.current_version"))
@@ -53,32 +50,9 @@ async function ownedPlatformIds(db, orgId, platformIds) {
53
50
  .execute();
54
51
  return new Set(rows.map((r) => r.id));
55
52
  }
56
- /**
57
- * A stored template definition as the current format reads it: `selectedSkills` (removed with
58
- * skills on by default, spec §6.2) is dropped. Migration 0116 removed it from org-made versions;
59
- * versions written from a plugin package keep it as the package wrote it, so every read drops it.
60
- */
61
- export function storedTemplate(definition) {
62
- if (definition === null || typeof definition !== "object" || Array.isArray(definition)) {
63
- return definition;
64
- }
65
- if (!("selectedSkills" in definition))
66
- return definition;
67
- const { selectedSkills: _s, ...rest } = definition;
68
- return rest;
69
- }
70
- /**
71
- * Stored rows as {@link TemplateRow}s; tool keys read as current keys (tool naming spec §8.3): old
72
- * builtin names always, rc `<x>__<tool>` keys with the org's legacy scope, read once when needed.
73
- */
74
- async function normalized(db, orgId, rows) {
75
- const scope = rows.some((r) => needsLegacyScope(r.definition))
76
- ? await loadLegacyScope(db, orgId)
77
- : undefined;
78
- return rows.map(({ definition, ...r }) => ({
79
- ...r,
80
- template: storedTemplate(normalizeToolKeys(definition, scope)),
81
- }));
53
+ /** Stored rows as {@link TemplateRow}s. */
54
+ function normalized(rows) {
55
+ return rows.map(({ definition, ...r }) => ({ ...r, template: definition }));
82
56
  }
83
57
  const orgRaw = (r) => ({
84
58
  id: r.id,
@@ -120,7 +94,7 @@ async function platformRowsOn(db, orgId, ids) {
120
94
  .select("a.id")
121
95
  .whereRef("a.item_id", "=", "p.catalog_item_id")
122
96
  .where("a.org_id", "=", orgId)
123
- .where("a.status", "in", [...LIVE_INSTALL]))
97
+ .where("a.status", "in", [...LIVE_INSTALL_STATUSES]))
124
98
  .as("installed"),
125
99
  eb
126
100
  .exists(eb
@@ -373,7 +347,7 @@ export async function loadTemplates(db, orgId, ids, log) {
373
347
  if (o)
374
348
  raw.push({ key: id, row: o });
375
349
  }
376
- const done = await normalized(db, orgId, raw.map((x) => x.row));
350
+ const done = normalized(raw.map((x) => x.row));
377
351
  return new Map(raw.map((x, i) => [x.key, done[i]]));
378
352
  }
379
353
  /**
@@ -410,12 +384,12 @@ export async function usableTemplates(db, orgId, log) {
410
384
  ...(await loadTemplates(db, orgId, promoted.map((r) => r.id), log)).values(),
411
385
  ];
412
386
  const rows = [
413
- ...(await normalized(db, orgId, [
387
+ ...normalized([
414
388
  ...own
415
389
  .filter((r) => r.platform_template_id === null || pinnedOn.has(r.platform_template_id))
416
390
  .map(orgRaw),
417
391
  ...(await platformOn(db, orgId, undefined, log)).rows.filter((p) => !promotedTo.has(p.id)),
418
- ])),
392
+ ]),
419
393
  ...served,
420
394
  ];
421
395
  const key = (t) => [t.plugin ?? "", t.name, t.id];
@@ -2,6 +2,8 @@ import { KernelDb } from "../infra/database/kernel-db.js";
2
2
  import { TransactionHost } from "../infra/database/transaction-host.js";
3
3
  import { BackgroundLaunchLock } from "./launch-lock.js";
4
4
  export type BackgroundTaskStatus = "running" | "completed" | "failed" | "stopped" | "timed_out" | "lost";
5
+ /** The status of a task that is still live; the one filter every "running tasks" read shares. */
6
+ export declare const RUNNING_TASK_STATUS = "running";
5
7
  /** A task as the kernel reads it: the columns of `capybara.background_tasks`, camel-cased. */
6
8
  export interface BackgroundTaskRow {
7
9
  id: string;
@@ -13,6 +13,8 @@ import { KernelDb } from "../infra/database/kernel-db.js";
13
13
  import { TransactionHost } from "../infra/database/transaction-host.js";
14
14
  import { Transactional } from "../infra/database/transactional.decorator.js";
15
15
  import { BackgroundLaunchLock } from "./launch-lock.js";
16
+ /** The status of a task that is still live; the one filter every "running tasks" read shares. */
17
+ export const RUNNING_TASK_STATUS = "running";
16
18
  const toRow = (r) => ({
17
19
  id: r.id,
18
20
  orgId: r.org_id,
@@ -223,7 +225,7 @@ let BackgroundTaskStore = class BackgroundTaskStore {
223
225
  .selectFrom("background_tasks")
224
226
  .selectAll()
225
227
  .where("sandbox_conversation_id", "=", sandboxConversationId)
226
- .where("status", "=", "running")
228
+ .where("status", "=", RUNNING_TASK_STATUS)
227
229
  .orderBy("started_at", "asc")
228
230
  .orderBy("id", "asc")
229
231
  .execute();
@@ -1,5 +1,6 @@
1
1
  import { sql } from "kysely";
2
2
  import { effectiveWakeOnBackgroundTask, readOrgSettings } from "../orgs/settings.service.js";
3
+ import { isLive } from "../runtime/run-liveness.js";
3
4
  /**
4
5
  * The wake rules of an idle conversation (spec 2026-11-05-background-bash-design §3, generalized
5
6
  * by agent map spec §5.3 to a second event kind): a finished background task or a sub-agent's
@@ -86,7 +87,7 @@ export async function wakeDecisionIn(t, conv, consumed, deploymentOn, canSend) {
86
87
  .select(["queue_paused", "deleted_at", "tree_stopped_at"])
87
88
  .where("id", "=", conv.rootId)
88
89
  .executeTakeFirst();
89
- if (!root || root.queue_paused || root.deleted_at !== null)
90
+ if (!root || root.queue_paused || !isLive(root.deleted_at))
90
91
  return null;
91
92
  const treeStopped = root.tree_stopped_at !== null;
92
93
  const candidates = [...finishes, ...(treeStopped ? [] : deliveries)]
@@ -53,8 +53,7 @@ export declare class AdminCatalogController {
53
53
  * `application/octet-stream`, at most `packages.maxBytes`): reads and checks the whole plugin
54
54
  * (extension, skills, connector templates; dependencies resolved for the review), stages it for 24
55
55
  * hours and returns one review `{ stagingId, review }`, confirmed with `imports/:stagingId/confirm`.
56
- * A pre-0.1.0 package -> 422 `catalog.legacy_format`; an invalid plugin -> 422
57
- * `catalog.invalid_manifest` (details list each problem); version already imported -> 409
56
+ * An invalid plugin -> 422 `catalog.invalid_manifest` (details list each problem); version already imported -> 409
58
57
  * `catalog.version_exists`; an item with the same name from another npm package -> 409
59
58
  * `catalog.name_conflict`; an extension named like a config-declared one -> 409.
60
59
  */
@@ -105,8 +105,7 @@ let AdminCatalogController = class AdminCatalogController {
105
105
  * `application/octet-stream`, at most `packages.maxBytes`): reads and checks the whole plugin
106
106
  * (extension, skills, connector templates; dependencies resolved for the review), stages it for 24
107
107
  * hours and returns one review `{ stagingId, review }`, confirmed with `imports/:stagingId/confirm`.
108
- * A pre-0.1.0 package -> 422 `catalog.legacy_format`; an invalid plugin -> 422
109
- * `catalog.invalid_manifest` (details list each problem); version already imported -> 409
108
+ * An invalid plugin -> 422 `catalog.invalid_manifest` (details list each problem); version already imported -> 409
110
109
  * `catalog.version_exists`; an item with the same name from another npm package -> 409
111
110
  * `catalog.name_conflict`; an extension named like a config-declared one -> 409.
112
111
  */
@@ -235,9 +235,7 @@ let AppearanceService = class AppearanceService {
235
235
  const enabled = "orgId" in level ? await this.host.enabledPlugins(level.orgId) : null;
236
236
  const loaded = this.host
237
237
  .uiContributions()
238
- .filter((c) => c.plugin === found.name &&
239
- c.contribution.aliasOf === undefined &&
240
- (enabled === null || enabled.has(c.plugin)));
238
+ .filter((c) => c.plugin === found.name && (enabled === null || enabled.has(c.plugin)));
241
239
  const arrangeable = "orgId" in level ? ORG_ARRANGEABLE : UI_ARRANGEABLE_SLOTS;
242
240
  const planned = new Set();
243
241
  for (const [ref, id] of entries) {
@@ -41,7 +41,7 @@ export interface OrgCatalogItem extends Omit<CatalogItemView, "installs" | "mark
41
41
  /** The plugin's extension (or a template's connector extension) is not on the deployment. */
42
42
  notDeployed: boolean;
43
43
  /**
44
- * This org's live plugin install of the item (installing, installed or upgrading);
44
+ * This org's live plugin install of the item (installing or installed);
45
45
  * `upgradeAvailable` is always null since plugin scope phase 2 (no per-org upgrade, ruling F2;
46
46
  * kept for the web until its upgrade dialog goes).
47
47
  */
@@ -4,7 +4,6 @@
4
4
  // module whose provider injects PluginInstaller (an ESM import cycle would run decorators early).
5
5
  import { createHash } from "node:crypto";
6
6
  import { parseAgentTemplate, parseConnectorTemplateFile, parseThemeFile, themeIdOf, validateThemeAssets, } from "@capybara-hq/plugin-sdk";
7
- import { normalizeToolKeys } from "../agents/definition.js";
8
7
  import { ApiError } from "../errors.js";
9
8
  import { can } from "../orgs/roles.js";
10
9
  import { packagePath } from "../packages/tgz.js";
@@ -365,9 +364,7 @@ export async function readCatalogAgentTemplates(storage, v) {
365
364
  if (!parsed || "errors" in parsed) {
366
365
  throw new ApiError("internal", `Stored agent template ${path} is missing or invalid`);
367
366
  }
368
- // an rc package's template may name old builtins: read as the current names (tool naming
369
- // spec §8.3); rc `<x>__<tool>` keys are read with the org's scope by `loadTemplates`
370
- return { path, template: normalizeToolKeys(parsed.template) };
367
+ return { path, template: parsed.template };
371
368
  });
372
369
  }
373
370
  /** The asset paths a parsed theme references (fonts, logo mark and favicon), without `./`. */
@@ -7,6 +7,7 @@ import { blockingKeys } from "../extensions/permission-set.js";
7
7
  import { audit } from "../identity/audit.js";
8
8
  import { endpointCredentialIssues } from "../tools/endpoint.js";
9
9
  import { gitLocationIdentity } from "./git-source.js";
10
+ import { LIVE_INSTALL_STATUSES } from "./install-status.js";
10
11
  import { entryCompatible, entryContentChanged, entryDeprecated, sourceEffective, unimportable, } from "./marketplaces.service.js";
11
12
  import { ownerOf, ownersOf, PLATFORM_OWNER, packageOwner, pendingDigest, } from "./ownership.js";
12
13
  import { schemaHasPath } from "./schema-path.js";
@@ -453,7 +454,7 @@ export async function countInstalls(db, items, versions) {
453
454
  .selectFrom("plugin_installs")
454
455
  .select(["item_id", "org_id"])
455
456
  .where("item_id", "in", items.map((i) => i.id))
456
- .where("status", "in", ["installed", "upgrading"])
457
+ .where("status", "=", "installed")
457
458
  .execute();
458
459
  for (const r of installed)
459
460
  orgs.get(r.item_id)?.add(r.org_id);
@@ -563,7 +564,6 @@ export async function itemConfirmations(admin, items, versions) {
563
564
  }
564
565
  return out;
565
566
  }
566
- const LIVE_INSTALL = ["installing", "installed", "upgrading"];
567
567
  /**
568
568
  * Per item: the orgs of its `named` list, the orgs it is on in (a live plugin install; every org for
569
569
  * a builtin item) and whether it is pending (`confirmations`, see {@link itemConfirmations}).
@@ -598,7 +598,7 @@ export async function itemScopeFacts(db, items, confirmations) {
598
598
  .innerJoin("orgs as o", "o.id", "a.org_id")
599
599
  .select(["a.item_id", (eb) => eb.fn.count("a.org_id").distinct().as("n")])
600
600
  .where("a.item_id", "in", ids)
601
- .where("a.status", "in", [...LIVE_INSTALL])
601
+ .where("a.status", "in", [...LIVE_INSTALL_STATUSES])
602
602
  .where("o.deleted_at", "is", null)
603
603
  .groupBy("a.item_id")
604
604
  .execute();
@@ -1,7 +1,6 @@
1
1
  import { ApiError } from "../errors.js";
2
2
  import { ExtensionAdminOps } from "../extensions/admin-ops.js";
3
3
  import { ExtensionAdmin } from "../extensions/admin-view.js";
4
- import { ExtensionLifecycle } from "../extensions/lifecycle.js";
5
4
  import { PluginInstallLock } from "../extensions/locks.js";
6
5
  import { SuperAdminLock } from "../identity/super-admin.js";
7
6
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -89,8 +88,7 @@ export declare function conflictsError(conflicts: ScopePreview["conflicts"]): Ap
89
88
  * The super admin's plugin scope and deployment-level disable (plugin and component management
90
89
  * spec §4.1, §5 rules 2-4 and 8), and the import confirm that owes the scope sync of the item it
91
90
  * wrote. A change is previewed, then confirmed with the preview's `scopeHash`, recomputed under the
92
- * item row lock (a difference -> 409 `plugin.scope_stale`); it bumps `scope_version`, audits
93
- * `catalog.scope_changed` and owes the item's scope sync in the same transaction, which installs or
91
+ * item row lock (a difference -> 409 `plugin.scope_stale`); it audits `catalog.scope_changed` and owes the item's scope sync in the same transaction, which installs or
94
92
  * uninstalls in every org. Disabling keeps the scope, its org list and the org switches, so
95
93
  * re-enabling (no hash needed) reinstalls where it was on. Builtin items -> 409 `plugin.builtin`.
96
94
  * Stateless, shared by every replica.
@@ -113,8 +111,6 @@ export declare class CatalogScopeService {
113
111
  private readonly orgLock;
114
112
  /** The per-name install lock a reject / withdraw releases the name claim under (M1). */
115
113
  private readonly installLock;
116
- /** This replica's reconcile once a confirmed extension is enabled (before the scope sync). */
117
- private readonly lifecycle;
118
114
  /** Owes the scope syncs and the removed org plugin's cleanup (P3-21, pre-flight F9). */
119
115
  private readonly outbox;
120
116
  private readonly log;
@@ -128,15 +124,13 @@ export declare class CatalogScopeService {
128
124
  orgLock: OrgLock,
129
125
  /** The per-name install lock a reject / withdraw releases the name claim under (M1). */
130
126
  installLock: PluginInstallLock,
131
- /** This replica's reconcile once a confirmed extension is enabled (before the scope sync). */
132
- lifecycle: ExtensionLifecycle,
133
127
  /** Owes the scope syncs and the removed org plugin's cleanup (P3-21, pre-flight F9). */
134
128
  outbox: Pick<OutboxService, "add">, log: KernelLogger, txHost: TransactionHost);
135
129
  private get db();
136
130
  /**
137
131
  * Confirms a staged import ({@link PluginImport.confirm}: installs and enables the extension,
138
- * writes the new item's scope), then owes the item's scope sync when its scope turns it on
139
- * by itself (`all` or `named`; an `optional` item is on only where an org admin switches it on).
132
+ * writes the new item's scope). The item's scope sync is owed by the import's commit, or by its
133
+ * extension's deploy when it has one to deploy.
140
134
  */
141
135
  confirmImport(actor: string, stagingId: string, input: Parameters<PluginImport["confirm"]>[2], opts?: ActorOpts): Promise<PluginConfirmResult>;
142
136
  /**
@@ -145,7 +139,8 @@ export declare class CatalogScopeService {
145
139
  * review digest; a changed set -> 409 `extension.approval_stale`); an extension that was never
146
140
  * deployed (no install record) is installed and enabled first (the package is in the package
147
141
  * store from the import). Nothing waiting (a covered snapshot a person approved already, an item
148
- * without an extension) -> 409 `extension.not_pending`. Enqueues the item's scope sync after.
142
+ * without an extension) -> 409 `extension.not_pending`. The item's scope sync is owed by the
143
+ * approval of an enabled extension, or by the enable.
149
144
  *
150
145
  * An org-owned item is confirmed only while an upload of it waits (ruling P3-10, see
151
146
  * {@link confirmOrgUpload}); otherwise -> 409 `extension.not_pending`.
@@ -161,7 +156,7 @@ export declare class CatalogScopeService {
161
156
  * A first version: its platform components planned and their files copied (keyed by content),
162
157
  * its extension installed, its permissions approved, enabled, then (one transaction) the item
163
158
  * stops waiting, its platform component rows are written and the owner is told
164
- * (`upload_confirmed`); after the commit the scope sync is owed. Each step re-reads
159
+ * (`upload_confirmed`) and the scope sync is owed in that commit. Each step re-reads
165
160
  * the item under its row lock: removed meanwhile -> 409 `catalog.item_removed`, the pending
166
161
  * version replaced -> `extension.approval_stale`; the extension this confirmation installed is
167
162
  * then taken out again. A new version: the platform update to it
@@ -171,8 +166,7 @@ export declare class CatalogScopeService {
171
166
  */
172
167
  private confirmOrgUpload;
173
168
  /**
174
- * {@link confirmOrgUpload} under the item lock; returns the confirmed first version (its scope
175
- * sync follows after), null for a new version.
169
+ * {@link confirmOrgUpload} under the item lock.
176
170
  */
177
171
  private confirmLocked;
178
172
  /** The item is live and its first version confirmed (no longer awaiting). */
@@ -272,8 +266,7 @@ export declare class CatalogScopeService {
272
266
  /**
273
267
  * Adds one org to a `named` item's list in the caller's transaction (an approved `access`
274
268
  * request, spec §5.1 rule 2): nobody loses access, so no preview. The item row is locked; it
275
- * must be live and not builtin (404 / `plugin.builtin`). Bumps `scope_version`, audits
276
- * `catalog.scope_changed` and owes the item's scope sync in that transaction. Returns whether
269
+ * must be live and not builtin (404 / `plugin.builtin`). Audits `catalog.scope_changed` and owes the item's scope sync in that transaction. Returns whether
277
270
  * the list changed (false: not `named`, or listed already).
278
271
  */
279
272
  addOrg(actor: string, itemId: string, orgId: string, opts?: ActorOpts & {
@@ -286,17 +279,6 @@ export declare class CatalogScopeService {
286
279
  enqueueSync(itemId: string): Promise<void>;
287
280
  /** Owes the item's scope sync in the transaction that changes its scope (outbox spec §8.1). */
288
281
  private enqueue;
289
- /**
290
- * Owes the item's scope sync in a transaction of its own, after a confirmation whose last write
291
- * (the extension's deploy, or the platform components) committed outside the scope service: the
292
- * sync must not run before the extension it installs is enabled.
293
- */
294
- private oweSync;
295
- /**
296
- * Owes the delayed backstop of the item's sync in a transaction of its own (ruling R24): a
297
- * permissions confirm writes nothing of the scope service's before its enable.
298
- */
299
- private oweBackstop;
300
282
  /**
301
283
  * 409 `theme.platform_default` when a live theme of the item is the platform default and `after`
302
284
  * says the change leaves it narrower than `all` or gone (themes spec §7). In the caller's
@@ -323,8 +305,8 @@ export declare class CatalogScopeService {
323
305
  private componentChanges;
324
306
  /**
325
307
  * Sends the components of the item with their own scope back to following it (a plugin scope
326
- * change, spec §5 rule 2): `scope_mode = follow`, their own lists dropped, `scope_version`
327
- * bumped, one `component.scope_changed` audit each. In the caller's transaction.
308
+ * change, spec §5 rule 2): `scope_mode = follow`, their own lists dropped, one
309
+ * `component.scope_changed` audit each. In the caller's transaction.
328
310
  */
329
311
  private followAgain;
330
312
  }