@vellumai/assistant 0.8.9 → 0.8.10-dev.202606092238.d04fd59

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 (147) hide show
  1. package/AGENTS.md +1 -1
  2. package/examples/plugins/echo/README.md +3 -3
  3. package/node_modules/@vellumai/skill-host-contracts/src/tool-types.ts +2 -0
  4. package/openapi.yaml +38 -12
  5. package/package.json +1 -1
  6. package/scripts/sync-llm-catalog.ts +2 -0
  7. package/src/__tests__/agent-loop-exit-reason.test.ts +19 -14
  8. package/src/__tests__/build-persisted-content.test.ts +75 -1
  9. package/src/__tests__/config-managed-gemini-defaults.test.ts +2 -46
  10. package/src/__tests__/context-overflow-reducer.test.ts +264 -124
  11. package/src/__tests__/context-window-manager-overflow-rung.test.ts +289 -0
  12. package/src/__tests__/conversation-agent-loop-overflow.test.ts +22 -22
  13. package/src/__tests__/conversation-agent-loop.test.ts +45 -37
  14. package/src/__tests__/conversation-fork-crud.test.ts +110 -0
  15. package/src/__tests__/conversation-provider-retry-repair.test.ts +16 -20
  16. package/src/__tests__/conversation-runtime-assembly.test.ts +118 -5
  17. package/src/__tests__/conversation-surfaces-app-control.test.ts +4 -1
  18. package/src/__tests__/conversation-tool-setup-app-refresh.test.ts +91 -142
  19. package/src/__tests__/conversation-tool-setup-skill-attribution.test.ts +116 -0
  20. package/src/__tests__/conversation-tool-setup-test-helpers.ts +98 -0
  21. package/src/__tests__/corrected-target.test.ts +93 -0
  22. package/src/__tests__/credential-execution-feature-gates.test.ts +3 -5
  23. package/src/__tests__/credential-security-invariants.test.ts +1 -0
  24. package/src/__tests__/embedding-managed-proxy-selection.test.ts +6 -40
  25. package/src/__tests__/external-plugin-loader.test.ts +0 -1
  26. package/src/__tests__/guardian-routing-invariants.test.ts +91 -0
  27. package/src/__tests__/history-repair-hook.test.ts +2 -0
  28. package/src/__tests__/host-app-control-proxy.test.ts +45 -0
  29. package/src/__tests__/llm-catalog-parity.test.ts +4 -0
  30. package/src/__tests__/memory-retrieval-hook.test.ts +29 -15
  31. package/src/__tests__/notification-decision-strategy.test.ts +3 -3
  32. package/src/__tests__/persistence-secret-redaction.test.ts +78 -0
  33. package/src/__tests__/plugin-bootstrap.test.ts +82 -73
  34. package/src/__tests__/plugin-tool-contribution.test.ts +7 -4
  35. package/src/__tests__/plugin-types.test.ts +0 -8
  36. package/src/__tests__/provider-catalog-visibility.test.ts +1 -9
  37. package/src/__tests__/retry-thinking-adaptive-only.test.ts +245 -0
  38. package/src/__tests__/server-history-render.test.ts +39 -0
  39. package/src/__tests__/skills.test.ts +123 -0
  40. package/src/__tests__/title-generate-hook.test.ts +2 -0
  41. package/src/__tests__/tool-audit-listener.test.ts +51 -0
  42. package/src/__tests__/tool-executor-lifecycle-events.test.ts +32 -0
  43. package/src/__tests__/tool-start-timestamp.test.ts +218 -0
  44. package/src/agent/loop.ts +26 -23
  45. package/src/api/events/tool-result.ts +9 -0
  46. package/src/api/events/tool-use-start.ts +7 -0
  47. package/src/api/responses/conversation-message.ts +91 -14
  48. package/src/approvals/guardian-request-resolvers.ts +26 -0
  49. package/src/cli/commands/channel-verification-sessions.ts +6 -6
  50. package/src/cli/commands/inference-providers.ts +0 -8
  51. package/src/cli/commands/plugins.ts +2 -2
  52. package/src/cli/lib/__tests__/install-from-github.test.ts +174 -18
  53. package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +1 -1
  54. package/src/cli/lib/__tests__/plugin-details.test.ts +1 -1
  55. package/src/cli/lib/__tests__/plugin-marketplace.test.ts +1 -1
  56. package/src/cli/lib/__tests__/search-plugins.test.ts +11 -11
  57. package/src/cli/lib/install-from-github.ts +130 -19
  58. package/src/cli/lib/plugin-catalog-cache.ts +1 -1
  59. package/src/cli/lib/plugin-details.ts +4 -4
  60. package/src/cli/lib/plugin-marketplace.ts +2 -2
  61. package/src/cli/lib/search-plugins.ts +6 -6
  62. package/src/config/bundled-skills/skill-management/SKILL.md +89 -1
  63. package/src/config/env-registry.ts +12 -0
  64. package/src/config/feature-flag-registry.json +0 -80
  65. package/src/config/loader.ts +5 -22
  66. package/src/config/seed-inference-profiles.ts +1 -1
  67. package/src/config/skills.ts +101 -47
  68. package/src/context/strip-injections.ts +7 -4
  69. package/src/daemon/conversation-agent-loop-handlers.ts +102 -6
  70. package/src/daemon/conversation-agent-loop.ts +134 -232
  71. package/src/daemon/conversation-runtime-assembly.ts +44 -8
  72. package/src/daemon/conversation-tool-setup.ts +9 -1
  73. package/src/daemon/external-plugins-bootstrap.ts +33 -87
  74. package/src/daemon/handlers/config-channels.ts +11 -2
  75. package/src/daemon/handlers/shared.ts +9 -1
  76. package/src/daemon/handlers/skills.ts +6 -2
  77. package/src/daemon/host-app-control-proxy.ts +72 -57
  78. package/src/daemon/message-protocol.ts +0 -7
  79. package/src/daemon/message-types/skills.ts +4 -0
  80. package/src/events/tool-audit-listener.ts +7 -1
  81. package/src/memory/__tests__/tool-invocation-test-helpers.ts +69 -0
  82. package/src/memory/conversation-crud.ts +44 -1
  83. package/src/memory/db-init.ts +4 -0
  84. package/src/memory/embedding-backend.ts +5 -22
  85. package/src/memory/memory-retrospective-startup-cleanup.ts +1 -1
  86. package/src/memory/migrations/275-tool-invocations-add-skill-id.test.ts +81 -0
  87. package/src/memory/migrations/275-tool-invocations-add-skill-id.ts +20 -0
  88. package/src/memory/migrations/276-tool-invocations-created-at-id-index.test.ts +68 -0
  89. package/src/memory/migrations/276-tool-invocations-created-at-id-index.ts +20 -0
  90. package/src/memory/migrations/index.ts +2 -0
  91. package/src/memory/schema/conversations.ts +3 -0
  92. package/src/memory/tool-execution-events-store.test.ts +162 -0
  93. package/src/memory/tool-execution-events-store.ts +73 -0
  94. package/src/memory/tool-usage-store.ts +4 -3
  95. package/src/memory/v2/__tests__/injected-block-slugs.test.ts +51 -0
  96. package/src/memory/v2/activation-store.ts +50 -1
  97. package/src/memory/v2/injected-block-slugs.ts +30 -0
  98. package/src/notifications/__tests__/copy-composer.test.ts +244 -0
  99. package/src/notifications/access-request-copy.ts +298 -0
  100. package/src/notifications/adapters/slack.ts +3 -3
  101. package/src/notifications/adapters/telegram.ts +2 -1
  102. package/src/notifications/copy-composer.ts +49 -267
  103. package/src/notifications/decision-engine.ts +16 -35
  104. package/src/notifications/home-feed-side-effect.ts +1 -6
  105. package/src/platform/client.ts +1 -3
  106. package/src/platform/feature-gate.ts +3 -12
  107. package/src/plugin-api/constants.ts +2 -0
  108. package/src/plugin-api/index.ts +34 -6
  109. package/src/plugin-api/types.ts +19 -0
  110. package/src/plugins/defaults/compaction/compact.ts +39 -1
  111. package/src/plugins/defaults/compaction/context-overflow-reducer.ts +240 -32
  112. package/src/plugins/defaults/compaction/corrected-target.ts +53 -0
  113. package/src/plugins/defaults/compaction/window-manager.ts +136 -0
  114. package/src/plugins/defaults/index.ts +24 -0
  115. package/src/plugins/defaults/memory-retrieval/hooks/post-compact.ts +68 -43
  116. package/src/plugins/defaults/memory-retrieval/hooks/{user-prompt-submit-temp.ts → user-prompt-submit.ts} +36 -67
  117. package/src/plugins/defaults/memory-retrieval/package.json +14 -0
  118. package/src/plugins/external-api.ts +1 -1
  119. package/src/plugins/types.ts +5 -51
  120. package/src/providers/inference/__tests__/base-url-route-validation.test.ts +1 -2
  121. package/src/providers/model-catalog.ts +57 -1
  122. package/src/providers/registry.ts +0 -8
  123. package/src/providers/retry.ts +35 -7
  124. package/src/runtime/routes/__tests__/acp-routes.test.ts +151 -0
  125. package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +0 -62
  126. package/src/runtime/routes/__tests__/plugins-routes.test.ts +4 -4
  127. package/src/runtime/routes/acp-routes.test.ts +106 -0
  128. package/src/runtime/routes/acp-routes.ts +248 -2
  129. package/src/runtime/routes/browser-tabs-routes.ts +1 -1
  130. package/src/runtime/routes/channel-verification-routes.ts +14 -5
  131. package/src/runtime/routes/chatgpt-subscription-auth-routes.ts +0 -14
  132. package/src/runtime/routes/inbound-stages/acl-enforcement.ts +33 -34
  133. package/src/runtime/routes/inference-provider-connection-routes.ts +0 -45
  134. package/src/runtime/routes/plugins-routes.ts +3 -3
  135. package/src/runtime/verification-outbound-actions.ts +147 -2
  136. package/src/runtime/verification-templates.ts +29 -3
  137. package/src/telemetry/types.ts +25 -1
  138. package/src/telemetry/usage-telemetry-reporter.test.ts +141 -7
  139. package/src/telemetry/usage-telemetry-reporter.ts +63 -7
  140. package/src/tools/executor.ts +4 -1
  141. package/src/tools/skills/load.ts +11 -6
  142. package/src/tools/terminal/safe-env.ts +1 -0
  143. package/src/tools/types.ts +10 -0
  144. package/src/__tests__/plugin-skill-contribution.test.ts +0 -355
  145. package/src/daemon/message-types/browser.ts +0 -10
  146. package/src/notifications/__tests__/emit-signal-home-feed.test.ts +0 -187
  147. package/src/plugins/plugin-skill-contributions.ts +0 -292
