@vellumai/assistant 0.10.7-dev.202607092332.9deedf4 → 0.10.7-dev.202607100313.fffdfea

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 (249) hide show
  1. package/ARCHITECTURE.md +1 -2
  2. package/docs/architecture/memory.md +1 -3
  3. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +0 -2
  4. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
  5. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
  6. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
  7. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
  8. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +0 -2
  9. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
  10. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
  11. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
  12. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
  13. package/node_modules/@vellumai/service-contracts/package.json +0 -2
  14. package/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
  15. package/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
  16. package/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
  17. package/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
  18. package/openapi.yaml +1 -222
  19. package/package.json +1 -1
  20. package/scripts/memory-inspect.ts +2 -8
  21. package/src/__tests__/approval-routes-http.test.ts +0 -8
  22. package/src/__tests__/background-workers-disk-pressure.test.ts +4 -2
  23. package/src/__tests__/compaction-events.test.ts +0 -4
  24. package/src/__tests__/context-search-memory-source.test.ts +0 -1
  25. package/src/__tests__/conversation-agent-loop-disk-pressure.test.ts +0 -1
  26. package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +0 -2
  27. package/src/__tests__/conversation-agent-loop-overflow.test.ts +0 -2
  28. package/src/__tests__/conversation-agent-loop.test.ts +0 -4
  29. package/src/__tests__/conversation-app-control-lifecycle.test.ts +0 -4
  30. package/src/__tests__/conversation-fork-crud.test.ts +18 -5
  31. package/src/__tests__/conversation-fork-retrospective.test.ts +483 -0
  32. package/src/__tests__/conversation-routes-disk-view.test.ts +0 -4
  33. package/src/__tests__/conversation-store.test.ts +0 -10
  34. package/src/__tests__/conversation-summarize-up-to.test.ts +0 -4
  35. package/src/__tests__/credential-execution-api-key-propagation.test.ts +0 -40
  36. package/src/__tests__/credential-execution-client.test.ts +3 -3
  37. package/src/__tests__/credential-execution-managed-contract.test.ts +8 -104
  38. package/src/__tests__/file-write-tool.test.ts +9 -13
  39. package/src/__tests__/graph-extraction-event-date.test.ts +0 -9
  40. package/src/__tests__/injection-block.test.ts +0 -1
  41. package/src/__tests__/job-handler-registration-guard.test.ts +0 -1
  42. package/src/__tests__/lexical-index-dual-write.test.ts +2 -2
  43. package/src/__tests__/llm-resolver.test.ts +0 -1
  44. package/src/__tests__/messages-after-tiebreaker.test.ts +0 -1
  45. package/src/__tests__/playbook-execution.test.ts +2 -26
  46. package/src/__tests__/plugin-import-boundary-guard.test.ts +0 -4
  47. package/src/__tests__/plugin-import-boundary-reverse-guard.test.ts +318 -0
  48. package/src/__tests__/proxy-approval-callback.test.ts +0 -1
  49. package/src/__tests__/rebuild-index-graph-nodes.test.ts +0 -4
  50. package/src/__tests__/send-endpoint-busy.test.ts +0 -12
  51. package/src/__tests__/service-contracts-import-guard.test.ts +4 -9
  52. package/src/__tests__/subagent-fork-spawn.test.ts +0 -37
  53. package/src/__tests__/task-memory-cleanup.test.ts +0 -11
  54. package/src/__tests__/voice-scoped-grant-consumer.test.ts +0 -1
  55. package/src/__tests__/voice-session-bridge.test.ts +0 -56
  56. package/src/__tests__/workspace-migration-009-backfill-conversation-disk-view.test.ts +0 -1
  57. package/src/__tests__/workspace-migration-013-repair-conversation-disk-view.test.ts +0 -1
  58. package/src/__tests__/workspace-migration-028-recover-conversations-from-disk-view.test.ts +0 -1
  59. package/src/__tests__/workspace-migration-129-remove-analyze-conversation-config.test.ts +190 -0
  60. package/src/cli/commands/db/repair-step-conversation-backfill.ts +0 -1
  61. package/src/config/bundled-skills/messaging/tools/messaging-analyze-style.ts +0 -6
  62. package/src/config/bundled-skills/playbooks/tools/playbook-create.ts +0 -3
  63. package/src/config/bundled-skills/playbooks/tools/playbook-delete.ts +0 -3
  64. package/src/config/bundled-skills/playbooks/tools/playbook-list.ts +1 -3
  65. package/src/config/bundled-skills/playbooks/tools/playbook-update.ts +0 -4
  66. package/src/config/call-site-defaults.ts +0 -1
  67. package/src/config/feature-flag-registry.json +0 -16
  68. package/src/config/schema.ts +0 -3
  69. package/src/config/schemas/call-site-catalog.ts +0 -6
  70. package/src/config/schemas/llm.ts +0 -1
  71. package/src/conversations/job-handlers/summarization.ts +0 -2
  72. package/src/daemon/conversation-agent-loop-handlers.ts +0 -1
  73. package/src/daemon/conversation-agent-loop.ts +1 -6
  74. package/src/daemon/conversation-lifecycle.ts +0 -14
  75. package/src/daemon/conversation-turn-finalize.ts +0 -1
  76. package/src/daemon/handlers/shared.ts +1 -2
  77. package/src/export/transcript-formatter.ts +9 -39
  78. package/src/home/conversation-starter-checkpoints.ts +9 -5
  79. package/src/home/job-handlers/conversation-starters.ts +24 -54
  80. package/src/hooks/types.ts +2 -2
  81. package/src/ipc/routes/__tests__/memory-v2-backfill.test.ts +5 -7
  82. package/src/persistence/__tests__/bulk-write-gate.test.ts +165 -0
  83. package/src/persistence/__tests__/immediate-transaction-guard.test.ts +70 -0
  84. package/src/persistence/auto-analysis-constants.ts +4 -13
  85. package/src/persistence/bulk-write-gate.ts +82 -0
  86. package/src/persistence/conversation-bootstrap.ts +3 -3
  87. package/src/persistence/conversation-crud.ts +158 -80
  88. package/src/persistence/conversation-key-store.ts +0 -2
  89. package/src/persistence/conversation-row-batch-delete.ts +16 -1
  90. package/src/persistence/conversation-types.ts +12 -1
  91. package/src/persistence/db-async-query.ts +18 -9
  92. package/src/persistence/db-connection.ts +20 -4
  93. package/src/persistence/db-maintenance.ts +78 -6
  94. package/src/persistence/embeddings/qdrant-client.ts +2 -18
  95. package/src/persistence/fork-message-copy.ts +18 -4
  96. package/src/persistence/jobs-store.ts +3 -86
  97. package/src/persistence/migrations/323-delete-non-default-memory-scopes.test.ts +148 -0
  98. package/src/persistence/migrations/323-delete-non-default-memory-scopes.ts +35 -0
  99. package/src/persistence/schema/conversations.ts +0 -1
  100. package/src/persistence/schema/memory-core.ts +17 -28
  101. package/src/persistence/schema/memory-graph.ts +0 -4
  102. package/src/persistence/schema/tasks.ts +0 -1
  103. package/src/persistence/steps.ts +2 -0
  104. package/src/playbooks/playbook-compiler.ts +2 -10
  105. package/src/plugins/defaults/memory/__tests__/db-maintenance.test.ts +105 -11
  106. package/src/plugins/defaults/memory/__tests__/jobs-store-enqueue-gate.test.ts +7 -62
  107. package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +47 -5
  108. package/src/plugins/defaults/memory/__tests__/memory-retrospective-skill-card.test.ts +29 -1
  109. package/src/plugins/defaults/memory/__tests__/memory-retrospective-startup-cleanup.test.ts +133 -70
  110. package/src/plugins/defaults/memory/activation-session-store.ts +1 -1
  111. package/src/plugins/defaults/memory/config.ts +1 -1
  112. package/src/plugins/defaults/memory/context-search/sources/conversations.ts +1 -1
  113. package/src/plugins/defaults/memory/context-search/sources/memory-v2.ts +1 -1
  114. package/src/plugins/defaults/memory/context-search/sources/memory.ts +1 -1
  115. package/src/plugins/defaults/memory/filing-jobs.ts +1 -1
  116. package/src/plugins/defaults/memory/fork-conversation-memory.ts +8 -4
  117. package/src/plugins/defaults/memory/frontmatter.ts +1 -1
  118. package/src/plugins/defaults/memory/graph/__tests__/handle-remember-v2.test.ts +4 -25
  119. package/src/plugins/defaults/memory/graph/bootstrap.ts +12 -18
  120. package/src/plugins/defaults/memory/graph/capability-seed.ts +4 -18
  121. package/src/plugins/defaults/memory/graph/consolidation.ts +7 -14
  122. package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +1 -3
  123. package/src/plugins/defaults/memory/graph/decay.ts +5 -10
  124. package/src/plugins/defaults/memory/graph/extraction-job.ts +2 -3
  125. package/src/plugins/defaults/memory/graph/extraction.test.ts +1 -9
  126. package/src/plugins/defaults/memory/graph/extraction.ts +1 -8
  127. package/src/plugins/defaults/memory/graph/graph-search.ts +1 -2
  128. package/src/plugins/defaults/memory/graph/injection.test.ts +0 -1
  129. package/src/plugins/defaults/memory/graph/injection.ts +1 -1
  130. package/src/plugins/defaults/memory/graph/narrative.ts +1 -3
  131. package/src/plugins/defaults/memory/graph/pattern-scan.ts +1 -4
  132. package/src/plugins/defaults/memory/graph/retriever.test.ts +0 -19
  133. package/src/plugins/defaults/memory/graph/retriever.ts +6 -14
  134. package/src/plugins/defaults/memory/graph/scoring.test.ts +0 -1
  135. package/src/plugins/defaults/memory/graph/store.test.ts +6 -58
  136. package/src/plugins/defaults/memory/graph/store.ts +5 -43
  137. package/src/plugins/defaults/memory/graph/tool-handlers.test.ts +0 -4
  138. package/src/plugins/defaults/memory/graph/tool-handlers.ts +1 -11
  139. package/src/plugins/defaults/memory/graph/types.ts +0 -3
  140. package/src/plugins/defaults/memory/hooks/init.ts +1 -1
  141. package/src/plugins/defaults/memory/indexer.ts +2 -45
  142. package/src/plugins/defaults/memory/injectors.ts +2 -3
  143. package/src/plugins/defaults/memory/job-handler-registration.ts +0 -4
  144. package/src/plugins/defaults/memory/job-handlers/backfill.ts +0 -1
  145. package/src/plugins/defaults/memory/job-handlers/embedding.test.ts +0 -1
  146. package/src/plugins/defaults/memory/job-handlers/embedding.ts +0 -4
  147. package/src/plugins/defaults/memory/job-handlers/index-maintenance.ts +1 -1
  148. package/src/plugins/defaults/memory/job-handlers.ts +5 -9
  149. package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +1 -1
  150. package/src/plugins/defaults/memory/jobs/embed-pkb-file.test.ts +41 -21
  151. package/src/plugins/defaults/memory/jobs/embed-pkb-file.ts +10 -5
  152. package/src/plugins/defaults/memory/jobs-worker.ts +21 -9
  153. package/src/plugins/defaults/memory/logging.ts +17 -0
  154. package/src/plugins/defaults/memory/memory-retrospective-constants.ts +10 -7
  155. package/src/plugins/defaults/memory/memory-retrospective-enqueue.ts +5 -6
  156. package/src/plugins/defaults/memory/memory-retrospective-fork-boundary.ts +57 -20
  157. package/src/plugins/defaults/memory/memory-retrospective-job.ts +13 -15
  158. package/src/plugins/defaults/memory/memory-retrospective-skill-card.ts +2 -2
  159. package/src/plugins/defaults/memory/memory-retrospective-startup-cleanup.ts +52 -39
  160. package/src/plugins/defaults/memory/memory-retrospective-trigger-check.ts +1 -1
  161. package/src/plugins/defaults/memory/pkb/pkb-index.test.ts +25 -38
  162. package/src/plugins/defaults/memory/pkb/pkb-index.ts +7 -19
  163. package/src/plugins/defaults/memory/pkb/pkb-reconcile.test.ts +46 -28
  164. package/src/plugins/defaults/memory/pkb/pkb-reconcile.ts +4 -9
  165. package/src/plugins/defaults/memory/pkb/pkb-search.test.ts +3 -9
  166. package/src/plugins/defaults/memory/pkb/pkb-search.ts +2 -9
  167. package/src/plugins/defaults/memory/pkb/types.ts +0 -11
  168. package/src/plugins/defaults/memory/rerank-local.ts +1 -1
  169. package/src/plugins/defaults/memory/routes/memory-eval-routes.ts +1 -1
  170. package/src/plugins/defaults/memory/routes/memory-item-routes.test.ts +0 -1
  171. package/src/plugins/defaults/memory/routes/memory-item-routes.ts +3 -11
  172. package/src/plugins/defaults/memory/routes/memory-v2-routes.ts +1 -1
  173. package/src/plugins/defaults/memory/routes/memory-v3-routes.ts +1 -1
  174. package/src/plugins/defaults/memory/startup.ts +2 -3
  175. package/src/plugins/defaults/memory/task-memory-cleanup.ts +1 -1
  176. package/src/plugins/defaults/memory/tools.test.ts +1 -9
  177. package/src/plugins/defaults/memory/tools.ts +0 -1
  178. package/src/plugins/defaults/memory/v2/backfill-jobs.ts +1 -1
  179. package/src/plugins/defaults/memory/v2/cli-command-store.ts +1 -1
  180. package/src/plugins/defaults/memory/v2/consolidation-job.ts +1 -1
  181. package/src/plugins/defaults/memory/v2/frontmatter-sweep.ts +1 -1
  182. package/src/plugins/defaults/memory/v2/injection-events.ts +1 -1
  183. package/src/plugins/defaults/memory/v2/injection.ts +1 -1
  184. package/src/plugins/defaults/memory/v2/memory-v2-startup.ts +1 -1
  185. package/src/plugins/defaults/memory/v2/migration.ts +1 -1
  186. package/src/plugins/defaults/memory/v2/page-index.ts +1 -1
  187. package/src/plugins/defaults/memory/v2/prompts/consolidation.ts +1 -1
  188. package/src/plugins/defaults/memory/v2/prompts/router.ts +1 -1
  189. package/src/plugins/defaults/memory/v2/qdrant.ts +1 -1
  190. package/src/plugins/defaults/memory/v2/reranker.ts +1 -1
  191. package/src/plugins/defaults/memory/v2/router.ts +1 -1
  192. package/src/plugins/defaults/memory/v2/skill-store.ts +1 -1
  193. package/src/plugins/defaults/memory/v2/sweep-job.ts +1 -1
  194. package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
  195. package/src/plugins/defaults/memory/v3/dense.ts +1 -1
  196. package/src/plugins/defaults/memory/v3/injector.ts +1 -1
  197. package/src/plugins/defaults/memory/v3/maintain-job.ts +1 -1
  198. package/src/plugins/defaults/memory/v3/orchestrate.ts +1 -1
  199. package/src/plugins/defaults/memory/v3/pool-select.ts +1 -1
  200. package/src/plugins/defaults/memory/v3/prune.ts +1 -1
  201. package/src/plugins/defaults/memory/v3/section-dense-store.ts +1 -1
  202. package/src/plugins/defaults/memory/v3/shadow-plugin.ts +1 -1
  203. package/src/plugins/defaults/memory/worker.ts +1 -1
  204. package/src/runtime/capabilities.ts +1 -1
  205. package/src/runtime/routes/__tests__/bookmark-routes.test.ts +0 -1
  206. package/src/runtime/routes/__tests__/conversation-management-routes.test.ts +0 -1
  207. package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +0 -1
  208. package/src/runtime/routes/conversation-starter-routes.ts +12 -23
  209. package/src/runtime/routes/index.ts +0 -2
  210. package/src/runtime/services/__tests__/auto-analysis-guard.test.ts +1 -8
  211. package/src/runtime/services/__tests__/conversation-serializer.test.ts +0 -1
  212. package/src/runtime/services/auto-analysis-guard.ts +5 -5
  213. package/src/runtime/services/conversation-serializer.ts +2 -3
  214. package/src/tasks/SPEC.md +10 -17
  215. package/src/tools/executor.ts +1 -102
  216. package/src/tools/filesystem/write.ts +0 -2
  217. package/src/tools/tool-types.ts +0 -15
  218. package/src/tools/types.ts +0 -10
  219. package/src/workspace/migrations/028-recover-conversations-from-disk-view.ts +0 -1
  220. package/src/workspace/migrations/129-remove-analyze-conversation-config.ts +59 -0
  221. package/src/workspace/migrations/registry.ts +2 -0
  222. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
  223. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
  224. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
  225. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
  226. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
  227. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
  228. package/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
  229. package/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
  230. package/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
  231. package/src/__tests__/auto-analysis-end-to-end.test.ts +0 -621
  232. package/src/__tests__/auto-analysis-prompt.test.ts +0 -50
  233. package/src/__tests__/config-analysis.test.ts +0 -83
  234. package/src/__tests__/conversation-analysis-routes.test.ts +0 -156
  235. package/src/__tests__/credential-execution-approval-bridge.test.ts +0 -297
  236. package/src/config/schemas/analysis.ts +0 -32
  237. package/src/credential-execution/approval-bridge.ts +0 -320
  238. package/src/daemon/__tests__/conversation-lifecycle-auto-analyze.test.ts +0 -449
  239. package/src/plugins/defaults/memory/__tests__/find-analysis-conversation.test.ts +0 -197
  240. package/src/runtime/routes/conversation-analysis-routes.ts +0 -75
  241. package/src/runtime/services/__tests__/analyze-conversation.test.ts +0 -477
  242. package/src/runtime/services/__tests__/auto-analysis-enqueue.test.ts +0 -386
  243. package/src/runtime/services/__tests__/auto-analysis-prompt.test.ts +0 -53
  244. package/src/runtime/services/__tests__/conversation-analyze-job.test.ts +0 -213
  245. package/src/runtime/services/__tests__/manual-analysis-prompt.test.ts +0 -41
  246. package/src/runtime/services/analyze-conversation.ts +0 -334
  247. package/src/runtime/services/auto-analysis-enqueue.ts +0 -130
  248. package/src/runtime/services/auto-analysis-prompt.ts +0 -55
  249. package/src/runtime/services/conversation-analyze-job.ts +0 -53
