@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,109 @@
1
+ import { describe, it, expect, beforeEach, vi } from "vitest";
2
+ import { render, screen, fireEvent } from "@testing-library/react";
3
+ import { FeedPanel } from "../../components/feed/FeedPanel";
4
+ import { useFeedStore, useEventStreamStore } from "../../stores/use-feed-store";
5
+ import { act } from "@testing-library/react";
6
+
7
+ vi.mock("../../lib/api-client", () => ({
8
+ apiClient: {
9
+ call: vi.fn().mockResolvedValue({ posts: [] }),
10
+ subscribe: vi.fn().mockResolvedValue("sub-1"),
11
+ unsubscribe: vi.fn(),
12
+ },
13
+ }));
14
+
15
+ vi.mock("../../stores/use-log-store", () => ({
16
+ useLogStore: Object.assign(
17
+ (s: (state: { addLog: () => void }) => unknown) => s({ addLog: vi.fn() }),
18
+ { getState: () => ({ addLog: vi.fn() }) }
19
+ ),
20
+ }));
21
+
22
+ vi.mock("../../stores/use-connection-store", () => ({
23
+ useConnectionStore: Object.assign(
24
+ (s: (state: { ready: boolean }) => unknown) => s({ ready: true }),
25
+ { getState: () => ({ ready: true }) }
26
+ ),
27
+ }));
28
+
29
+ vi.mock("react-i18next", () => ({
30
+ useTranslation: () => ({
31
+ t: (key: string) => {
32
+ const map: Record<string, string> = {
33
+ "feed.title": "Feed",
34
+ "feed.newPost": "New Post",
35
+ "feed.authorPlaceholder": "Author",
36
+ "feed.postPlaceholder": "Write a post...",
37
+ "feed.post": "Post",
38
+ "feed.noPostsYet": "No posts yet",
39
+ "feed.subscribeWithFilter": "Subscribe",
40
+ "feed.filterPlaceholder": "Filter JSON",
41
+ "feed.subscribe": "Subscribe",
42
+ "feed.unsubscribe": "Unsubscribe",
43
+ "feed.noFilter": "No filter",
44
+ "feed.eventStream": "Events",
45
+ "feed.live": "LIVE",
46
+ };
47
+ return map[key] ?? key;
48
+ },
49
+ i18n: { language: "en" },
50
+ }),
51
+ }));
52
+
53
+ describe("FeedPanel", () => {
54
+ beforeEach(() => {
55
+ act(() => {
56
+ useFeedStore.setState({
57
+ posts: [],
58
+ author: "alice",
59
+ category: "tech",
60
+ content: "",
61
+ loading: false,
62
+ });
63
+ useEventStreamStore.setState({
64
+ entries: [],
65
+ activeEventType: "feed.update",
66
+ activeFilter: "",
67
+ subscriptionId: null,
68
+ subscribed: false,
69
+ });
70
+ });
71
+ });
72
+
73
+ it("renders feed title", () => {
74
+ render(<FeedPanel />);
75
+ expect(screen.getByText("Feed")).toBeInTheDocument();
76
+ });
77
+
78
+ it("shows empty state when no posts", () => {
79
+ render(<FeedPanel />);
80
+ expect(screen.getByText("No posts yet")).toBeInTheDocument();
81
+ });
82
+
83
+ it("renders post creation form", () => {
84
+ render(<FeedPanel />);
85
+ expect(screen.getByPlaceholderText("Author")).toBeInTheDocument();
86
+ expect(screen.getByPlaceholderText("Write a post...")).toBeInTheDocument();
87
+ expect(screen.getByText("Post")).toBeInTheDocument();
88
+ });
89
+
90
+ it("updates author on typing", () => {
91
+ render(<FeedPanel />);
92
+ const input = screen.getByPlaceholderText("Author");
93
+ fireEvent.change(input, { target: { value: "bob" } });
94
+ expect(useFeedStore.getState().author).toBe("bob");
95
+ });
96
+
97
+ it("displays posts when present", () => {
98
+ act(() => {
99
+ useFeedStore.setState({
100
+ posts: [
101
+ { id: "1", content: "Hello feed", category: "tech", author: "alice", timestamp: Date.now() },
102
+ ],
103
+ });
104
+ });
105
+ render(<FeedPanel />);
106
+ expect(screen.getByText("Hello feed")).toBeInTheDocument();
107
+ expect(screen.getByText("alice")).toBeInTheDocument();
108
+ });
109
+ });
@@ -0,0 +1,151 @@
1
+ import { describe, it, expect, beforeEach, vi } from "vitest";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { GitPanel } from "../../components/git/GitPanel";
4
+ import { useGitStore } from "../../stores/use-git-store";
5
+ import { act } from "@testing-library/react";
6
+
7
+ const defaultGitState = {
8
+ branch: "main",
9
+ ahead: 0,
10
+ behind: 0,
11
+ staged: [],
12
+ changed: [],
13
+ untracked: [],
14
+ commits: [],
15
+ loadingCommits: false,
16
+ currentDiff: null,
17
+ loadingDiff: false,
18
+ expandedCommits: new Set(),
19
+ commitFiles: {},
20
+ loadingCommitFiles: new Set(),
21
+ branches: [],
22
+ loadingBranches: false,
23
+ worktrees: [],
24
+ loadingAction: null,
25
+ fetchStatus: vi.fn().mockResolvedValue(undefined),
26
+ fetchDiff: vi.fn().mockResolvedValue(undefined),
27
+ fetchLog: vi.fn().mockResolvedValue(undefined),
28
+ clearDiff: vi.fn(),
29
+ toggleCommitExpand: vi.fn().mockResolvedValue(undefined),
30
+ fetchCommitFileDiff: vi.fn().mockResolvedValue(undefined),
31
+ fetchBranches: vi.fn().mockResolvedValue(undefined),
32
+ checkout: vi.fn().mockResolvedValue(undefined),
33
+ stageFiles: vi.fn().mockResolvedValue(undefined),
34
+ unstageFiles: vi.fn().mockResolvedValue(undefined),
35
+ commit: vi.fn().mockResolvedValue(undefined),
36
+ push: vi.fn().mockResolvedValue(undefined),
37
+ pull: vi.fn().mockResolvedValue(undefined),
38
+ fetchWorktrees: vi.fn().mockResolvedValue(undefined),
39
+ refresh: vi.fn().mockResolvedValue(undefined),
40
+ };
41
+
42
+ vi.mock("../../lib/api-client", () => ({
43
+ apiClient: {
44
+ call: vi.fn().mockResolvedValue({}),
45
+ },
46
+ }));
47
+
48
+ vi.mock("../../stores/use-log-store", () => ({
49
+ useLogStore: Object.assign(
50
+ (s: (state: { addLog: () => void }) => unknown) => s({ addLog: vi.fn() }),
51
+ { getState: () => ({ addLog: vi.fn() }) }
52
+ ),
53
+ }));
54
+
55
+ vi.mock("../../stores/use-explorer-store", () => ({
56
+ useExplorerStore: Object.assign(
57
+ (s: (state: { currentPath: string; openFile: () => void }) => unknown) =>
58
+ s({ currentPath: "/repo", openFile: vi.fn() }),
59
+ { getState: () => ({ currentPath: "/repo", openFile: vi.fn() }) }
60
+ ),
61
+ }));
62
+
63
+ vi.mock("../../stores/use-sidebar-store", () => ({
64
+ useSidebarStore: (s: (state: { isPinned: boolean; breakpoint: string }) => unknown) =>
65
+ s({ isPinned: false, breakpoint: "desktop" }),
66
+ }));
67
+
68
+ vi.mock("react-i18next", () => ({
69
+ useTranslation: () => ({
70
+ t: (key: string) => {
71
+ const map: Record<string, string> = {
72
+ "git.title": "Source Control",
73
+ "git.staged": "Staged",
74
+ "git.changes": "Changes",
75
+ "git.untracked": "Untracked",
76
+ "git.noChanges": "No changes",
77
+ "git.commits": "Commits",
78
+ "git.refresh": "Refresh",
79
+ "git.pull": "Pull",
80
+ "git.push": "Push",
81
+ "git.unstageAll": "Unstage All",
82
+ "git.stageAll": "Stage All",
83
+ "git.openDiff": "Open Diff",
84
+ "git.openFile": "Open File",
85
+ "git.copyPath": "Copy Path",
86
+ "git.copyHash": "Copy Hash",
87
+ "git.copyMessage": "Copy Message",
88
+ "git.loadingFiles": "Loading...",
89
+ "git.noFiles": "No files",
90
+ "git.noCommits": "No commits",
91
+ "git.worktrees": "Worktrees",
92
+ "git.close": "Close",
93
+ "git.justNow": "just now",
94
+ "git.minutesAgo": "{{count}}m ago",
95
+ "git.hoursAgo": "{{count}}h ago",
96
+ "git.daysAgo": "{{count}}d ago",
97
+ "common.loading": "Loading...",
98
+ "git.commitPlaceholder": "Message",
99
+ };
100
+ return map[key] ?? key;
101
+ },
102
+ i18n: { language: "en" },
103
+ }),
104
+ }));
105
+
106
+ describe("GitPanel", () => {
107
+ beforeEach(() => {
108
+ act(() => {
109
+ useGitStore.setState(defaultGitState);
110
+ });
111
+ });
112
+
113
+ it("renders git title", () => {
114
+ render(<GitPanel />);
115
+ expect(screen.getByText("Source Control")).toBeInTheDocument();
116
+ });
117
+
118
+ it("shows no changes when empty", () => {
119
+ render(<GitPanel />);
120
+ expect(screen.getByText("No changes")).toBeInTheDocument();
121
+ });
122
+
123
+ it("displays staged files with label", () => {
124
+ act(() => {
125
+ useGitStore.setState({
126
+ ...defaultGitState,
127
+ staged: [{ path: "src/foo.ts", status: "modified" }],
128
+ });
129
+ });
130
+ render(<GitPanel />);
131
+ expect(screen.getByText("foo.ts")).toBeInTheDocument();
132
+ expect(screen.getByText(/Staged/)).toBeInTheDocument();
133
+ });
134
+
135
+ it("displays changed files with label", () => {
136
+ act(() => {
137
+ useGitStore.setState({
138
+ ...defaultGitState,
139
+ changed: [{ path: "src/bar.ts", status: "added" }],
140
+ });
141
+ });
142
+ render(<GitPanel />);
143
+ expect(screen.getByText("bar.ts")).toBeInTheDocument();
144
+ expect(screen.getByText(/Changes/)).toBeInTheDocument();
145
+ });
146
+
147
+ it("shows branch name", () => {
148
+ render(<GitPanel />);
149
+ expect(screen.getByText("main")).toBeInTheDocument();
150
+ });
151
+ });
@@ -0,0 +1,48 @@
1
+ import { describe, it, expect, beforeEach, vi } from "vitest";
2
+
3
+ describe("i18n configuration", () => {
4
+ beforeEach(async () => {
5
+ vi.resetModules();
6
+ });
7
+
8
+ it("should export configured i18n instance", async () => {
9
+ const i18n = await import("../../lib/i18n");
10
+ expect(i18n.default).toBeDefined();
11
+ expect(i18n.default.isInitialized).toBe(true);
12
+ });
13
+
14
+ it("should have English translations", async () => {
15
+ const i18n = await import("../../lib/i18n");
16
+ expect(
17
+ i18n.default.getResource("en", "translation", "app.title")
18
+ ).toBeDefined();
19
+ });
20
+
21
+ it("should have Chinese translations", async () => {
22
+ const i18n = await import("../../lib/i18n");
23
+ expect(
24
+ i18n.default.getResource("zh", "translation", "app.title")
25
+ ).toBeDefined();
26
+ });
27
+
28
+ it("should change language", async () => {
29
+ const i18n = await import("../../lib/i18n");
30
+ await i18n.default.changeLanguage("zh");
31
+ expect(i18n.default.language).toBe("zh");
32
+
33
+ await i18n.default.changeLanguage("en");
34
+ expect(i18n.default.language).toBe("en");
35
+ });
36
+
37
+ it("should translate keys correctly in English", async () => {
38
+ const i18n = await import("../../lib/i18n");
39
+ await i18n.default.changeLanguage("en");
40
+ expect(i18n.default.t("app.title")).toBe("Pi Agent");
41
+ });
42
+
43
+ it("should translate keys correctly in Chinese", async () => {
44
+ const i18n = await import("../../lib/i18n");
45
+ await i18n.default.changeLanguage("zh");
46
+ expect(i18n.default.t("app.title")).toBe("Pi Agent");
47
+ });
48
+ });
@@ -0,0 +1,8 @@
1
+ import { describe, it, expect } from "vitest";
2
+
3
+ describe("vitest setup", () => {
4
+ it("runs in happy-dom environment", () => {
5
+ expect(typeof window).toBe("object");
6
+ expect(typeof document).toBe("object");
7
+ });
8
+ });
@@ -0,0 +1,37 @@
1
+ import "@testing-library/jest-dom/vitest";
2
+
3
+ Object.defineProperty(window, "matchMedia", {
4
+ writable: true,
5
+ value: (query: string) => ({
6
+ matches: false,
7
+ media: query,
8
+ onchange: null,
9
+ addListener: () => {},
10
+ removeListener: () => {},
11
+ addEventListener: () => {},
12
+ removeEventListener: () => {},
13
+ dispatchEvent: () => false,
14
+ }),
15
+ });
16
+
17
+ const localStorageMock = (() => {
18
+ let store: Record<string, string> = {};
19
+ return {
20
+ getItem: (key: string) => store[key] ?? null,
21
+ setItem: (key: string, value: string) => {
22
+ store[key] = String(value);
23
+ },
24
+ removeItem: (key: string) => {
25
+ delete store[key];
26
+ },
27
+ clear: () => {
28
+ store = {};
29
+ },
30
+ get length() {
31
+ return Object.keys(store).length;
32
+ },
33
+ key: (i: number) => Object.keys(store)[i] ?? null,
34
+ };
35
+ })();
36
+
37
+ Object.defineProperty(window, "localStorage", { value: localStorageMock });
@@ -0,0 +1,40 @@
1
+ import { Folder, GitBranch, Search, MessageSquare, Rss, Bug } from "lucide-react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { useSidebarStore, type SidebarPanelId } from "../../stores/use-sidebar-store";
4
+
5
+ const items: { id: SidebarPanelId; icon: typeof Folder; labelKey: string }[] = [
6
+ { id: "explorer", icon: Folder, labelKey: "sidebar.explorer" },
7
+ { id: "git", icon: GitBranch, labelKey: "sidebar.git" },
8
+ { id: "search", icon: Search, labelKey: "sidebar.search" },
9
+ { id: "chat", icon: MessageSquare, labelKey: "tabs.chat" },
10
+ { id: "feed", icon: Rss, labelKey: "tabs.feed" },
11
+ { id: "debug", icon: Bug, labelKey: "tabs.debug" },
12
+ ];
13
+
14
+ export function ActivityBar() {
15
+ const { t } = useTranslation();
16
+ const activePanel = useSidebarStore((s) => s.activePanel);
17
+ const togglePanel = useSidebarStore((s) => s.togglePanel);
18
+
19
+ return (
20
+ <div data-testid="activity-bar" className="w-12 bg-[var(--color-bg-primary)] border-r border-[var(--color-border-primary)] flex flex-col items-center py-2 gap-1 flex-shrink-0">
21
+ {items.map(({ id, icon: Icon, labelKey }) => (
22
+ <button
23
+ key={id}
24
+ data-testid={`tab-${id}`}
25
+ title={t(labelKey)}
26
+ onClick={() => togglePanel(id)}
27
+ className={`w-10 h-10 flex items-center justify-center rounded transition-colors ${
28
+ activePanel === id
29
+ ? "bg-[var(--color-bg-tertiary)] text-[var(--color-text-primary)] border-l-2 border-[var(--color-text-primary)]"
30
+ : "text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)]"
31
+ }`}
32
+ >
33
+ <Icon className="w-5 h-5" />
34
+ </button>
35
+ ))}
36
+ </div>
37
+ );
38
+ }
39
+
40
+ export { items };
@@ -0,0 +1,29 @@
1
+ import { useTranslation } from "react-i18next";
2
+ import { useSidebarStore } from "../../stores/use-sidebar-store";
3
+ import { items } from "./ActivityBar";
4
+
5
+ export function MobileTabBar() {
6
+ const { t } = useTranslation();
7
+ const activePanel = useSidebarStore((s) => s.activePanel);
8
+ const togglePanel = useSidebarStore((s) => s.togglePanel);
9
+
10
+ return (
11
+ <div className="h-14 bg-[var(--color-bg-primary)] border-t border-[var(--color-border-primary)] flex items-center justify-around flex-shrink-0">
12
+ {items.map(({ id, icon: Icon, labelKey }) => (
13
+ <button
14
+ key={id}
15
+ data-testid={`tab-${id}`}
16
+ onClick={() => togglePanel(id)}
17
+ className={`flex flex-col items-center justify-center gap-0.5 px-3 py-1 rounded transition-colors ${
18
+ activePanel === id
19
+ ? "text-[var(--color-text-accent)]"
20
+ : "text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)]"
21
+ }`}
22
+ >
23
+ <Icon className="w-5 h-5" />
24
+ <span className="text-[10px]">{t(labelKey)}</span>
25
+ </button>
26
+ ))}
27
+ </div>
28
+ );
29
+ }
@@ -0,0 +1,66 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { MessageSquare, Send } from "lucide-react";
3
+ import { useTranslation } from "react-i18next";
4
+ import { useChatStore } from "../../stores/use-chat-store";
5
+ import { MessageBubble } from "./MessageBubble";
6
+
7
+ export function ChatPanel() {
8
+ const { t } = useTranslation();
9
+ const messages = useChatStore((s) => s.messages);
10
+ const inputText = useChatStore((s) => s.inputText);
11
+ const setInputText = useChatStore((s) => s.setInputText);
12
+ const sendMessage = useChatStore((s) => s.sendMessage);
13
+ const messagesEndRef = useRef<HTMLDivElement>(null);
14
+
15
+ useEffect(() => {
16
+ messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
17
+ }, [messages]);
18
+
19
+ return (
20
+ <div className="flex-1 flex flex-col overflow-hidden relative">
21
+ {/* Chat header */}
22
+ <div className="px-4 py-2 bg-[var(--color-bg-secondary)] border-b border-[var(--color-border-primary)] flex items-center justify-between flex-shrink-0">
23
+ <h2 className="text-sm font-semibold flex items-center gap-1.5">
24
+ <MessageSquare className="w-4 h-4 text-[var(--color-text-accent)]" />
25
+ {t("chat.title")}
26
+ {messages.length > 0 && (
27
+ <span className="ml-1 px-2 py-0.5 bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] rounded text-[10px]">
28
+ {messages.length}
29
+ </span>
30
+ )}
31
+ </h2>
32
+ </div>
33
+
34
+ {/* Messages list */}
35
+ <div className="flex-1 overflow-y-auto p-4 space-y-3">
36
+ {messages.length === 0 ? (
37
+ <div className="flex items-center justify-center h-full text-[var(--color-text-placeholder)] text-sm">
38
+ {t("chat.empty")}
39
+ </div>
40
+ ) : (
41
+ messages.map((msg) => <MessageBubble key={msg.id} message={msg} />)
42
+ )}
43
+ <div ref={messagesEndRef} />
44
+ </div>
45
+
46
+ {/* Input bar */}
47
+ <div className="px-4 py-3 bg-[var(--color-bg-secondary)] border-t border-[var(--color-border-primary)] flex gap-2 flex-shrink-0">
48
+ <input
49
+ type="text"
50
+ value={inputText}
51
+ onChange={(e) => setInputText(e.target.value)}
52
+ onKeyDown={(e) => e.key === "Enter" && !e.shiftKey && sendMessage()}
53
+ placeholder={t("chat.placeholder")}
54
+ className="flex-1 px-3 py-2 text-sm bg-[var(--color-bg-tertiary)] rounded-lg text-[var(--color-text-primary)] border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
55
+ />
56
+ <button
57
+ onClick={sendMessage}
58
+ className="px-4 py-2 text-sm bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded-lg transition-colors flex items-center gap-1.5"
59
+ >
60
+ <Send className="w-4 h-4" />
61
+ {t("chat.send")}
62
+ </button>
63
+ </div>
64
+ </div>
65
+ );
66
+ }
@@ -0,0 +1,85 @@
1
+ import { Bot } from "lucide-react";
2
+ import ReactMarkdown from "react-markdown";
3
+ import remarkGfm from "remark-gfm";
4
+ import { Highlight, themes } from "prism-react-renderer";
5
+ import type { ChatMessage } from "../../types";
6
+
7
+ interface MessageBubbleProps {
8
+ message: ChatMessage;
9
+ }
10
+
11
+ function formatTime(ts: number): string {
12
+ const d = new Date(ts);
13
+ const hh = d.getHours().toString().padStart(2, "0");
14
+ const mm = d.getMinutes().toString().padStart(2, "0");
15
+ return `${hh}:${mm}`;
16
+ }
17
+
18
+ function CodeBlock({ children, className }: { children: string; className?: string }) {
19
+ const language = className?.replace(/language-/, "") || "text";
20
+ return (
21
+ <Highlight theme={themes.nightOwl} code={children.trimEnd()} language={language}>
22
+ {({ style, tokens, getLineProps, getTokenProps }) => (
23
+ <pre
24
+ className="rounded-md p-3 my-2 overflow-x-auto text-xs leading-relaxed"
25
+ style={{ ...style, background: "#1e1e2e" }}
26
+ >
27
+ {tokens.map((line, i) => (
28
+ <div key={i} {...getLineProps({ line })}>
29
+ {line.map((token, key) => (
30
+ <span key={key} {...getTokenProps({ token })} />
31
+ ))}
32
+ </div>
33
+ ))}
34
+ </pre>
35
+ )}
36
+ </Highlight>
37
+ );
38
+ }
39
+
40
+ export function MessageBubble({ message }: MessageBubbleProps) {
41
+ const isUser = message.role === "user";
42
+
43
+ return (
44
+ <div className={`flex ${isUser ? "justify-end" : "justify-start"} items-start gap-2`}>
45
+ {!isUser && (
46
+ <div className="flex-shrink-0 mt-1">
47
+ <Bot className="w-4 h-4 text-[var(--color-text-accent)]" />
48
+ </div>
49
+ )}
50
+ <div
51
+ className={`max-w-[85%] px-3 py-2 rounded-lg text-sm break-words ${
52
+ isUser
53
+ ? "bg-[var(--color-accent)] text-[var(--color-text-primary)]"
54
+ : "bg-[var(--color-bg-tertiary)] text-[var(--color-text-secondary)]"
55
+ }`}
56
+ >
57
+ {isUser ? (
58
+ <span className="whitespace-pre-wrap">{message.content}</span>
59
+ ) : (
60
+ <div className="markdown-body prose prose-invert prose-sm max-w-none [&_p]:mb-2 [&_p:last-child]:mb-0 [&_ul]:list-disc [&_ul]:pl-4 [&_ol]:list-decimal [&_ol]:pl-4 [&_li]:mb-1 [&_h1]:text-base [&_h1]:font-bold [&_h1]:mb-2 [&_h2]:text-sm [&_h2]:font-bold [&_h2]:mb-1 [&_blockquote]:border-l-2 [&_blockquote]:border-[var(--color-text-accent)] [&_blockquote]:pl-3 [&_blockquote]:text-[var(--color-text-tertiary)] [&_a]:text-[var(--color-text-accent)] [&_a]:underline [&_code:not(pre_code)]:bg-[var(--color-bg-input)] [&_code:not(pre_code)]:px-1 [&_code:not(pre_code)]:rounded [&_code:not(pre_code)]:text-xs [&_table]:border-collapse [&_th]:border [&_th]:border-[var(--color-border-secondary)] [&_th]:px-2 [&_th]:py-1 [&_td]:border [&_td]:border-[var(--color-border-secondary)] [&_td]:px-2 [&_td]:py-1">
61
+ <ReactMarkdown
62
+ remarkPlugins={[remarkGfm]}
63
+ components={{
64
+ code({ className, children, ...props }) {
65
+ const isBlock = className?.startsWith("language-") || String(children).includes("\n");
66
+ if (isBlock) {
67
+ return <CodeBlock className={className}>{String(children)}</CodeBlock>;
68
+ }
69
+ return <code className={className} {...props}>{children}</code>;
70
+ },
71
+ }}
72
+ >
73
+ {message.content}
74
+ </ReactMarkdown>
75
+ </div>
76
+ )}
77
+ </div>
78
+ {message.timestamp && (
79
+ <span className="text-[10px] text-[var(--color-text-tertiary)] ml-2 flex-shrink-0">
80
+ {formatTime(message.timestamp)}
81
+ </span>
82
+ )}
83
+ </div>
84
+ );
85
+ }
@@ -0,0 +1,15 @@
1
+ import { useLocaleStore } from "../../stores/use-locale-store";
2
+
3
+ export function LanguageSwitcher() {
4
+ const { locale, setLocale } = useLocaleStore();
5
+
6
+ return (
7
+ <button
8
+ onClick={() => setLocale(locale === "en" ? "zh" : "en")}
9
+ className="px-1.5 py-0.5 rounded text-xs hover:bg-[var(--color-bg-hover)] transition-colors text-[var(--color-text-secondary)]"
10
+ title={locale === "en" ? "切换到中文" : "Switch to English"}
11
+ >
12
+ {locale === "en" ? "中" : "EN"}
13
+ </button>
14
+ );
15
+ }
@@ -0,0 +1,24 @@
1
+ import { useThemeStore } from "../../stores/use-theme-store";
2
+
3
+ export function ThemeToggle() {
4
+ const theme = useThemeStore((s) => s.theme);
5
+ const toggleTheme = useThemeStore((s) => s.toggleTheme);
6
+
7
+ return (
8
+ <button
9
+ onClick={toggleTheme}
10
+ className="p-1.5 rounded-md hover:bg-[var(--color-bg-hover)] transition-colors"
11
+ title={theme === "dark" ? "Switch to light mode" : "Switch to dark mode"}
12
+ >
13
+ {theme === "dark" ? (
14
+ <svg className="w-4 h-4 text-yellow-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
15
+ <path strokeLinecap="round" strokeLinejoin="round" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" />
16
+ </svg>
17
+ ) : (
18
+ <svg className="w-4 h-4 text-gray-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
19
+ <path strokeLinecap="round" strokeLinejoin="round" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" />
20
+ </svg>
21
+ )}
22
+ </button>
23
+ );
24
+ }