whale-code 6.5.5 → 6.5.6

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 (847) hide show
  1. package/README.md +39 -31
  2. package/bin/{swagmanager-mcp.js → whale-code.js} +17 -2
  3. package/dist/cli/app.js +148 -72
  4. package/dist/cli/app.js.map +1 -0
  5. package/dist/cli/chat/AgentSelector.js +105 -10
  6. package/dist/cli/chat/AgentSelector.js.map +1 -0
  7. package/dist/cli/chat/ChatApp.d.ts +31 -0
  8. package/dist/cli/chat/ChatApp.js +539 -286
  9. package/dist/cli/chat/ChatApp.js.map +1 -0
  10. package/dist/cli/chat/ChatInput.js +1088 -770
  11. package/dist/cli/chat/ChatInput.js.map +1 -0
  12. package/dist/cli/chat/MarkdownText.js +39 -14
  13. package/dist/cli/chat/MarkdownText.js.map +1 -0
  14. package/dist/cli/chat/MemoryManager.js +181 -46
  15. package/dist/cli/chat/MemoryManager.js.map +1 -0
  16. package/dist/cli/chat/MessageList.d.ts +2 -3
  17. package/dist/cli/chat/MessageList.js +186 -45
  18. package/dist/cli/chat/MessageList.js.map +1 -0
  19. package/dist/cli/chat/ModelSelector.js +282 -63
  20. package/dist/cli/chat/ModelSelector.js.map +1 -0
  21. package/dist/cli/chat/NodeManager.js +165 -75
  22. package/dist/cli/chat/NodeManager.js.map +1 -0
  23. package/dist/cli/chat/NodeSelector.js +171 -30
  24. package/dist/cli/chat/NodeSelector.js.map +1 -0
  25. package/dist/cli/chat/PlanApproval.js +281 -57
  26. package/dist/cli/chat/PlanApproval.js.map +1 -0
  27. package/dist/cli/chat/RewindViewer.js +559 -144
  28. package/dist/cli/chat/RewindViewer.js.map +1 -0
  29. package/dist/cli/chat/SessionManager.js +137 -30
  30. package/dist/cli/chat/SessionManager.js.map +1 -0
  31. package/dist/cli/chat/SlashMenu.js +293 -164
  32. package/dist/cli/chat/SlashMenu.js.map +1 -0
  33. package/dist/cli/chat/StatusBar.js +172 -9
  34. package/dist/cli/chat/StatusBar.js.map +1 -0
  35. package/dist/cli/chat/StoreSelector.js +147 -18
  36. package/dist/cli/chat/StoreSelector.js.map +1 -0
  37. package/dist/cli/chat/StreamingText.d.ts +1 -5
  38. package/dist/cli/chat/StreamingText.js +22 -7
  39. package/dist/cli/chat/StreamingText.js.map +1 -0
  40. package/dist/cli/chat/SubagentPanel.d.ts +1 -2
  41. package/dist/cli/chat/SubagentPanel.js +612 -72
  42. package/dist/cli/chat/SubagentPanel.js.map +1 -0
  43. package/dist/cli/chat/TeamPanel.d.ts +1 -0
  44. package/dist/cli/chat/TeamPanel.js +230 -30
  45. package/dist/cli/chat/TeamPanel.js.map +1 -0
  46. package/dist/cli/chat/ThemeSelector.js +84 -24
  47. package/dist/cli/chat/ThemeSelector.js.map +1 -0
  48. package/dist/cli/chat/ToolIndicator.js +1476 -371
  49. package/dist/cli/chat/ToolIndicator.js.map +1 -0
  50. package/dist/cli/chat/hooks/useAgentLoop.d.ts +1 -0
  51. package/dist/cli/chat/hooks/useAgentLoop.js +481 -367
  52. package/dist/cli/chat/hooks/useAgentLoop.js.map +1 -0
  53. package/dist/cli/chat/hooks/useSlashCommands.d.ts +3 -14
  54. package/dist/cli/chat/hooks/useSlashCommands.js +744 -572
  55. package/dist/cli/chat/hooks/useSlashCommands.js.map +1 -0
  56. package/dist/cli/commands/config-cmd.js +56 -57
  57. package/dist/cli/commands/config-cmd.js.map +1 -0
  58. package/dist/cli/commands/db.js +184 -169
  59. package/dist/cli/commands/db.js.map +1 -0
  60. package/dist/cli/commands/doctor.js +212 -122
  61. package/dist/cli/commands/doctor.js.map +1 -0
  62. package/dist/cli/commands/init.js +211 -244
  63. package/dist/cli/commands/init.js.map +1 -0
  64. package/dist/cli/commands/mcp.js +127 -122
  65. package/dist/cli/commands/mcp.js.map +1 -0
  66. package/dist/cli/login/LoginApp.js +355 -141
  67. package/dist/cli/login/LoginApp.js.map +1 -0
  68. package/dist/cli/print-mode.js +196 -177
  69. package/dist/cli/print-mode.js.map +1 -0
  70. package/dist/cli/serve-mode.js +615 -530
  71. package/dist/cli/serve-mode.js.map +1 -0
  72. package/dist/cli/services/agent-config.d.ts +5 -1
  73. package/dist/cli/services/agent-config.js +66 -36
  74. package/dist/cli/services/agent-config.js.map +1 -0
  75. package/dist/cli/services/agent-definitions.d.ts +4 -1
  76. package/dist/cli/services/agent-definitions.js +97 -56
  77. package/dist/cli/services/agent-definitions.js.map +1 -0
  78. package/dist/cli/services/agent-events.js +225 -162
  79. package/dist/cli/services/agent-events.js.map +1 -0
  80. package/dist/cli/services/agent-loop.js +976 -688
  81. package/dist/cli/services/agent-loop.js.map +1 -0
  82. package/dist/cli/services/agent-worker-base.d.ts +35 -5
  83. package/dist/cli/services/agent-worker-base.js +337 -153
  84. package/dist/cli/services/agent-worker-base.js.map +1 -0
  85. package/dist/cli/services/api-retry.js +69 -64
  86. package/dist/cli/services/api-retry.js.map +1 -0
  87. package/dist/cli/services/auth-service.d.ts +3 -3
  88. package/dist/cli/services/auth-service.js +209 -132
  89. package/dist/cli/services/auth-service.js.map +1 -0
  90. package/dist/cli/services/background-processes.js +343 -267
  91. package/dist/cli/services/background-processes.js.map +1 -0
  92. package/dist/cli/services/browser-auth.d.ts +2 -2
  93. package/dist/cli/services/browser-auth.js +159 -118
  94. package/dist/cli/services/browser-auth.js.map +1 -0
  95. package/dist/cli/services/claude-md-loader.js +40 -36
  96. package/dist/cli/services/claude-md-loader.js.map +1 -0
  97. package/dist/cli/services/config-store.d.ts +9 -4
  98. package/dist/cli/services/config-store.js +164 -117
  99. package/dist/cli/services/config-store.js.map +1 -0
  100. package/dist/cli/services/debug-log.d.ts +1 -1
  101. package/dist/cli/services/debug-log.js +34 -35
  102. package/dist/cli/services/debug-log.js.map +1 -0
  103. package/dist/cli/services/env-detect.d.ts +7 -0
  104. package/dist/cli/services/env-detect.js +9 -0
  105. package/dist/cli/services/env-detect.js.map +1 -0
  106. package/dist/cli/services/error-logger.js +187 -169
  107. package/dist/cli/services/error-logger.js.map +1 -0
  108. package/dist/cli/services/file-history.d.ts +1 -1
  109. package/dist/cli/services/file-history.js +50 -54
  110. package/dist/cli/services/file-history.js.map +1 -0
  111. package/dist/cli/services/format-server-response.js +332 -372
  112. package/dist/cli/services/format-server-response.js.map +1 -0
  113. package/dist/cli/services/git-context.js +61 -45
  114. package/dist/cli/services/git-context.js.map +1 -0
  115. package/dist/cli/services/hooks.d.ts +2 -2
  116. package/dist/cli/services/hooks.js +195 -180
  117. package/dist/cli/services/hooks.js.map +1 -0
  118. package/dist/cli/services/ink-incremental.d.ts +19 -0
  119. package/dist/cli/services/ink-incremental.js +59 -0
  120. package/dist/cli/services/ink-incremental.js.map +1 -0
  121. package/dist/cli/services/ink-resize-fix.js +54 -44
  122. package/dist/cli/services/ink-resize-fix.js.map +1 -0
  123. package/dist/cli/services/ink-sync-output.d.ts +12 -0
  124. package/dist/cli/services/ink-sync-output.js +16 -0
  125. package/dist/cli/services/ink-sync-output.js.map +1 -0
  126. package/dist/cli/services/interactive-tools.js +268 -212
  127. package/dist/cli/services/interactive-tools.js.map +1 -0
  128. package/dist/cli/services/keybinding-manager.d.ts +11 -1
  129. package/dist/cli/services/keybinding-manager.js +126 -63
  130. package/dist/cli/services/keybinding-manager.js.map +1 -0
  131. package/dist/cli/services/local-tools.d.ts +1 -1
  132. package/dist/cli/services/local-tools.js +939 -656
  133. package/dist/cli/services/local-tools.js.map +1 -0
  134. package/dist/cli/services/lsp-manager.js +757 -594
  135. package/dist/cli/services/lsp-manager.js.map +1 -0
  136. package/dist/cli/services/mcp-client.d.ts +1 -1
  137. package/dist/cli/services/mcp-client.js +173 -134
  138. package/dist/cli/services/mcp-client.js.map +1 -0
  139. package/dist/cli/services/memory-manager.js +53 -40
  140. package/dist/cli/services/memory-manager.js.map +1 -0
  141. package/dist/cli/services/model-manager.js +55 -40
  142. package/dist/cli/services/model-manager.js.map +1 -0
  143. package/dist/cli/services/model-router.js +115 -85
  144. package/dist/cli/services/model-router.js.map +1 -0
  145. package/dist/cli/services/paths.d.ts +30 -0
  146. package/dist/cli/services/paths.js +81 -0
  147. package/dist/cli/services/paths.js.map +1 -0
  148. package/dist/cli/services/permission-modes.js +32 -25
  149. package/dist/cli/services/permission-modes.js.map +1 -0
  150. package/dist/cli/services/rewind.js +182 -168
  151. package/dist/cli/services/rewind.js.map +1 -0
  152. package/dist/cli/services/ripgrep.js +115 -115
  153. package/dist/cli/services/ripgrep.js.map +1 -0
  154. package/dist/cli/services/sandbox.d.ts +1 -1
  155. package/dist/cli/services/sandbox.js +58 -37
  156. package/dist/cli/services/sandbox.js.map +1 -0
  157. package/dist/cli/services/server-tools.js +738 -565
  158. package/dist/cli/services/server-tools.js.map +1 -0
  159. package/dist/cli/services/session-persistence.js +69 -74
  160. package/dist/cli/services/session-persistence.js.map +1 -0
  161. package/dist/cli/services/subagent-worker.js +42 -27
  162. package/dist/cli/services/subagent-worker.js.map +1 -0
  163. package/dist/cli/services/subagent.d.ts +2 -0
  164. package/dist/cli/services/subagent.js +605 -433
  165. package/dist/cli/services/subagent.js.map +1 -0
  166. package/dist/cli/services/system-prompt.js +86 -78
  167. package/dist/cli/services/system-prompt.js.map +1 -0
  168. package/dist/cli/services/task-decomposer.d.ts +1 -1
  169. package/dist/cli/services/task-decomposer.js +172 -139
  170. package/dist/cli/services/task-decomposer.js.map +1 -0
  171. package/dist/cli/services/team-lead.d.ts +2 -2
  172. package/dist/cli/services/team-lead.js +727 -529
  173. package/dist/cli/services/team-lead.js.map +1 -0
  174. package/dist/cli/services/team-state.js +319 -319
  175. package/dist/cli/services/team-state.js.map +1 -0
  176. package/dist/cli/services/teammate.d.ts +8 -2
  177. package/dist/cli/services/teammate.js +857 -569
  178. package/dist/cli/services/teammate.js.map +1 -0
  179. package/dist/cli/services/telemetry.d.ts +6 -1
  180. package/dist/cli/services/telemetry.js +180 -157
  181. package/dist/cli/services/telemetry.js.map +1 -0
  182. package/dist/cli/services/tools/agent-tools.d.ts +3 -3
  183. package/dist/cli/services/tools/agent-tools.js +480 -322
  184. package/dist/cli/services/tools/agent-tools.js.map +1 -0
  185. package/dist/cli/services/tools/file-ops.js +563 -450
  186. package/dist/cli/services/tools/file-ops.js.map +1 -0
  187. package/dist/cli/services/tools/search-tools.js +231 -162
  188. package/dist/cli/services/tools/search-tools.js.map +1 -0
  189. package/dist/cli/services/tools/shell-exec.js +197 -151
  190. package/dist/cli/services/tools/shell-exec.js.map +1 -0
  191. package/dist/cli/services/tools/task-manager.js +206 -173
  192. package/dist/cli/services/tools/task-manager.js.map +1 -0
  193. package/dist/cli/services/tools/web-tools.js +388 -341
  194. package/dist/cli/services/tools/web-tools.js.map +1 -0
  195. package/dist/cli/setup/SetupApp.d.ts +2 -2
  196. package/dist/cli/setup/SetupApp.js +608 -160
  197. package/dist/cli/setup/SetupApp.js.map +1 -0
  198. package/dist/cli/shared/ErrorBoundary.d.ts +22 -0
  199. package/dist/cli/shared/ErrorBoundary.js +73 -0
  200. package/dist/cli/shared/ErrorBoundary.js.map +1 -0
  201. package/dist/cli/shared/MatrixIntro.js +66 -69
  202. package/dist/cli/shared/MatrixIntro.js.map +1 -0
  203. package/dist/cli/shared/SpinnerSlot.d.ts +14 -0
  204. package/dist/cli/shared/SpinnerSlot.js +63 -0
  205. package/dist/cli/shared/SpinnerSlot.js.map +1 -0
  206. package/dist/cli/shared/Theme.d.ts +1 -1
  207. package/dist/cli/shared/Theme.js +136 -92
  208. package/dist/cli/shared/Theme.js.map +1 -0
  209. package/dist/cli/shared/WhaleBanner.js +99 -11
  210. package/dist/cli/shared/WhaleBanner.js.map +1 -0
  211. package/dist/cli/shared/markdown.d.ts +3 -1
  212. package/dist/cli/shared/markdown.js +736 -674
  213. package/dist/cli/shared/markdown.js.map +1 -0
  214. package/dist/cli/shared/marked-terminal.d.js +2 -0
  215. package/dist/cli/shared/marked-terminal.d.js.map +1 -0
  216. package/dist/cli/shared/theme-manager.js +99 -90
  217. package/dist/cli/shared/theme-manager.js.map +1 -0
  218. package/dist/cli/shared/theme-presets.js +256 -254
  219. package/dist/cli/shared/theme-presets.js.map +1 -0
  220. package/dist/cli/status/StatusApp.js +235 -86
  221. package/dist/cli/status/StatusApp.js.map +1 -0
  222. package/dist/cli/stores/StoreApp.js +275 -65
  223. package/dist/cli/stores/StoreApp.js.map +1 -0
  224. package/dist/index.d.ts +2 -2
  225. package/dist/index.js +509 -396
  226. package/dist/index.js.map +1 -0
  227. package/dist/local-agent/connection.d.ts +2 -2
  228. package/dist/local-agent/connection.js +352 -293
  229. package/dist/local-agent/connection.js.map +1 -0
  230. package/dist/local-agent/discovery.js +259 -122
  231. package/dist/local-agent/discovery.js.map +1 -0
  232. package/dist/local-agent/executor.js +216 -193
  233. package/dist/local-agent/executor.js.map +1 -0
  234. package/dist/local-agent/index.d.ts +2 -2
  235. package/dist/local-agent/index.js +156 -156
  236. package/dist/local-agent/index.js.map +1 -0
  237. package/dist/node/adapters/base.js +18 -8
  238. package/dist/node/adapters/base.js.map +1 -0
  239. package/dist/node/adapters/discord.js +286 -275
  240. package/dist/node/adapters/discord.js.map +1 -0
  241. package/dist/node/adapters/email.js +189 -202
  242. package/dist/node/adapters/email.js.map +1 -0
  243. package/dist/node/adapters/imessage.js +145 -142
  244. package/dist/node/adapters/imessage.js.map +1 -0
  245. package/dist/node/adapters/slack.js +237 -236
  246. package/dist/node/adapters/slack.js.map +1 -0
  247. package/dist/node/adapters/sms.js +149 -151
  248. package/dist/node/adapters/sms.js.map +1 -0
  249. package/dist/node/adapters/telegram.js +88 -92
  250. package/dist/node/adapters/telegram.js.map +1 -0
  251. package/dist/node/adapters/webchat.js +160 -136
  252. package/dist/node/adapters/webchat.js.map +1 -0
  253. package/dist/node/adapters/whatsapp.js +212 -215
  254. package/dist/node/adapters/whatsapp.js.map +1 -0
  255. package/dist/node/cli.js +884 -653
  256. package/dist/node/cli.js.map +1 -0
  257. package/dist/node/config.js +20 -18
  258. package/dist/node/config.js.map +1 -0
  259. package/dist/node/gateway-client.js +191 -181
  260. package/dist/node/gateway-client.js.map +1 -0
  261. package/dist/node/portal/clipboard.js +161 -130
  262. package/dist/node/portal/clipboard.js.map +1 -0
  263. package/dist/node/portal/discovery.js +51 -45
  264. package/dist/node/portal/discovery.js.map +1 -0
  265. package/dist/node/portal/forward.js +64 -58
  266. package/dist/node/portal/forward.js.map +1 -0
  267. package/dist/node/portal/index.js +246 -221
  268. package/dist/node/portal/index.js.map +1 -0
  269. package/dist/node/portal/multiplexer.js +192 -182
  270. package/dist/node/portal/multiplexer.js.map +1 -0
  271. package/dist/node/portal/permissions.js +102 -70
  272. package/dist/node/portal/permissions.js.map +1 -0
  273. package/dist/node/portal/protocol.js +153 -116
  274. package/dist/node/portal/protocol.js.map +1 -0
  275. package/dist/node/portal/screen.js +80 -69
  276. package/dist/node/portal/screen.js.map +1 -0
  277. package/dist/node/portal/session.js +124 -117
  278. package/dist/node/portal/session.js.map +1 -0
  279. package/dist/node/portal/shell.js +140 -113
  280. package/dist/node/portal/shell.js.map +1 -0
  281. package/dist/node/portal/stream.js +77 -75
  282. package/dist/node/portal/stream.js.map +1 -0
  283. package/dist/node/portal/transfer.js +190 -167
  284. package/dist/node/portal/transfer.js.map +1 -0
  285. package/dist/node/portal/ui.js +124 -99
  286. package/dist/node/portal/ui.js.map +1 -0
  287. package/dist/node/remote-desktop/compile-helper.js +50 -45
  288. package/dist/node/remote-desktop/compile-helper.js.map +1 -0
  289. package/dist/node/remote-desktop/index.js +215 -187
  290. package/dist/node/remote-desktop/index.js.map +1 -0
  291. package/dist/node/remote-desktop/protocol.js +45 -29
  292. package/dist/node/remote-desktop/protocol.js.map +1 -0
  293. package/dist/node/runtime.js +493 -410
  294. package/dist/node/runtime.js.map +1 -0
  295. package/dist/server/handlers/__test-utils__/test-db.js +39 -89
  296. package/dist/server/handlers/__test-utils__/test-db.js.map +1 -0
  297. package/dist/server/handlers/analytics.js +467 -261
  298. package/dist/server/handlers/analytics.js.map +1 -0
  299. package/dist/server/handlers/api-docs.js +1030 -895
  300. package/dist/server/handlers/api-docs.js.map +1 -0
  301. package/dist/server/handlers/api-keys.js +291 -242
  302. package/dist/server/handlers/api-keys.js.map +1 -0
  303. package/dist/server/handlers/billing.js +330 -239
  304. package/dist/server/handlers/billing.js.map +1 -0
  305. package/dist/server/handlers/browser.js +468 -395
  306. package/dist/server/handlers/browser.js.map +1 -0
  307. package/dist/server/handlers/catalog.js +1377 -978
  308. package/dist/server/handlers/catalog.js.map +1 -0
  309. package/dist/server/handlers/clickhouse.js +157 -109
  310. package/dist/server/handlers/clickhouse.js.map +1 -0
  311. package/dist/server/handlers/comms.js +1439 -984
  312. package/dist/server/handlers/comms.js.map +1 -0
  313. package/dist/server/handlers/creations.js +461 -394
  314. package/dist/server/handlers/creations.js.map +1 -0
  315. package/dist/server/handlers/crm.js +1082 -791
  316. package/dist/server/handlers/crm.js.map +1 -0
  317. package/dist/server/handlers/discovery.js +251 -232
  318. package/dist/server/handlers/discovery.js.map +1 -0
  319. package/dist/server/handlers/embeddings.js +241 -164
  320. package/dist/server/handlers/embeddings.js.map +1 -0
  321. package/dist/server/handlers/enrichment.js +887 -718
  322. package/dist/server/handlers/enrichment.js.map +1 -0
  323. package/dist/server/handlers/image-gen.js +467 -376
  324. package/dist/server/handlers/image-gen.js.map +1 -0
  325. package/dist/server/handlers/inventory.js +797 -424
  326. package/dist/server/handlers/inventory.js.map +1 -0
  327. package/dist/server/handlers/kali.js +272 -230
  328. package/dist/server/handlers/kali.js.map +1 -0
  329. package/dist/server/handlers/llm-providers.js +803 -580
  330. package/dist/server/handlers/llm-providers.js.map +1 -0
  331. package/dist/server/handlers/local-agent.js +133 -105
  332. package/dist/server/handlers/local-agent.js.map +1 -0
  333. package/dist/server/handlers/media.js +1179 -857
  334. package/dist/server/handlers/media.js.map +1 -0
  335. package/dist/server/handlers/meta-ads.js +2669 -2093
  336. package/dist/server/handlers/meta-ads.js.map +1 -0
  337. package/dist/server/handlers/nodes.js +1321 -913
  338. package/dist/server/handlers/nodes.js.map +1 -0
  339. package/dist/server/handlers/operations.js +183 -157
  340. package/dist/server/handlers/operations.js.map +1 -0
  341. package/dist/server/handlers/platform.js +346 -210
  342. package/dist/server/handlers/platform.js.map +1 -0
  343. package/dist/server/handlers/remove-bg.js +118 -86
  344. package/dist/server/handlers/remove-bg.js.map +1 -0
  345. package/dist/server/handlers/storefront.js +586 -446
  346. package/dist/server/handlers/storefront.js.map +1 -0
  347. package/dist/server/handlers/supply-chain.js +546 -326
  348. package/dist/server/handlers/supply-chain.js.map +1 -0
  349. package/dist/server/handlers/transcription.js +106 -97
  350. package/dist/server/handlers/transcription.js.map +1 -0
  351. package/dist/server/handlers/video-gen.js +593 -424
  352. package/dist/server/handlers/video-gen.js.map +1 -0
  353. package/dist/server/handlers/voice.js +1458 -1039
  354. package/dist/server/handlers/voice.js.map +1 -0
  355. package/dist/server/handlers/workflow-steps.js +2837 -2116
  356. package/dist/server/handlers/workflow-steps.js.map +1 -0
  357. package/dist/server/handlers/workflows.js +1630 -933
  358. package/dist/server/handlers/workflows.js.map +1 -0
  359. package/dist/server/index.js +3167 -2422
  360. package/dist/server/index.js.map +1 -0
  361. package/dist/server/lib/batch-client.js +471 -409
  362. package/dist/server/lib/batch-client.js.map +1 -0
  363. package/dist/server/lib/clickhouse-buffer.js +118 -104
  364. package/dist/server/lib/clickhouse-buffer.js.map +1 -0
  365. package/dist/server/lib/clickhouse-client.js +107 -107
  366. package/dist/server/lib/clickhouse-client.js.map +1 -0
  367. package/dist/server/lib/coa-renderer.js +1786 -356
  368. package/dist/server/lib/coa-renderer.js.map +1 -0
  369. package/dist/server/lib/code-worker-pool.js +227 -177
  370. package/dist/server/lib/code-worker-pool.js.map +1 -0
  371. package/dist/server/lib/code-worker.js +174 -164
  372. package/dist/server/lib/code-worker.js.map +1 -0
  373. package/dist/server/lib/compaction-service.d.ts +2 -12
  374. package/dist/server/lib/compaction-service.js +74 -184
  375. package/dist/server/lib/compaction-service.js.map +1 -0
  376. package/dist/server/lib/logger.js +36 -24
  377. package/dist/server/lib/logger.js.map +1 -0
  378. package/dist/server/lib/otel.js +101 -80
  379. package/dist/server/lib/otel.js.map +1 -0
  380. package/dist/server/lib/pdf-renderer.js +952 -788
  381. package/dist/server/lib/pdf-renderer.js.map +1 -0
  382. package/dist/server/lib/prompt-sanitizer.js +188 -108
  383. package/dist/server/lib/prompt-sanitizer.js.map +1 -0
  384. package/dist/server/lib/provider-capabilities.js +136 -138
  385. package/dist/server/lib/provider-capabilities.js.map +1 -0
  386. package/dist/server/lib/provider-failover.js +190 -168
  387. package/dist/server/lib/provider-failover.js.map +1 -0
  388. package/dist/server/lib/rate-limiter.js +186 -117
  389. package/dist/server/lib/rate-limiter.js.map +1 -0
  390. package/dist/server/lib/react-pdf-layout.js +551 -382
  391. package/dist/server/lib/react-pdf-layout.js.map +1 -0
  392. package/dist/server/lib/server-agent-loop.d.ts +4 -1
  393. package/dist/server/lib/server-agent-loop.js +906 -634
  394. package/dist/server/lib/server-agent-loop.js.map +1 -0
  395. package/dist/server/lib/server-subagent.js +260 -164
  396. package/dist/server/lib/server-subagent.js.map +1 -0
  397. package/dist/server/lib/session-checkpoint.js +105 -96
  398. package/dist/server/lib/session-checkpoint.js.map +1 -0
  399. package/dist/server/lib/ssrf-guard.js +193 -184
  400. package/dist/server/lib/ssrf-guard.js.map +1 -0
  401. package/dist/server/lib/supabase-client.js +94 -82
  402. package/dist/server/lib/supabase-client.js.map +1 -0
  403. package/dist/server/lib/template-resolver.js +154 -176
  404. package/dist/server/lib/template-resolver.js.map +1 -0
  405. package/dist/server/lib/utils.js +242 -133
  406. package/dist/server/lib/utils.js.map +1 -0
  407. package/dist/server/local-agent-gateway.d.ts +2 -2
  408. package/dist/server/local-agent-gateway.js +785 -627
  409. package/dist/server/local-agent-gateway.js.map +1 -0
  410. package/dist/server/providers/anthropic.js +250 -172
  411. package/dist/server/providers/anthropic.js.map +1 -0
  412. package/dist/server/providers/bedrock.js +217 -158
  413. package/dist/server/providers/bedrock.js.map +1 -0
  414. package/dist/server/providers/gemini.js +548 -418
  415. package/dist/server/providers/gemini.js.map +1 -0
  416. package/dist/server/providers/openai.js +571 -437
  417. package/dist/server/providers/openai.js.map +1 -0
  418. package/dist/server/providers/registry.js +23 -18
  419. package/dist/server/providers/registry.js.map +1 -0
  420. package/dist/server/providers/shared.js +123 -95
  421. package/dist/server/providers/shared.js.map +1 -0
  422. package/dist/server/providers/types.js +1 -11
  423. package/dist/server/providers/types.js.map +1 -0
  424. package/dist/server/proxy-handlers.js +209 -165
  425. package/dist/server/proxy-handlers.js.map +1 -0
  426. package/dist/server/tool-router.js +959 -599
  427. package/dist/server/tool-router.js.map +1 -0
  428. package/dist/server/validation.js +248 -188
  429. package/dist/server/validation.js.map +1 -0
  430. package/dist/server/worker.js +202 -133
  431. package/dist/server/worker.js.map +1 -0
  432. package/dist/setup.d.ts +2 -2
  433. package/dist/setup.js +151 -147
  434. package/dist/setup.js.map +1 -0
  435. package/dist/shared/agent-core.d.ts +115 -26
  436. package/dist/shared/agent-core.js +956 -522
  437. package/dist/shared/agent-core.js.map +1 -0
  438. package/dist/shared/anthropic-types.js +1 -6
  439. package/dist/shared/anthropic-types.js.map +1 -0
  440. package/dist/shared/api-client.d.ts +16 -9
  441. package/dist/shared/api-client.js +419 -327
  442. package/dist/shared/api-client.js.map +1 -0
  443. package/dist/shared/compaction.d.ts +36 -0
  444. package/dist/shared/compaction.js +138 -0
  445. package/dist/shared/compaction.js.map +1 -0
  446. package/dist/shared/constants.js +67 -64
  447. package/dist/shared/constants.js.map +1 -0
  448. package/dist/shared/sse-parser.js +221 -219
  449. package/dist/shared/sse-parser.js.map +1 -0
  450. package/dist/shared/tool-dispatch.d.ts +4 -0
  451. package/dist/shared/tool-dispatch.js +226 -165
  452. package/dist/shared/tool-dispatch.js.map +1 -0
  453. package/dist/shared/types.js +1 -6
  454. package/dist/shared/types.js.map +1 -0
  455. package/dist/types/cli-highlight.d.js +2 -0
  456. package/dist/types/cli-highlight.d.js.map +1 -0
  457. package/dist/types/diff.d.js +2 -0
  458. package/dist/types/diff.d.js.map +1 -0
  459. package/dist/types/pdf-parse.d.js +2 -0
  460. package/dist/types/pdf-parse.d.js.map +1 -0
  461. package/dist/updater.d.ts +1 -1
  462. package/dist/updater.js +118 -92
  463. package/dist/updater.js.map +1 -0
  464. package/dist/webchat/widget.js +227 -380
  465. package/dist/webchat/widget.js.map +1 -0
  466. package/package.json +22 -10
  467. package/vendor/ink/build/ansi-tokenizer.d.ts +38 -0
  468. package/vendor/ink/build/ansi-tokenizer.js +316 -0
  469. package/vendor/ink/build/ansi-tokenizer.js.map +1 -0
  470. package/vendor/ink/build/apply-styles.js +175 -0
  471. package/vendor/ink/build/build-layout.js +77 -0
  472. package/vendor/ink/build/calculate-wrapped-text.js +53 -0
  473. package/vendor/ink/build/colorize.d.ts +3 -0
  474. package/vendor/ink/build/colorize.js +48 -0
  475. package/vendor/ink/build/colorize.js.map +1 -0
  476. package/vendor/ink/build/components/AccessibilityContext.d.ts +3 -0
  477. package/vendor/ink/build/components/AccessibilityContext.js +5 -0
  478. package/vendor/ink/build/components/AccessibilityContext.js.map +1 -0
  479. package/vendor/ink/build/components/App.d.ts +18 -0
  480. package/vendor/ink/build/components/App.js +351 -0
  481. package/vendor/ink/build/components/App.js.map +1 -0
  482. package/vendor/ink/build/components/AppContext.d.ts +15 -0
  483. package/vendor/ink/build/components/AppContext.js +11 -0
  484. package/vendor/ink/build/components/AppContext.js.map +1 -0
  485. package/vendor/ink/build/components/BackgroundContext.d.ts +4 -0
  486. package/vendor/ink/build/components/BackgroundContext.js +3 -0
  487. package/vendor/ink/build/components/BackgroundContext.js.map +1 -0
  488. package/vendor/ink/build/components/Box.d.ts +117 -0
  489. package/vendor/ink/build/components/Box.js +34 -0
  490. package/vendor/ink/build/components/Box.js.map +1 -0
  491. package/vendor/ink/build/components/Color.js +62 -0
  492. package/vendor/ink/build/components/Cursor.d.ts +83 -0
  493. package/vendor/ink/build/components/Cursor.js +53 -0
  494. package/vendor/ink/build/components/Cursor.js.map +1 -0
  495. package/vendor/ink/build/components/CursorContext.d.ts +11 -0
  496. package/vendor/ink/build/components/CursorContext.js +8 -0
  497. package/vendor/ink/build/components/CursorContext.js.map +1 -0
  498. package/vendor/ink/build/components/ErrorBoundary.d.ts +18 -0
  499. package/vendor/ink/build/components/ErrorBoundary.js +23 -0
  500. package/vendor/ink/build/components/ErrorBoundary.js.map +1 -0
  501. package/vendor/ink/build/components/ErrorOverview.d.ts +6 -0
  502. package/vendor/ink/build/components/ErrorOverview.js +84 -0
  503. package/vendor/ink/build/components/ErrorOverview.js.map +1 -0
  504. package/vendor/ink/build/components/FocusContext.d.ts +16 -0
  505. package/vendor/ink/build/components/FocusContext.js +17 -0
  506. package/vendor/ink/build/components/FocusContext.js.map +1 -0
  507. package/vendor/ink/build/components/Newline.d.ts +13 -0
  508. package/vendor/ink/build/components/Newline.js +8 -0
  509. package/vendor/ink/build/components/Newline.js.map +1 -0
  510. package/vendor/ink/build/components/Spacer.d.ts +7 -0
  511. package/vendor/ink/build/components/Spacer.js +11 -0
  512. package/vendor/ink/build/components/Spacer.js.map +1 -0
  513. package/vendor/ink/build/components/Static.d.ts +24 -0
  514. package/vendor/ink/build/components/Static.js +28 -0
  515. package/vendor/ink/build/components/Static.js.map +1 -0
  516. package/vendor/ink/build/components/StderrContext.d.ts +15 -0
  517. package/vendor/ink/build/components/StderrContext.js +13 -0
  518. package/vendor/ink/build/components/StderrContext.js.map +1 -0
  519. package/vendor/ink/build/components/StdinContext.d.ts +22 -0
  520. package/vendor/ink/build/components/StdinContext.js +19 -0
  521. package/vendor/ink/build/components/StdinContext.js.map +1 -0
  522. package/vendor/ink/build/components/StdoutContext.d.ts +15 -0
  523. package/vendor/ink/build/components/StdoutContext.js +13 -0
  524. package/vendor/ink/build/components/StdoutContext.js.map +1 -0
  525. package/vendor/ink/build/components/Text.d.ts +55 -0
  526. package/vendor/ink/build/components/Text.js +50 -0
  527. package/vendor/ink/build/components/Text.js.map +1 -0
  528. package/vendor/ink/build/components/Transform.d.ts +16 -0
  529. package/vendor/ink/build/components/Transform.js +15 -0
  530. package/vendor/ink/build/components/Transform.js.map +1 -0
  531. package/vendor/ink/build/cursor-helpers.d.ts +38 -0
  532. package/vendor/ink/build/cursor-helpers.js +56 -0
  533. package/vendor/ink/build/cursor-helpers.js.map +1 -0
  534. package/vendor/ink/build/devtools-window-polyfill.d.ts +1 -0
  535. package/vendor/ink/build/devtools-window-polyfill.js +65 -0
  536. package/vendor/ink/build/devtools-window-polyfill.js.map +1 -0
  537. package/vendor/ink/build/devtools.d.ts +1 -0
  538. package/vendor/ink/build/devtools.js +11 -0
  539. package/vendor/ink/build/devtools.js.map +1 -0
  540. package/vendor/ink/build/dom.d.ts +56 -0
  541. package/vendor/ink/build/dom.js +124 -0
  542. package/vendor/ink/build/dom.js.map +1 -0
  543. package/vendor/ink/build/experimental/apply-style.js +140 -0
  544. package/vendor/ink/build/experimental/dom.js +123 -0
  545. package/vendor/ink/build/experimental/output.js +91 -0
  546. package/vendor/ink/build/experimental/reconciler.js +141 -0
  547. package/vendor/ink/build/experimental/renderer.js +81 -0
  548. package/vendor/ink/build/get-max-width.d.ts +3 -0
  549. package/vendor/ink/build/get-max-width.js +10 -0
  550. package/vendor/ink/build/get-max-width.js.map +1 -0
  551. package/vendor/ink/build/hooks/use-app.d.ts +5 -0
  552. package/vendor/ink/build/hooks/use-app.js +8 -0
  553. package/vendor/ink/build/hooks/use-app.js.map +1 -0
  554. package/vendor/ink/build/hooks/use-cursor.d.ts +12 -0
  555. package/vendor/ink/build/hooks/use-cursor.js +29 -0
  556. package/vendor/ink/build/hooks/use-cursor.js.map +1 -0
  557. package/vendor/ink/build/hooks/use-focus-manager.d.ts +28 -0
  558. package/vendor/ink/build/hooks/use-focus-manager.js +17 -0
  559. package/vendor/ink/build/hooks/use-focus-manager.js.map +1 -0
  560. package/vendor/ink/build/hooks/use-focus.d.ts +29 -0
  561. package/vendor/ink/build/hooks/use-focus.js +42 -0
  562. package/vendor/ink/build/hooks/use-focus.js.map +1 -0
  563. package/vendor/ink/build/hooks/use-input.d.ts +131 -0
  564. package/vendor/ink/build/hooks/use-input.js +124 -0
  565. package/vendor/ink/build/hooks/use-input.js.map +1 -0
  566. package/vendor/ink/build/hooks/use-is-screen-reader-enabled.d.ts +5 -0
  567. package/vendor/ink/build/hooks/use-is-screen-reader-enabled.js +11 -0
  568. package/vendor/ink/build/hooks/use-is-screen-reader-enabled.js.map +1 -0
  569. package/vendor/ink/build/hooks/use-stderr.d.ts +5 -0
  570. package/vendor/ink/build/hooks/use-stderr.js +8 -0
  571. package/vendor/ink/build/hooks/use-stderr.js.map +1 -0
  572. package/vendor/ink/build/hooks/use-stdin.d.ts +5 -0
  573. package/vendor/ink/build/hooks/use-stdin.js +8 -0
  574. package/vendor/ink/build/hooks/use-stdin.js.map +1 -0
  575. package/vendor/ink/build/hooks/use-stdout.d.ts +5 -0
  576. package/vendor/ink/build/hooks/use-stdout.js +8 -0
  577. package/vendor/ink/build/hooks/use-stdout.js.map +1 -0
  578. package/vendor/ink/build/hooks/useInput.js +38 -0
  579. package/vendor/ink/build/index.d.ts +34 -0
  580. package/vendor/ink/build/index.js +20 -0
  581. package/vendor/ink/build/index.js.map +1 -0
  582. package/vendor/ink/build/ink.d.ts +90 -0
  583. package/vendor/ink/build/ink.js +654 -0
  584. package/vendor/ink/build/ink.js.map +1 -0
  585. package/vendor/ink/build/input-parser.d.ts +7 -0
  586. package/vendor/ink/build/input-parser.js +154 -0
  587. package/vendor/ink/build/input-parser.js.map +1 -0
  588. package/vendor/ink/build/instance.js +205 -0
  589. package/vendor/ink/build/instances.d.ts +3 -0
  590. package/vendor/ink/build/instances.js +8 -0
  591. package/vendor/ink/build/instances.js.map +1 -0
  592. package/vendor/ink/build/kitty-keyboard.d.ts +23 -0
  593. package/vendor/ink/build/kitty-keyboard.js +32 -0
  594. package/vendor/ink/build/kitty-keyboard.js.map +1 -0
  595. package/vendor/ink/build/layout.d.ts +7 -0
  596. package/vendor/ink/build/layout.js +33 -0
  597. package/vendor/ink/build/layout.js.map +1 -0
  598. package/vendor/ink/build/log-update.d.ts +19 -0
  599. package/vendor/ink/build/log-update.js +243 -0
  600. package/vendor/ink/build/log-update.js.map +1 -0
  601. package/vendor/ink/build/measure-element.d.ts +16 -0
  602. package/vendor/ink/build/measure-element.js +9 -0
  603. package/vendor/ink/build/measure-element.js.map +1 -0
  604. package/vendor/ink/build/measure-text.d.ts +6 -0
  605. package/vendor/ink/build/measure-text.js +21 -0
  606. package/vendor/ink/build/measure-text.js.map +1 -0
  607. package/vendor/ink/build/options.d.ts +52 -0
  608. package/vendor/ink/build/options.js +2 -0
  609. package/vendor/ink/build/options.js.map +1 -0
  610. package/vendor/ink/build/output.d.ts +35 -0
  611. package/vendor/ink/build/output.js +183 -0
  612. package/vendor/ink/build/output.js.map +1 -0
  613. package/vendor/ink/build/parse-keypress.d.ts +22 -0
  614. package/vendor/ink/build/parse-keypress.js +493 -0
  615. package/vendor/ink/build/parse-keypress.js.map +1 -0
  616. package/vendor/ink/build/reconciler.d.ts +4 -0
  617. package/vendor/ink/build/reconciler.js +274 -0
  618. package/vendor/ink/build/reconciler.js.map +1 -0
  619. package/vendor/ink/build/render-background.d.ts +4 -0
  620. package/vendor/ink/build/render-background.js +25 -0
  621. package/vendor/ink/build/render-background.js.map +1 -0
  622. package/vendor/ink/build/render-border.d.ts +4 -0
  623. package/vendor/ink/build/render-border.js +73 -0
  624. package/vendor/ink/build/render-border.js.map +1 -0
  625. package/vendor/ink/build/render-node-to-output.d.ts +14 -0
  626. package/vendor/ink/build/render-node-to-output.js +147 -0
  627. package/vendor/ink/build/render-node-to-output.js.map +1 -0
  628. package/vendor/ink/build/render-to-string.d.ts +38 -0
  629. package/vendor/ink/build/render-to-string.js +115 -0
  630. package/vendor/ink/build/render-to-string.js.map +1 -0
  631. package/vendor/ink/build/render.d.ts +121 -0
  632. package/vendor/ink/build/render.js +55 -0
  633. package/vendor/ink/build/render.js.map +1 -0
  634. package/vendor/ink/build/renderer.d.ts +8 -0
  635. package/vendor/ink/build/renderer.js +55 -0
  636. package/vendor/ink/build/renderer.js.map +1 -0
  637. package/vendor/ink/build/sanitize-ansi.d.ts +2 -0
  638. package/vendor/ink/build/sanitize-ansi.js +27 -0
  639. package/vendor/ink/build/sanitize-ansi.js.map +1 -0
  640. package/vendor/ink/build/screen-reader-update.d.ts +13 -0
  641. package/vendor/ink/build/screen-reader-update.js +38 -0
  642. package/vendor/ink/build/screen-reader-update.js.map +1 -0
  643. package/vendor/ink/build/squash-text-nodes.d.ts +3 -0
  644. package/vendor/ink/build/squash-text-nodes.js +36 -0
  645. package/vendor/ink/build/squash-text-nodes.js.map +1 -0
  646. package/vendor/ink/build/styles.d.ts +240 -0
  647. package/vendor/ink/build/styles.js +232 -0
  648. package/vendor/ink/build/styles.js.map +1 -0
  649. package/vendor/ink/build/utils.d.ts +2 -0
  650. package/vendor/ink/build/utils.js +4 -0
  651. package/vendor/ink/build/utils.js.map +1 -0
  652. package/vendor/ink/build/wrap-text.d.ts +3 -0
  653. package/vendor/ink/build/wrap-text.js +31 -0
  654. package/vendor/ink/build/wrap-text.js.map +1 -0
  655. package/vendor/ink/build/write-synchronized.d.ts +4 -0
  656. package/vendor/ink/build/write-synchronized.js +7 -0
  657. package/vendor/ink/build/write-synchronized.js.map +1 -0
  658. package/vendor/ink/license +10 -0
  659. package/vendor/ink/node_modules/@types/node/LICENSE +21 -0
  660. package/vendor/ink/node_modules/@types/node/README.md +15 -0
  661. package/vendor/ink/node_modules/@types/node/assert/strict.d.ts +105 -0
  662. package/vendor/ink/node_modules/@types/node/assert.d.ts +955 -0
  663. package/vendor/ink/node_modules/@types/node/async_hooks.d.ts +623 -0
  664. package/vendor/ink/node_modules/@types/node/buffer.buffer.d.ts +466 -0
  665. package/vendor/ink/node_modules/@types/node/buffer.d.ts +1810 -0
  666. package/vendor/ink/node_modules/@types/node/child_process.d.ts +1428 -0
  667. package/vendor/ink/node_modules/@types/node/cluster.d.ts +486 -0
  668. package/vendor/ink/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  669. package/vendor/ink/node_modules/@types/node/console.d.ts +151 -0
  670. package/vendor/ink/node_modules/@types/node/constants.d.ts +20 -0
  671. package/vendor/ink/node_modules/@types/node/crypto.d.ts +4065 -0
  672. package/vendor/ink/node_modules/@types/node/dgram.d.ts +564 -0
  673. package/vendor/ink/node_modules/@types/node/diagnostics_channel.d.ts +576 -0
  674. package/vendor/ink/node_modules/@types/node/dns/promises.d.ts +503 -0
  675. package/vendor/ink/node_modules/@types/node/dns.d.ts +922 -0
  676. package/vendor/ink/node_modules/@types/node/domain.d.ts +166 -0
  677. package/vendor/ink/node_modules/@types/node/events.d.ts +1054 -0
  678. package/vendor/ink/node_modules/@types/node/fs/promises.d.ts +1329 -0
  679. package/vendor/ink/node_modules/@types/node/fs.d.ts +4676 -0
  680. package/vendor/ink/node_modules/@types/node/globals.d.ts +150 -0
  681. package/vendor/ink/node_modules/@types/node/globals.typedarray.d.ts +101 -0
  682. package/vendor/ink/node_modules/@types/node/http.d.ts +2167 -0
  683. package/vendor/ink/node_modules/@types/node/http2.d.ts +2480 -0
  684. package/vendor/ink/node_modules/@types/node/https.d.ts +405 -0
  685. package/vendor/ink/node_modules/@types/node/index.d.ts +115 -0
  686. package/vendor/ink/node_modules/@types/node/inspector/promises.d.ts +41 -0
  687. package/vendor/ink/node_modules/@types/node/inspector.d.ts +224 -0
  688. package/vendor/ink/node_modules/@types/node/inspector.generated.d.ts +4226 -0
  689. package/vendor/ink/node_modules/@types/node/module.d.ts +819 -0
  690. package/vendor/ink/node_modules/@types/node/net.d.ts +933 -0
  691. package/vendor/ink/node_modules/@types/node/os.d.ts +507 -0
  692. package/vendor/ink/node_modules/@types/node/package.json +155 -0
  693. package/vendor/ink/node_modules/@types/node/path/posix.d.ts +8 -0
  694. package/vendor/ink/node_modules/@types/node/path/win32.d.ts +8 -0
  695. package/vendor/ink/node_modules/@types/node/path.d.ts +187 -0
  696. package/vendor/ink/node_modules/@types/node/perf_hooks.d.ts +643 -0
  697. package/vendor/ink/node_modules/@types/node/process.d.ts +2156 -0
  698. package/vendor/ink/node_modules/@types/node/punycode.d.ts +117 -0
  699. package/vendor/ink/node_modules/@types/node/querystring.d.ts +152 -0
  700. package/vendor/ink/node_modules/@types/node/quic.d.ts +910 -0
  701. package/vendor/ink/node_modules/@types/node/readline/promises.d.ts +161 -0
  702. package/vendor/ink/node_modules/@types/node/readline.d.ts +541 -0
  703. package/vendor/ink/node_modules/@types/node/repl.d.ts +415 -0
  704. package/vendor/ink/node_modules/@types/node/sea.d.ts +162 -0
  705. package/vendor/ink/node_modules/@types/node/sqlite.d.ts +955 -0
  706. package/vendor/ink/node_modules/@types/node/stream/consumers.d.ts +38 -0
  707. package/vendor/ink/node_modules/@types/node/stream/promises.d.ts +211 -0
  708. package/vendor/ink/node_modules/@types/node/stream/web.d.ts +296 -0
  709. package/vendor/ink/node_modules/@types/node/stream.d.ts +1760 -0
  710. package/vendor/ink/node_modules/@types/node/string_decoder.d.ts +67 -0
  711. package/vendor/ink/node_modules/@types/node/test/reporters.d.ts +96 -0
  712. package/vendor/ink/node_modules/@types/node/test.d.ts +2240 -0
  713. package/vendor/ink/node_modules/@types/node/timers/promises.d.ts +108 -0
  714. package/vendor/ink/node_modules/@types/node/timers.d.ts +159 -0
  715. package/vendor/ink/node_modules/@types/node/tls.d.ts +1198 -0
  716. package/vendor/ink/node_modules/@types/node/trace_events.d.ts +197 -0
  717. package/vendor/ink/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +462 -0
  718. package/vendor/ink/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
  719. package/vendor/ink/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
  720. package/vendor/ink/node_modules/@types/node/ts5.6/index.d.ts +117 -0
  721. package/vendor/ink/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
  722. package/vendor/ink/node_modules/@types/node/ts5.7/index.d.ts +117 -0
  723. package/vendor/ink/node_modules/@types/node/tty.d.ts +250 -0
  724. package/vendor/ink/node_modules/@types/node/url.d.ts +519 -0
  725. package/vendor/ink/node_modules/@types/node/util/types.d.ts +558 -0
  726. package/vendor/ink/node_modules/@types/node/util.d.ts +1662 -0
  727. package/vendor/ink/node_modules/@types/node/v8.d.ts +983 -0
  728. package/vendor/ink/node_modules/@types/node/vm.d.ts +1208 -0
  729. package/vendor/ink/node_modules/@types/node/wasi.d.ts +202 -0
  730. package/vendor/ink/node_modules/@types/node/web-globals/abortcontroller.d.ts +59 -0
  731. package/vendor/ink/node_modules/@types/node/web-globals/blob.d.ts +23 -0
  732. package/vendor/ink/node_modules/@types/node/web-globals/console.d.ts +9 -0
  733. package/vendor/ink/node_modules/@types/node/web-globals/crypto.d.ts +39 -0
  734. package/vendor/ink/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  735. package/vendor/ink/node_modules/@types/node/web-globals/encoding.d.ts +11 -0
  736. package/vendor/ink/node_modules/@types/node/web-globals/events.d.ts +106 -0
  737. package/vendor/ink/node_modules/@types/node/web-globals/fetch.d.ts +69 -0
  738. package/vendor/ink/node_modules/@types/node/web-globals/importmeta.d.ts +13 -0
  739. package/vendor/ink/node_modules/@types/node/web-globals/messaging.d.ts +23 -0
  740. package/vendor/ink/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
  741. package/vendor/ink/node_modules/@types/node/web-globals/performance.d.ts +45 -0
  742. package/vendor/ink/node_modules/@types/node/web-globals/storage.d.ts +24 -0
  743. package/vendor/ink/node_modules/@types/node/web-globals/streams.d.ts +115 -0
  744. package/vendor/ink/node_modules/@types/node/web-globals/timers.d.ts +44 -0
  745. package/vendor/ink/node_modules/@types/node/web-globals/url.d.ts +24 -0
  746. package/vendor/ink/node_modules/@types/node/worker_threads.d.ts +717 -0
  747. package/vendor/ink/node_modules/@types/node/zlib.d.ts +618 -0
  748. package/vendor/ink/node_modules/node-pty/LICENSE +69 -0
  749. package/vendor/ink/node_modules/node-pty/README.md +164 -0
  750. package/vendor/ink/node_modules/node-pty/binding.gyp +150 -0
  751. package/vendor/ink/node_modules/node-pty/lib/conpty_console_list_agent.js +25 -0
  752. package/vendor/ink/node_modules/node-pty/lib/eventEmitter2.js +47 -0
  753. package/vendor/ink/node_modules/node-pty/lib/index.js +52 -0
  754. package/vendor/ink/node_modules/node-pty/lib/interfaces.js +7 -0
  755. package/vendor/ink/node_modules/node-pty/lib/shared/conout.js +11 -0
  756. package/vendor/ink/node_modules/node-pty/lib/terminal.js +190 -0
  757. package/vendor/ink/node_modules/node-pty/lib/types.js +7 -0
  758. package/vendor/ink/node_modules/node-pty/lib/unixTerminal.js +349 -0
  759. package/vendor/ink/node_modules/node-pty/lib/utils.js +39 -0
  760. package/vendor/ink/node_modules/node-pty/lib/windowsConoutConnection.js +125 -0
  761. package/vendor/ink/node_modules/node-pty/lib/windowsPtyAgent.js +287 -0
  762. package/vendor/ink/node_modules/node-pty/lib/windowsTerminal.js +201 -0
  763. package/vendor/ink/node_modules/node-pty/lib/worker/conoutSocketWorker.js +22 -0
  764. package/vendor/ink/node_modules/node-pty/package.json +65 -0
  765. package/vendor/ink/node_modules/node-pty/prebuilds/darwin-arm64/pty.node +0 -0
  766. package/vendor/ink/node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper +0 -0
  767. package/vendor/ink/node_modules/node-pty/prebuilds/darwin-x64/pty.node +0 -0
  768. package/vendor/ink/node_modules/node-pty/prebuilds/darwin-x64/spawn-helper +0 -0
  769. package/vendor/ink/node_modules/node-pty/prebuilds/linux-arm64/pty.node +0 -0
  770. package/vendor/ink/node_modules/node-pty/prebuilds/linux-x64/pty.node +0 -0
  771. package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty/OpenConsole.exe +0 -0
  772. package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty/conpty.dll +0 -0
  773. package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty.node +0 -0
  774. package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty.pdb +0 -0
  775. package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty_console_list.node +0 -0
  776. package/vendor/ink/node_modules/node-pty/prebuilds/win32-arm64/conpty_console_list.pdb +0 -0
  777. package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe +0 -0
  778. package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty/conpty.dll +0 -0
  779. package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty.node +0 -0
  780. package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty.pdb +0 -0
  781. package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty_console_list.node +0 -0
  782. package/vendor/ink/node_modules/node-pty/prebuilds/win32-x64/conpty_console_list.pdb +0 -0
  783. package/vendor/ink/node_modules/node-pty/scripts/post-install.js +76 -0
  784. package/vendor/ink/node_modules/node-pty/scripts/prebuild.js +34 -0
  785. package/vendor/ink/node_modules/node-pty/src/unix/pty.cc +875 -0
  786. package/vendor/ink/node_modules/node-pty/src/unix/spawn-helper.cc +23 -0
  787. package/vendor/ink/node_modules/node-pty/src/win/conpty.cc +582 -0
  788. package/vendor/ink/node_modules/node-pty/src/win/conpty.h +41 -0
  789. package/vendor/ink/node_modules/node-pty/src/win/conpty_console_list.cc +44 -0
  790. package/vendor/ink/node_modules/node-pty/src/win/path_util.cc +95 -0
  791. package/vendor/ink/node_modules/node-pty/src/win/path_util.h +26 -0
  792. package/vendor/ink/node_modules/node-pty/third_party/conpty/1.23.251008001/win10-arm64/OpenConsole.exe +0 -0
  793. package/vendor/ink/node_modules/node-pty/third_party/conpty/1.23.251008001/win10-arm64/conpty.dll +0 -0
  794. package/vendor/ink/node_modules/node-pty/third_party/conpty/1.23.251008001/win10-x64/OpenConsole.exe +0 -0
  795. package/vendor/ink/node_modules/node-pty/third_party/conpty/1.23.251008001/win10-x64/conpty.dll +0 -0
  796. package/vendor/ink/node_modules/node-pty/typings/node-pty.d.ts +215 -0
  797. package/vendor/ink/node_modules/undici-types/LICENSE +21 -0
  798. package/vendor/ink/node_modules/undici-types/README.md +6 -0
  799. package/vendor/ink/node_modules/undici-types/agent.d.ts +32 -0
  800. package/vendor/ink/node_modules/undici-types/api.d.ts +43 -0
  801. package/vendor/ink/node_modules/undici-types/balanced-pool.d.ts +30 -0
  802. package/vendor/ink/node_modules/undici-types/cache-interceptor.d.ts +173 -0
  803. package/vendor/ink/node_modules/undici-types/cache.d.ts +36 -0
  804. package/vendor/ink/node_modules/undici-types/client-stats.d.ts +15 -0
  805. package/vendor/ink/node_modules/undici-types/client.d.ts +108 -0
  806. package/vendor/ink/node_modules/undici-types/connector.d.ts +34 -0
  807. package/vendor/ink/node_modules/undici-types/content-type.d.ts +21 -0
  808. package/vendor/ink/node_modules/undici-types/cookies.d.ts +30 -0
  809. package/vendor/ink/node_modules/undici-types/diagnostics-channel.d.ts +74 -0
  810. package/vendor/ink/node_modules/undici-types/dispatcher.d.ts +276 -0
  811. package/vendor/ink/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
  812. package/vendor/ink/node_modules/undici-types/errors.d.ts +161 -0
  813. package/vendor/ink/node_modules/undici-types/eventsource.d.ts +66 -0
  814. package/vendor/ink/node_modules/undici-types/fetch.d.ts +211 -0
  815. package/vendor/ink/node_modules/undici-types/formdata.d.ts +108 -0
  816. package/vendor/ink/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  817. package/vendor/ink/node_modules/undici-types/global-origin.d.ts +7 -0
  818. package/vendor/ink/node_modules/undici-types/h2c-client.d.ts +73 -0
  819. package/vendor/ink/node_modules/undici-types/handlers.d.ts +15 -0
  820. package/vendor/ink/node_modules/undici-types/header.d.ts +160 -0
  821. package/vendor/ink/node_modules/undici-types/index.d.ts +88 -0
  822. package/vendor/ink/node_modules/undici-types/interceptors.d.ts +73 -0
  823. package/vendor/ink/node_modules/undici-types/mock-agent.d.ts +68 -0
  824. package/vendor/ink/node_modules/undici-types/mock-call-history.d.ts +111 -0
  825. package/vendor/ink/node_modules/undici-types/mock-client.d.ts +27 -0
  826. package/vendor/ink/node_modules/undici-types/mock-errors.d.ts +12 -0
  827. package/vendor/ink/node_modules/undici-types/mock-interceptor.d.ts +94 -0
  828. package/vendor/ink/node_modules/undici-types/mock-pool.d.ts +27 -0
  829. package/vendor/ink/node_modules/undici-types/package.json +55 -0
  830. package/vendor/ink/node_modules/undici-types/patch.d.ts +29 -0
  831. package/vendor/ink/node_modules/undici-types/pool-stats.d.ts +19 -0
  832. package/vendor/ink/node_modules/undici-types/pool.d.ts +41 -0
  833. package/vendor/ink/node_modules/undici-types/proxy-agent.d.ts +29 -0
  834. package/vendor/ink/node_modules/undici-types/readable.d.ts +68 -0
  835. package/vendor/ink/node_modules/undici-types/retry-agent.d.ts +8 -0
  836. package/vendor/ink/node_modules/undici-types/retry-handler.d.ts +125 -0
  837. package/vendor/ink/node_modules/undici-types/round-robin-pool.d.ts +41 -0
  838. package/vendor/ink/node_modules/undici-types/snapshot-agent.d.ts +109 -0
  839. package/vendor/ink/node_modules/undici-types/util.d.ts +18 -0
  840. package/vendor/ink/node_modules/undici-types/utility.d.ts +7 -0
  841. package/vendor/ink/node_modules/undici-types/webidl.d.ts +341 -0
  842. package/vendor/ink/node_modules/undici-types/websocket.d.ts +186 -0
  843. package/vendor/ink/package.json +201 -0
  844. package/vendor/ink/readme.md +2636 -0
  845. package/bin/swag-agent.js +0 -9
  846. package/dist/server/lib/pg-rate-limiter.d.ts +0 -21
  847. package/dist/server/lib/pg-rate-limiter.js +0 -86
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-tools.js","names":["createClient","writeFileSync","readFileSync","mkdirSync","join","tmpdir","resolveConfig","getValidToken","createAuthenticatedClient","formatServerResponse","executionContext","setServerToolContext","ctx","cachedClient","cachedStoreId","cachedAuthMethod","cachedToken","getSupabaseClient","config","supabaseUrl","supabaseKey","client","storeId","auth","persistSession","autoRefreshToken","token","resetServerToolClient","connectionVerified","loadedTools","loadedToolNames","clear","toolsLoadedAt","checkConnection","conn","error","from","select","limit","Set","TOOL_CACHE_TTL","loadServerToolDefinitions","force","length","Date","now","data","eq","neq","console","message","map","t","name","description","definition","input_schema","type","properties","tool","add","err","isServerTool","has","getAllServerToolDefinitions","getServerStatus","loadConfig","tools","connected","store_id","storeName","store_name","toolCount","authMethod","MEDIA_FIELDS","audio_base64","ext","label","stems_zip_base64","MEDIA_TOOLS","downloadSingleMedia","toolName","outDir","inputArgs","fileUrl","file_url","startsWith","text","prompt","substring","replace","toLowerCase","action","format","urlPath","URL","pathname","urlExt","split","pop","ts","nameParts","String","filter","Boolean","filename","localPath","resp","fetch","ok","download_error","status","buffer","Buffer","arrayBuffer","local_file","file_size","download","downloadRemoteMedia","process","cwd","Array","isArray","images","img","previews","preview","extractMediaToFiles","dirCreated","field","Object","entries","b64","recursive","filePath","i","audio_file","executeServerTool","input","emitter","serverUrl","success","output","authToken","serverArgs","file_paths","file_path","paths","MAX_TOTAL_BYTES","MAX_SINGLE_FILE","samples","totalBytes","p","buf","isPVC","subarray","maxTotal","push","toString","_fp","_f","rest","audio_samples","reference_audio_base64","test","MAX_FILE_SIZE","MAX_BATCH_BYTES","MAX_BATCH_COUNT","toFixed","_fps","base64","file_name","basename","files","errors","slice","_read_errors","undefined","_fu","image_path","image_url","imgPath","_ip","_iu","image_base64","attachments","rawAtts","hasLocalFiles","some","a","url","processed","att","content","_a","local_path","_lp","encoding","path","isStreamable","response","method","headers","body","JSON","stringify","mode","tool_name","args","trace_id","traceId","conversation_id","conversationId","userId","userEmail","source","catch","reader","getReader","decoder","TextDecoder","finalResult","done","value","read","decode","stream","newlineIdx","indexOf","line","trim","parsed","parse","progress","emitToolOutput","emitToolProgress","remaining","result","json","dataObj","SAFETY_MAX_SERVER_CHARS","toLocaleString","errorMsg","nested"],"sources":["../../../src/cli/services/server-tools.ts"],"sourcesContent":["/**\n * Server Tools — loaded dynamically from ai_tool_registry\n *\n * Single source of truth: the database. Same as the MCP server (index.ts).\n * No hardcoded definitions. Tools are cached for 60s after first load.\n *\n * Execution: proxied to the Fly.io server or Supabase edge function (mode: \"tool\").\n * All business logic lives server-side — CLI is a thin client.\n * Claude formats the JSON results for the user (no client-side formatter).\n */\n\nimport { createClient, type SupabaseClient } from \"@supabase/supabase-js\";\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport { writeFileSync, readFileSync, mkdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { tmpdir } from \"node:os\";\n// Note: extractMediaToFiles below is a fallback for any tools that still return\n// base64 media. The voice handler now uploads to Supabase Storage and returns\n// file_url instead, but this remains for backwards compatibility.\nimport { resolveConfig } from \"./config-store.js\";\nimport { getValidToken, createAuthenticatedClient } from \"./auth-service.js\";\nimport { formatServerResponse } from \"./format-server-response.js\";\nimport type { AgentEventEmitter } from \"./agent-events.js\";\nimport { ToolResult } from \"../../shared/types.js\";\nexport type { ToolResult };\n\n// ============================================================================\n// EXECUTION CONTEXT — set by agent-loop before tool dispatch\n// Provides trace + user identity for server-side telemetry correlation.\n// ============================================================================\n\ninterface ToolExecutionContext {\n traceId?: string;\n conversationId?: string;\n userId?: string;\n userEmail?: string;\n source?: string;\n}\n\nlet executionContext: ToolExecutionContext = {};\n\n/**\n * Set the execution context for server tool calls.\n * Called by agent-loop.ts before each turn so tool calls carry trace/user identity.\n */\nexport function setServerToolContext(ctx: ToolExecutionContext): void {\n executionContext = ctx;\n}\n\nexport interface ServerStatus {\n connected: boolean;\n storeId: string;\n storeName: string;\n toolCount: number;\n authMethod: \"service_role\" | \"jwt\" | \"none\";\n}\n\n// ============================================================================\n// SUPABASE CLIENT (tiered: service role > user JWT)\n// Used only for loading tool definitions from ai_tool_registry.\n// Tool execution goes through the edge function.\n// ============================================================================\n\nlet cachedClient: SupabaseClient | null = null;\nlet cachedStoreId: string = \"\";\nlet cachedAuthMethod: \"service_role\" | \"jwt\" | \"none\" = \"none\";\nlet cachedToken: string = \"\";\n\nasync function getSupabaseClient(): Promise<{ client: SupabaseClient; storeId: string } | null> {\n const config = resolveConfig();\n\n // Tier 1: Service role key (full access, MCP server mode) — never expires\n if (config.supabaseUrl && config.supabaseKey) {\n if (cachedClient && cachedAuthMethod === \"service_role\") {\n return { client: cachedClient, storeId: cachedStoreId };\n }\n cachedClient = createClient(config.supabaseUrl, config.supabaseKey, {\n auth: { persistSession: false, autoRefreshToken: false },\n });\n cachedStoreId = config.storeId || \"\";\n cachedAuthMethod = \"service_role\";\n return { client: cachedClient, storeId: cachedStoreId };\n }\n\n // Tier 2: User JWT (CLI login) — recreate client when token refreshes\n const token = await getValidToken();\n if (token) {\n if (cachedClient && cachedToken === token) {\n cachedStoreId = config.storeId || \"\";\n return { client: cachedClient, storeId: cachedStoreId };\n }\n cachedClient = createAuthenticatedClient(token);\n cachedToken = token;\n cachedStoreId = config.storeId || \"\";\n cachedAuthMethod = \"jwt\";\n return { client: cachedClient, storeId: cachedStoreId };\n }\n\n cachedClient = null;\n cachedToken = \"\";\n cachedAuthMethod = \"none\";\n return null;\n}\n\nexport function resetServerToolClient(): void {\n cachedClient = null;\n cachedStoreId = \"\";\n cachedToken = \"\";\n cachedAuthMethod = \"none\";\n connectionVerified = false;\n // Also clear tool cache so next load fetches fresh\n loadedTools = [];\n loadedToolNames.clear();\n toolsLoadedAt = 0;\n}\n\n// ============================================================================\n// CONNECTION CHECK\n// ============================================================================\n\nlet connectionVerified = false;\n\nexport async function checkConnection(): Promise<boolean> {\n if (connectionVerified) return true;\n\n const conn = await getSupabaseClient();\n if (!conn) return false;\n\n try {\n // Quick health check — query a small table\n const { error } = await conn.client.from(\"stores\").select(\"id\").limit(1);\n connectionVerified = !error;\n return connectionVerified;\n } catch {\n return false;\n }\n}\n\n// ============================================================================\n// TOOL DEFINITIONS — loaded from ai_tool_registry (single source of truth)\n// ============================================================================\n\nlet loadedTools: Anthropic.Tool[] = [];\nlet loadedToolNames = new Set<string>();\nlet toolsLoadedAt = 0;\nconst TOOL_CACHE_TTL = 60_000; // 1 minute\n\n/**\n * Load server tool definitions from ai_tool_registry.\n * Same query as the MCP server (index.ts). Cached for 60s.\n * Filters out tool_mode='code' (those are local CLI tools).\n */\nexport async function loadServerToolDefinitions(force = false): Promise<Anthropic.Tool[]> {\n // Return cache if fresh\n if (!force && loadedTools.length > 0 && Date.now() - toolsLoadedAt < TOOL_CACHE_TTL) {\n return loadedTools;\n }\n\n const conn = await getSupabaseClient();\n if (!conn) return [];\n\n try {\n const { data, error } = await conn.client\n .from(\"ai_tool_registry\")\n .select(\"name, description, definition\")\n .eq(\"is_active\", true)\n .neq(\"tool_mode\", \"code\");\n\n if (error) {\n console.error(\"[server-tools] Failed to load from ai_tool_registry:\", error.message);\n return loadedTools; // Return stale cache on error\n }\n\n loadedTools = (data || []).map(t => ({\n name: t.name,\n description: t.description || t.definition?.description || `Execute ${t.name}`,\n input_schema: t.definition?.input_schema || { type: \"object\" as const, properties: {} },\n }));\n\n // Rebuild the name set\n loadedToolNames.clear();\n for (const tool of loadedTools) {\n loadedToolNames.add(tool.name);\n }\n\n toolsLoadedAt = Date.now();\n connectionVerified = true;\n\n return loadedTools;\n } catch (err) {\n console.error(\"[server-tools] Error loading tool definitions:\", err);\n return loadedTools;\n }\n}\n\n/**\n * Check if a tool name is a server tool.\n * After first load, checks against the dynamically loaded set.\n */\nexport function isServerTool(name: string): boolean {\n return loadedToolNames.has(name);\n}\n\n/**\n * Get currently loaded definitions (for /tools listing).\n * Returns whatever is cached — call loadServerToolDefinitions() first to populate.\n */\nexport function getAllServerToolDefinitions(): Anthropic.Tool[] {\n return loadedTools;\n}\n\n// ============================================================================\n// SERVER STATUS\n// ============================================================================\n\nexport async function getServerStatus(): Promise<ServerStatus> {\n const { loadConfig } = await import(\"./config-store.js\");\n const config = loadConfig();\n\n // Loading tools also verifies connection\n const tools = await loadServerToolDefinitions();\n return {\n connected: tools.length > 0,\n storeId: config.store_id || \"\",\n storeName: config.store_name || \"\",\n toolCount: tools.length,\n authMethod: cachedAuthMethod,\n };\n}\n\n// ============================================================================\n// EXECUTE SERVER TOOL — proxied to edge function\n// ============================================================================\n\n/** Media fields that contain base64-encoded binary data */\nconst MEDIA_FIELDS: Record<string, { ext: string; label: string }> = {\n audio_base64: { ext: \"mp3\", label: \"audio\" },\n stems_zip_base64: { ext: \"zip\", label: \"stems\" },\n};\n\n/** Tools that produce downloadable media files via file_url */\nconst MEDIA_TOOLS = new Set([\"voice\", \"image_gen\", \"video_gen\"]);\n\n/**\n * Download a single file_url to a local path, replacing the URL in the data.\n * inputArgs is the original tool call args — used to derive descriptive filenames\n * when the result data doesn't include the text/prompt.\n */\nasync function downloadSingleMedia(data: Record<string, unknown>, toolName: string, outDir: string, inputArgs?: Record<string, unknown>): Promise<void> {\n const fileUrl = data.file_url;\n if (typeof fileUrl !== \"string\" || !fileUrl.startsWith(\"http\")) return;\n\n // Derive a descriptive filename\n // Check result data first, then fall back to input args for text/prompt\n let label = \"\";\n const text = (data.prompt || data.text || inputArgs?.text || inputArgs?.prompt) as string | undefined;\n if (text) {\n label = text.substring(0, 40).replace(/[^a-zA-Z0-9]+/g, \"-\").replace(/-+$/, \"\").toLowerCase();\n }\n const action = (data.action as string) || (inputArgs?.action as string) || toolName;\n // Detect format: explicit field > file extension from URL > tool-based default\n let format = data.format as string | undefined;\n if (!format) {\n try {\n const urlPath = new URL(fileUrl).pathname;\n const urlExt = urlPath.split(\".\").pop();\n if (urlExt && urlExt.length <= 4) format = urlExt;\n } catch { /* invalid URL — use default */ }\n }\n if (!format) format = toolName === \"image_gen\" ? \"png\" : toolName === \"video_gen\" ? \"mp4\" : \"mp3\";\n const ts = Date.now();\n const nameParts = [action, label, String(ts)].filter(Boolean);\n const filename = `${nameParts.join(\"-\")}.${format}`;\n const localPath = join(outDir, filename);\n\n try {\n const resp = await fetch(fileUrl);\n if (!resp.ok) {\n data.download_error = `Failed to download: HTTP ${resp.status}`;\n return;\n }\n const buffer = Buffer.from(await resp.arrayBuffer());\n writeFileSync(localPath, buffer);\n\n // Keep file_url for downstream tools (email, workflows) that need public URLs\n data.local_file = localPath;\n data.file_size = buffer.length;\n delete data.download;\n } catch (err: any) {\n data.download_error = `Download failed: ${err.message || err}`;\n }\n}\n\n/**\n * Download remote media (file_url) to the user's working directory.\n * This ensures the LLM never needs to handle URLs — it just reports local paths.\n * Prevents the hallucinated-URL problem where models fabricate wrong download URLs.\n *\n * Handles both single results (file_url at top level) and batch results\n * (file_url inside images[] or previews[] arrays).\n */\nasync function downloadRemoteMedia(data: Record<string, unknown>, toolName: string, inputArgs?: Record<string, unknown>): Promise<void> {\n // Save to cwd — the user's working directory, not a hidden temp folder\n const outDir = process.cwd();\n\n // Single file at top level (voice speak, image_gen generate, etc.)\n if (typeof data.file_url === \"string\" && data.file_url.startsWith(\"http\")) {\n await downloadSingleMedia(data, toolName, outDir, inputArgs);\n }\n\n // Batch arrays — image_gen batch returns images[], voice_design returns previews[]\n if (Array.isArray(data.images)) {\n for (const img of data.images) {\n if (img && typeof img === \"object\" && typeof (img as any).file_url === \"string\") {\n await downloadSingleMedia(img as Record<string, unknown>, toolName, outDir);\n }\n }\n }\n if (Array.isArray(data.previews)) {\n for (const preview of data.previews) {\n if (preview && typeof preview === \"object\" && typeof (preview as any).file_url === \"string\") {\n await downloadSingleMedia(preview as Record<string, unknown>, toolName, outDir);\n }\n }\n }\n}\n\n/**\n * Extract base64 media from tool results, save to temp files, and replace\n * with file paths. This prevents truncation from destroying binary data\n * that the model needs to save for the user.\n */\nfunction extractMediaToFiles(data: Record<string, unknown>, toolName: string): void {\n const outDir = join(tmpdir(), \"whale-audio\");\n let dirCreated = false;\n\n for (const [field, { ext, label }] of Object.entries(MEDIA_FIELDS)) {\n const b64 = data[field];\n if (typeof b64 !== \"string\" || b64.length < 100) continue;\n\n if (!dirCreated) {\n mkdirSync(outDir, { recursive: true });\n dirCreated = true;\n }\n\n const ts = Date.now();\n const filename = `${toolName}-${label}-${ts}.${ext}`;\n const filePath = join(outDir, filename);\n\n try {\n writeFileSync(filePath, Buffer.from(b64, \"base64\"));\n // Replace base64 with file path so model can reference it\n data[field] = `(saved to ${filePath})`;\n data[`${label}_file`] = filePath;\n } catch {\n // Leave original data if write fails\n }\n }\n\n // Handle voice_design previews array\n if (Array.isArray(data.previews)) {\n if (!dirCreated) {\n mkdirSync(outDir, { recursive: true });\n }\n for (let i = 0; i < data.previews.length; i++) {\n const preview = data.previews[i] as Record<string, unknown> | undefined;\n if (!preview?.audio_base64 || typeof preview.audio_base64 !== \"string\") continue;\n const ts = Date.now();\n const filePath = join(outDir, `${toolName}-preview-${i}-${ts}.mp3`);\n try {\n writeFileSync(filePath, Buffer.from(preview.audio_base64 as string, \"base64\"));\n preview.audio_base64 = `(saved to ${filePath})`;\n preview.audio_file = filePath;\n } catch {\n // Leave original\n }\n }\n }\n}\n\n/**\n * Execute a server tool via the Fly.io server or Supabase edge function (mode: \"tool\").\n * Returns the raw JSON — Claude formats it for the user.\n * No client-side formatting: the model is the presentation layer.\n *\n * For tools that support live progress (kali exec), uses `mode: \"tool_stream\"` with NDJSON\n * and emits `tool_output` events via the optional emitter for real-time CLI rendering.\n */\nexport async function executeServerTool(\n name: string,\n input: Record<string, unknown>,\n emitter?: AgentEventEmitter,\n): Promise<ToolResult> {\n const config = resolveConfig();\n if (!config.serverUrl) {\n return { success: false, output: \"No server URL configured — server tools unavailable.\" };\n }\n\n // Auth token: service role key preferred, user JWT fallback\n let authToken = config.supabaseKey;\n if (!authToken) {\n authToken = await getValidToken() || \"\";\n }\n if (!authToken) {\n return { success: false, output: \"No auth token — server tools unavailable. Run: whale login\" };\n }\n\n // ── Pre-process file_paths for voice tool ──\n // Reads local files and base64-encodes them so the LLM never handles binary data.\n // CRITICAL: We must NOT mutate `input` — the agent loop keeps a reference to it\n // in the conversation history. If we inject base64 into `input`, it leaks into\n // the LLM context and blows the 200K token limit.\n let serverArgs: Record<string, unknown> = input;\n\n if (name === \"voice\" && (input.file_paths || input.file_path)) {\n let paths: string[] = [];\n if (Array.isArray(input.file_paths)) {\n paths = input.file_paths as string[];\n } else if (typeof input.file_path === \"string\") {\n paths = [input.file_path as string];\n }\n\n const MAX_TOTAL_BYTES = 7_000_000; // 7MB raw = ~9.3MB base64, under 10MB server limit\n const MAX_SINGLE_FILE = 2_000_000; // 2MB per file (~2 min at 128kbps) — enough for good clone\n const samples: string[] = [];\n let totalBytes = 0;\n for (const p of paths) {\n try {\n let buf = readFileSync(p);\n // IVC: trim to 2MB per file. PVC: no trim (needs 30+ min for best quality)\n const isPVC = input.action === \"pvc_upload\";\n if (!isPVC && buf.length > MAX_SINGLE_FILE) {\n buf = buf.subarray(0, MAX_SINGLE_FILE);\n }\n totalBytes += buf.length;\n const maxTotal = isPVC ? 25_000_000 : MAX_TOTAL_BYTES;\n if (totalBytes > maxTotal) break; // use what we have\n samples.push(buf.toString(\"base64\"));\n } catch (err: any) {\n // Skip unreadable files instead of killing the entire batch\n continue;\n }\n }\n if (samples.length === 0) {\n return { success: false, output: \"No valid audio files found in the provided paths.\" };\n }\n\n // Build a SEPARATE args object for the server — never touch `input`\n const { file_paths: _fp, file_path: _f, ...rest } = input;\n serverArgs = { ...rest };\n if (input.action === \"clone_voice\" || input.action === \"pvc_upload\") {\n serverArgs.audio_samples = samples;\n } else if (input.action === \"voice_design\") {\n serverArgs.reference_audio_base64 = samples[0];\n } else {\n serverArgs.audio_base64 = samples[0];\n }\n }\n\n // ── Pre-process file_path(s) for media upload tool ──\n // Same pattern as voice: read local files in-process so base64 never flows\n // through shell output (which truncates at ~100K chars) or conversation context.\n // Also intercept file_url that's actually a local path (agents confuse the two).\n if (name === \"media\" && (input.action === \"upload\" || input.action === \"bulk_upload\")) {\n const fileUrl = input.file_url as string | undefined;\n if (fileUrl && (fileUrl.startsWith(\"/\") || /^[A-Z]:\\\\/i.test(fileUrl)) && !input.file_path && !input.file_paths) {\n input = { ...input, file_path: fileUrl };\n delete (input as any).file_url;\n }\n }\n if (name === \"media\" && (input.action === \"upload\" || input.action === \"bulk_upload\") && (input.file_path || input.file_paths)) {\n let paths: string[] = [];\n if (Array.isArray(input.file_paths)) {\n paths = input.file_paths as string[];\n } else if (typeof input.file_path === \"string\") {\n paths = [input.file_path as string];\n }\n\n if (paths.length > 0) {\n const MAX_FILE_SIZE = 10_000_000; // 10MB per file\n const MAX_BATCH_BYTES = 50_000_000; // 50MB total batch\n const MAX_BATCH_COUNT = 50;\n\n if (paths.length === 1) {\n // ── Single file → standard upload action ──\n const filePath = paths[0];\n try {\n const buf = readFileSync(filePath);\n if (buf.length > MAX_FILE_SIZE) {\n return { success: false, output: `File too large: ${(buf.length / 1_000_000).toFixed(1)}MB (max 10MB). Compress or resize first.` };\n }\n const { file_path: _fp, file_paths: _fps, ...rest } = input;\n serverArgs = { ...rest, action: \"upload\", base64: buf.toString(\"base64\") };\n if (!serverArgs.file_name) {\n const basename = filePath.split(\"/\").pop() || filePath.split(\"\\\\\").pop() || \"\";\n if (basename) serverArgs.file_name = basename;\n }\n } catch (err: any) {\n return { success: false, output: `Cannot read file \"${filePath}\": ${err.message || err}` };\n }\n } else {\n // ── Multiple files → bulk_upload action ──\n const files: { base64: string; file_name: string }[] = [];\n const errors: string[] = [];\n let totalBytes = 0;\n\n for (const filePath of paths.slice(0, MAX_BATCH_COUNT)) {\n try {\n const buf = readFileSync(filePath);\n if (buf.length > MAX_FILE_SIZE) {\n errors.push(`${filePath.split(\"/\").pop()}: ${(buf.length / 1_000_000).toFixed(1)}MB exceeds 10MB limit, skipped`);\n continue;\n }\n totalBytes += buf.length;\n if (totalBytes > MAX_BATCH_BYTES) {\n errors.push(`Batch limit reached (50MB) — remaining files skipped`);\n break;\n }\n const basename = filePath.split(\"/\").pop() || filePath.split(\"\\\\\").pop() || \"file\";\n files.push({ base64: buf.toString(\"base64\"), file_name: basename });\n } catch (err: any) {\n errors.push(`${filePath.split(\"/\").pop()}: ${err.message || \"unreadable\"}`);\n }\n }\n if (paths.length > MAX_BATCH_COUNT) {\n errors.push(`Only first ${MAX_BATCH_COUNT} files processed (${paths.length} provided)`);\n }\n\n if (files.length === 0) {\n return { success: false, output: `No valid files to upload. Errors:\\n${errors.join(\"\\n\")}` };\n }\n\n const { file_path: _fp, file_paths: _fps, ...rest } = input;\n serverArgs = { ...rest, action: \"bulk_upload\", files, _read_errors: errors.length > 0 ? errors : undefined };\n }\n }\n }\n\n // ── Pre-process file_path for media replace tool ──\n // Same pattern as upload: read local file in-process, base64-encode for server.\n if (name === \"media\" && input.action === \"replace\" && (input.file_path || (typeof input.file_url === \"string\" && (input.file_url as string).startsWith(\"/\")))) {\n const localPath = (input.file_path || input.file_url) as string;\n try {\n const buf = readFileSync(localPath);\n if (buf.length > 10_000_000) {\n return { success: false, output: `File too large: ${(buf.length / 1_000_000).toFixed(1)}MB (max 10MB). Compress or resize first.` };\n }\n const { file_path: _fp, file_url: _fu, ...rest } = input;\n serverArgs = { ...rest, base64: buf.toString(\"base64\") };\n if (!serverArgs.file_name) {\n const basename = localPath.split(\"/\").pop() || localPath.split(\"\\\\\").pop() || \"\";\n if (basename) serverArgs.file_name = basename;\n }\n } catch (err: any) {\n return { success: false, output: `Cannot read file \"${localPath}\": ${err.message || err}` };\n }\n }\n\n // ── Pre-process image_path for remove_bg tool ──\n // Same pattern: read local image, send as image_base64.\n if (name === \"remove_bg\" && (input.image_path || (typeof input.image_url === \"string\" && (input.image_url as string).startsWith(\"/\")))) {\n const imgPath = (input.image_path || input.image_url) as string;\n try {\n const buf = readFileSync(imgPath);\n if (buf.length > 10_000_000) {\n return { success: false, output: `Image too large: ${(buf.length / 1_000_000).toFixed(1)}MB (max 10MB).` };\n }\n const { image_path: _ip, image_url: _iu, ...rest } = input;\n serverArgs = { ...rest, image_base64: buf.toString(\"base64\") };\n } catch (err: any) {\n return { success: false, output: `Cannot read image \"${imgPath}\": ${err.message || err}` };\n }\n }\n\n // ── Pre-process file_path in email attachments ──\n // Reads local files referenced in attachments[].file_path, converts to base64 content.\n if (name === \"email\" && input.action === \"send\" && Array.isArray(input.attachments)) {\n const rawAtts = input.attachments as { file_path?: string; url?: string; filename?: string; content?: string }[];\n const hasLocalFiles = rawAtts.some(a => a.file_path || (typeof a.url === \"string\" && a.url.startsWith(\"/\")));\n if (hasLocalFiles) {\n const processed: { filename: string; content: string }[] = [];\n for (const att of rawAtts) {\n const localPath = att.file_path || (typeof att.url === \"string\" && att.url.startsWith(\"/\") ? att.url : null);\n if (localPath) {\n try {\n const buf = readFileSync(localPath);\n if (buf.length > 10_000_000) {\n return { success: false, output: `Attachment too large: ${localPath.split(\"/\").pop()} is ${(buf.length / 1_000_000).toFixed(1)}MB (max 10MB).` };\n }\n const filename = att.filename || localPath.split(\"/\").pop() || \"attachment\";\n processed.push({ filename, content: buf.toString(\"base64\") });\n } catch (err: any) {\n return { success: false, output: `Cannot read attachment \"${localPath}\": ${err.message || err}` };\n }\n } else if (att.content && att.filename) {\n processed.push({ filename: att.filename, content: att.content });\n } else if (att.url && att.filename) {\n processed.push(att as any); // URL-based, let server fetch it\n }\n }\n const { attachments: _a, ...rest } = input;\n serverArgs = { ...rest, attachments: processed };\n }\n }\n\n // ── Pre-process file_path for kali upload ──\n // Reads local file and sends content as base64 to the kali box.\n if (name === \"kali\" && input.action === \"upload\" && (input.file_path || input.local_path)) {\n const localPath = (input.file_path || input.local_path) as string;\n if (localPath && !input.content) {\n try {\n const buf = readFileSync(localPath);\n if (buf.length > 50_000_000) {\n return { success: false, output: `File too large for kali upload: ${(buf.length / 1_000_000).toFixed(1)}MB (max 50MB).` };\n }\n const { file_path: _fp, local_path: _lp, ...rest } = input;\n serverArgs = { ...rest, content: buf.toString(\"base64\"), encoding: \"base64\" };\n // Auto-set remote path from filename if not provided\n if (!serverArgs.path) {\n const basename = localPath.split(\"/\").pop() || \"upload\";\n serverArgs.path = `/tmp/${basename}`;\n }\n } catch (err: any) {\n return { success: false, output: `Cannot read file \"${localPath}\": ${err.message || err}` };\n }\n }\n }\n\n // ── Streaming path for kali exec actions ──\n // Uses NDJSON streaming to show live stdout/stderr in the CLI while the command runs.\n const isStreamable = name === \"kali\" && emitter &&\n (input.action === \"exec\" || input.action === \"exec_stream\");\n\n if (isStreamable) {\n try {\n const serverUrl = config.serverUrl;\n const response = await fetch(serverUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Authorization\": `Bearer ${authToken}`,\n },\n body: JSON.stringify({\n mode: \"tool_stream\",\n tool_name: name,\n args: serverArgs,\n store_id: config.storeId || undefined,\n trace_id: executionContext.traceId || undefined,\n conversation_id: executionContext.conversationId || undefined,\n userId: executionContext.userId || undefined,\n userEmail: executionContext.userEmail || undefined,\n source: executionContext.source || \"whale-code\",\n }),\n });\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\");\n return { success: false, output: `Server tool stream error: HTTP ${response.status}: ${text.substring(0, 500)}` };\n }\n\n if (!response.body) {\n return { success: false, output: \"Server returned no response body for tool_stream\" };\n }\n\n // Read NDJSON stream — emit progress events, collect final result\n const reader = (response.body as any).getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n let finalResult: { success: boolean; data?: unknown; error?: string } | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n\n let newlineIdx: number;\n while ((newlineIdx = buffer.indexOf(\"\\n\")) !== -1) {\n const line = buffer.substring(0, newlineIdx).trim();\n buffer = buffer.substring(newlineIdx + 1);\n if (!line) continue;\n try {\n const parsed = JSON.parse(line);\n if (parsed.type === \"progress\" && parsed.progress) {\n const p = parsed.progress as { type?: string; data?: string };\n if ((p.type === \"stdout\" || p.type === \"stderr\") && p.data) {\n emitter.emitToolOutput(name, p.data);\n }\n } else if (parsed.type === \"status\" && parsed.progress) {\n emitter.emitToolProgress(name, parsed.progress);\n } else if (parsed.type === \"result\") {\n finalResult = parsed;\n }\n } catch { /* skip malformed lines */ }\n }\n }\n\n // Process remaining buffer\n const remaining = buffer.trim();\n if (remaining) {\n try {\n const parsed = JSON.parse(remaining);\n if (parsed.type === \"result\") finalResult = parsed;\n } catch { /* skip */ }\n }\n\n if (finalResult) {\n if (finalResult.success && finalResult.data) {\n const output = typeof finalResult.data === \"string\"\n ? finalResult.data\n : formatServerResponse(finalResult.data, name);\n return { success: true, output };\n }\n return { success: false, output: finalResult.error || `Server tool \"${name}\" returned success=false` };\n }\n\n return { success: false, output: \"No result received from streaming tool execution\" };\n } catch (err: any) {\n return { success: false, output: `Server tool stream error: ${err.message || err}` };\n }\n }\n\n // ── Standard path: non-streaming tools ──\n try {\n const serverUrl = config.serverUrl;\n const response = await fetch(serverUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Authorization\": `Bearer ${authToken}`,\n },\n body: JSON.stringify({\n mode: \"tool\",\n tool_name: name,\n args: serverArgs,\n store_id: config.storeId || undefined,\n trace_id: executionContext.traceId || undefined,\n conversation_id: executionContext.conversationId || undefined,\n userId: executionContext.userId || undefined,\n userEmail: executionContext.userEmail || undefined,\n source: executionContext.source || \"whale-code\",\n }),\n });\n\n const result = await response.json() as { success: boolean; data?: unknown; error?: string };\n\n if (result.success) {\n if (result.data && typeof result.data === \"object\") {\n const dataObj = result.data as Record<string, unknown>;\n // Auto-download remote media files to local temp paths\n if (MEDIA_TOOLS.has(name)) {\n await downloadRemoteMedia(dataObj, name, input);\n }\n // Legacy: extract base64 media to temp files\n extractMediaToFiles(dataObj, name);\n }\n\n let output = typeof result.data === \"string\"\n ? result.data\n : formatServerResponse(result.data, name);\n\n // Safety cap only — Anthropic context_management handles normal limits.\n // Old limit was 30K which caused constant truncation and extra tool calls.\n const SAFETY_MAX_SERVER_CHARS = 500_000;\n if (output.length > SAFETY_MAX_SERVER_CHARS) {\n output = output.slice(0, SAFETY_MAX_SERVER_CHARS)\n + `\\n\\n... (safety truncated — ${output.length.toLocaleString()} chars total)`;\n }\n return { success: true, output };\n }\n\n // Extract error from nested data if top-level error is missing\n let errorMsg = result.error;\n if (!errorMsg && result.data && typeof result.data === \"object\") {\n const nested = (result.data as Record<string, unknown>).error;\n if (typeof nested === \"string\") errorMsg = nested;\n }\n return { success: false, output: errorMsg || `Server tool \"${name}\" returned success=false with no error message` };\n } catch (err: any) {\n return { success: false, output: `Server tool error: ${err.message || err}` };\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,QAA6B,uBAAuB;AAEzE,SAASC,aAAa,EAAEC,YAAY,EAAEC,SAAS,QAAQ,SAAS;AAChE,SAASC,IAAI,QAAQ,WAAW;AAChC,SAASC,MAAM,QAAQ,SAAS;AAChC;AACA;AACA;AACA,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,aAAa,EAAEC,yBAAyB,QAAQ,mBAAmB;AAC5E,SAASC,oBAAoB,QAAQ,6BAA6B;;AAKlE;AACA;AACA;AACA;;AAUA,IAAIC,gBAAsC,GAAG,CAAC,CAAC;;AAE/C;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAACC,GAAyB,EAAQ;EACpEF,gBAAgB,GAAGE,GAAG;AACxB;AAUA;AACA;AACA;AACA;AACA;;AAEA,IAAIC,YAAmC,GAAG,IAAI;AAC9C,IAAIC,aAAqB,GAAG,EAAE;AAC9B,IAAIC,gBAAiD,GAAG,MAAM;AAC9D,IAAIC,WAAmB,GAAG,EAAE;AAE5B,eAAeC,iBAAiBA,CAAA,EAAgE;EAC9F,MAAMC,MAAM,GAAGZ,aAAa,CAAC,CAAC;;EAE9B;EACA,IAAIY,MAAM,CAACC,WAAW,IAAID,MAAM,CAACE,WAAW,EAAE;IAC5C,IAAIP,YAAY,IAAIE,gBAAgB,KAAK,cAAc,EAAE;MACvD,OAAO;QAAEM,MAAM,EAAER,YAAY;QAAES,OAAO,EAAER;MAAc,CAAC;IACzD;IACAD,YAAY,GAAGb,YAAY,CAACkB,MAAM,CAACC,WAAW,EAAED,MAAM,CAACE,WAAW,EAAE;MAClEG,IAAI,EAAE;QAAEC,cAAc,EAA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M,EAAEoG,QAAQ,IAAI,gBAAgB7L,IAAI;IAAiD,CAAC;EACrH,CAAC,CAAC,OAAOQ,GAAQ,EAAE;IACjB,OAAO;MAAEgF,OAAO,EAAE,KAAK;MAAEC,MAAM,EAAE,sBAAsBjF,GAAG,CAACX,OAAO,IAAIW,GAAG;IAAG,CAAC;EAC/E;AACF","ignoreList":[]}
@@ -4,96 +4,91 @@
4
4
  * Extracted from agent-loop.ts for single-responsibility.
