@vellumai/assistant 0.10.6-dev.202607062330.7613445 → 0.10.6-dev.202607070055.e6ecf41
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/package.json +1 -1
- package/src/__tests__/agent-loop-override-profile.test.ts +1 -1
- package/src/__tests__/conversation-lifecycle.test.ts +25 -3
- package/src/__tests__/persistence-layering-guard.test.ts +5 -5
- package/src/__tests__/schedule-retry.test.ts +8 -0
- package/src/__tests__/scheduler-recurrence.test.ts +8 -0
- package/src/__tests__/scheduler-reuse-conversation.test.ts +8 -0
- package/src/__tests__/scheduler-wake.test.ts +8 -0
- package/src/__tests__/subagent-call-site-routing.test.ts +1 -1
- package/src/__tests__/subagent-fork-prompt-role.test.ts +1 -1
- package/src/__tests__/subagent-notify-parent.test.ts +124 -137
- package/src/__tests__/subagent-spawn-and-await.test.ts +1 -1
- package/src/__tests__/task-scheduler.test.ts +8 -0
- package/src/__tests__/telephony-tts-guard.test.ts +142 -2
- package/src/calls/call-controller.ts +34 -66
- package/src/calls/call-speech-output.ts +58 -45
- package/src/calls/media-stream-stt-session.ts +2 -3
- package/src/config/feature-flag-registry.json +8 -0
- package/src/config/schemas/memory-lifecycle.ts +2 -2
- package/src/config/schemas/schedules.ts +2 -2
- package/src/daemon/conversation.ts +21 -3
- package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +26 -0
- package/src/live-voice/__tests__/live-voice-events.test.ts +16 -25
- package/src/live-voice/__tests__/live-voice-integration.test.ts +194 -3
- package/src/live-voice/__tests__/live-voice-metrics.test.ts +74 -0
- package/src/live-voice/__tests__/live-voice-stt.test.ts +274 -0
- package/src/live-voice/__tests__/live-voice-tts-session.test.ts +60 -0
- package/src/live-voice/__tests__/live-voice-tts.test.ts +44 -0
- package/src/live-voice/__tests__/live-voice-vad.test.ts +1039 -0
- package/src/live-voice/__tests__/protocol.test.ts +227 -0
- package/src/live-voice/live-voice-metrics.ts +91 -2
- package/src/live-voice/live-voice-session.ts +751 -158
- package/src/live-voice/live-voice-tts.ts +26 -16
- package/src/live-voice/protocol.ts +95 -0
- package/src/persistence/conversation-crud.ts +2 -2
- package/src/persistence/subagent-store.ts +19 -1
- package/src/plugins/defaults/memory/fork-conversation-memory.ts +128 -0
- package/src/plugins/defaults/memory/jobs-worker.ts +3 -2
- package/src/plugins/defaults/memory/pkb-schedule.ts +2 -3
- package/src/stt/__tests__/speech-energy.test.ts +68 -0
- package/src/stt/speech-energy.ts +49 -0
- package/src/subagent/manager.ts +79 -128
- package/src/subagent/notify.ts +114 -0
- package/src/tools/subagent/notify-parent.ts +2 -3
- package/src/tts/__tests__/synthesis-stream.test.ts +805 -0
- package/src/tts/synthesis-stream.ts +259 -0
- package/src/plugins/defaults/memory/persistence-hooks.ts +0 -127
package/package.json
CHANGED
|
@@ -128,7 +128,10 @@ mock.module("../plugins/defaults/memory/v3/ever-injected-store.js", () => ({
|
|
|
128
128
|
: realEverInjectedStore.getPrunedSlugs(conversationId),
|
|
129
129
|
}));
|
|
130
130
|
|
|
131
|
-
import {
|
|
131
|
+
import {
|
|
132
|
+
Conversation,
|
|
133
|
+
type ConversationConstructorOptions,
|
|
134
|
+
} from "../daemon/conversation.js";
|
|
132
135
|
|
|
133
136
|
beforeEach(() => {
|
|
134
137
|
lifecycleStoreMockActive = true;
|
|
@@ -139,7 +142,9 @@ afterAll(() => {
|
|
|
139
142
|
lifecycleStoreMockActive = false;
|
|
140
143
|
});
|
|
141
144
|
|
|
142
|
-
function makeConversation(
|
|
145
|
+
function makeConversation(
|
|
146
|
+
options: ConversationConstructorOptions = { maxTokens: 4096 },
|
|
147
|
+
): Conversation {
|
|
143
148
|
const provider = {
|
|
144
149
|
name: "mock",
|
|
145
150
|
sendMessage: async () => ({
|
|
@@ -155,7 +160,7 @@ function makeConversation(): Conversation {
|
|
|
155
160
|
"system prompt",
|
|
156
161
|
() => {},
|
|
157
162
|
"/tmp",
|
|
158
|
-
|
|
163
|
+
options,
|
|
159
164
|
);
|
|
160
165
|
// Default to guardian trust so tests load all messages.
|
|
161
166
|
conv.setTrustContext({ trustClass: "guardian", sourceChannel: "vellum" });
|
|
@@ -173,6 +178,23 @@ function defaultConv() {
|
|
|
173
178
|
};
|
|
174
179
|
}
|
|
175
180
|
|
|
181
|
+
describe("Conversation — subagent identity", () => {
|
|
182
|
+
test("is not a subagent by default", () => {
|
|
183
|
+
const conv = makeConversation();
|
|
184
|
+
expect(conv.parentConversationId).toBeUndefined();
|
|
185
|
+
expect(conv.isSubagent).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("derives isSubagent from the constructor parentConversationId", () => {
|
|
189
|
+
const conv = makeConversation({
|
|
190
|
+
maxTokens: 4096,
|
|
191
|
+
parentConversationId: "parent-1",
|
|
192
|
+
});
|
|
193
|
+
expect(conv.parentConversationId).toBe("parent-1");
|
|
194
|
+
expect(conv.isSubagent).toBe(true);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
176
198
|
describe("loadFromDb metadata injection rehydration", () => {
|
|
177
199
|
beforeEach(() => {
|
|
178
200
|
nextMockMessageId = 1;
|
|
@@ -42,10 +42,10 @@ const MEMORY_DIR = join(ASSISTANT_SRC, "plugins", "defaults", "memory");
|
|
|
42
42
|
* plan.
|
|
43
43
|
*
|
|
44
44
|
* Current entries, both on the conversation write paths:
|
|
45
|
-
* - `
|
|
46
|
-
* synchronously inside the fork transaction (see the module
|
|
47
|
-
* why it
|
|
48
|
-
*
|
|
45
|
+
* - `fork-conversation-memory` — the memory plugin's fork-time state carry,
|
|
46
|
+
* invoked synchronously inside the fork transaction (see the module
|
|
47
|
+
* docstring for why it is a direct call rather than a first-class `hooks`
|
|
48
|
+
* dispatch like the other lifecycle events).
|
|
49
49
|
* - `indexer` — the plain `addMessage` path invokes `indexMessageNow` to feed
|
|
50
50
|
* the persisted message into memory segment indexing, matching the other
|
|
51
51
|
* (non-persistence) write seams that already call it directly.
|
|
@@ -55,7 +55,7 @@ const MEMORY_DIR = join(ASSISTANT_SRC, "plugins", "defaults", "memory");
|
|
|
55
55
|
*/
|
|
56
56
|
const PERSISTENCE_TO_MEMORY_ALLOWLIST: Record<string, ReadonlySet<string>> = {
|
|
57
57
|
"assistant/src/persistence/conversation-crud.ts": new Set([
|
|
58
|
-
"
|
|
58
|
+
"fork-conversation-memory",
|
|
59
59
|
"indexer",
|
|
60
60
|
]),
|
|
61
61
|
};
|
|
@@ -64,6 +64,7 @@ mock.module("../notifications/emit-signal.js", () => ({
|
|
|
64
64
|
emitNotificationSignalImpl(payload),
|
|
65
65
|
}));
|
|
66
66
|
|
|
67
|
+
import { loadRawConfig, saveRawConfig } from "../config/loader.js";
|
|
67
68
|
import { getDb } from "../persistence/db-connection.js";
|
|
68
69
|
import { initializeDb } from "../persistence/db-init.js";
|
|
69
70
|
import { applyRetryDecision, decideRetry } from "../schedule/retry-policy.js";
|
|
@@ -104,6 +105,13 @@ function startScheduler(
|
|
|
104
105
|
|
|
105
106
|
await initializeDb();
|
|
106
107
|
|
|
108
|
+
// The schedule worker is on by default, which stands the daemon's in-process
|
|
109
|
+
// scheduler down. These tests exercise that in-process execution path directly,
|
|
110
|
+
// so pin the worker flag off for this test process.
|
|
111
|
+
const rawConfig = loadRawConfig();
|
|
112
|
+
rawConfig.schedules = { worker: { enabled: false } };
|
|
113
|
+
saveRawConfig(rawConfig);
|
|
114
|
+
|
|
107
115
|
/** Access the underlying bun:sqlite Database for raw parameterized queries. */
|
|
108
116
|
function getRawDb(): import("bun:sqlite").Database {
|
|
109
117
|
return (getDb() as unknown as { $client: import("bun:sqlite").Database })
|
|
@@ -69,6 +69,7 @@ mock.module("../notifications/emit-signal.js", () => ({
|
|
|
69
69
|
},
|
|
70
70
|
}));
|
|
71
71
|
|
|
72
|
+
import { loadRawConfig, saveRawConfig } from "../config/loader.js";
|
|
72
73
|
import { getDb } from "../persistence/db-connection.js";
|
|
73
74
|
import { initializeDb } from "../persistence/db-init.js";
|
|
74
75
|
import {
|
|
@@ -81,6 +82,13 @@ import { createTask } from "../tasks/task-store.js";
|
|
|
81
82
|
|
|
82
83
|
await initializeDb();
|
|
83
84
|
|
|
85
|
+
// The schedule worker is on by default, which stands the daemon's in-process
|
|
86
|
+
// scheduler down. These tests exercise that in-process execution path directly,
|
|
87
|
+
// so pin the worker flag off for this test process.
|
|
88
|
+
const rawConfig = loadRawConfig();
|
|
89
|
+
rawConfig.schedules = { worker: { enabled: false } };
|
|
90
|
+
saveRawConfig(rawConfig);
|
|
91
|
+
|
|
84
92
|
/** Access the underlying bun:sqlite Database for raw parameterized queries. */
|
|
85
93
|
function getRawDb(): import("bun:sqlite").Database {
|
|
86
94
|
return (getDb() as unknown as { $client: import("bun:sqlite").Database })
|
|
@@ -104,6 +104,7 @@ mock.module("../daemon/process-message.js", () => ({
|
|
|
104
104
|
processMessageImpl(conversationId, message),
|
|
105
105
|
}));
|
|
106
106
|
|
|
107
|
+
import { loadRawConfig, saveRawConfig } from "../config/loader.js";
|
|
107
108
|
import { deleteConversation } from "../persistence/conversation-crud.js";
|
|
108
109
|
import { getDb } from "../persistence/db-connection.js";
|
|
109
110
|
import { initializeDb } from "../persistence/db-init.js";
|
|
@@ -113,6 +114,13 @@ import { startScheduler } from "../schedule/scheduler.js";
|
|
|
113
114
|
|
|
114
115
|
await initializeDb();
|
|
115
116
|
|
|
117
|
+
// The schedule worker is on by default, which stands the daemon's in-process
|
|
118
|
+
// scheduler down. These tests exercise that in-process execution path directly,
|
|
119
|
+
// so pin the worker flag off for this test process.
|
|
120
|
+
const rawConfig = loadRawConfig();
|
|
121
|
+
rawConfig.schedules = { worker: { enabled: false } };
|
|
122
|
+
saveRawConfig(rawConfig);
|
|
123
|
+
|
|
116
124
|
/** Access the underlying bun:sqlite Database for raw parameterized queries. */
|
|
117
125
|
function getRawDb(): import("bun:sqlite").Database {
|
|
118
126
|
return (getDb() as unknown as { $client: import("bun:sqlite").Database })
|
|
@@ -32,6 +32,7 @@ mock.module("../daemon/process-message.js", () => ({
|
|
|
32
32
|
processMessage: mockProcessMessage,
|
|
33
33
|
}));
|
|
34
34
|
|
|
35
|
+
import { loadRawConfig, saveRawConfig } from "../config/loader.js";
|
|
35
36
|
import { getDb } from "../persistence/db-connection.js";
|
|
36
37
|
import { initializeDb } from "../persistence/db-init.js";
|
|
37
38
|
import { createSchedule } from "../schedule/schedule-store.js";
|
|
@@ -39,6 +40,13 @@ import { startScheduler } from "../schedule/scheduler.js";
|
|
|
39
40
|
|
|
40
41
|
await initializeDb();
|
|
41
42
|
|
|
43
|
+
// The schedule worker is on by default, which stands the daemon's in-process
|
|
44
|
+
// scheduler down. These tests exercise that in-process execution path directly,
|
|
45
|
+
// so pin the worker flag off for this test process.
|
|
46
|
+
const rawConfig = loadRawConfig();
|
|
47
|
+
rawConfig.schedules = { worker: { enabled: false } };
|
|
48
|
+
saveRawConfig(rawConfig);
|
|
49
|
+
|
|
42
50
|
/** Access the underlying bun:sqlite Database for raw parameterized queries. */
|
|
43
51
|
function getRawDb(): import("bun:sqlite").Database {
|
|
44
52
|
return (getDb() as unknown as { $client: import("bun:sqlite").Database })
|
|
@@ -38,15 +38,41 @@ mock.module("../persistence/conversation-crud.js", () => ({
|
|
|
38
38
|
*/
|
|
39
39
|
const capturedMessages: string[] = [];
|
|
40
40
|
|
|
41
|
+
/** Parent conversation ids that a notification was routed to (findConversation). */
|
|
42
|
+
const capturedParentIds: string[] = [];
|
|
43
|
+
|
|
44
|
+
// Live subagent conversations, keyed by conversationId. notifyParentFromChild
|
|
45
|
+
// routes to the parent recorded here (the non-writable in-process source), so
|
|
46
|
+
// tests register a child before expecting a notification to route.
|
|
47
|
+
const liveSubagents = new Map<string, { parentConversationId: string }>();
|
|
48
|
+
|
|
41
49
|
mock.module("../daemon/conversation-registry.js", () => ({
|
|
42
|
-
findConversation: (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
findConversation: (id: string) => {
|
|
51
|
+
capturedParentIds.push(id);
|
|
52
|
+
return {
|
|
53
|
+
enqueueMessage: (options: { content: string }) => {
|
|
54
|
+
capturedMessages.push(options.content);
|
|
55
|
+
return { queued: true };
|
|
56
|
+
},
|
|
57
|
+
persistUserMessage: async () => ({ id: "mock-msg", deduplicated: false }),
|
|
58
|
+
runAgentLoop: async () => {},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
findConversationOrSubagent: (id: string) => {
|
|
62
|
+
const live = liveSubagents.get(id);
|
|
63
|
+
return live
|
|
64
|
+
? { parentConversationId: live.parentConversationId }
|
|
65
|
+
: undefined;
|
|
66
|
+
},
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
// notifyParentFromChild reads cosmetic label/fork/objective from the durable
|
|
70
|
+
// record. Routing does NOT come from here (see liveSubagents above), so a
|
|
71
|
+
// tampered record can only mislabel, never redirect.
|
|
72
|
+
const records = new Map<string, SubagentRecord>();
|
|
73
|
+
mock.module("../persistence/subagent-store.js", () => ({
|
|
74
|
+
getSubagentRecordByConversationId: (conversationId: string) =>
|
|
75
|
+
records.get(conversationId),
|
|
50
76
|
}));
|
|
51
77
|
|
|
52
78
|
mock.module("../runtime/assistant-event-hub.js", () => ({
|
|
@@ -54,9 +80,8 @@ mock.module("../runtime/assistant-event-hub.js", () => ({
|
|
|
54
80
|
}));
|
|
55
81
|
|
|
56
82
|
import { isToolActiveForContext } from "../daemon/conversation-tool-setup.js";
|
|
57
|
-
import {
|
|
58
|
-
import {
|
|
59
|
-
import type { SubagentState } from "../subagent/types.js";
|
|
83
|
+
import type { SubagentRecord } from "../persistence/subagent-store.js";
|
|
84
|
+
import { notifyParentFromChild } from "../subagent/notify.js";
|
|
60
85
|
import {
|
|
61
86
|
executeSubagentNotifyParent,
|
|
62
87
|
notifyParentTool,
|
|
@@ -65,61 +90,42 @@ import {
|
|
|
65
90
|
// ── Shared helpers ──────────────────────────────────────────────────
|
|
66
91
|
|
|
67
92
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
93
|
+
* Register a subagent so `notifyParentFromChild` (and the `notify_parent` tool)
|
|
94
|
+
* treat `conversationId` as a live subagent: a live child conversation (the
|
|
95
|
+
* routing source) plus a durable record (cosmetic label/fork/objective).
|
|
96
|
+
* Defaults to a running general subagent; pass overrides for status, label,
|
|
97
|
+
* fork, etc. By default the live parent matches the record's parent; pass
|
|
98
|
+
* `liveParentConversationId` to diverge them (models a tampered record).
|
|
70
99
|
*/
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
state: SubagentState;
|
|
84
|
-
parentSendToClient: () => void;
|
|
85
|
-
}
|
|
86
|
-
>;
|
|
87
|
-
parentToChildren: Map<string, Set<string>>;
|
|
88
|
-
};
|
|
89
|
-
const state: SubagentState = {
|
|
90
|
-
config: {
|
|
91
|
-
id: subagentId,
|
|
92
|
-
parentConversationId,
|
|
93
|
-
label: "Test",
|
|
94
|
-
objective: "test",
|
|
95
|
-
},
|
|
96
|
-
status,
|
|
97
|
-
conversationId: `conv-${subagentId}`,
|
|
100
|
+
function seedSubagent(
|
|
101
|
+
conversationId: string,
|
|
102
|
+
overrides: Partial<SubagentRecord> = {},
|
|
103
|
+
liveParentConversationId?: string,
|
|
104
|
+
): void {
|
|
105
|
+
const record: SubagentRecord = {
|
|
106
|
+
id: `sub-${conversationId}`,
|
|
107
|
+
parentConversationId: `parent-${conversationId}`,
|
|
108
|
+
conversationId,
|
|
109
|
+
label: "Test",
|
|
110
|
+
objective: "test",
|
|
111
|
+
role: "general",
|
|
98
112
|
isFork: false,
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
sendResultToUser: null,
|
|
114
|
+
status: "running",
|
|
115
|
+
error: null,
|
|
116
|
+
createdAt: 0,
|
|
117
|
+
startedAt: null,
|
|
118
|
+
completedAt: null,
|
|
119
|
+
inputTokens: 0,
|
|
120
|
+
outputTokens: 0,
|
|
121
|
+
estimatedCost: 0,
|
|
101
122
|
...overrides,
|
|
102
123
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
sendToClient: () => {},
|
|
108
|
-
usageStats: { inputTokens: 0, outputTokens: 0, estimatedCost: 0 },
|
|
109
|
-
enqueueMessage: () => ({ queued: false }),
|
|
110
|
-
persistUserMessage: async () => ({ id: "msg-1", deduplicated: false }),
|
|
111
|
-
runAgentLoop: async () => {},
|
|
112
|
-
};
|
|
113
|
-
internals.subagents.set(subagentId, {
|
|
114
|
-
conversation: fakeConversation,
|
|
115
|
-
state,
|
|
116
|
-
parentSendToClient: () => {},
|
|
124
|
+
records.set(conversationId, record);
|
|
125
|
+
liveSubagents.set(conversationId, {
|
|
126
|
+
parentConversationId:
|
|
127
|
+
liveParentConversationId ?? record.parentConversationId,
|
|
117
128
|
});
|
|
118
|
-
if (!internals.parentToChildren.has(parentConversationId)) {
|
|
119
|
-
internals.parentToChildren.set(parentConversationId, new Set());
|
|
120
|
-
}
|
|
121
|
-
internals.parentToChildren.get(parentConversationId)!.add(subagentId);
|
|
122
|
-
return state;
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
function makeContext(
|
|
@@ -209,14 +215,12 @@ describe("executeSubagentNotifyParent", () => {
|
|
|
209
215
|
|
|
210
216
|
test("succeeds when called from a subagent conversation", async () => {
|
|
211
217
|
clearCaptured();
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
const parentConversationId = "notify-parent-1";
|
|
215
|
-
injectSubagent(manager, subagentId, parentConversationId, "running");
|
|
218
|
+
const conversationId = "conv-notify-sub-1";
|
|
219
|
+
seedSubagent(conversationId);
|
|
216
220
|
|
|
217
221
|
const result = await executeSubagentNotifyParent(
|
|
218
222
|
{ message: "Found key results", urgency: "important" },
|
|
219
|
-
makeContext(
|
|
223
|
+
makeContext(conversationId),
|
|
220
224
|
);
|
|
221
225
|
expect(result.isError).toBe(false);
|
|
222
226
|
const parsed = JSON.parse(result.content);
|
|
@@ -227,21 +231,15 @@ describe("executeSubagentNotifyParent", () => {
|
|
|
227
231
|
|
|
228
232
|
test("formats message with label and urgency", async () => {
|
|
229
233
|
clearCaptured();
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
config: {
|
|
235
|
-
id: subagentId,
|
|
236
|
-
parentConversationId,
|
|
237
|
-
label: "Research Task",
|
|
238
|
-
objective: "research",
|
|
239
|
-
},
|
|
234
|
+
const conversationId = "conv-notify-format-1";
|
|
235
|
+
seedSubagent(conversationId, {
|
|
236
|
+
label: "Research Task",
|
|
237
|
+
objective: "research",
|
|
240
238
|
});
|
|
241
239
|
|
|
242
240
|
await executeSubagentNotifyParent(
|
|
243
241
|
{ message: "Preliminary findings ready", urgency: "info" },
|
|
244
|
-
makeContext(
|
|
242
|
+
makeContext(conversationId),
|
|
245
243
|
);
|
|
246
244
|
expect(lastCapturedMessage()).toBe(
|
|
247
245
|
'[Subagent "Research Task" — info] Preliminary findings ready',
|
|
@@ -267,14 +265,12 @@ describe("executeSubagentNotifyParent", () => {
|
|
|
267
265
|
});
|
|
268
266
|
|
|
269
267
|
test("defaults urgency to info when not provided", async () => {
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
const parentConversationId = "notify-default-urg-parent";
|
|
273
|
-
injectSubagent(manager, subagentId, parentConversationId, "running");
|
|
268
|
+
const conversationId = "conv-notify-default-urg-1";
|
|
269
|
+
seedSubagent(conversationId);
|
|
274
270
|
|
|
275
271
|
const result = await executeSubagentNotifyParent(
|
|
276
272
|
{ message: "Progress update" },
|
|
277
|
-
makeContext(
|
|
273
|
+
makeContext(conversationId),
|
|
278
274
|
);
|
|
279
275
|
expect(result.isError).toBe(false);
|
|
280
276
|
const parsed = JSON.parse(result.content);
|
|
@@ -283,14 +279,12 @@ describe("executeSubagentNotifyParent", () => {
|
|
|
283
279
|
|
|
284
280
|
test("appends guidance hint for blocked urgency", async () => {
|
|
285
281
|
clearCaptured();
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
const parentConversationId = "notify-blocked-parent";
|
|
289
|
-
injectSubagent(manager, subagentId, parentConversationId, "running");
|
|
282
|
+
const conversationId = "conv-notify-blocked-1";
|
|
283
|
+
seedSubagent(conversationId);
|
|
290
284
|
|
|
291
285
|
await executeSubagentNotifyParent(
|
|
292
286
|
{ message: "Need API key to proceed", urgency: "blocked" },
|
|
293
|
-
makeContext(
|
|
287
|
+
makeContext(conversationId),
|
|
294
288
|
);
|
|
295
289
|
expect(lastCapturedMessage()).toContain("Need API key to proceed");
|
|
296
290
|
expect(lastCapturedMessage()).toContain(
|
|
@@ -299,68 +293,61 @@ describe("executeSubagentNotifyParent", () => {
|
|
|
299
293
|
});
|
|
300
294
|
});
|
|
301
295
|
|
|
302
|
-
// ──
|
|
296
|
+
// ── notifyParentFromChild ──────────────────────────────────────────
|
|
297
|
+
|
|
298
|
+
describe("notifyParentFromChild", () => {
|
|
299
|
+
test("returns false when the conversation is not a subagent", () => {
|
|
300
|
+
expect(notifyParentFromChild("unknown-conversation", "hi", "info")).toBe(
|
|
301
|
+
false,
|
|
302
|
+
);
|
|
303
|
+
});
|
|
303
304
|
|
|
304
|
-
describe("SubagentManager.notifyParent", () => {
|
|
305
305
|
test("returns false for terminal subagents", () => {
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const result = manager.notifyParent(
|
|
314
|
-
`conv-${subagentId}`,
|
|
315
|
-
"Should not arrive",
|
|
316
|
-
"info",
|
|
317
|
-
);
|
|
318
|
-
expect(result).toBe(false);
|
|
306
|
+
for (const status of ["completed", "failed", "aborted"] as const) {
|
|
307
|
+
const conversationId = `conv-terminal-${status}`;
|
|
308
|
+
seedSubagent(conversationId, { status });
|
|
309
|
+
expect(
|
|
310
|
+
notifyParentFromChild(conversationId, "Should not arrive", "info"),
|
|
311
|
+
).toBe(false);
|
|
319
312
|
}
|
|
320
313
|
});
|
|
321
314
|
|
|
322
|
-
test("returns true for running subagent
|
|
315
|
+
test("returns true for a running subagent and injects into the parent", () => {
|
|
323
316
|
clearCaptured();
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const result = manager.notifyParent(
|
|
330
|
-
`conv-${subagentId}`,
|
|
331
|
-
"Test message",
|
|
332
|
-
"info",
|
|
317
|
+
const conversationId = "conv-running-1";
|
|
318
|
+
seedSubagent(conversationId);
|
|
319
|
+
|
|
320
|
+
expect(notifyParentFromChild(conversationId, "Test message", "info")).toBe(
|
|
321
|
+
true,
|
|
333
322
|
);
|
|
334
|
-
expect(result).toBe(true);
|
|
335
323
|
expect(lastCapturedMessage()).toContain("Test message");
|
|
336
324
|
});
|
|
337
|
-
});
|
|
338
325
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
326
|
+
test("labels forks as Fork", () => {
|
|
327
|
+
clearCaptured();
|
|
328
|
+
const conversationId = "conv-fork-1";
|
|
329
|
+
seedSubagent(conversationId, { isFork: true, label: "Explore" });
|
|
330
|
+
|
|
331
|
+
notifyParentFromChild(conversationId, "branch result", "info");
|
|
332
|
+
expect(lastCapturedMessage()).toBe('[Fork "Explore" — info] branch result');
|
|
344
333
|
});
|
|
345
334
|
|
|
346
|
-
test("
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
});
|
|
335
|
+
test("routes to the live parent, ignoring a tampered record parent", () => {
|
|
336
|
+
clearCaptured();
|
|
337
|
+
capturedParentIds.length = 0;
|
|
338
|
+
const conversationId = "conv-tamper-1";
|
|
339
|
+
// The durable record claims a victim conversation as parent; the live
|
|
340
|
+
// child's real parent differs. Routing must follow the live child.
|
|
341
|
+
seedSubagent(
|
|
342
|
+
conversationId,
|
|
343
|
+
{ parentConversationId: "victim-conversation" },
|
|
344
|
+
"real-parent-conversation",
|
|
345
|
+
);
|
|
358
346
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
expect(
|
|
363
|
-
expect(
|
|
364
|
-
expect(typeof info!.parentSendToClient).toBe("function");
|
|
347
|
+
expect(notifyParentFromChild(conversationId, "injected", "info")).toBe(
|
|
348
|
+
true,
|
|
349
|
+
);
|
|
350
|
+
expect(capturedParentIds).toContain("real-parent-conversation");
|
|
351
|
+
expect(capturedParentIds).not.toContain("victim-conversation");
|
|
365
352
|
});
|
|
366
353
|
});
|
|
@@ -102,6 +102,7 @@ mock.module("../daemon/process-message.js", () => ({
|
|
|
102
102
|
) => processMessageImpl(conversationId, message, options),
|
|
103
103
|
}));
|
|
104
104
|
|
|
105
|
+
import { loadRawConfig, saveRawConfig } from "../config/loader.js";
|
|
105
106
|
import { getDb } from "../persistence/db-connection.js";
|
|
106
107
|
import { initializeDb } from "../persistence/db-init.js";
|
|
107
108
|
import { recordUsageEvent } from "../persistence/llm-usage-store.js";
|
|
@@ -121,6 +122,13 @@ import { createTask } from "../tasks/task-store.js";
|
|
|
121
122
|
|
|
122
123
|
await initializeDb();
|
|
123
124
|
|
|
125
|
+
// The schedule worker is on by default, which stands the daemon's in-process
|
|
126
|
+
// scheduler down. These tests exercise that in-process execution path directly
|
|
127
|
+
// (runScheduleDueWorkOnce), so pin the worker flag off for this test process.
|
|
128
|
+
const rawConfig = loadRawConfig();
|
|
129
|
+
rawConfig.schedules = { worker: { enabled: false } };
|
|
130
|
+
saveRawConfig(rawConfig);
|
|
131
|
+
|
|
124
132
|
/** Access the underlying bun:sqlite Database for raw parameterized queries. */
|
|
125
133
|
function getRawDb(): import("bun:sqlite").Database {
|
|
126
134
|
return (getDb() as unknown as { $client: import("bun:sqlite").Database })
|