snow-ai 0.4.16 → 0.4.18

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 (352) hide show
  1. package/bundle/cli.mjs +477445 -0
  2. package/bundle/sql-wasm.wasm +0 -0
  3. package/bundle/tiktoken_bg.wasm +0 -0
  4. package/package.json +31 -26
  5. package/dist/agents/codebaseIndexAgent.d.ts +0 -102
  6. package/dist/agents/codebaseIndexAgent.js +0 -641
  7. package/dist/agents/codebaseReviewAgent.d.ts +0 -61
  8. package/dist/agents/codebaseReviewAgent.js +0 -301
  9. package/dist/agents/compactAgent.d.ts +0 -55
  10. package/dist/agents/compactAgent.js +0 -306
  11. package/dist/agents/promptOptimizeAgent.d.ts +0 -54
  12. package/dist/agents/promptOptimizeAgent.js +0 -268
  13. package/dist/agents/reviewAgent.d.ts +0 -50
  14. package/dist/agents/reviewAgent.js +0 -265
  15. package/dist/agents/summaryAgent.d.ts +0 -57
  16. package/dist/agents/summaryAgent.js +0 -260
  17. package/dist/api/anthropic.d.ts +0 -44
  18. package/dist/api/anthropic.js +0 -598
  19. package/dist/api/chat.d.ts +0 -73
  20. package/dist/api/chat.js +0 -386
  21. package/dist/api/embedding.d.ts +0 -34
  22. package/dist/api/embedding.js +0 -80
  23. package/dist/api/gemini.d.ts +0 -31
  24. package/dist/api/gemini.js +0 -445
  25. package/dist/api/models.d.ts +0 -15
  26. package/dist/api/models.js +0 -139
  27. package/dist/api/responses.d.ts +0 -38
  28. package/dist/api/responses.js +0 -515
  29. package/dist/api/systemPrompt.d.ts +0 -4
  30. package/dist/api/systemPrompt.js +0 -408
  31. package/dist/api/types.d.ts +0 -53
  32. package/dist/api/types.js +0 -4
  33. package/dist/app.d.ts +0 -8
  34. package/dist/app.js +0 -112
  35. package/dist/cli.d.ts +0 -2
  36. package/dist/cli.js +0 -199
  37. package/dist/hooks/useAgentPicker.d.ts +0 -14
  38. package/dist/hooks/useAgentPicker.js +0 -119
  39. package/dist/hooks/useClipboard.d.ts +0 -4
  40. package/dist/hooks/useClipboard.js +0 -175
  41. package/dist/hooks/useCommandHandler.d.ts +0 -35
  42. package/dist/hooks/useCommandHandler.js +0 -346
  43. package/dist/hooks/useCommandPanel.d.ts +0 -17
  44. package/dist/hooks/useCommandPanel.js +0 -114
  45. package/dist/hooks/useConversation.d.ts +0 -49
  46. package/dist/hooks/useConversation.js +0 -1052
  47. package/dist/hooks/useFilePicker.d.ts +0 -18
  48. package/dist/hooks/useFilePicker.js +0 -224
  49. package/dist/hooks/useGlobalExit.d.ts +0 -5
  50. package/dist/hooks/useGlobalExit.js +0 -34
  51. package/dist/hooks/useGlobalNavigation.d.ts +0 -6
  52. package/dist/hooks/useGlobalNavigation.js +0 -17
  53. package/dist/hooks/useHistoryNavigation.d.ts +0 -35
  54. package/dist/hooks/useHistoryNavigation.js +0 -133
  55. package/dist/hooks/useInputBuffer.d.ts +0 -6
  56. package/dist/hooks/useInputBuffer.js +0 -45
  57. package/dist/hooks/useKeyboardInput.d.ts +0 -80
  58. package/dist/hooks/useKeyboardInput.js +0 -608
  59. package/dist/hooks/useSessionManagement.d.ts +0 -10
  60. package/dist/hooks/useSessionManagement.js +0 -43
  61. package/dist/hooks/useSessionSave.d.ts +0 -8
  62. package/dist/hooks/useSessionSave.js +0 -63
  63. package/dist/hooks/useSnapshotState.d.ts +0 -26
  64. package/dist/hooks/useSnapshotState.js +0 -28
  65. package/dist/hooks/useStreamingState.d.ts +0 -33
  66. package/dist/hooks/useStreamingState.js +0 -105
  67. package/dist/hooks/useTerminalFocus.d.ts +0 -28
  68. package/dist/hooks/useTerminalFocus.js +0 -87
  69. package/dist/hooks/useTerminalSize.d.ts +0 -4
  70. package/dist/hooks/useTerminalSize.js +0 -20
  71. package/dist/hooks/useTodoPicker.d.ts +0 -16
  72. package/dist/hooks/useTodoPicker.js +0 -94
  73. package/dist/hooks/useToolConfirmation.d.ts +0 -19
  74. package/dist/hooks/useToolConfirmation.js +0 -61
  75. package/dist/hooks/useVSCodeState.d.ts +0 -8
  76. package/dist/hooks/useVSCodeState.js +0 -81
  77. package/dist/i18n/I18nContext.d.ts +0 -14
  78. package/dist/i18n/I18nContext.js +0 -24
  79. package/dist/i18n/index.d.ts +0 -3
  80. package/dist/i18n/index.js +0 -2
  81. package/dist/i18n/lang/en.d.ts +0 -2
  82. package/dist/i18n/lang/en.js +0 -502
  83. package/dist/i18n/lang/es.d.ts +0 -2
  84. package/dist/i18n/lang/es.js +0 -502
  85. package/dist/i18n/lang/ja.d.ts +0 -2
  86. package/dist/i18n/lang/ja.js +0 -502
  87. package/dist/i18n/lang/ko.d.ts +0 -2
  88. package/dist/i18n/lang/ko.js +0 -502
  89. package/dist/i18n/lang/zh-TW.d.ts +0 -2
  90. package/dist/i18n/lang/zh-TW.js +0 -502
  91. package/dist/i18n/lang/zh.d.ts +0 -2
  92. package/dist/i18n/lang/zh.js +0 -502
  93. package/dist/i18n/translations.d.ts +0 -2
  94. package/dist/i18n/translations.js +0 -14
  95. package/dist/i18n/types.d.ts +0 -478
  96. package/dist/i18n/types.js +0 -1
  97. package/dist/mcp/aceCodeSearch.d.ts +0 -247
  98. package/dist/mcp/aceCodeSearch.js +0 -1058
  99. package/dist/mcp/bash.d.ts +0 -50
  100. package/dist/mcp/bash.js +0 -153
  101. package/dist/mcp/codebaseSearch.d.ts +0 -44
  102. package/dist/mcp/codebaseSearch.js +0 -275
  103. package/dist/mcp/filesystem.d.ts +0 -392
  104. package/dist/mcp/filesystem.js +0 -1445
  105. package/dist/mcp/ideDiagnostics.d.ts +0 -36
  106. package/dist/mcp/ideDiagnostics.js +0 -90
  107. package/dist/mcp/notebook.d.ts +0 -10
  108. package/dist/mcp/notebook.js +0 -367
  109. package/dist/mcp/subagent.d.ts +0 -37
  110. package/dist/mcp/subagent.js +0 -113
  111. package/dist/mcp/todo.d.ts +0 -46
  112. package/dist/mcp/todo.js +0 -511
  113. package/dist/mcp/types/aceCodeSearch.types.d.ts +0 -92
  114. package/dist/mcp/types/aceCodeSearch.types.js +0 -4
  115. package/dist/mcp/types/bash.types.d.ts +0 -13
  116. package/dist/mcp/types/bash.types.js +0 -4
  117. package/dist/mcp/types/filesystem.types.d.ts +0 -210
  118. package/dist/mcp/types/filesystem.types.js +0 -27
  119. package/dist/mcp/types/todo.types.d.ts +0 -27
  120. package/dist/mcp/types/todo.types.js +0 -4
  121. package/dist/mcp/types/websearch.types.d.ts +0 -30
  122. package/dist/mcp/types/websearch.types.js +0 -4
  123. package/dist/mcp/utils/aceCodeSearch/filesystem.utils.d.ts +0 -34
  124. package/dist/mcp/utils/aceCodeSearch/filesystem.utils.js +0 -146
  125. package/dist/mcp/utils/aceCodeSearch/language.utils.d.ts +0 -14
  126. package/dist/mcp/utils/aceCodeSearch/language.utils.js +0 -418
  127. package/dist/mcp/utils/aceCodeSearch/search.utils.d.ts +0 -31
  128. package/dist/mcp/utils/aceCodeSearch/search.utils.js +0 -136
  129. package/dist/mcp/utils/aceCodeSearch/symbol.utils.d.ts +0 -20
  130. package/dist/mcp/utils/aceCodeSearch/symbol.utils.js +0 -141
  131. package/dist/mcp/utils/bash/security.utils.d.ts +0 -20
  132. package/dist/mcp/utils/bash/security.utils.js +0 -34
  133. package/dist/mcp/utils/filesystem/batch-operations.utils.d.ts +0 -39
  134. package/dist/mcp/utils/filesystem/batch-operations.utils.js +0 -182
  135. package/dist/mcp/utils/filesystem/code-analysis.utils.d.ts +0 -18
  136. package/dist/mcp/utils/filesystem/code-analysis.utils.js +0 -165
  137. package/dist/mcp/utils/filesystem/match-finder.utils.d.ts +0 -16
  138. package/dist/mcp/utils/filesystem/match-finder.utils.js +0 -85
  139. package/dist/mcp/utils/filesystem/office-parser.utils.d.ts +0 -43
  140. package/dist/mcp/utils/filesystem/office-parser.utils.js +0 -163
  141. package/dist/mcp/utils/filesystem/path-fixer.utils.d.ts +0 -7
  142. package/dist/mcp/utils/filesystem/path-fixer.utils.js +0 -60
  143. package/dist/mcp/utils/filesystem/similarity.utils.d.ts +0 -22
  144. package/dist/mcp/utils/filesystem/similarity.utils.js +0 -75
  145. package/dist/mcp/utils/todo/date.utils.d.ts +0 -9
  146. package/dist/mcp/utils/todo/date.utils.js +0 -14
  147. package/dist/mcp/utils/websearch/browser.utils.d.ts +0 -8
  148. package/dist/mcp/utils/websearch/browser.utils.js +0 -58
  149. package/dist/mcp/utils/websearch/text.utils.d.ts +0 -16
  150. package/dist/mcp/utils/websearch/text.utils.js +0 -39
  151. package/dist/mcp/websearch.d.ts +0 -88
  152. package/dist/mcp/websearch.js +0 -375
  153. package/dist/test/logger-test.d.ts +0 -1
  154. package/dist/test/logger-test.js +0 -7
  155. package/dist/types/index.d.ts +0 -15
  156. package/dist/types/index.js +0 -1
  157. package/dist/ui/components/AgentPickerPanel.d.ts +0 -10
  158. package/dist/ui/components/AgentPickerPanel.js +0 -74
  159. package/dist/ui/components/ChatInput.d.ts +0 -46
  160. package/dist/ui/components/ChatInput.js +0 -384
  161. package/dist/ui/components/CommandPanel.d.ts +0 -15
  162. package/dist/ui/components/CommandPanel.js +0 -80
  163. package/dist/ui/components/DiffViewer.d.ts +0 -11
  164. package/dist/ui/components/DiffViewer.js +0 -178
  165. package/dist/ui/components/FileList.d.ts +0 -15
  166. package/dist/ui/components/FileList.js +0 -360
  167. package/dist/ui/components/FileRollbackConfirmation.d.ts +0 -8
  168. package/dist/ui/components/FileRollbackConfirmation.js +0 -108
  169. package/dist/ui/components/HelpPanel.d.ts +0 -2
  170. package/dist/ui/components/HelpPanel.js +0 -67
  171. package/dist/ui/components/MCPInfoPanel.d.ts +0 -2
  172. package/dist/ui/components/MCPInfoPanel.js +0 -108
  173. package/dist/ui/components/MCPInfoScreen.d.ts +0 -7
  174. package/dist/ui/components/MCPInfoScreen.js +0 -115
  175. package/dist/ui/components/MarkdownRenderer.d.ts +0 -6
  176. package/dist/ui/components/MarkdownRenderer.js +0 -70
  177. package/dist/ui/components/Menu.d.ts +0 -17
  178. package/dist/ui/components/Menu.js +0 -88
  179. package/dist/ui/components/MessageList.d.ts +0 -56
  180. package/dist/ui/components/MessageList.js +0 -97
  181. package/dist/ui/components/PendingMessages.d.ts +0 -13
  182. package/dist/ui/components/PendingMessages.js +0 -29
  183. package/dist/ui/components/PendingToolCalls.d.ts +0 -11
  184. package/dist/ui/components/PendingToolCalls.js +0 -35
  185. package/dist/ui/components/ScrollableSelectInput.d.ts +0 -29
  186. package/dist/ui/components/ScrollableSelectInput.js +0 -157
  187. package/dist/ui/components/SessionListPanel.d.ts +0 -7
  188. package/dist/ui/components/SessionListPanel.js +0 -175
  189. package/dist/ui/components/SessionListScreen.d.ts +0 -7
  190. package/dist/ui/components/SessionListScreen.js +0 -217
  191. package/dist/ui/components/SessionListScreenWrapper.d.ts +0 -7
  192. package/dist/ui/components/SessionListScreenWrapper.js +0 -14
  193. package/dist/ui/components/ShimmerText.d.ts +0 -9
  194. package/dist/ui/components/ShimmerText.js +0 -30
  195. package/dist/ui/components/TodoPickerPanel.d.ts +0 -14
  196. package/dist/ui/components/TodoPickerPanel.js +0 -119
  197. package/dist/ui/components/TodoTree.d.ts +0 -15
  198. package/dist/ui/components/TodoTree.js +0 -60
  199. package/dist/ui/components/ToolConfirmation.d.ts +0 -21
  200. package/dist/ui/components/ToolConfirmation.js +0 -204
  201. package/dist/ui/components/ToolResultPreview.d.ts +0 -13
  202. package/dist/ui/components/ToolResultPreview.js +0 -337
  203. package/dist/ui/components/UsagePanel.d.ts +0 -2
  204. package/dist/ui/components/UsagePanel.js +0 -394
  205. package/dist/ui/contexts/ThemeContext.d.ts +0 -13
  206. package/dist/ui/contexts/ThemeContext.js +0 -28
  207. package/dist/ui/pages/ChatScreen.d.ts +0 -6
  208. package/dist/ui/pages/ChatScreen.js +0 -1519
  209. package/dist/ui/pages/CodeBaseConfigScreen.d.ts +0 -8
  210. package/dist/ui/pages/CodeBaseConfigScreen.js +0 -350
  211. package/dist/ui/pages/ConfigScreen.d.ts +0 -8
  212. package/dist/ui/pages/ConfigScreen.js +0 -1101
  213. package/dist/ui/pages/CustomHeadersScreen.d.ts +0 -6
  214. package/dist/ui/pages/CustomHeadersScreen.js +0 -502
  215. package/dist/ui/pages/HeadlessModeScreen.d.ts +0 -7
  216. package/dist/ui/pages/HeadlessModeScreen.js +0 -381
  217. package/dist/ui/pages/LanguageSettingsScreen.d.ts +0 -7
  218. package/dist/ui/pages/LanguageSettingsScreen.js +0 -91
  219. package/dist/ui/pages/MCPConfigScreen.d.ts +0 -6
  220. package/dist/ui/pages/MCPConfigScreen.js +0 -55
  221. package/dist/ui/pages/ProxyConfigScreen.d.ts +0 -8
  222. package/dist/ui/pages/ProxyConfigScreen.js +0 -149
  223. package/dist/ui/pages/SensitiveCommandConfigScreen.d.ts +0 -7
  224. package/dist/ui/pages/SensitiveCommandConfigScreen.js +0 -271
  225. package/dist/ui/pages/SubAgentConfigScreen.d.ts +0 -9
  226. package/dist/ui/pages/SubAgentConfigScreen.js +0 -435
  227. package/dist/ui/pages/SubAgentListScreen.d.ts +0 -9
  228. package/dist/ui/pages/SubAgentListScreen.js +0 -131
  229. package/dist/ui/pages/SystemPromptConfigScreen.d.ts +0 -6
  230. package/dist/ui/pages/SystemPromptConfigScreen.js +0 -326
  231. package/dist/ui/pages/ThemeSettingsScreen.d.ts +0 -7
  232. package/dist/ui/pages/ThemeSettingsScreen.js +0 -106
  233. package/dist/ui/pages/WelcomeScreen.d.ts +0 -7
  234. package/dist/ui/pages/WelcomeScreen.js +0 -217
  235. package/dist/ui/themes/index.d.ts +0 -23
  236. package/dist/ui/themes/index.js +0 -140
  237. package/dist/utils/apiConfig.d.ts +0 -126
  238. package/dist/utils/apiConfig.js +0 -423
  239. package/dist/utils/autoCompress.d.ts +0 -15
  240. package/dist/utils/autoCompress.js +0 -24
  241. package/dist/utils/chatExporter.d.ts +0 -9
  242. package/dist/utils/chatExporter.js +0 -118
  243. package/dist/utils/checkpointManager.d.ts +0 -74
  244. package/dist/utils/checkpointManager.js +0 -181
  245. package/dist/utils/codebaseConfig.d.ts +0 -16
  246. package/dist/utils/codebaseConfig.js +0 -67
  247. package/dist/utils/codebaseDatabase.d.ts +0 -102
  248. package/dist/utils/codebaseDatabase.js +0 -333
  249. package/dist/utils/codebaseSearchEvents.d.ts +0 -16
  250. package/dist/utils/codebaseSearchEvents.js +0 -13
  251. package/dist/utils/commandExecutor.d.ts +0 -13
  252. package/dist/utils/commandExecutor.js +0 -26
  253. package/dist/utils/commands/agent.d.ts +0 -2
  254. package/dist/utils/commands/agent.js +0 -12
  255. package/dist/utils/commands/clear.d.ts +0 -2
  256. package/dist/utils/commands/clear.js +0 -12
  257. package/dist/utils/commands/compact.d.ts +0 -2
  258. package/dist/utils/commands/compact.js +0 -12
  259. package/dist/utils/commands/export.d.ts +0 -2
  260. package/dist/utils/commands/export.js +0 -12
  261. package/dist/utils/commands/help.d.ts +0 -2
  262. package/dist/utils/commands/help.js +0 -11
  263. package/dist/utils/commands/home.d.ts +0 -2
  264. package/dist/utils/commands/home.js +0 -34
  265. package/dist/utils/commands/ide.d.ts +0 -2
  266. package/dist/utils/commands/ide.js +0 -32
  267. package/dist/utils/commands/init.d.ts +0 -2
  268. package/dist/utils/commands/init.js +0 -93
  269. package/dist/utils/commands/mcp.d.ts +0 -2
  270. package/dist/utils/commands/mcp.js +0 -12
  271. package/dist/utils/commands/resume.d.ts +0 -2
  272. package/dist/utils/commands/resume.js +0 -12
  273. package/dist/utils/commands/review.d.ts +0 -2
  274. package/dist/utils/commands/review.js +0 -81
  275. package/dist/utils/commands/role.d.ts +0 -2
  276. package/dist/utils/commands/role.js +0 -37
  277. package/dist/utils/commands/todoPicker.d.ts +0 -2
  278. package/dist/utils/commands/todoPicker.js +0 -12
  279. package/dist/utils/commands/usage.d.ts +0 -2
  280. package/dist/utils/commands/usage.js +0 -12
  281. package/dist/utils/commands/yolo.d.ts +0 -2
  282. package/dist/utils/commands/yolo.js +0 -12
  283. package/dist/utils/configManager.d.ts +0 -45
  284. package/dist/utils/configManager.js +0 -303
  285. package/dist/utils/contextCompressor.d.ts +0 -16
  286. package/dist/utils/contextCompressor.js +0 -334
  287. package/dist/utils/devMode.d.ts +0 -13
  288. package/dist/utils/devMode.js +0 -54
  289. package/dist/utils/escapeHandler.d.ts +0 -79
  290. package/dist/utils/escapeHandler.js +0 -153
  291. package/dist/utils/fileDialog.d.ts +0 -9
  292. package/dist/utils/fileDialog.js +0 -74
  293. package/dist/utils/fileUtils.d.ts +0 -40
  294. package/dist/utils/fileUtils.js +0 -185
  295. package/dist/utils/historyManager.d.ts +0 -45
  296. package/dist/utils/historyManager.js +0 -159
  297. package/dist/utils/incrementalSnapshot.d.ts +0 -109
  298. package/dist/utils/incrementalSnapshot.js +0 -383
  299. package/dist/utils/index.d.ts +0 -11
  300. package/dist/utils/index.js +0 -18
  301. package/dist/utils/languageConfig.d.ts +0 -21
  302. package/dist/utils/languageConfig.js +0 -61
  303. package/dist/utils/logger.d.ts +0 -37
  304. package/dist/utils/logger.js +0 -122
  305. package/dist/utils/mcpToolsManager.d.ts +0 -52
  306. package/dist/utils/mcpToolsManager.js +0 -878
  307. package/dist/utils/messageFormatter.d.ts +0 -12
  308. package/dist/utils/messageFormatter.js +0 -115
  309. package/dist/utils/notebookManager.d.ts +0 -59
  310. package/dist/utils/notebookManager.js +0 -213
  311. package/dist/utils/patch-highlight.d.ts +0 -5
  312. package/dist/utils/patch-highlight.js +0 -23
  313. package/dist/utils/processManager.d.ts +0 -27
  314. package/dist/utils/processManager.js +0 -75
  315. package/dist/utils/proxyUtils.d.ts +0 -15
  316. package/dist/utils/proxyUtils.js +0 -50
  317. package/dist/utils/resourceMonitor.d.ts +0 -65
  318. package/dist/utils/resourceMonitor.js +0 -175
  319. package/dist/utils/retryUtils.d.ts +0 -49
  320. package/dist/utils/retryUtils.js +0 -303
  321. package/dist/utils/sensitiveCommandManager.d.ts +0 -53
  322. package/dist/utils/sensitiveCommandManager.js +0 -308
  323. package/dist/utils/sessionConverter.d.ts +0 -7
  324. package/dist/utils/sessionConverter.js +0 -306
  325. package/dist/utils/sessionManager.d.ts +0 -53
  326. package/dist/utils/sessionManager.js +0 -371
  327. package/dist/utils/subAgentConfig.d.ts +0 -50
  328. package/dist/utils/subAgentConfig.js +0 -221
  329. package/dist/utils/subAgentExecutor.d.ts +0 -40
  330. package/dist/utils/subAgentExecutor.js +0 -434
  331. package/dist/utils/terminal.d.ts +0 -5
  332. package/dist/utils/terminal.js +0 -13
  333. package/dist/utils/textBuffer.d.ts +0 -99
  334. package/dist/utils/textBuffer.js +0 -547
  335. package/dist/utils/textUtils.d.ts +0 -37
  336. package/dist/utils/textUtils.js +0 -102
  337. package/dist/utils/themeConfig.d.ts +0 -21
  338. package/dist/utils/themeConfig.js +0 -61
  339. package/dist/utils/todoPreprocessor.d.ts +0 -5
  340. package/dist/utils/todoPreprocessor.js +0 -18
  341. package/dist/utils/todoScanner.d.ts +0 -8
  342. package/dist/utils/todoScanner.js +0 -148
  343. package/dist/utils/toolDisplayConfig.d.ts +0 -16
  344. package/dist/utils/toolDisplayConfig.js +0 -47
  345. package/dist/utils/toolExecutor.d.ts +0 -37
  346. package/dist/utils/toolExecutor.js +0 -224
  347. package/dist/utils/usageLogger.d.ts +0 -11
  348. package/dist/utils/usageLogger.js +0 -114
  349. package/dist/utils/vscodeConnection.d.ts +0 -76
  350. package/dist/utils/vscodeConnection.js +0 -430
  351. package/dist/utils/workspaceSnapshot.d.ts +0 -63
  352. package/dist/utils/workspaceSnapshot.js +0 -300
