@dyyz1993/create-agent 2.1.0 → 2.1.2

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 (349) hide show
  1. package/package.json +5 -4
  2. package/src/__tests__/cli.test.ts +2 -0
  3. package/src/__tests__/copy.test.ts +110 -122
  4. package/src/__tests__/create-args.test.ts +113 -0
  5. package/src/__tests__/templates.test.ts +29 -3
  6. package/src/__tests__/update.test.ts +129 -0
  7. package/src/cli.ts +30 -32
  8. package/src/commands/create.ts +83 -24
  9. package/src/commands/update.ts +174 -0
  10. package/src/commands/workspace.ts +26 -6
  11. package/src/lib/copy.ts +233 -93
  12. package/src/lib/templates.ts +12 -0
  13. package/templates/agent/.husky/commit-msg +4 -0
  14. package/templates/agent/.husky/pre-commit +11 -0
  15. package/templates/agent/.husky/pre-push +6 -0
  16. package/templates/agent/.prettierignore +6 -0
  17. package/templates/agent/.prettierrc +9 -0
  18. package/templates/agent/CHANGELOG.md +15 -0
  19. package/templates/agent/commitlint.config.js +8 -0
  20. package/templates/agent/package.json +19 -4
  21. package/templates/agent/src/gateway/__tests__/ws-handler-token.test.ts +53 -39
  22. package/templates/agent/src/mainview/App.tsx +14 -12
  23. package/templates/agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +194 -190
  24. package/templates/agent/src/mainview/components/bash/BashPanel.tsx +210 -189
  25. package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +45 -20
  26. package/templates/agent/src/mainview/components/common/ThemeToggle.tsx +41 -21
  27. package/templates/agent/src/mainview/components/debug/DebugPanel.tsx +181 -114
  28. package/templates/agent/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +80 -80
  29. package/templates/agent/src/mainview/components/diff/__tests__/DiffViewerPanel.test.tsx +61 -58
  30. package/templates/agent/src/mainview/components/feed/FeedPanel.tsx +43 -41
  31. package/templates/agent/src/mainview/components/file-preview/FilePreviewOverlay.tsx +69 -50
  32. package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +31 -18
  33. package/templates/agent/src/mainview/components/git/GitPanel.tsx +731 -490
  34. package/templates/agent/src/mainview/components/git/__tests__/GitPanel.test.tsx +157 -139
  35. package/templates/agent/src/mainview/components/layout/AppLayout.tsx +210 -161
  36. package/templates/agent/src/mainview/components/layout/__tests__/AppLayout.test.tsx +130 -122
  37. package/templates/agent/src/mainview/components/rules/RulesPanel.tsx +119 -109
  38. package/templates/agent/src/mainview/components/search/SearchPanel.tsx +123 -117
  39. package/templates/agent/src/mainview/components/search/__tests__/SearchPanel.test.tsx +64 -44
  40. package/templates/agent/src/mainview/components/sidebar/__tests__/PinButton.test.tsx +38 -38
  41. package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +40 -38
  42. package/templates/agent/src/mainview/components/todo/__tests__/TodoPanel.test.tsx +72 -72
  43. package/templates/agent/src/mainview/lib/i18n/locales/en.json +175 -155
  44. package/templates/agent/src/mainview/lib/i18n/locales/zh.json +173 -155
  45. package/templates/agent/src/mainview/stores/use-app-store.ts +96 -86
  46. package/templates/agent/src/mainview/stores/use-explorer-store.ts +292 -275
  47. package/templates/agent/src/mainview/types/index.ts +23 -22
  48. package/templates/agent/src/mainview/utils/file-icon.tsx +17 -21
  49. package/templates/agent/src/shared/handlers/chat.ts +53 -53
  50. package/templates/agent/src/shared/handlers/debug.ts +13 -3
  51. package/templates/browser-agent/.env.example +19 -0
  52. package/templates/browser-agent/.husky/commit-msg +4 -0
  53. package/templates/browser-agent/.husky/pre-commit +11 -0
  54. package/templates/browser-agent/.husky/pre-push +6 -0
  55. package/templates/browser-agent/.prettierignore +6 -0
  56. package/templates/browser-agent/.prettierrc +9 -0
  57. package/templates/browser-agent/AGENTS.md +396 -0
  58. package/templates/browser-agent/CHANGELOG.md +15 -0
  59. package/templates/browser-agent/LICENSE +21 -0
  60. package/templates/browser-agent/README.md +103 -0
  61. package/templates/browser-agent/commitlint.config.js +8 -0
  62. package/templates/browser-agent/electrobun.config.ts +27 -0
  63. package/templates/browser-agent/electron/main.js +46 -0
  64. package/templates/browser-agent/electron/preload.js +5 -0
  65. package/templates/browser-agent/electron-builder.json +40 -0
  66. package/templates/browser-agent/eslint.config.mjs +79 -0
  67. package/templates/browser-agent/llms.txt +24 -0
  68. package/templates/browser-agent/package.json +140 -0
  69. package/templates/browser-agent/postcss.config.js +6 -0
  70. package/templates/browser-agent/scripts/dev.ts +138 -0
  71. package/templates/browser-agent/src/__tests__/hybrid-mode.test.ts +126 -0
  72. package/templates/browser-agent/src/__tests__/server-config-security.test.ts +55 -0
  73. package/templates/browser-agent/src/__tests__/server-config.test.ts +59 -0
  74. package/templates/browser-agent/src/bun/index.ts +130 -0
  75. package/templates/browser-agent/src/bun/three.d.ts +1 -0
  76. package/templates/browser-agent/src/gateway/http-routes.ts +1 -0
  77. package/templates/browser-agent/src/gateway/ipc-transport.ts +68 -0
  78. package/templates/browser-agent/src/gateway/sse-transport.ts +221 -0
  79. package/templates/browser-agent/src/mainview/App.tsx +45 -0
  80. package/templates/browser-agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
  81. package/templates/browser-agent/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
  82. package/templates/browser-agent/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
  83. package/templates/browser-agent/src/mainview/__tests__/setup.ts +40 -0
  84. package/templates/browser-agent/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
  85. package/templates/browser-agent/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
  86. package/templates/browser-agent/src/mainview/__tests__/theme-variables.test.ts +36 -0
  87. package/templates/browser-agent/src/mainview/components/assets/AssetsPanel.tsx +139 -0
  88. package/templates/browser-agent/src/mainview/components/chat/ChatPanel.tsx +219 -0
  89. package/templates/browser-agent/src/mainview/components/chat/CommandBar.tsx +184 -0
  90. package/templates/browser-agent/src/mainview/components/chat/MessageBubble.tsx +249 -0
  91. package/templates/browser-agent/src/mainview/components/chat/ToolPicker.tsx +115 -0
  92. package/templates/browser-agent/src/mainview/components/common/ErrorBoundary.tsx +1 -0
  93. package/templates/browser-agent/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
  94. package/templates/browser-agent/src/mainview/components/common/ThemeToggle.tsx +45 -0
  95. package/templates/browser-agent/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
  96. package/templates/browser-agent/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
  97. package/templates/browser-agent/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
  98. package/templates/browser-agent/src/mainview/components/dev/NetworkPanel.tsx +155 -0
  99. package/templates/browser-agent/src/mainview/components/layout/AppLayout.tsx +311 -0
  100. package/templates/browser-agent/src/mainview/components/onboarding/SetupWizard.tsx +310 -0
  101. package/templates/browser-agent/src/mainview/components/process/ProcessPanel.tsx +329 -0
  102. package/templates/browser-agent/src/mainview/components/sidebar/SessionSidebar.tsx +122 -0
  103. package/templates/browser-agent/src/mainview/components/sidebar/SkillSidebar.tsx +115 -0
  104. package/templates/browser-agent/src/mainview/components/topbar/TopBar.tsx +350 -0
  105. package/templates/browser-agent/src/mainview/global.d.ts +13 -0
  106. package/templates/browser-agent/src/mainview/hooks/__tests__/use-breakpoint.test.ts +151 -0
  107. package/templates/browser-agent/src/mainview/hooks/use-agent-chat.ts +157 -0
  108. package/templates/browser-agent/src/mainview/hooks/use-breakpoint.ts +68 -0
  109. package/templates/browser-agent/src/mainview/hooks/use-rpc-init.ts +71 -0
  110. package/templates/browser-agent/src/mainview/hooks/use-sidebar-resize.ts +40 -0
  111. package/templates/browser-agent/src/mainview/index.css +71 -0
  112. package/templates/browser-agent/src/mainview/index.html +12 -0
  113. package/templates/browser-agent/src/mainview/lib/api-client.ts +397 -0
  114. package/templates/browser-agent/src/mainview/lib/i18n/index.ts +30 -0
  115. package/templates/browser-agent/src/mainview/lib/i18n/locales/en.json +130 -0
  116. package/templates/browser-agent/src/mainview/lib/i18n/locales/zh.json +128 -0
  117. package/templates/browser-agent/src/mainview/lib/network-bus.ts +92 -0
  118. package/templates/browser-agent/src/mainview/lib/rpc-cache.ts +94 -0
  119. package/templates/browser-agent/src/mainview/main.tsx +18 -0
  120. package/templates/browser-agent/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
  121. package/templates/browser-agent/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
  122. package/templates/browser-agent/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
  123. package/templates/browser-agent/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
  124. package/templates/browser-agent/src/mainview/stores/message-batcher.ts +25 -0
  125. package/templates/browser-agent/src/mainview/stores/use-asset-store.ts +65 -0
  126. package/templates/browser-agent/src/mainview/stores/use-chat-store.ts +200 -0
  127. package/templates/browser-agent/src/mainview/stores/use-connection-store.ts +173 -0
  128. package/templates/browser-agent/src/mainview/stores/use-locale-store.ts +27 -0
  129. package/templates/browser-agent/src/mainview/stores/use-log-store.ts +16 -0
  130. package/templates/browser-agent/src/mainview/stores/use-network-panel-store.ts +18 -0
  131. package/templates/browser-agent/src/mainview/stores/use-record-store.ts +147 -0
  132. package/templates/browser-agent/src/mainview/stores/use-session-store.ts +151 -0
  133. package/templates/browser-agent/src/mainview/stores/use-sidebar-store.ts +161 -0
  134. package/templates/browser-agent/src/mainview/stores/use-theme-store.ts +46 -0
  135. package/templates/browser-agent/src/mainview/stores/use-view-store.ts +20 -0
  136. package/templates/browser-agent/src/mainview/types/index.ts +6 -0
  137. package/templates/browser-agent/src/server-config.ts +45 -0
  138. package/templates/browser-agent/src/server.ts +78 -0
  139. package/templates/browser-agent/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
  140. package/templates/browser-agent/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
  141. package/templates/browser-agent/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
  142. package/templates/browser-agent/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
  143. package/templates/browser-agent/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
  144. package/templates/browser-agent/src/shared/handlers/browser.ts +596 -0
  145. package/templates/browser-agent/src/shared/handlers/chat.ts +213 -0
  146. package/templates/browser-agent/src/shared/handlers/file.ts +99 -0
  147. package/templates/browser-agent/src/shared/handlers/index.ts +7 -0
  148. package/templates/browser-agent/src/shared/handlers/session.ts +167 -0
  149. package/templates/browser-agent/src/shared/handlers/system.ts +27 -0
  150. package/templates/browser-agent/src/shared/handlers/timer.ts +34 -0
  151. package/templates/browser-agent/src/shared/http-routes.ts +437 -0
  152. package/templates/browser-agent/src/shared/lib/__tests__/logger.test.ts +92 -0
  153. package/templates/browser-agent/src/shared/lib/__tests__/path-security.test.ts +77 -0
  154. package/templates/browser-agent/src/shared/lib/__tests__/web-server.test.ts +203 -0
  155. package/templates/browser-agent/src/shared/lib/agent.ts +384 -0
  156. package/templates/browser-agent/src/shared/lib/cdp.ts +448 -0
  157. package/templates/browser-agent/src/shared/lib/generate.ts +111 -0
  158. package/templates/browser-agent/src/shared/lib/logger.ts +152 -0
  159. package/templates/browser-agent/src/shared/lib/mock-stream.ts +147 -0
  160. package/templates/browser-agent/src/shared/lib/path-security.ts +38 -0
  161. package/templates/browser-agent/src/shared/lib/port-registry.ts +103 -0
  162. package/templates/browser-agent/src/shared/lib/web-server.ts +127 -0
  163. package/templates/browser-agent/src/shared/lib/xhs-extract.ts +71 -0
  164. package/templates/browser-agent/src/shared/modules/browser.ts +86 -0
  165. package/templates/browser-agent/src/shared/modules/chat.ts +20 -0
  166. package/templates/browser-agent/src/shared/modules/file.ts +40 -0
  167. package/templates/browser-agent/src/shared/modules/session.ts +55 -0
  168. package/templates/browser-agent/src/shared/modules/system.ts +8 -0
  169. package/templates/browser-agent/src/shared/modules/timer.ts +11 -0
  170. package/templates/browser-agent/src/shared/register-all-handlers.ts +36 -0
  171. package/templates/browser-agent/src/shared/rpc-schema.ts +34 -0
  172. package/templates/browser-agent/tailwind.config.js +15 -0
  173. package/templates/browser-agent/tsconfig.ipc.json +14 -0
  174. package/templates/browser-agent/tsconfig.json +36 -0
  175. package/templates/browser-agent/vite.config.ts +3 -0
  176. package/templates/browser-agent/vitest.config.ts +3 -0
  177. package/templates/chat/.husky/commit-msg +4 -0
  178. package/templates/chat/.husky/pre-commit +11 -0
  179. package/templates/chat/.husky/pre-push +6 -0
  180. package/templates/chat/CHANGELOG.md +15 -0
  181. package/templates/chat/commitlint.config.js +8 -0
  182. package/templates/chat/package.json +19 -4
  183. package/templates/chat/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
  184. package/templates/chat/src/mainview/__tests__/setup.ts +32 -29
  185. package/templates/chat/src/mainview/components/chat/ChatPanel.tsx +80 -55
  186. package/templates/chat/src/mainview/components/common/ThemeToggle.tsx +40 -20
  187. package/templates/chat/src/mainview/lib/i18n/locales/en.json +175 -155
  188. package/templates/chat/src/mainview/lib/i18n/locales/zh.json +173 -155
  189. package/templates/chat/src/shared/handlers/chat.ts +17 -19
  190. package/templates/chat/src/shared/handlers/debug.ts +12 -2
  191. package/templates/cowork/.env.example +8 -0
  192. package/templates/cowork/.prettierignore +6 -0
  193. package/templates/cowork/.prettierrc +9 -0
  194. package/templates/cowork/AGENTS.md +236 -0
  195. package/templates/cowork/CHANGELOG.md +15 -0
  196. package/templates/cowork/LICENSE +21 -0
  197. package/templates/cowork/README.md +103 -0
  198. package/templates/cowork/commitlint.config.js +8 -0
  199. package/templates/cowork/docs/CODE-VIEW-PLAN.md +637 -0
  200. package/templates/cowork/docs/CODE-VIEW-V2.md +196 -0
  201. package/templates/cowork/docs/CODE-VIEW-V4.md +150 -0
  202. package/templates/cowork/electrobun.config.ts +27 -0
  203. package/templates/cowork/eslint.config.mjs +79 -0
  204. package/templates/cowork/llms.txt +24 -0
  205. package/templates/cowork/package.json +87 -0
  206. package/templates/cowork/postcss.config.js +6 -0
  207. package/templates/cowork/scripts/dev.ts +138 -0
  208. package/templates/cowork/src/__tests__/hybrid-mode.test.ts +126 -0
  209. package/templates/cowork/src/__tests__/server-config-security.test.ts +55 -0
  210. package/templates/cowork/src/__tests__/server-config.test.ts +59 -0
  211. package/templates/cowork/src/bun/index.ts +130 -0
  212. package/templates/cowork/src/bun/three.d.ts +1 -0
  213. package/templates/cowork/src/gateway/http-routes.ts +1 -0
  214. package/templates/cowork/src/gateway/ipc-transport.ts +68 -0
  215. package/templates/cowork/src/gateway/sse-transport.ts +231 -0
  216. package/templates/cowork/src/mainview/App.tsx +45 -0
  217. package/templates/cowork/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
  218. package/templates/cowork/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
  219. package/templates/cowork/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
  220. package/templates/cowork/src/mainview/__tests__/setup.ts +40 -0
  221. package/templates/cowork/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
  222. package/templates/cowork/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
  223. package/templates/cowork/src/mainview/__tests__/theme-variables.test.ts +36 -0
  224. package/templates/cowork/src/mainview/components/chat/TaskChat.tsx +311 -0
  225. package/templates/cowork/src/mainview/components/chat/__tests__/localhost-links.test.ts +76 -0
  226. package/templates/cowork/src/mainview/components/common/ErrorBoundary.tsx +1 -0
  227. package/templates/cowork/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
  228. package/templates/cowork/src/mainview/components/common/ThemeToggle.tsx +45 -0
  229. package/templates/cowork/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
  230. package/templates/cowork/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
  231. package/templates/cowork/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
  232. package/templates/cowork/src/mainview/components/dev/NetworkPanel.tsx +155 -0
  233. package/templates/cowork/src/mainview/components/layout/AppLayout.tsx +216 -0
  234. package/templates/cowork/src/mainview/components/right/ArtifactsPanel.tsx +54 -0
  235. package/templates/cowork/src/mainview/components/right/ContextPanel.tsx +133 -0
  236. package/templates/cowork/src/mainview/components/right/ElementPicker.tsx +206 -0
  237. package/templates/cowork/src/mainview/components/right/PreviewBlock.tsx +155 -0
  238. package/templates/cowork/src/mainview/components/right/ProgressPanel.tsx +85 -0
  239. package/templates/cowork/src/mainview/components/sidebar/TaskSidebar.tsx +211 -0
  240. package/templates/cowork/src/mainview/components/topbar/TopBar.tsx +86 -0
  241. package/templates/cowork/src/mainview/global.d.ts +13 -0
  242. package/templates/cowork/src/mainview/hooks/__tests__/use-breakpoint.test.ts +123 -0
  243. package/templates/cowork/src/mainview/hooks/use-breakpoint.ts +53 -0
  244. package/templates/cowork/src/mainview/hooks/use-rpc-init.ts +26 -0
  245. package/templates/cowork/src/mainview/hooks/use-sidebar-resize.ts +40 -0
  246. package/templates/cowork/src/mainview/index.css +89 -0
  247. package/templates/cowork/src/mainview/index.html +12 -0
  248. package/templates/cowork/src/mainview/lib/api-client.ts +404 -0
  249. package/templates/cowork/src/mainview/lib/i18n/index.ts +30 -0
  250. package/templates/cowork/src/mainview/lib/i18n/locales/en.json +130 -0
  251. package/templates/cowork/src/mainview/lib/i18n/locales/zh.json +128 -0
  252. package/templates/cowork/src/mainview/lib/network-bus.ts +92 -0
  253. package/templates/cowork/src/mainview/lib/rpc-cache.ts +94 -0
  254. package/templates/cowork/src/mainview/main.tsx +18 -0
  255. package/templates/cowork/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
  256. package/templates/cowork/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
  257. package/templates/cowork/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
  258. package/templates/cowork/src/mainview/stores/__tests__/use-preview-store.test.ts +193 -0
  259. package/templates/cowork/src/mainview/stores/__tests__/use-sidebar-store.test.ts +81 -0
  260. package/templates/cowork/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
  261. package/templates/cowork/src/mainview/stores/message-batcher.ts +25 -0
  262. package/templates/cowork/src/mainview/stores/use-chat-store.ts +198 -0
  263. package/templates/cowork/src/mainview/stores/use-connection-store.ts +168 -0
  264. package/templates/cowork/src/mainview/stores/use-context-store.ts +68 -0
  265. package/templates/cowork/src/mainview/stores/use-locale-store.ts +27 -0
  266. package/templates/cowork/src/mainview/stores/use-log-store.ts +16 -0
  267. package/templates/cowork/src/mainview/stores/use-network-panel-store.ts +18 -0
  268. package/templates/cowork/src/mainview/stores/use-output-store.ts +47 -0
  269. package/templates/cowork/src/mainview/stores/use-preview-store.ts +97 -0
  270. package/templates/cowork/src/mainview/stores/use-sidebar-store.ts +272 -0
  271. package/templates/cowork/src/mainview/stores/use-task-store.ts +86 -0
  272. package/templates/cowork/src/mainview/stores/use-theme-store.ts +46 -0
  273. package/templates/cowork/src/mainview/stores/use-view-store.ts +29 -0
  274. package/templates/cowork/src/mainview/types/index.ts +6 -0
  275. package/templates/cowork/src/server-config.ts +44 -0
  276. package/templates/cowork/src/server.ts +78 -0
  277. package/templates/cowork/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
  278. package/templates/cowork/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
  279. package/templates/cowork/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
  280. package/templates/cowork/src/shared/handlers/__tests__/preview-handler.test.ts +172 -0
  281. package/templates/cowork/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
  282. package/templates/cowork/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
  283. package/templates/cowork/src/shared/handlers/chat.ts +213 -0
  284. package/templates/cowork/src/shared/handlers/context.ts +72 -0
  285. package/templates/cowork/src/shared/handlers/file.ts +99 -0
  286. package/templates/cowork/src/shared/handlers/index.ts +9 -0
  287. package/templates/cowork/src/shared/handlers/output.ts +59 -0
  288. package/templates/cowork/src/shared/handlers/preview.ts +81 -0
  289. package/templates/cowork/src/shared/handlers/system.ts +27 -0
  290. package/templates/cowork/src/shared/handlers/task.ts +101 -0
  291. package/templates/cowork/src/shared/handlers/timer.ts +34 -0
  292. package/templates/cowork/src/shared/http-routes.ts +444 -0
  293. package/templates/cowork/src/shared/lib/__tests__/logger.test.ts +92 -0
  294. package/templates/cowork/src/shared/lib/__tests__/path-security.test.ts +77 -0
  295. package/templates/cowork/src/shared/lib/__tests__/web-server.test.ts +203 -0
  296. package/templates/cowork/src/shared/lib/logger.ts +152 -0
  297. package/templates/cowork/src/shared/lib/path-security.ts +38 -0
  298. package/templates/cowork/src/shared/lib/port-registry.ts +103 -0
  299. package/templates/cowork/src/shared/lib/web-server.ts +127 -0
  300. package/templates/cowork/src/shared/modules/chat.ts +20 -0
  301. package/templates/cowork/src/shared/modules/context.ts +32 -0
  302. package/templates/cowork/src/shared/modules/file.ts +40 -0
  303. package/templates/cowork/src/shared/modules/output.ts +20 -0
  304. package/templates/cowork/src/shared/modules/preview.ts +44 -0
  305. package/templates/cowork/src/shared/modules/system.ts +8 -0
  306. package/templates/cowork/src/shared/modules/task.ts +31 -0
  307. package/templates/cowork/src/shared/modules/timer.ts +11 -0
  308. package/templates/cowork/src/shared/register-all-handlers.ts +36 -0
  309. package/templates/cowork/src/shared/rpc-schema.ts +38 -0
  310. package/templates/cowork/tailwind.config.js +15 -0
  311. package/templates/cowork/test-upload.txt +0 -0
  312. package/templates/cowork/tsconfig.ipc.json +14 -0
  313. package/templates/cowork/tsconfig.json +36 -0
  314. package/templates/cowork/vite.config.ts +3 -0
  315. package/templates/cowork/vitest.config.ts +3 -0
  316. package/templates/general/.husky/commit-msg +4 -0
  317. package/templates/general/.husky/pre-commit +11 -0
  318. package/templates/general/.husky/pre-push +6 -0
  319. package/templates/general/CHANGELOG.md +15 -0
  320. package/templates/general/commitlint.config.js +8 -0
  321. package/templates/general/package.json +19 -4
  322. package/templates/general/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
  323. package/templates/general/src/mainview/__tests__/setup.ts +32 -29
  324. package/templates/general/src/mainview/components/chat/ChatPanel.tsx +80 -55
  325. package/templates/general/src/mainview/components/common/ThemeToggle.tsx +40 -20
  326. package/templates/general/src/mainview/components/debug/DebugPanel.tsx +170 -156
  327. package/templates/general/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +169 -0
  328. package/templates/general/src/mainview/components/explorer/ConfirmDialog.tsx +42 -42
  329. package/templates/general/src/mainview/components/explorer/ContextMenu.tsx +72 -67
  330. package/templates/general/src/mainview/components/feed/FeedPanel.tsx +7 -5
  331. package/templates/general/src/mainview/components/file-preview/FilePreviewOverlay.tsx +64 -45
  332. package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +24 -7
  333. package/templates/general/src/mainview/components/git/GitPanel.tsx +700 -473
  334. package/templates/general/src/mainview/components/layout/AppLayout.tsx +123 -114
  335. package/templates/general/src/mainview/components/search/SearchPanel.tsx +15 -19
  336. package/templates/general/src/mainview/lib/i18n/locales/en.json +175 -155
  337. package/templates/general/src/mainview/lib/i18n/locales/zh.json +173 -155
  338. package/templates/general/src/mainview/stores/__tests__/use-explorer-store.test.ts +259 -0
  339. package/templates/general/src/mainview/stores/__tests__/use-feed-store.test.ts +160 -0
  340. package/templates/general/src/mainview/stores/__tests__/use-git-store.test.ts +313 -0
  341. package/templates/general/src/mainview/stores/__tests__/use-notification-store.test.ts +115 -0
  342. package/templates/general/src/mainview/stores/__tests__/use-sidebar-store.test.ts +120 -0
  343. package/templates/general/src/mainview/stores/use-explorer-store.ts +277 -260
  344. package/templates/general/src/mainview/types/index.ts +21 -20
  345. package/templates/general/src/shared/handlers/chat.ts +1 -1
  346. package/templates/general/src/shared/handlers/debug.ts +12 -2
  347. package/templates/shared/components/ErrorBoundary.tsx +0 -1
  348. package/templates/shared/vite-base.config.ts +8 -7
  349. /package/templates/{shared → browser-agent}/test-upload.txt +0 -0
