@machina.ai/cell-cli 1.10.0-rc1 → 1.13.0-rc1

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 (813) hide show
  1. package/dist/index.js +5 -5
  2. package/dist/index.js.map +1 -1
  3. package/dist/package.json +14 -12
  4. package/dist/src/commands/extensions/disable.d.ts +1 -1
  5. package/dist/src/commands/extensions/disable.js +19 -8
  6. package/dist/src/commands/extensions/disable.js.map +1 -1
  7. package/dist/src/commands/extensions/enable.d.ts +1 -1
  8. package/dist/src/commands/extensions/enable.js +19 -9
  9. package/dist/src/commands/extensions/enable.js.map +1 -1
  10. package/dist/src/commands/extensions/examples/mcp-server/example.js +46 -0
  11. package/dist/src/commands/extensions/examples/mcp-server/example.js.map +1 -0
  12. package/dist/src/commands/extensions/install.d.ts +1 -0
  13. package/dist/src/commands/extensions/install.js +29 -4
  14. package/dist/src/commands/extensions/install.js.map +1 -1
  15. package/dist/src/commands/extensions/install.test.js +39 -19
  16. package/dist/src/commands/extensions/install.test.js.map +1 -1
  17. package/dist/src/commands/extensions/link.js +16 -4
  18. package/dist/src/commands/extensions/link.js.map +1 -1
  19. package/dist/src/commands/extensions/list.js +17 -6
  20. package/dist/src/commands/extensions/list.js.map +1 -1
  21. package/dist/src/commands/extensions/new.js +14 -20
  22. package/dist/src/commands/extensions/new.js.map +1 -1
  23. package/dist/src/commands/extensions/uninstall.js +16 -4
  24. package/dist/src/commands/extensions/uninstall.js.map +1 -1
  25. package/dist/src/commands/extensions/update.js +28 -23
  26. package/dist/src/commands/extensions/update.js.map +1 -1
  27. package/dist/src/commands/extensions/validate.d.ts +12 -0
  28. package/dist/src/commands/extensions/validate.js +83 -0
  29. package/dist/src/commands/extensions/validate.js.map +1 -0
  30. package/dist/src/commands/extensions/validate.test.d.ts +6 -0
  31. package/dist/src/commands/extensions/validate.test.js +93 -0
  32. package/dist/src/commands/extensions/validate.test.js.map +1 -0
  33. package/dist/src/commands/extensions.js +3 -0
  34. package/dist/src/commands/extensions.js.map +1 -1
  35. package/dist/src/commands/mcp/add.js +7 -4
  36. package/dist/src/commands/mcp/add.js.map +1 -1
  37. package/dist/src/commands/mcp/add.test.d.ts +6 -0
  38. package/dist/src/commands/mcp/add.test.js +247 -0
  39. package/dist/src/commands/mcp/add.test.js.map +1 -0
  40. package/dist/src/commands/mcp/list.js +18 -9
  41. package/dist/src/commands/mcp/list.js.map +1 -1
  42. package/dist/src/commands/mcp/list.test.d.ts +6 -0
  43. package/dist/src/commands/mcp/list.test.js +128 -0
  44. package/dist/src/commands/mcp/list.test.js.map +1 -0
  45. package/dist/src/commands/mcp/remove.js +3 -2
  46. package/dist/src/commands/mcp/remove.js.map +1 -1
  47. package/dist/src/commands/mcp/remove.test.d.ts +6 -0
  48. package/dist/src/commands/mcp/remove.test.js +175 -0
  49. package/dist/src/commands/mcp/remove.test.js.map +1 -0
  50. package/dist/src/commands/mcp.test.d.ts +6 -0
  51. package/dist/src/commands/mcp.test.js +62 -0
  52. package/dist/src/commands/mcp.test.js.map +1 -0
  53. package/dist/src/config/auth.js +0 -3
  54. package/dist/src/config/auth.js.map +1 -1
  55. package/dist/src/config/config.d.ts +6 -15
  56. package/dist/src/config/config.integration.test.d.ts +6 -0
  57. package/dist/src/config/config.integration.test.js +321 -0
  58. package/dist/src/config/config.integration.test.js.map +1 -0
  59. package/dist/src/config/config.js +85 -164
  60. package/dist/src/config/config.js.map +1 -1
  61. package/dist/src/config/config.test.d.ts +6 -0
  62. package/dist/src/config/config.test.js +1972 -0
  63. package/dist/src/config/config.test.js.map +1 -0
  64. package/dist/src/config/extension-manager.d.ts +63 -0
  65. package/dist/src/config/extension-manager.js +450 -0
  66. package/dist/src/config/extension-manager.js.map +1 -0
  67. package/dist/src/config/extension.d.ts +4 -61
  68. package/dist/src/config/extension.js +1 -538
  69. package/dist/src/config/extension.js.map +1 -1
  70. package/dist/src/config/extension.test.d.ts +6 -0
  71. package/dist/src/config/extension.test.js +1412 -0
  72. package/dist/src/config/extension.test.js.map +1 -0
  73. package/dist/src/config/extensions/consent.d.ts +38 -0
  74. package/dist/src/config/extensions/consent.js +123 -0
  75. package/dist/src/config/extensions/consent.js.map +1 -0
  76. package/dist/src/config/extensions/extensionEnablement.d.ts +2 -2
  77. package/dist/src/config/extensions/extensionEnablement.js +7 -5
  78. package/dist/src/config/extensions/extensionEnablement.js.map +1 -1
  79. package/dist/src/config/extensions/extensionEnablement.test.js +31 -28
  80. package/dist/src/config/extensions/extensionEnablement.test.js.map +1 -1
  81. package/dist/src/config/extensions/extensionSettings.d.ts +15 -0
  82. package/dist/src/config/extensions/extensionSettings.js +113 -0
  83. package/dist/src/config/extensions/extensionSettings.js.map +1 -0
  84. package/dist/src/config/extensions/extensionSettings.test.d.ts +6 -0
  85. package/dist/src/config/extensions/extensionSettings.test.js +254 -0
  86. package/dist/src/config/extensions/extensionSettings.test.js.map +1 -0
  87. package/dist/src/config/extensions/github.d.ts +18 -9
  88. package/dist/src/config/extensions/github.js +108 -36
  89. package/dist/src/config/extensions/github.js.map +1 -1
  90. package/dist/src/config/extensions/github.test.js +158 -164
  91. package/dist/src/config/extensions/github.test.js.map +1 -1
  92. package/dist/src/config/extensions/github_fetch.d.ts +1 -1
  93. package/dist/src/config/extensions/github_fetch.js +13 -1
  94. package/dist/src/config/extensions/github_fetch.js.map +1 -1
  95. package/dist/src/config/extensions/github_fetch.test.d.ts +6 -0
  96. package/dist/src/config/extensions/github_fetch.test.js +169 -0
  97. package/dist/src/config/extensions/github_fetch.test.js.map +1 -0
  98. package/dist/src/config/extensions/storage.d.ts +14 -0
  99. package/dist/src/config/extensions/storage.js +32 -0
  100. package/dist/src/config/extensions/storage.js.map +1 -0
  101. package/dist/src/config/extensions/update.d.ts +5 -4
  102. package/dist/src/config/extensions/update.js +41 -37
  103. package/dist/src/config/extensions/update.js.map +1 -1
  104. package/dist/src/config/extensions/update.test.js +72 -74
  105. package/dist/src/config/extensions/update.test.js.map +1 -1
  106. package/dist/src/config/extensions/variableSchema.d.ts +0 -4
  107. package/dist/src/config/extensions/variableSchema.js.map +1 -1
  108. package/dist/src/config/extensions/variables.d.ts +4 -0
  109. package/dist/src/config/extensions/variables.js +6 -0
  110. package/dist/src/config/extensions/variables.js.map +1 -1
  111. package/dist/src/config/keyBindings.d.ts +5 -1
  112. package/dist/src/config/keyBindings.js +34 -10
  113. package/dist/src/config/keyBindings.js.map +1 -1
  114. package/dist/src/config/keyBindings.test.js +17 -0
  115. package/dist/src/config/keyBindings.test.js.map +1 -1
  116. package/dist/src/config/policies/read-only.toml +56 -0
  117. package/dist/src/config/policies/write.toml +63 -0
  118. package/dist/src/config/policies/yolo.toml +31 -0
  119. package/dist/src/config/policy-engine.integration.test.js +41 -38
  120. package/dist/src/config/policy-engine.integration.test.js.map +1 -1
  121. package/dist/src/config/policy.d.ts +4 -3
  122. package/dist/src/config/policy.js +13 -142
  123. package/dist/src/config/policy.js.map +1 -1
  124. package/dist/src/config/sandboxConfig.d.ts +1 -2
  125. package/dist/src/config/sandboxConfig.js +7 -6
  126. package/dist/src/config/sandboxConfig.js.map +1 -1
  127. package/dist/src/config/settings.d.ts +2 -1
  128. package/dist/src/config/settings.js +59 -15
  129. package/dist/src/config/settings.js.map +1 -1
  130. package/dist/src/config/settings.test.d.ts +6 -0
  131. package/dist/src/config/settings.test.js +2000 -0
  132. package/dist/src/config/settings.test.js.map +1 -0
  133. package/dist/src/config/settingsSchema.d.ts +170 -28
  134. package/dist/src/config/settingsSchema.js +418 -27
  135. package/dist/src/config/settingsSchema.js.map +1 -1
  136. package/dist/src/config/settingsSchema.test.js +42 -1
  137. package/dist/src/config/settingsSchema.test.js.map +1 -1
  138. package/dist/src/config/trustedFolders.d.ts +1 -1
  139. package/dist/src/config/trustedFolders.js +4 -2
  140. package/dist/src/config/trustedFolders.js.map +1 -1
  141. package/dist/src/core/initializer.js +2 -1
  142. package/dist/src/core/initializer.js.map +1 -1
  143. package/dist/src/gemini.d.ts +1 -1
  144. package/dist/src/gemini.js +63 -27
  145. package/dist/src/gemini.js.map +1 -1
  146. package/dist/src/gemini.test.js +123 -34
  147. package/dist/src/gemini.test.js.map +1 -1
  148. package/dist/src/generated/git-commit.d.ts +2 -2
  149. package/dist/src/generated/git-commit.js +2 -2
  150. package/dist/src/nonInteractiveCli.d.ts +9 -1
  151. package/dist/src/nonInteractiveCli.js +205 -10
  152. package/dist/src/nonInteractiveCli.js.map +1 -1
  153. package/dist/src/nonInteractiveCli.test.d.ts +6 -0
  154. package/dist/src/nonInteractiveCli.test.js +984 -0
  155. package/dist/src/nonInteractiveCli.test.js.map +1 -0
  156. package/dist/src/nonInteractiveCliCommands.js +2 -2
  157. package/dist/src/nonInteractiveCliCommands.js.map +1 -1
  158. package/dist/src/services/BuiltinCommandLoader.js +4 -0
  159. package/dist/src/services/BuiltinCommandLoader.js.map +1 -1
  160. package/dist/src/services/BuiltinCommandLoader.test.js +22 -0
  161. package/dist/src/services/BuiltinCommandLoader.test.js.map +1 -1
  162. package/dist/src/services/CommandService.js +2 -1
  163. package/dist/src/services/CommandService.js.map +1 -1
  164. package/dist/src/services/FeedbackService.js +2 -2
  165. package/dist/src/services/FeedbackService.js.map +1 -1
  166. package/dist/src/services/FileCommandLoader.test.d.ts +6 -0
  167. package/dist/src/services/FileCommandLoader.test.js +971 -0
  168. package/dist/src/services/FileCommandLoader.test.js.map +1 -0
  169. package/dist/src/services/McpPromptLoader.js +2 -2
  170. package/dist/src/services/McpPromptLoader.js.map +1 -1
  171. package/dist/src/services/McpPromptLoader.test.js +4 -2
  172. package/dist/src/services/McpPromptLoader.test.js.map +1 -1
  173. package/dist/src/services/prompt-processors/argumentProcessor.test.d.ts +6 -0
  174. package/dist/src/services/prompt-processors/argumentProcessor.test.js +40 -0
  175. package/dist/src/services/prompt-processors/argumentProcessor.test.js.map +1 -0
  176. package/dist/src/services/prompt-processors/atFileProcessor.js +3 -2
  177. package/dist/src/services/prompt-processors/atFileProcessor.js.map +1 -1
  178. package/dist/src/services/prompt-processors/shellProcessor.test.d.ts +6 -0
  179. package/dist/src/services/prompt-processors/shellProcessor.test.js +482 -0
  180. package/dist/src/services/prompt-processors/shellProcessor.test.js.map +1 -0
  181. package/dist/src/test-utils/async.d.ts +9 -0
  182. package/dist/src/test-utils/async.js +29 -0
  183. package/dist/src/test-utils/async.js.map +1 -0
  184. package/dist/src/test-utils/createExtension.d.ts +3 -1
  185. package/dist/src/test-utils/createExtension.js +3 -3
  186. package/dist/src/test-utils/createExtension.js.map +1 -1
  187. package/dist/src/test-utils/render.d.ts +17 -2
  188. package/dist/src/test-utils/render.js +69 -4
  189. package/dist/src/test-utils/render.js.map +1 -1
  190. package/dist/src/test-utils/render.test.d.ts +6 -0
  191. package/dist/src/test-utils/render.test.js +79 -0
  192. package/dist/src/test-utils/render.test.js.map +1 -0
  193. package/dist/src/ui/App.test.d.ts +6 -0
  194. package/dist/src/ui/App.test.js +110 -0
  195. package/dist/src/ui/App.test.js.map +1 -0
  196. package/dist/src/ui/AppContainer.js +223 -92
  197. package/dist/src/ui/AppContainer.js.map +1 -1
  198. package/dist/src/ui/AppContainer.test.js +531 -147
  199. package/dist/src/ui/AppContainer.test.js.map +1 -1
  200. package/dist/src/ui/IdeIntegrationNudge.js +1 -1
  201. package/dist/src/ui/IdeIntegrationNudge.js.map +1 -1
  202. package/dist/src/ui/auth/ApiAuthDialog.d.ts +14 -0
  203. package/dist/src/ui/auth/ApiAuthDialog.js +26 -0
  204. package/dist/src/ui/auth/ApiAuthDialog.js.map +1 -0
  205. package/dist/src/ui/auth/ApiAuthDialog.test.d.ts +6 -0
  206. package/dist/src/ui/auth/ApiAuthDialog.test.js +91 -0
  207. package/dist/src/ui/auth/ApiAuthDialog.test.js.map +1 -0
  208. package/dist/src/ui/auth/AuthDialog.d.ts +1 -1
  209. package/dist/src/ui/auth/AuthDialog.js +9 -3
  210. package/dist/src/ui/auth/AuthDialog.js.map +1 -1
  211. package/dist/src/ui/auth/useAuth.d.ts +3 -1
  212. package/dist/src/ui/auth/useAuth.js +35 -4
  213. package/dist/src/ui/auth/useAuth.js.map +1 -1
  214. package/dist/src/ui/colors.js +3 -0
  215. package/dist/src/ui/colors.js.map +1 -1
  216. package/dist/src/ui/commands/aboutCommand.js +1 -1
  217. package/dist/src/ui/commands/aboutCommand.test.d.ts +6 -0
  218. package/dist/src/ui/commands/aboutCommand.test.js +130 -0
  219. package/dist/src/ui/commands/aboutCommand.test.js.map +1 -0
  220. package/dist/src/ui/commands/authCommand.js +1 -1
  221. package/dist/src/ui/commands/authCommand.test.d.ts +6 -0
  222. package/dist/src/ui/commands/authCommand.test.js +30 -0
  223. package/dist/src/ui/commands/authCommand.test.js.map +1 -0
  224. package/dist/src/ui/commands/bugCommand.js +1 -1
  225. package/dist/src/ui/commands/bugCommand.test.d.ts +6 -0
  226. package/dist/src/ui/commands/bugCommand.test.js +105 -0
  227. package/dist/src/ui/commands/bugCommand.test.js.map +1 -0
  228. package/dist/src/ui/commands/chatCommand.js +1 -1
  229. package/dist/src/ui/commands/chatCommand.js.map +1 -1
  230. package/dist/src/ui/commands/chatCommand.test.d.ts +6 -0
  231. package/dist/src/ui/commands/chatCommand.test.js +555 -0
  232. package/dist/src/ui/commands/chatCommand.test.js.map +1 -0
  233. package/dist/src/ui/commands/clearCommand.js +1 -1
  234. package/dist/src/ui/commands/clearCommand.test.d.ts +6 -0
  235. package/dist/src/ui/commands/clearCommand.test.js +76 -0
  236. package/dist/src/ui/commands/clearCommand.test.js.map +1 -0
  237. package/dist/src/ui/commands/compressCommand.js +1 -1
  238. package/dist/src/ui/commands/compressCommand.js.map +1 -1
  239. package/dist/src/ui/commands/compressCommand.test.d.ts +6 -0
  240. package/dist/src/ui/commands/compressCommand.test.js +98 -0
  241. package/dist/src/ui/commands/compressCommand.test.js.map +1 -0
  242. package/dist/src/ui/commands/copyCommand.js +2 -1
  243. package/dist/src/ui/commands/copyCommand.js.map +1 -1
  244. package/dist/src/ui/commands/copyCommand.test.d.ts +6 -0
  245. package/dist/src/ui/commands/copyCommand.test.js +242 -0
  246. package/dist/src/ui/commands/copyCommand.test.js.map +1 -0
  247. package/dist/src/ui/commands/corgiCommand.js +1 -1
  248. package/dist/src/ui/commands/corgiCommand.js.map +1 -1
  249. package/dist/src/ui/commands/corgiCommand.test.d.ts +6 -0
  250. package/dist/src/ui/commands/corgiCommand.test.js +28 -0
  251. package/dist/src/ui/commands/corgiCommand.test.js.map +1 -0
  252. package/dist/src/ui/commands/directoryCommand.js +1 -1
  253. package/dist/src/ui/commands/directoryCommand.js.map +1 -1
  254. package/dist/src/ui/commands/directoryCommand.test.d.ts +6 -0
  255. package/dist/src/ui/commands/directoryCommand.test.js +144 -0
  256. package/dist/src/ui/commands/directoryCommand.test.js.map +1 -0
  257. package/dist/src/ui/commands/docsCommand.js +1 -1
  258. package/dist/src/ui/commands/docsCommand.test.d.ts +6 -0
  259. package/dist/src/ui/commands/docsCommand.test.js +72 -0
  260. package/dist/src/ui/commands/docsCommand.test.js.map +1 -0
  261. package/dist/src/ui/commands/editorCommand.js +1 -1
  262. package/dist/src/ui/commands/editorCommand.test.d.ts +6 -0
  263. package/dist/src/ui/commands/editorCommand.test.js +27 -0
  264. package/dist/src/ui/commands/editorCommand.test.js.map +1 -0
  265. package/dist/src/ui/commands/extensionsCommand.js +64 -11
  266. package/dist/src/ui/commands/extensionsCommand.js.map +1 -1
  267. package/dist/src/ui/commands/extensionsCommand.test.d.ts +6 -0
  268. package/dist/src/ui/commands/extensionsCommand.test.js +315 -0
  269. package/dist/src/ui/commands/extensionsCommand.test.js.map +1 -0
  270. package/dist/src/ui/commands/helpCommand.js +1 -1
  271. package/dist/src/ui/commands/helpCommand.test.d.ts +6 -0
  272. package/dist/src/ui/commands/helpCommand.test.js +42 -0
  273. package/dist/src/ui/commands/helpCommand.test.js.map +1 -0
  274. package/dist/src/ui/commands/ideCommand.js +6 -6
  275. package/dist/src/ui/commands/ideCommand.test.d.ts +6 -0
  276. package/dist/src/ui/commands/ideCommand.test.js +205 -0
  277. package/dist/src/ui/commands/ideCommand.test.js.map +1 -0
  278. package/dist/src/ui/commands/initCommand.js +1 -1
  279. package/dist/src/ui/commands/initCommand.js.map +1 -1
  280. package/dist/src/ui/commands/initCommand.test.d.ts +6 -0
  281. package/dist/src/ui/commands/initCommand.test.js +80 -0
  282. package/dist/src/ui/commands/initCommand.test.js.map +1 -0
  283. package/dist/src/ui/commands/mcpCommand.js +110 -100
  284. package/dist/src/ui/commands/mcpCommand.js.map +1 -1
  285. package/dist/src/ui/commands/mcpCommand.test.d.ts +6 -0
  286. package/dist/src/ui/commands/mcpCommand.test.js +152 -0
  287. package/dist/src/ui/commands/mcpCommand.test.js.map +1 -0
  288. package/dist/src/ui/commands/memoryCommand.js +6 -6
  289. package/dist/src/ui/commands/memoryCommand.js.map +1 -1
  290. package/dist/src/ui/commands/memoryCommand.test.d.ts +6 -0
  291. package/dist/src/ui/commands/memoryCommand.test.js +268 -0
  292. package/dist/src/ui/commands/memoryCommand.test.js.map +1 -0
  293. package/dist/src/ui/commands/policiesCommand.d.ts +7 -0
  294. package/dist/src/ui/commands/policiesCommand.js +59 -0
  295. package/dist/src/ui/commands/policiesCommand.js.map +1 -0
  296. package/dist/src/ui/commands/policiesCommand.test.d.ts +6 -0
  297. package/dist/src/ui/commands/policiesCommand.test.js +83 -0
  298. package/dist/src/ui/commands/policiesCommand.test.js.map +1 -0
  299. package/dist/src/ui/commands/privacyCommand.js +1 -1
  300. package/dist/src/ui/commands/privacyCommand.test.d.ts +6 -0
  301. package/dist/src/ui/commands/privacyCommand.test.js +32 -0
  302. package/dist/src/ui/commands/privacyCommand.test.js.map +1 -0
  303. package/dist/src/ui/commands/quitCommand.js +1 -1
  304. package/dist/src/ui/commands/quitCommand.test.d.ts +6 -0
  305. package/dist/src/ui/commands/quitCommand.test.js +50 -0
  306. package/dist/src/ui/commands/quitCommand.test.js.map +1 -0
  307. package/dist/src/ui/commands/restoreCommand.test.d.ts +6 -0
  308. package/dist/src/ui/commands/restoreCommand.test.js +190 -0
  309. package/dist/src/ui/commands/restoreCommand.test.js.map +1 -0
  310. package/dist/src/ui/commands/settingsCommand.test.d.ts +6 -0
  311. package/dist/src/ui/commands/settingsCommand.test.js +30 -0
  312. package/dist/src/ui/commands/settingsCommand.test.js.map +1 -0
  313. package/dist/src/ui/commands/setupGithubCommand.js +4 -3
  314. package/dist/src/ui/commands/setupGithubCommand.js.map +1 -1
  315. package/dist/src/ui/commands/setupGithubCommand.test.js +1 -2
  316. package/dist/src/ui/commands/setupGithubCommand.test.js.map +1 -1
  317. package/dist/src/ui/commands/statsCommand.js +3 -3
  318. package/dist/src/ui/commands/statsCommand.js.map +1 -1
  319. package/dist/src/ui/commands/statsCommand.test.d.ts +6 -0
  320. package/dist/src/ui/commands/statsCommand.test.js +53 -0
  321. package/dist/src/ui/commands/statsCommand.test.js.map +1 -0
  322. package/dist/src/ui/commands/terminalSetupCommand.test.d.ts +6 -0
  323. package/dist/src/ui/commands/terminalSetupCommand.test.js +66 -0
  324. package/dist/src/ui/commands/terminalSetupCommand.test.js.map +1 -0
  325. package/dist/src/ui/commands/themeCommand.js +1 -1
  326. package/dist/src/ui/commands/themeCommand.test.d.ts +6 -0
  327. package/dist/src/ui/commands/themeCommand.test.js +32 -0
  328. package/dist/src/ui/commands/themeCommand.test.js.map +1 -0
  329. package/dist/src/ui/commands/toolsCommand.js +1 -1
  330. package/dist/src/ui/commands/toolsCommand.test.d.ts +6 -0
  331. package/dist/src/ui/commands/toolsCommand.test.js +100 -0
  332. package/dist/src/ui/commands/toolsCommand.test.js.map +1 -0
  333. package/dist/src/ui/commands/types.d.ts +1 -0
  334. package/dist/src/ui/commands/vimCommand.js +1 -1
  335. package/dist/src/ui/components/AnsiOutput.test.js +1 -1
  336. package/dist/src/ui/components/AnsiOutput.test.js.map +1 -1
  337. package/dist/src/ui/components/AsciiArt.d.ts +3 -3
  338. package/dist/src/ui/components/AsciiArt.js +3 -3
  339. package/dist/src/ui/components/Composer.js +6 -4
  340. package/dist/src/ui/components/Composer.js.map +1 -1
  341. package/dist/src/ui/components/Composer.test.js +21 -3
  342. package/dist/src/ui/components/Composer.test.js.map +1 -1
  343. package/dist/src/ui/components/ConfigInitDisplay.js +4 -6
  344. package/dist/src/ui/components/ConfigInitDisplay.js.map +1 -1
  345. package/dist/src/ui/components/ConsentPrompt.test.js +18 -8
  346. package/dist/src/ui/components/ConsentPrompt.test.js.map +1 -1
  347. package/dist/src/ui/components/ConsoleSummaryDisplay.js +1 -1
  348. package/dist/src/ui/components/ConsoleSummaryDisplay.js.map +1 -1
  349. package/dist/src/ui/components/ContextSummaryDisplay.d.ts +0 -1
  350. package/dist/src/ui/components/ContextSummaryDisplay.js +2 -12
  351. package/dist/src/ui/components/ContextSummaryDisplay.js.map +1 -1
  352. package/dist/src/ui/components/ContextSummaryDisplay.test.d.ts +6 -0
  353. package/dist/src/ui/components/ContextSummaryDisplay.test.js +71 -0
  354. package/dist/src/ui/components/ContextSummaryDisplay.test.js.map +1 -0
  355. package/dist/src/ui/components/DetailedMessagesDisplay.js +1 -1
  356. package/dist/src/ui/components/DetailedMessagesDisplay.js.map +1 -1
  357. package/dist/src/ui/components/DialogManager.js +5 -5
  358. package/dist/src/ui/components/DialogManager.js.map +1 -1
  359. package/dist/src/ui/components/EditorSettingsDialog.js +1 -1
  360. package/dist/src/ui/components/EditorSettingsDialog.js.map +1 -1
  361. package/dist/src/ui/components/FolderTrustDialog.test.js +8 -3
  362. package/dist/src/ui/components/FolderTrustDialog.test.js.map +1 -1
  363. package/dist/src/ui/components/Footer.js +4 -3
  364. package/dist/src/ui/components/Footer.js.map +1 -1
  365. package/dist/src/ui/components/Footer.test.d.ts +6 -0
  366. package/dist/src/ui/components/Footer.test.js +314 -0
  367. package/dist/src/ui/components/Footer.test.js.map +1 -0
  368. package/dist/src/ui/components/Header.test.js +13 -5
  369. package/dist/src/ui/components/Header.test.js.map +1 -1
  370. package/dist/src/ui/components/Help.test.js +5 -4
  371. package/dist/src/ui/components/Help.test.js.map +1 -1
  372. package/dist/src/ui/components/HistoryItemDisplay.js +1 -1
  373. package/dist/src/ui/components/HistoryItemDisplay.js.map +1 -1
  374. package/dist/src/ui/components/InputPrompt.d.ts +4 -0
  375. package/dist/src/ui/components/InputPrompt.js +80 -12
  376. package/dist/src/ui/components/InputPrompt.js.map +1 -1
  377. package/dist/src/ui/components/InputPrompt.test.d.ts +6 -0
  378. package/dist/src/ui/components/InputPrompt.test.js +1786 -0
  379. package/dist/src/ui/components/InputPrompt.test.js.map +1 -0
  380. package/dist/src/ui/components/LoadingIndicator.js +2 -2
  381. package/dist/src/ui/components/LoadingIndicator.js.map +1 -1
  382. package/dist/src/ui/components/LoadingIndicator.test.js +28 -15
  383. package/dist/src/ui/components/LoadingIndicator.test.js.map +1 -1
  384. package/dist/src/ui/components/LoopDetectionConfirmation.js +1 -1
  385. package/dist/src/ui/components/LoopDetectionConfirmation.js.map +1 -1
  386. package/dist/src/ui/components/LoopDetectionConfirmation.test.js +2 -2
  387. package/dist/src/ui/components/LoopDetectionConfirmation.test.js.map +1 -1
  388. package/dist/src/ui/components/MainContent.js +15 -4
  389. package/dist/src/ui/components/MainContent.js.map +1 -1
  390. package/dist/src/ui/components/ModelDialog.js +1 -1
  391. package/dist/src/ui/components/ModelDialog.js.map +1 -1
  392. package/dist/src/ui/components/ModelDialog.test.js +23 -13
  393. package/dist/src/ui/components/ModelDialog.test.js.map +1 -1
  394. package/dist/src/ui/components/ModelStatsDisplay.test.d.ts +6 -0
  395. package/dist/src/ui/components/ModelStatsDisplay.test.js +285 -0
  396. package/dist/src/ui/components/ModelStatsDisplay.test.js.map +1 -0
  397. package/dist/src/ui/components/Notifications.js +38 -5
  398. package/dist/src/ui/components/Notifications.js.map +1 -1
  399. package/dist/src/ui/components/PermissionsModifyTrustDialog.js +22 -18
  400. package/dist/src/ui/components/PermissionsModifyTrustDialog.js.map +1 -1
  401. package/dist/src/ui/components/PermissionsModifyTrustDialog.test.js +12 -4
  402. package/dist/src/ui/components/PermissionsModifyTrustDialog.test.js.map +1 -1
  403. package/dist/src/ui/components/PrepareLabel.test.js +14 -8
  404. package/dist/src/ui/components/PrepareLabel.test.js.map +1 -1
  405. package/dist/src/ui/components/ProQuotaDialog.test.js +14 -6
  406. package/dist/src/ui/components/ProQuotaDialog.test.js.map +1 -1
  407. package/dist/src/ui/components/QueuedMessageDisplay.js +3 -3
  408. package/dist/src/ui/components/QueuedMessageDisplay.js.map +1 -1
  409. package/dist/src/ui/components/QueuedMessageDisplay.test.js +15 -6
  410. package/dist/src/ui/components/QueuedMessageDisplay.test.js.map +1 -1
  411. package/dist/src/ui/components/RawMarkdownIndicator.d.ts +7 -0
  412. package/dist/src/ui/components/RawMarkdownIndicator.js +8 -0
  413. package/dist/src/ui/components/RawMarkdownIndicator.js.map +1 -0
  414. package/dist/src/ui/components/SessionSummaryDisplay.test.d.ts +6 -0
  415. package/dist/src/ui/components/SessionSummaryDisplay.test.js +74 -0
  416. package/dist/src/ui/components/SessionSummaryDisplay.test.js.map +1 -0
  417. package/dist/src/ui/components/SettingsDialog.js +43 -35
  418. package/dist/src/ui/components/SettingsDialog.js.map +1 -1
  419. package/dist/src/ui/components/SettingsDialog.test.js +554 -545
  420. package/dist/src/ui/components/SettingsDialog.test.js.map +1 -1
  421. package/dist/src/ui/components/ShellConfirmationDialog.js +1 -1
  422. package/dist/src/ui/components/ShellConfirmationDialog.js.map +1 -1
  423. package/dist/src/ui/components/ShellConfirmationDialog.test.js +2 -2
  424. package/dist/src/ui/components/ShellConfirmationDialog.test.js.map +1 -1
  425. package/dist/src/ui/components/StatsDisplay.test.d.ts +6 -0
  426. package/dist/src/ui/components/StatsDisplay.test.js +351 -0
  427. package/dist/src/ui/components/StatsDisplay.test.js.map +1 -0
  428. package/dist/src/ui/components/SuggestionsDisplay.js +1 -1
  429. package/dist/src/ui/components/SuggestionsDisplay.js.map +1 -1
  430. package/dist/src/ui/components/ThemeDialog.d.ts +4 -2
  431. package/dist/src/ui/components/ThemeDialog.js +3 -3
  432. package/dist/src/ui/components/ThemeDialog.js.map +1 -1
  433. package/dist/src/ui/components/ThemeDialog.test.js +14 -1
  434. package/dist/src/ui/components/ThemeDialog.test.js.map +1 -1
  435. package/dist/src/ui/components/ToolStatsDisplay.test.d.ts +6 -0
  436. package/dist/src/ui/components/ToolStatsDisplay.test.js +227 -0
  437. package/dist/src/ui/components/ToolStatsDisplay.test.js.map +1 -0
  438. package/dist/src/ui/components/messages/CompressionMessage.test.js +25 -17
  439. package/dist/src/ui/components/messages/CompressionMessage.test.js.map +1 -1
  440. package/dist/src/ui/components/messages/DiffRenderer.test.js +1 -1
  441. package/dist/src/ui/components/messages/DiffRenderer.test.js.map +1 -1
  442. package/dist/src/ui/components/messages/GeminiMessage.js +3 -1
  443. package/dist/src/ui/components/messages/GeminiMessage.js.map +1 -1
  444. package/dist/src/ui/components/messages/GeminiMessage.test.d.ts +6 -0
  445. package/dist/src/ui/components/messages/GeminiMessage.test.js +35 -0
  446. package/dist/src/ui/components/messages/GeminiMessage.test.js.map +1 -0
  447. package/dist/src/ui/components/messages/GeminiMessageContent.js +3 -1
  448. package/dist/src/ui/components/messages/GeminiMessageContent.js.map +1 -1
  449. package/dist/src/ui/components/messages/InfoMessage.js +1 -1
  450. package/dist/src/ui/components/messages/InfoMessage.js.map +1 -1
  451. package/dist/src/ui/components/messages/Todo.d.ts +7 -0
  452. package/dist/src/ui/components/messages/Todo.js +91 -0
  453. package/dist/src/ui/components/messages/Todo.js.map +1 -0
  454. package/dist/src/ui/components/messages/Todo.test.d.ts +6 -0
  455. package/dist/src/ui/components/messages/Todo.test.js +114 -0
  456. package/dist/src/ui/components/messages/Todo.test.js.map +1 -0
  457. package/dist/src/ui/components/messages/ToolConfirmationMessage.js +1 -1
  458. package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -1
  459. package/dist/src/ui/components/messages/ToolGroupMessage.js +1 -1
  460. package/dist/src/ui/components/messages/ToolGroupMessage.js.map +1 -1
  461. package/dist/src/ui/components/messages/ToolGroupMessage.test.js +29 -15
  462. package/dist/src/ui/components/messages/ToolGroupMessage.test.js.map +1 -1
  463. package/dist/src/ui/components/messages/ToolMessage.js +8 -3
  464. package/dist/src/ui/components/messages/ToolMessage.js.map +1 -1
  465. package/dist/src/ui/components/messages/ToolMessage.test.js +2 -2
  466. package/dist/src/ui/components/messages/ToolMessage.test.js.map +1 -1
  467. package/dist/src/ui/components/messages/ToolMessageRawMarkdown.test.d.ts +6 -0
  468. package/dist/src/ui/components/messages/ToolMessageRawMarkdown.test.js +30 -0
  469. package/dist/src/ui/components/messages/ToolMessageRawMarkdown.test.js.map +1 -0
  470. package/dist/src/ui/components/messages/UserShellMessage.js +1 -1
  471. package/dist/src/ui/components/messages/UserShellMessage.js.map +1 -1
  472. package/dist/src/ui/components/messages/WarningMessage.js +2 -2
  473. package/dist/src/ui/components/messages/WarningMessage.js.map +1 -1
  474. package/dist/src/ui/components/shared/BaseSelectionList.test.js +34 -25
  475. package/dist/src/ui/components/shared/BaseSelectionList.test.js.map +1 -1
  476. package/dist/src/ui/components/shared/MaxSizedBox.test.js +43 -22
  477. package/dist/src/ui/components/shared/MaxSizedBox.test.js.map +1 -1
  478. package/dist/src/ui/components/shared/TextInput.d.ts +15 -0
  479. package/dist/src/ui/components/shared/TextInput.js +38 -0
  480. package/dist/src/ui/components/shared/TextInput.js.map +1 -0
  481. package/dist/src/ui/components/shared/TextInput.test.d.ts +6 -0
  482. package/dist/src/ui/components/shared/TextInput.test.js +242 -0
  483. package/dist/src/ui/components/shared/TextInput.test.js.map +1 -0
  484. package/dist/src/ui/components/shared/text-buffer.d.ts +9 -2
  485. package/dist/src/ui/components/shared/text-buffer.js +52 -14
  486. package/dist/src/ui/components/shared/text-buffer.js.map +1 -1
  487. package/dist/src/ui/components/shared/text-buffer.test.d.ts +6 -0
  488. package/dist/src/ui/components/shared/text-buffer.test.js +1761 -0
  489. package/dist/src/ui/components/shared/text-buffer.test.js.map +1 -0
  490. package/dist/src/ui/components/shared/vim-buffer-actions.test.d.ts +6 -0
  491. package/dist/src/ui/components/shared/vim-buffer-actions.test.js +951 -0
  492. package/dist/src/ui/components/shared/vim-buffer-actions.test.js.map +1 -0
  493. package/dist/src/ui/components/views/ChatList.test.js +7 -4
  494. package/dist/src/ui/components/views/ChatList.test.js.map +1 -1
  495. package/dist/src/ui/components/views/ExtensionsList.d.ts +7 -1
  496. package/dist/src/ui/components/views/ExtensionsList.js +12 -15
  497. package/dist/src/ui/components/views/ExtensionsList.js.map +1 -1
  498. package/dist/src/ui/components/views/ExtensionsList.test.js +43 -29
  499. package/dist/src/ui/components/views/ExtensionsList.test.js.map +1 -1
  500. package/dist/src/ui/components/views/McpStatus.d.ts +0 -1
  501. package/dist/src/ui/components/views/McpStatus.js +4 -4
  502. package/dist/src/ui/components/views/McpStatus.js.map +1 -1
  503. package/dist/src/ui/components/views/McpStatus.test.js +23 -17
  504. package/dist/src/ui/components/views/McpStatus.test.js.map +1 -1
  505. package/dist/src/ui/components/views/ToolsList.test.js +4 -4
  506. package/dist/src/ui/components/views/ToolsList.test.js.map +1 -1
  507. package/dist/src/ui/contexts/KeypressContext.d.ts +4 -2
  508. package/dist/src/ui/contexts/KeypressContext.js +635 -439
  509. package/dist/src/ui/contexts/KeypressContext.js.map +1 -1
  510. package/dist/src/ui/contexts/KeypressContext.test.js +634 -515
  511. package/dist/src/ui/contexts/KeypressContext.test.js.map +1 -1
  512. package/dist/src/ui/contexts/MouseContext.d.ts +21 -0
  513. package/dist/src/ui/contexts/MouseContext.js +89 -0
  514. package/dist/src/ui/contexts/MouseContext.js.map +1 -0
  515. package/dist/src/ui/contexts/MouseContext.test.d.ts +6 -0
  516. package/dist/src/ui/contexts/MouseContext.test.js +164 -0
  517. package/dist/src/ui/contexts/MouseContext.test.js.map +1 -0
  518. package/dist/src/ui/contexts/SessionContext.test.d.ts +6 -0
  519. package/dist/src/ui/contexts/SessionContext.test.js +195 -0
  520. package/dist/src/ui/contexts/SessionContext.test.js.map +1 -0
  521. package/dist/src/ui/contexts/UIActionsContext.d.ts +7 -4
  522. package/dist/src/ui/contexts/UIStateContext.d.ts +5 -3
  523. package/dist/src/ui/contexts/UIStateContext.js.map +1 -1
  524. package/dist/src/ui/hooks/atCommandProcessor.js +33 -11
  525. package/dist/src/ui/hooks/atCommandProcessor.js.map +1 -1
  526. package/dist/src/ui/hooks/atCommandProcessor.test.js +163 -64
  527. package/dist/src/ui/hooks/atCommandProcessor.test.js.map +1 -1
  528. package/dist/src/ui/hooks/shellCommandProcessor.js +0 -1
  529. package/dist/src/ui/hooks/shellCommandProcessor.js.map +1 -1
  530. package/dist/src/ui/hooks/shellCommandProcessor.test.js +64 -35
  531. package/dist/src/ui/hooks/shellCommandProcessor.test.js.map +1 -1
  532. package/dist/src/ui/hooks/slashCommandProcessor.js +2 -0
  533. package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
  534. package/dist/src/ui/hooks/slashCommandProcessor.test.d.ts +6 -0
  535. package/dist/src/ui/hooks/slashCommandProcessor.test.js +807 -0
  536. package/dist/src/ui/hooks/slashCommandProcessor.test.js.map +1 -0
  537. package/dist/src/ui/hooks/useAtCompletion.js +2 -2
  538. package/dist/src/ui/hooks/useAtCompletion.js.map +1 -1
  539. package/dist/src/ui/hooks/useAtCompletion.test.d.ts +6 -0
  540. package/dist/src/ui/hooks/useAtCompletion.test.js +396 -0
  541. package/dist/src/ui/hooks/useAtCompletion.test.js.map +1 -0
  542. package/dist/src/ui/hooks/useAutoAcceptIndicator.js +10 -0
  543. package/dist/src/ui/hooks/useAutoAcceptIndicator.js.map +1 -1
  544. package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js +32 -2
  545. package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js.map +1 -1
  546. package/dist/src/ui/hooks/useCommandCompletion.d.ts +1 -1
  547. package/dist/src/ui/hooks/useCommandCompletion.js +5 -3
  548. package/dist/src/ui/hooks/useCommandCompletion.js.map +1 -1
  549. package/dist/src/ui/hooks/useCommandCompletion.test.d.ts +6 -0
  550. package/dist/src/ui/hooks/useCommandCompletion.test.js +377 -0
  551. package/dist/src/ui/hooks/useCommandCompletion.test.js.map +1 -0
  552. package/dist/src/ui/hooks/useConsoleMessages.test.d.ts +6 -0
  553. package/dist/src/ui/hooks/useConsoleMessages.test.js +127 -0
  554. package/dist/src/ui/hooks/useConsoleMessages.test.js.map +1 -0
  555. package/dist/src/ui/hooks/useEditorSettings.test.js +40 -34
  556. package/dist/src/ui/hooks/useEditorSettings.test.js.map +1 -1
  557. package/dist/src/ui/hooks/useExtensionUpdates.d.ts +14 -4
  558. package/dist/src/ui/hooks/useExtensionUpdates.js +18 -11
  559. package/dist/src/ui/hooks/useExtensionUpdates.js.map +1 -1
  560. package/dist/src/ui/hooks/useExtensionUpdates.test.js +52 -35
  561. package/dist/src/ui/hooks/useExtensionUpdates.test.js.map +1 -1
  562. package/dist/src/ui/hooks/useFlickerDetector.test.js +9 -5
  563. package/dist/src/ui/hooks/useFlickerDetector.test.js.map +1 -1
  564. package/dist/src/ui/hooks/useFocus.test.d.ts +6 -0
  565. package/dist/src/ui/hooks/useFocus.test.js +131 -0
  566. package/dist/src/ui/hooks/useFocus.test.js.map +1 -0
  567. package/dist/src/ui/hooks/useFolderTrust.test.d.ts +6 -0
  568. package/dist/src/ui/hooks/useFolderTrust.test.js +188 -0
  569. package/dist/src/ui/hooks/useFolderTrust.test.js.map +1 -0
  570. package/dist/src/ui/hooks/useGeminiStream.js +119 -74
  571. package/dist/src/ui/hooks/useGeminiStream.js.map +1 -1
  572. package/dist/src/ui/hooks/useGeminiStream.test.d.ts +6 -0
  573. package/dist/src/ui/hooks/useGeminiStream.test.js +1820 -0
  574. package/dist/src/ui/hooks/useGeminiStream.test.js.map +1 -0
  575. package/dist/src/ui/hooks/useGitBranchName.js +4 -0
  576. package/dist/src/ui/hooks/useGitBranchName.js.map +1 -1
  577. package/dist/src/ui/hooks/useGitBranchName.test.js +46 -34
  578. package/dist/src/ui/hooks/useGitBranchName.test.js.map +1 -1
  579. package/dist/src/ui/hooks/useHistoryManager.test.js +2 -1
  580. package/dist/src/ui/hooks/useHistoryManager.test.js.map +1 -1
  581. package/dist/src/ui/hooks/useIdeTrustListener.test.js +40 -9
  582. package/dist/src/ui/hooks/useIdeTrustListener.test.js.map +1 -1
  583. package/dist/src/ui/hooks/useInputHistory.test.js +2 -1
  584. package/dist/src/ui/hooks/useInputHistory.test.js.map +1 -1
  585. package/dist/src/ui/hooks/useInputHistoryStore.js +2 -1
  586. package/dist/src/ui/hooks/useInputHistoryStore.js.map +1 -1
  587. package/dist/src/ui/hooks/useInputHistoryStore.test.js +2 -1
  588. package/dist/src/ui/hooks/useInputHistoryStore.test.js.map +1 -1
  589. package/dist/src/ui/hooks/useKeypress.test.d.ts +6 -0
  590. package/dist/src/ui/hooks/useKeypress.test.js +223 -0
  591. package/dist/src/ui/hooks/useKeypress.test.js.map +1 -0
  592. package/dist/src/ui/hooks/useLoadingIndicator.test.js +29 -6
  593. package/dist/src/ui/hooks/useLoadingIndicator.test.js.map +1 -1
  594. package/dist/src/ui/hooks/useMemoryMonitor.test.js +10 -5
  595. package/dist/src/ui/hooks/useMemoryMonitor.test.js.map +1 -1
  596. package/dist/src/ui/hooks/useMessageQueue.d.ts +1 -0
  597. package/dist/src/ui/hooks/useMessageQueue.js +14 -0
  598. package/dist/src/ui/hooks/useMessageQueue.js.map +1 -1
  599. package/dist/src/ui/hooks/useMessageQueue.test.js +173 -35
  600. package/dist/src/ui/hooks/useMessageQueue.test.js.map +1 -1
  601. package/dist/src/ui/hooks/useModelCommand.test.js +21 -11
  602. package/dist/src/ui/hooks/useModelCommand.test.js.map +1 -1
  603. package/dist/src/ui/hooks/useMouse.d.ts +17 -0
  604. package/dist/src/ui/hooks/useMouse.js +27 -0
  605. package/dist/src/ui/hooks/useMouse.js.map +1 -0
  606. package/dist/src/ui/hooks/useMouse.test.d.ts +6 -0
  607. package/dist/src/ui/hooks/useMouse.test.js +57 -0
  608. package/dist/src/ui/hooks/useMouse.test.js.map +1 -0
  609. package/dist/src/ui/hooks/usePermissionsModifyTrust.test.js +2 -2
  610. package/dist/src/ui/hooks/usePermissionsModifyTrust.test.js.map +1 -1
  611. package/dist/src/ui/hooks/usePhraseCycler.d.ts +1 -0
  612. package/dist/src/ui/hooks/usePhraseCycler.js +156 -5
  613. package/dist/src/ui/hooks/usePhraseCycler.js.map +1 -1
  614. package/dist/src/ui/hooks/usePhraseCycler.test.d.ts +6 -0
  615. package/dist/src/ui/hooks/usePhraseCycler.test.js +158 -0
  616. package/dist/src/ui/hooks/usePhraseCycler.test.js.map +1 -0
  617. package/dist/src/ui/hooks/usePrivacySettings.test.js +26 -6
  618. package/dist/src/ui/hooks/usePrivacySettings.test.js.map +1 -1
  619. package/dist/src/ui/hooks/usePromptCompletion.js +2 -2
  620. package/dist/src/ui/hooks/usePromptCompletion.js.map +1 -1
  621. package/dist/src/ui/hooks/useQuotaAndFallback.js +13 -14
  622. package/dist/src/ui/hooks/useQuotaAndFallback.js.map +1 -1
  623. package/dist/src/ui/hooks/useQuotaAndFallback.test.js +55 -48
  624. package/dist/src/ui/hooks/useQuotaAndFallback.test.js.map +1 -1
  625. package/dist/src/ui/hooks/useReactToolScheduler.d.ts +8 -1
  626. package/dist/src/ui/hooks/useReactToolScheduler.js +61 -36
  627. package/dist/src/ui/hooks/useReactToolScheduler.js.map +1 -1
  628. package/dist/src/ui/hooks/useReactToolScheduler.test.d.ts +6 -0
  629. package/dist/src/ui/hooks/useReactToolScheduler.test.js +65 -0
  630. package/dist/src/ui/hooks/useReactToolScheduler.test.js.map +1 -0
  631. package/dist/src/ui/hooks/useReverseSearchCompletion.test.js +2 -2
  632. package/dist/src/ui/hooks/useReverseSearchCompletion.test.js.map +1 -1
  633. package/dist/src/ui/hooks/useSelectionList.js +5 -4
  634. package/dist/src/ui/hooks/useSelectionList.js.map +1 -1
  635. package/dist/src/ui/hooks/useSelectionList.test.js +272 -183
  636. package/dist/src/ui/hooks/useSelectionList.test.js.map +1 -1
  637. package/dist/src/ui/hooks/useShellHistory.test.js +52 -20
  638. package/dist/src/ui/hooks/useShellHistory.test.js.map +1 -1
  639. package/dist/src/ui/hooks/useShowMemoryCommand.d.ts +1 -1
  640. package/dist/src/ui/hooks/useShowMemoryCommand.js +4 -3
  641. package/dist/src/ui/hooks/useShowMemoryCommand.js.map +1 -1
  642. package/dist/src/ui/hooks/useSlashCompletion.js +20 -8
  643. package/dist/src/ui/hooks/useSlashCompletion.js.map +1 -1
  644. package/dist/src/ui/hooks/useSlashCompletion.test.js +275 -137
  645. package/dist/src/ui/hooks/useSlashCompletion.test.js.map +1 -1
  646. package/dist/src/ui/hooks/useThemeCommand.d.ts +2 -1
  647. package/dist/src/ui/hooks/useThemeCommand.js +6 -0
  648. package/dist/src/ui/hooks/useThemeCommand.js.map +1 -1
  649. package/dist/src/ui/hooks/useTimer.test.js +43 -14
  650. package/dist/src/ui/hooks/useTimer.test.js.map +1 -1
  651. package/dist/src/ui/hooks/useToolScheduler.test.js +229 -242
  652. package/dist/src/ui/hooks/useToolScheduler.test.js.map +1 -1
  653. package/dist/src/ui/hooks/vim.js +2 -1
  654. package/dist/src/ui/hooks/vim.js.map +1 -1
  655. package/dist/src/ui/hooks/vim.test.d.ts +6 -0
  656. package/dist/src/ui/hooks/vim.test.js +1269 -0
  657. package/dist/src/ui/hooks/vim.test.js.map +1 -0
  658. package/dist/src/ui/keyMatchers.test.js +39 -6
  659. package/dist/src/ui/keyMatchers.test.js.map +1 -1
  660. package/dist/src/ui/state/extensions.d.ts +1 -0
  661. package/dist/src/ui/state/extensions.js +1 -0
  662. package/dist/src/ui/state/extensions.js.map +1 -1
  663. package/dist/src/ui/themes/ansi-light.js +1 -0
  664. package/dist/src/ui/themes/ansi-light.js.map +1 -1
  665. package/dist/src/ui/themes/ansi.js +1 -0
  666. package/dist/src/ui/themes/ansi.js.map +1 -1
  667. package/dist/src/ui/themes/atom-one-dark.js +2 -0
  668. package/dist/src/ui/themes/atom-one-dark.js.map +1 -1
  669. package/dist/src/ui/themes/ayu-light.js +2 -0
  670. package/dist/src/ui/themes/ayu-light.js.map +1 -1
  671. package/dist/src/ui/themes/ayu.js +2 -0
  672. package/dist/src/ui/themes/ayu.js.map +1 -1
  673. package/dist/src/ui/themes/color-utils.d.ts +1 -0
  674. package/dist/src/ui/themes/color-utils.js +8 -1
  675. package/dist/src/ui/themes/color-utils.js.map +1 -1
  676. package/dist/src/ui/themes/color-utils.test.js +13 -1
  677. package/dist/src/ui/themes/color-utils.test.js.map +1 -1
  678. package/dist/src/ui/themes/dracula.js +2 -0
  679. package/dist/src/ui/themes/dracula.js.map +1 -1
  680. package/dist/src/ui/themes/github-dark.js +2 -0
  681. package/dist/src/ui/themes/github-dark.js.map +1 -1
  682. package/dist/src/ui/themes/github-light.js +2 -0
  683. package/dist/src/ui/themes/github-light.js.map +1 -1
  684. package/dist/src/ui/themes/googlecode.js +2 -0
  685. package/dist/src/ui/themes/googlecode.js.map +1 -1
  686. package/dist/src/ui/themes/no-color.js +3 -0
  687. package/dist/src/ui/themes/no-color.js.map +1 -1
  688. package/dist/src/ui/themes/semantic-tokens.d.ts +2 -0
  689. package/dist/src/ui/themes/semantic-tokens.js +6 -0
  690. package/dist/src/ui/themes/semantic-tokens.js.map +1 -1
  691. package/dist/src/ui/themes/shades-of-purple.js +2 -0
  692. package/dist/src/ui/themes/shades-of-purple.js.map +1 -1
  693. package/dist/src/ui/themes/theme-manager.js +8 -7
  694. package/dist/src/ui/themes/theme-manager.js.map +1 -1
  695. package/dist/src/ui/themes/theme.d.ts +3 -0
  696. package/dist/src/ui/themes/theme.js +14 -3
  697. package/dist/src/ui/themes/theme.js.map +1 -1
  698. package/dist/src/ui/themes/theme.test.d.ts +6 -0
  699. package/dist/src/ui/themes/theme.test.js +151 -0
  700. package/dist/src/ui/themes/theme.test.js.map +1 -0
  701. package/dist/src/ui/themes/xcode.js +2 -0
  702. package/dist/src/ui/themes/xcode.js.map +1 -1
  703. package/dist/src/ui/types.d.ts +3 -2
  704. package/dist/src/ui/types.js +2 -0
  705. package/dist/src/ui/types.js.map +1 -1
  706. package/dist/src/ui/utils/CodeColorizer.d.ts +1 -1
  707. package/dist/src/ui/utils/CodeColorizer.js +6 -3
  708. package/dist/src/ui/utils/CodeColorizer.js.map +1 -1
  709. package/dist/src/ui/utils/InlineMarkdownRenderer.d.ts +1 -0
  710. package/dist/src/ui/utils/InlineMarkdownRenderer.js +11 -10
  711. package/dist/src/ui/utils/InlineMarkdownRenderer.js.map +1 -1
  712. package/dist/src/ui/utils/MarkdownDisplay.d.ts +1 -0
  713. package/dist/src/ui/utils/MarkdownDisplay.js +19 -10
  714. package/dist/src/ui/utils/MarkdownDisplay.js.map +1 -1
  715. package/dist/src/ui/utils/clipboardUtils.js +2 -2
  716. package/dist/src/ui/utils/clipboardUtils.js.map +1 -1
  717. package/dist/src/ui/utils/commandUtils.js +20 -3
  718. package/dist/src/ui/utils/commandUtils.js.map +1 -1
  719. package/dist/src/ui/utils/commandUtils.test.js +61 -6
  720. package/dist/src/ui/utils/commandUtils.test.js.map +1 -1
  721. package/dist/src/ui/utils/computeStats.js +5 -2
  722. package/dist/src/ui/utils/computeStats.js.map +1 -1
  723. package/dist/src/ui/utils/computeStats.test.d.ts +6 -0
  724. package/dist/src/ui/utils/computeStats.test.js +262 -0
  725. package/dist/src/ui/utils/computeStats.test.js.map +1 -0
  726. package/dist/src/ui/utils/input.d.ts +17 -0
  727. package/dist/src/ui/utils/input.js +51 -0
  728. package/dist/src/ui/utils/input.js.map +1 -0
  729. package/dist/src/ui/utils/input.test.d.ts +6 -0
  730. package/dist/src/ui/utils/input.test.js +44 -0
  731. package/dist/src/ui/utils/input.test.js.map +1 -0
  732. package/dist/src/ui/utils/kittyProtocolDetector.js +13 -4
  733. package/dist/src/ui/utils/kittyProtocolDetector.js.map +1 -1
  734. package/dist/src/ui/utils/mouse.d.ts +31 -0
  735. package/dist/src/ui/utils/mouse.js +164 -0
  736. package/dist/src/ui/utils/mouse.js.map +1 -0
  737. package/dist/src/ui/utils/mouse.test.d.ts +6 -0
  738. package/dist/src/ui/utils/mouse.test.js +131 -0
  739. package/dist/src/ui/utils/mouse.test.js.map +1 -0
  740. package/dist/src/ui/utils/terminalSetup.js +3 -2
  741. package/dist/src/ui/utils/terminalSetup.js.map +1 -1
  742. package/dist/src/ui/utils/textOutput.d.ts +25 -0
  743. package/dist/src/ui/utils/textOutput.js +49 -0
  744. package/dist/src/ui/utils/textOutput.js.map +1 -0
  745. package/dist/src/ui/utils/textOutput.test.d.ts +6 -0
  746. package/dist/src/ui/utils/textOutput.test.js +79 -0
  747. package/dist/src/ui/utils/textOutput.test.js.map +1 -0
  748. package/dist/src/ui/utils/updateCheck.d.ts +9 -2
  749. package/dist/src/ui/utils/updateCheck.js +38 -30
  750. package/dist/src/ui/utils/updateCheck.js.map +1 -1
  751. package/dist/src/ui/utils/updateCheck.test.js +48 -59
  752. package/dist/src/ui/utils/updateCheck.test.js.map +1 -1
  753. package/dist/src/utils/cleanup.test.d.ts +6 -0
  754. package/dist/src/utils/cleanup.test.js +49 -0
  755. package/dist/src/utils/cleanup.test.js.map +1 -0
  756. package/dist/src/utils/commentJson.js +2 -2
  757. package/dist/src/utils/commentJson.js.map +1 -1
  758. package/dist/src/utils/commentJson.test.js +7 -6
  759. package/dist/src/utils/commentJson.test.js.map +1 -1
  760. package/dist/src/utils/envVarResolver.d.ts +2 -2
  761. package/dist/src/utils/envVarResolver.js +10 -7
  762. package/dist/src/utils/envVarResolver.js.map +1 -1
  763. package/dist/src/utils/errors.d.ts +1 -0
  764. package/dist/src/utils/errors.js +66 -5
  765. package/dist/src/utils/errors.js.map +1 -1
  766. package/dist/src/utils/events.d.ts +11 -2
  767. package/dist/src/utils/events.js +1 -0
  768. package/dist/src/utils/events.js.map +1 -1
  769. package/dist/src/utils/gitUtils.js +3 -2
  770. package/dist/src/utils/gitUtils.js.map +1 -1
  771. package/dist/src/utils/handleAutoUpdate.js +9 -3
  772. package/dist/src/utils/handleAutoUpdate.js.map +1 -1
  773. package/dist/src/utils/handleAutoUpdate.test.d.ts +6 -0
  774. package/dist/src/utils/handleAutoUpdate.test.js +225 -0
  775. package/dist/src/utils/handleAutoUpdate.test.js.map +1 -0
  776. package/dist/src/utils/installationInfo.js +2 -2
  777. package/dist/src/utils/installationInfo.js.map +1 -1
  778. package/dist/src/utils/installationInfo.test.js +8 -4
  779. package/dist/src/utils/installationInfo.test.js.map +1 -1
  780. package/dist/src/utils/readStdin.js +2 -1
  781. package/dist/src/utils/readStdin.js.map +1 -1
  782. package/dist/src/utils/sandbox-macos-permissive-open.sb +2 -0
  783. package/dist/src/utils/sandbox.js +28 -30
  784. package/dist/src/utils/sandbox.js.map +1 -1
  785. package/dist/src/utils/sessionCleanup.js +4 -4
  786. package/dist/src/utils/sessionCleanup.js.map +1 -1
  787. package/dist/src/utils/startupWarnings.test.d.ts +6 -0
  788. package/dist/src/utils/startupWarnings.test.js +61 -0
  789. package/dist/src/utils/startupWarnings.test.js.map +1 -0
  790. package/dist/src/utils/version.js +6 -2
  791. package/dist/src/utils/version.js.map +1 -1
  792. package/dist/src/validateNonInterActiveAuth.js +2 -2
  793. package/dist/src/validateNonInterActiveAuth.js.map +1 -1
  794. package/dist/src/zed-integration/acp.js +2 -1
  795. package/dist/src/zed-integration/acp.js.map +1 -1
  796. package/dist/src/zed-integration/schema.d.ts +4 -4
  797. package/dist/src/zed-integration/zedIntegration.d.ts +2 -2
  798. package/dist/src/zed-integration/zedIntegration.js +16 -25
  799. package/dist/src/zed-integration/zedIntegration.js.map +1 -1
  800. package/dist/tsconfig.tsbuildinfo +1 -1
  801. package/package.json +17 -17
  802. package/dist/src/config/policy.test.js +0 -336
  803. package/dist/src/config/policy.test.js.map +0 -1
  804. package/dist/src/ui/components/WorkspaceMigrationDialog.d.ts +0 -11
  805. package/dist/src/ui/components/WorkspaceMigrationDialog.js +0 -44
  806. package/dist/src/ui/components/WorkspaceMigrationDialog.js.map +0 -1
  807. package/dist/src/ui/hooks/useWorkspaceMigration.d.ts +0 -13
  808. package/dist/src/ui/hooks/useWorkspaceMigration.js +0 -59
  809. package/dist/src/ui/hooks/useWorkspaceMigration.js.map +0 -1
  810. package/dist/src/utils/package.d.ts +0 -12
  811. package/dist/src/utils/package.js +0 -24
  812. package/dist/src/utils/package.js.map +0 -1
  813. /package/dist/src/{config/policy.test.d.ts → commands/extensions/examples/mcp-server/example.d.ts} +0 -0
