@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,161 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+
3
+ vi.mock("../../lib/api-client", () => ({
4
+ apiClient: { call: vi.fn() },
5
+ }));
6
+
7
+ vi.mock("../use-log-store", () => ({
8
+ useLogStore: { getState: () => ({ addLog: vi.fn() }) },
9
+ }));
10
+
11
+ describe("useGitStore", () => {
12
+ beforeEach(async () => {
13
+ vi.resetModules();
14
+ });
15
+
16
+ it("should have correct initial state", async () => {
17
+ const { useGitStore } = await import("../use-git-store");
18
+ const state = useGitStore.getState();
19
+ expect(state.branch).toBe("");
20
+ expect(state.ahead).toBe(0);
21
+ expect(state.behind).toBe(0);
22
+ expect(state.staged).toEqual([]);
23
+ expect(state.changed).toEqual([]);
24
+ expect(state.untracked).toEqual([]);
25
+ expect(state.commits).toEqual([]);
26
+ expect(state.loadingCommits).toBe(false);
27
+ expect(state.currentDiff).toBeNull();
28
+ expect(state.loadingDiff).toBe(false);
29
+ expect(state.branches).toEqual([]);
30
+ expect(state.worktrees).toEqual([]);
31
+ expect(state.loadingAction).toBeNull();
32
+ });
33
+
34
+ it("should fetch status", async () => {
35
+ const { apiClient } = await import("../../lib/api-client");
36
+ const { useGitStore } = await import("../use-git-store");
37
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
38
+ branch: "main",
39
+ ahead: 2,
40
+ behind: 1,
41
+ staged: [{ path: "a.ts", status: "modified" }],
42
+ changed: [{ path: "b.ts", status: "added" }],
43
+ untracked: ["c.ts"],
44
+ });
45
+
46
+ await useGitStore.getState().fetchStatus("/repo");
47
+ const state = useGitStore.getState();
48
+ expect(state.branch).toBe("main");
49
+ expect(state.ahead).toBe(2);
50
+ expect(state.behind).toBe(1);
51
+ expect(state.staged).toHaveLength(1);
52
+ expect(state.untracked).toEqual(["c.ts"]);
53
+ });
54
+
55
+ it("should fetch diff", async () => {
56
+ const { apiClient } = await import("../../lib/api-client");
57
+ const { useGitStore } = await import("../use-git-store");
58
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
59
+ filePath: "a.ts",
60
+ diff: "+hello",
61
+ oldContent: "",
62
+ newContent: "hello",
63
+ });
64
+
65
+ await useGitStore.getState().fetchDiff("/repo", "a.ts");
66
+ const state = useGitStore.getState();
67
+ expect(state.currentDiff).not.toBeNull();
68
+ expect(state.currentDiff!.filePath).toBe("a.ts");
69
+ expect(state.loadingDiff).toBe(false);
70
+ });
71
+
72
+ it("should clear diff", async () => {
73
+ const { useGitStore } = await import("../use-git-store");
74
+ useGitStore.setState({ currentDiff: { filePath: "a.ts", diff: "", oldContent: "", newContent: "" } });
75
+ useGitStore.getState().clearDiff();
76
+ expect(useGitStore.getState().currentDiff).toBeNull();
77
+ });
78
+
79
+ it("should fetch log", async () => {
80
+ const { apiClient } = await import("../../lib/api-client");
81
+ const { useGitStore } = await import("../use-git-store");
82
+ const commits = [
83
+ { hash: "abc123", shortHash: "abc1234", message: "init", author: "user", date: "2024-01-01" },
84
+ ];
85
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ commits });
86
+
87
+ await useGitStore.getState().fetchLog("/repo");
88
+ expect(useGitStore.getState().commits).toHaveLength(1);
89
+ expect(useGitStore.getState().loadingCommits).toBe(false);
90
+ });
91
+
92
+ it("should stage files and refresh", async () => {
93
+ const { apiClient } = await import("../../lib/api-client");
94
+ const { useGitStore } = await import("../use-git-store");
95
+ const callMock = apiClient.call as ReturnType<typeof vi.fn>;
96
+ callMock.mockResolvedValueOnce(undefined);
97
+ callMock.mockResolvedValueOnce({
98
+ branch: "main", ahead: 0, behind: 0, staged: [], changed: [], untracked: [],
99
+ });
100
+
101
+ await useGitStore.getState().stageFiles("/repo", ["a.ts"]);
102
+ expect(callMock).toHaveBeenCalledWith("git.add", { repoPath: "/repo", paths: ["a.ts"] });
103
+ expect(useGitStore.getState().loadingAction).toBeNull();
104
+ });
105
+
106
+ it("should unstage files and refresh", async () => {
107
+ const { apiClient } = await import("../../lib/api-client");
108
+ const { useGitStore } = await import("../use-git-store");
109
+ const callMock = apiClient.call as ReturnType<typeof vi.fn>;
110
+ callMock.mockResolvedValueOnce(undefined);
111
+ callMock.mockResolvedValueOnce({
112
+ branch: "main", ahead: 0, behind: 0, staged: [], changed: [], untracked: [],
113
+ });
114
+
115
+ await useGitStore.getState().unstageFiles("/repo", ["a.ts"]);
116
+ expect(callMock).toHaveBeenCalledWith("git.reset", { repoPath: "/repo", paths: ["a.ts"] });
117
+ expect(useGitStore.getState().loadingAction).toBeNull();
118
+ });
119
+
120
+ it("should commit and refresh", async () => {
121
+ const { apiClient } = await import("../../lib/api-client");
122
+ const { useGitStore } = await import("../use-git-store");
123
+ const callMock = apiClient.call as ReturnType<typeof vi.fn>;
124
+ callMock.mockResolvedValueOnce({ shortHash: "abc1234" });
125
+ callMock.mockResolvedValueOnce({
126
+ branch: "main", ahead: 0, behind: 0, staged: [], changed: [], untracked: [],
127
+ });
128
+
129
+ await useGitStore.getState().commit("/repo", "init commit");
130
+ expect(callMock).toHaveBeenCalledWith("git.commit", { repoPath: "/repo", message: "init commit" });
131
+ expect(useGitStore.getState().loadingAction).toBeNull();
132
+ });
133
+
134
+ it("should toggle commit expand and load files", async () => {
135
+ const { apiClient } = await import("../../lib/api-client");
136
+ const { useGitStore } = await import("../use-git-store");
137
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
138
+ files: [{ path: "a.ts", status: "modified" }],
139
+ });
140
+
141
+ await useGitStore.getState().toggleCommitExpand("/repo", "abc123");
142
+ const state = useGitStore.getState();
143
+ expect(state.expandedCommits.has("abc123")).toBe(true);
144
+ expect(state.commitFiles["abc123"]).toHaveLength(1);
145
+ });
146
+
147
+ it("should fetch branches", async () => {
148
+ const { apiClient } = await import("../../lib/api-client");
149
+ const { useGitStore } = await import("../use-git-store");
150
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
151
+ branches: [
152
+ { name: "main", isCurrent: true, isRemote: false },
153
+ { name: "dev", isCurrent: false, isRemote: false },
154
+ ],
155
+ });
156
+
157
+ await useGitStore.getState().fetchBranches("/repo");
158
+ expect(useGitStore.getState().branches).toHaveLength(2);
159
+ expect(useGitStore.getState().loadingBranches).toBe(false);
160
+ });
161
+ });
@@ -0,0 +1,32 @@
1
+ import { describe, it, expect, beforeEach, vi } from "vitest";
2
+
3
+ describe("useLocaleStore", () => {
4
+ beforeEach(async () => {
5
+ vi.resetModules();
6
+ localStorage.clear();
7
+ });
8
+
9
+ it("should default to English", async () => {
10
+ const { useLocaleStore } = await import("../use-locale-store");
11
+ expect(useLocaleStore.getState().locale).toBe("en");
12
+ });
13
+
14
+ it("should change locale", async () => {
15
+ const { useLocaleStore } = await import("../use-locale-store");
16
+ useLocaleStore.getState().setLocale("zh");
17
+ expect(useLocaleStore.getState().locale).toBe("zh");
18
+ });
19
+
20
+ it("should persist locale to localStorage", async () => {
21
+ const { useLocaleStore } = await import("../use-locale-store");
22
+ useLocaleStore.getState().setLocale("zh");
23
+ expect(localStorage.getItem("locale")).toBe("zh");
24
+ });
25
+
26
+ it("should restore locale from localStorage", async () => {
27
+ localStorage.setItem("locale", "zh");
28
+ vi.resetModules();
29
+ const { useLocaleStore } = await import("../use-locale-store");
30
+ expect(useLocaleStore.getState().locale).toBe("zh");
31
+ });
32
+ });
@@ -0,0 +1,28 @@
1
+ import { describe, it, expect, beforeEach } from "vitest";
2
+
3
+ describe("useLogStore", () => {
4
+ beforeEach(async () => {
5
+ vi.resetModules();
6
+ });
7
+
8
+ it("should start with empty logs", async () => {
9
+ const { useLogStore } = await import("../use-log-store");
10
+ expect(useLogStore.getState().logs).toEqual([]);
11
+ });
12
+
13
+ it("should add log entries", async () => {
14
+ const { useLogStore } = await import("../use-log-store");
15
+ useLogStore.getState().addLog("test message");
16
+ const logs = useLogStore.getState().logs;
17
+ expect(logs).toHaveLength(1);
18
+ expect(logs[0]).toContain("test message");
19
+ });
20
+
21
+ it("should limit log entries", async () => {
22
+ const { useLogStore } = await import("../use-log-store");
23
+ for (let i = 0; i < 200; i++) {
24
+ useLogStore.getState().addLog(`log ${i}`);
25
+ }
26
+ expect(useLogStore.getState().logs.length).toBeLessThanOrEqual(100);
27
+ });
28
+ });
@@ -0,0 +1,102 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+
3
+ describe("useNotificationStore", () => {
4
+ beforeEach(async () => {
5
+ vi.resetModules();
6
+ vi.useFakeTimers();
7
+ });
8
+
9
+ afterEach(() => {
10
+ vi.useRealTimers();
11
+ });
12
+
13
+ it("should have correct initial state", async () => {
14
+ const { useNotificationStore } = await import("../use-notification-store");
15
+ const state = useNotificationStore.getState();
16
+ expect(state.notifications).toEqual([]);
17
+ expect(state.panelOpen).toBe(false);
18
+ });
19
+
20
+ it("should push a notification", async () => {
21
+ const { useNotificationStore } = await import("../use-notification-store");
22
+ useNotificationStore.getState().push({ message: "hello", level: "info" });
23
+ const state = useNotificationStore.getState();
24
+ expect(state.notifications).toHaveLength(1);
25
+ expect(state.notifications[0].message).toBe("hello");
26
+ expect(state.notifications[0].level).toBe("info");
27
+ expect(state.notifications[0].read).toBe(false);
28
+ expect(state.notifications[0].id).toMatch(/^notif-/);
29
+ });
30
+
31
+ it("should auto-dismiss info notifications after 5s", async () => {
32
+ const { useNotificationStore } = await import("../use-notification-store");
33
+ useNotificationStore.getState().push({ message: "temp", level: "info" });
34
+ expect(useNotificationStore.getState().notifications).toHaveLength(1);
35
+
36
+ vi.advanceTimersByTime(5000);
37
+ expect(useNotificationStore.getState().notifications).toHaveLength(0);
38
+ });
39
+
40
+ it("should not auto-dismiss warning/error notifications", async () => {
41
+ const { useNotificationStore } = await import("../use-notification-store");
42
+ useNotificationStore.getState().push({ message: "warn", level: "warning" });
43
+ useNotificationStore.getState().push({ message: "err", level: "error" });
44
+
45
+ vi.advanceTimersByTime(10000);
46
+ expect(useNotificationStore.getState().notifications).toHaveLength(2);
47
+ });
48
+
49
+ it("should mark a notification as read", async () => {
50
+ const { useNotificationStore } = await import("../use-notification-store");
51
+ useNotificationStore.getState().push({ message: "test", level: "warning" });
52
+ const id = useNotificationStore.getState().notifications[0].id;
53
+
54
+ useNotificationStore.getState().markRead(id);
55
+ expect(useNotificationStore.getState().notifications[0].read).toBe(true);
56
+ });
57
+
58
+ it("should mark all notifications as read", async () => {
59
+ const { useNotificationStore } = await import("../use-notification-store");
60
+ useNotificationStore.getState().push({ message: "a", level: "warning" });
61
+ useNotificationStore.getState().push({ message: "b", level: "error" });
62
+
63
+ useNotificationStore.getState().markAllRead();
64
+ const state = useNotificationStore.getState();
65
+ expect(state.notifications.every((n) => n.read)).toBe(true);
66
+ });
67
+
68
+ it("should dismiss a notification", async () => {
69
+ const { useNotificationStore } = await import("../use-notification-store");
70
+ useNotificationStore.getState().push({ message: "bye", level: "warning" });
71
+ const id = useNotificationStore.getState().notifications[0].id;
72
+
73
+ useNotificationStore.getState().dismiss(id);
74
+ expect(useNotificationStore.getState().notifications).toHaveLength(0);
75
+ });
76
+
77
+ it("should clear all notifications", async () => {
78
+ const { useNotificationStore } = await import("../use-notification-store");
79
+ useNotificationStore.getState().push({ message: "a", level: "error" });
80
+ useNotificationStore.getState().push({ message: "b", level: "error" });
81
+
82
+ useNotificationStore.getState().clearAll();
83
+ expect(useNotificationStore.getState().notifications).toHaveLength(0);
84
+ });
85
+
86
+ it("should toggle panel", async () => {
87
+ const { useNotificationStore } = await import("../use-notification-store");
88
+ expect(useNotificationStore.getState().panelOpen).toBe(false);
89
+ useNotificationStore.getState().togglePanel();
90
+ expect(useNotificationStore.getState().panelOpen).toBe(true);
91
+ useNotificationStore.getState().togglePanel();
92
+ expect(useNotificationStore.getState().panelOpen).toBe(false);
93
+ });
94
+
95
+ it("should set panel open explicitly", async () => {
96
+ const { useNotificationStore } = await import("../use-notification-store");
97
+ useNotificationStore.getState().setPanelOpen(true);
98
+ expect(useNotificationStore.getState().panelOpen).toBe(true);
99
+ useNotificationStore.getState().setPanelOpen(false);
100
+ expect(useNotificationStore.getState().panelOpen).toBe(false);
101
+ });
102
+ });
@@ -0,0 +1,75 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+
3
+ vi.mock("../../lib/api-client", () => ({
4
+ apiClient: { call: vi.fn() },
5
+ }));
6
+
7
+ vi.mock("../use-log-store", () => ({
8
+ useLogStore: { getState: () => ({ addLog: vi.fn() }) },
9
+ }));
10
+
11
+ describe("useRulesStore", () => {
12
+ beforeEach(async () => {
13
+ vi.resetModules();
14
+ });
15
+
16
+ it("should have correct initial state", async () => {
17
+ const { useRulesStore } = await import("../use-rules-store");
18
+ expect(useRulesStore.getState().rules).toEqual([]);
19
+ });
20
+
21
+ it("should fetch rules", async () => {
22
+ const { apiClient } = await import("../../lib/api-client");
23
+ const { useRulesStore } = await import("../use-rules-store");
24
+ const rules = [
25
+ { id: "r1", name: "no-console", pattern: "**/*.ts", enabled: true },
26
+ ];
27
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ rules });
28
+
29
+ await useRulesStore.getState().fetchRules();
30
+ expect(useRulesStore.getState().rules).toHaveLength(1);
31
+ expect(useRulesStore.getState().rules[0].name).toBe("no-console");
32
+ });
33
+
34
+ it("should add a rule", async () => {
35
+ const { apiClient } = await import("../../lib/api-client");
36
+ const { useRulesStore } = await import("../use-rules-store");
37
+ const newRule = { id: "r2", name: "test-rule", pattern: "*.js", enabled: true };
38
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ rule: newRule });
39
+
40
+ await useRulesStore.getState().addRule("test-rule", "*.js");
41
+ expect(useRulesStore.getState().rules).toHaveLength(1);
42
+ expect(useRulesStore.getState().rules[0].id).toBe("r2");
43
+ expect(apiClient.call).toHaveBeenCalledWith("rules.add", { name: "test-rule", pattern: "*.js" });
44
+ });
45
+
46
+ it("should toggle a rule", async () => {
47
+ const { apiClient } = await import("../../lib/api-client");
48
+ const { useRulesStore } = await import("../use-rules-store");
49
+ useRulesStore.setState({
50
+ rules: [{ id: "r1", name: "rule", pattern: "*.ts", enabled: true }],
51
+ });
52
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
53
+ rule: { id: "r1", name: "rule", pattern: "*.ts", enabled: false },
54
+ });
55
+
56
+ await useRulesStore.getState().toggleRule("r1");
57
+ expect(useRulesStore.getState().rules[0].enabled).toBe(false);
58
+ });
59
+
60
+ it("should remove a rule", async () => {
61
+ const { apiClient } = await import("../../lib/api-client");
62
+ const { useRulesStore } = await import("../use-rules-store");
63
+ useRulesStore.setState({
64
+ rules: [
65
+ { id: "r1", name: "a", pattern: "*.ts", enabled: true },
66
+ { id: "r2", name: "b", pattern: "*.js", enabled: false },
67
+ ],
68
+ });
69
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ success: true });
70
+
71
+ await useRulesStore.getState().removeRule("r1");
72
+ expect(useRulesStore.getState().rules).toHaveLength(1);
73
+ expect(useRulesStore.getState().rules[0].id).toBe("r2");
74
+ });
75
+ });
@@ -0,0 +1,59 @@
1
+ import { describe, it, expect, beforeEach, vi } from "vitest";
2
+
3
+ describe("useThemeStore", () => {
4
+ beforeEach(async () => {
5
+ vi.resetModules();
6
+ localStorage.clear();
7
+ document.documentElement.classList.remove("dark");
8
+ });
9
+
10
+ it("should default to dark theme", async () => {
11
+ const { useThemeStore } = await import("../use-theme-store");
12
+ const state = useThemeStore.getState();
13
+ expect(state.theme).toBe("dark");
14
+ });
15
+
16
+ it("should toggle between light and dark", async () => {
17
+ const { useThemeStore } = await import("../use-theme-store");
18
+ const store = useThemeStore.getState();
19
+
20
+ expect(store.theme).toBe("dark");
21
+ store.toggleTheme();
22
+ expect(useThemeStore.getState().theme).toBe("light");
23
+
24
+ useThemeStore.getState().toggleTheme();
25
+ expect(useThemeStore.getState().theme).toBe("dark");
26
+ });
27
+
28
+ it("should set theme explicitly", async () => {
29
+ const { useThemeStore } = await import("../use-theme-store");
30
+ useThemeStore.getState().setTheme("light");
31
+ expect(useThemeStore.getState().theme).toBe("light");
32
+ });
33
+
34
+ it("should persist theme to localStorage", async () => {
35
+ const { useThemeStore } = await import("../use-theme-store");
36
+ useThemeStore.getState().setTheme("light");
37
+
38
+ expect(localStorage.getItem("theme")).toBe("light");
39
+ });
40
+
41
+ it("should restore theme from localStorage", async () => {
42
+ localStorage.setItem("theme", "light");
43
+
44
+ vi.resetModules();
45
+ const { useThemeStore } = await import("../use-theme-store");
46
+
47
+ expect(useThemeStore.getState().theme).toBe("light");
48
+ });
49
+
50
+ it("should apply dark class to document element", async () => {
51
+ const { useThemeStore } = await import("../use-theme-store");
52
+ useThemeStore.getState().setTheme("dark");
53
+
54
+ expect(document.documentElement.classList.contains("dark")).toBe(true);
55
+
56
+ useThemeStore.getState().setTheme("light");
57
+ expect(document.documentElement.classList.contains("dark")).toBe(false);
58
+ });
59
+ });
@@ -0,0 +1,75 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+
3
+ vi.mock("../../lib/api-client", () => ({
4
+ apiClient: { call: vi.fn() },
5
+ }));
6
+
7
+ vi.mock("../use-log-store", () => ({
8
+ useLogStore: { getState: () => ({ addLog: vi.fn() }) },
9
+ }));
10
+
11
+ describe("useTodoStore", () => {
12
+ beforeEach(async () => {
13
+ vi.resetModules();
14
+ });
15
+
16
+ it("should have correct initial state", async () => {
17
+ const { useTodoStore } = await import("../use-todo-store");
18
+ expect(useTodoStore.getState().items).toEqual([]);
19
+ });
20
+
21
+ it("should fetch items", async () => {
22
+ const { apiClient } = await import("../../lib/api-client");
23
+ const { useTodoStore } = await import("../use-todo-store");
24
+ const items = [
25
+ { id: "t1", content: "task 1", status: "pending", createdAt: Date.now() },
26
+ ];
27
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ items });
28
+
29
+ await useTodoStore.getState().fetchItems();
30
+ expect(useTodoStore.getState().items).toHaveLength(1);
31
+ expect(useTodoStore.getState().items[0].content).toBe("task 1");
32
+ });
33
+
34
+ it("should add an item", async () => {
35
+ const { apiClient } = await import("../../lib/api-client");
36
+ const { useTodoStore } = await import("../use-todo-store");
37
+ const newItem = { id: "t2", content: "new task", status: "pending" as const, createdAt: Date.now() };
38
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ item: newItem });
39
+
40
+ await useTodoStore.getState().addItem("new task");
41
+ expect(useTodoStore.getState().items).toHaveLength(1);
42
+ expect(useTodoStore.getState().items[0].id).toBe("t2");
43
+ expect(apiClient.call).toHaveBeenCalledWith("todo.add", { content: "new task" });
44
+ });
45
+
46
+ it("should update an item status", async () => {
47
+ const { apiClient } = await import("../../lib/api-client");
48
+ const { useTodoStore } = await import("../use-todo-store");
49
+ useTodoStore.setState({
50
+ items: [{ id: "t1", content: "task", status: "pending", createdAt: Date.now() }],
51
+ });
52
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
53
+ item: { id: "t1", content: "task", status: "completed", createdAt: Date.now() },
54
+ });
55
+
56
+ await useTodoStore.getState().updateItem("t1", "completed");
57
+ expect(useTodoStore.getState().items[0].status).toBe("completed");
58
+ });
59
+
60
+ it("should remove an item", async () => {
61
+ const { apiClient } = await import("../../lib/api-client");
62
+ const { useTodoStore } = await import("../use-todo-store");
63
+ useTodoStore.setState({
64
+ items: [
65
+ { id: "t1", content: "a", status: "pending", createdAt: Date.now() },
66
+ { id: "t2", content: "b", status: "completed", createdAt: Date.now() },
67
+ ],
68
+ });
69
+ (apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ success: true });
70
+
71
+ await useTodoStore.getState().removeItem("t1");
72
+ expect(useTodoStore.getState().items).toHaveLength(1);
73
+ expect(useTodoStore.getState().items[0].id).toBe("t2");
74
+ });
75
+ });
@@ -0,0 +1,25 @@
1
+ type Update = { sessionId: string; apply: () => void };
2
+
3
+ let queue: Update[] = [];
4
+ let rafId: number | null = null;
5
+
6
+ function flush() {
7
+ rafId = null;
8
+ const batch = queue;
9
+ queue = [];
10
+ for (const u of batch) u.apply();
11
+ }
12
+
13
+ export function batchMessageUpdate(sessionId: string, apply: () => void) {
14
+ queue.push({ sessionId, apply });
15
+ if (!rafId) {
16
+ rafId = requestAnimationFrame(flush);
17
+ }
18
+ }
19
+
20
+ export function flushNow() {
21
+ if (rafId) {
22
+ cancelAnimationFrame(rafId);
23
+ flush();
24
+ }
25
+ }
@@ -0,0 +1,99 @@
1
+ import { create } from "zustand";
2
+ import { apiClient } from "../lib/api-client";
3
+ import type { RPCMethods } from "../lib/api-client";
4
+ import type { MethodResult } from "@dyyzz1993/rpc-core";
5
+ import type { DemoMethod } from "../types";
6
+ import { useLogStore } from "./use-log-store";
7
+
8
+ type DemoResult = MethodResult<RPCMethods, "system.ping">
9
+ | MethodResult<RPCMethods, "system.hello">
10
+ | MethodResult<RPCMethods, "system.echo">
11
+ | MethodResult<RPCMethods, "chat.send">;
12
+
13
+ interface AppState {
14
+ method: DemoMethod;
15
+ result: DemoResult | null;
16
+ tickEvents: string[];
17
+ tickCount: number;
18
+ subscriptionId: string | null;
19
+ timerRunning: boolean;
20
+
21
+ setMethod: (method: DemoMethod) => void;
22
+ callRPC: (inputText: string) => Promise<void>;
23
+ handleSubscribe: () => Promise<void>;
24
+ handleUnsubscribe: () => Promise<void>;
25
+ }
26
+
27
+ export const useAppStore = create<AppState>((set, get) => ({
28
+ method: "system.ping",
29
+ result: null,
30
+ tickEvents: [],
31
+ tickCount: 0,
32
+ subscriptionId: null,
33
+ timerRunning: false,
34
+
35
+ setMethod: (method) => set({ method }),
36
+
37
+ callRPC: async (inputText: string) => {
38
+ const { method } = get();
39
+ const addLog = useLogStore.getState().addLog;
40
+ addLog(`RPC call: ${method}`);
41
+ try {
42
+ addLog(`Calling: ${method}...`);
43
+ let res: DemoResult;
44
+ if (method === "system.ping") {
45
+ res = await apiClient.call("system.ping", {});
46
+ } else if (method === "system.hello") {
47
+ res = await apiClient.call("system.hello", {});
48
+ } else if (method === "system.echo") {
49
+ res = await apiClient.call("system.echo", {});
50
+ } else if (method === "chat.send") {
51
+ const content = inputText.trim() || "Hello from RPC";
52
+ res = await apiClient.call("chat.send", { content });
53
+ }
54
+ set({ result: res });
55
+ addLog(`Result: ${JSON.stringify(res)}`);
56
+ } catch (err) {
57
+ addLog(`Error: ${err instanceof Error ? err.message : String(err)}`);
58
+ }
59
+ },
60
+
61
+ handleSubscribe: async () => {
62
+ const addLog = useLogStore.getState().addLog;
63
+ try {
64
+ addLog("Subscribing to tick events...");
65
+ await apiClient.call("timer.start", {});
66
+ set({ timerRunning: true });
67
+ addLog("Timer started");
68
+
69
+ const subId = await apiClient.subscribe("timer.tick", (payload) => {
70
+ const time = new Date(payload.timestamp).toLocaleTimeString();
71
+ set((s) => ({
72
+ tickEvents: [...s.tickEvents.slice(-19), `#${payload.count} @ ${time}`],
73
+ tickCount: s.tickCount + 1,
74
+ }));
75
+ }, {});
76
+ set({ subscriptionId: subId });
77
+ addLog(`Subscribed: ${subId}`);
78
+ } catch (err) {
79
+ addLog(`Subscribe error: ${err instanceof Error ? err.message : String(err)}`);
80
+ }
81
+ },
82
+
83
+ handleUnsubscribe: async () => {
84
+ const { subscriptionId } = get();
85
+ const addLog = useLogStore.getState().addLog;
86
+ try {
87
+ if (subscriptionId) {
88
+ apiClient.unsubscribe(subscriptionId);
89
+ set({ subscriptionId: null });
90
+ addLog("Unsubscribed");
91
+ }
92
+ await apiClient.call("timer.stop", {});
93
+ set({ timerRunning: false });
94
+ addLog("Timer stopped");
95
+ } catch (err) {
96
+ addLog(`Unsubscribe error: ${err instanceof Error ? err.message : String(err)}`);
97
+ }
98
+ },
99
+ }));