@vellumai/assistant 0.8.7-dev.202606052232.2ddc989 → 0.8.8

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 (262) hide show
  1. package/bun.lock +2 -2
  2. package/docs/plugins.md +832 -0
  3. package/examples/plugins/echo/README.md +60 -61
  4. package/examples/plugins/echo/package.json +2 -1
  5. package/examples/plugins/echo/register.ts +143 -0
  6. package/node_modules/@vellumai/skill-host-contracts/src/skill-host.ts +6 -7
  7. package/openapi.yaml +5 -15
  8. package/package.json +2 -2
  9. package/src/__tests__/agent-loop-exit-reason.test.ts +56 -3
  10. package/src/__tests__/anthropic-provider.test.ts +1 -1
  11. package/src/__tests__/app-control-flow.test.ts +1 -1
  12. package/src/__tests__/app-dir-path-guard.test.ts +0 -1
  13. package/src/__tests__/approval-routes-http.test.ts +1 -4
  14. package/src/__tests__/channel-approval-routes.test.ts +1 -1
  15. package/src/__tests__/channel-approvals.test.ts +1 -1
  16. package/src/__tests__/circuit-breaker-pipeline.test.ts +405 -0
  17. package/src/__tests__/compaction-pipeline.test.ts +210 -0
  18. package/src/__tests__/compaction-timeout-recovery.test.ts +251 -0
  19. package/src/__tests__/conversation-agent-loop-disk-pressure.test.ts +3 -0
  20. package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +3 -0
  21. package/src/__tests__/conversation-agent-loop-overflow.test.ts +7 -3
  22. package/src/__tests__/conversation-agent-loop.test.ts +39 -42
  23. package/src/__tests__/conversation-clean-command.test.ts +2 -5
  24. package/src/__tests__/conversation-provider-retry-repair.test.ts +5 -4
  25. package/src/__tests__/conversation-runtime-assembly.test.ts +71 -140
  26. package/src/__tests__/conversation-runtime-workspace.test.ts +27 -108
  27. package/src/__tests__/conversation-starter-routes.test.ts +6 -14
  28. package/src/__tests__/conversation-workspace-cache-state.test.ts +16 -17
  29. package/src/__tests__/conversation-workspace-injection.test.ts +1 -61
  30. package/src/__tests__/conversation-workspace-tool-tracking.test.ts +6 -7
  31. package/src/__tests__/db-acp-history.test.ts +0 -101
  32. package/src/__tests__/dynamic-page-surface.test.ts +0 -31
  33. package/src/__tests__/file-write-tool.test.ts +0 -63
  34. package/src/__tests__/gateway-only-guard.test.ts +2 -12
  35. package/src/__tests__/guardian-grant-minting.test.ts +1 -1
  36. package/src/__tests__/guardian-routing-invariants.test.ts +4 -2
  37. package/src/__tests__/handlers-user-message-approval-consumption.test.ts +1 -1
  38. package/src/__tests__/heartbeat-disk-pressure.test.ts +0 -1
  39. package/src/__tests__/heartbeat-service.test.ts +0 -1
  40. package/src/__tests__/host-app-control-routes.test.ts +1 -1
  41. package/src/__tests__/host-cu-routes-targeted.test.ts +3 -3
  42. package/src/__tests__/injector-background-turn.test.ts +1 -1
  43. package/src/__tests__/injector-chain.test.ts +6 -34
  44. package/src/__tests__/injector-disk-pressure.test.ts +34 -77
  45. package/src/__tests__/injector-document-comments.test.ts +1 -1
  46. package/src/__tests__/list-messages-hidden-metadata.test.ts +0 -38
  47. package/src/__tests__/memory-v2-static-injector.test.ts +1 -1
  48. package/src/__tests__/{overflow-reduction-loop.test.ts → overflow-reduce-pipeline.test.ts} +284 -64
  49. package/src/__tests__/pipeline-runner.test.ts +554 -0
  50. package/src/__tests__/plugin-api-shim.test.ts +6 -3
  51. package/src/__tests__/plugin-bootstrap.test.ts +23 -12
  52. package/src/__tests__/plugin-registry.test.ts +49 -3
  53. package/src/__tests__/plugin-types.test.ts +70 -0
  54. package/src/__tests__/reaction-persistence.test.ts +1 -1
  55. package/src/__tests__/send-endpoint-busy.test.ts +1 -4
  56. package/src/__tests__/skill-feature-flags-integration.test.ts +0 -33
  57. package/src/__tests__/subagent-call-site-routing.test.ts +1 -1
  58. package/src/__tests__/subagent-fork-notifications.test.ts +3 -1
  59. package/src/__tests__/subagent-fork-spawn.test.ts +1 -1
  60. package/src/__tests__/subagent-manager-notify.test.ts +3 -1
  61. package/src/__tests__/subagent-notify-parent.test.ts +3 -1
  62. package/src/__tests__/subagent-spawn-tool-fork.test.ts +1 -1
  63. package/src/__tests__/user-plugin-loader.test.ts +286 -54
  64. package/src/acp/__tests__/client-handler.test.ts +0 -40
  65. package/src/acp/__tests__/prepare-agent-env.test.ts +0 -137
  66. package/src/acp/__tests__/session-manager-persistence.test.ts +28 -95
  67. package/src/acp/agent-process.ts +1 -61
  68. package/src/acp/client-handler.ts +0 -31
  69. package/src/acp/prepare-agent-env.ts +29 -83
  70. package/src/acp/resolve-agent.test.ts +7 -320
  71. package/src/acp/resolve-agent.ts +18 -182
  72. package/src/acp/session-manager.ts +73 -495
  73. package/src/acp/types.ts +0 -8
  74. package/src/agent/compaction-circuit.ts +102 -60
  75. package/src/agent/loop.ts +59 -32
  76. package/src/api/responses/conversation-message.ts +1 -7
  77. package/src/approvals/guardian-request-resolvers.ts +1 -1
  78. package/src/background-wake/next-wake.ts +0 -1
  79. package/src/config/__tests__/feature-flag-registry-guard.test.ts +2 -2
  80. package/src/config/acp-defaults.test.ts +0 -10
  81. package/src/config/acp-defaults.ts +0 -6
  82. package/src/config/bundled-skills/acp/SKILL.md +31 -83
  83. package/src/config/bundled-skills/acp/TOOLS.json +4 -4
  84. package/src/config/bundled-skills/app-builder/SKILL.md +381 -224
  85. package/src/config/bundled-skills/app-builder/TOOLS.json +0 -29
  86. package/src/config/bundled-skills/document-editor/SKILL.md +23 -28
  87. package/src/config/bundled-skills/document-editor/TOOLS.json +1 -1
  88. package/src/config/bundled-tool-registry.ts +0 -2
  89. package/src/config/feature-flag-registry.json +5 -14
  90. package/src/config/schemas/heartbeat.ts +0 -9
  91. package/src/context/strip-injections.ts +2 -8
  92. package/src/context/window-manager.ts +1 -2
  93. package/src/daemon/conversation-agent-loop-handlers.ts +11 -0
  94. package/src/daemon/conversation-agent-loop.ts +279 -62
  95. package/src/daemon/conversation-runtime-assembly.ts +69 -106
  96. package/src/daemon/conversation-store.ts +90 -9
  97. package/src/daemon/conversation-workspace.ts +0 -17
  98. package/src/daemon/conversation.ts +6 -0
  99. package/src/daemon/external-plugins-bootstrap.ts +11 -11
  100. package/src/daemon/handlers/conversations.ts +1 -3
  101. package/src/daemon/handlers/skills.ts +1 -4
  102. package/src/daemon/lifecycle.ts +0 -21
  103. package/src/daemon/server.ts +0 -2
  104. package/src/heartbeat/__tests__/heartbeat-service.test.ts +0 -3
  105. package/src/heartbeat/heartbeat-run-store.ts +1 -23
  106. package/src/heartbeat/heartbeat-service.ts +0 -26
  107. package/src/ipc/__tests__/browser-ipc.test.ts +1 -1
  108. package/src/ipc/__tests__/ui-request-route.test.ts +3 -3
  109. package/src/ipc/skill-routes/__tests__/memory.test.ts +0 -15
  110. package/src/ipc/skill-routes/memory.ts +2 -4
  111. package/src/memory/conversation-starter-checkpoints.ts +0 -1
  112. package/src/memory/db-init.ts +0 -2
  113. package/src/memory/job-handlers/conversation-starters.ts +2 -13
  114. package/src/memory/jobs-worker.ts +1 -1
  115. package/src/memory/migrations/index.ts +0 -1
  116. package/src/memory/schema/acp.ts +0 -4
  117. package/src/memory/v2/__tests__/consolidation-job.test.ts +3 -3
  118. package/src/memory/v2/consolidation-job.ts +4 -13
  119. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/assign.test.ts +4 -4
  120. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/live-integration.test.ts +4 -4
  121. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/maintain-job.test.ts +5 -5
  122. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/orchestrate.test.ts +3 -3
  123. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/reconcile.test.ts +2 -2
  124. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/render-injection.test.ts +1 -1
  125. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/router.test.ts +3 -3
  126. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/selection-log-store.test.ts +8 -8
  127. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/selector.test.ts +3 -3
  128. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/shadow-plugin.test.ts +12 -12
  129. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/assign.ts +5 -5
  130. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/capabilities.ts +2 -2
  131. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/maintain-job.ts +8 -8
  132. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/page-content.ts +2 -2
  133. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/provider-blocks.ts +1 -1
  134. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/reconcile.ts +3 -3
  135. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/render-injection.ts +1 -1
  136. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/router.ts +3 -3
  137. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/selection-log-store.ts +4 -4
  138. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/selector.ts +4 -4
  139. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/shadow-plugin.ts +90 -28
  140. package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/tree.ts +1 -1
  141. package/src/plugin-api/index.ts +5 -0
  142. package/src/plugins/defaults/circuit-breaker/middlewares/circuitBreaker.ts +93 -0
  143. package/src/plugins/defaults/{memory-v3-shadow → circuit-breaker}/package.json +2 -2
  144. package/src/plugins/defaults/circuit-breaker/register.ts +39 -0
  145. package/src/plugins/defaults/compaction/middlewares/compaction.ts +25 -0
  146. package/src/plugins/defaults/compaction/package.json +1 -1
  147. package/src/plugins/defaults/compaction/register.ts +19 -8
  148. package/src/plugins/defaults/compaction/terminal.ts +73 -0
  149. package/src/plugins/defaults/index.ts +5 -3
  150. package/src/plugins/defaults/{memory-retrieval/injectors.ts → injectors/register.ts} +7 -45
  151. package/src/plugins/defaults/memory-retrieval/hooks/post-compact.ts +7 -11
  152. package/src/plugins/defaults/memory-retrieval/injector-chain.ts +2 -2
  153. package/src/plugins/defaults/overflow-reduce/middlewares/overflowReduce.ts +126 -0
  154. package/src/plugins/defaults/overflow-reduce/package.json +15 -0
  155. package/src/plugins/defaults/overflow-reduce/register.ts +42 -0
  156. package/src/plugins/external-api.ts +2 -2
  157. package/src/plugins/pipeline.ts +293 -6
  158. package/src/plugins/registry.ts +37 -9
  159. package/src/plugins/types.ts +336 -32
  160. package/src/plugins/user-loader.ts +127 -30
  161. package/src/proactive-artifact/aux-message-injector.ts +1 -1
  162. package/src/proactive-artifact/job.test.ts +1 -1
  163. package/src/prompts/__tests__/system-prompt.test.ts +0 -6
  164. package/src/prompts/templates/BOOTSTRAP-ACTIVATION-RAIL.md +2 -4
  165. package/src/runtime/__tests__/agent-wake.test.ts +5 -5
  166. package/src/runtime/__tests__/interactive-ui.test.ts +1 -1
  167. package/src/runtime/agent-wake.ts +3 -0
  168. package/src/runtime/assistant-event-hub.ts +1 -1
  169. package/src/runtime/channel-approvals.ts +1 -1
  170. package/src/runtime/interactive-ui.ts +1 -1
  171. package/src/runtime/routes/__tests__/acp-routes.test.ts +55 -283
  172. package/src/runtime/routes/__tests__/conversation-list-routes.test.ts +1 -1
  173. package/src/runtime/routes/__tests__/surface-action-routes.test.ts +4 -5
  174. package/src/runtime/routes/__tests__/surface-content-routes.test.ts +1 -4
  175. package/src/runtime/routes/acp-routes.test.ts +25 -89
  176. package/src/runtime/routes/acp-routes.ts +29 -81
  177. package/src/runtime/routes/approval-routes.ts +1 -1
  178. package/src/runtime/routes/browser-routes.ts +1 -1
  179. package/src/runtime/routes/browser-tabs-routes.ts +10 -6
  180. package/src/runtime/routes/conversation-cli-routes.ts +1 -1
  181. package/src/runtime/routes/conversation-list-routes.ts +1 -1
  182. package/src/runtime/routes/conversation-query-routes.ts +1 -1
  183. package/src/runtime/routes/conversation-routes.ts +2 -15
  184. package/src/runtime/routes/conversation-starter-routes.ts +7 -13
  185. package/src/runtime/routes/conversations-import-routes.ts +7 -24
  186. package/src/runtime/routes/host-app-control-routes.ts +1 -1
  187. package/src/runtime/routes/host-cu-routes.ts +1 -1
  188. package/src/runtime/routes/identity-routes.ts +3 -18
  189. package/src/runtime/routes/inbound-message-handler.ts +1 -1
  190. package/src/runtime/routes/memory-v3-routes.ts +6 -16
  191. package/src/runtime/routes/playground/helpers.ts +1 -1
  192. package/src/runtime/routes/surface-conversation-resolver.ts +3 -4
  193. package/src/runtime/routes/work-items-routes.ts +4 -2
  194. package/src/runtime/services/conversation-serializer.ts +1 -1
  195. package/src/signals/cancel.ts +4 -2
  196. package/src/subagent/manager.ts +5 -17
  197. package/src/tools/acp/list-agents.test.ts +1 -7
  198. package/src/tools/acp/spawn.test.ts +55 -158
  199. package/src/tools/acp/spawn.ts +72 -47
  200. package/src/tools/acp/steer.test.ts +8 -105
  201. package/src/tools/acp/steer.ts +17 -48
  202. package/src/tools/apps/executors.ts +8 -13
  203. package/src/tools/filesystem/write.ts +0 -34
  204. package/src/tools/subagent/spawn.ts +4 -2
  205. package/src/tools/ui-surface/definitions.ts +4 -25
  206. package/src/workspace/migrations/051-seed-conversation-summarization-callsite.ts +5 -4
  207. package/src/workspace/migrations/097-enable-adaptive-thinking-managed-profiles.ts +45 -69
  208. package/examples/plugins/echo/hooks/post-tool-use.ts +0 -18
  209. package/examples/plugins/echo/hooks/stop.ts +0 -16
  210. package/examples/plugins/echo/hooks/user-prompt-submit.ts +0 -18
  211. package/examples/plugins/echo/src/emit.ts +0 -19
  212. package/src/__tests__/compaction-circuit.test.ts +0 -258
  213. package/src/__tests__/compaction-direct.test.ts +0 -132
  214. package/src/__tests__/conversations-import-system-filter.test.ts +0 -101
  215. package/src/acp/__tests__/agent-process.test.ts +0 -161
  216. package/src/acp/__tests__/helpers/acp-history-db.ts +0 -82
  217. package/src/acp/__tests__/helpers/exec-file-stub.ts +0 -101
  218. package/src/acp/__tests__/session-manager-resume.test.ts +0 -736
  219. package/src/acp/auto-install.test.ts +0 -196
  220. package/src/acp/auto-install.ts +0 -177
  221. package/src/acp/feature-gate.test.ts +0 -48
  222. package/src/acp/feature-gate.ts +0 -34
  223. package/src/acp/resume-hint.ts +0 -25
  224. package/src/config/bundled-skills/app-builder/references/DESIGN_SYSTEM.md +0 -48
  225. package/src/config/bundled-skills/app-builder/references/RESPONSIVE.md +0 -57
  226. package/src/config/bundled-skills/app-builder/references/SLIDES.md +0 -38
  227. package/src/config/bundled-skills/app-builder/tools/app-list.ts +0 -62
  228. package/src/daemon/conversation-registry.ts +0 -159
  229. package/src/daemon/overflow-reduction-loop.ts +0 -230
  230. package/src/memory/migrations/272-acp-session-history-cwd.ts +0 -36
  231. package/src/plugins/defaults/compaction/compact.ts +0 -59
  232. package/src/plugins/defaults/memory-v3-shadow/hooks/post-compact.ts +0 -14
  233. package/src/plugins/defaults/memory-v3-shadow/hooks/user-prompt-submit.ts +0 -19
  234. package/src/plugins/defaults/memory-v3-shadow/injector.ts +0 -75
  235. package/src/plugins/defaults/memory-v3-shadow/register.ts +0 -26
  236. package/src/tools/acp/context.ts +0 -20
  237. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/capabilities.test.ts +0 -0
  238. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/core.test.ts +0 -0
  239. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/fixtures/eval-turns.json +0 -0
  240. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/fixtures/live-turns.json +0 -0
  241. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/health.test.ts +0 -0
  242. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/needle.test.ts +0 -0
  243. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/provider-blocks.test.ts +0 -0
  244. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/snapshot.test.ts +0 -0
  245. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/tree.test.ts +0 -0
  246. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/types.test.ts +0 -0
  247. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/working-set-eviction.test.ts +0 -0
  248. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/__tests__/working-set-skeleton.test.ts +0 -0
  249. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/core.ts +0 -0
  250. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/data/README.md +0 -0
  251. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/data/assignments.json +0 -0
  252. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/data/core.json +0 -0
  253. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/data/leaves/domain-a/topic-x.md +0 -0
  254. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/data/leaves/domain-a/topic-y.md +0 -0
  255. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/data/leaves/domain-b/topic-z.md +0 -0
  256. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/health.ts +0 -0
  257. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/llm-retry.ts +0 -0
  258. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/needle.ts +0 -0
  259. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/orchestrate.ts +0 -0
  260. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/snapshot.ts +0 -0
  261. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/types.ts +0 -0
  262. /package/src/{plugins/defaults/memory-v3-shadow → memory/v3}/working-set.ts +0 -0
