Skip to content

feat(prompt): add optional user config to prompts#84

Open
todaymare wants to merge 1 commit intojnsahaj:mainfrom
todaymare:command-md-configs
Open

feat(prompt): add optional user config to prompts#84
todaymare wants to merge 1 commit intojnsahaj:mainfrom
todaymare:command-md-configs

Conversation

@todaymare
Copy link

@todaymare todaymare commented Jan 4, 2026

Add support for loading optional markdown files as user preferences for explain, draft, and operate prompts. Also restructure prompt generation to separate markdown config from command-specific content.

Happy to adjust or drop this if it doesn’t fit the project direction.
I went ahead and implemented it to provide something concrete to review.

Summary by CodeRabbit

  • New Features

    • Users can now provide custom markdown configuration snippets to personalize AI prompts for explain, draft, and operate commands.
  • Refactor

    • Enhanced prompt construction to support optional user configuration sections within the AI prompt workflow.

✏️ Tip: You can customize this high-level summary in your review settings.

Add support for loading optional markdown files as user preferences
for explain, draft, and operate prompts. Also restructure prompt
generation to separate markdown config from command-specific content.
@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2026

📝 Walkthrough

Walkthrough

The PR extends the AI prompt system to support markdown-based customization by making the configuration path lookup public and adding a helper function to load markdown snippets from the config directory, which are then injected into prompts within a <UserConfig> wrapper section.

Changes

Cohort / File(s) Summary
AI Prompt Configuration System
src/ai_prompt.rs
Added get_md() helper to load markdown files from config directory; refactored explain, draft, and operate prompt flows to wrap content with <UserConfig> section containing optional markdown configuration and command prompts.
Configuration Access
src/command/configure.rs
Made get_config_path() function public to allow external modules to access the configuration directory path.

Sequence Diagram

sequenceDiagram
    participant Prompt as ai_prompt.rs
    participant Config as ConfigureCommand
    participant FS as File System
    
    Prompt->>Prompt: explain/draft/operate flow initiated
    Prompt->>Prompt: get_md(name)
    Prompt->>Config: get_config_path()
    Config->>Config: resolve ~/.config/lumen
    Config-->>Prompt: PathBuf
    Prompt->>FS: read [name].md from config path
    FS-->>Prompt: markdown content (or None)
    Prompt->>Prompt: wrap in <UserConfig> block<br/>with cmd_prompt + content
    Prompt-->>Prompt: final prompt ready
Loading

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly Related PRs

Suggested Reviewers

  • jnsahaj

Poem

🐰✨ A config path now shines so bright,
Markdown snippets join the prompt flight,
UserConfig wraps them tight,
Customization takes its height! 📝

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(prompt): add optional user config to prompts' clearly and concisely summarizes the main change: adding optional user configuration to prompts via markdown files.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/ai_prompt.rs (1)

209-218: Consider logging when config path resolution fails.

The .ok() on line 211 silently converts get_config_path() errors (e.g., unable to determine home directory) to None, which then returns an empty string. While this makes the feature gracefully optional, it could mask legitimate filesystem or configuration issues from users.

Additionally, consider adding file size limits to prevent accidentally loading large files that could bloat prompts and hit token limits with AI providers.

💡 Potential improvements

Option 1: Add logging for errors

 fn get_md(cmd: &str) -> Result<String, AIPromptError> {
-    ConfigureCommand::get_config_path()
+    let path_result = ConfigureCommand::get_config_path();
+    if let Err(e) = &path_result {
+        eprintln!("Warning: Could not access config path: {}", e);
+    }
+    path_result
         .ok()
         .map(|p| p.join(cmd))
         .filter(|p| p.exists())
         .map(std::fs::read_to_string)
         .transpose()
         .map_err(|e| AIPromptError(format!("'{cmd}': {e}")))
         .map(|v| v.unwrap_or_default())
 }

Option 2: Add file size validation

fn get_md(cmd: &str) -> Result<String, AIPromptError> {
    const MAX_CONFIG_SIZE: u64 = 10_000; // 10KB limit
    
    ConfigureCommand::get_config_path()
        .ok()
        .map(|p| p.join(cmd))
        .filter(|p| {
            p.exists() && p.metadata().map(|m| m.len() <= MAX_CONFIG_SIZE).unwrap_or(false)
        })
        .map(std::fs::read_to_string)
        .transpose()
        .map_err(|e| AIPromptError(format!("'{cmd}': {e}")))
        .map(|v| v.unwrap_or_default())
}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5739118 and c2c110a.

📒 Files selected for processing (2)
  • src/ai_prompt.rs
  • src/command/configure.rs
🧰 Additional context used
🧬 Code graph analysis (1)
src/ai_prompt.rs (2)
src/provider/mod.rs (2)
  • draft (156-159)
  • explain (151-154)
src/command/configure.rs (1)
  • get_config_path (107-114)
🔇 Additional comments (5)
src/command/configure.rs (1)

107-107: LGTM! Visibility change enables cross-module config access.

Making get_config_path() public is a minimal change that properly enables the new markdown config feature in ai_prompt.rs without altering any behavior.

src/ai_prompt.rs (4)

2-2: LGTM! Import enables config path access.

Adding ConfigureCommand to imports is necessary for the get_md() helper to locate markdown configuration files.


54-105: Clean refactoring with clear optional config structure.

The prompt restructuring effectively separates user preferences (loaded from explain.md) from command-specific content. The explicit labeling of "OPTIONAL user preferences" with the constraint "MUST NOT violate the mandatory rules" provides good guardrails for the AI model.

Minor observation: If explain.md doesn't exist or is empty, the <UserConfig> section will be present but empty. This should function correctly but might be slightly redundant in the prompt.


176-206: Consistent pattern applied across all prompt builders.

The operate prompt follows the same structural pattern as the explain and draft prompts, with optional user configuration in a <UserConfig> block. This consistency makes the codebase easier to maintain and understand.

The ordering places user preferences before the specific task request, maintaining a logical flow.


139-168: Excellent ordering: mandatory rules before optional preferences.

The prompt structure effectively prioritizes the mandatory commit message requirements (format, character limit, etc.) before introducing optional user preferences. This hierarchy should help ensure the AI model respects the critical constraints.

The code correctly uses implicit variable capture for context, md_prompt, and diff within the formatdoc! macro. The project is configured with Rust 2021 edition, which fully supports this pattern.

@jnsahaj
Copy link
Owner

jnsahaj commented Jan 6, 2026

Hi, changes look good to me

I think we should also make a couple of changes for consistence

  1. deprecate lumen.config.json in favour of lumen/config.json (it should still work though, just not documented)
  2. deprecate the command.draft.commit_types thing in lumen config. User should be able to describe what they want
  3. Update README so users know this is possible

@todaymare
Copy link
Author

todaymare commented Jan 6, 2026

Deprecating lumen.config.json and adding lumen/config.json should be easy enough.

I’m not entirely sure what you mean by deprecating command.draft.commit_types though
Do you mean because users should be able to describe what they want in draft.md?

  • if yes, should we have a default draft.md?
  • should usage of lumen.config.json log a warning or should we silently migrate to config.json?

@jnsahaj
Copy link
Owner

jnsahaj commented Jan 6, 2026

yes correct. I don't think we need a rigid system for defining the commit types specifically for the draft command.

The user can define the constraints in draft.md and that should be totally fine

also, I think these should be under /lumen/rules/<command>.md for clarity

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