5
5
  * All consumers should import from agent-loop.ts (re-export facade).
6
6
  */
7
+
7
8
  import { readFileSync, existsSync, mkdirSync, writeFileSync, readdirSync, appendFileSync } from "fs";
8
9
  import { join } from "path";
9
- import { homedir } from "os";
10
10
  import { getModel } from "./model-manager.js";
11
- const SESSIONS_DIR = join(homedir(), ".swagmanager", "sessions");
11
+ import { SESSIONS_DIR, APP_DATA_DIR, ensureDataDir } from "./paths.js";
12
12
  function ensureSessionsDir() {
13
- if (!existsSync(SESSIONS_DIR))
14
- mkdirSync(SESSIONS_DIR, { recursive: true });
13
+ ensureDataDir();
14
+ if (!existsSync(SESSIONS_DIR)) mkdirSync(SESSIONS_DIR, {
15
+ recursive: true
16
+ });
15
17
  }
16
18
  export function saveSession(messages, sessionId) {
17
- ensureSessionsDir();
18
- const id = sessionId || `session-${Date.now()}`;
19
- const meta = {
20
- id,
21
- title: extractSessionTitle(messages),
22
- model: getModel(),
23
- messageCount: messages.length,
24
- createdAt: new Date().toISOString(),
25
- updatedAt: new Date().toISOString(),
26
- cwd: process.cwd(),
27
- };
28
- const data = JSON.stringify({ meta, messages }, null, 2);
29
- writeFileSync(join(SESSIONS_DIR, `${id}.json`), data, "utf-8");
30
- logSessionHistory(meta);
31
- return id;
19
+ ensureSessionsDir();
20
+ const id = sessionId || `session-${Date.now()}`;
21
+ const meta = {
22
+ id,
23
+ title: extractSessionTitle(messages),
24
+ model: getModel(),
25
+ messageCount: messages.length,
26
+ createdAt: new Date().toISOString(),
27
+ updatedAt: new Date().toISOString(),
28
+ cwd: process.cwd()
29
+ };
30
+ const data = JSON.stringify({
31
+ meta,
32
+ messages
33
+ }, null, 2);
34
+ writeFileSync(join(SESSIONS_DIR, `${id}.json`), data, "utf-8");
35
+ logSessionHistory(meta);
36
+ return id;
32
37
  }
