@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,206 @@
|
|
|
1
|
+
import { useState, useRef, useEffect, useCallback } from "react";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
import { Play, Square, X } from "lucide-react";
|
|
4
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
5
|
+
import { useBashStore } from "../../stores/use-bash-store";
|
|
6
|
+
|
|
7
|
+
export function BashPanel() {
|
|
8
|
+
const { t } = useTranslation();
|
|
9
|
+
const [command, setCommand] = useState("");
|
|
10
|
+
const processes = useBashStore((s) => s.processes);
|
|
11
|
+
const activePid = useBashStore((s) => s.activePid);
|
|
12
|
+
const executeCommand = useBashStore((s) => s.executeCommand);
|
|
13
|
+
const killProcess = useBashStore((s) => s.killProcess);
|
|
14
|
+
const setActive = useBashStore((s) => s.setActive);
|
|
15
|
+
const parentRef = useRef<HTMLDivElement>(null);
|
|
16
|
+
const isUserScrollingRef = useRef(false);
|
|
17
|
+
|
|
18
|
+
const activeProcess = activePid != null ? processes.get(activePid) : null;
|
|
19
|
+
const lines = activeProcess?.output ? activeProcess.output.split("\n") : [];
|
|
20
|
+
|
|
21
|
+
const virtualizer = useVirtualizer({
|
|
22
|
+
count: lines.length,
|
|
23
|
+
getScrollElement: () => parentRef.current,
|
|
24
|
+
estimateSize: () => 20,
|
|
25
|
+
overscan: 20,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const handleScroll = useCallback(() => {
|
|
29
|
+
const el = parentRef.current;
|
|
30
|
+
if (!el) return;
|
|
31
|
+
const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 40;
|
|
32
|
+
isUserScrollingRef.current = !atBottom;
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!isUserScrollingRef.current && lines.length > 0) {
|
|
37
|
+
virtualizer.scrollToIndex(lines.length - 1, { align: "end" });
|
|
38
|
+
}
|
|
39
|
+
}, [lines.length, virtualizer]);
|
|
40
|
+
|
|
41
|
+
const handleRun = () => {
|
|
42
|
+
if (!command.trim()) return;
|
|
43
|
+
executeCommand(command.trim());
|
|
44
|
+
setCommand("");
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
48
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
handleRun();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const processList = Array.from(processes.entries());
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div className="flex flex-col h-full">
|
|
58
|
+
<div className="p-3 border-b border-[var(--color-border-primary)] flex items-center gap-2">
|
|
59
|
+
<input
|
|
60
|
+
type="text"
|
|
61
|
+
value={command}
|
|
62
|
+
onChange={(e) => setCommand(e.target.value)}
|
|
63
|
+
onKeyDown={handleKeyDown}
|
|
64
|
+
placeholder={t("bash.enterCommand")}
|
|
65
|
+
className="flex-1 bg-[var(--color-bg-secondary)] text-[var(--color-text-secondary)] px-3 py-1.5 rounded text-sm font-mono border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
|
|
66
|
+
/>
|
|
67
|
+
<button
|
|
68
|
+
onClick={handleRun}
|
|
69
|
+
disabled={!command.trim()}
|
|
70
|
+
className="flex items-center gap-1 px-3 py-1.5 bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] disabled:opacity-40 disabled:cursor-not-allowed rounded text-sm text-[var(--color-text-primary)]"
|
|
71
|
+
>
|
|
72
|
+
<Play className="w-3.5 h-3.5" />
|
|
73
|
+
{t("bash.run")}
|
|
74
|
+
</button>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
{processList.length > 0 && (
|
|
78
|
+
<div className="flex gap-1 px-3 py-2 border-b border-[var(--color-border-primary)] overflow-x-auto">
|
|
79
|
+
{processList.map(([pid, proc]) => (
|
|
80
|
+
<button
|
|
81
|
+
key={pid}
|
|
82
|
+
onClick={() => setActive(pid)}
|
|
83
|
+
className={`group relative flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs whitespace-nowrap transition-colors ${
|
|
84
|
+
activePid === pid
|
|
85
|
+
? proc.running
|
|
86
|
+
? "bg-green-900/50 text-green-300 border border-green-700"
|
|
87
|
+
: "bg-[var(--color-bg-tertiary)] text-[var(--color-text-secondary)] border border-[var(--color-border-secondary)]"
|
|
88
|
+
: "text-[var(--color-text-placeholder)] bg-[var(--color-bg-secondary)]/50 border border-transparent hover:text-[var(--color-text-secondary)]"
|
|
89
|
+
}`}
|
|
90
|
+
>
|
|
91
|
+
{proc.running && (
|
|
92
|
+
<span className="relative flex h-2 w-2">
|
|
93
|
+
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75" />
|
|
94
|
+
<span className="relative inline-flex rounded-full h-2 w-2 bg-green-500" />
|
|
95
|
+
</span>
|
|
96
|
+
)}
|
|
97
|
+
{!proc.running && (
|
|
98
|
+
<span className={`w-2 h-2 rounded-full ${proc.exitCode === 0 ? "bg-green-500" : "bg-red-500"}`} />
|
|
99
|
+
)}
|
|
100
|
+
PID {pid}
|
|
101
|
+
{proc.running && activePid === pid && (
|
|
102
|
+
<button
|
|
103
|
+
onClick={(e) => { e.stopPropagation(); killProcess(pid); }}
|
|
104
|
+
className="ml-0.5 text-[var(--color-text-error)] hover:text-red-300"
|
|
105
|
+
>
|
|
106
|
+
<X className="w-3 h-3" />
|
|
107
|
+
</button>
|
|
108
|
+
)}
|
|
109
|
+
{!proc.running && (
|
|
110
|
+
<span className={`text-[10px] ${proc.exitCode === 0 ? "text-green-500/70" : "text-red-500/70"}`}>
|
|
111
|
+
{t("bash.exited", { code: proc.exitCode ?? "?" })}
|
|
112
|
+
</span>
|
|
113
|
+
)}
|
|
114
|
+
</button>
|
|
115
|
+
))}
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
118
|
+
|
|
119
|
+
<div
|
|
120
|
+
ref={parentRef}
|
|
121
|
+
onScroll={handleScroll}
|
|
122
|
+
className="flex-1 overflow-auto p-3 font-mono text-xs text-[var(--color-text-secondary)] bg-gray-950 whitespace-pre-wrap leading-relaxed"
|
|
123
|
+
>
|
|
124
|
+
{activeProcess ? (
|
|
125
|
+
<>
|
|
126
|
+
{activeProcess.running && (
|
|
127
|
+
<div className="flex items-center gap-2 text-yellow-400 mb-2 pb-2 border-b border-[var(--color-bg-secondary)]">
|
|
128
|
+
<span className="relative flex h-2 w-2">
|
|
129
|
+
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-yellow-400 opacity-75" />
|
|
130
|
+
<span className="relative inline-flex rounded-full h-2 w-2 bg-yellow-500" />
|
|
131
|
+
</span>
|
|
132
|
+
{t("bash.processRunning", { pid: activePid })}
|
|
133
|
+
</div>
|
|
134
|
+
)}
|
|
135
|
+
{lines.length > 0 ? (
|
|
136
|
+
<div
|
|
137
|
+
style={{
|
|
138
|
+
height: virtualizer.getTotalSize(),
|
|
139
|
+
width: "100%",
|
|
140
|
+
position: "relative",
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
{virtualizer.getVirtualItems().map((virtualRow) => {
|
|
144
|
+
const line = lines[virtualRow.index];
|
|
145
|
+
return (
|
|
146
|
+
<div
|
|
147
|
+
key={virtualRow.index}
|
|
148
|
+
style={{
|
|
149
|
+
position: "absolute",
|
|
150
|
+
top: 0,
|
|
151
|
+
left: 0,
|
|
152
|
+
width: "100%",
|
|
153
|
+
height: `${virtualRow.size}px`,
|
|
154
|
+
transform: `translateY(${virtualRow.start}px)`,
|
|
155
|
+
}}
|
|
156
|
+
className="hover:bg-[var(--color-bg-secondary)]/30 px-1 -mx-1 rounded"
|
|
157
|
+
>
|
|
158
|
+
<span className="text-[var(--color-text-placeholder)] select-none mr-2">></span>
|
|
159
|
+
<span>{line || "\u00A0"}</span>
|
|
160
|
+
</div>
|
|
161
|
+
);
|
|
162
|
+
})}
|
|
163
|
+
</div>
|
|
164
|
+
) : activeProcess.running ? (
|
|
165
|
+
<span className="text-gray-600">{t("bash.waitingOutput")}</span>
|
|
166
|
+
) : null}
|
|
167
|
+
{!activeProcess.running && activeProcess.exitCode != null && (
|
|
168
|
+
<div className={`mt-2 pt-2 border-t border-[var(--color-bg-secondary)] text-xs font-semibold ${
|
|
169
|
+
activeProcess.exitCode === 0 ? "text-[var(--color-text-success)]" : "text-[var(--color-text-error)]"
|
|
170
|
+
}`}>
|
|
171
|
+
{t("bash.exit", { code: activeProcess.exitCode })}
|
|
172
|
+
</div>
|
|
173
|
+
)}
|
|
174
|
+
</>
|
|
175
|
+
) : (
|
|
176
|
+
<div className="flex flex-col items-center justify-center h-full text-gray-600">
|
|
177
|
+
<TerminalIcon className="w-12 h-12 mb-3 opacity-30" />
|
|
178
|
+
<span className="text-sm">{t("bash.noActiveProcess")}</span>
|
|
179
|
+
<span className="text-xs mt-1">{t("bash.getStarted")}</span>
|
|
180
|
+
</div>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
{activeProcess?.running && (
|
|
185
|
+
<div className="p-2 border-t border-[var(--color-border-primary)] flex justify-end">
|
|
186
|
+
<button
|
|
187
|
+
onClick={() => activePid != null && killProcess(activePid)}
|
|
188
|
+
className="flex items-center gap-1 px-3 py-1 bg-red-600 hover:bg-red-500 rounded text-xs text-[var(--color-text-primary)]"
|
|
189
|
+
>
|
|
190
|
+
<Square className="w-3 h-3" />
|
|
191
|
+
{t("bash.kill")}
|
|
192
|
+
</button>
|
|
193
|
+
</div>
|
|
194
|
+
)}
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function TerminalIcon({ className }: { className?: string }) {
|
|
200
|
+
return (
|
|
201
|
+
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
|
|
202
|
+
<polyline points="4 17 10 11 4 5" />
|
|
203
|
+
<line x1="12" y1="19" x2="20" y2="19" />
|
|
204
|
+
</svg>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("@tanstack/react-virtual", () => ({
|
|
4
|
+
useVirtualizer: (options: { count: number }) => ({
|
|
5
|
+
getVirtualItems: () =>
|
|
6
|
+
Array.from({ length: options.count }).map((_, i) => ({
|
|
7
|
+
index: i,
|
|
8
|
+
key: i,
|
|
9
|
+
start: i * 20,
|
|
10
|
+
size: 20,
|
|
11
|
+
})),
|
|
12
|
+
getTotalSize: () => options.count * 20,
|
|
13
|
+
scrollToIndex: vi.fn(),
|
|
14
|
+
}),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
import { render, screen, cleanup, fireEvent } from "@testing-library/react";
|
|
18
|
+
import React from "react";
|
|
19
|
+
|
|
20
|
+
const mockExecuteCommand = vi.fn();
|
|
21
|
+
const mockKillProcess = vi.fn();
|
|
22
|
+
const mockSetActive = vi.fn();
|
|
23
|
+
|
|
24
|
+
vi.mock("../../../stores/use-bash-store", () => ({
|
|
25
|
+
useBashStore: (selector: any) =>
|
|
26
|
+
selector({
|
|
27
|
+
processes: new Map([
|
|
28
|
+
[1234, { running: true, output: "hello\nworld", exitCode: null }],
|
|
29
|
+
[5678, { running: false, output: "done", exitCode: 0 }],
|
|
30
|
+
]),
|
|
31
|
+
activePid: 1234,
|
|
32
|
+
executeCommand: mockExecuteCommand,
|
|
33
|
+
killProcess: mockKillProcess,
|
|
34
|
+
setActive: mockSetActive,
|
|
35
|
+
}),
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
vi.mock("react-i18next", () => ({
|
|
39
|
+
useTranslation: () => ({ t: (k: string) => k }),
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
describe("BashPanel", () => {
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
cleanup();
|
|
45
|
+
vi.clearAllMocks();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should render command input", async () => {
|
|
49
|
+
const { BashPanel } = await import("../BashPanel");
|
|
50
|
+
render(<BashPanel />);
|
|
51
|
+
expect(screen.getByPlaceholderText("bash.enterCommand")).toBeDefined();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should render run button", async () => {
|
|
55
|
+
const { BashPanel } = await import("../BashPanel");
|
|
56
|
+
render(<BashPanel />);
|
|
57
|
+
expect(screen.getByText("bash.run")).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should show process tabs", async () => {
|
|
61
|
+
const { BashPanel } = await import("../BashPanel");
|
|
62
|
+
render(<BashPanel />);
|
|
63
|
+
expect(screen.getByText(/PID 1234/)).toBeDefined();
|
|
64
|
+
expect(screen.getByText(/PID 5678/)).toBeDefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should display active process output", async () => {
|
|
68
|
+
const { BashPanel } = await import("../BashPanel");
|
|
69
|
+
render(<BashPanel />);
|
|
70
|
+
expect(screen.getByText("hello")).toBeDefined();
|
|
71
|
+
expect(screen.getByText("world")).toBeDefined();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should render kill button for running process", async () => {
|
|
75
|
+
const { BashPanel } = await import("../BashPanel");
|
|
76
|
+
render(<BashPanel />);
|
|
77
|
+
expect(screen.getByText("bash.kill")).toBeDefined();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should call executeCommand on run", async () => {
|
|
81
|
+
const { BashPanel } = await import("../BashPanel");
|
|
82
|
+
render(<BashPanel />);
|
|
83
|
+
const input = screen.getByPlaceholderText("bash.enterCommand");
|
|
84
|
+
fireEvent.change(input, { target: { value: "ls -la" } });
|
|
85
|
+
fireEvent.click(screen.getByText("bash.run"));
|
|
86
|
+
expect(mockExecuteCommand).toHaveBeenCalledWith("ls -la");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("should submit on Enter key", async () => {
|
|
90
|
+
const { BashPanel } = await import("../BashPanel");
|
|
91
|
+
render(<BashPanel />);
|
|
92
|
+
const input = screen.getByPlaceholderText("bash.enterCommand");
|
|
93
|
+
fireEvent.change(input, { target: { value: "pwd" } });
|
|
94
|
+
fireEvent.keyDown(input, { key: "Enter" });
|
|
95
|
+
expect(mockExecuteCommand).toHaveBeenCalledWith("pwd");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should show running indicator", async () => {
|
|
99
|
+
const { BashPanel } = await import("../BashPanel");
|
|
100
|
+
render(<BashPanel />);
|
|
101
|
+
expect(screen.getByText(/bash.processRunning/)).toBeDefined();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
4
|
+
import { MessageSquare, Send } from "lucide-react";
|
|
5
|
+
import { useChatStore } from "../../stores/use-chat-store";
|
|
6
|
+
import { MessageBubble } from "./MessageBubble";
|
|
7
|
+
|
|
8
|
+
export function ChatPanel() {
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
const messages = useChatStore((s) => s.messages);
|
|
11
|
+
const inputText = useChatStore((s) => s.inputText);
|
|
12
|
+
const setInputText = useChatStore((s) => s.setInputText);
|
|
13
|
+
const sendMessage = useChatStore((s) => s.sendMessage);
|
|
14
|
+
const parentRef = useRef<HTMLDivElement>(null);
|
|
15
|
+
const prevMessageCountRef = useRef(0);
|
|
16
|
+
|
|
17
|
+
const virtualizer = useVirtualizer({
|
|
18
|
+
count: messages.length,
|
|
19
|
+
getScrollElement: () => parentRef.current,
|
|
20
|
+
estimateSize: () => 80,
|
|
21
|
+
overscan: 5,
|
|
22
|
+
measureElement: (element) => element?.getBoundingClientRect().height ?? 80,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (messages.length > prevMessageCountRef.current) {
|
|
27
|
+
virtualizer.scrollToIndex(messages.length - 1, { align: "end" });
|
|
28
|
+
}
|
|
29
|
+
prevMessageCountRef.current = messages.length;
|
|
30
|
+
}, [messages.length, virtualizer]);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div className="flex-1 flex flex-col overflow-hidden relative">
|
|
34
|
+
<div className="px-4 py-2 bg-[var(--color-bg-secondary)] border-b border-[var(--color-border-primary)] flex items-center justify-between flex-shrink-0">
|
|
35
|
+
<h2 className="text-sm font-semibold flex items-center gap-1.5">
|
|
36
|
+
<MessageSquare className="w-4 h-4 text-[var(--color-text-accent)]" />
|
|
37
|
+
{t("chat.title")}
|
|
38
|
+
{messages.length > 0 && (
|
|
39
|
+
<span className="ml-1 px-2 py-0.5 bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] rounded text-[10px]">
|
|
40
|
+
{messages.length}
|
|
41
|
+
</span>
|
|
42
|
+
)}
|
|
43
|
+
</h2>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<div ref={parentRef} className="flex-1 overflow-y-auto">
|
|
47
|
+
{messages.length === 0 ? (
|
|
48
|
+
<div className="flex items-center justify-center h-full text-[var(--color-text-placeholder)] text-sm">
|
|
49
|
+
{t("chat.empty")}
|
|
50
|
+
</div>
|
|
51
|
+
) : (
|
|
52
|
+
<div
|
|
53
|
+
style={{
|
|
54
|
+
height: virtualizer.getTotalSize(),
|
|
55
|
+
width: "100%",
|
|
56
|
+
position: "relative",
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{virtualizer.getVirtualItems().map((virtualItem) => {
|
|
60
|
+
const msg = messages[virtualItem.index];
|
|
61
|
+
return (
|
|
62
|
+
<div
|
|
63
|
+
key={msg.id}
|
|
64
|
+
data-index={virtualItem.index}
|
|
65
|
+
ref={virtualizer.measureElement}
|
|
66
|
+
style={{
|
|
67
|
+
position: "absolute",
|
|
68
|
+
top: 0,
|
|
69
|
+
left: 0,
|
|
70
|
+
width: "100%",
|
|
71
|
+
transform: `translateY(${virtualItem.start}px)`,
|
|
72
|
+
padding: "6px 16px",
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
<MessageBubble message={msg} />
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
})}
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<div className="px-4 py-3 bg-[var(--color-bg-secondary)] border-t border-[var(--color-border-primary)] flex gap-2 flex-shrink-0">
|
|
84
|
+
<input
|
|
85
|
+
type="text"
|
|
86
|
+
value={inputText}
|
|
87
|
+
onChange={(e) => setInputText(e.target.value)}
|
|
88
|
+
onKeyDown={(e) => e.key === "Enter" && !e.shiftKey && sendMessage()}
|
|
89
|
+
placeholder={t("chat.placeholder")}
|
|
90
|
+
className="flex-1 px-3 py-2 text-sm bg-[var(--color-bg-tertiary)] rounded-lg text-[var(--color-text-primary)] border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
|
|
91
|
+
/>
|
|
92
|
+
<button
|
|
93
|
+
onClick={sendMessage}
|
|
94
|
+
className="px-4 py-2 text-sm bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded-lg transition-colors flex items-center gap-1.5"
|
|
95
|
+
>
|
|
96
|
+
<Send className="w-4 h-4" />
|
|
97
|
+
{t("chat.send")}
|
|
98
|
+
</button>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { memo } from "react";
|
|
2
|
+
import { Bot } from "lucide-react";
|
|
3
|
+
import ReactMarkdown from "react-markdown";
|
|
4
|
+
import remarkGfm from "remark-gfm";
|
|
5
|
+
import { Highlight, themes } from "prism-react-renderer";
|
|
6
|
+
import type { ChatMessage } from "../../types";
|
|
7
|
+
|
|
8
|
+
interface MessageBubbleProps {
|
|
9
|
+
message: ChatMessage;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function formatTime(ts: number): string {
|
|
13
|
+
const d = new Date(ts);
|
|
14
|
+
const hh = d.getHours().toString().padStart(2, "0");
|
|
15
|
+
const mm = d.getMinutes().toString().padStart(2, "0");
|
|
16
|
+
return `${hh}:${mm}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function CodeBlock({ children, className }: { children: string; className?: string }) {
|
|
20
|
+
const language = className?.replace(/language-/, "") || "text";
|
|
21
|
+
return (
|
|
22
|
+
<Highlight theme={themes.nightOwl} code={children.trimEnd()} language={language}>
|
|
23
|
+
{({ style, tokens, getLineProps, getTokenProps }) => (
|
|
24
|
+
<pre
|
|
25
|
+
className="rounded-md p-3 my-2 overflow-x-auto text-xs leading-relaxed"
|
|
26
|
+
style={{ ...style, background: "#1e1e2e" }}
|
|
27
|
+
>
|
|
28
|
+
{tokens.map((line, i) => (
|
|
29
|
+
<div key={i} {...getLineProps({ line })}>
|
|
30
|
+
{line.map((token, key) => (
|
|
31
|
+
<span key={key} {...getTokenProps({ token })} />
|
|
32
|
+
))}
|
|
33
|
+
</div>
|
|
34
|
+
))}
|
|
35
|
+
</pre>
|
|
36
|
+
)}
|
|
37
|
+
</Highlight>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const MessageBubble = memo(function MessageBubble({ message }: MessageBubbleProps) {
|
|
42
|
+
const isUser = message.role === "user";
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className={`flex ${isUser ? "justify-end" : "justify-start"} items-start gap-2`}>
|
|
46
|
+
{!isUser && (
|
|
47
|
+
<div className="flex-shrink-0 mt-1">
|
|
48
|
+
<Bot className="w-4 h-4 text-[var(--color-text-accent)]" />
|
|
49
|
+
</div>
|
|
50
|
+
)}
|
|
51
|
+
<div
|
|
52
|
+
className={`max-w-[85%] px-3 py-2 rounded-lg text-sm break-words ${
|
|
53
|
+
isUser
|
|
54
|
+
? "bg-[var(--color-accent)] text-[var(--color-text-primary)]"
|
|
55
|
+
: "bg-[var(--color-bg-tertiary)] text-[var(--color-text-secondary)]"
|
|
56
|
+
}`}
|
|
57
|
+
>
|
|
58
|
+
{isUser ? (
|
|
59
|
+
<span className="whitespace-pre-wrap">{message.content}</span>
|
|
60
|
+
) : (
|
|
61
|
+
<div className="markdown-body prose prose-invert prose-sm max-w-none [&_p]:mb-2 [&_p:last-child]:mb-0 [&_ul]:list-disc [&_ul]:pl-4 [&_ol]:list-decimal [&_ol]:pl-4 [&_li]:mb-1 [&_h1]:text-base [&_h1]:font-bold [&_h1]:mb-2 [&_h2]:text-sm [&_h2]:font-bold [&_h2]:mb-1 [&_blockquote]:border-l-2 [&_blockquote]:border-[var(--color-text-accent)] [&_blockquote]:pl-3 [&_blockquote]:text-[var(--color-text-tertiary)] [&_a]:text-[var(--color-text-accent)] [&_a]:underline [&_code:not(pre_code)]:bg-[var(--color-bg-input)] [&_code:not(pre_code)]:px-1 [&_code:not(pre_code)]:rounded [&_code:not(pre_code)]:text-xs [&_table]:border-collapse [&_th]:border [&_th]:border-[var(--color-border-secondary)] [&_th]:px-2 [&_th]:py-1 [&_td]:border [&_td]:border-[var(--color-border-secondary)] [&_td]:px-2 [&_td]:py-1">
|
|
62
|
+
<ReactMarkdown
|
|
63
|
+
remarkPlugins={[remarkGfm]}
|
|
64
|
+
components={{
|
|
65
|
+
code({ className, children, ...props }) {
|
|
66
|
+
const isBlock = className?.startsWith("language-") || String(children).includes("\n");
|
|
67
|
+
if (isBlock) {
|
|
68
|
+
return <CodeBlock className={className}>{String(children)}</CodeBlock>;
|
|
69
|
+
}
|
|
70
|
+
return <code className={className} {...props}>{children}</code>;
|
|
71
|
+
},
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
{message.content}
|
|
75
|
+
</ReactMarkdown>
|
|
76
|
+
</div>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
{message.timestamp && (
|
|
80
|
+
<span className="text-[10px] text-[var(--color-text-tertiary)] ml-2 flex-shrink-0">
|
|
81
|
+
{formatTime(message.timestamp)}
|
|
82
|
+
</span>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React, { Component, type ErrorInfo, type ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
fallback?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface State {
|
|
9
|
+
hasError: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class ErrorBoundary extends Component<Props, State> {
|
|
14
|
+
constructor(props: Props) {
|
|
15
|
+
super(props);
|
|
16
|
+
this.state = { hasError: false, error: null };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static getDerivedStateFromError(error: Error): State {
|
|
20
|
+
return { hasError: true, error };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
|
|
24
|
+
console.error("[ErrorBoundary]", error, errorInfo);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
handleRetry = (): void => {
|
|
28
|
+
this.setState({ hasError: false, error: null });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
render(): ReactNode {
|
|
32
|
+
if (this.state.hasError) {
|
|
33
|
+
if (this.props.fallback) {
|
|
34
|
+
return this.props.fallback;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div className="flex flex-col items-center justify-center h-full p-8 bg-[var(--color-bg-primary)] text-[var(--color-text-primary)]">
|
|
39
|
+
<div className="text-4xl mb-4">⚠️</div>
|
|
40
|
+
<h2 className="text-lg font-semibold mb-2">Something went wrong</h2>
|
|
41
|
+
<p className="text-sm text-[var(--color-text-secondary)] mb-4 max-w-md text-center">
|
|
42
|
+
{this.state.error?.message || "An unexpected error occurred"}
|
|
43
|
+
</p>
|
|
44
|
+
<button
|
|
45
|
+
onClick={this.handleRetry}
|
|
46
|
+
className="px-4 py-2 bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-white rounded-lg transition-colors text-sm"
|
|
47
|
+
role="button"
|
|
48
|
+
aria-label="Retry"
|
|
49
|
+
>
|
|
50
|
+
Retry
|
|
51
|
+
</button>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this.props.children;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useLocaleStore } from "../../stores/use-locale-store";
|
|
2
|
+
|
|
3
|
+
export function LanguageSwitcher() {
|
|
4
|
+
const { locale, setLocale } = useLocaleStore();
|
|
5
|
+
return (
|
|
6
|
+
<button
|
|
7
|
+
onClick={() => setLocale(locale === "en" ? "zh" : "en")}
|
|
8
|
+
className="px-1.5 py-0.5 rounded text-xs hover:bg-[var(--color-bg-hover)] transition-colors text-[var(--color-text-secondary)]"
|
|
9
|
+
title={locale === "en" ? "切换到中文" : "Switch to English"}
|
|
10
|
+
>
|
|
11
|
+
{locale === "en" ? "中" : "EN"}
|
|
12
|
+
</button>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useThemeStore } from "../../stores/use-theme-store";
|
|
2
|
+
|
|
3
|
+
export function ThemeToggle() {
|
|
4
|
+
const theme = useThemeStore((s) => s.theme);
|
|
5
|
+
const toggleTheme = useThemeStore((s) => s.toggleTheme);
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<button
|
|
9
|
+
onClick={toggleTheme}
|
|
10
|
+
className="p-1.5 rounded-md hover:bg-[var(--color-bg-hover)] transition-colors"
|
|
11
|
+
title={theme === "dark" ? "Switch to light mode" : "Switch to dark mode"}
|
|
12
|
+
>
|
|
13
|
+
{theme === "dark" ? (
|
|
14
|
+
<svg className="w-4 h-4 text-yellow-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
|
15
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" />
|
|
16
|
+
</svg>
|
|
17
|
+
) : (
|
|
18
|
+
<svg className="w-4 h-4 text-gray-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
|
19
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" />
|
|
20
|
+
</svg>
|
|
21
|
+
)}
|
|
22
|
+
</button>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
vi.mock("../../../lib/i18n", () => ({
|
|
6
|
+
default: {
|
|
7
|
+
isInitialized: true,
|
|
8
|
+
language: "en",
|
|
9
|
+
changeLanguage: vi.fn(),
|
|
10
|
+
t: (key: string) => key,
|
|
11
|
+
getResource: vi.fn(),
|
|
12
|
+
},
|
|
13
|
+
supportedLocales: ["en", "zh"],
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
vi.mock("react-i18next", () => ({
|
|
17
|
+
useTranslation: () => ({
|
|
18
|
+
t: (key: string) => key,
|
|
19
|
+
i18n: { language: "en", changeLanguage: vi.fn() },
|
|
20
|
+
}),
|
|
21
|
+
initReactI18next: { type: "3rdParty", init: vi.fn() },
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
describe("ErrorBoundary", () => {
|
|
25
|
+
it("should render children when no error", async () => {
|
|
26
|
+
const { ErrorBoundary } = await import("../ErrorBoundary");
|
|
27
|
+
render(
|
|
28
|
+
<ErrorBoundary>
|
|
29
|
+
<div>Normal content</div>
|
|
30
|
+
</ErrorBoundary>
|
|
31
|
+
);
|
|
32
|
+
expect(screen.getByText("Normal content")).toBeDefined();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should render fallback UI when child throws", async () => {
|
|
36
|
+
const { ErrorBoundary } = await import("../ErrorBoundary");
|
|
37
|
+
|
|
38
|
+
const ThrowingComponent = () => {
|
|
39
|
+
throw new Error("Test error");
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const spy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
43
|
+
|
|
44
|
+
render(
|
|
45
|
+
<ErrorBoundary>
|
|
46
|
+
<ThrowingComponent />
|
|
47
|
+
</ErrorBoundary>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(screen.getByText(/something went wrong/i)).toBeDefined();
|
|
51
|
+
|
|
52
|
+
spy.mockRestore();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should show retry button in error state", async () => {
|
|
56
|
+
const { ErrorBoundary } = await import("../ErrorBoundary");
|
|
57
|
+
|
|
58
|
+
const ThrowingComponent = () => {
|
|
59
|
+
throw new Error("Test error");
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const spy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
63
|
+
|
|
64
|
+
render(
|
|
65
|
+
<ErrorBoundary>
|
|
66
|
+
<ThrowingComponent />
|
|
67
|
+
</ErrorBoundary>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
expect(screen.getByRole("button", { name: /retry/i })).toBeDefined();
|
|
71
|
+
|
|
72
|
+
spy.mockRestore();
|
|
73
|
+
});
|
|
74
|
+
});
|