@@ -75,6 +75,7 @@ const steerOrResumeMock = mock(
75
75
  mock.module("../../../acp/index.js", () => ({
76
76
  getAcpSessionManager: () => ({
77
77
  getStatus: () => fakeInMemorySessions,
78
+ getActiveAndPendingIds: () => fakeInMemorySessions.map((s) => s.id),
78
79
  spawn: spawnMock,
79
80
  steerOrResume: steerOrResumeMock,
80
81
  }),
@@ -86,6 +87,34 @@ mock.module("../../../acp/prepare-agent-env.js", () => ({
86
87
  prepareAgentEnv: async (agentConfig: unknown) => agentConfig,
87
88
  }));
88
89
 
90
+ // The spawn route and steer's resume branch gate on a high-risk approval
91
+ // (ATL-822) before starting the host agent. These tests pin the
92
+ // resolve/install/resume flow, so the hub mock auto-resolves the freshly
93
+ // registered confirmation the same way `POST /v1/confirm` would (resolve +
94
+ // directResolve). `approvalBehavior` flips allow/deny; `confirmationRequests`
95
+ // captures the prompts. Other event types are ignored.
96
+ import * as pendingInteractions from "../../../runtime/pending-interactions.js";
97
+
98
+ let approvalBehavior: "allow" | "deny" = "allow";
99
+ const confirmationRequests: Array<Record<string, unknown>> = [];
100
+ const broadcasts: Array<Record<string, unknown>> = [];
101
+
102
+ mock.module("../../../runtime/assistant-event-hub.js", () => ({
103
+ broadcastMessage: (msg: { type?: string; requestId?: string }) => {
104
+ broadcasts.push(msg as Record<string, unknown>);
105
+ if (msg?.type !== "confirmation_request") return;
106
+ confirmationRequests.push(msg as Record<string, unknown>);
107
+ const interaction = pendingInteractions.resolve(
108
+ msg.requestId as string,
109
+ approvalBehavior === "allow" ? "approved" : "rejected",
110
+ );
111
+ interaction?.directResolve?.(approvalBehavior);
112
+ },
113
+ }));
114
+
115
+ /** Drain pending micro/macrotasks so background resume work settles. */
116
+ const flushAsync = () => new Promise((resolve) => setTimeout(resolve, 0));
117
+
89
118
  const config = await installAcpConfigStub();
90
119
  const which = installWhichStub();
91
120
 
@@ -143,6 +172,9 @@ beforeEach(() => {
143
172
  _resetAdapterInstallCacheForTests();
144
173
  config.setConfig({});
145
174
  which.setWhich((cmd) => `/usr/local/bin/${cmd}`);
175
+ approvalBehavior = "allow";
176
+ confirmationRequests.length = 0;
177
+ broadcasts.length = 0;
146
178
  });
147
179
 
148
180
  describe("GET /v1/acp/sessions — merged in-memory + history", () => {
@@ -652,3 +684,122 @@ describe("POST /v1/acp/:id/steer: resume fallback", () => {
652
684
  await expect(promise).rejects.toBeInstanceOf(NotFoundError);
653
685
  });
654
686
  });
687
+
688
+ // ---------------------------------------------------------------------------
689
+ // POST /v1/acp/:id/steer: resume crosses the host-spawn boundary, so it is
690
+ // gated by the same high-risk guardian approval as spawn (ATL-822). Steering
691
+ // a session still active in memory only redirects an already-approved live
692
+ // process and is NOT prompted.
693
+ // ---------------------------------------------------------------------------
694
+
695
+ describe("POST /v1/acp/:id/steer: resume approval gate", () => {
696
+ test("acks immediately with approvalPending, then resumes once granted", async () => {
697
+ insertHistoryRow({
698
+ id: "gone-1",
699
+ agentId: "claude",
700
+ parentConversationId: "conv-z",
701
+ status: "completed",
702
+ cwd: "/work/repo",
703
+ });
704
+ steerOrResumeImpl = async () => ({ resumed: true });
705
+
706
+ const handler = getSteerHandler();
707
+ // The ack returns before the (async) resume completes, so a slow guardian
708
+ // approval can't trip the client's short ack timeout (ATL-822 / Codex P2).
709
+ const body = await handler({
710
+ pathParams: { id: "gone-1" },
711
+ body: { instruction: "keep going" },
712
+ });
713
+ expect(body).toEqual({
714
+ acpSessionId: "gone-1",
715
+ steered: false,
716
+ approvalPending: true,
717
+ });
718
+
719
+ // The high-risk prompt is surfaced for the resume.
720
+ expect(confirmationRequests).toHaveLength(1);
721
+ const prompt = confirmationRequests[0];
722
+ expect(prompt.toolName).toBe("acp_steer");
723
+ expect(prompt.riskLevel).toBe("high");
724
+ expect(prompt.executionTarget).toBe("host");
725
+ expect(prompt.conversationId).toBe("conv-z");
726
+ expect((prompt.input as { cwd?: string }).cwd).toBe("/work/repo");
727
+
728
+ // After approval settles, the background worker performs the resume.
729
+ await flushAsync();
730
+ expect(steerOrResumeMock).toHaveBeenCalledTimes(1);
731
+ expect(steerOrResumeMock.mock.calls[0][0]).toBe("gone-1");
732
+ });
733
+
734
+ test("denied resume never reaches the session manager and reports an error event", async () => {
735
+ approvalBehavior = "deny";
736
+ insertHistoryRow({
737
+ id: "gone-2",
738
+ acpSessionId: "proto-gone-2",
739
+ parentConversationId: "conv-z",
740
+ status: "completed",
741
+ cwd: "/work/repo",
742
+ });
743
+
744
+ const handler = getSteerHandler();
745
+ const body = await handler({
746
+ pathParams: { id: "gone-2" },
747
+ body: { instruction: "do evil" },
748
+ });
749
+ expect(body).toEqual({
750
+ acpSessionId: "gone-2",
751
+ steered: false,
752
+ approvalPending: true,
753
+ });
754
+
755
+ await flushAsync();
756
+ // Denied before any host re-spawn, and the denial surfaces over SSE.
757
+ expect(steerOrResumeMock).not.toHaveBeenCalled();
758
+ expect(pendingInteractions.getAll()).toHaveLength(0);
759
+ // Keyed by the daemon/route id (what SSE consumers index by), not the
760
+ // persisted protocol id.
761
+ const errEvent = broadcasts.find((m) => m.type === "acp_session_error");
762
+ expect(errEvent?.acpSessionId).toBe("gone-2");
763
+ });
764
+
765
+ test("a legacy row without a persisted cwd is not resumable, so no prompt", async () => {
766
+ insertHistoryRow({ id: "legacy-2", status: "completed", cwd: null });
767
+ steerOrResumeImpl = async (id) => {
768
+ throw new AcpResumeError(
769
+ new Error(`ACP session "${id}" cannot be resumed.`),
770
+ );
771
+ };
772
+
773
+ const handler = getSteerHandler();
774
+ await expect(
775
+ handler({ pathParams: { id: "legacy-2" }, body: { instruction: "go" } }),
776
+ ).rejects.toBeInstanceOf(FailedDependencyError);
777
+ // No spawn would occur, so the gate stays out of the way.
778
+ expect(confirmationRequests).toHaveLength(0);
779
+ });
780
+
781
+ test("steering a session active in memory is not prompted", async () => {
782
+ fakeInMemorySessions = [
783
+ {
784
+ id: "live-2",
785
+ agentId: "claude",
786
+ acpSessionId: "proto-live-2",
787
+ parentConversationId: "conv-1",
788
+ status: "running",
789
+ startedAt: 1000,
790
+ },
791
+ ];
792
+ // A resumable row also exists, but the in-memory session wins → steer.
793
+ insertHistoryRow({ id: "live-2", status: "completed", cwd: "/work/repo" });
794
+
795
+ const handler = getSteerHandler();
796
+ const body = await handler({
797
+ pathParams: { id: "live-2" },
798
+ body: { instruction: "redirect" },
799
+ });
800
+
801
+ expect(confirmationRequests).toHaveLength(0);
802
+ expect(body).toEqual({ acpSessionId: "live-2", steered: true });
803
+ expect(steerOrResumeMock).toHaveBeenCalledTimes(1);
804
+ });
805
+ });
@@ -29,7 +29,6 @@ mock.module("../../../util/logger.js", () => ({
29
29
 
30
30
  // ── Real imports (after mocks) ────────────────────────────────────────────────
31
31
 
32
- import { setOverridesForTesting } from "../../../__tests__/feature-flag-test-helpers.js";
33
32
  import { getDb } from "../../../memory/db-connection.js";
34
33
  import { initializeDb } from "../../../memory/db-init.js";
35
34
  import { providerConnections } from "../../../memory/schema/inference.js";
@@ -91,7 +90,6 @@ function seedConnection(opts: {
91
90
  beforeEach(() => {
92
91
  clearConnections();
93
92
  fakeConfig = {};
94
- setOverridesForTesting({ "openai-compatible-endpoints": true });
95
93
  });
96
94
 
97
95
  // ── GET list ─────────────────────────────────────────────────────────────────
@@ -160,36 +158,6 @@ describe("GET inference/provider-connections (list)", () => {
160
158
  expect(result.connections).toEqual([]);
161
159
  });
162
160
 
163
- test("hides openai-compatible rows when the feature flag is disabled", async () => {
164
- setOverridesForTesting({ "openai-compatible-endpoints": false });
165
- seedConnection({
166
- name: "my-openai",
167
- provider: "openai",
168
- auth: { type: "platform" },
169
- });
170
- seedConnection({
171
- name: "my-compatible",
172
- provider: "openai-compatible",
173
- auth: { type: "api_key", credential: "ref/k" },
174
- });
175
-
176
- const result = (await call(
177
- findHandler("inference_provider_connections_list"),
178
- {},
179
- )) as { connections: Array<{ name: string }> };
180
-
181
- expect(result.connections.map((c) => c.name)).toEqual(["my-openai"]);
182
- });
183
-
184
- test("rejects openai-compatible provider filter when the feature flag is disabled", async () => {
185
- setOverridesForTesting({ "openai-compatible-endpoints": false });
186
-
187
- await expect(
188
- call(findHandler("inference_provider_connections_list"), {
189
- queryParams: { provider: "openai-compatible" },
190
- }),
191
- ).rejects.toBeInstanceOf(BadRequestError);
192
- });
193
161
  });
194
162
 
195
163
  // ── GET single ────────────────────────────────────────────────────────────────
@@ -219,20 +187,6 @@ describe("GET inference/provider-connections/:name (single)", () => {
219
187
  ).rejects.toBeInstanceOf(NotFoundError);
220
188
  });
221
189
 
222
- test("throws 404 for openai-compatible row when the feature flag is disabled", async () => {
223
- setOverridesForTesting({ "openai-compatible-endpoints": false });
224
- seedConnection({
225
- name: "my-compatible",
226
- provider: "openai-compatible",
227
- auth: { type: "api_key", credential: "ref/k" },
228
- });
229
-
230
- await expect(
231
- call(findHandler("inference_provider_connections_get"), {
232
- pathParams: { name: "my-compatible" },
233
- }),
234
- ).rejects.toBeInstanceOf(NotFoundError);
235
- });
236
190
  });
237
191
 
238
192
  // ── POST create ───────────────────────────────────────────────────────────────
@@ -317,22 +271,6 @@ describe("POST inference/provider-connections (create)", () => {
317
271
  ).rejects.toBeInstanceOf(BadRequestError);
318
272
  });
319
273
 
320
- test("rejects openai-compatible creation when the feature flag is disabled", async () => {
321
- setOverridesForTesting({ "openai-compatible-endpoints": false });
322
-
323
- await expect(
324
- call(findHandler("inference_provider_connections_create"), {
325
- body: {
326
- name: "my-compatible",
327
- provider: "openai-compatible",
328
- auth: { type: "api_key", credential: "ref/k" },
329
- base_url: "http://localhost:8080/v1",
330
- models: [{ id: "local-model" }],
331
- },
332
- }),
333
- ).rejects.toBeInstanceOf(BadRequestError);
334
- });
335
-
336
274
  test("throws 400 when auth schema is invalid (api_key without credential)", async () => {
337
275
  await expect(
338
276
  call(findHandler("inference_provider_connections_create"), {
@@ -369,7 +369,7 @@ describe("GET /v1/plugins/search", () => {
369
369
  catalog(ref, [
370
370
  {
371
371
  name: "simple-memory",
372
- path: "experimental/plugins/simple-memory",
372
+ path: "plugins/simple-memory",
373
373
  source: { kind: "first-party" },
374
374
  },
375
375
  {
@@ -402,7 +402,7 @@ describe("GET /v1/plugins/search", () => {
402
402
  matches: [
403
403
  {
404
404
  name: "simple-memory",
405
- path: "experimental/plugins/simple-memory",
405
+ path: "plugins/simple-memory",
406
406
  source: { kind: "first-party" },
407
407
  },
408
408
  ],
@@ -458,7 +458,7 @@ describe("GET /v1/plugins/search", () => {
458
458
  test("PluginCatalogUnavailableError → ServiceUnavailableError (503)", async () => {
459
459
  getCatalogSpy.mockImplementation(async () => {
460
460
  throw new PluginCatalogUnavailableError(
461
- "GitHub contents listing failed for experimental/plugins @ main: HTTP 403",
461
+ "GitHub contents listing failed for plugins @ main: HTTP 403",
462
462
  403,
463
463
  );
464
464
  });
@@ -489,7 +489,7 @@ describe("GET /v1/plugins/search", () => {
489
489
  const frozenMatches = Object.freeze([
490
490
  Object.freeze({
491
491
  name: "a",
492
- path: "experimental/plugins/a",
492
+ path: "plugins/a",
493
493
  source: { kind: "first-party" } as const,
494
494
  }),
495
495
  ]) as readonly PluginSearchMatch[];
@@ -39,6 +39,7 @@ import {
39
39
  import { installAcpConfigStub } from "../../acp/__tests__/helpers/acp-config-stub.js";
40
40
  import { installWhichStub } from "../../acp/__tests__/helpers/which-stub.js";
41
41
  import type { AcpSessionState } from "../../acp/index.js";
42
+ import * as pendingInteractions from "../pending-interactions.js";
42
43
 
43
44
  const config = await installAcpConfigStub();
44
45
  const which = installWhichStub();
@@ -170,6 +171,31 @@ mock.module("../../tools/credentials/broker.js", () => ({
170
171
  },
171
172
  }));
172
173
 
174
+ // Drive the spawn route's high-risk approval gate (ATL-822). `spawnSession`
175
+ // registers a `directResolve` confirmation in `pendingInteractions` and then
176
+ // broadcasts a `confirmation_request`. Real broadcasting needs the event hub /
177
+ // SSE wiring, so the mock auto-resolves the freshly registered interaction
178
+ // the same way `POST /v1/confirm` would (resolve + directResolve). Tests flip
179
+ // `approvalBehavior` to exercise allow / deny, and read `confirmationRequests`
180
+ // to assert the prompt's risk shape. `interaction_resolved` and other event
181
+ // types are ignored.
182
+ type ApprovalBehavior = "allow" | "deny";
183
+ let approvalBehavior: ApprovalBehavior = "allow";
184
+ const confirmationRequests: Array<Record<string, unknown>> = [];
185
+
186
+ mock.module("../../runtime/assistant-event-hub.js", () => ({
187
+ broadcastMessage: (msg: { type?: string; requestId?: string }) => {
188
+ if (msg?.type !== "confirmation_request") return;
189
+ confirmationRequests.push(msg as Record<string, unknown>);
190
+ const decision = approvalBehavior;
191
+ const interaction = pendingInteractions.resolve(
192
+ msg.requestId as string,
193
+ decision === "allow" ? "approved" : "rejected",
194
+ );
195
+ interaction?.directResolve?.(decision);
196
+ },
197
+ }));
198
+
173
199
  import { eq } from "drizzle-orm";
174
200
 
175
201
  import { getDb, getSqlite } from "../../memory/db-connection.js";
@@ -193,6 +219,8 @@ beforeEach(() => {
193
219
  capturedSpawns.length = 0;
194
220
  vaultStore.clear();
195
221
  metadataStore.clear();
222
+ approvalBehavior = "allow";
223
+ confirmationRequests.length = 0;
196
224
  });
197
225
 
198
226
  // ---------------------------------------------------------------------------
@@ -224,6 +252,84 @@ describe("POST /v1/acp/spawn", () => {
224
252
  await expect(handler({ body: { agent: "claude" } })).rejects.toThrow(
225
253
  "agent, task, and conversationId are required",
226
254
  );
255
+ // Guard runs before the approval gate — no prompt is surfaced.
256
+ expect(confirmationRequests).toHaveLength(0);
257
+ });
258
+ });
259
+
260
+ // ---------------------------------------------------------------------------
261
+ // POST /v1/acp/spawn — high-risk approval gate (ATL-822)
262
+ //
263
+ // Spawning an ACP agent is a host subprocess with auto-allowed
264
+ // filesystem/terminal access. The skill-tool path gets the descriptor's
265
+ // `risk: "high"` prompt via ToolExecutor; this route reaches the session
266
+ // manager directly, so it surfaces the same confirmation itself and refuses
267
+ // to spawn unless a guardian approves.
268
+ // ---------------------------------------------------------------------------
269
+
270
+ describe("POST /v1/acp/spawn — approval gate", () => {
271
+ test("surfaces a high-risk host confirmation before spawning", async () => {
272
+ seedVaultToken("test-token-abc123");
273
+
274
+ const handler = getSpawnHandler();
275
+ await handler({
276
+ body: {
277
+ agent: "claude",
278
+ task: "do a thing",
279
+ conversationId: "conv-1",
280
+ cwd: "/work/repo",
281
+ },
282
+ });
283
+
284
+ expect(confirmationRequests).toHaveLength(1);
285
+ const prompt = confirmationRequests[0];
286
+ expect(prompt.toolName).toBe("acp_spawn");
287
+ expect(prompt.riskLevel).toBe("high");
288
+ expect(prompt.executionTarget).toBe("host");
289
+ expect(prompt.conversationId).toBe("conv-1");
290
+ expect((prompt.input as { cwd?: string }).cwd).toBe("/work/repo");
291
+ // Prompt resolved "allow" → spawn proceeds.
292
+ expect(capturedSpawns).toHaveLength(1);
293
+ });
294
+
295
+ test("throws ForbiddenError and does not spawn when the guardian denies", async () => {
296
+ approvalBehavior = "deny";
297
+ seedVaultToken("test-token-abc123");
298
+
299
+ const handler = getSpawnHandler();
300
+ await expect(
301
+ handler({
302
+ body: {
303
+ agent: "claude",
304
+ task: "do a thing",
305
+ conversationId: "conv-1",
306
+ },
307
+ }),
308
+ ).rejects.toThrow(/guardian approval/i);
309
+
310
+ // Denied before any host side effects: no subprocess, no pending leak.
311
+ expect(capturedSpawns).toHaveLength(0);
312
+ expect(pendingInteractions.getAll()).toHaveLength(0);
313
+ });
314
+
315
+ test("denies (and does not spawn) when the client disconnects before approval", async () => {
316
+ seedVaultToken("test-token-abc123");
317
+ const controller = new AbortController();
318
+ controller.abort();
319
+
320
+ const handler = getSpawnHandler();
321
+ await expect(
322
+ handler({
323
+ body: {
324
+ agent: "claude",
325
+ task: "do a thing",
326
+ conversationId: "conv-1",
327
+ },
328
+ abortSignal: controller.signal,
329
+ }),
330
+ ).rejects.toThrow(/guardian approval/i);
331
+
332
+ expect(capturedSpawns).toHaveLength(0);
227
333
  });
228
334
  });
229
335