@vellumai/assistant 0.10.3-dev.202606301559.bafb7ae → 0.10.3-dev.202606301742.2b63687

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 (52) hide show
  1. package/openapi.yaml +43 -0
  2. package/package.json +1 -1
  3. package/src/__tests__/background-shell-bash.test.ts +25 -0
  4. package/src/__tests__/background-shell-host-bash.test.ts +1 -0
  5. package/src/__tests__/background-tool-registry.test.ts +97 -0
  6. package/src/__tests__/background-tool-routes.test.ts +72 -1
  7. package/src/__tests__/background-workers-disk-pressure.test.ts +0 -1
  8. package/src/__tests__/conversation-queue.test.ts +44 -0
  9. package/src/__tests__/lifecycle-memory-v2-seed.test.ts +2 -2
  10. package/src/__tests__/persistence-layering-guard.test.ts +33 -18
  11. package/src/__tests__/plugin-import-boundary-guard.test.ts +2 -0
  12. package/src/__tests__/secret-routes-platform-proxy.test.ts +1 -1
  13. package/src/__tests__/shell-observability.test.ts +1 -0
  14. package/src/acp/__tests__/prepare-agent-env.test.ts +0 -97
  15. package/src/acp/auto-install.ts +12 -8
  16. package/src/acp/prepare-agent-env.ts +0 -12
  17. package/src/acp/resolve-agent.test.ts +6 -45
  18. package/src/acp/resolve-agent.ts +2 -4
  19. package/src/api/events/background-tool-completed.test.ts +51 -0
  20. package/src/api/events/background-tool-completed.ts +29 -0
  21. package/src/api/events/background-tool-started.test.ts +36 -0
  22. package/src/api/events/background-tool-started.ts +28 -0
  23. package/src/api/index.ts +12 -0
  24. package/src/api/responses/conversation-message.ts +5 -0
  25. package/src/config/acp-defaults.test.ts +0 -10
  26. package/src/config/acp-defaults.ts +0 -6
  27. package/src/config/bundled-skills/acp/SKILL.md +13 -45
  28. package/src/config/bundled-skills/acp/TOOLS.json +3 -3
  29. package/src/config/feature-flag-registry.json +8 -0
  30. package/src/daemon/conversation-process.ts +11 -8
  31. package/src/daemon/lifecycle.ts +4 -4
  32. package/src/daemon/message-protocol.ts +3 -0
  33. package/src/daemon/message-types/background-tools.ts +28 -0
  34. package/src/daemon/skill-memory-refresh.ts +2 -2
  35. package/src/persistence/conversation-crud.ts +0 -62
  36. package/src/plugins/defaults/memory/__tests__/find-most-recent-retrospective-for.test.ts +2 -4
  37. package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +7 -4
  38. package/src/plugins/defaults/memory/find-most-recent-retrospective-for.ts +66 -0
  39. package/src/plugins/defaults/memory/memory-retrospective-job.ts +1 -1
  40. package/src/{daemon → plugins/defaults/memory/v2}/__tests__/memory-v2-startup.test.ts +6 -6
  41. package/src/{daemon → plugins/defaults/memory/v2}/memory-v2-startup.test.ts +8 -8
  42. package/src/{daemon → plugins/defaults/memory/v2}/memory-v2-startup.ts +20 -22
  43. package/src/runtime/routes/background-tool-routes.ts +34 -5
  44. package/src/runtime/routes/conversation-routes.ts +13 -0
  45. package/src/runtime/routes/secret-routes.ts +1 -1
  46. package/src/tools/acp/list-agents.test.ts +0 -6
  47. package/src/tools/background-tool-registry.ts +61 -0
  48. package/src/tools/host-terminal/host-shell.test.ts +397 -0
  49. package/src/tools/host-terminal/host-shell.ts +194 -14
  50. package/src/tools/terminal/shell.test.ts +177 -0
  51. package/src/tools/terminal/shell.ts +93 -4
  52. package/src/workspace/migrations/070-memory-v2-summary-schema-rebuild.ts +1 -1
package/openapi.yaml CHANGED
@@ -2310,8 +2310,49 @@ paths:
2310
2310
  - command
2311
2311
  - startedAt
2312
2312
  additionalProperties: false