33
38
  export function loadSession(sessionId) {
34
- const path = join(SESSIONS_DIR, `${sessionId}.json`);
35
- if (!existsSync(path))
36
- return null;
37
- try {
38
- return JSON.parse(readFileSync(path, "utf-8"));
39
- }
40
- catch {
41
- return null;
42
- }
39
+ const path = join(SESSIONS_DIR, `${sessionId}.json`);
40
+ if (!existsSync(path)) return null;
41
+ try {
42
+ return JSON.parse(readFileSync(path, "utf-8"));
43
+ } catch {
44
+ return null;
45
+ }
43
46
  }
44
47
  export function listSessions(limit = 20) {
45
- ensureSessionsDir();
46
- const files = readdirSync(SESSIONS_DIR)
47
- .filter((f) => f.endsWith(".json"))
48
- .sort()
49
- .reverse()
50
- .slice(0, limit);
51
- const sessions = [];
52
- for (const f of files) {
53
- try {
54
- const data = JSON.parse(readFileSync(join(SESSIONS_DIR, f), "utf-8"));
55
- if (data.meta)
56
- sessions.push(data.meta);
57
- }
58
- catch { /* skip corrupted */ }
59
- }
60
- return sessions;
48
+ ensureSessionsDir();
49
+ const files = readdirSync(SESSIONS_DIR).filter(f => f.endsWith(".json")).sort().reverse().slice(0, limit);
50
+ const sessions = [];
51
+ for (const f of files) {
52
+ try {
53
+ const data = JSON.parse(readFileSync(join(SESSIONS_DIR, f), "utf-8"));
54
+ if (data.meta) sessions.push(data.meta);
55
+ } catch {/* skip corrupted */}
56
+ }
57
+ return sessions;
61
58
  }
