@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,117 @@
1
+ import { useState, useEffect } from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { Plus, Trash2, Shield, CheckCircle2, Circle } from "lucide-react";
4
+ import { useRulesStore } from "../../stores/use-rules-store";
5
+
6
+ export function RulesPanel() {
7
+ const { t } = useTranslation();
8
+ const [showForm, setShowForm] = useState(false);
9
+ const [name, setName] = useState("");
10
+ const [pattern, setPattern] = useState("");
11
+ const rules = useRulesStore((s) => s.rules);
12
+ const fetchRules = useRulesStore((s) => s.fetchRules);
13
+ const addRule = useRulesStore((s) => s.addRule);
14
+ const toggleRule = useRulesStore((s) => s.toggleRule);
15
+ const removeRule = useRulesStore((s) => s.removeRule);
16
+
17
+ useEffect(() => {
18
+ fetchRules();
19
+ }, [fetchRules]);
20
+
21
+ const handleAdd = () => {
22
+ if (!name.trim() || !pattern.trim()) return;
23
+ addRule(name.trim(), pattern.trim());
24
+ setName("");
25
+ setPattern("");
26
+ setShowForm(false);
27
+ };
28
+
29
+ return (
30
+ <div className="flex flex-col h-full">
31
+ <div className="p-3 border-b border-[var(--color-border-primary)] flex items-center justify-between">
32
+ <div className="flex items-center gap-2 text-sm text-[var(--color-text-secondary)]">
33
+ <Shield className="w-4 h-4" />
34
+ {t("rules.title")}
35
+ </div>
36
+ <button
37
+ onClick={() => setShowForm(!showForm)}
38
+ className="flex items-center gap-1 px-2 py-1 text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded text-[var(--color-text-primary)]"
39
+ >
40
+ <Plus className="w-3 h-3" />
41
+ {t("rules.add")}
42
+ </button>
43
+ </div>
44
+
45
+ {showForm && (
46
+ <div className="p-3 border-b border-[var(--color-border-primary)] bg-[var(--color-bg-secondary)] flex flex-col gap-2">
47
+ <input
48
+ type="text"
49
+ value={name}
50
+ onChange={(e) => setName(e.target.value)}
51
+ placeholder={t("rules.namePlaceholder")}
52
+ className="bg-[var(--color-bg-primary)] text-[var(--color-text-secondary)] px-3 py-1.5 rounded text-sm border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
53
+ />
54
+ <input
55
+ type="text"
56
+ value={pattern}
57
+ onChange={(e) => setPattern(e.target.value)}
58
+ placeholder={t("rules.patternPlaceholder")}
59
+ className="bg-[var(--color-bg-primary)] text-[var(--color-text-secondary)] px-3 py-1.5 rounded text-sm font-mono border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
60
+ />
61
+ <button
62
+ onClick={handleAdd}
63
+ disabled={!name.trim() || !pattern.trim()}
64
+ className="self-end px-3 py-1 text-xs bg-green-600 hover:bg-green-500 disabled:opacity-40 rounded text-white"
65
+ >
66
+ {t("rules.save")}
67
+ </button>
68
+ </div>
69
+ )}
70
+
71
+ <div className="flex-1 overflow-auto p-3">
72
+ {rules.length === 0 ? (
73
+ <div className="flex flex-col items-center justify-center h-full text-gray-600">
74
+ <Shield className="w-12 h-12 mb-3 opacity-30" />
75
+ <span className="text-sm">{t("rules.empty")}</span>
76
+ <span className="text-xs mt-1">{t("rules.emptyHint")}</span>
77
+ </div>
78
+ ) : (
79
+ <div className="space-y-2.5">
80
+ {rules.map((rule) => (
81
+ <div
82
+ key={rule.id}
83
+ onClick={() => toggleRule(rule.id)}
84
+ className="group relative bg-[var(--color-bg-secondary)]/60 border border-[var(--color-border-primary)]/80 rounded-lg p-3 cursor-pointer hover:bg-[var(--color-bg-secondary)] hover:border-[var(--color-border-secondary)] transition-all"
85
+ >
86
+ <div className="flex items-start justify-between gap-2">
87
+ <div className="flex items-center gap-2 min-w-0 flex-1">
88
+ {rule.enabled ? (
89
+ <CheckCircle2 className="w-4 h-4 text-[var(--color-text-success)] flex-shrink-0 mt-0.5" />
90
+ ) : (
91
+ <Circle className="w-4 h-4 text-[var(--color-text-placeholder)] flex-shrink-0 mt-0.5" />
92
+ )}
93
+ <span className={`font-semibold text-sm truncate ${rule.enabled ? "text-[var(--color-text-secondary)]" : "text-[var(--color-text-placeholder)]"}`}>
94
+ {rule.name}
95
+ </span>
96
+ </div>
97
+ <code className="text-[11px] font-mono text-[var(--color-text-placeholder)] bg-[var(--color-bg-primary)]/80 px-1.5 py-0.5 rounded flex-shrink-0 hidden sm:block">
98
+ {rule.pattern}
99
+ </code>
100
+ <button
101
+ onClick={(e) => { e.stopPropagation(); removeRule(rule.id); }}
102
+ className="text-gray-600 hover:text-[var(--color-text-error)] opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0"
103
+ >
104
+ <Trash2 className="w-3.5 h-3.5" />
105
+ </button>
106
+ </div>
107
+ <p className={`text-xs mt-1.5 ml-6 ${rule.enabled ? "text-[var(--color-text-tertiary)]" : "text-gray-600"}`}>
108
+ {t("rules.pattern")} <code className="font-mono text-[var(--color-text-placeholder)]">{rule.pattern}</code>
109
+ </p>
110
+ </div>
111
+ ))}
112
+ </div>
113
+ )}
114
+ </div>
115
+ </div>
116
+ );
117
+ }
@@ -0,0 +1,91 @@
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
+ const mockAddRule = vi.fn();
6
+ const mockToggleRule = vi.fn();
7
+ const mockRemoveRule = vi.fn();
8
+ const mockFetchRules = vi.fn();
9
+
10
+ vi.mock("../../../stores/use-rules-store", () => ({
11
+ useRulesStore: (selector: any) =>
12
+ selector({
13
+ rules: [
14
+ { id: "1", name: "No Console", pattern: "*.ts", enabled: true },
15
+ { id: "2", name: "Test Rule", pattern: "*.test.*", enabled: false },
16
+ ],
17
+ fetchRules: mockFetchRules,
18
+ addRule: mockAddRule,
19
+ toggleRule: mockToggleRule,
20
+ removeRule: mockRemoveRule,
21
+ }),
22
+ }));
23
+
24
+ vi.mock("react-i18next", () => ({
25
+ useTranslation: () => ({ t: (k: string) => k }),
26
+ }));
27
+
28
+ describe("RulesPanel", () => {
29
+ afterEach(() => {
30
+ cleanup();
31
+ vi.clearAllMocks();
32
+ });
33
+
34
+ it("should render rules title", async () => {
35
+ const { RulesPanel } = await import("../RulesPanel");
36
+ render(<RulesPanel />);
37
+ expect(screen.getByText("rules.title")).toBeDefined();
38
+ });
39
+
40
+ it("should render add button", async () => {
41
+ const { RulesPanel } = await import("../RulesPanel");
42
+ render(<RulesPanel />);
43
+ expect(screen.getByText("rules.add")).toBeDefined();
44
+ });
45
+
46
+ it("should display rule items", async () => {
47
+ const { RulesPanel } = await import("../RulesPanel");
48
+ render(<RulesPanel />);
49
+ expect(screen.getByText("No Console")).toBeDefined();
50
+ expect(screen.getByText("Test Rule")).toBeDefined();
51
+ });
52
+
53
+ it("should call fetchRules on mount", async () => {
54
+ const { RulesPanel } = await import("../RulesPanel");
55
+ render(<RulesPanel />);
56
+ expect(mockFetchRules).toHaveBeenCalled();
57
+ });
58
+
59
+ it("should show form when add button is clicked", async () => {
60
+ const { RulesPanel } = await import("../RulesPanel");
61
+ render(<RulesPanel />);
62
+ fireEvent.click(screen.getByText("rules.add"));
63
+ expect(screen.getByPlaceholderText("rules.namePlaceholder")).toBeDefined();
64
+ expect(screen.getByPlaceholderText("rules.patternPlaceholder")).toBeDefined();
65
+ });
66
+
67
+ it("should call addRule on form submit", async () => {
68
+ const { RulesPanel } = await import("../RulesPanel");
69
+ render(<RulesPanel />);
70
+ fireEvent.click(screen.getByText("rules.add"));
71
+ fireEvent.change(screen.getByPlaceholderText("rules.namePlaceholder"), { target: { value: "New Rule" } });
72
+ fireEvent.change(screen.getByPlaceholderText("rules.patternPlaceholder"), { target: { value: "*.js" } });
73
+ fireEvent.click(screen.getByText("rules.save"));
74
+ expect(mockAddRule).toHaveBeenCalledWith("New Rule", "*.js");
75
+ });
76
+
77
+ it("should call toggleRule on rule click", async () => {
78
+ const { RulesPanel } = await import("../RulesPanel");
79
+ render(<RulesPanel />);
80
+ fireEvent.click(screen.getByText("No Console"));
81
+ expect(mockToggleRule).toHaveBeenCalledWith("1");
82
+ });
83
+
84
+ it("should render rule patterns", async () => {
85
+ const { RulesPanel } = await import("../RulesPanel");
86
+ render(<RulesPanel />);
87
+ const patterns = screen.getAllByText("*.ts");
88
+ expect(patterns.length).toBeGreaterThanOrEqual(1);
89
+ expect(screen.getAllByText("*.test.*").length).toBeGreaterThanOrEqual(1);
90
+ });
91
+ });
@@ -0,0 +1,404 @@
1
+ import { useState, useCallback, useRef, useEffect } from "react";
2
+ import {
3
+ Search,
4
+ CaseSensitive,
5
+ WholeWord,
6
+ Regex,
7
+ FileText,
8
+ ChevronRight,
9
+ ChevronDown,
10
+ Loader2,
11
+ X,
12
+ } from "lucide-react";
13
+ import { apiClient } from "../../lib/api-client";
14
+ import { useExplorerStore } from "../../stores/use-explorer-store";
15
+ import type { TreeNode } from "../../types";
16
+
17
+ interface SearchMatch {
18
+ file: string;
19
+ line: number;
20
+ column: number;
21
+ text: string;
22
+ highlightStart: number;
23
+ highlightEnd: number;
24
+ }
25
+
26
+ interface FileGroup {
27
+ filePath: string;
28
+ relativePath: string;
29
+ matches: SearchMatch[];
30
+ expanded: boolean;
31
+ }
32
+
33
+ const SKIP_DIRS = new Set([
34
+ "node_modules",
35
+ ".git",
36
+ "dist",
37
+ "build",
38
+ ".next",
39
+ ".nuxt",
40
+ "coverage",
41
+ ".cache",
42
+ ".turbo",
43
+ ".vercel",
44
+ "out",
45
+ ".output",
46
+ ]);
47
+
48
+ const TEXT_EXTENSIONS = new Set([
49
+ "ts", "tsx", "js", "jsx", "mjs", "cjs",
50
+ "json", "md", "mdx", "yaml", "yml", "toml",
51
+ "css", "scss", "less", "sass",
52
+ "html", "htm", "xml", "svg",
53
+ "py", "rb", "go", "rs", "java", "kt", "swift", "c", "cpp", "h", "hpp",
54
+ "sh", "bash", "zsh", "fish",
55
+ "sql", "graphql", "gql",
56
+ "txt", "csv", "env", "gitignore", "eslintrc", "prettierrc",
57
+ "conf", "ini", "cfg", "log",
58
+ "vue", "svelte",
59
+ ]);
60
+
61
+ function isTextFile(name: string): boolean {
62
+ const dotIdx = name.lastIndexOf(".");
63
+ if (dotIdx === -1) return false;
64
+ const ext = name.slice(dotIdx + 1).toLowerCase();
65
+ if (TEXT_EXTENSIONS.has(ext)) return true;
66
+ if (name.startsWith(".") && TEXT_EXTENSIONS.has(name.slice(1))) return true;
67
+ return false;
68
+ }
69
+
70
+ function buildSearchRegex(query: string, caseSensitive: boolean, wholeWord: boolean, useRegex: boolean): RegExp {
71
+ let pattern = useRegex ? query : query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
72
+ if (wholeWord) pattern = `\\b${pattern}\\b`;
73
+ return new RegExp(pattern, caseSensitive ? "g" : "gi");
74
+ }
75
+
76
+ export function SearchPanel() {
77
+ const [query, setQuery] = useState("");
78
+ const [caseSensitive, setCaseSensitive] = useState(false);
79
+ const [wholeWord, setWholeWord] = useState(false);
80
+ const [useRegex, setUseRegex] = useState(false);
81
+ const [results, setResults] = useState<FileGroup[]>([]);
82
+ const [isSearching, setIsSearching] = useState(false);
83
+ const [totalMatches, setTotalMatches] = useState(0);
84
+ const [filesSearched, setFilesSearched] = useState(0);
85
+ const [hasSearched, setHasSearched] = useState(false);
86
+ const inputRef = useRef<HTMLInputElement>(null);
87
+ const abortRef = useRef(false);
88
+
89
+ const currentPath = useExplorerStore((s) => s.currentPath);
90
+
91
+ useEffect(() => {
92
+ inputRef.current?.focus();
93
+ }, []);
94
+
95
+ const collectFiles = useCallback(async (dirPath: string): Promise<string[]> => {
96
+ const files: string[] = [];
97
+ const queue = [dirPath];
98
+
99
+ while (queue.length > 0 && !abortRef.current) {
100
+ const current = queue.shift()!;
101
+ try {
102
+ const res = await apiClient.call("file.listDir", { path: current });
103
+ for (const entry of res.entries) {
104
+ if (abortRef.current) break;
105
+ if (entry.name.startsWith(".") && entry.name !== ".env" && entry.name !== ".env.local") continue;
106
+ if (entry.type === "directory") {
107
+ if (!SKIP_DIRS.has(entry.name)) queue.push(entry.path);
108
+ } else if (isTextFile(entry.name)) {
109
+ files.push(entry.path);
110
+ }
111
+ }
112
+ } catch {
113
+ // skip unreadable dirs
114
+ }
115
+ }
116
+ return files;
117
+ }, []);
118
+
119
+ const performSearch = useCallback(async () => {
120
+ if (!query.trim() || !currentPath) return;
121
+
122
+ abortRef.current = false;
123
+ setIsSearching(true);
124
+ setHasSearched(true);
125
+ setResults([]);
126
+ setTotalMatches(0);
127
+
128
+ try {
129
+ const regex = buildSearchRegex(query.trim(), caseSensitive, wholeWord, useRegex);
130
+ const filePaths = await collectFiles(currentPath);
131
+ const matchMap = new Map<string, SearchMatch[]>();
132
+ let matchCount = 0;
133
+
134
+ for (const fp of filePaths) {
135
+ if (abortRef.current) break;
136
+ try {
137
+ const res = await apiClient.call("file.readFile", { path: fp });
138
+ const lines = res.content.split("\n");
139
+ for (let i = 0; i < lines.length; i++) {
140
+ const line = lines[i];
141
+ regex.lastIndex = 0;
142
+ const m = regex.exec(line);
143
+ if (m) {
144
+ if (!matchMap.has(fp)) matchMap.set(fp, []);
145
+ matchMap.get(fp)!.push({
146
+ file: fp,
147
+ line: i + 1,
148
+ column: m.index + 1,
149
+ text: line,
150
+ highlightStart: m.index,
151
+ highlightEnd: m.index + m[0].length,
152
+ });
153
+ matchCount++;
154
+ }
155
+ }
156
+ } catch {
157
+ // skip unreadable files
158
+ }
159
+ }
160
+
161
+ setFilesSearched(filePaths.length);
162
+
163
+ const rootPath = currentPath.endsWith("/") ? currentPath : currentPath + "/";
164
+ const groups: FileGroup[] = [];
165
+ for (const [filePath, matches] of matchMap) {
166
+ groups.push({
167
+ filePath,
168
+ relativePath: filePath.startsWith(rootPath) ? filePath.slice(rootPath.length) : filePath,
169
+ matches,
170
+ expanded: true,
171
+ });
172
+ }
173
+
174
+ setResults(groups);
175
+ setTotalMatches(matchCount);
176
+ } catch {
177
+ // search error
178
+ } finally {
179
+ setIsSearching(false);
180
+ }
181
+ }, [query, caseSensitive, wholeWord, useRegex, currentPath, collectFiles]);
182
+
183
+ const cancelSearch = useCallback(() => {
184
+ abortRef.current = true;
185
+ }, []);
186
+
187
+ const handleKeyDown = useCallback(
188
+ (e: React.KeyboardEvent) => {
189
+ if (e.key === "Enter" && !isSearching) {
190
+ performSearch();
191
+ }
192
+ if (e.key === "Escape") {
193
+ setQuery("");
194
+ inputRef.current?.focus();
195
+ }
196
+ },
197
+ [performSearch, isSearching],
198
+ );
199
+
200
+ const toggleGroup = useCallback((index: number) => {
201
+ setResults((prev) => prev.map((g, i) => (i === index ? { ...g, expanded: !g.expanded } : g)));
202
+ }, []);
203
+
204
+ const handleOpenFile = useCallback((filePath: string, _line: number) => {
205
+ const node: TreeNode = {
206
+ name: filePath.split("/").pop() || filePath,
207
+ path: filePath,
208
+ type: "file",
209
+ };
210
+ useExplorerStore.getState().openFile(node);
211
+ }, []);
212
+
213
+ const modKey = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent) ? "⌘" : "Ctrl";
214
+
215
+ return (
216
+ <div className="flex flex-col h-full bg-[var(--color-bg-primary)]">
217
+ {/* Header */}
218
+ <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 flex-shrink-0">
219
+ <div className="flex items-center gap-1.5">
220
+ <Search className="w-3.5 h-3.5" />
221
+ Search
222
+ </div>
223
+ <kbd className="px-1.5 py-0.5 text-[10px] text-[var(--color-text-placeholder)] bg-[var(--color-bg-secondary)] border border-[var(--color-border-primary)] rounded font-mono">
224
+ {modKey}⇧F
225
+ </kbd>
226
+ </div>
227
+
228
+ {/* Search input */}
229
+ <div className="p-2 border-b border-[var(--color-border-primary)] flex-shrink-0">
230
+ <div className="relative">
231
+ <Search className="absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-[var(--color-text-placeholder)]" />
232
+ <input
233
+ ref={inputRef}
234
+ type="text"
235
+ value={query}
236
+ onChange={(e) => setQuery(e.target.value)}
237
+ onKeyDown={handleKeyDown}
238
+ placeholder="Search in files..."
239
+ className="w-full pl-7 pr-7 py-1.5 text-xs bg-[var(--color-bg-secondary)] rounded text-[var(--color-text-primary)] border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
240
+ />
241
+ {query && (
242
+ <button
243
+ onClick={() => {
244
+ setQuery("");
245
+ inputRef.current?.focus();
246
+ }}
247
+ className="absolute right-2 top-1/2 -translate-y-1/2 text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)]"
248
+ >
249
+ <X className="w-3 h-3" />
250
+ </button>
251
+ )}
252
+ </div>
253
+
254
+ {/* Toggle buttons */}
255
+ <div className="flex items-center gap-0.5 mt-1.5">
256
+ <button
257
+ onClick={() => setCaseSensitive((v) => !v)}
258
+ className={`p-1 rounded text-xs transition-colors ${
259
+ caseSensitive
260
+ ? "bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] border border-[var(--color-accent)]/50"
261
+ : "text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)] border border-transparent"
262
+ }`}
263
+ title="Match Case"
264
+ >
265
+ <CaseSensitive className="w-3.5 h-3.5" />
266
+ </button>
267
+ <button
268
+ onClick={() => setWholeWord((v) => !v)}
269
+ className={`p-1 rounded text-xs transition-colors ${
270
+ wholeWord
271
+ ? "bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] border border-[var(--color-accent)]/50"
272
+ : "text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)] border border-transparent"
273
+ }`}
274
+ title="Match Whole Word"
275
+ >
276
+ <WholeWord className="w-3.5 h-3.5" />
277
+ </button>
278
+ <button
279
+ onClick={() => setUseRegex((v) => !v)}
280
+ className={`p-1 rounded text-xs transition-colors ${
281
+ useRegex
282
+ ? "bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] border border-[var(--color-accent)]/50"
283
+ : "text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)] border border-transparent"
284
+ }`}
285
+ title="Use Regular Expression"
286
+ >
287
+ <Regex className="w-3.5 h-3.5" />
288
+ </button>
289
+
290
+ <div className="flex-1" />
291
+
292
+ {isSearching ? (
293
+ <button
294
+ onClick={cancelSearch}
295
+ className="px-2 py-1 text-xs text-[var(--color-text-error)] hover:text-red-300 transition-colors flex items-center gap-1"
296
+ >
297
+ <Loader2 className="w-3 h-3 animate-spin" />
298
+ Cancel
299
+ </button>
300
+ ) : (
301
+ query.trim() && (
302
+ <button
303
+ onClick={performSearch}
304
+ className="px-2 py-1 text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded transition-colors"
305
+ >
306
+ Search
307
+ </button>
308
+ )
309
+ )}
310
+ </div>
311
+ </div>
312
+
313
+ {/* Results header */}
314
+ {hasSearched && !isSearching && (
315
+ <div className="px-3 py-1.5 text-[11px] text-[var(--color-text-placeholder)] border-b border-[var(--color-bg-secondary)] flex-shrink-0">
316
+ {totalMatches > 0 ? (
317
+ <>
318
+ <span className="text-[var(--color-text-accent)] font-medium">{totalMatches}</span> result{totalMatches !== 1 && "s"} in{" "}
319
+ <span className="text-[var(--color-text-accent)] font-medium">{results.length}</span> file
320
+ {results.length !== 1 && "s"}
321
+ <span className="ml-2 text-gray-600">({filesSearched} files searched)</span>
322
+ </>
323
+ ) : (
324
+ "No results found"
325
+ )}
326
+ </div>
327
+ )}
328
+
329
+ {/* Loading state */}
330
+ {isSearching && (
331
+ <div className="flex items-center justify-center py-8 text-[var(--color-text-placeholder)] text-sm flex-shrink-0">
332
+ <Loader2 className="w-4 h-4 animate-spin mr-2" />
333
+ Searching...
334
+ </div>
335
+ )}
336
+
337
+ {/* Results list */}
338
+ <div className="flex-1 overflow-y-auto">
339
+ {!hasSearched && !isSearching ? (
340
+ <div className="flex flex-col items-center justify-center h-full text-gray-600 text-xs px-4">
341
+ <Search className="w-8 h-8 mb-2 text-gray-700" />
342
+ <p>Type a search term and press Enter</p>
343
+ <p className="mt-1 text-gray-700">
344
+ {modKey}+Shift+F to focus search
345
+ </p>
346
+ </div>
347
+ ) : !isSearching && totalMatches === 0 ? (
348
+ <div className="flex flex-col items-center justify-center h-full text-gray-600 text-xs px-4">
349
+ <FileText className="w-8 h-8 mb-2 text-gray-700" />
350
+ <p>No results for "{query}"</p>
351
+ <p className="mt-1 text-gray-700">Try different search terms</p>
352
+ </div>
353
+ ) : (
354
+ <div className="py-1">
355
+ {results.map((group, gi) => (
356
+ <div key={group.filePath}>
357
+ {/* File group header */}
358
+ <button
359
+ onClick={() => toggleGroup(gi)}
360
+ className="w-full flex items-center gap-1 px-2 py-1 text-xs hover:bg-[var(--color-bg-secondary)] transition-colors text-left"
361
+ >
362
+ {group.expanded ? (
363
+ <ChevronDown className="w-3 h-3 text-[var(--color-text-placeholder)] flex-shrink-0" />
364
+ ) : (
365
+ <ChevronRight className="w-3 h-3 text-[var(--color-text-placeholder)] flex-shrink-0" />
366
+ )}
367
+ <FileText className="w-3.5 h-3.5 text-[var(--color-text-placeholder)] flex-shrink-0" />
368
+ <span className="text-[var(--color-text-secondary)] truncate flex-1">{group.relativePath}</span>
369
+ <span className="text-[10px] text-gray-600 flex-shrink-0 ml-1">
370
+ {group.matches.length}
371
+ </span>
372
+ </button>
373
+
374
+ {/* Individual matches */}
375
+ {group.expanded && (
376
+ <div className="ml-4">
377
+ {group.matches.map((match, mi) => (
378
+ <button
379
+ key={mi}
380
+ onClick={() => handleOpenFile(match.file, match.line)}
381
+ className="w-full text-left px-2 py-0.5 text-[11px] hover:bg-[var(--color-bg-secondary)] transition-colors group flex items-start gap-2"
382
+ >
383
+ <span className="text-gray-600 w-6 text-right flex-shrink-0 select-none pt-px">
384
+ {match.line}
385
+ </span>
386
+ <span className="text-[var(--color-text-tertiary)] truncate font-mono leading-relaxed">
387
+ {match.text.slice(0, match.highlightStart)}
388
+ <span className="bg-[var(--color-accent)]/40 text-[var(--color-text-accent)]">
389
+ {match.text.slice(match.highlightStart, match.highlightEnd)}
390
+ </span>
391
+ {match.text.slice(match.highlightEnd)}
392
+ </span>
393
+ </button>
394
+ ))}
395
+ </div>
396
+ )}
397
+ </div>
398
+ ))}
399
+ </div>
400
+ )}
401
+ </div>
402
+ </div>
403
+ );
404
+ }
@@ -0,0 +1,50 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, screen, cleanup } from "@testing-library/react";
3
+ import React from "react";
4
+
5
+ vi.mock("../../../stores/use-explorer-store", () => ({
6
+ useExplorerStore: (selector: any) =>
7
+ selector({ currentPath: "/project" }),
8
+ }));
9
+
10
+ vi.mock("../../../lib/api-client", () => ({
11
+ apiClient: { call: vi.fn() },
12
+ }));
13
+
14
+ describe("SearchPanel", () => {
15
+ afterEach(cleanup);
16
+
17
+ it("should render search header", async () => {
18
+ const { SearchPanel } = await import("../SearchPanel");
19
+ render(<SearchPanel />);
20
+ expect(screen.getByText("Search")).toBeDefined();
21
+ });
22
+
23
+ it("should render search input", async () => {
24
+ const { SearchPanel } = await import("../SearchPanel");
25
+ render(<SearchPanel />);
26
+ expect(screen.getByPlaceholderText("Search in files...")).toBeDefined();
27
+ });
28
+
29
+ it("should render keyboard shortcut hint", async () => {
30
+ const { SearchPanel } = await import("../SearchPanel");
31
+ render(<SearchPanel />);
32
+ const kbd = document.querySelector("kbd");
33
+ expect(kbd).not.toBeNull();
34
+ expect(kbd?.textContent).toMatch(/[⌘Ctrl]/);
35
+ });
36
+
37
+ it("should render toggle buttons for case/word/regex", async () => {
38
+ const { SearchPanel } = await import("../SearchPanel");
39
+ render(<SearchPanel />);
40
+ expect(screen.getByTitle("Match Case")).toBeDefined();
41
+ expect(screen.getByTitle("Match Whole Word")).toBeDefined();
42
+ expect(screen.getByTitle("Use Regular Expression")).toBeDefined();
43
+ });
44
+
45
+ it("should show initial empty state before search", async () => {
46
+ const { SearchPanel } = await import("../SearchPanel");
47
+ render(<SearchPanel />);
48
+ expect(screen.getByText("Type a search term and press Enter")).toBeDefined();
49
+ });
50
+ });
@@ -0,0 +1,20 @@
1
+ import { Pin, PinOff } from "lucide-react";
2
+ import { useSidebarStore } from "../../stores/use-sidebar-store";
3
+
4
+ export function PinButton() {
5
+ const isPinned = useSidebarStore((s) => s.isPinned);
6
+ const setPinned = useSidebarStore((s) => s.setPinned);
7
+ const isMobile = useSidebarStore((s) => s.breakpoint) === "mobile";
8
+
9
+ if (isMobile) return null;
10
+
11
+ return (
12
+ <button
13
+ onClick={() => setPinned(!isPinned)}
14
+ title={isPinned ? "Unpin sidebar" : "Pin sidebar"}
15
+ className="text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)] transition-colors"
16
+ >
17
+ {isPinned ? <PinOff className="w-3 h-3" /> : <Pin className="w-3 h-3" />}
18
+ </button>
19
+ );
20
+ }