@dyyz1993/create-agent 2.1.1 → 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.
- package/package.json +5 -4
- package/src/__tests__/cli.test.ts +2 -0
- package/src/__tests__/copy.test.ts +110 -122
- package/src/__tests__/create-args.test.ts +113 -0
- package/src/__tests__/templates.test.ts +29 -3
- package/src/__tests__/update.test.ts +129 -0
- package/src/cli.ts +30 -32
- package/src/commands/create.ts +83 -24
- package/src/commands/update.ts +174 -0
- package/src/commands/workspace.ts +26 -6
- package/src/lib/copy.ts +127 -91
- package/src/lib/templates.ts +12 -0
- package/templates/agent/.husky/commit-msg +4 -0
- package/templates/agent/.husky/pre-commit +11 -0
- package/templates/agent/.husky/pre-push +6 -0
- package/templates/agent/CHANGELOG.md +15 -0
- package/templates/agent/package.json +3 -3
- package/templates/agent/src/gateway/__tests__/ws-handler-token.test.ts +53 -39
- package/templates/agent/src/mainview/App.tsx +14 -12
- package/templates/agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +194 -190
- package/templates/agent/src/mainview/components/bash/BashPanel.tsx +210 -189
- package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +45 -20
- package/templates/agent/src/mainview/components/common/ThemeToggle.tsx +41 -21
- package/templates/agent/src/mainview/components/debug/DebugPanel.tsx +181 -114
- package/templates/agent/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +80 -80
- package/templates/agent/src/mainview/components/diff/__tests__/DiffViewerPanel.test.tsx +61 -58
- package/templates/agent/src/mainview/components/feed/FeedPanel.tsx +43 -41
- package/templates/agent/src/mainview/components/file-preview/FilePreviewOverlay.tsx +69 -50
- package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +31 -18
- package/templates/agent/src/mainview/components/git/GitPanel.tsx +731 -490
- package/templates/agent/src/mainview/components/git/__tests__/GitPanel.test.tsx +157 -139
- package/templates/agent/src/mainview/components/layout/AppLayout.tsx +210 -161
- package/templates/agent/src/mainview/components/layout/__tests__/AppLayout.test.tsx +130 -122
- package/templates/agent/src/mainview/components/rules/RulesPanel.tsx +119 -109
- package/templates/agent/src/mainview/components/search/SearchPanel.tsx +123 -117
- package/templates/agent/src/mainview/components/search/__tests__/SearchPanel.test.tsx +64 -44
- package/templates/agent/src/mainview/components/sidebar/__tests__/PinButton.test.tsx +38 -38
- package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +40 -38
- package/templates/agent/src/mainview/components/todo/__tests__/TodoPanel.test.tsx +72 -72
- package/templates/agent/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/agent/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/agent/src/mainview/stores/use-app-store.ts +96 -86
- package/templates/agent/src/mainview/stores/use-explorer-store.ts +292 -275
- package/templates/agent/src/mainview/types/index.ts +23 -22
- package/templates/agent/src/mainview/utils/file-icon.tsx +17 -21
- package/templates/agent/src/shared/handlers/chat.ts +53 -53
- package/templates/agent/src/shared/handlers/debug.ts +13 -3
- package/templates/browser-agent/.env.example +19 -0
- package/templates/browser-agent/.husky/commit-msg +4 -0
- package/templates/browser-agent/.husky/pre-commit +11 -0
- package/templates/browser-agent/.husky/pre-push +6 -0
- package/templates/browser-agent/.prettierignore +6 -0
- package/templates/browser-agent/.prettierrc +9 -0
- package/templates/browser-agent/AGENTS.md +396 -0
- package/templates/browser-agent/CHANGELOG.md +15 -0
- package/templates/browser-agent/LICENSE +21 -0
- package/templates/browser-agent/README.md +103 -0
- package/templates/browser-agent/commitlint.config.js +8 -0
- package/templates/browser-agent/electrobun.config.ts +27 -0
- package/templates/browser-agent/electron/main.js +46 -0
- package/templates/browser-agent/electron/preload.js +5 -0
- package/templates/browser-agent/electron-builder.json +40 -0
- package/templates/browser-agent/eslint.config.mjs +79 -0
- package/templates/browser-agent/llms.txt +24 -0
- package/templates/browser-agent/package.json +140 -0
- package/templates/browser-agent/postcss.config.js +6 -0
- package/templates/browser-agent/scripts/dev.ts +138 -0
- package/templates/browser-agent/src/__tests__/hybrid-mode.test.ts +126 -0
- package/templates/browser-agent/src/__tests__/server-config-security.test.ts +55 -0
- package/templates/browser-agent/src/__tests__/server-config.test.ts +59 -0
- package/templates/browser-agent/src/bun/index.ts +130 -0
- package/templates/browser-agent/src/bun/three.d.ts +1 -0
- package/templates/browser-agent/src/gateway/http-routes.ts +1 -0
- package/templates/browser-agent/src/gateway/ipc-transport.ts +68 -0
- package/templates/browser-agent/src/gateway/sse-transport.ts +221 -0
- package/templates/browser-agent/src/mainview/App.tsx +45 -0
- package/templates/browser-agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
- package/templates/browser-agent/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/browser-agent/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
- package/templates/browser-agent/src/mainview/__tests__/setup.ts +40 -0
- package/templates/browser-agent/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
- package/templates/browser-agent/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
- package/templates/browser-agent/src/mainview/__tests__/theme-variables.test.ts +36 -0
- package/templates/browser-agent/src/mainview/components/assets/AssetsPanel.tsx +139 -0
- package/templates/browser-agent/src/mainview/components/chat/ChatPanel.tsx +219 -0
- package/templates/browser-agent/src/mainview/components/chat/CommandBar.tsx +184 -0
- package/templates/browser-agent/src/mainview/components/chat/MessageBubble.tsx +249 -0
- package/templates/browser-agent/src/mainview/components/chat/ToolPicker.tsx +115 -0
- package/templates/browser-agent/src/mainview/components/common/ErrorBoundary.tsx +1 -0
- package/templates/browser-agent/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/browser-agent/src/mainview/components/common/ThemeToggle.tsx +45 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/browser-agent/src/mainview/components/dev/NetworkPanel.tsx +155 -0
- package/templates/browser-agent/src/mainview/components/layout/AppLayout.tsx +311 -0
- package/templates/browser-agent/src/mainview/components/onboarding/SetupWizard.tsx +310 -0
- package/templates/browser-agent/src/mainview/components/process/ProcessPanel.tsx +329 -0
- package/templates/browser-agent/src/mainview/components/sidebar/SessionSidebar.tsx +122 -0
- package/templates/browser-agent/src/mainview/components/sidebar/SkillSidebar.tsx +115 -0
- package/templates/browser-agent/src/mainview/components/topbar/TopBar.tsx +350 -0
- package/templates/browser-agent/src/mainview/global.d.ts +13 -0
- package/templates/browser-agent/src/mainview/hooks/__tests__/use-breakpoint.test.ts +151 -0
- package/templates/browser-agent/src/mainview/hooks/use-agent-chat.ts +157 -0
- package/templates/browser-agent/src/mainview/hooks/use-breakpoint.ts +68 -0
- package/templates/browser-agent/src/mainview/hooks/use-rpc-init.ts +71 -0
- package/templates/browser-agent/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/browser-agent/src/mainview/index.css +71 -0
- package/templates/browser-agent/src/mainview/index.html +12 -0
- package/templates/browser-agent/src/mainview/lib/api-client.ts +397 -0
- package/templates/browser-agent/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/browser-agent/src/mainview/lib/i18n/locales/en.json +130 -0
- package/templates/browser-agent/src/mainview/lib/i18n/locales/zh.json +128 -0
- package/templates/browser-agent/src/mainview/lib/network-bus.ts +92 -0
- package/templates/browser-agent/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/browser-agent/src/mainview/main.tsx +18 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/browser-agent/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/browser-agent/src/mainview/stores/use-asset-store.ts +65 -0
- package/templates/browser-agent/src/mainview/stores/use-chat-store.ts +200 -0
- package/templates/browser-agent/src/mainview/stores/use-connection-store.ts +173 -0
- package/templates/browser-agent/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/browser-agent/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/browser-agent/src/mainview/stores/use-network-panel-store.ts +18 -0
- package/templates/browser-agent/src/mainview/stores/use-record-store.ts +147 -0
- package/templates/browser-agent/src/mainview/stores/use-session-store.ts +151 -0
- package/templates/browser-agent/src/mainview/stores/use-sidebar-store.ts +161 -0
- package/templates/browser-agent/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/browser-agent/src/mainview/stores/use-view-store.ts +20 -0
- package/templates/browser-agent/src/mainview/types/index.ts +6 -0
- package/templates/browser-agent/src/server-config.ts +45 -0
- package/templates/browser-agent/src/server.ts +78 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/browser-agent/src/shared/handlers/browser.ts +596 -0
- package/templates/browser-agent/src/shared/handlers/chat.ts +213 -0
- package/templates/browser-agent/src/shared/handlers/file.ts +99 -0
- package/templates/browser-agent/src/shared/handlers/index.ts +7 -0
- package/templates/browser-agent/src/shared/handlers/session.ts +167 -0
- package/templates/browser-agent/src/shared/handlers/system.ts +27 -0
- package/templates/browser-agent/src/shared/handlers/timer.ts +34 -0
- package/templates/browser-agent/src/shared/http-routes.ts +437 -0
- package/templates/browser-agent/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/browser-agent/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/browser-agent/src/shared/lib/__tests__/web-server.test.ts +203 -0
- package/templates/browser-agent/src/shared/lib/agent.ts +384 -0
- package/templates/browser-agent/src/shared/lib/cdp.ts +448 -0
- package/templates/browser-agent/src/shared/lib/generate.ts +111 -0
- package/templates/browser-agent/src/shared/lib/logger.ts +152 -0
- package/templates/browser-agent/src/shared/lib/mock-stream.ts +147 -0
- package/templates/browser-agent/src/shared/lib/path-security.ts +38 -0
- package/templates/browser-agent/src/shared/lib/port-registry.ts +103 -0
- package/templates/browser-agent/src/shared/lib/web-server.ts +127 -0
- package/templates/browser-agent/src/shared/lib/xhs-extract.ts +71 -0
- package/templates/browser-agent/src/shared/modules/browser.ts +86 -0
- package/templates/browser-agent/src/shared/modules/chat.ts +20 -0
- package/templates/browser-agent/src/shared/modules/file.ts +40 -0
- package/templates/browser-agent/src/shared/modules/session.ts +55 -0
- package/templates/browser-agent/src/shared/modules/system.ts +8 -0
- package/templates/browser-agent/src/shared/modules/timer.ts +11 -0
- package/templates/browser-agent/src/shared/register-all-handlers.ts +36 -0
- package/templates/browser-agent/src/shared/rpc-schema.ts +34 -0
- package/templates/browser-agent/tailwind.config.js +15 -0
- package/templates/browser-agent/tsconfig.ipc.json +14 -0
- package/templates/browser-agent/tsconfig.json +36 -0
- package/templates/browser-agent/vite.config.ts +3 -0
- package/templates/browser-agent/vitest.config.ts +3 -0
- package/templates/chat/.husky/commit-msg +4 -0
- package/templates/chat/.husky/pre-commit +11 -0
- package/templates/chat/.husky/pre-push +6 -0
- package/templates/chat/CHANGELOG.md +15 -0
- package/templates/chat/commitlint.config.js +8 -0
- package/templates/chat/package.json +19 -4
- package/templates/chat/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/chat/src/mainview/__tests__/setup.ts +32 -29
- package/templates/chat/src/mainview/components/chat/ChatPanel.tsx +80 -55
- package/templates/chat/src/mainview/components/common/ThemeToggle.tsx +40 -20
- package/templates/chat/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/chat/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/chat/src/shared/handlers/chat.ts +17 -19
- package/templates/chat/src/shared/handlers/debug.ts +12 -2
- package/templates/cowork/.env.example +8 -0
- package/templates/cowork/.prettierignore +6 -0
- package/templates/cowork/.prettierrc +9 -0
- package/templates/cowork/AGENTS.md +236 -0
- package/templates/cowork/CHANGELOG.md +15 -0
- package/templates/cowork/LICENSE +21 -0
- package/templates/cowork/README.md +103 -0
- package/templates/cowork/commitlint.config.js +8 -0
- package/templates/cowork/docs/CODE-VIEW-PLAN.md +637 -0
- package/templates/cowork/docs/CODE-VIEW-V2.md +196 -0
- package/templates/cowork/docs/CODE-VIEW-V4.md +150 -0
- package/templates/cowork/electrobun.config.ts +27 -0
- package/templates/cowork/eslint.config.mjs +79 -0
- package/templates/cowork/llms.txt +24 -0
- package/templates/cowork/package.json +87 -0
- package/templates/cowork/postcss.config.js +6 -0
- package/templates/cowork/scripts/dev.ts +138 -0
- package/templates/cowork/src/__tests__/hybrid-mode.test.ts +126 -0
- package/templates/cowork/src/__tests__/server-config-security.test.ts +55 -0
- package/templates/cowork/src/__tests__/server-config.test.ts +59 -0
- package/templates/cowork/src/bun/index.ts +130 -0
- package/templates/cowork/src/bun/three.d.ts +1 -0
- package/templates/cowork/src/gateway/http-routes.ts +1 -0
- package/templates/cowork/src/gateway/ipc-transport.ts +68 -0
- package/templates/cowork/src/gateway/sse-transport.ts +231 -0
- package/templates/cowork/src/mainview/App.tsx +45 -0
- package/templates/cowork/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
- package/templates/cowork/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/cowork/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
- package/templates/cowork/src/mainview/__tests__/setup.ts +40 -0
- package/templates/cowork/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
- package/templates/cowork/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
- package/templates/cowork/src/mainview/__tests__/theme-variables.test.ts +36 -0
- package/templates/cowork/src/mainview/components/chat/TaskChat.tsx +311 -0
- package/templates/cowork/src/mainview/components/chat/__tests__/localhost-links.test.ts +76 -0
- package/templates/cowork/src/mainview/components/common/ErrorBoundary.tsx +1 -0
- package/templates/cowork/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/cowork/src/mainview/components/common/ThemeToggle.tsx +45 -0
- package/templates/cowork/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/cowork/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/cowork/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/cowork/src/mainview/components/dev/NetworkPanel.tsx +155 -0
- package/templates/cowork/src/mainview/components/layout/AppLayout.tsx +216 -0
- package/templates/cowork/src/mainview/components/right/ArtifactsPanel.tsx +54 -0
- package/templates/cowork/src/mainview/components/right/ContextPanel.tsx +133 -0
- package/templates/cowork/src/mainview/components/right/ElementPicker.tsx +206 -0
- package/templates/cowork/src/mainview/components/right/PreviewBlock.tsx +155 -0
- package/templates/cowork/src/mainview/components/right/ProgressPanel.tsx +85 -0
- package/templates/cowork/src/mainview/components/sidebar/TaskSidebar.tsx +211 -0
- package/templates/cowork/src/mainview/components/topbar/TopBar.tsx +86 -0
- package/templates/cowork/src/mainview/global.d.ts +13 -0
- package/templates/cowork/src/mainview/hooks/__tests__/use-breakpoint.test.ts +123 -0
- package/templates/cowork/src/mainview/hooks/use-breakpoint.ts +53 -0
- package/templates/cowork/src/mainview/hooks/use-rpc-init.ts +26 -0
- package/templates/cowork/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/cowork/src/mainview/index.css +89 -0
- package/templates/cowork/src/mainview/index.html +12 -0
- package/templates/cowork/src/mainview/lib/api-client.ts +404 -0
- package/templates/cowork/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/cowork/src/mainview/lib/i18n/locales/en.json +130 -0
- package/templates/cowork/src/mainview/lib/i18n/locales/zh.json +128 -0
- package/templates/cowork/src/mainview/lib/network-bus.ts +92 -0
- package/templates/cowork/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/cowork/src/mainview/main.tsx +18 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-preview-store.test.ts +193 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-sidebar-store.test.ts +81 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/cowork/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/cowork/src/mainview/stores/use-chat-store.ts +198 -0
- package/templates/cowork/src/mainview/stores/use-connection-store.ts +168 -0
- package/templates/cowork/src/mainview/stores/use-context-store.ts +68 -0
- package/templates/cowork/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/cowork/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/cowork/src/mainview/stores/use-network-panel-store.ts +18 -0
- package/templates/cowork/src/mainview/stores/use-output-store.ts +47 -0
- package/templates/cowork/src/mainview/stores/use-preview-store.ts +97 -0
- package/templates/cowork/src/mainview/stores/use-sidebar-store.ts +272 -0
- package/templates/cowork/src/mainview/stores/use-task-store.ts +86 -0
- package/templates/cowork/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/cowork/src/mainview/stores/use-view-store.ts +29 -0
- package/templates/cowork/src/mainview/types/index.ts +6 -0
- package/templates/cowork/src/server-config.ts +44 -0
- package/templates/cowork/src/server.ts +78 -0
- package/templates/cowork/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
- package/templates/cowork/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/cowork/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/cowork/src/shared/handlers/__tests__/preview-handler.test.ts +172 -0
- package/templates/cowork/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/cowork/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/cowork/src/shared/handlers/chat.ts +213 -0
- package/templates/cowork/src/shared/handlers/context.ts +72 -0
- package/templates/cowork/src/shared/handlers/file.ts +99 -0
- package/templates/cowork/src/shared/handlers/index.ts +9 -0
- package/templates/cowork/src/shared/handlers/output.ts +59 -0
- package/templates/cowork/src/shared/handlers/preview.ts +81 -0
- package/templates/cowork/src/shared/handlers/system.ts +27 -0
- package/templates/cowork/src/shared/handlers/task.ts +101 -0
- package/templates/cowork/src/shared/handlers/timer.ts +34 -0
- package/templates/cowork/src/shared/http-routes.ts +444 -0
- package/templates/cowork/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/cowork/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/cowork/src/shared/lib/__tests__/web-server.test.ts +203 -0
- package/templates/cowork/src/shared/lib/logger.ts +152 -0
- package/templates/cowork/src/shared/lib/path-security.ts +38 -0
- package/templates/cowork/src/shared/lib/port-registry.ts +103 -0
- package/templates/cowork/src/shared/lib/web-server.ts +127 -0
- package/templates/cowork/src/shared/modules/chat.ts +20 -0
- package/templates/cowork/src/shared/modules/context.ts +32 -0
- package/templates/cowork/src/shared/modules/file.ts +40 -0
- package/templates/cowork/src/shared/modules/output.ts +20 -0
- package/templates/cowork/src/shared/modules/preview.ts +44 -0
- package/templates/cowork/src/shared/modules/system.ts +8 -0
- package/templates/cowork/src/shared/modules/task.ts +31 -0
- package/templates/cowork/src/shared/modules/timer.ts +11 -0
- package/templates/cowork/src/shared/register-all-handlers.ts +36 -0
- package/templates/cowork/src/shared/rpc-schema.ts +38 -0
- package/templates/cowork/tailwind.config.js +15 -0
- package/templates/cowork/test-upload.txt +0 -0
- package/templates/cowork/tsconfig.ipc.json +14 -0
- package/templates/cowork/tsconfig.json +36 -0
- package/templates/cowork/vite.config.ts +3 -0
- package/templates/cowork/vitest.config.ts +3 -0
- package/templates/general/.husky/commit-msg +4 -0
- package/templates/general/.husky/pre-commit +11 -0
- package/templates/general/.husky/pre-push +6 -0
- package/templates/general/CHANGELOG.md +15 -0
- package/templates/general/commitlint.config.js +8 -0
- package/templates/general/package.json +19 -4
- package/templates/general/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/general/src/mainview/__tests__/setup.ts +32 -29
- package/templates/general/src/mainview/components/chat/ChatPanel.tsx +80 -55
- package/templates/general/src/mainview/components/common/ThemeToggle.tsx +40 -20
- package/templates/general/src/mainview/components/debug/DebugPanel.tsx +170 -156
- package/templates/general/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +169 -0
- package/templates/general/src/mainview/components/explorer/ConfirmDialog.tsx +42 -42
- package/templates/general/src/mainview/components/explorer/ContextMenu.tsx +72 -67
- package/templates/general/src/mainview/components/feed/FeedPanel.tsx +7 -5
- package/templates/general/src/mainview/components/file-preview/FilePreviewOverlay.tsx +64 -45
- package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +24 -7
- package/templates/general/src/mainview/components/git/GitPanel.tsx +700 -473
- package/templates/general/src/mainview/components/layout/AppLayout.tsx +123 -114
- package/templates/general/src/mainview/components/search/SearchPanel.tsx +15 -19
- package/templates/general/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/general/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/general/src/mainview/stores/__tests__/use-explorer-store.test.ts +259 -0
- package/templates/general/src/mainview/stores/__tests__/use-feed-store.test.ts +160 -0
- package/templates/general/src/mainview/stores/__tests__/use-git-store.test.ts +313 -0
- package/templates/general/src/mainview/stores/__tests__/use-notification-store.test.ts +115 -0
- package/templates/general/src/mainview/stores/__tests__/use-sidebar-store.test.ts +120 -0
- package/templates/general/src/mainview/stores/use-explorer-store.ts +277 -260
- package/templates/general/src/mainview/types/index.ts +21 -20
- package/templates/general/src/shared/handlers/chat.ts +1 -1
- package/templates/general/src/shared/handlers/debug.ts +12 -2
- package/templates/shared/components/ErrorBoundary.tsx +0 -1
- package/templates/shared/vite-base.config.ts +8 -7
- /package/templates/{shared → browser-agent}/test-upload.txt +0 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
|
|
3
|
+
export type Breakpoint = 'mobile' | 'tablet' | 'desktop' | 'wide';
|
|
4
|
+
|
|
5
|
+
/** 侧边栏三态折叠模式 */
|
|
6
|
+
export type SidebarMode = 'full' | 'icon' | 'hidden';
|
|
7
|
+
|
|
8
|
+
const PINNED_KEY = 'sidebar-pinned';
|
|
9
|
+
const WIDTH_KEY = 'sidebar-width';
|
|
10
|
+
const MODE_KEY = 'sidebar-mode';
|
|
11
|
+
const COLLAPSED_SECTIONS_KEY = 'sidebar-collapsed-sections';
|
|
12
|
+
|
|
13
|
+
export const SIDEBAR_MIN_WIDTH = 220;
|
|
14
|
+
export const SIDEBAR_MAX_WIDTH = 520;
|
|
15
|
+
export const SIDEBAR_ICON_WIDTH = 56;
|
|
16
|
+
const DEFAULT_WIDTH = 280;
|
|
17
|
+
|
|
18
|
+
/** 断点定义:mobile <768, tablet 768-1023, desktop 1024-1279, wide ≥1280 */
|
|
19
|
+
function getBreakpoint(width: number): Breakpoint {
|
|
20
|
+
if (width < 768) return 'mobile';
|
|
21
|
+
if (width < 1024) return 'tablet';
|
|
22
|
+
if (width < 1280) return 'desktop';
|
|
23
|
+
return 'wide';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface SidebarState {
|
|
27
|
+
breakpoint: Breakpoint;
|
|
28
|
+
isPinned: boolean;
|
|
29
|
+
drawerOpen: boolean;
|
|
30
|
+
sidebarWidth: number;
|
|
31
|
+
/** 三态折叠模式(替代 isPinned 在桌面端的主折叠语义) */
|
|
32
|
+
sidebarMode: SidebarMode;
|
|
33
|
+
/** 区块级折叠(section id 集合,如 "skills" / "sessions") */
|
|
34
|
+
collapsedSections: Set<string>;
|
|
35
|
+
setPinned: (pinned: boolean) => void;
|
|
36
|
+
setDrawerOpen: (open: boolean) => void;
|
|
37
|
+
setSidebarWidth: (width: number) => void;
|
|
38
|
+
setSidebarMode: (mode: SidebarMode) => void;
|
|
39
|
+
/** 循环切换:full → icon → hidden → full */
|
|
40
|
+
cycleSidebarMode: () => void;
|
|
41
|
+
/** 切换区块折叠状态 */
|
|
42
|
+
toggleSection: (id: string) => void;
|
|
43
|
+
_setBreakpoint: (bp: Breakpoint) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function readPinned(): boolean {
|
|
47
|
+
try {
|
|
48
|
+
const stored = localStorage.getItem(PINNED_KEY);
|
|
49
|
+
if (stored !== null) return stored !== 'false';
|
|
50
|
+
return window.innerWidth >= 1024;
|
|
51
|
+
} catch {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function readWidth(): number {
|
|
57
|
+
try {
|
|
58
|
+
const v = Number(localStorage.getItem(WIDTH_KEY));
|
|
59
|
+
if (Number.isNaN(v) || v < SIDEBAR_MIN_WIDTH || v > SIDEBAR_MAX_WIDTH) return DEFAULT_WIDTH;
|
|
60
|
+
return v;
|
|
61
|
+
} catch {
|
|
62
|
+
return DEFAULT_WIDTH;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function readMode(): SidebarMode {
|
|
67
|
+
try {
|
|
68
|
+
const v = localStorage.getItem(MODE_KEY);
|
|
69
|
+
if (v === 'full' || v === 'icon' || v === 'hidden') return v;
|
|
70
|
+
} catch {
|
|
71
|
+
/* ignore */
|
|
72
|
+
}
|
|
73
|
+
return 'full';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function readCollapsedSections(): Set<string> {
|
|
77
|
+
try {
|
|
78
|
+
const v = localStorage.getItem(COLLAPSED_SECTIONS_KEY);
|
|
79
|
+
if (v) return new Set(JSON.parse(v) as string[]);
|
|
80
|
+
} catch {
|
|
81
|
+
/* ignore */
|
|
82
|
+
}
|
|
83
|
+
return new Set();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function persistCollapsedSections(set: Set<string>): void {
|
|
87
|
+
try {
|
|
88
|
+
localStorage.setItem(COLLAPSED_SECTIONS_KEY, JSON.stringify([...set]));
|
|
89
|
+
} catch {
|
|
90
|
+
/* ignore */
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const initialWidth = typeof window !== 'undefined' ? window.innerWidth : 1024;
|
|
95
|
+
|
|
96
|
+
export const useSidebarStore = create<SidebarState>((set, get) => ({
|
|
97
|
+
breakpoint: getBreakpoint(initialWidth),
|
|
98
|
+
isPinned: readPinned(),
|
|
99
|
+
drawerOpen: false,
|
|
100
|
+
sidebarWidth: readWidth(),
|
|
101
|
+
sidebarMode: readMode(),
|
|
102
|
+
collapsedSections: readCollapsedSections(),
|
|
103
|
+
|
|
104
|
+
setPinned: (pinned) => {
|
|
105
|
+
try {
|
|
106
|
+
localStorage.setItem(PINNED_KEY, String(pinned));
|
|
107
|
+
} catch {
|
|
108
|
+
/* ignore */
|
|
109
|
+
}
|
|
110
|
+
set({ isPinned: pinned, drawerOpen: false });
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
setDrawerOpen: (open) => {
|
|
114
|
+
set({ drawerOpen: open });
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
setSidebarWidth: (width) => {
|
|
118
|
+
const clamped = Math.min(SIDEBAR_MAX_WIDTH, Math.max(SIDEBAR_MIN_WIDTH, width));
|
|
119
|
+
try {
|
|
120
|
+
localStorage.setItem(WIDTH_KEY, String(clamped));
|
|
121
|
+
} catch {
|
|
122
|
+
/* ignore */
|
|
123
|
+
}
|
|
124
|
+
set({ sidebarWidth: clamped });
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
setSidebarMode: (mode) => {
|
|
128
|
+
try {
|
|
129
|
+
localStorage.setItem(MODE_KEY, mode);
|
|
130
|
+
} catch {
|
|
131
|
+
/* ignore */
|
|
132
|
+
}
|
|
133
|
+
set({ sidebarMode: mode });
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
cycleSidebarMode: () => {
|
|
137
|
+
const order: SidebarMode[] = ['full', 'icon', 'hidden'];
|
|
138
|
+
const current = get().sidebarMode;
|
|
139
|
+
const next = order[(order.indexOf(current) + 1) % order.length] || 'full';
|
|
140
|
+
try {
|
|
141
|
+
localStorage.setItem(MODE_KEY, next);
|
|
142
|
+
} catch {
|
|
143
|
+
/* ignore */
|
|
144
|
+
}
|
|
145
|
+
set({ sidebarMode: next });
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
toggleSection: (id) => {
|
|
149
|
+
const sections = new Set<string>(get().collapsedSections);
|
|
150
|
+
if (sections.has(id)) {
|
|
151
|
+
sections.delete(id);
|
|
152
|
+
} else {
|
|
153
|
+
sections.add(id);
|
|
154
|
+
}
|
|
155
|
+
persistCollapsedSections(sections);
|
|
156
|
+
set({ collapsedSections: sections });
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
_setBreakpoint: (bp) => set({ breakpoint: bp }),
|
|
160
|
+
}));
|
|
161
|
+
|
|
162
|
+
/** 右侧面板状态 — 可调宽 + 可收起(类似左栏) */
|
|
163
|
+
export type RightPanelMode = 'full' | 'hidden';
|
|
164
|
+
|
|
165
|
+
const RIGHT_WIDTH_KEY = 'rightpanel-width';
|
|
166
|
+
const RIGHT_MODE_KEY = 'rightpanel-mode';
|
|
167
|
+
export const RIGHT_PANEL_MIN_WIDTH = 240;
|
|
168
|
+
export const RIGHT_PANEL_MAX_WIDTH = 600;
|
|
169
|
+
export const RIGHT_PANEL_DEFAULT_WIDTH = 320;
|
|
170
|
+
|
|
171
|
+
function readRightWidth(): number {
|
|
172
|
+
try {
|
|
173
|
+
const v = Number(localStorage.getItem(RIGHT_WIDTH_KEY));
|
|
174
|
+
if (Number.isNaN(v) || v < RIGHT_PANEL_MIN_WIDTH || v > RIGHT_PANEL_MAX_WIDTH)
|
|
175
|
+
return RIGHT_PANEL_DEFAULT_WIDTH;
|
|
176
|
+
return v;
|
|
177
|
+
} catch {
|
|
178
|
+
return RIGHT_PANEL_DEFAULT_WIDTH;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function readRightMode(): RightPanelMode {
|
|
183
|
+
try {
|
|
184
|
+
const v = localStorage.getItem(RIGHT_MODE_KEY);
|
|
185
|
+
if (v === 'hidden') return 'hidden';
|
|
186
|
+
} catch {
|
|
187
|
+
/* ignore */
|
|
188
|
+
}
|
|
189
|
+
return 'full';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
interface RightPanelState {
|
|
193
|
+
width: number;
|
|
194
|
+
mode: RightPanelMode;
|
|
195
|
+
/**
|
|
196
|
+
* 因点击聊天中的 localhost 链接而展开的预览态。
|
|
197
|
+
* 为 true 时,右栏强制展开并以 ~40% 宽度显示浏览器预览,
|
|
198
|
+
* 优先级高于 mode 和当前 Tab 的默认右栏内容。
|
|
199
|
+
*/
|
|
200
|
+
expandedForPreview: boolean;
|
|
201
|
+
/** 展开前的宽度,关闭预览后恢复 */
|
|
202
|
+
widthBeforeExpand: number | null;
|
|
203
|
+
setWidth: (w: number) => void;
|
|
204
|
+
setMode: (m: RightPanelMode) => void;
|
|
205
|
+
toggleMode: () => void;
|
|
206
|
+
/** 点击聊天链接触发:展开右栏到 ~40% 并显示预览 */
|
|
207
|
+
openForPreview: () => void;
|
|
208
|
+
/** 关闭预览:恢复展开前的宽度与 mode */
|
|
209
|
+
closePreview: () => void;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export const useRightPanelStore = create<RightPanelState>((set, get) => ({
|
|
213
|
+
width: readRightWidth(),
|
|
214
|
+
mode: readRightMode(),
|
|
215
|
+
expandedForPreview: false,
|
|
216
|
+
widthBeforeExpand: null,
|
|
217
|
+
|
|
218
|
+
setWidth: (w) => {
|
|
219
|
+
const clamped = Math.min(RIGHT_PANEL_MAX_WIDTH, Math.max(RIGHT_PANEL_MIN_WIDTH, w));
|
|
220
|
+
try {
|
|
221
|
+
localStorage.setItem(RIGHT_WIDTH_KEY, String(clamped));
|
|
222
|
+
} catch {
|
|
223
|
+
/* ignore */
|
|
224
|
+
}
|
|
225
|
+
set({ width: clamped });
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
setMode: (m) => {
|
|
229
|
+
try {
|
|
230
|
+
localStorage.setItem(RIGHT_MODE_KEY, m);
|
|
231
|
+
} catch {
|
|
232
|
+
/* ignore */
|
|
233
|
+
}
|
|
234
|
+
set({ mode: m });
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
toggleMode: () => {
|
|
238
|
+
const next: RightPanelMode = get().mode === 'full' ? 'hidden' : 'full';
|
|
239
|
+
try {
|
|
240
|
+
localStorage.setItem(RIGHT_MODE_KEY, next);
|
|
241
|
+
} catch {
|
|
242
|
+
/* ignore */
|
|
243
|
+
}
|
|
244
|
+
set({ mode: next });
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 聊天链接点击:展开右栏至视口的 ~40%,
|
|
249
|
+
* 记录展开前的宽度以便关闭时恢复。
|
|
250
|
+
*/
|
|
251
|
+
openForPreview: () => {
|
|
252
|
+
const { expandedForPreview, width } = get();
|
|
253
|
+
if (expandedForPreview) return; // 已展开则不重复触发
|
|
254
|
+
const target = Math.round((typeof window !== 'undefined' ? window.innerWidth : 1440) * 0.4);
|
|
255
|
+
const clamped = Math.min(RIGHT_PANEL_MAX_WIDTH, Math.max(RIGHT_PANEL_MIN_WIDTH, target));
|
|
256
|
+
set({
|
|
257
|
+
expandedForPreview: true,
|
|
258
|
+
widthBeforeExpand: width,
|
|
259
|
+
width: clamped,
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
/** 关闭预览:恢复展开前的宽度 */
|
|
264
|
+
closePreview: () => {
|
|
265
|
+
const { widthBeforeExpand } = get();
|
|
266
|
+
set({
|
|
267
|
+
expandedForPreview: false,
|
|
268
|
+
width: widthBeforeExpand ?? readRightWidth(),
|
|
269
|
+
widthBeforeExpand: null,
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
}));
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 任务 Store — 任务 CRUD + 选中态
|
|
3
|
+
*/
|
|
4
|
+
import { create } from "zustand";
|
|
5
|
+
import { apiClient } from "../lib/api-client";
|
|
6
|
+
import { useLogStore } from "./use-log-store";
|
|
7
|
+
|
|
8
|
+
export type TaskStatus = "queued" | "analyzing" | "executing" | "waiting_input" | "review" | "completed" | "failed";
|
|
9
|
+
|
|
10
|
+
export interface Step {
|
|
11
|
+
label: string;
|
|
12
|
+
status: "pending" | "running" | "done" | "error";
|
|
13
|
+
detail?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Task {
|
|
17
|
+
id: string;
|
|
18
|
+
title: string;
|
|
19
|
+
status: TaskStatus;
|
|
20
|
+
progress?: { steps: Step[] };
|
|
21
|
+
createdAt: number;
|
|
22
|
+
updatedAt: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface TaskState {
|
|
26
|
+
tasks: Task[];
|
|
27
|
+
currentTaskId: string | null;
|
|
28
|
+
fetchTasks: () => Promise<void>;
|
|
29
|
+
createTask: (title: string) => Promise<Task>;
|
|
30
|
+
selectTask: (id: string) => void;
|
|
31
|
+
updateTask: (id: string, patch: Partial<Pick<Task, "title" | "status" | "progress">>) => Promise<void>;
|
|
32
|
+
deleteTask: (id: string) => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const useTaskStore = create<TaskState>((set, get) => ({
|
|
36
|
+
tasks: [],
|
|
37
|
+
currentTaskId: null,
|
|
38
|
+
|
|
39
|
+
fetchTasks: async () => {
|
|
40
|
+
try {
|
|
41
|
+
const res = await apiClient.call("task.list", {});
|
|
42
|
+
set({ tasks: res.tasks });
|
|
43
|
+
// 自动选中第一个任务
|
|
44
|
+
const first = res.tasks[0];
|
|
45
|
+
if (!get().currentTaskId && first) {
|
|
46
|
+
set({ currentTaskId: first.id });
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
useLogStore.getState().addLog("error", "Failed to fetch tasks", { error: err });
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
createTask: async (title) => {
|
|
54
|
+
const res = await apiClient.call("task.create", { title });
|
|
55
|
+
set((s) => ({ tasks: [res.task, ...s.tasks], currentTaskId: res.task.id }));
|
|
56
|
+
return res.task;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
selectTask: (id) => set({ currentTaskId: id }),
|
|
60
|
+
|
|
61
|
+
updateTask: async (id, patch) => {
|
|
62
|
+
try {
|
|
63
|
+
const res = await apiClient.call("task.update", { id, patch });
|
|
64
|
+
set((s) => ({
|
|
65
|
+
tasks: s.tasks.map((t) => (t.id === id ? res.task : t)),
|
|
66
|
+
}));
|
|
67
|
+
} catch (err) {
|
|
68
|
+
useLogStore.getState().addLog("error", "Failed to update task", { error: err });
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
deleteTask: async (id) => {
|
|
73
|
+
try {
|
|
74
|
+
await apiClient.call("task.delete", { id });
|
|
75
|
+
set((s) => {
|
|
76
|
+
const tasks = s.tasks.filter((t) => t.id !== id);
|
|
77
|
+
return {
|
|
78
|
+
tasks,
|
|
79
|
+
currentTaskId: s.currentTaskId === id ? (tasks[0]?.id ?? null) : s.currentTaskId,
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
} catch (err) {
|
|
83
|
+
useLogStore.getState().addLog("error", "Failed to delete task", { error: err });
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
}));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
|
|
3
|
+
export type Theme = "light" | "dark";
|
|
4
|
+
|
|
5
|
+
interface ThemeState {
|
|
6
|
+
theme: Theme;
|
|
7
|
+
setTheme: (theme: Theme) => void;
|
|
8
|
+
toggleTheme: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getInitialTheme(): Theme {
|
|
12
|
+
if (typeof window === "undefined") return "dark";
|
|
13
|
+
const stored = localStorage.getItem("theme");
|
|
14
|
+
if (stored === "light" || stored === "dark") return stored;
|
|
15
|
+
return "dark";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function applyTheme(theme: Theme): void {
|
|
19
|
+
if (typeof document === "undefined") return;
|
|
20
|
+
if (theme === "dark") {
|
|
21
|
+
document.documentElement.classList.add("dark");
|
|
22
|
+
} else {
|
|
23
|
+
document.documentElement.classList.remove("dark");
|
|
24
|
+
}
|
|
25
|
+
localStorage.setItem("theme", theme);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const useThemeStore = create<ThemeState>((set) => {
|
|
29
|
+
const initial = getInitialTheme();
|
|
30
|
+
applyTheme(initial);
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
theme: initial,
|
|
34
|
+
setTheme: (theme) => {
|
|
35
|
+
applyTheme(theme);
|
|
36
|
+
set({ theme });
|
|
37
|
+
},
|
|
38
|
+
toggleTheme: () => {
|
|
39
|
+
set((state) => {
|
|
40
|
+
const next = state.theme === "dark" ? "light" : "dark";
|
|
41
|
+
applyTheme(next);
|
|
42
|
+
return { theme: next };
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* View Store — 全局视图状态
|
|
3
|
+
*
|
|
4
|
+
* 管理当前激活的视图 Tab(Chat/Code/Cowork)+ 右侧面板折叠状态。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { create } from "zustand";
|
|
8
|
+
|
|
9
|
+
export type CenterTab = "chat" | "code" | "cowork";
|
|
10
|
+
|
|
11
|
+
interface ViewState {
|
|
12
|
+
centerTab: CenterTab;
|
|
13
|
+
setCenterTab: (tab: CenterTab) => void;
|
|
14
|
+
rightPanelCollapsed: Record<string, boolean>;
|
|
15
|
+
toggleRightPanel: (id: string) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useViewStore = create<ViewState>((set) => ({
|
|
19
|
+
centerTab: "cowork",
|
|
20
|
+
setCenterTab: (tab) => set({ centerTab: tab }),
|
|
21
|
+
rightPanelCollapsed: {},
|
|
22
|
+
toggleRightPanel: (id) =>
|
|
23
|
+
set((s) => ({
|
|
24
|
+
rightPanelCollapsed: {
|
|
25
|
+
...s.rightPanelCollapsed,
|
|
26
|
+
[id]: !s.rightPanelCollapsed[id],
|
|
27
|
+
},
|
|
28
|
+
})),
|
|
29
|
+
}));
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web server configuration — single source of truth.
|
|
3
|
+
* Values are read from environment variables with sensible defaults.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { randomUUID } from 'crypto';
|
|
7
|
+
|
|
8
|
+
if (process.env.NODE_ENV === 'production' && !process.env.AUTH_TOKEN) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
'[FATAL] AUTH_TOKEN environment variable must be set in production mode. ' +
|
|
11
|
+
'Example: AUTH_TOKEN=$(openssl rand -hex 32) bun src/server.ts',
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function parseEnvInt(
|
|
16
|
+
key: string,
|
|
17
|
+
value: string | undefined,
|
|
18
|
+
defaultValue: number,
|
|
19
|
+
min: number,
|
|
20
|
+
max: number,
|
|
21
|
+
): number {
|
|
22
|
+
if (value === undefined || value === '') return defaultValue;
|
|
23
|
+
const parsed = parseInt(value, 10);
|
|
24
|
+
if (isNaN(parsed) || parsed < min || parsed > max) {
|
|
25
|
+
process.stderr.write(`[config] Invalid ${key}: "${value}", using default: ${defaultValue}\n`);
|
|
26
|
+
return defaultValue;
|
|
27
|
+
}
|
|
28
|
+
return parsed;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const config = {
|
|
32
|
+
port: parseEnvInt('PORT', process.env.PORT, 5300, 1024, 65535),
|
|
33
|
+
authToken: process.env.AUTH_TOKEN || `dev-${randomUUID()}`,
|
|
34
|
+
maxUploadSize: parseEnvInt(
|
|
35
|
+
'MAX_UPLOAD_SIZE',
|
|
36
|
+
process.env.MAX_UPLOAD_SIZE,
|
|
37
|
+
50 * 1024 * 1024,
|
|
38
|
+
0,
|
|
39
|
+
1024 * 1024 * 1024,
|
|
40
|
+
),
|
|
41
|
+
logDir: process.env.LOG_DIR || 'logs',
|
|
42
|
+
enableWebService: process.env.ENABLE_WEB_SERVICE === 'true',
|
|
43
|
+
corsOrigin: process.env.CORS_ORIGIN || 'http://localhost:7300',
|
|
44
|
+
} as const;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web server entry point — HTTP file endpoints + SSE/HTTP RPC gateway.
|
|
3
|
+
* Port auto-negotiation: tries config.port first, increments on EADDRINUSE.
|
|
4
|
+
* Writes actual port to .server-port for dev orchestration.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { writeFileSync, unlinkSync, existsSync } from "fs";
|
|
8
|
+
import { join, resolve, basename } from "path";
|
|
9
|
+
import { config } from "./server-config";
|
|
10
|
+
import { createWebServer, getLocalIP } from "./shared/lib/web-server";
|
|
11
|
+
import { createLogger, configureLogDir } from "./shared/lib/logger";
|
|
12
|
+
import { registerPort, unregisterPort, formatRegistryForOutput } from "./shared/lib/port-registry";
|
|
13
|
+
import { discoverMethodNames } from "./shared/register-all-handlers";
|
|
14
|
+
|
|
15
|
+
configureLogDir(config.logDir);
|
|
16
|
+
const log = createLogger("server");
|
|
17
|
+
|
|
18
|
+
const PORT_FILE = join(import.meta.dir, "..", ".server-port");
|
|
19
|
+
const PROJECT_ROOT = resolve(import.meta.dir, "..");
|
|
20
|
+
const PROJECT_NAME = basename(PROJECT_ROOT);
|
|
21
|
+
|
|
22
|
+
function cleanupPortFile() {
|
|
23
|
+
try {
|
|
24
|
+
if (existsSync(PORT_FILE)) unlinkSync(PORT_FILE);
|
|
25
|
+
} catch {}
|
|
26
|
+
unregisterPort(PROJECT_ROOT);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function writePortFile(port: number) {
|
|
30
|
+
writeFileSync(PORT_FILE, String(port), "utf-8");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
process.on("exit", cleanupPortFile);
|
|
34
|
+
process.on("SIGINT", () => {
|
|
35
|
+
cleanupPortFile();
|
|
36
|
+
process.exit(0);
|
|
37
|
+
});
|
|
38
|
+
process.on("SIGTERM", () => {
|
|
39
|
+
cleanupPortFile();
|
|
40
|
+
process.exit(0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
async function start() {
|
|
44
|
+
const { port, close } = await createWebServer({
|
|
45
|
+
port: config.port,
|
|
46
|
+
authToken: config.authToken,
|
|
47
|
+
maxUploadSize: config.maxUploadSize,
|
|
48
|
+
corsOrigin: config.corsOrigin,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
process.on("SIGINT", () => {
|
|
52
|
+
close();
|
|
53
|
+
cleanupPortFile();
|
|
54
|
+
process.exit(0);
|
|
55
|
+
});
|
|
56
|
+
process.on("SIGTERM", () => {
|
|
57
|
+
close();
|
|
58
|
+
cleanupPortFile();
|
|
59
|
+
process.exit(0);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
writePortFile(port);
|
|
63
|
+
registerPort(PROJECT_ROOT, port, PROJECT_NAME);
|
|
64
|
+
|
|
65
|
+
const localIp = getLocalIP();
|
|
66
|
+
log.info(`HTTP + SSE server running on http://localhost:${port}`);
|
|
67
|
+
log.info(`Local network access: http://${localIp}:${port}`);
|
|
68
|
+
log.info(`RPC: POST http://localhost:${port}/api/rpc (auth required)`);
|
|
69
|
+
log.info(`SSE: GET http://localhost:${port}/api/events (auth required)`);
|
|
70
|
+
log.info(`Available RPC methods: ${discoverMethodNames().join(", ")}`);
|
|
71
|
+
log.info("File endpoints: GET /file/{path}, GET /info/{path}");
|
|
72
|
+
log.info(formatRegistryForOutput());
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
start().catch((err) => {
|
|
76
|
+
log.error("Server failed to start", { error: err.message });
|
|
77
|
+
process.exit(1);
|
|
78
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { unlink } from "fs/promises";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
|
|
7
|
+
vi.mock("../../lib/logger", () => ({
|
|
8
|
+
createLogger: () => ({
|
|
9
|
+
info: vi.fn(),
|
|
10
|
+
error: vi.fn(),
|
|
11
|
+
warn: vi.fn(),
|
|
12
|
+
debug: vi.fn(),
|
|
13
|
+
}),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
function createMockServer() {
|
|
17
|
+
const handlers = new Map<string, (params: unknown) => Promise<unknown>>();
|
|
18
|
+
return {
|
|
19
|
+
register: vi.fn((method: string, handler: (params: unknown) => Promise<unknown>) => {
|
|
20
|
+
handlers.set(method, handler);
|
|
21
|
+
}),
|
|
22
|
+
emitEvent: vi.fn(),
|
|
23
|
+
handlers,
|
|
24
|
+
async call(method: string, params: unknown) {
|
|
25
|
+
const h = handlers.get(method);
|
|
26
|
+
if (!h) throw new Error(`No handler for ${method}`);
|
|
27
|
+
return h(params);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const DESKTOP_HISTORY_PATH = join(homedir(), ".pi-agent", "chat-history-desktop.json");
|
|
33
|
+
|
|
34
|
+
describe("Chat Handler 并发安全", () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
vi.resetModules();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(async () => {
|
|
40
|
+
if (existsSync(DESKTOP_HISTORY_PATH)) {
|
|
41
|
+
await unlink(DESKTOP_HISTORY_PATH).catch(() => {});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("两个独立的 RPCServer 应注册各自的 handler", async () => {
|
|
46
|
+
const { register } = await import("../chat");
|
|
47
|
+
const serverA = createMockServer();
|
|
48
|
+
const serverB = createMockServer();
|
|
49
|
+
|
|
50
|
+
register(serverA as any, { platform: "desktop" });
|
|
51
|
+
register(serverB as any, { platform: "web" });
|
|
52
|
+
|
|
53
|
+
expect(serverA.register).toHaveBeenCalledWith("chat.list", expect.any(Function));
|
|
54
|
+
expect(serverA.register).toHaveBeenCalledWith("chat.send", expect.any(Function));
|
|
55
|
+
expect(serverB.register).toHaveBeenCalledWith("chat.list", expect.any(Function));
|
|
56
|
+
expect(serverB.register).toHaveBeenCalledWith("chat.send", expect.any(Function));
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("server A 的消息不影响 server B 的消息列表", async () => {
|
|
60
|
+
const { register } = await import("../chat");
|
|
61
|
+
const serverA = createMockServer();
|
|
62
|
+
const serverB = createMockServer();
|
|
63
|
+
|
|
64
|
+
register(serverA as any, { platform: "desktop" });
|
|
65
|
+
register(serverB as any, { platform: "web" });
|
|
66
|
+
|
|
67
|
+
await serverA.call("chat.send", { content: "hello from desktop" });
|
|
68
|
+
await serverB.call("chat.send", { content: "hello from web" });
|
|
69
|
+
|
|
70
|
+
const resultA = (await serverA.call("chat.list", { limit: 50 })) as {
|
|
71
|
+
messages: { content: string }[];
|
|
72
|
+
};
|
|
73
|
+
const resultB = (await serverB.call("chat.list", { limit: 50 })) as {
|
|
74
|
+
messages: { content: string }[];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const desktopContents = resultA.messages.map((m) => m.content);
|
|
78
|
+
const webContents = resultB.messages.map((m) => m.content);
|
|
79
|
+
|
|
80
|
+
expect(desktopContents).toContain("hello from desktop");
|
|
81
|
+
expect(webContents).toContain("hello from web");
|
|
82
|
+
expect(desktopContents).not.toContain("hello from web");
|
|
83
|
+
expect(webContents).not.toContain("hello from desktop");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("同一 server 内的消息按顺序写入", async () => {
|
|
87
|
+
const { register } = await import("../chat");
|
|
88
|
+
const server = createMockServer();
|
|
89
|
+
register(server as any, { platform: "desktop" });
|
|
90
|
+
|
|
91
|
+
await server.call("chat.send", { content: "msg1" });
|
|
92
|
+
await server.call("chat.send", { content: "msg2" });
|
|
93
|
+
await server.call("chat.send", { content: "msg3" });
|
|
94
|
+
|
|
95
|
+
const result = (await server.call("chat.list", { limit: 50 })) as {
|
|
96
|
+
messages: { role: string; content: string }[];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const userMsgs = result.messages.filter((m) => m.role === "user").map((m) => m.content);
|
|
100
|
+
expect(userMsgs).toEqual(["msg1", "msg2", "msg3"]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("存储路径应包含平台标识(desktop/web)或唯一 ID", async () => {
|
|
104
|
+
const { getStoragePathFor } = await import("../chat");
|
|
105
|
+
const desktopPath = getStoragePathFor("desktop");
|
|
106
|
+
const webPath = getStoragePathFor("web");
|
|
107
|
+
|
|
108
|
+
expect(desktopPath).toContain("desktop");
|
|
109
|
+
expect(webPath).not.toBe(desktopPath);
|
|
110
|
+
expect(webPath).toMatch(/web/);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("desktop 使用固定路径保留历史", async () => {
|
|
114
|
+
const { getStoragePathFor } = await import("../chat");
|
|
115
|
+
const path1 = getStoragePathFor("desktop");
|
|
116
|
+
const path2 = getStoragePathFor("desktop");
|
|
117
|
+
expect(path1).toBe(path2);
|
|
118
|
+
expect(path1).toContain("chat-history-desktop.json");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("web 每次生成不同的路径", async () => {
|
|
122
|
+
const { getStoragePathFor } = await import("../chat");
|
|
123
|
+
const path1 = getStoragePathFor("web");
|
|
124
|
+
const path2 = getStoragePathFor("web");
|
|
125
|
+
expect(path1).not.toBe(path2);
|
|
126
|
+
});
|
|
127
|
+
});
|