Skip to content

Conversation

@Emt-lin
Copy link
Collaborator

@Emt-lin Emt-lin commented Oct 27, 2025

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 .md files 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 userSystemPrompt from 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

  1. SystemPromptManager (src/system-prompts/systemPromptManager.ts)

    • Singleton pattern for centralized CRUD operations
    • Manages file operations via Obsidian Vault API
    • Integrates with state management layer
  2. 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
  3. Migration System (src/system-prompts/migration.ts)

    • Automatic migration from legacy userSystemPrompt setting
    • User-friendly notification modal
    • Safe handling of existing files
  4. 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

  • Create new system prompts via UI
  • Edit existing system prompts (title and content)
  • Delete system prompts with proper error handling
  • Duplicate system prompts with automatic name generation
  • Session-level prompt selection in chat settings
  • Global default prompt configuration in settings
  • Migration from legacy userSystemPrompt setting
  • File system operations (create, read, update, delete)
  • Frontmatter metadata handling
  • Error handling and user notifications (Notice)

Unit Tests

  • All existing tests pass
  • New test coverage: 1,671 lines across 4 test files
  • Migration scenarios tested
  • State management tested
  • CRUD operations tested
  • Utility functions tested

Integration Testing

  • Works with existing chat functionality
  • Compatible with all LLM providers
  • Session prompts reset correctly on new chat/load history
  • Global defaults persist across sessions

Screenshots

2025-10-27.22.35.10.mp4

Migration Notes

For users upgrading to this version:

  1. Existing custom system prompt (userSystemPrompt in settings) will be automatically migrated to a file named "Migrated Custom System Prompt" in the system prompts
    folder
  2. The migrated prompt will be set as the global default automatically
  3. A notification modal will inform users about the upgrade
  4. No manual intervention required

@Emt-lin Emt-lin requested a review from logancyang October 27, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants