repoburg 1.3.202 → 1.3.204

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 (282) hide show
  1. package/agent-pane/backend/dist/index.js +2092 -32001
  2. package/agent-pane/backend/dist/server.js +45304 -0
  3. package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
  4. package/daemon/dist/agentPane.js +128 -0
  5. package/daemon/dist/agentPane.spec.js +183 -0
  6. package/daemon/dist/index.js +28 -8
  7. package/daemon/package.json +1 -1
  8. package/package.json +15 -2
  9. package/agent-pane/.prettierignore +0 -5
  10. package/agent-pane/.prettierrc +0 -8
  11. package/agent-pane/backend/coverage/base.css +0 -224
  12. package/agent-pane/backend/coverage/block-navigation.js +0 -87
  13. package/agent-pane/backend/coverage/clover.xml +0 -887
  14. package/agent-pane/backend/coverage/coverage-final.json +0 -10
  15. package/agent-pane/backend/coverage/favicon.png +0 -0
  16. package/agent-pane/backend/coverage/index.html +0 -176
  17. package/agent-pane/backend/coverage/prettify.css +0 -1
  18. package/agent-pane/backend/coverage/prettify.js +0 -2
  19. package/agent-pane/backend/coverage/sort-arrow-sprite.png +0 -0
  20. package/agent-pane/backend/coverage/sorter.js +0 -210
  21. package/agent-pane/backend/coverage/src/codex/codex-provider.ts.html +0 -1402
  22. package/agent-pane/backend/coverage/src/codex/index.html +0 -131
  23. package/agent-pane/backend/coverage/src/codex/item-mapper.ts.html +0 -331
  24. package/agent-pane/backend/coverage/src/db/index.html +0 -131
  25. package/agent-pane/backend/coverage/src/db/index.ts.html +0 -436
  26. package/agent-pane/backend/coverage/src/db/schema.ts.html +0 -175
  27. package/agent-pane/backend/coverage/src/index.html +0 -116
  28. package/agent-pane/backend/coverage/src/index.ts.html +0 -262
  29. package/agent-pane/backend/coverage/src/routes/index.html +0 -146
  30. package/agent-pane/backend/coverage/src/routes/sessions.ts.html +0 -991
  31. package/agent-pane/backend/coverage/src/routes/turns.ts.html +0 -256
  32. package/agent-pane/backend/coverage/src/routes/workspaces.ts.html +0 -406
  33. package/agent-pane/backend/coverage/src/ws/index.html +0 -116
  34. package/agent-pane/backend/coverage/src/ws/index.ts.html +0 -238
  35. package/agent-pane/backend/data.db +0 -0
  36. package/agent-pane/backend/data.db-shm +0 -0
  37. package/agent-pane/backend/data.db-wal +0 -0
  38. package/agent-pane/backend/package-lock.json +0 -5945
  39. package/agent-pane/backend/package.json +0 -33
  40. package/agent-pane/backend/scripts/backfill-from-jsonl.ts +0 -206
  41. package/agent-pane/backend/scripts/import-session-from-jsonl.ts +0 -264
  42. package/agent-pane/backend/src/claude/claude-message-mapper.test.ts +0 -271
  43. package/agent-pane/backend/src/claude/claude-message-mapper.ts +0 -259
  44. package/agent-pane/backend/src/claude/claude-provider.test.ts +0 -455
  45. package/agent-pane/backend/src/claude/claude-provider.ts +0 -1319
  46. package/agent-pane/backend/src/claude/claude-types.ts +0 -45
  47. package/agent-pane/backend/src/codex/app-server-client.test.ts +0 -183
  48. package/agent-pane/backend/src/codex/app-server-client.ts +0 -247
  49. package/agent-pane/backend/src/codex/app-server-types.ts +0 -259
  50. package/agent-pane/backend/src/codex/codex-provider-runtime-config.test.ts +0 -56
  51. package/agent-pane/backend/src/codex/codex-provider.test.ts +0 -60
  52. package/agent-pane/backend/src/codex/codex-provider.ts +0 -619
  53. package/agent-pane/backend/src/codex/item-mapper.test.ts +0 -221
  54. package/agent-pane/backend/src/codex/item-mapper.ts +0 -86
  55. package/agent-pane/backend/src/codex/shared-app-server.ts +0 -25
  56. package/agent-pane/backend/src/db/index.test.ts +0 -125
  57. package/agent-pane/backend/src/db/index.ts +0 -236
  58. package/agent-pane/backend/src/db/schema.ts +0 -34
  59. package/agent-pane/backend/src/index.ts +0 -89
  60. package/agent-pane/backend/src/integration/__fixtures__/cancel-turn.json +0 -29
  61. package/agent-pane/backend/src/integration/__fixtures__/delta-streaming.json +0 -40
  62. package/agent-pane/backend/src/integration/__fixtures__/failed-turn.json +0 -16
  63. package/agent-pane/backend/src/integration/__fixtures__/mcp-tool-call.json +0 -60
  64. package/agent-pane/backend/src/integration/__fixtures__/missing-item-started.json +0 -34
  65. package/agent-pane/backend/src/integration/__fixtures__/multi-item-turn.json +0 -85
  66. package/agent-pane/backend/src/integration/__fixtures__/multi-turn.json +0 -48
  67. package/agent-pane/backend/src/integration/__fixtures__/simple-turn.json +0 -35
  68. package/agent-pane/backend/src/integration/delta-streaming.test.ts +0 -130
  69. package/agent-pane/backend/src/integration/helpers/app-server-mock.ts +0 -272
  70. package/agent-pane/backend/src/integration/helpers/test-app.ts +0 -110
  71. package/agent-pane/backend/src/integration/helpers/ws-capture.ts +0 -64
  72. package/agent-pane/backend/src/integration/item-lifecycle.test.ts +0 -133
  73. package/agent-pane/backend/src/integration/mcp-tool-call.test.ts +0 -102
  74. package/agent-pane/backend/src/integration/missing-item-started.test.ts +0 -91
  75. package/agent-pane/backend/src/integration/multi-turn.test.ts +0 -121
  76. package/agent-pane/backend/src/integration/session-operations.test.ts +0 -175
  77. package/agent-pane/backend/src/integration/threads-claude-fork.test.ts +0 -241
  78. package/agent-pane/backend/src/integration/threads.test.ts +0 -309
  79. package/agent-pane/backend/src/integration/title-generation.test.ts +0 -109
  80. package/agent-pane/backend/src/integration/turn-cancel.test.ts +0 -111
  81. package/agent-pane/backend/src/integration/turn-failure.test.ts +0 -97
  82. package/agent-pane/backend/src/integration/turn-lifecycle.test.ts +0 -141
  83. package/agent-pane/backend/src/providers/index.ts +0 -16
  84. package/agent-pane/backend/src/providers/registry.test.ts +0 -92
  85. package/agent-pane/backend/src/providers/registry.ts +0 -43
  86. package/agent-pane/backend/src/providers/runtime-provider.ts +0 -49
  87. package/agent-pane/backend/src/repoburg/action-mapping.test.ts +0 -122
  88. package/agent-pane/backend/src/repoburg/action-mapping.ts +0 -294
  89. package/agent-pane/backend/src/repoburg/agent-runtime-client.test.ts +0 -271
  90. package/agent-pane/backend/src/repoburg/agent-runtime-client.ts +0 -285
  91. package/agent-pane/backend/src/repoburg/backend-resolver.test.ts +0 -356
  92. package/agent-pane/backend/src/repoburg/backend-resolver.ts +0 -261
  93. package/agent-pane/backend/src/repoburg/repoburg-client.test.ts +0 -180
  94. package/agent-pane/backend/src/repoburg/repoburg-client.ts +0 -194
  95. package/agent-pane/backend/src/repoburg/repoburg-provider.test.ts +0 -780
  96. package/agent-pane/backend/src/repoburg/repoburg-provider.ts +0 -471
  97. package/agent-pane/backend/src/repoburg/turn-projector.test.ts +0 -621
  98. package/agent-pane/backend/src/repoburg/turn-projector.ts +0 -637
  99. package/agent-pane/backend/src/routes/files.ts +0 -31
  100. package/agent-pane/backend/src/routes/mcp.ts +0 -33
  101. package/agent-pane/backend/src/routes/models.test.ts +0 -92
  102. package/agent-pane/backend/src/routes/models.ts +0 -16
  103. package/agent-pane/backend/src/routes/plugins.ts +0 -40
  104. package/agent-pane/backend/src/routes/providers.test.ts +0 -86
  105. package/agent-pane/backend/src/routes/providers.ts +0 -86
  106. package/agent-pane/backend/src/routes/sessions.test.ts +0 -772
  107. package/agent-pane/backend/src/routes/sessions.ts +0 -565
  108. package/agent-pane/backend/src/routes/skills.test.ts +0 -114
  109. package/agent-pane/backend/src/routes/skills.ts +0 -70
  110. package/agent-pane/backend/src/routes/threads.ts +0 -323
  111. package/agent-pane/backend/src/routes/turns.test.ts +0 -196
  112. package/agent-pane/backend/src/routes/turns.ts +0 -103
  113. package/agent-pane/backend/src/routes/workspaces.test.ts +0 -197
  114. package/agent-pane/backend/src/routes/workspaces.ts +0 -128
  115. package/agent-pane/backend/src/ws/index.test.ts +0 -107
  116. package/agent-pane/backend/src/ws/index.ts +0 -51
  117. package/agent-pane/backend/tsconfig.json +0 -25
  118. package/agent-pane/backend/vitest.config.ts +0 -20
  119. package/agent-pane/eslint.config.js +0 -33
  120. package/agent-pane/frontend/coverage/base.css +0 -224
  121. package/agent-pane/frontend/coverage/block-navigation.js +0 -87
  122. package/agent-pane/frontend/coverage/clover.xml +0 -2962
  123. package/agent-pane/frontend/coverage/coverage-final.json +0 -37
  124. package/agent-pane/frontend/coverage/favicon.png +0 -0
  125. package/agent-pane/frontend/coverage/index.html +0 -251
  126. package/agent-pane/frontend/coverage/prettify.css +0 -1
  127. package/agent-pane/frontend/coverage/prettify.js +0 -2
  128. package/agent-pane/frontend/coverage/sort-arrow-sprite.png +0 -0
  129. package/agent-pane/frontend/coverage/sorter.js +0 -210
  130. package/agent-pane/frontend/coverage/src/App.tsx.html +0 -217
  131. package/agent-pane/frontend/coverage/src/AppInitializer.tsx.html +0 -223
  132. package/agent-pane/frontend/coverage/src/api/client.ts.html +0 -187
  133. package/agent-pane/frontend/coverage/src/api/index.html +0 -161
  134. package/agent-pane/frontend/coverage/src/api/sessions.ts.html +0 -316
  135. package/agent-pane/frontend/coverage/src/api/websocket.ts.html +0 -544
  136. package/agent-pane/frontend/coverage/src/api/workspaces.ts.html +0 -199
  137. package/agent-pane/frontend/coverage/src/components/CollapsibleToolCalls.tsx.html +0 -226
  138. package/agent-pane/frontend/coverage/src/components/CommandInputBar.tsx.html +0 -382
  139. package/agent-pane/frontend/coverage/src/components/CommandPalette.tsx.html +0 -715
  140. package/agent-pane/frontend/coverage/src/components/IdeWorkspace.tsx.html +0 -160
  141. package/agent-pane/frontend/coverage/src/components/ModelSelector.tsx.html +0 -478
  142. package/agent-pane/frontend/coverage/src/components/NewSessionDialog.tsx.html +0 -472
  143. package/agent-pane/frontend/coverage/src/components/RenderArea.tsx.html +0 -574
  144. package/agent-pane/frontend/coverage/src/components/RightPanel.tsx.html +0 -205
  145. package/agent-pane/frontend/coverage/src/components/RuntimeIcon.tsx.html +0 -133
  146. package/agent-pane/frontend/coverage/src/components/SessionTabs.tsx.html +0 -217
  147. package/agent-pane/frontend/coverage/src/components/StatusBar.tsx.html +0 -271
  148. package/agent-pane/frontend/coverage/src/components/StatusDot.tsx.html +0 -109
  149. package/agent-pane/frontend/coverage/src/components/Toast.tsx.html +0 -313
  150. package/agent-pane/frontend/coverage/src/components/TurnContent.tsx.html +0 -1216
  151. package/agent-pane/frontend/coverage/src/components/WorkspaceSidebar.tsx.html +0 -1138
  152. package/agent-pane/frontend/coverage/src/components/index.html +0 -326
  153. package/agent-pane/frontend/coverage/src/components/panels/ChangesPanel.tsx.html +0 -247
  154. package/agent-pane/frontend/coverage/src/components/panels/LogsPanel.tsx.html +0 -160
  155. package/agent-pane/frontend/coverage/src/components/panels/MetricsPanel.tsx.html +0 -427
  156. package/agent-pane/frontend/coverage/src/components/panels/TurnsPanel.tsx.html +0 -397
  157. package/agent-pane/frontend/coverage/src/components/panels/index.html +0 -161
  158. package/agent-pane/frontend/coverage/src/constants/index.html +0 -116
  159. package/agent-pane/frontend/coverage/src/constants/models.ts.html +0 -406
  160. package/agent-pane/frontend/coverage/src/hooks/index.html +0 -146
  161. package/agent-pane/frontend/coverage/src/hooks/useEscapeKey.ts.html +0 -124
  162. package/agent-pane/frontend/coverage/src/hooks/useOutsideClick.ts.html +0 -142
  163. package/agent-pane/frontend/coverage/src/hooks/useSessionStatus.ts.html +0 -187
  164. package/agent-pane/frontend/coverage/src/index.html +0 -146
  165. package/agent-pane/frontend/coverage/src/main.tsx.html +0 -115
  166. package/agent-pane/frontend/coverage/src/store/index.html +0 -116
  167. package/agent-pane/frontend/coverage/src/store/store.ts.html +0 -2404
  168. package/agent-pane/frontend/coverage/src/test/component-helpers.ts.html +0 -190
  169. package/agent-pane/frontend/coverage/src/test/fixtures.ts.html +0 -367
  170. package/agent-pane/frontend/coverage/src/test/index.html +0 -131
  171. package/agent-pane/frontend/coverage/src/types/index.html +0 -116
  172. package/agent-pane/frontend/coverage/src/types/index.ts.html +0 -466
  173. package/agent-pane/frontend/coverage/src/utils/changes.ts.html +0 -202
  174. package/agent-pane/frontend/coverage/src/utils/duration.ts.html +0 -127
  175. package/agent-pane/frontend/coverage/src/utils/index.html +0 -131
  176. package/agent-pane/frontend/dist/assets/index-CJxD4YmJ.js +0 -370
  177. package/agent-pane/frontend/dist/assets/index-r-xwfOKQ.css +0 -1
  178. package/agent-pane/frontend/dist/index.html +0 -19
  179. package/agent-pane/frontend/index.html +0 -18
  180. package/agent-pane/frontend/package-lock.json +0 -4211
  181. package/agent-pane/frontend/package.json +0 -35
  182. package/agent-pane/frontend/src/App.test.tsx +0 -74
  183. package/agent-pane/frontend/src/App.tsx +0 -44
  184. package/agent-pane/frontend/src/AppInitializer.test.tsx +0 -142
  185. package/agent-pane/frontend/src/AppInitializer.tsx +0 -46
  186. package/agent-pane/frontend/src/__tests__/ThreadsPanel.test.tsx +0 -192
  187. package/agent-pane/frontend/src/api/client.test.ts +0 -126
  188. package/agent-pane/frontend/src/api/client.ts +0 -34
  189. package/agent-pane/frontend/src/api/models.ts +0 -7
  190. package/agent-pane/frontend/src/api/providers.ts +0 -17
  191. package/agent-pane/frontend/src/api/sessions.test.ts +0 -246
  192. package/agent-pane/frontend/src/api/sessions.ts +0 -97
  193. package/agent-pane/frontend/src/api/skills.ts +0 -12
  194. package/agent-pane/frontend/src/api/websocket.test.ts +0 -288
  195. package/agent-pane/frontend/src/api/websocket.ts +0 -240
  196. package/agent-pane/frontend/src/api/workspaces.test.ts +0 -112
  197. package/agent-pane/frontend/src/api/workspaces.ts +0 -38
  198. package/agent-pane/frontend/src/components/AskUserItem.test.tsx +0 -143
  199. package/agent-pane/frontend/src/components/AskUserItem.tsx +0 -207
  200. package/agent-pane/frontend/src/components/CollapsibleToolCalls.test.tsx +0 -49
  201. package/agent-pane/frontend/src/components/CollapsibleToolCalls.tsx +0 -56
  202. package/agent-pane/frontend/src/components/CommandInputBar.test.tsx +0 -133
  203. package/agent-pane/frontend/src/components/CommandInputBar.tsx +0 -584
  204. package/agent-pane/frontend/src/components/CommandPalette.test.tsx +0 -226
  205. package/agent-pane/frontend/src/components/CommandPalette.tsx +0 -194
  206. package/agent-pane/frontend/src/components/CommentableText.test.tsx +0 -196
  207. package/agent-pane/frontend/src/components/CommentableText.tsx +0 -379
  208. package/agent-pane/frontend/src/components/IdeWorkspace.test.tsx +0 -39
  209. package/agent-pane/frontend/src/components/IdeWorkspace.tsx +0 -51
  210. package/agent-pane/frontend/src/components/ModelSelector.test.tsx +0 -129
  211. package/agent-pane/frontend/src/components/ModelSelector.tsx +0 -191
  212. package/agent-pane/frontend/src/components/NewSessionDialog.test.tsx +0 -95
  213. package/agent-pane/frontend/src/components/NewSessionDialog.tsx +0 -129
  214. package/agent-pane/frontend/src/components/RenderArea.test.tsx +0 -160
  215. package/agent-pane/frontend/src/components/RenderArea.tsx +0 -170
  216. package/agent-pane/frontend/src/components/ResizeHandle.tsx +0 -29
  217. package/agent-pane/frontend/src/components/RightPanel.test.tsx +0 -43
  218. package/agent-pane/frontend/src/components/RightPanel.tsx +0 -46
  219. package/agent-pane/frontend/src/components/RuntimeIcon.test.tsx +0 -32
  220. package/agent-pane/frontend/src/components/RuntimeIcon.tsx +0 -16
  221. package/agent-pane/frontend/src/components/SessionTabs.test.tsx +0 -72
  222. package/agent-pane/frontend/src/components/SessionTabs.tsx +0 -49
  223. package/agent-pane/frontend/src/components/StatusBar.test.tsx +0 -56
  224. package/agent-pane/frontend/src/components/StatusBar.tsx +0 -129
  225. package/agent-pane/frontend/src/components/StatusDot.test.tsx +0 -25
  226. package/agent-pane/frontend/src/components/StatusDot.tsx +0 -8
  227. package/agent-pane/frontend/src/components/Toast.test.tsx +0 -79
  228. package/agent-pane/frontend/src/components/Toast.tsx +0 -76
  229. package/agent-pane/frontend/src/components/TurnContent.test.tsx +0 -377
  230. package/agent-pane/frontend/src/components/TurnContent.tsx +0 -594
  231. package/agent-pane/frontend/src/components/WorkspaceSidebar.test.tsx +0 -297
  232. package/agent-pane/frontend/src/components/WorkspaceSidebar.tsx +0 -351
  233. package/agent-pane/frontend/src/components/input/OptionSubPopup.tsx +0 -32
  234. package/agent-pane/frontend/src/components/input/SkillMentionPopup.test.tsx +0 -63
  235. package/agent-pane/frontend/src/components/input/SkillMentionPopup.tsx +0 -78
  236. package/agent-pane/frontend/src/components/input/SlashPopup.test.tsx +0 -96
  237. package/agent-pane/frontend/src/components/input/SlashPopup.tsx +0 -82
  238. package/agent-pane/frontend/src/components/panels/ChangesPanel.test.tsx +0 -61
  239. package/agent-pane/frontend/src/components/panels/ChangesPanel.tsx +0 -54
  240. package/agent-pane/frontend/src/components/panels/TasksPanel.test.tsx +0 -97
  241. package/agent-pane/frontend/src/components/panels/TasksPanel.tsx +0 -208
  242. package/agent-pane/frontend/src/components/panels/ThreadsPanel.tsx +0 -382
  243. package/agent-pane/frontend/src/components/panels/TurnsPanel.test.tsx +0 -131
  244. package/agent-pane/frontend/src/components/panels/TurnsPanel.tsx +0 -131
  245. package/agent-pane/frontend/src/constants/models.test.ts +0 -97
  246. package/agent-pane/frontend/src/constants/models.ts +0 -166
  247. package/agent-pane/frontend/src/hooks/useEscapeKey.test.ts +0 -42
  248. package/agent-pane/frontend/src/hooks/useEscapeKey.ts +0 -13
  249. package/agent-pane/frontend/src/hooks/useOutsideClick.test.ts +0 -92
  250. package/agent-pane/frontend/src/hooks/useOutsideClick.ts +0 -19
  251. package/agent-pane/frontend/src/hooks/useProvider.ts +0 -44
  252. package/agent-pane/frontend/src/hooks/useResizable.test.ts +0 -97
  253. package/agent-pane/frontend/src/hooks/useResizable.ts +0 -75
  254. package/agent-pane/frontend/src/hooks/useSessionStatus.test.ts +0 -116
  255. package/agent-pane/frontend/src/hooks/useSessionStatus.ts +0 -34
  256. package/agent-pane/frontend/src/main.test.tsx +0 -37
  257. package/agent-pane/frontend/src/main.tsx +0 -10
  258. package/agent-pane/frontend/src/store/sessionSlice.ts +0 -440
  259. package/agent-pane/frontend/src/store/store.test.ts +0 -1338
  260. package/agent-pane/frontend/src/store/store.ts +0 -37
  261. package/agent-pane/frontend/src/store/threadSlice.ts +0 -136
  262. package/agent-pane/frontend/src/store/uiSlice.ts +0 -133
  263. package/agent-pane/frontend/src/store/workspaceSlice.ts +0 -77
  264. package/agent-pane/frontend/src/store/wsSlice.ts +0 -368
  265. package/agent-pane/frontend/src/styles/app.css +0 -627
  266. package/agent-pane/frontend/src/styles/tokens.css +0 -62
  267. package/agent-pane/frontend/src/test/component-helpers.ts +0 -38
  268. package/agent-pane/frontend/src/test/fixtures.ts +0 -101
  269. package/agent-pane/frontend/src/test-setup.ts +0 -5
  270. package/agent-pane/frontend/src/types/index.test.ts +0 -128
  271. package/agent-pane/frontend/src/types/index.ts +0 -134
  272. package/agent-pane/frontend/src/utils/changes.test.ts +0 -81
  273. package/agent-pane/frontend/src/utils/changes.ts +0 -39
  274. package/agent-pane/frontend/src/utils/duration.test.ts +0 -76
  275. package/agent-pane/frontend/src/utils/duration.ts +0 -14
  276. package/agent-pane/frontend/tsconfig.json +0 -25
  277. package/agent-pane/frontend/vite.config.ts +0 -22
  278. package/agent-pane/frontend/vitest.config.ts +0 -29
  279. package/agent-pane/package-lock.json +0 -1527
  280. package/agent-pane/package.json +0 -19
  281. package/agent-pane/shared/provider-types.ts +0 -67
  282. package/agent-pane/shared/types.ts +0 -184