@@ -0,0 +1,1761 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { describe, it, expect, beforeEach } from 'vitest';
7
+ import stripAnsi from 'strip-ansi';
8
+ import { act } from 'react';
9
+ import { renderHook } from '../../../test-utils/render.js';
10
+ import { useTextBuffer, offsetToLogicalPos, logicalPosToOffset, textBufferReducer, findWordEndInLine, findNextWordStartInLine, isWordCharStrict, } from './text-buffer.js';
11
+ import { cpLen } from '../../utils/textUtils.js';
12
+ const defaultVisualLayout = {
13
+ visualLines: [''],
14
+ logicalToVisualMap: [[[0, 0]]],
15
+ visualToLogicalMap: [[0, 0]],
16
+ };
17
+ const initialState = {
18
+ lines: [''],
19
+ cursorRow: 0,
20
+ cursorCol: 0,
21
+ preferredCol: null,
22
+ undoStack: [],
23
+ redoStack: [],
24
+ clipboard: null,
25
+ selectionAnchor: null,
26
+ viewportWidth: 80,
27
+ viewportHeight: 24,
28
+ visualLayout: defaultVisualLayout,
29
+ };
30
+ describe('textBufferReducer', () => {
31
+ it('should return the initial state if state is undefined', () => {
32
+ const action = { type: 'unknown_action' };
33
+ const state = textBufferReducer(initialState, action);
34
+ expect(state).toHaveOnlyValidCharacters();
35
+ expect(state).toEqual(initialState);
36
+ });
37
+ describe('set_text action', () => {
38
+ it('should set new text and move cursor to the end', () => {
39
+ const action = {
40
+ type: 'set_text',
41
+ payload: 'hello\nworld',
42
+ };
43
+ const state = textBufferReducer(initialState, action);
44
+ expect(state).toHaveOnlyValidCharacters();
45
+ expect(state.lines).toEqual(['hello', 'world']);
46
+ expect(state.cursorRow).toBe(1);
47
+ expect(state.cursorCol).toBe(5);
48
+ expect(state.undoStack.length).toBe(1);
49
+ });
50
+ it('should not create an undo snapshot if pushToUndo is false', () => {
51
+ const action = {
52
+ type: 'set_text',
53
+ payload: 'no undo',
54
+ pushToUndo: false,
55
+ };
56
+ const state = textBufferReducer(initialState, action);
57
+ expect(state).toHaveOnlyValidCharacters();
58
+ expect(state.lines).toEqual(['no undo']);
59
+ expect(state.undoStack.length).toBe(0);
60
+ });
61
+ });
62
+ describe('insert action', () => {
63
+ it('should insert a character', () => {
64
+ const action = { type: 'insert', payload: 'a' };
65
+ const state = textBufferReducer(initialState, action);
66
+ expect(state).toHaveOnlyValidCharacters();
67
+ expect(state.lines).toEqual(['a']);
68
+ expect(state.cursorCol).toBe(1);
69
+ });
70
+ it('should insert a newline', () => {
71
+ const stateWithText = { ...initialState, lines: ['hello'] };
72
+ const action = { type: 'insert', payload: '\n' };
73
+ const state = textBufferReducer(stateWithText, action);
74
+ expect(state).toHaveOnlyValidCharacters();
75
+ expect(state.lines).toEqual(['', 'hello']);
76
+ expect(state.cursorRow).toBe(1);
77
+ expect(state.cursorCol).toBe(0);
78
+ });
79
+ });
80
+ describe('insert action with options', () => {
81
+ it('should filter input using inputFilter option', () => {
82
+ const action = { type: 'insert', payload: 'a1b2c3' };
83
+ const options = {
84
+ inputFilter: (text) => text.replace(/[0-9]/g, ''),
85
+ };
86
+ const state = textBufferReducer(initialState, action, options);
87
+ expect(state.lines).toEqual(['abc']);
88
+ expect(state.cursorCol).toBe(3);
89
+ });
90
+ it('should strip newlines when singleLine option is true', () => {
91
+ const action = {
92
+ type: 'insert',
93
+ payload: 'hello\nworld',
94
+ };
95
+ const options = { singleLine: true };
96
+ const state = textBufferReducer(initialState, action, options);
97
+ expect(state.lines).toEqual(['helloworld']);
98
+ expect(state.cursorCol).toBe(10);
99
+ });
100
+ it('should apply both inputFilter and singleLine options', () => {
101
+ const action = {
102
+ type: 'insert',
103
+ payload: 'h\ne\nl\nl\no\n1\n2\n3',
104
+ };
105
+ const options = {
106
+ singleLine: true,
107
+ inputFilter: (text) => text.replace(/[0-9]/g, ''),
108
+ };
109
+ const state = textBufferReducer(initialState, action, options);
110
+ expect(state.lines).toEqual(['hello']);
111
+ expect(state.cursorCol).toBe(5);
112
+ });
113
+ });
114
+ describe('backspace action', () => {
115
+ it('should remove a character', () => {
116
+ const stateWithText = {
117
+ ...initialState,
118
+ lines: ['a'],
119
+ cursorRow: 0,
120
+ cursorCol: 1,
121
+ };
122
+ const action = { type: 'backspace' };
123
+ const state = textBufferReducer(stateWithText, action);
124
+ expect(state).toHaveOnlyValidCharacters();
125
+ expect(state.lines).toEqual(['']);
126
+ expect(state.cursorCol).toBe(0);
127
+ });
128
+ it('should join lines if at the beginning of a line', () => {
129
+ const stateWithText = {
130
+ ...initialState,
131
+ lines: ['hello', 'world'],
132
+ cursorRow: 1,
133
+ cursorCol: 0,
134
+ };
135
+ const action = { type: 'backspace' };
136
+ const state = textBufferReducer(stateWithText, action);
137
+ expect(state).toHaveOnlyValidCharacters();
138
+ expect(state.lines).toEqual(['helloworld']);
139
+ expect(state.cursorRow).toBe(0);
140
+ expect(state.cursorCol).toBe(5);
141
+ });
142
+ });
143
+ describe('undo/redo actions', () => {
144
+ it('should undo and redo a change', () => {
145
+ // 1. Insert text
146
+ const insertAction = {
147
+ type: 'insert',
148
+ payload: 'test',
149
+ };
150
+ const stateAfterInsert = textBufferReducer(initialState, insertAction);
151
+ expect(stateAfterInsert).toHaveOnlyValidCharacters();
152
+ expect(stateAfterInsert.lines).toEqual(['test']);
153
+ expect(stateAfterInsert.undoStack.length).toBe(1);
154
+ // 2. Undo
155
+ const undoAction = { type: 'undo' };
156
+ const stateAfterUndo = textBufferReducer(stateAfterInsert, undoAction);
157
+ expect(stateAfterUndo).toHaveOnlyValidCharacters();
158
+ expect(stateAfterUndo.lines).toEqual(['']);
159
+ expect(stateAfterUndo.undoStack.length).toBe(0);
160
+ expect(stateAfterUndo.redoStack.length).toBe(1);
161
+ // 3. Redo
162
+ const redoAction = { type: 'redo' };
163
+ const stateAfterRedo = textBufferReducer(stateAfterUndo, redoAction);
164
+ expect(stateAfterRedo).toHaveOnlyValidCharacters();
165
+ expect(stateAfterRedo.lines).toEqual(['test']);
166
+ expect(stateAfterRedo.undoStack.length).toBe(1);
167
+ expect(stateAfterRedo.redoStack.length).toBe(0);
168
+ });
169
+ });
170
+ describe('create_undo_snapshot action', () => {
171
+ it('should create a snapshot without changing state', () => {
172
+ const stateWithText = {
173
+ ...initialState,
174
+ lines: ['hello'],
175
+ cursorRow: 0,
176
+ cursorCol: 5,
177
+ };
178
+ const action = { type: 'create_undo_snapshot' };
179
+ const state = textBufferReducer(stateWithText, action);
180
+ expect(state).toHaveOnlyValidCharacters();
181
+ expect(state.lines).toEqual(['hello']);
182
+ expect(state.cursorRow).toBe(0);
183
+ expect(state.cursorCol).toBe(5);
184
+ expect(state.undoStack.length).toBe(1);
185
+ expect(state.undoStack[0].lines).toEqual(['hello']);
186
+ expect(state.undoStack[0].cursorRow).toBe(0);
187
+ expect(state.undoStack[0].cursorCol).toBe(5);
188
+ });
189
+ });
190
+ describe('delete_word_left action', () => {
191
+ const createSingleLineState = (text, col) => ({
192
+ ...initialState,
193
+ lines: [text],
194
+ cursorRow: 0,
195
+ cursorCol: col,
196
+ });
197
+ it.each([
198
+ {
199
+ input: 'hello world',
200
+ cursorCol: 11,
201
+ expectedLines: ['hello '],
202
+ expectedCol: 6,
203
+ desc: 'simple word',
204
+ },
205
+ {
206
+ input: 'path/to/file',
207
+ cursorCol: 12,
208
+ expectedLines: ['path/to/'],
209
+ expectedCol: 8,
210
+ desc: 'path segment',
211
+ },
212
+ {
213
+ input: 'variable_name',
214
+ cursorCol: 13,
215
+ expectedLines: ['variable_'],
216
+ expectedCol: 9,
217
+ desc: 'variable_name parts',
218
+ },
219
+ ])('should delete $desc', ({ input, cursorCol, expectedLines, expectedCol }) => {
220
+ const state = textBufferReducer(createSingleLineState(input, cursorCol), { type: 'delete_word_left' });
221
+ expect(state.lines).toEqual(expectedLines);
222
+ expect(state.cursorCol).toBe(expectedCol);
223
+ });
224
+ it('should act like backspace at the beginning of a line', () => {
225
+ const stateWithText = {
226
+ ...initialState,
227
+ lines: ['hello', 'world'],
228
+ cursorRow: 1,
229
+ cursorCol: 0,
230
+ };
231
+ const state = textBufferReducer(stateWithText, {
232
+ type: 'delete_word_left',
233
+ });
234
+ expect(state.lines).toEqual(['helloworld']);
235
+ expect(state.cursorRow).toBe(0);
236
+ expect(state.cursorCol).toBe(5);
237
+ });
238
+ });
239
+ describe('delete_word_right action', () => {
240
+ const createSingleLineState = (text, col) => ({
241
+ ...initialState,
242
+ lines: [text],
243
+ cursorRow: 0,
244
+ cursorCol: col,
245
+ });
246
+ it.each([
247
+ {
248
+ input: 'hello world',
249
+ cursorCol: 0,
250
+ expectedLines: ['world'],
251
+ expectedCol: 0,
252
+ desc: 'simple word',
253
+ },
254
+ {
255
+ input: 'variable_name',
256
+ cursorCol: 0,
257
+ expectedLines: ['_name'],
258
+ expectedCol: 0,
259
+ desc: 'variable_name parts',
260
+ },
261
+ ])('should delete $desc', ({ input, cursorCol, expectedLines, expectedCol }) => {
262
+ const state = textBufferReducer(createSingleLineState(input, cursorCol), { type: 'delete_word_right' });
263
+ expect(state.lines).toEqual(expectedLines);
264
+ expect(state.cursorCol).toBe(expectedCol);
265
+ });
266
+ it('should delete path segments progressively', () => {
267
+ const stateWithText = {
268
+ ...initialState,
269
+ lines: ['path/to/file'],
270
+ cursorRow: 0,
271
+ cursorCol: 0,
272
+ };
273
+ let state = textBufferReducer(stateWithText, {
274
+ type: 'delete_word_right',
275
+ });
276
+ expect(state.lines).toEqual(['/to/file']);
277
+ state = textBufferReducer(state, { type: 'delete_word_right' });
278
+ expect(state.lines).toEqual(['to/file']);
279
+ });
280
+ it('should act like delete at the end of a line', () => {
281
+ const stateWithText = {
282
+ ...initialState,
283
+ lines: ['hello', 'world'],
284
+ cursorRow: 0,
285
+ cursorCol: 5,
286
+ };
287
+ const state = textBufferReducer(stateWithText, {
288
+ type: 'delete_word_right',
289
+ });
290
+ expect(state.lines).toEqual(['helloworld']);
291
+ expect(state.cursorRow).toBe(0);
292
+ expect(state.cursorCol).toBe(5);
293
+ });
294
+ });
295
+ });
296
+ const getBufferState = (result) => {
297
+ expect(result.current).toHaveOnlyValidCharacters();
298
+ return {
299
+ text: result.current.text,
300
+ lines: [...result.current.lines], // Clone for safety
301
+ cursor: [...result.current.cursor],
302
+ allVisualLines: [...result.current.allVisualLines],
303
+ viewportVisualLines: [...result.current.viewportVisualLines],
304
+ visualCursor: [...result.current.visualCursor],
305
+ visualScrollRow: result.current.visualScrollRow,
306
+ preferredCol: result.current.preferredCol,
307
+ };
308
+ };
309
+ describe('useTextBuffer', () => {
310
+ let viewport;
311
+ beforeEach(() => {
312
+ viewport = { width: 10, height: 3 }; // Default viewport for tests
313
+ });
314
+ describe('Initialization', () => {
315
+ it('should initialize with empty text and cursor at (0,0) by default', () => {
316
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
317
+ const state = getBufferState(result);
318
+ expect(state.text).toBe('');
319
+ expect(state.lines).toEqual(['']);
320
+ expect(state.cursor).toEqual([0, 0]);
321
+ expect(state.allVisualLines).toEqual(['']);
322
+ expect(state.viewportVisualLines).toEqual(['']);
323
+ expect(state.visualCursor).toEqual([0, 0]);
324
+ expect(state.visualScrollRow).toBe(0);
325
+ });
326
+ it('should initialize with provided initialText', () => {
327
+ const { result } = renderHook(() => useTextBuffer({
328
+ initialText: 'hello',
329
+ viewport,
330
+ isValidPath: () => false,
331
+ }));
332
+ const state = getBufferState(result);
333
+ expect(state.text).toBe('hello');
334
+ expect(state.lines).toEqual(['hello']);
335
+ expect(state.cursor).toEqual([0, 0]); // Default cursor if offset not given
336
+ expect(state.allVisualLines).toEqual(['hello']);
337
+ expect(state.viewportVisualLines).toEqual(['hello']);
338
+ expect(state.visualCursor).toEqual([0, 0]);
339
+ });
340
+ it('should initialize with initialText and initialCursorOffset', () => {
341
+ const { result } = renderHook(() => useTextBuffer({
342
+ initialText: 'hello\nworld',
343
+ initialCursorOffset: 7, // Should be at 'o' in 'world'
344
+ viewport,
345
+ isValidPath: () => false,
346
+ }));
347
+ const state = getBufferState(result);
348
+ expect(state.text).toBe('hello\nworld');
349
+ expect(state.lines).toEqual(['hello', 'world']);
350
+ expect(state.cursor).toEqual([1, 1]); // Logical cursor at 'o' in "world"
351
+ expect(state.allVisualLines).toEqual(['hello', 'world']);
352
+ expect(state.viewportVisualLines).toEqual(['hello', 'world']);
353
+ expect(state.visualCursor[0]).toBe(1); // On the second visual line
354
+ expect(state.visualCursor[1]).toBe(1); // At 'o' in "world"
355
+ });
356
+ it('should wrap visual lines', () => {
357
+ const { result } = renderHook(() => useTextBuffer({
358
+ initialText: 'The quick brown fox jumps over the lazy dog.',
359
+ initialCursorOffset: 2, // After '好'
360
+ viewport: { width: 15, height: 4 },
361
+ isValidPath: () => false,
362
+ }));
363
+ const state = getBufferState(result);
364
+ expect(state.allVisualLines).toEqual([
365
+ 'The quick',
366
+ 'brown fox',
367
+ 'jumps over the',
368
+ 'lazy dog.',
369
+ ]);
370
+ });
371
+ it('should wrap visual lines with multiple spaces', () => {
372
+ const { result } = renderHook(() => useTextBuffer({
373
+ initialText: 'The quick brown fox jumps over the lazy dog.',
374
+ viewport: { width: 15, height: 4 },
375
+ isValidPath: () => false,
376
+ }));
377
+ const state = getBufferState(result);
378
+ // Including multiple spaces at the end of the lines like this is
379
+ // consistent with Google docs behavior and makes it intuitive to edit
380
+ // the spaces as needed.
381
+ expect(state.allVisualLines).toEqual([
382
+ 'The quick ',
383
+ 'brown fox ',
384
+ 'jumps over the',
385
+ 'lazy dog.',
386
+ ]);
387
+ });
388
+ it('should wrap visual lines even without spaces', () => {
389
+ const { result } = renderHook(() => useTextBuffer({
390
+ initialText: '123456789012345ABCDEFG', // 4 chars, 12 bytes
391
+ viewport: { width: 15, height: 2 },
392
+ isValidPath: () => false,
393
+ }));
394
+ const state = getBufferState(result);
395
+ // Including multiple spaces at the end of the lines like this is
396
+ // consistent with Google docs behavior and makes it intuitive to edit
397
+ // the spaces as needed.
398
+ expect(state.allVisualLines).toEqual(['123456789012345', 'ABCDEFG']);
399
+ });
400
+ it('should initialize with multi-byte unicode characters and correct cursor offset', () => {
401
+ const { result } = renderHook(() => useTextBuffer({
402
+ initialText: '你好世界', // 4 chars, 12 bytes
403
+ initialCursorOffset: 2, // After '好'
404
+ viewport: { width: 5, height: 2 },
405
+ isValidPath: () => false,
406
+ }));
407
+ const state = getBufferState(result);
408
+ expect(state.text).toBe('你好世界');
409
+ expect(state.lines).toEqual(['你好世界']);
410
+ expect(state.cursor).toEqual([0, 2]);
411
+ // Visual: "你好" (width 4), "世"界" (width 4) with viewport width 5
412
+ expect(state.allVisualLines).toEqual(['你好', '世界']);
413
+ expect(state.visualCursor).toEqual([1, 0]);
414
+ });
415
+ });
416
+ describe('Basic Editing', () => {
417
+ it('insert: should insert a character and update cursor', () => {
418
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
419
+ act(() => result.current.insert('a'));
420
+ let state = getBufferState(result);
421
+ expect(state.text).toBe('a');
422
+ expect(state.cursor).toEqual([0, 1]);
423
+ expect(state.visualCursor).toEqual([0, 1]);
424
+ act(() => result.current.insert('b'));
425
+ state = getBufferState(result);
426
+ expect(state.text).toBe('ab');
427
+ expect(state.cursor).toEqual([0, 2]);
428
+ expect(state.visualCursor).toEqual([0, 2]);
429
+ });
430
+ it('insert: should insert text in the middle of a line', () => {
431
+ const { result } = renderHook(() => useTextBuffer({
432
+ initialText: 'abc',
433
+ viewport,
434
+ isValidPath: () => false,
435
+ }));
436
+ act(() => result.current.move('right'));
437
+ act(() => result.current.insert('-NEW-'));
438
+ const state = getBufferState(result);
439
+ expect(state.text).toBe('a-NEW-bc');
440
+ expect(state.cursor).toEqual([0, 6]);
441
+ });
442
+ it('newline: should create a new line and move cursor', () => {
443
+ const { result } = renderHook(() => useTextBuffer({
444
+ initialText: 'ab',
445
+ viewport,
446
+ isValidPath: () => false,
447
+ }));
448
+ act(() => result.current.move('end')); // cursor at [0,2]
449
+ act(() => result.current.newline());
450
+ const state = getBufferState(result);
451
+ expect(state.text).toBe('ab\n');
452
+ expect(state.lines).toEqual(['ab', '']);
453
+ expect(state.cursor).toEqual([1, 0]);
454
+ expect(state.allVisualLines).toEqual(['ab', '']);
455
+ expect(state.viewportVisualLines).toEqual(['ab', '']); // viewport height 3
456
+ expect(state.visualCursor).toEqual([1, 0]); // On the new visual line
457
+ });
458
+ it('backspace: should delete char to the left or merge lines', () => {
459
+ const { result } = renderHook(() => useTextBuffer({
460
+ initialText: 'a\nb',
461
+ viewport,
462
+ isValidPath: () => false,
463
+ }));
464
+ act(() => {
465
+ result.current.move('down');
466
+ });
467
+ act(() => {
468
+ result.current.move('end'); // cursor to [1,1] (end of 'b')
469
+ });
470
+ act(() => result.current.backspace()); // delete 'b'
471
+ let state = getBufferState(result);
472
+ expect(state.text).toBe('a\n');
473
+ expect(state.cursor).toEqual([1, 0]);
474
+ act(() => result.current.backspace()); // merge lines
475
+ state = getBufferState(result);
476
+ expect(state.text).toBe('a');
477
+ expect(state.cursor).toEqual([0, 1]); // cursor after 'a'
478
+ expect(state.allVisualLines).toEqual(['a']);
479
+ expect(state.viewportVisualLines).toEqual(['a']);
480
+ expect(state.visualCursor).toEqual([0, 1]);
481
+ });
482
+ it('del: should delete char to the right or merge lines', () => {
483
+ const { result } = renderHook(() => useTextBuffer({
484
+ initialText: 'a\nb',
485
+ viewport,
486
+ isValidPath: () => false,
487
+ }));
488
+ // cursor at [0,0]
489
+ act(() => result.current.del()); // delete 'a'
490
+ let state = getBufferState(result);
491
+ expect(state.text).toBe('\nb');
492
+ expect(state.cursor).toEqual([0, 0]);
493
+ act(() => result.current.del()); // merge lines (deletes newline)
494
+ state = getBufferState(result);
495
+ expect(state.text).toBe('b');
496
+ expect(state.cursor).toEqual([0, 0]);
497
+ expect(state.allVisualLines).toEqual(['b']);
498
+ expect(state.viewportVisualLines).toEqual(['b']);
499
+ expect(state.visualCursor).toEqual([0, 0]);
500
+ });
501
+ });
502
+ describe('Drag and Drop File Paths', () => {
503
+ it('should prepend @ to a valid file path on insert', () => {
504
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => true }));
505
+ const filePath = '/path/to/a/valid/file.txt';
506
+ act(() => result.current.insert(filePath, { paste: true }));
507
+ expect(getBufferState(result).text).toBe(`@${filePath} `);
508
+ });
509
+ it('should not prepend @ to an invalid file path on insert', () => {
510
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
511
+ const notAPath = 'this is just some long text';
512
+ act(() => result.current.insert(notAPath, { paste: true }));
513
+ expect(getBufferState(result).text).toBe(notAPath);
514
+ });
515
+ it('should handle quoted paths', () => {
516
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => true }));
517
+ const filePath = "'/path/to/a/valid/file.txt'";
518
+ act(() => result.current.insert(filePath, { paste: true }));
519
+ expect(getBufferState(result).text).toBe(`@/path/to/a/valid/file.txt `);
520
+ });
521
+ it('should not prepend @ to short text that is not a path', () => {
522
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => true }));
523
+ const shortText = 'ab';
524
+ act(() => result.current.insert(shortText, { paste: true }));
525
+ expect(getBufferState(result).text).toBe(shortText);
526
+ });
527
+ });
528
+ describe('Shell Mode Behavior', () => {
529
+ it('should not prepend @ to valid file paths when shellModeActive is true', () => {
530
+ const { result } = renderHook(() => useTextBuffer({
531
+ viewport,
532
+ isValidPath: () => true,
533
+ shellModeActive: true,
534
+ }));
535
+ const filePath = '/path/to/a/valid/file.txt';
536
+ act(() => result.current.insert(filePath, { paste: true }));
537
+ expect(getBufferState(result).text).toBe(filePath); // No @ prefix
538
+ });
539
+ it('should not prepend @ to quoted paths when shellModeActive is true', () => {
540
+ const { result } = renderHook(() => useTextBuffer({
541
+ viewport,
542
+ isValidPath: () => true,
543
+ shellModeActive: true,
544
+ }));
545
+ const quotedFilePath = "'/path/to/a/valid/file.txt'";
546
+ act(() => result.current.insert(quotedFilePath, { paste: true }));
547
+ expect(getBufferState(result).text).toBe(quotedFilePath); // No @ prefix, keeps quotes
548
+ });
549
+ it('should behave normally with invalid paths when shellModeActive is true', () => {
550
+ const { result } = renderHook(() => useTextBuffer({
551
+ viewport,
552
+ isValidPath: () => false,
553
+ shellModeActive: true,
554
+ }));
555
+ const notAPath = 'this is just some text';
556
+ act(() => result.current.insert(notAPath, { paste: true }));
557
+ expect(getBufferState(result).text).toBe(notAPath);
558
+ });
559
+ it('should behave normally with short text when shellModeActive is true', () => {
560
+ const { result } = renderHook(() => useTextBuffer({
561
+ viewport,
562
+ isValidPath: () => true,
563
+ shellModeActive: true,
564
+ }));
565
+ const shortText = 'ls';
566
+ act(() => result.current.insert(shortText, { paste: true }));
567
+ expect(getBufferState(result).text).toBe(shortText); // No @ prefix for short text
568
+ });
569
+ });
570
+ describe('Cursor Movement', () => {
571
+ it('move: left/right should work within and across visual lines (due to wrapping)', () => {
572
+ // Text: "long line1next line2" (20 chars)
573
+ // Viewport width 5. Word wrapping should produce:
574
+ // "long " (5)
575
+ // "line1" (5)
576
+ // "next " (5)
577
+ // "line2" (5)
578
+ const { result } = renderHook(() => useTextBuffer({
579
+ initialText: 'long line1next line2', // Corrected: was 'long line1next line2'
580
+ viewport: { width: 5, height: 4 },
581
+ isValidPath: () => false,
582
+ }));
583
+ // Initial cursor [0,0] logical, visual [0,0] ("l" of "long ")
584
+ act(() => result.current.move('right')); // visual [0,1] ("o")
585
+ expect(getBufferState(result).visualCursor).toEqual([0, 1]);
586
+ act(() => result.current.move('right')); // visual [0,2] ("n")
587
+ act(() => result.current.move('right')); // visual [0,3] ("g")
588
+ act(() => result.current.move('right')); // visual [0,4] (" ")
589
+ expect(getBufferState(result).visualCursor).toEqual([0, 4]);
590
+ act(() => result.current.move('right')); // visual [1,0] ("l" of "line1")
591
+ expect(getBufferState(result).visualCursor).toEqual([1, 0]);
592
+ expect(getBufferState(result).cursor).toEqual([0, 5]); // logical cursor
593
+ act(() => result.current.move('left')); // visual [0,4] (" " of "long ")
594
+ expect(getBufferState(result).visualCursor).toEqual([0, 4]);
595
+ expect(getBufferState(result).cursor).toEqual([0, 4]); // logical cursor
596
+ });
597
+ it('move: up/down should preserve preferred visual column', () => {
598
+ const text = 'abcde\nxy\n12345';
599
+ const { result } = renderHook(() => useTextBuffer({
600
+ initialText: text,
601
+ viewport,
602
+ isValidPath: () => false,
603
+ }));
604
+ expect(result.current.allVisualLines).toEqual(['abcde', 'xy', '12345']);
605
+ // Place cursor at the end of "abcde" -> logical [0,5]
606
+ act(() => {
607
+ result.current.move('home'); // to [0,0]
608
+ });
609
+ for (let i = 0; i < 5; i++) {
610
+ act(() => {
611
+ result.current.move('right'); // to [0,5]
612
+ });
613
+ }
614
+ expect(getBufferState(result).cursor).toEqual([0, 5]);
615
+ expect(getBufferState(result).visualCursor).toEqual([0, 5]);
616
+ // Set preferredCol by moving up then down to the same spot, then test.
617
+ act(() => {
618
+ result.current.move('down'); // to xy, logical [1,2], visual [1,2], preferredCol should be 5
619
+ });
620
+ let state = getBufferState(result);
621
+ expect(state.cursor).toEqual([1, 2]); // Logical cursor at end of 'xy'
622
+ expect(state.visualCursor).toEqual([1, 2]); // Visual cursor at end of 'xy'
623
+ expect(state.preferredCol).toBe(5);
624
+ act(() => result.current.move('down')); // to '12345', preferredCol=5.
625
+ state = getBufferState(result);
626
+ expect(state.cursor).toEqual([2, 5]); // Logical cursor at end of '12345'
627
+ expect(state.visualCursor).toEqual([2, 5]); // Visual cursor at end of '12345'
628
+ expect(state.preferredCol).toBe(5); // Preferred col is maintained
629
+ act(() => result.current.move('left')); // preferredCol should reset
630
+ state = getBufferState(result);
631
+ expect(state.preferredCol).toBe(null);
632
+ });
633
+ it('move: home/end should go to visual line start/end', () => {
634
+ const initialText = 'line one\nsecond line';
635
+ const { result } = renderHook(() => useTextBuffer({
636
+ initialText,
637
+ viewport: { width: 5, height: 5 },
638
+ isValidPath: () => false,
639
+ }));
640
+ expect(result.current.allVisualLines).toEqual([
641
+ 'line',
642
+ 'one',
643
+ 'secon',
644
+ 'd',
645
+ 'line',
646
+ ]);
647
+ // Initial cursor [0,0] (start of "line")
648
+ act(() => result.current.move('down')); // visual cursor from [0,0] to [1,0] ("o" of "one")
649
+ act(() => result.current.move('right')); // visual cursor to [1,1] ("n" of "one")
650
+ expect(getBufferState(result).visualCursor).toEqual([1, 1]);
651
+ act(() => result.current.move('home')); // visual cursor to [1,0] (start of "one")
652
+ expect(getBufferState(result).visualCursor).toEqual([1, 0]);
653
+ act(() => result.current.move('end')); // visual cursor to [1,3] (end of "one")
654
+ expect(getBufferState(result).visualCursor).toEqual([1, 3]); // "one" is 3 chars
655
+ });
656
+ });
657
+ describe('Visual Layout & Viewport', () => {
658
+ it('should wrap long lines correctly into visualLines', () => {
659
+ const { result } = renderHook(() => useTextBuffer({
660
+ initialText: 'This is a very long line of text.', // 33 chars
661
+ viewport: { width: 10, height: 5 },
662
+ isValidPath: () => false,
663
+ }));
664
+ const state = getBufferState(result);
665
+ // Expected visual lines with word wrapping (viewport width 10):
666
+ // "This is a"
667
+ // "very long"
668
+ // "line of"
669
+ // "text."
670
+ expect(state.allVisualLines.length).toBe(4);
671
+ expect(state.allVisualLines[0]).toBe('This is a');
672
+ expect(state.allVisualLines[1]).toBe('very long');
673
+ expect(state.allVisualLines[2]).toBe('line of');
674
+ expect(state.allVisualLines[3]).toBe('text.');
675
+ });
676
+ it('should update visualScrollRow when visualCursor moves out of viewport', () => {
677
+ const { result } = renderHook(() => useTextBuffer({
678
+ initialText: 'l1\nl2\nl3\nl4\nl5',
679
+ viewport: { width: 5, height: 3 }, // Can show 3 visual lines
680
+ isValidPath: () => false,
681
+ }));
682
+ // Initial: l1, l2, l3 visible. visualScrollRow = 0. visualCursor = [0,0]
683
+ expect(getBufferState(result).visualScrollRow).toBe(0);
684
+ expect(getBufferState(result).allVisualLines).toEqual([
685
+ 'l1',
686
+ 'l2',
687
+ 'l3',
688
+ 'l4',
689
+ 'l5',
690
+ ]);
691
+ expect(getBufferState(result).viewportVisualLines).toEqual([
692
+ 'l1',
693
+ 'l2',
694
+ 'l3',
695
+ ]);
696
+ act(() => result.current.move('down')); // vc=[1,0]
697
+ act(() => result.current.move('down')); // vc=[2,0] (l3)
698
+ expect(getBufferState(result).visualScrollRow).toBe(0);
699
+ act(() => result.current.move('down')); // vc=[3,0] (l4) - scroll should happen
700
+ // Now: l2, l3, l4 visible. visualScrollRow = 1.
701
+ let state = getBufferState(result);
702
+ expect(state.visualScrollRow).toBe(1);
703
+ expect(state.allVisualLines).toEqual(['l1', 'l2', 'l3', 'l4', 'l5']);
704
+ expect(state.viewportVisualLines).toEqual(['l2', 'l3', 'l4']);
705
+ expect(state.visualCursor).toEqual([3, 0]);
706
+ act(() => result.current.move('up')); // vc=[2,0] (l3)
707
+ act(() => result.current.move('up')); // vc=[1,0] (l2)
708
+ expect(getBufferState(result).visualScrollRow).toBe(1);
709
+ act(() => result.current.move('up')); // vc=[0,0] (l1) - scroll up
710
+ // Now: l1, l2, l3 visible. visualScrollRow = 0
711
+ state = getBufferState(result); // Assign to the existing `state` variable
712
+ expect(state.visualScrollRow).toBe(0);
713
+ expect(state.allVisualLines).toEqual(['l1', 'l2', 'l3', 'l4', 'l5']);
714
+ expect(state.viewportVisualLines).toEqual(['l1', 'l2', 'l3']);
715
+ expect(state.visualCursor).toEqual([0, 0]);
716
+ });
717
+ });
718
+ describe('Undo/Redo', () => {
719
+ it('should undo and redo an insert operation', () => {
720
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
721
+ act(() => result.current.insert('a'));
722
+ expect(getBufferState(result).text).toBe('a');
723
+ act(() => result.current.undo());
724
+ expect(getBufferState(result).text).toBe('');
725
+ expect(getBufferState(result).cursor).toEqual([0, 0]);
726
+ act(() => result.current.redo());
727
+ expect(getBufferState(result).text).toBe('a');
728
+ expect(getBufferState(result).cursor).toEqual([0, 1]);
729
+ });
730
+ it('should undo and redo a newline operation', () => {
731
+ const { result } = renderHook(() => useTextBuffer({
732
+ initialText: 'test',
733
+ viewport,
734
+ isValidPath: () => false,
735
+ }));
736
+ act(() => result.current.move('end'));
737
+ act(() => result.current.newline());
738
+ expect(getBufferState(result).text).toBe('test\n');
739
+ act(() => result.current.undo());
740
+ expect(getBufferState(result).text).toBe('test');
741
+ expect(getBufferState(result).cursor).toEqual([0, 4]);
742
+ act(() => result.current.redo());
743
+ expect(getBufferState(result).text).toBe('test\n');
744
+ expect(getBufferState(result).cursor).toEqual([1, 0]);
745
+ });
746
+ });
747
+ describe('Unicode Handling', () => {
748
+ it('insert: should correctly handle multi-byte unicode characters', () => {
749
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
750
+ act(() => result.current.insert('你好'));
751
+ const state = getBufferState(result);
752
+ expect(state.text).toBe('你好');
753
+ expect(state.cursor).toEqual([0, 2]); // Cursor is 2 (char count)
754
+ expect(state.visualCursor).toEqual([0, 2]);
755
+ });
756
+ it('backspace: should correctly delete multi-byte unicode characters', () => {
757
+ const { result } = renderHook(() => useTextBuffer({
758
+ initialText: '你好',
759
+ viewport,
760
+ isValidPath: () => false,
761
+ }));
762
+ act(() => result.current.move('end')); // cursor at [0,2]
763
+ act(() => result.current.backspace()); // delete '好'
764
+ let state = getBufferState(result);
765
+ expect(state.text).toBe('你');
766
+ expect(state.cursor).toEqual([0, 1]);
767
+ act(() => result.current.backspace()); // delete '你'
768
+ state = getBufferState(result);
769
+ expect(state.text).toBe('');
770
+ expect(state.cursor).toEqual([0, 0]);
771
+ });
772
+ it('move: left/right should treat multi-byte chars as single units for visual cursor', () => {
773
+ const { result } = renderHook(() => useTextBuffer({
774
+ initialText: '🐶🐱',
775
+ viewport: { width: 5, height: 1 },
776
+ isValidPath: () => false,
777
+ }));
778
+ // Initial: visualCursor [0,0]
779
+ act(() => result.current.move('right')); // visualCursor [0,1] (after 🐶)
780
+ let state = getBufferState(result);
781
+ expect(state.cursor).toEqual([0, 1]);
782
+ expect(state.visualCursor).toEqual([0, 1]);
783
+ act(() => result.current.move('right')); // visualCursor [0,2] (after 🐱)
784
+ state = getBufferState(result);
785
+ expect(state.cursor).toEqual([0, 2]);
786
+ expect(state.visualCursor).toEqual([0, 2]);
787
+ act(() => result.current.move('left')); // visualCursor [0,1] (before 🐱 / after 🐶)
788
+ state = getBufferState(result);
789
+ expect(state.cursor).toEqual([0, 1]);
790
+ expect(state.visualCursor).toEqual([0, 1]);
791
+ });
792
+ });
793
+ describe('handleInput', () => {
794
+ it('should insert printable characters', () => {
795
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
796
+ act(() => result.current.handleInput({
797
+ name: 'h',
798
+ ctrl: false,
799
+ meta: false,
800
+ shift: false,
801
+ paste: false,
802
+ sequence: 'h',
803
+ }));
804
+ act(() => result.current.handleInput({
805
+ name: 'i',
806
+ ctrl: false,
807
+ meta: false,
808
+ shift: false,
809
+ paste: false,
810
+ sequence: 'i',
811
+ }));
812
+ expect(getBufferState(result).text).toBe('hi');
813
+ });
814
+ it('should handle "Enter" key as newline', () => {
815
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
816
+ act(() => result.current.handleInput({
817
+ name: 'return',
818
+ ctrl: false,
819
+ meta: false,
820
+ shift: false,
821
+ paste: false,
822
+ sequence: '\r',
823
+ }));
824
+ expect(getBufferState(result).lines).toEqual(['', '']);
825
+ });
826
+ it('should do nothing for a tab key press', () => {
827
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
828
+ act(() => result.current.handleInput({
829
+ name: 'tab',
830
+ ctrl: false,
831
+ meta: false,
832
+ shift: false,
833
+ paste: false,
834
+ sequence: '\t',
835
+ }));
836
+ expect(getBufferState(result).text).toBe('');
837
+ });
838
+ it('should do nothing for a shift tab key press', () => {
839
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
840
+ act(() => result.current.handleInput({
841
+ name: 'tab',
842
+ ctrl: false,
843
+ meta: false,
844
+ shift: true,
845
+ paste: false,
846
+ sequence: '\u001b[9;2u',
847
+ }));
848
+ expect(getBufferState(result).text).toBe('');
849
+ });
850
+ it('should handle "Backspace" key', () => {
851
+ const { result } = renderHook(() => useTextBuffer({
852
+ initialText: 'a',
853
+ viewport,
854
+ isValidPath: () => false,
855
+ }));
856
+ act(() => result.current.move('end'));
857
+ act(() => result.current.handleInput({
858
+ name: 'backspace',
859
+ ctrl: false,
860
+ meta: false,
861
+ shift: false,
862
+ paste: false,
863
+ sequence: '\x7f',
864
+ }));
865
+ expect(getBufferState(result).text).toBe('');
866
+ });
867
+ it('should handle multiple delete characters in one input', () => {
868
+ const { result } = renderHook(() => useTextBuffer({
869
+ initialText: 'abcde',
870
+ viewport,
871
+ isValidPath: () => false,
872
+ }));
873
+ act(() => result.current.move('end')); // cursor at the end
874
+ expect(getBufferState(result).cursor).toEqual([0, 5]);
875
+ act(() => {
876
+ result.current.handleInput({
877
+ name: 'backspace',
878
+ ctrl: false,
879
+ meta: false,
880
+ shift: false,
881
+ paste: false,
882
+ sequence: '\x7f',
883
+ });
884
+ result.current.handleInput({
885
+ name: 'backspace',
886
+ ctrl: false,
887
+ meta: false,
888
+ shift: false,
889
+ paste: false,
890
+ sequence: '\x7f',
891
+ });
892
+ result.current.handleInput({
893
+ name: 'backspace',
894
+ ctrl: false,
895
+ meta: false,
896
+ shift: false,
897
+ paste: false,
898
+ sequence: '\x7f',
899
+ });
900
+ });
901
+ expect(getBufferState(result).text).toBe('ab');
902
+ expect(getBufferState(result).cursor).toEqual([0, 2]);
903
+ });
904
+ it('should handle inserts that contain delete characters', () => {
905
+ const { result } = renderHook(() => useTextBuffer({
906
+ initialText: 'abcde',
907
+ viewport,
908
+ isValidPath: () => false,
909
+ }));
910
+ act(() => result.current.move('end')); // cursor at the end
911
+ expect(getBufferState(result).cursor).toEqual([0, 5]);
912
+ act(() => {
913
+ result.current.insert('\x7f\x7f\x7f');
914
+ });
915
+ expect(getBufferState(result).text).toBe('ab');
916
+ expect(getBufferState(result).cursor).toEqual([0, 2]);
917
+ });
918
+ it('should handle inserts with a mix of regular and delete characters', () => {
919
+ const { result } = renderHook(() => useTextBuffer({
920
+ initialText: 'abcde',
921
+ viewport,
922
+ isValidPath: () => false,
923
+ }));
924
+ act(() => result.current.move('end')); // cursor at the end
925
+ expect(getBufferState(result).cursor).toEqual([0, 5]);
926
+ act(() => {
927
+ result.current.insert('\x7fI\x7f\x7fNEW');
928
+ });
929
+ expect(getBufferState(result).text).toBe('abcNEW');
930
+ expect(getBufferState(result).cursor).toEqual([0, 6]);
931
+ });
932
+ it('should handle arrow keys for movement', () => {
933
+ const { result } = renderHook(() => useTextBuffer({
934
+ initialText: 'ab',
935
+ viewport,
936
+ isValidPath: () => false,
937
+ }));
938
+ act(() => result.current.move('end')); // cursor [0,2]
939
+ act(() => result.current.handleInput({
940
+ name: 'left',
941
+ ctrl: false,
942
+ meta: false,
943
+ shift: false,
944
+ paste: false,
945
+ sequence: '\x1b[D',
946
+ })); // cursor [0,1]
947
+ expect(getBufferState(result).cursor).toEqual([0, 1]);
948
+ act(() => result.current.handleInput({
949
+ name: 'right',
950
+ ctrl: false,
951
+ meta: false,
952
+ shift: false,
953
+ paste: false,
954
+ sequence: '\x1b[C',
955
+ })); // cursor [0,2]
956
+ expect(getBufferState(result).cursor).toEqual([0, 2]);
957
+ });
958
+ it('should strip ANSI escape codes when pasting text', () => {
959
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
960
+ const textWithAnsi = '\x1B[31mHello\x1B[0m \x1B[32mWorld\x1B[0m';
961
+ // Simulate pasting by calling handleInput with a string longer than 1 char
962
+ act(() => result.current.handleInput({
963
+ name: '',
964
+ ctrl: false,
965
+ meta: false,
966
+ shift: false,
967
+ paste: false,
968
+ sequence: textWithAnsi,
969
+ }));
970
+ expect(getBufferState(result).text).toBe('Hello World');
971
+ });
972
+ it('should handle VSCode terminal Shift+Enter as newline', () => {
973
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
974
+ act(() => result.current.handleInput({
975
+ name: 'return',
976
+ ctrl: false,
977
+ meta: false,
978
+ shift: true,
979
+ paste: false,
980
+ sequence: '\r',
981
+ })); // Simulates Shift+Enter in VSCode terminal
982
+ expect(getBufferState(result).lines).toEqual(['', '']);
983
+ });
984
+ it('should correctly handle repeated pasting of long text', () => {
985
+ const longText = `not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
986
+
987
+ Why do we use it?
988
+ It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
989
+
990
+ Where does it come from?
991
+ Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lore
992
+ `;
993
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
994
+ // Simulate pasting the long text multiple times
995
+ act(() => {
996
+ result.current.insert(longText, { paste: true });
997
+ result.current.insert(longText, { paste: true });
998
+ result.current.insert(longText, { paste: true });
999
+ });
1000
+ const state = getBufferState(result);
1001
+ // Check that the text is the result of three concatenations.
1002
+ expect(state.lines).toStrictEqual((longText + longText + longText).split('\n'));
1003
+ const expectedCursorPos = offsetToLogicalPos(state.text, state.text.length);
1004
+ expect(state.cursor).toEqual(expectedCursorPos);
1005
+ });
1006
+ });
1007
+ // More tests would be needed for:
1008
+ // - setText, replaceRange
1009
+ // - deleteWordLeft, deleteWordRight
1010
+ // - More complex undo/redo scenarios
1011
+ // - Selection and clipboard (copy/paste) - might need clipboard API mocks or internal state check
1012
+ // - openInExternalEditor (heavy mocking of fs, child_process, os)
1013
+ // - All edge cases for visual scrolling and wrapping with different viewport sizes and text content.
1014
+ describe('replaceRange', () => {
1015
+ it('should replace a single-line range with single-line text', () => {
1016
+ const { result } = renderHook(() => useTextBuffer({
1017
+ initialText: '@pac',
1018
+ viewport,
1019
+ isValidPath: () => false,
1020
+ }));
1021
+ act(() => result.current.replaceRange(0, 1, 0, 4, 'packages'));
1022
+ const state = getBufferState(result);
1023
+ expect(state.text).toBe('@packages');
1024
+ expect(state.cursor).toEqual([0, 9]); // cursor after 'typescript'
1025
+ });
1026
+ it('should replace a multi-line range with single-line text', () => {
1027
+ const { result } = renderHook(() => useTextBuffer({
1028
+ initialText: 'hello\nworld\nagain',
1029
+ viewport,
1030
+ isValidPath: () => false,
1031
+ }));
1032
+ act(() => result.current.replaceRange(0, 2, 1, 3, ' new ')); // replace 'llo\nwor' with ' new '
1033
+ const state = getBufferState(result);
1034
+ expect(state.text).toBe('he new ld\nagain');
1035
+ expect(state.cursor).toEqual([0, 7]); // cursor after ' new '
1036
+ });
1037
+ it('should delete a range when replacing with an empty string', () => {
1038
+ const { result } = renderHook(() => useTextBuffer({
1039
+ initialText: 'hello world',
1040
+ viewport,
1041
+ isValidPath: () => false,
1042
+ }));
1043
+ act(() => result.current.replaceRange(0, 5, 0, 11, '')); // delete ' world'
1044
+ const state = getBufferState(result);
1045
+ expect(state.text).toBe('hello');
1046
+ expect(state.cursor).toEqual([0, 5]);
1047
+ });
1048
+ it('should handle replacing at the beginning of the text', () => {
1049
+ const { result } = renderHook(() => useTextBuffer({
1050
+ initialText: 'world',
1051
+ viewport,
1052
+ isValidPath: () => false,
1053
+ }));
1054
+ act(() => result.current.replaceRange(0, 0, 0, 0, 'hello '));
1055
+ const state = getBufferState(result);
1056
+ expect(state.text).toBe('hello world');
1057
+ expect(state.cursor).toEqual([0, 6]);
1058
+ });
1059
+ it('should handle replacing at the end of the text', () => {
1060
+ const { result } = renderHook(() => useTextBuffer({
1061
+ initialText: 'hello',
1062
+ viewport,
1063
+ isValidPath: () => false,
1064
+ }));
1065
+ act(() => result.current.replaceRange(0, 5, 0, 5, ' world'));
1066
+ const state = getBufferState(result);
1067
+ expect(state.text).toBe('hello world');
1068
+ expect(state.cursor).toEqual([0, 11]);
1069
+ });
1070
+ it('should handle replacing the entire buffer content', () => {
1071
+ const { result } = renderHook(() => useTextBuffer({
1072
+ initialText: 'old text',
1073
+ viewport,
1074
+ isValidPath: () => false,
1075
+ }));
1076
+ act(() => result.current.replaceRange(0, 0, 0, 8, 'new text'));
1077
+ const state = getBufferState(result);
1078
+ expect(state.text).toBe('new text');
1079
+ expect(state.cursor).toEqual([0, 8]);
1080
+ });
1081
+ it('should correctly replace with unicode characters', () => {
1082
+ const { result } = renderHook(() => useTextBuffer({
1083
+ initialText: 'hello *** world',
1084
+ viewport,
1085
+ isValidPath: () => false,
1086
+ }));
1087
+ act(() => result.current.replaceRange(0, 6, 0, 9, '你好'));
1088
+ const state = getBufferState(result);
1089
+ expect(state.text).toBe('hello 你好 world');
1090
+ expect(state.cursor).toEqual([0, 8]); // after '你好'
1091
+ });
1092
+ it('should handle invalid range by returning false and not changing text', () => {
1093
+ const { result } = renderHook(() => useTextBuffer({
1094
+ initialText: 'test',
1095
+ viewport,
1096
+ isValidPath: () => false,
1097
+ }));
1098
+ act(() => {
1099
+ result.current.replaceRange(0, 5, 0, 3, 'fail'); // startCol > endCol in same line
1100
+ });
1101
+ expect(getBufferState(result).text).toBe('test');
1102
+ act(() => {
1103
+ result.current.replaceRange(1, 0, 0, 0, 'fail'); // startRow > endRow
1104
+ });
1105
+ expect(getBufferState(result).text).toBe('test');
1106
+ });
1107
+ it('replaceRange: multiple lines with a single character', () => {
1108
+ const { result } = renderHook(() => useTextBuffer({
1109
+ initialText: 'first\nsecond\nthird',
1110
+ viewport,
1111
+ isValidPath: () => false,
1112
+ }));
1113
+ act(() => result.current.replaceRange(0, 2, 2, 3, 'X')); // Replace 'rst\nsecond\nthi'
1114
+ const state = getBufferState(result);
1115
+ expect(state.text).toBe('fiXrd');
1116
+ expect(state.cursor).toEqual([0, 3]); // After 'X'
1117
+ });
1118
+ it('should replace a single-line range with multi-line text', () => {
1119
+ const { result } = renderHook(() => useTextBuffer({
1120
+ initialText: 'one two three',
1121
+ viewport,
1122
+ isValidPath: () => false,
1123
+ }));
1124
+ // Replace "two" with "new\nline"
1125
+ act(() => result.current.replaceRange(0, 4, 0, 7, 'new\nline'));
1126
+ const state = getBufferState(result);
1127
+ expect(state.lines).toEqual(['one new', 'line three']);
1128
+ expect(state.text).toBe('one new\nline three');
1129
+ expect(state.cursor).toEqual([1, 4]); // cursor after 'line'
1130
+ });
1131
+ });
1132
+ describe('Input Sanitization', () => {
1133
+ const createInput = (sequence) => ({
1134
+ name: '',
1135
+ ctrl: false,
1136
+ meta: false,
1137
+ shift: false,
1138
+ paste: false,
1139
+ sequence,
1140
+ });
1141
+ it.each([
1142
+ {
1143
+ input: '\x1B[31mHello\x1B[0m \x1B[32mWorld\x1B[0m',
1144
+ expected: 'Hello World',
1145
+ desc: 'ANSI escape codes',
1146
+ },
1147
+ {
1148
+ input: 'H\x07e\x08l\x0Bl\x0Co',
1149
+ expected: 'Hello',
1150
+ desc: 'control characters',
1151
+ },
1152
+ {
1153
+ input: '\u001B[4mH\u001B[0mello',
1154
+ expected: 'Hello',
1155
+ desc: 'mixed ANSI and control characters',
1156
+ },
1157
+ {
1158
+ input: '\u001B[4mPasted\u001B[4m Text',
1159
+ expected: 'Pasted Text',
1160
+ desc: 'pasted text with ANSI',
1161
+ },
1162
+ ])('should strip $desc from input', ({ input, expected }) => {
1163
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
1164
+ act(() => result.current.handleInput(createInput(input)));
1165
+ expect(getBufferState(result).text).toBe(expected);
1166
+ });
1167
+ it('should not strip standard characters or newlines', () => {
1168
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
1169
+ const validText = 'Hello World\nThis is a test.';
1170
+ act(() => result.current.handleInput(createInput(validText)));
1171
+ expect(getBufferState(result).text).toBe(validText);
1172
+ });
1173
+ it('should sanitize large text (>5000 chars) and strip unsafe characters', () => {
1174
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
1175
+ const unsafeChars = '\x07\x08\x0B\x0C';
1176
+ const largeTextWithUnsafe = 'safe text'.repeat(600) + unsafeChars + 'more safe text';
1177
+ expect(largeTextWithUnsafe.length).toBeGreaterThan(5000);
1178
+ act(() => result.current.handleInput({
1179
+ name: '',
1180
+ ctrl: false,
1181
+ meta: false,
1182
+ shift: false,
1183
+ paste: false,
1184
+ sequence: largeTextWithUnsafe,
1185
+ }));
1186
+ const resultText = getBufferState(result).text;
1187
+ expect(resultText).not.toContain('\x07');
1188
+ expect(resultText).not.toContain('\x08');
1189
+ expect(resultText).not.toContain('\x0B');
1190
+ expect(resultText).not.toContain('\x0C');
1191
+ expect(resultText).toContain('safe text');
1192
+ expect(resultText).toContain('more safe text');
1193
+ });
1194
+ it('should sanitize large ANSI text (>5000 chars) and strip escape codes', () => {
1195
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
1196
+ const largeTextWithAnsi = '\x1B[31m' +
1197
+ 'red text'.repeat(800) +
1198
+ '\x1B[0m' +
1199
+ '\x1B[32m' +
1200
+ 'green text'.repeat(200) +
1201
+ '\x1B[0m';
1202
+ expect(largeTextWithAnsi.length).toBeGreaterThan(5000);
1203
+ act(() => result.current.handleInput({
1204
+ name: '',
1205
+ ctrl: false,
1206
+ meta: false,
1207
+ shift: false,
1208
+ paste: false,
1209
+ sequence: largeTextWithAnsi,
1210
+ }));
1211
+ const resultText = getBufferState(result).text;
1212
+ expect(resultText).not.toContain('\x1B[31m');
1213
+ expect(resultText).not.toContain('\x1B[32m');
1214
+ expect(resultText).not.toContain('\x1B[0m');
1215
+ expect(resultText).toContain('red text');
1216
+ expect(resultText).toContain('green text');
1217
+ });
1218
+ it('should not strip popular emojis', () => {
1219
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath: () => false }));
1220
+ const emojis = '🐍🐳🦀🦄';
1221
+ act(() => result.current.handleInput({
1222
+ name: '',
1223
+ ctrl: false,
1224
+ meta: false,
1225
+ shift: false,
1226
+ paste: false,
1227
+ sequence: emojis,
1228
+ }));
1229
+ expect(getBufferState(result).text).toBe(emojis);
1230
+ });
1231
+ });
1232
+ describe('inputFilter', () => {
1233
+ it('should filter input based on the provided filter function', () => {
1234
+ const { result } = renderHook(() => useTextBuffer({
1235
+ viewport,
1236
+ isValidPath: () => false,
1237
+ inputFilter: (text) => text.replace(/[^0-9]/g, ''),
1238
+ }));
1239
+ act(() => result.current.insert('a1b2c3'));
1240
+ expect(getBufferState(result).text).toBe('123');
1241
+ });
1242
+ it('should handle empty result from filter', () => {
1243
+ const { result } = renderHook(() => useTextBuffer({
1244
+ viewport,
1245
+ isValidPath: () => false,
1246
+ inputFilter: (text) => text.replace(/[^0-9]/g, ''),
1247
+ }));
1248
+ act(() => result.current.insert('abc'));
1249
+ expect(getBufferState(result).text).toBe('');
1250
+ });
1251
+ it('should filter pasted text', () => {
1252
+ const { result } = renderHook(() => useTextBuffer({
1253
+ viewport,
1254
+ isValidPath: () => false,
1255
+ inputFilter: (text) => text.toUpperCase(),
1256
+ }));
1257
+ act(() => result.current.insert('hello', { paste: true }));
1258
+ expect(getBufferState(result).text).toBe('HELLO');
1259
+ });
1260
+ it('should not filter newlines if they are allowed by the filter', () => {
1261
+ const { result } = renderHook(() => useTextBuffer({
1262
+ viewport,
1263
+ isValidPath: () => false,
1264
+ inputFilter: (text) => text, // Allow everything including newlines
1265
+ }));
1266
+ act(() => result.current.insert('a\nb'));
1267
+ // The insert function splits by newline and inserts separately if it detects them.
1268
+ // If the filter allows them, they should be handled correctly by the subsequent logic in insert.
1269
+ expect(getBufferState(result).text).toBe('a\nb');
1270
+ });
1271
+ it('should filter before newline check in insert', () => {
1272
+ const { result } = renderHook(() => useTextBuffer({
1273
+ viewport,
1274
+ isValidPath: () => false,
1275
+ inputFilter: (text) => text.replace(/\n/g, ''), // Filter out newlines
1276
+ }));
1277
+ act(() => result.current.insert('a\nb'));
1278
+ expect(getBufferState(result).text).toBe('ab');
1279
+ });
1280
+ });
1281
+ describe('stripAnsi', () => {
1282
+ it('should correctly strip ANSI escape codes', () => {
1283
+ const textWithAnsi = '\x1B[31mHello\x1B[0m World';
1284
+ expect(stripAnsi(textWithAnsi)).toBe('Hello World');
1285
+ });
1286
+ it('should handle multiple ANSI codes', () => {
1287
+ const textWithMultipleAnsi = '\x1B[1m\x1B[34mBold Blue\x1B[0m Text';
1288
+ expect(stripAnsi(textWithMultipleAnsi)).toBe('Bold Blue Text');
1289
+ });
1290
+ it('should not modify text without ANSI codes', () => {
1291
+ const plainText = 'Plain text';
1292
+ expect(stripAnsi(plainText)).toBe('Plain text');
1293
+ });
1294
+ it('should handle empty string', () => {
1295
+ expect(stripAnsi('')).toBe('');
1296
+ });
1297
+ });
1298
+ describe('Memoization', () => {
1299
+ it('should keep action references stable across re-renders', () => {
1300
+ // We pass a stable `isValidPath` so that callbacks that depend on it
1301
+ // are not recreated on every render.
1302
+ const isValidPath = () => false;
1303
+ const { result, rerender } = renderHook(() => useTextBuffer({ viewport, isValidPath }));
1304
+ const initialInsert = result.current.insert;
1305
+ const initialBackspace = result.current.backspace;
1306
+ const initialMove = result.current.move;
1307
+ const initialHandleInput = result.current.handleInput;
1308
+ rerender();
1309
+ expect(result.current.insert).toBe(initialInsert);
1310
+ expect(result.current.backspace).toBe(initialBackspace);
1311
+ expect(result.current.move).toBe(initialMove);
1312
+ expect(result.current.handleInput).toBe(initialHandleInput);
1313
+ });
1314
+ it('should have memoized actions that operate on the latest state', () => {
1315
+ const isValidPath = () => false;
1316
+ const { result } = renderHook(() => useTextBuffer({ viewport, isValidPath }));
1317
+ // Store a reference to the memoized insert function.
1318
+ const memoizedInsert = result.current.insert;
1319
+ // Update the buffer state.
1320
+ act(() => {
1321
+ result.current.insert('hello');
1322
+ });
1323
+ expect(getBufferState(result).text).toBe('hello');
1324
+ // Now, call the original memoized function reference.
1325
+ act(() => {
1326
+ memoizedInsert(' world');
1327
+ });
1328
+ // It should have operated on the updated state.
1329
+ expect(getBufferState(result).text).toBe('hello world');
1330
+ });
1331
+ });
1332
+ describe('singleLine mode', () => {
1333
+ it('should not insert a newline character when singleLine is true', () => {
1334
+ const { result } = renderHook(() => useTextBuffer({
1335
+ viewport,
1336
+ isValidPath: () => false,
1337
+ singleLine: true,
1338
+ }));
1339
+ act(() => result.current.insert('\n'));
1340
+ const state = getBufferState(result);
1341
+ expect(state.text).toBe('');
1342
+ expect(state.lines).toEqual(['']);
1343
+ });
1344
+ it('should not create a new line when newline() is called and singleLine is true', () => {
1345
+ const { result } = renderHook(() => useTextBuffer({
1346
+ initialText: 'ab',
1347
+ viewport,
1348
+ isValidPath: () => false,
1349
+ singleLine: true,
1350
+ }));
1351
+ act(() => result.current.move('end')); // cursor at [0,2]
1352
+ act(() => result.current.newline());
1353
+ const state = getBufferState(result);
1354
+ expect(state.text).toBe('ab');
1355
+ expect(state.lines).toEqual(['ab']);
1356
+ expect(state.cursor).toEqual([0, 2]);
1357
+ });
1358
+ it('should not handle "Enter" key as newline when singleLine is true', () => {
1359
+ const { result } = renderHook(() => useTextBuffer({
1360
+ viewport,
1361
+ isValidPath: () => false,
1362
+ singleLine: true,
1363
+ }));
1364
+ act(() => result.current.handleInput({
1365
+ name: 'return',
1366
+ ctrl: false,
1367
+ meta: false,
1368
+ shift: false,
1369
+ paste: false,
1370
+ sequence: '\r',
1371
+ }));
1372
+ expect(getBufferState(result).lines).toEqual(['']);
1373
+ });
1374
+ it('should strip newlines from pasted text when singleLine is true', () => {
1375
+ const { result } = renderHook(() => useTextBuffer({
1376
+ viewport,
1377
+ isValidPath: () => false,
1378
+ singleLine: true,
1379
+ }));
1380
+ act(() => result.current.insert('hello\nworld', { paste: true }));
1381
+ const state = getBufferState(result);
1382
+ expect(state.text).toBe('helloworld');
1383
+ expect(state.lines).toEqual(['helloworld']);
1384
+ });
1385
+ });
1386
+ });
1387
+ describe('offsetToLogicalPos', () => {
1388
+ it.each([
1389
+ { text: 'any text', offset: 0, expected: [0, 0], desc: 'offset 0' },
1390
+ { text: 'hello', offset: 0, expected: [0, 0], desc: 'single line start' },
1391
+ { text: 'hello', offset: 2, expected: [0, 2], desc: 'single line middle' },
1392
+ { text: 'hello', offset: 5, expected: [0, 5], desc: 'single line end' },
1393
+ { text: 'hello', offset: 10, expected: [0, 5], desc: 'beyond end clamps' },
1394
+ {
1395
+ text: 'a\n\nc',
1396
+ offset: 0,
1397
+ expected: [0, 0],
1398
+ desc: 'empty lines - first char',
1399
+ },
1400
+ {
1401
+ text: 'a\n\nc',
1402
+ offset: 1,
1403
+ expected: [0, 1],
1404
+ desc: 'empty lines - end of first',
1405
+ },
1406
+ {
1407
+ text: 'a\n\nc',
1408
+ offset: 2,
1409
+ expected: [1, 0],
1410
+ desc: 'empty lines - empty line',
1411
+ },
1412
+ {
1413
+ text: 'a\n\nc',
1414
+ offset: 3,
1415
+ expected: [2, 0],
1416
+ desc: 'empty lines - last line start',
1417
+ },
1418
+ {
1419
+ text: 'a\n\nc',
1420
+ offset: 4,
1421
+ expected: [2, 1],
1422
+ desc: 'empty lines - last line end',
1423
+ },
1424
+ {
1425
+ text: 'hello\n',
1426
+ offset: 5,
1427
+ expected: [0, 5],
1428
+ desc: 'newline end - before newline',
1429
+ },
1430
+ {
1431
+ text: 'hello\n',
1432
+ offset: 6,
1433
+ expected: [1, 0],
1434
+ desc: 'newline end - after newline',
1435
+ },
1436
+ {
1437
+ text: 'hello\n',
1438
+ offset: 7,
1439
+ expected: [1, 0],
1440
+ desc: 'newline end - beyond',
1441
+ },
1442
+ {
1443
+ text: '\nhello',
1444
+ offset: 0,
1445
+ expected: [0, 0],
1446
+ desc: 'newline start - first line',
1447
+ },
1448
+ {
1449
+ text: '\nhello',
1450
+ offset: 1,
1451
+ expected: [1, 0],
1452
+ desc: 'newline start - second line',
1453
+ },
1454
+ {
1455
+ text: '\nhello',
1456
+ offset: 3,
1457
+ expected: [1, 2],
1458
+ desc: 'newline start - middle of second',
1459
+ },
1460
+ { text: '', offset: 0, expected: [0, 0], desc: 'empty string at 0' },
1461
+ { text: '', offset: 5, expected: [0, 0], desc: 'empty string beyond' },
1462
+ {
1463
+ text: '你好\n世界',
1464
+ offset: 0,
1465
+ expected: [0, 0],
1466
+ desc: 'unicode - start',
1467
+ },
1468
+ {
1469
+ text: '你好\n世界',
1470
+ offset: 1,
1471
+ expected: [0, 1],
1472
+ desc: 'unicode - after first char',
1473
+ },
1474
+ {
1475
+ text: '你好\n世界',
1476
+ offset: 2,
1477
+ expected: [0, 2],
1478
+ desc: 'unicode - end first line',
1479
+ },
1480
+ {
1481
+ text: '你好\n世界',
1482
+ offset: 3,
1483
+ expected: [1, 0],
1484
+ desc: 'unicode - second line start',
1485
+ },
1486
+ {
1487
+ text: '你好\n世界',
1488
+ offset: 4,
1489
+ expected: [1, 1],
1490
+ desc: 'unicode - second line middle',
1491
+ },
1492
+ {
1493
+ text: '你好\n世界',
1494
+ offset: 5,
1495
+ expected: [1, 2],
1496
+ desc: 'unicode - second line end',
1497
+ },
1498
+ {
1499
+ text: '你好\n世界',
1500
+ offset: 6,
1501
+ expected: [1, 2],
1502
+ desc: 'unicode - beyond',
1503
+ },
1504
+ {
1505
+ text: 'abc\ndef',
1506
+ offset: 3,
1507
+ expected: [0, 3],
1508
+ desc: 'at newline - end of line',
1509
+ },
1510
+ {
1511
+ text: 'abc\ndef',
1512
+ offset: 4,
1513
+ expected: [1, 0],
1514
+ desc: 'at newline - after newline',
1515
+ },
1516
+ { text: '🐶🐱', offset: 0, expected: [0, 0], desc: 'emoji - start' },
1517
+ { text: '🐶🐱', offset: 1, expected: [0, 1], desc: 'emoji - middle' },
1518
+ { text: '🐶🐱', offset: 2, expected: [0, 2], desc: 'emoji - end' },
1519
+ ])('should handle $desc', ({ text, offset, expected }) => {
1520
+ expect(offsetToLogicalPos(text, offset)).toEqual(expected);
1521
+ });
1522
+ describe('multi-line text', () => {
1523
+ const text = 'hello\nworld\n123';
1524
+ it.each([
1525
+ { offset: 0, expected: [0, 0], desc: 'start of first line' },
1526
+ { offset: 3, expected: [0, 3], desc: 'middle of first line' },
1527
+ { offset: 5, expected: [0, 5], desc: 'end of first line' },
1528
+ { offset: 6, expected: [1, 0], desc: 'start of second line' },
1529
+ { offset: 8, expected: [1, 2], desc: 'middle of second line' },
1530
+ { offset: 11, expected: [1, 5], desc: 'end of second line' },
1531
+ { offset: 12, expected: [2, 0], desc: 'start of third line' },
1532
+ { offset: 13, expected: [2, 1], desc: 'middle of third line' },
1533
+ { offset: 15, expected: [2, 3], desc: 'end of third line' },
1534
+ { offset: 20, expected: [2, 3], desc: 'beyond end' },
1535
+ ])('should return $expected for $desc (offset $offset)', ({ offset, expected }) => {
1536
+ expect(offsetToLogicalPos(text, offset)).toEqual(expected);
1537
+ });
1538
+ });
1539
+ });
1540
+ describe('logicalPosToOffset', () => {
1541
+ it('should convert row/col position to offset correctly', () => {
1542
+ const lines = ['hello', 'world', '123'];
1543
+ // Line 0: "hello" (5 chars)
1544
+ expect(logicalPosToOffset(lines, 0, 0)).toBe(0); // Start of 'hello'
1545
+ expect(logicalPosToOffset(lines, 0, 3)).toBe(3); // 'l' in 'hello'
1546
+ expect(logicalPosToOffset(lines, 0, 5)).toBe(5); // End of 'hello'
1547
+ // Line 1: "world" (5 chars), offset starts at 6 (5 + 1 for newline)
1548
+ expect(logicalPosToOffset(lines, 1, 0)).toBe(6); // Start of 'world'
1549
+ expect(logicalPosToOffset(lines, 1, 2)).toBe(8); // 'r' in 'world'
1550
+ expect(logicalPosToOffset(lines, 1, 5)).toBe(11); // End of 'world'
1551
+ // Line 2: "123" (3 chars), offset starts at 12 (5 + 1 + 5 + 1)
1552
+ expect(logicalPosToOffset(lines, 2, 0)).toBe(12); // Start of '123'
1553
+ expect(logicalPosToOffset(lines, 2, 1)).toBe(13); // '2' in '123'
1554
+ expect(logicalPosToOffset(lines, 2, 3)).toBe(15); // End of '123'
1555
+ });
1556
+ it('should handle empty lines', () => {
1557
+ const lines = ['a', '', 'c'];
1558
+ expect(logicalPosToOffset(lines, 0, 0)).toBe(0); // 'a'
1559
+ expect(logicalPosToOffset(lines, 0, 1)).toBe(1); // End of 'a'
1560
+ expect(logicalPosToOffset(lines, 1, 0)).toBe(2); // Empty line
1561
+ expect(logicalPosToOffset(lines, 2, 0)).toBe(3); // 'c'
1562
+ expect(logicalPosToOffset(lines, 2, 1)).toBe(4); // End of 'c'
1563
+ });
1564
+ it('should handle single empty line', () => {
1565
+ const lines = [''];
1566
+ expect(logicalPosToOffset(lines, 0, 0)).toBe(0);
1567
+ });
1568
+ it('should be inverse of offsetToLogicalPos', () => {
1569
+ const lines = ['hello', 'world', '123'];
1570
+ const text = lines.join('\n');
1571
+ // Test round-trip conversion
1572
+ for (let offset = 0; offset <= text.length; offset++) {
1573
+ const [row, col] = offsetToLogicalPos(text, offset);
1574
+ const convertedOffset = logicalPosToOffset(lines, row, col);
1575
+ expect(convertedOffset).toBe(offset);
1576
+ }
1577
+ });
1578
+ it('should handle out-of-bounds positions', () => {
1579
+ const lines = ['hello'];
1580
+ // Beyond end of line
1581
+ expect(logicalPosToOffset(lines, 0, 10)).toBe(5); // Clamps to end of line
1582
+ // Beyond array bounds - should clamp to the last line
1583
+ expect(logicalPosToOffset(lines, 5, 0)).toBe(0); // Clamps to start of last line (row 0)
1584
+ expect(logicalPosToOffset(lines, 5, 10)).toBe(5); // Clamps to end of last line
1585
+ });
1586
+ });
1587
+ const createTestState = (lines, cursorRow, cursorCol, viewportWidth = 80) => {
1588
+ const text = lines.join('\n');
1589
+ let state = textBufferReducer(initialState, {
1590
+ type: 'set_text',
1591
+ payload: text,
1592
+ });
1593
+ state = textBufferReducer(state, {
1594
+ type: 'set_cursor',
1595
+ payload: { cursorRow, cursorCol, preferredCol: null },
1596
+ });
1597
+ state = textBufferReducer(state, {
1598
+ type: 'set_viewport',
1599
+ payload: { width: viewportWidth, height: 24 },
1600
+ });
1601
+ return state;
1602
+ };
1603
+ describe('textBufferReducer vim operations', () => {
1604
+ describe('vim_delete_line', () => {
1605
+ it('should delete a single line including newline in multi-line text', () => {
1606
+ const state = createTestState(['line1', 'line2', 'line3'], 1, 2);
1607
+ const action = {
1608
+ type: 'vim_delete_line',
1609
+ payload: { count: 1 },
1610
+ };
1611
+ const result = textBufferReducer(state, action);
1612
+ expect(result).toHaveOnlyValidCharacters();
1613
+ // After deleting line2, we should have line1 and line3, with cursor on line3 (now at index 1)
1614
+ expect(result.lines).toEqual(['line1', 'line3']);
1615
+ expect(result.cursorRow).toBe(1);
1616
+ expect(result.cursorCol).toBe(0);
1617
+ });
1618
+ it('should delete multiple lines when count > 1', () => {
1619
+ const state = createTestState(['line1', 'line2', 'line3', 'line4'], 1, 0);
1620
+ const action = {
1621
+ type: 'vim_delete_line',
1622
+ payload: { count: 2 },
1623
+ };
1624
+ const result = textBufferReducer(state, action);
1625
+ expect(result).toHaveOnlyValidCharacters();
1626
+ // Should delete line2 and line3, leaving line1 and line4
1627
+ expect(result.lines).toEqual(['line1', 'line4']);
1628
+ expect(result.cursorRow).toBe(1);
1629
+ expect(result.cursorCol).toBe(0);
1630
+ });
1631
+ it('should clear single line content when only one line exists', () => {
1632
+ const state = createTestState(['only line'], 0, 5);
1633
+ const action = {
1634
+ type: 'vim_delete_line',
1635
+ payload: { count: 1 },
1636
+ };
1637
+ const result = textBufferReducer(state, action);
1638
+ expect(result).toHaveOnlyValidCharacters();
1639
+ // Should clear the line content but keep the line
1640
+ expect(result.lines).toEqual(['']);
1641
+ expect(result.cursorRow).toBe(0);
1642
+ expect(result.cursorCol).toBe(0);
1643
+ });
1644
+ it('should handle deleting the last line properly', () => {
1645
+ const state = createTestState(['line1', 'line2'], 1, 0);
1646
+ const action = {
1647
+ type: 'vim_delete_line',
1648
+ payload: { count: 1 },
1649
+ };
1650
+ const result = textBufferReducer(state, action);
1651
+ expect(result).toHaveOnlyValidCharacters();
1652
+ // Should delete the last line completely, not leave empty line
1653
+ expect(result.lines).toEqual(['line1']);
1654
+ expect(result.cursorRow).toBe(0);
1655
+ expect(result.cursorCol).toBe(0);
1656
+ });
1657
+ it('should handle deleting all lines and maintain valid state for subsequent paste', () => {
1658
+ const state = createTestState(['line1', 'line2', 'line3', 'line4'], 0, 0);
1659
+ // Delete all 4 lines with 4dd
1660
+ const deleteAction = {
1661
+ type: 'vim_delete_line',
1662
+ payload: { count: 4 },
1663
+ };
1664
+ const afterDelete = textBufferReducer(state, deleteAction);
1665
+ expect(afterDelete).toHaveOnlyValidCharacters();
1666
+ // After deleting all lines, should have one empty line
1667
+ expect(afterDelete.lines).toEqual(['']);
1668
+ expect(afterDelete.cursorRow).toBe(0);
1669
+ expect(afterDelete.cursorCol).toBe(0);
1670
+ // Now paste multiline content - this should work correctly
1671
+ const pasteAction = {
1672
+ type: 'insert',
1673
+ payload: 'new1\nnew2\nnew3\nnew4',
1674
+ };
1675
+ const afterPaste = textBufferReducer(afterDelete, pasteAction);
1676
+ expect(afterPaste).toHaveOnlyValidCharacters();
1677
+ // All lines including the first one should be present
1678
+ expect(afterPaste.lines).toEqual(['new1', 'new2', 'new3', 'new4']);
1679
+ expect(afterPaste.cursorRow).toBe(3);
1680
+ expect(afterPaste.cursorCol).toBe(4);
1681
+ });
1682
+ });
1683
+ });
1684
+ describe('Unicode helper functions', () => {
1685
+ describe('findWordEndInLine with Unicode', () => {
1686
+ it('should handle combining characters', () => {
1687
+ // café with combining accent
1688
+ const cafeWithCombining = 'cafe\u0301';
1689
+ const result = findWordEndInLine(cafeWithCombining + ' test', 0);
1690
+ expect(result).toBe(3); // End of 'café' at base character 'e', not combining accent
1691
+ });
1692
+ it('should handle precomposed characters with diacritics', () => {
1693
+ // café with precomposed é (U+00E9)
1694
+ const cafePrecomposed = 'café';
1695
+ const result = findWordEndInLine(cafePrecomposed + ' test', 0);
1696
+ expect(result).toBe(3); // End of 'café' at precomposed character 'é'
1697
+ });
1698
+ it('should return null when no word end found', () => {
1699
+ const result = findWordEndInLine(' ', 0);
1700
+ expect(result).toBeNull(); // No word end found in whitespace-only string string
1701
+ });
1702
+ });
1703
+ describe('findNextWordStartInLine with Unicode', () => {
1704
+ it('should handle right-to-left text', () => {
1705
+ const result = findNextWordStartInLine('hello مرحبا world', 0);
1706
+ expect(result).toBe(6); // Start of Arabic word
1707
+ });
1708
+ it('should handle Chinese characters', () => {
1709
+ const result = findNextWordStartInLine('hello 你好 world', 0);
1710
+ expect(result).toBe(6); // Start of Chinese word
1711
+ });
1712
+ it('should return null at end of line', () => {
1713
+ const result = findNextWordStartInLine('hello', 10);
1714
+ expect(result).toBeNull();
1715
+ });
1716
+ it('should handle combining characters', () => {
1717
+ // café with combining accent + next word
1718
+ const textWithCombining = 'cafe\u0301 test';
1719
+ const result = findNextWordStartInLine(textWithCombining, 0);
1720
+ expect(result).toBe(6); // Start of 'test' after 'café ' (combining char makes string longer)
1721
+ });
1722
+ it('should handle precomposed characters with diacritics', () => {
1723
+ // café with precomposed é + next word
1724
+ const textPrecomposed = 'café test';
1725
+ const result = findNextWordStartInLine(textPrecomposed, 0);
1726
+ expect(result).toBe(5); // Start of 'test' after 'café '
1727
+ });
1728
+ });
1729
+ describe('isWordCharStrict with Unicode', () => {
1730
+ it('should return true for ASCII word characters', () => {
1731
+ expect(isWordCharStrict('a')).toBe(true);
1732
+ expect(isWordCharStrict('Z')).toBe(true);
1733
+ expect(isWordCharStrict('0')).toBe(true);
1734
+ expect(isWordCharStrict('_')).toBe(true);
1735
+ });
1736
+ it('should return false for punctuation', () => {
1737
+ expect(isWordCharStrict('.')).toBe(false);
1738
+ expect(isWordCharStrict(',')).toBe(false);
1739
+ expect(isWordCharStrict('!')).toBe(false);
1740
+ });
1741
+ it('should return true for non-Latin scripts', () => {
1742
+ expect(isWordCharStrict('你')).toBe(true); // Chinese character
1743
+ expect(isWordCharStrict('م')).toBe(true); // Arabic character
1744
+ });
1745
+ it('should return false for whitespace', () => {
1746
+ expect(isWordCharStrict(' ')).toBe(false);
1747
+ expect(isWordCharStrict('\t')).toBe(false);
1748
+ });
1749
+ });
1750
+ describe('cpLen with Unicode', () => {
1751
+ it('should handle combining characters', () => {
1752
+ expect(cpLen('é')).toBe(1); // Precomposed
1753
+ expect(cpLen('e\u0301')).toBe(2); // e + combining acute
1754
+ });
1755
+ it('should handle Chinese and Arabic text', () => {
1756
+ expect(cpLen('hello 你好 world')).toBe(14); // 5 + 1 + 2 + 1 + 5 = 14
1757
+ expect(cpLen('hello مرحبا world')).toBe(17);
1758
+ });
1759
+ });
1760
+ });
1761
+ //# sourceMappingURL=text-buffer.test.js.map