@dyyz1993/create-agent 2.1.0 → 2.1.2
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 +5 -4
- package/src/__tests__/cli.test.ts +2 -0
- package/src/__tests__/copy.test.ts +110 -122
- package/src/__tests__/create-args.test.ts +113 -0
- package/src/__tests__/templates.test.ts +29 -3
- package/src/__tests__/update.test.ts +129 -0
- package/src/cli.ts +30 -32
- package/src/commands/create.ts +83 -24
- package/src/commands/update.ts +174 -0
- package/src/commands/workspace.ts +26 -6
- package/src/lib/copy.ts +233 -93
- package/src/lib/templates.ts +12 -0
- package/templates/agent/.husky/commit-msg +4 -0
- package/templates/agent/.husky/pre-commit +11 -0
- package/templates/agent/.husky/pre-push +6 -0
- package/templates/agent/.prettierignore +6 -0
- package/templates/agent/.prettierrc +9 -0
- package/templates/agent/CHANGELOG.md +15 -0
- package/templates/agent/commitlint.config.js +8 -0
- package/templates/agent/package.json +19 -4
- package/templates/agent/src/gateway/__tests__/ws-handler-token.test.ts +53 -39
- package/templates/agent/src/mainview/App.tsx +14 -12
- package/templates/agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +194 -190
- package/templates/agent/src/mainview/components/bash/BashPanel.tsx +210 -189
- package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +45 -20
- package/templates/agent/src/mainview/components/common/ThemeToggle.tsx +41 -21
- package/templates/agent/src/mainview/components/debug/DebugPanel.tsx +181 -114
- package/templates/agent/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +80 -80
- package/templates/agent/src/mainview/components/diff/__tests__/DiffViewerPanel.test.tsx +61 -58
- package/templates/agent/src/mainview/components/feed/FeedPanel.tsx +43 -41
- package/templates/agent/src/mainview/components/file-preview/FilePreviewOverlay.tsx +69 -50
- package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +31 -18
- package/templates/agent/src/mainview/components/git/GitPanel.tsx +731 -490
- package/templates/agent/src/mainview/components/git/__tests__/GitPanel.test.tsx +157 -139
- package/templates/agent/src/mainview/components/layout/AppLayout.tsx +210 -161
- package/templates/agent/src/mainview/components/layout/__tests__/AppLayout.test.tsx +130 -122
- package/templates/agent/src/mainview/components/rules/RulesPanel.tsx +119 -109
- package/templates/agent/src/mainview/components/search/SearchPanel.tsx +123 -117
- package/templates/agent/src/mainview/components/search/__tests__/SearchPanel.test.tsx +64 -44
- package/templates/agent/src/mainview/components/sidebar/__tests__/PinButton.test.tsx +38 -38
- package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +40 -38
- package/templates/agent/src/mainview/components/todo/__tests__/TodoPanel.test.tsx +72 -72
- package/templates/agent/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/agent/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/agent/src/mainview/stores/use-app-store.ts +96 -86
- package/templates/agent/src/mainview/stores/use-explorer-store.ts +292 -275
- package/templates/agent/src/mainview/types/index.ts +23 -22
- package/templates/agent/src/mainview/utils/file-icon.tsx +17 -21
- package/templates/agent/src/shared/handlers/chat.ts +53 -53
- package/templates/agent/src/shared/handlers/debug.ts +13 -3
- package/templates/browser-agent/.env.example +19 -0
- package/templates/browser-agent/.husky/commit-msg +4 -0
- package/templates/browser-agent/.husky/pre-commit +11 -0
- package/templates/browser-agent/.husky/pre-push +6 -0
- package/templates/browser-agent/.prettierignore +6 -0
- package/templates/browser-agent/.prettierrc +9 -0
- package/templates/browser-agent/AGENTS.md +396 -0
- package/templates/browser-agent/CHANGELOG.md +15 -0
- package/templates/browser-agent/LICENSE +21 -0
- package/templates/browser-agent/README.md +103 -0
- package/templates/browser-agent/commitlint.config.js +8 -0
- package/templates/browser-agent/electrobun.config.ts +27 -0
- package/templates/browser-agent/electron/main.js +46 -0
- package/templates/browser-agent/electron/preload.js +5 -0
- package/templates/browser-agent/electron-builder.json +40 -0
- package/templates/browser-agent/eslint.config.mjs +79 -0
- package/templates/browser-agent/llms.txt +24 -0
- package/templates/browser-agent/package.json +140 -0
- package/templates/browser-agent/postcss.config.js +6 -0
- package/templates/browser-agent/scripts/dev.ts +138 -0
- package/templates/browser-agent/src/__tests__/hybrid-mode.test.ts +126 -0
- package/templates/browser-agent/src/__tests__/server-config-security.test.ts +55 -0
- package/templates/browser-agent/src/__tests__/server-config.test.ts +59 -0
- package/templates/browser-agent/src/bun/index.ts +130 -0
- package/templates/browser-agent/src/bun/three.d.ts +1 -0
- package/templates/browser-agent/src/gateway/http-routes.ts +1 -0
- package/templates/browser-agent/src/gateway/ipc-transport.ts +68 -0
- package/templates/browser-agent/src/gateway/sse-transport.ts +221 -0
- package/templates/browser-agent/src/mainview/App.tsx +45 -0
- package/templates/browser-agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
- package/templates/browser-agent/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/browser-agent/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
- package/templates/browser-agent/src/mainview/__tests__/setup.ts +40 -0
- package/templates/browser-agent/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
- package/templates/browser-agent/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
- package/templates/browser-agent/src/mainview/__tests__/theme-variables.test.ts +36 -0
- package/templates/browser-agent/src/mainview/components/assets/AssetsPanel.tsx +139 -0
- package/templates/browser-agent/src/mainview/components/chat/ChatPanel.tsx +219 -0
- package/templates/browser-agent/src/mainview/components/chat/CommandBar.tsx +184 -0
- package/templates/browser-agent/src/mainview/components/chat/MessageBubble.tsx +249 -0
- package/templates/browser-agent/src/mainview/components/chat/ToolPicker.tsx +115 -0
- package/templates/browser-agent/src/mainview/components/common/ErrorBoundary.tsx +1 -0
- package/templates/browser-agent/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/browser-agent/src/mainview/components/common/ThemeToggle.tsx +45 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/browser-agent/src/mainview/components/dev/NetworkPanel.tsx +155 -0
- package/templates/browser-agent/src/mainview/components/layout/AppLayout.tsx +311 -0
- package/templates/browser-agent/src/mainview/components/onboarding/SetupWizard.tsx +310 -0
- package/templates/browser-agent/src/mainview/components/process/ProcessPanel.tsx +329 -0
- package/templates/browser-agent/src/mainview/components/sidebar/SessionSidebar.tsx +122 -0
- package/templates/browser-agent/src/mainview/components/sidebar/SkillSidebar.tsx +115 -0
- package/templates/browser-agent/src/mainview/components/topbar/TopBar.tsx +350 -0
- package/templates/browser-agent/src/mainview/global.d.ts +13 -0
- package/templates/browser-agent/src/mainview/hooks/__tests__/use-breakpoint.test.ts +151 -0
- package/templates/browser-agent/src/mainview/hooks/use-agent-chat.ts +157 -0
- package/templates/browser-agent/src/mainview/hooks/use-breakpoint.ts +68 -0
- package/templates/browser-agent/src/mainview/hooks/use-rpc-init.ts +71 -0
- package/templates/browser-agent/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/browser-agent/src/mainview/index.css +71 -0
- package/templates/browser-agent/src/mainview/index.html +12 -0
- package/templates/browser-agent/src/mainview/lib/api-client.ts +397 -0
- package/templates/browser-agent/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/browser-agent/src/mainview/lib/i18n/locales/en.json +130 -0
- package/templates/browser-agent/src/mainview/lib/i18n/locales/zh.json +128 -0
- package/templates/browser-agent/src/mainview/lib/network-bus.ts +92 -0
- package/templates/browser-agent/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/browser-agent/src/mainview/main.tsx +18 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/browser-agent/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/browser-agent/src/mainview/stores/use-asset-store.ts +65 -0
- package/templates/browser-agent/src/mainview/stores/use-chat-store.ts +200 -0
- package/templates/browser-agent/src/mainview/stores/use-connection-store.ts +173 -0
- package/templates/browser-agent/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/browser-agent/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/browser-agent/src/mainview/stores/use-network-panel-store.ts +18 -0
- package/templates/browser-agent/src/mainview/stores/use-record-store.ts +147 -0
- package/templates/browser-agent/src/mainview/stores/use-session-store.ts +151 -0
- package/templates/browser-agent/src/mainview/stores/use-sidebar-store.ts +161 -0
- package/templates/browser-agent/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/browser-agent/src/mainview/stores/use-view-store.ts +20 -0
- package/templates/browser-agent/src/mainview/types/index.ts +6 -0
- package/templates/browser-agent/src/server-config.ts +45 -0
- package/templates/browser-agent/src/server.ts +78 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/browser-agent/src/shared/handlers/browser.ts +596 -0
- package/templates/browser-agent/src/shared/handlers/chat.ts +213 -0
- package/templates/browser-agent/src/shared/handlers/file.ts +99 -0
- package/templates/browser-agent/src/shared/handlers/index.ts +7 -0
- package/templates/browser-agent/src/shared/handlers/session.ts +167 -0
- package/templates/browser-agent/src/shared/handlers/system.ts +27 -0
- package/templates/browser-agent/src/shared/handlers/timer.ts +34 -0
- package/templates/browser-agent/src/shared/http-routes.ts +437 -0
- package/templates/browser-agent/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/browser-agent/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/browser-agent/src/shared/lib/__tests__/web-server.test.ts +203 -0
- package/templates/browser-agent/src/shared/lib/agent.ts +384 -0
- package/templates/browser-agent/src/shared/lib/cdp.ts +448 -0
- package/templates/browser-agent/src/shared/lib/generate.ts +111 -0
- package/templates/browser-agent/src/shared/lib/logger.ts +152 -0
- package/templates/browser-agent/src/shared/lib/mock-stream.ts +147 -0
- package/templates/browser-agent/src/shared/lib/path-security.ts +38 -0
- package/templates/browser-agent/src/shared/lib/port-registry.ts +103 -0
- package/templates/browser-agent/src/shared/lib/web-server.ts +127 -0
- package/templates/browser-agent/src/shared/lib/xhs-extract.ts +71 -0
- package/templates/browser-agent/src/shared/modules/browser.ts +86 -0
- package/templates/browser-agent/src/shared/modules/chat.ts +20 -0
- package/templates/browser-agent/src/shared/modules/file.ts +40 -0
- package/templates/browser-agent/src/shared/modules/session.ts +55 -0
- package/templates/browser-agent/src/shared/modules/system.ts +8 -0
- package/templates/browser-agent/src/shared/modules/timer.ts +11 -0
- package/templates/browser-agent/src/shared/register-all-handlers.ts +36 -0
- package/templates/browser-agent/src/shared/rpc-schema.ts +34 -0
- package/templates/browser-agent/tailwind.config.js +15 -0
- package/templates/browser-agent/tsconfig.ipc.json +14 -0
- package/templates/browser-agent/tsconfig.json +36 -0
- package/templates/browser-agent/vite.config.ts +3 -0
- package/templates/browser-agent/vitest.config.ts +3 -0
- package/templates/chat/.husky/commit-msg +4 -0
- package/templates/chat/.husky/pre-commit +11 -0
- package/templates/chat/.husky/pre-push +6 -0
- package/templates/chat/CHANGELOG.md +15 -0
- package/templates/chat/commitlint.config.js +8 -0
- package/templates/chat/package.json +19 -4
- package/templates/chat/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/chat/src/mainview/__tests__/setup.ts +32 -29
- package/templates/chat/src/mainview/components/chat/ChatPanel.tsx +80 -55
- package/templates/chat/src/mainview/components/common/ThemeToggle.tsx +40 -20
- package/templates/chat/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/chat/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/chat/src/shared/handlers/chat.ts +17 -19
- package/templates/chat/src/shared/handlers/debug.ts +12 -2
- package/templates/cowork/.env.example +8 -0
- package/templates/cowork/.prettierignore +6 -0
- package/templates/cowork/.prettierrc +9 -0
- package/templates/cowork/AGENTS.md +236 -0
- package/templates/cowork/CHANGELOG.md +15 -0
- package/templates/cowork/LICENSE +21 -0
- package/templates/cowork/README.md +103 -0
- package/templates/cowork/commitlint.config.js +8 -0
- package/templates/cowork/docs/CODE-VIEW-PLAN.md +637 -0
- package/templates/cowork/docs/CODE-VIEW-V2.md +196 -0
- package/templates/cowork/docs/CODE-VIEW-V4.md +150 -0
- package/templates/cowork/electrobun.config.ts +27 -0
- package/templates/cowork/eslint.config.mjs +79 -0
- package/templates/cowork/llms.txt +24 -0
- package/templates/cowork/package.json +87 -0
- package/templates/cowork/postcss.config.js +6 -0
- package/templates/cowork/scripts/dev.ts +138 -0
- package/templates/cowork/src/__tests__/hybrid-mode.test.ts +126 -0
- package/templates/cowork/src/__tests__/server-config-security.test.ts +55 -0
- package/templates/cowork/src/__tests__/server-config.test.ts +59 -0
- package/templates/cowork/src/bun/index.ts +130 -0
- package/templates/cowork/src/bun/three.d.ts +1 -0
- package/templates/cowork/src/gateway/http-routes.ts +1 -0
- package/templates/cowork/src/gateway/ipc-transport.ts +68 -0
- package/templates/cowork/src/gateway/sse-transport.ts +231 -0
- package/templates/cowork/src/mainview/App.tsx +45 -0
- package/templates/cowork/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
- package/templates/cowork/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/cowork/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
- package/templates/cowork/src/mainview/__tests__/setup.ts +40 -0
- package/templates/cowork/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
- package/templates/cowork/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
- package/templates/cowork/src/mainview/__tests__/theme-variables.test.ts +36 -0
- package/templates/cowork/src/mainview/components/chat/TaskChat.tsx +311 -0
- package/templates/cowork/src/mainview/components/chat/__tests__/localhost-links.test.ts +76 -0
- package/templates/cowork/src/mainview/components/common/ErrorBoundary.tsx +1 -0
- package/templates/cowork/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/cowork/src/mainview/components/common/ThemeToggle.tsx +45 -0
- package/templates/cowork/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/cowork/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/cowork/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/cowork/src/mainview/components/dev/NetworkPanel.tsx +155 -0
- package/templates/cowork/src/mainview/components/layout/AppLayout.tsx +216 -0
- package/templates/cowork/src/mainview/components/right/ArtifactsPanel.tsx +54 -0
- package/templates/cowork/src/mainview/components/right/ContextPanel.tsx +133 -0
- package/templates/cowork/src/mainview/components/right/ElementPicker.tsx +206 -0
- package/templates/cowork/src/mainview/components/right/PreviewBlock.tsx +155 -0
- package/templates/cowork/src/mainview/components/right/ProgressPanel.tsx +85 -0
- package/templates/cowork/src/mainview/components/sidebar/TaskSidebar.tsx +211 -0
- package/templates/cowork/src/mainview/components/topbar/TopBar.tsx +86 -0
- package/templates/cowork/src/mainview/global.d.ts +13 -0
- package/templates/cowork/src/mainview/hooks/__tests__/use-breakpoint.test.ts +123 -0
- package/templates/cowork/src/mainview/hooks/use-breakpoint.ts +53 -0
- package/templates/cowork/src/mainview/hooks/use-rpc-init.ts +26 -0
- package/templates/cowork/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/cowork/src/mainview/index.css +89 -0
- package/templates/cowork/src/mainview/index.html +12 -0
- package/templates/cowork/src/mainview/lib/api-client.ts +404 -0
- package/templates/cowork/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/cowork/src/mainview/lib/i18n/locales/en.json +130 -0
- package/templates/cowork/src/mainview/lib/i18n/locales/zh.json +128 -0
- package/templates/cowork/src/mainview/lib/network-bus.ts +92 -0
- package/templates/cowork/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/cowork/src/mainview/main.tsx +18 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-preview-store.test.ts +193 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-sidebar-store.test.ts +81 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/cowork/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/cowork/src/mainview/stores/use-chat-store.ts +198 -0
- package/templates/cowork/src/mainview/stores/use-connection-store.ts +168 -0
- package/templates/cowork/src/mainview/stores/use-context-store.ts +68 -0
- package/templates/cowork/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/cowork/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/cowork/src/mainview/stores/use-network-panel-store.ts +18 -0
- package/templates/cowork/src/mainview/stores/use-output-store.ts +47 -0
- package/templates/cowork/src/mainview/stores/use-preview-store.ts +97 -0
- package/templates/cowork/src/mainview/stores/use-sidebar-store.ts +272 -0
- package/templates/cowork/src/mainview/stores/use-task-store.ts +86 -0
- package/templates/cowork/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/cowork/src/mainview/stores/use-view-store.ts +29 -0
- package/templates/cowork/src/mainview/types/index.ts +6 -0
- package/templates/cowork/src/server-config.ts +44 -0
- package/templates/cowork/src/server.ts +78 -0
- package/templates/cowork/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
- package/templates/cowork/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/cowork/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/cowork/src/shared/handlers/__tests__/preview-handler.test.ts +172 -0
- package/templates/cowork/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/cowork/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/cowork/src/shared/handlers/chat.ts +213 -0
- package/templates/cowork/src/shared/handlers/context.ts +72 -0
- package/templates/cowork/src/shared/handlers/file.ts +99 -0
- package/templates/cowork/src/shared/handlers/index.ts +9 -0
- package/templates/cowork/src/shared/handlers/output.ts +59 -0
- package/templates/cowork/src/shared/handlers/preview.ts +81 -0
- package/templates/cowork/src/shared/handlers/system.ts +27 -0
- package/templates/cowork/src/shared/handlers/task.ts +101 -0
- package/templates/cowork/src/shared/handlers/timer.ts +34 -0
- package/templates/cowork/src/shared/http-routes.ts +444 -0
- package/templates/cowork/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/cowork/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/cowork/src/shared/lib/__tests__/web-server.test.ts +203 -0
- package/templates/cowork/src/shared/lib/logger.ts +152 -0
- package/templates/cowork/src/shared/lib/path-security.ts +38 -0
- package/templates/cowork/src/shared/lib/port-registry.ts +103 -0
- package/templates/cowork/src/shared/lib/web-server.ts +127 -0
- package/templates/cowork/src/shared/modules/chat.ts +20 -0
- package/templates/cowork/src/shared/modules/context.ts +32 -0
- package/templates/cowork/src/shared/modules/file.ts +40 -0
- package/templates/cowork/src/shared/modules/output.ts +20 -0
- package/templates/cowork/src/shared/modules/preview.ts +44 -0
- package/templates/cowork/src/shared/modules/system.ts +8 -0
- package/templates/cowork/src/shared/modules/task.ts +31 -0
- package/templates/cowork/src/shared/modules/timer.ts +11 -0
- package/templates/cowork/src/shared/register-all-handlers.ts +36 -0
- package/templates/cowork/src/shared/rpc-schema.ts +38 -0
- package/templates/cowork/tailwind.config.js +15 -0
- package/templates/cowork/test-upload.txt +0 -0
- package/templates/cowork/tsconfig.ipc.json +14 -0
- package/templates/cowork/tsconfig.json +36 -0
- package/templates/cowork/vite.config.ts +3 -0
- package/templates/cowork/vitest.config.ts +3 -0
- package/templates/general/.husky/commit-msg +4 -0
- package/templates/general/.husky/pre-commit +11 -0
- package/templates/general/.husky/pre-push +6 -0
- package/templates/general/CHANGELOG.md +15 -0
- package/templates/general/commitlint.config.js +8 -0
- package/templates/general/package.json +19 -4
- package/templates/general/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/general/src/mainview/__tests__/setup.ts +32 -29
- package/templates/general/src/mainview/components/chat/ChatPanel.tsx +80 -55
- package/templates/general/src/mainview/components/common/ThemeToggle.tsx +40 -20
- package/templates/general/src/mainview/components/debug/DebugPanel.tsx +170 -156
- package/templates/general/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +169 -0
- package/templates/general/src/mainview/components/explorer/ConfirmDialog.tsx +42 -42
- package/templates/general/src/mainview/components/explorer/ContextMenu.tsx +72 -67
- package/templates/general/src/mainview/components/feed/FeedPanel.tsx +7 -5
- package/templates/general/src/mainview/components/file-preview/FilePreviewOverlay.tsx +64 -45
- package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +24 -7
- package/templates/general/src/mainview/components/git/GitPanel.tsx +700 -473
- package/templates/general/src/mainview/components/layout/AppLayout.tsx +123 -114
- package/templates/general/src/mainview/components/search/SearchPanel.tsx +15 -19
- package/templates/general/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/general/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/general/src/mainview/stores/__tests__/use-explorer-store.test.ts +259 -0
- package/templates/general/src/mainview/stores/__tests__/use-feed-store.test.ts +160 -0
- package/templates/general/src/mainview/stores/__tests__/use-git-store.test.ts +313 -0
- package/templates/general/src/mainview/stores/__tests__/use-notification-store.test.ts +115 -0
- package/templates/general/src/mainview/stores/__tests__/use-sidebar-store.test.ts +120 -0
- package/templates/general/src/mainview/stores/use-explorer-store.ts +277 -260
- package/templates/general/src/mainview/types/index.ts +21 -20
- package/templates/general/src/shared/handlers/chat.ts +1 -1
- package/templates/general/src/shared/handlers/debug.ts +12 -2
- package/templates/shared/components/ErrorBoundary.tsx +0 -1
- package/templates/shared/vite-base.config.ts +8 -7
- /package/templates/{shared → browser-agent}/test-upload.txt +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dyyz1993/create-agent",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Create Agent project scaffolding CLI",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
"templates/"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"sync-templates": "
|
|
18
|
-
"test": "bun test src/__tests__/",
|
|
19
|
-
"
|
|
17
|
+
"sync-templates": "node scripts/sync-templates.mjs",
|
|
18
|
+
"test": "bun test src/__tests__/cli.test.ts src/__tests__/copy.test.ts src/__tests__/templates.test.ts src/__tests__/create-args.test.ts src/__tests__/update.test.ts",
|
|
19
|
+
"verify-templates": "node scripts/verify-templates.mjs",
|
|
20
|
+
"prepublishOnly": "node scripts/verify-templates.mjs && bun test src/__tests__/cli.test.ts src/__tests__/copy.test.ts src/__tests__/templates.test.ts src/__tests__/create-args.test.ts src/__tests__/update.test.ts"
|
|
20
21
|
},
|
|
21
22
|
"engines": {
|
|
22
23
|
"bun": ">=1.0.0"
|
|
@@ -64,6 +64,8 @@ describe('CLI argument parsing (list)', () => {
|
|
|
64
64
|
expect(output).toContain('general');
|
|
65
65
|
expect(output).toContain('chat');
|
|
66
66
|
expect(output).toContain('agent');
|
|
67
|
+
expect(output).toContain('browser-agent');
|
|
68
|
+
expect(output).toContain('cowork');
|
|
67
69
|
expect(output).toContain('Available templates');
|
|
68
70
|
|
|
69
71
|
mockLog.mockRestore();
|
|
@@ -1,168 +1,156 @@
|
|
|
1
|
-
import { describe, test, expect, afterAll } from
|
|
2
|
-
import { mkdtempSync, mkdirSync, writeFileSync, existsSync, readFileSync, rmSync } from
|
|
3
|
-
import { join } from
|
|
4
|
-
import { tmpdir } from
|
|
5
|
-
import { copyAndReplace, deriveNames } from
|
|
1
|
+
import { describe, test, expect, afterAll } from "bun:test";
|
|
2
|
+
import { mkdtempSync, mkdirSync, writeFileSync, existsSync, readFileSync, rmSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { copyAndReplace, deriveNames } from "../lib/copy";
|
|
6
6
|
|
|
7
7
|
const TMP_DIRS: string[] = [];
|
|
8
8
|
|
|
9
9
|
afterAll(() => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
for (const d of TMP_DIRS) {
|
|
11
|
+
if (existsSync(d)) rmSync(d, { recursive: true, force: true });
|
|
12
|
+
}
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
function makeTmp(prefix =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
function makeTmp(prefix = "pi-cli-test-"): string {
|
|
16
|
+
const d = mkdtempSync(join(tmpdir(), prefix));
|
|
17
|
+
TMP_DIRS.push(d);
|
|
18
|
+
return d;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
describe(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
21
|
+
describe("deriveNames", () => {
|
|
22
|
+
test("simple name", () => {
|
|
23
|
+
const names = deriveNames("my-app");
|
|
24
|
+
expect(names.pascalName).toBe("MyApp");
|
|
25
|
+
expect(names.identifier).toBe("com.myapp.app");
|
|
26
|
+
expect(names.shortId).toBe("com.myapp");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("single word", () => {
|
|
30
|
+
const names = deriveNames("hello");
|
|
31
|
+
expect(names.pascalName).toBe("Hello");
|
|
32
|
+
expect(names.identifier).toBe("com.hello.app");
|
|
33
|
+
expect(names.shortId).toBe("com.hello");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("multi-segment name", () => {
|
|
37
|
+
const names = deriveNames("my-cool-project");
|
|
38
|
+
expect(names.pascalName).toBe("MyCoolProject");
|
|
39
|
+
expect(names.identifier).toBe("com.mycoolproject.app");
|
|
40
|
+
expect(names.shortId).toBe("com.mycoolproject");
|
|
41
|
+
});
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
describe(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
describe("copyAndReplace", () => {
|
|
45
|
+
test("copies files from src to dest", () => {
|
|
46
|
+
const srcDir = makeTmp("pi-src-");
|
|
47
|
+
const destDir = makeTmp("pi-dest-");
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
writeFileSync(join(srcDir, "hello.txt"), "hello world");
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
copyAndReplace(srcDir, destDir, "test-project");
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
expect(existsSync(join(destDir, "hello.txt"))).toBe(true);
|
|
54
|
+
expect(readFileSync(join(destDir, "hello.txt"), "utf-8")).toBe("hello world");
|
|
55
|
+
});
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
test("replaces pi-agent-template with project name", () => {
|
|
58
|
+
const srcDir = makeTmp("pi-src-");
|
|
59
|
+
const destDir = makeTmp("pi-dest-");
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
writeFileSync(join(srcDir, "config.json"), '{"name": "pi-agent-template"}');
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
copyAndReplace(srcDir, destDir, "my-app");
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
const content = readFileSync(join(destDir, "config.json"), "utf-8");
|
|
66
|
+
expect(content).toBe('{"name": "my-app"}');
|
|
67
|
+
});
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
test("replaces Pi Agent Template with pascal name", () => {
|
|
70
|
+
const srcDir = makeTmp("pi-src-");
|
|
71
|
+
const destDir = makeTmp("pi-dest-");
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
writeFileSync(join(srcDir, "readme.md"), "# Pi Agent Template");
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
copyAndReplace(srcDir, destDir, "my-app");
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
const content = readFileSync(join(destDir, "readme.md"), "utf-8");
|
|
78
|
+
expect(content).toBe("# MyApp");
|
|
79
|
+
});
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
test("replaces Pi Agent with pascal name", () => {
|
|
82
|
+
const srcDir = makeTmp("pi-src-");
|
|
83
|
+
const destDir = makeTmp("pi-dest-");
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
writeFileSync(join(srcDir, "app.ts"), "export const Pi Agent = true");
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
copyAndReplace(srcDir, destDir, "cool-project");
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
const content = readFileSync(join(destDir, "app.ts"), "utf-8");
|
|
90
|
+
expect(content).toBe("export const CoolProject = true");
|
|
91
|
+
});
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
test("replaces com.piagent.template with identifier", () => {
|
|
94
|
+
const srcDir = makeTmp("pi-src-");
|
|
95
|
+
const destDir = makeTmp("pi-dest-");
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
writeFileSync(join(srcDir, "plist.xml"), "<string>com.piagent.template</string>");
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
copyAndReplace(srcDir, destDir, "my-app");
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
const content = readFileSync(join(destDir, "plist.xml"), "utf-8");
|
|
102
|
+
expect(content).toBe("<string>com.myapp.app</string>");
|
|
103
|
+
});
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
test("replaces com.piagent with shortId", () => {
|
|
106
|
+
const srcDir = makeTmp("pi-src-");
|
|
107
|
+
const destDir = makeTmp("pi-dest-");
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
writeFileSync(join(srcDir, "config.xml"), "<id>com.piagent.something</id>");
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
copyAndReplace(srcDir, destDir, "my-app");
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
const content = readFileSync(join(destDir, "config.xml"), "utf-8");
|
|
114
|
+
expect(content).toBe("<id>com.myapp.something</id>");
|
|
115
|
+
});
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
test("skips node_modules directory", () => {
|
|
118
|
+
const srcDir = makeTmp("pi-src-");
|
|
119
|
+
const destDir = makeTmp("pi-dest-");
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
mkdirSync(join(srcDir, "node_modules", "pkg"), { recursive: true });
|
|
122
|
+
writeFileSync(join(srcDir, "node_modules", "pkg", "index.js"), "module.exports = 1;");
|
|
123
|
+
writeFileSync(join(srcDir, "root.txt"), "root");
|
|
122
124
|
|
|
123
|
-
|
|
125
|
+
copyAndReplace(srcDir, destDir, "test");
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
expect(existsSync(join(destDir, "root.txt"))).toBe(true);
|
|
128
|
+
expect(existsSync(join(destDir, "node_modules"))).toBe(false);
|
|
129
|
+
});
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
test("skips bun.lock file", () => {
|
|
132
|
+
const srcDir = makeTmp("pi-src-");
|
|
133
|
+
const destDir = makeTmp("pi-dest-");
|
|
132
134
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
writeFileSync(join(srcDir, 'root.txt'), 'root');
|
|
135
|
+
writeFileSync(join(srcDir, "bun.lock"), "lockfile content");
|
|
136
|
+
writeFileSync(join(srcDir, "package.json"), "{}");
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
copyAndReplace(srcDir, destDir, "test");
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
expect(existsSync(join(destDir, "package.json"))).toBe(true);
|
|
141
|
+
expect(existsSync(join(destDir, "bun.lock"))).toBe(false);
|
|
142
|
+
});
|
|
142
143
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
test("copies nested directories recursively", () => {
|
|
145
|
+
const srcDir = makeTmp("pi-src-");
|
|
146
|
+
const destDir = makeTmp("pi-dest-");
|
|
146
147
|
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
mkdirSync(join(srcDir, "src", "lib"), { recursive: true });
|
|
149
|
+
writeFileSync(join(srcDir, "src", "lib", "util.ts"), "// pi-agent-template util");
|
|
149
150
|
|
|
150
|
-
|
|
151
|
+
copyAndReplace(srcDir, destDir, "my-proj");
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
test('copies nested directories recursively', () => {
|
|
157
|
-
const srcDir = makeTmp('pi-src-');
|
|
158
|
-
const destDir = makeTmp('pi-dest-');
|
|
159
|
-
|
|
160
|
-
mkdirSync(join(srcDir, 'src', 'lib'), { recursive: true });
|
|
161
|
-
writeFileSync(join(srcDir, 'src', 'lib', 'util.ts'), '// pi-agent-template util');
|
|
162
|
-
|
|
163
|
-
copyAndReplace(srcDir, destDir, 'my-proj');
|
|
164
|
-
|
|
165
|
-
const content = readFileSync(join(destDir, 'src', 'lib', 'util.ts'), 'utf-8');
|
|
166
|
-
expect(content).toBe('// my-proj util');
|
|
167
|
-
});
|
|
153
|
+
const content = readFileSync(join(destDir, "src", "lib", "util.ts"), "utf-8");
|
|
154
|
+
expect(content).toBe("// my-proj util");
|
|
155
|
+
});
|
|
168
156
|
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { describe, test, expect } from "bun:test";
|
|
2
|
+
import { mkdtempSync, writeFileSync, readFileSync, rmSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { parseArgs } from "../commands/create";
|
|
6
|
+
import { validateWorkspaceName } from "../commands/workspace";
|
|
7
|
+
import { copyAndReplace, expandTilde } from "../lib/copy";
|
|
8
|
+
import { homedir } from "os";
|
|
9
|
+
|
|
10
|
+
describe("create parseArgs", () => {
|
|
11
|
+
test("parses --type and --dir with separate values", () => {
|
|
12
|
+
const result = parseArgs(["my-app", "--type", "chat", "--dir", "/tmp/x"]);
|
|
13
|
+
expect(result.error).toBeUndefined();
|
|
14
|
+
expect(result.positional).toEqual(["my-app"]);
|
|
15
|
+
expect(result.options.type).toBe("chat");
|
|
16
|
+
expect(result.options.dir).toBe("/tmp/x");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("supports --key=value syntax", () => {
|
|
20
|
+
const result = parseArgs(["my-app", "--type=chat"]);
|
|
21
|
+
expect(result.error).toBeUndefined();
|
|
22
|
+
expect(result.options.type).toBe("chat");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("unknown flag returns an error instead of silently ignoring", () => {
|
|
26
|
+
const result = parseArgs(["my-app", "--typo", "chat"]);
|
|
27
|
+
expect(result.error).toContain("Unknown option: --typo");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("missing --type value returns an error instead of falling back to general", () => {
|
|
31
|
+
const result = parseArgs(["my-app", "--type"]);
|
|
32
|
+
expect(result.error).toContain("--type requires a value");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("--type followed by another flag returns an error", () => {
|
|
36
|
+
const result = parseArgs(["my-app", "--type", "--dir", "/tmp"]);
|
|
37
|
+
expect(result.error).toContain("--type requires a value");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("-- separates remaining args as positional", () => {
|
|
41
|
+
const result = parseArgs(["my-app", "--", "not-a-flag"]);
|
|
42
|
+
expect(result.error).toBeUndefined();
|
|
43
|
+
expect(result.positional).toEqual(["my-app", "not-a-flag"]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("expandTilde", () => {
|
|
48
|
+
test("~ expands to home dir", () => {
|
|
49
|
+
expect(expandTilde("~")).toBe(homedir());
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("~/x expands under home dir", () => {
|
|
53
|
+
expect(expandTilde("~/projects/app")).toBe(join(homedir(), "projects/app"));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("other paths untouched", () => {
|
|
57
|
+
expect(expandTilde("/tmp/x")).toBe("/tmp/x");
|
|
58
|
+
expect(expandTilde("~bin/x")).toBe("~bin/x");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("validateWorkspaceName", () => {
|
|
63
|
+
test("accepts word chars, dots and dashes", () => {
|
|
64
|
+
expect(validateWorkspaceName("feature-chat-ui")).toBeNull();
|
|
65
|
+
expect(validateWorkspaceName("fix_1.2")).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("rejects spaces, slashes, shell metacharacters and empty names", () => {
|
|
69
|
+
expect(validateWorkspaceName("my workspace")).not.toBeNull();
|
|
70
|
+
expect(validateWorkspaceName("a/b")).not.toBeNull();
|
|
71
|
+
expect(validateWorkspaceName("x`cmd`")).not.toBeNull();
|
|
72
|
+
expect(validateWorkspaceName("..")).not.toBeNull();
|
|
73
|
+
expect(validateWorkspaceName("")).not.toBeNull();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("copyAndReplace binary safety", () => {
|
|
78
|
+
test("binary files are copied byte-for-byte, not utf-8 re-encoded", () => {
|
|
79
|
+
const src = mkdtempSync(join(tmpdir(), "pi-bin-src-"));
|
|
80
|
+
const dest = mkdtempSync(join(tmpdir(), "pi-bin-dest-"));
|
|
81
|
+
try {
|
|
82
|
+
// PNG magic bytes + NUL bytes that utf-8 round-trip would corrupt
|
|
83
|
+
const binary = Buffer.from([
|
|
84
|
+
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0xff, 0xfe, 0x01,
|
|
85
|
+
]);
|
|
86
|
+
writeFileSync(join(src, "icon.png"), binary);
|
|
87
|
+
writeFileSync(join(src, "data.bin"), Buffer.from([0x00, 0x01, 0x02, 0x03]));
|
|
88
|
+
|
|
89
|
+
copyAndReplace(src, dest, "my-app");
|
|
90
|
+
|
|
91
|
+
expect(readFileSync(join(dest, "icon.png")).equals(binary)).toBe(true);
|
|
92
|
+
expect(
|
|
93
|
+
readFileSync(join(dest, "data.bin")).equals(Buffer.from([0x00, 0x01, 0x02, 0x03]))
|
|
94
|
+
).toBe(true);
|
|
95
|
+
} finally {
|
|
96
|
+
rmSync(src, { recursive: true, force: true });
|
|
97
|
+
rmSync(dest, { recursive: true, force: true });
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("text files still get placeholder replacement", () => {
|
|
102
|
+
const src = mkdtempSync(join(tmpdir(), "pi-txt-src-"));
|
|
103
|
+
const dest = mkdtempSync(join(tmpdir(), "pi-txt-dest-"));
|
|
104
|
+
try {
|
|
105
|
+
writeFileSync(join(src, "notes.md"), "project pi-agent-template rocks");
|
|
106
|
+
copyAndReplace(src, dest, "my-app");
|
|
107
|
+
expect(readFileSync(join(dest, "notes.md"), "utf-8")).toBe("project my-app rocks");
|
|
108
|
+
} finally {
|
|
109
|
+
rmSync(src, { recursive: true, force: true });
|
|
110
|
+
rmSync(dest, { recursive: true, force: true });
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -2,17 +2,19 @@ import { describe, test, expect } from 'bun:test';
|
|
|
2
2
|
import { getAllTemplates, getTemplateInfo, resolveTemplateDir } from '../lib/templates';
|
|
3
3
|
|
|
4
4
|
describe('getAllTemplates', () => {
|
|
5
|
-
test('returns
|
|
5
|
+
test('returns 5 templates', () => {
|
|
6
6
|
const templates = getAllTemplates();
|
|
7
|
-
expect(templates).toHaveLength(
|
|
7
|
+
expect(templates).toHaveLength(5);
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
test('includes general, chat, agent types', () => {
|
|
10
|
+
test('includes general, chat, agent, browser-agent, cowork types', () => {
|
|
11
11
|
const templates = getAllTemplates();
|
|
12
12
|
const types = templates.map((t) => t.type);
|
|
13
13
|
expect(types).toContain('general');
|
|
14
14
|
expect(types).toContain('chat');
|
|
15
15
|
expect(types).toContain('agent');
|
|
16
|
+
expect(types).toContain('browser-agent');
|
|
17
|
+
expect(types).toContain('cowork');
|
|
16
18
|
});
|
|
17
19
|
|
|
18
20
|
test('all templates are available', () => {
|
|
@@ -53,6 +55,20 @@ describe('getTemplateInfo', () => {
|
|
|
53
55
|
expect(info!.type).toBe('agent');
|
|
54
56
|
});
|
|
55
57
|
|
|
58
|
+
test('returns info for "browser-agent"', () => {
|
|
59
|
+
const info = getTemplateInfo('browser-agent');
|
|
60
|
+
expect(info).toBeDefined();
|
|
61
|
+
expect(info!.type).toBe('browser-agent');
|
|
62
|
+
expect(info!.dir).toBe('templates/browser-agent');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('returns info for "cowork"', () => {
|
|
66
|
+
const info = getTemplateInfo('cowork');
|
|
67
|
+
expect(info).toBeDefined();
|
|
68
|
+
expect(info!.type).toBe('cowork');
|
|
69
|
+
expect(info!.dir).toBe('templates/cowork');
|
|
70
|
+
});
|
|
71
|
+
|
|
56
72
|
test('returns undefined for unknown type', () => {
|
|
57
73
|
expect(getTemplateInfo('nonexistent')).toBeUndefined();
|
|
58
74
|
expect(getTemplateInfo('')).toBeUndefined();
|
|
@@ -75,6 +91,16 @@ describe('resolveTemplateDir', () => {
|
|
|
75
91
|
expect(dir).toBe('/fake/root/templates/agent');
|
|
76
92
|
});
|
|
77
93
|
|
|
94
|
+
test('resolves browser-agent template path', () => {
|
|
95
|
+
const dir = resolveTemplateDir('/fake/root', 'browser-agent');
|
|
96
|
+
expect(dir).toBe('/fake/root/templates/browser-agent');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('resolves cowork template path', () => {
|
|
100
|
+
const dir = resolveTemplateDir('/fake/root', 'cowork');
|
|
101
|
+
expect(dir).toBe('/fake/root/templates/cowork');
|
|
102
|
+
});
|
|
103
|
+
|
|
78
104
|
test('throws for invalid template type', () => {
|
|
79
105
|
expect(() => resolveTemplateDir('/root', 'invalid')).toThrow(
|
|
80
106
|
'Unknown template type: "invalid"',
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { describe, test, expect, afterAll } from "bun:test";
|
|
2
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { detectTemplateMeta } from "../commands/update";
|
|
6
|
+
import { postProcessTemplate } from "../lib/copy";
|
|
7
|
+
|
|
8
|
+
const TMP_DIRS: string[] = [];
|
|
9
|
+
|
|
10
|
+
afterAll(() => {
|
|
11
|
+
for (const d of TMP_DIRS) {
|
|
12
|
+
if (existsSync(d)) rmSync(d, { recursive: true, force: true });
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function makeTmp(prefix = "pi-update-test-"): string {
|
|
17
|
+
const d = mkdtempSync(join(tmpdir(), prefix));
|
|
18
|
+
TMP_DIRS.push(d);
|
|
19
|
+
return d;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function makeProject(name: string, modules: string[]): string {
|
|
23
|
+
const dir = makeTmp();
|
|
24
|
+
writeFileSync(join(dir, "package.json"), JSON.stringify({ name, version: "1.0.0" }, null, "\t"));
|
|
25
|
+
const modulesDir = join(dir, "src", "shared", "modules");
|
|
26
|
+
mkdirSync(modulesDir, { recursive: true });
|
|
27
|
+
for (const m of modules) {
|
|
28
|
+
mkdirSync(join(modulesDir, m), { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
return dir;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe("detectTemplateMeta", () => {
|
|
34
|
+
test("agent: bash + todo + rules", () => {
|
|
35
|
+
const dir = makeProject("my-agent", ["bash", "todo", "rules", "chat"]);
|
|
36
|
+
expect(detectTemplateMeta(dir)?.templateType).toBe("agent");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("browser-agent: browser module", () => {
|
|
40
|
+
const dir = makeProject("my-browser", ["browser", "chat"]);
|
|
41
|
+
expect(detectTemplateMeta(dir)?.templateType).toBe("browser-agent");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("cowork: task + context + output", () => {
|
|
45
|
+
const dir = makeProject("my-cowork", ["task", "context", "output"]);
|
|
46
|
+
expect(detectTemplateMeta(dir)?.templateType).toBe("cowork");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("chat: chat without file/git", () => {
|
|
50
|
+
const dir = makeProject("my-chat", ["chat"]);
|
|
51
|
+
expect(detectTemplateMeta(dir)?.templateType).toBe("chat");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("general: everything else", () => {
|
|
55
|
+
const dir = makeProject("my-general", ["chat", "file", "git"]);
|
|
56
|
+
expect(detectTemplateMeta(dir)?.templateType).toBe("general");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("returns project name from package.json", () => {
|
|
60
|
+
const dir = makeProject("custom-name", ["chat"]);
|
|
61
|
+
expect(detectTemplateMeta(dir)?.projectName).toBe("custom-name");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("null when no modules dir", () => {
|
|
65
|
+
const dir = makeTmp();
|
|
66
|
+
writeFileSync(join(dir, "package.json"), JSON.stringify({ name: "x" }));
|
|
67
|
+
expect(detectTemplateMeta(dir)).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("postProcessTemplate", () => {
|
|
72
|
+
test("resolves workspace deps to npm ranges and rewrites package name", () => {
|
|
73
|
+
const dir = makeTmp();
|
|
74
|
+
writeFileSync(
|
|
75
|
+
join(dir, "package.json"),
|
|
76
|
+
JSON.stringify(
|
|
77
|
+
{
|
|
78
|
+
name: "pi-general-app",
|
|
79
|
+
workspaces: ["packages/*"],
|
|
80
|
+
dependencies: { "@dyyz1993/rpc-core": "workspace:*" },
|
|
81
|
+
devDependencies: { "@dyyz1993/eslint-plugin-rpc": "workspace:*" },
|
|
82
|
+
},
|
|
83
|
+
null,
|
|
84
|
+
"\t"
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
writeFileSync(
|
|
88
|
+
join(dir, "eslint.config.mjs"),
|
|
89
|
+
[
|
|
90
|
+
"import rpcPlugin from '@dyyz1993/eslint-plugin-rpc';",
|
|
91
|
+
"export default [",
|
|
92
|
+
" {",
|
|
93
|
+
" plugins: { rpc: rpcPlugin },",
|
|
94
|
+
" rules: {",
|
|
95
|
+
" 'rpc/no-bare-method': 'error',",
|
|
96
|
+
" },",
|
|
97
|
+
" },",
|
|
98
|
+
"];",
|
|
99
|
+
"",
|
|
100
|
+
].join("\n")
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
postProcessTemplate(dir, "my-app");
|
|
104
|
+
|
|
105
|
+
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
|
|
106
|
+
// workspace:* 必须被解析成 npm 版本 range,且不允许写回(update --force 的回归测试)
|
|
107
|
+
expect(JSON.stringify(pkg)).not.toContain("workspace:");
|
|
108
|
+
expect(pkg.workspaces).toBeUndefined();
|
|
109
|
+
expect(pkg.dependencies?.["@dyyz1993/rpc-core"]).toMatch(/^\^?\d+\.\d+\.\d+/);
|
|
110
|
+
// 插件现在从 npm 安装,依赖保留而不是删除
|
|
111
|
+
expect(pkg.devDependencies?.["@dyyz1993/eslint-plugin-rpc"]).toMatch(/^\^?\d+\.\d+\.\d+/);
|
|
112
|
+
// 项目名写回(此前模板 name 永远不会被替换)
|
|
113
|
+
expect(pkg.name).toBe("my-app");
|
|
114
|
+
|
|
115
|
+
// RPC lint 规则在生成项目中保持启用
|
|
116
|
+
const eslint = readFileSync(join(dir, "eslint.config.mjs"), "utf-8");
|
|
117
|
+
expect(eslint).toContain("import rpcPlugin from '@dyyz1993/eslint-plugin-rpc'");
|
|
118
|
+
expect(eslint).toContain("'rpc/no-bare-method': 'error'");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("copies shared/ into the project", () => {
|
|
122
|
+
const dir = makeTmp();
|
|
123
|
+
postProcessTemplate(dir, "my-app");
|
|
124
|
+
expect(existsSync(join(dir, "shared", "vite-base.config.ts"))).toBe(true);
|
|
125
|
+
// 开发期专用文件不应进入用户项目
|
|
126
|
+
expect(existsSync(join(dir, "shared", "http-routes.ts"))).toBe(false);
|
|
127
|
+
expect(existsSync(join(dir, "shared", "logger.ts"))).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
});
|