@dyyz1993/create-agent 1.9.0

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 (358) hide show
  1. package/package.json +25 -0
  2. package/src/__tests__/cli.test.ts +85 -0
  3. package/src/__tests__/copy.test.ts +168 -0
  4. package/src/__tests__/templates.test.ts +87 -0
  5. package/src/cli.ts +65 -0
  6. package/src/commands/create.ts +49 -0
  7. package/src/commands/list.ts +12 -0
  8. package/src/commands/status.ts +85 -0
  9. package/src/commands/workspace.ts +129 -0
  10. package/src/lib/copy.ts +285 -0
  11. package/src/lib/templates.ts +57 -0
  12. package/src/lib/types.ts +6 -0
  13. package/templates/agent/.env.example +7 -0
  14. package/templates/agent/LICENSE +21 -0
  15. package/templates/agent/README.md +87 -0
  16. package/templates/agent/bun.lock +1279 -0
  17. package/templates/agent/electrobun.config.ts +27 -0
  18. package/templates/agent/eslint.config.mjs +63 -0
  19. package/templates/agent/llms.txt +24 -0
  20. package/templates/agent/package-lock.json +3670 -0
  21. package/templates/agent/package.json +59 -0
  22. package/templates/agent/postcss.config.js +6 -0
  23. package/templates/agent/scripts/dev.ts +138 -0
  24. package/templates/agent/src/__tests__/server-config.test.ts +59 -0
  25. package/templates/agent/src/bun/index.ts +73 -0
  26. package/templates/agent/src/gateway/__tests__/ws-handler.test.ts +48 -0
  27. package/templates/agent/src/gateway/http-routes.ts +1 -0
  28. package/templates/agent/src/gateway/ipc-transport.ts +68 -0
  29. package/templates/agent/src/gateway/ws-handler.ts +86 -0
  30. package/templates/agent/src/mainview/App.tsx +41 -0
  31. package/templates/agent/src/mainview/__tests__/components/ChatPanel.test.tsx +114 -0
  32. package/templates/agent/src/mainview/__tests__/components/ExplorerSidebar.test.tsx +141 -0
  33. package/templates/agent/src/mainview/__tests__/components/MessageBubble.test.tsx +72 -0
  34. package/templates/agent/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
  35. package/templates/agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +217 -0
  36. package/templates/agent/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
  37. package/templates/agent/src/mainview/__tests__/i18n/i18n.test.ts +48 -0
  38. package/templates/agent/src/mainview/__tests__/setup.ts +37 -0
  39. package/templates/agent/src/mainview/__tests__/stores/use-chat-store.test.ts +83 -0
  40. package/templates/agent/src/mainview/__tests__/stores/use-sidebar-store.test.ts +85 -0
  41. package/templates/agent/src/mainview/components/activity-bar/ActivityBar.tsx +36 -0
  42. package/templates/agent/src/mainview/components/activity-bar/MobileTabBar.tsx +36 -0
  43. package/templates/agent/src/mainview/components/activity-bar/__tests__/ActivityBar.test.tsx +44 -0
  44. package/templates/agent/src/mainview/components/activity-bar/__tests__/MobileTabBar.test.tsx +44 -0
  45. package/templates/agent/src/mainview/components/bash/BashPanel.tsx +206 -0
  46. package/templates/agent/src/mainview/components/bash/__tests__/BashPanel.test.tsx +103 -0
  47. package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +102 -0
  48. package/templates/agent/src/mainview/components/chat/MessageBubble.tsx +86 -0
  49. package/templates/agent/src/mainview/components/common/ErrorBoundary.tsx +58 -0
  50. package/templates/agent/src/mainview/components/common/LanguageSwitcher.tsx +14 -0
  51. package/templates/agent/src/mainview/components/common/ThemeToggle.tsx +24 -0
  52. package/templates/agent/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
  53. package/templates/agent/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
  54. package/templates/agent/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
  55. package/templates/agent/src/mainview/components/debug/DebugPanel.tsx +120 -0
  56. package/templates/agent/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +102 -0
  57. package/templates/agent/src/mainview/components/diff/DiffViewerPanel.tsx +106 -0
  58. package/templates/agent/src/mainview/components/diff/__tests__/DiffViewerPanel.test.tsx +73 -0
  59. package/templates/agent/src/mainview/components/explorer/ConfirmDialog.tsx +53 -0
  60. package/templates/agent/src/mainview/components/explorer/ContextMenu.tsx +82 -0
  61. package/templates/agent/src/mainview/components/explorer/ExplorerSidebar.tsx +221 -0
  62. package/templates/agent/src/mainview/components/explorer/InlineInput.tsx +55 -0
  63. package/templates/agent/src/mainview/components/explorer/TreeNodeItem.tsx +121 -0
  64. package/templates/agent/src/mainview/components/explorer/__tests__/ConfirmDialog.test.tsx +37 -0
  65. package/templates/agent/src/mainview/components/explorer/__tests__/ContextMenu.test.tsx +49 -0
  66. package/templates/agent/src/mainview/components/explorer/__tests__/InlineInput.test.tsx +48 -0
  67. package/templates/agent/src/mainview/components/explorer/__tests__/TreeNodeItem.test.tsx +146 -0
  68. package/templates/agent/src/mainview/components/feed/FeedPanel.tsx +239 -0
  69. package/templates/agent/src/mainview/components/feed/__tests__/FeedPanel.test.tsx +108 -0
  70. package/templates/agent/src/mainview/components/file-preview/FilePreviewOverlay.tsx +56 -0
  71. package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +99 -0
  72. package/templates/agent/src/mainview/components/file-preview/__tests__/FilePreviewOverlay.test.tsx +96 -0
  73. package/templates/agent/src/mainview/components/file-preview/__tests__/VirtualizedCodeView.test.tsx +58 -0
  74. package/templates/agent/src/mainview/components/git/GitBranchSelector.tsx +98 -0
  75. package/templates/agent/src/mainview/components/git/GitCommitInput.tsx +60 -0
  76. package/templates/agent/src/mainview/components/git/GitPanel.tsx +528 -0
  77. package/templates/agent/src/mainview/components/git/__tests__/GitBranchSelector.test.tsx +76 -0
  78. package/templates/agent/src/mainview/components/git/__tests__/GitCommitInput.test.tsx +91 -0
  79. package/templates/agent/src/mainview/components/git/__tests__/GitPanel.test.tsx +174 -0
  80. package/templates/agent/src/mainview/components/layout/AppLayout.tsx +170 -0
  81. package/templates/agent/src/mainview/components/layout/__tests__/AppLayout.test.tsx +163 -0
  82. package/templates/agent/src/mainview/components/rules/RulesPanel.tsx +117 -0
  83. package/templates/agent/src/mainview/components/rules/__tests__/RulesPanel.test.tsx +91 -0
  84. package/templates/agent/src/mainview/components/search/SearchPanel.tsx +404 -0
  85. package/templates/agent/src/mainview/components/search/__tests__/SearchPanel.test.tsx +50 -0
  86. package/templates/agent/src/mainview/components/sidebar/PinButton.tsx +20 -0
  87. package/templates/agent/src/mainview/components/sidebar/__tests__/PinButton.test.tsx +48 -0
  88. package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +141 -0
  89. package/templates/agent/src/mainview/components/todo/__tests__/TodoPanel.test.tsx +91 -0
  90. package/templates/agent/src/mainview/global.d.ts +13 -0
  91. package/templates/agent/src/mainview/hooks/__tests__/use-breakpoint.test.ts +147 -0
  92. package/templates/agent/src/mainview/hooks/use-breakpoint.ts +34 -0
  93. package/templates/agent/src/mainview/hooks/use-input-history.ts +84 -0
  94. package/templates/agent/src/mainview/hooks/use-rpc-init.ts +61 -0
  95. package/templates/agent/src/mainview/hooks/use-sidebar-resize.ts +40 -0
  96. package/templates/agent/src/mainview/index.css +61 -0
  97. package/templates/agent/src/mainview/index.html +12 -0
  98. package/templates/agent/src/mainview/lib/api-client.ts +192 -0
  99. package/templates/agent/src/mainview/lib/i18n/index.ts +30 -0
  100. package/templates/agent/src/mainview/lib/i18n/locales/en.json +157 -0
  101. package/templates/agent/src/mainview/lib/i18n/locales/zh.json +157 -0
  102. package/templates/agent/src/mainview/lib/rpc-cache.ts +94 -0
  103. package/templates/agent/src/mainview/main.tsx +24 -0
  104. package/templates/agent/src/mainview/stores/__tests__/use-app-store.test.ts +86 -0
  105. package/templates/agent/src/mainview/stores/__tests__/use-bash-store.test.ts +99 -0
  106. package/templates/agent/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
  107. package/templates/agent/src/mainview/stores/__tests__/use-explorer-store.test.ts +130 -0
  108. package/templates/agent/src/mainview/stores/__tests__/use-feed-store.test.ts +132 -0
  109. package/templates/agent/src/mainview/stores/__tests__/use-git-store.test.ts +161 -0
  110. package/templates/agent/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
  111. package/templates/agent/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
  112. package/templates/agent/src/mainview/stores/__tests__/use-notification-store.test.ts +102 -0
  113. package/templates/agent/src/mainview/stores/__tests__/use-rules-store.test.ts +75 -0
  114. package/templates/agent/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
  115. package/templates/agent/src/mainview/stores/__tests__/use-todo-store.test.ts +75 -0
  116. package/templates/agent/src/mainview/stores/message-batcher.ts +25 -0
  117. package/templates/agent/src/mainview/stores/use-app-store.ts +99 -0
  118. package/templates/agent/src/mainview/stores/use-bash-store.ts +93 -0
  119. package/templates/agent/src/mainview/stores/use-chat-store.ts +37 -0
  120. package/templates/agent/src/mainview/stores/use-connection-store.ts +42 -0
  121. package/templates/agent/src/mainview/stores/use-explorer-store.ts +320 -0
  122. package/templates/agent/src/mainview/stores/use-feed-store.ts +129 -0
  123. package/templates/agent/src/mainview/stores/use-git-store.ts +291 -0
  124. package/templates/agent/src/mainview/stores/use-locale-store.ts +27 -0
  125. package/templates/agent/src/mainview/stores/use-log-store.ts +16 -0
  126. package/templates/agent/src/mainview/stores/use-notification-store.ts +82 -0
  127. package/templates/agent/src/mainview/stores/use-rules-store.ts +54 -0
  128. package/templates/agent/src/mainview/stores/use-sidebar-store.ts +99 -0
  129. package/templates/agent/src/mainview/stores/use-theme-store.ts +46 -0
  130. package/templates/agent/src/mainview/stores/use-todo-store.ts +54 -0
  131. package/templates/agent/src/mainview/types/index.ts +33 -0
  132. package/templates/agent/src/mainview/utils/constants.ts +1 -0
  133. package/templates/agent/src/mainview/utils/drop-handler.ts +150 -0
  134. package/templates/agent/src/mainview/utils/file-icon.tsx +24 -0
  135. package/templates/agent/src/mainview/utils/file-utils.ts +35 -0
  136. package/templates/agent/src/server-config.ts +43 -0
  137. package/templates/agent/src/server.ts +89 -0
  138. package/templates/agent/src/shared/handlers/__tests__/bash-handler.test.ts +135 -0
  139. package/templates/agent/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
  140. package/templates/agent/src/shared/handlers/__tests__/feed-handler.test.ts +108 -0
  141. package/templates/agent/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
  142. package/templates/agent/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
  143. package/templates/agent/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
  144. package/templates/agent/src/shared/handlers/bash.ts +89 -0
  145. package/templates/agent/src/shared/handlers/chat.ts +179 -0
  146. package/templates/agent/src/shared/handlers/feed.ts +53 -0
  147. package/templates/agent/src/shared/handlers/file.ts +99 -0
  148. package/templates/agent/src/shared/handlers/git.ts +263 -0
  149. package/templates/agent/src/shared/handlers/index.ts +10 -0
  150. package/templates/agent/src/shared/handlers/rules.ts +45 -0
  151. package/templates/agent/src/shared/handlers/system.ts +27 -0
  152. package/templates/agent/src/shared/handlers/timer.ts +34 -0
  153. package/templates/agent/src/shared/handlers/todo.ts +45 -0
  154. package/templates/agent/src/shared/lib/__tests__/bash-security.test.ts +125 -0
  155. package/templates/agent/src/shared/lib/__tests__/logger.test.ts +92 -0
  156. package/templates/agent/src/shared/lib/__tests__/path-security.test.ts +77 -0
  157. package/templates/agent/src/shared/lib/bash-security.ts +64 -0
  158. package/templates/agent/src/shared/lib/logger.ts +130 -0
  159. package/templates/agent/src/shared/lib/path-security.ts +38 -0
  160. package/templates/agent/src/shared/lib/port-registry.ts +103 -0
  161. package/templates/agent/src/shared/modules/bash.ts +19 -0
  162. package/templates/agent/src/shared/modules/chat.ts +20 -0
  163. package/templates/agent/src/shared/modules/feed.ts +30 -0
  164. package/templates/agent/src/shared/modules/file.ts +40 -0
  165. package/templates/agent/src/shared/modules/git.ts +81 -0
  166. package/templates/agent/src/shared/modules/rules.ts +25 -0
  167. package/templates/agent/src/shared/modules/system.ts +8 -0
  168. package/templates/agent/src/shared/modules/timer.ts +11 -0
  169. package/templates/agent/src/shared/modules/todo.ts +27 -0
  170. package/templates/agent/src/shared/register-all-handlers.ts +36 -0
  171. package/templates/agent/src/shared/rpc-schema.ts +35 -0
  172. package/templates/agent/tailwind.config.js +15 -0
  173. package/templates/agent/tsconfig.json +26 -0
  174. package/templates/agent/vite.config.ts +3 -0
  175. package/templates/agent/vitest.config.ts +3 -0
  176. package/templates/chat/.env.example +6 -0
  177. package/templates/chat/LICENSE +21 -0
  178. package/templates/chat/README.md +56 -0
  179. package/templates/chat/bun.lock +1203 -0
  180. package/templates/chat/electrobun.config.ts +27 -0
  181. package/templates/chat/eslint.config.mjs +56 -0
  182. package/templates/chat/llms.txt +24 -0
  183. package/templates/chat/package-lock.json +3670 -0
  184. package/templates/chat/package.json +58 -0
  185. package/templates/chat/postcss.config.js +6 -0
  186. package/templates/chat/scripts/dev.ts +138 -0
  187. package/templates/chat/src/__tests__/server-config.test.ts +59 -0
  188. package/templates/chat/src/bun/index.ts +72 -0
  189. package/templates/chat/src/gateway/__tests__/ws-handler.test.ts +48 -0
  190. package/templates/chat/src/gateway/http-routes.ts +1 -0
  191. package/templates/chat/src/gateway/ipc-transport.ts +68 -0
  192. package/templates/chat/src/gateway/ws-handler.ts +86 -0
  193. package/templates/chat/src/mainview/App.tsx +108 -0
  194. package/templates/chat/src/mainview/__tests__/components/ChatPanel.test.tsx +76 -0
  195. package/templates/chat/src/mainview/__tests__/components/MessageBubble.test.tsx +48 -0
  196. package/templates/chat/src/mainview/__tests__/i18n/i18n.test.ts +48 -0
  197. package/templates/chat/src/mainview/__tests__/setup-verify.test.ts +8 -0
  198. package/templates/chat/src/mainview/__tests__/setup.ts +37 -0
  199. package/templates/chat/src/mainview/__tests__/stores/use-app-store.test.ts +46 -0
  200. package/templates/chat/src/mainview/__tests__/stores/use-chat-store.test.ts +104 -0
  201. package/templates/chat/src/mainview/__tests__/stores/use-connection-store.test.ts +35 -0
  202. package/templates/chat/src/mainview/__tests__/stores/use-log-store.test.ts +45 -0
  203. package/templates/chat/src/mainview/__tests__/stores/use-notification-store.test.ts +102 -0
  204. package/templates/chat/src/mainview/__tests__/stores/use-sidebar-store.test.ts +89 -0
  205. package/templates/chat/src/mainview/components/activity-bar/ActivityBar.tsx +26 -0
  206. package/templates/chat/src/mainview/components/activity-bar/MobileTabBar.tsx +20 -0
  207. package/templates/chat/src/mainview/components/chat/ChatPanel.tsx +66 -0
  208. package/templates/chat/src/mainview/components/chat/MessageBubble.tsx +85 -0
  209. package/templates/chat/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
  210. package/templates/chat/src/mainview/components/common/ThemeToggle.tsx +24 -0
  211. package/templates/chat/src/mainview/components/sidebar/PinButton.tsx +20 -0
  212. package/templates/chat/src/mainview/global.d.ts +13 -0
  213. package/templates/chat/src/mainview/hooks/use-breakpoint.ts +34 -0
  214. package/templates/chat/src/mainview/hooks/use-input-history.ts +84 -0
  215. package/templates/chat/src/mainview/index.css +61 -0
  216. package/templates/chat/src/mainview/index.html +12 -0
  217. package/templates/chat/src/mainview/lib/api-client.ts +175 -0
  218. package/templates/chat/src/mainview/lib/i18n/index.ts +30 -0
  219. package/templates/chat/src/mainview/lib/i18n/locales/en.json +157 -0
  220. package/templates/chat/src/mainview/lib/i18n/locales/zh.json +157 -0
  221. package/templates/chat/src/mainview/main.tsx +20 -0
  222. package/templates/chat/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
  223. package/templates/chat/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
  224. package/templates/chat/src/mainview/stores/message-batcher.ts +25 -0
  225. package/templates/chat/src/mainview/stores/use-app-store.ts +50 -0
  226. package/templates/chat/src/mainview/stores/use-chat-store.ts +37 -0
  227. package/templates/chat/src/mainview/stores/use-connection-store.ts +42 -0
  228. package/templates/chat/src/mainview/stores/use-locale-store.ts +27 -0
  229. package/templates/chat/src/mainview/stores/use-log-store.ts +16 -0
  230. package/templates/chat/src/mainview/stores/use-notification-store.ts +82 -0
  231. package/templates/chat/src/mainview/stores/use-sidebar-store.ts +98 -0
  232. package/templates/chat/src/mainview/stores/use-theme-store.ts +46 -0
  233. package/templates/chat/src/mainview/types/index.ts +8 -0
  234. package/templates/chat/src/mainview/utils/constants.ts +1 -0
  235. package/templates/chat/src/server-config.ts +42 -0
  236. package/templates/chat/src/server.ts +89 -0
  237. package/templates/chat/src/shared/__tests__/chat-handler.test.ts +71 -0
  238. package/templates/chat/src/shared/__tests__/system-handler.test.ts +70 -0
  239. package/templates/chat/src/shared/handlers/chat.ts +186 -0
  240. package/templates/chat/src/shared/handlers/index.ts +2 -0
  241. package/templates/chat/src/shared/handlers/system.ts +27 -0
  242. package/templates/chat/src/shared/lib/logger.ts +130 -0
  243. package/templates/chat/src/shared/lib/path-security.ts +38 -0
  244. package/templates/chat/src/shared/lib/port-registry.ts +103 -0
  245. package/templates/chat/src/shared/modules/chat.ts +20 -0
  246. package/templates/chat/src/shared/modules/system.ts +8 -0
  247. package/templates/chat/src/shared/register-all-handlers.ts +36 -0
  248. package/templates/chat/src/shared/rpc-schema.ts +11 -0
  249. package/templates/chat/tailwind.config.js +15 -0
  250. package/templates/chat/tsconfig.json +26 -0
  251. package/templates/chat/vite.config.ts +3 -0
  252. package/templates/chat/vitest.config.ts +3 -0
  253. package/templates/general/.env.example +7 -0
  254. package/templates/general/LICENSE +21 -0
  255. package/templates/general/README.md +113 -0
  256. package/templates/general/bun.lock +1266 -0
  257. package/templates/general/electrobun.config.ts +27 -0
  258. package/templates/general/eslint.config.mjs +56 -0
  259. package/templates/general/llms.txt +24 -0
  260. package/templates/general/package-lock.json +3670 -0
  261. package/templates/general/package.json +59 -0
  262. package/templates/general/postcss.config.js +6 -0
  263. package/templates/general/scripts/dev.ts +138 -0
  264. package/templates/general/src/__tests__/server-config.test.ts +59 -0
  265. package/templates/general/src/bun/index.ts +72 -0
  266. package/templates/general/src/gateway/http-routes.ts +1 -0
  267. package/templates/general/src/gateway/ipc-transport.ts +68 -0
  268. package/templates/general/src/gateway/ws-handler.ts +86 -0
  269. package/templates/general/src/mainview/App.tsx +40 -0
  270. package/templates/general/src/mainview/__tests__/components/ChatPanel.test.tsx +82 -0
  271. package/templates/general/src/mainview/__tests__/components/FeedPanel.test.tsx +109 -0
  272. package/templates/general/src/mainview/__tests__/components/GitPanel.test.tsx +151 -0
  273. package/templates/general/src/mainview/__tests__/i18n/i18n.test.ts +48 -0
  274. package/templates/general/src/mainview/__tests__/setup-verify.test.ts +8 -0
  275. package/templates/general/src/mainview/__tests__/setup.ts +37 -0
  276. package/templates/general/src/mainview/components/activity-bar/ActivityBar.tsx +40 -0
  277. package/templates/general/src/mainview/components/activity-bar/MobileTabBar.tsx +29 -0
  278. package/templates/general/src/mainview/components/chat/ChatPanel.tsx +66 -0
  279. package/templates/general/src/mainview/components/chat/MessageBubble.tsx +85 -0
  280. package/templates/general/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
  281. package/templates/general/src/mainview/components/common/ThemeToggle.tsx +24 -0
  282. package/templates/general/src/mainview/components/debug/DebugPanel.tsx +176 -0
  283. package/templates/general/src/mainview/components/diff/DiffViewerPanel.tsx +108 -0
  284. package/templates/general/src/mainview/components/explorer/ConfirmDialog.tsx +52 -0
  285. package/templates/general/src/mainview/components/explorer/ContextMenu.tsx +82 -0
  286. package/templates/general/src/mainview/components/explorer/ExplorerSidebar.tsx +225 -0
  287. package/templates/general/src/mainview/components/explorer/InlineInput.tsx +55 -0
  288. package/templates/general/src/mainview/components/explorer/TreeNodeItem.tsx +121 -0
  289. package/templates/general/src/mainview/components/feed/FeedPanel.tsx +248 -0
  290. package/templates/general/src/mainview/components/file-preview/FilePreviewOverlay.tsx +55 -0
  291. package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +99 -0
  292. package/templates/general/src/mainview/components/git/GitBranchSelector.tsx +93 -0
  293. package/templates/general/src/mainview/components/git/GitCommitInput.tsx +60 -0
  294. package/templates/general/src/mainview/components/git/GitPanel.tsx +533 -0
  295. package/templates/general/src/mainview/components/layout/AppLayout.tsx +146 -0
  296. package/templates/general/src/mainview/components/search/SearchPanel.tsx +405 -0
  297. package/templates/general/src/mainview/components/sidebar/PinButton.tsx +20 -0
  298. package/templates/general/src/mainview/global.d.ts +13 -0
  299. package/templates/general/src/mainview/hooks/use-breakpoint.ts +34 -0
  300. package/templates/general/src/mainview/hooks/use-input-history.ts +84 -0
  301. package/templates/general/src/mainview/hooks/use-rpc-init.ts +61 -0
  302. package/templates/general/src/mainview/hooks/use-sidebar-resize.ts +40 -0
  303. package/templates/general/src/mainview/index.css +61 -0
  304. package/templates/general/src/mainview/index.html +12 -0
  305. package/templates/general/src/mainview/lib/api-client.ts +175 -0
  306. package/templates/general/src/mainview/lib/i18n/index.ts +30 -0
  307. package/templates/general/src/mainview/lib/i18n/locales/en.json +157 -0
  308. package/templates/general/src/mainview/lib/i18n/locales/zh.json +157 -0
  309. package/templates/general/src/mainview/main.tsx +20 -0
  310. package/templates/general/src/mainview/stores/__tests__/use-chat-store.test.ts +104 -0
  311. package/templates/general/src/mainview/stores/__tests__/use-connection-store.test.ts +35 -0
  312. package/templates/general/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
  313. package/templates/general/src/mainview/stores/__tests__/use-log-store.test.ts +45 -0
  314. package/templates/general/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
  315. package/templates/general/src/mainview/stores/message-batcher.ts +25 -0
  316. package/templates/general/src/mainview/stores/use-app-store.ts +104 -0
  317. package/templates/general/src/mainview/stores/use-chat-store.ts +37 -0
  318. package/templates/general/src/mainview/stores/use-connection-store.ts +42 -0
  319. package/templates/general/src/mainview/stores/use-explorer-store.ts +315 -0
  320. package/templates/general/src/mainview/stores/use-feed-store.ts +129 -0
  321. package/templates/general/src/mainview/stores/use-git-store.ts +284 -0
  322. package/templates/general/src/mainview/stores/use-locale-store.ts +27 -0
  323. package/templates/general/src/mainview/stores/use-log-store.ts +16 -0
  324. package/templates/general/src/mainview/stores/use-notification-store.ts +82 -0
  325. package/templates/general/src/mainview/stores/use-sidebar-store.ts +99 -0
  326. package/templates/general/src/mainview/stores/use-theme-store.ts +46 -0
  327. package/templates/general/src/mainview/types/index.ts +33 -0
  328. package/templates/general/src/mainview/utils/constants.ts +1 -0
  329. package/templates/general/src/mainview/utils/drop-handler.ts +150 -0
  330. package/templates/general/src/mainview/utils/file-icon.tsx +24 -0
  331. package/templates/general/src/mainview/utils/file-utils.ts +35 -0
  332. package/templates/general/src/server-config.ts +42 -0
  333. package/templates/general/src/server.ts +89 -0
  334. package/templates/general/src/shared/handlers/__tests__/chat.test.ts +183 -0
  335. package/templates/general/src/shared/handlers/__tests__/system.test.ts +94 -0
  336. package/templates/general/src/shared/handlers/__tests__/timer.test.ts +113 -0
  337. package/templates/general/src/shared/handlers/chat.ts +179 -0
  338. package/templates/general/src/shared/handlers/feed.ts +53 -0
  339. package/templates/general/src/shared/handlers/file.ts +99 -0
  340. package/templates/general/src/shared/handlers/git.ts +263 -0
  341. package/templates/general/src/shared/handlers/index.ts +7 -0
  342. package/templates/general/src/shared/handlers/system.ts +27 -0
  343. package/templates/general/src/shared/handlers/timer.ts +34 -0
  344. package/templates/general/src/shared/lib/logger.ts +130 -0
  345. package/templates/general/src/shared/lib/path-security.ts +38 -0
  346. package/templates/general/src/shared/lib/port-registry.ts +103 -0
  347. package/templates/general/src/shared/modules/chat.ts +20 -0
  348. package/templates/general/src/shared/modules/feed.ts +30 -0
  349. package/templates/general/src/shared/modules/file.ts +40 -0
  350. package/templates/general/src/shared/modules/git.ts +81 -0
  351. package/templates/general/src/shared/modules/system.ts +8 -0
  352. package/templates/general/src/shared/modules/timer.ts +11 -0
  353. package/templates/general/src/shared/register-all-handlers.ts +36 -0
  354. package/templates/general/src/shared/rpc-schema.ts +31 -0
  355. package/templates/general/tailwind.config.js +15 -0
  356. package/templates/general/tsconfig.json +26 -0
  357. package/templates/general/vite.config.ts +3 -0
  358. package/templates/general/vitest.config.ts +3 -0
