repoburg 1.3.199 → 1.3.201
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/agent-pane/backend/data.db +0 -0
- package/agent-pane/backend/data.db-shm +0 -0
- package/agent-pane/backend/data.db-wal +0 -0
- package/agent-pane/backend/dist/index.js +1425 -272
- package/agent-pane/backend/src/claude/claude-provider.test.ts +393 -3
- package/agent-pane/backend/src/claude/claude-provider.ts +53 -50
- package/agent-pane/backend/src/db/index.ts +6 -0
- package/agent-pane/backend/src/index.ts +5 -2
- package/agent-pane/backend/src/integration/threads-claude-fork.test.ts +241 -0
- package/agent-pane/backend/src/providers/index.ts +3 -1
- package/agent-pane/backend/src/repoburg/action-mapping.ts +216 -0
- package/agent-pane/backend/src/repoburg/agent-runtime-client.test.ts +271 -0
- package/agent-pane/backend/src/repoburg/agent-runtime-client.ts +262 -0
- package/agent-pane/backend/src/repoburg/backend-resolver.test.ts +271 -0
- package/agent-pane/backend/src/repoburg/backend-resolver.ts +246 -0
- package/agent-pane/backend/src/repoburg/repoburg-client.test.ts +159 -0
- package/agent-pane/backend/src/repoburg/repoburg-client.ts +181 -0
- package/agent-pane/backend/src/repoburg/repoburg-provider.test.ts +723 -0
- package/agent-pane/backend/src/repoburg/repoburg-provider.ts +422 -0
- package/agent-pane/backend/src/repoburg/turn-projector.test.ts +475 -0
- package/agent-pane/backend/src/repoburg/turn-projector.ts +537 -0
- package/agent-pane/backend/src/routes/providers.test.ts +18 -1
- package/agent-pane/backend/src/routes/providers.ts +19 -1
- package/agent-pane/backend/src/routes/sessions.ts +12 -0
- package/agent-pane/backend/src/routes/threads.ts +21 -6
- package/agent-pane/backend/src/routes/turns.test.ts +45 -1
- package/agent-pane/frontend/dist/assets/{index-Dwwhx7YN.css → index-34WaZYsW.css} +1 -1
- package/agent-pane/frontend/dist/assets/index-y7xlT86e.js +362 -0
- package/agent-pane/frontend/dist/index.html +2 -2
- package/agent-pane/frontend/src/components/CommentableText.test.tsx +196 -0
- package/agent-pane/frontend/src/components/CommentableText.tsx +109 -21
- package/agent-pane/frontend/src/components/IdeWorkspace.test.tsx +39 -0
- package/agent-pane/frontend/src/components/IdeWorkspace.tsx +28 -2
- package/agent-pane/frontend/src/components/ResizeHandle.tsx +29 -0
- package/agent-pane/frontend/src/components/panels/ThreadsPanel.tsx +35 -3
- package/agent-pane/frontend/src/constants/models.ts +37 -0
- package/agent-pane/frontend/src/hooks/useResizable.test.ts +97 -0
- package/agent-pane/frontend/src/hooks/useResizable.ts +75 -0
- package/agent-pane/frontend/src/store/store.test.ts +35 -0
- package/agent-pane/frontend/src/store/uiSlice.ts +50 -0
- package/agent-pane/frontend/src/styles/app.css +10 -1
- package/agent-pane/frontend/src/test/component-helpers.ts +2 -0
- package/agent-pane-bug-repro-no-agent-reply.png +0 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.d.ts +20 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js +112 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js.map +1 -0
- package/backend/dist/src/agent-runtime/agent-runtime.controller.d.ts +11 -0
- package/backend/dist/src/agent-runtime/agent-runtime.controller.js +91 -0
- package/backend/dist/src/agent-runtime/agent-runtime.controller.js.map +1 -0
- package/backend/dist/src/agent-runtime/agent-runtime.module.d.ts +2 -0
- package/backend/dist/src/agent-runtime/agent-runtime.module.js +26 -0
- package/backend/dist/src/agent-runtime/agent-runtime.module.js.map +1 -0
- package/backend/dist/src/agent-runtime/agent-runtime.types.d.ts +77 -0
- package/backend/dist/src/agent-runtime/agent-runtime.types.js +3 -0
- package/backend/dist/src/agent-runtime/agent-runtime.types.js.map +1 -0
- package/backend/dist/src/app.module.js +4 -0
- package/backend/dist/src/app.module.js.map +1 -1
- package/backend/dist/src/interactive-chat/chat.module.js +4 -0
- package/backend/dist/src/interactive-chat/chat.module.js.map +1 -1
- package/backend/dist/src/interactive-chat/chat.service.d.ts +3 -1
- package/backend/dist/src/interactive-chat/chat.service.js +33 -6
- package/backend/dist/src/interactive-chat/chat.service.js.map +1 -1
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.d.ts +3 -1
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js +20 -2
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-orchestration.module.js +2 -0
- package/backend/dist/src/llm-orchestration/llm-orchestration.module.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.d.ts +4 -1
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js +35 -2
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js.map +1 -1
- package/backend/dist/src/llm-provider/ollama-llm.provider.d.ts +1 -0
- package/backend/dist/src/llm-provider/ollama-llm.provider.js +19 -1
- package/backend/dist/src/llm-provider/ollama-llm.provider.js.map +1 -1
- package/backend/dist/src/llm-responses/llm-responses.module.js +4 -0
- package/backend/dist/src/llm-responses/llm-responses.module.js.map +1 -1
- package/backend/dist/src/llm-responses/llm-responses.service.d.ts +4 -1
- package/backend/dist/src/llm-responses/llm-responses.service.js +52 -2
- package/backend/dist/src/llm-responses/llm-responses.service.js.map +1 -1
- package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
- package/daemon/dist/index.js +0 -0
- package/package.json +1 -1
- package/agent-pane/frontend/dist/assets/index-BYo-lnxm.js +0 -362
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Capture broadcasts.
|
|
4
|
+
const captured: Array<{ event: string; data: unknown }> = [];
|
|
5
|
+
vi.mock('../ws/index.ts', async (importOriginal) => {
|
|
6
|
+
const actual = (await importOriginal()) as Record<string, unknown>;
|
|
7
|
+
return {
|
|
8
|
+
...actual,
|
|
9
|
+
broadcast: vi.fn((event: string, data: unknown) => {
|
|
10
|
+
captured.push({ event, data });
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
import { TurnProjector, RESULT_TIMEOUT_MS, MAX_RESULT_EXTENSIONS } from './turn-projector.ts';
|
|
16
|
+
import type { AgentRuntimeActionInfo, AgentRuntimeMessage } from './agent-runtime-client.ts';
|
|
17
|
+
import { initDb } from '../db/index.ts';
|
|
18
|
+
import type Database from 'better-sqlite3';
|
|
19
|
+
import type { RepoburgRuntimeClient } from './repoburg-client.ts';
|
|
20
|
+
|
|
21
|
+
const SESSION_ID = 's1';
|
|
22
|
+
const TURN_ID = 't1';
|
|
23
|
+
const RUNTIME_SESSION_ID = 'rs-1';
|
|
24
|
+
|
|
25
|
+
/** Standard action info block for tool_result messages. */
|
|
26
|
+
function actionInfo(overrides: Partial<AgentRuntimeActionInfo> = {}): AgentRuntimeActionInfo {
|
|
27
|
+
return {
|
|
28
|
+
id: 'a1',
|
|
29
|
+
action_type: 'create_file',
|
|
30
|
+
file_path: 'src/a.ts',
|
|
31
|
+
command_string: null,
|
|
32
|
+
status: 'CONFIRMED_KEPT',
|
|
33
|
+
server_name: null,
|
|
34
|
+
tool_name: null,
|
|
35
|
+
arguments: null,
|
|
36
|
+
plain: null,
|
|
37
|
+
order_of_execution: 0,
|
|
38
|
+
...overrides,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('TurnProjector', () => {
|
|
43
|
+
let db: Database.Database;
|
|
44
|
+
let projector: TurnProjector | null = null;
|
|
45
|
+
const client = {
|
|
46
|
+
getSessionInputs: vi.fn(),
|
|
47
|
+
getSession: vi.fn(),
|
|
48
|
+
} as unknown as RepoburgRuntimeClient;
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
vi.clearAllMocks();
|
|
52
|
+
captured.length = 0;
|
|
53
|
+
db = initDb(':memory:');
|
|
54
|
+
const now = new Date().toISOString();
|
|
55
|
+
db.prepare(
|
|
56
|
+
`INSERT INTO sessions (id, title, runtime_type, status, is_running, lifecycle, created_at, updated_at)
|
|
57
|
+
VALUES (?, NULL, 'repoburg', 'running', 1, 'working', ?, ?)`,
|
|
58
|
+
).run(SESSION_ID, now, now);
|
|
59
|
+
db.prepare(
|
|
60
|
+
`INSERT INTO turns (id, session_id, user_prompt, status, created_at, updated_at)
|
|
61
|
+
VALUES (?, ?, 'hello', 'running', ?, ?)`,
|
|
62
|
+
).run(TURN_ID, SESSION_ID, now, now);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterEach(() => {
|
|
66
|
+
projector?.close();
|
|
67
|
+
projector = null;
|
|
68
|
+
db.close();
|
|
69
|
+
vi.useRealTimers();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
function makeProjector(): TurnProjector {
|
|
73
|
+
projector = new TurnProjector({
|
|
74
|
+
agentPaneSessionId: SESSION_ID,
|
|
75
|
+
turnId: TURN_ID,
|
|
76
|
+
repoburgSessionId: RUNTIME_SESSION_ID,
|
|
77
|
+
client,
|
|
78
|
+
});
|
|
79
|
+
return projector;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function items(): Array<{ external_item_id: string; type: string; status: string; data: string }> {
|
|
83
|
+
return db
|
|
84
|
+
.prepare('SELECT external_item_id, type, status, data FROM items WHERE turn_id = ? ORDER BY rowid')
|
|
85
|
+
.all(TURN_ID) as never;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function turnRow(): { status: string; agent_response: string | null; token_usage: string | null; error: string | null } {
|
|
89
|
+
return db.prepare('SELECT status, agent_response, token_usage, error FROM turns WHERE id = ?').get(TURN_ID) as never;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
describe('stream_event + assistant', () => {
|
|
93
|
+
it('starts items on first delta and streams further deltas', () => {
|
|
94
|
+
const p = makeProjector();
|
|
95
|
+
|
|
96
|
+
p.handle({
|
|
97
|
+
type: 'stream_event',
|
|
98
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
99
|
+
inputId: 'in-1',
|
|
100
|
+
delta: { type: 'text', text: 'Hel' },
|
|
101
|
+
});
|
|
102
|
+
p.handle({
|
|
103
|
+
type: 'stream_event',
|
|
104
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
105
|
+
inputId: 'in-1',
|
|
106
|
+
delta: { type: 'text', text: 'lo' },
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const rows = items();
|
|
110
|
+
expect(rows).toHaveLength(1);
|
|
111
|
+
expect(rows[0].type).toBe('agent_message');
|
|
112
|
+
expect(rows[0].status).toBe('in_progress');
|
|
113
|
+
expect(JSON.parse(rows[0].data)).toEqual({ text: 'Hel' }); // item data from FIRST insert
|
|
114
|
+
|
|
115
|
+
const delta = captured.find((b) => b.event === 'item:delta');
|
|
116
|
+
expect(delta).toBeDefined();
|
|
117
|
+
expect(delta!.data).toMatchObject({ turnId: TURN_ID, itemId: 'in-1-text', delta: 'lo' });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('completes streamed items when the assistant message arrives', () => {
|
|
121
|
+
const p = makeProjector();
|
|
122
|
+
p.handle({
|
|
123
|
+
type: 'stream_event',
|
|
124
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
125
|
+
inputId: 'in-1',
|
|
126
|
+
delta: { type: 'text', text: 'Hel' },
|
|
127
|
+
});
|
|
128
|
+
p.handle({
|
|
129
|
+
type: 'assistant',
|
|
130
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
131
|
+
inputId: 'in-1',
|
|
132
|
+
content: [
|
|
133
|
+
{ type: 'thinking', thinking: 'hmm' },
|
|
134
|
+
{ type: 'text', text: 'Hello world' },
|
|
135
|
+
],
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const rows = items();
|
|
139
|
+
expect(rows.map((r) => r.type)).toEqual(['agent_message', 'reasoning']);
|
|
140
|
+
expect(rows.every((r) => r.status === 'completed')).toBe(true);
|
|
141
|
+
expect(JSON.parse(rows[0].data)).toEqual({ text: 'Hello world' });
|
|
142
|
+
expect(JSON.parse(rows[1].data)).toEqual({ text: 'hmm' });
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('creates completed items from assistant alone (deltas off/missed)', () => {
|
|
146
|
+
const p = makeProjector();
|
|
147
|
+
p.handle({
|
|
148
|
+
type: 'assistant',
|
|
149
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
150
|
+
inputId: 'in-1',
|
|
151
|
+
content: [{ type: 'text', text: 'Hello' }],
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const rows = items();
|
|
155
|
+
expect(rows).toHaveLength(1);
|
|
156
|
+
expect(rows[0].status).toBe('completed');
|
|
157
|
+
expect(JSON.parse(rows[0].data)).toEqual({ text: 'Hello' });
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('user tool_result', () => {
|
|
162
|
+
it('maps actions to items and skips final/html_final (part of the response)', () => {
|
|
163
|
+
const p = makeProjector();
|
|
164
|
+
p.handle({
|
|
165
|
+
type: 'user',
|
|
166
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
167
|
+
inputId: 'in-1',
|
|
168
|
+
content: [
|
|
169
|
+
{
|
|
170
|
+
type: 'tool_result',
|
|
171
|
+
tool_use_id: 'a1',
|
|
172
|
+
content: 'created',
|
|
173
|
+
is_error: false,
|
|
174
|
+
action: actionInfo({ id: 'a1', action_type: 'create_file' }),
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
type: 'tool_result',
|
|
178
|
+
tool_use_id: 'a2',
|
|
179
|
+
content: 'ls output',
|
|
180
|
+
is_error: false,
|
|
181
|
+
action: actionInfo({ id: 'a2', action_type: 'run_command', file_path: null, command_string: 'ls' }),
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
type: 'tool_result',
|
|
185
|
+
tool_use_id: 'a3',
|
|
186
|
+
content: 'final text',
|
|
187
|
+
is_error: false,
|
|
188
|
+
action: actionInfo({ id: 'a3', action_type: 'final', plain: 'Final text' }),
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const rows = items();
|
|
194
|
+
expect(rows.map((r) => r.external_item_id)).toEqual(['in-1-action-a1', 'in-1-action-a2']);
|
|
195
|
+
expect(rows[0].type).toBe('file_change');
|
|
196
|
+
expect(rows[1].type).toBe('command_execution');
|
|
197
|
+
expect(JSON.parse(rows[1].data).aggregated_output).toBe('ls output');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('maps failed actions to failed items with the error text', () => {
|
|
201
|
+
const p = makeProjector();
|
|
202
|
+
p.handle({
|
|
203
|
+
type: 'user',
|
|
204
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
205
|
+
inputId: 'in-1',
|
|
206
|
+
content: [
|
|
207
|
+
{
|
|
208
|
+
type: 'tool_result',
|
|
209
|
+
tool_use_id: 'a1',
|
|
210
|
+
content: 'command crashed',
|
|
211
|
+
is_error: true,
|
|
212
|
+
action: actionInfo({
|
|
213
|
+
id: 'a1',
|
|
214
|
+
action_type: 'run_command',
|
|
215
|
+
file_path: null,
|
|
216
|
+
command_string: 'boom',
|
|
217
|
+
status: 'EXECUTION_FAILED',
|
|
218
|
+
}),
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const rows = items();
|
|
224
|
+
expect(rows).toHaveLength(1);
|
|
225
|
+
expect(rows[0].status).toBe('failed');
|
|
226
|
+
expect(JSON.parse(rows[0].data).status).toBe('failed');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('is idempotent — replayed messages do not duplicate items', () => {
|
|
230
|
+
const p = makeProjector();
|
|
231
|
+
const assistant: AgentRuntimeMessage = {
|
|
232
|
+
type: 'assistant',
|
|
233
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
234
|
+
inputId: 'in-1',
|
|
235
|
+
content: [{ type: 'text', text: 'Hello' }],
|
|
236
|
+
};
|
|
237
|
+
const user: AgentRuntimeMessage = {
|
|
238
|
+
type: 'user',
|
|
239
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
240
|
+
inputId: 'in-1',
|
|
241
|
+
content: [
|
|
242
|
+
{
|
|
243
|
+
type: 'tool_result',
|
|
244
|
+
tool_use_id: 'a1',
|
|
245
|
+
content: 'created',
|
|
246
|
+
is_error: false,
|
|
247
|
+
action: actionInfo(),
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
p.handle(assistant);
|
|
253
|
+
p.handle(user);
|
|
254
|
+
p.handle(assistant); // replay (reconnect)
|
|
255
|
+
p.handle(user);
|
|
256
|
+
|
|
257
|
+
expect(items().map((r) => r.external_item_id).sort()).toEqual(['in-1-action-a1', 'in-1-text']);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('result', () => {
|
|
262
|
+
it('success completes the turn with result text, usage, and title sync', async () => {
|
|
263
|
+
(client.getSession as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
264
|
+
id: RUNTIME_SESSION_ID,
|
|
265
|
+
session_title: 'Synced Title',
|
|
266
|
+
is_running: false,
|
|
267
|
+
});
|
|
268
|
+
const p = makeProjector();
|
|
269
|
+
|
|
270
|
+
p.handle({
|
|
271
|
+
type: 'assistant',
|
|
272
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
273
|
+
inputId: 'in-1',
|
|
274
|
+
content: [{ type: 'text', text: 'working' }],
|
|
275
|
+
});
|
|
276
|
+
p.handle({
|
|
277
|
+
type: 'result',
|
|
278
|
+
subtype: 'success',
|
|
279
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
280
|
+
is_error: false,
|
|
281
|
+
result: 'All done',
|
|
282
|
+
usage: { input_tokens: 10, output_tokens: 5, cache_read_input_tokens: 2, cache_creation_input_tokens: 0 },
|
|
283
|
+
num_rounds: 2,
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
const row = turnRow();
|
|
287
|
+
expect(row.status).toBe('completed');
|
|
288
|
+
expect(row.agent_response).toBe('All done');
|
|
289
|
+
expect(JSON.parse(row.token_usage!)).toMatchObject({
|
|
290
|
+
input_tokens: 10,
|
|
291
|
+
output_tokens: 5,
|
|
292
|
+
cached_input_tokens: 2,
|
|
293
|
+
});
|
|
294
|
+
expect(captured.find((b) => b.event === 'turn:completed')).toBeDefined();
|
|
295
|
+
|
|
296
|
+
// Session marked not-running with unreviewed actions.
|
|
297
|
+
const session = db.prepare('SELECT is_running, status, has_unreviewed FROM sessions WHERE id = ?').get(SESSION_ID) as never;
|
|
298
|
+
expect(session).toMatchObject({ is_running: 0, status: 'active', has_unreviewed: 1 });
|
|
299
|
+
|
|
300
|
+
// Title sync (async, fire-and-forget).
|
|
301
|
+
await vi.waitFor(() => {
|
|
302
|
+
const s = db.prepare('SELECT title FROM sessions WHERE id = ?').get(SESSION_ID) as { title: string | null };
|
|
303
|
+
expect(s.title).toBe('Synced Title');
|
|
304
|
+
});
|
|
305
|
+
expect(captured.find((b) => b.event === 'session:title')).toBeDefined();
|
|
306
|
+
|
|
307
|
+
// Projector done — later messages ignored.
|
|
308
|
+
p.handle({
|
|
309
|
+
type: 'result',
|
|
310
|
+
subtype: 'success',
|
|
311
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
312
|
+
is_error: false,
|
|
313
|
+
result: 'late',
|
|
314
|
+
num_rounds: 0,
|
|
315
|
+
} as never);
|
|
316
|
+
expect(turnRow().agent_response).toBe('All done');
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('success falls back to the last round text when result text is empty', () => {
|
|
320
|
+
const p = makeProjector();
|
|
321
|
+
p.handle({
|
|
322
|
+
type: 'assistant',
|
|
323
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
324
|
+
inputId: 'in-1',
|
|
325
|
+
content: [{ type: 'text', text: 'Fallback text' }],
|
|
326
|
+
});
|
|
327
|
+
p.handle({
|
|
328
|
+
type: 'result',
|
|
329
|
+
subtype: 'success',
|
|
330
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
331
|
+
is_error: false,
|
|
332
|
+
result: '',
|
|
333
|
+
num_rounds: 1,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
expect(turnRow().agent_response).toBe('Fallback text');
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('error fails the turn and closes open items as failed', () => {
|
|
340
|
+
const p = makeProjector();
|
|
341
|
+
p.handle({
|
|
342
|
+
type: 'stream_event',
|
|
343
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
344
|
+
inputId: 'in-1',
|
|
345
|
+
delta: { type: 'text', text: 'partial' },
|
|
346
|
+
});
|
|
347
|
+
p.handle({
|
|
348
|
+
type: 'result',
|
|
349
|
+
subtype: 'error_during_execution',
|
|
350
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
351
|
+
is_error: true,
|
|
352
|
+
result: '',
|
|
353
|
+
num_rounds: 1,
|
|
354
|
+
errors: ['boom', 'bang'],
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const row = turnRow();
|
|
358
|
+
expect(row.status).toBe('failed');
|
|
359
|
+
expect(row.error).toBe('boom; bang');
|
|
360
|
+
expect(items()[0].status).toBe('failed');
|
|
361
|
+
expect(captured.find((b) => b.event === 'turn:failed')).toBeDefined();
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('aborted aborts the turn and closes open items as completed', () => {
|
|
365
|
+
const p = makeProjector();
|
|
366
|
+
p.handle({
|
|
367
|
+
type: 'stream_event',
|
|
368
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
369
|
+
inputId: 'in-1',
|
|
370
|
+
delta: { type: 'text', text: 'partial' },
|
|
371
|
+
});
|
|
372
|
+
p.handle({
|
|
373
|
+
type: 'result',
|
|
374
|
+
subtype: 'aborted',
|
|
375
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
376
|
+
is_error: true,
|
|
377
|
+
result: '',
|
|
378
|
+
num_rounds: 0,
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
expect(turnRow().status).toBe('aborted');
|
|
382
|
+
expect(items()[0].status).toBe('completed');
|
|
383
|
+
expect(captured.find((b) => b.event === 'turn:cancelled')).toBeDefined();
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
describe('watch-dog + snapshot reconcile', () => {
|
|
388
|
+
it('completes the turn from the snapshot when the result never arrives', async () => {
|
|
389
|
+
vi.useFakeTimers();
|
|
390
|
+
(client.getSessionInputs as ReturnType<typeof vi.fn>).mockResolvedValue([
|
|
391
|
+
{
|
|
392
|
+
id: 'in-1',
|
|
393
|
+
role: 'model',
|
|
394
|
+
raw_llm_response: 'Snapshot reply',
|
|
395
|
+
thoughts: null,
|
|
396
|
+
input_token_count: 12,
|
|
397
|
+
output_token_count: 6,
|
|
398
|
+
cached_token_count: 3,
|
|
399
|
+
aiActions: [
|
|
400
|
+
{
|
|
401
|
+
id: 'a1',
|
|
402
|
+
action_type: 'create_file',
|
|
403
|
+
file_path: 'src/x.ts',
|
|
404
|
+
status: 'CONFIRMED_KEPT',
|
|
405
|
+
order_of_execution: 0,
|
|
406
|
+
executionLogs: [{ output: 'created', error_message: null }],
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
]);
|
|
411
|
+
(client.getSession as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
412
|
+
id: RUNTIME_SESSION_ID,
|
|
413
|
+
session_title: null,
|
|
414
|
+
is_running: false,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const p = makeProjector();
|
|
418
|
+
p.handle({
|
|
419
|
+
type: 'assistant',
|
|
420
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
421
|
+
inputId: 'in-1',
|
|
422
|
+
content: [{ type: 'text', text: 'Snapshot reply' }],
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
await vi.advanceTimersByTimeAsync(RESULT_TIMEOUT_MS + 1000);
|
|
426
|
+
|
|
427
|
+
// Snapshot projected (action item) and turn completed.
|
|
428
|
+
const ids = items().map((r) => r.external_item_id);
|
|
429
|
+
expect(ids).toContain('in-1-action-a1');
|
|
430
|
+
const row = turnRow();
|
|
431
|
+
expect(row.status).toBe('completed');
|
|
432
|
+
expect(row.agent_response).toBe('Snapshot reply');
|
|
433
|
+
expect(JSON.parse(row.token_usage!)).toMatchObject({ input_tokens: 12, output_tokens: 6, cached_input_tokens: 3 });
|
|
434
|
+
expect(client.getSessionInputs).toHaveBeenCalledWith(RUNTIME_SESSION_ID);
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
it('re-arms while the runtime session is still running, then fails after max extensions', async () => {
|
|
438
|
+
vi.useFakeTimers();
|
|
439
|
+
(client.getSessionInputs as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
|
440
|
+
(client.getSession as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
441
|
+
id: RUNTIME_SESSION_ID,
|
|
442
|
+
session_title: null,
|
|
443
|
+
is_running: true,
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
makeProjector();
|
|
447
|
+
|
|
448
|
+
const firings = MAX_RESULT_EXTENSIONS + 1;
|
|
449
|
+
await vi.advanceTimersByTimeAsync(RESULT_TIMEOUT_MS * firings + 1000 * firings);
|
|
450
|
+
|
|
451
|
+
const row = turnRow();
|
|
452
|
+
expect(row.status).toBe('failed');
|
|
453
|
+
expect(row.error).toMatch(/still running/);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it('a live result cancels the watchdog', async () => {
|
|
457
|
+
vi.useFakeTimers();
|
|
458
|
+
const p = makeProjector();
|
|
459
|
+
p.handle({
|
|
460
|
+
type: 'result',
|
|
461
|
+
subtype: 'success',
|
|
462
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
463
|
+
is_error: false,
|
|
464
|
+
result: 'done',
|
|
465
|
+
num_rounds: 1,
|
|
466
|
+
});
|
|
467
|
+
expect(turnRow().status).toBe('completed');
|
|
468
|
+
|
|
469
|
+
(client.getSessionInputs as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
|
470
|
+
await vi.advanceTimersByTimeAsync(RESULT_TIMEOUT_MS * 5);
|
|
471
|
+
expect(client.getSessionInputs).not.toHaveBeenCalled();
|
|
472
|
+
expect(p.isDone).toBe(true);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
});
|