repoburg 1.3.188 → 1.3.196

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.
Files changed (265) hide show
  1. package/agent-pane/.prettierignore +5 -0
  2. package/agent-pane/.prettierrc +8 -0
  3. package/agent-pane/backend/coverage/base.css +224 -0
  4. package/agent-pane/backend/coverage/block-navigation.js +87 -0
  5. package/agent-pane/backend/coverage/clover.xml +887 -0
  6. package/agent-pane/backend/coverage/coverage-final.json +10 -0
  7. package/agent-pane/backend/coverage/favicon.png +0 -0
  8. package/agent-pane/backend/coverage/index.html +176 -0
  9. package/agent-pane/backend/coverage/prettify.css +1 -0
  10. package/agent-pane/backend/coverage/prettify.js +2 -0
  11. package/agent-pane/backend/coverage/sort-arrow-sprite.png +0 -0
  12. package/agent-pane/backend/coverage/sorter.js +210 -0
  13. package/agent-pane/backend/coverage/src/codex/codex-provider.ts.html +1402 -0
  14. package/agent-pane/backend/coverage/src/codex/index.html +131 -0
  15. package/agent-pane/backend/coverage/src/codex/item-mapper.ts.html +331 -0
  16. package/agent-pane/backend/coverage/src/db/index.html +131 -0
  17. package/agent-pane/backend/coverage/src/db/index.ts.html +436 -0
  18. package/agent-pane/backend/coverage/src/db/schema.ts.html +175 -0
  19. package/agent-pane/backend/coverage/src/index.html +116 -0
  20. package/agent-pane/backend/coverage/src/index.ts.html +262 -0
  21. package/agent-pane/backend/coverage/src/routes/index.html +146 -0
  22. package/agent-pane/backend/coverage/src/routes/sessions.ts.html +991 -0
  23. package/agent-pane/backend/coverage/src/routes/turns.ts.html +256 -0
  24. package/agent-pane/backend/coverage/src/routes/workspaces.ts.html +406 -0
  25. package/agent-pane/backend/coverage/src/ws/index.html +116 -0
  26. package/agent-pane/backend/coverage/src/ws/index.ts.html +238 -0
  27. package/agent-pane/backend/data.db +0 -0
  28. package/agent-pane/backend/data.db-shm +0 -0
  29. package/agent-pane/backend/data.db-wal +0 -0
  30. package/agent-pane/backend/dist/index.js +70869 -0
  31. package/agent-pane/backend/package-lock.json +4529 -1013
  32. package/agent-pane/backend/package.json +10 -6
  33. package/agent-pane/backend/src/claude/claude-message-mapper.test.ts +163 -0
  34. package/agent-pane/backend/src/claude/claude-message-mapper.ts +154 -0
  35. package/agent-pane/backend/src/claude/claude-provider.test.ts +65 -0
  36. package/agent-pane/backend/src/claude/claude-provider.ts +482 -0
  37. package/agent-pane/backend/src/claude/claude-types.ts +33 -0
  38. package/agent-pane/backend/src/codex/app-server-client.test.ts +183 -0
  39. package/agent-pane/backend/src/codex/app-server-client.ts +225 -0
  40. package/agent-pane/backend/src/codex/app-server-types.ts +259 -0
  41. package/agent-pane/backend/src/codex/codex-provider-runtime-config.test.ts +56 -0
  42. package/agent-pane/backend/src/codex/codex-provider.test.ts +60 -0
  43. package/agent-pane/backend/src/codex/codex-provider.ts +521 -265
  44. package/agent-pane/backend/src/codex/item-mapper.test.ts +221 -0
  45. package/agent-pane/backend/src/codex/item-mapper.ts +35 -8
  46. package/agent-pane/backend/src/codex/shared-app-server.ts +25 -0
  47. package/agent-pane/backend/src/db/index.test.ts +125 -0
  48. package/agent-pane/backend/src/db/index.ts +39 -8
  49. package/agent-pane/backend/src/db/schema.ts +28 -74
  50. package/agent-pane/backend/src/index.ts +29 -2
  51. package/agent-pane/backend/src/integration/__fixtures__/cancel-turn.json +29 -0
  52. package/agent-pane/backend/src/integration/__fixtures__/delta-streaming.json +40 -0
  53. package/agent-pane/backend/src/integration/__fixtures__/failed-turn.json +16 -0
  54. package/agent-pane/backend/src/integration/__fixtures__/mcp-tool-call.json +60 -0
  55. package/agent-pane/backend/src/integration/__fixtures__/missing-item-started.json +34 -0
  56. package/agent-pane/backend/src/integration/__fixtures__/multi-item-turn.json +85 -0
  57. package/agent-pane/backend/src/integration/__fixtures__/multi-turn.json +48 -0
  58. package/agent-pane/backend/src/integration/__fixtures__/simple-turn.json +35 -0
  59. package/agent-pane/backend/src/integration/delta-streaming.test.ts +130 -0
  60. package/agent-pane/backend/src/integration/helpers/app-server-mock.ts +272 -0
  61. package/agent-pane/backend/src/integration/helpers/test-app.ts +108 -0
  62. package/agent-pane/backend/src/integration/helpers/ws-capture.ts +64 -0
  63. package/agent-pane/backend/src/integration/item-lifecycle.test.ts +133 -0
  64. package/agent-pane/backend/src/integration/mcp-tool-call.test.ts +102 -0
  65. package/agent-pane/backend/src/integration/missing-item-started.test.ts +91 -0
  66. package/agent-pane/backend/src/integration/multi-turn.test.ts +121 -0
  67. package/agent-pane/backend/src/integration/session-operations.test.ts +168 -0
  68. package/agent-pane/backend/src/integration/title-generation.test.ts +109 -0
  69. package/agent-pane/backend/src/integration/turn-cancel.test.ts +111 -0
  70. package/agent-pane/backend/src/integration/turn-failure.test.ts +97 -0
  71. package/agent-pane/backend/src/integration/turn-lifecycle.test.ts +141 -0
  72. package/agent-pane/backend/src/providers/index.ts +14 -0
  73. package/agent-pane/backend/src/providers/registry.test.ts +92 -0
  74. package/agent-pane/backend/src/providers/registry.ts +43 -0
  75. package/agent-pane/backend/src/providers/runtime-provider.ts +25 -0
  76. package/agent-pane/backend/src/routes/files.ts +31 -0
  77. package/agent-pane/backend/src/routes/mcp.ts +33 -0
  78. package/agent-pane/backend/src/routes/models.test.ts +92 -0
  79. package/agent-pane/backend/src/routes/models.ts +16 -0
  80. package/agent-pane/backend/src/routes/plugins.ts +40 -0
  81. package/agent-pane/backend/src/routes/providers.test.ts +69 -0
  82. package/agent-pane/backend/src/routes/providers.ts +57 -0
  83. package/agent-pane/backend/src/routes/sessions.test.ts +424 -0
  84. package/agent-pane/backend/src/routes/sessions.ts +295 -42
  85. package/agent-pane/backend/src/routes/skills.test.ts +114 -0
  86. package/agent-pane/backend/src/routes/skills.ts +70 -0
  87. package/agent-pane/backend/src/routes/turns.test.ts +152 -0
  88. package/agent-pane/backend/src/routes/turns.ts +36 -16
  89. package/agent-pane/backend/src/routes/workspaces.test.ts +197 -0
  90. package/agent-pane/backend/src/routes/workspaces.ts +73 -55
  91. package/agent-pane/backend/src/ws/index.test.ts +107 -0
  92. package/agent-pane/backend/src/ws/index.ts +19 -11
  93. package/agent-pane/backend/tsconfig.json +4 -2
  94. package/agent-pane/backend/vitest.config.ts +20 -0
  95. package/agent-pane/eslint.config.js +33 -0
  96. package/agent-pane/frontend/coverage/base.css +224 -0
  97. package/agent-pane/frontend/coverage/block-navigation.js +87 -0
  98. package/agent-pane/frontend/coverage/clover.xml +2962 -0
  99. package/agent-pane/frontend/coverage/coverage-final.json +37 -0
  100. package/agent-pane/frontend/coverage/favicon.png +0 -0
  101. package/agent-pane/frontend/coverage/index.html +251 -0
  102. package/agent-pane/frontend/coverage/prettify.css +1 -0
  103. package/agent-pane/frontend/coverage/prettify.js +2 -0
  104. package/agent-pane/frontend/coverage/sort-arrow-sprite.png +0 -0
  105. package/agent-pane/frontend/coverage/sorter.js +210 -0
  106. package/agent-pane/frontend/coverage/src/App.tsx.html +217 -0
  107. package/agent-pane/frontend/coverage/src/AppInitializer.tsx.html +223 -0
  108. package/agent-pane/frontend/coverage/src/api/client.ts.html +187 -0
  109. package/agent-pane/frontend/coverage/src/api/index.html +161 -0
  110. package/agent-pane/frontend/coverage/src/api/sessions.ts.html +316 -0
  111. package/agent-pane/frontend/coverage/src/api/websocket.ts.html +544 -0
  112. package/agent-pane/frontend/coverage/src/api/workspaces.ts.html +199 -0
  113. package/agent-pane/frontend/coverage/src/components/CollapsibleToolCalls.tsx.html +226 -0
  114. package/agent-pane/frontend/coverage/src/components/CommandInputBar.tsx.html +382 -0
  115. package/agent-pane/frontend/coverage/src/components/CommandPalette.tsx.html +715 -0
  116. package/agent-pane/frontend/coverage/src/components/IdeWorkspace.tsx.html +160 -0
  117. package/agent-pane/frontend/coverage/src/components/ModelSelector.tsx.html +478 -0
  118. package/agent-pane/frontend/coverage/src/components/NewSessionDialog.tsx.html +472 -0
  119. package/agent-pane/frontend/coverage/src/components/RenderArea.tsx.html +574 -0
  120. package/agent-pane/frontend/coverage/src/components/RightPanel.tsx.html +205 -0
  121. package/agent-pane/frontend/coverage/src/components/RuntimeIcon.tsx.html +133 -0
  122. package/agent-pane/frontend/coverage/src/components/SessionTabs.tsx.html +217 -0
  123. package/agent-pane/frontend/coverage/src/components/StatusBar.tsx.html +271 -0
  124. package/agent-pane/frontend/coverage/src/components/StatusDot.tsx.html +109 -0
  125. package/agent-pane/frontend/coverage/src/components/Toast.tsx.html +313 -0
  126. package/agent-pane/frontend/coverage/src/components/TurnContent.tsx.html +1216 -0
  127. package/agent-pane/frontend/coverage/src/components/WorkspaceSidebar.tsx.html +1138 -0
  128. package/agent-pane/frontend/coverage/src/components/index.html +326 -0
  129. package/agent-pane/frontend/coverage/src/components/panels/ChangesPanel.tsx.html +247 -0
  130. package/agent-pane/frontend/coverage/src/components/panels/LogsPanel.tsx.html +160 -0
  131. package/agent-pane/frontend/coverage/src/components/panels/MetricsPanel.tsx.html +427 -0
  132. package/agent-pane/frontend/coverage/src/components/panels/TurnsPanel.tsx.html +397 -0
  133. package/agent-pane/frontend/coverage/src/components/panels/index.html +161 -0
  134. package/agent-pane/frontend/coverage/src/constants/index.html +116 -0
  135. package/agent-pane/frontend/coverage/src/constants/models.ts.html +406 -0
  136. package/agent-pane/frontend/coverage/src/hooks/index.html +146 -0
  137. package/agent-pane/frontend/coverage/src/hooks/useEscapeKey.ts.html +124 -0
  138. package/agent-pane/frontend/coverage/src/hooks/useOutsideClick.ts.html +142 -0
  139. package/agent-pane/frontend/coverage/src/hooks/useSessionStatus.ts.html +187 -0
  140. package/agent-pane/frontend/coverage/src/index.html +146 -0
  141. package/agent-pane/frontend/coverage/src/main.tsx.html +115 -0
  142. package/agent-pane/frontend/coverage/src/store/index.html +116 -0
  143. package/agent-pane/frontend/coverage/src/store/store.ts.html +2404 -0
  144. package/agent-pane/frontend/coverage/src/test/component-helpers.ts.html +190 -0
  145. package/agent-pane/frontend/coverage/src/test/fixtures.ts.html +367 -0
  146. package/agent-pane/frontend/coverage/src/test/index.html +131 -0
  147. package/agent-pane/frontend/coverage/src/types/index.html +116 -0
  148. package/agent-pane/frontend/coverage/src/types/index.ts.html +466 -0
  149. package/agent-pane/frontend/coverage/src/utils/changes.ts.html +202 -0
  150. package/agent-pane/frontend/coverage/src/utils/duration.ts.html +127 -0
  151. package/agent-pane/frontend/coverage/src/utils/index.html +131 -0
  152. package/agent-pane/frontend/dist/assets/index-Bg0PF2aV.css +1 -0
  153. package/agent-pane/frontend/dist/assets/index-BlybeX5e.js +281 -0
  154. package/agent-pane/frontend/dist/index.html +19 -0
  155. package/agent-pane/frontend/package-lock.json +2434 -213
  156. package/agent-pane/frontend/package.json +10 -3
  157. package/agent-pane/frontend/src/App.test.tsx +74 -0
  158. package/agent-pane/frontend/src/App.tsx +1 -1
  159. package/agent-pane/frontend/src/AppInitializer.test.tsx +142 -0
  160. package/agent-pane/frontend/src/AppInitializer.tsx +1 -1
  161. package/agent-pane/frontend/src/api/client.test.ts +126 -0
  162. package/agent-pane/frontend/src/api/client.ts +22 -29
  163. package/agent-pane/frontend/src/api/models.ts +7 -0
  164. package/agent-pane/frontend/src/api/providers.ts +12 -0
  165. package/agent-pane/frontend/src/api/sessions.test.ts +241 -0
  166. package/agent-pane/frontend/src/api/sessions.ts +43 -1
  167. package/agent-pane/frontend/src/api/skills.ts +12 -0
  168. package/agent-pane/frontend/src/api/websocket.test.ts +288 -0
  169. package/agent-pane/frontend/src/api/websocket.ts +27 -2
  170. package/agent-pane/frontend/src/api/workspaces.test.ts +112 -0
  171. package/agent-pane/frontend/src/api/workspaces.ts +17 -3
  172. package/agent-pane/frontend/src/components/CollapsibleToolCalls.test.tsx +49 -0
  173. package/agent-pane/frontend/src/components/CollapsibleToolCalls.tsx +2 -5
  174. package/agent-pane/frontend/src/components/CommandInputBar.test.tsx +133 -0
  175. package/agent-pane/frontend/src/components/CommandInputBar.tsx +296 -17
  176. package/agent-pane/frontend/src/components/CommandPalette.test.tsx +230 -0
  177. package/agent-pane/frontend/src/components/CommandPalette.tsx +26 -23
  178. package/agent-pane/frontend/src/components/IdeWorkspace.tsx +1 -1
  179. package/agent-pane/frontend/src/components/ModelSelector.test.tsx +129 -0
  180. package/agent-pane/frontend/src/components/ModelSelector.tsx +191 -0
  181. package/agent-pane/frontend/src/components/NewSessionDialog.test.tsx +95 -0
  182. package/agent-pane/frontend/src/components/NewSessionDialog.tsx +58 -13
  183. package/agent-pane/frontend/src/components/RenderArea.test.tsx +160 -0
  184. package/agent-pane/frontend/src/components/RenderArea.tsx +18 -25
  185. package/agent-pane/frontend/src/components/RightPanel.test.tsx +43 -0
  186. package/agent-pane/frontend/src/components/RightPanel.tsx +1 -1
  187. package/agent-pane/frontend/src/components/RuntimeIcon.test.tsx +32 -0
  188. package/agent-pane/frontend/src/components/RuntimeIcon.tsx +1 -1
  189. package/agent-pane/frontend/src/components/SessionTabs.test.tsx +72 -0
  190. package/agent-pane/frontend/src/components/SessionTabs.tsx +12 -12
  191. package/agent-pane/frontend/src/components/StatusBar.test.tsx +56 -0
  192. package/agent-pane/frontend/src/components/StatusBar.tsx +25 -31
  193. package/agent-pane/frontend/src/components/StatusDot.test.tsx +25 -0
  194. package/agent-pane/frontend/src/components/StatusDot.tsx +2 -7
  195. package/agent-pane/frontend/src/components/Toast.test.tsx +79 -0
  196. package/agent-pane/frontend/src/components/Toast.tsx +2 -6
  197. package/agent-pane/frontend/src/components/TurnContent.test.tsx +287 -0
  198. package/agent-pane/frontend/src/components/TurnContent.tsx +107 -24
  199. package/agent-pane/frontend/src/components/WorkspaceSidebar.test.tsx +297 -0
  200. package/agent-pane/frontend/src/components/WorkspaceSidebar.tsx +33 -32
  201. package/agent-pane/frontend/src/components/input/OptionSubPopup.tsx +32 -0
  202. package/agent-pane/frontend/src/components/input/SkillMentionPopup.test.tsx +63 -0
  203. package/agent-pane/frontend/src/components/input/SkillMentionPopup.tsx +78 -0
  204. package/agent-pane/frontend/src/components/input/SlashPopup.test.tsx +96 -0
  205. package/agent-pane/frontend/src/components/input/SlashPopup.tsx +63 -0
  206. package/agent-pane/frontend/src/components/panels/ChangesPanel.test.tsx +61 -0
  207. package/agent-pane/frontend/src/components/panels/ChangesPanel.tsx +12 -39
  208. package/agent-pane/frontend/src/components/panels/LogsPanel.test.tsx +58 -0
  209. package/agent-pane/frontend/src/components/panels/LogsPanel.tsx +1 -1
  210. package/agent-pane/frontend/src/components/panels/MetricsPanel.test.tsx +71 -0
  211. package/agent-pane/frontend/src/components/panels/MetricsPanel.tsx +63 -31
  212. package/agent-pane/frontend/src/components/panels/TurnsPanel.test.tsx +83 -0
  213. package/agent-pane/frontend/src/components/panels/TurnsPanel.tsx +66 -7
  214. package/agent-pane/frontend/src/constants/models.test.ts +97 -0
  215. package/agent-pane/frontend/src/constants/models.ts +129 -0
  216. package/agent-pane/frontend/src/hooks/useEscapeKey.test.ts +42 -0
  217. package/agent-pane/frontend/src/hooks/useEscapeKey.ts +13 -0
  218. package/agent-pane/frontend/src/hooks/useOutsideClick.test.ts +92 -0
  219. package/agent-pane/frontend/src/hooks/useOutsideClick.ts +19 -0
  220. package/agent-pane/frontend/src/hooks/useProvider.ts +44 -0
  221. package/agent-pane/frontend/src/hooks/useSessionStatus.test.ts +114 -0
  222. package/agent-pane/frontend/src/hooks/useSessionStatus.ts +34 -0
  223. package/agent-pane/frontend/src/main.test.tsx +37 -0
  224. package/agent-pane/frontend/src/main.tsx +1 -1
  225. package/agent-pane/frontend/src/store/sessionSlice.ts +417 -0
  226. package/agent-pane/frontend/src/store/store.test.ts +1284 -0
  227. package/agent-pane/frontend/src/store/store.ts +16 -617
  228. package/agent-pane/frontend/src/store/uiSlice.ts +83 -0
  229. package/agent-pane/frontend/src/store/workspaceSlice.ts +77 -0
  230. package/agent-pane/frontend/src/store/wsSlice.ts +292 -0
  231. package/agent-pane/frontend/src/styles/app.css +113 -7
  232. package/agent-pane/frontend/src/test/component-helpers.ts +36 -0
  233. package/agent-pane/frontend/src/test/fixtures.ts +96 -0
  234. package/agent-pane/frontend/src/test-setup.ts +5 -0
  235. package/agent-pane/frontend/src/types/index.test.ts +128 -0
  236. package/agent-pane/frontend/src/types/index.ts +80 -104
  237. package/agent-pane/frontend/src/utils/changes.test.ts +81 -0
  238. package/agent-pane/frontend/src/utils/changes.ts +39 -0
  239. package/agent-pane/frontend/src/utils/duration.test.ts +71 -0
  240. package/agent-pane/frontend/src/utils/duration.ts +14 -0
  241. package/agent-pane/frontend/tsconfig.json +4 -1
  242. package/agent-pane/frontend/vite.config.ts +6 -0
  243. package/agent-pane/frontend/vitest.config.ts +29 -0
  244. package/agent-pane/package-lock.json +1527 -0
  245. package/agent-pane/package.json +19 -0
  246. package/agent-pane/shared/provider-types.ts +53 -0
  247. package/agent-pane/shared/types.ts +107 -0
  248. package/agentpane-branch-session.png +0 -0
  249. package/agentpane-expanded-all.png +0 -0
  250. package/agentpane-fixed-rendering.png +0 -0
  251. package/agentpane-focus-check.png +0 -0
  252. package/agentpane-initial.png +0 -0
  253. package/agentpane-mcp-detail.png +0 -0
  254. package/agentpane-no-focus-ring.png +0 -0
  255. package/agentpane-soft-focus.png +0 -0
  256. package/backend/dist/src/llm-provider/ollama-llm.provider.js +1 -0
  257. package/backend/dist/src/llm-provider/ollama-llm.provider.js.map +1 -1
  258. package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
  259. package/data.db +0 -0
  260. package/empty-state.png +0 -0
  261. package/frontend-home.png +0 -0
  262. package/model-selector-open.png +0 -0
  263. package/package.json +1 -1
  264. package/slash-popup-working.png +0 -0
  265. package/agent-pane/frontend/src/components/DiffViewer.tsx +0 -27
