cherry-studio/CLAUDE.md
kangfenmao 78278ce96d refactor: remove heroui
commit 7c8bf8b591
Author: defi-failure <159208748+defi-failure@users.noreply.github.com>
Date:   Thu Nov 6 17:59:38 2025 +0800

    fix: add token usage to agent session message

commit ff8e5ddd27
Author: defi-failure <159208748+defi-failure@users.noreply.github.com>
Date:   Thu Nov 6 17:25:54 2025 +0800

    fix: close prompt stream when finish or error chunk received

commit 530e6516fd
Author: defi-failure <159208748+defi-failure@users.noreply.github.com>
Date:   Thu Nov 6 17:19:53 2025 +0800

    chore: code cleanup

commit ab21c0d56c
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 16:13:36 2025 +0800

    feat(SessionItem): implement auto-rename feature for sessions and improve context menu handling

    - Added a new context menu option to automatically rename sessions based on topics.
    - Introduced useDeferredValue for managing target session state.
    - Updated imports to include necessary thunk actions and components.
    - Enhanced API service to handle optional assistant model in message summary fetching.
    - Exported renameAgentSessionIfNeeded function for better accessibility in the store.

commit 21ea8ccf37
Merge: ab7b207d2 816a92c60
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 15:29:09 2025 +0800

    Merge branch 'main' of github.com:CherryHQ/cherry-studio into refactor/heroui-antd

    # Conflicts:
    #	src/renderer/src/pages/home/Tabs/components/AddButton.tsx
    #	src/renderer/src/pages/home/Tabs/components/SessionItem.tsx
    #	src/renderer/src/pages/home/Tabs/components/Sessions.tsx
    #	src/renderer/src/pages/home/Tabs/components/Topics.tsx
    #	src/renderer/src/pages/paintings/NewApiPage.tsx

commit ab7b207d29
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 14:50:05 2025 +0800

    refactor: streamline event listener management in useAppInit and update ToolPermissionRequestCard styling

commit 3834c5d402
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 14:21:25 2025 +0800

    refactor: enhance API server state management and remove unused initialization in useAppInit

commit a64b94a41f
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 13:21:58 2025 +0800

    refactor: update OpenAPI documentation paths to include subdirectories for better route coverage

commit 2e0ff28505
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 12:26:09 2025 +0800

    refactor: center align columns in InstalledPluginsList and set AntTable size to small

commit 84bf94e2ff
Author: defi-failure <159208748+defi-failure@users.noreply.github.com>
Date:   Thu Nov 6 12:06:09 2025 +0800

    refactor: align create agent model selection with edit agent

commit 84f2281506
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 11:29:32 2025 +0800

    refactor: integrate API server functionality into various components and enhance user notifications

commit 4e01210df4
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 10:56:38 2025 +0800

    refactor: replace ContextMenu with Dropdown in AgentItem and SessionItem components for improved context menu handling

commit 9df38c7e83
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 10:27:30 2025 +0800

    refactor: update AddButton styling to use CSS variable for border radius and remove unused settings hook

commit 251c269ab3
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 10:11:21 2025 +0800

    refactor: remove unused error handling alerts from AssistantsTab component

commit 9b9640d8d1
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 10:07:26 2025 +0800

    refactor: adjust margin styling for UnifiedAddButton component

commit edd6b11aa7
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 10:04:01 2025 +0800

    refactor: update AddButton styling based on topic position and clean up CSS for root element

commit 1c0de625d8
Author: kangfenmao <kangfenmao@qq.com>
Date:   Thu Nov 6 09:56:42 2025 +0800

    fix: update assistant addition messages for multiple languages

commit 0ea4dd4e3a
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 21:01:24 2025 +0800

    fix: init message api err

commit f3bbd4ed44
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 20:42:49 2025 +0800

    refactor: remove heroui

commit d01609fc36
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 19:08:41 2025 +0800

    refactor: migrate heroui/toast to antd message

commit f4b14dfc10
Author: kangfenmao <kangfenmao@qq.com>
Date:   Wed Nov 5 18:51:29 2025 +0800

    refactor: enhance Sessions component layout with styled Scrollbar and adjust UnifiedAddButton margins

commit 6ae5f69163
Author: kangfenmao <kangfenmao@qq.com>
Date:   Wed Nov 5 18:44:13 2025 +0800

    refactor: update PluginSettings and ToolingSettings for improved layout and functionality

commit fcb0020787
Author: kangfenmao <kangfenmao@qq.com>
Date:   Wed Nov 5 18:29:52 2025 +0800

    wip

commit 02265f369e
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 17:26:39 2025 +0800

    fix: error block related

commit 5e22d9d36f
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 17:14:25 2025 +0800

    fix: note head nav related

commit 3f52b7766a
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 16:45:49 2025 +0800

    chore: remove dead code

commit 484622f12b
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 16:43:12 2025 +0800

    chore: remove dead code

commit 2bceb302e0
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 15:33:25 2025 +0800

    fix: tool setting related

