@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,75 +0,0 @@
1
- /**
2
- * Route handler for conversation analysis.
3
- *
4
- * POST /v1/conversations/:id/analyze — analyze a conversation via a new
5
- * agent loop that produces a structured self-assessment.
6
- *
7
- * The heavy lifting lives in `services/analyze-conversation.ts`. This module
8
- * is thin glue: map the route params to the service, translate service
9
- * errors, and build the success response.
10
- */
11
-
12
- import { z } from "zod";
13
-
14
- import { ACTOR_PRINCIPALS } from "../auth/route-policy.js";
15
- import { analyzeConversation } from "../services/analyze-conversation.js";
16
- import { buildConversationDetailResponse } from "../services/conversation-serializer.js";
17
- import { conversationSummarySchema } from "./conversation-list-routes.js";
18
- import { BadRequestError, InternalError, NotFoundError } from "./errors.js";
19
- import type { RouteDefinition, RouteHandlerArgs } from "./types.js";
20
-
21
- // ---------------------------------------------------------------------------
22
- // Handler
23
- // ---------------------------------------------------------------------------
24
-
25
- async function handleAnalyzeConversation({
26
- pathParams = {},
27
- }: RouteHandlerArgs) {
28
- const conversationId = pathParams.id;
29
- if (!conversationId) {
30
- throw new BadRequestError("Conversation ID is required");
31
- }
32
-
33
- const result = await analyzeConversation(conversationId, {
34
- trigger: "manual",
35
- });
36
-
37
- if ("error" in result) {
38
- const { kind, message } = result.error;
39
- if (kind === "NOT_FOUND") throw new NotFoundError(message);
40
- if (kind === "BAD_REQUEST") throw new BadRequestError(message);
41
- throw new InternalError(message);
42
- }
43
-
44
- const detail = buildConversationDetailResponse(result.analysisConversationId);
45
- if (!detail) {
46
- throw new InternalError(
47
- `Analysis conversation ${result.analysisConversationId} could not be loaded`,
48
- );
49
- }
50
- return detail;
51
- }
52
-
53
- // ---------------------------------------------------------------------------
54
- // Transport-agnostic route definitions
55
- // ---------------------------------------------------------------------------
56
-
57
- export const ROUTES: RouteDefinition[] = [
58
- {
59
- operationId: "analyzeConversation",
60
- endpoint: "conversations/:id/analyze",
61
- method: "POST",
62
- policy: {
63
- requiredScopes: ["chat.write"],
64
- allowedPrincipalTypes: ACTOR_PRINCIPALS,
65
- },
66
- summary: "Analyze a conversation",
67
- description:
68
- "Create a new conversation with a structured self-assessment of an existing conversation.",
69
- tags: ["conversations"],
70
- responseBody: z.object({
71
- conversation: conversationSummarySchema,
72
- }),
73
- handler: handleAnalyzeConversation,
74
- },
75
- ];
@@ -1,477 +0,0 @@
1
- /**
2
- * Unit tests for the analyzeConversation service.
3
- *
4
- * The service is driven directly (no HTTP routing) so tests exercise the
5
- * validation + setup logic against mocked memory/CRUD + transcript helpers.
6
- */
7
-
8
- import { beforeEach, describe, expect, mock, test } from "bun:test";
9
-
10
- mock.module("../../../util/logger.js", () => ({
11
- getLogger: () =>
12
- new Proxy({} as Record<string, unknown>, {
13
- get: () => () => {},
14
- }),
15
- }));
16
-
17
- const mockResolveConversationId = mock((id: string) => id as string | null);
18
- const mockGetConversation = mock(
19
- () =>
20
- ({
21
- id: "conv-1",
22
- title: "Source",
23
- conversationType: "standard",
24
- }) as Record<string, unknown> | null,
25
- );
26
- const mockGetMessages = mock(
27
- () => [{ id: "m-source" }] as Array<{ id: string }>,
28
- );
29
- const mockCreateConversation = mock((_opts?: Record<string, unknown>) => ({
30
- id: "analysis-new",
31
- }));
32
- // Echo back the caller-supplied row id (the request id, under the
33
- // requestId-as-row-id invariant) so tests can assert the persisted message
34
- // row id matches the turn's request id. Falls back to "msg-1" when no id is
35
- // passed.
36
- const mockAddMessage = mock(
37
- async (
38
- _conversationId: string,
39
- _role: string,
40
- _content: string,
41
- opts?: { id?: string },
42
- ) => ({ id: opts?.id ?? "msg-1" }),
43
- );
44
- const mockFindAnalysisConversationFor = mock(
45
- (_parent: string) => null as { id: string } | null,
46
- );
47
- const mockGetConversationSource = mock((_id: string) => null as string | null);
48
-
49
- mock.module("../../../persistence/conversation-key-store.js", () => ({
50
- resolveConversationId: mockResolveConversationId,
51
- }));
52
-
53
- mock.module("../../../persistence/conversation-crud.js", () => ({
54
- getConversation: mockGetConversation,
55
- getMessages: mockGetMessages,
56
- createConversation: mockCreateConversation,
57
- addMessage: mockAddMessage,
58
- findAnalysisConversationFor: mockFindAnalysisConversationFor,
59
- getConversationSource: mockGetConversationSource,
60
- reserveMessage: mock(async () => ({ id: "msg-reserve" })),
61
- }));
62
-
63
- mock.module("../../../export/transcript-formatter.js", () => ({
64
- buildAnalysisTranscript: () => "user: hi",
65
- }));
66
-
67
- // Mock the direct imports the service now uses instead of DI deps.
68
- function makeConversation() {
69
- return {
70
- setTrustContext: mock(() => {}),
71
- ensureActorScopedHistory: mock(() => Promise.resolve()),
72
- setSubagentAllowedTools: mock(() => {}),
73
- updateClient: mock(() => {}),
74
- processing: false,
75
- isProcessing(this: { processing: boolean }) {
76
- return this.processing;
77
- },
78
- setProcessing(this: { processing: boolean }, value: boolean) {
79
- this.processing = value;
80
- },
81
- abortController: null as AbortController | null,
82
- currentRequestId: null as string | null,
83
- loadedHistoryTrustClass: undefined as string | undefined,
84
- runAgentLoop: mock(() => Promise.resolve()),
85
- };
86
- }
87
-
88
- let currentConversation = makeConversation();
89
- const mockGetOrCreateConversation = mock(async () => currentConversation);
90
-
91
- mock.module("../../../daemon/conversation-store.js", () => ({
92
- getOrCreateConversation: mockGetOrCreateConversation,
93
- }));
94
-
95
- import { AssistantEventHub } from "../../assistant-event-hub.js";
96
-
97
- const testHub = new AssistantEventHub();
98
- mock.module("../../assistant-event-hub.js", () => ({
99
- AssistantEventHub,
100
- assistantEventHub: testHub,
101
- broadcastMessage: async () => {},
102
- }));
103
-
104
- import { analyzeConversation } from "../analyze-conversation.js";
105
-
106
- beforeEach(() => {
107
- mockResolveConversationId.mockReset();
108
- mockResolveConversationId.mockImplementation((id: string) => id);
109
- mockGetConversation.mockReset();
110
- mockGetConversation.mockImplementation(() => ({
111
- id: "conv-1",
112
- title: "Source",
113
- conversationType: "standard",
114
- }));
115
- mockGetMessages.mockReset();
116
- mockGetMessages.mockImplementation(() => [{ id: "m-source" }]);
117
- mockCreateConversation.mockReset();
118
- mockCreateConversation.mockImplementation(() => ({ id: "analysis-new" }));
119
- mockAddMessage.mockReset();
120
- mockAddMessage.mockImplementation(
121
- async (
122
- _conversationId: string,
123
- _role: string,
124
- _content: string,
125
- opts?: { id?: string },
126
- ) => ({ id: opts?.id ?? "msg-1" }),
127
- );
128
- mockFindAnalysisConversationFor.mockReset();
129
- mockFindAnalysisConversationFor.mockImplementation(() => null);
130
- mockGetConversationSource.mockReset();
131
- mockGetConversationSource.mockImplementation(() => null);
132
- mockGetOrCreateConversation.mockReset();
133
- currentConversation = makeConversation();
134
- mockGetOrCreateConversation.mockImplementation(
135
- async () => currentConversation,
136
- );
137
- });
138
-
139
- describe("analyzeConversation", () => {
140
- test("returns NOT_FOUND when the source ID does not resolve", async () => {
141
- mockResolveConversationId.mockImplementation(() => null);
142
-
143
- const result = await analyzeConversation("missing", {
144
- trigger: "manual",
145
- });
146
-
147
- expect("error" in result).toBe(true);
148
- if (!("error" in result)) throw new Error("expected error");
149
- expect(result.error.kind).toBe("NOT_FOUND");
150
- expect(result.error.status).toBe(404);
151
- expect(mockGetConversation).not.toHaveBeenCalled();
152
- });
153
-
154
- test("returns NOT_FOUND when the conversation record is missing", async () => {
155
- mockGetConversation.mockImplementation(() => null);
156
-
157
- const result = await analyzeConversation("conv-1", {
158
- trigger: "manual",
159
- });
160
-
161
- expect("error" in result).toBe(true);
162
- if (!("error" in result)) throw new Error("expected error");
163
- expect(result.error.kind).toBe("NOT_FOUND");
164
- expect(result.error.status).toBe(404);
165
- });
166
-
167
- test("returns BAD_REQUEST when the source conversation has no messages", async () => {
168
- mockGetMessages.mockImplementation(() => []);
169
-
170
- const result = await analyzeConversation("conv-1", {
171
- trigger: "manual",
172
- });
173
-
174
- expect("error" in result).toBe(true);
175
- if (!("error" in result)) throw new Error("expected error");
176
- expect(result.error.kind).toBe("BAD_REQUEST");
177
- expect(result.error.status).toBe(400);
178
- });
179
-
180
- test("creates an analysis conversation with unknown trust, no tools, and returns the new ID", async () => {
181
- const result = await analyzeConversation("conv-1", {
182
- trigger: "manual",
183
- });
184
-
185
- expect("error" in result).toBe(false);
186
- if ("error" in result) throw new Error("expected success");
187
- expect(result.analysisConversationId).toBe("analysis-new");
188
-
189
- // Persists the prompt as a user message with unknown trust, under a
190
- // caller-minted row id (the turn's request id).
191
- expect(mockAddMessage).toHaveBeenCalledWith(
192
- "analysis-new",
193
- "user",
194
- expect.any(String),
195
- { id: expect.any(String), metadata: { provenanceTrustClass: "unknown" } },
196
- );
197
-
198
- // Sets trust context to unknown.
199
- expect(currentConversation.setTrustContext).toHaveBeenCalledWith({
200
- trustClass: "unknown",
201
- sourceChannel: "vellum",
202
- });
203
-
204
- // Strips all tools.
205
- expect(currentConversation.setSubagentAllowedTools).toHaveBeenCalledTimes(
206
- 1,
207
- );
208
- const allowedTools = (
209
- currentConversation.setSubagentAllowedTools.mock
210
- .calls as unknown as Array<[Set<string> | undefined]>
211
- )[0]?.[0];
212
- expect(allowedTools).toBeInstanceOf(Set);
213
- expect(allowedTools?.size).toBe(0);
214
-
215
- // requestId === userMessageId invariant: the id the prompt row was
216
- // persisted under, the turn's currentRequestId, and the userMessageId
217
- // handed to the agent loop are all the same value.
218
- const persistedId = (
219
- mockAddMessage.mock.calls as unknown as Array<
220
- [string, string, string, { id?: string } | undefined]
221
- >
222
- )[0]?.[3]?.id;
223
- expect(typeof persistedId).toBe("string");
224
- expect(currentConversation.currentRequestId).toBe(persistedId ?? null);
225
-
226
- // Fires the agent loop with the analyzeConversation call-site so the
227
- // per-call provider config flows through `resolveCallSiteConfig`, keying
228
- // the loop off the same id as userMessageId.
229
- expect(currentConversation.runAgentLoop).toHaveBeenCalledWith(
230
- expect.any(String),
231
- persistedId,
232
- expect.objectContaining({
233
- isInteractive: false,
234
- isUserMessage: true,
235
- callSite: "analyzeConversation",
236
- }),
237
- );
238
- });
239
-
240
- // ── Auto trigger ──────────────────────────────────────────────────
241
-
242
- test("auto: creates a new analysis conversation when none exists, with source=auto-analysis, dedicated groupId, and forkParentConversationId", async () => {
243
- mockFindAnalysisConversationFor.mockImplementation(() => null);
244
-
245
- const result = await analyzeConversation("conv-1", {
246
- trigger: "auto",
247
- });
248
-
249
- expect("error" in result).toBe(false);
250
- if ("error" in result) throw new Error("expected success");
251
- expect(result.analysisConversationId).toBe("analysis-new");
252
-
253
- // Verifies the rolling-analysis lookup was consulted against the source ID.
254
- expect(mockFindAnalysisConversationFor).toHaveBeenCalledWith("conv-1");
255
-
256
- expect(mockCreateConversation).toHaveBeenCalledTimes(1);
257
- expect(mockCreateConversation).toHaveBeenCalledWith(
258
- expect.objectContaining({
259
- title: "Analysis: Source",
260
- source: "auto-analysis",
261
- groupId: "system:background",
262
- forkParentConversationId: "conv-1",
263
- }),
264
- );
265
- });
266
-
267
- test("auto: skips the run (no agent loop, no message persisted) when the rolling analysis conversation is already processing", async () => {
268
- currentConversation.processing = true;
269
-
270
- const result = await analyzeConversation("conv-1", {
271
- trigger: "auto",
272
- });
273
-
274
- // Returns a successful no-op result tagged with `skipped: true`.
275
- expect("error" in result).toBe(false);
276
- if ("error" in result) throw new Error("expected success");
277
- expect(result.analysisConversationId).toBe("analysis-new");
278
- expect(result.skipped).toBe(true);
279
-
280
- // Critically, none of the mutating side effects should have run: no
281
- // message persisted, no trust context overwritten, no agent loop fired.
282
- expect(mockAddMessage).not.toHaveBeenCalled();
283
- expect(currentConversation.setTrustContext).not.toHaveBeenCalled();
284
- expect(currentConversation.runAgentLoop).not.toHaveBeenCalled();
285
- expect(currentConversation.abortController).toBeNull();
286
- });
287
-
288
- test("manual: does NOT skip when the conversation reports processing (guard is auto-only)", async () => {
289
- currentConversation.processing = true;
290
-
291
- const result = await analyzeConversation("conv-1", {
292
- trigger: "manual",
293
- });
294
-
295
- expect("error" in result).toBe(false);
296
- if ("error" in result) throw new Error("expected success");
297
- expect(result.skipped).toBeUndefined();
298
-
299
- // Manual trigger always proceeds — it creates a fresh conversation per
300
- // invocation, so there is no shared-state concurrency hazard.
301
- expect(mockAddMessage).toHaveBeenCalled();
302
- expect(currentConversation.runAgentLoop).toHaveBeenCalled();
303
- });
304
-
305
- test("auto: reuses an existing rolling analysis conversation (no new row)", async () => {
306
- mockFindAnalysisConversationFor.mockImplementation(() => ({
307
- id: "analysis-existing",
308
- }));
309
-
310
- const result = await analyzeConversation("conv-1", {
311
- trigger: "auto",
312
- });
313
-
314
- expect("error" in result).toBe(false);
315
- if ("error" in result) throw new Error("expected success");
316
- expect(result.analysisConversationId).toBe("analysis-existing");
317
-
318
- // No new conversation row is created on reuse.
319
- expect(mockCreateConversation).not.toHaveBeenCalled();
320
-
321
- // The new user message is appended to the existing analysis conversation,
322
- // persisted under the turn's request id.
323
- expect(mockAddMessage).toHaveBeenCalledWith(
324
- "analysis-existing",
325
- "user",
326
- expect.any(String),
327
- {
328
- id: expect.any(String),
329
- metadata: { provenanceTrustClass: "guardian" },
330
- },
331
- );
332
- });
333
-
334
- test("auto: invalidates loadedHistoryTrustClass before ensureActorScopedHistory on reuse so stale ctx.messages is reloaded", async () => {
335
- // Simulate a reused rolling conversation whose prior run already cached
336
- // a guardian-class history load. Without explicit invalidation,
337
- // ensureActorScopedHistory would short-circuit and runAgentLoopImpl
338
- // would execute against ctx.messages missing the newly-enqueued prompt.
339
- mockFindAnalysisConversationFor.mockImplementation(() => ({
340
- id: "analysis-existing",
341
- }));
342
- currentConversation.loadedHistoryTrustClass = "guardian";
343
- let trustClassWhenEnsured: string | undefined = "sentinel";
344
- currentConversation.ensureActorScopedHistory.mockImplementation(() => {
345
- trustClassWhenEnsured = currentConversation.loadedHistoryTrustClass;
346
- return Promise.resolve();
347
- });
348
-
349
- const result = await analyzeConversation("conv-1", {
350
- trigger: "auto",
351
- });
352
-
353
- expect("error" in result).toBe(false);
354
- // The invalidation must land before ensureActorScopedHistory runs so
355
- // the reload inside it pulls the freshly-persisted user prompt.
356
- expect(trustClassWhenEnsured).toBeUndefined();
357
- expect(currentConversation.ensureActorScopedHistory).toHaveBeenCalledTimes(
358
- 1,
359
- );
360
- });
361
-
362
- test("auto: sets trustClass to guardian", async () => {
363
- const result = await analyzeConversation("conv-1", {
364
- trigger: "auto",
365
- });
366
- expect("error" in result).toBe(false);
367
-
368
- expect(currentConversation.setTrustContext).toHaveBeenCalledWith({
369
- trustClass: "guardian",
370
- sourceChannel: "vellum",
371
- });
372
- });
373
-
374
- test("auto: does NOT strip the tool surface", async () => {
375
- const result = await analyzeConversation("conv-1", {
376
- trigger: "auto",
377
- });
378
- expect("error" in result).toBe(false);
379
-
380
- // Manual mode calls this with an empty Set; auto mode must leave the
381
- // conversation's default tool surface intact.
382
- expect(currentConversation.setSubagentAllowedTools).not.toHaveBeenCalled();
383
- });
384
-
385
- test("auto: rejects when the source conversation is itself an auto-analysis conversation", async () => {
386
- mockGetConversationSource.mockImplementation(() => "auto-analysis");
387
-
388
- const result = await analyzeConversation("conv-1", {
389
- trigger: "auto",
390
- });
391
-
392
- expect("error" in result).toBe(true);
393
- if (!("error" in result)) throw new Error("expected error");
394
- expect(result.error.kind).toBe("BAD_REQUEST");
395
- expect(result.error.status).toBe(400);
396
-
397
- // Nothing downstream of the guard should have fired.
398
- expect(mockFindAnalysisConversationFor).not.toHaveBeenCalled();
399
- expect(mockCreateConversation).not.toHaveBeenCalled();
400
- expect(mockAddMessage).not.toHaveBeenCalled();
401
- });
402
-
403
- test.each(["memory-retrospective", "memory-retrospective-fork"])(
404
- "auto: rejects when the source conversation is a %s conversation",
405
- async (source) => {
406
- // Fork-kind retrospective conversations carry a full copy of the
407
- // source conversation's history; auto-analyzing one would re-process
408
- // the entire source conversation and double-write memory.
409
- mockGetConversationSource.mockImplementation(() => source);
410
-
411
- const result = await analyzeConversation("conv-1", {
412
- trigger: "auto",
413
- });
414
-
415
- expect("error" in result).toBe(true);
416
- if (!("error" in result)) throw new Error("expected error");
417
- expect(result.error.kind).toBe("BAD_REQUEST");
418
- expect(result.error.status).toBe(400);
419
-
420
- // Nothing downstream of the guard should have fired.
421
- expect(mockFindAnalysisConversationFor).not.toHaveBeenCalled();
422
- expect(mockCreateConversation).not.toHaveBeenCalled();
423
- expect(mockAddMessage).not.toHaveBeenCalled();
424
- },
425
- );
426
-
427
- test("manual: does NOT reject a memory-retrospective conversation (guard is auto-only)", async () => {
428
- mockGetConversationSource.mockImplementation(
429
- () => "memory-retrospective-fork",
430
- );
431
-
432
- const result = await analyzeConversation("conv-1", {
433
- trigger: "manual",
434
- });
435
-
436
- expect("error" in result).toBe(false);
437
- if ("error" in result) throw new Error("expected success");
438
- expect(result.analysisConversationId).toBe("analysis-new");
439
- });
440
-
441
- test("auto: routes the agent loop through callSite: 'analyzeConversation'", async () => {
442
- await analyzeConversation("conv-1", { trigger: "auto" });
443
-
444
- // Same requestId === userMessageId invariant on the auto path: the row
445
- // id the prompt was persisted under, currentRequestId, and the loop's
446
- // userMessageId are the same value.
447
- const persistedId = (
448
- mockAddMessage.mock.calls as unknown as Array<
449
- [string, string, string, { id?: string } | undefined]
450
- >
451
- )[0]?.[3]?.id;
452
- expect(typeof persistedId).toBe("string");
453
- expect(currentConversation.currentRequestId).toBe(persistedId ?? null);
454
- expect(currentConversation.runAgentLoop).toHaveBeenCalledWith(
455
- expect.any(String),
456
- persistedId,
457
- expect.objectContaining({ callSite: "analyzeConversation" }),
458
- );
459
- });
460
-
461
- test("does not thread modelIntent/modelOverride into getOrCreateConversation", async () => {
462
- // Per-call model selection now happens via the call-site resolver against
463
- // `llm.callSites.analyzeConversation`, not via legacy modelIntent/
464
- // modelOverride keys on the conversation create options.
465
- await analyzeConversation("conv-1", { trigger: "auto" });
466
-
467
- const calls = mockGetOrCreateConversation.mock.calls as unknown as Array<
468
- [string, Record<string, unknown> | undefined]
469
- >;
470
- expect(calls.length).toBe(1);
471
- const passedOpts = calls[0]?.[1];
472
- if (passedOpts !== undefined) {
473
- expect("modelIntent" in passedOpts).toBe(false);
474
- expect("modelOverride" in passedOpts).toBe(false);
475
- }
476
- });
477
- });