# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Project Overview Cloud Drive Renamer (云盘批量重命名工具) - A Chrome/Edge extension for batch renaming files on cloud storage platforms. Currently supports Quark Drive (夸克网盘) with architecture ready for Aliyun Drive and Baidu Drive expansion. **Tech Stack:** - TypeScript 5.9+ with strict mode - Vite 5.4+ for building (with @crxjs/vite-plugin for Chrome extension support) - Lit 3.3+ for Web Components UI - Vitest for unit/integration tests, Playwright for E2E tests - Chrome Extension Manifest V3 ## Common Development Commands ### Development Workflow ```bash # Start development server with hot reload npm run dev # Run tests in watch mode during development npm test # Before committing: full validation (lint + typecheck + tests) npm run validate # Production build with complete quality gates npm run build ``` ### Testing ```bash # Unit tests with coverage npm run test:coverage # E2E tests npm run test:e2e # E2E tests with UI npm run test:e2e:ui # Run single test file npx vitest run tests/unit/executor.test.ts # Run test with specific pattern npx vitest run -t "should handle batch execution" ``` ### Code Quality ```bash # Lint check npm run lint # Auto-fix lint issues npm run lint:fix # TypeScript type checking (no emit) npm run typecheck ``` ### CI/CD ```bash # Full CI pipeline (used in GitHub Actions) npm run ci # Verify release package integrity npm run verify:release ``` ### Utilities ```bash # Sync version between package.json and manifest.json npm run sync:version # Resize images for store assets (parameterized) npm run resize screenshot # Store screenshots (1280x800) npm run resize logo # Logo (300x300) npm run resize small-promo # Small promo tile (440x280) npm run resize large-promo # Large promo tile (1400x560) ``` ## Architecture Overview ### Core Design Patterns **Adapter Pattern for Platform Support:** - `src/adapters/base/adapter.interface.ts` - Base adapter interface - `src/adapters/quark/` - Quark Drive implementation - `src/adapters/aliyun/` - Aliyun Drive implementation - `src/adapters/baidu/` - Baidu Pan implementation **Strategy Pattern for Rename Rules:** - `src/rules/base-rule.ts` - Base rule class - `src/rules/rule-factory.ts` - Rule factory for creating rule instances - 5 concrete rule implementations: replace, prefix, suffix, numbering, sanitize **Executor Pattern for Batch Processing:** - `src/core/executor.ts` - BatchExecutor with rate limiting (800ms interval) - `src/core/retry.ts` - Exponential backoff retry mechanism - `src/core/crash-recovery.ts` - Crash recovery with idempotency - `src/core/conflict-detector.ts` - Duplicate name detection ### Key Architectural Components **Content Script Architecture:** ``` Content Script (ISOLATED world) ├── FloatingButton (Shadow DOM) │ └── src/content/components/floating-button.ts ├── Main Panel (Lit Web Components) │ ├── file-selector-panel.ts - 3-column container (config / list / preview) │ ├── config-panel.ts - Rule config + execution/progress │ ├── file-list-panel.ts - Search/filter/select + virtual list │ └── preview-panel.ts - Preview + conflict/status + virtual list └── Platform Adapter Integration Page Script (MAIN world) - For API interception └── src/adapters/{quark,aliyun,baidu}/page-script.ts (dynamically injected) Dialog Page (extension iframe, optional/legacy UI) └── src/dialog/ (hosts rename-dialog/rename-preview, if used) ``` **Message Communication:** - Content Script ↔ Background Service Worker via `chrome.runtime.sendMessage` - Content Script ↔ Page Script via `window.postMessage` (cross-world communication) - See `src/types/message.ts` for message protocol definitions **Batch Execution Flow:** 1. Get selected files via platform adapter 2. Apply rename rules via RuleFactory 3. Preview changes with conflict detection 4. Execute batch rename with: - 800ms request interval (rate limiting) - Concurrent execution with staggered delays - Progress tracking via event system - Automatic retry with exponential backoff - Crash recovery support ## Critical Implementation Details ### Chrome Extension Specifics **Manifest V3 Requirements:** - Service Worker background script (not persistent) - Content script runs in ISOLATED world; platform page-scripts are injected into MAIN world via `