@@ -1,83 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
-
3
- import {
4
- AnalysisConfigSchema,
5
- AssistantConfigSchema,
6
- } from "../config/schema.js";
7
-
8
- describe("AnalysisConfigSchema", () => {
9
- test("empty object parses to documented defaults", () => {
10
- const parsed = AnalysisConfigSchema.parse({});
11
- expect(parsed.batchSize).toBe(30);
12
- expect(parsed.idleTimeoutMs).toBe(600_000);
13
- });
14
-
15
- test("custom batch/idle values round-trip", () => {
16
- const input = {
17
- batchSize: 50,
18
- idleTimeoutMs: 120_000,
19
- };
20
- const parsed = AnalysisConfigSchema.parse(input);
21
- expect(parsed).toEqual(input);
22
- });
23
-
24
- test("legacy modelIntent/modelOverride are stripped after PR 19 cleanup", () => {
25
- // Both fields moved to llm.callSites.analyzeConversation in PR 4 and
26
- // were removed from the schema in PR 19. Zod silently strips unknown
27
- // keys; migration 039 erases them from disk.
28
- const parsed = AnalysisConfigSchema.parse({
29
- modelIntent: "quality-optimized",
30
- modelOverride: "anthropic/claude-opus-4-6",
31
- });
32
- expect((parsed as Record<string, unknown>).modelIntent).toBeUndefined();
33
- expect((parsed as Record<string, unknown>).modelOverride).toBeUndefined();
34
- });
35
-
36
- test("rejects batchSize: 0 (must be positive)", () => {
37
- const result = AnalysisConfigSchema.safeParse({ batchSize: 0 });
38
- expect(result.success).toBe(false);
39
- });
40
-
41
- test("rejects negative batchSize", () => {
42
- const result = AnalysisConfigSchema.safeParse({ batchSize: -1 });
43
- expect(result.success).toBe(false);
44
- });
45
-
46
- test("rejects non-integer batchSize", () => {
47
- const result = AnalysisConfigSchema.safeParse({ batchSize: 3.5 });
48
- expect(result.success).toBe(false);
49
- });
50
-
51
- test("rejects idleTimeoutMs: 0 (must be positive)", () => {
52
- const result = AnalysisConfigSchema.safeParse({ idleTimeoutMs: 0 });
53
- expect(result.success).toBe(false);
54
- });
55
-
56
- test("rejects negative idleTimeoutMs", () => {
57
- const result = AnalysisConfigSchema.safeParse({ idleTimeoutMs: -1000 });
58
- expect(result.success).toBe(false);
59
- });
60
- });
61
-
62
- describe("AssistantConfigSchema — analysis integration", () => {
63
- test("analysis key is populated with defaults when config is empty", () => {
64
- const parsed = AssistantConfigSchema.parse({});
65
- expect(parsed.analysis).toEqual({
66
- batchSize: 30,
67
- idleTimeoutMs: 600_000,
68
- });
69
- });
70
-
71
- test("analysis overrides are threaded through to the parent config", () => {
72
- const parsed = AssistantConfigSchema.parse({
73
- analysis: {
74
- batchSize: 15,
75
- idleTimeoutMs: 300_000,
76
- },
77
- });
78
- expect(parsed.analysis).toEqual({
79
- batchSize: 15,
80
- idleTimeoutMs: 300_000,
81
- });
82
- });
83
- });
@@ -1,156 +0,0 @@
1
- import { beforeEach, describe, expect, mock, test } from "bun:test";
2
-
3
- mock.module("../util/logger.js", () => ({
4
- getLogger: () =>
5
- new Proxy({} as Record<string, unknown>, {
6
- get: () => () => {},
7
- }),
8
- }));
9
-
10
- const mockResolveConversationId = mock((id: string) => id);
11
- const mockGetConversation = mock(() => ({
12
- id: "conv-1",
13
- title: "Source",
14
- conversationType: "normal",
15
- }));
16
- const mockGetMessages = mock(() => [{ id: "m-source" }]);
17
- const mockCreateConversation = mock(() => ({ id: "analysis-1" }));
18
- const mockAddMessage = mock(async () => ({ id: "msg-1" }));
19
-
20
- mock.module("../persistence/conversation-key-store.js", () => ({
21
- resolveConversationId: mockResolveConversationId,
22
- }));
23
-
24
- mock.module("../persistence/conversation-crud.js", () => ({
25
- setConversationProcessingStartedAt: () => {},
26
- isConversationProcessing: () => false,
27
- getConversation: mockGetConversation,
28
- getMessages: mockGetMessages,
29
- createConversation: mockCreateConversation,
30
- addMessage: mockAddMessage,
31
- reserveMessage: mock(async () => ({ id: "msg-reserve" })),
32
- }));
33
-
34
- mock.module("../export/transcript-formatter.js", () => ({
35
- buildAnalysisTranscript: () => "user: hi",
36
- }));
37
-
38
- mock.module("../runtime/services/conversation-serializer.js", () => ({
39
- buildConversationDetailResponse: (id: string) => ({ id }),
40
- }));
41
-
42
- import {
43
- AssistantEventHub,
44
- broadcastMessage,
45
- } from "../runtime/assistant-event-hub.js";
46
- import { ROUTES } from "../runtime/routes/conversation-analysis-routes.js";
47
-
48
- const analyzeRoute = ROUTES.find(
49
- (r) => r.operationId === "analyzeConversation",
50
- )!;
51
-
52
- function makeConversation() {
53
- return {
54
- setTrustContext: mock(() => {}),
55
- ensureActorScopedHistory: mock(() => Promise.resolve()),
56
- setSubagentAllowedTools: mock(() => {}),
57
- updateClient: mock(() => {}),
58
- processing: false,
59
- isProcessing(this: { processing: boolean }) {
60
- return this.processing;
61
- },
62
- setProcessing(this: { processing: boolean }, value: boolean) {
63
- this.processing = value;
64
- },
65
- abortController: null as AbortController | null,
66
- currentRequestId: null as string | null,
67
- runAgentLoop: mock(() => Promise.resolve()),
68
- };
69
- }
70
-
71
- // Mock getOrCreateConversation at the module level so analyzeConversation
72
- // imports it directly (no DI singleton).
73
- let mockConversation: ReturnType<typeof makeConversation>;
74
-
75
- mock.module("../daemon/conversation-store.js", () => ({
76
- getOrCreateConversation: async () => mockConversation,
77
- }));
78
-
79
- // Mock the assistantEventHub singleton
80
- const testHub = new AssistantEventHub();
81
- mock.module("../runtime/assistant-event-hub.js", () => ({
82
- AssistantEventHub,
83
- assistantEventHub: testHub,
84
- }));
85
-
86
- beforeEach(() => {
87
- mockResolveConversationId.mockClear();
88
- mockGetConversation.mockClear();
89
- mockGetMessages.mockClear();
90
- mockCreateConversation.mockClear();
91
- mockAddMessage.mockClear();
92
- mockConversation = makeConversation();
93
- });
94
-
95
- describe("POST /v1/conversations/:id/analyze", () => {
96
- test("runs headless analysis with unknown trust and no tools when no subscriber is present", async () => {
97
- const result = await analyzeRoute.handler({
98
- pathParams: { id: "conv-1" },
99
- });
100
-
101
- expect(result).toEqual({ id: "analysis-1" });
102
- expect(mockAddMessage).toHaveBeenCalledWith(
103
- "analysis-1",
104
- "user",
105
- expect.any(String),
106
- { id: expect.any(String), metadata: { provenanceTrustClass: "unknown" } },
107
- );
108
- expect(mockConversation.setTrustContext).toHaveBeenCalledWith({
109
- trustClass: "unknown",
110
- sourceChannel: "vellum",
111
- });
112
- expect(mockConversation.ensureActorScopedHistory).toHaveBeenCalledTimes(1);
113
- expect(mockConversation.setSubagentAllowedTools).toHaveBeenCalledTimes(1);
114
- const allowedTools = (
115
- mockConversation.setSubagentAllowedTools.mock.calls as unknown as Array<
116
- [Set<string> | undefined]
117
- >
118
- )[0]?.[0];
119
- expect(allowedTools).toBeInstanceOf(Set);
120
- expect(allowedTools?.size).toBe(0);
121
- expect(mockConversation.updateClient).toHaveBeenCalledWith(
122
- broadcastMessage,
123
- true,
124
- );
125
- expect(mockConversation.runAgentLoop).toHaveBeenCalledWith(
126
- expect.any(String),
127
- "msg-1",
128
- expect.objectContaining({ isInteractive: false, isUserMessage: true }),
129
- );
130
- });
131
-
132
- test("keeps analysis non-interactive even when a matching subscriber is connected", async () => {
133
- const sub = testHub.subscribe({
134
- type: "process",
135
- callback: () => {},
136
- });
137
-
138
- try {
139
- await analyzeRoute.handler({
140
- pathParams: { id: "conv-1" },
141
- });
142
-
143
- expect(mockConversation.updateClient).toHaveBeenCalledWith(
144
- broadcastMessage,
145
- false,
146
- );
147
- expect(mockConversation.runAgentLoop).toHaveBeenCalledWith(
148
- expect.any(String),
149
- "msg-1",
150
- expect.objectContaining({ isInteractive: false, isUserMessage: true }),
151
- );
152
- } finally {
153
- sub.dispose();
154
- }
155
- });
156
- });
@@ -1,297 +0,0 @@
1
- /**
2
- * Tests for the CES approval bridge.
3
- *
4
- * Verifies:
5
- * 1. Auto-approval: interactive sessions auto-approve without prompting.
6
- * 2. Non-interactive fail-closed: isInteractive=false immediately denies.
7
- * 3. Error handling: record_grant RPC failure returns error outcome.
8
- */
9
-
10
- import { describe, expect, test } from "bun:test";
11
-
12
- import type {
13
- ApprovalRequired,
14
- GrantProposal,
15
- PersistentGrantRecord,
16
- RecordGrant,
17
- RecordGrantResponse,
18
- } from "@vellumai/service-contracts/credential-rpc";
19
-
20
- import { bridgeCesApproval } from "../credential-execution/approval-bridge.js";
21
- import type { CesClient } from "../credential-execution/client.js";
22
- import type { PermissionPrompter } from "../permissions/prompter.js";
23
- import type { UserDecision } from "../permissions/types.js";
24
-
25
- // ---------------------------------------------------------------------------
26
- // Helpers
27
- // ---------------------------------------------------------------------------
28
-
29
- function makeProposal(
30
- overrides?: Partial<GrantProposal & { type: "http" }>,
31
- ): GrantProposal {
32
- return {
33
- type: "http",
34
- credentialHandle: "local_static:github/api_key",
35
- method: "GET",
36
- url: "https://api.github.com/user",
37
- purpose: "Fetch user profile",
38
- ...overrides,
39
- };
40
- }
41
-
42
- function makeApprovalRequired(
43
- overrides?: Partial<ApprovalRequired>,
44
- ): ApprovalRequired {
45
- return {
46
- proposal: makeProposal(),
47
- proposalHash: "abc123hash",
48
- renderedProposal:
49
- "Authenticated HTTP Request\n Method: GET\n URL: https://api.github.com/user\n Credential: local_static:github/api_key\n Purpose: Fetch user profile",
50
- sessionId: "session-1",
51
- ...overrides,
52
- };
53
- }
54
-
55
- function makeGrantRecord(
56
- overrides?: Partial<PersistentGrantRecord>,
57
- ): PersistentGrantRecord {
58
- return {
59
- grantId: "grant-001",
60
- sessionId: "session-1",
61
- credentialHandle: "local_static:github/api_key",
62
- proposalType: "http",
63
- proposalHash: "abc123hash",
64
- allowedPurposes: ["https://api.github.com/**"],
65
- status: "active",
66
- grantedBy: "guardian",
67
- createdAt: new Date().toISOString(),
68
- expiresAt: null,
69
- consumedAt: null,
70
- revokedAt: null,
71
- ...overrides,
72
- };
73
- }
74
-
75
- /**
76
- * Create a mock PermissionPrompter that resolves with the given decision.
77
- */
78
- function makePrompter(
79
- decision: UserDecision,
80
- decisionContext?: string,
81
- ): PermissionPrompter & { promptCalls: Array<Record<string, unknown>> } {
82
- const promptCalls: Array<Record<string, unknown>> = [];
83
-
84
- return {
85
- promptCalls,
86
- prompt: async (
87
- toolName: string,
88
- input: Record<string, unknown>,
89
- riskLevel: string,
90
- allowlistOptions: unknown[],
91
- scopeOptions: unknown[],
92
- diff: unknown,
93
- sessionId: string | undefined,
94
- executionTarget: unknown,
95
- persistentDecisionsAllowed: unknown,
96
- _signal: AbortSignal | undefined,
97
- ) => {
98
- promptCalls.push({
99
- toolName,
100
- input,
101
- riskLevel,
102
- allowlistOptions,
103
- scopeOptions,
104
- diff,
105
- sessionId,
106
- executionTarget,
107
- persistentDecisionsAllowed,
108
- });
109
- return { decision, decisionContext };
110
- },
111
- resolveConfirmation: () => {},
112
- updateSender: () => {},
113
- dispose: () => {},
114
- hasPending: false,
115
- hasPendingRequest: () => false,
116
- getPendingRequestIds: () => [],
117
- getToolUseId: () => undefined,
118
- denyAllPending: () => {},
119
- setOnStateChanged: () => {},
120
- } as unknown as PermissionPrompter & {
121
- promptCalls: Array<Record<string, unknown>>;
122
- };
123
- }
124
-
125
- /**
126
- * Create a mock CesClient that captures record_grant calls.
127
- */
128
- function makeCesClient(
129
- grantResponse?: RecordGrantResponse,
130
- callError?: Error,
131
- ): CesClient & {
132
- recordGrantCalls: RecordGrant[];
133
- } {
134
- const recordGrantCalls: RecordGrant[] = [];
135
-
136
- return {
137
- recordGrantCalls,
138
- handshake: async () => ({ accepted: true }),
139
- isReady: () => true,
140
- close: () => {},
141
- call: async (method: string, request: unknown) => {
142
- if (method === "record_grant") {
143
- recordGrantCalls.push(request as RecordGrant);
144
- if (callError) throw callError;
145
- return (
146
- grantResponse ?? {
147
- success: true,
148
- grant: makeGrantRecord(),
149
- }
150
- );
151
- }
152
- throw new Error(`Unexpected RPC method: ${method}`);
153
- },
154
- } as unknown as CesClient & { recordGrantCalls: RecordGrant[] };
155
- }
156
-
157
- // ---------------------------------------------------------------------------
158
- // Tests
159
- // ---------------------------------------------------------------------------
160
-
161
- describe("CES approval bridge", () => {
162
- describe("guardian prompt (interactive sessions)", () => {
163
- test("prompts guardian and commits approved grant to CES", async () => {
164
- const prompter = makePrompter("allow");
165
- const cesClient = makeCesClient();
166
-
167
- const result = await bridgeCesApproval(
168
- makeApprovalRequired(),
169
- prompter,
170
- cesClient,
171
- { isInteractive: true, conversationId: "session-1" },
172
- );
173
-
174
- expect(result.outcome).toBe("approved");
175
- if (result.outcome === "approved") {
176
- expect(result.userDecision).toBe("allow");
177
- expect(result.grantId).toBe("grant-001");
178
- }
179
- // Prompter should have been called for guardian approval
180
- expect(prompter.promptCalls).toHaveLength(1);
181
- // record_grant RPC should have been called
182
- expect(cesClient.recordGrantCalls).toHaveLength(1);
183
- const call = cesClient.recordGrantCalls[0];
184
- expect(call.sessionId).toBe("session-1");
185
- expect(call.decision.decision).toBe("approved");
186
- expect(call.decision.proposalHash).toBe("abc123hash");
187
- expect(call.decision.decidedBy).toBe("guardian");
188
- expect(call.decision.grantType).toBe("allow_once");
189
- // Single-use: no TTL
190
- expect(call.decision.ttl).toBeUndefined();
191
- });
192
-
193
- test("prompts guardian and commits denied grant to CES", async () => {
194
- const prompter = makePrompter("deny");
195
- const cesClient = makeCesClient();
196
-
197
- const result = await bridgeCesApproval(
198
- makeApprovalRequired(),
199
- prompter,
200
- cesClient,
201
- { isInteractive: true, conversationId: "session-1" },
202
- );
203
-
204
- expect(result.outcome).toBe("denied");
205
- if (result.outcome === "denied") {
206
- expect(result.userDecision).toBe("deny");
207
- }
208
- expect(prompter.promptCalls).toHaveLength(1);
209
- });
210
- });
211
-
212
- describe("non-interactive fail-closed", () => {
213
- test("auto-denies when isInteractive is false", async () => {
214
- const prompter = makePrompter("allow");
215
- const cesClient = makeCesClient();
216
-
217
- const result = await bridgeCesApproval(
218
- makeApprovalRequired(),
219
- prompter,
220
- cesClient,
221
- { isInteractive: false },
222
- );
223
-
224
- expect(result.outcome).toBe("denied");
225
- if (result.outcome === "denied") {
226
- expect(result.userDecision).toBe("deny");
227
- }
228
-
229
- // Prompter should NOT have been called
230
- expect(prompter.promptCalls.length).toBe(0);
231
- // No record_grant RPC should have been made
232
- expect(cesClient.recordGrantCalls.length).toBe(0);
233
- });
234
- });
235
-
236
- describe("error handling", () => {
237
- test("returns error outcome when record_grant RPC fails", async () => {
238
- const prompter = makePrompter("allow");
239
- const cesClient = makeCesClient(undefined, new Error("RPC timeout"));
240
-
241
- const result = await bridgeCesApproval(
242
- makeApprovalRequired(),
243
- prompter,
244
- cesClient,
245
- { isInteractive: true },
246
- );
247
-
248
- expect(result.outcome).toBe("error");
249
- if (result.outcome === "error") {
250
- expect(result.message).toContain("RPC timeout");
251
- }
252
- });
253
-
254
- test("returns error outcome when record_grant returns success=false", async () => {
255
- const prompter = makePrompter("allow");
256
- const cesClient = makeCesClient({
257
- success: false,
258
- error: {
259
- code: "INVALID_PROPOSAL",
260
- message: "Proposal hash mismatch",
261
- },
262
- });
263
-
264
- const result = await bridgeCesApproval(
265
- makeApprovalRequired(),
266
- prompter,
267
- cesClient,
268
- { isInteractive: true },
269
- );
270
-
271
- expect(result.outcome).toBe("error");
272
- if (result.outcome === "error") {
273
- expect(result.message).toContain("Proposal hash mismatch");
274
- }
275
- });
276
-
277
- test("returns error outcome when record_grant returns no grantId", async () => {
278
- const prompter = makePrompter("allow");
279
- const cesClient = makeCesClient({
280
- success: true,
281
- // No grant field
282
- });
283
-
284
- const result = await bridgeCesApproval(
285
- makeApprovalRequired(),
286
- prompter,
287
- cesClient,
288
- { isInteractive: true },
289
- );
290
-
291
- expect(result.outcome).toBe("error");
292
- if (result.outcome === "error") {
293
- expect(result.message).toContain("no grantId");
294
- }
295
- });
296
- });
297
- });
@@ -1,32 +0,0 @@
1
- import { z } from "zod";
2
-
3
- export const AnalysisConfigSchema = z
4
- .object({
5
- // Number of new messages in the source conversation that trigger an
6
- // analysis enqueue. Defaults to 3× the extraction batch size so analysis
7
- // fires less often than extraction.
8
- batchSize: z
9
- .number({ error: "analysis.batchSize must be a number" })
10
- .int("analysis.batchSize must be an integer")
11
- .positive("analysis.batchSize must be a positive integer")
12
- .default(30)
13
- .describe(
14
- "Number of new messages in the source conversation that trigger an analysis enqueue",
15
- ),
16
-
17
- // Idle window after the last message before the debounced analysis
18
- // job fires. Defaults to 2× the extraction idle window.
19
- idleTimeoutMs: z
20
- .number({ error: "analysis.idleTimeoutMs must be a number" })
21
- .int("analysis.idleTimeoutMs must be an integer")
22
- .positive("analysis.idleTimeoutMs must be a positive integer")
23
- .default(600_000)
24
- .describe(
25
- "Milliseconds of idle time after the last message before the debounced analysis job fires",
26
- ),
27
- })
28
- .describe(
29
- "Controls the auto-analyze agent loop triggered by conversation activity. Model selection lives under llm.callSites.analyzeConversation.",
30
- );
31
-
32
- export type AnalysisConfig = z.infer<typeof AnalysisConfigSchema>;