@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
|
@@ -511,6 +511,7 @@ describe("surfaceProxyResolver — app-control tool routing", () => {
|
|
|
511
511
|
_setActiveAppControlSession({
|
|
512
512
|
conversationId: "conv-1",
|
|
513
513
|
app: "com.example.editor",
|
|
514
|
+
targetClientId: "client-b",
|
|
514
515
|
});
|
|
515
516
|
|
|
516
517
|
const resultPromise = surfaceProxyResolver(ctx, "app_control_observe", {
|
|
@@ -595,6 +596,7 @@ describe("surfaceProxyResolver — app-control tool routing", () => {
|
|
|
595
596
|
_setActiveAppControlSession({
|
|
596
597
|
conversationId: "conv-1",
|
|
597
598
|
app: "com.example.editor",
|
|
599
|
+
targetClientId: "client-mine",
|
|
598
600
|
});
|
|
599
601
|
|
|
600
602
|
const resultPromise = surfaceProxyResolver(ctx, "app_control_observe", {
|
|
@@ -617,7 +619,7 @@ describe("surfaceProxyResolver — app-control tool routing", () => {
|
|
|
617
619
|
proxy.dispose();
|
|
618
620
|
});
|
|
619
621
|
|
|
620
|
-
test("single same-user client with no target
|
|
622
|
+
test("single same-user client with no target resolves to that client", async () => {
|
|
621
623
|
mockHubClients = [
|
|
622
624
|
{
|
|
623
625
|
clientId: "only-client",
|
|
@@ -630,6 +632,7 @@ describe("surfaceProxyResolver — app-control tool routing", () => {
|
|
|
630
632
|
_setActiveAppControlSession({
|
|
631
633
|
conversationId: "conv-1",
|
|
632
634
|
app: "com.example.editor",
|
|
635
|
+
targetClientId: "only-client",
|
|
633
636
|
});
|
|
634
637
|
|
|
635
638
|
const resultPromise = surfaceProxyResolver(ctx, "app_control_observe", {
|
|
@@ -12,55 +12,20 @@
|
|
|
12
12
|
|
|
13
13
|
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
14
14
|
|
|
15
|
-
import type { ToolSetupContext } from "../daemon/conversation-tool-setup.js";
|
|
16
|
-
import type { SurfaceData, SurfaceType } from "../daemon/message-protocol.js";
|
|
17
15
|
import { SYNC_TAGS } from "../daemon/message-types/sync.js";
|
|
18
16
|
import type { PermissionPrompter } from "../permissions/prompter.js";
|
|
19
17
|
import type { SecretPrompter } from "../permissions/secret-prompter.js";
|
|
20
18
|
import type { ToolExecutor } from "../tools/executor.js";
|
|
21
19
|
import type { ToolExecutionResult } from "../tools/types.js";
|
|
20
|
+
import {
|
|
21
|
+
broadcastMessageSpy,
|
|
22
|
+
installConversationToolSetupMocks,
|
|
23
|
+
makeToolSetupContext,
|
|
24
|
+
refreshSurfacesForAppSpy,
|
|
25
|
+
updatePublishedAppDeploymentSpy,
|
|
26
|
+
} from "./conversation-tool-setup-test-helpers.js";
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
// Spies for side-effect verification
|
|
25
|
-
// ---------------------------------------------------------------------------
|
|
26
|
-
|
|
27
|
-
const refreshSpy = mock(() => {});
|
|
28
|
-
const updatePublishedSpy = mock(() => Promise.resolve());
|
|
29
|
-
const broadcastSpy = mock(() => {});
|
|
30
|
-
|
|
31
|
-
mock.module("../runtime/assistant-event-hub.js", () => ({
|
|
32
|
-
broadcastMessage: broadcastSpy,
|
|
33
|
-
}));
|
|
34
|
-
|
|
35
|
-
// Mock session-surfaces so refreshSurfacesForApp is captured
|
|
36
|
-
mock.module("../daemon/conversation-surfaces.js", () => ({
|
|
37
|
-
refreshSurfacesForApp: refreshSpy,
|
|
38
|
-
surfaceProxyResolver: mock(() =>
|
|
39
|
-
Promise.resolve({ content: "", isError: false }),
|
|
40
|
-
),
|
|
41
|
-
}));
|
|
42
|
-
|
|
43
|
-
// Mock published-app-updater to prevent real deployment calls
|
|
44
|
-
mock.module("../services/published-app-updater.js", () => ({
|
|
45
|
-
updatePublishedAppDeployment: updatePublishedSpy,
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
// Mock browser-screencast registration (no-op)
|
|
49
|
-
mock.module("../tools/browser/browser-screencast.js", () => ({
|
|
50
|
-
registerConversationSender: mock(() => {}),
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
// Stub app-store functions used by other modules (e.g. app-source-watcher,
|
|
54
|
-
// conversation-surfaces) so tool-side-effects' hooks can run without touching
|
|
55
|
-
// the real app store during tests.
|
|
56
|
-
mock.module("../memory/app-store.js", () => ({
|
|
57
|
-
getApp: mock(() => null),
|
|
58
|
-
getAppDirPath: mock(() => "/tmp/test-apps/dummy"),
|
|
59
|
-
isMultifileApp: mock(() => false),
|
|
60
|
-
getAppsDir: mock(() => "/tmp/test-apps"),
|
|
61
|
-
resolveAppIdByDirName: mock(() => null),
|
|
62
|
-
resolveAppIdFromPath: mock(() => null),
|
|
63
|
-
}));
|
|
28
|
+
installConversationToolSetupMocks();
|
|
64
29
|
|
|
65
30
|
// ---------------------------------------------------------------------------
|
|
66
31
|
// Import createToolExecutor after mocks are in place
|
|
@@ -73,7 +38,9 @@ import { createToolExecutor } from "../daemon/conversation-tool-setup.js";
|
|
|
73
38
|
// ---------------------------------------------------------------------------
|
|
74
39
|
|
|
75
40
|
function broadcastPayloads(): unknown[] {
|
|
76
|
-
return (
|
|
41
|
+
return (broadcastMessageSpy.mock.calls as unknown[][]).map(
|
|
42
|
+
([payload]) => payload,
|
|
43
|
+
);
|
|
77
44
|
}
|
|
78
45
|
|
|
79
46
|
function expectAppChangeBroadcast(appId: string): void {
|
|
@@ -85,34 +52,6 @@ function expectAppChangeBroadcast(appId: string): void {
|
|
|
85
52
|
);
|
|
86
53
|
}
|
|
87
54
|
|
|
88
|
-
/** Build a minimal ToolSetupContext stub. */
|
|
89
|
-
function makeCtx(overrides: Partial<ToolSetupContext> = {}): ToolSetupContext {
|
|
90
|
-
return {
|
|
91
|
-
conversationId: "conv-test",
|
|
92
|
-
currentRequestId: "req-1",
|
|
93
|
-
workingDir: "/tmp/test",
|
|
94
|
-
abortController: null,
|
|
95
|
-
traceEmitter: { emit: () => {} },
|
|
96
|
-
sendToClient: mock(() => {}),
|
|
97
|
-
pendingSurfaceActions: new Map(),
|
|
98
|
-
lastSurfaceAction: new Map(),
|
|
99
|
-
surfaceState: new Map<
|
|
100
|
-
string,
|
|
101
|
-
{ surfaceType: SurfaceType; data: SurfaceData; title?: string }
|
|
102
|
-
>(),
|
|
103
|
-
surfaceUndoStacks: new Map(),
|
|
104
|
-
accumulatedSurfaceState: new Map(),
|
|
105
|
-
surfaceActionRequestIds: new Set<string>(),
|
|
106
|
-
currentTurnSurfaces: [],
|
|
107
|
-
isProcessing: () => false,
|
|
108
|
-
enqueueMessage: () => ({ queued: false, requestId: "r" }),
|
|
109
|
-
getQueueDepth: () => 0,
|
|
110
|
-
processMessage: async () => "",
|
|
111
|
-
withSurface: async <T>(_id: string, fn: () => T | Promise<T>) => fn(),
|
|
112
|
-
...overrides,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
55
|
/** Fake ToolExecutor whose execute() returns a controlled result. */
|
|
117
56
|
function makeFakeExecutor(
|
|
118
57
|
result: ToolExecutionResult = { content: "{}", isError: false },
|
|
@@ -137,16 +76,16 @@ const noopLifecycleHandler = mock(() => {});
|
|
|
137
76
|
|
|
138
77
|
describe("session-tool-setup app refresh side effects", () => {
|
|
139
78
|
beforeEach(() => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
79
|
+
refreshSurfacesForAppSpy.mockClear();
|
|
80
|
+
broadcastMessageSpy.mockClear();
|
|
81
|
+
updatePublishedAppDeploymentSpy.mockClear();
|
|
143
82
|
});
|
|
144
83
|
|
|
145
84
|
// ── app_refresh ─────────────────────────────────────────────────────
|
|
146
85
|
|
|
147
86
|
describe("app_refresh", () => {
|
|
148
87
|
test("triggers refreshSurfacesForApp when result is not an error", async () => {
|
|
149
|
-
const ctx =
|
|
88
|
+
const ctx = makeToolSetupContext();
|
|
150
89
|
const executor = makeFakeExecutor({
|
|
151
90
|
content: '{"id":"app-1"}',
|
|
152
91
|
isError: false,
|
|
@@ -162,13 +101,17 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
162
101
|
|
|
163
102
|
await toolFn("app_refresh", { app_id: "app-1" });
|
|
164
103
|
|
|
165
|
-
expect(
|
|
166
|
-
expect((
|
|
167
|
-
|
|
104
|
+
expect(refreshSurfacesForAppSpy).toHaveBeenCalledTimes(1);
|
|
105
|
+
expect((refreshSurfacesForAppSpy.mock.calls as unknown[][])[0][0]).toBe(
|
|
106
|
+
ctx,
|
|
107
|
+
);
|
|
108
|
+
expect((refreshSurfacesForAppSpy.mock.calls as unknown[][])[0][1]).toBe(
|
|
109
|
+
"app-1",
|
|
110
|
+
);
|
|
168
111
|
});
|
|
169
112
|
|
|
170
113
|
test("broadcasts app_files_changed with correct appId", async () => {
|
|
171
|
-
const ctx =
|
|
114
|
+
const ctx = makeToolSetupContext();
|
|
172
115
|
const executor = makeFakeExecutor({ content: "{}", isError: false });
|
|
173
116
|
|
|
174
117
|
const toolFn = createToolExecutor(
|
|
@@ -181,12 +124,12 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
181
124
|
|
|
182
125
|
await toolFn("app_refresh", { app_id: "app-42" });
|
|
183
126
|
|
|
184
|
-
expect(
|
|
127
|
+
expect(broadcastMessageSpy).toHaveBeenCalledTimes(2);
|
|
185
128
|
expectAppChangeBroadcast("app-42");
|
|
186
129
|
});
|
|
187
130
|
|
|
188
131
|
test("calls updatePublishedAppDeployment", async () => {
|
|
189
|
-
const ctx =
|
|
132
|
+
const ctx = makeToolSetupContext();
|
|
190
133
|
const executor = makeFakeExecutor({ content: "{}", isError: false });
|
|
191
134
|
|
|
192
135
|
const toolFn = createToolExecutor(
|
|
@@ -201,14 +144,14 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
201
144
|
|
|
202
145
|
// updatePublishedAppDeployment is called with void (fire-and-forget),
|
|
203
146
|
// so just verify it was invoked.
|
|
204
|
-
expect(
|
|
205
|
-
expect(
|
|
206
|
-
|
|
207
|
-
);
|
|
147
|
+
expect(updatePublishedAppDeploymentSpy).toHaveBeenCalledTimes(1);
|
|
148
|
+
expect(
|
|
149
|
+
(updatePublishedAppDeploymentSpy.mock.calls as unknown[][])[0][0],
|
|
150
|
+
).toBe("app-publish");
|
|
208
151
|
});
|
|
209
152
|
|
|
210
153
|
test("skips side effects when result is an error", async () => {
|
|
211
|
-
const ctx =
|
|
154
|
+
const ctx = makeToolSetupContext();
|
|
212
155
|
const executor = makeFakeExecutor({
|
|
213
156
|
content: "Error: not found",
|
|
214
157
|
isError: true,
|
|
@@ -224,13 +167,13 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
224
167
|
|
|
225
168
|
await toolFn("app_refresh", { app_id: "app-err" });
|
|
226
169
|
|
|
227
|
-
expect(
|
|
228
|
-
expect(
|
|
229
|
-
expect(
|
|
170
|
+
expect(refreshSurfacesForAppSpy).not.toHaveBeenCalled();
|
|
171
|
+
expect(broadcastMessageSpy).not.toHaveBeenCalled();
|
|
172
|
+
expect(updatePublishedAppDeploymentSpy).not.toHaveBeenCalled();
|
|
230
173
|
});
|
|
231
174
|
|
|
232
175
|
test("skips side effects when app_id is missing", async () => {
|
|
233
|
-
const ctx =
|
|
176
|
+
const ctx = makeToolSetupContext();
|
|
234
177
|
const executor = makeFakeExecutor({ content: "{}", isError: false });
|
|
235
178
|
|
|
236
179
|
const toolFn = createToolExecutor(
|
|
@@ -243,8 +186,8 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
243
186
|
|
|
244
187
|
await toolFn("app_refresh", {});
|
|
245
188
|
|
|
246
|
-
expect(
|
|
247
|
-
expect(
|
|
189
|
+
expect(refreshSurfacesForAppSpy).not.toHaveBeenCalled();
|
|
190
|
+
expect(broadcastMessageSpy).not.toHaveBeenCalled();
|
|
248
191
|
});
|
|
249
192
|
});
|
|
250
193
|
|
|
@@ -252,7 +195,7 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
252
195
|
|
|
253
196
|
describe("app_update", () => {
|
|
254
197
|
test("triggers refreshSurfacesForApp and broadcast on success", async () => {
|
|
255
|
-
const ctx =
|
|
198
|
+
const ctx = makeToolSetupContext();
|
|
256
199
|
const executor = makeFakeExecutor({
|
|
257
200
|
content: '{"updated":true,"appId":"app-7"}',
|
|
258
201
|
isError: false,
|
|
@@ -268,17 +211,19 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
268
211
|
|
|
269
212
|
await toolFn("app_update", { app_id: "app-7" });
|
|
270
213
|
|
|
271
|
-
expect(
|
|
272
|
-
expect((
|
|
273
|
-
expectAppChangeBroadcast("app-7");
|
|
274
|
-
expect(updatePublishedSpy).toHaveBeenCalledTimes(1);
|
|
275
|
-
expect((updatePublishedSpy.mock.calls as unknown[][])[0][0]).toBe(
|
|
214
|
+
expect(refreshSurfacesForAppSpy).toHaveBeenCalledTimes(1);
|
|
215
|
+
expect((refreshSurfacesForAppSpy.mock.calls as unknown[][])[0][1]).toBe(
|
|
276
216
|
"app-7",
|
|
277
217
|
);
|
|
218
|
+
expectAppChangeBroadcast("app-7");
|
|
219
|
+
expect(updatePublishedAppDeploymentSpy).toHaveBeenCalledTimes(1);
|
|
220
|
+
expect(
|
|
221
|
+
(updatePublishedAppDeploymentSpy.mock.calls as unknown[][])[0][0],
|
|
222
|
+
).toBe("app-7");
|
|
278
223
|
});
|
|
279
224
|
|
|
280
225
|
test("skips side effects when result is an error", async () => {
|
|
281
|
-
const ctx =
|
|
226
|
+
const ctx = makeToolSetupContext();
|
|
282
227
|
const executor = makeFakeExecutor({
|
|
283
228
|
content: "Error: not found",
|
|
284
229
|
isError: true,
|
|
@@ -294,13 +239,13 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
294
239
|
|
|
295
240
|
await toolFn("app_update", { app_id: "app-err" });
|
|
296
241
|
|
|
297
|
-
expect(
|
|
298
|
-
expect(
|
|
299
|
-
expect(
|
|
242
|
+
expect(refreshSurfacesForAppSpy).not.toHaveBeenCalled();
|
|
243
|
+
expect(broadcastMessageSpy).not.toHaveBeenCalled();
|
|
244
|
+
expect(updatePublishedAppDeploymentSpy).not.toHaveBeenCalled();
|
|
300
245
|
});
|
|
301
246
|
|
|
302
247
|
test("skips side effects when app_id is missing", async () => {
|
|
303
|
-
const ctx =
|
|
248
|
+
const ctx = makeToolSetupContext();
|
|
304
249
|
const executor = makeFakeExecutor({ content: "{}", isError: false });
|
|
305
250
|
|
|
306
251
|
const toolFn = createToolExecutor(
|
|
@@ -313,8 +258,8 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
313
258
|
|
|
314
259
|
await toolFn("app_update", {});
|
|
315
260
|
|
|
316
|
-
expect(
|
|
317
|
-
expect(
|
|
261
|
+
expect(refreshSurfacesForAppSpy).not.toHaveBeenCalled();
|
|
262
|
+
expect(broadcastMessageSpy).not.toHaveBeenCalled();
|
|
318
263
|
});
|
|
319
264
|
});
|
|
320
265
|
|
|
@@ -322,7 +267,7 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
322
267
|
|
|
323
268
|
describe("app_create side effects", () => {
|
|
324
269
|
test("broadcasts app_files_changed immediately after app_create", async () => {
|
|
325
|
-
const ctx =
|
|
270
|
+
const ctx = makeToolSetupContext();
|
|
326
271
|
const executor = makeFakeExecutor({
|
|
327
272
|
content: JSON.stringify({ id: "new-app-1", name: "My App" }),
|
|
328
273
|
isError: false,
|
|
@@ -338,8 +283,8 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
338
283
|
|
|
339
284
|
await toolFn("app_create", { name: "My App", html: "<h1>hi</h1>" });
|
|
340
285
|
|
|
341
|
-
expect(
|
|
342
|
-
expect((
|
|
286
|
+
expect(broadcastMessageSpy.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
287
|
+
expect((broadcastMessageSpy.mock.calls as unknown[][])[0][0]).toEqual({
|
|
343
288
|
type: "app_files_changed",
|
|
344
289
|
appId: "new-app-1",
|
|
345
290
|
});
|
|
@@ -347,7 +292,9 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
347
292
|
});
|
|
348
293
|
|
|
349
294
|
test("canonicalizes create_app skill_execute alias before hooks run", async () => {
|
|
350
|
-
const ctx =
|
|
295
|
+
const ctx = makeToolSetupContext({
|
|
296
|
+
allowedToolNames: new Set(["app_create"]),
|
|
297
|
+
});
|
|
351
298
|
const executor = makeFakeExecutor({
|
|
352
299
|
content: JSON.stringify({ id: "alias-app-1", name: "Alias App" }),
|
|
353
300
|
isError: false,
|
|
@@ -370,8 +317,8 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
370
317
|
const calls = executor.execute.mock.calls as unknown[][];
|
|
371
318
|
expect(calls[0][0]).toBe("app_create");
|
|
372
319
|
expect(calls[0][1]).toEqual({ name: "Alias App" });
|
|
373
|
-
expect(
|
|
374
|
-
expect((
|
|
320
|
+
expect(broadcastMessageSpy.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
321
|
+
expect((broadcastMessageSpy.mock.calls as unknown[][])[0][0]).toEqual({
|
|
375
322
|
type: "app_files_changed",
|
|
376
323
|
appId: "alias-app-1",
|
|
377
324
|
});
|
|
@@ -379,7 +326,9 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
379
326
|
});
|
|
380
327
|
|
|
381
328
|
test("canonicalizes legacy computer_use_press_key skill_execute alias before dispatch", async () => {
|
|
382
|
-
const ctx =
|
|
329
|
+
const ctx = makeToolSetupContext({
|
|
330
|
+
allowedToolNames: new Set(["computer_use_key"]),
|
|
331
|
+
});
|
|
383
332
|
const executor = makeFakeExecutor({ content: "ok", isError: false });
|
|
384
333
|
|
|
385
334
|
const toolFn = createToolExecutor(
|
|
@@ -409,7 +358,7 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
409
358
|
});
|
|
410
359
|
|
|
411
360
|
test("preserves exact active create_app skill tool when app_create is also active", async () => {
|
|
412
|
-
const ctx =
|
|
361
|
+
const ctx = makeToolSetupContext({
|
|
413
362
|
allowedToolNames: new Set(["create_app", "app_create"]),
|
|
414
363
|
});
|
|
415
364
|
const executor = makeFakeExecutor({
|
|
@@ -433,11 +382,11 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
433
382
|
|
|
434
383
|
const calls = executor.execute.mock.calls as unknown[][];
|
|
435
384
|
expect(calls[0][0]).toBe("create_app");
|
|
436
|
-
expect(
|
|
385
|
+
expect(broadcastMessageSpy).not.toHaveBeenCalled();
|
|
437
386
|
});
|
|
438
387
|
|
|
439
388
|
test("skips side effects when app_create result is an error", async () => {
|
|
440
|
-
const ctx =
|
|
389
|
+
const ctx = makeToolSetupContext();
|
|
441
390
|
const executor = makeFakeExecutor({ content: "Error", isError: true });
|
|
442
391
|
|
|
443
392
|
const toolFn = createToolExecutor(
|
|
@@ -450,7 +399,7 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
450
399
|
|
|
451
400
|
await toolFn("app_create", { name: "Bad", html: "" });
|
|
452
401
|
|
|
453
|
-
expect(
|
|
402
|
+
expect(broadcastMessageSpy).not.toHaveBeenCalled();
|
|
454
403
|
});
|
|
455
404
|
|
|
456
405
|
test("fires notify side effects regardless of compile outcome reported in payload", async () => {
|
|
@@ -459,7 +408,7 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
459
408
|
// compile or returns compile_errors, the hook still refreshes
|
|
460
409
|
// surfaces and broadcasts — compile retries are the LLM's
|
|
461
410
|
// responsibility via a follow-up tool call, not the hook's.
|
|
462
|
-
const ctx =
|
|
411
|
+
const ctx = makeToolSetupContext();
|
|
463
412
|
const executor = makeFakeExecutor({
|
|
464
413
|
content: JSON.stringify({
|
|
465
414
|
id: "new-app-err",
|
|
@@ -480,14 +429,14 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
480
429
|
|
|
481
430
|
await toolFn("app_create", { name: "Busted", html: "" });
|
|
482
431
|
|
|
483
|
-
expect(
|
|
484
|
-
expect(
|
|
485
|
-
expect((
|
|
432
|
+
expect(refreshSurfacesForAppSpy).toHaveBeenCalledTimes(1);
|
|
433
|
+
expect(broadcastMessageSpy.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
434
|
+
expect((broadcastMessageSpy.mock.calls as unknown[][])[0][0]).toEqual({
|
|
486
435
|
type: "app_files_changed",
|
|
487
436
|
appId: "new-app-err",
|
|
488
437
|
});
|
|
489
438
|
expectAppChangeBroadcast("new-app-err");
|
|
490
|
-
expect(
|
|
439
|
+
expect(updatePublishedAppDeploymentSpy).toHaveBeenCalledTimes(1);
|
|
491
440
|
});
|
|
492
441
|
});
|
|
493
442
|
|
|
@@ -495,7 +444,7 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
495
444
|
|
|
496
445
|
describe("app_delete side effects", () => {
|
|
497
446
|
test("broadcasts app_files_changed after app_delete", async () => {
|
|
498
|
-
const ctx =
|
|
447
|
+
const ctx = makeToolSetupContext();
|
|
499
448
|
const executor = makeFakeExecutor({ content: "{}", isError: false });
|
|
500
449
|
|
|
501
450
|
const toolFn = createToolExecutor(
|
|
@@ -508,12 +457,12 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
508
457
|
|
|
509
458
|
await toolFn("app_delete", { app_id: "del-app-1" });
|
|
510
459
|
|
|
511
|
-
expect(
|
|
460
|
+
expect(broadcastMessageSpy).toHaveBeenCalledTimes(2);
|
|
512
461
|
expectAppChangeBroadcast("del-app-1");
|
|
513
462
|
});
|
|
514
463
|
|
|
515
464
|
test("skips side effects when app_delete result is an error", async () => {
|
|
516
|
-
const ctx =
|
|
465
|
+
const ctx = makeToolSetupContext();
|
|
517
466
|
const executor = makeFakeExecutor({ content: "Error", isError: true });
|
|
518
467
|
|
|
519
468
|
const toolFn = createToolExecutor(
|
|
@@ -526,7 +475,7 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
526
475
|
|
|
527
476
|
await toolFn("app_delete", { app_id: "del-err" });
|
|
528
477
|
|
|
529
|
-
expect(
|
|
478
|
+
expect(broadcastMessageSpy).not.toHaveBeenCalled();
|
|
530
479
|
});
|
|
531
480
|
});
|
|
532
481
|
|
|
@@ -538,7 +487,7 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
538
487
|
// string comparison, not tool metadata or origin. This means skill-
|
|
539
488
|
// projected tools with the same name trigger the same afterExecute
|
|
540
489
|
// hooks as core tools.
|
|
541
|
-
const ctx =
|
|
490
|
+
const ctx = makeToolSetupContext();
|
|
542
491
|
const executor = makeFakeExecutor({ content: "{}", isError: false });
|
|
543
492
|
|
|
544
493
|
const toolFn = createToolExecutor(
|
|
@@ -551,19 +500,19 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
551
500
|
|
|
552
501
|
// Simulate calling app_refresh by name (as the agent loop does)
|
|
553
502
|
for (const toolName of ["app_refresh"]) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
503
|
+
refreshSurfacesForAppSpy.mockClear();
|
|
504
|
+
broadcastMessageSpy.mockClear();
|
|
505
|
+
broadcastMessageSpy.mockClear();
|
|
506
|
+
updatePublishedAppDeploymentSpy.mockClear();
|
|
558
507
|
|
|
559
508
|
await toolFn(toolName, {
|
|
560
509
|
app_id: "skill-app",
|
|
561
510
|
});
|
|
562
511
|
|
|
563
|
-
expect(
|
|
564
|
-
expect(
|
|
512
|
+
expect(refreshSurfacesForAppSpy).toHaveBeenCalledTimes(1);
|
|
513
|
+
expect(broadcastMessageSpy).toHaveBeenCalledTimes(2);
|
|
565
514
|
expectAppChangeBroadcast("skill-app");
|
|
566
|
-
expect(
|
|
515
|
+
expect(updatePublishedAppDeploymentSpy).toHaveBeenCalledTimes(1);
|
|
567
516
|
}
|
|
568
517
|
});
|
|
569
518
|
});
|
|
@@ -572,7 +521,7 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
572
521
|
|
|
573
522
|
describe("non-app tools", () => {
|
|
574
523
|
test("other tool names do not trigger app refresh side effects", async () => {
|
|
575
|
-
const ctx =
|
|
524
|
+
const ctx = makeToolSetupContext();
|
|
576
525
|
const executor = makeFakeExecutor({ content: "{}", isError: false });
|
|
577
526
|
|
|
578
527
|
const toolFn = createToolExecutor(
|
|
@@ -591,16 +540,16 @@ describe("session-tool-setup app refresh side effects", () => {
|
|
|
591
540
|
"app_file_edit",
|
|
592
541
|
"app_file_write",
|
|
593
542
|
]) {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
543
|
+
refreshSurfacesForAppSpy.mockClear();
|
|
544
|
+
broadcastMessageSpy.mockClear();
|
|
545
|
+
broadcastMessageSpy.mockClear();
|
|
546
|
+
updatePublishedAppDeploymentSpy.mockClear();
|
|
598
547
|
|
|
599
548
|
await toolFn(toolName, { app_id: "app-1" });
|
|
600
549
|
|
|
601
|
-
expect(
|
|
602
|
-
expect(
|
|
603
|
-
expect(
|
|
550
|
+
expect(refreshSurfacesForAppSpy).not.toHaveBeenCalled();
|
|
551
|
+
expect(broadcastMessageSpy).not.toHaveBeenCalled();
|
|
552
|
+
expect(updatePublishedAppDeploymentSpy).not.toHaveBeenCalled();
|
|
604
553
|
}
|
|
605
554
|
});
|
|
606
555
|
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for skill attribution in the skill_execute interception of
|
|
3
|
+
* createToolExecutor (conversation-tool-setup.ts): skill-routed dispatches
|
|
4
|
+
* must carry the owning skill's id on the ToolContext handed to the
|
|
5
|
+
* executor, while direct tool calls must not.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { afterAll, describe, expect, mock, test } from "bun:test";
|
|
9
|
+
|
|
10
|
+
import type { PermissionPrompter } from "../permissions/prompter.js";
|
|
11
|
+
import type { SecretPrompter } from "../permissions/secret-prompter.js";
|
|
12
|
+
import { RiskLevel } from "../permissions/types.js";
|
|
13
|
+
import type { ToolExecutor } from "../tools/executor.js";
|
|
14
|
+
import type { Tool, ToolContext, ToolExecutionResult } from "../tools/types.js";
|
|
15
|
+
import {
|
|
16
|
+
installConversationToolSetupMocks,
|
|
17
|
+
makeToolSetupContext,
|
|
18
|
+
} from "./conversation-tool-setup-test-helpers.js";
|
|
19
|
+
|
|
20
|
+
installConversationToolSetupMocks();
|
|
21
|
+
|
|
22
|
+
import { createToolExecutor } from "../daemon/conversation-tool-setup.js";
|
|
23
|
+
import { registerSkillTools, unregisterSkillTools } from "../tools/registry.js";
|
|
24
|
+
|
|
25
|
+
const SKILL_ID = "attribution-test-skill";
|
|
26
|
+
const SKILL_TOOL_NAME = "attribution_test_tool";
|
|
27
|
+
|
|
28
|
+
const skillTool: Tool = {
|
|
29
|
+
name: SKILL_TOOL_NAME,
|
|
30
|
+
description: "skill tool for attribution tests",
|
|
31
|
+
category: "skill",
|
|
32
|
+
defaultRiskLevel: RiskLevel.Low,
|
|
33
|
+
executionTarget: "sandbox",
|
|
34
|
+
input_schema: { type: "object", properties: {} },
|
|
35
|
+
execute: async () => ({ content: "ok", isError: false }),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
registerSkillTools(SKILL_ID, [skillTool]);
|
|
39
|
+
afterAll(() => unregisterSkillTools(SKILL_ID));
|
|
40
|
+
|
|
41
|
+
/** Fake ToolExecutor that captures the context of each execute() call. */
|
|
42
|
+
function makeCapturingExecutor() {
|
|
43
|
+
const calls: Array<{ name: string; context: ToolContext }> = [];
|
|
44
|
+
const executor = {
|
|
45
|
+
execute: async (
|
|
46
|
+
name: string,
|
|
47
|
+
_input: Record<string, unknown>,
|
|
48
|
+
context: ToolContext,
|
|
49
|
+
): Promise<ToolExecutionResult> => {
|
|
50
|
+
calls.push({ name, context });
|
|
51
|
+
return { content: "ok", isError: false };
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
return { executor: executor as unknown as ToolExecutor, calls };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const noopPrompter = {
|
|
58
|
+
prompt: mock(async () => ({ decision: "allow" as const })),
|
|
59
|
+
} as unknown as PermissionPrompter;
|
|
60
|
+
const noopSecretPrompter = {
|
|
61
|
+
prompt: mock(async () => ({ cancelled: true })),
|
|
62
|
+
} as unknown as SecretPrompter;
|
|
63
|
+
|
|
64
|
+
function makeToolFn(executor: ToolExecutor) {
|
|
65
|
+
return createToolExecutor(
|
|
66
|
+
executor,
|
|
67
|
+
noopPrompter,
|
|
68
|
+
noopSecretPrompter,
|
|
69
|
+
makeToolSetupContext(),
|
|
70
|
+
() => {},
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
describe("conversation-tool-setup skill attribution", () => {
|
|
75
|
+
test("skill_execute dispatch sets the owning skill id on the executor context", async () => {
|
|
76
|
+
const { executor, calls } = makeCapturingExecutor();
|
|
77
|
+
const toolFn = makeToolFn(executor);
|
|
78
|
+
|
|
79
|
+
const result = await toolFn("skill_execute", {
|
|
80
|
+
tool: SKILL_TOOL_NAME,
|
|
81
|
+
input: {},
|
|
82
|
+
activity: "testing",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(result).toMatchObject({ content: "ok", isError: false });
|
|
86
|
+
expect(calls).toHaveLength(1);
|
|
87
|
+
expect(calls[0].name).toBe(SKILL_TOOL_NAME);
|
|
88
|
+
expect(calls[0].context.skillId).toBe(SKILL_ID);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("skill_execute with a non-skill-owned tool leaves skillId unset", async () => {
|
|
92
|
+
const { executor, calls } = makeCapturingExecutor();
|
|
93
|
+
const toolFn = makeToolFn(executor);
|
|
94
|
+
|
|
95
|
+
await toolFn("skill_execute", {
|
|
96
|
+
tool: "file_read",
|
|
97
|
+
input: { path: "/tmp/a" },
|
|
98
|
+
activity: "testing",
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(calls).toHaveLength(1);
|
|
102
|
+
expect(calls[0].name).toBe("file_read");
|
|
103
|
+
expect(calls[0].context.skillId).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("direct tool calls leave skillId unset", async () => {
|
|
107
|
+
const { executor, calls } = makeCapturingExecutor();
|
|
108
|
+
const toolFn = makeToolFn(executor);
|
|
109
|
+
|
|
110
|
+
await toolFn("file_read", { path: "/tmp/a" });
|
|
111
|
+
|
|
112
|
+
expect(calls).toHaveLength(1);
|
|
113
|
+
expect(calls[0].name).toBe("file_read");
|
|
114
|
+
expect(calls[0].context.skillId).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
});
|