@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,146 @@
1
+ import { Wifi, Monitor, MessageSquare, Rss } from "lucide-react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { useConnectionStore } from "../../stores/use-connection-store";
4
+ import { useExplorerStore } from "../../stores/use-explorer-store";
5
+ import { useSidebarStore } from "../../stores/use-sidebar-store";
6
+ import { ActivityBar } from "../activity-bar/ActivityBar";
7
+ import { MobileTabBar } from "../activity-bar/MobileTabBar";
8
+ import { ExplorerSidebar } from "../explorer/ExplorerSidebar";
9
+ import { GitPanel } from "../git/GitPanel";
10
+ import { SearchPanel } from "../search/SearchPanel";
11
+ import { ChatPanel } from "../chat/ChatPanel";
12
+ import { FeedPanel } from "../feed/FeedPanel";
13
+ import { FilePreviewOverlay } from "../file-preview/FilePreviewOverlay";
14
+ import { DiffViewerPanel } from "../diff/DiffViewerPanel";
15
+ import { DebugPanel } from "../debug/DebugPanel";
16
+
17
+ export type CenterTab = "chat" | "feed";
18
+
19
+ interface AppLayoutProps {
20
+ centerTab: CenterTab;
21
+ setCenterTab: (tab: CenterTab) => void;
22
+ sidebarWidth: number;
23
+ handleResizeStart: (e: React.MouseEvent) => void;
24
+ }
25
+
26
+ export function AppLayout({
27
+ centerTab,
28
+ setCenterTab,
29
+ sidebarWidth,
30
+ handleResizeStart,
31
+ }: AppLayoutProps) {
32
+ const { t } = useTranslation();
33
+ const mode = useConnectionStore((s) => s.mode);
34
+ const filePreview = useExplorerStore((s) => s.filePreview);
35
+ const loadingFile = useExplorerStore((s) => s.loadingFile);
36
+ const closePreview = useExplorerStore((s) => s.closePreview);
37
+
38
+ const activePanel = useSidebarStore((s) => s.activePanel);
39
+ const isPinned = useSidebarStore((s) => s.isPinned);
40
+ const drawerOpen = useSidebarStore((s) => s.drawerOpen);
41
+ const setDrawerOpen = useSidebarStore((s) => s.setDrawerOpen);
42
+ const breakpoint = useSidebarStore((s) => s.breakpoint);
43
+
44
+ const isMobile = breakpoint === "mobile";
45
+ const isDesktop = breakpoint === "desktop";
46
+ const sidebarIsDrawer = isMobile || !isPinned;
47
+ const showSidebar = activePanel !== null && (isPinned || drawerOpen);
48
+ const showDebug = isDesktop;
49
+
50
+ const sidebarContent = activePanel === "explorer" ? (
51
+ <ExplorerSidebar hideOuterShell />
52
+ ) : activePanel === "git" ? (
53
+ <GitPanel hideOuterShell />
54
+ ) : activePanel === "search" ? (
55
+ <SearchPanel />
56
+ ) : activePanel === "chat" ? (
57
+ <ChatPanel />
58
+ ) : activePanel === "feed" ? (
59
+ <FeedPanel />
60
+ ) : activePanel === "debug" ? (
61
+ <DebugPanel />
62
+ ) : null;
63
+
64
+ const centerTabs: { id: CenterTab; icon: typeof MessageSquare; label: string }[] = [
65
+ { id: "chat", icon: MessageSquare, label: t("tabs.chat") },
66
+ { id: "feed", icon: Rss, label: t("tabs.feed") },
67
+ ];
68
+
69
+ return (
70
+ <div className="h-screen bg-[var(--color-bg-primary)] text-[var(--color-text-primary)] flex flex-col overflow-hidden">
71
+ {!isMobile && (
72
+ <div className="h-8 bg-[var(--color-bg-secondary)] flex items-center px-3 text-xs border-b border-[var(--color-border-primary)] flex-shrink-0">
73
+ <span className={`px-2 py-0.5 rounded flex items-center gap-1 ${mode === "desktop" ? "bg-green-600" : "bg-blue-600"}`}>
74
+ {mode === "desktop" ? <Monitor className="w-3 h-3" /> : <Wifi className="w-3 h-3" />}
75
+ {mode === "desktop" ? t("app.mode.desktop") : t("app.mode.web")}
76
+ </span>
77
+ <span className="ml-3 text-[var(--color-text-tertiary)]">{t("app.title")}</span>
78
+ </div>
79
+ )}
80
+
81
+ <div className="flex-1 flex overflow-hidden relative">
82
+ {!isMobile && <ActivityBar />}
83
+
84
+ {showSidebar && isPinned && !isMobile && (
85
+ <div className="bg-[var(--color-bg-primary)] border-r border-[var(--color-border-primary)] flex flex-col flex-shrink-0 overflow-hidden relative"
86
+ style={{ width: sidebarWidth }}>
87
+ {sidebarContent}
88
+ <div
89
+ className="absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize bg-[var(--color-border-primary)] hover:bg-indigo-500/50 active:bg-indigo-500 transition-colors z-10"
90
+ onMouseDown={handleResizeStart}
91
+ />
92
+ </div>
93
+ )}
94
+
95
+ <div className="flex-1 flex flex-col overflow-hidden relative">
96
+ <div className="flex items-center bg-[var(--color-bg-secondary)] border-b border-[var(--color-border-primary)] flex-shrink-0">
97
+ {centerTabs.map(({ id, icon: Icon, label }) => (
98
+ <button
99
+ key={id}
100
+ onClick={() => setCenterTab(id)}
101
+ className={`flex items-center gap-1.5 px-4 py-1.5 text-xs border-b-2 transition-colors ${
102
+ centerTab === id
103
+ ? "border-[var(--color-accent)] text-[var(--color-text-primary)]"
104
+ : "border-transparent text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)]"
105
+ }`}
106
+ >
107
+ <Icon className="w-3.5 h-3.5" />
108
+ {label}
109
+ </button>
110
+ ))}
111
+ </div>
112
+
113
+ {centerTab === "chat" ? <ChatPanel /> : <FeedPanel />}
114
+ {filePreview && (
115
+ <FilePreviewOverlay
116
+ preview={filePreview}
117
+ loading={loadingFile}
118
+ onClose={closePreview}
119
+ />
120
+ )}
121
+ <DiffViewerPanel />
122
+ </div>
123
+
124
+ {showDebug && <DebugPanel />}
125
+ </div>
126
+
127
+ {sidebarIsDrawer && showSidebar && (
128
+ <>
129
+ <div
130
+ className="fixed inset-0 bg-black/50 z-40"
131
+ style={isMobile ? { bottom: 56 } : undefined}
132
+ onClick={() => setDrawerOpen(false)}
133
+ />
134
+ <div
135
+ className="fixed left-0 top-0 w-60 z-50 bg-[var(--color-bg-primary)] border-r border-[var(--color-border-primary)] flex flex-col overflow-hidden"
136
+ style={isMobile ? { top: 0, bottom: 56 } : { top: 0, bottom: 0 }}
137
+ >
138
+ {sidebarContent}
139
+ </div>
140
+ </>
141
+ )}
142
+
143
+ {isMobile && <MobileTabBar />}
144
+ </div>
145
+ );
146
+ }
@@ -0,0 +1,405 @@
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 { useTranslation } from "react-i18next";
14
+ import { apiClient } from "../../lib/api-client";
15
+ import { useExplorerStore } from "../../stores/use-explorer-store";
16
+ import type { TreeNode } from "../../types";
17
+
18
+ interface SearchMatch {
19
+ file: string;
20
+ line: number;
21
+ column: number;
22
+ text: string;
23
+ highlightStart: number;
24
+ highlightEnd: number;
25
+ }
26
+
27
+ interface FileGroup {
28
+ filePath: string;
29
+ relativePath: string;
30
+ matches: SearchMatch[];
31
+ expanded: boolean;
32
+ }
33
+
34
+ const SKIP_DIRS = new Set([
35
+ "node_modules",
36
+ ".git",
37
+ "dist",
38
+ "build",
39
+ ".next",
40
+ ".nuxt",
41
+ "coverage",
42
+ ".cache",
43
+ ".turbo",
44
+ ".vercel",
45
+ "out",
46
+ ".output",
47
+ ]);
48
+
49
+ const TEXT_EXTENSIONS = new Set([
50
+ "ts", "tsx", "js", "jsx", "mjs", "cjs",
51
+ "json", "md", "mdx", "yaml", "yml", "toml",
52
+ "css", "scss", "less", "sass",
53
+ "html", "htm", "xml", "svg",
54
+ "py", "rb", "go", "rs", "java", "kt", "swift", "c", "cpp", "h", "hpp",
55
+ "sh", "bash", "zsh", "fish",
56
+ "sql", "graphql", "gql",
57
+ "txt", "csv", "env", "gitignore", "eslintrc", "prettierrc",
58
+ "conf", "ini", "cfg", "log",
59
+ "vue", "svelte",
60
+ ]);
61
+
62
+ function isTextFile(name: string): boolean {
63
+ const dotIdx = name.lastIndexOf(".");
64
+ if (dotIdx === -1) return false;
65
+ const ext = name.slice(dotIdx + 1).toLowerCase();
66
+ if (TEXT_EXTENSIONS.has(ext)) return true;
67
+ if (name.startsWith(".") && TEXT_EXTENSIONS.has(name.slice(1))) return true;
68
+ return false;
69
+ }
70
+
71
+ function buildSearchRegex(query: string, caseSensitive: boolean, wholeWord: boolean, useRegex: boolean): RegExp {
72
+ let pattern = useRegex ? query : query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
73
+ if (wholeWord) pattern = `\\b${pattern}\\b`;
74
+ return new RegExp(pattern, caseSensitive ? "g" : "gi");
75
+ }
76
+
77
+ export function SearchPanel() {
78
+ const { t } = useTranslation();
79
+ const [query, setQuery] = useState("");
80
+ const [caseSensitive, setCaseSensitive] = useState(false);
81
+ const [wholeWord, setWholeWord] = useState(false);
82
+ const [useRegex, setUseRegex] = useState(false);
83
+ const [results, setResults] = useState<FileGroup[]>([]);
84
+ const [isSearching, setIsSearching] = useState(false);
85
+ const [totalMatches, setTotalMatches] = useState(0);
86
+ const [filesSearched, setFilesSearched] = useState(0);
87
+ const [hasSearched, setHasSearched] = useState(false);
88
+ const inputRef = useRef<HTMLInputElement>(null);
89
+ const abortRef = useRef(false);
90
+
91
+ const currentPath = useExplorerStore((s) => s.currentPath);
92
+
93
+ useEffect(() => {
94
+ inputRef.current?.focus();
95
+ }, []);
96
+
97
+ const collectFiles = useCallback(async (dirPath: string): Promise<string[]> => {
98
+ const files: string[] = [];
99
+ const queue = [dirPath];
100
+
101
+ while (queue.length > 0 && !abortRef.current) {
102
+ const current = queue.shift()!;
103
+ try {
104
+ const res = await apiClient.call("file.listDir", { path: current });
105
+ for (const entry of res.entries) {
106
+ if (abortRef.current) break;
107
+ if (entry.name.startsWith(".") && entry.name !== ".env" && entry.name !== ".env.local") continue;
108
+ if (entry.type === "directory") {
109
+ if (!SKIP_DIRS.has(entry.name)) queue.push(entry.path);
110
+ } else if (isTextFile(entry.name)) {
111
+ files.push(entry.path);
112
+ }
113
+ }
114
+ } catch {
115
+ // skip unreadable dirs
116
+ }
117
+ }
118
+ return files;
119
+ }, []);
120
+
121
+ const performSearch = useCallback(async () => {
122
+ if (!query.trim() || !currentPath) return;
123
+
124
+ abortRef.current = false;
125
+ setIsSearching(true);
126
+ setHasSearched(true);
127
+ setResults([]);
128
+ setTotalMatches(0);
129
+
130
+ try {
131
+ const regex = buildSearchRegex(query.trim(), caseSensitive, wholeWord, useRegex);
132
+ const filePaths = await collectFiles(currentPath);
133
+ const matchMap = new Map<string, SearchMatch[]>();
134
+ let matchCount = 0;
135
+
136
+ for (const fp of filePaths) {
137
+ if (abortRef.current) break;
138
+ try {
139
+ const res = await apiClient.call("file.readFile", { path: fp });
140
+ const lines = res.content.split("\n");
141
+ for (let i = 0; i < lines.length; i++) {
142
+ const line = lines[i];
143
+ regex.lastIndex = 0;
144
+ const m = regex.exec(line);
145
+ if (m) {
146
+ if (!matchMap.has(fp)) matchMap.set(fp, []);
147
+ matchMap.get(fp)!.push({
148
+ file: fp,
149
+ line: i + 1,
150
+ column: m.index + 1,
151
+ text: line,
152
+ highlightStart: m.index,
153
+ highlightEnd: m.index + m[0].length,
154
+ });
155
+ matchCount++;
156
+ }
157
+ }
158
+ } catch {
159
+ // skip unreadable files
160
+ }
161
+ }
162
+
163
+ setFilesSearched(filePaths.length);
164
+
165
+ const rootPath = currentPath.endsWith("/") ? currentPath : currentPath + "/";
166
+ const groups: FileGroup[] = [];
167
+ for (const [filePath, matches] of matchMap) {
168
+ groups.push({
169
+ filePath,
170
+ relativePath: filePath.startsWith(rootPath) ? filePath.slice(rootPath.length) : filePath,
171
+ matches,
172
+ expanded: true,
173
+ });
174
+ }
175
+
176
+ setResults(groups);
177
+ setTotalMatches(matchCount);
178
+ } catch {
179
+ // search error
180
+ } finally {
181
+ setIsSearching(false);
182
+ }
183
+ }, [query, caseSensitive, wholeWord, useRegex, currentPath, collectFiles]);
184
+
185
+ const cancelSearch = useCallback(() => {
186
+ abortRef.current = true;
187
+ }, []);
188
+
189
+ const handleKeyDown = useCallback(
190
+ (e: React.KeyboardEvent) => {
191
+ if (e.key === "Enter" && !isSearching) {
192
+ performSearch();
193
+ }
194
+ if (e.key === "Escape") {
195
+ setQuery("");
196
+ inputRef.current?.focus();
197
+ }
198
+ },
199
+ [performSearch, isSearching],
200
+ );
201
+
202
+ const toggleGroup = useCallback((index: number) => {
203
+ setResults((prev) => prev.map((g, i) => (i === index ? { ...g, expanded: !g.expanded } : g)));
204
+ }, []);
205
+
206
+ const handleOpenFile = useCallback((filePath: string, _line: number) => {
207
+ const node: TreeNode = {
208
+ name: filePath.split("/").pop() || filePath,
209
+ path: filePath,
210
+ type: "file",
211
+ };
212
+ useExplorerStore.getState().openFile(node);
213
+ }, []);
214
+
215
+ const modKey = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent) ? "⌘" : "Ctrl";
216
+
217
+ return (
218
+ <div className="flex flex-col h-full bg-[var(--color-bg-primary)]">
219
+ <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">
220
+ <div className="flex items-center gap-1.5">
221
+ <Search className="w-3.5 h-3.5" />
222
+ {t("sidebar.search")}
223
+ </div>
224
+ <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">
225
+ {modKey}⇧F
226
+ </kbd>
227
+ </div>
228
+
229
+ {/* Search input */}
230
+ <div className="p-2 border-b border-[var(--color-border-primary)] flex-shrink-0">
231
+ <div className="relative">
232
+ <Search className="absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-[var(--color-text-placeholder)]" />
233
+ <input
234
+ ref={inputRef}
235
+ type="text"
236
+ value={query}
237
+ onChange={(e) => setQuery(e.target.value)}
238
+ onKeyDown={handleKeyDown}
239
+ placeholder="Search in files..."
240
+ 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"
241
+ />
242
+ {query && (
243
+ <button
244
+ onClick={() => {
245
+ setQuery("");
246
+ inputRef.current?.focus();
247
+ }}
248
+ className="absolute right-2 top-1/2 -translate-y-1/2 text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)]"
249
+ >
250
+ <X className="w-3 h-3" />
251
+ </button>
252
+ )}
253
+ </div>
254
+
255
+ {/* Toggle buttons */}
256
+ <div className="flex items-center gap-0.5 mt-1.5">
257
+ <button
258
+ onClick={() => setCaseSensitive((v) => !v)}
259
+ className={`p-1 rounded text-xs transition-colors ${
260
+ caseSensitive
261
+ ? "bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] border border-[var(--color-accent)]/50"
262
+ : "text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)] border border-transparent"
263
+ }`}
264
+ title="Match Case"
265
+ >
266
+ <CaseSensitive className="w-3.5 h-3.5" />
267
+ </button>
268
+ <button
269
+ onClick={() => setWholeWord((v) => !v)}
270
+ className={`p-1 rounded text-xs transition-colors ${
271
+ wholeWord
272
+ ? "bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] border border-[var(--color-accent)]/50"
273
+ : "text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)] border border-transparent"
274
+ }`}
275
+ title="Match Whole Word"
276
+ >
277
+ <WholeWord className="w-3.5 h-3.5" />
278
+ </button>
279
+ <button
280
+ onClick={() => setUseRegex((v) => !v)}
281
+ className={`p-1 rounded text-xs transition-colors ${
282
+ useRegex
283
+ ? "bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] border border-[var(--color-accent)]/50"
284
+ : "text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)] border border-transparent"
285
+ }`}
286
+ title="Use Regular Expression"
287
+ >
288
+ <Regex className="w-3.5 h-3.5" />
289
+ </button>
290
+
291
+ <div className="flex-1" />
292
+
293
+ {isSearching ? (
294
+ <button
295
+ onClick={cancelSearch}
296
+ className="px-2 py-1 text-xs text-red-400 hover:text-red-300 transition-colors flex items-center gap-1"
297
+ >
298
+ <Loader2 className="w-3 h-3 animate-spin" />
299
+ Cancel
300
+ </button>
301
+ ) : (
302
+ query.trim() && (
303
+ <button
304
+ onClick={performSearch}
305
+ className="px-2 py-1 text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded transition-colors"
306
+ >
307
+ Search
308
+ </button>
309
+ )
310
+ )}
311
+ </div>
312
+ </div>
313
+
314
+ {/* Results header */}
315
+ {hasSearched && !isSearching && (
316
+ <div className="px-3 py-1.5 text-[11px] text-[var(--color-text-placeholder)] border-b border-[var(--color-bg-secondary)] flex-shrink-0">
317
+ {totalMatches > 0 ? (
318
+ <>
319
+ <span className="text-[var(--color-text-accent)] font-medium">{totalMatches}</span> result{totalMatches !== 1 && "s"} in{" "}
320
+ <span className="text-[var(--color-text-accent)] font-medium">{results.length}</span> file
321
+ {results.length !== 1 && "s"}
322
+ <span className="ml-2 text-gray-600">({filesSearched} files searched)</span>
323
+ </>
324
+ ) : (
325
+ "No results found"
326
+ )}
327
+ </div>
328
+ )}
329
+
330
+ {/* Loading state */}
331
+ {isSearching && (
332
+ <div className="flex items-center justify-center py-8 text-[var(--color-text-placeholder)] text-sm flex-shrink-0">
333
+ <Loader2 className="w-4 h-4 animate-spin mr-2" />
334
+ Searching...
335
+ </div>
336
+ )}
337
+
338
+ {/* Results list */}
339
+ <div className="flex-1 overflow-y-auto">
340
+ {!hasSearched && !isSearching ? (
341
+ <div className="flex flex-col items-center justify-center h-full text-[var(--color-text-tertiary)] text-xs px-4">
342
+ <Search className="w-8 h-8 mb-2 text-[var(--color-text-placeholder)]" />
343
+ <p>Type a search term and press Enter</p>
344
+ <p className="mt-1 text-[var(--color-text-placeholder)]">
345
+ {modKey}+Shift+F to focus search
346
+ </p>
347
+ </div>
348
+ ) : !isSearching && totalMatches === 0 ? (
349
+ <div className="flex flex-col items-center justify-center h-full text-[var(--color-text-tertiary)] text-xs px-4">
350
+ <FileText className="w-8 h-8 mb-2 text-[var(--color-text-placeholder)]" />
351
+ <p>No results for "{query}"</p>
352
+ <p className="mt-1 text-[var(--color-text-placeholder)]">Try different search terms</p>
353
+ </div>
354
+ ) : (
355
+ <div className="py-1">
356
+ {results.map((group, gi) => (
357
+ <div key={group.filePath}>
358
+ {/* File group header */}
359
+ <button
360
+ onClick={() => toggleGroup(gi)}
361
+ className="w-full flex items-center gap-1 px-2 py-1 text-xs hover:bg-[var(--color-bg-secondary)] transition-colors text-left"
362
+ >
363
+ {group.expanded ? (
364
+ <ChevronDown className="w-3 h-3 text-[var(--color-text-placeholder)] flex-shrink-0" />
365
+ ) : (
366
+ <ChevronRight className="w-3 h-3 text-[var(--color-text-placeholder)] flex-shrink-0" />
367
+ )}
368
+ <FileText className="w-3.5 h-3.5 text-[var(--color-text-placeholder)] flex-shrink-0" />
369
+ <span className="text-[var(--color-text-secondary)] truncate flex-1">{group.relativePath}</span>
370
+ <span className="text-[10px] text-gray-600 flex-shrink-0 ml-1">
371
+ {group.matches.length}
372
+ </span>
373
+ </button>
374
+
375
+ {/* Individual matches */}
376
+ {group.expanded && (
377
+ <div className="ml-4">
378
+ {group.matches.map((match, mi) => (
379
+ <button
380
+ key={mi}
381
+ onClick={() => handleOpenFile(match.file, match.line)}
382
+ 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"
383
+ >
384
+ <span className="text-[var(--color-text-tertiary)] w-6 text-right flex-shrink-0 select-none pt-px">
385
+ {match.line}
386
+ </span>
387
+ <span className="text-[var(--color-text-tertiary)] truncate font-mono leading-relaxed">
388
+ {match.text.slice(0, match.highlightStart)}
389
+ <span className="bg-[var(--color-accent)]/40 text-[var(--color-text-accent)]">
390
+ {match.text.slice(match.highlightStart, match.highlightEnd)}
391
+ </span>
392
+ {match.text.slice(match.highlightEnd)}
393
+ </span>
394
+ </button>
395
+ ))}
396
+ </div>
397
+ )}
398
+ </div>
399
+ ))}
400
+ </div>
401
+ )}
402
+ </div>
403
+ </div>
404
+ );
405
+ }
@@ -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
+ }
@@ -0,0 +1,13 @@
1
+ declare global {
2
+ interface Window {
3
+ __electrobun?: {
4
+ receiveMessageFromBun: (msg: unknown) => void;
5
+ };
6
+ __electrobunBunBridge?: {
7
+ postMessage: (msg: string) => void;
8
+ };
9
+ /** Desktop IPC receiver: Bun calls this via executeJavascript */
10
+ __piAgentIPC?: (msg: unknown) => void;
11
+ }
12
+ }
13
+ export {};
@@ -0,0 +1,34 @@
1
+ import { useEffect } from "react";
2
+ import { useSidebarStore, type Breakpoint } from "../stores/use-sidebar-store";
3
+
4
+ function getBreakpoint(width: number): Breakpoint {
5
+ if (width < 768) return "mobile";
6
+ if (width < 1024) return "tablet";
7
+ return "desktop";
8
+ }
9
+
10
+ /**
11
+ * 单一 ResizeObserver,同步 breakpoint 到 sidebar store。
12
+ * 组件通过 useSidebarStore(s => s.breakpoint) 读取。
13
+ */
14
+ export function useBreakpointSync() {
15
+ useEffect(() => {
16
+ let timer: ReturnType<typeof setTimeout>;
17
+ const obs = new ResizeObserver((entries) => {
18
+ clearTimeout(timer);
19
+ timer = setTimeout(() => {
20
+ for (const entry of entries) {
21
+ const bp = getBreakpoint(entry.contentRect.width);
22
+ if (bp !== useSidebarStore.getState().breakpoint) {
23
+ useSidebarStore.getState()._setBreakpoint(bp);
24
+ }
25
+ }
26
+ }, 100);
27
+ });
28
+ obs.observe(document.documentElement);
29
+ return () => {
30
+ clearTimeout(timer);
31
+ obs.disconnect();
32
+ };
33
+ }, []);
34
+ }