feat: Add comprehensive system prompt management system.
Summary
This PR introduces a comprehensive file-based system prompt management system that replaces the legacy single system prompt setting with a flexible, multi-prompt architecture.
Key Features
- File-Based Storage: System prompts are stored as
.mdfiles in a configurable folder - CRUD Operations: Full create, read, update, delete, and duplicate functionality
- Clean Architecture: Repository → Manager → UIState → UI pattern with Jotai state management
- Automatic Migration: Seamlessly migrates existing
userSystemPromptfrom settings to file system - Session & Global Prompts: Supports both session-level (temporary) and global default (persistent) prompt selection
- Rich UI: New management modal and chat settings integration with proper error handling and user feedback
Architecture Highlights
Core Components
-
SystemPromptManager (
src/system-prompts/systemPromptManager.ts)- Singleton pattern for centralized CRUD operations
- Manages file operations via Obsidian Vault API
- Integrates with state management layer
-
State Management (
src/system-prompts/state.ts)- Jotai-based reactive state with independent store
- Dual API: React hooks (reactive) + imperative functions (non-React)
- Session-level and persistent settings support
-
Migration System (
src/system-prompts/migration.ts)- Automatic migration from legacy
userSystemPromptsetting - User-friendly notification modal
- Safe handling of existing files
- Automatic migration from legacy
-
Utilities (
src/system-prompts/systemPromptUtils.ts)- File operations and validation
- Frontmatter management
- Name generation and conflict resolution
UI Components
-
SystemPromptManagerModal: Full-featured management interface
- Add new prompts
- Edit existing prompts
- Delete with confirmation
- Duplicate prompts
- Success/error notifications
-
ChatSettingsPopover: Enhanced chat settings
- System prompt selector dropdown
- Session-level prompt override
- Model parameter customization
- Clear warnings for disabling builtin prompts
Breaking Changes
None. This PR includes automatic migration from the legacy userSystemPrompt setting to the new file-based system.
Test Plan
Functionality Testing
- [x] Create new system prompts via UI
- [x] Edit existing system prompts (title and content)
- [x] Delete system prompts with proper error handling
- [x] Duplicate system prompts with automatic name generation
- [x] Session-level prompt selection in chat settings
- [x] Global default prompt configuration in settings
- [x] Migration from legacy
userSystemPromptsetting - [x] File system operations (create, read, update, delete)
- [x] Frontmatter metadata handling
- [x] Error handling and user notifications (Notice)
Unit Tests
- [x] All existing tests pass
- [x] New test coverage: 1,671 lines across 4 test files
- [x] Migration scenarios tested
- [x] State management tested
- [x] CRUD operations tested
- [x] Utility functions tested
Integration Testing
- [x] Works with existing chat functionality
- [x] Compatible with all LLM providers
- [x] Session prompts reset correctly on new chat/load history
- [x] Global defaults persist across sessions
Screenshots
https://github.com/user-attachments/assets/6f30f847-6899-482d-8ef1-2670eab7d286
Migration Notes
For users upgrading to this version:
- Existing custom system prompt (
userSystemPromptin settings) will be automatically migrated to a file named "Migrated Custom System Prompt" in the system prompts folder - The migrated prompt will be set as the global default automatically
- A notification modal will inform users about the upgrade
- No manual intervention required