@@ -0,0 +1,272 @@
1
+ /**
2
+ * App-server replay mock for integration tests.
3
+ *
4
+ * Replaces the old `@openai/codex-sdk` replay mock. The mock AppServerClient
5
+ * replays fixture events as JSON-RPC notifications (item/started, item/completed,
6
+ * turn/completed, turn/failed) instead of SDK async generators.
7
+ *
8
+ * The fixture format is unchanged — events use SDK-style names (thread.started,
9
+ * item.started, etc.) which are translated to app-server notification names
10
+ * (thread/started, item/started, etc.) by the mock.
11
+ */
12
+
13
+ import { EventEmitter } from 'node:events';
14
+
15
+ /** A single event captured from the real SDK (or app-server). */
16
+ type FixtureEvent = Record<string, unknown>;
17
+
18
+ /** A captured interaction (events for one turn). */
19
+ interface ReplayCall {
20
+ prompt: string;
21
+ events: FixtureEvent[];
22
+ eventDelay?: number;
23
+ }
24
+
25
+ /** A captured title generation interaction. */
26
+ interface TitleCall {
27
+ prompt: string;
28
+ result: { finalResponse: string };
29
+ }
30
+
31
+ /** A complete fixture — all interactions for one test scenario. */
32
+ export interface Fixture {
33
+ name: string;
34
+ description: string;
35
+ threadId: string;
36
+ runStreamedCalls: ReplayCall[];
37
+ runCalls: TitleCall[];
38
+ }
39
+
40
+ /** Read a fixture from a JSON string. */
41
+ export function parseFixture(json: string): Fixture {
42
+ return JSON.parse(json) as Fixture;
43
+ }
44
+
45
+ /** Map SDK event type to app-server notification method. */
46
+ function sdkEventToNotification(eventType: string): string {
47
+ switch (eventType) {
48
+ case 'thread.started':
49
+ return 'thread/started';
50
+ case 'item.started':
51
+ return 'item/started';
52
+ case 'item.updated':
53
+ return 'item/updated';
54
+ case 'item.completed':
55
+ return 'item/completed';
56
+ case 'item.agentMessage.delta':
57
+ return 'item/agentMessage/delta';
58
+ case 'turn.completed':
59
+ return 'turn/completed';
60
+ case 'thread.tokenUsage.updated':
61
+ return 'thread/tokenUsage/updated';
62
+ case 'error':
63
+ return 'turn/failed';
64
+ default:
65
+ return eventType;
66
+ }
67
+ }
68
+
69
+ /** Map an SDK event to app-server notification params. */
70
+ function sdkEventToParams(event: FixtureEvent, threadId: string, turnId: string): Record<string, unknown> {
71
+ const type = event.type as string;
72
+
73
+ if (type === 'turn.completed') {
74
+ // Real app-server sends { threadId, turn: { id, status } } — no usage.
75
+ // Token usage arrives via separate thread/tokenUsage/updated notification.
76
+ return {
77
+ threadId,
78
+ turnId,
79
+ };
80
+ }
81
+
82
+ if (type === 'error') {
83
+ return {
84
+ threadId,
85
+ turnId,
86
+ error: { message: event.message as string },
87
+ };
88
+ }
89
+
90
+ if (type === 'item.agentMessage.delta') {
91
+ return {
92
+ threadId,
93
+ turnId,
94
+ itemId: event.itemId as string,
95
+ delta: event.delta as string,
96
+ };
97
+ }
98
+
99
+ if (type === 'thread.tokenUsage.updated') {
100
+ const usage = event.tokenUsage as {
101
+ inputTokens: number;
102
+ cachedInputTokens: number;
103
+ cacheWriteInputTokens: number;
104
+ outputTokens: number;
105
+ reasoningOutputTokens: number;
106
+ totalTokens: number;
107
+ };
108
+ return {
109
+ threadId,
110
+ turnId,
111
+ tokenUsage: {
112
+ total: usage,
113
+ last: usage,
114
+ modelContextWindow: event.modelContextWindow ?? 258400,
115
+ },
116
+ };
117
+ }
118
+
119
+ // item.* events
120
+ return {
121
+ threadId,
122
+ turnId,
123
+ item: event.item as Record<string, unknown>,
124
+ };
125
+ }
126
+
127
+ /**
128
+ * Create a mock AppServerClient class that replays fixture events.
129
+ *
130
+ * @param fixture — The fixture to replay.
131
+ * @returns A class that can be used to mock the AppServerClient module.
132
+ */
133
+ export function createAppServerMock(fixture: Fixture) {
134
+ return class MockAppServerClient {
135
+ readonly events = new EventEmitter();
136
+ private notificationHandlers = new Map<string, Array<(params: unknown) => void>>();
137
+ private closed = false;
138
+ private interrupted = false;
139
+ private turnStartIndex = 0;
140
+ private titleCallIndex = 0;
141
+
142
+ async initialize(): Promise<{ userAgent: string }> {
143
+ return { userAgent: 'mock/0.147.0' };
144
+ }
145
+
146
+ async request<T>(method: string, params?: unknown): Promise<T> {
147
+ if (this.closed) throw new Error('MockAppServerClient is closed');
148
+
149
+ switch (method) {
150
+ case 'thread/start':
151
+ case 'thread/resume':
152
+ return { thread: { id: fixture.threadId } } as T;
153
+
154
+ case 'turn/start': {
155
+ // Detect title generation by checking input prompt prefix
156
+ const inputText = (params as { input?: Array<{ text?: string }> })?.input?.[0]?.text ?? '';
157
+ const isTitleGen = inputText.startsWith('Generate a concise 3-5 word title');
158
+
159
+ if (isTitleGen) {
160
+ // Title generation — use runCalls
161
+ if (this.titleCallIndex < fixture.runCalls.length) {
162
+ const call = fixture.runCalls[this.titleCallIndex];
163
+ this.titleCallIndex++;
164
+
165
+ const turnId = `title_${this.titleCallIndex}`;
166
+ this.replayTitleCall(call, fixture.threadId, turnId);
167
+
168
+ return { turn: { id: turnId } } as T;
169
+ }
170
+ // No more title calls — return empty turn
171
+ return { turn: { id: 'empty_title' } } as T;
172
+ }
173
+
174
+ // Main turns use runStreamedCalls
175
+ if (this.turnStartIndex < fixture.runStreamedCalls.length) {
176
+ const call = fixture.runStreamedCalls[this.turnStartIndex];
177
+ this.turnStartIndex++;
178
+
179
+ const turnId = `turn_${this.turnStartIndex}`;
180
+ this.replayEvents(call, fixture.threadId, turnId);
181
+
182
+ return { turn: { id: turnId } } as T;
183
+ }
184
+
185
+ // No more fixture calls — return empty turn (no events)
186
+ return { turn: { id: 'empty' } } as T;
187
+ }
188
+
189
+ case 'turn/interrupt':
190
+ this.interrupted = true;
191
+ return {} as T;
192
+
193
+ default:
194
+ return {} as T;
195
+ }
196
+ }
197
+
198
+ notify(): void {
199
+ // No-op
200
+ }
201
+
202
+ onNotification(method: string, handler: (params: unknown) => void): void {
203
+ const handlers = this.notificationHandlers.get(method) ?? [];
204
+ handlers.push(handler);
205
+ this.notificationHandlers.set(method, handlers);
206
+ }
207
+
208
+ onRequest(): void {
209
+ // No-op
210
+ }
211
+
212
+ isClosed(): boolean {
213
+ return this.closed;
214
+ }
215
+
216
+ async close(): Promise<void> {
217
+ this.closed = true;
218
+ }
219
+
220
+ /** Replay fixture events as notifications with optional delay. */
221
+ private async replayEvents(call: ReplayCall, threadId: string, turnId: string): Promise<void> {
222
+ for (const event of call.events) {
223
+ if (this.interrupted) {
224
+ // On interrupt, stop replaying — codex-provider handles DB update + broadcast
225
+ return;
226
+ }
227
+
228
+ if (call.eventDelay) {
229
+ await new Promise((r) => setTimeout(r, call.eventDelay));
230
+ }
231
+
232
+ const type = event.type as string;
233
+ const method = sdkEventToNotification(type);
234
+ const params = sdkEventToParams(event, threadId, turnId);
235
+
236
+ this.emitNotification(method, params);
237
+ }
238
+ }
239
+
240
+ /** Replay a title generation call as notifications (item/completed + turn/completed). */
241
+ private async replayTitleCall(call: TitleCall, threadId: string, turnId: string): Promise<void> {
242
+ // Simulate: agent_message item started → completed → turn completed
243
+ this.emitNotification('item/started', {
244
+ threadId,
245
+ turnId,
246
+ item: { id: 'title_item', type: 'agent_message', text: '' },
247
+ });
248
+
249
+ this.emitNotification('item/completed', {
250
+ threadId,
251
+ turnId,
252
+ item: { id: 'title_item', type: 'agent_message', text: call.result.finalResponse },
253
+ });
254
+
255
+ this.emitNotification('turn/completed', {
256
+ threadId,
257
+ turnId,
258
+ });
259
+ }
260
+
261
+ /** Emit a notification to all registered handlers for the method. */
262
+ private emitNotification(method: string, params: unknown): void {
263
+ const handlers = this.notificationHandlers.get(method);
264
+ if (handlers) {
265
+ for (const handler of handlers) {
266
+ handler(params);
267
+ }
268
+ }
269
+ this.events.emit('notification', method, params);
270
+ }
271
+ };
272
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Test app factory for integration tests.
3
+ *
4
+ * Sets up a Fastify instance with all route handlers registered, using
5
+ * an in-memory SQLite database. The `app-server-client.ts` module is mocked
6
+ * by the test file (not here) using `createAppServerMock(fixture)`.
7
+ *
8
+ * Usage in a test file:
9
+ * ```ts
10
+ * vi.mock('../codex/app-server-client.ts', () => ({ AppServerClient: createAppServerMock(fixture) }));
11
+ * vi.mock('../../ws/index.ts', () => ({ ...realWs, broadcast: mockBroadcast }));
12
+ * const { app, db } = await createTestApp();
13
+ * ```
14
+ */
15
+
16
+ import Fastify, { type FastifyInstance } from 'fastify';
17
+ import type Database from 'better-sqlite3';
18
+ import { initDb } from '../../db/index.ts';
19
+ import { initWs } from '../../ws/index.ts';
20
+ import { registerSessionRoutes } from '../../routes/sessions.ts';
21
+ import { registerTurnRoutes } from '../../routes/turns.ts';
22
+ import { registerWorkspaceRoutes } from '../../routes/workspaces.ts';
23
+ import { clearAllProviders } from '../../providers/registry.ts';
24
+ import '../../providers/index.ts'; // register providers for integration tests
25
+
26
+ export interface TestApp {
27
+ app: FastifyInstance;
28
+ db: Database.Database;
29
+ /** Close the Fastify instance and close the DB. */
30
+ cleanup: () => Promise<void>;
31
+ }
32
+
33
+ /**
34
+ * Create a test Fastify app with all routes and an in-memory DB.
35
+ *
36
+ * @returns `{ app, db, cleanup }`. Call `cleanup()` in `afterEach`.
37
+ */
38
+ export async function createTestApp(): Promise<TestApp> {
39
+ const db = initDb(':memory:');
40
+
41
+ const app = Fastify();
42
+
43
+ await registerSessionRoutes(app);
44
+ await registerTurnRoutes(app);
45
+ await registerWorkspaceRoutes(app);
46
+
47
+ initWs();
48
+
49
+ return {
50
+ app,
51
+ db,
52
+ cleanup: async () => {
53
+ clearAllProviders();
54
+ await app.close();
55
+ db.close();
56
+ },
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Wait for a turn to reach a terminal status by polling the DB.
62
+ *
63
+ * `startTurn()` is fire-and-forget — the HTTP POST returns immediately.
64
+ * Integration tests must wait for the async turn to finish before
65
+ * asserting on DB state or WS broadcasts.
66
+ *
67
+ * @param db — The in-memory DB instance.
68
+ * @param turnId — The turn ID to poll.
69
+ * @param timeoutMs — Max wait time (default 5000ms).
70
+ * @throws If the turn does not reach a terminal status within the timeout.
71
+ */
72
+ export async function waitForTurn(db: Database.Database, turnId: string, timeoutMs = 5000): Promise<void> {
73
+ const start = Date.now();
74
+ while (Date.now() - start < timeoutMs) {
75
+ const row = db.prepare('SELECT status FROM turns WHERE id = ?').get(turnId) as { status: string } | undefined;
76
+ if (!row) {
77
+ throw new Error(`Turn ${turnId} not found in DB`);
78
+ }
79
+ if (row.status === 'completed' || row.status === 'failed' || row.status === 'aborted') {
80
+ return;
81
+ }
82
+ await new Promise((r) => setTimeout(r, 50));
83
+ }
84
+ throw new Error(`Turn ${turnId} did not complete within ${timeoutMs}ms`);
85
+ }
86
+
87
+ /** Insert a session row with sensible defaults for integration tests. */
88
+ export function insertTestSession(db: Database.Database, id: string, overrides: Record<string, unknown> = {}): void {
89
+ const now = new Date().toISOString();
90
+ db.prepare(
91
+ `INSERT INTO sessions (id, title, runtime_type, model, model_reasoning_effort, cwd, external_thread_id, status, is_running, lifecycle, has_unreviewed, created_at, updated_at)
92
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
93
+ ).run(
94
+ id,
95
+ (overrides['title'] as string | null) ?? null,
96
+ (overrides['runtime_type'] as string) ?? 'codex',
97
+ (overrides['model'] as string | null) ?? null,
98
+ (overrides['model_reasoning_effort'] as string | null) ?? null,
99
+ (overrides['cwd'] as string | null) ?? null,
100
+ (overrides['external_thread_id'] as string | null) ?? null,
101
+ (overrides['status'] as string) ?? 'active',
102
+ (overrides['is_running'] as number) ?? 0,
103
+ (overrides['lifecycle'] as string) ?? 'working',
104
+ (overrides['has_unreviewed'] as number) ?? 0,
105
+ (overrides['created_at'] as string) ?? now,
106
+ (overrides['updated_at'] as string) ?? now,
107
+ );
108
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Broadcast capture helper for integration tests.
3
+ *
4
+ * Replaces the real `broadcast()` function in `ws/index.ts` with a spy
5
+ * that records every call. This lets integration tests assert on the
6
+ * exact sequence of WS events without connecting a real WebSocket client.
7
+ */
8
+
9
+ export interface CapturedBroadcast {
10
+ event: string;
11
+ data: unknown;
12
+ }
13
+
14
+ /** A list of captured broadcast calls, populated by the mock. */
15
+ export const capturedBroadcasts: CapturedBroadcast[] = [];
16
+
17
+ /** Clear all captured broadcasts. Call in `beforeEach`. */
18
+ export function clearBroadcasts(): void {
19
+ capturedBroadcasts.length = 0;
20
+ }
21
+
22
+ /**
23
+ * Mock broadcast function — records the call into `capturedBroadcasts`.
24
+ * Drop-in replacement for the real `broadcast()` in `ws/index.ts`.
25
+ */
26
+ export function mockBroadcast(event: string, data: unknown): void {
27
+ capturedBroadcasts.push({ event, data });
28
+ }
29
+
30
+ /**
31
+ * Assert that broadcasts contain a specific event type.
32
+ * @param event — The event name to find (e.g. 'turn:started').
33
+ * @returns The first matching broadcast's data.
34
+ * @throws If no matching broadcast is found.
35
+ */
36
+ export function findBroadcast(event: string): unknown {
37
+ const found = capturedBroadcasts.find((b) => b.event === event);
38
+ if (!found) {
39
+ const events = capturedBroadcasts.map((b) => b.event).join(', ');
40
+ throw new Error(`Expected broadcast "${event}" not found. Actual broadcasts: [${events}]`);
41
+ }
42
+ return found.data;
43
+ }
44
+
45
+ /**
46
+ * Assert the ordered sequence of broadcast event names.
47
+ * @param expected — Array of event names in expected order.
48
+ */
49
+ export function expectBroadcastSequence(expected: string[]): void {
50
+ const actual = capturedBroadcasts.map((b) => b.event);
51
+ if (actual.length < expected.length) {
52
+ throw new Error(
53
+ `Expected ${expected.length} broadcasts but got ${actual.length}. ` +
54
+ `Expected: [${expected.join(', ')}]. Actual: [${actual.join(', ')}]`,
55
+ );
56
+ }
57
+ for (let i = 0; i < expected.length; i++) {
58
+ if (actual[i] !== expected[i]) {
59
+ throw new Error(
60
+ `Broadcast ${i}: expected "${expected[i]}" but got "${actual[i]}". ` + `Full actual: [${actual.join(', ')}]`,
61
+ );
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Integration test: item lifecycle across multiple item types.
3
+ *
4
+ * Verifies that handleEvent correctly processes all item types through
5
+ * item-mapper, including status transitions, thoughts accumulation,
6
+ * and WS broadcasts for each item event.
7
+ *
8
+ * Uses HTTP POST to trigger the turn (fire-and-forget startTurn).
9
+ */
10
+
11
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
12
+ import { readFileSync } from 'node:fs';
13
+ import { resolve } from 'node:path';
14
+ import type Database from 'better-sqlite3';
15
+ import { createAppServerMock, type Fixture } from './helpers/app-server-mock.ts';
16
+ import { clearBroadcasts, capturedBroadcasts } from './helpers/ws-capture.ts';
17
+ import type { TestApp } from './helpers/test-app.ts';
18
+
19
+ const fixture = JSON.parse(readFileSync(resolve(__dirname, '__fixtures__/multi-item-turn.json'), 'utf-8')) as Fixture;
20
+
21
+ vi.mock('../codex/app-server-client.ts', () => ({
22
+ AppServerClient: createAppServerMock(fixture),
23
+ }));
24
+
25
+ vi.mock('../ws/index.ts', async (importOriginal) => {
26
+ const actual = (await importOriginal()) as Record<string, unknown>;
27
+ return {
28
+ ...actual,
29
+ broadcast: vi.fn((event: string, data: unknown) => {
30
+ capturedBroadcasts.push({ event, data });
31
+ }),
32
+ };
33
+ });
34
+
35
+ const { getDb } = await import('../db/index.ts');
36
+ const { createTestApp, waitForTurn } = await import('./helpers/test-app.ts');
37
+
38
+ describe('Integration: item lifecycle', () => {
39
+ let testApp: TestApp;
40
+
41
+ beforeEach(async () => {
42
+ vi.clearAllMocks();
43
+ clearBroadcasts();
44
+ testApp = await createTestApp();
45
+ });
46
+
47
+ afterEach(async () => {
48
+ await testApp.cleanup();
49
+ });
50
+
51
+ it('processes reasoning, command, file_change, agent_message items correctly', async () => {
52
+ const db: Database.Database = getDb();
53
+
54
+ // Create session
55
+ const createRes = await testApp.app.inject({
56
+ method: 'POST',
57
+ url: '/api/sessions',
58
+ payload: {},
59
+ });
60
+ const session = createRes.json();
61
+
62
+ // Submit turn via HTTP
63
+ const turnRes = await testApp.app.inject({
64
+ method: 'POST',
65
+ url: `/api/sessions/${session.id}/turns`,
66
+ payload: { user_prompt: 'List files and create a test file' },
67
+ });
68
+ const turn = turnRes.json();
69
+
70
+ await waitForTurn(db, turn.id);
71
+
72
+ // Assert items in DB — all 4 types mapped correctly
73
+ const items = db.prepare('SELECT * FROM items WHERE turn_id = ? ORDER BY created_at ASC').all(turn.id) as {
74
+ type: string;
75
+ data: string;
76
+ status: string;
77
+ }[];
78
+
79
+ expect(items).toHaveLength(4);
80
+
81
+ // Reasoning
82
+ expect(items[0].type).toBe('reasoning');
83
+ expect(items[0].status).toBe('completed');
84
+ expect(JSON.parse(items[0].data)).toEqual({
85
+ text: 'I need to list files first, then create a test file.',
86
+ });
87
+
88
+ // Command execution
89
+ expect(items[1].type).toBe('command_execution');
90
+ expect(items[1].status).toBe('completed');
91
+ expect(JSON.parse(items[1].data)).toEqual({
92
+ command: 'ls -la',
93
+ aggregated_output: 'total 0\ndrwxr-xr-x 2 user staff 64 Jan 1 00:00 .',
94
+ exit_code: 0,
95
+ status: 'completed',
96
+ });
97
+
98
+ // File change
99
+ expect(items[2].type).toBe('file_change');
100
+ expect(items[2].status).toBe('completed');
101
+ expect(JSON.parse(items[2].data)).toEqual({
102
+ changes: [{ path: 'test.txt', change_type: 'added' }],
103
+ status: 'completed',
104
+ });
105
+
106
+ // Agent message
107
+ expect(items[3].type).toBe('agent_message');
108
+ expect(items[3].status).toBe('completed');
109
+ expect(JSON.parse(items[3].data)).toEqual({
110
+ text: 'I listed the files and created test.txt for you.',
111
+ });
112
+
113
+ // Assert turn-level fields updated from items
114
+ const dbTurn = db.prepare('SELECT thoughts, agent_response FROM turns WHERE id = ?').get(turn.id) as {
115
+ thoughts: string | null;
116
+ agent_response: string | null;
117
+ };
118
+ expect(dbTurn.thoughts).toBe('I need to list files first, then create a test file.');
119
+ expect(dbTurn.agent_response).toBe('I listed the files and created test.txt for you.');
120
+
121
+ // Assert WS broadcasts — 4 item:started + 4 item:completed
122
+ const startedCount = capturedBroadcasts.filter((b) => b.event === 'item:started').length;
123
+ const completedCount = capturedBroadcasts.filter((b) => b.event === 'item:completed').length;
124
+ expect(startedCount).toBe(4);
125
+ expect(completedCount).toBe(4);
126
+
127
+ // Verify item:completed broadcasts contain correct item types
128
+ const completedTypes = capturedBroadcasts
129
+ .filter((b) => b.event === 'item:completed')
130
+ .map((b) => (b.data as { item: { type: string } }).item.type);
131
+ expect(completedTypes).toEqual(['reasoning', 'command_execution', 'file_change', 'agent_message']);
132
+ });
133
+ });
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Integration test: MCP tool call item type.
3
+ *
4
+ * Verifies that mcp_tool_call items are correctly mapped via item-mapper
5
+ * and stored in DB with the right data shape.
6
+ *
7
+ * Uses HTTP POST to trigger the turn (fire-and-forget startTurn).
8
+ */
9
+
10
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
11
+ import { readFileSync } from 'node:fs';
12
+ import { resolve } from 'node:path';
13
+ import type Database from 'better-sqlite3';
14
+ import { createAppServerMock, type Fixture } from './helpers/app-server-mock.ts';
15
+ import { clearBroadcasts, capturedBroadcasts } from './helpers/ws-capture.ts';
16
+ import type { TestApp } from './helpers/test-app.ts';
17
+
18
+ const fixture = JSON.parse(readFileSync(resolve(__dirname, '__fixtures__/mcp-tool-call.json'), 'utf-8')) as Fixture;
19
+
20
+ vi.mock('../codex/app-server-client.ts', () => ({
21
+ AppServerClient: createAppServerMock(fixture),
22
+ }));
23
+
24
+ vi.mock('../ws/index.ts', async (importOriginal) => {
25
+ const actual = (await importOriginal()) as Record<string, unknown>;
26
+ return {
27
+ ...actual,
28
+ broadcast: vi.fn((event: string, data: unknown) => {
29
+ capturedBroadcasts.push({ event, data });
30
+ }),
31
+ };
32
+ });
33
+
34
+ const { getDb } = await import('../db/index.ts');
35
+ const { createTestApp, waitForTurn } = await import('./helpers/test-app.ts');
36
+
37
+ describe('Integration: MCP tool call', () => {
38
+ let testApp: TestApp;
39
+
40
+ beforeEach(async () => {
41
+ vi.clearAllMocks();
42
+ clearBroadcasts();
43
+ testApp = await createTestApp();
44
+ });
45
+
46
+ afterEach(async () => {
47
+ await testApp.cleanup();
48
+ });
49
+
50
+ it('maps mcp_tool_call item with server, tool, arguments, result', async () => {
51
+ const db: Database.Database = getDb();
52
+
53
+ // Create session
54
+ const createRes = await testApp.app.inject({
55
+ method: 'POST',
56
+ url: '/api/sessions',
57
+ payload: {},
58
+ });
59
+ const session = createRes.json();
60
+
61
+ // Submit turn via HTTP
62
+ const turnRes = await testApp.app.inject({
63
+ method: 'POST',
64
+ url: `/api/sessions/${session.id}/turns`,
65
+ payload: { user_prompt: 'Search the web for cats' },
66
+ });
67
+ const turn = turnRes.json();
68
+
69
+ await waitForTurn(db, turn.id);
70
+
71
+ const items = db.prepare('SELECT * FROM items WHERE turn_id = ? ORDER BY created_at ASC').all(turn.id) as {
72
+ type: string;
73
+ data: string;
74
+ status: string;
75
+ }[];
76
+ expect(items).toHaveLength(2);
77
+
78
+ // MCP tool call
79
+ expect(items[0].type).toBe('mcp_tool_call');
80
+ expect(items[0].status).toBe('completed');
81
+ expect(JSON.parse(items[0].data)).toEqual({
82
+ server: 'web-search',
83
+ tool: 'search',
84
+ arguments: { query: 'cats' },
85
+ result: { urls: ['https://example.com/cats'] },
86
+ error: null,
87
+ status: 'completed',
88
+ });
89
+
90
+ // Agent message
91
+ expect(items[1].type).toBe('agent_message');
92
+ expect(items[1].status).toBe('completed');
93
+
94
+ // Verify WS: mcp item:started has in_progress status
95
+ const mcpStarted = capturedBroadcasts.find(
96
+ (b) => b.event === 'item:started' && (b.data as { item: { type: string } }).item.type === 'mcp_tool_call',
97
+ );
98
+ expect(mcpStarted).toBeDefined();
99
+ const mcpStartedData = mcpStarted!.data as { item: { status: string } };
100
+ expect(mcpStartedData.item.status).toBe('in_progress');
101
+ });
102
+ });