@@ -1,22 +1,17 @@
1
1
  /**
2
- * Tests for the user plugin loader.
2
+ * Tests for the user plugin loader (PR 29).
3
3
  *
4
4
  * Redirects `getWorkspaceDir()` into a per-test temp directory via
5
5
  * `VELLUM_WORKSPACE_DIR` so `loadUserPlugins()` walks an isolated tree
6
6
  * that we populate on demand.
7
7
  *
8
- * The loader's own responsibility is directory discovery and dispatch: it
9
- * scans `<workspaceDir>/plugins/*` and hands every subdirectory carrying a
10
- * `package.json` to `loadExternalPlugin`. The plugin-build mechanics
11
- * (manifest parsing, hook/tool wiring, the per-plugin timeout, error
12
- * isolation) are covered directly in `external-plugin-loader.test.ts`; here
13
- * we assert the discovery contract:
14
- *
15
- * - A directory with a `package.json` is loaded and registered.
16
- * - A directory without a `package.json` is skipped silently.
17
- * - A missing `getWorkspaceDir()/plugins/` directory is a no-op (zero
18
- * installed user plugins is the default shape of a fresh daemon).
19
- * - One failing plugin does not prevent a sibling from registering.
8
+ * Covers:
9
+ * - A plugin whose `register.ts` calls `registerPlugin()` at import time
10
+ * ends up in the registry after `loadUserPlugins()` resolves.
11
+ * - A plugin whose `register.ts` throws during import is logged + skipped;
12
+ * other plugins in the same directory still load.
13
+ * - A missing `getWorkspaceDir()/plugins/` directory is a no-op (zero installed
14
+ * user plugins is the default shape of a fresh daemon).
20
15
  */
