@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,60 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import { Check } from "lucide-react";
|
|
3
|
+
import { useTranslation } from "react-i18next";
|
|
4
|
+
import { useGitStore } from "../../stores/use-git-store";
|
|
5
|
+
import { useExplorerStore } from "../../stores/use-explorer-store";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Git commit message input — VS Code style.
|
|
9
|
+
* Shows at the top of the Git panel when there are staged changes.
|
|
10
|
+
* Self-contained: only depends on useGitStore + useExplorerStore.
|
|
11
|
+
*/
|
|
12
|
+
export function GitCommitInput() {
|
|
13
|
+
const { t } = useTranslation();
|
|
14
|
+
const staged = useGitStore((s) => s.staged);
|
|
15
|
+
const loadingAction = useGitStore((s) => s.loadingAction);
|
|
16
|
+
const commit = useGitStore((s) => s.commit);
|
|
17
|
+
const currentPath = useExplorerStore((s) => s.currentPath);
|
|
18
|
+
|
|
19
|
+
const [message, setMessage] = useState("");
|
|
20
|
+
|
|
21
|
+
const handleSubmit = useCallback(() => {
|
|
22
|
+
const trimmed = message.trim();
|
|
23
|
+
if (!trimmed || staged.length === 0) return;
|
|
24
|
+
commit(currentPath, trimmed);
|
|
25
|
+
setMessage("");
|
|
26
|
+
}, [message, staged.length, commit, currentPath]);
|
|
27
|
+
|
|
28
|
+
const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
|
|
29
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
handleSubmit();
|
|
32
|
+
}
|
|
33
|
+
}, [handleSubmit]);
|
|
34
|
+
|
|
35
|
+
if (staged.length === 0) return null;
|
|
36
|
+
|
|
37
|
+
const isCommitting = loadingAction === "commit";
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div className="p-2 border-b border-[var(--color-border-primary)]">
|
|
41
|
+
<textarea
|
|
42
|
+
className="w-full bg-[var(--color-bg-secondary)] border border-[var(--color-border-secondary)] rounded px-2 py-1.5 text-xs text-[var(--color-text-secondary)] placeholder-[var(--color-text-placeholder)] resize-none outline-none focus:border-[var(--color-accent)] transition-colors"
|
|
43
|
+
rows={3}
|
|
44
|
+
placeholder={t("git.commitPlaceholder")}
|
|
45
|
+
value={message}
|
|
46
|
+
onChange={(e) => setMessage(e.target.value)}
|
|
47
|
+
onKeyDown={handleKeyDown}
|
|
48
|
+
disabled={isCommitting}
|
|
49
|
+
/>
|
|
50
|
+
<button
|
|
51
|
+
className="mt-1.5 w-full flex items-center justify-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed bg-[var(--color-accent)] hover:bg-[var(--color-accent)] text-[var(--color-text-primary)]"
|
|
52
|
+
onClick={handleSubmit}
|
|
53
|
+
disabled={!message.trim() || isCommitting}
|
|
54
|
+
>
|
|
55
|
+
<Check className="w-3 h-3" />
|
|
56
|
+
{isCommitting ? t("git.committing") : t("git.commit")}
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
import { memo, useEffect, useCallback, useState, useRef } from "react";
|
|
2
|
+
import {
|
|
3
|
+
GitBranch, RefreshCw, FileQuestion, Plus, Minus, Pencil,
|
|
4
|
+
ChevronRight, ChevronDown, Eye, FileText, Copy,
|
|
5
|
+
Upload, Download, ChevronUp, ChevronDown as BranchChevron,
|
|
6
|
+
FolderTree,
|
|
7
|
+
} from "lucide-react";
|
|
8
|
+
import { useTranslation } from "react-i18next";
|
|
9
|
+
import { useGitStore, type GitFileChange, type GitCommit } from "../../stores/use-git-store";
|
|
10
|
+
import { useExplorerStore } from "../../stores/use-explorer-store";
|
|
11
|
+
import { ContextMenu, type MenuItem } from "../explorer/ContextMenu";
|
|
12
|
+
import { GitCommitInput } from "./GitCommitInput";
|
|
13
|
+
import { GitBranchSelector } from "./GitBranchSelector";
|
|
14
|
+
import { PinButton } from "../sidebar/PinButton";
|
|
15
|
+
|
|
16
|
+
/* ── Helpers ────────────────────────────────────────────── */
|
|
17
|
+
|
|
18
|
+
function statusIcon(status: GitFileChange["status"]) {
|
|
19
|
+
switch (status) {
|
|
20
|
+
case "added": return <Plus className="w-3 h-3 text-[var(--color-text-success)]" />;
|
|
21
|
+
case "deleted": return <Minus className="w-3 h-3 text-[var(--color-text-error)]" />;
|
|
22
|
+
case "modified": return <Pencil className="w-3 h-3 text-yellow-400" />;
|
|
23
|
+
default: return <FileQuestion className="w-3 h-3 text-[var(--color-text-tertiary)]" />;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function statusLabel(status: GitFileChange["status"]) {
|
|
28
|
+
switch (status) {
|
|
29
|
+
case "added": return "A";
|
|
30
|
+
case "deleted": return "D";
|
|
31
|
+
case "modified": return "M";
|
|
32
|
+
case "renamed": return "R";
|
|
33
|
+
case "copied": return "C";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function relativeTime(dateStr: string, t: (key: string, options?: Record<string, unknown>) => string): string {
|
|
38
|
+
const d = new Date(dateStr);
|
|
39
|
+
const now = new Date();
|
|
40
|
+
const diff = now.getTime() - d.getTime();
|
|
41
|
+
const mins = Math.floor(diff / 60000);
|
|
42
|
+
if (mins < 1) return t("git.justNow");
|
|
43
|
+
if (mins < 60) return t("git.minutesAgo", { count: mins });
|
|
44
|
+
const hours = Math.floor(mins / 60);
|
|
45
|
+
if (hours < 24) return t("git.hoursAgo", { count: hours });
|
|
46
|
+
const days = Math.floor(hours / 24);
|
|
47
|
+
if (days < 30) return t("git.daysAgo", { count: days });
|
|
48
|
+
return d.toLocaleDateString();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* ── Sub-components ─────────────────────────────────────── */
|
|
52
|
+
|
|
53
|
+
/* Working file item (staged / changed) with stage/unstage button */
|
|
54
|
+
interface FileItemProps {
|
|
55
|
+
path: string;
|
|
56
|
+
status: GitFileChange["status"];
|
|
57
|
+
isSelected: boolean;
|
|
58
|
+
isStaged?: boolean;
|
|
59
|
+
onClick: (filePath: string, staged?: boolean) => void;
|
|
60
|
+
onContextMenu: (e: React.MouseEvent, filePath: string, isStaged?: boolean) => void;
|
|
61
|
+
onStageToggle: (filePath: string, isStaged?: boolean) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const FileItem = memo(function FileItem({
|
|
65
|
+
path, status, isSelected, isStaged, onClick, onContextMenu, onStageToggle,
|
|
66
|
+
}: FileItemProps) {
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
className={`group flex items-center gap-1.5 px-2 py-0.5 text-xs rounded cursor-pointer transition-colors ${
|
|
70
|
+
isSelected ? "bg-[var(--color-accent)]/30 text-[var(--color-text-primary)]" : "hover:bg-[var(--color-bg-hover)] text-[var(--color-text-secondary)]"
|
|
71
|
+
}`}
|
|
72
|
+
onClick={() => onClick(path, isStaged)}
|
|
73
|
+
onContextMenu={(e) => { e.preventDefault(); onContextMenu(e, path, isStaged); }}
|
|
74
|
+
>
|
|
75
|
+
{statusIcon(status)}
|
|
76
|
+
<span className="truncate flex-1">{path.split("/").pop()}</span>
|
|
77
|
+
<span className="text-[var(--color-text-placeholder)] text-[10px]">{statusLabel(status)}</span>
|
|
78
|
+
<button
|
|
79
|
+
className={`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-[var(--color-bg-active)] ${
|
|
80
|
+
isStaged ? "text-orange-400 hover:text-orange-300" : "text-[var(--color-text-success)] hover:text-green-300"
|
|
81
|
+
}`}
|
|
82
|
+
onClick={(e) => { e.stopPropagation(); onStageToggle(path, isStaged); }}
|
|
83
|
+
title={isStaged ? "Unstage" : "Stage"}
|
|
84
|
+
>
|
|
85
|
+
{isStaged ? <ChevronUp className="w-3 h-3" /> : <Plus className="w-3 h-3" />}
|
|
86
|
+
</button>
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/* Untracked item with stage button */
|
|
92
|
+
interface UntrackedItemProps {
|
|
93
|
+
path: string;
|
|
94
|
+
isSelected: boolean;
|
|
95
|
+
onClick: (filePath: string) => void;
|
|
96
|
+
onContextMenu: (e: React.MouseEvent, filePath: string) => void;
|
|
97
|
+
onStage: (filePath: string) => void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const UntrackedItem = memo(function UntrackedItem({
|
|
101
|
+
path, isSelected, onClick, onContextMenu, onStage,
|
|
102
|
+
}: UntrackedItemProps) {
|
|
103
|
+
return (
|
|
104
|
+
<div
|
|
105
|
+
className={`group flex items-center gap-1.5 px-2 py-0.5 text-xs rounded cursor-pointer transition-colors ${
|
|
106
|
+
isSelected ? "bg-[var(--color-accent)]/30 text-[var(--color-text-primary)]" : "hover:bg-[var(--color-bg-hover)] text-[var(--color-text-tertiary)]"
|
|
107
|
+
}`}
|
|
108
|
+
onClick={() => onClick(path)}
|
|
109
|
+
onContextMenu={(e) => { e.preventDefault(); onContextMenu(e, path); }}
|
|
110
|
+
>
|
|
111
|
+
<FileQuestion className="w-3 h-3 text-[var(--color-text-placeholder)]" />
|
|
112
|
+
<span className="truncate flex-1">{path.split("/").pop()}</span>
|
|
113
|
+
<span className="text-gray-600 text-[10px]">U</span>
|
|
114
|
+
<button
|
|
115
|
+
className="opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded text-[var(--color-text-success)] hover:text-green-300 hover:bg-[var(--color-bg-active)]"
|
|
116
|
+
onClick={(e) => { e.stopPropagation(); onStage(path); }}
|
|
117
|
+
title="Stage"
|
|
118
|
+
>
|
|
119
|
+
<Plus className="w-3 h-3" />
|
|
120
|
+
</button>
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
/* Commit file item (inside expanded commit) */
|
|
126
|
+
interface CommitFileItemProps {
|
|
127
|
+
path: string;
|
|
128
|
+
status: GitFileChange["status"];
|
|
129
|
+
isSelected: boolean;
|
|
130
|
+
onClick: () => void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const CommitFileItem = memo(function CommitFileItem({ path, status, isSelected, onClick }: CommitFileItemProps) {
|
|
134
|
+
return (
|
|
135
|
+
<div
|
|
136
|
+
className={`flex items-center gap-1.5 pl-7 pr-2 py-0.5 text-xs rounded cursor-pointer transition-colors ${
|
|
137
|
+
isSelected ? "bg-[var(--color-accent)]/30 text-[var(--color-text-primary)]" : "hover:bg-[var(--color-bg-hover)] text-[var(--color-text-tertiary)]"
|
|
138
|
+
}`}
|
|
139
|
+
onClick={onClick}
|
|
140
|
+
>
|
|
141
|
+
{statusIcon(status)}
|
|
142
|
+
<span className="truncate flex-1">{path.split("/").pop()}</span>
|
|
143
|
+
<span className="text-gray-600 text-[10px]">{statusLabel(status)}</span>
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
/* Expandable commit item */
|
|
149
|
+
interface CommitItemProps {
|
|
150
|
+
commit: GitCommit;
|
|
151
|
+
expanded: boolean;
|
|
152
|
+
files: GitFileChange[] | undefined;
|
|
153
|
+
loading: boolean;
|
|
154
|
+
selectedFilePath: string | null;
|
|
155
|
+
onToggle: () => void;
|
|
156
|
+
onFileClick: (filePath: string) => void;
|
|
157
|
+
onContextMenu: (e: React.MouseEvent, commit: GitCommit) => void;
|
|
158
|
+
t: (key: string, options?: Record<string, unknown>) => string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const CommitItem = memo(function CommitItem({
|
|
162
|
+
commit, expanded, files, loading, selectedFilePath, onToggle, onFileClick, onContextMenu, t,
|
|
163
|
+
}: CommitItemProps) {
|
|
164
|
+
return (
|
|
165
|
+
<div>
|
|
166
|
+
<div
|
|
167
|
+
className="flex items-start gap-1.5 px-2 py-1 text-xs hover:bg-[var(--color-bg-hover)]/50 rounded cursor-pointer"
|
|
168
|
+
onClick={onToggle}
|
|
169
|
+
onContextMenu={(e) => { e.preventDefault(); onContextMenu(e, commit); }}
|
|
170
|
+
>
|
|
171
|
+
{expanded
|
|
172
|
+
? <ChevronDown className="w-3 h-3 text-[var(--color-text-placeholder)] mt-0.5 shrink-0" />
|
|
173
|
+
: <ChevronRight className="w-3 h-3 text-[var(--color-text-placeholder)] mt-0.5 shrink-0" />}
|
|
174
|
+
<div className="flex-1 min-w-0">
|
|
175
|
+
<div className="text-[var(--color-text-secondary)] truncate">{commit.message}</div>
|
|
176
|
+
<div className="text-[var(--color-text-placeholder)] text-[10px] flex items-center gap-1.5 mt-0.5">
|
|
177
|
+
<span className="text-[var(--color-text-accent)] font-mono">{commit.shortHash}</span>
|
|
178
|
+
<span>{commit.author}</span>
|
|
179
|
+
<span>{relativeTime(commit.date, t)}</span>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
{expanded && (
|
|
184
|
+
<div className="ml-1">
|
|
185
|
+
{loading ? (
|
|
186
|
+
<div className="text-gray-600 text-[10px] pl-7 py-1">{t("git.loadingFiles")}</div>
|
|
187
|
+
) : files && files.length > 0 ? (
|
|
188
|
+
files.map((f) => (
|
|
189
|
+
<CommitFileItem
|
|
190
|
+
key={f.path}
|
|
191
|
+
path={f.path}
|
|
192
|
+
status={f.status}
|
|
193
|
+
isSelected={selectedFilePath === f.path}
|
|
194
|
+
onClick={() => onFileClick(f.path)}
|
|
195
|
+
/>
|
|
196
|
+
))
|
|
197
|
+
) : (
|
|
198
|
+
<div className="text-gray-600 text-[10px] pl-7 py-1">{t("git.noFiles")}</div>
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
201
|
+
)}
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
/* ── Main Panel ─────────────────────────────────────────── */
|
|
207
|
+
|
|
208
|
+
interface GitPanelProps {
|
|
209
|
+
hideOuterShell?: boolean;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function GitPanel({ hideOuterShell }: GitPanelProps) {
|
|
213
|
+
const { t } = useTranslation();
|
|
214
|
+
const branch = useGitStore((s) => s.branch);
|
|
215
|
+
const ahead = useGitStore((s) => s.ahead);
|
|
216
|
+
const behind = useGitStore((s) => s.behind);
|
|
217
|
+
const staged = useGitStore((s) => s.staged);
|
|
218
|
+
const changed = useGitStore((s) => s.changed);
|
|
219
|
+
const untracked = useGitStore((s) => s.untracked);
|
|
220
|
+
const commits = useGitStore((s) => s.commits);
|
|
221
|
+
const loadingCommits = useGitStore((s) => s.loadingCommits);
|
|
222
|
+
const currentDiff = useGitStore((s) => s.currentDiff);
|
|
223
|
+
const expandedCommits = useGitStore((s) => s.expandedCommits);
|
|
224
|
+
const commitFiles = useGitStore((s) => s.commitFiles);
|
|
225
|
+
const loadingCommitFiles = useGitStore((s) => s.loadingCommitFiles);
|
|
226
|
+
const loadingAction = useGitStore((s) => s.loadingAction);
|
|
227
|
+
const worktrees = useGitStore((s) => s.worktrees);
|
|
228
|
+
const fetchStatus = useGitStore((s) => s.fetchStatus);
|
|
229
|
+
const fetchDiff = useGitStore((s) => s.fetchDiff);
|
|
230
|
+
const fetchLog = useGitStore((s) => s.fetchLog);
|
|
231
|
+
const toggleCommitExpand = useGitStore((s) => s.toggleCommitExpand);
|
|
232
|
+
const fetchCommitFileDiff = useGitStore((s) => s.fetchCommitFileDiff);
|
|
233
|
+
const stageFiles = useGitStore((s) => s.stageFiles);
|
|
234
|
+
const unstageFiles = useGitStore((s) => s.unstageFiles);
|
|
235
|
+
const push = useGitStore((s) => s.push);
|
|
236
|
+
const pull = useGitStore((s) => s.pull);
|
|
237
|
+
const fetchWorktrees = useGitStore((s) => s.fetchWorktrees);
|
|
238
|
+
|
|
239
|
+
const currentPath = useExplorerStore((s) => s.currentPath);
|
|
240
|
+
const openFile = useExplorerStore((s) => s.openFile);
|
|
241
|
+
|
|
242
|
+
const [commitsExpanded, setCommitsExpanded] = useState(false);
|
|
243
|
+
const [showBranches, setShowBranches] = useState(false);
|
|
244
|
+
const [showWorktrees, setShowWorktrees] = useState(false);
|
|
245
|
+
const [ctxMenu, setCtxMenu] = useState<{ x: number; y: number; filePath: string; isStaged?: boolean } | null>(null);
|
|
246
|
+
const [commitCtxMenu, setCommitCtxMenu] = useState<{ x: number; y: number; commit: GitCommit } | null>(null);
|
|
247
|
+
|
|
248
|
+
const branchBtnRef = useRef<HTMLButtonElement>(null);
|
|
249
|
+
|
|
250
|
+
/* Refresh status + worktrees on mount */
|
|
251
|
+
const refresh = useCallback(() => {
|
|
252
|
+
fetchStatus(currentPath);
|
|
253
|
+
fetchWorktrees(currentPath);
|
|
254
|
+
if (commitsExpanded) fetchLog(currentPath);
|
|
255
|
+
}, [fetchStatus, fetchWorktrees, fetchLog, currentPath, commitsExpanded]);
|
|
256
|
+
|
|
257
|
+
useEffect(() => { refresh(); }, [refresh]);
|
|
258
|
+
|
|
259
|
+
/* File click handlers */
|
|
260
|
+
const handleFileClick = useCallback((filePath: string, staged?: boolean) => {
|
|
261
|
+
fetchDiff(currentPath, filePath, staged);
|
|
262
|
+
}, [fetchDiff, currentPath]);
|
|
263
|
+
|
|
264
|
+
const handleContextMenu = useCallback((e: React.MouseEvent, filePath: string, isStaged?: boolean) => {
|
|
265
|
+
setCtxMenu({ x: e.clientX, y: e.clientY, filePath, isStaged });
|
|
266
|
+
}, []);
|
|
267
|
+
|
|
268
|
+
const handleOpenFile = useCallback((filePath: string) => {
|
|
269
|
+
const fullPath = `${currentPath}/${filePath}`;
|
|
270
|
+
openFile({ name: filePath.split("/").pop() || filePath, path: fullPath, type: "file" as const });
|
|
271
|
+
}, [openFile, currentPath]);
|
|
272
|
+
|
|
273
|
+
const handleCopyPath = useCallback(async (filePath: string) => {
|
|
274
|
+
await navigator.clipboard.writeText(`${currentPath}/${filePath}`);
|
|
275
|
+
}, [currentPath]);
|
|
276
|
+
|
|
277
|
+
const getContextMenuItems = useCallback((filePath: string, isStaged?: boolean): MenuItem[] => [
|
|
278
|
+
{ label: t("git.openDiff"), icon: <Eye className="w-3 h-3" />, onClick: () => fetchDiff(currentPath, filePath, isStaged) },
|
|
279
|
+
{ label: t("git.openFile"), icon: <FileText className="w-3 h-3" />, onClick: () => handleOpenFile(filePath) },
|
|
280
|
+
{ label: "", onClick: () => {}, divider: true },
|
|
281
|
+
{ label: t("git.copyPath"), icon: <Copy className="w-3 h-3" />, onClick: () => handleCopyPath(filePath) },
|
|
282
|
+
], [fetchDiff, currentPath, handleOpenFile, handleCopyPath, t]);
|
|
283
|
+
|
|
284
|
+
/* Commit context menu */
|
|
285
|
+
const handleCommitContextMenu = useCallback((e: React.MouseEvent, commit: GitCommit) => {
|
|
286
|
+
setCommitCtxMenu({ x: e.clientX, y: e.clientY, commit });
|
|
287
|
+
}, []);
|
|
288
|
+
|
|
289
|
+
const getCommitContextMenuItems = useCallback((commit: GitCommit): MenuItem[] => [
|
|
290
|
+
{ label: t("git.copyHash"), icon: <Copy className="w-3 h-3" />, onClick: () => navigator.clipboard.writeText(commit.hash) },
|
|
291
|
+
{ label: t("git.copyMessage"), icon: <Copy className="w-3 h-3" />, onClick: () => navigator.clipboard.writeText(commit.message) },
|
|
292
|
+
], [t]);
|
|
293
|
+
|
|
294
|
+
/* Commit file diff */
|
|
295
|
+
const handleCommitFileClick = useCallback((hash: string, filePath: string) => {
|
|
296
|
+
fetchCommitFileDiff(currentPath, hash, filePath);
|
|
297
|
+
}, [fetchCommitFileDiff, currentPath]);
|
|
298
|
+
|
|
299
|
+
/* Stage / Unstage */
|
|
300
|
+
const handleStageToggle = useCallback((filePath: string, isStaged?: boolean) => {
|
|
301
|
+
if (isStaged) {
|
|
302
|
+
unstageFiles(currentPath, [filePath]);
|
|
303
|
+
} else {
|
|
304
|
+
stageFiles(currentPath, [filePath]);
|
|
305
|
+
}
|
|
306
|
+
}, [stageFiles, unstageFiles, currentPath]);
|
|
307
|
+
|
|
308
|
+
const handleStageAll = useCallback(() => {
|
|
309
|
+
const paths = [...changed.map((f) => f.path), ...untracked];
|
|
310
|
+
if (paths.length > 0) stageFiles(currentPath, paths);
|
|
311
|
+
}, [changed, untracked, stageFiles, currentPath]);
|
|
312
|
+
|
|
313
|
+
const handleUnstageAll = useCallback(() => {
|
|
314
|
+
const paths = staged.map((f) => f.path);
|
|
315
|
+
if (paths.length > 0) unstageFiles(currentPath, paths);
|
|
316
|
+
}, [staged, unstageFiles, currentPath]);
|
|
317
|
+
|
|
318
|
+
const handleUntrackedStage = useCallback((filePath: string) => {
|
|
319
|
+
stageFiles(currentPath, [filePath]);
|
|
320
|
+
}, [stageFiles, currentPath]);
|
|
321
|
+
|
|
322
|
+
/* Commits toggle */
|
|
323
|
+
const toggleCommits = useCallback(() => {
|
|
324
|
+
const next = !commitsExpanded;
|
|
325
|
+
setCommitsExpanded(next);
|
|
326
|
+
if (next && commits.length === 0) fetchLog(currentPath);
|
|
327
|
+
}, [commitsExpanded, commits.length, fetchLog, currentPath]);
|
|
328
|
+
|
|
329
|
+
/* Push / Pull */
|
|
330
|
+
const handlePush = useCallback(() => push(currentPath), [push, currentPath]);
|
|
331
|
+
const handlePull = useCallback(() => pull(currentPath), [pull, currentPath]);
|
|
332
|
+
|
|
333
|
+
const totalChanges = staged.length + changed.length + untracked.length;
|
|
334
|
+
const selectedFilePath = currentDiff?.filePath ?? null;
|
|
335
|
+
const hasMultipleWorktrees = worktrees.length > 1;
|
|
336
|
+
|
|
337
|
+
const pinButton = <PinButton />;
|
|
338
|
+
|
|
339
|
+
const panelContent = (
|
|
340
|
+
<>
|
|
341
|
+
{/* Header */}
|
|
342
|
+
<div className="px-3 py-2 text-xs font-semibold text-[var(--color-text-tertiary)] uppercase tracking-wide border-b border-[var(--color-border-primary)] flex items-center gap-1.5">
|
|
343
|
+
<GitBranch className="w-3.5 h-3.5" />
|
|
344
|
+
{t("git.title")}
|
|
345
|
+
<span className="ml-auto flex items-center gap-1">
|
|
346
|
+
{totalChanges > 0 && (
|
|
347
|
+
<span className="bg-[var(--color-accent)] text-[var(--color-text-primary)] px-1.5 py-0.5 rounded-full text-[10px] leading-none">
|
|
348
|
+
{totalChanges}
|
|
349
|
+
</span>
|
|
350
|
+
)}
|
|
351
|
+
{pinButton}
|
|
352
|
+
<button onClick={handlePull} className="text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)]" disabled={loadingAction === "pull"} title={t("git.pull")}>
|
|
353
|
+
<Download className="w-3 h-3" />
|
|
354
|
+
</button>
|
|
355
|
+
<button onClick={handlePush} className="text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)]" disabled={loadingAction === "push"} title={t("git.push")}>
|
|
356
|
+
<Upload className="w-3 h-3" />
|
|
357
|
+
</button>
|
|
358
|
+
<button onClick={refresh} className="text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)]" title={t("git.refresh")}>
|
|
359
|
+
<RefreshCw className="w-3 h-3" />
|
|
360
|
+
</button>
|
|
361
|
+
</span>
|
|
362
|
+
</div>
|
|
363
|
+
|
|
364
|
+
{/* Branch info + selector */}
|
|
365
|
+
<div className="px-2 py-1.5 text-xs text-[var(--color-text-tertiary)] flex items-center gap-1.5 border-b border-[var(--color-border-primary)]/50">
|
|
366
|
+
<button
|
|
367
|
+
ref={branchBtnRef}
|
|
368
|
+
className="flex items-center gap-1 hover:text-[var(--color-text-primary)] transition-colors"
|
|
369
|
+
onClick={() => setShowBranches(!showBranches)}
|
|
370
|
+
>
|
|
371
|
+
<GitBranch className="w-3 h-3" />
|
|
372
|
+
<span className="font-medium">{branch}</span>
|
|
373
|
+
{ahead > 0 && <span className="text-green-400">↑{ahead}</span>}
|
|
374
|
+
{behind > 0 && <span className="text-orange-400">↓{behind}</span>}
|
|
375
|
+
<BranchChevron className="w-3 h-3 text-[var(--color-text-placeholder)]" />
|
|
376
|
+
</button>
|
|
377
|
+
|
|
378
|
+
{/* Worktree indicator */}
|
|
379
|
+
{hasMultipleWorktrees && (
|
|
380
|
+
<button
|
|
381
|
+
className="ml-auto text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)] transition-colors"
|
|
382
|
+
onClick={() => setShowWorktrees(!showWorktrees)}
|
|
383
|
+
title={`${worktrees.length} worktrees`}
|
|
384
|
+
>
|
|
385
|
+
<FolderTree className="w-3 h-3" />
|
|
386
|
+
</button>
|
|
387
|
+
)}
|
|
388
|
+
</div>
|
|
389
|
+
|
|
390
|
+
{/* Commit input */}
|
|
391
|
+
<GitCommitInput />
|
|
392
|
+
|
|
393
|
+
<div className="flex-1 overflow-y-auto p-1">
|
|
394
|
+
{/* Staged */}
|
|
395
|
+
{staged.length > 0 && (
|
|
396
|
+
<div className="mt-1">
|
|
397
|
+
<div className="px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold flex items-center">
|
|
398
|
+
<span>{t("git.staged")} ({staged.length})</span>
|
|
399
|
+
<button className="ml-auto text-orange-400 hover:text-orange-300" onClick={handleUnstageAll} title={t("git.unstageAll")}>
|
|
400
|
+
<ChevronUp className="w-3 h-3" />
|
|
401
|
+
</button>
|
|
402
|
+
</div>
|
|
403
|
+
{staged.map((f) => (
|
|
404
|
+
<FileItem key={f.path} path={f.path} status={f.status} isSelected={selectedFilePath === f.path} isStaged
|
|
405
|
+
onClick={handleFileClick} onContextMenu={handleContextMenu} onStageToggle={handleStageToggle} />
|
|
406
|
+
))}
|
|
407
|
+
</div>
|
|
408
|
+
)}
|
|
409
|
+
|
|
410
|
+
{/* Changed */}
|
|
411
|
+
{changed.length > 0 && (
|
|
412
|
+
<div className="mt-2">
|
|
413
|
+
<div className="px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold flex items-center">
|
|
414
|
+
<span>{t("git.changes")} ({changed.length})</span>
|
|
415
|
+
<button className="ml-auto text-[var(--color-text-success)] hover:text-green-300" onClick={handleStageAll} title={t("git.stageAll")}>
|
|
416
|
+
<Plus className="w-3 h-3" />
|
|
417
|
+
</button>
|
|
418
|
+
</div>
|
|
419
|
+
{changed.map((f) => (
|
|
420
|
+
<FileItem key={f.path} path={f.path} status={f.status} isSelected={selectedFilePath === f.path}
|
|
421
|
+
onClick={handleFileClick} onContextMenu={handleContextMenu} onStageToggle={handleStageToggle} />
|
|
422
|
+
))}
|
|
423
|
+
</div>
|
|
424
|
+
)}
|
|
425
|
+
|
|
426
|
+
{/* Untracked */}
|
|
427
|
+
{untracked.length > 0 && (
|
|
428
|
+
<div className="mt-2">
|
|
429
|
+
<div className="px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold">
|
|
430
|
+
{t("git.untracked")} ({untracked.length})
|
|
431
|
+
</div>
|
|
432
|
+
{untracked.map((f) => (
|
|
433
|
+
<UntrackedItem key={f} path={f} isSelected={selectedFilePath === f}
|
|
434
|
+
onClick={handleFileClick} onContextMenu={handleContextMenu} onStage={handleUntrackedStage} />
|
|
435
|
+
))}
|
|
436
|
+
</div>
|
|
437
|
+
)}
|
|
438
|
+
|
|
439
|
+
{totalChanges === 0 && !commitsExpanded && (
|
|
440
|
+
<div className="text-[var(--color-text-placeholder)] text-xs text-center py-8">{t("git.noChanges")}</div>
|
|
441
|
+
)}
|
|
442
|
+
|
|
443
|
+
{/* Commit History */}
|
|
444
|
+
<div className="mt-2 border-t border-[var(--color-border-primary)] pt-1">
|
|
445
|
+
<button
|
|
446
|
+
className="w-full px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold flex items-center gap-1 hover:text-[var(--color-text-secondary)] transition-colors"
|
|
447
|
+
onClick={toggleCommits}
|
|
448
|
+
>
|
|
449
|
+
{commitsExpanded ? <ChevronDown className="w-3 h-3" /> : <ChevronRight className="w-3 h-3" />}
|
|
450
|
+
{t("git.commits")}
|
|
451
|
+
{commits.length > 0 && <span className="text-gray-600 ml-auto">{commits.length}</span>}
|
|
452
|
+
</button>
|
|
453
|
+
{commitsExpanded && (
|
|
454
|
+
<div className="mt-0.5">
|
|
455
|
+
{loadingCommits ? (
|
|
456
|
+
<div className="text-[var(--color-text-placeholder)] text-xs text-center py-4">{t("common.loading")}</div>
|
|
457
|
+
) : commits.length === 0 ? (
|
|
458
|
+
<div className="text-gray-600 text-xs text-center py-4">{t("git.noCommits")}</div>
|
|
459
|
+
) : (
|
|
460
|
+
commits.map((c) => (
|
|
461
|
+
<CommitItem key={c.hash} commit={c}
|
|
462
|
+
expanded={expandedCommits.has(c.hash)}
|
|
463
|
+
files={commitFiles[c.hash]}
|
|
464
|
+
loading={loadingCommitFiles.has(c.hash)}
|
|
465
|
+
selectedFilePath={selectedFilePath}
|
|
466
|
+
onToggle={() => toggleCommitExpand(currentPath, c.hash)}
|
|
467
|
+
onFileClick={(fp) => handleCommitFileClick(c.hash, fp)}
|
|
468
|
+
onContextMenu={handleCommitContextMenu}
|
|
469
|
+
t={t}
|
|
470
|
+
/>
|
|
471
|
+
))
|
|
472
|
+
)}
|
|
473
|
+
</div>
|
|
474
|
+
)}
|
|
475
|
+
</div>
|
|
476
|
+
</div>
|
|
477
|
+
|
|
478
|
+
{/* Branch selector popup */}
|
|
479
|
+
{showBranches && branchBtnRef.current && (
|
|
480
|
+
<div className="absolute z-50" style={{
|
|
481
|
+
top: branchBtnRef.current.getBoundingClientRect().bottom + 4,
|
|
482
|
+
left: branchBtnRef.current.getBoundingClientRect().left,
|
|
483
|
+
}}>
|
|
484
|
+
<GitBranchSelector onClose={() => setShowBranches(false)} />
|
|
485
|
+
</div>
|
|
486
|
+
)}
|
|
487
|
+
|
|
488
|
+
{/* Worktree popup */}
|
|
489
|
+
{showWorktrees && worktrees.length > 1 && (
|
|
490
|
+
<div className="fixed z-50 min-w-[200px] bg-[var(--color-bg-secondary)] border border-[var(--color-border-secondary)] rounded-md shadow-xl py-1"
|
|
491
|
+
style={{ top: 80, left: 48 }}>
|
|
492
|
+
<div className="px-3 py-1 text-[10px] uppercase tracking-wide text-[var(--color-text-placeholder)] font-semibold">{t("git.worktrees")}</div>
|
|
493
|
+
{worktrees.map((wt) => (
|
|
494
|
+
<div key={wt.path} className={`px-3 py-1.5 text-xs flex items-center gap-2 ${
|
|
495
|
+
wt.path === currentPath ? "text-[var(--color-text-accent)]" : "text-[var(--color-text-secondary)]"
|
|
496
|
+
}`}>
|
|
497
|
+
<FolderTree className="w-3 h-3 shrink-0" />
|
|
498
|
+
<div className="min-w-0 flex-1">
|
|
499
|
+
<div className="truncate">{wt.branch}</div>
|
|
500
|
+
<div className="text-[var(--color-text-placeholder)] text-[10px] truncate">{wt.path}</div>
|
|
501
|
+
</div>
|
|
502
|
+
{wt.isMain && <span className="text-gray-600 text-[10px]">main</span>}
|
|
503
|
+
</div>
|
|
504
|
+
))}
|
|
505
|
+
<button className="w-full text-left px-3 py-1 text-[10px] text-[var(--color-text-placeholder)] hover:text-[var(--color-text-secondary)] border-t border-[var(--color-border-primary)] mt-1 pt-1"
|
|
506
|
+
onClick={() => setShowWorktrees(false)}>{t("git.close")}</button>
|
|
507
|
+
</div>
|
|
508
|
+
)}
|
|
509
|
+
|
|
510
|
+
{/* Context menus */}
|
|
511
|
+
{ctxMenu && (
|
|
512
|
+
<ContextMenu x={ctxMenu.x} y={ctxMenu.y}
|
|
513
|
+
items={getContextMenuItems(ctxMenu.filePath, ctxMenu.isStaged)}
|
|
514
|
+
onClose={() => setCtxMenu(null)} />
|
|
515
|
+
)}
|
|
516
|
+
{commitCtxMenu && (
|
|
517
|
+
<ContextMenu x={commitCtxMenu.x} y={commitCtxMenu.y}
|
|
518
|
+
items={getCommitContextMenuItems(commitCtxMenu.commit)}
|
|
519
|
+
onClose={() => setCommitCtxMenu(null)} />
|
|
520
|
+
)}
|
|
521
|
+
</>
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
if (hideOuterShell) {
|
|
525
|
+
return <div className="flex flex-col flex-1 overflow-hidden">{panelContent}</div>;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
return (
|
|
529
|
+
<div className="w-60 bg-[var(--color-bg-primary)] flex flex-col flex-shrink-0 overflow-hidden">
|
|
530
|
+
{panelContent}
|
|
531
|
+
</div>
|
|
532
|
+
);
|
|
533
|
+
}
|