@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,76 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
3
|
+
import { ChatPanel } from "../../components/chat/ChatPanel";
|
|
4
|
+
import { useChatStore } from "../../stores/use-chat-store";
|
|
5
|
+
import { act } from "@testing-library/react";
|
|
6
|
+
|
|
7
|
+
vi.mock("../../lib/api-client", () => ({
|
|
8
|
+
apiClient: {
|
|
9
|
+
call: vi.fn().mockResolvedValue({ ok: true }),
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
vi.mock("../../stores/use-log-store", () => ({
|
|
14
|
+
useLogStore: {
|
|
15
|
+
getState: () => ({ addLog: vi.fn() }),
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
vi.mock("react-i18next", () => ({
|
|
20
|
+
useTranslation: () => ({
|
|
21
|
+
t: (key: string) => {
|
|
22
|
+
const map: Record<string, string> = {
|
|
23
|
+
"chat.title": "Chat",
|
|
24
|
+
"chat.empty": "No messages yet",
|
|
25
|
+
"chat.placeholder": "Type a message...",
|
|
26
|
+
"chat.send": "Send",
|
|
27
|
+
};
|
|
28
|
+
return map[key] ?? key;
|
|
29
|
+
},
|
|
30
|
+
i18n: { language: "en" },
|
|
31
|
+
}),
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
describe("ChatPanel", () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
act(() => {
|
|
37
|
+
useChatStore.setState({ messages: [], inputText: "" });
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("renders chat title", () => {
|
|
42
|
+
render(<ChatPanel />);
|
|
43
|
+
expect(screen.getByText("Chat")).toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("shows empty state when no messages", () => {
|
|
47
|
+
render(<ChatPanel />);
|
|
48
|
+
expect(screen.getByText("No messages yet")).toBeInTheDocument();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("renders input and send button", () => {
|
|
52
|
+
render(<ChatPanel />);
|
|
53
|
+
expect(screen.getByPlaceholderText("Type a message...")).toBeInTheDocument();
|
|
54
|
+
expect(screen.getByText("Send")).toBeInTheDocument();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("updates input value on typing", () => {
|
|
58
|
+
render(<ChatPanel />);
|
|
59
|
+
const input = screen.getByPlaceholderText("Type a message...");
|
|
60
|
+
fireEvent.change(input, { target: { value: "hello" } });
|
|
61
|
+
expect(useChatStore.getState().inputText).toBe("hello");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("displays messages when present", () => {
|
|
65
|
+
act(() => {
|
|
66
|
+
useChatStore.setState({
|
|
67
|
+
messages: [
|
|
68
|
+
{ id: "1", role: "user", content: "Hi there", timestamp: Date.now() },
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
render(<ChatPanel />);
|
|
73
|
+
expect(screen.getByText("Hi there")).toBeInTheDocument();
|
|
74
|
+
expect(screen.queryByText("No messages yet")).not.toBeInTheDocument();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { MessageBubble } from "../../components/chat/MessageBubble";
|
|
4
|
+
import type { ChatMessage } from "../../types";
|
|
5
|
+
|
|
6
|
+
function makeMessage(overrides: Partial<ChatMessage> = {}): ChatMessage {
|
|
7
|
+
return {
|
|
8
|
+
id: "1",
|
|
9
|
+
role: "user",
|
|
10
|
+
content: "Hello world",
|
|
11
|
+
timestamp: new Date("2025-01-15T10:30:00").getTime(),
|
|
12
|
+
...overrides,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("MessageBubble", () => {
|
|
17
|
+
it("renders user message content", () => {
|
|
18
|
+
render(<MessageBubble message={makeMessage({ role: "user", content: "Hi" })} />);
|
|
19
|
+
expect(screen.getByText("Hi")).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("renders assistant message with markdown", () => {
|
|
23
|
+
render(<MessageBubble message={makeMessage({ role: "assistant", content: "Hello **bold**" })} />);
|
|
24
|
+
expect(screen.getByText("Hello")).toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("shows timestamp when provided", () => {
|
|
28
|
+
const ts = new Date("2025-06-15T14:05:00").getTime();
|
|
29
|
+
render(<MessageBubble message={makeMessage({ timestamp: ts })} />);
|
|
30
|
+
expect(screen.getByText("14:05")).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("shows bot icon for assistant messages", () => {
|
|
34
|
+
const { container } = render(
|
|
35
|
+
<MessageBubble message={makeMessage({ role: "assistant" })} />
|
|
36
|
+
);
|
|
37
|
+
const svg = container.querySelector("svg");
|
|
38
|
+
expect(svg).toBeInTheDocument();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("does not show bot icon for user messages", () => {
|
|
42
|
+
const { container } = render(
|
|
43
|
+
<MessageBubble message={makeMessage({ role: "user" })} />
|
|
44
|
+
);
|
|
45
|
+
const svgs = container.querySelectorAll("svg");
|
|
46
|
+
expect(svgs.length).toBe(0);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("i18n configuration", () => {
|
|
4
|
+
beforeEach(async () => {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("should export configured i18n instance", async () => {
|
|
9
|
+
const i18n = await import("../../lib/i18n");
|
|
10
|
+
expect(i18n.default).toBeDefined();
|
|
11
|
+
expect(i18n.default.isInitialized).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should have English translations", async () => {
|
|
15
|
+
const i18n = await import("../../lib/i18n");
|
|
16
|
+
expect(
|
|
17
|
+
i18n.default.getResource("en", "translation", "app.title")
|
|
18
|
+
).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should have Chinese translations", async () => {
|
|
22
|
+
const i18n = await import("../../lib/i18n");
|
|
23
|
+
expect(
|
|
24
|
+
i18n.default.getResource("zh", "translation", "app.title")
|
|
25
|
+
).toBeDefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should change language", async () => {
|
|
29
|
+
const i18n = await import("../../lib/i18n");
|
|
30
|
+
await i18n.default.changeLanguage("zh");
|
|
31
|
+
expect(i18n.default.language).toBe("zh");
|
|
32
|
+
|
|
33
|
+
await i18n.default.changeLanguage("en");
|
|
34
|
+
expect(i18n.default.language).toBe("en");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should translate keys correctly in English", async () => {
|
|
38
|
+
const i18n = await import("../../lib/i18n");
|
|
39
|
+
await i18n.default.changeLanguage("en");
|
|
40
|
+
expect(i18n.default.t("app.title")).toBe("Pi Chat");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should translate keys correctly in Chinese", async () => {
|
|
44
|
+
const i18n = await import("../../lib/i18n");
|
|
45
|
+
await i18n.default.changeLanguage("zh");
|
|
46
|
+
expect(i18n.default.t("app.title")).toBe("Pi Chat");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import "@testing-library/jest-dom/vitest";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(window, "matchMedia", {
|
|
4
|
+
writable: true,
|
|
5
|
+
value: (query: string) => ({
|
|
6
|
+
matches: false,
|
|
7
|
+
media: query,
|
|
8
|
+
onchange: null,
|
|
9
|
+
addListener: () => {},
|
|
10
|
+
removeListener: () => {},
|
|
11
|
+
addEventListener: () => {},
|
|
12
|
+
removeEventListener: () => {},
|
|
13
|
+
dispatchEvent: () => false,
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const localStorageMock = (() => {
|
|
18
|
+
let store: Record<string, string> = {};
|
|
19
|
+
return {
|
|
20
|
+
getItem: (key: string) => store[key] ?? null,
|
|
21
|
+
setItem: (key: string, value: string) => {
|
|
22
|
+
store[key] = String(value);
|
|
23
|
+
},
|
|
24
|
+
removeItem: (key: string) => {
|
|
25
|
+
delete store[key];
|
|
26
|
+
},
|
|
27
|
+
clear: () => {
|
|
28
|
+
store = {};
|
|
29
|
+
},
|
|
30
|
+
get length() {
|
|
31
|
+
return Object.keys(store).length;
|
|
32
|
+
},
|
|
33
|
+
key: (i: number) => Object.keys(store)[i] ?? null,
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
|
|
37
|
+
Object.defineProperty(window, "localStorage", { value: localStorageMock });
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import { useAppStore } from "../../stores/use-app-store";
|
|
3
|
+
import { act } from "@testing-library/react";
|
|
4
|
+
|
|
5
|
+
vi.mock("../../lib/api-client", () => ({
|
|
6
|
+
apiClient: {
|
|
7
|
+
call: vi.fn().mockResolvedValue({ pong: true, timestamp: Date.now(), platform: "web" }),
|
|
8
|
+
},
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
vi.mock("../../stores/use-log-store", () => ({
|
|
12
|
+
useLogStore: {
|
|
13
|
+
getState: () => ({ addLog: vi.fn() }),
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
describe("useAppStore", () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
act(() => {
|
|
20
|
+
useAppStore.setState({
|
|
21
|
+
method: "system.ping",
|
|
22
|
+
result: null,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("initial state", () => {
|
|
28
|
+
const state = useAppStore.getState();
|
|
29
|
+
expect(state.method).toBe("system.ping");
|
|
30
|
+
expect(state.result).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("setMethod", () => {
|
|
34
|
+
act(() => {
|
|
35
|
+
useAppStore.getState().setMethod("system.hello");
|
|
36
|
+
});
|
|
37
|
+
expect(useAppStore.getState().method).toBe("system.hello");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("callRPC should set result on success", async () => {
|
|
41
|
+
await act(async () => {
|
|
42
|
+
await useAppStore.getState().callRPC("");
|
|
43
|
+
});
|
|
44
|
+
expect(useAppStore.getState().result).not.toBeNull();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import { useChatStore } from "../../stores/use-chat-store";
|
|
3
|
+
import { act } from "@testing-library/react";
|
|
4
|
+
|
|
5
|
+
vi.mock("../../lib/api-client", () => ({
|
|
6
|
+
apiClient: {
|
|
7
|
+
call: vi.fn().mockResolvedValue({ ok: true }),
|
|
8
|
+
},
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
vi.mock("../../stores/use-log-store", () => ({
|
|
12
|
+
useLogStore: {
|
|
13
|
+
getState: () => ({ addLog: vi.fn() }),
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
describe("useChatStore", () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
act(() => {
|
|
20
|
+
useChatStore.setState({
|
|
21
|
+
messages: [],
|
|
22
|
+
inputText: "",
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("initial state", () => {
|
|
28
|
+
const state = useChatStore.getState();
|
|
29
|
+
expect(state.messages).toEqual([]);
|
|
30
|
+
expect(state.inputText).toBe("");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("setInputText", () => {
|
|
34
|
+
act(() => {
|
|
35
|
+
useChatStore.getState().setInputText("hello");
|
|
36
|
+
});
|
|
37
|
+
expect(useChatStore.getState().inputText).toBe("hello");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("addMessage", () => {
|
|
41
|
+
const msg = {
|
|
42
|
+
id: "1",
|
|
43
|
+
role: "user" as const,
|
|
44
|
+
content: "hi",
|
|
45
|
+
timestamp: Date.now(),
|
|
46
|
+
};
|
|
47
|
+
act(() => {
|
|
48
|
+
useChatStore.getState().addMessage(msg);
|
|
49
|
+
});
|
|
50
|
+
expect(useChatStore.getState().messages).toHaveLength(1);
|
|
51
|
+
expect(useChatStore.getState().messages[0].content).toBe("hi");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("setMessages", () => {
|
|
55
|
+
const msgs = [
|
|
56
|
+
{ id: "1", role: "user" as const, content: "a", timestamp: 1000 },
|
|
57
|
+
{ id: "2", role: "assistant" as const, content: "b", timestamp: 2000 },
|
|
58
|
+
];
|
|
59
|
+
act(() => {
|
|
60
|
+
useChatStore.getState().setMessages(msgs);
|
|
61
|
+
});
|
|
62
|
+
expect(useChatStore.getState().messages).toHaveLength(2);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("addMessage appends to existing", () => {
|
|
66
|
+
act(() => {
|
|
67
|
+
useChatStore.getState().setMessages([
|
|
68
|
+
{ id: "1", role: "user", content: "a", timestamp: 1000 },
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
act(() => {
|
|
72
|
+
useChatStore.getState().addMessage({
|
|
73
|
+
id: "2",
|
|
74
|
+
role: "assistant",
|
|
75
|
+
content: "b",
|
|
76
|
+
timestamp: 2000,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
const msgs = useChatStore.getState().messages;
|
|
80
|
+
expect(msgs).toHaveLength(2);
|
|
81
|
+
expect(msgs[1].content).toBe("b");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("sendMessage clears inputText after sending", async () => {
|
|
85
|
+
act(() => {
|
|
86
|
+
useChatStore.getState().setInputText("hello world");
|
|
87
|
+
});
|
|
88
|
+
await act(async () => {
|
|
89
|
+
await useChatStore.getState().sendMessage();
|
|
90
|
+
});
|
|
91
|
+
expect(useChatStore.getState().inputText).toBe("");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("sendMessage does nothing with empty input", async () => {
|
|
95
|
+
act(() => {
|
|
96
|
+
useChatStore.getState().setInputText(" ");
|
|
97
|
+
});
|
|
98
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
99
|
+
const callSpy = vi.mocked(apiClient.call);
|
|
100
|
+
callSpy.mockClear();
|
|
101
|
+
await useChatStore.getState().sendMessage();
|
|
102
|
+
expect(callSpy).not.toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("useConnectionStore", () => {
|
|
4
|
+
beforeEach(async () => {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("should have initial state", async () => {
|
|
9
|
+
const { useConnectionStore } = await import("../../stores/use-connection-store");
|
|
10
|
+
const state = useConnectionStore.getState();
|
|
11
|
+
expect(state.mode).toBe("web");
|
|
12
|
+
expect(state.ready).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should set ready state", async () => {
|
|
16
|
+
const { useConnectionStore } = await import("../../stores/use-connection-store");
|
|
17
|
+
useConnectionStore.getState().setReady(true);
|
|
18
|
+
expect(useConnectionStore.getState().ready).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should set mode", async () => {
|
|
22
|
+
const { useConnectionStore } = await import("../../stores/use-connection-store");
|
|
23
|
+
useConnectionStore.getState().setMode("desktop");
|
|
24
|
+
expect(useConnectionStore.getState().mode).toBe("desktop");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should toggle mode between web and desktop", async () => {
|
|
28
|
+
const { useConnectionStore } = await import("../../stores/use-connection-store");
|
|
29
|
+
expect(useConnectionStore.getState().mode).toBe("web");
|
|
30
|
+
useConnectionStore.getState().setMode("desktop");
|
|
31
|
+
expect(useConnectionStore.getState().mode).toBe("desktop");
|
|
32
|
+
useConnectionStore.getState().setMode("web");
|
|
33
|
+
expect(useConnectionStore.getState().mode).toBe("web");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("useLogStore", () => {
|
|
4
|
+
beforeEach(async () => {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("should start with empty logs", async () => {
|
|
9
|
+
const { useLogStore } = await import("../../stores/use-log-store");
|
|
10
|
+
expect(useLogStore.getState().logs).toEqual([]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should add log entries", async () => {
|
|
14
|
+
const { useLogStore } = await import("../../stores/use-log-store");
|
|
15
|
+
useLogStore.getState().addLog("test message");
|
|
16
|
+
const logs = useLogStore.getState().logs;
|
|
17
|
+
expect(logs).toHaveLength(1);
|
|
18
|
+
expect(logs[0]).toContain("test message");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should prepend timestamp to log entries", async () => {
|
|
22
|
+
const { useLogStore } = await import("../../stores/use-log-store");
|
|
23
|
+
useLogStore.getState().addLog("hello");
|
|
24
|
+
const log = useLogStore.getState().logs[0];
|
|
25
|
+
expect(log).toMatch(/^\[\d{2}:\d{2}:\d{2}\] hello$/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should limit log entries to MAX_LOGS", async () => {
|
|
29
|
+
const { useLogStore } = await import("../../stores/use-log-store");
|
|
30
|
+
for (let i = 0; i < 200; i++) {
|
|
31
|
+
useLogStore.getState().addLog(`log ${i}`);
|
|
32
|
+
}
|
|
33
|
+
expect(useLogStore.getState().logs.length).toBeLessThanOrEqual(100);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should keep most recent logs when exceeding limit", async () => {
|
|
37
|
+
const { useLogStore } = await import("../../stores/use-log-store");
|
|
38
|
+
for (let i = 0; i < 150; i++) {
|
|
39
|
+
useLogStore.getState().addLog(`log ${i}`);
|
|
40
|
+
}
|
|
41
|
+
const logs = useLogStore.getState().logs;
|
|
42
|
+
expect(logs.length).toBeLessThanOrEqual(100);
|
|
43
|
+
expect(logs[logs.length - 1]).toContain("log 149");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("useNotificationStore", () => {
|
|
4
|
+
beforeEach(async () => {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
vi.useFakeTimers();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
vi.useRealTimers();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should have correct initial state", async () => {
|
|
14
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
15
|
+
const state = useNotificationStore.getState();
|
|
16
|
+
expect(state.notifications).toEqual([]);
|
|
17
|
+
expect(state.panelOpen).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should push a notification", async () => {
|
|
21
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
22
|
+
useNotificationStore.getState().push({ message: "hello", level: "info" });
|
|
23
|
+
const state = useNotificationStore.getState();
|
|
24
|
+
expect(state.notifications).toHaveLength(1);
|
|
25
|
+
expect(state.notifications[0].message).toBe("hello");
|
|
26
|
+
expect(state.notifications[0].level).toBe("info");
|
|
27
|
+
expect(state.notifications[0].read).toBe(false);
|
|
28
|
+
expect(state.notifications[0].id).toMatch(/^notif-/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should auto-dismiss info notifications after 5s", async () => {
|
|
32
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
33
|
+
useNotificationStore.getState().push({ message: "temp", level: "info" });
|
|
34
|
+
expect(useNotificationStore.getState().notifications).toHaveLength(1);
|
|
35
|
+
|
|
36
|
+
vi.advanceTimersByTime(5000);
|
|
37
|
+
expect(useNotificationStore.getState().notifications).toHaveLength(0);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should not auto-dismiss warning/error notifications", async () => {
|
|
41
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
42
|
+
useNotificationStore.getState().push({ message: "warn", level: "warning" });
|
|
43
|
+
useNotificationStore.getState().push({ message: "err", level: "error" });
|
|
44
|
+
|
|
45
|
+
vi.advanceTimersByTime(10000);
|
|
46
|
+
expect(useNotificationStore.getState().notifications).toHaveLength(2);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should mark a notification as read", async () => {
|
|
50
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
51
|
+
useNotificationStore.getState().push({ message: "test", level: "warning" });
|
|
52
|
+
const id = useNotificationStore.getState().notifications[0].id;
|
|
53
|
+
|
|
54
|
+
useNotificationStore.getState().markRead(id);
|
|
55
|
+
expect(useNotificationStore.getState().notifications[0].read).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should mark all notifications as read", async () => {
|
|
59
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
60
|
+
useNotificationStore.getState().push({ message: "a", level: "warning" });
|
|
61
|
+
useNotificationStore.getState().push({ message: "b", level: "error" });
|
|
62
|
+
|
|
63
|
+
useNotificationStore.getState().markAllRead();
|
|
64
|
+
const state = useNotificationStore.getState();
|
|
65
|
+
expect(state.notifications.every((n) => n.read)).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should dismiss a notification", async () => {
|
|
69
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
70
|
+
useNotificationStore.getState().push({ message: "bye", level: "warning" });
|
|
71
|
+
const id = useNotificationStore.getState().notifications[0].id;
|
|
72
|
+
|
|
73
|
+
useNotificationStore.getState().dismiss(id);
|
|
74
|
+
expect(useNotificationStore.getState().notifications).toHaveLength(0);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should clear all notifications", async () => {
|
|
78
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
79
|
+
useNotificationStore.getState().push({ message: "a", level: "error" });
|
|
80
|
+
useNotificationStore.getState().push({ message: "b", level: "error" });
|
|
81
|
+
|
|
82
|
+
useNotificationStore.getState().clearAll();
|
|
83
|
+
expect(useNotificationStore.getState().notifications).toHaveLength(0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("should toggle panel", async () => {
|
|
87
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
88
|
+
expect(useNotificationStore.getState().panelOpen).toBe(false);
|
|
89
|
+
useNotificationStore.getState().togglePanel();
|
|
90
|
+
expect(useNotificationStore.getState().panelOpen).toBe(true);
|
|
91
|
+
useNotificationStore.getState().togglePanel();
|
|
92
|
+
expect(useNotificationStore.getState().panelOpen).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("should set panel open explicitly", async () => {
|
|
96
|
+
const { useNotificationStore } = await import("../../stores/use-notification-store");
|
|
97
|
+
useNotificationStore.getState().setPanelOpen(true);
|
|
98
|
+
expect(useNotificationStore.getState().panelOpen).toBe(true);
|
|
99
|
+
useNotificationStore.getState().setPanelOpen(false);
|
|
100
|
+
expect(useNotificationStore.getState().panelOpen).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const localStorageMock = (() => {
|
|
4
|
+
let store: Record<string, string> = {};
|
|
5
|
+
return {
|
|
6
|
+
getItem: (key: string) => store[key] ?? null,
|
|
7
|
+
setItem: (key: string, value: string) => { store[key] = value; },
|
|
8
|
+
removeItem: (key: string) => { delete store[key]; },
|
|
9
|
+
clear: () => { store = {}; },
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(globalThis, "localStorage", { value: localStorageMock });
|
|
14
|
+
|
|
15
|
+
describe("useSidebarStore", () => {
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
vi.resetModules();
|
|
18
|
+
localStorageMock.clear();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should have correct initial state", async () => {
|
|
22
|
+
const { useSidebarStore } = await import("../../stores/use-sidebar-store");
|
|
23
|
+
const state = useSidebarStore.getState();
|
|
24
|
+
expect(state.activePanel).toBeNull();
|
|
25
|
+
expect(state.drawerOpen).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should set active panel", async () => {
|
|
29
|
+
const { useSidebarStore } = await import("../../stores/use-sidebar-store");
|
|
30
|
+
useSidebarStore.getState().setActivePanel(null);
|
|
31
|
+
expect(useSidebarStore.getState().activePanel).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should set pinned state", async () => {
|
|
35
|
+
const { useSidebarStore } = await import("../../stores/use-sidebar-store");
|
|
36
|
+
useSidebarStore.getState().setPinned(true);
|
|
37
|
+
expect(useSidebarStore.getState().isPinned).toBe(true);
|
|
38
|
+
expect(localStorageMock.getItem("sidebar-pinned")).toBe("true");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should unpin and close drawer", async () => {
|
|
42
|
+
const { useSidebarStore } = await import("../../stores/use-sidebar-store");
|
|
43
|
+
useSidebarStore.getState().setPinned(true);
|
|
44
|
+
useSidebarStore.getState().setPinned(false);
|
|
45
|
+
expect(useSidebarStore.getState().isPinned).toBe(false);
|
|
46
|
+
expect(useSidebarStore.getState().drawerOpen).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should set drawer open", async () => {
|
|
50
|
+
const { useSidebarStore } = await import("../../stores/use-sidebar-store");
|
|
51
|
+
useSidebarStore.getState().setDrawerOpen(true);
|
|
52
|
+
expect(useSidebarStore.getState().drawerOpen).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should close drawer and clear panel when unpinned", async () => {
|
|
56
|
+
const { useSidebarStore } = await import("../../stores/use-sidebar-store");
|
|
57
|
+
useSidebarStore.getState().setPinned(false);
|
|
58
|
+
useSidebarStore.getState().setDrawerOpen(true);
|
|
59
|
+
useSidebarStore.getState().setDrawerOpen(false);
|
|
60
|
+
expect(useSidebarStore.getState().drawerOpen).toBe(false);
|
|
61
|
+
expect(useSidebarStore.getState().activePanel).toBeNull();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should clamp sidebar width within bounds", async () => {
|
|
65
|
+
const { useSidebarStore, SIDEBAR_MIN_WIDTH, SIDEBAR_MAX_WIDTH } = await import("../../stores/use-sidebar-store");
|
|
66
|
+
useSidebarStore.getState().setSidebarWidth(50);
|
|
67
|
+
expect(useSidebarStore.getState().sidebarWidth).toBe(SIDEBAR_MIN_WIDTH);
|
|
68
|
+
|
|
69
|
+
useSidebarStore.getState().setSidebarWidth(999);
|
|
70
|
+
expect(useSidebarStore.getState().sidebarWidth).toBe(SIDEBAR_MAX_WIDTH);
|
|
71
|
+
|
|
72
|
+
useSidebarStore.getState().setSidebarWidth(300);
|
|
73
|
+
expect(useSidebarStore.getState().sidebarWidth).toBe(300);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should persist sidebar width to localStorage", async () => {
|
|
77
|
+
const { useSidebarStore } = await import("../../stores/use-sidebar-store");
|
|
78
|
+
useSidebarStore.getState().setSidebarWidth(300);
|
|
79
|
+
expect(localStorageMock.getItem("sidebar-width")).toBe("300");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should set breakpoint", async () => {
|
|
83
|
+
const { useSidebarStore } = await import("../../stores/use-sidebar-store");
|
|
84
|
+
useSidebarStore.getState()._setBreakpoint("mobile");
|
|
85
|
+
expect(useSidebarStore.getState().breakpoint).toBe("mobile");
|
|
86
|
+
useSidebarStore.getState()._setBreakpoint("desktop");
|
|
87
|
+
expect(useSidebarStore.getState().breakpoint).toBe("desktop");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MessageSquare } from "lucide-react";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
|
|
4
|
+
const items: { id: string; icon: typeof MessageSquare; labelKey: string }[] = [
|
|
5
|
+
{ id: "chat", icon: MessageSquare, labelKey: "tabs.chat" },
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
export function ActivityBar() {
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div className="w-12 bg-[var(--color-bg-primary)] border-r border-[var(--color-border-primary)] flex flex-col items-center py-2 gap-1 flex-shrink-0">
|
|
13
|
+
{items.map(({ id, icon: Icon, labelKey }) => (
|
|
14
|
+
<button
|
|
15
|
+
key={id}
|
|
16
|
+
title={t(labelKey)}
|
|
17
|
+
className="w-10 h-10 flex items-center justify-center rounded transition-colors text-[var(--color-text-accent)] bg-[var(--color-bg-tertiary)] border-l-2 border-[var(--color-text-primary)]"
|
|
18
|
+
>
|
|
19
|
+
<Icon className="w-5 h-5" />
|
|
20
|
+
</button>
|
|
21
|
+
))}
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { items };
|