@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,94 @@
|
|
|
1
|
+
interface CacheEntry<T> {
|
|
2
|
+
data: T;
|
|
3
|
+
timestamp: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
class RpcCache {
|
|
7
|
+
private cache = new Map<string, CacheEntry<unknown>>();
|
|
8
|
+
private defaultTTL: number;
|
|
9
|
+
private pruneTimer: ReturnType<typeof setInterval> | null = null;
|
|
10
|
+
|
|
11
|
+
constructor(defaultTTL = 2000) {
|
|
12
|
+
this.defaultTTL = defaultTTL;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private key(method: string, params: unknown): string {
|
|
16
|
+
return `${method}:${JSON.stringify(params)}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get<T>(method: string, params: unknown, ttl?: number): T | null {
|
|
20
|
+
const k = this.key(method, params);
|
|
21
|
+
const entry = this.cache.get(k);
|
|
22
|
+
if (!entry) return null;
|
|
23
|
+
|
|
24
|
+
const effectiveTTL = ttl ?? this.defaultTTL;
|
|
25
|
+
if (Date.now() - entry.timestamp > effectiveTTL) {
|
|
26
|
+
this.cache.delete(k);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return entry.data as T;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set<T>(method: string, params: unknown, data: T): void {
|
|
34
|
+
const k = this.key(method, params);
|
|
35
|
+
this.cache.set(k, { data, timestamp: Date.now() });
|
|
36
|
+
if (!this.pruneTimer) this.startPruneTimer();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
invalidate(method: string): void {
|
|
40
|
+
const prefix = `${method}:`;
|
|
41
|
+
for (const key of this.cache.keys()) {
|
|
42
|
+
if (key.startsWith(prefix)) {
|
|
43
|
+
this.cache.delete(key);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
invalidateAll(methods: string[]): void {
|
|
49
|
+
for (const m of methods) {
|
|
50
|
+
this.invalidate(m);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
clear(): void {
|
|
55
|
+
this.cache.clear();
|
|
56
|
+
if (this.pruneTimer) {
|
|
57
|
+
clearInterval(this.pruneTimer);
|
|
58
|
+
this.pruneTimer = null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
prune(): void {
|
|
63
|
+
const threshold = this.defaultTTL * 10;
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
for (const [key, entry] of this.cache) {
|
|
66
|
+
if (now - entry.timestamp > threshold) {
|
|
67
|
+
this.cache.delete(key);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (this.cache.size === 0 && this.pruneTimer) {
|
|
71
|
+
clearInterval(this.pruneTimer);
|
|
72
|
+
this.pruneTimer = null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private startPruneTimer(): void {
|
|
77
|
+
if (this.pruneTimer) return;
|
|
78
|
+
this.pruneTimer = setInterval(() => this.prune(), this.defaultTTL * 5);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const CACHEABLE_METHODS: Record<string, number> = {
|
|
83
|
+
"file.listDir": 2000,
|
|
84
|
+
"file.readFile": 3000,
|
|
85
|
+
"git.status": 2000,
|
|
86
|
+
"git.branches": 5000,
|
|
87
|
+
"git.log": 3000,
|
|
88
|
+
"git.diff": 3000,
|
|
89
|
+
"git.commitFiles": 3000,
|
|
90
|
+
"git.commitFileDiff": 3000,
|
|
91
|
+
"git.worktreeList": 5000,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const rpcCache = new RpcCache(2000);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "./lib/i18n";
|
|
2
|
+
import { StrictMode } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { apiClient } from "./lib/api-client";
|
|
5
|
+
import "./index.css";
|
|
6
|
+
import App from "./App";
|
|
7
|
+
|
|
8
|
+
const isElectrobun = typeof window !== "undefined" && !!window.__electrobunBunBridge;
|
|
9
|
+
|
|
10
|
+
if (isElectrobun) {
|
|
11
|
+
// 桌面端:同步初始化 IPC(Electrobun 要求桥接在页面加载时同步设置)
|
|
12
|
+
apiClient.initSyncForDesktop();
|
|
13
|
+
}
|
|
14
|
+
// Web 端 WS 初始化由 App.tsx 统一管理,避免竞争
|
|
15
|
+
|
|
16
|
+
if (import.meta.env.DEV) {
|
|
17
|
+
console.warn("[Main] Application starting, isElectrobun:", isElectrobun);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
createRoot(document.getElementById("root")!).render(
|
|
21
|
+
<StrictMode>
|
|
22
|
+
<App />
|
|
23
|
+
</StrictMode>
|
|
24
|
+
);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("../../lib/api-client", () => ({
|
|
4
|
+
apiClient: {
|
|
5
|
+
call: vi.fn().mockResolvedValue({ pong: true, timestamp: Date.now(), platform: "web" }),
|
|
6
|
+
subscribe: vi.fn().mockResolvedValue("sub-id"),
|
|
7
|
+
unsubscribe: vi.fn(),
|
|
8
|
+
},
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
vi.mock("./use-log-store", () => ({
|
|
12
|
+
useLogStore: {
|
|
13
|
+
getState: () => ({ addLog: vi.fn() }),
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
describe("useAppStore", () => {
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
vi.resetModules();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should have initial state", async () => {
|
|
23
|
+
const { useAppStore } = await import("../use-app-store");
|
|
24
|
+
const state = useAppStore.getState();
|
|
25
|
+
expect(state.method).toBe("system.ping");
|
|
26
|
+
expect(state.result).toBeNull();
|
|
27
|
+
expect(state.tickEvents).toEqual([]);
|
|
28
|
+
expect(state.tickCount).toBe(0);
|
|
29
|
+
expect(state.subscriptionId).toBeNull();
|
|
30
|
+
expect(state.timerRunning).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should set method", async () => {
|
|
34
|
+
const { useAppStore } = await import("../use-app-store");
|
|
35
|
+
useAppStore.getState().setMethod("system.hello");
|
|
36
|
+
expect(useAppStore.getState().method).toBe("system.hello");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should callRPC and store result for system.ping", async () => {
|
|
40
|
+
const { useAppStore } = await import("../use-app-store");
|
|
41
|
+
await useAppStore.getState().callRPC("test");
|
|
42
|
+
expect(useAppStore.getState().result).toEqual(
|
|
43
|
+
expect.objectContaining({ pong: true }),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should handleSubscribe and start timer", async () => {
|
|
48
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
49
|
+
const { useAppStore } = await import("../use-app-store");
|
|
50
|
+
|
|
51
|
+
await useAppStore.getState().handleSubscribe();
|
|
52
|
+
expect(apiClient.call).toHaveBeenCalledWith("timer.start", {});
|
|
53
|
+
expect(useAppStore.getState().timerRunning).toBe(true);
|
|
54
|
+
expect(apiClient.subscribe).toHaveBeenCalledWith(
|
|
55
|
+
"timer.tick",
|
|
56
|
+
expect.any(Function),
|
|
57
|
+
{},
|
|
58
|
+
);
|
|
59
|
+
expect(useAppStore.getState().subscriptionId).toBe("sub-id");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should handleUnsubscribe and stop timer", async () => {
|
|
63
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
64
|
+
const { useAppStore } = await import("../use-app-store");
|
|
65
|
+
|
|
66
|
+
await useAppStore.getState().handleSubscribe();
|
|
67
|
+
await useAppStore.getState().handleUnsubscribe();
|
|
68
|
+
|
|
69
|
+
expect(apiClient.unsubscribe).toHaveBeenCalledWith("sub-id");
|
|
70
|
+
expect(useAppStore.getState().timerRunning).toBe(false);
|
|
71
|
+
expect(useAppStore.getState().subscriptionId).toBeNull();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should stop timer even without subscription", async () => {
|
|
75
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
76
|
+
const { useAppStore } = await import("../use-app-store");
|
|
77
|
+
|
|
78
|
+
(apiClient.unsubscribe as ReturnType<typeof vi.fn>).mockClear();
|
|
79
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockClear();
|
|
80
|
+
|
|
81
|
+
await useAppStore.getState().handleUnsubscribe();
|
|
82
|
+
expect(apiClient.unsubscribe).not.toHaveBeenCalled();
|
|
83
|
+
expect(apiClient.call).toHaveBeenCalledWith("timer.stop", {});
|
|
84
|
+
expect(useAppStore.getState().timerRunning).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("../../lib/api-client", () => ({
|
|
4
|
+
apiClient: { call: vi.fn() },
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
vi.mock("../use-log-store", () => ({
|
|
8
|
+
useLogStore: { getState: () => ({ addLog: vi.fn() }) },
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
describe("useBashStore", () => {
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
vi.resetModules();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should have correct initial state", async () => {
|
|
17
|
+
const { useBashStore } = await import("../use-bash-store");
|
|
18
|
+
const state = useBashStore.getState();
|
|
19
|
+
expect(state.processes.size).toBe(0);
|
|
20
|
+
expect(state.activePid).toBeNull();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should add a process", async () => {
|
|
24
|
+
const { useBashStore } = await import("../use-bash-store");
|
|
25
|
+
useBashStore.getState().addProcess(1234, "ls -la");
|
|
26
|
+
const state = useBashStore.getState();
|
|
27
|
+
expect(state.processes.has(1234)).toBe(true);
|
|
28
|
+
expect(state.processes.get(1234)!.command).toBe("ls -la");
|
|
29
|
+
expect(state.processes.get(1234)!.running).toBe(true);
|
|
30
|
+
expect(state.processes.get(1234)!.output).toBe("");
|
|
31
|
+
expect(state.activePid).toBe(1234);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should update output", async () => {
|
|
35
|
+
const { useBashStore } = await import("../use-bash-store");
|
|
36
|
+
useBashStore.getState().addProcess(1234, "echo hello");
|
|
37
|
+
useBashStore.getState().updateOutput(1234, "hello\n");
|
|
38
|
+
expect(useBashStore.getState().processes.get(1234)!.output).toBe("hello\n");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should remove (stop) a process", async () => {
|
|
42
|
+
const { useBashStore } = await import("../use-bash-store");
|
|
43
|
+
useBashStore.getState().addProcess(1234, "ls");
|
|
44
|
+
useBashStore.getState().removeProcess(1234);
|
|
45
|
+
expect(useBashStore.getState().processes.get(1234)!.running).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should set active pid", async () => {
|
|
49
|
+
const { useBashStore } = await import("../use-bash-store");
|
|
50
|
+
useBashStore.getState().setActive(999);
|
|
51
|
+
expect(useBashStore.getState().activePid).toBe(999);
|
|
52
|
+
useBashStore.getState().setActive(null);
|
|
53
|
+
expect(useBashStore.getState().activePid).toBeNull();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should execute command via apiClient", async () => {
|
|
57
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
58
|
+
const { useBashStore } = await import("../use-bash-store");
|
|
59
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
|
|
60
|
+
pid: 5678,
|
|
61
|
+
output: "hello world\n",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await useBashStore.getState().executeCommand("echo hello world", "/home");
|
|
65
|
+
expect(apiClient.call).toHaveBeenCalledWith("bash.execute", { command: "echo hello world", cwd: "/home" });
|
|
66
|
+
const state = useBashStore.getState();
|
|
67
|
+
expect(state.processes.has(5678)).toBe(true);
|
|
68
|
+
expect(state.processes.get(5678)!.output).toBe("hello world\n");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should kill process via apiClient", async () => {
|
|
72
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
73
|
+
const { useBashStore } = await import("../use-bash-store");
|
|
74
|
+
useBashStore.getState().addProcess(1234, "sleep 100");
|
|
75
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce(undefined);
|
|
76
|
+
|
|
77
|
+
await useBashStore.getState().killProcess(1234);
|
|
78
|
+
expect(apiClient.call).toHaveBeenCalledWith("bash.kill", { pid: 1234 });
|
|
79
|
+
expect(useBashStore.getState().processes.get(1234)!.running).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should fetch processes", async () => {
|
|
83
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
84
|
+
const { useBashStore } = await import("../use-bash-store");
|
|
85
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
|
|
86
|
+
processes: [
|
|
87
|
+
{ pid: 100, command: "ls", running: true },
|
|
88
|
+
{ pid: 200, command: "pwd", running: false },
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
await useBashStore.getState().fetchProcesses();
|
|
93
|
+
const state = useBashStore.getState();
|
|
94
|
+
expect(state.processes.size).toBe(2);
|
|
95
|
+
expect(state.processes.get(100)!.command).toBe("ls");
|
|
96
|
+
expect(state.processes.get(100)!.running).toBe(true);
|
|
97
|
+
expect(state.processes.get(200)!.running).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, it, expect, vi, 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("../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("../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("../use-connection-store");
|
|
23
|
+
useConnectionStore.getState().setMode("desktop");
|
|
24
|
+
expect(useConnectionStore.getState().mode).toBe("desktop");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("../../lib/api-client", () => ({
|
|
4
|
+
apiClient: {
|
|
5
|
+
call: vi.fn(),
|
|
6
|
+
getBaseUrl: vi.fn(() => "http://localhost:3000"),
|
|
7
|
+
getAuthToken: vi.fn(() => "test-token"),
|
|
8
|
+
},
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
vi.mock("../use-log-store", () => ({
|
|
12
|
+
useLogStore: { getState: () => ({ addLog: vi.fn() }) },
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
vi.mock("../use-connection-store", () => ({
|
|
16
|
+
useConnectionStore: { getState: () => ({ mode: "desktop" }) },
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
describe("useExplorerStore", () => {
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
vi.resetModules();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should have correct initial state", async () => {
|
|
25
|
+
const { useExplorerStore } = await import("../use-explorer-store");
|
|
26
|
+
const state = useExplorerStore.getState();
|
|
27
|
+
expect(state.treeNodes).toEqual([]);
|
|
28
|
+
expect(state.currentPath).toBe("");
|
|
29
|
+
expect(state.selectedPath).toBeNull();
|
|
30
|
+
expect(state.filePreview).toBeNull();
|
|
31
|
+
expect(state.loadingFile).toBe(false);
|
|
32
|
+
expect(state.editingNode).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should set currentPath", async () => {
|
|
36
|
+
const { useExplorerStore } = await import("../use-explorer-store");
|
|
37
|
+
useExplorerStore.getState().setCurrentPath("/home/user");
|
|
38
|
+
expect(useExplorerStore.getState().currentPath).toBe("/home/user");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should list root directory", async () => {
|
|
42
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
43
|
+
const { useExplorerStore } = await import("../use-explorer-store");
|
|
44
|
+
const mockEntries = [
|
|
45
|
+
{ name: "src", path: "/src", type: "directory" as const, size: 0 },
|
|
46
|
+
{ name: "readme.md", path: "/readme.md", type: "file" as const, size: 100 },
|
|
47
|
+
];
|
|
48
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
|
|
49
|
+
entries: mockEntries,
|
|
50
|
+
basePath: "/root",
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
useExplorerStore.getState().setCurrentPath("/");
|
|
54
|
+
await useExplorerStore.getState().listRootDir();
|
|
55
|
+
|
|
56
|
+
const state = useExplorerStore.getState();
|
|
57
|
+
expect(state.treeNodes).toHaveLength(2);
|
|
58
|
+
expect(state.treeNodes[0].name).toBe("src");
|
|
59
|
+
expect(state.treeNodes[0].expanded).toBe(false);
|
|
60
|
+
expect(state.treeNodes[0].loaded).toBe(false);
|
|
61
|
+
expect(state.treeNodes[1].name).toBe("readme.md");
|
|
62
|
+
expect(state.currentPath).toBe("/root");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should toggle node to expand and load children", async () => {
|
|
66
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
67
|
+
const { useExplorerStore } = await import("../use-explorer-store");
|
|
68
|
+
|
|
69
|
+
const rootNodes = [
|
|
70
|
+
{ name: "src", path: "/src", type: "directory" as const, size: 0 },
|
|
71
|
+
];
|
|
72
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
|
|
73
|
+
entries: rootNodes,
|
|
74
|
+
basePath: "/",
|
|
75
|
+
});
|
|
76
|
+
await useExplorerStore.getState().listRootDir();
|
|
77
|
+
|
|
78
|
+
const childEntries = [
|
|
79
|
+
{ name: "index.ts", path: "/src/index.ts", type: "file" as const, size: 50 },
|
|
80
|
+
];
|
|
81
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
|
|
82
|
+
entries: childEntries,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
await useExplorerStore.getState().toggleNode("/src");
|
|
86
|
+
|
|
87
|
+
const state = useExplorerStore.getState();
|
|
88
|
+
expect(state.treeNodes[0].expanded).toBe(true);
|
|
89
|
+
expect(state.treeNodes[0].loaded).toBe(true);
|
|
90
|
+
expect(state.treeNodes[0].children).toHaveLength(1);
|
|
91
|
+
expect(state.treeNodes[0].children![0].name).toBe("index.ts");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should collapse an expanded node", async () => {
|
|
95
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
96
|
+
const { useExplorerStore } = await import("../use-explorer-store");
|
|
97
|
+
|
|
98
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
|
|
99
|
+
entries: [{ name: "src", path: "/src", type: "directory" as const, size: 0 }],
|
|
100
|
+
basePath: "/",
|
|
101
|
+
});
|
|
102
|
+
await useExplorerStore.getState().listRootDir();
|
|
103
|
+
|
|
104
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
|
|
105
|
+
entries: [],
|
|
106
|
+
});
|
|
107
|
+
await useExplorerStore.getState().toggleNode("/src");
|
|
108
|
+
expect(useExplorerStore.getState().treeNodes[0].expanded).toBe(true);
|
|
109
|
+
|
|
110
|
+
await useExplorerStore.getState().toggleNode("/src");
|
|
111
|
+
expect(useExplorerStore.getState().treeNodes[0].expanded).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("should start and cancel editing", async () => {
|
|
115
|
+
const { useExplorerStore } = await import("../use-explorer-store");
|
|
116
|
+
useExplorerStore.getState().startEditing("/src", "file");
|
|
117
|
+
expect(useExplorerStore.getState().editingNode).toEqual({ path: "/src", type: "file" });
|
|
118
|
+
|
|
119
|
+
useExplorerStore.getState().cancelEditing();
|
|
120
|
+
expect(useExplorerStore.getState().editingNode).toBeNull();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should close preview", async () => {
|
|
124
|
+
const { useExplorerStore } = await import("../use-explorer-store");
|
|
125
|
+
useExplorerStore.setState({ selectedPath: "/file.ts", filePreview: { path: "/file.ts", name: "file.ts" } as any });
|
|
126
|
+
useExplorerStore.getState().closePreview();
|
|
127
|
+
expect(useExplorerStore.getState().selectedPath).toBeNull();
|
|
128
|
+
expect(useExplorerStore.getState().filePreview).toBeNull();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("../../lib/api-client", () => ({
|
|
4
|
+
apiClient: {
|
|
5
|
+
call: vi.fn(),
|
|
6
|
+
subscribe: vi.fn(() => "sub-id"),
|
|
7
|
+
unsubscribe: vi.fn(),
|
|
8
|
+
},
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
describe("useFeedStore", () => {
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
vi.resetModules();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should have correct initial state", async () => {
|
|
17
|
+
const { useFeedStore } = await import("../use-feed-store");
|
|
18
|
+
const state = useFeedStore.getState();
|
|
19
|
+
expect(state.posts).toEqual([]);
|
|
20
|
+
expect(state.author).toBe("alice");
|
|
21
|
+
expect(state.category).toBe("tech");
|
|
22
|
+
expect(state.content).toBe("");
|
|
23
|
+
expect(state.loading).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should set author, category, content", async () => {
|
|
27
|
+
const { useFeedStore } = await import("../use-feed-store");
|
|
28
|
+
const store = useFeedStore.getState();
|
|
29
|
+
store.setAuthor("bob");
|
|
30
|
+
store.setCategory("news");
|
|
31
|
+
store.setContent("hello world");
|
|
32
|
+
const state = useFeedStore.getState();
|
|
33
|
+
expect(state.author).toBe("bob");
|
|
34
|
+
expect(state.category).toBe("news");
|
|
35
|
+
expect(state.content).toBe("hello world");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should create post and clear content", async () => {
|
|
39
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
40
|
+
const { useFeedStore } = await import("../use-feed-store");
|
|
41
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ id: "post-1" });
|
|
42
|
+
useFeedStore.getState().setContent(" new post ");
|
|
43
|
+
|
|
44
|
+
await useFeedStore.getState().createPost();
|
|
45
|
+
expect(apiClient.call).toHaveBeenCalledWith("feed.post", {
|
|
46
|
+
content: "new post",
|
|
47
|
+
category: "tech",
|
|
48
|
+
author: "alice",
|
|
49
|
+
});
|
|
50
|
+
expect(useFeedStore.getState().content).toBe("");
|
|
51
|
+
expect(useFeedStore.getState().loading).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should not create post with empty content", async () => {
|
|
55
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
56
|
+
const { useFeedStore } = await import("../use-feed-store");
|
|
57
|
+
|
|
58
|
+
useFeedStore.setState({ content: " " });
|
|
59
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockClear();
|
|
60
|
+
|
|
61
|
+
await useFeedStore.getState().createPost();
|
|
62
|
+
expect(apiClient.call).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should load posts", async () => {
|
|
66
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
67
|
+
const { useFeedStore } = await import("../use-feed-store");
|
|
68
|
+
const posts = [
|
|
69
|
+
{ id: "1", content: "hello", category: "tech", author: "alice", timestamp: Date.now() },
|
|
70
|
+
];
|
|
71
|
+
(apiClient.call as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ posts });
|
|
72
|
+
|
|
73
|
+
await useFeedStore.getState().loadPosts();
|
|
74
|
+
expect(useFeedStore.getState().posts).toHaveLength(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should add a post locally", async () => {
|
|
78
|
+
const { useFeedStore } = await import("../use-feed-store");
|
|
79
|
+
const post = { id: "p1", content: "hi", category: "tech" as const, author: "alice", timestamp: Date.now() };
|
|
80
|
+
useFeedStore.getState().addPost(post);
|
|
81
|
+
expect(useFeedStore.getState().posts).toHaveLength(1);
|
|
82
|
+
expect(useFeedStore.getState().posts[0].id).toBe("p1");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("useEventStreamStore", () => {
|
|
87
|
+
beforeEach(async () => {
|
|
88
|
+
vi.resetModules();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should have correct initial state", async () => {
|
|
92
|
+
const { useEventStreamStore } = await import("../use-feed-store");
|
|
93
|
+
const state = useEventStreamStore.getState();
|
|
94
|
+
expect(state.entries).toEqual([]);
|
|
95
|
+
expect(state.activeEventType).toBe("feed.update");
|
|
96
|
+
expect(state.activeFilter).toBe("");
|
|
97
|
+
expect(state.subscriptionId).toBeNull();
|
|
98
|
+
expect(state.subscribed).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should set active event type and filter", async () => {
|
|
102
|
+
const { useEventStreamStore } = await import("../use-feed-store");
|
|
103
|
+
useEventStreamStore.getState().setActiveEventType("chat.message");
|
|
104
|
+
useEventStreamStore.getState().setActiveFilter('{"key":"val"}');
|
|
105
|
+
const state = useEventStreamStore.getState();
|
|
106
|
+
expect(state.activeEventType).toBe("chat.message");
|
|
107
|
+
expect(state.activeFilter).toBe('{"key":"val"}');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should subscribe and unsubscribe", async () => {
|
|
111
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
112
|
+
const { useEventStreamStore } = await import("../use-feed-store");
|
|
113
|
+
|
|
114
|
+
await useEventStreamStore.getState().handleSubscribe();
|
|
115
|
+
expect(apiClient.subscribe).toHaveBeenCalled();
|
|
116
|
+
expect(useEventStreamStore.getState().subscribed).toBe(true);
|
|
117
|
+
expect(useEventStreamStore.getState().subscriptionId).toBe("sub-id");
|
|
118
|
+
|
|
119
|
+
useEventStreamStore.getState().handleUnsubscribe();
|
|
120
|
+
expect(apiClient.unsubscribe).toHaveBeenCalledWith("sub-id");
|
|
121
|
+
expect(useEventStreamStore.getState().subscribed).toBe(false);
|
|
122
|
+
expect(useEventStreamStore.getState().subscriptionId).toBeNull();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should add entries keeping max 50", async () => {
|
|
126
|
+
const { useEventStreamStore } = await import("../use-feed-store");
|
|
127
|
+
for (let i = 0; i < 55; i++) {
|
|
128
|
+
useEventStreamStore.getState().addEntry("feed.update", { i }, {});
|
|
129
|
+
}
|
|
130
|
+
expect(useEventStreamStore.getState().entries.length).toBeLessThanOrEqual(50);
|
|
131
|
+
});
|
|
132
|
+
});
|