commit 5c455f25eb
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 13:59:33 2025 +0800

    chore: remove dead code

commit d1d1dbc046
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 13:51:41 2025 +0800

    fix: tool permission card related

commit bf4ec23ef7
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 12:22:53 2025 +0800

    fix: remove button and modal renaming

commit 47db5baeb1
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 12:20:36 2025 +0800

    fix: plugin setting related

commit 81fecce552
Author: kangfenmao <kangfenmao@qq.com>
Date:   Wed Nov 5 12:16:42 2025 +0800

    refactor: enhance ChatNavbarContent structure by replacing Breadcrumbs with custom layout and adding separators

commit fc64b6c611
Author: kangfenmao <kangfenmao@qq.com>
Date:   Wed Nov 5 12:10:48 2025 +0800

    refactor: simplify MessageAgentTools component structure by removing unnecessary wrapper div

commit e0f383a050
Author: kangfenmao <kangfenmao@qq.com>
Date:   Wed Nov 5 12:08:32 2025 +0800

    fix: update button classes in AddAssistantOrAgentPopup for improved cursor behavior

commit 720284262f
Author: kangfenmao <kangfenmao@qq.com>
Date:   Wed Nov 5 12:06:58 2025 +0800

    refactor: update AgentModal to use TopView for improved modal management and enhance form structure

commit b334a2c5be
Author: kangfenmao <kangfenmao@qq.com>
Date:   Wed Nov 5 11:40:47 2025 +0800

    refactor: replace UpdateDialog with UpdateDialogPopup for better modal handling

commit 468aebd632
Author: dev <verc20.dev@proton.me>
Date:   Wed Nov 5 10:56:40 2025 +0800

    fix: plugins related wip

commit bd4a979f62
Author: dev <verc20.dev@proton.me>
Date:   Tue Nov 4 17:46:14 2025 +0800

    fix: add button related

commit b3316a4dc8
Author: dev <verc20.dev@proton.me>
Date:   Tue Nov 4 17:18:31 2025 +0800

    fix: agent tool result related components

commit 6ca7597a98
Author: dev <verc20.dev@proton.me>
Date:   Tue Nov 4 11:12:01 2025 +0800

    fix: lint

commit 7d0f0b38a6
Author: kangfenmao <kangfenmao@qq.com>
Date:   Tue Nov 4 09:56:32 2025 +0800

    wip

commit 96a607a410
Author: kangfenmao <kangfenmao@qq.com>
Date:   Mon Nov 3 20:23:25 2025 +0800

    wip

commit 235ad16252
Author: kangfenmao <kangfenmao@qq.com>
Date:   Mon Nov 3 20:08:45 2025 +0800

    wip

commit f23fe1b9e9
Author: kangfenmao <kangfenmao@qq.com>
Date:   Mon Nov 3 19:15:01 2025 +0800

    wip

commit 28fac543fc
Author: kangfenmao <kangfenmao@qq.com>
Date:   Mon Nov 3 18:39:39 2025 +0800

    wip

commit 3cc7ee01e2
Author: kangfenmao <kangfenmao@qq.com>
Date:   Mon Nov 3 17:33:13 2025 +0800

    wip

commit 37bdf9e508
Author: kangfenmao <kangfenmao@qq.com>
Date:   Sat Nov 1 19:16:58 2025 +0800

    wip

commit 1bf5104f97
Author: kangfenmao <kangfenmao@qq.com>
Date:   Sat Nov 1 12:12:01 2025 +0800

    wip
2025-11-06 18:27:43 +08:00

7.1 KiB

AI Assistant Guide

This file provides guidance to AI coding assistants when working with code in this repository. Adherence to these guidelines is crucial for maintaining code quality and consistency.

Guiding Principles (MUST FOLLOW)

  • Keep it clear: Write code that is easy to read, maintain, and explain.
  • Match the house style: Reuse existing patterns, naming, and conventions.
  • Search smart: Prefer ast-grep for semantic queries; fall back to rg/grep when needed.
  • Build with HeroUI: Use HeroUI for every new UI component; never add antd or styled-components.
  • Log centrally: Route all logging through loggerService with the right context—no console.log.
  • Research via subagent: Lean on subagent for external docs, APIs, news, and references.
  • Always propose before executing: Before making any changes, clearly explain your planned approach and wait for explicit user approval to ensure alignment and prevent unwanted modifications.
  • Write conventional commits with emoji: Commit small, focused changes using emoji-prefixed Conventional Commit messages (e.g., ✨ feat:, 🐛 fix:, ♻️ refactor:, 📝 docs:).

Development Commands

  • Install: yarn install - Install all project dependencies
  • Development: yarn dev - Runs Electron app in development mode with hot reload
  • Debug: yarn debug - Starts with debugging enabled, use chrome://inspect to attach debugger
  • Build Check: yarn build:check - REQUIRED before commits (lint + test + typecheck)
    • If having i18n sort issues, run yarn sync:i18n first to sync template
    • If having formatting issues, run yarn format first
  • Test: yarn test - Run all tests (Vitest) across main and renderer processes
  • Single Test:
    • yarn test:main - Run tests for main process only
    • yarn test:renderer - Run tests for renderer process only
  • Lint: yarn lint - Fix linting issues and run TypeScript type checking
  • Format: yarn format - Auto-format code using Biome

