Commit Graph

17 Commits

  • refactor(backend): phase 1 - unified error handling with thiserror
    Introduce AppError enum to replace Result<T, String> pattern across
    the codebase, improving error context preservation and type safety.
    
    ## Changes
    
    ### Core Infrastructure
    - Add src/error.rs with AppError enum using thiserror
    - Add thiserror dependency to Cargo.toml
    - Implement helper functions: io(), json(), toml() for ergonomic error creation
    - Implement From<PoisonError> for automatic lock error conversion
    - Implement From<AppError> for String to maintain Tauri command compatibility
    
    ### Module Migrations (60% complete)
    - config.rs: Full migration to AppError
      - read_json_file, write_json_file, atomic_write
      - archive_file, copy_file, delete_file
    - claude_mcp.rs: Full migration to AppError
      - get_mcp_status, read_mcp_json, upsert_mcp_server
      - delete_mcp_server, validate_command_in_path
      - set_mcp_servers_map
    - codex_config.rs: Full migration to AppError
      - write_codex_live_atomic with rollback support
      - read_and_validate_codex_config_text
      - validate_config_toml
    - app_config.rs: Partial migration
      - MultiAppConfig::load, MultiAppConfig::save
    - store.rs: Partial migration
      - AppState::save now returns Result<(), AppError>
    - commands.rs: Minimal changes
      - Use .map_err(Into::into) for compatibility
    - mcp.rs: Minimal changes
      - sync_enabled_to_claude uses Into::into conversion
    
    ### Documentation
    - Add docs/BACKEND_REFACTOR_PLAN.md with detailed refactoring roadmap
    
    ## Benefits
    - Type-safe error handling with preserved error chains
    - Better error messages with file paths and context
    - Reduced boilerplate code (118 Result<T, String> instances to migrate)
    - Automatic error conversion for seamless integration
    
    ## Testing
    - All existing tests pass (4/4)
    - Compilation successful with no warnings
    - Build time: 0.61s (no performance regression)
    
    ## Remaining Work
    - claude_plugin.rs (7 functions)
    - migration.rs, import_export.rs
    - Add unit tests for error.rs
    - Complete commands.rs migration after dependent modules
    
    Co-authored-by: Claude <claude@anthropic.com>
  • test: add frontend testing infrastructure with vitest
    - Introduce Vitest + React Testing Library + jsdom environment
    - Add useDragSort hook unit tests covering:
      * Sorting logic (sortIndex → createdAt → name)
      * Successful drag operation (API call + cache invalidation)
      * Failed drag operation (error toast display)
      * Edge case (no valid target, no API call)
    - Configure global test setup (i18n mock, auto cleanup)
    - Update TypeScript configs to include tests/ directory
    - Add test development plan documentation
    
    Test Coverage:
      ✓ Provider drag-and-drop sorting core logic
      ✓ React Query cache refresh
      ✓ Toast notification display
      ✓ Boundary condition handling
    
    Test Results: 4/4 passed (671ms)
    Next Steps: Sprint 2 - component tests with MSW mock layer
  • refactor: consolidate provider form components
    This commit completes Stage 2.5-2.6 of the refactoring plan by:
    
    - Consolidating 8 provider form files (1941+ lines) into a single
      unified ProviderForm component (353 lines), reducing code by ~82%
    - Implementing modern form management with react-hook-form and zod
    - Adding preset provider categorization with grouped select UI
    - Supporting dual-mode operation for both Claude and Codex configs
    - Removing redundant subcomponents:
      - ApiKeyInput.tsx (72 lines)
      - ClaudeConfigEditor.tsx (205 lines)
      - CodexConfigEditor.tsx (667 lines)
      - EndpointSpeedTest.tsx (636 lines)
      - KimiModelSelector.tsx (195 lines)
      - PresetSelector.tsx (119 lines)
    
    Key improvements:
    - Type-safe form values with ProviderFormValues extension
    - Automatic template value application for presets
    - Better internationalization coverage
    - Cleaner separation of concerns
    - Enhanced UX with categorized preset groups
    
    Updates AddProviderDialog and EditProviderDialog to pass appType prop
    and handle preset category metadata.
  • feat: complete stage 4 cleanup and code formatting
    This commit completes stage 4 of the refactoring plan, focusing on cleanup
    and optimization of the modernized codebase.
    
    ## Key Changes
    
    ### Code Cleanup
    - Remove legacy `src/lib/styles.ts` (no longer needed)
    - Remove old modal components (`ImportProgressModal.tsx`, `ProviderList.tsx`)
    - Streamline `src/lib/tauri-api.ts` from 712 lines to 17 lines (-97.6%)
      - Remove global `window.api` pollution
      - Keep only event listeners (`tauriEvents.onProviderSwitched`)
      - All API calls now use modular `@/lib/api/*` layer
    
    ### Type System
    - Clean up `src/vite-env.d.ts` (remove 156 lines of outdated types)
    - Remove obsolete global type declarations
    - All TypeScript checks pass with zero errors
    
    ### Code Formatting
    - Format all source files with Prettier (82 files)
    - Fix formatting issues in 15 files:
      - App.tsx and core components
      - MCP management components
      - Settings module components
      - Provider management components
      - UI components
    
    ### Documentation Updates
    - Update `REFACTORING_CHECKLIST.md` with stage 4 progress
    - Mark completed tasks in `REFACTORING_MASTER_PLAN.md`
    
    ## Impact
    
    **Code Reduction:**
    - Total: -1,753 lines, +384 lines (net -1,369 lines)
    - tauri-api.ts: 712 → 17 lines (-97.6%)
    - Removed styles.ts: -82 lines
    - Removed vite-env.d.ts declarations: -156 lines
    
    **Quality Improvements:**
    -  Zero TypeScript errors
    -  Zero TODO/FIXME comments
    -  100% Prettier compliant
    -  Zero `window.api` references
    -  Fully modular API layer
    
    ## Testing
    - [x] TypeScript compilation passes
    - [x] Code formatting validated
    - [x] No linting errors
    
    Stage 4 completion: 100%
    Ready for stage 5 (testing and bug fixes)
  • docs: add comprehensive refactoring documentation
    Add three key documents to guide the project restructure:
    - REFACTORING_MASTER_PLAN.md: Complete refactoring roadmap with 6 stages
    - REFACTORING_CHECKLIST.md: Detailed task checklist for tracking progress
    - REFACTORING_REFERENCE.md: Technical reference and implementation guide
    
    This refactoring aims to modernize the codebase with React Query,
    react-hook-form, zod validation, and shadcn/ui components while
    maintaining the current Tailwind CSS 4.x stack.
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-Authored-By: Claude <noreply@anthropic.com>
  • chore: bump version to v3.5.0 and update roadmap
    Version Changes:
    - Update version to 3.5.0 in package.json, Cargo.toml, and tauri.conf.json
    
    Changelog Updates:
    - Add v3.5.0 release notes with comprehensive feature list
    - Document MCP management system implementation
    - Document configuration import/export functionality
    - Document endpoint speed testing feature
    - List all improvements, bug fixes, and technical enhancements
    
    Roadmap Updates:
    - Mark MCP manager as completed 
    - Mark i18n (internationalization) as completed 
    - Add new planned features: memory management, cloud sync
    - Reorganize feature priorities
  • refactor: reorganize documentation structure
    - Remove docs/ from .gitignore to track documentation files
    - Delete completed plan documents (encrypted-config-plan.md, updater-plan.md)
    - Add roadmap.md with project milestones and future features
  • feat(ui): implement dark mode with system preference support
    - Add useDarkMode hook for managing theme state and persistence
    - Integrate dark mode toggle button in app header
    - Update all components with dark variant styles using Tailwind v4
    - Create centralized style utilities for consistent theming
    - Support system color scheme preference as fallback
    - Store user preference in localStorage for persistence
  • docs(cleanup): remove 'current' as special provider; align UI/messages and migration naming to 'default' and one-time import rule
    - App: update auto-import message to '默认供应商'
    - README: clarify default import only when providers are empty
    - Plan doc: replace 'current entry' wording with current pointer (manager.current)
    - Migration: name live-imported item 'default' instead of 'current'