Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📚 [Feature]: Proposal for User-customizable Prompts through Configuration Files #212

Open
sebastienfi opened this issue Jun 20, 2023 · 4 comments

Comments

@sebastienfi
Copy link
Contributor

sebastienfi commented Jun 20, 2023

Description

👋 Hi amazing OpenCommit maintainers and community! 🌟 First of all, a huge thanks to the code owners for the incredible work on OpenCommit. 🚀 I have a proposal that could make OpenCommit even more awesome. I'd love to hear your thoughts! 🧠

Currently, OpenCommit uses fixed prompts which are not customizable by users. Adding an ability for users to fine-tune the prompts would open up new possibilities and even facilitate community contributions for better prompts. 🛠️

#205
#191
#180 (Partially)
#135 (Partially)
#175
#155
#61

Suggested Solution

Let's allow OpenCommit to check for user-specific prompt files in ~/.opencommit/ (Or $HOME). If present, it should use them, else fallback to the global defaults. This way, users can create and modify prompts as they like.

  1. Define a format for prompt files (Pure Text/JSON/YAML).
  2. Use a template engine like Handlebars for dynamic content insertion.
  3. At startup, check if ~/.opencommit/ prompts exists, and load prompts from there if it does.
  4. On update, backup user's custom prompts if global defaults changed.

Alternatives

  • Instead of files, we could use a database, but that adds complexity. Using files is simple and transparent.
  • Allow customization only through UI, but this limits the extensibility and contributions.

Additional Context

This feature addresses many requests from the community about customizing commit message formats, prefixes, and ticket numbers. It’s a versatile solution that keeps everyone's preferences in mind. 🤗

💙 Looking forward to the community's feedback and insights! 🙏

@sebastienfi sebastienfi changed the title [Feature]: Proposal for User-customizable Prompts through Configuration Files 📚 [Feature]: Proposal for User-customizable Prompts through Configuration Files Jun 20, 2023
@seho-dev
Copy link
Contributor

Do you have a code example for your proposed solution?

@sebastienfi
Copy link
Contributor Author

@seho-dev I don't, but that's pretty straightforward. My intent is to gather feedback before doing this.

@sebastienfi
Copy link
Contributor Author

Something like this maybe? (very rough)

import fs from 'fs';
import path from 'path';
import Handlebars from 'handlebars';

// Path to user's custom prompts
const globalConfigDir = path.join(process.env.HOME || '', '.opencommit');
const localConfigDir = '.opencommit';

// Load prompt from file
const loadPrompt = (filePath: string): string | null => {
    try {
        return fs.readFileSync(filePath, 'utf-8');
    } catch {
        return null;
    }
};

const checkPromptsHash = () => {
    // Get local/global prompt file(s) hash, compare to static value (kept up-to-date at build time)
    const hash = crypto(...etc.
}

checkPromptsHash()

// Render prompts with Handlebars
const renderPrompts = (prompts: string[], context: Record<string, any>): string[] => {
    return prompts.map(prompt => {
        const template = Handlebars.compile(prompt);
        return template(context);
    });
};

const getPrompts = () => {
    const prompts = []
    let mainPromptFilePath = path.join(localConfigDir, 'main_prompt.txt')
    if (fs.existsSync(mainPromptFilePath)) {
        prompts = loadPrompts(mainPromptFilePath);
    } else {
      mainPromptFilePath = path.join(globalConfigDir, 'main_prompt.txt');
      if (fs.existsSync(userPromptDir)) {
          prompts = loadPrompts(mainPromptFilePath);
      }
    }
   // Render prompts with Handlebars
   return renderPrompts(prompts, { username: 'John' });
}

console.log(getPrompts())


@github-actions
Copy link

Stale issue message

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

No branches or pull requests

3 participants