mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 18:50:56 +08:00
commit7c8bf8b591Author: 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 commitff8e5ddd27Author: 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 commit530e6516fdAuthor: defi-failure <159208748+defi-failure@users.noreply.github.com> Date: Thu Nov 6 17:19:53 2025 +0800 chore: code cleanup commitab21c0d56cAuthor: 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. commit21ea8ccf37Merge:ab7b207d2816a92c60Author: 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 commitab7b207d29Author: kangfenmao <kangfenmao@qq.com> Date: Thu Nov 6 14:50:05 2025 +0800 refactor: streamline event listener management in useAppInit and update ToolPermissionRequestCard styling commit3834c5d402Author: 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 commita64b94a41fAuthor: 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 commit2e0ff28505Author: 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 commit84bf94e2ffAuthor: 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 commit84f2281506Author: 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 commit4e01210df4Author: 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 commit9df38c7e83Author: 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 commit251c269ab3Author: kangfenmao <kangfenmao@qq.com> Date: Thu Nov 6 10:11:21 2025 +0800 refactor: remove unused error handling alerts from AssistantsTab component commit9b9640d8d1Author: kangfenmao <kangfenmao@qq.com> Date: Thu Nov 6 10:07:26 2025 +0800 refactor: adjust margin styling for UnifiedAddButton component commitedd6b11aa7Author: 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 commit1c0de625d8Author: kangfenmao <kangfenmao@qq.com> Date: Thu Nov 6 09:56:42 2025 +0800 fix: update assistant addition messages for multiple languages commit0ea4dd4e3aAuthor: dev <verc20.dev@proton.me> Date: Wed Nov 5 21:01:24 2025 +0800 fix: init message api err commitf3bbd4ed44Author: dev <verc20.dev@proton.me> Date: Wed Nov 5 20:42:49 2025 +0800 refactor: remove heroui commitd01609fc36Author: dev <verc20.dev@proton.me> Date: Wed Nov 5 19:08:41 2025 +0800 refactor: migrate heroui/toast to antd message commitf4b14dfc10Author: 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 commit6ae5f69163Author: kangfenmao <kangfenmao@qq.com> Date: Wed Nov 5 18:44:13 2025 +0800 refactor: update PluginSettings and ToolingSettings for improved layout and functionality commitfcb0020787Author: kangfenmao <kangfenmao@qq.com> Date: Wed Nov 5 18:29:52 2025 +0800 wip commit02265f369eAuthor: dev <verc20.dev@proton.me> Date: Wed Nov 5 17:26:39 2025 +0800 fix: error block related commit5e22d9d36fAuthor: dev <verc20.dev@proton.me> Date: Wed Nov 5 17:14:25 2025 +0800 fix: note head nav related commit3f52b7766aAuthor: dev <verc20.dev@proton.me> Date: Wed Nov 5 16:45:49 2025 +0800 chore: remove dead code commit484622f12bAuthor: dev <verc20.dev@proton.me> Date: Wed Nov 5 16:43:12 2025 +0800 chore: remove dead code commit2bceb302e0Author: dev <verc20.dev@proton.me> Date: Wed Nov 5 15:33:25 2025 +0800 fix: tool setting related commit5c455f25ebAuthor: dev <verc20.dev@proton.me> Date: Wed Nov 5 13:59:33 2025 +0800 chore: remove dead code commitd1d1dbc046Author: dev <verc20.dev@proton.me> Date: Wed Nov 5 13:51:41 2025 +0800 fix: tool permission card related commitbf4ec23ef7Author: dev <verc20.dev@proton.me> Date: Wed Nov 5 12:22:53 2025 +0800 fix: remove button and modal renaming commit47db5baeb1Author: dev <verc20.dev@proton.me> Date: Wed Nov 5 12:20:36 2025 +0800 fix: plugin setting related commit81fecce552Author: 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 commitfc64b6c611Author: kangfenmao <kangfenmao@qq.com> Date: Wed Nov 5 12:10:48 2025 +0800 refactor: simplify MessageAgentTools component structure by removing unnecessary wrapper div commite0f383a050Author: kangfenmao <kangfenmao@qq.com> Date: Wed Nov 5 12:08:32 2025 +0800 fix: update button classes in AddAssistantOrAgentPopup for improved cursor behavior commit720284262fAuthor: 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 commitb334a2c5beAuthor: kangfenmao <kangfenmao@qq.com> Date: Wed Nov 5 11:40:47 2025 +0800 refactor: replace UpdateDialog with UpdateDialogPopup for better modal handling commit468aebd632Author: dev <verc20.dev@proton.me> Date: Wed Nov 5 10:56:40 2025 +0800 fix: plugins related wip commitbd4a979f62Author: dev <verc20.dev@proton.me> Date: Tue Nov 4 17:46:14 2025 +0800 fix: add button related commitb3316a4dc8Author: dev <verc20.dev@proton.me> Date: Tue Nov 4 17:18:31 2025 +0800 fix: agent tool result related components commit6ca7597a98Author: dev <verc20.dev@proton.me> Date: Tue Nov 4 11:12:01 2025 +0800 fix: lint commit7d0f0b38a6Author: kangfenmao <kangfenmao@qq.com> Date: Tue Nov 4 09:56:32 2025 +0800 wip commit96a607a410Author: kangfenmao <kangfenmao@qq.com> Date: Mon Nov 3 20:23:25 2025 +0800 wip commit235ad16252Author: kangfenmao <kangfenmao@qq.com> Date: Mon Nov 3 20:08:45 2025 +0800 wip commitf23fe1b9e9Author: kangfenmao <kangfenmao@qq.com> Date: Mon Nov 3 19:15:01 2025 +0800 wip commit28fac543fcAuthor: kangfenmao <kangfenmao@qq.com> Date: Mon Nov 3 18:39:39 2025 +0800 wip commit3cc7ee01e2Author: kangfenmao <kangfenmao@qq.com> Date: Mon Nov 3 17:33:13 2025 +0800 wip commit37bdf9e508Author: kangfenmao <kangfenmao@qq.com> Date: Sat Nov 1 19:16:58 2025 +0800 wip commit1bf5104f97Author: kangfenmao <kangfenmao@qq.com> Date: Sat Nov 1 12:12:01 2025 +0800 wip
7.1 KiB
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-grepfor semantic queries; fall back torg/grepwhen needed. - Build with HeroUI: Use HeroUI for every new UI component; never add
antdorstyled-components. - Log centrally: Route all logging through
loggerServicewith the right context—noconsole.log. - Research via subagent: Lean on
subagentfor 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, usechrome://inspectto attach debugger - Build Check:
yarn build:check- REQUIRED before commits (lint + test + typecheck)- If having i18n sort issues, run
yarn sync:i18nfirst to sync template - If having formatting issues, run
yarn formatfirst
- If having i18n sort issues, run
- Test:
yarn test- Run all tests (Vitest) across main and renderer processes - Single Test:
yarn test:main- Run tests for main process onlyyarn 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
xxxTablepattern (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 topreference.tstable definition - JSON Serialization: For JSON fields, no need to manually serialize/deserialize when reading/writing to database, Drizzle handles this automatically
- Timestamps: Use existing
crudTimestampsutility - 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,usePersistCachehooks, orcacheService
Preference System
- Purpose: User configuration and application settings
- Lifecycle: Permanent until user changes
- Use Cases: Theme, language, editor settings, user preferences
- APIs:
usePreference,usePreferenceshooks, orpreferenceService
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:
useDataApihook ordataApiServicefor 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)