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]: Custom Commit Messages with OpenAI Enhancement (-m Flag) #294

Open
JumpLink opened this issue Jan 11, 2024 · 3 comments
Open

Comments

@JumpLink
Copy link

Description

TAdd a new flag, -m, which allows users to specify their own commit message as a basis. OpenCommit will then enhance and improve this user-provided message using the LLM.

Suggested Solution

The addition of the -m flag would provide users with greater control and personalization over their commit messages while still benefiting from OpenAI's powerful language capabilities. Here's how the proposed feature would work:

  1. Users will invoke OpenCommit from the command line with the -m flag, followed by their custom commit message, like this:
oco -m "Implement feature X"
  1. OpenCommit will accept the user-provided message as the initial commit message.

  2. The LLM will then be utilized to enhance and optimize the message. The LLM will analyze the content and context of the commit, making it more concise, clear, and in accordance with established commit message best practices.

  3. The final commit message, which is an improved version of the user's input after LLM processing, will be used for the commit.

This feature would provide users with the flexibility to convey their intentions while benefiting from AI-powered improvements to create informative and coherent commit messages.

Alternatives

While the proposed -m flag is a direct way to allow users to specify their own commit message, there are alternatives to consider:

Enhanced Prompt: Instead of a flag, users could input their custom commit message as a prompt. OpenCommit could then process this prompt and generate an enhanced commit message based on it.

User Feedback Loop: Allow users to review and refine the commit message generated by OpenCommit, creating a feedback loop for continuous improvement.

Additional Context

The ability to specify a custom commit message with the -m flag would be valuable for developers who have specific terminology or conventions within their project or team. It would also cater to scenarios where the commit message requires personalization beyond what automated generation provides. This feature would enhance the utility of OpenCommit and make it even more adaptable to various development workflows and preferences.

Copy link

Stale issue message

@di-sukharev
Copy link
Owner

great idea, sometimes it cant understand why the change was made, this can solve it

@sebastienfi
Copy link
Contributor

Great feature. @JumpLink would you like to propose a PR? I've outlined a few things to consider and implementation steps to get you started.

To implement the new -m flag feature in OpenCommit, which allows users to specify their own commit message for enhancement by an LLM, you'll need to follow several steps. This feature involves integrating a new command-line flag, processing the user's input, and leveraging the LLM to enhance the commit message. Here's a guide to help you get started:

Understanding the Current Architecture

  1. Entry Point (cli.ts): The main entry point of OpenCommit is the cli.ts file, where the CLI is configured and initialized. This file processes command-line arguments and dispatches commands based on user input.

  2. Commit Command (commit.ts): The commit.ts module is crucial for handling commit-related operations. It includes logic for generating commit messages based on git diffs, staging files, and executing the git commit command.

  3. LLM Integration (ollama.ts and openAi.ts): The ollama.ts and openAi.ts modules under the engine directory are responsible for interfacing with the LLM to generate or enhance commit messages. Depending on the configuration, OpenCommit uses either a local model (Ollama) or OpenAI's API.

Integrating the -m Flag

  1. Modify CLI Configuration (cli.ts): Add a new flag definition for -m in the cli function call. This involves updating the flags object to accept a string value for the -m flag.

  2. Process User Input: In the main async function within cli.ts, add logic to check if the -m flag is present in the flags object. If so, extract the custom commit message provided by the user.

  3. Enhance Commit Message: Use the extracted commit message as input to the LLM for enhancement. This might involve modifying the commit function in commit.ts or creating a new function specifically for handling and enhancing user-provided commit messages. Ensure that the LLM's output is used as the final commit message.

Leveraging Existing Functionality

  • LLM Invocation: The logic for invoking the LLM and processing its output is already implemented in the ollama.ts and openAi.ts modules. You can reuse this functionality by ensuring that the user-provided commit message is passed correctly to the LLM.

  • Commit Message Processing: The existing commit process, including staging files and executing the git commit command, can be reused. After enhancing the user-provided commit message, follow the same flow to complete the commit operation.

Testing and Compatibility

  • Unit Tests: Add unit tests for the new -m flag processing logic. Ensure that the user-provided commit message is correctly passed to the LLM and that the enhanced message is used for the commit.

  • Integration Tests: Perform integration tests to verify that the new feature works seamlessly with existing functionalities, such as staging changes and generating commit messages from diffs when the -m flag is not used.

  • Manual Testing: Manually test the new feature in various scenarios, including providing valid and invalid commit messages, to ensure that the behavior is as expected.

Initial Steps

  1. Start by adding the -m flag definition in cli.ts.
  2. Implement logic to check for the -m flag and process the user-provided commit message.
  3. Modify the commit process to enhance the user-provided message using the LLM.
  4. Test thoroughly to ensure compatibility and correctness.

You should be able to successfully implement the new -m flag feature in OpenCommit. We'll provide you with assistance once you (or someone else) creates a PR.

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