repoburg 1.3.199 → 1.3.202
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 +1658 -277
- 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 +12 -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/providers/runtime-provider.ts +6 -0
- package/agent-pane/backend/src/repoburg/action-mapping.test.ts +122 -0
- package/agent-pane/backend/src/repoburg/action-mapping.ts +294 -0
- package/agent-pane/backend/src/repoburg/agent-runtime-client.test.ts +271 -0
- package/agent-pane/backend/src/repoburg/agent-runtime-client.ts +285 -0
- package/agent-pane/backend/src/repoburg/backend-resolver.test.ts +356 -0
- package/agent-pane/backend/src/repoburg/backend-resolver.ts +261 -0
- package/agent-pane/backend/src/repoburg/repoburg-client.test.ts +180 -0
- package/agent-pane/backend/src/repoburg/repoburg-client.ts +194 -0
- package/agent-pane/backend/src/repoburg/repoburg-provider.test.ts +780 -0
- package/agent-pane/backend/src/repoburg/repoburg-provider.ts +471 -0
- package/agent-pane/backend/src/repoburg/turn-projector.test.ts +621 -0
- package/agent-pane/backend/src/repoburg/turn-projector.ts +637 -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.test.ts +215 -1
- package/agent-pane/backend/src/routes/sessions.ts +82 -9
- 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-CJxD4YmJ.js +370 -0
- package/agent-pane/frontend/dist/assets/{index-Dwwhx7YN.css → index-r-xwfOKQ.css} +1 -1
- package/agent-pane/frontend/dist/index.html +2 -2
- package/agent-pane/frontend/src/api/sessions.test.ts +1 -0
- package/agent-pane/frontend/src/api/websocket.test.ts +2 -2
- package/agent-pane/frontend/src/api/websocket.ts +3 -1
- package/agent-pane/frontend/src/components/AskUserItem.test.tsx +143 -0
- package/agent-pane/frontend/src/components/AskUserItem.tsx +207 -0
- 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/TurnContent.test.tsx +79 -0
- package/agent-pane/frontend/src/components/TurnContent.tsx +49 -3
- package/agent-pane/frontend/src/components/panels/ThreadsPanel.tsx +35 -3
- package/agent-pane/frontend/src/components/panels/TurnsPanel.test.tsx +48 -0
- package/agent-pane/frontend/src/components/panels/TurnsPanel.tsx +7 -2
- 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 +54 -0
- package/agent-pane/frontend/src/store/uiSlice.ts +50 -0
- package/agent-pane/frontend/src/store/wsSlice.ts +10 -3
- package/agent-pane/frontend/src/styles/app.css +26 -1
- package/agent-pane/frontend/src/test/component-helpers.ts +2 -0
- package/agent-pane/frontend/src/test/fixtures.ts +1 -0
- package/agent-pane/frontend/src/types/index.ts +2 -0
- package/agent-pane/frontend/src/utils/duration.test.ts +1 -0
- package/agent-pane/shared/types.ts +17 -0
- package/agent-pane-bug-repro-no-agent-reply.png +0 -0
- package/askuser-after-step5-postgres-selected.png +0 -0
- package/askuser-after-step7-answer-sent.png +0 -0
- package/askuser-card-visible.png +0 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.d.ts +36 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js +199 -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 +92 -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.controller.d.ts +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/app.service.d.ts +1 -0
- package/backend/dist/src/app.service.js +4 -1
- package/backend/dist/src/app.service.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 +7 -1
- package/backend/dist/src/interactive-chat/chat.service.js +54 -7
- package/backend/dist/src/interactive-chat/chat.service.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/invoke-subagent.handler.js +12 -1
- package/backend/dist/src/llm-orchestration/action-handlers/invoke-subagent.handler.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.interfaces.d.ts +1 -0
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.js +1 -0
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.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 +37 -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/api/services.js +4 -0
- package/daemon/dist/index.js +0 -0
- package/daemon/dist/serviceManager.js +30 -11
- package/daemon/dist/serviceManager.spec.js +26 -0
- package/daemon/dist/workspace-validation.js +63 -0
- package/daemon/dist/workspace-validation.spec.js +63 -0
- package/package.json +1 -1
- package/r2-step4-apple-banana.png +0 -0
- package/r2-step5-after-rewind-apple-last.png +0 -0
- package/r2-step7-apple-cherry.png +0 -0
- package/r2-step8-cherry-menu-no-restore.png +0 -0
- package/r3-step3-live-task-card-running.png +0 -0
- package/r3-step4-after-completion.png +0 -0
- package/r3-step5-persistence-after-reload.png +0 -0
- package/r3-step6-tasks-tab-card.png +0 -0
- package/reverify-answered-state-answer-sent.png +0 -0
- package/reverify-card-visible-after-completion.png +0 -0
- package/rewind-step3-apple-banana-turns.png +0 -0
- package/rewind-step5-ui-unchanged-after-confirmed-rewind.png +0 -0
- package/rewind-step6-apple-menu-no-restore.png +0 -0
- package/rewind-step7-final-turnlist-unchanged.png +0 -0
- package/rewind-step7-negative-error-toast.png +0 -0
- package/rewind-step7-negative-error-toast2.png +0 -0
- package/subagent-r2-step5-turn-after-reload-no-card.png +0 -0
- package/subagent-r2-step6-tasks-panel-card.png +0 -0
- package/subagent-step3-tasks-tab-done-card.png +0 -0
- package/subagent-step4-turn-stuck-no-cards.png +0 -0
- package/agent-pane/frontend/dist/assets/index-BYo-lnxm.js +0 -362
|
@@ -0,0 +1,621 @@
|
|
|
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
|
+
selections: null,
|
|
38
|
+
order_of_execution: 0,
|
|
39
|
+
...overrides,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('TurnProjector', () => {
|
|
44
|
+
let db: Database.Database;
|
|
45
|
+
let projector: TurnProjector | null = null;
|
|
46
|
+
const client = {
|
|
47
|
+
getSessionInputs: vi.fn(),
|
|
48
|
+
getSession: vi.fn(),
|
|
49
|
+
} as unknown as RepoburgRuntimeClient;
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
vi.clearAllMocks();
|
|
53
|
+
captured.length = 0;
|
|
54
|
+
db = initDb(':memory:');
|
|
55
|
+
const now = new Date().toISOString();
|
|
56
|
+
db.prepare(
|
|
57
|
+
`INSERT INTO sessions (id, title, runtime_type, status, is_running, lifecycle, created_at, updated_at)
|
|
58
|
+
VALUES (?, NULL, 'repoburg', 'running', 1, 'working', ?, ?)`,
|
|
59
|
+
).run(SESSION_ID, now, now);
|
|
60
|
+
db.prepare(
|
|
61
|
+
`INSERT INTO turns (id, session_id, user_prompt, status, created_at, updated_at)
|
|
62
|
+
VALUES (?, ?, 'hello', 'running', ?, ?)`,
|
|
63
|
+
).run(TURN_ID, SESSION_ID, now, now);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
afterEach(() => {
|
|
67
|
+
projector?.close();
|
|
68
|
+
projector = null;
|
|
69
|
+
db.close();
|
|
70
|
+
vi.useRealTimers();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
function makeProjector(): TurnProjector {
|
|
74
|
+
projector = new TurnProjector({
|
|
75
|
+
agentPaneSessionId: SESSION_ID,
|
|
76
|
+
turnId: TURN_ID,
|
|
77
|
+
repoburgSessionId: RUNTIME_SESSION_ID,
|
|
78
|
+
client,
|
|
79
|
+
});
|
|
80
|
+
return projector;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function items(): Array<{ external_item_id: string; type: string; status: string; data: string }> {
|
|
84
|
+
return db
|
|
85
|
+
.prepare('SELECT external_item_id, type, status, data FROM items WHERE turn_id = ? ORDER BY rowid')
|
|
86
|
+
.all(TURN_ID) as never;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function turnRow(): { status: string; agent_response: string | null; token_usage: string | null; error: string | null } {
|
|
90
|
+
return db.prepare('SELECT status, agent_response, token_usage, error FROM turns WHERE id = ?').get(TURN_ID) as never;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
describe('stream_event + assistant', () => {
|
|
94
|
+
it('starts items on first delta and streams further deltas', () => {
|
|
95
|
+
const p = makeProjector();
|
|
96
|
+
|
|
97
|
+
p.handle({
|
|
98
|
+
type: 'stream_event',
|
|
99
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
100
|
+
inputId: 'in-1',
|
|
101
|
+
delta: { type: 'text', text: 'Hel' },
|
|
102
|
+
});
|
|
103
|
+
p.handle({
|
|
104
|
+
type: 'stream_event',
|
|
105
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
106
|
+
inputId: 'in-1',
|
|
107
|
+
delta: { type: 'text', text: 'lo' },
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const rows = items();
|
|
111
|
+
expect(rows).toHaveLength(1);
|
|
112
|
+
expect(rows[0].type).toBe('agent_message');
|
|
113
|
+
expect(rows[0].status).toBe('in_progress');
|
|
114
|
+
expect(JSON.parse(rows[0].data)).toEqual({ text: 'Hel' }); // item data from FIRST insert
|
|
115
|
+
|
|
116
|
+
const delta = captured.find((b) => b.event === 'item:delta');
|
|
117
|
+
expect(delta).toBeDefined();
|
|
118
|
+
expect(delta!.data).toMatchObject({ turnId: TURN_ID, itemId: 'in-1-text', delta: 'lo' });
|
|
119
|
+
});
|
|
120
|
+
it('records runtime input ids into turns.runtime_input_ids (rewind anchor mapping)', () => {
|
|
121
|
+
const p = makeProjector();
|
|
122
|
+
|
|
123
|
+
// Round 1
|
|
124
|
+
p.handle({
|
|
125
|
+
type: 'assistant',
|
|
126
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
127
|
+
inputId: 'in-1',
|
|
128
|
+
content: [{ type: 'text', text: 'Round one' }],
|
|
129
|
+
});
|
|
130
|
+
// Round 2 (multi-round turn)
|
|
131
|
+
p.handle({
|
|
132
|
+
type: 'assistant',
|
|
133
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
134
|
+
inputId: 'in-2',
|
|
135
|
+
content: [{ type: 'text', text: 'Round two' }],
|
|
136
|
+
});
|
|
137
|
+
// Replay of an existing round must NOT duplicate the id
|
|
138
|
+
p.handle({
|
|
139
|
+
type: 'stream_event',
|
|
140
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
141
|
+
inputId: 'in-2',
|
|
142
|
+
delta: { type: 'text', text: ' again' },
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const row = db
|
|
146
|
+
.prepare('SELECT runtime_input_ids FROM turns WHERE id = ?')
|
|
147
|
+
.get(TURN_ID) as { runtime_input_ids: string | null };
|
|
148
|
+
expect(JSON.parse(row.runtime_input_ids!)).toEqual(['in-1', 'in-2']);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('completes streamed items when the assistant message arrives', () => {
|
|
152
|
+
const p = makeProjector();
|
|
153
|
+
p.handle({
|
|
154
|
+
type: 'stream_event',
|
|
155
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
156
|
+
inputId: 'in-1',
|
|
157
|
+
delta: { type: 'text', text: 'Hel' },
|
|
158
|
+
});
|
|
159
|
+
p.handle({
|
|
160
|
+
type: 'assistant',
|
|
161
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
162
|
+
inputId: 'in-1',
|
|
163
|
+
content: [
|
|
164
|
+
{ type: 'thinking', thinking: 'hmm' },
|
|
165
|
+
{ type: 'text', text: 'Hello world' },
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const rows = items();
|
|
170
|
+
expect(rows.map((r) => r.type)).toEqual(['agent_message', 'reasoning']);
|
|
171
|
+
expect(rows.every((r) => r.status === 'completed')).toBe(true);
|
|
172
|
+
expect(JSON.parse(rows[0].data)).toEqual({ text: 'Hello world' });
|
|
173
|
+
expect(JSON.parse(rows[1].data)).toEqual({ text: 'hmm' });
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('creates completed items from assistant alone (deltas off/missed)', () => {
|
|
177
|
+
const p = makeProjector();
|
|
178
|
+
p.handle({
|
|
179
|
+
type: 'assistant',
|
|
180
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
181
|
+
inputId: 'in-1',
|
|
182
|
+
content: [{ type: 'text', text: 'Hello' }],
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const rows = items();
|
|
186
|
+
expect(rows).toHaveLength(1);
|
|
187
|
+
expect(rows[0].status).toBe('completed');
|
|
188
|
+
expect(JSON.parse(rows[0].data)).toEqual({ text: 'Hello' });
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('user tool_result', () => {
|
|
193
|
+
it('maps actions to items and skips final/html_final (part of the response)', () => {
|
|
194
|
+
const p = makeProjector();
|
|
195
|
+
p.handle({
|
|
196
|
+
type: 'user',
|
|
197
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
198
|
+
inputId: 'in-1',
|
|
199
|
+
content: [
|
|
200
|
+
{
|
|
201
|
+
type: 'tool_result',
|
|
202
|
+
tool_use_id: 'a1',
|
|
203
|
+
content: 'created',
|
|
204
|
+
is_error: false,
|
|
205
|
+
action: actionInfo({ id: 'a1', action_type: 'create_file' }),
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
type: 'tool_result',
|
|
209
|
+
tool_use_id: 'a2',
|
|
210
|
+
content: 'ls output',
|
|
211
|
+
is_error: false,
|
|
212
|
+
action: actionInfo({ id: 'a2', action_type: 'run_command', file_path: null, command_string: 'ls' }),
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
type: 'tool_result',
|
|
216
|
+
tool_use_id: 'a3',
|
|
217
|
+
content: 'final text',
|
|
218
|
+
is_error: false,
|
|
219
|
+
action: actionInfo({ id: 'a3', action_type: 'final', plain: 'Final text' }),
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
const rows = items();
|
|
225
|
+
expect(rows.map((r) => r.external_item_id)).toEqual(['in-1-action-a1', 'in-1-action-a2']);
|
|
226
|
+
expect(rows[0].type).toBe('file_change');
|
|
227
|
+
expect(rows[1].type).toBe('command_execution');
|
|
228
|
+
expect(JSON.parse(rows[1].data).aggregated_output).toBe('ls output');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('maps failed actions to failed items with the error text', () => {
|
|
232
|
+
const p = makeProjector();
|
|
233
|
+
p.handle({
|
|
234
|
+
type: 'user',
|
|
235
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
236
|
+
inputId: 'in-1',
|
|
237
|
+
content: [
|
|
238
|
+
{
|
|
239
|
+
type: 'tool_result',
|
|
240
|
+
tool_use_id: 'a1',
|
|
241
|
+
content: 'command crashed',
|
|
242
|
+
is_error: true,
|
|
243
|
+
action: actionInfo({
|
|
244
|
+
id: 'a1',
|
|
245
|
+
action_type: 'run_command',
|
|
246
|
+
file_path: null,
|
|
247
|
+
command_string: 'boom',
|
|
248
|
+
status: 'EXECUTION_FAILED',
|
|
249
|
+
}),
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const rows = items();
|
|
255
|
+
expect(rows).toHaveLength(1);
|
|
256
|
+
expect(rows[0].status).toBe('failed');
|
|
257
|
+
expect(JSON.parse(rows[0].data).status).toBe('failed');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('is idempotent — replayed messages do not duplicate items', () => {
|
|
261
|
+
const p = makeProjector();
|
|
262
|
+
const assistant: AgentRuntimeMessage = {
|
|
263
|
+
type: 'assistant',
|
|
264
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
265
|
+
inputId: 'in-1',
|
|
266
|
+
content: [{ type: 'text', text: 'Hello' }],
|
|
267
|
+
};
|
|
268
|
+
const user: AgentRuntimeMessage = {
|
|
269
|
+
type: 'user',
|
|
270
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
271
|
+
inputId: 'in-1',
|
|
272
|
+
content: [
|
|
273
|
+
{
|
|
274
|
+
type: 'tool_result',
|
|
275
|
+
tool_use_id: 'a1',
|
|
276
|
+
content: 'created',
|
|
277
|
+
is_error: false,
|
|
278
|
+
action: actionInfo(),
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
p.handle(assistant);
|
|
284
|
+
p.handle(user);
|
|
285
|
+
p.handle(assistant); // replay (reconnect)
|
|
286
|
+
p.handle(user);
|
|
287
|
+
|
|
288
|
+
expect(items().map((r) => r.external_item_id).sort()).toEqual(['in-1-action-a1', 'in-1-text']);
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
describe('result', () => {
|
|
293
|
+
it('success completes the turn with result text, usage, and title sync', async () => {
|
|
294
|
+
(client.getSession as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
295
|
+
id: RUNTIME_SESSION_ID,
|
|
296
|
+
session_title: 'Synced Title',
|
|
297
|
+
is_running: false,
|
|
298
|
+
});
|
|
299
|
+
const p = makeProjector();
|
|
300
|
+
|
|
301
|
+
p.handle({
|
|
302
|
+
type: 'assistant',
|
|
303
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
304
|
+
inputId: 'in-1',
|
|
305
|
+
content: [{ type: 'text', text: 'working' }],
|
|
306
|
+
});
|
|
307
|
+
p.handle({
|
|
308
|
+
type: 'result',
|
|
309
|
+
subtype: 'success',
|
|
310
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
311
|
+
is_error: false,
|
|
312
|
+
result: 'All done',
|
|
313
|
+
usage: { input_tokens: 10, output_tokens: 5, cache_read_input_tokens: 2, cache_creation_input_tokens: 0 },
|
|
314
|
+
num_rounds: 2,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
const row = turnRow();
|
|
318
|
+
expect(row.status).toBe('completed');
|
|
319
|
+
expect(row.agent_response).toBe('All done');
|
|
320
|
+
expect(JSON.parse(row.token_usage!)).toMatchObject({
|
|
321
|
+
input_tokens: 10,
|
|
322
|
+
output_tokens: 5,
|
|
323
|
+
cached_input_tokens: 2,
|
|
324
|
+
});
|
|
325
|
+
expect(captured.find((b) => b.event === 'turn:completed')).toBeDefined();
|
|
326
|
+
// The completion broadcast carries the final text — the FE renders it
|
|
327
|
+
// for final-action turns that have no agent_message item.
|
|
328
|
+
const completed = captured.find((b) => b.event === 'turn:completed');
|
|
329
|
+
expect(completed!.data).toMatchObject({ response: 'All done' });
|
|
330
|
+
|
|
331
|
+
// Session marked not-running with unreviewed actions.
|
|
332
|
+
const session = db.prepare('SELECT is_running, status, has_unreviewed FROM sessions WHERE id = ?').get(SESSION_ID) as never;
|
|
333
|
+
expect(session).toMatchObject({ is_running: 0, status: 'active', has_unreviewed: 1 });
|
|
334
|
+
|
|
335
|
+
// Title sync (async, fire-and-forget).
|
|
336
|
+
await vi.waitFor(() => {
|
|
337
|
+
const s = db.prepare('SELECT title FROM sessions WHERE id = ?').get(SESSION_ID) as { title: string | null };
|
|
338
|
+
expect(s.title).toBe('Synced Title');
|
|
339
|
+
});
|
|
340
|
+
expect(captured.find((b) => b.event === 'session:title')).toBeDefined();
|
|
341
|
+
|
|
342
|
+
// Projector done — later messages ignored.
|
|
343
|
+
p.handle({
|
|
344
|
+
type: 'result',
|
|
345
|
+
subtype: 'success',
|
|
346
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
347
|
+
is_error: false,
|
|
348
|
+
result: 'late',
|
|
349
|
+
num_rounds: 0,
|
|
350
|
+
} as never);
|
|
351
|
+
expect(turnRow().agent_response).toBe('All done');
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('success falls back to the last round text when result text is empty', () => {
|
|
355
|
+
const p = makeProjector();
|
|
356
|
+
p.handle({
|
|
357
|
+
type: 'assistant',
|
|
358
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
359
|
+
inputId: 'in-1',
|
|
360
|
+
content: [{ type: 'text', text: 'Fallback text' }],
|
|
361
|
+
});
|
|
362
|
+
p.handle({
|
|
363
|
+
type: 'result',
|
|
364
|
+
subtype: 'success',
|
|
365
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
366
|
+
is_error: false,
|
|
367
|
+
result: '',
|
|
368
|
+
num_rounds: 1,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
expect(turnRow().agent_response).toBe('Fallback text');
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('error fails the turn and closes open items as failed', () => {
|
|
375
|
+
const p = makeProjector();
|
|
376
|
+
p.handle({
|
|
377
|
+
type: 'stream_event',
|
|
378
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
379
|
+
inputId: 'in-1',
|
|
380
|
+
delta: { type: 'text', text: 'partial' },
|
|
381
|
+
});
|
|
382
|
+
p.handle({
|
|
383
|
+
type: 'result',
|
|
384
|
+
subtype: 'error_during_execution',
|
|
385
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
386
|
+
is_error: true,
|
|
387
|
+
result: '',
|
|
388
|
+
num_rounds: 1,
|
|
389
|
+
errors: ['boom', 'bang'],
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
const row = turnRow();
|
|
393
|
+
expect(row.status).toBe('failed');
|
|
394
|
+
expect(row.error).toBe('boom; bang');
|
|
395
|
+
expect(items()[0].status).toBe('failed');
|
|
396
|
+
expect(captured.find((b) => b.event === 'turn:failed')).toBeDefined();
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('aborted aborts the turn and closes open items as completed', () => {
|
|
400
|
+
const p = makeProjector();
|
|
401
|
+
p.handle({
|
|
402
|
+
type: 'stream_event',
|
|
403
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
404
|
+
inputId: 'in-1',
|
|
405
|
+
delta: { type: 'text', text: 'partial' },
|
|
406
|
+
});
|
|
407
|
+
p.handle({
|
|
408
|
+
type: 'result',
|
|
409
|
+
subtype: 'aborted',
|
|
410
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
411
|
+
is_error: true,
|
|
412
|
+
result: '',
|
|
413
|
+
num_rounds: 0,
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
expect(turnRow().status).toBe('aborted');
|
|
417
|
+
expect(items()[0].status).toBe('completed');
|
|
418
|
+
expect(captured.find((b) => b.event === 'turn:cancelled')).toBeDefined();
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
describe('watch-dog + snapshot reconcile', () => {
|
|
423
|
+
it('completes the turn from the snapshot when the result never arrives', async () => {
|
|
424
|
+
vi.useFakeTimers();
|
|
425
|
+
(client.getSessionInputs as ReturnType<typeof vi.fn>).mockResolvedValue([
|
|
426
|
+
{
|
|
427
|
+
id: 'in-1',
|
|
428
|
+
role: 'model',
|
|
429
|
+
raw_llm_response: 'Snapshot reply',
|
|
430
|
+
thoughts: null,
|
|
431
|
+
input_token_count: 12,
|
|
432
|
+
output_token_count: 6,
|
|
433
|
+
cached_token_count: 3,
|
|
434
|
+
aiActions: [
|
|
435
|
+
{
|
|
436
|
+
id: 'a1',
|
|
437
|
+
action_type: 'create_file',
|
|
438
|
+
file_path: 'src/x.ts',
|
|
439
|
+
status: 'CONFIRMED_KEPT',
|
|
440
|
+
order_of_execution: 0,
|
|
441
|
+
executionLogs: [{ output: 'created', error_message: null }],
|
|
442
|
+
},
|
|
443
|
+
],
|
|
444
|
+
},
|
|
445
|
+
]);
|
|
446
|
+
(client.getSession as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
447
|
+
id: RUNTIME_SESSION_ID,
|
|
448
|
+
session_title: null,
|
|
449
|
+
is_running: false,
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
const p = makeProjector();
|
|
453
|
+
p.handle({
|
|
454
|
+
type: 'assistant',
|
|
455
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
456
|
+
inputId: 'in-1',
|
|
457
|
+
content: [{ type: 'text', text: 'Snapshot reply' }],
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
await vi.advanceTimersByTimeAsync(RESULT_TIMEOUT_MS + 1000);
|
|
461
|
+
|
|
462
|
+
// Snapshot projected (action item) and turn completed.
|
|
463
|
+
const ids = items().map((r) => r.external_item_id);
|
|
464
|
+
expect(ids).toContain('in-1-action-a1');
|
|
465
|
+
const row = turnRow();
|
|
466
|
+
expect(row.status).toBe('completed');
|
|
467
|
+
expect(row.agent_response).toBe('Snapshot reply');
|
|
468
|
+
expect(JSON.parse(row.token_usage!)).toMatchObject({ input_tokens: 12, output_tokens: 6, cached_input_tokens: 3 });
|
|
469
|
+
expect(client.getSessionInputs).toHaveBeenCalledWith(RUNTIME_SESSION_ID);
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it('re-arms while the runtime session is still running, then fails after max extensions', async () => {
|
|
473
|
+
vi.useFakeTimers();
|
|
474
|
+
(client.getSessionInputs as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
|
475
|
+
(client.getSession as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
476
|
+
id: RUNTIME_SESSION_ID,
|
|
477
|
+
session_title: null,
|
|
478
|
+
is_running: true,
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
makeProjector();
|
|
482
|
+
|
|
483
|
+
const firings = MAX_RESULT_EXTENSIONS + 1;
|
|
484
|
+
await vi.advanceTimersByTimeAsync(RESULT_TIMEOUT_MS * firings + 1000 * firings);
|
|
485
|
+
|
|
486
|
+
const row = turnRow();
|
|
487
|
+
expect(row.status).toBe('failed');
|
|
488
|
+
expect(row.error).toMatch(/still running/);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
describe('subagent lifecycle → background_task', () => {
|
|
492
|
+
/** One registered sub-agent event message. */
|
|
493
|
+
function subagent(event: 'started' | 'progress' | 'completed' | 'failed', extra: Record<string, unknown> = {}): AgentRuntimeMessage {
|
|
494
|
+
return {
|
|
495
|
+
type: 'subagent',
|
|
496
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
497
|
+
event,
|
|
498
|
+
task_id: 'child-1',
|
|
499
|
+
agent_name: 'explore-codebase',
|
|
500
|
+
description: 'Find auth files',
|
|
501
|
+
input_id: 'in-1',
|
|
502
|
+
action_id: 'act-1',
|
|
503
|
+
...extra,
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
it('started/progress/completed converge on ONE background_task item', () => {
|
|
508
|
+
const p = makeProjector();
|
|
509
|
+
|
|
510
|
+
p.handle(subagent('started'));
|
|
511
|
+
let rows = items();
|
|
512
|
+
expect(rows).toHaveLength(1);
|
|
513
|
+
expect(rows[0]).toMatchObject({
|
|
514
|
+
external_item_id: 'in-1-action-act-1',
|
|
515
|
+
type: 'background_task',
|
|
516
|
+
status: 'in_progress',
|
|
517
|
+
});
|
|
518
|
+
expect(JSON.parse(rows[0].data)).toMatchObject({
|
|
519
|
+
task_id: 'child-1',
|
|
520
|
+
description: 'Find auth files',
|
|
521
|
+
task_type: 'subagent',
|
|
522
|
+
subagent_type: 'explore-codebase',
|
|
523
|
+
status: 'running',
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
p.handle(subagent('progress', { description: 'create_file: src/auth.ts', last_tool_name: 'create_file', token_count: 120 }));
|
|
527
|
+
rows = items();
|
|
528
|
+
expect(rows).toHaveLength(1); // SAME item — no duplicates
|
|
529
|
+
expect(JSON.parse(rows[0].data)).toMatchObject({
|
|
530
|
+
description: 'create_file: src/auth.ts',
|
|
531
|
+
last_tool_name: 'create_file',
|
|
532
|
+
token_count: 120,
|
|
533
|
+
status: 'running',
|
|
534
|
+
});
|
|
535
|
+
const updated = captured.filter((b) => b.event === 'item:updated');
|
|
536
|
+
expect(updated).toHaveLength(1);
|
|
537
|
+
|
|
538
|
+
p.handle(subagent('completed', { summary: 'auth files found', usage: { input_tokens: 100, output_tokens: 20, cache_read_input_tokens: 0, cache_creation_input_tokens: 0 } }));
|
|
539
|
+
rows = items();
|
|
540
|
+
expect(rows).toHaveLength(1);
|
|
541
|
+
expect(rows[0].status).toBe('completed');
|
|
542
|
+
expect(JSON.parse(rows[0].data)).toMatchObject({
|
|
543
|
+
status: 'completed',
|
|
544
|
+
summary: 'auth files found',
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it('failed settlement marks the card failed', () => {
|
|
549
|
+
const p = makeProjector();
|
|
550
|
+
|
|
551
|
+
p.handle(subagent('started'));
|
|
552
|
+
p.handle(subagent('failed', { summary: 'boom' }));
|
|
553
|
+
|
|
554
|
+
const rows = items();
|
|
555
|
+
expect(rows).toHaveLength(1);
|
|
556
|
+
expect(rows[0].status).toBe('failed');
|
|
557
|
+
expect(JSON.parse(rows[0].data)).toMatchObject({ status: 'failed', summary: 'boom' });
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
it('invoke_subagent tool_result with the same action id does NOT duplicate the live card', () => {
|
|
561
|
+
const p = makeProjector();
|
|
562
|
+
|
|
563
|
+
p.handle(subagent('started'));
|
|
564
|
+
p.handle({
|
|
565
|
+
type: 'user',
|
|
566
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
567
|
+
inputId: 'in-1',
|
|
568
|
+
content: [
|
|
569
|
+
{
|
|
570
|
+
type: 'tool_result',
|
|
571
|
+
tool_use_id: 'act-1',
|
|
572
|
+
content: 'child output',
|
|
573
|
+
is_error: false,
|
|
574
|
+
action: actionInfo({
|
|
575
|
+
id: 'act-1',
|
|
576
|
+
action_type: 'invoke_subagent',
|
|
577
|
+
arguments: JSON.stringify({ agent_name: 'explore-codebase', prompt: 'Find auth files' }),
|
|
578
|
+
file_path: null,
|
|
579
|
+
}),
|
|
580
|
+
},
|
|
581
|
+
],
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
const rows = items();
|
|
585
|
+
expect(rows).toHaveLength(1);
|
|
586
|
+
expect(rows[0].external_item_id).toBe('in-1-action-act-1');
|
|
587
|
+
expect(rows[0].type).toBe('background_task');
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it('a completed card from subagent events survives a later completed event idempotently', () => {
|
|
591
|
+
const p = makeProjector();
|
|
592
|
+
|
|
593
|
+
p.handle(subagent('started'));
|
|
594
|
+
p.handle(subagent('completed', { summary: 'done' }));
|
|
595
|
+
p.handle(subagent('completed', { summary: 'done' })); // replay
|
|
596
|
+
|
|
597
|
+
const rows = items();
|
|
598
|
+
expect(rows).toHaveLength(1);
|
|
599
|
+
expect(rows[0].status).toBe('completed');
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
it('a live result cancels the watchdog', async () => {
|
|
603
|
+
vi.useFakeTimers();
|
|
604
|
+
const p = makeProjector();
|
|
605
|
+
p.handle({
|
|
606
|
+
type: 'result',
|
|
607
|
+
subtype: 'success',
|
|
608
|
+
sessionId: RUNTIME_SESSION_ID,
|
|
609
|
+
is_error: false,
|
|
610
|
+
result: 'done',
|
|
611
|
+
num_rounds: 1,
|
|
612
|
+
});
|
|
613
|
+
expect(turnRow().status).toBe('completed');
|
|
614
|
+
|
|
615
|
+
(client.getSessionInputs as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
|
616
|
+
await vi.advanceTimersByTimeAsync(RESULT_TIMEOUT_MS * 5);
|
|
617
|
+
expect(client.getSessionInputs).not.toHaveBeenCalled();
|
|
618
|
+
expect(p.isDone).toBe(true);
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
});
|