@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,98 @@
1
+ import { useEffect, useCallback, useRef } from "react";
2
+ import { GitBranch as BranchIcon, Check } from "lucide-react";
3
+ import { useShallow } from "zustand/react/shallow";
4
+ import { useGitStore, type GitBranch } from "../../stores/use-git-store";
5
+ import { useExplorerStore } from "../../stores/use-explorer-store";
6
+
7
+ /**
8
+ * Branch selector popup — lists local/remote branches with checkout action.
9
+ * Self-contained: only depends on useGitStore + useExplorerStore.
10
+ */
11
+ interface GitBranchSelectorProps {
12
+ onClose: () => void;
13
+ }
14
+
15
+ export function GitBranchSelector({ onClose }: GitBranchSelectorProps) {
16
+ const { branches, loadingBranches, loadingAction } = useGitStore(
17
+ useShallow((s) => ({
18
+ branches: s.branches,
19
+ loadingBranches: s.loadingBranches,
20
+ loadingAction: s.loadingAction,
21
+ }))
22
+ );
23
+ const fetchBranches = useGitStore((s) => s.fetchBranches);
24
+ const checkout = useGitStore((s) => s.checkout);
25
+ const currentPath = useExplorerStore((s) => s.currentPath);
26
+ const ref = useRef<HTMLDivElement>(null);
27
+
28
+ useEffect(() => {
29
+ fetchBranches(currentPath);
30
+ }, [fetchBranches, currentPath]);
31
+
32
+ useEffect(() => {
33
+ const handleClick = (e: MouseEvent) => {
34
+ if (ref.current && !ref.current.contains(e.target as Node)) onClose();
35
+ };
36
+ const handleKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); };
37
+ document.addEventListener("mousedown", handleClick);
38
+ document.addEventListener("keydown", handleKey);
39
+ return () => {
40
+ document.removeEventListener("mousedown", handleClick);
41
+ document.removeEventListener("keydown", handleKey);
42
+ };
43
+ }, [onClose]);
44
+
45
+ const handleCheckout = useCallback((branch: GitBranch) => {
46
+ if (branch.isCurrent) return;
47
+ const name = branch.isRemote ? branch.name.split("/").slice(1).join("/") : branch.name;
48
+ if (!name) return;
49
+ checkout(currentPath, name);
50
+ onClose();
51
+ }, [checkout, currentPath, onClose]);
52
+
53
+ const localBranches = branches.filter((b) => !b.isRemote);
54
+ const remoteBranches = branches.filter((b) => b.isRemote);
55
+
56
+ const renderBranch = (b: GitBranch) => (
57
+ <button
58
+ key={b.name}
59
+ className={`w-full text-left px-3 py-1.5 text-xs flex items-center gap-2 transition-colors ${
60
+ b.isCurrent ? "text-[var(--color-text-accent)]" : "text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-hover)]"
61
+ }`}
62
+ onClick={() => handleCheckout(b)}
63
+ disabled={loadingAction === "checkout"}
64
+ >
65
+ {b.isCurrent && <Check className="w-3 h-3 shrink-0" />}
66
+ {!b.isCurrent && <span className="w-3 shrink-0" />}
67
+ <BranchIcon className="w-3 h-3 shrink-0" />
68
+ <span className="truncate">{b.isRemote ? b.name.split("/").slice(1).join("/") : b.name}</span>
69
+ </button>
70
+ );
71
+
72
+ return (
73
+ <div
74
+ ref={ref}
75
+ className="fixed z-50 w-56 max-h-64 overflow-y-auto bg-[var(--color-bg-secondary)] border border-[var(--color-border-secondary)] rounded-md shadow-xl py-1"
76
+ style={{ /* positioned by parent via absolute */ }}
77
+ >
78
+ {loadingBranches ? (
79
+ <div className="text-[var(--color-text-placeholder)] text-xs text-center py-4">Loading branches...</div>
80
+ ) : (
81
+ <>
82
+ {localBranches.length > 0 && (
83
+ <>
84
+ <div className="px-3 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold">Local</div>
85
+ {localBranches.map(renderBranch)}
86
+ </>
87
+ )}
88
+ {remoteBranches.length > 0 && (
89
+ <>
90
+ <div className="px-3 py-1 mt-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold border-t border-[var(--color-border-primary)] pt-1">Remote</div>
91
+ {remoteBranches.map(renderBranch)}
92
+ </>
93
+ )}
94
+ </>
95
+ )}
96
+ </div>
97
+ );
98
+ }
@@ -0,0 +1,60 @@
1
+ import { useState, useCallback } from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { Check } from "lucide-react";
4
+ import { useShallow } from "zustand/react/shallow";
5
+ import { useGitStore } from "../../stores/use-git-store";
6
+ import { useExplorerStore } from "../../stores/use-explorer-store";
7
+
8
+ export function GitCommitInput() {
9
+ const { t } = useTranslation();
10
+ const { staged, loadingAction } = useGitStore(
11
+ useShallow((s) => ({
12
+ staged: s.staged,
13
+ loadingAction: s.loadingAction,
14
+ }))
15
+ );
16
+ const commit = useGitStore((s) => s.commit);
17
+ const currentPath = useExplorerStore((s) => s.currentPath);
18
+
19
+ const [message, setMessage] = useState("");
20
+
21
+ const handleSubmit = useCallback(() => {
22
+ const trimmed = message.trim();
23
+ if (!trimmed || staged.length === 0) return;
24
+ commit(currentPath, trimmed);
25
+ setMessage("");
26
+ }, [message, staged.length, commit, currentPath]);
27
+
28
+ const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
29
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
30
+ e.preventDefault();
31
+ handleSubmit();
32
+ }
33
+ }, [handleSubmit]);
34
+
35
+ if (staged.length === 0) return null;
36
+
37
+ const isCommitting = loadingAction === "commit";
38
+
39
+ return (
40
+ <div className="p-2 border-b border-[var(--color-border-primary)]">
41
+ <textarea
42
+ className="w-full bg-[var(--color-bg-secondary)] border border-[var(--color-border-secondary)] rounded px-2 py-1.5 text-xs text-[var(--color-text-secondary)] placeholder-[var(--color-text-placeholder)] resize-none outline-none focus:border-[var(--color-accent)] transition-colors"
43
+ rows={3}
44
+ placeholder={t("git.commitPlaceholder")}
45
+ value={message}
46
+ onChange={(e) => setMessage(e.target.value)}
47
+ onKeyDown={handleKeyDown}
48
+ disabled={isCommitting}
49
+ />
50
+ <button
51
+ className="mt-1.5 w-full flex items-center justify-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-[var(--color-text-primary)]"
52
+ onClick={handleSubmit}
53
+ disabled={!message.trim() || isCommitting}
54
+ >
55
+ <Check className="w-3 h-3" />
56
+ {isCommitting ? t("git.committing") : t("git.commit")}
57
+ </button>
58
+ </div>
59
+ );
60
+ }
@@ -0,0 +1,528 @@
1
+ import { memo, useEffect, useCallback, useState, useRef } from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { useShallow } from "zustand/react/shallow";
4
+ import {
5
+ GitBranch, RefreshCw, FileQuestion, Plus, Minus, Pencil,
6
+ ChevronRight, ChevronDown, Eye, FileText, Copy,
7
+ Upload, Download, ChevronUp, ChevronDown as BranchChevron,
8
+ FolderTree,
9
+ } from "lucide-react";
10
+ import { useGitStore, type GitFileChange, type GitCommit } from "../../stores/use-git-store";
11
+ import { useExplorerStore } from "../../stores/use-explorer-store";
12
+ import { ContextMenu, type MenuItem } from "../explorer/ContextMenu";
13
+ import { GitCommitInput } from "./GitCommitInput";
14
+ import { GitBranchSelector } from "./GitBranchSelector";
15
+ import { PinButton } from "../sidebar/PinButton";
16
+
17
+ function statusIcon(status: GitFileChange["status"]) {
18
+ switch (status) {
19
+ case "added": return <Plus className="w-3 h-3 text-[var(--color-text-success)]" />;
20
+ case "deleted": return <Minus className="w-3 h-3 text-[var(--color-text-error)]" />;
21
+ case "modified": return <Pencil className="w-3 h-3 text-yellow-400" />;
22
+ default: return <FileQuestion className="w-3 h-3 text-[var(--color-text-tertiary)]" />;
23
+ }
24
+ }
25
+
26
+ function statusLabel(status: GitFileChange["status"]) {
27
+ switch (status) {
28
+ case "added": return "A";
29
+ case "deleted": return "D";
30
+ case "modified": return "M";
31
+ case "renamed": return "R";
32
+ case "copied": return "C";
33
+ }
34
+ }
35
+
36
+ interface FileItemProps {
37
+ path: string;
38
+ status: GitFileChange["status"];
39
+ isSelected: boolean;
40
+ isStaged?: boolean;
41
+ onClick: (filePath: string, staged?: boolean) => void;
42
+ onContextMenu: (e: React.MouseEvent, filePath: string, isStaged?: boolean) => void;
43
+ onStageToggle: (filePath: string, isStaged?: boolean) => void;
44
+ stageTitle: string;
45
+ unstageTitle: string;
46
+ }
47
+
48
+ const FileItem = memo(function FileItem({
49
+ path, status, isSelected, isStaged, onClick, onContextMenu, onStageToggle, stageTitle, unstageTitle,
50
+ }: FileItemProps) {
51
+ return (
52
+ <div
53
+ className={`group flex items-center gap-1.5 px-2 py-0.5 text-xs rounded cursor-pointer transition-colors ${
54
+ isSelected ? "bg-[var(--color-accent)]/30 text-[var(--color-text-primary)]" : "hover:bg-[var(--color-bg-hover)] text-[var(--color-text-secondary)]"
55
+ }`}
56
+ onClick={() => onClick(path, isStaged)}
57
+ onContextMenu={(e) => { e.preventDefault(); onContextMenu(e, path, isStaged); }}
58
+ >
59
+ {statusIcon(status)}
60
+ <span className="truncate flex-1">{path.split("/").pop()}</span>
61
+ <span className="text-[var(--color-text-placeholder)] text-[10px]">{statusLabel(status)}</span>
62
+ <button
63
+ className={`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-[var(--color-bg-active)] ${
64
+ isStaged ? "text-orange-400 hover:text-orange-300" : "text-[var(--color-text-success)] hover:text-green-300"
65
+ }`}
66
+ onClick={(e) => { e.stopPropagation(); onStageToggle(path, isStaged); }}
67
+ title={isStaged ? unstageTitle : stageTitle}
68
+ >
69
+ {isStaged ? <ChevronUp className="w-3 h-3" /> : <Plus className="w-3 h-3" />}
70
+ </button>
71
+ </div>
72
+ );
73
+ });
74
+
75
+ interface UntrackedItemProps {
76
+ path: string;
77
+ isSelected: boolean;
78
+ onClick: (filePath: string) => void;
79
+ onContextMenu: (e: React.MouseEvent, filePath: string) => void;
80
+ onStage: (filePath: string) => void;
81
+ stageTitle: string;
82
+ }
83
+
84
+ const UntrackedItem = memo(function UntrackedItem({
85
+ path, isSelected, onClick, onContextMenu, onStage, stageTitle,
86
+ }: UntrackedItemProps) {
87
+ return (
88
+ <div
89
+ className={`group flex items-center gap-1.5 px-2 py-0.5 text-xs rounded cursor-pointer transition-colors ${
90
+ isSelected ? "bg-[var(--color-accent)]/30 text-[var(--color-text-primary)]" : "hover:bg-[var(--color-bg-hover)] text-[var(--color-text-tertiary)]"
91
+ }`}
92
+ onClick={() => onClick(path)}
93
+ onContextMenu={(e) => { e.preventDefault(); onContextMenu(e, path); }}
94
+ >
95
+ <FileQuestion className="w-3 h-3 text-[var(--color-text-placeholder)]" />
96
+ <span className="truncate flex-1">{path.split("/").pop()}</span>
97
+ <span className="text-gray-600 text-[10px]">U</span>
98
+ <button
99
+ className="opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded text-[var(--color-text-success)] hover:text-green-300 hover:bg-[var(--color-bg-active)]"
100
+ onClick={(e) => { e.stopPropagation(); onStage(path); }}
101
+ title={stageTitle}
102
+ >
103
+ <Plus className="w-3 h-3" />
104
+ </button>
105
+ </div>
106
+ );
107
+ });
108
+
109
+ interface CommitFileItemProps {
110
+ path: string;
111
+ status: GitFileChange["status"];
112
+ isSelected: boolean;
113
+ onClick: () => void;
114
+ }
115
+
116
+ const CommitFileItem = memo(function CommitFileItem({ path, status, isSelected, onClick }: CommitFileItemProps) {
117
+ return (
118
+ <div
119
+ className={`flex items-center gap-1.5 pl-7 pr-2 py-0.5 text-xs rounded cursor-pointer transition-colors ${
120
+ isSelected ? "bg-[var(--color-accent)]/30 text-[var(--color-text-primary)]" : "hover:bg-[var(--color-bg-hover)] text-[var(--color-text-tertiary)]"
121
+ }`}
122
+ onClick={onClick}
123
+ >
124
+ {statusIcon(status)}
125
+ <span className="truncate flex-1">{path.split("/").pop()}</span>
126
+ <span className="text-gray-600 text-[10px]">{statusLabel(status)}</span>
127
+ </div>
128
+ );
129
+ });
130
+
131
+ interface CommitItemProps {
132
+ commit: GitCommit;
133
+ expanded: boolean;
134
+ files: GitFileChange[] | undefined;
135
+ loading: boolean;
136
+ selectedFilePath: string | null;
137
+ onToggle: () => void;
138
+ onFileClick: (filePath: string) => void;
139
+ onContextMenu: (e: React.MouseEvent, commit: GitCommit) => void;
140
+ t: (key: string) => string;
141
+ }
142
+
143
+ function relativeTime(dateStr: string, t: (key: string, options?: Record<string, unknown>) => string): string {
144
+ const d = new Date(dateStr);
145
+ const now = new Date();
146
+ const diff = now.getTime() - d.getTime();
147
+ const mins = Math.floor(diff / 60000);
148
+ if (mins < 1) return t("git.justNow");
149
+ if (mins < 60) return t("git.minutesAgo", { count: mins });
150
+ const hours = Math.floor(mins / 60);
151
+ if (hours < 24) return t("git.hoursAgo", { count: hours });
152
+ const days = Math.floor(hours / 24);
153
+ if (days < 30) return t("git.daysAgo", { count: days });
154
+ return d.toLocaleDateString();
155
+ }
156
+
157
+ const CommitItem = memo(function CommitItem({
158
+ commit, expanded, files, loading, selectedFilePath, onToggle, onFileClick, onContextMenu, t,
159
+ }: CommitItemProps) {
160
+ return (
161
+ <div>
162
+ <div
163
+ className="flex items-start gap-1.5 px-2 py-1 text-xs hover:bg-[var(--color-bg-hover)]/50 rounded cursor-pointer"
164
+ onClick={onToggle}
165
+ onContextMenu={(e) => { e.preventDefault(); onContextMenu(e, commit); }}
166
+ >
167
+ {expanded
168
+ ? <ChevronDown className="w-3 h-3 text-[var(--color-text-placeholder)] mt-0.5 shrink-0" />
169
+ : <ChevronRight className="w-3 h-3 text-[var(--color-text-placeholder)] mt-0.5 shrink-0" />}
170
+ <div className="flex-1 min-w-0">
171
+ <div className="text-[var(--color-text-secondary)] truncate">{commit.message}</div>
172
+ <div className="text-[var(--color-text-placeholder)] text-[10px] flex items-center gap-1.5 mt-0.5">
173
+ <span className="text-[var(--color-text-accent)] font-mono">{commit.shortHash}</span>
174
+ <span>{commit.author}</span>
175
+ <span>{relativeTime(commit.date, t)}</span>
176
+ </div>
177
+ </div>
178
+ </div>
179
+ {expanded && (
180
+ <div className="ml-1">
181
+ {loading ? (
182
+ <div className="text-gray-600 text-[10px] pl-7 py-1">{t("git.loadingFiles")}</div>
183
+ ) : files && files.length > 0 ? (
184
+ files.map((f) => (
185
+ <CommitFileItem
186
+ key={f.path}
187
+ path={f.path}
188
+ status={f.status}
189
+ isSelected={selectedFilePath === f.path}
190
+ onClick={() => onFileClick(f.path)}
191
+ />
192
+ ))
193
+ ) : (
194
+ <div className="text-gray-600 text-[10px] pl-7 py-1">{t("git.noFiles")}</div>
195
+ )}
196
+ </div>
197
+ )}
198
+ </div>
199
+ );
200
+ });
201
+
202
+ interface GitPanelProps {
203
+ hideOuterShell?: boolean;
204
+ }
205
+
206
+ export function GitPanel({ hideOuterShell }: GitPanelProps) {
207
+ const { t } = useTranslation();
208
+
209
+ const { branch, ahead, behind } = useGitStore(
210
+ useShallow((s) => ({
211
+ branch: s.branch,
212
+ ahead: s.ahead,
213
+ behind: s.behind,
214
+ }))
215
+ );
216
+
217
+ const { staged, changed, untracked } = useGitStore(
218
+ useShallow((s) => ({
219
+ staged: s.staged,
220
+ changed: s.changed,
221
+ untracked: s.untracked,
222
+ }))
223
+ );
224
+
225
+ const { commits, loadingCommits, currentDiff, expandedCommits, commitFiles, loadingCommitFiles, loadingAction, worktrees } = useGitStore(
226
+ useShallow((s) => ({
227
+ commits: s.commits,
228
+ loadingCommits: s.loadingCommits,
229
+ currentDiff: s.currentDiff,
230
+ expandedCommits: s.expandedCommits,
231
+ commitFiles: s.commitFiles,
232
+ loadingCommitFiles: s.loadingCommitFiles,
233
+ loadingAction: s.loadingAction,
234
+ worktrees: s.worktrees,
235
+ }))
236
+ );
237
+
238
+ const fetchStatus = useGitStore((s) => s.fetchStatus);
239
+ const fetchDiff = useGitStore((s) => s.fetchDiff);
240
+ const fetchLog = useGitStore((s) => s.fetchLog);
241
+ const toggleCommitExpand = useGitStore((s) => s.toggleCommitExpand);
242
+ const fetchCommitFileDiff = useGitStore((s) => s.fetchCommitFileDiff);
243
+ const stageFiles = useGitStore((s) => s.stageFiles);
244
+ const unstageFiles = useGitStore((s) => s.unstageFiles);
245
+ const push = useGitStore((s) => s.push);
246
+ const pull = useGitStore((s) => s.pull);
247
+ const fetchWorktrees = useGitStore((s) => s.fetchWorktrees);
248
+
249
+ const currentPath = useExplorerStore((s) => s.currentPath);
250
+ const openFile = useExplorerStore((s) => s.openFile);
251
+
252
+ const [commitsExpanded, setCommitsExpanded] = useState(false);
253
+ const [showBranches, setShowBranches] = useState(false);
254
+ const [showWorktrees, setShowWorktrees] = useState(false);
255
+ const [ctxMenu, setCtxMenu] = useState<{ x: number; y: number; filePath: string; isStaged?: boolean } | null>(null);
256
+ const [commitCtxMenu, setCommitCtxMenu] = useState<{ x: number; y: number; commit: GitCommit } | null>(null);
257
+
258
+ const branchBtnRef = useRef<HTMLButtonElement>(null);
259
+
260
+ const refresh = useCallback(() => {
261
+ fetchStatus(currentPath);
262
+ fetchWorktrees(currentPath);
263
+ if (commitsExpanded) fetchLog(currentPath);
264
+ }, [fetchStatus, fetchWorktrees, fetchLog, currentPath, commitsExpanded]);
265
+
266
+ useEffect(() => { refresh(); }, [refresh]);
267
+
268
+ const handleFileClick = useCallback((filePath: string, staged?: boolean) => {
269
+ fetchDiff(currentPath, filePath, staged);
270
+ }, [fetchDiff, currentPath]);
271
+
272
+ const handleContextMenu = useCallback((e: React.MouseEvent, filePath: string, isStaged?: boolean) => {
273
+ setCtxMenu({ x: e.clientX, y: e.clientY, filePath, isStaged });
274
+ }, []);
275
+
276
+ const handleOpenFile = useCallback((filePath: string) => {
277
+ const fullPath = `${currentPath}/${filePath}`;
278
+ openFile({ name: filePath.split("/").pop() || filePath, path: fullPath, type: "file" as const });
279
+ }, [openFile, currentPath]);
280
+
281
+ const handleCopyPath = useCallback(async (filePath: string) => {
282
+ await navigator.clipboard.writeText(`${currentPath}/${filePath}`);
283
+ }, [currentPath]);
284
+
285
+ const getContextMenuItems = useCallback((filePath: string, isStaged?: boolean): MenuItem[] => [
286
+ { label: t("git.openDiff"), icon: <Eye className="w-3 h-3" />, onClick: () => fetchDiff(currentPath, filePath, isStaged) },
287
+ { label: t("git.openFile"), icon: <FileText className="w-3 h-3" />, onClick: () => handleOpenFile(filePath) },
288
+ { label: "", onClick: () => {}, divider: true },
289
+ { label: t("git.copyPath"), icon: <Copy className="w-3 h-3" />, onClick: () => handleCopyPath(filePath) },
290
+ ], [fetchDiff, currentPath, handleOpenFile, handleCopyPath, t]);
291
+
292
+ const handleCommitContextMenu = useCallback((e: React.MouseEvent, commit: GitCommit) => {
293
+ setCommitCtxMenu({ x: e.clientX, y: e.clientY, commit });
294
+ }, []);
295
+
296
+ const getCommitContextMenuItems = useCallback((commit: GitCommit): MenuItem[] => [
297
+ { label: t("git.copyHash"), icon: <Copy className="w-3 h-3" />, onClick: () => navigator.clipboard.writeText(commit.hash) },
298
+ { label: t("git.copyMessage"), icon: <Copy className="w-3 h-3" />, onClick: () => navigator.clipboard.writeText(commit.message) },
299
+ ], [t]);
300
+
301
+ const handleCommitFileClick = useCallback((hash: string, filePath: string) => {
302
+ fetchCommitFileDiff(currentPath, hash, filePath);
303
+ }, [fetchCommitFileDiff, currentPath]);
304
+
305
+ const handleStageToggle = useCallback((filePath: string, isStaged?: boolean) => {
306
+ if (isStaged) {
307
+ unstageFiles(currentPath, [filePath]);
308
+ } else {
309
+ stageFiles(currentPath, [filePath]);
310
+ }
311
+ }, [stageFiles, unstageFiles, currentPath]);
312
+
313
+ const handleStageAll = useCallback(() => {
314
+ const paths = [...changed.map((f) => f.path), ...untracked];
315
+ if (paths.length > 0) stageFiles(currentPath, paths);
316
+ }, [changed, untracked, stageFiles, currentPath]);
317
+
318
+ const handleUnstageAll = useCallback(() => {
319
+ const paths = staged.map((f) => f.path);
320
+ if (paths.length > 0) unstageFiles(currentPath, paths);
321
+ }, [staged, unstageFiles, currentPath]);
322
+
323
+ const handleUntrackedStage = useCallback((filePath: string) => {
324
+ stageFiles(currentPath, [filePath]);
325
+ }, [stageFiles, currentPath]);
326
+
327
+ const toggleCommits = useCallback(() => {
328
+ const next = !commitsExpanded;
329
+ setCommitsExpanded(next);
330
+ if (next && commits.length === 0) fetchLog(currentPath);
331
+ }, [commitsExpanded, commits.length, fetchLog, currentPath]);
332
+
333
+ const handlePush = useCallback(() => push(currentPath), [push, currentPath]);
334
+ const handlePull = useCallback(() => pull(currentPath), [pull, currentPath]);
335
+
336
+ const totalChanges = staged.length + changed.length + untracked.length;
337
+ const selectedFilePath = currentDiff?.filePath ?? null;
338
+ const hasMultipleWorktrees = worktrees.length > 1;
339
+
340
+ const pinButton = <PinButton />;
341
+
342
+ const panelContent = (
343
+ <>
344
+ <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 gap-1.5">
345
+ <GitBranch className="w-3.5 h-3.5" />
346
+ {t("git.title")}
347
+ <span className="ml-auto flex items-center gap-1">
348
+ {totalChanges > 0 && (
349
+ <span className="bg-[var(--color-accent)] text-[var(--color-text-primary)] px-1.5 py-0.5 rounded-full text-[10px] leading-none">
350
+ {totalChanges}
351
+ </span>
352
+ )}
353
+ {pinButton}
354
+ <button onClick={handlePull} className="text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)]" disabled={loadingAction === "pull"} title={t("git.pull")}>
355
+ <Download className="w-3 h-3" />
356
+ </button>
357
+ <button onClick={handlePush} className="text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)]" disabled={loadingAction === "push"} title={t("git.push")}>
358
+ <Upload className="w-3 h-3" />
359
+ </button>
360
+ <button onClick={refresh} className="text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)]" title={t("git.refresh")}>
361
+ <RefreshCw className="w-3 h-3" />
362
+ </button>
363
+ </span>
364
+ </div>
365
+
366
+ <div className="px-2 py-1.5 text-xs text-[var(--color-text-tertiary)] flex items-center gap-1.5 border-b border-[var(--color-border-primary)]/50">
367
+ <button
368
+ ref={branchBtnRef}
369
+ className="flex items-center gap-1 hover:text-[var(--color-text-primary)] transition-colors"
370
+ onClick={() => setShowBranches(!showBranches)}
371
+ >
372
+ <GitBranch className="w-3 h-3" />
373
+ <span className="font-medium">{branch}</span>
374
+ {ahead > 0 && <span className="text-green-400">↑{ahead}</span>}
375
+ {behind > 0 && <span className="text-orange-400">↓{behind}</span>}
376
+ <BranchChevron className="w-3 h-3 text-[var(--color-text-placeholder)]" />
377
+ </button>
378
+
379
+ {hasMultipleWorktrees && (
380
+ <button
381
+ className="ml-auto text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)] transition-colors"
382
+ onClick={() => setShowWorktrees(!showWorktrees)}
383
+ title={`${worktrees.length} worktrees`}
384
+ >
385
+ <FolderTree className="w-3 h-3" />
386
+ </button>
387
+ )}
388
+ </div>
389
+
390
+ <GitCommitInput />
391
+
392
+ <div className="flex-1 overflow-y-auto p-1">
393
+ {staged.length > 0 && (
394
+ <div className="mt-1">
395
+ <div className="px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold flex items-center">
396
+ <span>{t("git.staged")} ({staged.length})</span>
397
+ <button className="ml-auto text-orange-400 hover:text-orange-300" onClick={handleUnstageAll} title={t("git.unstageAll")}>
398
+ <ChevronUp className="w-3 h-3" />
399
+ </button>
400
+ </div>
401
+ {staged.map((f) => (
402
+ <FileItem key={f.path} path={f.path} status={f.status} isSelected={selectedFilePath === f.path} isStaged
403
+ onClick={handleFileClick} onContextMenu={handleContextMenu} onStageToggle={handleStageToggle}
404
+ stageTitle={t("git.stage")} unstageTitle={t("git.unstage")} />
405
+ ))}
406
+ </div>
407
+ )}
408
+
409
+ {changed.length > 0 && (
410
+ <div className="mt-2">
411
+ <div className="px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold flex items-center">
412
+ <span>{t("git.changes")} ({changed.length})</span>
413
+ <button className="ml-auto text-[var(--color-text-success)] hover:text-green-300" onClick={handleStageAll} title={t("git.stageAll")}>
414
+ <Plus className="w-3 h-3" />
415
+ </button>
416
+ </div>
417
+ {changed.map((f) => (
418
+ <FileItem key={f.path} path={f.path} status={f.status} isSelected={selectedFilePath === f.path}
419
+ onClick={handleFileClick} onContextMenu={handleContextMenu} onStageToggle={handleStageToggle}
420
+ stageTitle={t("git.stage")} unstageTitle={t("git.unstage")} />
421
+ ))}
422
+ </div>
423
+ )}
424
+
425
+ {untracked.length > 0 && (
426
+ <div className="mt-2">
427
+ <div className="px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold">
428
+ {t("git.untracked")} ({untracked.length})
429
+ </div>
430
+ {untracked.map((f) => (
431
+ <UntrackedItem key={f} path={f} isSelected={selectedFilePath === f}
432
+ onClick={handleFileClick} onContextMenu={handleContextMenu} onStage={handleUntrackedStage}
433
+ stageTitle={t("git.stage")} />
434
+ ))}
435
+ </div>
436
+ )}
437
+
438
+ {totalChanges === 0 && !commitsExpanded && (
439
+ <div className="text-[var(--color-text-placeholder)] text-xs text-center py-8">{t("git.noChanges")}</div>
440
+ )}
441
+
442
+ <div className="mt-2 border-t border-[var(--color-border-primary)] pt-1">
443
+ <button
444
+ className="w-full px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold flex items-center gap-1 hover:text-[var(--color-text-secondary)] transition-colors"
445
+ onClick={toggleCommits}
446
+ >
447
+ {commitsExpanded ? <ChevronDown className="w-3 h-3" /> : <ChevronRight className="w-3 h-3" />}
448
+ {t("git.commits")}
449
+ {commits.length > 0 && <span className="text-gray-600 ml-auto">{commits.length}</span>}
450
+ </button>
451
+ {commitsExpanded && (
452
+ <div className="mt-0.5">
453
+ {loadingCommits ? (
454
+ <div className="text-[var(--color-text-placeholder)] text-xs text-center py-4">{t("common.loading")}</div>
455
+ ) : commits.length === 0 ? (
456
+ <div className="text-gray-600 text-xs text-center py-4">{t("git.noCommits")}</div>
457
+ ) : (
458
+ commits.map((c) => (
459
+ <CommitItem key={c.hash} commit={c}
460
+ expanded={expandedCommits.has(c.hash)}
461
+ files={commitFiles[c.hash]}
462
+ loading={loadingCommitFiles.has(c.hash)}
463
+ selectedFilePath={selectedFilePath}
464
+ onToggle={() => toggleCommitExpand(currentPath, c.hash)}
465
+ onFileClick={(fp) => handleCommitFileClick(c.hash, fp)}
466
+ onContextMenu={handleCommitContextMenu}
467
+ t={t}
468
+ />
469
+ ))
470
+ )}
471
+ </div>
472
+ )}
473
+ </div>
474
+ </div>
475
+
476
+ {showBranches && branchBtnRef.current && (
477
+ <div className="absolute z-50" style={{
478
+ top: branchBtnRef.current.getBoundingClientRect().bottom + 4,
479
+ left: branchBtnRef.current.getBoundingClientRect().left,
480
+ }}>
481
+ <GitBranchSelector onClose={() => setShowBranches(false)} />
482
+ </div>
483
+ )}
484
+
485
+ {showWorktrees && worktrees.length > 1 && (
486
+ <div className="fixed z-50 min-w-[200px] bg-[var(--color-bg-secondary)] border border-[var(--color-border-secondary)] rounded-md shadow-xl py-1"
487
+ style={{ top: 80, left: 48 }}>
488
+ <div className="px-3 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold">{t("git.worktrees")}</div>
489
+ {worktrees.map((wt) => (
490
+ <div key={wt.path} className={`px-3 py-1.5 text-xs flex items-center gap-2 ${
491
+ wt.path === currentPath ? "text-[var(--color-text-accent)]" : "text-[var(--color-text-secondary)]"
492
+ }`}>
493
+ <FolderTree className="w-3 h-3 shrink-0" />
494
+ <div className="min-w-0 flex-1">
495
+ <div className="truncate">{wt.branch}</div>
496
+ <div className="text-[var(--color-text-placeholder)] text-[10px] truncate">{wt.path}</div>
497
+ </div>
498
+ {wt.isMain && <span className="text-gray-600 text-[10px]">main</span>}
499
+ </div>
500
+ ))}
501
+ <button className="w-full text-left px-3 py-1 text-[10px] text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)] border-t border-[var(--color-border-primary)] mt-1 pt-1"
502
+ onClick={() => setShowWorktrees(false)}>{t("git.close")}</button>
503
+ </div>
504
+ )}
505
+
506
+ {ctxMenu && (
507
+ <ContextMenu x={ctxMenu.x} y={ctxMenu.y}
508
+ items={getContextMenuItems(ctxMenu.filePath, ctxMenu.isStaged)}
509
+ onClose={() => setCtxMenu(null)} />
510
+ )}
511
+ {commitCtxMenu && (
512
+ <ContextMenu x={commitCtxMenu.x} y={commitCtxMenu.y}
513
+ items={getCommitContextMenuItems(commitCtxMenu.commit)}
514
+ onClose={() => setCommitCtxMenu(null)} />
515
+ )}
516
+ </>
517
+ );
518
+
519
+ if (hideOuterShell) {
520
+ return <div className="flex flex-col flex-1 overflow-hidden">{panelContent}</div>;
521
+ }
522
+
523
+ return (
524
+ <div className="w-60 bg-[var(--color-bg-primary)] flex flex-col flex-shrink-0 overflow-hidden">
525
+ {panelContent}
526
+ </div>
527
+ );
528
+ }