Project Architecture

Electron Structure

  • Main Process (src/main/): Node.js backend with services (MCP, Knowledge, Storage, etc.)
  • Renderer Process (src/renderer/): React UI with Redux state management
  • Preload Scripts (src/preload/): Secure IPC bridge

Key Architectural Components

Main Process Services (src/main/services/)

  • MCPService: Model Context Protocol server management
  • KnowledgeService: Document processing and knowledge base management
  • FileStorage/S3Storage/WebDav: Multiple storage backends
  • WindowService: Multi-window management (main, mini, selection windows)
  • ProxyManager: Network proxy handling
  • SearchService: Full-text search capabilities

AI Core (src/renderer/src/aiCore/)

  • Middleware System: Composable pipeline for AI request processing
  • Client Factory: Supports multiple AI providers (OpenAI, Anthropic, Gemini, etc.)
  • Stream Processing: Real-time response handling

Data Management

  • Cache System: Three-layer caching (memory/shared/persist) with React hooks integration
  • Preferences: Type-safe configuration management with multi-window synchronization
  • User Data: SQLite-based storage with Drizzle ORM for business data

Knowledge Management

  • Embeddings: Vector search with multiple providers (OpenAI, Voyage, etc.)
  • OCR: Document text extraction (system OCR, Doc2x, Mineru)
  • Preprocessing: Document preparation pipeline
  • Loaders: Support for various file formats (PDF, DOCX, EPUB, etc.)

Build System

  • Electron-Vite: Development and build tooling (v4.0.0)
  • Rolldown-Vite: Using experimental rolldown-vite instead of standard vite
  • Workspaces: Monorepo structure with packages/ directory
  • Multiple Entry Points: Main app, mini window, selection toolbar
  • Styled Components: CSS-in-JS styling with SWC optimization

Testing Strategy

  • Vitest: Unit and integration testing
  • Playwright: End-to-end testing
  • Component Testing: React Testing Library
  • Coverage: Available via yarn test:coverage

Key Patterns

  • IPC Communication: Secure main-renderer communication via preload scripts
  • Service Layer: Clear separation between UI and business logic
  • Plugin Architecture: Extensible via MCP servers and middleware
  • Multi-language Support: i18n with dynamic loading
  • Theme System: Light/dark themes with custom CSS variables

UI Design

The project is in the process of migrating from antd & styled-components to HeroUI. Please use HeroUI to build UI components. The use of antd and styled-components is prohibited.

HeroUI Docs: https://www.heroui.com/docs/guide/introduction

Database Architecture

  • Database: SQLite (cherrystudio.sqlite) + libsql driver
  • ORM: Drizzle ORM with comprehensive migration system
  • Schemas: Located in src/main/data/db/schemas/ directory

Database Standards

  • Table Naming: Use singular form with snake_case (e.g., topic, message, app_state)
  • Schema Exports: Export using xxxTable pattern (e.g., topicTable, appStateTable)
  • Field Definition: Drizzle auto-infers field names, no need to add default field names
  • JSON Fields: For JSON support, add { mode: 'json' }, refer to preference.ts table definition
  • JSON Serialization: For JSON fields, no need to manually serialize/deserialize when reading/writing to database, Drizzle handles this automatically
  • Timestamps: Use existing crudTimestamps utility
  • Migrations: Generate via yarn run migrations:generate

Data Access Patterns

The application uses three distinct data management systems. Choose the appropriate system based on data characteristics:

Cache System

  • Purpose: Temporary data that can be regenerated
  • Lifecycle: Component-level (memory), window-level (shared), or persistent (survives restart)
  • Use Cases: API response caching, computed results, temporary UI state
  • APIs: useCache, useSharedCache, usePersistCache hooks, or cacheService

Preference System

  • Purpose: User configuration and application settings
  • Lifecycle: Permanent until user changes
  • Use Cases: Theme, language, editor settings, user preferences
  • APIs: usePreference, usePreferences hooks, or preferenceService

User Data API

  • Purpose: Core business data (conversations, files, notes, etc.)
  • Lifecycle: Permanent business records
  • Use Cases: Topics, messages, files, knowledge base, user-generated content
  • APIs: useDataApi hook or dataApiService for direct calls

Selection Guidelines

  • Use Cache for data that can be lost without impact (computed values, API responses)
  • Use Preferences for user settings that affect app behavior (UI configuration, feature flags)
  • Use User Data API for irreplaceable business data (conversations, documents, user content)

Logging Standards

Usage

import { loggerService } from '@logger'
const logger = loggerService.withContext('moduleName')
// Renderer: loggerService.initWindowSource('windowName') first
logger.info('message', CONTEXT)