@@ -1,271 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { mapAssistantContent, mapPartialDelta, mapUsage, applyToolResult, deriveFileChangeData, extractToolResultText } from './claude-message-mapper.ts';
3
-
4
- describe('claude-message-mapper', () => {
5
- describe('mapAssistantContent', () => {
6
- it('maps a text block to agent_message', () => {
7
- const content = [{ type: 'text', text: 'Hello world', citations: null }] as never;
8
- const result = mapAssistantContent(content, 'msg-1');
9
- expect(result).toHaveLength(1);
10
- expect(result[0].type).toBe('agent_message');
11
- expect(result[0].data).toEqual({ text: 'Hello world' });
12
- });
13
-
14
- it('maps a thinking block to reasoning', () => {
15
- const content = [{ type: 'thinking', thinking: 'I should respond', signature: 'sig' }] as never;
16
- const result = mapAssistantContent(content, 'msg-1');
17
- expect(result).toHaveLength(1);
18
- expect(result[0].type).toBe('reasoning');
19
- expect(result[0].data).toEqual({ text: 'I should respond' });
20
- });
21
-
22
- it('uses thinkingTexts fallback when thinking block is empty (signed-empty)', () => {
23
- const content = [{ type: 'thinking', thinking: '', signature: 'sig' }] as never;
24
- const thinkingTexts = new Map([[0, 'Accumulated thinking text']]);
25
- const result = mapAssistantContent(content, 'msg-1', thinkingTexts);
26
- expect(result).toHaveLength(1);
27
- expect(result[0].type).toBe('reasoning');
28
- expect(result[0].data).toEqual({ text: 'Accumulated thinking text' });
29
- });
30
-
31
- it('keeps empty text when thinkingTexts is not provided', () => {
32
- const content = [{ type: 'thinking', thinking: '', signature: 'sig' }] as never;
33
- const result = mapAssistantContent(content, 'msg-1');
34
- expect(result).toHaveLength(1);
35
- expect(result[0].data).toEqual({ text: '' });
36
- });
37
-
38
- it('maps a Bash tool_use to command_execution', () => {
39
- const content = [{ type: 'tool_use', id: 'tu-1', name: 'Bash', input: { command: 'ls -la' } }] as never;
40
- const result = mapAssistantContent(content, 'msg-1');
41
- expect(result).toHaveLength(1);
42
- expect(result[0].type).toBe('command_execution');
43
- expect(result[0].data).toEqual({
44
- command: 'ls -la',
45
- aggregated_output: null,
46
- exit_code: null,
47
- status: 'in_progress',
48
- });
49
- expect(result[0].externalId).toBe('tu-1');
50
- });
51
-
52
- it('maps an Edit tool_use to file_change with canonical changes array', () => {
53
- const content = [{ type: 'tool_use', id: 'tu-2', name: 'Edit', input: { file_path: 'foo.ts', old_string: 'a', new_string: 'b' } }] as never;
54
- const result = mapAssistantContent(content, 'msg-1');
55
- expect(result).toHaveLength(1);
56
- expect(result[0].type).toBe('file_change');
57
- expect(result[0].data).toEqual({
58
- changes: [{ path: 'foo.ts', kind: 'modify' }],
59
- status: 'in_progress',
60
- });
61
- });
62
-
63
- it('maps a Write tool_use to file_change with kind "add"', () => {
64
- const content = [{ type: 'tool_use', id: 'tu-3', name: 'Write', input: { file_path: 'bar.ts', content: 'x' } }] as never;
65
- const result = mapAssistantContent(content, 'msg-1');
66
- expect(result).toHaveLength(1);
67
- expect(result[0].type).toBe('file_change');
68
- expect(result[0].data).toEqual({
69
- changes: [{ path: 'bar.ts', kind: 'add' }],
70
- status: 'in_progress',
71
- });
72
- });
73
-
74
- it('maps an unknown tool_use to mcp_tool_call', () => {
75
- const content = [{ type: 'tool_use', id: 'tu-4', name: 'CustomTool', input: { x: 1 } }] as never;
76
- const result = mapAssistantContent(content, 'msg-1');
77
- expect(result).toHaveLength(1);
78
- expect(result[0].type).toBe('mcp_tool_call');
79
- expect(result[0].data).toEqual({
80
- server: null,
81
- tool: 'CustomTool',
82
- arguments: { x: 1 },
83
- result: null,
84
- error: null,
85
- status: 'in_progress',
86
- });
87
- });
88
-
89
- it('skips redacted_thinking blocks', () => {
90
- const content = [{ type: 'redacted_thinking', data: 'encrypted' }] as never;
91
- const result = mapAssistantContent(content, 'msg-1');
92
- expect(result).toHaveLength(0);
93
- });
94
-
95
- it('skips unknown block types', () => {
96
- const content = [{ type: 'server_tool_use', id: 'x', name: 'y', input: {} }] as never;
97
- const result = mapAssistantContent(content, 'msg-1');
98
- expect(result).toHaveLength(0);
99
- });
100
-
101
- it('maps multiple blocks in one message', () => {
102
- const content = [
103
- { type: 'thinking', thinking: 'Let me think', signature: 's' },
104
- { type: 'text', text: 'Here is my answer', citations: null },
105
- { type: 'tool_use', id: 'tu-5', name: 'Bash', input: { command: 'echo hi' } },
106
- ] as never;
107
- const result = mapAssistantContent(content, 'msg-1');
108
- expect(result).toHaveLength(3);
109
- expect(result[0].type).toBe('reasoning');
110
- expect(result[1].type).toBe('agent_message');
111
- expect(result[2].type).toBe('command_execution');
112
- });
113
- });
114
-
115
- describe('deriveFileChangeData', () => {
116
- it('maps an Edit input to a single modify change', () => {
117
- expect(deriveFileChangeData({ file_path: 'a.ts', old_string: 'x', new_string: 'y' }, 'Edit')).toEqual({
118
- changes: [{ path: 'a.ts', kind: 'modify' }],
119
- status: 'in_progress',
120
- });
121
- });
122
-
123
- it('maps a Write input to an add change', () => {
124
- expect(deriveFileChangeData({ file_path: 'b.ts', content: 'x' }, 'Write')).toEqual({
125
- changes: [{ path: 'b.ts', kind: 'add' }],
126
- status: 'in_progress',
127
- });
128
- });
129
-
130
- it('falls back to notebook_path and defaults kind to modify', () => {
131
- expect(deriveFileChangeData({ notebook_path: 'nb.ipynb' }, 'NotebookEdit')).toEqual({
132
- changes: [{ path: 'nb.ipynb', kind: 'modify' }],
133
- status: 'in_progress',
134
- });
135
- });
136
-
137
- it('uses empty string when no path field present', () => {
138
- expect(deriveFileChangeData({}, 'MultiEdit')).toEqual({
139
- changes: [{ path: '', kind: 'modify' }],
140
- status: 'in_progress',
141
- });
142
- });
143
- });
144
-
145
- describe('extractToolResultText', () => {
146
- it('returns a string content as-is', () => {
147
- expect(extractToolResultText('hello')).toBe('hello');
148
- });
149
- it('joins text blocks in an array', () => {
150
- expect(extractToolResultText([{ type: 'text', text: 'a' }, { type: 'text', text: 'b' }])).toBe('a\nb');
151
- });
152
- it('ignores non-text blocks', () => {
153
- expect(extractToolResultText([{ type: 'tool_reference', tool_name: 'x' }, { type: 'text', text: 'a' }])).toBe('a');
154
- });
155
- it('returns empty for null/undefined', () => {
156
- expect(extractToolResultText(null)).toBe('');
157
- expect(extractToolResultText(undefined)).toBe('');
158
- });
159
- });
160
-
161
- describe('applyToolResult', () => {
162
- it('command_execution: fills aggregated_output from structured stdout+stderr and exit_code from is_error', () => {
163
- const existing = { command: 'ls', aggregated_output: null, exit_code: null, status: 'in_progress' };
164
- const out = applyToolResult('command_execution', existing, { tool_use_id: 't1', content: 'file1\nfile2' }, { stdout: 'file1\nfile2', stderr: 'warn', interrupted: false, isImage: false, noOutputExpected: false }, false);
165
- expect(out).toEqual({ command: 'ls', aggregated_output: 'file1\nfile2\nwarn', exit_code: 0, status: 'completed' });
166
- });
167
-
168
- it('command_execution: marks failed and exit_code 1 on error', () => {
169
- const existing = { command: 'bad', aggregated_output: null, exit_code: null, status: 'in_progress' };
170
- const out = applyToolResult('command_execution', existing, { tool_use_id: 't2', is_error: true, content: 'boom' }, { stdout: 'boom', stderr: '' }, true);
171
- expect(out.exit_code).toBe(1);
172
- expect(out.status).toBe('failed');
173
- expect(out.aggregated_output).toBe('boom');
174
- });
175
-
176
- it('mcp_tool_call: fills result text and no error on success', () => {
177
- const existing = { server: null, tool: 'Linear.get', arguments: { id: 'PAR-1' }, result: null, error: null, status: 'in_progress' };
178
- const out = applyToolResult('mcp_tool_call', existing, { tool_use_id: 't3', content: [{ type: 'text', text: '{"id":"PAR-1"}' }] }, null, false);
179
- expect(out.result).toEqual([{ type: 'text', text: '{"id":"PAR-1"}' }]);
180
- expect(out.error).toBeNull();
181
- expect(out.status).toBe('completed');
182
- });
183
-
184
- it('mcp_tool_call: sets error on is_error', () => {
185
- const existing = { server: null, tool: 'X', arguments: {}, result: null, error: null, status: 'in_progress' };
186
- const out = applyToolResult('mcp_tool_call', existing, { tool_use_id: 't4', is_error: true, content: 'denied' }, null, true);
187
- expect(out.error).toBe('denied');
188
- expect(out.status).toBe('failed');
189
- });
190
-
191
- it('file_change: keeps existing changes and flips status to completed', () => {
192
- const existing = { changes: [{ path: 'a.ts', kind: 'modify' }], status: 'in_progress' };
193
- const out = applyToolResult('file_change', existing, { tool_use_id: 't5', content: 'ok' }, null, false);
194
- expect(out).toEqual({ changes: [{ path: 'a.ts', kind: 'modify' }], status: 'completed' });
195
- });
196
-
197
- it('unknown type: returns existing data unchanged', () => {
198
- const existing = { foo: 1 };
199
- expect(applyToolResult('agent_message', existing, null, null, false)).toEqual({ foo: 1 });
200
- });
201
- });
202
-
203
- describe('mapPartialDelta', () => {
204
- it('maps a text_delta event', () => {
205
- const event = {
206
- type: 'content_block_delta',
207
- delta: { type: 'text_delta', text: 'Hello' },
208
- index: 0,
209
- };
210
- const result = mapPartialDelta(event);
211
- expect(result).toEqual({ kind: 'text', text: 'Hello', index: 0 });
212
- });
213
-
214
- it('maps a thinking_delta event', () => {
215
- const event = {
216
- type: 'content_block_delta',
217
- delta: { type: 'thinking_delta', thinking: 'Hmm', estimated_tokens: null },
218
- index: 0,
219
- };
220
- const result = mapPartialDelta(event);
221
- expect(result).toEqual({ kind: 'thinking', text: 'Hmm', index: 0 });
222
- });
223
-
224
- it('returns null for non-delta events', () => {
225
- const event = { type: 'content_block_start', index: 0, content_block: {} };
226
- const result = mapPartialDelta(event);
227
- expect(result).toBeNull();
228
- });
229
-
230
- it('returns null for unknown delta types', () => {
231
- const event = {
232
- type: 'content_block_delta',
233
- delta: { type: 'input_json_delta', partial_json: '{}' },
234
- index: 0,
235
- };
236
- const result = mapPartialDelta(event);
237
- expect(result).toBeNull();
238
- });
239
- });
240
-
241
- describe('mapUsage', () => {
242
- it('maps camelCase usage fields to snake_case TokenUsage', () => {
243
- const usage = {
244
- input_tokens: 100,
245
- output_tokens: 50,
246
- cache_read_input_tokens: 30,
247
- cache_creation_input_tokens: 20,
248
- };
249
- const result = mapUsage(usage);
250
- expect(result).toEqual({
251
- input_tokens: 100,
252
- cached_input_tokens: 30,
253
- cache_write_input_tokens: 20,
254
- output_tokens: 50,
255
- reasoning_output_tokens: 0,
256
- });
257
- });
258
-
259
- it('handles null cache values with fallback to 0', () => {
260
- const usage = {
261
- input_tokens: 200,
262
- output_tokens: 80,
263
- cache_read_input_tokens: 0,
264
- cache_creation_input_tokens: 0,
265
- };
266
- const result = mapUsage(usage);
267
- expect(result.cached_input_tokens).toBe(0);
268
- expect(result.cache_write_input_tokens).toBe(0);
269
- });
270
- });
271
- });
@@ -1,259 +0,0 @@
1
- /**
2
- * Map Claude SDK messages to AgentPane item descriptors.
3
- *
4
- * Three mapping functions:
5
- * - `mapAssistantContent` — BetaContentBlock[] → item descriptors
6
- * - `mapPartialDelta` — BetaRawMessageStreamEvent → text/thinking delta
7
- * - `mapUsage` — NonNullableUsage → TokenUsage (snake_case)
8
- */
9
-
10
- import type { TokenUsage } from '@agentpane/shared';
11
- import type {
12
- BetaContentBlock,
13
- BetaRawContentBlockDeltaEvent,
14
- BetaTextBlock,
15
- BetaThinkingBlock,
16
- BetaToolUseBlock,
17
- } from '@anthropic-ai/sdk/resources/beta/messages/messages';
18
-
19
- /** Item descriptor — output of mapping a content block to a DB-ready item. */
20
- export interface ItemDescriptor {
21
- type: string; // DB item type (snake_case)
22
- data: Record<string, unknown>;
23
- externalId: string; // Claude content block ID (or UUID)
24
- }
25
-
26
- /** Map assistant content blocks to item descriptors.
27
- * @param thinkingTexts — Optional map of content-block index → accumulated thinking_delta text.
28
- * When a `thinking` block has empty `thinking` (signed-empty), the mapper falls back to
29
- * the accumulated text from stream events. */
30
- export function mapAssistantContent(
31
- content: BetaContentBlock[],
32
- messageId: string,
33
- thinkingTexts?: Map<number, string>,
34
- ): ItemDescriptor[] {
35
- const descriptors: ItemDescriptor[] = [];
36
-
37
- for (let i = 0; i < content.length; i++) {
38
- const block = content[i];
39
- switch (block.type) {
40
- case 'text': {
41
- const tb = block as BetaTextBlock;
42
- descriptors.push({
43
- type: 'agent_message',
44
- data: { text: tb.text },
45
- externalId: messageId,
46
- });
47
- break;
48
- }
49
-
50
- case 'thinking': {
51
- const tb = block as BetaThinkingBlock;
52
- let text = tb.thinking;
53
- if (!text && thinkingTexts) {
54
- text = thinkingTexts.get(i) ?? '';
55
- }
56
- descriptors.push({
57
- type: 'reasoning',
58
- data: { text },
59
- externalId: messageId,
60
- });
61
- break;
62
- }
63
-
64
- case 'tool_use': {
65
- const tu = block as BetaToolUseBlock;
66
- const desc = mapToolUse(tu);
67
- descriptors.push(desc);
68
- break;
69
- }
70
-
71
- case 'redacted_thinking':
72
- // Skip — redacted content has no displayable text.
73
- break;
74
-
75
- default:
76
- // Skip unknown block types.
77
- break;
78
- }
79
- }
80
-
81
- return descriptors;
82
- }
83
-
84
- /** Map a tool_use block to the correct item type based on tool name. */
85
- function mapToolUse(block: BetaToolUseBlock): ItemDescriptor {
86
- const input = block.input as Record<string, unknown>;
87
-
88
- if (block.name === 'Bash') {
89
- return {
90
- type: 'command_execution',
91
- data: {
92
- command: input.command ?? '',
93
- aggregated_output: null,
94
- exit_code: null,
95
- status: 'in_progress',
96
- },
97
- externalId: block.id,
98
- };
99
- }
100
-
101
- if (block.name === 'Edit' || block.name === 'Write' || block.name === 'MultiEdit' || block.name === 'NotebookEdit') {
102
- return {
103
- type: 'file_change',
104
- data: deriveFileChangeData(input, block.name),
105
- externalId: block.id,
106
- };
107
- }
108
-
109
- // All other tools → mcp_tool_call.
110
- return {
111
- type: 'mcp_tool_call',
112
- data: {
113
- server: null,
114
- tool: block.name,
115
- arguments: input,
116
- result: null,
117
- error: null,
118
- status: 'in_progress',
119
- },
120
- externalId: block.id,
121
- };
122
- }
123
-
124
- // ---------------------------------------------------------------------------
125
- // Tool-result mapping — pure functions shared by the live provider and the
126
- // JSONL backfill script. Kept free of DB / SDK-specific types so both callers
127
- // (which hold different shapes: typed SDK blocks vs parsed JSON) can use them.
128
- // ---------------------------------------------------------------------------
129
-
130
- /** Derive the canonical file_change data from a Claude file-edit tool_use input.
131
- * Each Edit/Write/MultiEdit/NotebookEdit touches a single file → one change.
132
- * Frontend expects `changes: Array<{ path, kind }>` (matches Codex app-server). */
133
- export function deriveFileChangeData(
134
- input: Record<string, unknown>,
135
- toolName: string,
136
- ): { changes: Array<{ path: string; kind: string }>; status: string } {
137
- const path = (input.file_path ?? input.notebook_path ?? '') as string;
138
- const kind = toolName === 'Write' ? 'add' : 'modify';
139
- return { changes: [{ path, kind }], status: 'in_progress' };
140
- }
141
-
142
- /** Loose shape of a `tool_result` content block — works for SDK blocks and parsed JSONL. */
143
- export interface ToolResultLike {
144
- tool_use_id?: string;
145
- is_error?: boolean;
146
- content?: unknown;
147
- }
148
-
149
- /** Extract concatenated text from a tool_result `content` (string or array of text blocks). */
150
- export function extractToolResultText(content: unknown): string {
151
- if (!content) return '';
152
- if (typeof content === 'string') return content;
153
- if (Array.isArray(content)) {
154
- return content
155
- .map((b) => {
156
- if (b && typeof b === 'object' && (b as { type?: string }).type === 'text') {
157
- return String((b as { text?: unknown }).text ?? '');
158
- }
159
- return '';
160
- })
161
- .filter(Boolean)
162
- .join('\n');
163
- }
164
- return '';
165
- }
166
-
167
- /** Build the updated item `data` after a tool_result arrives. Pure; no DB access.
168
- *
169
- * - `command_execution`: aggregated_output from the result text (Bash stdout) plus
170
- * structured stderr when present; exit_code heuristically from is_error (the Claude
171
- * SDK does not expose a real exit code for Bash).
172
- * - `mcp_tool_call`: result text from the tool_result content; error when is_error.
173
- * - `file_change`: the `changes` array was set at tool_use time — just mark status.
174
- * @param itemType — DB item type ('command_execution' | 'file_change' | 'mcp_tool_call').
175
- * @param existingData — current `data` object stored on the item.
176
- * @param toolResult — the tool_result content block (may be null if only structured output exists).
177
- * @param toolUseResult — the SDK `tool_use_result` structured object (per-tool shape; Bash → {stdout, stderr}).
178
- * @param isError — whether the tool_result flagged an error. */
179
- export function applyToolResult(
180
- itemType: string,
181
- existingData: Record<string, unknown>,
182
- toolResult: ToolResultLike | null,
183
- toolUseResult: unknown,
184
- isError: boolean,
185
- ): Record<string, unknown> {
186
- switch (itemType) {
187
- case 'command_execution': {
188
- const text = extractToolResultText(toolResult?.content);
189
- const tur = (toolUseResult && typeof toolUseResult === 'object' ? toolUseResult : {}) as Record<string, unknown>;
190
- const stdout = typeof tur.stdout === 'string' ? tur.stdout : '';
191
- const stderr = typeof tur.stderr === 'string' ? tur.stderr : '';
192
- let aggregated = text || stdout;
193
- if (stderr) aggregated = aggregated ? `${aggregated}\n${stderr}` : stderr;
194
- return {
195
- ...existingData,
196
- aggregated_output: aggregated,
197
- exit_code: isError ? 1 : 0,
198
- status: isError ? 'failed' : 'completed',
199
- };
200
- }
201
-
202
- case 'mcp_tool_call': {
203
- const text = extractToolResultText(toolResult?.content);
204
- return {
205
- ...existingData,
206
- result: text ? [{ type: 'text', text }] : (toolUseResult ?? null),
207
- error: isError ? (text || 'Tool error') : null,
208
- status: isError ? 'failed' : 'completed',
209
- };
210
- }
211
-
212
- case 'file_change': {
213
- // `changes` was derived at tool_use time; only flip the inner status.
214
- return { ...existingData, status: isError ? 'failed' : 'completed' };
215
- }
216
-
217
- default:
218
- return existingData;
219
- }
220
- }
221
-
222
- /** Result of mapping a partial (streaming) delta event. */
223
- export interface DeltaResult {
224
- kind: 'text' | 'thinking';
225
- text: string;
226
- index: number;
227
- }
228
-
229
- /** Map a streaming delta event to a text or thinking fragment. Returns null for non-delta events. */
230
- export function mapPartialDelta(event: unknown): DeltaResult | null {
231
- const e = event as BetaRawContentBlockDeltaEvent;
232
- if (e.type !== 'content_block_delta') return null;
233
-
234
- const delta = e.delta as unknown as Record<string, unknown>;
235
- if (delta.type === 'text_delta') {
236
- return { kind: 'text', text: delta.text as string, index: e.index };
237
- }
238
- if (delta.type === 'thinking_delta') {
239
- return { kind: 'thinking', text: delta.thinking as string, index: e.index };
240
- }
241
-
242
- return null;
243
- }
244
-
245
- /** Map Claude SDK NonNullableUsage (camelCase) to AgentPane TokenUsage (snake_case). */
246
- export function mapUsage(usage: {
247
- input_tokens: number;
248
- output_tokens: number;
249
- cache_read_input_tokens: number;
250
- cache_creation_input_tokens: number;
251
- }): TokenUsage {
252
- return {
253
- input_tokens: usage.input_tokens,
254
- cached_input_tokens: usage.cache_read_input_tokens ?? 0,
255
- cache_write_input_tokens: usage.cache_creation_input_tokens ?? 0,
256
- output_tokens: usage.output_tokens,
257
- reasoning_output_tokens: 0, // Claude SDK does not provide this separately.
258
- };
259
- }