@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,48 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, screen, cleanup, fireEvent } from "@testing-library/react";
3
+ import React from "react";
4
+
5
+ const mockSetPinned = vi.fn();
6
+
7
+ vi.mock("../../../stores/use-sidebar-store", () => ({
8
+ useSidebarStore: (selector: any) =>
9
+ selector({ isPinned: true, setPinned: mockSetPinned, breakpoint: "desktop" }),
10
+ }));
11
+
12
+ describe("PinButton", () => {
13
+ afterEach(() => {
14
+ cleanup();
15
+ vi.clearAllMocks();
16
+ });
17
+
18
+ it("should render a button", async () => {
19
+ const { PinButton } = await import("../PinButton");
20
+ render(<PinButton />);
21
+ expect(screen.getByRole("button")).toBeDefined();
22
+ });
23
+
24
+ it("should show unpin title when pinned", async () => {
25
+ const { PinButton } = await import("../PinButton");
26
+ render(<PinButton />);
27
+ expect(screen.getByTitle("Unpin sidebar")).toBeDefined();
28
+ });
29
+
30
+ it("should call setPinned on click", async () => {
31
+ const { PinButton } = await import("../PinButton");
32
+ render(<PinButton />);
33
+ fireEvent.click(screen.getByRole("button"));
34
+ expect(mockSetPinned).toHaveBeenCalledWith(false);
35
+ });
36
+
37
+ it("should not render on mobile", async () => {
38
+ vi.resetModules();
39
+ vi.doMock("../../../stores/use-sidebar-store", () => ({
40
+ useSidebarStore: (selector: any) =>
41
+ selector({ isPinned: false, setPinned: vi.fn(), breakpoint: "mobile" }),
42
+ }));
43
+ const mod = await import("../PinButton");
44
+ const { container } = render(<mod.PinButton />);
45
+ expect(container.innerHTML).toBe("");
46
+ vi.resetModules();
47
+ });
48
+ });
@@ -0,0 +1,141 @@
1
+ import { useState, useEffect } from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { Plus, Trash2, Circle, Clock, CheckCircle2, ListTodo } from "lucide-react";
4
+ import { useTodoStore } from "../../stores/use-todo-store";
5
+ import type { TodoStatus } from "../../../shared/modules/todo";
6
+
7
+ const nextStatus: Record<TodoStatus, TodoStatus> = {
8
+ pending: "in_progress",
9
+ in_progress: "completed",
10
+ completed: "pending",
11
+ };
12
+
13
+ const statusFlow = ["pending", "in_progress", "completed"] as const;
14
+
15
+ export function TodoPanel() {
16
+ const { t } = useTranslation();
17
+ const [showInput, setShowInput] = useState(false);
18
+ const [input, setInput] = useState("");
19
+ const items = useTodoStore((s) => s.items);
20
+ const fetchItems = useTodoStore((s) => s.fetchItems);
21
+ const addItem = useTodoStore((s) => s.addItem);
22
+ const updateItem = useTodoStore((s) => s.updateItem);
23
+ const removeItem = useTodoStore((s) => s.removeItem);
24
+
25
+ useEffect(() => {
26
+ fetchItems();
27
+ }, [fetchItems]);
28
+
29
+ const handleAdd = () => {
30
+ if (!input.trim()) return;
31
+ addItem(input.trim());
32
+ setInput("");
33
+ setShowInput(false);
34
+ };
35
+
36
+ const handleKeyDown = (e: React.KeyboardEvent) => {
37
+ if (e.key === "Enter") handleAdd();
38
+ if (e.key === "Escape") setShowInput(false);
39
+ };
40
+
41
+ const statusConfig: Record<TodoStatus, { icon: typeof Circle; color: string; label: string; circleColor: string }> = {
42
+ pending: { icon: Circle, color: "text-gray-400", label: t("todo.statusPending"), circleColor: "border-gray-500" },
43
+ in_progress: { icon: Clock, color: "text-yellow-400", label: t("todo.statusInProgress"), circleColor: "border-yellow-400 bg-yellow-400/20" },
44
+ completed: { icon: CheckCircle2, color: "text-green-400", label: t("todo.statusCompleted"), circleColor: "border-green-400 bg-green-400/20" },
45
+ };
46
+
47
+ return (
48
+ <div className="flex flex-col h-full">
49
+ <div className="p-3 border-b border-[var(--color-border-primary)] flex items-center justify-between">
50
+ <span className="text-sm text-[var(--color-text-secondary)]">{t("todo.title")}</span>
51
+ <button
52
+ onClick={() => setShowInput(!showInput)}
53
+ className="flex items-center gap-1 px-2 py-1 text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded text-[var(--color-text-primary)]"
54
+ >
55
+ <Plus className="w-3 h-3" />
56
+ {t("todo.add")}
57
+ </button>
58
+ </div>
59
+
60
+ {showInput && (
61
+ <div className="p-3 border-b border-[var(--color-border-primary)] bg-[var(--color-bg-secondary)] flex items-center gap-2">
62
+ <input
63
+ type="text"
64
+ value={input}
65
+ onChange={(e) => setInput(e.target.value)}
66
+ onKeyDown={handleKeyDown}
67
+ placeholder={t("todo.placeholder")}
68
+ autoFocus
69
+ className="flex-1 bg-[var(--color-bg-primary)] text-[var(--color-text-secondary)] px-3 py-1.5 rounded text-sm border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
70
+ />
71
+ <button
72
+ onClick={handleAdd}
73
+ disabled={!input.trim()}
74
+ className="px-3 py-1 text-xs bg-green-600 hover:bg-green-500 disabled:opacity-40 rounded text-white"
75
+ >
76
+ {t("todo.save")}
77
+ </button>
78
+ </div>
79
+ )}
80
+
81
+ <div className="flex-1 overflow-auto p-3">
82
+ {items.length === 0 ? (
83
+ <div className="flex flex-col items-center justify-center h-full text-gray-600">
84
+ <ListTodo className="w-12 h-12 mb-3 opacity-30" />
85
+ <span className="text-sm">{t("todo.empty")}</span>
86
+ <span className="text-xs mt-1">{t("todo.emptyHint")}</span>
87
+ </div>
88
+ ) : (
89
+ <div className="space-y-2.5">
90
+ {items.map((item) => {
91
+ const cfg = statusConfig[item.status as TodoStatus];
92
+ const Icon = cfg.icon;
93
+ return (
94
+ <div
95
+ key={item.id}
96
+ className="group relative bg-[var(--color-bg-secondary)]/60 border border-[var(--color-border-primary)]/80 rounded-lg p-3 hover:bg-[var(--color-bg-secondary)] hover:border-[var(--color-border-secondary)] transition-all"
97
+ >
98
+ <div className="flex items-start gap-3">
99
+ <button
100
+ onClick={() => updateItem(item.id, nextStatus[item.status as TodoStatus])}
101
+ className={`flex-shrink-0 mt-0.5 w-5 h-5 rounded-full border-2 flex items-center justify-center transition-all ${cfg.circleColor} ${cfg.color} hover:scale-110`}
102
+ >
103
+ <Icon className="w-3 h-3" />
104
+ </button>
105
+ <div className="flex-1 min-w-0">
106
+ <p className={`text-sm leading-relaxed ${
107
+ item.status === "completed" ? "text-[var(--color-text-placeholder)] line-through" : "text-[var(--color-text-secondary)]"
108
+ }`}>
109
+ {item.content}
110
+ </p>
111
+ <div className="flex items-center gap-1.5 mt-2 text-[11px] text-[var(--color-text-placeholder)]">
112
+ <span>{t("todo.status")}</span>
113
+ {statusFlow.map((s) => {
114
+ const sc = statusConfig[s];
115
+ const isActive = s === item.status;
116
+ return (
117
+ <span key={s} className={`inline-flex items-center gap-0.5 ${isActive ? sc.color + " font-medium" : ""}`}>
118
+ {isActive && <sc.icon className="w-2.5 h-2.5" />}
119
+ {sc.label}
120
+ {s !== "completed" && <span className="text-gray-700 mx-0.5">&rarr;</span>}
121
+ </span>
122
+ );
123
+ })}
124
+ </div>
125
+ </div>
126
+ <button
127
+ onClick={() => removeItem(item.id)}
128
+ className="text-gray-600 hover:text-[var(--color-text-error)] opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0 self-start mt-0.5"
129
+ >
130
+ <Trash2 className="w-3.5 h-3.5" />
131
+ </button>
132
+ </div>
133
+ </div>
134
+ );
135
+ })}
136
+ </div>
137
+ )}
138
+ </div>
139
+ </div>
140
+ );
141
+ }
@@ -0,0 +1,91 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, screen, cleanup, fireEvent } from "@testing-library/react";
3
+ import React from "react";
4
+
5
+ const mockAddItem = vi.fn();
6
+ const mockUpdateItem = vi.fn();
7
+ const mockRemoveItem = vi.fn();
8
+ const mockFetchItems = vi.fn();
9
+
10
+ vi.mock("../../../stores/use-todo-store", () => ({
11
+ useTodoStore: (selector: any) =>
12
+ selector({
13
+ items: [
14
+ { id: "1", content: "Buy milk", status: "pending" },
15
+ { id: "2", content: "Write code", status: "completed" },
16
+ ],
17
+ fetchItems: mockFetchItems,
18
+ addItem: mockAddItem,
19
+ updateItem: mockUpdateItem,
20
+ removeItem: mockRemoveItem,
21
+ }),
22
+ }));
23
+
24
+ vi.mock("react-i18next", () => ({
25
+ useTranslation: () => ({ t: (k: string) => k }),
26
+ }));
27
+
28
+ describe("TodoPanel", () => {
29
+ afterEach(() => {
30
+ cleanup();
31
+ vi.clearAllMocks();
32
+ });
33
+
34
+ it("should render todo title", async () => {
35
+ const { TodoPanel } = await import("../TodoPanel");
36
+ render(<TodoPanel />);
37
+ expect(screen.getByText("todo.title")).toBeDefined();
38
+ });
39
+
40
+ it("should render add button", async () => {
41
+ const { TodoPanel } = await import("../TodoPanel");
42
+ render(<TodoPanel />);
43
+ expect(screen.getByText("todo.add")).toBeDefined();
44
+ });
45
+
46
+ it("should display todo items", async () => {
47
+ const { TodoPanel } = await import("../TodoPanel");
48
+ render(<TodoPanel />);
49
+ expect(screen.getByText("Buy milk")).toBeDefined();
50
+ expect(screen.getByText("Write code")).toBeDefined();
51
+ });
52
+
53
+ it("should call fetchItems on mount", async () => {
54
+ const { TodoPanel } = await import("../TodoPanel");
55
+ render(<TodoPanel />);
56
+ expect(mockFetchItems).toHaveBeenCalled();
57
+ });
58
+
59
+ it("should show input when add button is clicked", async () => {
60
+ const { TodoPanel } = await import("../TodoPanel");
61
+ render(<TodoPanel />);
62
+ fireEvent.click(screen.getByText("todo.add"));
63
+ expect(screen.getByPlaceholderText("todo.placeholder")).toBeDefined();
64
+ });
65
+
66
+ it("should call addItem on input submit", async () => {
67
+ const { TodoPanel } = await import("../TodoPanel");
68
+ render(<TodoPanel />);
69
+ fireEvent.click(screen.getByText("todo.add"));
70
+ const input = screen.getByPlaceholderText("todo.placeholder");
71
+ fireEvent.change(input, { target: { value: "New task" } });
72
+ fireEvent.click(screen.getByText("todo.save"));
73
+ expect(mockAddItem).toHaveBeenCalledWith("New task");
74
+ });
75
+
76
+ it("should hide input on Escape", async () => {
77
+ const { TodoPanel } = await import("../TodoPanel");
78
+ render(<TodoPanel />);
79
+ fireEvent.click(screen.getByText("todo.add"));
80
+ const input = screen.getByPlaceholderText("todo.placeholder");
81
+ fireEvent.keyDown(input, { key: "Escape" });
82
+ expect(screen.queryByPlaceholderText("todo.placeholder")).toBeNull();
83
+ });
84
+
85
+ it("should render status indicators for each item", async () => {
86
+ const { TodoPanel } = await import("../TodoPanel");
87
+ const _container = render(<TodoPanel />);
88
+ const statusTexts = screen.getAllByText("todo.status");
89
+ expect(statusTexts.length).toBeGreaterThan(0);
90
+ });
91
+ });
@@ -0,0 +1,13 @@
1
+ declare global {
2
+ interface Window {
3
+ __electrobun?: {
4
+ receiveMessageFromBun: (msg: unknown) => void;
5
+ };
6
+ __electrobunBunBridge?: {
7
+ postMessage: (msg: string) => void;
8
+ };
9
+ /** Desktop IPC receiver: Bun calls this via executeJavascript */
10
+ __piAgentIPC?: (msg: unknown) => void;
11
+ }
12
+ }
13
+ export {};
@@ -0,0 +1,147 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { renderHook, act } from "@testing-library/react";
3
+
4
+ const mockSetBreakpoint = vi.fn();
5
+
6
+ vi.mock("../../stores/use-sidebar-store", () => ({
7
+ useSidebarStore: {
8
+ getState: () => ({
9
+ breakpoint: "desktop",
10
+ _setBreakpoint: mockSetBreakpoint,
11
+ }),
12
+ },
13
+ }));
14
+
15
+ describe("useBreakpointSync", () => {
16
+ let observerCallback: ResizeObserverCallback;
17
+ let mockObserve: ReturnType<typeof vi.fn>;
18
+ let mockDisconnect: ReturnType<typeof vi.fn>;
19
+
20
+ beforeEach(() => {
21
+ vi.resetModules();
22
+ mockSetBreakpoint.mockClear();
23
+
24
+ mockObserve = vi.fn();
25
+ mockDisconnect = vi.fn();
26
+
27
+ class MockResizeObserver {
28
+ constructor(cb: ResizeObserverCallback) {
29
+ observerCallback = cb;
30
+ }
31
+ observe = mockObserve;
32
+ disconnect = mockDisconnect;
33
+ unobserve = vi.fn();
34
+ }
35
+ globalThis.ResizeObserver = MockResizeObserver as any;
36
+ });
37
+
38
+ it("should create ResizeObserver and observe documentElement", async () => {
39
+ const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
40
+ renderHook(() => useBreakpointSync());
41
+ expect(mockObserve).toHaveBeenCalledWith(document.documentElement);
42
+ });
43
+
44
+ it("should set mobile breakpoint for width < 768", async () => {
45
+ const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
46
+ renderHook(() => useBreakpointSync());
47
+
48
+ act(() => {
49
+ observerCallback(
50
+ [
51
+ {
52
+ target: document.documentElement,
53
+ contentRect: { width: 500, height: 800 } as DOMRectReadOnly,
54
+ borderBoxSize: [] as any,
55
+ contentBoxSize: [] as any,
56
+ },
57
+ ],
58
+ {} as ResizeObserver,
59
+ );
60
+ });
61
+
62
+ await new Promise((r) => setTimeout(r, 150));
63
+ expect(mockSetBreakpoint).toHaveBeenCalledWith("mobile");
64
+ });
65
+
66
+ it("should set tablet breakpoint for 768 <= width < 1024", async () => {
67
+ const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
68
+ renderHook(() => useBreakpointSync());
69
+
70
+ act(() => {
71
+ observerCallback(
72
+ [
73
+ {
74
+ target: document.documentElement,
75
+ contentRect: { width: 900, height: 600 } as DOMRectReadOnly,
76
+ borderBoxSize: [] as any,
77
+ contentBoxSize: [] as any,
78
+ },
79
+ ],
80
+ {} as ResizeObserver,
81
+ );
82
+ });
83
+
84
+ await new Promise((r) => setTimeout(r, 150));
85
+ expect(mockSetBreakpoint).toHaveBeenCalledWith("tablet");
86
+ });
87
+
88
+ it("should not call _setBreakpoint if breakpoint unchanged", async () => {
89
+ const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
90
+ renderHook(() => useBreakpointSync());
91
+
92
+ act(() => {
93
+ observerCallback(
94
+ [
95
+ {
96
+ target: document.documentElement,
97
+ contentRect: { width: 1440, height: 900 } as DOMRectReadOnly,
98
+ borderBoxSize: [] as any,
99
+ contentBoxSize: [] as any,
100
+ },
101
+ ],
102
+ {} as ResizeObserver,
103
+ );
104
+ });
105
+
106
+ await new Promise((r) => setTimeout(r, 150));
107
+ expect(mockSetBreakpoint).not.toHaveBeenCalled();
108
+ });
109
+
110
+ it("should set desktop breakpoint when transitioning from mobile", async () => {
111
+ vi.doMock("../../stores/use-sidebar-store", () => ({
112
+ useSidebarStore: {
113
+ getState: () => ({
114
+ breakpoint: "mobile",
115
+ _setBreakpoint: mockSetBreakpoint,
116
+ }),
117
+ },
118
+ }));
119
+
120
+ const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
121
+ renderHook(() => useBreakpointSync());
122
+
123
+ act(() => {
124
+ observerCallback(
125
+ [
126
+ {
127
+ target: document.documentElement,
128
+ contentRect: { width: 1440, height: 900 } as DOMRectReadOnly,
129
+ borderBoxSize: [] as any,
130
+ contentBoxSize: [] as any,
131
+ },
132
+ ],
133
+ {} as ResizeObserver,
134
+ );
135
+ });
136
+
137
+ await new Promise((r) => setTimeout(r, 150));
138
+ expect(mockSetBreakpoint).toHaveBeenCalledWith("desktop");
139
+ });
140
+
141
+ it("should disconnect observer on unmount", async () => {
142
+ const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
143
+ const { unmount } = renderHook(() => useBreakpointSync());
144
+ unmount();
145
+ expect(mockDisconnect).toHaveBeenCalled();
146
+ });
147
+ });
@@ -0,0 +1,34 @@
1
+ import { useEffect } from "react";
2
+ import { useSidebarStore, type Breakpoint } from "../stores/use-sidebar-store";
3
+
4
+ function getBreakpoint(width: number): Breakpoint {
5
+ if (width < 768) return "mobile";
6
+ if (width < 1024) return "tablet";
7
+ return "desktop";
8
+ }
9
+
10
+ /**
11
+ * 单一 ResizeObserver,同步 breakpoint 到 sidebar store。
12
+ * 组件通过 useSidebarStore(s => s.breakpoint) 读取。
13
+ */
14
+ export function useBreakpointSync() {
15
+ useEffect(() => {
16
+ let timer: ReturnType<typeof setTimeout>;
17
+ const obs = new ResizeObserver((entries) => {
18
+ clearTimeout(timer);
19
+ timer = setTimeout(() => {
20
+ for (const entry of entries) {
21
+ const bp = getBreakpoint(entry.contentRect.width);
22
+ if (bp !== useSidebarStore.getState().breakpoint) {
23
+ useSidebarStore.getState()._setBreakpoint(bp);
24
+ }
25
+ }
26
+ }, 100);
27
+ });
28
+ obs.observe(document.documentElement);
29
+ return () => {
30
+ clearTimeout(timer);
31
+ obs.disconnect();
32
+ };
33
+ }, []);
34
+ }
@@ -0,0 +1,84 @@
1
+ import { useState, useCallback, useRef } from "react";
2
+
3
+ const HISTORY_KEY = "pi-input-history";
4
+ const MAX_ITEMS = 10;
5
+
6
+ function getStorageKey(sessionId: string): string {
7
+ return `${HISTORY_KEY}:${sessionId}`;
8
+ }
9
+
10
+ function readHistory(sessionId: string): string[] {
11
+ try {
12
+ const raw = localStorage.getItem(getStorageKey(sessionId));
13
+ if (!raw) return [];
14
+ const parsed = JSON.parse(raw);
15
+ if (Array.isArray(parsed)) return parsed.slice(0, MAX_ITEMS);
16
+ } catch { /* ignore */ }
17
+ return [];
18
+ }
19
+
20
+ function writeHistory(sessionId: string, items: string[]) {
21
+ try {
22
+ localStorage.setItem(getStorageKey(sessionId), JSON.stringify(items.slice(0, MAX_ITEMS)));
23
+ } catch { /* ignore */ }
24
+ }
25
+
26
+ export function useInputHistory(sessionId: string) {
27
+ const historyRef = useRef<string[]>(readHistory(sessionId));
28
+ const indexRef = useRef(-1);
29
+ const [, forceUpdate] = useState(0);
30
+
31
+ const hasPrev = historyRef.current.length > 0 && indexRef.current < historyRef.current.length - 1;
32
+ const hasNext = indexRef.current > 0;
33
+
34
+ const saveToHistory = useCallback((text: string) => {
35
+ const trimmed = text.trim();
36
+ if (!trimmed) return;
37
+ const h = historyRef.current;
38
+ const filtered = h.filter((item) => item !== trimmed);
39
+ const updated = [trimmed, ...filtered].slice(0, MAX_ITEMS);
40
+ historyRef.current = updated;
41
+ writeHistory(sessionId, updated);
42
+ indexRef.current = -1;
43
+ forceUpdate((n) => n + 1);
44
+ }, [sessionId]);
45
+
46
+ const navigatePrev = useCallback((): string | null => {
47
+ const h = historyRef.current;
48
+ if (h.length === 0) return null;
49
+ const nextIdx = Math.min(indexRef.current + 1, h.length - 1);
50
+ indexRef.current = nextIdx;
51
+ forceUpdate((n) => n + 1);
52
+ return h[nextIdx];
53
+ }, []);
54
+
55
+ const navigateNext = useCallback((): string | null => {
56
+ const h = historyRef.current;
57
+ if (h.length === 0) return null;
58
+ const nextIdx = indexRef.current - 1;
59
+ if (nextIdx < 0) {
60
+ indexRef.current = -1;
61
+ forceUpdate((n) => n + 1);
62
+ return "";
63
+ }
64
+ indexRef.current = nextIdx;
65
+ forceUpdate((n) => n + 1);
66
+ return h[nextIdx];
67
+ }, []);
68
+
69
+ const clearHistory = useCallback(() => {
70
+ historyRef.current = [];
71
+ indexRef.current = -1;
72
+ try {
73
+ localStorage.removeItem(getStorageKey(sessionId));
74
+ } catch { /* ignore */ }
75
+ forceUpdate((n) => n + 1);
76
+ }, [sessionId]);
77
+
78
+ const resetIndex = useCallback(() => {
79
+ indexRef.current = -1;
80
+ forceUpdate((n) => n + 1);
81
+ }, []);
82
+
83
+ return { saveToHistory, navigatePrev, navigateNext, clearHistory, resetIndex, hasPrev, hasNext };
84
+ }
@@ -0,0 +1,61 @@
1
+ import { useEffect } from "react";
2
+ import { useConnectionStore } from "../stores/use-connection-store";
3
+ import { useLogStore } from "../stores/use-log-store";
4
+ import { useExplorerStore } from "../stores/use-explorer-store";
5
+ import { useChatStore } from "../stores/use-chat-store";
6
+ import { apiClient } from "../lib/api-client";
7
+
8
+ export function useRpcInit() {
9
+ const ready = useConnectionStore((s) => s.ready);
10
+ const addLog = useLogStore((s) => s.addLog);
11
+ const initializeConnection = useConnectionStore((s) => s.initializeConnection);
12
+ const listRootDir = useExplorerStore((s) => s.listRootDir);
13
+
14
+ useEffect(() => {
15
+ initializeConnection();
16
+ }, [initializeConnection]);
17
+
18
+ useEffect(() => {
19
+ if (!ready) return;
20
+
21
+ let subscriptionId: string | null = null;
22
+
23
+ const setup = async () => {
24
+ listRootDir();
25
+
26
+ subscriptionId = await apiClient.subscribe("chat.message", (payload) => {
27
+ useChatStore.getState().addMessage({
28
+ id: payload.id,
29
+ role: payload.role,
30
+ content: payload.content,
31
+ timestamp: payload.timestamp,
32
+ });
33
+ }, {});
34
+ addLog("Subscribed to chat.message");
35
+
36
+ try {
37
+ const history = await apiClient.call("chat.list", { limit: 100 });
38
+ if (history.messages.length > 0) {
39
+ useChatStore.getState().setMessages(
40
+ history.messages.map((m: { id: string; role: "user" | "assistant"; content: string; timestamp: number }) => ({
41
+ id: m.id,
42
+ role: m.role,
43
+ content: m.content,
44
+ timestamp: m.timestamp,
45
+ }))
46
+ );
47
+ addLog(`Loaded ${history.messages.length} history messages`);
48
+ }
49
+ } catch (err) {
50
+ addLog(`Failed to load history: ${err instanceof Error ? err.message : String(err)}`);
51
+ }
52
+ };
53
+ setup();
54
+
55
+ return () => {
56
+ if (subscriptionId) {
57
+ apiClient.unsubscribe(subscriptionId);
58
+ }
59
+ };
60
+ }, [ready, addLog, listRootDir]);
61
+ }
@@ -0,0 +1,40 @@
1
+ import { useCallback, useRef } from "react";
2
+ import { useSidebarStore } from "../stores/use-sidebar-store";
3
+
4
+ export function useSidebarResize() {
5
+ const sidebarWidth = useSidebarStore((s) => s.sidebarWidth);
6
+ const setSidebarWidth = useSidebarStore((s) => s.setSidebarWidth);
7
+
8
+ const resizingRef = useRef(false);
9
+ const startXRef = useRef(0);
10
+ const startWidthRef = useRef(0);
11
+
12
+ const handleResizeStart = useCallback(
13
+ (e: React.MouseEvent) => {
14
+ e.preventDefault();
15
+ resizingRef.current = true;
16
+ startXRef.current = e.clientX;
17
+ startWidthRef.current = sidebarWidth;
18
+ document.body.style.cursor = "col-resize";
19
+ document.body.style.userSelect = "none";
20
+
21
+ const onMove = (ev: MouseEvent) => {
22
+ if (!resizingRef.current) return;
23
+ const delta = ev.clientX - startXRef.current;
24
+ setSidebarWidth(startWidthRef.current + delta);
25
+ };
26
+ const onUp = () => {
27
+ resizingRef.current = false;
28
+ document.body.style.cursor = "";
29
+ document.body.style.userSelect = "";
30
+ window.removeEventListener("mousemove", onMove);
31
+ window.removeEventListener("mouseup", onUp);
32
+ };
33
+ window.addEventListener("mousemove", onMove);
34
+ window.addEventListener("mouseup", onUp);
35
+ },
36
+ [sidebarWidth, setSidebarWidth]
37
+ );
38
+
39
+ return { sidebarWidth, handleResizeStart };
40
+ }