62
- const HISTORY_FILE = join(homedir(), ".swagmanager", "history.jsonl");
59
+ const HISTORY_FILE = join(APP_DATA_DIR, "history.jsonl");
63
60
  function logSessionHistory(meta) {
64
- try {
65
- const dir = join(homedir(), ".swagmanager");
66
- if (!existsSync(dir))
67
- mkdirSync(dir, { recursive: true });
68
- const entry = {
69
- display: meta.title,
70
- project: meta.cwd || process.cwd(),
71
- timestamp: meta.updatedAt,
72
- sessionId: meta.id,
73
- model: meta.model,
74
- };
75
- appendFileSync(HISTORY_FILE, JSON.stringify(entry) + "\n");
76
- }
77
- catch { /* best effort */ }
61
+ try {
62
+ ensureDataDir();
63
+ const entry = {
64
+ display: meta.title,
65
+ project: meta.cwd || process.cwd(),
66
+ timestamp: meta.updatedAt,
67
+ sessionId: meta.id,
68
+ model: meta.model
69
+ };
70
+ appendFileSync(HISTORY_FILE, JSON.stringify(entry) + "\n");
71
+ } catch {/* best effort */}
78
72
  }
79
73
  export function findLatestSessionForCwd() {
80
- const cwd = process.cwd();
81
- const sessions = listSessions(100);
82
- return sessions.find(s => s.cwd === cwd) || null;
74
+ const cwd = process.cwd();
75
+ const sessions = listSessions(100);
76
+ return sessions.find(s => s.cwd === cwd) || null;
83
77
  }