@@ -0,0 +1,396 @@
1
+ # Browser Agent — 系统指令
2
+
3
+ > 本文件既是 **Agent 的系统提示词**,也是 **项目规范文档**。
4
+ > 新增重要功能或需求时,请在「功能大纲」章节以大纲形式记录。
5
+
6
+ ---
7
+
8
+ ## 你的身份
9
+
10
+ 你是「Browser Agent」——一个浏览器自动化工作台助手。你运行在 **Web 模式**(非桌面端),通过 **xbrowser** 工具控制用户的真实 Chrome 浏览器。
11
+
12
+ 你的核心能力:打开网页、采集数据、搜索、点击、填写、截图、录制操作、加工录制为技能。
13
+
14
+ ## 核心工具
15
+
16
+ | 场景 | 命令 |
17
+ | ------------------- | ---------------------------- |
18
+ | 打开网页 | `goto <url>` |
19
+ | 页面标题 | `title` |
20
+ | 当前 URL | `url` |
21
+ | 页面文本 | `text` |
22
+ | 截图 | `screenshot` |
23
+ | 执行 JS | `eval "<expression>"` |
24
+ | 点击元素 | `click <selector>` |
25
+ | 输入内容 | `fill <selector> <value>` |
26
+ | 滚动 | `scroll down --distance 800` |
27
+ | 列出标签页 | `tab list` |
28
+ | 页面快照(带 ref) | `snapshot` |
29
+ | 采集页面转 Markdown | `scrape <url>` |
30
+ | 爬取网站 | `crawl <url> --limit N` |
31
+ | 搜索引擎 | `search "<query>"` |
32
+ | 发现网站 URL | `map <url>` |
33
+ | 列出插件 | `plugin list` |
34
+ | 插件详情 | `plugin info <name>` |
35
+
36
+ ## 录制能力
37
+
38
+ 用户可以通过顶栏录制按钮录制浏览器操作。录制的操作可以被你加工分析:
39
+
40
+ - 提取关键步骤(去掉无意义的滚动/悬停)
41
+ - 总结操作意图(一句话描述)
42
+ - 建议技能名称
43
+ - 参数化建议(哪些步骤可替换为变量)
44
+
45
+ ## 禁止操作 ❌
46
+
47
+ **Web 环境下绝对不允许:**
48
+
49
+ 1. 禁止 `open` 命令(桌面端打开文件/程序)
50
+ 2. 禁止 `xdg-open`、`start`、`explorer` 等系统命令
51
+ 3. 禁止本地文件操作(`mkdir`、`cp`、`mv`、`rm`、`chmod`)
52
+ 4. 禁止安装/卸载软件(`brew install`、`pip install`)
53
+ 5. 禁止修改系统配置
54
+
55
+ ## 渲染规则 📋
56
+
57
+ 涉及文件/路径/URL 时,**直接渲染给用户**,不执行打开:
58
+
59
+ | 类型 | 方式 |
60
+ | -------- | ---------------------------- |
61
+ | 文件路径 | `📄 /path/to/file` |
62
+ | URL | `[打开](https://...)` |
63
+ | 下载结果 | `✅ 已保存 file.csv (2.3MB)` |
64
+ | 数据表格 | Markdown 表格 |
65
+ | 截图 | 直接显示 |
66
+
67
+ ## 操作流程
68
+
69
+ 1. **先观察**:`title`、`url`、`snapshot` 了解页面状态
70
+ 2. **再操作**:`goto`、`click`、`fill` 改变页面
71
+ 3. **后验证**:确认结果
72
+ 4. **渲染结果**:清晰展示给用户
73
+
74
+ ## 工作原则
75
+
76
+ 1. 多步操作逐个执行,每步有反馈
77
+ 2. 遇到失败先诊断,不盲目重试
78
+ 3. 结果简洁,用表格/列表/代码块
79
+ 4. 中文交互
80
+ 5. 涉及文件只展示不执行
81
+
82
+ ---
83
+
84
+ # 项目规范文档
85
+
86
+ > 以下内容供开发者(含 AI 助手)参考。新增功能或需求时,在「功能大纲」记录。
87
+
88
+ ## 技术架构
89
+
90
+ ```
91
+ 浏览器前端 (React + Vite, :7200)
92
+ ├─ SSE EventSource ← /api/events (服务端推送)
93
+ ├─ HTTP POST → /api/rpc (RPC 请求)
94
+ └─ HTTP → /api/create-browser, /api/pack-extension (扩展安装)
95
+
96
+ 后端服务器 (Bun + Node HTTP, :5200)
97
+ ├─ SSE Transport (每客户端独立 RPCServer)
98
+ ├─ Handlers: browser / session / chat / system / timer / file
99
+ └─ xbrowser CLI (spawn 子进程, --cdp :9221)
100
+
101
+ 用户浏览器
102
+ └─ Chrome 扩展 → cdp-tunnel (:9221) → CDP 协议
103
+ ```
104
+
105
+ ### 当前定位
106
+
107
+ `/tmp/ba-demo` 是从 `pi-agent-template/templates/browser-agent` 生成出来的标准样例,优先作为 Browser Agent 的迁移沙盒和验收基线。
108
+
109
+ 不要继续以 `study-web/browser-agent-product` 里的手写静态页面作为主线 UI。该项目里已经验证过的 Web 多用户能力可以迁移进本模板体系,但 UI、RPC schema、录制、加工、会话、资源面板应以本项目结构为准。
110
+
111
+ ### 迁移策略
112
+
113
+ 目标顺序:
114
+
115
+ 1. 先在 `/tmp/ba-demo` 跑通标准模板能力。
116
+ 2. 把 `browser-agent-product` 中有价值的 Web gateway / 插件接入能力迁移进本项目。
117
+ 3. 本项目跑通后,再清理正式项目目录,把模板体系迁回正式目录。
118
+ 4. 不做双向搬运;模板/RPC Core 体系是主线,手写 Web 原型只是能力来源。
119
+
120
+ 从 `browser-agent-product` 迁移过来的能力只允许进入 adapter 或 server 层:
121
+
122
+ - 创建连接 Key。
123
+ - 插件下载时内置 gateway URL 和 key。
124
+ - 检测插件连接状态。
125
+ - Web 多用户 browser/session/connection 绑定。
126
+ - Cloud browser runtime / gateway 适配。
127
+ - 录制 start/status/stop 的云端 adapter。
128
+
129
+ 不要迁移以下内容作为主线:
130
+
131
+ - 手写 `web-app/public/app` UI。
132
+ - 绕过 RPC Core 的前端 API 调用模型。
133
+ - 固定 `localhost:9221` 的单用户假设。
134
+ - 与 React/Vite/Zustand/RPC schema 重复的临时状态管理。
135
+
136
+ ### Web / Desktop 双端分层
137
+
138
+ 本项目最终要同时服务 Web 多用户版和桌面单机版。上层业务必须共用,差异只能沉到 transport/runtime 层。
139
+
140
+ ```
141
+ React Workbench
142
+ -> RPC Client
143
+ -> RPC Handlers
144
+ -> Browser Service
145
+ -> BrowserRuntime Adapter
146
+ -> CloudBrowserRuntime -> Remote Gateway -> Chrome Extension
147
+ -> LocalBrowserRuntime -> Local Proxy -> Chrome Extension
148
+ ```
149
+
150
+ 共用层:
151
+
152
+ - `src/shared/modules/*`:RPC 方法和事件类型。
153
+ - `src/shared/handlers/*`:业务 handler,尽量不直接写 Web/Desktop 分支。
154
+ - `src/mainview/*`:工作台 UI、会话、录制、加工、资产、技能库。
155
+ - `recorder-core`:录制事件清洗、归一化、参数化、workflow/skill 生成。
156
+ - `workflow-engine`:录制回放、步骤状态、失败恢复。
157
+ - `event-stream`:统一的流式事件模型。
158
+
159
+ Web 专属层:
160
+
161
+ - Remote browser gateway。
162
+ - 用户 key/token 绑定。
163
+ - 多用户浏览器连接隔离。
164
+ - SaaS 登录、团队、计费、云存储。
165
+ - Server-side worker / queue / sandbox。
166
+
167
+ Desktop 专属层:
168
+
169
+ - 本地 proxy。
170
+ - `localhost` 插件连接。
171
+ - IPC / Electrobun bridge。
172
+ - 托盘、开机启动、后台常驻。
173
+ - 本地定时任务。
174
+ - 本地 SQLite / 文件系统存储。
175
+
176
+ ### 插件接入模型
177
+
178
+ Web 端不能把 `CLOUD_PROXY_URL` 当成单个用户浏览器地址。它只是公共 gateway。
179
+
180
+ Web 首期采用专属扩展包:
181
+
182
+ 1. 用户打开 Web 工作台。
183
+ 2. 服务端生成 `browserKey`。
184
+ 3. 下载时把 `wss://<gateway>/plugin?key=<browserKey>` 写入扩展包。
185
+ 4. 用户安装扩展。
186
+ 5. 扩展连接 gateway。
187
+ 6. Gateway 校验 key,并绑定 `userId -> browserId -> connectionId`。
188
+ 7. UI 通过 RPC 获取连接状态。
189
+
190
+ 后续再升级为公共扩展:
191
+
192
+ - 用户安装统一扩展。
193
+ - 在扩展内输入激活码或登录。
194
+ - 服务端完成浏览器绑定。
195
+
196
+ Desktop 端采用本地连接:
197
+
198
+ - 桌面 App 启动本地 proxy。
199
+ - 扩展默认连接 `ws://localhost:<port>/plugin`。
200
+ - 不依赖云端也能录制、加工、回放。
201
+
202
+ ### 录制到加工到技能
203
+
204
+ 录制不是最终产物。录制停止后必须进入加工流程:
205
+
206
+ ```
207
+ Raw Recording
208
+ -> Normalize
209
+ -> Clean / Deduplicate
210
+ -> Stabilize Selectors
211
+ -> Parameterize Inputs
212
+ -> Workflow
213
+ -> Recorded Skill
214
+ ```
215
+
216
+ 当前已有:
217
+
218
+ - 顶栏录制按钮。
219
+ - `browser.recordStart` / `browser.recordStatus` / `browser.recordStop`。
220
+ - 「加工」Tab。
221
+ - `browser.processRecording`。
222
+
223
+ 下一步要补齐:
224
+
225
+ - 录制结果保存。
226
+ - Workflow 结构化输出。
227
+ - 一键 replay。
228
+ - 加工结果保存为 Skill。
229
+ - Skill 出现在侧栏技能库。
230
+
231
+ ### 运行隔离与沙盒
232
+
233
+ MVP 可以先进程内执行任务,但接口必须按可替换 worker 设计。
234
+
235
+ Web 多用户运行隔离:
236
+
237
+ - 每次执行都有 `runId`。
238
+ - 每个 run 绑定 `userId/sessionId/browserId/connectionId`。
239
+ - 命令必须路由到该用户自己的浏览器连接。
240
+ - 事件必须只推送给对应 session/client。
241
+ - 后续可替换为 worker pool、child process、container 或 remote sandbox。
242
+
243
+ Desktop 单机运行隔离:
244
+
245
+ - 默认本机单用户。
246
+ - 任务可在本地后台队列中执行。
247
+ - 定时任务只属于桌面端,不进入 Web MVP。
248
+ - 本地执行仍需保留 `runId`、日志、取消、失败恢复。
249
+
250
+ ### 通讯架构(SSE + HTTP)
251
+
252
+ - **POST /api/rpc** — RPC 请求/响应(session.create, browser.agentChat 等)
253
+ - **GET /api/events** — SSE 流(Agent 流式事件:thinking/textDelta/toolCall/done)
254
+ - **Token 认证** — URL query `?token=`(EventSource 不支持自定义 header)
255
+
256
+ ### 响应式面板
257
+
258
+ | 断点 | 侧栏 | 资源面板 |
259
+ | --------------------- | -------- | -------- |
260
+ | wide ≥1280px | 固定展开 | 固定展开 |
261
+ | desktop 1024-1279px | 固定展开 | 抽屉 |
262
+ | tablet/mobile <1024px | 抽屉 | 抽屉 |
263
+
264
+ ## RPC 方法清单
265
+
266
+ ### Browser 模块
267
+
268
+ - `browser.checkConnection` — 检测 Chrome 连接状态
269
+ - `browser.getConnectionGuide` — 用户视角连接状态(不暴露技术细节)
270
+ - `browser.listTabs` — Chrome 标签页列表
271
+ - `browser.listPlugins` — xbrowser 插件列表
272
+ - `browser.execXbrowser` — 执行单个 xbrowser 命令(支持 --tab 注入)
273
+ - `browser.agentChat` — Agent 对话(流式事件推送)
274
+ - `browser.recordStart` — 开始录制
275
+ - `browser.recordStop` — 停止录制,返回操作数据
276
+ - `browser.recordStatus` — 查询录制状态
277
+ - `browser.processRecording` — Agent 加工录制数据(流式)
278
+ - `browser.getSystemInfo` — 系统信息
279
+
280
+ ### Session 模块
281
+
282
+ - `session.create` / `session.list` / `session.get` — 会话 CRUD
283
+ - `session.addMessage` / `session.updateLastMessage` — 消息管理
284
+ - `session.setStatus` / `session.disposeAgent` — 状态控制
285
+
286
+ ### 其他模块
287
+
288
+ - `chat.list` / `chat.send` — 聊天历史
289
+ - `system.ping` / `system.hello` / `system.echo` — 系统测试
290
+ - `timer.start` / `timer.stop` — 计时器
291
+ - `file.*` — 文件操作
292
+
293
+ ## 流式事件
294
+
295
+ Agent 执行时通过 SSE 推送以下事件:
296
+
297
+ | 事件 | 作用 |
298
+ | -------------------- | -------------------------- |
299
+ | `browser.agentStart` | Agent 开始(含 messageId) |
300
+ | `browser.toolCall` | 工具调用开始 |
301
+ | `browser.toolResult` | 工具调用结果 |
302
+ | `browser.thinking` | 思考增量 |
303
+ | `browser.textDelta` | 文本增量 |
304
+ | `browser.turn` | 轮次切换 |
305
+ | `browser.done` | 完成(含最终文本) |
306
+ | `browser.progress` | 采集进度 |
307
+
308
+ > ⚠️ **messageId 规则**:后端生成 `msg_${Date.now().toString(36)}`,前端必须等 `browser.agentStart` 事件获取真实 messageId,不能自己生成。
309
+
310
+ ## 功能大纲
311
+
312
+ ### ✅ 已完成
313
+
314
+ - [x] **三栏工作台**:侧栏(技能+会话) | 对话区(Tab切换) | 资源面板
315
+ - [x] **响应式布局**:宽屏展开 / 中屏侧栏+资源抽屉 / 窄屏全抽屉
316
+ - [x] **SSE + HTTP 通讯**:替换 WebSocket,支持 token 认证和自动重连
317
+ - [x] **Agent 流式对话**:browser.agentChat + 6 个流式事件
318
+ - [x] **直接命令栏**:xbrowser> 提示符,直接执行 scrape/crawl/map 等
319
+ - [x] **标签页选择器**:TopBar 下拉,自动注入 --tab 参数
320
+ - [x] **连接引导**:顶栏状态指示器 + 安装扩展向导 Modal
321
+ - [x] **默认空会话**:打开就有空会话,可直接输入
322
+ - [x] **智能新建会话**:空会话复用,不重复创建
323
+ - [x] **录制功能**:顶栏录制按钮 + recordStart/Stop/Status
324
+ - [x] **加工 Tab**:录制摘要 + 操作时间线 + Agent 加工分析
325
+ - [x] **网络通讯面板**:底部抽屉实时展示 RPC 请求/SSE 事件
326
+ - [x] **命令拦截**:Web 模式禁止 open 等桌面命令
327
+ - [x] **AGENTS.md 约束**:提示词限制 + 渲染规则
328
+
329
+ ### 🔲 待实现
330
+
331
+ - [ ] **Web gateway adapter**:迁移 browser-agent-product 的 key 生成、扩展打包、连接检测
332
+ - [ ] **技能保存**:加工完成后保存为可复用技能(侧栏技能库)
333
+ - [ ] **录制重放**:replay 命令支持,一键重放录制操作
334
+ - [ ] **会话持久化**:内存 SessionStore → SQLite
335
+ - [ ] **采集资源管理**:CSV/JSON/图片下载和预览
336
+ - [ ] **多语言完善**:i18n 全量覆盖
337
+ - [ ] **插件系统增强**:用户选中的插件影响 Agent 行为
338
+ - [ ] **桌面端(Electrobun)**:IPC 模式适配
339
+
340
+ ### 📋 需求记录
341
+
342
+ > 重要需求和设计决策记录在此,方便后续追溯。
343
+
344
+ #### 2026-06-26 禁止桌面命令
345
+
346
+ Web 模式下 `open`/`xdg-open`/`mkdir` 等命令无意义且危险。通过 AGENTS.md 提示词约束 + 后端 `BLOCKED_XBROWSER_COMMANDS` 双重拦截。录制相关命令(record/replay/convert/extract)已解禁。
347
+
348
+ #### 2026-06-26 录制与加工分离
349
+
350
+ 录制和会话是两种心智模型(录制=我做给 Agent 看,会话=我问 Agent 做),不能混在一起。加工过程独立展示在「⚙️ 加工」Tab。
351
+
352
+ #### 2026-06-26 SSE 替代 WebSocket
353
+
354
+ WebSocket 通讯对用户不可见、调试困难。改为 HTTP POST + SSE 后,DevTools Network 可直接看到请求,且加了网络通讯面板可视化。
355
+
356
+ #### 2026-06-26 默认空会话
357
+
358
+ 打开页面就有空会话占位,用户可直接输入。加号按钮智能创建——当前空会话没消息时不重复创建。
359
+
360
+ #### 2026-06-26 模板体系作为主线
361
+
362
+ `/tmp/ba-demo` 和 `pi-agent-template/templates/browser-agent` 是标准基线。`study-web/browser-agent-product` 中的手写 Web UI 不再作为主线继续演进,只迁移其中已经验证过的 Web gateway、插件专属包、连接检测和 Cloud runtime adapter 能力。
363
+
364
+ ## 开发规范
365
+
366
+ ### 端口
367
+
368
+ - 后端:5200
369
+ - 前端(Vite):7200
370
+ - cdp-tunnel:9221
371
+
372
+ ### 环境变量
373
+
374
+ ```
375
+ PORT=5200
376
+ VITE_PORT=7200
377
+ AUTH_TOKEN=dev-token
378
+ VITE_AUTH_TOKEN=dev-token
379
+ CDP_ENDPOINT=http://localhost:9221
380
+ CORS_ORIGIN=http://localhost:7200
381
+ CDP_TUNNEL_EXT=/path/to/cdp-tunnel2/extension-new
382
+ ```
383
+
384
+ ### 新增功能时的检查清单
385
+
386
+ 1. 在 `src/shared/modules/*.ts` 定义 RPC 类型
387
+ 2. 在 `src/shared/handlers/*.ts` 实现 handler
388
+ 3. 在 `src/shared/handlers/index.ts` 注册 barrel export
389
+ 4. 在 `src/shared/rpc-schema.ts` 合并类型
390
+ 5. 前端 store + 组件实现
391
+ 6. 在本文件「功能大纲」记录
392
+ 7. `tsc --noEmit` 零错误 + `vitest run` 全过
393
+
394
+ ---
395
+
396
+ > 📌 **文档维护规则**:当你(AI 助手)觉得某个东西比较重要,或有新增功能/需求变更时,请用大纲形式更新本文件的「功能大纲」和「需求记录」章节。
@@ -0,0 +1,15 @@
1
+ # browser-agent-app
2
+
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`29d2171`](https://github.com/dyyz1993/pi-agent-template/commit/29d217148f6e0b496cc06716e11847b3e522e266)]:
8
+ - @dyyz1993/rpc-core@2.2.1
9
+
10
+ ## 1.0.1
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [[`29d2171`](https://github.com/dyyz1993/pi-agent-template/commit/29d217148f6e0b496cc06716e11847b3e522e266), [`724470a`](https://github.com/dyyz1993/pi-agent-template/commit/724470a784b48a66591e06299fab8ad72f023962)]:
15
+ - @dyyz1993/rpc-core@3.0.0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 [username]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,103 @@
1
+ # Browser Agent Template
2
+
3
+ AI-powered browser automation agent. Built with Electrobun, React, Tailwind CSS, and RPC architecture.
4
+
5
+ Control a real Chrome browser via natural language — Agent executes xbrowser commands (goto, click, scrape, fill, screenshot, search...), streams progress in real-time with turn-by-turn tool call cards, and delivers collected data as structured files (CSV/JSON/MD).
6
+
7
+ 70+ site-specific plugins (小红书, 豆瓣, B站, 淘宝) available.
8
+
9
+ ## Getting Started
10
+
11
+ ```bash
12
+ bun install
13
+
14
+ # Web mode (development with HMR) — Backend :5200, Vite :7200
15
+ bun run dev:web
16
+
17
+ # Desktop mode (Electrobun native app)
18
+ bun run dev
19
+
20
+ # Build
21
+ bun run build
22
+ ```
23
+
24
+ ## Key Features
25
+
26
+ - **Agent Chat** — Natural language → browser automation. Streaming turns, tool call cards, thinking blocks
27
+ - **xbrowser Engine** — Full command set: goto, click, fill, scrape, crawl, search, screenshot, eval, tabs, plugins
28
+ - **Plugin System** — 70+ site plugins, inline selector in the topbar
29
+ - **Skill System** — Pre-built skills (小红书 explore/search/blogger) in sidebar
30
+ - **Session Management** — Conversation history, message persistence, context memory
31
+ - **Assets Panel** — Screenshots, images, CSV/JSON/MD files grouped and downloadable
32
+ - **Three-Panel Layout** — Sidebar (skills + sessions) | Chat | Assets
33
+ - **Desktop + Web** — Dual mode via Electrobun (desktop) + Vite (web)
34
+
35
+ ## RPC Modules
36
+
37
+ | Module | Methods | Events | Description |
38
+ |---|---|---|---|
39
+ | `browser` | agentChat, checkConnection, listTabs, listPlugins, execXbrowser, getSystemInfo | agentStart, toolCall, toolResult, thinking, textDelta, turn, done, progress | Browser auto + Agent AI loop |
40
+ | `session` | create, get, list, addMessage, updateLastMessage, setStatus | – | Session CRUD + message management |
41
+ | `system` | ping, hello, echo | – | Connectivity test |
42
+ | `file` | listDir, readFile, createFile, createDir, rename, delete, copy, findProjectRoot | – | File system operations |
43
+ | `timer` | start, stop | timer.tick | Timer + real-time push |
44
+ | `chat` | list, send | chat.message | Chat (role filtering) |
45
+ | `git` | status, diff, log, branches, checkout, add, reset, commit, push, pull | – | Git version control |
46
+ | `feed` | post, list | feed.update | Feed stream |
47
+
48
+ ## Project Structure
49
+
50
+ ```
51
+ ├── src/
52
+ │ ├── bun/index.ts # Desktop entry (Electrobun main process)
53
+ │ ├── server.ts # Web entry (HTTP + WebSocket server)
54
+ │ ├── server-config.ts # Config (PORT=5200, VITE_PORT=7200)
55
+ │ ├── gateway/
56
+ │ │ ├── http-routes.ts # HTTP endpoints + asset download
57
+ │ │ ├── ws-handler.ts # WebSocket RPC (token auth)
58
+ │ │ └── ipc-transport.ts # Electrobun IPC bridge
59
+ │ ├── shared/
60
+ │ │ ├── rpc-schema.ts # Unified RPC type definitions
61
+ │ │ ├── register-all-handlers.ts
62
+ │ │ ├── modules/
63
+ │ │ │ ├── browser.ts # Browser + Agent RPC types
64
+ │ │ │ └── session.ts # Session CRUD types
65
+ │ │ ├── handlers/
66
+ │ │ │ ├── browser.ts # Agent chat + xbrowser execution
67
+ │ │ │ └── session.ts # In-memory SessionStore
68
+ │ │ └── lib/
69
+ │ │ ├── agent.ts # RpcClient manager + agentChat()
70
+ │ │ ├── cdp.ts # xbrowser CLI + scrapeXhs pipeline
71
+ │ │ ├── generate.ts # CSV/JSON/MD/ZIP export
72
+ │ │ └── xhs-extract.ts # 小红书 DOM extraction
73
+ │ └── mainview/
74
+ │ ├── App.tsx # Entry + connection detection
75
+ │ ├── components/
76
+ │ │ ├── layout/ # AppLayout (sidebar|chat|assets)
77
+ │ │ ├── topbar/ # Logo, plugins, status, theme
78
+ │ │ ├── chat/ # ChatPanel + MessageBubble (streaming)
79
+ │ │ ├── sidebar/ # SkillSidebar + SessionSidebar
80
+ │ │ └── assets/ # AssetsPanel (files/images)
81
+ │ ├── stores/
82
+ │ │ ├── use-chat-store.ts # Agent streaming state
83
+ │ │ ├── use-session-store.ts # Session CRUD
84
+ │ │ ├── use-connection-store.ts # Browser + plugins
85
+ │ │ └── use-asset-store.ts # Assets management
86
+ │ └── lib/
87
+ │ └── api-client.ts # Typed RPC client (WS + IPC)
88
+ ├── AGENTS.md # Agent system prompt
89
+ ├── electrobun.config.ts
90
+ ├── vite.config.ts
91
+ └── tailwind.config.js
92
+ ```
93
+
94
+ ## Environment
95
+
96
+ | Variable | Default | Description |
97
+ |---|---|---|
98
+ | `PORT` | 5200 | Backend server port |
99
+ | `VITE_PORT` | 7200 | Vite dev server port |
100
+ | `AUTH_TOKEN` | (auto) | WebSocket auth token |
101
+ | `CDP_ENDPOINT` | http://localhost:9221 | cdp-tunnel address |
102
+ | `AGENT_MAX_TURNS` | 30 | Max agent turns per chat |
103
+ | `AGENT_TIMEOUT_MS` | 300000 | Agent timeout (5 min) |
@@ -0,0 +1,8 @@
1
+ export default {
2
+ extends: ['@commitlint/config-conventional'],
3
+ rules: {
4
+ 'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'revert', 'perf']],
5
+ 'subject-max-length': [2, 'always', 80],
6
+ 'subject-case': [0],
7
+ },
8
+ };
@@ -0,0 +1,27 @@
1
+ import type { ElectrobunConfig } from "electrobun";
2
+
3
+ export default {
4
+ app: {
5
+ name: "react-tailwind-vite",
6
+ identifier: "reacttailwindvite.electrobun.dev",
7
+ version: "0.0.1",
8
+ },
9
+ build: {
10
+ // Vite builds to dist/, we copy from there
11
+ copy: {
12
+ "dist/index.html": "views/mainview/index.html",
13
+ "dist/assets": "views/mainview/assets",
14
+ },
15
+ // Ignore Vite output in watch mode — HMR handles view rebuilds separately
16
+ watchIgnore: ["dist/**"],
17
+ mac: {
18
+ bundleCEF: false,
19
+ },
20
+ linux: {
21
+ bundleCEF: false,
22
+ },
23
+ win: {
24
+ bundleCEF: false,
25
+ },
26
+ },
27
+ } satisfies ElectrobunConfig;
@@ -0,0 +1,46 @@
1
+ const { app, BrowserWindow, ipcMain } = require('electron');
2
+ const path = require('path');
3
+
4
+ let mainWindow;
5
+
6
+ function createWindow() {
7
+ mainWindow = new BrowserWindow({
8
+ width: 1200,
9
+ height: 800,
10
+ webPreferences: {
11
+ preload: path.join(__dirname, 'preload.js'),
12
+ nodeIntegration: false,
13
+ contextIsolation: true,
14
+ },
15
+ });
16
+
17
+ if (process.env.NODE_ENV === 'development') {
18
+ mainWindow.loadURL('http://localhost:5173');
19
+ } else {
20
+ mainWindow.loadFile(path.join(__dirname, '../dist/index.html'));
21
+ }
22
+
23
+ mainWindow.on('closed', () => {
24
+ mainWindow = null;
25
+ });
26
+ }
27
+
28
+ app.whenReady().then(() => {
29
+ createWindow();
30
+ });
31
+
32
+ app.on('window-all-closed', () => {
33
+ if (process.platform !== 'darwin') {
34
+ app.quit();
35
+ }
36
+ });
37
+
38
+ app.on('activate', () => {
39
+ if (BrowserWindow.getAllWindows().length === 0) {
40
+ createWindow();
41
+ }
42
+ });
43
+
44
+ ipcMain.handle('ping', async () => {
45
+ return 'pong';
46
+ });
@@ -0,0 +1,5 @@
1
+ const { contextBridge, ipcRenderer } = require('electron');
2
+
3
+ contextBridge.exposeInMainWorld('electronAPI', {
4
+ ping: () => ipcRenderer.invoke('ping'),
5
+ });
@@ -0,0 +1,40 @@
1
+ {
2
+ "appId": "com.piagent.app",
3
+ "productName": "Pi Agent",
4
+ "copyright": "Copyright © 2024 dyyz1993",
5
+ "directories": {
6
+ "output": "dist-electron",
7
+ "buildResources": "build"
8
+ },
9
+ "files": ["dist/**/*", "electron/**/*", "package.json"],
10
+ "mac": {
11
+ "category": "public.app-category.developer-tools",
12
+ "hardenedRuntime": true,
13
+ "gatekeeperAssess": false,
14
+ "entitlements": ["com.apple.security.cs.allow-jit"],
15
+ "target": [
16
+ {
17
+ "target": "dmg",
18
+ "arch": ["x64", "arm64"]
19
+ }
20
+ ]
21
+ },
22
+ "win": {
23
+ "target": [
24
+ {
25
+ "target": "nsis",
26
+ "arch": ["x64"]
27
+ }
28
+ ],
29
+ "artifactName": "${productName}-${version}-${arch}.${ext}"
30
+ },
31
+ "linux": {
32
+ "target": ["AppImage", "deb"],
33
+ "category": "Development"
34
+ },
35
+ "publish": {
36
+ "provider": "github",
37
+ "owner": "dyyz1993",
38
+ "repo": "pi-agent-app"
39
+ }
40
+ }