@vellumai/assistant 0.8.9 → 0.8.10-dev.202606092334.09948c8
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.
- package/AGENTS.md +1 -1
- package/examples/plugins/echo/README.md +3 -3
- package/node_modules/@vellumai/skill-host-contracts/src/tool-types.ts +2 -0
- package/openapi.yaml +38 -12
- package/package.json +1 -1
- package/scripts/sync-llm-catalog.ts +2 -0
- package/src/__tests__/agent-loop-exit-reason.test.ts +21 -15
- package/src/__tests__/approval-cascade.test.ts +1 -0
- package/src/__tests__/build-persisted-content.test.ts +75 -1
- package/src/__tests__/compaction-events.test.ts +1 -0
- package/src/__tests__/config-managed-gemini-defaults.test.ts +2 -46
- package/src/__tests__/context-overflow-reducer.test.ts +264 -124
- package/src/__tests__/context-window-manager-overflow-rung.test.ts +351 -0
- package/src/__tests__/conversation-abort-tool-results.test.ts +1 -0
- package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +11 -0
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +90 -49
- package/src/__tests__/conversation-agent-loop.test.ts +113 -64
- package/src/__tests__/conversation-confirmation-signals.test.ts +1 -0
- package/src/__tests__/conversation-fork-crud.test.ts +110 -0
- package/src/__tests__/conversation-process-callsite.test.ts +1 -0
- package/src/__tests__/conversation-provider-retry-repair.test.ts +48 -48
- package/src/__tests__/conversation-queue.test.ts +1 -0
- package/src/__tests__/conversation-runtime-assembly.test.ts +119 -8
- package/src/__tests__/conversation-slash-queue.test.ts +1 -0
- package/src/__tests__/conversation-slash-unknown.test.ts +1 -0
- package/src/__tests__/conversation-speed-override.test.ts +1 -0
- package/src/__tests__/conversation-surfaces-app-control.test.ts +4 -1
- package/src/__tests__/conversation-tool-setup-app-refresh.test.ts +91 -142
- package/src/__tests__/conversation-tool-setup-skill-attribution.test.ts +116 -0
- package/src/__tests__/conversation-tool-setup-test-helpers.ts +98 -0
- package/src/__tests__/conversation-workspace-cache-state.test.ts +1 -0
- package/src/__tests__/conversation-workspace-injection.test.ts +1 -0
- package/src/__tests__/conversation-workspace-tool-tracking.test.ts +1 -0
- package/src/__tests__/corrected-target.test.ts +93 -0
- package/src/__tests__/credential-execution-feature-gates.test.ts +3 -5
- package/src/__tests__/credential-security-invariants.test.ts +1 -0
- package/src/__tests__/embedding-managed-proxy-selection.test.ts +6 -40
- package/src/__tests__/external-plugin-loader.test.ts +0 -1
- package/src/__tests__/guardian-routing-invariants.test.ts +91 -0
- package/src/__tests__/history-repair-hook.test.ts +2 -0
- package/src/__tests__/host-app-control-proxy.test.ts +45 -0
- package/src/__tests__/llm-catalog-parity.test.ts +4 -0
- package/src/__tests__/memory-retrieval-hook.test.ts +29 -15
- package/src/__tests__/notification-decision-strategy.test.ts +3 -3
- package/src/__tests__/persistence-secret-redaction.test.ts +78 -0
- package/src/__tests__/plugin-bootstrap.test.ts +82 -73
- package/src/__tests__/plugin-tool-contribution.test.ts +7 -4
- package/src/__tests__/plugin-types.test.ts +0 -8
- package/src/__tests__/provider-catalog-visibility.test.ts +1 -9
- package/src/__tests__/retry-thinking-adaptive-only.test.ts +245 -0
- package/src/__tests__/server-history-render.test.ts +39 -0
- package/src/__tests__/skills.test.ts +123 -0
- package/src/__tests__/title-generate-hook.test.ts +2 -0
- package/src/__tests__/tool-audit-listener.test.ts +51 -0
- package/src/__tests__/tool-executor-lifecycle-events.test.ts +32 -0
- package/src/__tests__/tool-start-timestamp.test.ts +218 -0
- package/src/agent/loop.ts +26 -39
- package/src/api/events/tool-result.ts +9 -0
- package/src/api/events/tool-use-start.ts +7 -0
- package/src/api/responses/conversation-message.ts +91 -14
- package/src/approvals/guardian-request-resolvers.ts +26 -0
- package/src/cli/commands/channel-verification-sessions.ts +6 -6
- package/src/cli/commands/inference-providers.ts +0 -8
- package/src/cli/commands/plugins.ts +2 -2
- package/src/cli/lib/__tests__/install-from-github.test.ts +174 -18
- package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +1 -1
- package/src/cli/lib/__tests__/plugin-details.test.ts +1 -1
- package/src/cli/lib/__tests__/plugin-marketplace.test.ts +1 -1
- package/src/cli/lib/__tests__/search-plugins.test.ts +11 -11
- package/src/cli/lib/install-from-github.ts +130 -19
- package/src/cli/lib/plugin-catalog-cache.ts +1 -1
- package/src/cli/lib/plugin-details.ts +4 -4
- package/src/cli/lib/plugin-marketplace.ts +2 -2
- package/src/cli/lib/search-plugins.ts +6 -6
- package/src/config/bundled-skills/skill-management/SKILL.md +89 -1
- package/src/config/env-registry.ts +12 -0
- package/src/config/feature-flag-registry.json +0 -80
- package/src/config/loader.ts +5 -22
- package/src/config/seed-inference-profiles.ts +1 -1
- package/src/config/skills.ts +101 -47
- package/src/context/strip-injections.ts +7 -4
- package/src/daemon/conversation-agent-loop-handlers.ts +102 -6
- package/src/daemon/conversation-agent-loop.ts +126 -270
- package/src/daemon/conversation-runtime-assembly.ts +44 -8
- package/src/daemon/conversation-tool-setup.ts +9 -1
- package/src/daemon/conversation.ts +13 -0
- package/src/daemon/external-plugins-bootstrap.ts +33 -87
- package/src/daemon/handlers/config-channels.ts +11 -2
- package/src/daemon/handlers/shared.ts +9 -1
- package/src/daemon/handlers/skills.ts +6 -2
- package/src/daemon/host-app-control-proxy.ts +72 -57
- package/src/daemon/message-protocol.ts +0 -7
- package/src/daemon/message-types/skills.ts +4 -0
- package/src/events/tool-audit-listener.ts +7 -1
- package/src/memory/__tests__/tool-invocation-test-helpers.ts +69 -0
- package/src/memory/conversation-crud.ts +44 -1
- package/src/memory/db-init.ts +4 -0
- package/src/memory/embedding-backend.ts +5 -22
- package/src/memory/memory-retrospective-startup-cleanup.ts +1 -1
- package/src/memory/migrations/275-tool-invocations-add-skill-id.test.ts +81 -0
- package/src/memory/migrations/275-tool-invocations-add-skill-id.ts +20 -0
- package/src/memory/migrations/276-tool-invocations-created-at-id-index.test.ts +68 -0
- package/src/memory/migrations/276-tool-invocations-created-at-id-index.ts +20 -0
- package/src/memory/migrations/index.ts +2 -0
- package/src/memory/schema/conversations.ts +3 -0
- package/src/memory/tool-execution-events-store.test.ts +162 -0
- package/src/memory/tool-execution-events-store.ts +73 -0
- package/src/memory/tool-usage-store.ts +4 -3
- package/src/memory/v2/__tests__/injected-block-slugs.test.ts +51 -0
- package/src/memory/v2/activation-store.ts +50 -1
- package/src/memory/v2/injected-block-slugs.ts +30 -0
- package/src/notifications/__tests__/copy-composer.test.ts +244 -0
- package/src/notifications/access-request-copy.ts +298 -0
- package/src/notifications/adapters/slack.ts +3 -3
- package/src/notifications/adapters/telegram.ts +2 -1
- package/src/notifications/copy-composer.ts +49 -267
- package/src/notifications/decision-engine.ts +16 -35
- package/src/notifications/home-feed-side-effect.ts +1 -6
- package/src/platform/client.ts +1 -3
- package/src/platform/feature-gate.ts +3 -12
- package/src/plugin-api/constants.ts +2 -0
- package/src/plugin-api/index.ts +37 -6
- package/src/plugin-api/types.ts +75 -0
- package/src/plugins/defaults/compaction/compact.ts +39 -1
- package/src/plugins/defaults/compaction/context-overflow-reducer.ts +240 -32
- package/src/plugins/defaults/compaction/corrected-target.ts +53 -0
- package/src/plugins/defaults/compaction/window-manager.ts +195 -1
- package/src/plugins/defaults/index.ts +24 -0
- package/src/plugins/defaults/memory-retrieval/hooks/post-compact.ts +76 -112
- package/src/plugins/defaults/memory-retrieval/hooks/{user-prompt-submit-temp.ts → user-prompt-submit.ts} +36 -67
- package/src/plugins/defaults/memory-retrieval/package.json +14 -0
- package/src/plugins/external-api.ts +1 -1
- package/src/plugins/types.ts +5 -51
- package/src/providers/inference/__tests__/base-url-route-validation.test.ts +1 -2
- package/src/providers/model-catalog.ts +57 -1
- package/src/providers/registry.ts +0 -8
- package/src/providers/retry.ts +35 -7
- package/src/runtime/routes/__tests__/acp-routes.test.ts +151 -0
- package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +0 -62
- package/src/runtime/routes/__tests__/plugins-routes.test.ts +4 -4
- package/src/runtime/routes/acp-routes.test.ts +106 -0
- package/src/runtime/routes/acp-routes.ts +248 -2
- package/src/runtime/routes/browser-tabs-routes.ts +1 -1
- package/src/runtime/routes/channel-verification-routes.ts +14 -5
- package/src/runtime/routes/chatgpt-subscription-auth-routes.ts +0 -14
- package/src/runtime/routes/inbound-stages/acl-enforcement.ts +33 -34
- package/src/runtime/routes/inference-provider-connection-routes.ts +0 -45
- package/src/runtime/routes/plugins-routes.ts +3 -3
- package/src/runtime/verification-outbound-actions.ts +147 -2
- package/src/runtime/verification-templates.ts +29 -3
- package/src/telemetry/types.ts +25 -1
- package/src/telemetry/usage-telemetry-reporter.test.ts +141 -7
- package/src/telemetry/usage-telemetry-reporter.ts +63 -7
- package/src/tools/executor.ts +4 -1
- package/src/tools/skills/load.ts +11 -6
- package/src/tools/terminal/safe-env.ts +1 -0
- package/src/tools/types.ts +10 -0
- package/src/__tests__/plugin-skill-contribution.test.ts +0 -355
- package/src/daemon/message-types/browser.ts +0 -10
- package/src/notifications/__tests__/emit-signal-home-feed.test.ts +0 -187
- package/src/plugins/plugin-skill-contributions.ts +0 -292
|
@@ -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: "
|
|
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: "
|
|
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
|
|
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: "
|
|
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
|
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Exposes spawn, steer, cancel, close, sessions, and permission operations
|
|
5
5
|
* over HTTP and IPC.
|
|
6
6
|
*/
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
|
+
|
|
7
9
|
import { and, desc, eq, inArray, notInArray } from "drizzle-orm";
|
|
8
10
|
import { z } from "zod";
|
|
9
11
|
|
|
@@ -13,16 +15,20 @@ import { prepareAgentEnv } from "../../acp/prepare-agent-env.js";
|
|
|
13
15
|
import { formatResolveFailure } from "../../acp/resolve-agent.js";
|
|
14
16
|
import { AcpResumeError } from "../../acp/session-manager.js";
|
|
15
17
|
import type { AcpSessionState } from "../../acp/types.js";
|
|
18
|
+
import { getConfig } from "../../config/loader.js";
|
|
16
19
|
import { getDb } from "../../memory/db-connection.js";
|
|
17
20
|
import { rawChanges } from "../../memory/raw-query.js";
|
|
18
21
|
import { acpSessionHistory } from "../../memory/schema.js";
|
|
22
|
+
import type { UserDecision } from "../../permissions/types.js";
|
|
19
23
|
import { broadcastMessage } from "../../runtime/assistant-event-hub.js";
|
|
20
24
|
import { getLogger } from "../../util/logger.js";
|
|
21
25
|
import { ACTOR_PRINCIPALS } from "../auth/route-policy.js";
|
|
26
|
+
import * as pendingInteractions from "../pending-interactions.js";
|
|
22
27
|
import {
|
|
23
28
|
BadRequestError,
|
|
24
29
|
ConflictError,
|
|
25
30
|
FailedDependencyError,
|
|
31
|
+
ForbiddenError,
|
|
26
32
|
NotFoundError,
|
|
27
33
|
} from "./errors.js";
|
|
28
34
|
import type { RouteDefinition, RouteHandlerArgs } from "./types.js";
|
|
@@ -53,7 +59,109 @@ type SessionEntry = z.infer<typeof sessionEntrySchema>;
|
|
|
53
59
|
// Handlers
|
|
54
60
|
// ---------------------------------------------------------------------------
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Surface a high-risk confirmation for an ACP route that starts a host agent
|
|
64
|
+
* subprocess (`POST /v1/acp/spawn`, and the resume branch of
|
|
65
|
+
* `POST /v1/acp/:id/steer`) and resolve to the guardian's decision.
|
|
66
|
+
*
|
|
67
|
+
* Unlike the `acp_spawn` / `acp_steer` skill tools (which are dispatched
|
|
68
|
+
* through `ToolExecutor`/`PermissionChecker` and so inherit the descriptors'
|
|
69
|
+
* `risk: "high"` approval prompt), these HTTP/IPC routes reach the ACP
|
|
70
|
+
* session manager directly. A spawned ACP agent is a host subprocess with
|
|
71
|
+
* advertised filesystem + terminal access whose in-session permission
|
|
72
|
+
* requests are auto-allowed, so starting one is exactly the high-risk action
|
|
73
|
+
* the descriptors gate. Without this prompt a caller holding only
|
|
74
|
+
* `chat.write` could start one with no human in the loop — directly via
|
|
75
|
+
* spawn (arbitrary `cwd`), or by resuming a terminal session via steer (its
|
|
76
|
+
* persisted `cwd`, enumerable through `GET /v1/acp/sessions`) (ATL-822).
|
|
77
|
+
*
|
|
78
|
+
* The confirmation is registered with `directResolve` so `POST /v1/confirm`
|
|
79
|
+
* resolves it without a live `Conversation` object. That route requires the
|
|
80
|
+
* bound guardian (`approval.write` + `requireGuardian`) — a strictly higher
|
|
81
|
+
* bar than the `chat.write` these routes demand — so the `chat.write` caller
|
|
82
|
+
* cannot self-approve. Timeout and client disconnect both deny, matching the
|
|
83
|
+
* tool path's "no interactive client → do not run" posture.
|
|
84
|
+
*/
|
|
85
|
+
function awaitRouteApproval(args: {
|
|
86
|
+
toolName: string;
|
|
87
|
+
input: Record<string, unknown>;
|
|
88
|
+
conversationId: string;
|
|
89
|
+
signal?: AbortSignal;
|
|
90
|
+
}): Promise<UserDecision> {
|
|
91
|
+
const { toolName, input, conversationId, signal } = args;
|
|
92
|
+
const requestId = randomUUID();
|
|
93
|
+
// Mirror the interactive prompt timeout; fall back to the schema default
|
|
94
|
+
// (300s) if the timeouts block is somehow absent so the gate never wedges.
|
|
95
|
+
const timeoutMs = (getConfig().timeouts?.permissionTimeoutSec ?? 300) * 1000;
|
|
96
|
+
|
|
97
|
+
return new Promise<UserDecision>((resolve) => {
|
|
98
|
+
let settled = false;
|
|
99
|
+
const settle = (
|
|
100
|
+
decision: UserDecision,
|
|
101
|
+
state: "approved" | "rejected" | "cancelled",
|
|
102
|
+
) => {
|
|
103
|
+
if (settled) return;
|
|
104
|
+
settled = true;
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
signal?.removeEventListener("abort", onAbort);
|
|
107
|
+
// Idempotent: the `/v1/confirm` directResolve path already removed the
|
|
108
|
+
// entry before invoking us, so this is a no-op there and only fires
|
|
109
|
+
// `interaction_resolved` for the timeout/abort paths.
|
|
110
|
+
pendingInteractions.resolve(requestId, state);
|
|
111
|
+
resolve(decision);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const timer = setTimeout(() => {
|
|
115
|
+
log.warn(
|
|
116
|
+
{ requestId, toolName, conversationId },
|
|
117
|
+
"ACP route approval timed out — denying",
|
|
118
|
+
);
|
|
119
|
+
settle("deny", "cancelled");
|
|
120
|
+
}, timeoutMs);
|
|
121
|
+
|
|
122
|
+
const onAbort = () => settle("deny", "cancelled");
|
|
123
|
+
if (signal?.aborted) {
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
resolve("deny");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
129
|
+
|
|
130
|
+
pendingInteractions.register(requestId, {
|
|
131
|
+
conversationId,
|
|
132
|
+
kind: "confirmation",
|
|
133
|
+
confirmationDetails: {
|
|
134
|
+
toolName,
|
|
135
|
+
input,
|
|
136
|
+
riskLevel: "high",
|
|
137
|
+
executionTarget: "host",
|
|
138
|
+
allowlistOptions: [],
|
|
139
|
+
scopeOptions: [],
|
|
140
|
+
persistentDecisionsAllowed: false,
|
|
141
|
+
},
|
|
142
|
+
directResolve: (decision) =>
|
|
143
|
+
settle(decision, decision === "allow" ? "approved" : "rejected"),
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
broadcastMessage(
|
|
147
|
+
{
|
|
148
|
+
type: "confirmation_request",
|
|
149
|
+
requestId,
|
|
150
|
+
toolName,
|
|
151
|
+
input,
|
|
152
|
+
riskLevel: "high",
|
|
153
|
+
executionTarget: "host",
|
|
154
|
+
allowlistOptions: [],
|
|
155
|
+
scopeOptions: [],
|
|
156
|
+
conversationId,
|
|
157
|
+
persistentDecisionsAllowed: false,
|
|
158
|
+
},
|
|
159
|
+
conversationId,
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function spawnSession({ body, abortSignal }: RouteHandlerArgs) {
|
|
57
165
|
const agent = body?.agent as string | undefined;
|
|
58
166
|
const task = body?.task as string | undefined;
|
|
59
167
|
const conversationId = body?.conversationId as string | undefined;
|
|
@@ -63,6 +171,22 @@ async function spawnSession({ body }: RouteHandlerArgs) {
|
|
|
63
171
|
throw new BadRequestError("agent, task, and conversationId are required");
|
|
64
172
|
}
|
|
65
173
|
|
|
174
|
+
// High-risk approval gate. Block BEFORE any side effects — resolution can
|
|
175
|
+
// trigger a `bun` global install (auto-install.ts) and `manager.spawn`
|
|
176
|
+
// launches the host subprocess — so an unapproved request mutates nothing.
|
|
177
|
+
const decision = await awaitRouteApproval({
|
|
178
|
+
toolName: "acp_spawn",
|
|
179
|
+
input: { agent, task, cwd },
|
|
180
|
+
conversationId,
|
|
181
|
+
signal: abortSignal,
|
|
182
|
+
});
|
|
183
|
+
if (decision !== "allow") {
|
|
184
|
+
throw new ForbiddenError(
|
|
185
|
+
"Spawning an ACP coding agent requires guardian approval, which was " +
|
|
186
|
+
"not granted.",
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
66
190
|
// Resolve the agent, silently auto-installing a missing allowlisted
|
|
67
191
|
// adapter binary (see acp/auto-install.ts). Shared with the skill-tool
|
|
68
192
|
// path in tools/acp/spawn.ts; only the transport mapping differs.
|
|
@@ -117,6 +241,43 @@ async function steerSession({ pathParams, body }: RouteHandlerArgs) {
|
|
|
117
241
|
// broadcastMessage plays the sender role spawnSession gives it, so
|
|
118
242
|
// connected clients render the session.
|
|
119
243
|
const manager = getAcpSessionManager();
|
|
244
|
+
|
|
245
|
+
// Resume re-spawns the host agent subprocess, so it crosses the same
|
|
246
|
+
// high-risk boundary as spawn and needs guardian approval (ATL-822). A
|
|
247
|
+
// steer of a session still active in memory only redirects an
|
|
248
|
+
// already-running, already-approved process, so it is left unprompted —
|
|
249
|
+
// matching "gate before spawning". A resume only happens when the id is
|
|
250
|
+
// absent from memory AND a resumable history row (non-null cwd) exists.
|
|
251
|
+
if (!manager.getActiveAndPendingIds().includes(id)) {
|
|
252
|
+
const resumable = getDb()
|
|
253
|
+
.select({
|
|
254
|
+
cwd: acpSessionHistory.cwd,
|
|
255
|
+
agentId: acpSessionHistory.agentId,
|
|
256
|
+
parentConversationId: acpSessionHistory.parentConversationId,
|
|
257
|
+
})
|
|
258
|
+
.from(acpSessionHistory)
|
|
259
|
+
.where(eq(acpSessionHistory.id, id))
|
|
260
|
+
.get();
|
|
261
|
+
if (resumable?.cwd != null) {
|
|
262
|
+
// Guardian approval is an out-of-band human action that can take far
|
|
263
|
+
// longer than a client's ack timeout (the macOS client uses 10s; the
|
|
264
|
+
// approval window is permissionTimeoutSec, default 300s). Blocking the
|
|
265
|
+
// HTTP response here would surface as a client transport failure even
|
|
266
|
+
// on an eventual approval. Acknowledge immediately and run approval +
|
|
267
|
+
// resume in the background, streaming via SSE like any other ACP
|
|
268
|
+
// activity. The request abortSignal is deliberately NOT threaded into
|
|
269
|
+
// the wait — the request is already complete.
|
|
270
|
+
void approveThenResume({
|
|
271
|
+
id,
|
|
272
|
+
instruction,
|
|
273
|
+
agentId: resumable.agentId,
|
|
274
|
+
cwd: resumable.cwd,
|
|
275
|
+
conversationId: resumable.parentConversationId,
|
|
276
|
+
});
|
|
277
|
+
return { acpSessionId: id, steered: false, approvalPending: true };
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
120
281
|
try {
|
|
121
282
|
const { resumed } = await manager.steerOrResume(
|
|
122
283
|
id,
|
|
@@ -138,6 +299,81 @@ async function steerSession({ pathParams, body }: RouteHandlerArgs) {
|
|
|
138
299
|
}
|
|
139
300
|
}
|
|
140
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Background worker for an approval-gated ACP resume initiated over the steer
|
|
304
|
+
* route. Awaits the guardian decision (see `awaitRouteApproval`), then resumes
|
|
305
|
+
* via the session manager so the agent's output streams back over SSE. A
|
|
306
|
+
* denial, timeout, or resume failure is surfaced as an `acp_session_error` on
|
|
307
|
+
* the parent conversation so the client isn't left with an optimistic steer
|
|
308
|
+
* row and no follow-up. Never throws — it owns the request lifecycle after the
|
|
309
|
+
* route has already acked.
|
|
310
|
+
*/
|
|
311
|
+
async function approveThenResume(args: {
|
|
312
|
+
id: string;
|
|
313
|
+
instruction: string;
|
|
314
|
+
agentId: string;
|
|
315
|
+
cwd: string;
|
|
316
|
+
conversationId: string;
|
|
317
|
+
}): Promise<void> {
|
|
318
|
+
const decision = await awaitRouteApproval({
|
|
319
|
+
toolName: "acp_steer",
|
|
320
|
+
input: {
|
|
321
|
+
acp_session_id: args.id,
|
|
322
|
+
instruction: args.instruction,
|
|
323
|
+
agent: args.agentId,
|
|
324
|
+
cwd: args.cwd,
|
|
325
|
+
},
|
|
326
|
+
conversationId: args.conversationId,
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
if (decision !== "allow") {
|
|
330
|
+
log.info(
|
|
331
|
+
{ acpSessionId: args.id, conversationId: args.conversationId },
|
|
332
|
+
"ACP resume approval not granted — skipping resume",
|
|
333
|
+
);
|
|
334
|
+
broadcastMessage(
|
|
335
|
+
{
|
|
336
|
+
type: "acp_session_error",
|
|
337
|
+
// Key the error by the daemon session id (the value the steer route
|
|
338
|
+
// accepts and ACP SSE consumers index by — see registerSession, where
|
|
339
|
+
// state.id is the broadcast acpSessionId), NOT the persisted protocol
|
|
340
|
+
// id. A denied resume never emits acp_session_spawned to map the
|
|
341
|
+
// protocol id, so a protocol-keyed error would be dropped.
|
|
342
|
+
acpSessionId: args.id,
|
|
343
|
+
error: "Resume was not approved.",
|
|
344
|
+
},
|
|
345
|
+
args.conversationId,
|
|
346
|
+
);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
await getAcpSessionManager().steerOrResume(
|
|
352
|
+
args.id,
|
|
353
|
+
args.instruction,
|
|
354
|
+
broadcastMessage,
|
|
355
|
+
);
|
|
356
|
+
} catch (err) {
|
|
357
|
+
const message =
|
|
358
|
+
err instanceof AcpResumeError || err instanceof Error
|
|
359
|
+
? err.message
|
|
360
|
+
: String(err);
|
|
361
|
+
log.warn(
|
|
362
|
+
{ acpSessionId: args.id, conversationId: args.conversationId, err },
|
|
363
|
+
"Approved ACP resume failed",
|
|
364
|
+
);
|
|
365
|
+
broadcastMessage(
|
|
366
|
+
{
|
|
367
|
+
type: "acp_session_error",
|
|
368
|
+
// Daemon session id (route + SSE key), not the protocol id — see above.
|
|
369
|
+
acpSessionId: args.id,
|
|
370
|
+
error: message,
|
|
371
|
+
},
|
|
372
|
+
args.conversationId,
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
141
377
|
async function cancelSession({ pathParams }: RouteHandlerArgs) {
|
|
142
378
|
const id = pathParams?.id as string;
|
|
143
379
|
const manager = getAcpSessionManager();
|
|
@@ -276,7 +512,10 @@ export const ROUTES: RouteDefinition[] = [
|
|
|
276
512
|
"Send a steering instruction to an ACP session. Sessions no longer " +
|
|
277
513
|
"in memory (completed, or lost to a daemon restart) are " +
|
|
278
514
|
"transparently resumed from persisted history first, when the agent " +
|
|
279
|
-
"supports ACP session loading."
|
|
515
|
+
"supports ACP session loading. Resuming a terminal session re-spawns " +
|
|
516
|
+
"the host agent, so it requires guardian approval: the route acks " +
|
|
517
|
+
"immediately with approvalPending=true and performs the resume in the " +
|
|
518
|
+
"background once approved, streaming results over SSE.",
|
|
280
519
|
tags: ["acp"],
|
|
281
520
|
requestBody: z.object({
|
|
282
521
|
instruction: z.string(),
|
|
@@ -290,6 +529,13 @@ export const ROUTES: RouteDefinition[] = [
|
|
|
290
529
|
.describe(
|
|
291
530
|
"True when the session was resumed from persisted history before steering.",
|
|
292
531
|
),
|
|
532
|
+
approvalPending: z
|
|
533
|
+
.boolean()
|
|
534
|
+
.optional()
|
|
535
|
+
.describe(
|
|
536
|
+
"True when the steer triggered a guardian-approval-gated resume " +
|
|
537
|
+
"that will run asynchronously; watch SSE for the outcome.",
|
|
538
|
+
),
|
|
293
539
|
}),
|
|
294
540
|
},
|
|
295
541
|
{
|
|
@@ -114,7 +114,7 @@ async function handleBrowserTabs({ body = {} }: RouteHandlerArgs) {
|
|
|
114
114
|
}
|
|
115
115
|
} else if (targetClientId) {
|
|
116
116
|
// Only scope-clear the targeted client's pin. With the per-(conversationId,
|
|
117
|
-
// clientId) pin store
|
|
117
|
+
// clientId) pin store, passing no clientId to clearPinnedTab
|
|
118
118
|
// would wipe pins for *every* connected client on this conversation
|
|
119
119
|
// and break their routing — so we skip the clear entirely when the
|
|
120
120
|
// caller didn't explicitly target a client. The stale pin (if any)
|
|
@@ -23,6 +23,7 @@ import { ACTOR_PRINCIPALS } from "../auth/route-policy.js";
|
|
|
23
23
|
import { revokePendingSessions } from "../channel-verification-service.js";
|
|
24
24
|
import {
|
|
25
25
|
cancelOutbound,
|
|
26
|
+
deliverVerificationEmail,
|
|
26
27
|
deliverVerificationSlack,
|
|
27
28
|
normalizeTelegramDestination,
|
|
28
29
|
resendOutbound,
|
|
@@ -139,11 +140,15 @@ export async function handleCreateVerificationSession({
|
|
|
139
140
|
verificationRateLimiter.recordFailure(rateLimitKey);
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
// Dispatch
|
|
143
|
+
// Dispatch delivery from the daemon process (not sandboxed).
|
|
143
144
|
if (result._pendingSlackDm) {
|
|
144
145
|
const { userId, text, assistantId: aid } = result._pendingSlackDm;
|
|
145
146
|
deliverVerificationSlack(userId, text, aid);
|
|
146
147
|
}
|
|
148
|
+
if (result._pendingEmail) {
|
|
149
|
+
const { to, text, subject, assistantId: aid } = result._pendingEmail;
|
|
150
|
+
deliverVerificationEmail(to, text, subject, aid);
|
|
151
|
+
}
|
|
147
152
|
|
|
148
153
|
if (!result.success) {
|
|
149
154
|
if (result.error === "rate_limited") {
|
|
@@ -157,8 +162,8 @@ export async function handleCreateVerificationSession({
|
|
|
157
162
|
);
|
|
158
163
|
}
|
|
159
164
|
|
|
160
|
-
// Strip internal
|
|
161
|
-
const { _pendingSlackDm: _, ...publicResult } = result;
|
|
165
|
+
// Strip internal fields from the response
|
|
166
|
+
const { _pendingSlackDm: _, _pendingEmail: __, ...publicResult } = result;
|
|
162
167
|
return publicResult;
|
|
163
168
|
}
|
|
164
169
|
|
|
@@ -204,11 +209,15 @@ export async function handleResendVerificationSession({
|
|
|
204
209
|
|
|
205
210
|
const result = resendOutbound({ channel, originConversationId });
|
|
206
211
|
|
|
207
|
-
// Dispatch
|
|
212
|
+
// Dispatch delivery from the daemon process (not sandboxed).
|
|
208
213
|
if (result._pendingSlackDm) {
|
|
209
214
|
const { userId, text, assistantId: aid } = result._pendingSlackDm;
|
|
210
215
|
deliverVerificationSlack(userId, text, aid);
|
|
211
216
|
}
|
|
217
|
+
if (result._pendingEmail) {
|
|
218
|
+
const { to, text, subject, assistantId: aid } = result._pendingEmail;
|
|
219
|
+
deliverVerificationEmail(to, text, subject, aid);
|
|
220
|
+
}
|
|
212
221
|
|
|
213
222
|
if (!result.success) {
|
|
214
223
|
if (result.error === "rate_limited") {
|
|
@@ -221,7 +230,7 @@ export async function handleResendVerificationSession({
|
|
|
221
230
|
);
|
|
222
231
|
}
|
|
223
232
|
|
|
224
|
-
const { _pendingSlackDm: _, ...publicResult } = result;
|
|
233
|
+
const { _pendingSlackDm: _, _pendingEmail: __, ...publicResult } = result;
|
|
225
234
|
return publicResult;
|
|
226
235
|
}
|
|
227
236
|
|