84
78
  function extractSessionTitle(messages) {
85
- // Use first user message as title (truncated)
86
- for (const m of messages) {
87
- if (m.role === "user" && typeof m.content === "string") {
88
- return m.content.slice(0, 60) + (m.content.length > 60 ? "..." : "");
89
- }
90
- if (m.role === "user" && Array.isArray(m.content)) {
91
- for (const block of m.content) {
92
- if ("text" in block && typeof block.text === "string") {
93
- return block.text.slice(0, 60) + (block.text.length > 60 ? "..." : "");
94
- }
95
- }
79
+ // Use first user message as title (truncated)
80
+ for (const m of messages) {
81
+ if (m.role === "user" && typeof m.content === "string") {
82
+ return m.content.slice(0, 60) + (m.content.length > 60 ? "..." : "");
83
+ }
84
+ if (m.role === "user" && Array.isArray(m.content)) {
85
+ for (const block of m.content) {
86
+ if ("text" in block && typeof block.text === "string") {
87
+ return block.text.slice(0, 60) + (block.text.length > 60 ? "..." : "");
96
88
  }
89
+ }
97
90
  }
98
- return "Untitled session";
91
+ }
92
+ return "Untitled session";
99
93
  }
94
+ //# sourceMappingURL=session-persistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-persistence.js","names":["readFileSync","existsSync","mkdirSync","writeFileSync","readdirSync","appendFileSync","join","getModel","SESSIONS_DIR","APP_DATA_DIR","ensureDataDir","ensureSessionsDir","recursive","saveSession","messages","sessionId","id","Date","now","meta","title","extractSessionTitle","model","messageCount","length","createdAt","toISOString","updatedAt","cwd","process","data","JSON","stringify","logSessionHistory","loadSession","path","parse","listSessions","limit","files","filter","f","endsWith","sort","reverse","slice","sessions","push","HISTORY_FILE","entry","display","project","timestamp","findLatestSessionForCwd","find","s","m","role","content","Array","isArray","block","text"],"sources":["../../../src/cli/services/session-persistence.ts"],"sourcesContent":["/**\n * Session Persistence — save/load conversations to disk\n *\n * Extracted from agent-loop.ts for single-responsibility.\n * All consumers should import from agent-loop.ts (re-export facade).\n */\n\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport { readFileSync, existsSync, mkdirSync, writeFileSync, readdirSync, appendFileSync } from \"fs\";\nimport { join } from \"path\";\nimport { getModel } from \"./model-manager.js\";\nimport { SESSIONS_DIR, APP_DATA_DIR, ensureDataDir } from \"./paths.js\";\n\nfunction ensureSessionsDir(): void {\n ensureDataDir();\n if (!existsSync(SESSIONS_DIR)) mkdirSync(SESSIONS_DIR, { recursive: true });\n}\n\nexport interface SessionMeta {\n id: string;\n title: string;\n model: string;\n messageCount: number;\n createdAt: string;\n updatedAt: string;\n cwd?: string;\n}\n\nexport function saveSession(\n messages: Anthropic.MessageParam[],\n sessionId?: string\n): string {\n ensureSessionsDir();\n const id = sessionId || `session-${Date.now()}`;\n const meta: SessionMeta = {\n id,\n title: extractSessionTitle(messages),\n model: getModel(),\n messageCount: messages.length,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n cwd: process.cwd(),\n };\n const data = JSON.stringify({ meta, messages }, null, 2);\n writeFileSync(join(SESSIONS_DIR, `${id}.json`), data, \"utf-8\");\n logSessionHistory(meta);\n return id;\n}\n\nexport function loadSession(sessionId: string): { meta: SessionMeta; messages: Anthropic.MessageParam[] } | null {\n const path = join(SESSIONS_DIR, `${sessionId}.json`);\n if (!existsSync(path)) return null;\n try {\n return JSON.parse(readFileSync(path, \"utf-8\"));\n } catch { return null; }\n}\n\nexport function listSessions(limit = 20): SessionMeta[] {\n ensureSessionsDir();\n const files = readdirSync(SESSIONS_DIR)\n .filter((f) => f.endsWith(\".json\"))\n .sort()\n .reverse()\n .slice(0, limit);\n const sessions: SessionMeta[] = [];\n for (const f of files) {\n try {\n const data = JSON.parse(readFileSync(join(SESSIONS_DIR, f), \"utf-8\"));\n if (data.meta) sessions.push(data.meta);\n } catch { /* skip corrupted */ }\n }\n return sessions;\n}\n\nconst HISTORY_FILE = join(APP_DATA_DIR, \"history.jsonl\");\n\nfunction logSessionHistory(meta: SessionMeta): void {\n try {\n ensureDataDir();\n const entry = {\n display: meta.title,\n project: meta.cwd || process.cwd(),\n timestamp: meta.updatedAt,\n sessionId: meta.id,\n model: meta.model,\n };\n appendFileSync(HISTORY_FILE, JSON.stringify(entry) + \"\\n\");\n } catch { /* best effort */ }\n}\n\nexport function findLatestSessionForCwd(): SessionMeta | null {\n const cwd = process.cwd();\n const sessions = listSessions(100);\n return sessions.find(s => s.cwd === cwd) || null;\n}\n\nfunction extractSessionTitle(messages: Anthropic.MessageParam[]): string {\n // Use first user message as title (truncated)\n for (const m of messages) {\n if (m.role === \"user\" && typeof m.content === \"string\") {\n return m.content.slice(0, 60) + (m.content.length > 60 ? \"...\" : \"\");\n }\n if (m.role === \"user\" && Array.isArray(m.content)) {\n for (const block of m.content) {\n if (\"text\" in block && typeof block.text === \"string\") {\n return block.text.slice(0, 60) + (block.text.length > 60 ? \"...\" : \"\");\n }\n }\n }\n }\n return \"Untitled session\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,YAAY,EAAEC,UAAU,EAAEC,SAAS,EAAEC,aAAa,EAAEC,WAAW,EAAEC,cAAc,QAAQ,IAAI;AACpG,SAASC,IAAI,QAAQ,MAAM;AAC3B,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,YAAY,EAAEC,YAAY,EAAEC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I) responsive. Results are posted back via parentPort.
8
8
  */
9
+
9
10
  import { parentPort, workerData } from "worker_threads";
10
11
  import { runSubagent } from "./subagent.js";
11
12
  async function main() {
12
- if (!parentPort) {
13
- console.error("subagent-worker must be run as a worker thread");
14
- process.exit(1);
15
- }
16
- const { options, index } = workerData;
17
- // Send progress updates (optional, for debugging)
18
- const reportProgress = (msg) => {
19
- parentPort.postMessage({ type: "progress", index, message: msg });
13
+ if (!parentPort) {
14
+ console.error("subagent-worker must be run as a worker thread");
15
+ process.exit(1);
16
+ }
17
+ const {
18
+ options,
19
+ index
20
+ } = workerData;
21
+
22
+ // Send progress updates (optional, for debugging)
23
+ const reportProgress = msg => {
24
+ parentPort.postMessage({
25
+ type: "progress",
26
+ index,
27
+ message: msg
28
+ });
29
+ };
30
+ try {
31
+ reportProgress(`Starting ${options.subagent_type} subagent...`);
32
+ const result = await runSubagent(options);
33
+ reportProgress(`Completed ${options.subagent_type} subagent`);
34
+ const response = {
35
+ success: true,
36
+ index,
37
+ result
20
38
  };
21
- try {
22
- reportProgress(`Starting ${options.subagent_type} subagent...`);
23
- const result = await runSubagent(options);
24
- reportProgress(`Completed ${options.subagent_type} subagent`);
25
- const response = {
26
- success: true,
27
- index,
28
- result,
29
- };
30
- parentPort.postMessage({ type: "result", ...response });
31
- }
32
- catch (err) {
33
- const response = {
34
- success: false,
35
- index,
36
- error: err.message || String(err),
37
- };
38
- parentPort.postMessage({ type: "result", ...response });
39
- }
39
+ parentPort.postMessage({
40
+ type: "result",
41
+ ...response
42
+ });
43
+ } catch (err) {
44
+ const response = {
45
+ success: false,
46
+ index,
47
+ error: err.message || String(err)
48
+ };
49
+ parentPort.postMessage({
50
+ type: "result",
51
+ ...response
52
+ });
53
+ }
40
54
  }
41
55
  main();
56
+ //# sourceMappingURL=subagent-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subagent-worker.js","names":["parentPort","workerData","runSubagent","main","console","error","process","exit","options","index","reportProgress","msg","postMessage","type","message","subagent_type","result","response","success","err","String"],"sources":["../../../src/cli/services/subagent-worker.ts"],"sourcesContent":["/**\n * Subagent Worker — runs in separate thread to not block UI\n *\n * Usage: Spawned by parallel_tasks via worker_threads\n *\n * This worker runs `runSubagent()` in isolation, keeping the main thread\n * (and Ink UI) responsive. Results are posted back via parentPort.\n */\n\nimport { parentPort, workerData } from \"worker_threads\";\nimport { runSubagent, type SubagentOptions, type SubagentResult } from \"./subagent.js\";\n\nexport interface WorkerData {\n options: SubagentOptions;\n index: number; // Task index for result ordering\n}\n\nexport interface WorkerResult {\n success: boolean;\n index: number;\n result?: SubagentResult;\n error?: string;\n}\n\nasync function main() {\n if (!parentPort) {\n console.error(\"subagent-worker must be run as a worker thread\");\n process.exit(1);\n }\n\n const { options, index } = workerData as WorkerData;\n\n // Send progress updates (optional, for debugging)\n const reportProgress = (msg: string) => {\n parentPort!.postMessage({ type: \"progress\", index, message: msg });\n };\n\n try {\n reportProgress(`Starting ${options.subagent_type} subagent...`);\n\n const result = await runSubagent(options);\n\n reportProgress(`Completed ${options.subagent_type} subagent`);\n\n const response: WorkerResult = {\n success: true,\n index,\n result,\n };\n parentPort.postMessage({ type: \"result\", ...response });\n } catch (err: any) {\n const response: WorkerResult = {\n success: false,\n index,\n error: err.message || String(err),\n };\n parentPort.postMessage({ type: \"result\", ...response });\n }\n}\n\nmain();\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,UAAU,EAAEC,UAAU,QAAQ,gBAAgB;AACvD,SAASC,WAAW,QAAmD,eAAe;AActF,eAAeC,IAAIA,CAAA,EAAG;EACpB,IAAI,CAACH,UAAU,EAAE;IACfI,OAAO,CAACC,KAAK,CAAC,gDAAgD,CAAC;IAC/DC,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC;EACjB;EAEA,MAAM;IAAEC,OAAO;IAAEC;EAAM,CAAC,GAAGR,UAAwB;;EAEnD;EACA,MAAMS,cAAc,GAAIC,GAAW,IAAK;IACtCX,UAAU,CAAEY,WAAW,CAAC;MAAEC,IAAI,EAAE,UAAU;MAAEJ,KAAK;MAAEK,OAAO,EAAEH;IAAI,CAAC,CAAC;EACpE,CAAC;EAED,IAAI;IACFD,cAAc,CAAC,YAAYF,OAAO,CAACO,aAAa,cAAc,CAAC;IAE/D,MAAMC,MAAM,GAAG,MAAMd,WAAW,CAACM,OAAO,CAAC;IAEzCE,cAAc,CAAC,aAAaF,OAAO,CAACO,aAAa,WAAW,CAAC;IAE7D,MAAME,QAAsB,GAAG;MAC7BC,OAAO,EAAE,IAAI;MACbT,KAAK;MACLO;IACF,CAAC;IACDhB,UAAU,CAACY,WAAW,CAAC;MAAEC,IAAI,EAAE,QAAQ;MAAE,GAAGI;IAAS,CAAC,CAAC;EACzD,CAAC,CAAC,OAAOE,GAAQ,EAAE;IACjB,MAAMF,QAAsB,GAAG;MAC7BC,OAAO,EAAE,KAAK;MACdT,KAAK;MACLJ,KAAK,EAAEc,GAAG,CAACL,OAAO,IAAIM,MAAM,CAACD,GAAG;IAClC,CAAC;IACDnB,UAAU,CAACY,WAAW,CAAC;MAAEC,IAAI,EAAE,QAAQ;MAAE,GAAGI;IAAS,CAAC,CAAC;EACzD;AACF;AAEAd,IAAI,CAAC,CAAC","ignoreList":[]}
@@ -28,6 +28,8 @@ export interface SubagentOptions {
28
28
  name?: string;
29
29
  parentContext?: string;
30
30
  parentTraceContext?: ParentTraceContext;
31
+ taskContext?: string;
32
+ signal?: AbortSignal;
31
33
  }
32
34
  export interface SubagentResult {
33
35
  success: boolean;