@@ -1,547 +0,0 @@
1
- import { cpLen, cpSlice, visualWidth, toCodePoints } from './textUtils.js';
2
- /**
3
- * Strip characters that can break terminal rendering.
4
- */
5
- function sanitizeInput(str) {
6
- // Replace problematic characters but preserve basic formatting
7
- return (str
8
- .replace(/\r\n/g, '\n') // Normalize line endings
9
- .replace(/\r/g, '\n') // Convert remaining \r to \n
10
- .replace(/\t/g, ' ') // Convert tabs to spaces
11
- // Remove focus events emitted during terminal focus changes
12
- .replace(/\x1b\[[IO]/g, '')
13
- // Remove stray [I/[O] tokens that precede drag-and-drop payloads
14
- .replace(/(^|\s+)\[(?:I|O)(?=(?:\s|$|["'~\\\/]|[A-Za-z]:))/g, '$1')
15
- // Remove control characters except newlines
16
- .replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, ''));
17
- }
18
- export class TextBuffer {
19
- constructor(viewport, onUpdate) {
20
- Object.defineProperty(this, "content", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: ''
25
- });
26
- Object.defineProperty(this, "cursorIndex", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: 0
31
- });
32
- Object.defineProperty(this, "viewport", {
33
- enumerable: true,
34
- configurable: true,
35
- writable: true,
36
- value: void 0
37
- });
38
- Object.defineProperty(this, "placeholderStorage", {
39
- enumerable: true,
40
- configurable: true,
41
- writable: true,
42
- value: new Map()
43
- }); // 统一的占位符存储
44
- Object.defineProperty(this, "textPlaceholderCounter", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: 0
49
- }); // 文本占位符计数器
50
- Object.defineProperty(this, "imagePlaceholderCounter", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: 0
55
- }); // 图片占位符计数器
56
- Object.defineProperty(this, "onUpdateCallback", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: void 0
61
- }); // 更新回调函数
62
- Object.defineProperty(this, "isDestroyed", {
63
- enumerable: true,
64
- configurable: true,
65
- writable: true,
66
- value: false
67
- }); // 标记是否已销毁
68
- Object.defineProperty(this, "tempPastingPlaceholder", {
69
- enumerable: true,
70
- configurable: true,
71
- writable: true,
72
- value: null
73
- }); // 临时"粘贴中"占位符文本
74
- Object.defineProperty(this, "visualLines", {
75
- enumerable: true,
76
- configurable: true,
77
- writable: true,
78
- value: ['']
79
- });
80
- Object.defineProperty(this, "visualLineStarts", {
81
- enumerable: true,
82
- configurable: true,
83
- writable: true,
84
- value: [0]
85
- });
86
- Object.defineProperty(this, "visualCursorPos", {
87
- enumerable: true,
88
- configurable: true,
89
- writable: true,
90
- value: [0, 0]
91
- });
92
- Object.defineProperty(this, "preferredVisualCol", {
93
- enumerable: true,
94
- configurable: true,
95
- writable: true,
96
- value: 0
97
- });
98
- this.viewport = viewport;
99
- this.onUpdateCallback = onUpdate;
100
- this.recalculateVisualState();
101
- }
102
- /**
103
- * Cleanup method to be called when the buffer is no longer needed
104
- */
105
- destroy() {
106
- this.isDestroyed = true;
107
- this.placeholderStorage.clear();
108
- this.onUpdateCallback = undefined;
109
- }
110
- get text() {
111
- return this.content;
112
- }
113
- /**
114
- * 获取完整文本,包括替换占位符为原始内容(仅文本类型)
115
- */
116
- getFullText() {
117
- let fullText = this.content;
118
- for (const placeholder of this.placeholderStorage.values()) {
119
- // 只替换文本类型的占位符
120
- if (placeholder.type === 'text' && placeholder.placeholder) {
121
- fullText = fullText
122
- .split(placeholder.placeholder)
123
- .join(placeholder.content);
124
- }
125
- }
126
- return fullText;
127
- }
128
- get visualCursor() {
129
- return this.visualCursorPos;
130
- }
131
- getCursorPosition() {
132
- return this.cursorIndex;
133
- }
134
- setCursorPosition(position) {
135
- this.cursorIndex = position;
136
- this.clampCursorIndex();
137
- this.recomputeVisualCursorOnly();
138
- }
139
- get viewportVisualLines() {
140
- return this.visualLines;
141
- }
142
- get maxWidth() {
143
- return this.viewport.width;
144
- }
145
- scheduleUpdate() {
146
- // Notify external components of updates
147
- if (!this.isDestroyed && this.onUpdateCallback) {
148
- this.onUpdateCallback();
149
- }
150
- }
151
- setText(text) {
152
- const sanitized = sanitizeInput(text);
153
- this.content = sanitized;
154
- this.clampCursorIndex();
155
- if (sanitized === '') {
156
- this.placeholderStorage.clear();
157
- this.textPlaceholderCounter = 0;
158
- this.imagePlaceholderCounter = 0;
159
- }
160
- this.recalculateVisualState();
161
- this.scheduleUpdate();
162
- }
163
- insert(input) {
164
- const sanitized = sanitizeInput(input);
165
- if (!sanitized) {
166
- return;
167
- }
168
- const charCount = sanitized.length;
169
- // 如果存在临时"粘贴中"占位符,先移除它,并调整光标位置
170
- if (this.tempPastingPlaceholder) {
171
- const placeholderIndex = this.content.indexOf(this.tempPastingPlaceholder);
172
- if (placeholderIndex !== -1) {
173
- // 找到占位符的位置
174
- const placeholderLength = cpLen(this.tempPastingPlaceholder);
175
- // 移除占位符
176
- this.content =
177
- this.content.slice(0, placeholderIndex) +
178
- this.content.slice(placeholderIndex + this.tempPastingPlaceholder.length);
179
- // 调整光标位置:如果光标在占位符之后,需要向前移动
180
- if (this.cursorIndex > placeholderIndex) {
181
- this.cursorIndex = Math.max(placeholderIndex, this.cursorIndex - placeholderLength);
182
- }
183
- }
184
- this.tempPastingPlaceholder = null;
185
- }
186
- // 如果是大文本(>300字符),直接创建占位符
187
- if (charCount > 300) {
188
- this.textPlaceholderCounter++;
189
- const pasteId = `paste_${Date.now()}_${this.textPlaceholderCounter}`;
190
- // 计算行数
191
- const lineCount = (sanitized.match(/\n/g) || []).length + 1;
192
- const placeholderText = `[Paste ${lineCount} lines #${this.textPlaceholderCounter}]`;
193
- this.placeholderStorage.set(pasteId, {
194
- id: pasteId,
195
- type: 'text',
196
- content: sanitized,
197
- charCount: charCount,
198
- index: this.textPlaceholderCounter,
199
- placeholder: placeholderText,
200
- });
201
- // 插入占位符而不是原文本
202
- this.insertPlainText(placeholderText);
203
- }
204
- else {
205
- // 普通输入,直接插入文本
206
- this.insertPlainText(sanitized);
207
- }
208
- this.scheduleUpdate();
209
- }
210
- /**
211
- * 插入临时"粘贴中"占位符,用于大文本粘贴时的用户反馈
212
- */
213
- insertPastingIndicator() {
214
- // 如果已经有临时占位符,不需要重复插入
215
- if (this.tempPastingPlaceholder) {
216
- return;
217
- }
218
- // 创建静态的临时占位符(简单明了)
219
- this.tempPastingPlaceholder = `[Pasting...]`;
220
- this.insertPlainText(this.tempPastingPlaceholder);
221
- this.scheduleUpdate();
222
- }
223
- insertPlainText(text) {
224
- if (!text) {
225
- return;
226
- }
227
- this.clampCursorIndex();
228
- const before = cpSlice(this.content, 0, this.cursorIndex);
229
- const after = cpSlice(this.content, this.cursorIndex);
230
- this.content = before + text + after;
231
- this.cursorIndex += cpLen(text);
232
- this.recalculateVisualState();
233
- }
234
- backspace() {
235
- if (this.cursorIndex === 0) {
236
- return;
237
- }
238
- const before = cpSlice(this.content, 0, this.cursorIndex - 1);
239
- const after = cpSlice(this.content, this.cursorIndex);
240
- this.content = before + after;
241
- this.cursorIndex -= 1;
242
- this.recalculateVisualState();
243
- this.scheduleUpdate();
244
- }
245
- delete() {
246
- if (this.cursorIndex >= cpLen(this.content)) {
247
- return;
248
- }
249
- const before = cpSlice(this.content, 0, this.cursorIndex);
250
- const after = cpSlice(this.content, this.cursorIndex + 1);
251
- this.content = before + after;
252
- this.recalculateVisualState();
253
- this.scheduleUpdate();
254
- }
255
- moveLeft() {
256
- if (this.cursorIndex === 0) {
257
- return;
258
- }
259
- this.cursorIndex -= 1;
260
- this.recomputeVisualCursorOnly();
261
- }
262
- moveRight() {
263
- if (this.cursorIndex >= cpLen(this.content)) {
264
- return;
265
- }
266
- this.cursorIndex += 1;
267
- this.recomputeVisualCursorOnly();
268
- }
269
- moveUp() {
270
- if (this.visualLines.length === 0) {
271
- return;
272
- }
273
- // 检查是否只有单行(没有换行符)
274
- const hasNewline = this.content.includes('\n');
275
- if (!hasNewline && this.visualLines.length === 1) {
276
- // 单行模式:移动到行首
277
- this.cursorIndex = 0;
278
- this.recomputeVisualCursorOnly();
279
- return;
280
- }
281
- const currentRow = this.visualCursorPos[0];
282
- if (currentRow <= 0) {
283
- return;
284
- }
285
- this.moveCursorToVisualRow(currentRow - 1);
286
- }
287
- moveDown() {
288
- if (this.visualLines.length === 0) {
289
- return;
290
- }
291
- // 检查是否只有单行(没有换行符)
292
- const hasNewline = this.content.includes('\n');
293
- if (!hasNewline && this.visualLines.length === 1) {
294
- // 单行模式:移动到行尾
295
- this.cursorIndex = cpLen(this.content);
296
- this.recomputeVisualCursorOnly();
297
- return;
298
- }
299
- const currentRow = this.visualCursorPos[0];
300
- if (currentRow >= this.visualLines.length - 1) {
301
- return;
302
- }
303
- this.moveCursorToVisualRow(currentRow + 1);
304
- }
305
- /**
306
- * Update the viewport dimensions, useful for terminal resize handling.
307
- */
308
- updateViewport(viewport) {
309
- const needsRecalculation = this.viewport.width !== viewport.width ||
310
- this.viewport.height !== viewport.height;
311
- this.viewport = viewport;
312
- if (needsRecalculation) {
313
- this.recalculateVisualState();
314
- this.scheduleUpdate();
315
- }
316
- }
317
- /**
318
- * Get the character and its visual info at cursor position for proper rendering.
319
- */
320
- getCharAtCursor() {
321
- const codePoints = toCodePoints(this.content);
322
- if (this.cursorIndex >= codePoints.length) {
323
- return { char: ' ', isWideChar: false };
324
- }
325
- const char = codePoints[this.cursorIndex] || ' ';
326
- return { char, isWideChar: visualWidth(char) > 1 };
327
- }
328
- clampCursorIndex() {
329
- const length = cpLen(this.content);
330
- if (this.cursorIndex < 0) {
331
- this.cursorIndex = 0;
332
- }
333
- else if (this.cursorIndex > length) {
334
- this.cursorIndex = length;
335
- }
336
- }
337
- recalculateVisualState() {
338
- this.clampCursorIndex();
339
- const width = this.viewport.width;
340
- const effectiveWidth = Number.isFinite(width) && width > 0 ? width : Number.POSITIVE_INFINITY;
341
- const rawLines = this.content.split('\n');
342
- const nextVisualLines = [];
343
- const nextStarts = [];
344
- let cpOffset = 0;
345
- const linesToProcess = rawLines.length > 0 ? rawLines : [''];
346
- for (let i = 0; i < linesToProcess.length; i++) {
347
- const rawLine = linesToProcess[i] ?? '';
348
- const segments = this.wrapLineToWidth(rawLine, effectiveWidth);
349
- if (segments.length === 0) {
350
- nextVisualLines.push('');
351
- nextStarts.push(cpOffset);
352
- }
353
- else {
354
- for (const segment of segments) {
355
- nextVisualLines.push(segment);
356
- nextStarts.push(cpOffset);
357
- cpOffset += cpLen(segment);
358
- }
359
- }
360
- if (i < linesToProcess.length - 1) {
361
- // Account for the newline character that separates raw lines
362
- cpOffset += 1;
363
- }
364
- }
365
- if (nextVisualLines.length === 0) {
366
- nextVisualLines.push('');
367
- nextStarts.push(0);
368
- }
369
- this.visualLines = nextVisualLines;
370
- this.visualLineStarts = nextStarts;
371
- this.visualCursorPos = this.computeVisualCursorFromIndex(this.cursorIndex);
372
- this.preferredVisualCol = this.visualCursorPos[1];
373
- }
374
- wrapLineToWidth(line, width) {
375
- if (line === '') {
376
- return [''];
377
- }
378
- if (!Number.isFinite(width) || width <= 0) {
379
- return [line];
380
- }
381
- const codePoints = toCodePoints(line);
382
- const segments = [];
383
- let start = 0;
384
- // Helper function to find placeholder at given position
385
- const findPlaceholderAt = (pos) => {
386
- // Look backwards to find the opening bracket
387
- let openPos = pos;
388
- while (openPos >= 0 && codePoints[openPos] !== '[') {
389
- openPos--;
390
- }
391
- if (openPos >= 0 && codePoints[openPos] === '[') {
392
- // Look forward to find the closing bracket
393
- let closePos = openPos + 1;
394
- while (closePos < codePoints.length && codePoints[closePos] !== ']') {
395
- closePos++;
396
- }
397
- if (closePos < codePoints.length && codePoints[closePos] === ']') {
398
- const placeholderText = codePoints.slice(openPos, closePos + 1).join('');
399
- // Check if it's a valid placeholder
400
- if (placeholderText.match(/^\[Paste \d+ lines #\d+\]$/) ||
401
- placeholderText.match(/^\[image #\d+\]$/) ||
402
- placeholderText === '[Pasting...]') {
403
- return { start: openPos, end: closePos + 1 };
404
- }
405
- }
406
- }
407
- return null;
408
- };
409
- while (start < codePoints.length) {
410
- let currentWidth = 0;
411
- let end = start;
412
- let lastBreak = -1;
413
- while (end < codePoints.length) {
414
- // Check if current position is start of a placeholder
415
- if (codePoints[end] === '[') {
416
- const placeholder = findPlaceholderAt(end);
417
- if (placeholder && placeholder.start === end) {
418
- const placeholderText = codePoints.slice(placeholder.start, placeholder.end).join('');
419
- const placeholderWidth = Array.from(placeholderText).reduce((sum, c) => sum + visualWidth(c), 0);
420
- // If placeholder fits on current line, include it
421
- if (currentWidth + placeholderWidth <= width) {
422
- currentWidth += placeholderWidth;
423
- end = placeholder.end;
424
- continue;
425
- }
426
- else if (currentWidth === 0) {
427
- // Placeholder doesn't fit but we're at line start, force it on this line
428
- end = placeholder.end;
429
- break;
430
- }
431
- else {
432
- // Placeholder doesn't fit, break before it
433
- break;
434
- }
435
- }
436
- }
437
- const char = codePoints[end] || '';
438
- const charWidth = visualWidth(char);
439
- if (char === ' ') {
440
- lastBreak = end + 1;
441
- }
442
- if (currentWidth + charWidth > width) {
443
- if (lastBreak > start) {
444
- end = lastBreak;
445
- }
446
- break;
447
- }
448
- currentWidth += charWidth;
449
- end++;
450
- }
451
- if (end === start) {
452
- end = Math.min(start + 1, codePoints.length);
453
- }
454
- segments.push(codePoints.slice(start, end).join(''));
455
- start = end;
456
- }
457
- return segments;
458
- }
459
- computeVisualCursorFromIndex(position) {
460
- if (this.visualLines.length === 0) {
461
- return [0, 0];
462
- }
463
- const totalLength = cpLen(this.content);
464
- const clamped = Math.max(0, Math.min(position, totalLength));
465
- for (let i = this.visualLines.length - 1; i >= 0; i--) {
466
- const start = this.visualLineStarts[i] ?? 0;
467
- if (clamped >= start) {
468
- const line = this.visualLines[i] ?? '';
469
- const col = Math.min(cpLen(line), clamped - start);
470
- return [i, col];
471
- }
472
- }
473
- return [0, clamped];
474
- }
475
- moveCursorToVisualRow(targetRow) {
476
- if (this.visualLines.length === 0) {
477
- this.cursorIndex = 0;
478
- this.visualCursorPos = [0, 0];
479
- return;
480
- }
481
- const row = Math.max(0, Math.min(targetRow, this.visualLines.length - 1));
482
- const start = this.visualLineStarts[row] ?? 0;
483
- const line = this.visualLines[row] ?? '';
484
- const lineLength = cpLen(line);
485
- const column = Math.min(this.preferredVisualCol, lineLength);
486
- this.cursorIndex = start + column;
487
- this.visualCursorPos = [row, column];
488
- }
489
- recomputeVisualCursorOnly() {
490
- this.visualCursorPos = this.computeVisualCursorFromIndex(this.cursorIndex);
491
- this.preferredVisualCol = this.visualCursorPos[1];
492
- }
493
- /**
494
- * 插入图片数据(使用统一的占位符系统)
495
- */
496
- insertImage(base64Data, mimeType) {
497
- // 清理 base64 数据:移除所有空白字符(包括换行符)
498
- // PowerShell/macOS 的 base64 编码可能包含换行符
499
- const cleanedBase64 = base64Data.replace(/\s+/g, '');
500
- this.imagePlaceholderCounter++;
501
- const imageId = `image_${Date.now()}_${this.imagePlaceholderCounter}`;
502
- const placeholderText = `[image #${this.imagePlaceholderCounter}]`;
503
- this.placeholderStorage.set(imageId, {
504
- id: imageId,
505
- type: 'image',
506
- content: cleanedBase64,
507
- charCount: cleanedBase64.length,
508
- index: this.imagePlaceholderCounter,
509
- placeholder: placeholderText,
510
- mimeType: mimeType,
511
- });
512
- this.insertPlainText(placeholderText);
513
- this.scheduleUpdate();
514
- }
515
- /**
516
- * 获取所有图片数据(还原为 data URL 格式)
517
- */
518
- getImages() {
519
- return Array.from(this.placeholderStorage.values())
520
- .filter(p => p.type === 'image')
521
- .map(p => {
522
- const mimeType = p.mimeType || 'image/png';
523
- // 还原为 data URL 格式
524
- const dataUrl = `data:${mimeType};base64,${p.content}`;
525
- return {
526
- id: p.id,
527
- data: dataUrl,
528
- mimeType: mimeType,
529
- index: p.index,
530
- placeholder: p.placeholder,
531
- };
532
- })
533
- .sort((a, b) => a.index - b.index);
534
- }
535
- /**
536
- * 清除所有图片
537
- */
538
- clearImages() {
539
- // 只清除图片类型的占位符
540
- for (const [id, placeholder] of this.placeholderStorage.entries()) {
541
- if (placeholder.type === 'image') {
542
- this.placeholderStorage.delete(id);
543
- }
544
- }
545
- this.imagePlaceholderCounter = 0;
546
- }
547
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * Convert a string to an array of code points (Unicode characters).
3
- * Handles surrogate pairs correctly.
4
- */
5
- export declare function toCodePoints(str: string): string[];
6
- /**
7
- * Get the length of a string in code points (not bytes).
8
- */
9
- export declare function cpLen(str: string): number;
10
- /**
11
- * Slice a string by code point indices (not byte indices).
12
- */
13
- export declare function cpSlice(str: string, start: number, end?: number): string;
14
- /**
15
- * Get the visual width of a string (how many columns it occupies in terminal).
16
- * Handles wide characters like Chinese, emojis, etc.
17
- */
18
- export declare function visualWidth(str: string): number;
19
- /**
20
- * Get character at visual position (accounting for wide characters).
21
- */
22
- export declare function getCharAtVisualPos(str: string, visualPos: number): {
23
- char: string;
24
- codePointIndex: number;
25
- } | null;
26
- /**
27
- * Convert code point index to visual position.
28
- */
29
- export declare function codePointToVisualPos(str: string, codePointIndex: number): number;
30
- /**
31
- * Convert visual position to code point index.
32
- */
33
- export declare function visualPosToCodePoint(str: string, visualPos: number): number;
34
- /**
35
- * Format elapsed time to human readable format.
36
- */
37
- export declare function formatElapsedTime(seconds: number): string;
@@ -1,102 +0,0 @@
1
- import stringWidth from 'string-width';
2
- /**
3
- * Convert a string to an array of code points (Unicode characters).
4
- * Handles surrogate pairs correctly.
5
- */
6
- export function toCodePoints(str) {
7
- return Array.from(str);
8
- }
9
- /**
10
- * Get the length of a string in code points (not bytes).
11
- */
12
- export function cpLen(str) {
13
- return toCodePoints(str).length;
14
- }
15
- /**
16
- * Slice a string by code point indices (not byte indices).
17
- */
18
- export function cpSlice(str, start, end) {
19
- const codePoints = toCodePoints(str);
20
- return codePoints.slice(start, end).join('');
21
- }
22
- /**
23
- * Get the visual width of a string (how many columns it occupies in terminal).
24
- * Handles wide characters like Chinese, emojis, etc.
25
- */
26
- export function visualWidth(str) {
27
- return stringWidth(str);
28
- }
29
- /**
30
- * Get character at visual position (accounting for wide characters).
31
- */
32
- export function getCharAtVisualPos(str, visualPos) {
33
- const codePoints = toCodePoints(str);
34
- let currentVisualPos = 0;
35
- for (let i = 0; i < codePoints.length; i++) {
36
- const char = codePoints[i] || '';
37
- const charWidth = visualWidth(char);
38
- if (currentVisualPos === visualPos) {
39
- return { char, codePointIndex: i };
40
- }
41
- if (currentVisualPos + charWidth > visualPos) {
42
- // We're in the middle of a wide character
43
- return { char, codePointIndex: i };
44
- }
45
- currentVisualPos += charWidth;
46
- }
47
- // Position is at the end of the string
48
- if (currentVisualPos === visualPos) {
49
- return { char: '', codePointIndex: codePoints.length };
50
- }
51
- return null;
52
- }
53
- /**
54
- * Convert code point index to visual position.
55
- */
56
- export function codePointToVisualPos(str, codePointIndex) {
57
- const codePoints = toCodePoints(str);
58
- let visualPos = 0;
59
- for (let i = 0; i < Math.min(codePointIndex, codePoints.length); i++) {
60
- const char = codePoints[i] || '';
61
- visualPos += visualWidth(char);
62
- }
63
- return visualPos;
64
- }
65
- /**
66
- * Convert visual position to code point index.
67
- */
68
- export function visualPosToCodePoint(str, visualPos) {
69
- const codePoints = toCodePoints(str);
70
- let currentVisualPos = 0;
71
- for (let i = 0; i < codePoints.length; i++) {
72
- const char = codePoints[i] || '';
73
- const charWidth = visualWidth(char);
74
- if (currentVisualPos + charWidth > visualPos) {
75
- return i;
76
- }
77
- currentVisualPos += charWidth;
78
- if (currentVisualPos >= visualPos) {
79
- return i + 1;
80
- }
81
- }
82
- return codePoints.length;
83
- }
84
- /**
85
- * Format elapsed time to human readable format.
86
- */
87
- export function formatElapsedTime(seconds) {
88
- if (seconds < 60) {
89
- return `${seconds}s`;
90
- }
91
- else if (seconds < 3600) {
92
- const minutes = Math.floor(seconds / 60);
93
- const remainingSeconds = seconds % 60;
94
- return `${minutes}m ${remainingSeconds}s`;
95
- }
96
- else {
97
- const hours = Math.floor(seconds / 3600);
98
- const remainingMinutes = Math.floor((seconds % 3600) / 60);
99
- const remainingSeconds = seconds % 60;
100
- return `${hours}h ${remainingMinutes}m ${remainingSeconds}s`;
101
- }
102
- }