@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,113 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach } from "vitest";
|
|
2
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
3
|
+
import { register } from "../timer";
|
|
4
|
+
|
|
5
|
+
type Handler = (params: unknown) => Promise<unknown>;
|
|
6
|
+
type EmittedEvent = { event: string; payload: unknown; filter: unknown };
|
|
7
|
+
|
|
8
|
+
function createMockServer() {
|
|
9
|
+
const handlers = new Map<string, Handler>();
|
|
10
|
+
const events: EmittedEvent[] = [];
|
|
11
|
+
return {
|
|
12
|
+
register: (method: string, handler: Handler) => {
|
|
13
|
+
handlers.set(method, handler);
|
|
14
|
+
},
|
|
15
|
+
emitEvent: (event: string, payload: unknown, filter?: unknown) => {
|
|
16
|
+
events.push({ event, payload, filter });
|
|
17
|
+
},
|
|
18
|
+
get: (method: string) => handlers.get(method),
|
|
19
|
+
has: (method: string) => handlers.has(method),
|
|
20
|
+
getEvents: () => events,
|
|
21
|
+
clearEvents: () => { events.length = 0; },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("timer handler", () => {
|
|
26
|
+
let server: ReturnType<typeof createMockServer>;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
server = createMockServer();
|
|
30
|
+
register(server as unknown as RPCServer, { platform: "desktop" });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("registers timer.start", () => {
|
|
34
|
+
expect(server.has("timer.start")).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("registers timer.stop", () => {
|
|
38
|
+
expect(server.has("timer.stop")).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("timer.start returns { started: true }", async () => {
|
|
42
|
+
const result = await server.get("timer.start")!({}) as Record<string, unknown>;
|
|
43
|
+
expect(result.started).toBe(true);
|
|
44
|
+
expect(result.alreadyRunning).toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("timer.start when already running returns { alreadyRunning: true }", async () => {
|
|
48
|
+
await server.get("timer.start")!({});
|
|
49
|
+
const result = await server.get("timer.start")!({}) as Record<string, unknown>;
|
|
50
|
+
expect(result.alreadyRunning).toBe(true);
|
|
51
|
+
expect(result.started).toBeUndefined();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("timer.start emits timer.tick events", async () => {
|
|
55
|
+
await server.get("timer.start")!({});
|
|
56
|
+
await new Promise((r) => setTimeout(r, 1200));
|
|
57
|
+
|
|
58
|
+
const tickEvents = server.getEvents().filter((e) => e.event === "timer.tick");
|
|
59
|
+
expect(tickEvents.length).toBeGreaterThanOrEqual(1);
|
|
60
|
+
|
|
61
|
+
const payload = tickEvents[0].payload as Record<string, unknown>;
|
|
62
|
+
expect(payload.count).toBeDefined();
|
|
63
|
+
expect(payload.timestamp).toBeDefined();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("timer.tick payload has incrementing count", async () => {
|
|
67
|
+
await server.get("timer.start")!({});
|
|
68
|
+
await new Promise((r) => setTimeout(r, 2200));
|
|
69
|
+
|
|
70
|
+
const tickEvents = server.getEvents().filter((e) => e.event === "timer.tick");
|
|
71
|
+
const counts = tickEvents.map((e) => (e.payload as Record<string, unknown>).count);
|
|
72
|
+
for (let i = 1; i < counts.length; i++) {
|
|
73
|
+
expect(Number(counts[i])).toBeGreaterThan(Number(counts[i - 1]));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("timer.stop returns { stopped: true }", async () => {
|
|
78
|
+
const result = await server.get("timer.stop")!({}) as Record<string, unknown>;
|
|
79
|
+
expect(result.stopped).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("timer.stop then start restarts the timer", async () => {
|
|
83
|
+
const r1 = await server.get("timer.start")!({}) as Record<string, unknown>;
|
|
84
|
+
expect(r1.started).toBe(true);
|
|
85
|
+
|
|
86
|
+
await server.get("timer.stop")!({});
|
|
87
|
+
|
|
88
|
+
const r2 = await server.get("timer.start")!({}) as Record<string, unknown>;
|
|
89
|
+
expect(r2.started).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("timer.stop stops tick events", async () => {
|
|
93
|
+
await server.get("timer.start")!({});
|
|
94
|
+
await new Promise((r) => setTimeout(r, 1100));
|
|
95
|
+
await server.get("timer.stop")!({});
|
|
96
|
+
|
|
97
|
+
server.clearEvents();
|
|
98
|
+
await new Promise((r) => setTimeout(r, 1200));
|
|
99
|
+
|
|
100
|
+
const tickEvents = server.getEvents().filter((e) => e.event === "timer.tick");
|
|
101
|
+
expect(tickEvents.length).toBe(0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("timer.tick events include filter with channel", async () => {
|
|
105
|
+
await server.get("timer.start")!({});
|
|
106
|
+
await new Promise((r) => setTimeout(r, 1100));
|
|
107
|
+
|
|
108
|
+
const tickEvents = server.getEvents().filter((e) => e.event === "timer.tick");
|
|
109
|
+
if (tickEvents.length > 0) {
|
|
110
|
+
expect(tickEvents[0].filter).toEqual({ channel: "default" });
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
4
|
+
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { join, dirname } from "path";
|
|
7
|
+
import { homedir } from "os";
|
|
8
|
+
import { createLogger } from "../lib/logger";
|
|
9
|
+
|
|
10
|
+
const log = createLogger("chat");
|
|
11
|
+
|
|
12
|
+
function getStoragePath(): string {
|
|
13
|
+
const dir = join(homedir(), ".pi-agent");
|
|
14
|
+
return join(dir, "chat-history.json");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type ChatMessage = { id: string; role: "user" | "assistant"; content: string; timestamp: number };
|
|
18
|
+
|
|
19
|
+
async function loadMessages(): Promise<ChatMessage[]> {
|
|
20
|
+
const filePath = getStoragePath();
|
|
21
|
+
try {
|
|
22
|
+
if (!existsSync(filePath)) {
|
|
23
|
+
log.info(`No history file at ${filePath}`);
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const raw = await readFile(filePath, "utf-8");
|
|
27
|
+
const msgs = JSON.parse(raw) as ChatMessage[];
|
|
28
|
+
log.info(`Loaded ${msgs.length} messages from ${filePath}`);
|
|
29
|
+
return msgs;
|
|
30
|
+
} catch (err) {
|
|
31
|
+
log.error("Failed to load history", { error: err });
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function saveMessages(messages: ChatMessage[]): Promise<void> {
|
|
37
|
+
const filePath = getStoragePath();
|
|
38
|
+
const dir = dirname(filePath);
|
|
39
|
+
try {
|
|
40
|
+
if (!existsSync(dir)) {
|
|
41
|
+
await mkdir(dir, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
await writeFile(filePath, JSON.stringify(messages, null, 2), "utf-8");
|
|
44
|
+
log.info(`Saved ${messages.length} messages to ${filePath}`);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
log.error("Failed to save history", { error: err });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
51
|
+
method: K,
|
|
52
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
53
|
+
) => void;
|
|
54
|
+
|
|
55
|
+
function generateReply(input: string): string {
|
|
56
|
+
const lower = input.toLowerCase().trim();
|
|
57
|
+
|
|
58
|
+
if (/^(hi|hello|hey|howdy|hola|yo|sup)\b/i.test(lower)) {
|
|
59
|
+
const greetings = [
|
|
60
|
+
"Hey there! How can I help you today?",
|
|
61
|
+
"Hello! Great to see you. What would you like to know?",
|
|
62
|
+
"Hi! I'm your desktop assistant. Ask me anything!",
|
|
63
|
+
];
|
|
64
|
+
return greetings[Math.floor(Math.random() * greetings.length)];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (/what('?s| is) the (time|date|day)|current (time|date)|what time|today'?s date/i.test(lower)) {
|
|
68
|
+
const now = new Date();
|
|
69
|
+
const date = now.toLocaleDateString("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric" });
|
|
70
|
+
const time = now.toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit" });
|
|
71
|
+
return `It's currently **${time}** on **${date}**.`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const mathMatch = lower.match(
|
|
75
|
+
/(?:what(?:'s| is)\s+)?(\d+(?:\.\d+)?)\s*([+\-*/x×÷^])\s*(\d+(?:\.\d+)?)/,
|
|
76
|
+
);
|
|
77
|
+
if (mathMatch) {
|
|
78
|
+
const a = parseFloat(mathMatch[1]);
|
|
79
|
+
const op = mathMatch[2];
|
|
80
|
+
const b = parseFloat(mathMatch[3]);
|
|
81
|
+
let result: number;
|
|
82
|
+
switch (op) {
|
|
83
|
+
case "+": result = a + b; break;
|
|
84
|
+
case "-": result = a - b; break;
|
|
85
|
+
case "*": case "x": case "×": result = a * b; break;
|
|
86
|
+
case "/": case "÷": result = b !== 0 ? a / b : NaN; break;
|
|
87
|
+
case "^": result = Math.pow(a, b); break;
|
|
88
|
+
default: result = NaN;
|
|
89
|
+
}
|
|
90
|
+
if (isNaN(result)) {
|
|
91
|
+
return "Hmm, I couldn't calculate that. Did you try dividing by zero?";
|
|
92
|
+
}
|
|
93
|
+
const niceResult = Number.isInteger(result) ? result.toString() : result.toFixed(4).replace(/0+$/, "").replace(/\.$/, "");
|
|
94
|
+
return `That would be **${niceResult}**! Need help with anything else?`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (/file|folder|directory|browse|explorer|open file|read file/i.test(lower)) {
|
|
98
|
+
return (
|
|
99
|
+
"To browse and manage files, use the **File Explorer** panel on the left sidebar. " +
|
|
100
|
+
"You can navigate directories, preview files, and open them for editing. " +
|
|
101
|
+
"Try typing a file path or asking me about a specific directory!"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (/git|commit|branch|push|pull|merge|status|diff|log/i.test(lower)) {
|
|
106
|
+
return (
|
|
107
|
+
"The **Git Panel** gives you full source control right inside the app. " +
|
|
108
|
+
"You can view changes, stage files, commit, switch branches, push/pull, and see the commit log. " +
|
|
109
|
+
"Look for the source control icon in the sidebar to get started."
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (/^(help|commands|what can you|what do you|capabilities|features)/i.test(lower)) {
|
|
114
|
+
return (
|
|
115
|
+
"Here's what I can help with:\n\n" +
|
|
116
|
+
"- **Greetings** - Say hi and I'll say hi back!\n" +
|
|
117
|
+
"- **Time & Date** - Ask \"what time is it?\" or \"what's today's date?\"\n" +
|
|
118
|
+
"- **Math** - Give me an expression like \"12 * 8\" or \"what is 100 / 4\"\n" +
|
|
119
|
+
"- **Files** - Ask about file browsing and I'll explain the File Explorer\n" +
|
|
120
|
+
"- **Git** - Ask about version control and I'll walk you through it\n" +
|
|
121
|
+
"- **Help** - Show this message anytime!\n\n" +
|
|
122
|
+
"This is a demo assistant - try different things to see what sticks!"
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const defaults = [
|
|
127
|
+
"That's an interesting question! I'm a demo assistant, so my knowledge is limited - but try asking about **time**, **math**, **files**, or **git**.",
|
|
128
|
+
"I wish I could help with that! For now I can answer questions about time, do simple math, and explain the app's features. Type **help** to see what I can do.",
|
|
129
|
+
"Hmm, I'm not sure about that one. But I *can* do math, tell you the time, and explain features. Give it a shot!",
|
|
130
|
+
];
|
|
131
|
+
return defaults[Math.floor(Math.random() * defaults.length)];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function register(server: RPCServer, _options: HandlerOptions): void {
|
|
135
|
+
const r: RegisterFn = (method, handler) => {
|
|
136
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
r("chat.list", async (params) => {
|
|
140
|
+
const all = await loadMessages();
|
|
141
|
+
const limit = params.limit ?? 50;
|
|
142
|
+
const messages = all.slice(-limit);
|
|
143
|
+
return {
|
|
144
|
+
messages,
|
|
145
|
+
hasMore: all.length > limit,
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
r("chat.send", async (params) => {
|
|
150
|
+
const all = await loadMessages();
|
|
151
|
+
|
|
152
|
+
const userMsg: ChatMessage = {
|
|
153
|
+
id: `msg-${Date.now()}-user`,
|
|
154
|
+
role: "user",
|
|
155
|
+
content: params.content,
|
|
156
|
+
timestamp: Date.now(),
|
|
157
|
+
};
|
|
158
|
+
all.push(userMsg);
|
|
159
|
+
|
|
160
|
+
server.emitEvent("chat.message", userMsg, { role: userMsg.role });
|
|
161
|
+
|
|
162
|
+
const thinkDelay = 200 + Math.floor(Math.random() * 300);
|
|
163
|
+
await new Promise((r) => setTimeout(r, thinkDelay));
|
|
164
|
+
|
|
165
|
+
const reply: ChatMessage = {
|
|
166
|
+
id: `msg-${Date.now()}-assistant`,
|
|
167
|
+
role: "assistant",
|
|
168
|
+
content: generateReply(params.content),
|
|
169
|
+
timestamp: Date.now(),
|
|
170
|
+
};
|
|
171
|
+
all.push(reply);
|
|
172
|
+
|
|
173
|
+
server.emitEvent("chat.message", reply, { role: reply.role });
|
|
174
|
+
|
|
175
|
+
await saveMessages(all);
|
|
176
|
+
|
|
177
|
+
return { ok: true };
|
|
178
|
+
});
|
|
179
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
4
|
+
import type { FeedPost, FeedCategory } from "../modules/feed";
|
|
5
|
+
import { createLogger } from "../lib/logger";
|
|
6
|
+
|
|
7
|
+
const log = createLogger("feed");
|
|
8
|
+
|
|
9
|
+
// 内存存储
|
|
10
|
+
const posts: FeedPost[] = [];
|
|
11
|
+
|
|
12
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
13
|
+
method: K,
|
|
14
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
15
|
+
) => void;
|
|
16
|
+
|
|
17
|
+
export function register(server: RPCServer, _options: HandlerOptions): void {
|
|
18
|
+
const r: RegisterFn = (method, handler) => {
|
|
19
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
r("feed.post", async (params) => {
|
|
23
|
+
const category = params.category as FeedCategory;
|
|
24
|
+
const author = (params.author as string) || "anonymous";
|
|
25
|
+
|
|
26
|
+
const post: FeedPost = {
|
|
27
|
+
id: `feed-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
28
|
+
content: params.content,
|
|
29
|
+
category,
|
|
30
|
+
author,
|
|
31
|
+
timestamp: Date.now(),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
posts.push(post);
|
|
35
|
+
log.info(`New post: ${post.id} [${category}] by ${author}`);
|
|
36
|
+
|
|
37
|
+
// 发送事件 — metadata 用于过滤
|
|
38
|
+
server.emitEvent("feed.update", post, { category, author });
|
|
39
|
+
|
|
40
|
+
return { id: post.id };
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
r("feed.list", async (params) => {
|
|
44
|
+
const limit = params.limit ?? 50;
|
|
45
|
+
let filtered = posts;
|
|
46
|
+
|
|
47
|
+
if (params.category) {
|
|
48
|
+
filtered = posts.filter((p) => p.category === params.category);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return { posts: filtered.slice(-limit) };
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
4
|
+
import { readdir, stat, writeFile, readFile, mkdir, rename, rm, cp } from "fs/promises";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { join, dirname } from "path";
|
|
7
|
+
import { createLogger } from "../lib/logger";
|
|
8
|
+
import { validatePath } from "../lib/path-security";
|
|
9
|
+
|
|
10
|
+
const log = createLogger("file");
|
|
11
|
+
|
|
12
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
13
|
+
method: K,
|
|
14
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
15
|
+
) => void;
|
|
16
|
+
|
|
17
|
+
export function register(server: RPCServer, _options: HandlerOptions): void {
|
|
18
|
+
const r: RegisterFn = (method, handler) => {
|
|
19
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
r("file.findProjectRoot", async () => {
|
|
23
|
+
let dir = process.cwd();
|
|
24
|
+
for (let i = 0; i < 20; i++) {
|
|
25
|
+
if (existsSync(join(dir, "package.json"))) return { path: dir };
|
|
26
|
+
const parent = dirname(dir);
|
|
27
|
+
if (parent === dir) break;
|
|
28
|
+
dir = parent;
|
|
29
|
+
}
|
|
30
|
+
return { path: process.cwd() };
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
r("file.listDir", async (params) => {
|
|
34
|
+
const basePath = validatePath(params.path || process.cwd());
|
|
35
|
+
const entries: { name: string; path: string; type: "file" | "directory"; size?: number }[] = [];
|
|
36
|
+
try {
|
|
37
|
+
const files = await readdir(basePath);
|
|
38
|
+
for (const name of files) {
|
|
39
|
+
const fullPath = join(basePath, name);
|
|
40
|
+
try {
|
|
41
|
+
const s = await stat(fullPath);
|
|
42
|
+
entries.push({
|
|
43
|
+
name,
|
|
44
|
+
path: fullPath,
|
|
45
|
+
type: s.isDirectory() ? "directory" : "file",
|
|
46
|
+
size: s.size,
|
|
47
|
+
});
|
|
48
|
+
} catch {
|
|
49
|
+
entries.push({ name, path: fullPath, type: "file" });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
log.error("listDir error", { error: err });
|
|
54
|
+
}
|
|
55
|
+
return { entries, basePath };
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
r("file.createFile", async (params) => {
|
|
59
|
+
const dirPath = validatePath(params.dirPath);
|
|
60
|
+
const filePath = join(dirPath, params.name);
|
|
61
|
+
await writeFile(filePath, "");
|
|
62
|
+
return { path: filePath };
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
r("file.createDir", async (params) => {
|
|
66
|
+
const dirPath = validatePath(params.dirPath);
|
|
67
|
+
const fullDirPath = join(dirPath, params.name);
|
|
68
|
+
await mkdir(fullDirPath, { recursive: true });
|
|
69
|
+
return { path: fullDirPath };
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
r("file.rename", async (params) => {
|
|
73
|
+
const oldPath = validatePath(params.oldPath);
|
|
74
|
+
const newPath = join(dirname(oldPath), params.newName);
|
|
75
|
+
await rename(oldPath, newPath);
|
|
76
|
+
return { newPath };
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
r("file.delete", async (params) => {
|
|
80
|
+
const safePath = validatePath(params.path);
|
|
81
|
+
await rm(safePath, { recursive: true, force: true });
|
|
82
|
+
return { ok: true };
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
r("file.copy", async (params) => {
|
|
86
|
+
const srcPath = validatePath(params.srcPath);
|
|
87
|
+
const destDir = validatePath(params.destDir);
|
|
88
|
+
const name = srcPath.split("/").pop() || srcPath;
|
|
89
|
+
const destPath = join(destDir, name);
|
|
90
|
+
await cp(srcPath, destPath, { recursive: true });
|
|
91
|
+
return { path: destPath };
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
r("file.readFile", async (params) => {
|
|
95
|
+
const filePath = validatePath(params.path);
|
|
96
|
+
const content = await readFile(filePath);
|
|
97
|
+
return { content: content.toString(), size: content.length };
|
|
98
|
+
});
|
|
99
|
+
}
|