@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,108 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import type { RPCServer } from "@dyyz1993/rpc-core";
3
+
4
+ vi.mock("../../lib/logger", () => ({
5
+ createLogger: () => ({
6
+ info: vi.fn(),
7
+ error: vi.fn(),
8
+ warn: vi.fn(),
9
+ debug: vi.fn(),
10
+ }),
11
+ }));
12
+
13
+ describe("Feed Handler", () => {
14
+ let registeredHandlers: Record<string, Function>;
15
+ let mockServer: {
16
+ register: ReturnType<typeof vi.fn>;
17
+ emitEvent: ReturnType<typeof vi.fn>;
18
+ };
19
+
20
+ beforeEach(async () => {
21
+ vi.resetModules();
22
+ registeredHandlers = {};
23
+ mockServer = {
24
+ register: vi.fn((method: string, handler: Function) => {
25
+ registeredHandlers[method] = handler;
26
+ }),
27
+ emitEvent: vi.fn(),
28
+ };
29
+ const { register } = await import("../feed");
30
+ register(mockServer as unknown as RPCServer, { platform: "web" });
31
+ });
32
+
33
+ it("should register feed.post and feed.list", () => {
34
+ expect(registeredHandlers["feed.post"]).toBeDefined();
35
+ expect(registeredHandlers["feed.list"]).toBeDefined();
36
+ });
37
+
38
+ it("feed.post should create a post and return id", async () => {
39
+ const result = await registeredHandlers["feed.post"]({
40
+ content: "Hello feed",
41
+ category: "tech",
42
+ author: "tester",
43
+ });
44
+ expect(result).toHaveProperty("id");
45
+ expect(result.id).toMatch(/^feed-/);
46
+ });
47
+
48
+ it("feed.post should default author to anonymous", async () => {
49
+ await registeredHandlers["feed.post"]({
50
+ content: "test",
51
+ category: "general",
52
+ });
53
+ expect(mockServer.emitEvent).toHaveBeenCalledWith(
54
+ "feed.update",
55
+ expect.objectContaining({ author: "anonymous" }),
56
+ expect.objectContaining({ author: "anonymous" }),
57
+ );
58
+ });
59
+
60
+ it("feed.post should emit feed.update event", async () => {
61
+ await registeredHandlers["feed.post"]({
62
+ content: "event test",
63
+ category: "news",
64
+ author: "reporter",
65
+ });
66
+ expect(mockServer.emitEvent).toHaveBeenCalledWith(
67
+ "feed.update",
68
+ expect.objectContaining({
69
+ content: "event test",
70
+ category: "news",
71
+ author: "reporter",
72
+ }),
73
+ { category: "news", author: "reporter" },
74
+ );
75
+ });
76
+
77
+ it("feed.list should return all posts by default", async () => {
78
+ await registeredHandlers["feed.post"]({ content: "post 1", category: "tech" });
79
+ await registeredHandlers["feed.post"]({ content: "post 2", category: "general" });
80
+
81
+ const result = await registeredHandlers["feed.list"]({});
82
+ expect(result.posts).toHaveLength(2);
83
+ });
84
+
85
+ it("feed.list should filter by category", async () => {
86
+ await registeredHandlers["feed.post"]({ content: "tech post", category: "tech" });
87
+ await registeredHandlers["feed.post"]({ content: "news post", category: "news" });
88
+ await registeredHandlers["feed.post"]({ content: "general post", category: "general" });
89
+
90
+ const result = await registeredHandlers["feed.list"]({ category: "tech" });
91
+ expect(result.posts).toHaveLength(1);
92
+ expect(result.posts[0].category).toBe("tech");
93
+ });
94
+
95
+ it("feed.list should respect limit param", async () => {
96
+ for (let i = 0; i < 5; i++) {
97
+ await registeredHandlers["feed.post"]({ content: `post ${i}`, category: "tech" });
98
+ }
99
+
100
+ const result = await registeredHandlers["feed.list"]({ limit: 3 });
101
+ expect(result.posts).toHaveLength(3);
102
+ });
103
+
104
+ it("feed.list should default limit to 50", async () => {
105
+ const result = await registeredHandlers["feed.list"]({});
106
+ expect(result.posts.length).toBeLessThanOrEqual(50);
107
+ });
108
+ });
@@ -0,0 +1,100 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+
3
+ vi.mock("../../lib/logger", () => ({
4
+ createLogger: () => ({
5
+ info: vi.fn(),
6
+ error: vi.fn(),
7
+ warn: vi.fn(),
8
+ debug: vi.fn(),
9
+ }),
10
+ }));
11
+
12
+ describe("File Handler", () => {
13
+ beforeEach(() => {
14
+ vi.resetModules();
15
+ });
16
+
17
+ describe("path-security integration", () => {
18
+ it("validatePath should reject null bytes", async () => {
19
+ const { validatePath } = await import("../../lib/path-security");
20
+ expect(() => validatePath("/some/path\0/evil")).toThrow(
21
+ "Access denied: path contains null bytes",
22
+ );
23
+ });
24
+
25
+ it("validatePath should reject paths outside allowed roots", async () => {
26
+ const { validatePath, setAllowedRoots } = await import("../../lib/path-security");
27
+ setAllowedRoots(["/safe/dir"]);
28
+ expect(() => validatePath("/etc/passwd")).toThrow(
29
+ "Access denied",
30
+ );
31
+ });
32
+
33
+ it("validatePath should accept paths within allowed roots", async () => {
34
+ const { validatePath, setAllowedRoots } = await import("../../lib/path-security");
35
+ setAllowedRoots(["/tmp"]);
36
+ const result = validatePath("/tmp/test.txt");
37
+ expect(result).toContain("/tmp");
38
+ });
39
+
40
+ it("isRpcPathAllowed should return false for null bytes", async () => {
41
+ const { isRpcPathAllowed } = await import("../../lib/path-security");
42
+ expect(isRpcPathAllowed("/some\0path")).toBe(false);
43
+ });
44
+ });
45
+
46
+ describe("register", () => {
47
+ it("should register all file.* methods", async () => {
48
+ const registeredMethods: string[] = [];
49
+ const mockServer = {
50
+ register: vi.fn((method: string) => {
51
+ registeredMethods.push(method);
52
+ }),
53
+ };
54
+
55
+ vi.doMock("fs/promises", async (importOriginal) => {
56
+ const actual = await importOriginal() as Record<string, unknown>;
57
+ return {
58
+ ...actual,
59
+ readdir: vi.fn().mockResolvedValue([]),
60
+ stat: vi.fn().mockResolvedValue({ isDirectory: () => true, size: 0 }),
61
+ writeFile: vi.fn().mockResolvedValue(undefined),
62
+ readFile: vi.fn().mockResolvedValue(Buffer.from("")),
63
+ mkdir: vi.fn().mockResolvedValue(undefined),
64
+ rename: vi.fn().mockResolvedValue(undefined),
65
+ rm: vi.fn().mockResolvedValue(undefined),
66
+ cp: vi.fn().mockResolvedValue(undefined),
67
+ };
68
+ });
69
+
70
+ vi.doMock("fs", async (importOriginal) => {
71
+ const actual = await importOriginal() as Record<string, unknown>;
72
+ return {
73
+ ...actual,
74
+ existsSync: vi.fn().mockReturnValue(true),
75
+ };
76
+ });
77
+
78
+ const { setAllowedRoots } = await import("../../lib/path-security");
79
+ setAllowedRoots(["/tmp"]);
80
+
81
+ const { register } = await import("../file");
82
+ register(mockServer as any, { platform: "web" });
83
+
84
+ const expectedMethods = [
85
+ "file.findProjectRoot",
86
+ "file.listDir",
87
+ "file.createFile",
88
+ "file.createDir",
89
+ "file.rename",
90
+ "file.delete",
91
+ "file.copy",
92
+ "file.readFile",
93
+ ];
94
+
95
+ for (const method of expectedMethods) {
96
+ expect(registeredMethods).toContain(method);
97
+ }
98
+ });
99
+ });
100
+ });
@@ -0,0 +1,55 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import type { RPCServer } from "@dyyz1993/rpc-core";
3
+
4
+ describe("System Handler", () => {
5
+ let mockServer: { register: ReturnType<typeof vi.fn> };
6
+ let registeredHandlers: Record<string, Function>;
7
+
8
+ beforeEach(async () => {
9
+ vi.resetModules();
10
+ registeredHandlers = {};
11
+ mockServer = {
12
+ register: vi.fn((method: string, handler: Function) => {
13
+ registeredHandlers[method] = handler;
14
+ }),
15
+ };
16
+ const { register } = await import("../system");
17
+ register(mockServer as unknown as RPCServer, { platform: "web" });
18
+ });
19
+
20
+ it("should register system methods", () => {
21
+ expect(registeredHandlers["system.ping"]).toBeDefined();
22
+ expect(registeredHandlers["system.hello"]).toBeDefined();
23
+ expect(registeredHandlers["system.echo"]).toBeDefined();
24
+ });
25
+
26
+ it("system.ping should return pong with timestamp and platform", async () => {
27
+ const result = await registeredHandlers["system.ping"]({});
28
+ expect(result).toHaveProperty("pong", true);
29
+ expect(result).toHaveProperty("timestamp");
30
+ expect(result).toHaveProperty("platform", "web");
31
+ expect(typeof result.timestamp).toBe("number");
32
+ });
33
+
34
+ it("system.hello should return greeting with provided name", async () => {
35
+ const result = await registeredHandlers["system.hello"]({ name: "World" });
36
+ expect(result.message).toContain("World");
37
+ expect(result.message).toBe("Hello World!");
38
+ expect(result).toHaveProperty("timestamp");
39
+ });
40
+
41
+ it("system.hello should default to 'World'", async () => {
42
+ const result = await registeredHandlers["system.hello"]({});
43
+ expect(result.message).toBe("Hello World!");
44
+ });
45
+
46
+ it("system.echo should return input params", async () => {
47
+ const result = await registeredHandlers["system.echo"]({ data: "test", num: 42 });
48
+ expect(result).toEqual({ data: "test", num: 42 });
49
+ });
50
+
51
+ it("system.echo should return empty object for empty params", async () => {
52
+ const result = await registeredHandlers["system.echo"]({});
53
+ expect(result).toEqual({});
54
+ });
55
+ });
@@ -0,0 +1,77 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import type { RPCServer } from "@dyyz1993/rpc-core";
3
+
4
+ describe("Timer Handler", () => {
5
+ let registeredHandlers: Record<string, Function>;
6
+ let mockServer: {
7
+ register: ReturnType<typeof vi.fn>;
8
+ emitEvent: ReturnType<typeof vi.fn>;
9
+ };
10
+
11
+ beforeEach(async () => {
12
+ vi.useFakeTimers();
13
+ vi.resetModules();
14
+ registeredHandlers = {};
15
+ mockServer = {
16
+ register: vi.fn((method: string, handler: Function) => {
17
+ registeredHandlers[method] = handler;
18
+ }),
19
+ emitEvent: vi.fn(),
20
+ };
21
+ const { register } = await import("../timer");
22
+ register(mockServer as unknown as RPCServer, { platform: "web" });
23
+ });
24
+
25
+ afterEach(() => {
26
+ vi.useRealTimers();
27
+ });
28
+
29
+ it("should register timer.start and timer.stop", () => {
30
+ expect(registeredHandlers["timer.start"]).toBeDefined();
31
+ expect(registeredHandlers["timer.stop"]).toBeDefined();
32
+ });
33
+
34
+ it("timer.start should return started: true", async () => {
35
+ const result = await registeredHandlers["timer.start"]({});
36
+ expect(result).toEqual({ started: true });
37
+ });
38
+
39
+ it("timer.start should return alreadyRunning: true if called twice", async () => {
40
+ await registeredHandlers["timer.start"]({});
41
+ const result = await registeredHandlers["timer.start"]({});
42
+ expect(result).toEqual({ alreadyRunning: true });
43
+ });
44
+
45
+ it("timer.start should emit timer.tick events on interval", async () => {
46
+ await registeredHandlers["timer.start"]({});
47
+ vi.advanceTimersByTime(3500);
48
+ expect(mockServer.emitEvent).toHaveBeenCalledTimes(3);
49
+ expect(mockServer.emitEvent).toHaveBeenCalledWith(
50
+ "timer.tick",
51
+ expect.objectContaining({ count: expect.any(Number), timestamp: expect.any(Number) }),
52
+ { channel: "default" },
53
+ );
54
+ });
55
+
56
+ it("timer.stop should return stopped: true", async () => {
57
+ await registeredHandlers["timer.start"]({});
58
+ const result = await registeredHandlers["timer.stop"]({});
59
+ expect(result).toEqual({ stopped: true });
60
+ });
61
+
62
+ it("timer.stop should stop emitting tick events", async () => {
63
+ await registeredHandlers["timer.start"]({});
64
+ vi.advanceTimersByTime(1500);
65
+ const ticksBefore = mockServer.emitEvent.mock.calls.length;
66
+
67
+ await registeredHandlers["timer.stop"]({});
68
+ vi.advanceTimersByTime(3000);
69
+
70
+ expect(mockServer.emitEvent.mock.calls.length).toBe(ticksBefore);
71
+ });
72
+
73
+ it("timer.stop without start should still return stopped: true", async () => {
74
+ const result = await registeredHandlers["timer.stop"]({});
75
+ expect(result).toEqual({ stopped: true });
76
+ });
77
+ });
@@ -0,0 +1,89 @@
1
+ import type { RPCServer } from "@dyyz1993/rpc-core";
2
+ import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
3
+ import type { RPCMethods, HandlerOptions } from "../rpc-schema";
4
+ import { validateCommand, setCommandPolicy } from "../lib/bash-security";
5
+
6
+ type RegisterFn = <K extends keyof RPCMethods & string>(
7
+ method: K,
8
+ handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
9
+ ) => void;
10
+
11
+ interface TrackedProcess {
12
+ pid: number;
13
+ command: string;
14
+ running: boolean;
15
+ }
16
+
17
+ const processes = new Map<number, TrackedProcess>();
18
+ let pidCounter = 1;
19
+
20
+ export function register(server: RPCServer, _options: HandlerOptions): void {
21
+ setCommandPolicy({
22
+ enabled: _options.enableBash !== false,
23
+ blockedPatterns: [
24
+ /rm\s+-rf\s+(.*\s)?\/($|\s)/,
25
+ /rm\s+-rf\s+--no-preserve-root/,
26
+ /mkfs/,
27
+ /dd\s+if=/,
28
+ />\s*\/dev\//,
29
+ /:()\s*\{.*\|.*&\s*\}/,
30
+ /shutdown/,
31
+ /reboot/,
32
+ ],
33
+ allowedCommands: null,
34
+ });
35
+
36
+ const r: RegisterFn = (method, handler) => {
37
+ server.register(method, handler as (params: unknown) => Promise<unknown>);
38
+ };
39
+
40
+ r("bash.execute", async (params) => {
41
+ const safeCommand = validateCommand(params.command);
42
+ const pid = pidCounter++;
43
+ const proc: TrackedProcess = { pid, command: safeCommand, running: true };
44
+ processes.set(pid, proc);
45
+
46
+ try {
47
+ const subprocess = Bun.spawn(safeCommand.split(" "), {
48
+ cwd: params.cwd || process.cwd(),
49
+ stdout: "pipe",
50
+ stderr: "pipe",
51
+ });
52
+
53
+ proc.pid = subprocess.pid;
54
+
55
+ const stdout = await new Response(subprocess.stdout).text();
56
+ const stderr = await new Response(subprocess.stderr).text();
57
+ const exitCode = await subprocess.exited;
58
+
59
+ proc.running = false;
60
+
61
+ const output = stdout + (stderr ? `\n[stderr]\n${stderr}` : "");
62
+
63
+ server.emitEvent("bash.output", { pid, data: output, stream: "stdout" }, {});
64
+ server.emitEvent("bash.exit", { pid, code: exitCode }, {});
65
+
66
+ return { pid, output };
67
+ } catch (err) {
68
+ proc.running = false;
69
+ const output = `Error: ${err instanceof Error ? err.message : String(err)}`;
70
+ server.emitEvent("bash.output", { pid, data: output, stream: "stderr" }, {});
71
+ server.emitEvent("bash.exit", { pid, code: 1 }, {});
72
+ return { pid, output };
73
+ }
74
+ });
75
+
76
+ r("bash.kill", async (params) => {
77
+ const proc = processes.get(params.pid);
78
+ if (proc) {
79
+ proc.running = false;
80
+ processes.delete(params.pid);
81
+ return { success: true };
82
+ }
83
+ return { success: false };
84
+ });
85
+
86
+ r("bash.listProcesses", async () => ({
87
+ processes: Array.from(processes.values()),
88
+ }));
89
+ }
@@ -0,0 +1,179 @@
1
+ import type { RPCServer } from "@dyyz1993/rpc-core";
2
+ import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
3
+ import type { RPCMethods, HandlerOptions } from "../rpc-schema";
4
+ import { readFile, writeFile, mkdir } from "fs/promises";
5
+ import { existsSync } from "fs";
6
+ import { join, dirname } from "path";
7
+ import { homedir } from "os";
8
+ import { createLogger } from "../lib/logger";
9
+
10
+ const log = createLogger("chat");
11
+
12
+ function getStoragePath(): string {
13
+ const dir = join(homedir(), ".pi-agent");
14
+ return join(dir, "chat-history.json");
15
+ }
16
+
17
+ type ChatMessage = { id: string; role: "user" | "assistant"; content: string; timestamp: number };
18
+
19
+ async function loadMessages(): Promise<ChatMessage[]> {
20
+ const filePath = getStoragePath();
21
+ try {
22
+ if (!existsSync(filePath)) {
23
+ log.info(`No history file at ${filePath}`);
24
+ return [];
25
+ }
26
+ const raw = await readFile(filePath, "utf-8");
27
+ const msgs = JSON.parse(raw) as ChatMessage[];
28
+ log.info(`Loaded ${msgs.length} messages from ${filePath}`);
29
+ return msgs;
30
+ } catch (err) {
31
+ log.error("Failed to load history", { error: err });
32
+ return [];
33
+ }
34
+ }
35
+
36
+ async function saveMessages(messages: ChatMessage[]): Promise<void> {
37
+ const filePath = getStoragePath();
38
+ const dir = dirname(filePath);
39
+ try {
40
+ if (!existsSync(dir)) {
41
+ await mkdir(dir, { recursive: true });
42
+ }
43
+ await writeFile(filePath, JSON.stringify(messages, null, 2), "utf-8");
44
+ log.info(`Saved ${messages.length} messages to ${filePath}`);
45
+ } catch (err) {
46
+ log.error("Failed to save history", { error: err });
47
+ }
48
+ }
49
+
50
+ type RegisterFn = <K extends keyof RPCMethods & string>(
51
+ method: K,
52
+ handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
53
+ ) => void;
54
+
55
+ function generateReply(input: string): string {
56
+ const lower = input.toLowerCase().trim();
57
+
58
+ if (/^(hi|hello|hey|howdy|hola|yo|sup)\b/i.test(lower)) {
59
+ const greetings = [
60
+ "Hey there! How can I help you today?",
61
+ "Hello! Great to see you. What would you like to know?",
62
+ "Hi! I'm your desktop assistant. Ask me anything!",
63
+ ];
64
+ return greetings[Math.floor(Math.random() * greetings.length)];
65
+ }
66
+
67
+ if (/what('?s| is) the (time|date|day)|current (time|date)|what time|today'?s date/i.test(lower)) {
68
+ const now = new Date();
69
+ const date = now.toLocaleDateString("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric" });
70
+ const time = now.toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit" });
71
+ return `It's currently **${time}** on **${date}**.`;
72
+ }
73
+
74
+ const mathMatch = lower.match(
75
+ /(?:what(?:'s| is)\s+)?(\d+(?:\.\d+)?)\s*([+\-*/x×÷^])\s*(\d+(?:\.\d+)?)/,
76
+ );
77
+ if (mathMatch) {
78
+ const a = parseFloat(mathMatch[1]);
79
+ const op = mathMatch[2];
80
+ const b = parseFloat(mathMatch[3]);
81
+ let result: number;
82
+ switch (op) {
83
+ case "+": result = a + b; break;
84
+ case "-": result = a - b; break;
85
+ case "*": case "x": case "×": result = a * b; break;
86
+ case "/": case "÷": result = b !== 0 ? a / b : NaN; break;
87
+ case "^": result = Math.pow(a, b); break;
88
+ default: result = NaN;
89
+ }
90
+ if (isNaN(result)) {
91
+ return "Hmm, I couldn't calculate that. Did you try dividing by zero?";
92
+ }
93
+ const niceResult = Number.isInteger(result) ? result.toString() : result.toFixed(4).replace(/0+$/, "").replace(/\.$/, "");
94
+ return `That would be **${niceResult}**! Need help with anything else?`;
95
+ }
96
+
97
+ if (/file|folder|directory|browse|explorer|open file|read file/i.test(lower)) {
98
+ return (
99
+ "To browse and manage files, use the **File Explorer** panel on the left sidebar. " +
100
+ "You can navigate directories, preview files, and open them for editing. " +
101
+ "Try typing a file path or asking me about a specific directory!"
102
+ );
103
+ }
104
+
105
+ if (/git|commit|branch|push|pull|merge|status|diff|log/i.test(lower)) {
106
+ return (
107
+ "The **Git Panel** gives you full source control right inside the app. " +
108
+ "You can view changes, stage files, commit, switch branches, push/pull, and see the commit log. " +
109
+ "Look for the source control icon in the sidebar to get started."
110
+ );
111
+ }
112
+
113
+ if (/^(help|commands|what can you|what do you|capabilities|features)/i.test(lower)) {
114
+ return (
115
+ "Here's what I can help with:\n\n" +
116
+ "- **Greetings** - Say hi and I'll say hi back!\n" +
117
+ "- **Time & Date** - Ask \"what time is it?\" or \"what's today's date?\"\n" +
118
+ "- **Math** - Give me an expression like \"12 * 8\" or \"what is 100 / 4\"\n" +
119
+ "- **Files** - Ask about file browsing and I'll explain the File Explorer\n" +
120
+ "- **Git** - Ask about version control and I'll walk you through it\n" +
121
+ "- **Help** - Show this message anytime!\n\n" +
122
+ "This is a demo assistant - try different things to see what sticks!"
123
+ );
124
+ }
125
+
126
+ const defaults = [
127
+ "That's an interesting question! I'm a demo assistant, so my knowledge is limited - but try asking about **time**, **math**, **files**, or **git**.",
128
+ "I wish I could help with that! For now I can answer questions about time, do simple math, and explain the app's features. Type **help** to see what I can do.",
129
+ "Hmm, I'm not sure about that one. But I *can* do math, tell you the time, and explain features. Give it a shot!",
130
+ ];
131
+ return defaults[Math.floor(Math.random() * defaults.length)];
132
+ }
133
+
134
+ export function register(server: RPCServer, _options: HandlerOptions): void {
135
+ const r: RegisterFn = (method, handler) => {
136
+ server.register(method, handler as (params: unknown) => Promise<unknown>);
137
+ };
138
+
139
+ r("chat.list", async (params) => {
140
+ const all = await loadMessages();
141
+ const limit = params.limit ?? 50;
142
+ const messages = all.slice(-limit);
143
+ return {
144
+ messages,
145
+ hasMore: all.length > limit,
146
+ };
147
+ });
148
+
149
+ r("chat.send", async (params) => {
150
+ const all = await loadMessages();
151
+
152
+ const userMsg: ChatMessage = {
153
+ id: `msg-${Date.now()}-user`,
154
+ role: "user",
155
+ content: params.content,
156
+ timestamp: Date.now(),
157
+ };
158
+ all.push(userMsg);
159
+
160
+ server.emitEvent("chat.message", userMsg, { role: userMsg.role });
161
+
162
+ const thinkDelay = 200 + Math.floor(Math.random() * 300);
163
+ await new Promise((r) => setTimeout(r, thinkDelay));
164
+
165
+ const reply: ChatMessage = {
166
+ id: `msg-${Date.now()}-assistant`,
167
+ role: "assistant",
168
+ content: generateReply(params.content),
169
+ timestamp: Date.now(),
170
+ };
171
+ all.push(reply);
172
+
173
+ server.emitEvent("chat.message", reply, { role: reply.role });
174
+
175
+ await saveMessages(all);
176
+
177
+ return { ok: true };
178
+ });
179
+ }
@@ -0,0 +1,53 @@
1
+ import type { RPCServer } from "@dyyz1993/rpc-core";
2
+ import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
3
+ import type { RPCMethods, HandlerOptions } from "../rpc-schema";
4
+ import type { FeedPost, FeedCategory } from "../modules/feed";
5
+ import { createLogger } from "../lib/logger";
6
+
7
+ const log = createLogger("feed");
8
+
9
+ // 内存存储
10
+ const posts: FeedPost[] = [];
11
+
12
+ type RegisterFn = <K extends keyof RPCMethods & string>(
13
+ method: K,
14
+ handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
15
+ ) => void;
16
+
17
+ export function register(server: RPCServer, _options: HandlerOptions): void {
18
+ const r: RegisterFn = (method, handler) => {
19
+ server.register(method, handler as (params: unknown) => Promise<unknown>);
20
+ };
21
+
22
+ r("feed.post", async (params) => {
23
+ const category = params.category as FeedCategory;
24
+ const author = (params.author as string) || "anonymous";
25
+
26
+ const post: FeedPost = {
27
+ id: `feed-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
28
+ content: params.content,
29
+ category,
30
+ author,
31
+ timestamp: Date.now(),
32
+ };
33
+
34
+ posts.push(post);
35
+ log.info(`New post: ${post.id} [${category}] by ${author}`);
36
+
37
+ // 发送事件 — metadata 用于过滤
38
+ server.emitEvent("feed.update", post, { category, author });
39
+
40
+ return { id: post.id };
41
+ });
42
+
43
+ r("feed.list", async (params) => {
44
+ const limit = params.limit ?? 50;
45
+ let filtered = posts;
46
+
47
+ if (params.category) {
48
+ filtered = posts.filter((p) => p.category === params.category);
49
+ }
50
+
51
+ return { posts: filtered.slice(-limit) };
52
+ });
53
+ }