@@ -0,0 +1,221 @@
1
+ import { useState, useCallback } from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { Folder, RefreshCw, File, FolderPlus, Pencil, Trash2, Copy } from "lucide-react";
4
+ import type { TreeNode } from "../../types";
5
+ import { readDropItems } from "../../utils/drop-handler";
6
+ import { useExplorerStore } from "../../stores/use-explorer-store";
7
+ import { TreeNodeItem } from "./TreeNodeItem";
8
+ import { ContextMenu, type MenuItem } from "./ContextMenu";
9
+ import { ConfirmDialog } from "./ConfirmDialog";
10
+ import { InlineInput } from "./InlineInput";
11
+ import { PinButton } from "../sidebar/PinButton";
12
+
13
+ interface ContextMenuState {
14
+ x: number;
15
+ y: number;
16
+ node: TreeNode | null;
17
+ }
18
+
19
+ export function ExplorerSidebar({ hideOuterShell }: { hideOuterShell?: boolean }) {
20
+ const { t } = useTranslation();
21
+ const treeNodes = useExplorerStore((s) => s.treeNodes);
22
+ const currentPath = useExplorerStore((s) => s.currentPath);
23
+ const selectedPath = useExplorerStore((s) => s.selectedPath);
24
+ const editingNode = useExplorerStore((s) => s.editingNode);
25
+ const setCurrentPath = useExplorerStore((s) => s.setCurrentPath);
26
+ const listRootDir = useExplorerStore((s) => s.listRootDir);
27
+ const toggleNode = useExplorerStore((s) => s.toggleNode);
28
+ const openFile = useExplorerStore((s) => s.openFile);
29
+ const createFile = useExplorerStore((s) => s.createFile);
30
+ const createDir = useExplorerStore((s) => s.createDir);
31
+ const renameNode = useExplorerStore((s) => s.renameNode);
32
+ const deleteNode = useExplorerStore((s) => s.deleteNode);
33
+ const startEditing = useExplorerStore((s) => s.startEditing);
34
+ const cancelEditing = useExplorerStore((s) => s.cancelEditing);
35
+ const importFiles = useExplorerStore((s) => s.importFiles);
36
+ const [contextMenu, setContextMenu] = useState<ContextMenuState | null>(null);
37
+ const [pendingDelete, setPendingDelete] = useState<string | null>(null);
38
+ const [isDragOver, setIsDragOver] = useState(false);
39
+
40
+ const handleContextMenu = useCallback((e: React.MouseEvent, node: TreeNode | null) => {
41
+ e.preventDefault();
42
+ e.stopPropagation();
43
+ setContextMenu({ x: e.clientX, y: e.clientY, node });
44
+ }, []);
45
+
46
+ const handleBlankContextMenu = useCallback((e: React.MouseEvent) => {
47
+ e.preventDefault();
48
+ setContextMenu({ x: e.clientX, y: e.clientY, node: null });
49
+ }, []);
50
+
51
+ const handleDragOver = useCallback((e: React.DragEvent) => {
52
+ e.preventDefault();
53
+ e.stopPropagation();
54
+ setIsDragOver(true);
55
+ }, []);
56
+
57
+ const handleDragLeave = useCallback(() => {
58
+ setIsDragOver(false);
59
+ }, []);
60
+
61
+ const handleDrop = useCallback(async (e: React.DragEvent) => {
62
+ e.preventDefault();
63
+ e.stopPropagation();
64
+ setIsDragOver(false);
65
+ const entries = await readDropItems(e.dataTransfer);
66
+ if (entries.length > 0) {
67
+ try {
68
+ await importFiles(entries, currentPath);
69
+ } catch { /* error logged in store */ }
70
+ }
71
+ }, [importFiles, currentPath]);
72
+
73
+ const buildMenuItems = useCallback((): MenuItem[] => {
74
+ if (!contextMenu) return [];
75
+ const node = contextMenu.node;
76
+
77
+ if (!node) {
78
+ return [
79
+ { label: t("explorer.newFile"), icon: <File className="w-3 h-3" />, onClick: () => startEditing(currentPath, "newFile") },
80
+ { label: t("explorer.newFolder"), icon: <FolderPlus className="w-3 h-3" />, onClick: () => startEditing(currentPath, "newDir") },
81
+ { label: t("explorer.refresh"), icon: <RefreshCw className="w-3 h-3" />, onClick: listRootDir, divider: true },
82
+ ];
83
+ }
84
+
85
+ const items: MenuItem[] = [];
86
+ if (node.type === "directory") {
87
+ items.push(
88
+ { label: t("explorer.newFile"), icon: <File className="w-3 h-3" />, onClick: () => startEditing(node.path, "newFile") },
89
+ { label: t("explorer.newFolder"), icon: <FolderPlus className="w-3 h-3" />, onClick: () => startEditing(node.path, "newDir") },
90
+ );
91
+ }
92
+ items.push(
93
+ { label: t("explorer.rename"), icon: <Pencil className="w-3 h-3" />, onClick: () => startEditing(node.path, "rename"), divider: items.length > 0 },
94
+ { label: t("explorer.delete"), icon: <Trash2 className="w-3 h-3" />, onClick: () => setPendingDelete(node.path), danger: true },
95
+ { label: t("explorer.copyPath"), icon: <Copy className="w-3 h-3" />, onClick: () => navigator.clipboard.writeText(node.path) },
96
+ );
97
+ return items;
98
+ }, [contextMenu, currentPath, listRootDir, startEditing, t]);
99
+
100
+ const handleSubmitEdit = useCallback(
101
+ (value: string) => {
102
+ if (!editingNode) return;
103
+ if (editingNode.type === "rename") {
104
+ renameNode(editingNode.path, value);
105
+ } else if (editingNode.type === "newFile") {
106
+ createFile(editingNode.path, value);
107
+ } else if (editingNode.type === "newDir") {
108
+ createDir(editingNode.path, value);
109
+ }
110
+ },
111
+ [editingNode, renameNode, createFile, createDir],
112
+ );
113
+
114
+ const isRootEditing =
115
+ editingNode &&
116
+ editingNode.path === currentPath &&
117
+ (editingNode.type === "newFile" || editingNode.type === "newDir");
118
+
119
+ const header = (
120
+ <div className="px-3 py-2 text-xs font-semibold text-[var(--color-text-tertiary)] uppercase tracking-wide border-b border-[var(--color-border-primary)] flex items-center justify-between">
121
+ <div className="flex items-center gap-1.5">
122
+ <Folder className="w-3.5 h-3.5" />
123
+ {t("explorer.title")}
124
+ </div>
125
+ <PinButton />
126
+ </div>
127
+ );
128
+
129
+ const content = (
130
+ <>
131
+ {header}
132
+ <div className="flex-1 overflow-hidden flex flex-col">
133
+ <div className="flex gap-2 p-2 border-b border-[var(--color-border-primary)]">
134
+ <input
135
+ type="text"
136
+ value={currentPath}
137
+ onChange={(e) => setCurrentPath(e.target.value)}
138
+ onKeyDown={(e) => e.key === "Enter" && listRootDir()}
139
+ placeholder={t("explorer.pathPlaceholder")}
140
+ className="flex-1 px-2 py-1 text-xs bg-[var(--color-bg-tertiary)] rounded text-[var(--color-text-primary)] border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
141
+ />
142
+ <button
143
+ onClick={listRootDir}
144
+ className="px-2 py-1 text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded transition-colors"
145
+ title={t("explorer.listDirectory")}
146
+ >
147
+ <RefreshCw className="w-3 h-3" />
148
+ </button>
149
+ </div>
150
+ <div
151
+ className={`flex-1 overflow-y-auto p-1 transition-colors ${
152
+ isDragOver ? "bg-[var(--color-accent)]/30 ring-1 ring-inset ring-[var(--color-accent)]/50" : ""
153
+ }`}
154
+ onContextMenu={handleBlankContextMenu}
155
+ onDragOver={handleDragOver}
156
+ onDragLeave={handleDragLeave}
157
+ onDrop={handleDrop}
158
+ >
159
+ {treeNodes.length === 0 ? (
160
+ <div className="text-[var(--color-text-placeholder)] text-xs text-center py-4">{t("explorer.emptyHint")}</div>
161
+ ) : (
162
+ <ul className="space-y-0.5">
163
+ {treeNodes.map((node) => (
164
+ <TreeNodeItem
165
+ key={node.path}
166
+ node={node}
167
+ depth={0}
168
+ selectedPath={selectedPath}
169
+ editingNode={editingNode}
170
+ onToggle={toggleNode}
171
+ onOpenFile={openFile}
172
+ onContextMenu={handleContextMenu}
173
+ onSubmitEdit={handleSubmitEdit}
174
+ onCancelEdit={cancelEditing}
175
+ />
176
+ ))}
177
+ {isRootEditing && (
178
+ <InlineInput
179
+ depth={0}
180
+ onSubmit={handleSubmitEdit}
181
+ onCancel={cancelEditing}
182
+ />
183
+ )}
184
+ </ul>
185
+ )}
186
+ </div>
187
+ </div>
188
+
189
+ {contextMenu && (
190
+ <ContextMenu
191
+ x={contextMenu.x}
192
+ y={contextMenu.y}
193
+ items={buildMenuItems()}
194
+ onClose={() => setContextMenu(null)}
195
+ />
196
+ )}
197
+
198
+ {pendingDelete && (
199
+ <ConfirmDialog
200
+ title={t("explorer.confirmDelete")}
201
+ message={t("explorer.confirmDeleteMessage", { name: pendingDelete.split("/").pop() })}
202
+ onConfirm={() => {
203
+ deleteNode(pendingDelete);
204
+ setPendingDelete(null);
205
+ }}
206
+ onCancel={() => setPendingDelete(null)}
207
+ />
208
+ )}
209
+ </>
210
+ );
211
+
212
+ if (hideOuterShell) {
213
+ return <div className="flex flex-col flex-1 overflow-hidden">{content}</div>;
214
+ }
215
+
216
+ return (
217
+ <div className="w-60 bg-[var(--color-bg-primary)] border-r border-[var(--color-border-primary)] flex flex-col flex-shrink-0">
218
+ {content}
219
+ </div>
220
+ );
221
+ }
@@ -0,0 +1,55 @@
1
+ import { useEffect, useRef } from "react";
2
+
3
+ interface InlineInputProps {
4
+ defaultValue?: string;
5
+ depth: number;
6
+ onSubmit: (value: string) => void;
7
+ onCancel: () => void;
8
+ }
9
+
10
+ export function InlineInput({ defaultValue = "", depth, onSubmit, onCancel }: InlineInputProps) {
11
+ const ref = useRef<HTMLInputElement>(null);
12
+ const committed = useRef(false);
13
+
14
+ useEffect(() => {
15
+ const el = ref.current;
16
+ if (!el) return;
17
+ el.focus();
18
+ // Select name part (before extension) if there's a dot
19
+ const dotIndex = defaultValue.lastIndexOf(".");
20
+ if (dotIndex > 0) {
21
+ el.setSelectionRange(0, dotIndex);
22
+ } else {
23
+ el.select();
24
+ }
25
+ }, [defaultValue]);
26
+
27
+ const handleKeyDown = (e: React.KeyboardEvent) => {
28
+ if (e.key === "Enter") {
29
+ const val = ref.current?.value.trim();
30
+ committed.current = true;
31
+ if (val) onSubmit(val);
32
+ else onCancel();
33
+ } else if (e.key === "Escape") {
34
+ committed.current = true;
35
+ onCancel();
36
+ }
37
+ };
38
+
39
+ const handleBlur = () => {
40
+ if (!committed.current) onCancel();
41
+ };
42
+
43
+ return (
44
+ <div style={{ paddingLeft: `${depth * 16 + 24}px` }} className="py-0.5 pr-2">
45
+ <input
46
+ ref={ref}
47
+ type="text"
48
+ defaultValue={defaultValue}
49
+ onKeyDown={handleKeyDown}
50
+ onBlur={handleBlur}
51
+ className="w-full px-1 py-0.5 text-xs bg-[var(--color-bg-tertiary)] text-[var(--color-text-primary)] border border-[var(--color-accent)] rounded outline-none"
52
+ />
53
+ </div>
54
+ );
55
+ }
@@ -0,0 +1,121 @@
1
+ import { memo } from "react";
2
+ import { ChevronRight, ChevronDown } from "lucide-react";
3
+ import type { TreeNode, EditingNode } from "../../types";
4
+ import { getFileIcon } from "../../utils/file-icon";
5
+ import { InlineInput } from "./InlineInput";
6
+
7
+ interface TreeNodeItemProps {
8
+ node: TreeNode;
9
+ depth: number;
10
+ selectedPath: string | null;
11
+ editingNode: EditingNode | null;
12
+ onToggle: (path: string) => void;
13
+ onOpenFile: (node: TreeNode) => void;
14
+ onContextMenu: (e: React.MouseEvent, node: TreeNode) => void;
15
+ onSubmitEdit: (value: string) => void;
16
+ onCancelEdit: () => void;
17
+ }
18
+
19
+ function TreeNodeItemInner({
20
+ node,
21
+ depth,
22
+ selectedPath,
23
+ editingNode,
24
+ onToggle,
25
+ onOpenFile,
26
+ onContextMenu,
27
+ onSubmitEdit,
28
+ onCancelEdit,
29
+ }: TreeNodeItemProps) {
30
+ const isDir = node.type === "directory";
31
+ const isSelected = selectedPath === node.path;
32
+ const isRenaming = editingNode?.path === node.path && editingNode.type === "rename";
33
+ const isAddingChild =
34
+ isDir &&
35
+ node.expanded &&
36
+ editingNode?.path === node.path &&
37
+ (editingNode.type === "newFile" || editingNode.type === "newDir");
38
+
39
+ return (
40
+ <li>
41
+ <div
42
+ className={`flex items-center gap-1.5 px-2 py-0.5 text-xs rounded cursor-pointer transition-colors ${
43
+ isSelected ? "bg-[var(--color-accent)]/30 text-[var(--color-text-primary)]" : "hover:bg-[var(--color-bg-hover)]"
44
+ }`}
45
+ style={{ paddingLeft: `${depth * 16 + 8}px` }}
46
+ onClick={() => isDir ? onToggle(node.path) : onOpenFile(node)}
47
+ onContextMenu={(e) => {
48
+ e.preventDefault();
49
+ e.stopPropagation();
50
+ onContextMenu(e, node);
51
+ }}
52
+ >
53
+ {isDir ? (
54
+ node.expanded ? (
55
+ <ChevronDown className="w-3 h-3 text-[var(--color-text-placeholder)] shrink-0" />
56
+ ) : (
57
+ <ChevronRight className="w-3 h-3 text-[var(--color-text-placeholder)] shrink-0" />
58
+ )
59
+ ) : (
60
+ <span className="w-3 shrink-0" />
61
+ )}
62
+ {getFileIcon(node)}
63
+ {isRenaming ? (
64
+ <InlineInput
65
+ defaultValue={node.name}
66
+ depth={depth}
67
+ onSubmit={onSubmitEdit}
68
+ onCancel={onCancelEdit}
69
+ />
70
+ ) : (
71
+ <span className={`truncate ${isDir ? "text-blue-300 font-medium" : "text-[var(--color-text-secondary)]"}`}>
72
+ {node.name}
73
+ </span>
74
+ )}
75
+ </div>
76
+ {isDir && node.expanded && node.children && (
77
+ <ul>
78
+ {node.children.map((child) => (
79
+ <TreeNodeItem
80
+ key={child.path}
81
+ node={child}
82
+ depth={depth + 1}
83
+ selectedPath={selectedPath}
84
+ editingNode={editingNode}
85
+ onToggle={onToggle}
86
+ onOpenFile={onOpenFile}
87
+ onContextMenu={onContextMenu}
88
+ onSubmitEdit={onSubmitEdit}
89
+ onCancelEdit={onCancelEdit}
90
+ />
91
+ ))}
92
+ {isAddingChild && (
93
+ <InlineInput
94
+ depth={depth + 1}
95
+ onSubmit={onSubmitEdit}
96
+ onCancel={onCancelEdit}
97
+ />
98
+ )}
99
+ </ul>
100
+ )}
101
+ </li>
102
+ );
103
+ }
104
+
105
+ export const TreeNodeItem = memo(TreeNodeItemInner, (prev, next) => {
106
+ // Fast path: same node reference and no editing state change
107
+ if (
108
+ prev.node === next.node &&
109
+ prev.selectedPath === next.selectedPath &&
110
+ prev.editingNode === next.editingNode &&
111
+ prev.depth === next.depth &&
112
+ prev.onToggle === next.onToggle &&
113
+ prev.onOpenFile === next.onOpenFile &&
114
+ prev.onContextMenu === next.onContextMenu &&
115
+ prev.onSubmitEdit === next.onSubmitEdit &&
116
+ prev.onCancelEdit === next.onCancelEdit
117
+ ) {
118
+ return true;
119
+ }
120
+ return false;
121
+ });
@@ -0,0 +1,37 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, screen, cleanup, fireEvent } from "@testing-library/react";
3
+ import React from "react";
4
+
5
+ vi.mock("react-i18next", () => ({
6
+ useTranslation: () => ({ t: (k: string) => k }),
7
+ }));
8
+
9
+ describe("ConfirmDialog", () => {
10
+ afterEach(() => {
11
+ cleanup();
12
+ vi.clearAllMocks();
13
+ });
14
+
15
+ it("should render title and message", async () => {
16
+ const { ConfirmDialog } = await import("../ConfirmDialog");
17
+ render(<ConfirmDialog title="Delete?" message="Are you sure?" onConfirm={vi.fn()} onCancel={vi.fn()} />);
18
+ expect(screen.getByText("Delete?")).toBeDefined();
19
+ expect(screen.getByText("Are you sure?")).toBeDefined();
20
+ });
21
+
22
+ it("should call onConfirm when confirm button clicked", async () => {
23
+ const onConfirm = vi.fn();
24
+ const { ConfirmDialog } = await import("../ConfirmDialog");
25
+ render(<ConfirmDialog title="T" message="M" onConfirm={onConfirm} onCancel={vi.fn()} />);
26
+ fireEvent.click(screen.getByText("common.delete"));
27
+ expect(onConfirm).toHaveBeenCalled();
28
+ });
29
+
30
+ it("should call onCancel when cancel button clicked", async () => {
31
+ const onCancel = vi.fn();
32
+ const { ConfirmDialog } = await import("../ConfirmDialog");
33
+ render(<ConfirmDialog title="T" message="M" onConfirm={vi.fn()} onCancel={onCancel} />);
34
+ fireEvent.click(screen.getByText("common.cancel"));
35
+ expect(onCancel).toHaveBeenCalled();
36
+ });
37
+ });
@@ -0,0 +1,49 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, screen, cleanup, fireEvent } from "@testing-library/react";
3
+ import React from "react";
4
+
5
+ describe("ContextMenu", () => {
6
+ afterEach(cleanup);
7
+
8
+ it("should render menu items", async () => {
9
+ const { ContextMenu } = await import("../ContextMenu");
10
+ const items = [
11
+ { label: "Open", onClick: vi.fn() },
12
+ { label: "Delete", onClick: vi.fn(), danger: true },
13
+ ];
14
+ render(<ContextMenu x={100} y={100} items={items} onClose={vi.fn()} />);
15
+ expect(screen.getByText("Open")).toBeDefined();
16
+ expect(screen.getByText("Delete")).toBeDefined();
17
+ });
18
+
19
+ it("should call item onClick and onClose when item clicked", async () => {
20
+ const { ContextMenu } = await import("../ContextMenu");
21
+ const onClick = vi.fn();
22
+ const onClose = vi.fn();
23
+ render(<ContextMenu x={0} y={0} items={[{ label: "Click", onClick }]} onClose={onClose} />);
24
+ fireEvent.click(screen.getByText("Click"));
25
+ expect(onClick).toHaveBeenCalled();
26
+ expect(onClose).toHaveBeenCalled();
27
+ });
28
+
29
+ it("should render divider when specified", async () => {
30
+ const { ContextMenu } = await import("../ContextMenu");
31
+ const items = [
32
+ { label: "A", onClick: vi.fn() },
33
+ { label: "", onClick: vi.fn(), divider: true },
34
+ { label: "B", onClick: vi.fn() },
35
+ ];
36
+ const { container } = render(<ContextMenu x={0} y={0} items={items} onClose={vi.fn()} />);
37
+ const dividers = container.querySelectorAll(".border-t");
38
+ expect(dividers.length).toBe(1);
39
+ });
40
+
41
+ it("should render icon when provided", async () => {
42
+ const { ContextMenu } = await import("../ContextMenu");
43
+ const items = [
44
+ { label: "Open", onClick: vi.fn(), icon: <span data-testid="icon">🔍</span> },
45
+ ];
46
+ render(<ContextMenu x={0} y={0} items={items} onClose={vi.fn()} />);
47
+ expect(screen.getByTestId("icon")).toBeDefined();
48
+ });
49
+ });
@@ -0,0 +1,48 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, screen, cleanup, fireEvent } from "@testing-library/react";
3
+ import React from "react";
4
+
5
+ describe("InlineInput", () => {
6
+ afterEach(() => {
7
+ cleanup();
8
+ vi.clearAllMocks();
9
+ });
10
+
11
+ it("should render input with defaultValue", async () => {
12
+ const { InlineInput } = await import("../InlineInput");
13
+ render(<InlineInput defaultValue="file.ts" depth={0} onSubmit={vi.fn()} onCancel={vi.fn()} />);
14
+ const input = screen.getByDisplayValue("file.ts");
15
+ expect(input).toBeDefined();
16
+ });
17
+
18
+ it("should call onSubmit on Enter", async () => {
19
+ const onSubmit = vi.fn();
20
+ const { InlineInput } = await import("../InlineInput");
21
+ render(<InlineInput defaultValue="name" depth={0} onSubmit={onSubmit} onCancel={vi.fn()} />);
22
+ fireEvent.keyDown(screen.getByDisplayValue("name"), { key: "Enter" });
23
+ expect(onSubmit).toHaveBeenCalledWith("name");
24
+ });
25
+
26
+ it("should call onCancel on Escape", async () => {
27
+ const onCancel = vi.fn();
28
+ const { InlineInput } = await import("../InlineInput");
29
+ render(<InlineInput defaultValue="" depth={0} onSubmit={vi.fn()} onCancel={onCancel} />);
30
+ fireEvent.keyDown(screen.getByRole("textbox"), { key: "Escape" });
31
+ expect(onCancel).toHaveBeenCalled();
32
+ });
33
+
34
+ it("should call onCancel on blur", async () => {
35
+ const onCancel = vi.fn();
36
+ const { InlineInput } = await import("../InlineInput");
37
+ render(<InlineInput defaultValue="" depth={0} onSubmit={vi.fn()} onCancel={onCancel} />);
38
+ fireEvent.blur(screen.getByRole("textbox"));
39
+ expect(onCancel).toHaveBeenCalled();
40
+ });
41
+
42
+ it("should apply depth-based padding", async () => {
43
+ const { InlineInput } = await import("../InlineInput");
44
+ const { container } = render(<InlineInput depth={2} onSubmit={vi.fn()} onCancel={vi.fn()} />);
45
+ const wrapper = container.firstChild as HTMLElement;
46
+ expect(wrapper.style.paddingLeft).toBe("56px");
47
+ });
48
+ });
@@ -0,0 +1,146 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, screen, cleanup, fireEvent } from "@testing-library/react";
3
+ import React from "react";
4
+
5
+ vi.mock("../../utils/file-icon", () => ({
6
+ getFileIcon: () => <span data-testid="file-icon" />,
7
+ }));
8
+
9
+ vi.mock("./InlineInput", () => ({
10
+ InlineInput: ({ onSubmit }: any) => (
11
+ <input data-testid="inline-input" onKeyDown={(e: any) => e.key === "Enter" && onSubmit("new")} />
12
+ ),
13
+ }));
14
+
15
+ describe("TreeNodeItem", () => {
16
+ const fileNode = { name: "app.ts", path: "/src/app.ts", type: "file" as const };
17
+ const dirNode = {
18
+ name: "src",
19
+ path: "/src",
20
+ type: "directory" as const,
21
+ expanded: false,
22
+ children: [] as any[],
23
+ };
24
+
25
+ afterEach(cleanup);
26
+
27
+ it("should render file name", async () => {
28
+ const { TreeNodeItem } = await import("../TreeNodeItem");
29
+ render(
30
+ <TreeNodeItem
31
+ node={fileNode}
32
+ depth={0}
33
+ selectedPath={null}
34
+ editingNode={null}
35
+ onToggle={vi.fn()}
36
+ onOpenFile={vi.fn()}
37
+ onContextMenu={vi.fn()}
38
+ onSubmitEdit={vi.fn()}
39
+ onCancelEdit={vi.fn()}
40
+ />,
41
+ );
42
+ expect(screen.getByText("app.ts")).toBeDefined();
43
+ });
44
+
45
+ it("should render directory name", async () => {
46
+ const { TreeNodeItem } = await import("../TreeNodeItem");
47
+ render(
48
+ <TreeNodeItem
49
+ node={dirNode}
50
+ depth={0}
51
+ selectedPath={null}
52
+ editingNode={null}
53
+ onToggle={vi.fn()}
54
+ onOpenFile={vi.fn()}
55
+ onContextMenu={vi.fn()}
56
+ onSubmitEdit={vi.fn()}
57
+ onCancelEdit={vi.fn()}
58
+ />,
59
+ );
60
+ expect(screen.getByText("src")).toBeDefined();
61
+ });
62
+
63
+ it("should call onToggle when directory clicked", async () => {
64
+ const onToggle = vi.fn();
65
+ const { TreeNodeItem } = await import("../TreeNodeItem");
66
+ render(
67
+ <TreeNodeItem
68
+ node={dirNode}
69
+ depth={0}
70
+ selectedPath={null}
71
+ editingNode={null}
72
+ onToggle={onToggle}
73
+ onOpenFile={vi.fn()}
74
+ onContextMenu={vi.fn()}
75
+ onSubmitEdit={vi.fn()}
76
+ onCancelEdit={vi.fn()}
77
+ />,
78
+ );
79
+ fireEvent.click(screen.getByText("src"));
80
+ expect(onToggle).toHaveBeenCalledWith("/src");
81
+ });
82
+
83
+ it("should call onOpenFile when file clicked", async () => {
84
+ const onOpenFile = vi.fn();
85
+ const { TreeNodeItem } = await import("../TreeNodeItem");
86
+ render(
87
+ <TreeNodeItem
88
+ node={fileNode}
89
+ depth={0}
90
+ selectedPath={null}
91
+ editingNode={null}
92
+ onToggle={vi.fn()}
93
+ onOpenFile={onOpenFile}
94
+ onContextMenu={vi.fn()}
95
+ onSubmitEdit={vi.fn()}
96
+ onCancelEdit={vi.fn()}
97
+ />,
98
+ );
99
+ fireEvent.click(screen.getByText("app.ts"));
100
+ expect(onOpenFile).toHaveBeenCalledWith(fileNode);
101
+ });
102
+
103
+ it("should apply selected style when selected", async () => {
104
+ const { TreeNodeItem } = await import("../TreeNodeItem");
105
+ const { container } = render(
106
+ <TreeNodeItem
107
+ node={fileNode}
108
+ depth={0}
109
+ selectedPath="/src/app.ts"
110
+ editingNode={null}
111
+ onToggle={vi.fn()}
112
+ onOpenFile={vi.fn()}
113
+ onContextMenu={vi.fn()}
114
+ onSubmitEdit={vi.fn()}
115
+ onCancelEdit={vi.fn()}
116
+ />,
117
+ );
118
+ const div = container.querySelector(".bg-\\[var\\(--color-accent\\)\\]\\/30");
119
+ expect(div).toBeDefined();
120
+ });
121
+
122
+ it("should render children when directory is expanded", async () => {
123
+ const expandedDir = {
124
+ name: "src",
125
+ path: "/src",
126
+ type: "directory" as const,
127
+ expanded: true,
128
+ children: [{ name: "index.ts", path: "/src/index.ts", type: "file" as const }],
129
+ };
130
+ const { TreeNodeItem } = await import("../TreeNodeItem");
131
+ render(
132
+ <TreeNodeItem
133
+ node={expandedDir}
134
+ depth={0}
135
+ selectedPath={null}
136
+ editingNode={null}
137
+ onToggle={vi.fn()}
138
+ onOpenFile={vi.fn()}
139
+ onContextMenu={vi.fn()}
140
+ onSubmitEdit={vi.fn()}
141
+ onCancelEdit={vi.fn()}
142
+ />,
143
+ );
144
+ expect(screen.getByText("index.ts")).toBeDefined();
145
+ });
146
+ });