2313
+ completed:
2314
+ type: array
2315
+ items:
2316
+ type: object
2317
+ properties:
2318
+ id:
2319
+ type: string
2320
+ toolName:
2321
+ type: string
2322
+ conversationId:
2323
+ type: string
2324
+ command:
2325
+ type: string
2326
+ startedAt:
2327
+ type: number
2328
+ status:
2329
+ type: string
2330
+ enum:
2331
+ - completed
2332
+ - failed
2333
+ - cancelled
2334
+ exitCode:
2335
+ anyOf:
2336
+ - type: number
2337
+ - type: "null"
2338
+ output:
2339
+ type: string
2340
+ completedAt:
2341
+ type: number
2342
+ required:
2343
+ - id
2344
+ - toolName
2345
+ - conversationId
2346
+ - command
2347
+ - startedAt
2348
+ - status
2349
+ - exitCode
2350
+ - output
2351
+ - completedAt
2352
+ additionalProperties: false
2313
2353
  required:
2314
2354
  - tools
2355
+ - completed
2315
2356
  additionalProperties: false
2316
2357
  /v1/background-tools/cancel:
2317
2358
  post:
@@ -17717,6 +17758,8 @@ paths:
17717
17758
  required:
17718
17759
  - acpSessionId
17719
17760
  additionalProperties: false
17761
+ backgroundToolNotification:
17762
+ type: boolean
17720
17763
  slackMessage:
17721
17764
  type: object
17722
17765
  properties:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.10.3-dev.202606301559.bafb7ae",
