@vellumai/assistant 0.10.11-dev.202607222129.31c06e5 → 0.10.11-dev.202607222226.fdf0e3d
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/ARCHITECTURE.md +30 -21
- package/package.json +1 -1
- package/src/__tests__/channel-delivery-store.test.ts +141 -0
- package/src/__tests__/dynamic-skill-background-guard.test.ts +102 -13
- package/src/__tests__/inline-skill-load-permissions.test.ts +29 -6
- package/src/__tests__/record-persisted-seq-lock-resilience.test.ts +95 -0
- package/src/__tests__/tool-approval-handler.test.ts +25 -1
- package/src/api/events/bookmark-created.ts +37 -0
- package/src/api/events/bookmark-deleted.ts +20 -0
- package/src/api/index.ts +14 -0
- package/src/daemon/message-types/bookmarks.ts +9 -14
- package/src/messaging/providers/telegram-bot/send.test.ts +88 -0
- package/src/messaging/providers/telegram-bot/send.ts +43 -3
- package/src/messaging/providers/telegram-bot/transport.ts +26 -8
- package/src/permissions/checker.ts +18 -21
- package/src/permissions/confirmation-guardian-request.ts +17 -1
- package/src/permissions/prompter.ts +3 -0
- package/src/persistence/conversation-crud.ts +36 -8
- package/src/persistence/delivery-crud.ts +13 -1
- package/src/persistence/external-conversation-store.ts +22 -0
- package/src/runtime/routes/inbound-conversation.ts +19 -3
- package/src/runtime/routes/inbound-message-handler.ts +8 -5
- package/src/tools/permission-checker.ts +42 -9
- package/src/tools/tool-approval-handler.ts +24 -4
package/ARCHITECTURE.md
CHANGED
|
@@ -1411,12 +1411,15 @@ Editing any file in the root skill or any included child invalidates the transit
|
|
|
1411
1411
|
|
|
1412
1412
|
#### Permission Gating (`skill_load_dynamic:*`)
|
|
1413
1413
|
|
|
1414
|
-
|
|
1414
|
+
Inline-command skill loads are classified **High** risk — in the gateway skill risk classifier (`gateway/src/risk/skill-risk-classifier.ts`), with a defense-in-depth elevation in `check()` for the gateway-unreachable path. The standard auto-approve threshold then governs them like any other high-risk action: they run without a prompt only at **Full access** (`autoApproveUpTo: "high"`) and prompt at every level below it. There is no separate "always ask" override outside the threshold.
|
|
1415
1415
|
|
|
1416
|
-
|
|
1417
|
-
2. `skill_load_dynamic:<skill-id>` — any-version approval
|
|
1416
|
+
These guarantees sit alongside the threshold:
|
|
1418
1417
|
|
|
1419
|
-
A
|
|
1418
|
+
- **Escape hatch (guardian).** A user trust rule that covers the load re-classifies its risk inside the gateway (arriving as matchType `user_rule`), so a guardian's own load runs without prompting at any threshold. (A trust rule does not lift the sensitive-tool capability floor, so a non-guardian actor's covered dynamic load is still escalated to the guardian — like any other sensitive tool.) Approvals are offered in a separate candidate namespace so a pinned rule can auto-approve a known-good version rather than falling through to the permissive default `skill_load:*` allow rule:
|
|
1419
|
+
1. `skill_load_dynamic:<skill-id>@<transitive-hash>` — version-pinned (most specific)
|
|
1420
|
+
2. `skill_load_dynamic:<skill-id>` — any-version
|
|
1421
|
+
- **Guardian-only self-approval (sensitive-tool gate).** An uncovered dynamic load is routed through the sensitive-tool gate (`tools/tool-approval-handler.ts`: `isSensitiveTool` → `resolveSensitiveToolDecision`). A non-guardian actor is escalated to the guardian via the capability floor — which no threshold, including Full access, can lift — while the guardian self-approves (`proceed`) and the threshold then governs (allow at Full access, prompt below). `skill_load` is otherwise not a side-effect tool, so this makes the dynamic case participate in the same capability floor as host/side-effect tools.
|
|
1422
|
+
- **Non-interactive denial.** An uncovered dynamic load in a session with no interactive client is denied outright — regardless of threshold, including Full access — because embedded shell must never run unattended without a covering rule. Enforced in `tools/permission-checker.ts` (lane B) via `isDynamicSkillLoadInvocation`, independent of the threshold decision.
|
|
1420
1423
|
|
|
1421
1424
|
```mermaid
|
|
1422
1425
|
graph TB
|
|
@@ -1429,11 +1432,17 @@ graph TB
|
|
|
1429
1432
|
SOURCE -->|"No (extra)"| FAIL_SOURCE["Fail closed:<br/>source not eligible"]
|
|
1430
1433
|
SOURCE -->|"Yes"| HASH["Compute transitive hash"]
|
|
1431
1434
|
HASH --> DYN["skill_load_dynamic:id@hash<br/>candidate emitted"]
|
|
1432
|
-
DYN --> PERM["PermissionChecker"]
|
|
1433
|
-
PERM --> RULE{"
|
|
1434
|
-
RULE -->|"
|
|
1435
|
-
RULE -->|"No rule"| PROMPT["Prompt guardian"]
|
|
1435
|
+
DYN --> PERM["PermissionChecker<br/>(classified High risk)"]
|
|
1436
|
+
PERM --> RULE{"Covering trust rule?"}
|
|
1437
|
+
RULE -->|"Allow"| RENDER["Execute + render"]
|
|
1436
1438
|
RULE -->|"Deny"| DENY["Blocked"]
|
|
1439
|
+
RULE -->|"None"| SENS{"Sensitive-tool gate<br/>(lane A): can self-approve?"}
|
|
1440
|
+
SENS -->|"No (non-guardian)"| ESCALATE["Escalate to guardian<br/>(capability floor)"]
|
|
1441
|
+
SENS -->|"Yes (guardian)"| INTERACTIVE{"Interactive client?"}
|
|
1442
|
+
INTERACTIVE -->|"No"| DENY
|
|
1443
|
+
INTERACTIVE -->|"Yes"| THRESH{"autoApproveUpTo"}
|
|
1444
|
+
THRESH -->|"Full access"| RENDER
|
|
1445
|
+
THRESH -->|"Below full"| PROMPT["Prompt guardian"]
|
|
1437
1446
|
```
|
|
1438
1447
|
|
|
1439
1448
|
#### Sandbox-Only Execution
|
|
@@ -1484,16 +1493,16 @@ Every layer in the pipeline defaults to rejection rather than silent degradation
|
|
|
1484
1493
|
|
|
1485
1494
|
#### Key Source Files
|
|
1486
1495
|
|
|
1487
|
-
| File | Role
|
|
1488
|
-
| --------------------------------------------------- |
|
|
1489
|
-
| `assistant/src/skills/inline-command-expansions.ts` | `parseInlineCommandExpansions()` — parser for `!`command`` tokens
|
|
1490
|
-
| `assistant/src/skills/inline-command-runner.ts` | `runInlineCommand()` — sandbox-only command executor
|
|
1491
|
-
| `assistant/src/skills/inline-command-render.ts` | `renderInlineCommands()` — token replacement and XML wrapping
|
|
1492
|
-
| `assistant/src/skills/transitive-version-hash.ts` | `computeTransitiveSkillVersionHash()` — hash covering root + included children
|
|
1493
|
-
| `assistant/src/tools/skills/load.ts` | `skill_load` execute path — feature flag check, source check, render integration
|
|
1494
|
-
| `assistant/src/permissions/checker.ts` | `skill_load_dynamic:*` candidate emission
|
|
1495
|
-
| `assistant/src/
|
|
1496
|
-
| `meta/feature-flags/feature-flag-registry.json` | `inline-skill-commands` flag definition
|
|
1496
|
+
| File | Role |
|
|
1497
|
+
| --------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
1498
|
+
| `assistant/src/skills/inline-command-expansions.ts` | `parseInlineCommandExpansions()` — parser for `!`command`` tokens |
|
|
1499
|
+
| `assistant/src/skills/inline-command-runner.ts` | `runInlineCommand()` — sandbox-only command executor |
|
|
1500
|
+
| `assistant/src/skills/inline-command-render.ts` | `renderInlineCommands()` — token replacement and XML wrapping |
|
|
1501
|
+
| `assistant/src/skills/transitive-version-hash.ts` | `computeTransitiveSkillVersionHash()` — hash covering root + included children |
|
|
1502
|
+
| `assistant/src/tools/skills/load.ts` | `skill_load` execute path — feature flag check, source check, render integration |
|
|
1503
|
+
| `assistant/src/permissions/checker.ts` | `skill_load_dynamic:*` candidate emission, allowlist options, High-risk elevation |
|
|
1504
|
+
| `assistant/src/tools/permission-checker.ts` | Non-interactive denial of uncovered dynamic loads (`isDynamicSkillLoadInvocation`) |
|
|
1505
|
+
| `meta/feature-flags/feature-flag-registry.json` | `inline-skill-commands` flag definition |
|
|
1497
1506
|
|
|
1498
1507
|
### Key Source Files
|
|
1499
1508
|
|
|
@@ -2051,10 +2060,10 @@ A parallel **client artifact** (`meta/tts-provider-catalog.json`) captures the s
|
|
|
2051
2060
|
|
|
2052
2061
|
**Config schema (`services.tts`):** The canonical config block lives at `services.tts` in the assistant config. The set of valid provider IDs and provider-specific config objects is catalog-driven — the Zod schema reads from the catalog rather than maintaining a separate hardcoded enum. It contains:
|
|
2053
2062
|
|
|
2054
|
-
| Field | Type | Default | Description
|
|
2055
|
-
| ----------------------------- | ------ | -------------- |
|
|
2063
|
+
| Field | Type | Default | Description |
|
|
2064
|
+
| ----------------------------- | ------ | -------------- | ---------------------------------------------------------------------------------------- |
|
|
2056
2065
|
| `services.tts.provider` | enum | `"elevenlabs"` | Active TTS provider (must be a catalog-known provider ID); `"vellum"` = platform-managed |
|
|
2057
|
-
| `services.tts.providers.<id>` | object | _(defaults)_ | Provider-specific settings, one block per catalog entry
|
|
2066
|
+
| `services.tts.providers.<id>` | object | _(defaults)_ | Provider-specific settings, one block per catalog entry |
|
|
2058
2067
|
|
|
2059
2068
|
Provider-specific config is nested under `services.tts.providers.<id>`. All legacy top-level keys (`elevenlabs.*`, `fishAudio.*`) were removed by workspace migration 032 — only canonical `services.tts` paths are supported at runtime.
|
|
2060
2069
|
|
package/package.json
CHANGED
|
@@ -151,6 +151,147 @@ describe("channel-delivery-store", () => {
|
|
|
151
151
|
expect(r1.conversationId).not.toBe(r2.conversationId);
|
|
152
152
|
});
|
|
153
153
|
|
|
154
|
+
// ── Telegram private-chat topics ──────────────────────────────────
|
|
155
|
+
|
|
156
|
+
test("same Telegram topic reuses the same conversation", () => {
|
|
157
|
+
const r1 = recordInbound("telegram", "chat-9", "msg-1", {
|
|
158
|
+
sourceThreadId: "777",
|
|
159
|
+
});
|
|
160
|
+
const r2 = recordInbound("telegram", "chat-9", "msg-2", {
|
|
161
|
+
sourceThreadId: "777",
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(r1.conversationId).toBe(r2.conversationId);
|
|
165
|
+
expect(
|
|
166
|
+
getConversationByKey("asst:self:telegram:chat-9:thread:777")
|
|
167
|
+
?.conversationId,
|
|
168
|
+
).toBe(r1.conversationId);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test("different Telegram topics in one chat get different conversations", () => {
|
|
172
|
+
const r1 = recordInbound("telegram", "chat-9", "msg-1", {
|
|
173
|
+
sourceThreadId: "777",
|
|
174
|
+
});
|
|
175
|
+
const r2 = recordInbound("telegram", "chat-9", "msg-2", {
|
|
176
|
+
sourceThreadId: "888",
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
expect(r1.conversationId).not.toBe(r2.conversationId);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("a Telegram message without a topic keeps the chat-level base key", () => {
|
|
183
|
+
const result = recordInbound("telegram", "chat-9", "msg-1");
|
|
184
|
+
|
|
185
|
+
expect(
|
|
186
|
+
getConversationByKey("asst:self:telegram:chat-9")?.conversationId,
|
|
187
|
+
).toBe(result.conversationId);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("a Telegram topic starts a fresh conversation; the chat's main conversation stays on the base key", () => {
|
|
191
|
+
const main = recordInbound("telegram", "chat-9", "msg-1");
|
|
192
|
+
const topic = recordInbound("telegram", "chat-9", "msg-2", {
|
|
193
|
+
sourceThreadId: "777",
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
expect(topic.conversationId).not.toBe(main.conversationId);
|
|
197
|
+
expect(
|
|
198
|
+
getConversationByKey("asst:self:telegram:chat-9")?.conversationId,
|
|
199
|
+
).toBe(main.conversationId);
|
|
200
|
+
expect(
|
|
201
|
+
getConversationByKey("asst:self:telegram:chat-9:thread:777")
|
|
202
|
+
?.conversationId,
|
|
203
|
+
).toBe(topic.conversationId);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("thread-less Slack reset clears only the channel-level binding, keeping thread bindings", async () => {
|
|
207
|
+
// Pins the channel-agnostic reset contract for Slack: a channel-root
|
|
208
|
+
// /new must not unbind the channel's thread conversations.
|
|
209
|
+
const db = getDb();
|
|
210
|
+
const now = Date.now();
|
|
211
|
+
for (const id of ["conv-slack-root", "conv-slack-thread"]) {
|
|
212
|
+
db.insert(conversations)
|
|
213
|
+
.values({ id, title: "test", createdAt: now, updatedAt: now })
|
|
214
|
+
.run();
|
|
215
|
+
}
|
|
216
|
+
upsertBinding({
|
|
217
|
+
conversationId: "conv-slack-root",
|
|
218
|
+
sourceChannel: "slack",
|
|
219
|
+
externalChatId: "C0123ABCDEF",
|
|
220
|
+
});
|
|
221
|
+
upsertBinding({
|
|
222
|
+
conversationId: "conv-slack-thread",
|
|
223
|
+
sourceChannel: "slack",
|
|
224
|
+
externalChatId: "C0123ABCDEF",
|
|
225
|
+
externalThreadId: "1710000000.000100",
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const req = new Request("http://localhost/channels/conversation", {
|
|
229
|
+
method: "DELETE",
|
|
230
|
+
headers: { "Content-Type": "application/json" },
|
|
231
|
+
body: JSON.stringify({
|
|
232
|
+
sourceChannel: "slack",
|
|
233
|
+
conversationExternalId: "C0123ABCDEF",
|
|
234
|
+
}),
|
|
235
|
+
});
|
|
236
|
+
const res = await handleDeleteConversation(req);
|
|
237
|
+
expect(res.status).toBe(200);
|
|
238
|
+
|
|
239
|
+
expect(getBindingByChannelChat("slack", "C0123ABCDEF")).toBeNull();
|
|
240
|
+
expect(
|
|
241
|
+
getBindingByChannelChatThread("slack", "C0123ABCDEF", "1710000000.000100")
|
|
242
|
+
?.conversationId,
|
|
243
|
+
).toBe("conv-slack-thread");
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test("thread-less Telegram reset clears only the main-chat binding, keeping topic bindings", async () => {
|
|
247
|
+
const db = getDb();
|
|
248
|
+
const now = Date.now();
|
|
249
|
+
for (const id of ["conv-main", "conv-topic"]) {
|
|
250
|
+
db.insert(conversations)
|
|
251
|
+
.values({ id, title: "test", createdAt: now, updatedAt: now })
|
|
252
|
+
.run();
|
|
253
|
+
}
|
|
254
|
+
setConversationKey("asst:self:telegram:chat-9", "conv-main");
|
|
255
|
+
setConversationKey("telegram:chat-9", "conv-main");
|
|
256
|
+
setConversationKey("asst:self:telegram:chat-9:thread:777", "conv-topic");
|
|
257
|
+
upsertBinding({
|
|
258
|
+
conversationId: "conv-main",
|
|
259
|
+
sourceChannel: "telegram",
|
|
260
|
+
externalChatId: "chat-9",
|
|
261
|
+
});
|
|
262
|
+
upsertBinding({
|
|
263
|
+
conversationId: "conv-topic",
|
|
264
|
+
sourceChannel: "telegram",
|
|
265
|
+
externalChatId: "chat-9",
|
|
266
|
+
externalThreadId: "777",
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const req = new Request("http://localhost/channels/conversation", {
|
|
270
|
+
method: "DELETE",
|
|
271
|
+
headers: { "Content-Type": "application/json" },
|
|
272
|
+
body: JSON.stringify({
|
|
273
|
+
sourceChannel: "telegram",
|
|
274
|
+
conversationExternalId: "chat-9",
|
|
275
|
+
}),
|
|
276
|
+
});
|
|
277
|
+
const res = await handleDeleteConversation(req);
|
|
278
|
+
expect(res.status).toBe(200);
|
|
279
|
+
|
|
280
|
+
// The main-chat keys and binding are gone…
|
|
281
|
+
expect(getConversationByKey("asst:self:telegram:chat-9")).toBeNull();
|
|
282
|
+
expect(getConversationByKey("telegram:chat-9")).toBeNull();
|
|
283
|
+
expect(getBindingByChannelChat("telegram", "chat-9")).toBeNull();
|
|
284
|
+
// …while the topic conversation keeps its key and binding.
|
|
285
|
+
expect(
|
|
286
|
+
getConversationByKey("asst:self:telegram:chat-9:thread:777")
|
|
287
|
+
?.conversationId,
|
|
288
|
+
).toBe("conv-topic");
|
|
289
|
+
expect(
|
|
290
|
+
getBindingByChannelChatThread("telegram", "chat-9", "777")
|
|
291
|
+
?.conversationId,
|
|
292
|
+
).toBe("conv-topic");
|
|
293
|
+
});
|
|
294
|
+
|
|
154
295
|
test("legacy Slack channel key with matching inbound root ts gets aliased to the threaded key", () => {
|
|
155
296
|
const channelId = "C0123ABCDEF";
|
|
156
297
|
const threadTs = "1710000000.000100";
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* silently approved.
|
|
2
|
+
* Inline-command ("dynamic") skill loads execute embedded shell at load time,
|
|
3
|
+
* so an uncovered one (no covering trust rule) is gated before it can run. The
|
|
4
|
+
* non-guardian escalation lives in the sensitive-tool gate (lane A) and is
|
|
5
|
+
* covered by tool-approval-handler.test.ts. This suite covers what the
|
|
6
|
+
* permission checker (lane B) still owns for such loads:
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* - A guardian background session auto-approves ordinary prompted tools within
|
|
9
|
+
* the background threshold, but an uncovered dynamic load is denied — no
|
|
10
|
+
* human is present to review embedded shell — at any threshold.
|
|
11
|
+
* - A guardian interactive session self-approves within its threshold (allow at
|
|
12
|
+
* Full access); a plain (non-dynamic) load is untouched by the gate.
|
|
13
|
+
*
|
|
14
|
+
* The gate keys off `isDynamicSkillLoadInvocation` from permissions/checker.js
|
|
15
|
+
* (resolved skill metadata).
|
|
12
16
|
*/
|
|
13
17
|
|
|
14
18
|
import { afterAll, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
@@ -25,17 +29,26 @@ const fakeToolResult: ToolExecutionResult = { content: "ok", isError: false };
|
|
|
25
29
|
/** Controls what isDynamicSkillLoadInvocation reports for the invocation. */
|
|
26
30
|
let dynamicSkillLoad = false;
|
|
27
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Controls the decision check() returns. The non-interactive dynamic-load guard
|
|
34
|
+
* is orthogonal to the threshold, so it must deny whether check() resolved to a
|
|
35
|
+
* "prompt" (background threshold below High) or an "allow" (background threshold
|
|
36
|
+
* at Full access).
|
|
37
|
+
*/
|
|
38
|
+
let checkDecision = "prompt";
|
|
39
|
+
|
|
28
40
|
mock.module("../permissions/channel-permission-query.js", () => ({
|
|
29
41
|
buildChannelPermissionCellQuery: () => undefined,
|
|
30
42
|
}));
|
|
31
43
|
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
44
|
+
// The scenario under test is "no trust rule covers this load" (a covering rule
|
|
45
|
+
// lowers the classified risk upstream and arrives as matchType "user_rule",
|
|
46
|
+
// which the guard exempts). check()'s decision is variable so both the
|
|
47
|
+
// below-Full (prompt) and Full-access (allow) background cases are exercised.
|
|
35
48
|
mock.module("../permissions/checker.js", () => ({
|
|
36
49
|
isDynamicSkillLoadInvocation: () => dynamicSkillLoad,
|
|
37
50
|
classifyRisk: async () => ({ level: "medium" }),
|
|
38
|
-
check: async () => ({ decision:
|
|
51
|
+
check: async () => ({ decision: checkDecision, reason: "medium risk" }),
|
|
39
52
|
generateAllowlistOptions: () => [],
|
|
40
53
|
generateScopeOptions: () => [],
|
|
41
54
|
getCachedAssessment: () => undefined,
|
|
@@ -115,8 +128,48 @@ async function checkSkillLoad(skill: string) {
|
|
|
115
128
|
);
|
|
116
129
|
}
|
|
117
130
|
|
|
131
|
+
function makeInteractiveContext(
|
|
132
|
+
trustClass: ToolContext["trustClass"],
|
|
133
|
+
): ToolContext {
|
|
134
|
+
return {
|
|
135
|
+
workingDir: "/tmp/project",
|
|
136
|
+
conversationId: "conversation-1",
|
|
137
|
+
trustClass,
|
|
138
|
+
isInteractive: true,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A prompter that records whether it was reached and resolves to `decision`. */
|
|
143
|
+
function makeRecordingPrompter(decision: "allow" | "deny") {
|
|
144
|
+
let called = false;
|
|
145
|
+
const prompter = {
|
|
146
|
+
prompt: async () => {
|
|
147
|
+
called = true;
|
|
148
|
+
return { decision };
|
|
149
|
+
},
|
|
150
|
+
} as unknown as PermissionPrompter;
|
|
151
|
+
return { prompter, wasCalled: () => called };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function checkSkillLoadWith(
|
|
155
|
+
prompter: PermissionPrompter,
|
|
156
|
+
context: ToolContext,
|
|
157
|
+
skill: string,
|
|
158
|
+
) {
|
|
159
|
+
const checker = new PermissionChecker(prompter);
|
|
160
|
+
return checker.checkPermission(
|
|
161
|
+
"skill_load",
|
|
162
|
+
{ skill },
|
|
163
|
+
skillLoadTool,
|
|
164
|
+
context,
|
|
165
|
+
Date.now(),
|
|
166
|
+
() => undefined,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
118
170
|
beforeEach(() => {
|
|
119
171
|
dynamicSkillLoad = false;
|
|
172
|
+
checkDecision = "prompt";
|
|
120
173
|
});
|
|
121
174
|
|
|
122
175
|
afterAll(() => {
|
|
@@ -136,4 +189,40 @@ describe("non-interactive guardian background auto-approve", () => {
|
|
|
136
189
|
expect(decision.allowed).toBe(false);
|
|
137
190
|
expect(decision.decision).toBe("denied");
|
|
138
191
|
});
|
|
192
|
+
|
|
193
|
+
test("a dynamic skill load is denied even when check() allows it (Full-access background)", async () => {
|
|
194
|
+
dynamicSkillLoad = true;
|
|
195
|
+
checkDecision = "allow";
|
|
196
|
+
const decision = await checkSkillLoad("inline-command-skill");
|
|
197
|
+
expect(decision.allowed).toBe(false);
|
|
198
|
+
expect(decision.decision).toBe("denied");
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("interactive self-approval gate", () => {
|
|
203
|
+
test("a guardian at Full access self-approves an uncovered dynamic load without prompting", async () => {
|
|
204
|
+
dynamicSkillLoad = true;
|
|
205
|
+
checkDecision = "allow"; // Full access → check() allows
|
|
206
|
+
const { prompter, wasCalled } = makeRecordingPrompter("deny");
|
|
207
|
+
const decision = await checkSkillLoadWith(
|
|
208
|
+
prompter,
|
|
209
|
+
makeInteractiveContext("guardian"),
|
|
210
|
+
"inline-command-skill",
|
|
211
|
+
);
|
|
212
|
+
expect(decision.allowed).toBe(true);
|
|
213
|
+
expect(wasCalled()).toBe(false); // no escalation — the guardian self-approves
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("a non-guardian plain (non-dynamic) skill load is unaffected by the gate", async () => {
|
|
217
|
+
dynamicSkillLoad = false;
|
|
218
|
+
checkDecision = "allow";
|
|
219
|
+
const { prompter, wasCalled } = makeRecordingPrompter("deny");
|
|
220
|
+
const decision = await checkSkillLoadWith(
|
|
221
|
+
prompter,
|
|
222
|
+
makeInteractiveContext("trusted_contact"),
|
|
223
|
+
"plain-skill",
|
|
224
|
+
);
|
|
225
|
+
expect(decision.allowed).toBe(true); // check()'s allow stands; gate skipped
|
|
226
|
+
expect(wasCalled()).toBe(false);
|
|
227
|
+
});
|
|
139
228
|
});
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
* 1. Emit skill_load_dynamic:<id>@<hash> / skill_load_dynamic:<id> candidates
|
|
8
8
|
* instead of skill_load:<id>@<hash> / skill_load:<id>.
|
|
9
|
-
* 2.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* 2. Classify the load as High risk so the auto-approve threshold governs it
|
|
10
|
+
* like any other high-risk action: it prompts below Full access and runs at
|
|
11
|
+
* Full access — unless a user trust rule covers it (gateway matchType
|
|
12
|
+
* "user_rule" lowers the risk, restoring the escape hatch).
|
|
12
13
|
* 3. Continue matching the existing skill_load:* flow for non-dynamic skills.
|
|
13
14
|
*/
|
|
14
15
|
|
|
@@ -111,18 +112,40 @@ describe("inline-command skill_load permissions", () => {
|
|
|
111
112
|
|
|
112
113
|
// ── Default behavior ─────────────────────────────────────────────────
|
|
113
114
|
|
|
114
|
-
describe("
|
|
115
|
-
test("an uncovered dynamic skill prompts
|
|
115
|
+
describe("threshold-governed prompting", () => {
|
|
116
|
+
test("an uncovered dynamic skill prompts below Full access", async () => {
|
|
116
117
|
ensureSkillsDir();
|
|
117
118
|
writeDynamicSkill("dynamic-prompt", "Dynamic Prompt Skill");
|
|
118
119
|
|
|
120
|
+
// interactive threshold "low" (beforeEach) is below the High risk of an
|
|
121
|
+
// inline-command load, so it prompts.
|
|
119
122
|
const result = await check(
|
|
120
123
|
"skill_load",
|
|
121
124
|
{ skill: "dynamic-prompt" },
|
|
122
125
|
"/tmp",
|
|
123
126
|
);
|
|
124
127
|
expect(result.decision).toBe("prompt");
|
|
125
|
-
expect(result.reason).toContain("
|
|
128
|
+
expect(result.reason).toContain("above auto-approve threshold");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("an uncovered dynamic skill runs at Full access (high threshold)", async () => {
|
|
132
|
+
ensureSkillsDir();
|
|
133
|
+
writeDynamicSkill("dynamic-full", "Dynamic Full Access Skill");
|
|
134
|
+
mockIpcResponse("get_global_thresholds", {
|
|
135
|
+
interactive: "high",
|
|
136
|
+
autonomous: "high",
|
|
137
|
+
headless: "high",
|
|
138
|
+
});
|
|
139
|
+
_clearGlobalCacheForTesting();
|
|
140
|
+
|
|
141
|
+
// Full access auto-approves High-risk actions — inline-command skill
|
|
142
|
+
// loads included. No special-case override forces a prompt.
|
|
143
|
+
const result = await check(
|
|
144
|
+
"skill_load",
|
|
145
|
+
{ skill: "dynamic-full" },
|
|
146
|
+
"/tmp",
|
|
147
|
+
);
|
|
148
|
+
expect(result.decision).toBe("allow");
|
|
126
149
|
});
|
|
127
150
|
|
|
128
151
|
test("a dynamic skill covered by a user trust rule is allowed", async () => {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression: `recordConversationPersistedSeq` must not throw on transient
|
|
3
|
+
* SQLite write contention.
|
|
4
|
+
*
|
|
5
|
+
* The persisted-seq anchor is written from the agent loop as fire-and-forget
|
|
6
|
+
* bookkeeping (`flushAccumulatedContent`, `handleMessageComplete`, tool
|
|
7
|
+
* events). Before this resilience layer the write went through a bare
|
|
8
|
+
* `rawRun`, so a `SQLITE_BUSY` ("database is locked") threw raw: on the
|
|
9
|
+
* debounced partial-flush path it surfaced as an unhandled promise rejection,
|
|
10
|
+
* and on the `message_complete` path it hit `dispatchAgentEvent`'s re-throw
|
|
11
|
+
* allowlist — either one tripped the daemon's fail-fast shutdown and crashed
|
|
12
|
+
* the process.
|
|
13
|
+
*
|
|
14
|
+
* These tests pin the two guarantees:
|
|
15
|
+
* 1. A retryable `SQLITE_BUSY` is swallowed (the anchor simply does not
|
|
16
|
+
* advance) and self-heals on the next successful record.
|
|
17
|
+
* 2. A non-retryable error (a genuine bug) still propagates.
|
|
18
|
+
*/
|
|
19
|
+
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
20
|
+
|
|
21
|
+
// Wrap the real raw-query module so the persisted-seq UPDATE can be made to
|
|
22
|
+
// throw on demand while every other DB call (createConversation, the read-back
|
|
23
|
+
// via `rawGet`) keeps hitting the real database.
|
|
24
|
+
//
|
|
25
|
+
// Destructure the real exports into stable locals BEFORE registering the mock:
|
|
26
|
+
// `mock.module` mutates the live module namespace in place, so reading
|
|
27
|
+
// `actualRawQuery.rawRun` from inside the factory would re-resolve to the mock
|
|
28
|
+
// and recurse forever. The captured `realRawRun` const is immune to that swap.
|
|
29
|
+
const actualRawQuery = await import("../persistence/raw-query.js");
|
|
30
|
+
const realRawRun = actualRawQuery.rawRun;
|
|
31
|
+
|
|
32
|
+
let injectedRecordError: Error | null = null;
|
|
33
|
+
|
|
34
|
+
mock.module("../persistence/raw-query.js", () => ({
|
|
35
|
+
...actualRawQuery,
|
|
36
|
+
rawRun: (label: string, sql: string, ...params: unknown[]): number => {
|
|
37
|
+
if (label === "conversation:recordPersistedSeq" && injectedRecordError) {
|
|
38
|
+
throw injectedRecordError;
|
|
39
|
+
}
|
|
40
|
+
return (realRawRun as (...a: unknown[]) => number)(label, sql, ...params);
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
import {
|
|
45
|
+
createConversation,
|
|
46
|
+
getConversationPersistedSeq,
|
|
47
|
+
recordConversationPersistedSeq,
|
|
48
|
+
} from "../persistence/conversation-crud.js";
|
|
49
|
+
import { initializeDb } from "../persistence/db-init.js";
|
|
50
|
+
|
|
51
|
+
await initializeDb();
|
|
52
|
+
|
|
53
|
+
function sqliteError(code: string): Error {
|
|
54
|
+
return Object.assign(new Error("database is locked"), { code });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe("recordConversationPersistedSeq write-contention resilience", () => {
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
injectedRecordError = null;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("swallows a transient SQLITE_BUSY and self-heals on the next record", () => {
|
|
63
|
+
// GIVEN a conversation with a recorded baseline anchor
|
|
64
|
+
const conv = createConversation();
|
|
65
|
+
recordConversationPersistedSeq(conv.id, 10);
|
|
66
|
+
expect(getConversationPersistedSeq(conv.id)).toBe(10);
|
|
67
|
+
|
|
68
|
+
// WHEN the anchor-advancing write loses the write-lock race
|
|
69
|
+
injectedRecordError = sqliteError("SQLITE_BUSY");
|
|
70
|
+
expect(() => recordConversationPersistedSeq(conv.id, 20)).not.toThrow();
|
|
71
|
+
|
|
72
|
+
// THEN the anchor is simply left un-advanced (no crash, no regression) ...
|
|
73
|
+
expect(getConversationPersistedSeq(conv.id)).toBe(10);
|
|
74
|
+
|
|
75
|
+
// ... and the next contention-free record advances it (self-healing).
|
|
76
|
+
injectedRecordError = null;
|
|
77
|
+
recordConversationPersistedSeq(conv.id, 20);
|
|
78
|
+
expect(getConversationPersistedSeq(conv.id)).toBe(20);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("swallows the extended-result-code SQLITE_BUSY_SNAPSHOT too", () => {
|
|
82
|
+
const conv = createConversation();
|
|
83
|
+
injectedRecordError = sqliteError("SQLITE_BUSY_SNAPSHOT");
|
|
84
|
+
expect(() => recordConversationPersistedSeq(conv.id, 5)).not.toThrow();
|
|
85
|
+
expect(getConversationPersistedSeq(conv.id)).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("rethrows a non-retryable SQLite error (a genuine bug)", () => {
|
|
89
|
+
const conv = createConversation();
|
|
90
|
+
injectedRecordError = sqliteError("SQLITE_ERROR");
|
|
91
|
+
expect(() => recordConversationPersistedSeq(conv.id, 5)).toThrow(
|
|
92
|
+
"database is locked",
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -28,6 +28,16 @@ mock.module("../tools/registry.js", () => ({
|
|
|
28
28
|
getAllTools: () => [fakeTool],
|
|
29
29
|
}));
|
|
30
30
|
|
|
31
|
+
// Mock the dynamic-skill predicate so isSensitiveTool's skill_load branch is
|
|
32
|
+
// exercised without a real skill catalog: "dynamic-skill" is an inline-command
|
|
33
|
+
// load, anything else is plain.
|
|
34
|
+
mock.module("../permissions/checker.js", () => ({
|
|
35
|
+
isDynamicSkillLoadInvocation: (
|
|
36
|
+
_name: string,
|
|
37
|
+
input: Record<string, unknown>,
|
|
38
|
+
) => input?.skill === "dynamic-skill",
|
|
39
|
+
}));
|
|
40
|
+
|
|
31
41
|
// Capture tool-audit terminal calls so tests can assert on denied/error outcomes
|
|
32
42
|
// the way they previously asserted on emitted lifecycle events.
|
|
33
43
|
const auditCalls = {
|
|
@@ -519,7 +529,7 @@ describe("ToolApprovalHandler / pre-exec gate grant check", () => {
|
|
|
519
529
|
});
|
|
520
530
|
|
|
521
531
|
describe("isSensitiveTool", () => {
|
|
522
|
-
test("sensitivity is a property of the tool and execution target
|
|
532
|
+
test("sensitivity is a property of the tool and execution target", () => {
|
|
523
533
|
// Side-effect tools are sensitive wherever they run.
|
|
524
534
|
expect(isSensitiveTool("bash", "sandbox")).toBe(true);
|
|
525
535
|
expect(isSensitiveTool("file_write", "sandbox")).toBe(true);
|
|
@@ -531,6 +541,20 @@ describe("isSensitiveTool", () => {
|
|
|
531
541
|
expect(isSensitiveTool("ui_update", "host")).toBe(false);
|
|
532
542
|
expect(isSensitiveTool("ui_dismiss", "host")).toBe(false);
|
|
533
543
|
});
|
|
544
|
+
|
|
545
|
+
test("an inline-command (dynamic) skill_load is sensitive; a plain one is not", () => {
|
|
546
|
+
// skill_load is not a side-effect tool, but a load that executes embedded
|
|
547
|
+
// shell at load time must pass through the capability floor — so a
|
|
548
|
+
// non-guardian's dynamic load escalates to the guardian, Full-access-proof.
|
|
549
|
+
expect(
|
|
550
|
+
isSensitiveTool("skill_load", "sandbox", { skill: "dynamic-skill" }),
|
|
551
|
+
).toBe(true);
|
|
552
|
+
expect(
|
|
553
|
+
isSensitiveTool("skill_load", "sandbox", { skill: "plain-skill" }),
|
|
554
|
+
).toBe(false);
|
|
555
|
+
// Without input, skill_load falls back to the name/target rule.
|
|
556
|
+
expect(isSensitiveTool("skill_load", "sandbox")).toBe(false);
|
|
557
|
+
});
|
|
534
558
|
});
|
|
535
559
|
|
|
536
560
|
describe("resolveSensitiveToolDecision / CapabilitySet floor invariant", () => {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `bookmark.created` SSE event.
|
|
3
|
+
*
|
|
4
|
+
* Server → client broadcast emitted after a bookmark is created, so a
|
|
5
|
+
* `BookmarkStore` in any other connected client refreshes in lock-step.
|
|
6
|
+
* Carries the full `BookmarkSummary` for the new bookmark.
|
|
7
|
+
*
|
|
8
|
+
* Canonical wire-contract source. Daemon code imports the type
|
|
9
|
+
* directly from this file; external consumers import via
|
|
10
|
+
* `@vellumai/assistant-api`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
/** Summary row for a saved message, as surfaced to clients. */
|
|
16
|
+
export const BookmarkSummarySchema = z.object({
|
|
17
|
+
id: z.string(),
|
|
18
|
+
messageId: z.string(),
|
|
19
|
+
conversationId: z.string(),
|
|
20
|
+
conversationTitle: z.string().nullable(),
|
|
21
|
+
messagePreview: z.string(),
|
|
22
|
+
/** "user" | "assistant" — kept free-form so it round-trips raw. */
|
|
23
|
+
messageRole: z.string(),
|
|
24
|
+
/** Unix milliseconds. */
|
|
25
|
+
messageCreatedAt: z.number(),
|
|
26
|
+
/** Unix milliseconds. */
|
|
27
|
+
createdAt: z.number(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export type BookmarkSummary = z.infer<typeof BookmarkSummarySchema>;
|
|
31
|
+
|
|
32
|
+
export const BookmarkCreatedEventSchema = z.object({
|
|
33
|
+
type: z.literal("bookmark.created"),
|
|
34
|
+
bookmark: BookmarkSummarySchema,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export type BookmarkCreatedEvent = z.infer<typeof BookmarkCreatedEventSchema>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `bookmark.deleted` SSE event.
|
|
3
|
+
*
|
|
4
|
+
* Server → client broadcast emitted after a bookmark is removed, so a
|
|
5
|
+
* `BookmarkStore` in any other connected client drops it in lock-step.
|
|
6
|
+
* Identifies the bookmark by the `messageId` it was anchored to.
|
|
7
|
+
*
|
|
8
|
+
* Canonical wire-contract source. Daemon code imports the type
|
|
9
|
+
* directly from this file; external consumers import via
|
|
10
|
+
* `@vellumai/assistant-api`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
export const BookmarkDeletedEventSchema = z.object({
|
|
16
|
+
type: z.literal("bookmark.deleted"),
|
|
17
|
+
messageId: z.string(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type BookmarkDeletedEvent = z.infer<typeof BookmarkDeletedEventSchema>;
|