21
16
  import { mkdirSync, rmSync, writeFileSync } from "node:fs";
22
17
  import { tmpdir } from "node:os";
@@ -31,6 +26,7 @@ import { loadUserPlugins } from "../plugins/user-loader.js";
31
26
 
32
27
  // Isolate every run under its own tempdir so parallel test files (and
33
28
  // repeated runs of this file) cannot collide on `<workspaceDir>/plugins/`.
29
+ // Each describe-scope gets a fresh subdirectory.
34
30
  const TEST_WORKSPACE_DIR = join(
35
31
  tmpdir(),
36
32
  `vellum-user-plugin-loader-test-${process.pid}-${Date.now()}`,
@@ -41,26 +37,30 @@ process.env.VELLUM_WORKSPACE_DIR = TEST_WORKSPACE_DIR;
41
37
  const PLUGINS_DIR = join(TEST_WORKSPACE_DIR, "plugins");
42
38
 
43
39
  /**
44
- * Write a directory-convention plugin: a `package.json` manifest plus any
45
- * surface files (`hooks/<name>.ts`, `tools/<name>.ts`) whose default export
46
- * the loader wires up.
40
+ * Write a plugin directory with a `register.ts` (TypeScript source, so bun
41
+ * can import it at test time without a build step) that executes the given
42
+ * body. The body has access to `registerPlugin` via a relative import back
43
+ * into the repo's registry module.
44
+ *
45
+ * `relativeRegistryImport` points from the synthetic plugin file at
46
+ * `<TEST_WORKSPACE_DIR>/plugins/<name>/register.ts` to the real
47
+ * registry source at `<repo>/assistant/src/plugins/registry.ts`. Using a
48
+ * relative path (rather than a project-root alias) keeps the test hermetic
49
+ * and matches how an on-disk user plugin would actually import the
50
+ * registry's public API in a real install.
47
51
  */
48
- function writePlugin(
49
- name: string,
50
- pkg: Record<string, unknown>,
51
- files: Record<string, string> = {},
52
- ): void {
52
+ function writePlugin(name: string, body: string): void {
53
53
  const pluginDir = join(PLUGINS_DIR, name);
54
54
  mkdirSync(pluginDir, { recursive: true });
55
- writeFileSync(join(pluginDir, "package.json"), JSON.stringify(pkg, null, 2));
56
- for (const [rel, body] of Object.entries(files)) {
57
- const parts = rel.split("/");
58
- parts.pop();
59
- if (parts.length > 0) {
60
- mkdirSync(join(pluginDir, ...parts), { recursive: true });
61
- }
62
- writeFileSync(join(pluginDir, rel), body);
63
- }
55
+ // Resolve the absolute path to the registry module so the synthetic
56
+ // register.ts can import it. bun happily resolves `.ts` files at runtime
57
+ // when the test suite itself is running in source mode.
58
+ const registryPath = join(import.meta.dir, "..", "plugins", "registry.ts");
59
+ const registerSource = `
60
+ import { registerPlugin } from ${JSON.stringify(registryPath)};
61
+ ${body}
62
+ `;
63
+ writeFileSync(join(pluginDir, "register.ts"), registerSource);
64
64
  }
65
65
 
66
66
  function clearPluginsDir(): void {
@@ -73,14 +73,17 @@ describe("user plugin loader", () => {
73
73
  clearPluginsDir();
74
74
  });
75
75
 
76
- test("loads a plugin via its package.json manifest and registers it", async () => {
76
+ test("loads a valid plugin whose register.ts calls registerPlugin()", async () => {
77
77
  writePlugin(
78
78
  "my-plugin",
79
- { name: "my-plugin", version: "0.1.0" },
80
- {
81
- "hooks/init.ts":
82
- "export default async function init(_ctx: unknown): Promise<void> {}\n",
83
- },
79
+ `
80
+ registerPlugin({
81
+ manifest: {
82
+ name: "my-plugin",
83
+ version: "0.0.1",
84
+ },
85
+ });
86
+ `,
84
87
  );
85
88
 
86
89
  await loadUserPlugins();
@@ -88,22 +91,34 @@ describe("user plugin loader", () => {
88
91
  const registered = getRegisteredPlugins();
89
92
  expect(registered).toHaveLength(1);
90
93
  expect(registered[0]?.manifest.name).toBe("my-plugin");
91
- expect(typeof registered[0]?.hooks?.init).toBe("function");
92
94
  });
93
95
 
94
96
  test("per-plugin failure is isolated: other plugins still load", async () => {
95
- // Plugin A has a malformed package.json; the loader must isolate the
96
- // failure and still register the healthy sibling — one bad user plugin
97
- // cannot brick the entire user-plugin surface or crash the daemon.
98
- const brokenDir = join(PLUGINS_DIR, "broken-plugin");
99
- mkdirSync(brokenDir, { recursive: true });
100
- writeFileSync(join(brokenDir, "package.json"), "{ not valid json");
101
-
102
- writePlugin("good-plugin", { name: "good-plugin", version: "0.1.0" });
97
+ // Plugin A throws at import time. The loader must log and move on so
98
+ // Plugin B still ends up registered — one bad user plugin cannot brick
99
+ // the entire user-plugin surface or crash the daemon.
100
+ writePlugin(
101
+ "broken-plugin",
102
+ `
103
+ throw new Error("boom at import time");
104
+ `,
105
+ );
106
+ writePlugin(
107
+ "good-plugin",
108
+ `
109
+ registerPlugin({
110
+ manifest: {
111
+ name: "good-plugin",
112
+ version: "0.0.1",
113
+ },
114
+ });
115
+ `,
116
+ );
103
117
 
104
118
  await loadUserPlugins();
105
119
 
106
- const names = getRegisteredPlugins().map((p) => p.manifest.name);
120
+ const registered = getRegisteredPlugins();
121
+ const names = registered.map((p) => p.manifest.name);
107
122
  // Order is not guaranteed (filesystem-dependent) — assert membership.
108
123
  expect(names).toContain("good-plugin");
109
124
  expect(names).not.toContain("broken-plugin");
@@ -117,9 +132,92 @@ describe("user plugin loader", () => {
117
132
  expect(getRegisteredPlugins()).toHaveLength(0);
118
133
  });
119
134
 
120
- test("subdirectory without package.json is silently skipped", async () => {
121
- // Populate a directory that looks like a plugin but lacks a manifest.
122
- // The loader must skip it without throwing.
135
+ test("plugin with hanging top-level await is timed out and skipped", async () => {
136
+ // A plugin whose module evaluation never resolves (hanging top-level
137
+ // await) would otherwise block daemon startup indefinitely. The loader
138
+ // must bound the import with a timeout so the hang is isolated the same
139
+ // way a thrown error would be. A neighboring well-behaved plugin must
140
+ // still load.
141
+ writePlugin(
142
+ "hanging-plugin",
143
+ `
144
+ await new Promise(() => {
145
+ // Intentionally never resolves — simulates a plugin whose top-level
146
+ // await blocks forever.
147
+ });
148
+ registerPlugin({
149
+ manifest: {
150
+ name: "hanging-plugin",
151
+ version: "0.0.1",
152
+ },
153
+ });
154
+ `,
155
+ );
156
+ writePlugin(
157
+ "healthy-plugin",
158
+ `
159
+ registerPlugin({
160
+ manifest: {
161
+ name: "healthy-plugin",
162
+ version: "0.0.1",
163
+ },
164
+ });
165
+ `,
166
+ );
167
+
168
+ // Use a short test-only timeout so the suite does not wait the full
169
+ // production 10s for the hung-plugin path.
170
+ await loadUserPlugins({ importTimeoutMs: 250 });
171
+
172
+ const names = getRegisteredPlugins().map((p) => p.manifest.name);
173
+ expect(names).toContain("healthy-plugin");
174
+ expect(names).not.toContain("hanging-plugin");
175
+ });
176
+
177
+ test("plugin whose top-level await resolves AFTER the timeout cannot register late", async () => {
178
+ // Codex/Devin P1 regression: racing `import(moduleUrl)` against a timeout
179
+ // only stops the loader from awaiting the module — it does NOT cancel
180
+ // module evaluation. A plugin whose top-level await eventually resolves
181
+ // continues running in the background and would otherwise call
182
+ // `registerPlugin()` after `loadUserPlugins()` has returned (and after
183
+ // `bootstrapPlugins()` has potentially already walked the registry),
184
+ // leaving the plugin visible to `getMiddlewaresFor()` with its `init()`
185
+ // hook never invoked.
186
+ //
187
+ // The `closeRegistration()` latch must reject that late arrival so the
188
+ // registry stays consistent with the bootstrap invariant.
189
+ writePlugin(
190
+ "slow-late-plugin",
191
+ `
192
+ await new Promise((resolve) => setTimeout(resolve, 200));
193
+ registerPlugin({
194
+ manifest: {
195
+ name: "slow-late-plugin",
196
+ version: "0.0.1",
197
+ },
198
+ });
199
+ `,
200
+ );
201
+
202
+ // Time out well before the plugin's top-level await resolves. The loader
203
+ // returns immediately; the abandoned import keeps evaluating in the
204
+ // background.
205
+ await loadUserPlugins({ importTimeoutMs: 25 });
206
+
207
+ // Wait long enough for the abandoned import's top-level await to resolve
208
+ // and try to `registerPlugin()`. The closed-registration latch must
209
+ // reject the call; the `.catch(() => {})` on the abandoned import must
210
+ // swallow the resulting rejection so the test does not see an
211
+ // unhandled-rejection crash.
212
+ await new Promise((resolve) => setTimeout(resolve, 400));
213
+
214
+ const names = getRegisteredPlugins().map((p) => p.manifest.name);
215
+ expect(names).not.toContain("slow-late-plugin");
216
+ });
217
+
218
+ test("subdirectory without register.{ts,js} is silently skipped", async () => {
219
+ // Populate a directory that looks like a plugin but lacks a register
220
+ // file. The loader must skip it without throwing.
123
221
  const stubDir = join(PLUGINS_DIR, "not-a-plugin");
124
222
  mkdirSync(stubDir, { recursive: true });
125
223
  writeFileSync(join(stubDir, "README.md"), "# not actually a plugin\n");
@@ -128,12 +226,146 @@ describe("user plugin loader", () => {
128
226
  expect(getRegisteredPlugins()).toHaveLength(0);
129
227
  });
130
228
 
131
- test("strips npm scope from package.json name", async () => {
132
- writePlugin("scoped", { name: "@vellumai/cool-plugin", version: "0.1.0" });
229
+ describe("experimental plugin framework branch", () => {
230
+ /**
231
+ * Write a directory-convention plugin (package.json + optional
232
+ * hooks/tools default exports). Mirrors `writePlugin()` above but
233
+ * targets the new experimental loader path.
234
+ */
235
+ function writeExperimentalPlugin(
236
+ name: string,
237
+ pkg: Record<string, unknown>,
238
+ files: Record<string, string> = {},
239
+ ): void {
240
+ const pluginDir = join(PLUGINS_DIR, name);
241
+ mkdirSync(pluginDir, { recursive: true });
242
+ writeFileSync(
243
+ join(pluginDir, "package.json"),
244
+ JSON.stringify(pkg, null, 2),
245
+ );
246
+ for (const [rel, body] of Object.entries(files)) {
247
+ const parts = rel.split("/");
248
+ parts.pop();
249
+ if (parts.length > 0) {
250
+ mkdirSync(join(pluginDir, ...parts), { recursive: true });
251
+ }
252
+ writeFileSync(join(pluginDir, rel), body);
253
+ }
254
+ }
133
255
 
134
- await loadUserPlugins();
256
+ test("loads a plugin via the package.json branch and registers it", async () => {
257
+ writeExperimentalPlugin(
258
+ "experimental-one",
259
+ { name: "experimental-one", version: "0.1.0" },
260
+ {
261
+ "hooks/init.ts":
262
+ "export default async function init(_ctx: unknown): Promise<void> {}\n",
263
+ },
264
+ );
135
265
 
136
- const names = getRegisteredPlugins().map((p) => p.manifest.name);
137
- expect(names).toContain("cool-plugin");
266
+ await loadUserPlugins();
267
+
268
+ const names = getRegisteredPlugins().map((p) => p.manifest.name);
269
+ expect(names).toContain("experimental-one");
270
+ const registered = getRegisteredPlugins().find(
271
+ (p) => p.manifest.name === "experimental-one",
272
+ );
273
+ expect(typeof registered?.hooks?.init).toBe("function");
274
+ });
275
+
276
+ test("strips npm scope from package.json name", async () => {
277
+ writeExperimentalPlugin("scoped", {
278
+ name: "@vellumai/cool-plugin",
279
+ version: "0.1.0",
280
+ });
281
+
282
+ await loadUserPlugins();
283
+
284
+ const names = getRegisteredPlugins().map((p) => p.manifest.name);
285
+ expect(names).toContain("cool-plugin");
286
+ });
287
+
288
+ test("a broken experimental plugin is logged and skipped without affecting others", async () => {
289
+ // Plugin A has a malformed package.json; Plugin B is a healthy
290
+ // legacy register.ts. The loader must isolate A's failure and still
291
+ // register B — same per-plugin contract as the legacy path.
292
+ const brokenDir = join(PLUGINS_DIR, "broken-experimental");
293
+ mkdirSync(brokenDir, { recursive: true });
294
+ writeFileSync(join(brokenDir, "package.json"), "{ not valid json");
295
+
296
+ writePlugin(
297
+ "healthy-legacy",
298
+ `
299
+ registerPlugin({
300
+ manifest: {
301
+ name: "healthy-legacy",
302
+ version: "0.0.1",
303
+ },
304
+ });
305
+ `,
306
+ );
307
+
308
+ await loadUserPlugins();
309
+
310
+ const names = getRegisteredPlugins().map((p) => p.manifest.name);
311
+ expect(names).toContain("healthy-legacy");
312
+ expect(names).not.toContain("broken-experimental");
313
+ });
314
+
315
+ test("experimental and legacy plugins coexist in one workspace", async () => {
316
+ writeExperimentalPlugin("new-style", {
317
+ name: "new-style",
318
+ version: "0.1.0",
319
+ });
320
+ writePlugin(
321
+ "old-style",
322
+ `
323
+ registerPlugin({
324
+ manifest: {
325
+ name: "old-style",
326
+ version: "0.0.1",
327
+ },
328
+ });
329
+ `,
330
+ );
331
+
332
+ await loadUserPlugins();
333
+
334
+ const names = getRegisteredPlugins()
335
+ .map((p) => p.manifest.name)
336
+ .sort();
337
+ expect(names).toEqual(["new-style", "old-style"]);
338
+ });
339
+
340
+ test("package.json branch wins over a stale register.ts in the same dir", async () => {
341
+ // A migrated plugin may keep its old register.ts on disk while it
342
+ // adopts the new convention. The package.json gate takes the
343
+ // experimental path and the legacy register.ts is never imported,
344
+ // so the plugin must register exactly once.
345
+ const dir = join(PLUGINS_DIR, "migrated");
346
+ mkdirSync(dir, { recursive: true });
347
+ writeFileSync(
348
+ join(dir, "package.json"),
349
+ JSON.stringify({ name: "migrated", version: "0.1.0" }),
350
+ );
351
+ // A register.ts that would double-register if both paths fired.
352
+ const registryPath = join(
353
+ import.meta.dir,
354
+ "..",
355
+ "plugins",
356
+ "registry.ts",
357
+ );
358
+ writeFileSync(
359
+ join(dir, "register.ts"),
360
+ `import { registerPlugin } from ${JSON.stringify(registryPath)};
361
+ registerPlugin({ manifest: { name: "migrated", version: "0.0.1", requires: { pluginRuntime: "v1" } } });
362
+ `,
363
+ );
364
+
365
+ await loadUserPlugins();
366
+
367
+ const names = getRegisteredPlugins().map((p) => p.manifest.name);
368
+ expect(names.filter((n) => n === "migrated")).toHaveLength(1);
369
+ });
138
370
  });
139
371
  });
@@ -62,43 +62,3 @@ describe("VellumAcpClientHandler.sessionUpdate", () => {
62
62
  expect(handler.responseText).toBe("");
63
63
  });
64
64
  });
65
-
66
- describe("VellumAcpClientHandler replay suppression", () => {
67
- function messageChunk(text: string): SessionNotification {
68
- return {
69
- sessionId: ACP_SESSION_ID,
70
- update: {
71
- sessionUpdate: "agent_message_chunk",
72
- content: { type: "text", text },
73
- },
74
- };
75
- }
76
-
77
- test("updates received while suppressed are dropped", async () => {
78
- const { handler, sent } = makeHandler();
79
-
80
- handler.beginReplaySuppression();
81
- await handler.sessionUpdate(messageChunk("replayed history"));
82
-
83
- expect(sent).toHaveLength(0);
84
- expect(handler.responseText).toBe("");
85
- });
86
-
87
- test("updates after endReplaySuppression() flow normally", async () => {
88
- const { handler, sent } = makeHandler();
89
-
90
- handler.beginReplaySuppression();
91
- await handler.sessionUpdate(messageChunk("replayed history"));
92
- handler.endReplaySuppression();
93
- await handler.sessionUpdate(messageChunk("live response"));
94
-
95
- expect(sent).toHaveLength(1);
96
- expect(sent[0]).toEqual({
97
- type: "acp_session_update",
98
- acpSessionId: ACP_SESSION_ID,
99
- updateType: "agent_message_chunk",
100
- content: "live response",
101
- });
102
- expect(handler.responseText).toBe("live response");
103
- });
104
- });
@@ -216,22 +216,6 @@ describe("prepareAgentEnv — claude-agent-acp gating", () => {
216
216
  expect(prepared.env?.CLAUDE_CODE_OAUTH_TOKEN).toBe("vault-FFF");
217
217
  });
218
218
 
219
- test("injects the token for the bunx-rewritten claude adapter (adapterCommand gate)", async () => {
220
- // The resolver rewrites a missing claude-agent-acp binary to run via
221
- // `bun x --bun <pkg>` and preserves the canonical identity on
222
- // `adapterCommand`. Without this gate, bunx-resolved spawns would start
223
- // with no auth and die as zombies on the first prompt.
224
- seedVaultToken("vault-bunx");
225
-
226
- const prepared = await prepareAgentEnv({
227
- command: "bun",
228
- args: ["x", "--bun", "@agentclientprotocol/claude-agent-acp"],
229
- adapterCommand: "claude-agent-acp",
230
- });
231
-
232
- expect(prepared.env?.CLAUDE_CODE_OAUTH_TOKEN).toBe("vault-bunx");
233
- });
234
-
235
219
  test("does NOT mutate the caller's agentConfig", async () => {
236
220
  seedVaultToken("vault-GGG");
237
221
  const original = {
@@ -250,115 +234,6 @@ describe("prepareAgentEnv — claude-agent-acp gating", () => {
250
234
  });
251
235
  });
252
236
 
253
- describe("prepareAgentEnv - gemini gating", () => {
254
- function seedVaultGeminiKey(key: string): void {
255
- vaultStore.set("acp/gemini_api_key", key);
256
- }
257
-
258
- test("injects GEMINI_API_KEY from the vault via the broker when agent.env has no override", async () => {
259
- seedVaultGeminiKey("vault-gem-AAA");
260
-
261
- const prepared = await prepareAgentEnv({
262
- command: "gemini",
263
- args: ["--acp"],
264
- });
265
-
266
- expect(prepared.env?.GEMINI_API_KEY).toBe("vault-gem-AAA");
267
- });
268
-
269
- test("auto-registers metadata with acp_spawn in allowedTools when none exists", async () => {
270
- seedVaultGeminiKey("vault-gem-auto-meta");
271
-
272
- await prepareAgentEnv({ command: "gemini", args: ["--acp"] });
273
-
274
- const meta = metadataStore.get("acp/gemini_api_key");
275
- expect(meta).toBeDefined();
276
- expect(meta!.allowedTools).toContain("acp_spawn");
277
- });
278
-
279
- test("injects the key for the bunx-rewritten gemini CLI (adapterCommand gate)", async () => {
280
- seedVaultGeminiKey("vault-gem-bunx");
281
-
282
- const prepared = await prepareAgentEnv({
283
- command: "bun",
284
- args: ["x", "--bun", "@google/gemini-cli", "--acp"],
285
- adapterCommand: "gemini",
286
- });
287
-
288
- expect(prepared.env?.GEMINI_API_KEY).toBe("vault-gem-bunx");
289
- });
290
-
291
- test("a vault miss does NOT throw and spawns without GEMINI_API_KEY (key is optional)", async () => {
292
- const prepared = await prepareAgentEnv({
293
- command: "gemini",
294
- args: ["--acp"],
295
- });
296
-
297
- expect(prepared.env).not.toHaveProperty("GEMINI_API_KEY");
298
- });
299
-
300
- test("respects explicit tool policy that excludes acp_spawn without failing the spawn", async () => {
301
- metadataStore.set("acp/gemini_api_key", {
302
- allowedTools: ["other_tool"],
303
- });
304
- seedVaultGeminiKey("vault-gem-restricted");
305
-
306
- const prepared = await prepareAgentEnv({
307
- command: "gemini",
308
- args: ["--acp"],
309
- });
310
-
311
- expect(prepared.env).not.toHaveProperty("GEMINI_API_KEY");
312
- const meta = metadataStore.get("acp/gemini_api_key");
313
- expect(meta!.allowedTools).toEqual(["other_tool"]);
314
- });
315
-
316
- test("agent.env override wins over the vault entry and skips the broker (precedence pin)", async () => {
317
- // Seed a vault value but no metadata: if the override path consulted the
318
- // broker anyway, ensureAcpCredentialPolicy would create metadata here.
319
- seedVaultGeminiKey("vault-gem-CCC");
320
-
321
- const prepared = await prepareAgentEnv({
322
- command: "gemini",
323
- args: ["--acp"],
324
- env: { GEMINI_API_KEY: "config-gem-DDD" },
325
- });
326
-
327
- expect(prepared.env?.GEMINI_API_KEY).toBe("config-gem-DDD");
328
- expect(metadataStore.has("acp/gemini_api_key")).toBe(false);
329
- });
330
-
331
- test("preserves unrelated env vars on agent.env when injecting from the vault", async () => {
332
- seedVaultGeminiKey("vault-gem-EEE");
333
-
334
- const prepared = await prepareAgentEnv({
335
- command: "gemini",
336
- args: ["--acp"],
337
- env: { NO_COLOR: "1" },
338
- });
339
-
340
- expect(prepared.env?.GEMINI_API_KEY).toBe("vault-gem-EEE");
341
- expect(prepared.env?.NO_COLOR).toBe("1");
342
- });
343
-
344
- test("does NOT mutate the caller's agentConfig", async () => {
345
- seedVaultGeminiKey("vault-gem-GGG");
346
- const original = {
347
- command: "gemini",
348
- args: ["--acp"],
349
- env: { OTHER: "keep" },
350
- };
351
- const beforeEnv = { ...original.env };
352
-
353
- const prepared = await prepareAgentEnv(original);
354
-
355
- expect(prepared).not.toBe(original);
356
- expect(prepared.env).not.toBe(original.env);
357
- expect(original.env).toEqual(beforeEnv);
358
- expect(original.env).not.toHaveProperty("GEMINI_API_KEY");
359
- });
360
- });
361
-
362
237
  describe("prepareAgentEnv — non-claude commands", () => {
363
238
  test("returns the config unchanged for codex-acp (no required env vars today)", async () => {
364
239
  const prepared = await prepareAgentEnv({
@@ -369,18 +244,6 @@ describe("prepareAgentEnv — non-claude commands", () => {
369
244
  expect(prepared.env).toEqual({});
370
245
  });
371
246
 
372
- test("no injection for a bunx-rewritten non-claude adapter", async () => {
373
- seedVaultToken("vault-should-not-leak");
374
-
375
- const prepared = await prepareAgentEnv({
376
- command: "bun",
377
- args: ["x", "--bun", "@zed-industries/codex-acp"],
378
- adapterCommand: "codex-acp",
379
- });
380
-
381
- expect(prepared.env).toEqual({});
382
- });
383
-
384
247
  test("returns the config unchanged for an unrecognized command basename", async () => {
385
248
  seedVaultToken("vault-HHH");
386
249