3
+ "version": "0.10.3-dev.202606301742.2b63687",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -80,6 +80,7 @@ const mockIsBackgroundToolLimitReached = mock(() => false);
80
80
  mock.module("../tools/background-tool-registry.js", () => ({
81
81
  registerBackgroundTool: mockRegisterBackgroundTool,
82
82
  removeBackgroundTool: mockRemoveBackgroundTool,
83
+ recordCompletedBackgroundTool: () => {},
83
84
  generateBackgroundToolId: mockGenerateBackgroundToolId,
84
85
  isBackgroundToolLimitReached: mockIsBackgroundToolLimitReached,
85
86
  MAX_BACKGROUND_TOOLS: 20,
@@ -211,6 +212,30 @@ describe("bash tool background mode", () => {
211
212
  expect(wakeCall.hint).toContain("exit=1");
212
213
  });
213
214
 
215
+ test("cancelled background process wakes with the cancellation, not a completed result", async () => {
216
+ await shellTool.execute(
217
+ { command: "sleep 30", activity: "test", background: true },
218
+ baseContext,
219
+ );
220
+
221
+ // User presses Stop: cancel aborts the run and kills the process.
222
+ const registered = mockRegisterBackgroundTool.mock
223
+ .calls[0]![0] as BackgroundTool;
224
+ registered.cancel();
225
+
226
+ await waitForWake(mockWakeAgentForOpportunity);
227
+
228
+ const wakeCall = mockWakeAgentForOpportunity.mock
229
+ .calls[0]![0] as WakeOptions;
230
+ // The wake must reflect the cancellation, not the generic "completed"
231
+ // framing + SIGKILL-failed output the assistant used to receive — so it
232
+ // matches the recorded/broadcast status and the inline card.
233
+ expect(wakeCall.hint).toContain("bg-test1234");
234
+ expect(wakeCall.hint).toContain("cancelled");
235
+ expect(wakeCall.hint).not.toContain("completed");
236
+ expect(wakeCall.untrustedOutput?.content).toContain("cancelled");
237
+ });
238
+
214
239
  test("foreground mode still works when background is not set", async () => {
215
240
  const result = await shellTool.execute(
216
241
  { command: "echo foreground_test_789", activity: "test" },
@@ -23,6 +23,7 @@ const mockIsBackgroundToolLimitReached = mock(() => false);
23
23
  mock.module("../tools/background-tool-registry.js", () => ({
24
24
  registerBackgroundTool: mockRegisterBackgroundTool,
25
25
  removeBackgroundTool: mockRemoveBackgroundTool,
26
+ recordCompletedBackgroundTool: () => {},
26
27
  generateBackgroundToolId: mockGenerateBackgroundToolId,
27
28
  isBackgroundToolLimitReached: mockIsBackgroundToolLimitReached,
28
29
  MAX_BACKGROUND_TOOLS: 20,
@@ -4,9 +4,13 @@ import {
4
4
  _clearRegistryForTesting,
5
5
  type BackgroundTool,
6
6
  cancelBackgroundTool,
7
+ type CompletedBackgroundTool,
7
8
  generateBackgroundToolId,
8
9
  listBackgroundTools,
10
+ listCompletedBackgroundTools,
9
11
  MAX_BACKGROUND_TOOLS,
12
+ MAX_COMPLETED_BACKGROUND_TOOLS,
13
+ recordCompletedBackgroundTool,
10
14
  registerBackgroundTool,
11
15
  removeBackgroundTool,
12
16
  } from "../tools/background-tool-registry.js";
@@ -129,6 +133,99 @@ describe("background-tool-registry", () => {
129
133
  });
130
134
  });
131
135
 
136
+ describe("completed ring (recordCompletedBackgroundTool)", () => {
137
+ function makeCompletion(
138
+ overrides: Partial<CompletedBackgroundTool> = {},
139
+ ): CompletedBackgroundTool {
140
+ return {
141
+ id: overrides.id ?? "bg-done-1",
142
+ toolName: overrides.toolName ?? "bash",
143
+ conversationId: overrides.conversationId ?? "conv-1",
144
+ command: overrides.command ?? "echo hi",
145
+ startedAt: overrides.startedAt ?? 1,
146
+ status: overrides.status ?? "completed",
147
+ exitCode: overrides.exitCode ?? 0,
148
+ output: overrides.output ?? "hi",
149
+ completedAt: overrides.completedAt ?? 2,
150
+ };
151
+ }
152
+
153
+ test("records a completed tool and lists it with terminal fields", () => {
154
+ recordCompletedBackgroundTool(
155
+ makeCompletion({ id: "bg-c1", status: "failed", exitCode: 1 }),
156
+ );
157
+
158
+ const listed = listCompletedBackgroundTools();
159
+ expect(listed).toHaveLength(1);
160
+ expect(listed[0]).toMatchObject({
161
+ id: "bg-c1",
162
+ status: "failed",
163
+ exitCode: 1,
164
+ output: "hi",
165
+ });
166
+ });
167
+
168
+ test("filters completed tools by conversationId", () => {
169
+ recordCompletedBackgroundTool(
170
+ makeCompletion({ id: "bg-c1", conversationId: "conv-1" }),
171
+ );
172
+ recordCompletedBackgroundTool(
173
+ makeCompletion({ id: "bg-c2", conversationId: "conv-2" }),
174
+ );
175
+
176
+ expect(listCompletedBackgroundTools("conv-1").map((t) => t.id)).toEqual([
177
+ "bg-c1",
178
+ ]);
179
+ expect(listCompletedBackgroundTools("conv-9")).toHaveLength(0);
180
+ });
181
+
182
+ test("re-recording the same id replaces rather than duplicates", () => {
183
+ recordCompletedBackgroundTool(
184
+ makeCompletion({ id: "bg-c1", status: "completed" }),
185
+ );
186
+ recordCompletedBackgroundTool(
187
+ makeCompletion({ id: "bg-c1", status: "cancelled" }),
188
+ );
189
+
190
+ const listed = listCompletedBackgroundTools();
191
+ expect(listed).toHaveLength(1);
192
+ expect(listed[0]!.status).toBe("cancelled");
193
+ });
194
+
195
+ test("evicts the oldest beyond MAX_COMPLETED_BACKGROUND_TOOLS", () => {
196
+ for (let i = 0; i < MAX_COMPLETED_BACKGROUND_TOOLS + 5; i++) {
197
+ recordCompletedBackgroundTool(makeCompletion({ id: `bg-r${i}` }));
198
+ }
199
+
200
+ const listed = listCompletedBackgroundTools();
201
+ expect(listed).toHaveLength(MAX_COMPLETED_BACKGROUND_TOOLS);
202
+ // Oldest five evicted; newest retained.
203
+ expect(listed.some((t) => t.id === "bg-r0")).toBe(false);
204
+ expect(listed.some((t) => t.id === "bg-r5")).toBe(true);
205
+ expect(
206
+ listed.some(
207
+ (t) => t.id === `bg-r${MAX_COMPLETED_BACKGROUND_TOOLS + 4}`,
208
+ ),
209
+ ).toBe(true);
210
+ });
211
+
212
+ test("recording a completion does not touch the active registry", () => {
213
+ registerBackgroundTool(makeTool({ id: "bg-active" }));
214
+ recordCompletedBackgroundTool(makeCompletion({ id: "bg-done" }));
215
+
216
+ expect(listBackgroundTools().map((t) => t.id)).toEqual(["bg-active"]);
217
+ expect(listCompletedBackgroundTools().map((t) => t.id)).toEqual([
218
+ "bg-done",
219
+ ]);
220
+ });
221
+
222
+ test("_clearRegistryForTesting clears the completed ring", () => {
223
+ recordCompletedBackgroundTool(makeCompletion({ id: "bg-c1" }));
224
+ _clearRegistryForTesting();
225
+ expect(listCompletedBackgroundTools()).toHaveLength(0);
226
+ });
227
+ });
228
+
132
229
  describe("generateBackgroundToolId", () => {
133
230
  test("returns a bg- prefixed string", () => {
134
231
  const id = generateBackgroundToolId();
@@ -5,6 +5,7 @@ import { BadRequestError } from "../runtime/routes/errors.js";
5
5
  import type { RouteDefinition } from "../runtime/routes/types.js";
6
6
  import {
7
7
  _clearRegistryForTesting,
8
+ recordCompletedBackgroundTool,
8
9
  registerBackgroundTool,
9
10
  } from "../tools/background-tool-registry.js";
10
11
 
@@ -45,13 +46,83 @@ afterEach(() => {
45
46
 
46
47
  describe("background tool routes", () => {
47
48
  describe("GET /v1/background-tools (list)", () => {
48
- test("returns empty array when no tools are registered", async () => {
49
+ test("returns empty arrays when no tools are registered", async () => {
49
50
  const route = findRoute("background_tool_list")!;
50
51
  const result = (await route.handler({})) as {
51
52
  tools: unknown[];
53
+ completed: unknown[];
52
54
  };
53
55
 
54
56
  expect(result.tools).toEqual([]);
57
+ expect(result.completed).toEqual([]);
58
+ });
59
+
60
+ test("returns recently-completed tools with terminal fields", async () => {
61
+ recordCompletedBackgroundTool({
62
+ id: "bg-done-1",
63
+ toolName: "bash",
64
+ conversationId: "conv-1",
65
+ command: "npm run build",
66
+ startedAt: 1700000000000,
67
+ status: "completed",
68
+ exitCode: 0,
69
+ output: "built",
70
+ completedAt: 1700000004200,
71
+ });
72
+
73
+ const route = findRoute("background_tool_list")!;
74
+ const result = (await route.handler({})) as {
75
+ tools: unknown[];
76
+ completed: Array<{
77
+ id: string;
78
+ status: string;
79
+ exitCode: number | null;
80
+ output: string;
81
+ completedAt: number;
82
+ }>;
83
+ };
84
+
85
+ expect(result.tools).toEqual([]);
86
+ expect(result.completed).toHaveLength(1);
87
+ expect(result.completed[0]).toMatchObject({
88
+ id: "bg-done-1",
89
+ status: "completed",
90
+ exitCode: 0,
91
+ output: "built",
92
+ completedAt: 1700000004200,
93
+ });
94
+ });
95
+
96
+ test("filters completed tools by conversationId", async () => {
97
+ recordCompletedBackgroundTool({
98
+ id: "bg-d1",
99
+ toolName: "bash",
100
+ conversationId: "conv-a",
101
+ command: "x",
102
+ startedAt: 1,
103
+ status: "completed",
104
+ exitCode: 0,
105
+ output: "",
106
+ completedAt: 2,
107
+ });
108
+ recordCompletedBackgroundTool({
109
+ id: "bg-d2",
110
+ toolName: "bash",
111
+ conversationId: "conv-b",
112
+ command: "x",
113
+ startedAt: 1,
114
+ status: "failed",
115
+ exitCode: 1,
116
+ output: "",
117
+ completedAt: 2,
118
+ });
119
+
120
+ const route = findRoute("background_tool_list")!;
121
+ const result = (await route.handler({
122
+ queryParams: { conversationId: "conv-a" },
123
+ })) as { completed: Array<{ id: string }> };
124
+
125
+ expect(result.completed.map((t) => t.id)).toEqual(["bg-d1"]);
55
126
  });
56
127
 
57
128
  test("returns registered tools with toolName field", async () => {
@@ -122,7 +122,6 @@ mock.module("../persistence/conversation-crud.js", () => ({
122
122
  })),
123
123
  deleteLastExchange: mock(() => 0),
124
124
  findAnalysisConversationFor: mock(() => null),
125
- findMostRecentRetrospectiveFor: mock(() => null),
126
125
  forkConversation: mock(() => ({ id: "conv-fork" })),
127
126
  forkConversationForRetrospective: mock(async () => ({ id: "conv-fork" })),
128
127
  getConversationOverrideProfile: () => undefined,
@@ -3090,4 +3090,48 @@ describe("subagent notification user_message_echo suppression", () => {
3090
3090
  await resolveRun(1);
3091
3091
  await new Promise((r) => setTimeout(r, 10));
3092
3092
  });
3093
+
3094
+ test("drained background-tool wake message persists and wakes the agent but emits no user_message_echo", async () => {
3095
+ const conversation = makeConversation();
3096
+ await conversation.loadFromDb();
3097
+
3098
+ const events1: ServerMessage[] = [];
3099
+ const eventsNotif: ServerMessage[] = [];
3100
+
3101
+ // Occupy the conversation so the injected wake queues.
3102
+ const p1 = conversation.processMessage({
3103
+ content: "msg-1",
3104
+ attachments: [],
3105
+ onEvent: (e) => events1.push(e),
3106
+ requestId: "req-1",
3107
+ });
3108
+ await waitForPendingRun(1);
3109
+
3110
+ // The backgrounded bash/host_bash completion wake persists a
3111
+ // `<background_event source="background-tool">` row, tagged with the
3112
+ // `backgroundEventSource` metadata `persistWakeTriggerMessage` writes.
3113
+ conversation.enqueueMessage({
3114
+ content:
3115
+ '<background_event source="background-tool">Background command completed (id=bg-1, exit=0):</background_event>',
3116
+ onEvent: (e) => eventsNotif.push(e),
3117
+ requestId: "req-bg-notif",
3118
+ metadata: { backgroundEventSource: "background-tool" },
3119
+ });
3120
+
3121
+ await resolveRun(0);
3122
+ await p1;
3123
+ await waitForPendingRun(2);
3124
+
3125
+ // Still persisted (so the orchestrator LLM sees it) and still wakes the
3126
+ // agent...
3127
+ expect(
3128
+ capturedAddMessages.some((m) => m.content.includes("background_event")),
3129
+ ).toBe(true);
3130
+ expect(pendingRuns.length).toBe(2);
3131
+ // ...but no user_message_echo, so the client never renders a live bubble.
3132
+ expect(eventsNotif.some((e) => e.type === "user_message_echo")).toBe(false);
3133
+
3134
+ await resolveRun(1);
3135
+ await new Promise((r) => setTimeout(r, 10));
3136
+ });
3093
3137
  });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Tests for the memory-v2 skill seed gate and the v2 concept-page schema
3
3
  * rebuild gate, both invoked from the daemon startup path
4
- * (`assistant/src/daemon/memory-v2-startup.ts`).
4
+ * (`assistant/src/plugins/defaults/memory/v2/memory-v2-startup.ts`).
5
5
  *
6
6
  * The gates are exercised in isolation rather than mounting the full
7
7
  * lifecycle import graph. Coverage matrix:
@@ -142,7 +142,7 @@ const {
142
142
  maybeSeedMemoryV2Skills,
143
143
  maybeRebuildMemoryV2Concepts,
144
144
  rebuildBm25CorpusStatsAndReseedSkills,
145
- } = await import("../daemon/memory-v2-startup.js");
145
+ } = await import("../plugins/defaults/memory/v2/memory-v2-startup.js");
146
146
 
147
147
  // ---------------------------------------------------------------------------
148
148
  // Test fixtures
@@ -36,26 +36,37 @@ const MEMORY_DIR = join(ASSISTANT_SRC, "plugins", "defaults", "memory");
36
36
  /**
37
37
  * TECH DEBT — residual `persistence/` → `memory/` feature back-imports.
38
38
  *
39
- * These are genuine couplings to the memory *feature* (conversation
40
- * title/disk-view services, conversation/group migrations, retrospective +
41
- * v2 state, the graph bootstrap, the conversation-key store, raw-query helpers,
42
- * the job checkpoint/cleanup/worker controls) that the
43
- * persistence layer still depends on. They violate the
44
- * one-way memory → persistence direction and are scheduled for decoupling in a
45
- * follow-up (move the depended-on feature logic behind a persistence-owned
46
- * seam, or invert the dependency so memory injects it). Until then they are
47
- * pinned here so the guard fails the moment a NEW back-import is introduced.
39
+ * A genuine coupling to the memory *feature* that violates the one-way
40
+ * memory → persistence direction, pinned here so the guard fails the moment a
41
+ * NEW back-import is introduced.
42
+ *
43
+ * The lone remaining entry is the in-worker memory consolidation /
44
+ * graph-maintenance SCHEDULER (`jobs-worker.ts` → `v2/consolidation-job` for
45
+ * `countBufferLines`). Inverting it means memory deciding what to enqueue on
46
+ * each worker tick — that is roadmap bullet #4 (memory-jobs → schedule-jobs),
47
+ * deferred until the Schedules worker + `/workspace/schedules` API land.
48
+ * Decouple it then; do not add to this list without a decoupling plan.
48
49
  *
49
50
  * Keyed by the importing persistence file (relative to repo root); the value
50
51
  * is the set of allowed `memory/<specifier>` module paths it may import.
51
- * Do NOT add to this list without a decoupling plan — the whole point of the
52
- * guard is to ratchet this set down to empty, never up.
53
52
  */
54
53
  const PERSISTENCE_TO_MEMORY_ALLOWLIST: Record<string, ReadonlySet<string>> = {
55
- "assistant/src/persistence/conversation-crud.ts": new Set([
56
- "memory-retrospective-constants",
57
- ]),
58
54
  "assistant/src/persistence/jobs-worker.ts": new Set(["v2/consolidation-job"]),
55
+ };
56
+
57
+ /**
58
+ * PERMANENT exception — the migration registry, NOT tech debt.
59
+ *
60
+ * `steps.ts` is the ordered list of every migration step; it imports each
61
+ * migration's forward/down function from the domain that owns it (memory's
62
+ * `graph/bootstrap`, apps' `app-store`, …). Migrations are append-only and
63
+ * checkpointed by stable function name, so they live in their owning feature by
64
+ * design and are merely *referenced* here by the registry — this is the
65
+ * registry's job, not a layering violation to ratchet to zero. Validated by the
66
+ * no-stale-entries test like the allowlist, so a removed migration drops its
67
+ * entry here.
68
+ */
69
+ const MIGRATION_REGISTRY_MEMORY_IMPORTS: Record<string, ReadonlySet<string>> = {
59
70
  "assistant/src/persistence/steps.ts": new Set(["graph/bootstrap"]),
60
71
  };
61
72
 
@@ -140,7 +151,10 @@ describe("persistence-layering boundary", () => {
140
151
  cwd: repoRoot,
141
152
  })) {
142
153
  const filePath = join(repoRoot, rel);
143
- const allowed = PERSISTENCE_TO_MEMORY_ALLOWLIST[rel] ?? new Set<string>();
154
+ const allowed = new Set<string>([
155
+ ...(PERSISTENCE_TO_MEMORY_ALLOWLIST[rel] ?? []),
156
+ ...(MIGRATION_REGISTRY_MEMORY_IMPORTS[rel] ?? []),
157
+ ]);
144
158
  for (const { resolvedFromRoot } of relativeImports(filePath, repoRoot)) {
145
159
  const target = stripJs(resolvedFromRoot);
146
160
  if (
@@ -178,9 +192,10 @@ describe("persistence-layering boundary", () => {
178
192
  const memoryFromRoot = relative(repoRoot, join(repoRoot, MEMORY_DIR));
179
193
  const stale: string[] = [];
180
194
 
181
- for (const [file, allowed] of Object.entries(
182
- PERSISTENCE_TO_MEMORY_ALLOWLIST,
183
- )) {
195
+ for (const [file, allowed] of [
196
+ ...Object.entries(PERSISTENCE_TO_MEMORY_ALLOWLIST),
197
+ ...Object.entries(MIGRATION_REGISTRY_MEMORY_IMPORTS),
198
+ ]) {
184
199
  const filePath = join(repoRoot, file);
185
200
  const actual = new Set<string>();
186
201
  for (const { resolvedFromRoot } of relativeImports(filePath, repoRoot)) {
@@ -106,6 +106,7 @@ const BASELINE: Record<string, readonly string[]> = {
106
106
  "../../../../daemon/conversation-notices.js",
107
107
  "../../../../daemon/conversation-registry.js",
108
108
  "../../../../daemon/conversation-runtime-assembly.js",
109
+ "../../../../daemon/embedding-reconcile.js",
109
110
  "../../../../daemon/identity-helpers.js",
110
111
  "../../../../daemon/message-protocol.js",
111
112
  "../../../../daemon/message-types/memory.js",
@@ -132,6 +133,7 @@ const BASELINE: Record<string, readonly string[]> = {
132
133
  "../../../../persistence/schema/index.js",
133
134
  "../../../../prompts/system-prompt.js",
134
135
  "../../../../providers/cache-control.js",
136
+ "../../../../providers/platform-proxy/context.js",
135
137
  "../../../../providers/provider-send-message.js",
136
138
  "../../../../providers/types.js",
137
139
  "../../../../runtime/actor-trust-resolver.js",
@@ -125,7 +125,7 @@ mock.module("../util/logger.js", () => ({
125
125
  // `handleAddSecret` fires this detached when a managed-proxy credential lands —
126
126
  // a v2-memory side effect outside this suite's provider-registry scope. Stub it
127
127
  // to a no-op; its behavior is covered by memory-v2-startup.test.ts.
128
- mock.module("../daemon/memory-v2-startup.js", () => ({
128
+ mock.module("../plugins/defaults/memory/v2/memory-v2-startup.js", () => ({
129
129
  maybeReseedCapabilitiesAfterManagedCredential: async () => {},
130
130
  }));
131
131
 
@@ -105,6 +105,7 @@ mock.module("../tools/background-tool-registry.js", () => ({
105
105
  const idx = registeredTools.findIndex((t) => t.id === id);
106
106
  if (idx !== -1) registeredTools.splice(idx, 1);
107
107
  },
108
+ recordCompletedBackgroundTool: () => {},
108
109
  generateBackgroundToolId: () => "bg-obs-test",
109
110
  isBackgroundToolLimitReached: () => false,
110
111
  MAX_BACKGROUND_TOOLS: 20,
@@ -233,103 +233,6 @@ describe("prepareAgentEnv — claude-agent-acp gating", () => {
233
233
  });
234
234
  });
235
235
 
236
- describe("prepareAgentEnv - gemini gating", () => {
237
- function seedVaultGeminiKey(key: string): void {
238
- vaultStore.set("acp/gemini_api_key", key);
239
- }
240
-
241
- test("injects GEMINI_API_KEY from the vault via the broker when agent.env has no override", async () => {
242
- seedVaultGeminiKey("vault-gem-AAA");
243
-
244
- const prepared = await prepareAgentEnv({
245
- command: "gemini",
246
- args: ["--acp"],
247
- });
248
-
249
- expect(prepared.env?.GEMINI_API_KEY).toBe("vault-gem-AAA");
250
- });
251
-
252
- test("auto-registers metadata with acp_spawn in allowedTools when none exists", async () => {
253
- seedVaultGeminiKey("vault-gem-auto-meta");
254
-
255
- await prepareAgentEnv({ command: "gemini", args: ["--acp"] });
256
-
257
- const meta = metadataStore.get("acp/gemini_api_key");
258
- expect(meta).toBeDefined();
259
- expect(meta!.allowedTools).toContain("acp_spawn");
260
- });
261
-
262
- test("a vault miss does NOT throw and spawns without GEMINI_API_KEY (key is optional)", async () => {
263
- const prepared = await prepareAgentEnv({
264
- command: "gemini",
265
- args: ["--acp"],
266
- });
267
-
268
- expect(prepared.env).not.toHaveProperty("GEMINI_API_KEY");
269
- });
270
-
271
- test("respects explicit tool policy that excludes acp_spawn without failing the spawn", async () => {
272
- metadataStore.set("acp/gemini_api_key", {
273
- allowedTools: ["other_tool"],
274
- });
275
- seedVaultGeminiKey("vault-gem-restricted");
276
-
277
- const prepared = await prepareAgentEnv({
278
- command: "gemini",
279
- args: ["--acp"],
280
- });
281
-
282
- expect(prepared.env).not.toHaveProperty("GEMINI_API_KEY");
283
- const meta = metadataStore.get("acp/gemini_api_key");
284
- expect(meta!.allowedTools).toEqual(["other_tool"]);
285
- });
286
-
287
- test("agent.env override wins over the vault entry and skips the broker (precedence pin)", async () => {
288
- // Seed a vault value but no metadata: if the override path consulted the
289
- // broker anyway, ensureAcpCredentialPolicy would create metadata here.
290
- seedVaultGeminiKey("vault-gem-CCC");
291
-
292
- const prepared = await prepareAgentEnv({
293
- command: "gemini",
294
- args: ["--acp"],
295
- env: { GEMINI_API_KEY: "config-gem-DDD" },
296
- });
297
-
298
- expect(prepared.env?.GEMINI_API_KEY).toBe("config-gem-DDD");
299
- expect(metadataStore.has("acp/gemini_api_key")).toBe(false);
300
- });
301
-
302
- test("preserves unrelated env vars on agent.env when injecting from the vault", async () => {
303
- seedVaultGeminiKey("vault-gem-EEE");
304
-
305
- const prepared = await prepareAgentEnv({
306
- command: "gemini",
307
- args: ["--acp"],
308
- env: { NO_COLOR: "1" },
309
- });
310
-
311
- expect(prepared.env?.GEMINI_API_KEY).toBe("vault-gem-EEE");
312
- expect(prepared.env?.NO_COLOR).toBe("1");
313
- });
314
-
315
- test("does NOT mutate the caller's agentConfig", async () => {
316
- seedVaultGeminiKey("vault-gem-GGG");
317
- const original = {
318
- command: "gemini",
319
- args: ["--acp"],
320
- env: { OTHER: "keep" },
321
- };
322
- const beforeEnv = { ...original.env };
323
-
324
- const prepared = await prepareAgentEnv(original);
325
-
326
- expect(prepared).not.toBe(original);
327
- expect(prepared.env).not.toBe(original.env);
328
- expect(original.env).toEqual(beforeEnv);
329
- expect(original.env).not.toHaveProperty("GEMINI_API_KEY");
330
- });
331
- });
332
-
333
236
  describe("prepareAgentEnv - codex-acp gating", () => {
334
237
  function seedVaultOpenaiKey(key: string): void {
335
238
  vaultStore.set("acp/openai_api_key", key);
@@ -16,11 +16,12 @@
16
16
  * never the untrusted task project dir. A clean cwd has no project-local
17
17
  * `node_modules/.bin`, `bunfig.toml`, or `.npmrc`, so none of the
18
18
  * cwd-based package-resolution hijacks apply.
19
- * - The installer env is a SANITIZED copy of `process.env` with
20
- * `CLAUDE_CODE_OAUTH_TOKEN` and `GEMINI_API_KEY` stripped, so the secret
21
- * is never in scope during package resolution, and `BUN_CONFIG_REGISTRY`
22
- * forced to the public npm registry so a redirected registry cannot serve
23
- * a malicious package.
19
+ * - The installer env is a SANITIZED copy of `process.env` with known
20
+ * ambient secrets (`CLAUDE_CODE_OAUTH_TOKEN`, plus the `GEMINI_API_KEY`
21
+ * used by the Gemini LLM provider) stripped, so no secret is ever in scope
22
+ * during package resolution, and `BUN_CONFIG_REGISTRY` forced to the
23
+ * public npm registry so a redirected registry cannot serve a malicious
24
+ * package.
24
25
  * - The token is injected ONLY later, at spawn time, on the real installed
25
26
  * binary (see `prepare-agent-env.ts`). `prepareAgentEnv` is never called
26
27
  * here.
@@ -99,9 +100,12 @@ function execFileWithTimeout(
99
100
  }
100
101
 
101
102
  /**
102
- * A copy of `process.env` safe to hand to the package installer: the ACP
103
- * secrets are stripped so they can never leak into a resolved package's
104
- * lifecycle/runtime, and the registry is pinned to the trusted public one.
103
+ * A copy of `process.env` safe to hand to the package installer: known
104
+ * ambient secrets are stripped so they can never leak into a resolved
105
+ * package's lifecycle/runtime, and the registry is pinned to the trusted
106
+ * public one. `CLAUDE_CODE_OAUTH_TOKEN` is the ACP adapter token;
107
+ * `GEMINI_API_KEY` belongs to the Gemini LLM provider but may be present in
108
+ * the daemon env, so it is stripped here as defense-in-depth.
105
109
  */
106
110
  function sanitizedInstallEnv(): NodeJS.ProcessEnv {
107
111
  const env: NodeJS.ProcessEnv = { ...process.env };