zed icon indicating copy to clipboard operation
zed copied to clipboard

Add editable git commit prompt to rule store

Open 0x524c opened this issue 1 month ago • 3 comments

Custom Git Commit Prompt Support

Adds user-customizable AI prompts for commit message generation via Rules Library integration.

Features

UI Integration:

  • Rules Library: Settings → AI → Rules Library → “Git Commit Prompt” (built-in rule)
  • Reset button (↻): Restores default prompt content with one click
  • Title handling: Title is fixed to “Git Commit Prompt”; body remains fully editable
  • Toggle behavior: Checkmark icon still controls whether the rule is active (metadata.default flag)

Functionality:

  • Custom prompt storage: Reuses Zed’s Rules Library (LMDB/heed) database
  • Activation control: Custom prompt only used when metadata.default = true
  • Auto-fallback: Falls back to bundled default prompt whenever the rule is inactive or loading fails
  • Rule lifecycle: Commit prompt is created with default content during initial database setup
  • Default state: Enabled by default (default = true on first initialization)

Implementation

Key files touched:

  • crates/prompt_store/src/prompt_store.rs – Adds PromptId::CommitMessage, initializes database entry, and forces the title to “Git Commit Prompt” when saving
  • crates/rules_library/src/rules_library.rs – Allows body edits, keeps title read-only, exposes reset action, and omits deletion for the built-in rule
  • crates/git_ui/src/git_panel.rs – Loads custom prompt only when metadata.default is true, otherwise uses the default text
  • crates/agent/src/agent.rs / crates/agent_ui/src/context_picker/rules_context_picker.rs – Hide the CommitMessage rule from agent pickers
  • crates/git_ui/Cargo.toml – Adds prompt_store dependency
  • Housekeeping: legacy ad-hoc tests (git_commit_prompt_tests.rs / git_custom_commit_tests.rs) removed after migrating coverage

Key Implementation Details:

  • PromptId enum gains a CommitMessage variant alongside EditWorkflow and User
  • Special-cased store logic keeps the prompt editable but enforces the canonical title
  • metadata.default flag (toggled from the Rules Library) governs activation during commit generation
  • Reset action reinstates the default commit prompt content (and preserves the active/inactive flag)
  • Database bootstrapping ensures the built-in rule exists with default content
  • Git panel falls back gracefully to bundled text whenever the custom rule is inactive or fails to load

Testing:

  • Targeted coverage via cargo test -p prompt_store -- git_commit_prompt
    • Initialization with default metadata and content
    • Custom body persistence while keeping title immutable
    • Default-flag persistence across sessions (drop/reopen LMDB)
    • Metadata cache refresh after saving custom content

Use Case:

Enables teams and individuals to enforce custom commit conventions (e.g., conventional commits, ticket references, specific format requirements) without modifying Zed source code.

Release Notes:

Feat: persist customizable git commit prompt

- register PromptId::CommitMessage as the built-in "Git Commit Prompt"
- seed PromptStore with commit_message_prompt.txt as the default body
- allow editing only the prompt body, keep the title immutable, and add reset support
- load the custom commit prompt in the git panel only when marked as default, otherwise fall back
- enforce the title invariant in PromptStore::save and refresh cached prompts after updates

0x524c avatar Nov 08 '25 15:11 0x524c

Warnings
:warning:

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by :no_entry_sign: dangerJS against 43066e5b543a45a33e1c9bc8b7c265a3355c2d97

zed-industries-bot avatar Nov 08 '25 15:11 zed-industries-bot

https://github.com/user-attachments/assets/d5db0cf9-8d66-4cd4-a099-bb30434d6762

0x524c avatar Nov 08 '25 16:11 0x524c

There is still a layout issue: the "Git Commit Prompt" rule title still allows selection and cursor movement over it. In my opinion, this shouldn't be possible, but I haven't been able to fix it yet. Currently, it only doesn't allow editing and deletion.

0x524c avatar Nov 08 '25 16:11 0x524c