repoburg 1.3.202 → 1.3.209
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/dist/index.js +2103 -32003
- package/agent-pane/backend/dist/server.js +45313 -0
- package/backend/dist/src/agent-runtime/agent-runtime.types.d.ts +1 -0
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js +6 -6
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js +1 -0
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js.map +1 -1
- package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
- package/daemon/dist/agentPane.js +128 -0
- package/daemon/dist/agentPane.spec.js +183 -0
- package/daemon/dist/index.js +28 -8
- package/daemon/package.json +1 -1
- package/model-selector-scroll.png +0 -0
- package/package.json +10 -2
- package/agent-pane/.prettierignore +0 -5
- package/agent-pane/.prettierrc +0 -8
- package/agent-pane/backend/coverage/base.css +0 -224
- package/agent-pane/backend/coverage/block-navigation.js +0 -87
- package/agent-pane/backend/coverage/clover.xml +0 -887
- package/agent-pane/backend/coverage/coverage-final.json +0 -10
- package/agent-pane/backend/coverage/favicon.png +0 -0
- package/agent-pane/backend/coverage/index.html +0 -176
- package/agent-pane/backend/coverage/prettify.css +0 -1
- package/agent-pane/backend/coverage/prettify.js +0 -2
- package/agent-pane/backend/coverage/sort-arrow-sprite.png +0 -0
- package/agent-pane/backend/coverage/sorter.js +0 -210
- package/agent-pane/backend/coverage/src/codex/codex-provider.ts.html +0 -1402
- package/agent-pane/backend/coverage/src/codex/index.html +0 -131
- package/agent-pane/backend/coverage/src/codex/item-mapper.ts.html +0 -331
- package/agent-pane/backend/coverage/src/db/index.html +0 -131
- package/agent-pane/backend/coverage/src/db/index.ts.html +0 -436
- package/agent-pane/backend/coverage/src/db/schema.ts.html +0 -175
- package/agent-pane/backend/coverage/src/index.html +0 -116
- package/agent-pane/backend/coverage/src/index.ts.html +0 -262
- package/agent-pane/backend/coverage/src/routes/index.html +0 -146
- package/agent-pane/backend/coverage/src/routes/sessions.ts.html +0 -991
- package/agent-pane/backend/coverage/src/routes/turns.ts.html +0 -256
- package/agent-pane/backend/coverage/src/routes/workspaces.ts.html +0 -406
- package/agent-pane/backend/coverage/src/ws/index.html +0 -116
- package/agent-pane/backend/coverage/src/ws/index.ts.html +0 -238
- 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/package-lock.json +0 -5945
- package/agent-pane/backend/package.json +0 -33
- package/agent-pane/backend/scripts/backfill-from-jsonl.ts +0 -206
- package/agent-pane/backend/scripts/import-session-from-jsonl.ts +0 -264
- package/agent-pane/backend/src/claude/claude-message-mapper.test.ts +0 -271
- package/agent-pane/backend/src/claude/claude-message-mapper.ts +0 -259
- package/agent-pane/backend/src/claude/claude-provider.test.ts +0 -455
- package/agent-pane/backend/src/claude/claude-provider.ts +0 -1319
- package/agent-pane/backend/src/claude/claude-types.ts +0 -45
- package/agent-pane/backend/src/codex/app-server-client.test.ts +0 -183
- package/agent-pane/backend/src/codex/app-server-client.ts +0 -247
- package/agent-pane/backend/src/codex/app-server-types.ts +0 -259
- package/agent-pane/backend/src/codex/codex-provider-runtime-config.test.ts +0 -56
- package/agent-pane/backend/src/codex/codex-provider.test.ts +0 -60
- package/agent-pane/backend/src/codex/codex-provider.ts +0 -619
- package/agent-pane/backend/src/codex/item-mapper.test.ts +0 -221
- package/agent-pane/backend/src/codex/item-mapper.ts +0 -86
- package/agent-pane/backend/src/codex/shared-app-server.ts +0 -25
- package/agent-pane/backend/src/db/index.test.ts +0 -125
- package/agent-pane/backend/src/db/index.ts +0 -236
- package/agent-pane/backend/src/db/schema.ts +0 -34
- package/agent-pane/backend/src/index.ts +0 -89
- package/agent-pane/backend/src/integration/__fixtures__/cancel-turn.json +0 -29
- package/agent-pane/backend/src/integration/__fixtures__/delta-streaming.json +0 -40
- package/agent-pane/backend/src/integration/__fixtures__/failed-turn.json +0 -16
- package/agent-pane/backend/src/integration/__fixtures__/mcp-tool-call.json +0 -60
- package/agent-pane/backend/src/integration/__fixtures__/missing-item-started.json +0 -34
- package/agent-pane/backend/src/integration/__fixtures__/multi-item-turn.json +0 -85
- package/agent-pane/backend/src/integration/__fixtures__/multi-turn.json +0 -48
- package/agent-pane/backend/src/integration/__fixtures__/simple-turn.json +0 -35
- package/agent-pane/backend/src/integration/delta-streaming.test.ts +0 -130
- package/agent-pane/backend/src/integration/helpers/app-server-mock.ts +0 -272
- package/agent-pane/backend/src/integration/helpers/test-app.ts +0 -110
- package/agent-pane/backend/src/integration/helpers/ws-capture.ts +0 -64
- package/agent-pane/backend/src/integration/item-lifecycle.test.ts +0 -133
- package/agent-pane/backend/src/integration/mcp-tool-call.test.ts +0 -102
- package/agent-pane/backend/src/integration/missing-item-started.test.ts +0 -91
- package/agent-pane/backend/src/integration/multi-turn.test.ts +0 -121
- package/agent-pane/backend/src/integration/session-operations.test.ts +0 -175
- package/agent-pane/backend/src/integration/threads-claude-fork.test.ts +0 -241
- package/agent-pane/backend/src/integration/threads.test.ts +0 -309
- package/agent-pane/backend/src/integration/title-generation.test.ts +0 -109
- package/agent-pane/backend/src/integration/turn-cancel.test.ts +0 -111
- package/agent-pane/backend/src/integration/turn-failure.test.ts +0 -97
- package/agent-pane/backend/src/integration/turn-lifecycle.test.ts +0 -141
- package/agent-pane/backend/src/providers/index.ts +0 -16
- package/agent-pane/backend/src/providers/registry.test.ts +0 -92
- package/agent-pane/backend/src/providers/registry.ts +0 -43
- package/agent-pane/backend/src/providers/runtime-provider.ts +0 -49
- package/agent-pane/backend/src/repoburg/action-mapping.test.ts +0 -122
- package/agent-pane/backend/src/repoburg/action-mapping.ts +0 -294
- package/agent-pane/backend/src/repoburg/agent-runtime-client.test.ts +0 -271
- package/agent-pane/backend/src/repoburg/agent-runtime-client.ts +0 -285
- package/agent-pane/backend/src/repoburg/backend-resolver.test.ts +0 -356
- package/agent-pane/backend/src/repoburg/backend-resolver.ts +0 -261
- package/agent-pane/backend/src/repoburg/repoburg-client.test.ts +0 -180
- package/agent-pane/backend/src/repoburg/repoburg-client.ts +0 -194
- package/agent-pane/backend/src/repoburg/repoburg-provider.test.ts +0 -780
- package/agent-pane/backend/src/repoburg/repoburg-provider.ts +0 -471
- package/agent-pane/backend/src/repoburg/turn-projector.test.ts +0 -621
- package/agent-pane/backend/src/repoburg/turn-projector.ts +0 -637
- package/agent-pane/backend/src/routes/files.ts +0 -31
- package/agent-pane/backend/src/routes/mcp.ts +0 -33
- package/agent-pane/backend/src/routes/models.test.ts +0 -92
- package/agent-pane/backend/src/routes/models.ts +0 -16
- package/agent-pane/backend/src/routes/plugins.ts +0 -40
- package/agent-pane/backend/src/routes/providers.test.ts +0 -86
- package/agent-pane/backend/src/routes/providers.ts +0 -86
- package/agent-pane/backend/src/routes/sessions.test.ts +0 -772
- package/agent-pane/backend/src/routes/sessions.ts +0 -565
- package/agent-pane/backend/src/routes/skills.test.ts +0 -114
- package/agent-pane/backend/src/routes/skills.ts +0 -70
- package/agent-pane/backend/src/routes/threads.ts +0 -323
- package/agent-pane/backend/src/routes/turns.test.ts +0 -196
- package/agent-pane/backend/src/routes/turns.ts +0 -103
- package/agent-pane/backend/src/routes/workspaces.test.ts +0 -197
- package/agent-pane/backend/src/routes/workspaces.ts +0 -128
- package/agent-pane/backend/src/ws/index.test.ts +0 -107
- package/agent-pane/backend/src/ws/index.ts +0 -51
- package/agent-pane/backend/tsconfig.json +0 -25
- package/agent-pane/backend/vitest.config.ts +0 -20
- package/agent-pane/eslint.config.js +0 -33
- package/agent-pane/frontend/coverage/base.css +0 -224
- package/agent-pane/frontend/coverage/block-navigation.js +0 -87
- package/agent-pane/frontend/coverage/clover.xml +0 -2962
- package/agent-pane/frontend/coverage/coverage-final.json +0 -37
- package/agent-pane/frontend/coverage/favicon.png +0 -0
- package/agent-pane/frontend/coverage/index.html +0 -251
- package/agent-pane/frontend/coverage/prettify.css +0 -1
- package/agent-pane/frontend/coverage/prettify.js +0 -2
- package/agent-pane/frontend/coverage/sort-arrow-sprite.png +0 -0
- package/agent-pane/frontend/coverage/sorter.js +0 -210
- package/agent-pane/frontend/coverage/src/App.tsx.html +0 -217
- package/agent-pane/frontend/coverage/src/AppInitializer.tsx.html +0 -223
- package/agent-pane/frontend/coverage/src/api/client.ts.html +0 -187
- package/agent-pane/frontend/coverage/src/api/index.html +0 -161
- package/agent-pane/frontend/coverage/src/api/sessions.ts.html +0 -316
- package/agent-pane/frontend/coverage/src/api/websocket.ts.html +0 -544
- package/agent-pane/frontend/coverage/src/api/workspaces.ts.html +0 -199
- package/agent-pane/frontend/coverage/src/components/CollapsibleToolCalls.tsx.html +0 -226
- package/agent-pane/frontend/coverage/src/components/CommandInputBar.tsx.html +0 -382
- package/agent-pane/frontend/coverage/src/components/CommandPalette.tsx.html +0 -715
- package/agent-pane/frontend/coverage/src/components/IdeWorkspace.tsx.html +0 -160
- package/agent-pane/frontend/coverage/src/components/ModelSelector.tsx.html +0 -478
- package/agent-pane/frontend/coverage/src/components/NewSessionDialog.tsx.html +0 -472
- package/agent-pane/frontend/coverage/src/components/RenderArea.tsx.html +0 -574
- package/agent-pane/frontend/coverage/src/components/RightPanel.tsx.html +0 -205
- package/agent-pane/frontend/coverage/src/components/RuntimeIcon.tsx.html +0 -133
- package/agent-pane/frontend/coverage/src/components/SessionTabs.tsx.html +0 -217
- package/agent-pane/frontend/coverage/src/components/StatusBar.tsx.html +0 -271
- package/agent-pane/frontend/coverage/src/components/StatusDot.tsx.html +0 -109
- package/agent-pane/frontend/coverage/src/components/Toast.tsx.html +0 -313
- package/agent-pane/frontend/coverage/src/components/TurnContent.tsx.html +0 -1216
- package/agent-pane/frontend/coverage/src/components/WorkspaceSidebar.tsx.html +0 -1138
- package/agent-pane/frontend/coverage/src/components/index.html +0 -326
- package/agent-pane/frontend/coverage/src/components/panels/ChangesPanel.tsx.html +0 -247
- package/agent-pane/frontend/coverage/src/components/panels/LogsPanel.tsx.html +0 -160
- package/agent-pane/frontend/coverage/src/components/panels/MetricsPanel.tsx.html +0 -427
- package/agent-pane/frontend/coverage/src/components/panels/TurnsPanel.tsx.html +0 -397
- package/agent-pane/frontend/coverage/src/components/panels/index.html +0 -161
- package/agent-pane/frontend/coverage/src/constants/index.html +0 -116
- package/agent-pane/frontend/coverage/src/constants/models.ts.html +0 -406
- package/agent-pane/frontend/coverage/src/hooks/index.html +0 -146
- package/agent-pane/frontend/coverage/src/hooks/useEscapeKey.ts.html +0 -124
- package/agent-pane/frontend/coverage/src/hooks/useOutsideClick.ts.html +0 -142
- package/agent-pane/frontend/coverage/src/hooks/useSessionStatus.ts.html +0 -187
- package/agent-pane/frontend/coverage/src/index.html +0 -146
- package/agent-pane/frontend/coverage/src/main.tsx.html +0 -115
- package/agent-pane/frontend/coverage/src/store/index.html +0 -116
- package/agent-pane/frontend/coverage/src/store/store.ts.html +0 -2404
- package/agent-pane/frontend/coverage/src/test/component-helpers.ts.html +0 -190
- package/agent-pane/frontend/coverage/src/test/fixtures.ts.html +0 -367
- package/agent-pane/frontend/coverage/src/test/index.html +0 -131
- package/agent-pane/frontend/coverage/src/types/index.html +0 -116
- package/agent-pane/frontend/coverage/src/types/index.ts.html +0 -466
- package/agent-pane/frontend/coverage/src/utils/changes.ts.html +0 -202
- package/agent-pane/frontend/coverage/src/utils/duration.ts.html +0 -127
- package/agent-pane/frontend/coverage/src/utils/index.html +0 -131
- package/agent-pane/frontend/dist/assets/index-CJxD4YmJ.js +0 -370
- package/agent-pane/frontend/dist/assets/index-r-xwfOKQ.css +0 -1
- package/agent-pane/frontend/dist/index.html +0 -19
- package/agent-pane/frontend/index.html +0 -18
- package/agent-pane/frontend/package-lock.json +0 -4211
- package/agent-pane/frontend/package.json +0 -35
- package/agent-pane/frontend/src/App.test.tsx +0 -74
- package/agent-pane/frontend/src/App.tsx +0 -44
- package/agent-pane/frontend/src/AppInitializer.test.tsx +0 -142
- package/agent-pane/frontend/src/AppInitializer.tsx +0 -46
- package/agent-pane/frontend/src/__tests__/ThreadsPanel.test.tsx +0 -192
- package/agent-pane/frontend/src/api/client.test.ts +0 -126
- package/agent-pane/frontend/src/api/client.ts +0 -34
- package/agent-pane/frontend/src/api/models.ts +0 -7
- package/agent-pane/frontend/src/api/providers.ts +0 -17
- package/agent-pane/frontend/src/api/sessions.test.ts +0 -246
- package/agent-pane/frontend/src/api/sessions.ts +0 -97
- package/agent-pane/frontend/src/api/skills.ts +0 -12
- package/agent-pane/frontend/src/api/websocket.test.ts +0 -288
- package/agent-pane/frontend/src/api/websocket.ts +0 -240
- package/agent-pane/frontend/src/api/workspaces.test.ts +0 -112
- package/agent-pane/frontend/src/api/workspaces.ts +0 -38
- package/agent-pane/frontend/src/components/AskUserItem.test.tsx +0 -143
- package/agent-pane/frontend/src/components/AskUserItem.tsx +0 -207
- package/agent-pane/frontend/src/components/CollapsibleToolCalls.test.tsx +0 -49
- package/agent-pane/frontend/src/components/CollapsibleToolCalls.tsx +0 -56
- package/agent-pane/frontend/src/components/CommandInputBar.test.tsx +0 -133
- package/agent-pane/frontend/src/components/CommandInputBar.tsx +0 -584
- package/agent-pane/frontend/src/components/CommandPalette.test.tsx +0 -226
- package/agent-pane/frontend/src/components/CommandPalette.tsx +0 -194
- package/agent-pane/frontend/src/components/CommentableText.test.tsx +0 -196
- package/agent-pane/frontend/src/components/CommentableText.tsx +0 -379
- package/agent-pane/frontend/src/components/IdeWorkspace.test.tsx +0 -39
- package/agent-pane/frontend/src/components/IdeWorkspace.tsx +0 -51
- package/agent-pane/frontend/src/components/ModelSelector.test.tsx +0 -129
- package/agent-pane/frontend/src/components/ModelSelector.tsx +0 -191
- package/agent-pane/frontend/src/components/NewSessionDialog.test.tsx +0 -95
- package/agent-pane/frontend/src/components/NewSessionDialog.tsx +0 -129
- package/agent-pane/frontend/src/components/RenderArea.test.tsx +0 -160
- package/agent-pane/frontend/src/components/RenderArea.tsx +0 -170
- package/agent-pane/frontend/src/components/ResizeHandle.tsx +0 -29
- package/agent-pane/frontend/src/components/RightPanel.test.tsx +0 -43
- package/agent-pane/frontend/src/components/RightPanel.tsx +0 -46
- package/agent-pane/frontend/src/components/RuntimeIcon.test.tsx +0 -32
- package/agent-pane/frontend/src/components/RuntimeIcon.tsx +0 -16
- package/agent-pane/frontend/src/components/SessionTabs.test.tsx +0 -72
- package/agent-pane/frontend/src/components/SessionTabs.tsx +0 -49
- package/agent-pane/frontend/src/components/StatusBar.test.tsx +0 -56
- package/agent-pane/frontend/src/components/StatusBar.tsx +0 -129
- package/agent-pane/frontend/src/components/StatusDot.test.tsx +0 -25
- package/agent-pane/frontend/src/components/StatusDot.tsx +0 -8
- package/agent-pane/frontend/src/components/Toast.test.tsx +0 -79
- package/agent-pane/frontend/src/components/Toast.tsx +0 -76
- package/agent-pane/frontend/src/components/TurnContent.test.tsx +0 -377
- package/agent-pane/frontend/src/components/TurnContent.tsx +0 -594
- package/agent-pane/frontend/src/components/WorkspaceSidebar.test.tsx +0 -297
- package/agent-pane/frontend/src/components/WorkspaceSidebar.tsx +0 -351
- package/agent-pane/frontend/src/components/input/OptionSubPopup.tsx +0 -32
- package/agent-pane/frontend/src/components/input/SkillMentionPopup.test.tsx +0 -63
- package/agent-pane/frontend/src/components/input/SkillMentionPopup.tsx +0 -78
- package/agent-pane/frontend/src/components/input/SlashPopup.test.tsx +0 -96
- package/agent-pane/frontend/src/components/input/SlashPopup.tsx +0 -82
- package/agent-pane/frontend/src/components/panels/ChangesPanel.test.tsx +0 -61
- package/agent-pane/frontend/src/components/panels/ChangesPanel.tsx +0 -54
- package/agent-pane/frontend/src/components/panels/TasksPanel.test.tsx +0 -97
- package/agent-pane/frontend/src/components/panels/TasksPanel.tsx +0 -208
- package/agent-pane/frontend/src/components/panels/ThreadsPanel.tsx +0 -382
- package/agent-pane/frontend/src/components/panels/TurnsPanel.test.tsx +0 -131
- package/agent-pane/frontend/src/components/panels/TurnsPanel.tsx +0 -131
- package/agent-pane/frontend/src/constants/models.test.ts +0 -97
- package/agent-pane/frontend/src/constants/models.ts +0 -166
- package/agent-pane/frontend/src/hooks/useEscapeKey.test.ts +0 -42
- package/agent-pane/frontend/src/hooks/useEscapeKey.ts +0 -13
- package/agent-pane/frontend/src/hooks/useOutsideClick.test.ts +0 -92
- package/agent-pane/frontend/src/hooks/useOutsideClick.ts +0 -19
- package/agent-pane/frontend/src/hooks/useProvider.ts +0 -44
- package/agent-pane/frontend/src/hooks/useResizable.test.ts +0 -97
- package/agent-pane/frontend/src/hooks/useResizable.ts +0 -75
- package/agent-pane/frontend/src/hooks/useSessionStatus.test.ts +0 -116
- package/agent-pane/frontend/src/hooks/useSessionStatus.ts +0 -34
- package/agent-pane/frontend/src/main.test.tsx +0 -37
- package/agent-pane/frontend/src/main.tsx +0 -10
- package/agent-pane/frontend/src/store/sessionSlice.ts +0 -440
- package/agent-pane/frontend/src/store/store.test.ts +0 -1338
- package/agent-pane/frontend/src/store/store.ts +0 -37
- package/agent-pane/frontend/src/store/threadSlice.ts +0 -136
- package/agent-pane/frontend/src/store/uiSlice.ts +0 -133
- package/agent-pane/frontend/src/store/workspaceSlice.ts +0 -77
- package/agent-pane/frontend/src/store/wsSlice.ts +0 -368
- package/agent-pane/frontend/src/styles/app.css +0 -627
- package/agent-pane/frontend/src/styles/tokens.css +0 -62
- package/agent-pane/frontend/src/test/component-helpers.ts +0 -38
- package/agent-pane/frontend/src/test/fixtures.ts +0 -101
- package/agent-pane/frontend/src/test-setup.ts +0 -5
- package/agent-pane/frontend/src/types/index.test.ts +0 -128
- package/agent-pane/frontend/src/types/index.ts +0 -134
- package/agent-pane/frontend/src/utils/changes.test.ts +0 -81
- package/agent-pane/frontend/src/utils/changes.ts +0 -39
- package/agent-pane/frontend/src/utils/duration.test.ts +0 -76
- package/agent-pane/frontend/src/utils/duration.ts +0 -14
- package/agent-pane/frontend/tsconfig.json +0 -25
- package/agent-pane/frontend/vite.config.ts +0 -22
- package/agent-pane/frontend/vitest.config.ts +0 -29
- package/agent-pane/package-lock.json +0 -1527
- package/agent-pane/package.json +0 -19
- package/agent-pane/shared/provider-types.ts +0 -67
- package/agent-pane/shared/types.ts +0 -184
|
@@ -1,621 +0,0 @@
|
|
|
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
|
-
});
|