@dyyz1993/create-agent 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +25 -0
- package/src/__tests__/cli.test.ts +85 -0
- package/src/__tests__/copy.test.ts +168 -0
- package/src/__tests__/templates.test.ts +87 -0
- package/src/cli.ts +65 -0
- package/src/commands/create.ts +49 -0
- package/src/commands/list.ts +12 -0
- package/src/commands/status.ts +85 -0
- package/src/commands/workspace.ts +129 -0
- package/src/lib/copy.ts +285 -0
- package/src/lib/templates.ts +57 -0
- package/src/lib/types.ts +6 -0
- package/templates/agent/.env.example +7 -0
- package/templates/agent/LICENSE +21 -0
- package/templates/agent/README.md +87 -0
- package/templates/agent/bun.lock +1279 -0
- package/templates/agent/electrobun.config.ts +27 -0
- package/templates/agent/eslint.config.mjs +63 -0
- package/templates/agent/llms.txt +24 -0
- package/templates/agent/package-lock.json +3670 -0
- package/templates/agent/package.json +59 -0
- package/templates/agent/postcss.config.js +6 -0
- package/templates/agent/scripts/dev.ts +138 -0
- package/templates/agent/src/__tests__/server-config.test.ts +59 -0
- package/templates/agent/src/bun/index.ts +73 -0
- package/templates/agent/src/gateway/__tests__/ws-handler.test.ts +48 -0
- package/templates/agent/src/gateway/http-routes.ts +1 -0
- package/templates/agent/src/gateway/ipc-transport.ts +68 -0
- package/templates/agent/src/gateway/ws-handler.ts +86 -0
- package/templates/agent/src/mainview/App.tsx +41 -0
- package/templates/agent/src/mainview/__tests__/components/ChatPanel.test.tsx +114 -0
- package/templates/agent/src/mainview/__tests__/components/ExplorerSidebar.test.tsx +141 -0
- package/templates/agent/src/mainview/__tests__/components/MessageBubble.test.tsx +72 -0
- package/templates/agent/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +217 -0
- package/templates/agent/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/agent/src/mainview/__tests__/i18n/i18n.test.ts +48 -0
- package/templates/agent/src/mainview/__tests__/setup.ts +37 -0
- package/templates/agent/src/mainview/__tests__/stores/use-chat-store.test.ts +83 -0
- package/templates/agent/src/mainview/__tests__/stores/use-sidebar-store.test.ts +85 -0
- package/templates/agent/src/mainview/components/activity-bar/ActivityBar.tsx +36 -0
- package/templates/agent/src/mainview/components/activity-bar/MobileTabBar.tsx +36 -0
- package/templates/agent/src/mainview/components/activity-bar/__tests__/ActivityBar.test.tsx +44 -0
- package/templates/agent/src/mainview/components/activity-bar/__tests__/MobileTabBar.test.tsx +44 -0
- package/templates/agent/src/mainview/components/bash/BashPanel.tsx +206 -0
- package/templates/agent/src/mainview/components/bash/__tests__/BashPanel.test.tsx +103 -0
- package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +102 -0
- package/templates/agent/src/mainview/components/chat/MessageBubble.tsx +86 -0
- package/templates/agent/src/mainview/components/common/ErrorBoundary.tsx +58 -0
- package/templates/agent/src/mainview/components/common/LanguageSwitcher.tsx +14 -0
- package/templates/agent/src/mainview/components/common/ThemeToggle.tsx +24 -0
- package/templates/agent/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/agent/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/agent/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/agent/src/mainview/components/debug/DebugPanel.tsx +120 -0
- package/templates/agent/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +102 -0
- package/templates/agent/src/mainview/components/diff/DiffViewerPanel.tsx +106 -0
- package/templates/agent/src/mainview/components/diff/__tests__/DiffViewerPanel.test.tsx +73 -0
- package/templates/agent/src/mainview/components/explorer/ConfirmDialog.tsx +53 -0
- package/templates/agent/src/mainview/components/explorer/ContextMenu.tsx +82 -0
- package/templates/agent/src/mainview/components/explorer/ExplorerSidebar.tsx +221 -0
- package/templates/agent/src/mainview/components/explorer/InlineInput.tsx +55 -0
- package/templates/agent/src/mainview/components/explorer/TreeNodeItem.tsx +121 -0
- package/templates/agent/src/mainview/components/explorer/__tests__/ConfirmDialog.test.tsx +37 -0
- package/templates/agent/src/mainview/components/explorer/__tests__/ContextMenu.test.tsx +49 -0
- package/templates/agent/src/mainview/components/explorer/__tests__/InlineInput.test.tsx +48 -0
- package/templates/agent/src/mainview/components/explorer/__tests__/TreeNodeItem.test.tsx +146 -0
- package/templates/agent/src/mainview/components/feed/FeedPanel.tsx +239 -0
- package/templates/agent/src/mainview/components/feed/__tests__/FeedPanel.test.tsx +108 -0
- package/templates/agent/src/mainview/components/file-preview/FilePreviewOverlay.tsx +56 -0
- package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +99 -0
- package/templates/agent/src/mainview/components/file-preview/__tests__/FilePreviewOverlay.test.tsx +96 -0
- package/templates/agent/src/mainview/components/file-preview/__tests__/VirtualizedCodeView.test.tsx +58 -0
- package/templates/agent/src/mainview/components/git/GitBranchSelector.tsx +98 -0
- package/templates/agent/src/mainview/components/git/GitCommitInput.tsx +60 -0
- package/templates/agent/src/mainview/components/git/GitPanel.tsx +528 -0
- package/templates/agent/src/mainview/components/git/__tests__/GitBranchSelector.test.tsx +76 -0
- package/templates/agent/src/mainview/components/git/__tests__/GitCommitInput.test.tsx +91 -0
- package/templates/agent/src/mainview/components/git/__tests__/GitPanel.test.tsx +174 -0
- package/templates/agent/src/mainview/components/layout/AppLayout.tsx +170 -0
- package/templates/agent/src/mainview/components/layout/__tests__/AppLayout.test.tsx +163 -0
- package/templates/agent/src/mainview/components/rules/RulesPanel.tsx +117 -0
- package/templates/agent/src/mainview/components/rules/__tests__/RulesPanel.test.tsx +91 -0
- package/templates/agent/src/mainview/components/search/SearchPanel.tsx +404 -0
- package/templates/agent/src/mainview/components/search/__tests__/SearchPanel.test.tsx +50 -0
- package/templates/agent/src/mainview/components/sidebar/PinButton.tsx +20 -0
- package/templates/agent/src/mainview/components/sidebar/__tests__/PinButton.test.tsx +48 -0
- package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +141 -0
- package/templates/agent/src/mainview/components/todo/__tests__/TodoPanel.test.tsx +91 -0
- package/templates/agent/src/mainview/global.d.ts +13 -0
- package/templates/agent/src/mainview/hooks/__tests__/use-breakpoint.test.ts +147 -0
- package/templates/agent/src/mainview/hooks/use-breakpoint.ts +34 -0
- package/templates/agent/src/mainview/hooks/use-input-history.ts +84 -0
- package/templates/agent/src/mainview/hooks/use-rpc-init.ts +61 -0
- package/templates/agent/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/agent/src/mainview/index.css +61 -0
- package/templates/agent/src/mainview/index.html +12 -0
- package/templates/agent/src/mainview/lib/api-client.ts +192 -0
- package/templates/agent/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/agent/src/mainview/lib/i18n/locales/en.json +157 -0
- package/templates/agent/src/mainview/lib/i18n/locales/zh.json +157 -0
- package/templates/agent/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/agent/src/mainview/main.tsx +24 -0
- package/templates/agent/src/mainview/stores/__tests__/use-app-store.test.ts +86 -0
- package/templates/agent/src/mainview/stores/__tests__/use-bash-store.test.ts +99 -0
- package/templates/agent/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/agent/src/mainview/stores/__tests__/use-explorer-store.test.ts +130 -0
- package/templates/agent/src/mainview/stores/__tests__/use-feed-store.test.ts +132 -0
- package/templates/agent/src/mainview/stores/__tests__/use-git-store.test.ts +161 -0
- package/templates/agent/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/agent/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/agent/src/mainview/stores/__tests__/use-notification-store.test.ts +102 -0
- package/templates/agent/src/mainview/stores/__tests__/use-rules-store.test.ts +75 -0
- package/templates/agent/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/agent/src/mainview/stores/__tests__/use-todo-store.test.ts +75 -0
- package/templates/agent/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/agent/src/mainview/stores/use-app-store.ts +99 -0
- package/templates/agent/src/mainview/stores/use-bash-store.ts +93 -0
- package/templates/agent/src/mainview/stores/use-chat-store.ts +37 -0
- package/templates/agent/src/mainview/stores/use-connection-store.ts +42 -0
- package/templates/agent/src/mainview/stores/use-explorer-store.ts +320 -0
- package/templates/agent/src/mainview/stores/use-feed-store.ts +129 -0
- package/templates/agent/src/mainview/stores/use-git-store.ts +291 -0
- package/templates/agent/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/agent/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/agent/src/mainview/stores/use-notification-store.ts +82 -0
- package/templates/agent/src/mainview/stores/use-rules-store.ts +54 -0
- package/templates/agent/src/mainview/stores/use-sidebar-store.ts +99 -0
- package/templates/agent/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/agent/src/mainview/stores/use-todo-store.ts +54 -0
- package/templates/agent/src/mainview/types/index.ts +33 -0
- package/templates/agent/src/mainview/utils/constants.ts +1 -0
- package/templates/agent/src/mainview/utils/drop-handler.ts +150 -0
- package/templates/agent/src/mainview/utils/file-icon.tsx +24 -0
- package/templates/agent/src/mainview/utils/file-utils.ts +35 -0
- package/templates/agent/src/server-config.ts +43 -0
- package/templates/agent/src/server.ts +89 -0
- package/templates/agent/src/shared/handlers/__tests__/bash-handler.test.ts +135 -0
- package/templates/agent/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/agent/src/shared/handlers/__tests__/feed-handler.test.ts +108 -0
- package/templates/agent/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/agent/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/agent/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/agent/src/shared/handlers/bash.ts +89 -0
- package/templates/agent/src/shared/handlers/chat.ts +179 -0
- package/templates/agent/src/shared/handlers/feed.ts +53 -0
- package/templates/agent/src/shared/handlers/file.ts +99 -0
- package/templates/agent/src/shared/handlers/git.ts +263 -0
- package/templates/agent/src/shared/handlers/index.ts +10 -0
- package/templates/agent/src/shared/handlers/rules.ts +45 -0
- package/templates/agent/src/shared/handlers/system.ts +27 -0
- package/templates/agent/src/shared/handlers/timer.ts +34 -0
- package/templates/agent/src/shared/handlers/todo.ts +45 -0
- package/templates/agent/src/shared/lib/__tests__/bash-security.test.ts +125 -0
- package/templates/agent/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/agent/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/agent/src/shared/lib/bash-security.ts +64 -0
- package/templates/agent/src/shared/lib/logger.ts +130 -0
- package/templates/agent/src/shared/lib/path-security.ts +38 -0
- package/templates/agent/src/shared/lib/port-registry.ts +103 -0
- package/templates/agent/src/shared/modules/bash.ts +19 -0
- package/templates/agent/src/shared/modules/chat.ts +20 -0
- package/templates/agent/src/shared/modules/feed.ts +30 -0
- package/templates/agent/src/shared/modules/file.ts +40 -0
- package/templates/agent/src/shared/modules/git.ts +81 -0
- package/templates/agent/src/shared/modules/rules.ts +25 -0
- package/templates/agent/src/shared/modules/system.ts +8 -0
- package/templates/agent/src/shared/modules/timer.ts +11 -0
- package/templates/agent/src/shared/modules/todo.ts +27 -0
- package/templates/agent/src/shared/register-all-handlers.ts +36 -0
- package/templates/agent/src/shared/rpc-schema.ts +35 -0
- package/templates/agent/tailwind.config.js +15 -0
- package/templates/agent/tsconfig.json +26 -0
- package/templates/agent/vite.config.ts +3 -0
- package/templates/agent/vitest.config.ts +3 -0
- package/templates/chat/.env.example +6 -0
- package/templates/chat/LICENSE +21 -0
- package/templates/chat/README.md +56 -0
- package/templates/chat/bun.lock +1203 -0
- package/templates/chat/electrobun.config.ts +27 -0
- package/templates/chat/eslint.config.mjs +56 -0
- package/templates/chat/llms.txt +24 -0
- package/templates/chat/package-lock.json +3670 -0
- package/templates/chat/package.json +58 -0
- package/templates/chat/postcss.config.js +6 -0
- package/templates/chat/scripts/dev.ts +138 -0
- package/templates/chat/src/__tests__/server-config.test.ts +59 -0
- package/templates/chat/src/bun/index.ts +72 -0
- package/templates/chat/src/gateway/__tests__/ws-handler.test.ts +48 -0
- package/templates/chat/src/gateway/http-routes.ts +1 -0
- package/templates/chat/src/gateway/ipc-transport.ts +68 -0
- package/templates/chat/src/gateway/ws-handler.ts +86 -0
- package/templates/chat/src/mainview/App.tsx +108 -0
- package/templates/chat/src/mainview/__tests__/components/ChatPanel.test.tsx +76 -0
- package/templates/chat/src/mainview/__tests__/components/MessageBubble.test.tsx +48 -0
- package/templates/chat/src/mainview/__tests__/i18n/i18n.test.ts +48 -0
- package/templates/chat/src/mainview/__tests__/setup-verify.test.ts +8 -0
- package/templates/chat/src/mainview/__tests__/setup.ts +37 -0
- package/templates/chat/src/mainview/__tests__/stores/use-app-store.test.ts +46 -0
- package/templates/chat/src/mainview/__tests__/stores/use-chat-store.test.ts +104 -0
- package/templates/chat/src/mainview/__tests__/stores/use-connection-store.test.ts +35 -0
- package/templates/chat/src/mainview/__tests__/stores/use-log-store.test.ts +45 -0
- package/templates/chat/src/mainview/__tests__/stores/use-notification-store.test.ts +102 -0
- package/templates/chat/src/mainview/__tests__/stores/use-sidebar-store.test.ts +89 -0
- package/templates/chat/src/mainview/components/activity-bar/ActivityBar.tsx +26 -0
- package/templates/chat/src/mainview/components/activity-bar/MobileTabBar.tsx +20 -0
- package/templates/chat/src/mainview/components/chat/ChatPanel.tsx +66 -0
- package/templates/chat/src/mainview/components/chat/MessageBubble.tsx +85 -0
- package/templates/chat/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/chat/src/mainview/components/common/ThemeToggle.tsx +24 -0
- package/templates/chat/src/mainview/components/sidebar/PinButton.tsx +20 -0
- package/templates/chat/src/mainview/global.d.ts +13 -0
- package/templates/chat/src/mainview/hooks/use-breakpoint.ts +34 -0
- package/templates/chat/src/mainview/hooks/use-input-history.ts +84 -0
- package/templates/chat/src/mainview/index.css +61 -0
- package/templates/chat/src/mainview/index.html +12 -0
- package/templates/chat/src/mainview/lib/api-client.ts +175 -0
- package/templates/chat/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/chat/src/mainview/lib/i18n/locales/en.json +157 -0
- package/templates/chat/src/mainview/lib/i18n/locales/zh.json +157 -0
- package/templates/chat/src/mainview/main.tsx +20 -0
- package/templates/chat/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/chat/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/chat/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/chat/src/mainview/stores/use-app-store.ts +50 -0
- package/templates/chat/src/mainview/stores/use-chat-store.ts +37 -0
- package/templates/chat/src/mainview/stores/use-connection-store.ts +42 -0
- package/templates/chat/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/chat/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/chat/src/mainview/stores/use-notification-store.ts +82 -0
- package/templates/chat/src/mainview/stores/use-sidebar-store.ts +98 -0
- package/templates/chat/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/chat/src/mainview/types/index.ts +8 -0
- package/templates/chat/src/mainview/utils/constants.ts +1 -0
- package/templates/chat/src/server-config.ts +42 -0
- package/templates/chat/src/server.ts +89 -0
- package/templates/chat/src/shared/__tests__/chat-handler.test.ts +71 -0
- package/templates/chat/src/shared/__tests__/system-handler.test.ts +70 -0
- package/templates/chat/src/shared/handlers/chat.ts +186 -0
- package/templates/chat/src/shared/handlers/index.ts +2 -0
- package/templates/chat/src/shared/handlers/system.ts +27 -0
- package/templates/chat/src/shared/lib/logger.ts +130 -0
- package/templates/chat/src/shared/lib/path-security.ts +38 -0
- package/templates/chat/src/shared/lib/port-registry.ts +103 -0
- package/templates/chat/src/shared/modules/chat.ts +20 -0
- package/templates/chat/src/shared/modules/system.ts +8 -0
- package/templates/chat/src/shared/register-all-handlers.ts +36 -0
- package/templates/chat/src/shared/rpc-schema.ts +11 -0
- package/templates/chat/tailwind.config.js +15 -0
- package/templates/chat/tsconfig.json +26 -0
- package/templates/chat/vite.config.ts +3 -0
- package/templates/chat/vitest.config.ts +3 -0
- package/templates/general/.env.example +7 -0
- package/templates/general/LICENSE +21 -0
- package/templates/general/README.md +113 -0
- package/templates/general/bun.lock +1266 -0
- package/templates/general/electrobun.config.ts +27 -0
- package/templates/general/eslint.config.mjs +56 -0
- package/templates/general/llms.txt +24 -0
- package/templates/general/package-lock.json +3670 -0
- package/templates/general/package.json +59 -0
- package/templates/general/postcss.config.js +6 -0
- package/templates/general/scripts/dev.ts +138 -0
- package/templates/general/src/__tests__/server-config.test.ts +59 -0
- package/templates/general/src/bun/index.ts +72 -0
- package/templates/general/src/gateway/http-routes.ts +1 -0
- package/templates/general/src/gateway/ipc-transport.ts +68 -0
- package/templates/general/src/gateway/ws-handler.ts +86 -0
- package/templates/general/src/mainview/App.tsx +40 -0
- package/templates/general/src/mainview/__tests__/components/ChatPanel.test.tsx +82 -0
- package/templates/general/src/mainview/__tests__/components/FeedPanel.test.tsx +109 -0
- package/templates/general/src/mainview/__tests__/components/GitPanel.test.tsx +151 -0
- package/templates/general/src/mainview/__tests__/i18n/i18n.test.ts +48 -0
- package/templates/general/src/mainview/__tests__/setup-verify.test.ts +8 -0
- package/templates/general/src/mainview/__tests__/setup.ts +37 -0
- package/templates/general/src/mainview/components/activity-bar/ActivityBar.tsx +40 -0
- package/templates/general/src/mainview/components/activity-bar/MobileTabBar.tsx +29 -0
- package/templates/general/src/mainview/components/chat/ChatPanel.tsx +66 -0
- package/templates/general/src/mainview/components/chat/MessageBubble.tsx +85 -0
- package/templates/general/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/general/src/mainview/components/common/ThemeToggle.tsx +24 -0
- package/templates/general/src/mainview/components/debug/DebugPanel.tsx +176 -0
- package/templates/general/src/mainview/components/diff/DiffViewerPanel.tsx +108 -0
- package/templates/general/src/mainview/components/explorer/ConfirmDialog.tsx +52 -0
- package/templates/general/src/mainview/components/explorer/ContextMenu.tsx +82 -0
- package/templates/general/src/mainview/components/explorer/ExplorerSidebar.tsx +225 -0
- package/templates/general/src/mainview/components/explorer/InlineInput.tsx +55 -0
- package/templates/general/src/mainview/components/explorer/TreeNodeItem.tsx +121 -0
- package/templates/general/src/mainview/components/feed/FeedPanel.tsx +248 -0
- package/templates/general/src/mainview/components/file-preview/FilePreviewOverlay.tsx +55 -0
- package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +99 -0
- package/templates/general/src/mainview/components/git/GitBranchSelector.tsx +93 -0
- package/templates/general/src/mainview/components/git/GitCommitInput.tsx +60 -0
- package/templates/general/src/mainview/components/git/GitPanel.tsx +533 -0
- package/templates/general/src/mainview/components/layout/AppLayout.tsx +146 -0
- package/templates/general/src/mainview/components/search/SearchPanel.tsx +405 -0
- package/templates/general/src/mainview/components/sidebar/PinButton.tsx +20 -0
- package/templates/general/src/mainview/global.d.ts +13 -0
- package/templates/general/src/mainview/hooks/use-breakpoint.ts +34 -0
- package/templates/general/src/mainview/hooks/use-input-history.ts +84 -0
- package/templates/general/src/mainview/hooks/use-rpc-init.ts +61 -0
- package/templates/general/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/general/src/mainview/index.css +61 -0
- package/templates/general/src/mainview/index.html +12 -0
- package/templates/general/src/mainview/lib/api-client.ts +175 -0
- package/templates/general/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/general/src/mainview/lib/i18n/locales/en.json +157 -0
- package/templates/general/src/mainview/lib/i18n/locales/zh.json +157 -0
- package/templates/general/src/mainview/main.tsx +20 -0
- package/templates/general/src/mainview/stores/__tests__/use-chat-store.test.ts +104 -0
- package/templates/general/src/mainview/stores/__tests__/use-connection-store.test.ts +35 -0
- package/templates/general/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/general/src/mainview/stores/__tests__/use-log-store.test.ts +45 -0
- package/templates/general/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/general/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/general/src/mainview/stores/use-app-store.ts +104 -0
- package/templates/general/src/mainview/stores/use-chat-store.ts +37 -0
- package/templates/general/src/mainview/stores/use-connection-store.ts +42 -0
- package/templates/general/src/mainview/stores/use-explorer-store.ts +315 -0
- package/templates/general/src/mainview/stores/use-feed-store.ts +129 -0
- package/templates/general/src/mainview/stores/use-git-store.ts +284 -0
- package/templates/general/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/general/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/general/src/mainview/stores/use-notification-store.ts +82 -0
- package/templates/general/src/mainview/stores/use-sidebar-store.ts +99 -0
- package/templates/general/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/general/src/mainview/types/index.ts +33 -0
- package/templates/general/src/mainview/utils/constants.ts +1 -0
- package/templates/general/src/mainview/utils/drop-handler.ts +150 -0
- package/templates/general/src/mainview/utils/file-icon.tsx +24 -0
- package/templates/general/src/mainview/utils/file-utils.ts +35 -0
- package/templates/general/src/server-config.ts +42 -0
- package/templates/general/src/server.ts +89 -0
- package/templates/general/src/shared/handlers/__tests__/chat.test.ts +183 -0
- package/templates/general/src/shared/handlers/__tests__/system.test.ts +94 -0
- package/templates/general/src/shared/handlers/__tests__/timer.test.ts +113 -0
- package/templates/general/src/shared/handlers/chat.ts +179 -0
- package/templates/general/src/shared/handlers/feed.ts +53 -0
- package/templates/general/src/shared/handlers/file.ts +99 -0
- package/templates/general/src/shared/handlers/git.ts +263 -0
- package/templates/general/src/shared/handlers/index.ts +7 -0
- package/templates/general/src/shared/handlers/system.ts +27 -0
- package/templates/general/src/shared/handlers/timer.ts +34 -0
- package/templates/general/src/shared/lib/logger.ts +130 -0
- package/templates/general/src/shared/lib/path-security.ts +38 -0
- package/templates/general/src/shared/lib/port-registry.ts +103 -0
- package/templates/general/src/shared/modules/chat.ts +20 -0
- package/templates/general/src/shared/modules/feed.ts +30 -0
- package/templates/general/src/shared/modules/file.ts +40 -0
- package/templates/general/src/shared/modules/git.ts +81 -0
- package/templates/general/src/shared/modules/system.ts +8 -0
- package/templates/general/src/shared/modules/timer.ts +11 -0
- package/templates/general/src/shared/register-all-handlers.ts +36 -0
- package/templates/general/src/shared/rpc-schema.ts +31 -0
- package/templates/general/tailwind.config.js +15 -0
- package/templates/general/tsconfig.json +26 -0
- package/templates/general/vite.config.ts +3 -0
- package/templates/general/vitest.config.ts +3 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import { apiClient } from "../lib/api-client";
|
|
3
|
+
import { useLogStore } from "./use-log-store";
|
|
4
|
+
|
|
5
|
+
export interface GitFileChange {
|
|
6
|
+
path: string;
|
|
7
|
+
status: "modified" | "added" | "deleted" | "renamed" | "copied";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface GitCommit {
|
|
11
|
+
hash: string;
|
|
12
|
+
shortHash: string;
|
|
13
|
+
message: string;
|
|
14
|
+
author: string;
|
|
15
|
+
date: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GitBranch {
|
|
19
|
+
name: string;
|
|
20
|
+
isCurrent: boolean;
|
|
21
|
+
isRemote: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface GitWorktree {
|
|
25
|
+
path: string;
|
|
26
|
+
branch: string;
|
|
27
|
+
isMain: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface GitState {
|
|
31
|
+
branch: string;
|
|
32
|
+
ahead: number;
|
|
33
|
+
behind: number;
|
|
34
|
+
staged: GitFileChange[];
|
|
35
|
+
changed: GitFileChange[];
|
|
36
|
+
untracked: string[];
|
|
37
|
+
commits: GitCommit[];
|
|
38
|
+
loadingCommits: boolean;
|
|
39
|
+
currentDiff: { filePath: string; diff: string; oldContent: string; newContent: string } | null;
|
|
40
|
+
loadingDiff: boolean;
|
|
41
|
+
expandedCommits: Set<string>;
|
|
42
|
+
commitFiles: Record<string, GitFileChange[]>;
|
|
43
|
+
loadingCommitFiles: Set<string>;
|
|
44
|
+
branches: GitBranch[];
|
|
45
|
+
loadingBranches: boolean;
|
|
46
|
+
worktrees: GitWorktree[];
|
|
47
|
+
loadingAction: string | null;
|
|
48
|
+
|
|
49
|
+
fetchStatus: (repoPath: string) => Promise<void>;
|
|
50
|
+
fetchDiff: (repoPath: string, filePath: string, staged?: boolean) => Promise<void>;
|
|
51
|
+
fetchLog: (repoPath: string) => Promise<void>;
|
|
52
|
+
clearDiff: () => void;
|
|
53
|
+
toggleCommitExpand: (repoPath: string, hash: string) => Promise<void>;
|
|
54
|
+
fetchCommitFileDiff: (repoPath: string, hash: string, filePath: string) => Promise<void>;
|
|
55
|
+
fetchBranches: (repoPath: string) => Promise<void>;
|
|
56
|
+
checkout: (repoPath: string, branch: string) => Promise<void>;
|
|
57
|
+
stageFiles: (repoPath: string, paths: string[]) => Promise<void>;
|
|
58
|
+
unstageFiles: (repoPath: string, paths: string[]) => Promise<void>;
|
|
59
|
+
commit: (repoPath: string, message: string) => Promise<void>;
|
|
60
|
+
push: (repoPath: string) => Promise<void>;
|
|
61
|
+
pull: (repoPath: string) => Promise<void>;
|
|
62
|
+
fetchWorktrees: (repoPath: string) => Promise<void>;
|
|
63
|
+
refresh: (repoPath: string) => Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const useGitStore = create<GitState>((set, get) => ({
|
|
67
|
+
branch: "",
|
|
68
|
+
ahead: 0,
|
|
69
|
+
behind: 0,
|
|
70
|
+
staged: [],
|
|
71
|
+
changed: [],
|
|
72
|
+
untracked: [],
|
|
73
|
+
commits: [],
|
|
74
|
+
loadingCommits: false,
|
|
75
|
+
currentDiff: null,
|
|
76
|
+
loadingDiff: false,
|
|
77
|
+
expandedCommits: new Set(),
|
|
78
|
+
commitFiles: {},
|
|
79
|
+
loadingCommitFiles: new Set(),
|
|
80
|
+
branches: [],
|
|
81
|
+
loadingBranches: false,
|
|
82
|
+
worktrees: [],
|
|
83
|
+
loadingAction: null,
|
|
84
|
+
|
|
85
|
+
refresh: async (repoPath) => {
|
|
86
|
+
await get().fetchStatus(repoPath);
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
fetchStatus: async (repoPath) => {
|
|
90
|
+
const addLog = useLogStore.getState().addLog;
|
|
91
|
+
try {
|
|
92
|
+
const res = await apiClient.call("git.status", { repoPath });
|
|
93
|
+
set({
|
|
94
|
+
branch: res.branch,
|
|
95
|
+
ahead: res.ahead,
|
|
96
|
+
behind: res.behind,
|
|
97
|
+
staged: res.staged,
|
|
98
|
+
changed: res.changed,
|
|
99
|
+
untracked: res.untracked,
|
|
100
|
+
});
|
|
101
|
+
} catch (err) {
|
|
102
|
+
addLog(`Git status error: ${err instanceof Error ? err.message : String(err)}`);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
fetchDiff: async (repoPath, filePath, staged) => {
|
|
107
|
+
const addLog = useLogStore.getState().addLog;
|
|
108
|
+
addLog(`Git diff: ${filePath}`);
|
|
109
|
+
set({ loadingDiff: true });
|
|
110
|
+
try {
|
|
111
|
+
const res = await apiClient.call("git.diff", { repoPath, filePath, staged });
|
|
112
|
+
addLog(`Git diff result: ${res.diff.length} chars`);
|
|
113
|
+
set({ currentDiff: res, loadingDiff: false });
|
|
114
|
+
} catch (err) {
|
|
115
|
+
addLog(`Git diff error: ${err instanceof Error ? err.message : String(err)}`);
|
|
116
|
+
set({ loadingDiff: false });
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
fetchLog: async (repoPath) => {
|
|
121
|
+
set({ loadingCommits: true });
|
|
122
|
+
try {
|
|
123
|
+
const res = await apiClient.call("git.log", { repoPath, maxCount: 50 });
|
|
124
|
+
set({ commits: res.commits, loadingCommits: false });
|
|
125
|
+
} catch (err) {
|
|
126
|
+
const addLog = useLogStore.getState().addLog;
|
|
127
|
+
addLog(`Git log error: ${err instanceof Error ? err.message : String(err)}`);
|
|
128
|
+
set({ loadingCommits: false });
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
clearDiff: () => set({ currentDiff: null }),
|
|
133
|
+
|
|
134
|
+
toggleCommitExpand: async (repoPath, hash) => {
|
|
135
|
+
const { expandedCommits, commitFiles } = get();
|
|
136
|
+
const next = new Set(expandedCommits);
|
|
137
|
+
|
|
138
|
+
if (next.has(hash)) {
|
|
139
|
+
next.delete(hash);
|
|
140
|
+
set({ expandedCommits: next });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
next.add(hash);
|
|
145
|
+
set({ expandedCommits: next });
|
|
146
|
+
|
|
147
|
+
if (!commitFiles[hash]) {
|
|
148
|
+
const loading = new Set(get().loadingCommitFiles);
|
|
149
|
+
loading.add(hash);
|
|
150
|
+
set({ loadingCommitFiles: loading });
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
const res = await apiClient.call("git.commitFiles", { repoPath, hash });
|
|
154
|
+
set({ commitFiles: { ...get().commitFiles, [hash]: res.files } });
|
|
155
|
+
} catch (err) {
|
|
156
|
+
const addLog = useLogStore.getState().addLog;
|
|
157
|
+
addLog(`Git commitFiles error: ${err instanceof Error ? err.message : String(err)}`);
|
|
158
|
+
} finally {
|
|
159
|
+
const loading = new Set(get().loadingCommitFiles);
|
|
160
|
+
loading.delete(hash);
|
|
161
|
+
set({ loadingCommitFiles: loading });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
fetchCommitFileDiff: async (repoPath, hash, filePath) => {
|
|
167
|
+
const addLog = useLogStore.getState().addLog;
|
|
168
|
+
addLog(`Git commit diff: ${hash.slice(0, 7)} ${filePath}`);
|
|
169
|
+
set({ loadingDiff: true });
|
|
170
|
+
try {
|
|
171
|
+
const res = await apiClient.call("git.commitFileDiff", { repoPath, hash, filePath });
|
|
172
|
+
set({ currentDiff: res, loadingDiff: false });
|
|
173
|
+
} catch (err) {
|
|
174
|
+
addLog(`Git commitFileDiff error: ${err instanceof Error ? err.message : String(err)}`);
|
|
175
|
+
set({ loadingDiff: false });
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
fetchBranches: async (repoPath) => {
|
|
180
|
+
set({ loadingBranches: true });
|
|
181
|
+
try {
|
|
182
|
+
const res = await apiClient.call("git.branches", { repoPath });
|
|
183
|
+
set({ branches: res.branches, loadingBranches: false });
|
|
184
|
+
} catch (err) {
|
|
185
|
+
const addLog = useLogStore.getState().addLog;
|
|
186
|
+
addLog(`Git branches error: ${err instanceof Error ? err.message : String(err)}`);
|
|
187
|
+
set({ loadingBranches: false });
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
checkout: async (repoPath, branch) => {
|
|
192
|
+
const addLog = useLogStore.getState().addLog;
|
|
193
|
+
set({ loadingAction: "checkout" });
|
|
194
|
+
try {
|
|
195
|
+
await apiClient.call("git.checkout", { repoPath, branch });
|
|
196
|
+
addLog(`Checked out: ${branch}`);
|
|
197
|
+
await get().refresh(repoPath);
|
|
198
|
+
} catch (err) {
|
|
199
|
+
addLog(`Git checkout error: ${err instanceof Error ? err.message : String(err)}`);
|
|
200
|
+
} finally {
|
|
201
|
+
set({ loadingAction: null });
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
stageFiles: async (repoPath, paths) => {
|
|
206
|
+
const addLog = useLogStore.getState().addLog;
|
|
207
|
+
set({ loadingAction: "stage" });
|
|
208
|
+
try {
|
|
209
|
+
await apiClient.call("git.add", { repoPath, paths });
|
|
210
|
+
addLog(`Staged: ${paths.join(", ")}`);
|
|
211
|
+
await get().refresh(repoPath);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
addLog(`Git add error: ${err instanceof Error ? err.message : String(err)}`);
|
|
214
|
+
} finally {
|
|
215
|
+
set({ loadingAction: null });
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
unstageFiles: async (repoPath, paths) => {
|
|
220
|
+
const addLog = useLogStore.getState().addLog;
|
|
221
|
+
set({ loadingAction: "unstage" });
|
|
222
|
+
try {
|
|
223
|
+
await apiClient.call("git.reset", { repoPath, paths });
|
|
224
|
+
addLog(`Unstaged: ${paths.join(", ")}`);
|
|
225
|
+
await get().refresh(repoPath);
|
|
226
|
+
} catch (err) {
|
|
227
|
+
addLog(`Git reset error: ${err instanceof Error ? err.message : String(err)}`);
|
|
228
|
+
} finally {
|
|
229
|
+
set({ loadingAction: null });
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
commit: async (repoPath, message) => {
|
|
234
|
+
const addLog = useLogStore.getState().addLog;
|
|
235
|
+
set({ loadingAction: "commit" });
|
|
236
|
+
try {
|
|
237
|
+
const res = await apiClient.call("git.commit", { repoPath, message });
|
|
238
|
+
addLog(`Committed: ${res.shortHash}`);
|
|
239
|
+
await get().refresh(repoPath);
|
|
240
|
+
} catch (err) {
|
|
241
|
+
addLog(`Git commit error: ${err instanceof Error ? err.message : String(err)}`);
|
|
242
|
+
} finally {
|
|
243
|
+
set({ loadingAction: null });
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
push: async (repoPath) => {
|
|
248
|
+
const addLog = useLogStore.getState().addLog;
|
|
249
|
+
set({ loadingAction: "push" });
|
|
250
|
+
try {
|
|
251
|
+
await apiClient.call("git.push", { repoPath });
|
|
252
|
+
addLog("Pushed successfully");
|
|
253
|
+
await get().refresh(repoPath);
|
|
254
|
+
} catch (err) {
|
|
255
|
+
addLog(`Git push error: ${err instanceof Error ? err.message : String(err)}`);
|
|
256
|
+
} finally {
|
|
257
|
+
set({ loadingAction: null });
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
pull: async (repoPath) => {
|
|
262
|
+
const addLog = useLogStore.getState().addLog;
|
|
263
|
+
set({ loadingAction: "pull" });
|
|
264
|
+
try {
|
|
265
|
+
await apiClient.call("git.pull", { repoPath });
|
|
266
|
+
addLog("Pulled successfully");
|
|
267
|
+
await get().refresh(repoPath);
|
|
268
|
+
} catch (err) {
|
|
269
|
+
addLog(`Git pull error: ${err instanceof Error ? err.message : String(err)}`);
|
|
270
|
+
} finally {
|
|
271
|
+
set({ loadingAction: null });
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
fetchWorktrees: async (repoPath) => {
|
|
276
|
+
try {
|
|
277
|
+
const res = await apiClient.call("git.worktreeList", { repoPath });
|
|
278
|
+
set({ worktrees: res.worktrees });
|
|
279
|
+
} catch (err) {
|
|
280
|
+
const addLog = useLogStore.getState().addLog;
|
|
281
|
+
addLog(`Git worktreeList error: ${err instanceof Error ? err.message : String(err)}`);
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
}));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import type { Locale } from "../lib/i18n";
|
|
3
|
+
|
|
4
|
+
interface LocaleState {
|
|
5
|
+
locale: Locale;
|
|
6
|
+
setLocale: (locale: Locale) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getInitialLocale(): Locale {
|
|
10
|
+
if (typeof window === "undefined") return "en";
|
|
11
|
+
const stored = localStorage.getItem("locale");
|
|
12
|
+
if (stored === "en" || stored === "zh") return stored;
|
|
13
|
+
const browserLang = navigator.language.toLowerCase();
|
|
14
|
+
if (browserLang.startsWith("zh")) return "zh";
|
|
15
|
+
return "en";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useLocaleStore = create<LocaleState>((set) => ({
|
|
19
|
+
locale: getInitialLocale(),
|
|
20
|
+
setLocale: (locale) => {
|
|
21
|
+
localStorage.setItem("locale", locale);
|
|
22
|
+
import("../lib/i18n").then((i18n) => {
|
|
23
|
+
i18n.default.changeLanguage(locale);
|
|
24
|
+
});
|
|
25
|
+
set({ locale });
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
|
|
3
|
+
interface LogState {
|
|
4
|
+
logs: string[];
|
|
5
|
+
addLog: (message: string) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const MAX_LOGS = 100;
|
|
9
|
+
|
|
10
|
+
export const useLogStore = create<LogState>((set) => ({
|
|
11
|
+
logs: [],
|
|
12
|
+
addLog: (message) =>
|
|
13
|
+
set((state) => ({
|
|
14
|
+
logs: [...state.logs.slice(-(MAX_LOGS - 1)), `[${new Date().toISOString().slice(11, 19)}] ${message}`],
|
|
15
|
+
})),
|
|
16
|
+
}));
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
|
|
3
|
+
export type NotificationLevel = "info" | "warning" | "error";
|
|
4
|
+
|
|
5
|
+
export interface AppNotification {
|
|
6
|
+
id: string;
|
|
7
|
+
message: string;
|
|
8
|
+
level: NotificationLevel;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
read: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface NotificationState {
|
|
15
|
+
notifications: AppNotification[];
|
|
16
|
+
panelOpen: boolean;
|
|
17
|
+
|
|
18
|
+
push: (n: Omit<AppNotification, "id" | "timestamp" | "read">) => void;
|
|
19
|
+
markRead: (id: string) => void;
|
|
20
|
+
markAllRead: () => void;
|
|
21
|
+
dismiss: (id: string) => void;
|
|
22
|
+
clearAll: () => void;
|
|
23
|
+
togglePanel: () => void;
|
|
24
|
+
setPanelOpen: (open: boolean) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const useNotificationStore = create<NotificationState>((set) => ({
|
|
28
|
+
notifications: [],
|
|
29
|
+
panelOpen: false,
|
|
30
|
+
|
|
31
|
+
push(n) {
|
|
32
|
+
const entry: AppNotification = {
|
|
33
|
+
...n,
|
|
34
|
+
id: `notif-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
35
|
+
timestamp: Date.now(),
|
|
36
|
+
read: false,
|
|
37
|
+
};
|
|
38
|
+
set((s) => ({
|
|
39
|
+
notifications: [entry, ...s.notifications],
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
if (n.level === "info") {
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
set((s) => ({
|
|
45
|
+
notifications: s.notifications.filter((x) => x.id !== entry.id),
|
|
46
|
+
}));
|
|
47
|
+
}, 5000);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
markRead(id) {
|
|
52
|
+
set((s) => ({
|
|
53
|
+
notifications: s.notifications.map((n) =>
|
|
54
|
+
n.id === id ? { ...n, read: true } : n,
|
|
55
|
+
),
|
|
56
|
+
}));
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
markAllRead() {
|
|
60
|
+
set((s) => ({
|
|
61
|
+
notifications: s.notifications.map((n) => ({ ...n, read: true })),
|
|
62
|
+
}));
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
dismiss(id) {
|
|
66
|
+
set((s) => ({
|
|
67
|
+
notifications: s.notifications.filter((n) => n.id !== id),
|
|
68
|
+
}));
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
clearAll() {
|
|
72
|
+
set({ notifications: [] });
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
togglePanel() {
|
|
76
|
+
set((s) => ({ panelOpen: !s.panelOpen }));
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
setPanelOpen(open) {
|
|
80
|
+
set({ panelOpen: open });
|
|
81
|
+
},
|
|
82
|
+
}));
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
|
|
3
|
+
export type SidebarPanelId = "explorer" | "git" | "search" | "chat" | "feed" | "debug";
|
|
4
|
+
export type Breakpoint = "mobile" | "tablet" | "desktop";
|
|
5
|
+
|
|
6
|
+
const PINNED_KEY = "sidebar-pinned";
|
|
7
|
+
const WIDTH_KEY = "sidebar-width";
|
|
8
|
+
export const SIDEBAR_MIN_WIDTH = 180;
|
|
9
|
+
export const SIDEBAR_MAX_WIDTH = 480;
|
|
10
|
+
const DEFAULT_WIDTH = 240;
|
|
11
|
+
|
|
12
|
+
function getBreakpoint(width: number): Breakpoint {
|
|
13
|
+
if (width < 768) return "mobile";
|
|
14
|
+
if (width < 1024) return "tablet";
|
|
15
|
+
return "desktop";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface SidebarState {
|
|
19
|
+
activePanel: SidebarPanelId | null;
|
|
20
|
+
isPinned: boolean;
|
|
21
|
+
drawerOpen: boolean;
|
|
22
|
+
sidebarWidth: number;
|
|
23
|
+
breakpoint: Breakpoint;
|
|
24
|
+
togglePanel: (id: SidebarPanelId) => void;
|
|
25
|
+
setActivePanel: (id: SidebarPanelId | null) => void;
|
|
26
|
+
setPinned: (pinned: boolean) => void;
|
|
27
|
+
setDrawerOpen: (open: boolean) => void;
|
|
28
|
+
setSidebarWidth: (width: number) => void;
|
|
29
|
+
_setBreakpoint: (bp: Breakpoint) => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function readPinned(): boolean {
|
|
33
|
+
try {
|
|
34
|
+
const stored = localStorage.getItem(PINNED_KEY);
|
|
35
|
+
if (stored !== null) return stored !== "false";
|
|
36
|
+
// 首次加载:desktop 默认 pinned,tablet/mobile 默认 drawer
|
|
37
|
+
return window.innerWidth >= 1024;
|
|
38
|
+
} catch {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function readWidth(): number {
|
|
44
|
+
try {
|
|
45
|
+
const v = Number(localStorage.getItem(WIDTH_KEY));
|
|
46
|
+
if (Number.isNaN(v) || v < SIDEBAR_MIN_WIDTH || v > SIDEBAR_MAX_WIDTH) return DEFAULT_WIDTH;
|
|
47
|
+
return v;
|
|
48
|
+
} catch {
|
|
49
|
+
return DEFAULT_WIDTH;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const initialWidth = typeof window !== "undefined" ? window.innerWidth : 1024;
|
|
54
|
+
|
|
55
|
+
export const useSidebarStore = create<SidebarState>((set, get) => ({
|
|
56
|
+
activePanel: "explorer",
|
|
57
|
+
isPinned: readPinned(),
|
|
58
|
+
drawerOpen: false,
|
|
59
|
+
sidebarWidth: readWidth(),
|
|
60
|
+
breakpoint: getBreakpoint(initialWidth),
|
|
61
|
+
|
|
62
|
+
togglePanel: (id) => {
|
|
63
|
+
const { activePanel, isPinned } = get();
|
|
64
|
+
if (activePanel === id) {
|
|
65
|
+
set({ activePanel: null, drawerOpen: false });
|
|
66
|
+
} else {
|
|
67
|
+
set({ activePanel: id, drawerOpen: !isPinned });
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
setActivePanel: (id) => set({ activePanel: id }),
|
|
72
|
+
|
|
73
|
+
setPinned: (pinned) => {
|
|
74
|
+
try {
|
|
75
|
+
localStorage.setItem(PINNED_KEY, String(pinned));
|
|
76
|
+
} catch { /* ignore */ }
|
|
77
|
+
set({ isPinned: pinned, drawerOpen: false });
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
setDrawerOpen: (open) => {
|
|
81
|
+
if (!open) {
|
|
82
|
+
const { isPinned } = get();
|
|
83
|
+
if (!isPinned) set({ drawerOpen: false, activePanel: null });
|
|
84
|
+
else set({ drawerOpen: false });
|
|
85
|
+
} else {
|
|
86
|
+
set({ drawerOpen: true });
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
setSidebarWidth: (width) => {
|
|
91
|
+
const clamped = Math.min(SIDEBAR_MAX_WIDTH, Math.max(SIDEBAR_MIN_WIDTH, width));
|
|
92
|
+
try {
|
|
93
|
+
localStorage.setItem(WIDTH_KEY, String(clamped));
|
|
94
|
+
} catch { /* ignore */ }
|
|
95
|
+
set({ sidebarWidth: clamped });
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
_setBreakpoint: (bp) => set({ breakpoint: bp }),
|
|
99
|
+
}));
|
|
@@ -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,33 @@
|
|
|
1
|
+
export type TreeNode = {
|
|
2
|
+
name: string;
|
|
3
|
+
path: string;
|
|
4
|
+
type: "file" | "directory";
|
|
5
|
+
size?: number;
|
|
6
|
+
children?: TreeNode[];
|
|
7
|
+
expanded?: boolean;
|
|
8
|
+
loaded?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type DemoMethod = "system.ping" | "system.hello" | "system.echo" | "chat.send";
|
|
12
|
+
|
|
13
|
+
export type FilePreview = {
|
|
14
|
+
path: string;
|
|
15
|
+
name: string;
|
|
16
|
+
content: string | null;
|
|
17
|
+
imageUrl: string | null;
|
|
18
|
+
mimeType: string;
|
|
19
|
+
size: number;
|
|
20
|
+
isText: boolean;
|
|
21
|
+
isImage: boolean;
|
|
22
|
+
totalLines?: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type ChatMessage = {
|
|
26
|
+
id: string;
|
|
27
|
+
role: "user" | "assistant";
|
|
28
|
+
content: string;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type EditingType = "rename" | "newFile" | "newDir";
|
|
33
|
+
export type EditingNode = { path: string; type: EditingType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MAX_PREVIEW_SIZE = 500 * 1024; // 500KB
|