In this blog, Iโm thrilled to unveil Commit-Sensei, an interactive CLI tool designed to streamline and automate the process of generating commit messages.
๐ Reason Behind Implementation:
Every time I commit code, I need to come up with a commit message that is short , fits the standards at the same time more descriptive ๐คฏ.
I decided , why not let the AI do the process. Hence the idea was born to automate the commit process.
The next step was to research whether there were any tools that already did the same thing
During my research, I discovered several tools with similar functionality. However, I noticed some gaps:
Interactive Editing ๐: Existing tools lacked the ability for users to edit commit messages before finalizing them. I wanted a tool that provides the initial AI-generated suggestion but also allows for user refinement.
Rate Limit Awareness ๐ฆ: For users on a free tier, it's crucial to manage API usage effectively. A feature to notify users when they approach or exceed limits was essential.
Personal Experimentation ๐: Beyond addressing these gaps, I also wanted to experiment with implementing these features, driven by a mix of curiosity and the potential for personal benefit.
๐ Process
There was lots of learning and levels I had to cross. I'm excited to share the journey here with everyone ๐.
Level 1: Learning How to Build a CLI ๐ ๏ธ:
I had some experience with Node.js, but I had no idea how to build a CLI. So, level 1 was to learn how to make one. Below is the link to a video I used to learn about building a CLI using Node.js and Clack:
First level crossed!
Next, I needed to break things down:
I was able to get through most of the steps, but got stuck with the editor part. The problem was Clack's text component did not support multiline values. Whenever I plugged in the value to the text component of Clack, I was only getting the last line.
To solve this, I needed to find a component that supported multiline input. So, I switched to another package called inquirer
to use its editor feature. I know it's not the perfect choice, but I did it!
With that editor cleared on , I wanted to separate the config and the commit generation part. Next barrier came in, how to separate it out ? ๐ค
After some research, I discovered a package called commander
that I could utilize. I then modified the index.js
file to run set-config
and generate-commit
based on the command.
#!/usr/bin/env node
import {program} from 'commander'
import setConfig from './set-config.js'
import generateCommit from './generate-commit.js'
program
.command('set-config')
.description('Set up the API key and other configurations')
.action(setConfig);
program
.command('generate')
.description('Generate a commit message')
.action(generateCommit);
program.parse(process.argv);
Now demo time
๐ ๏ธ Stack
๐ฉ Node.js
๐ป JavaScript (ES6+)
๐ฆ npm
๐ค Google Generative AI API (Gemini Model)
๐ Third-party Libraries:
๐ Configuration Files:
.genai-config.json
&.genai-usage.json
๐งฉ Version Control: GitHub
๐ Git
Usage
Installation and Configuration
To install Commit Sensei globally, run:
npm install -g commit-sensei
After installation, set up the tool with your Google Generative AI API key by running:
commit-sensei set-config
This command prompts you to enter your API key, saving it securely in a configuration file.
Generating Commit Messages
With the configuration set, generating a commit message is as simple as running:
commit-sensei generate
This command analyzes the staged changes, generates a message, and offers an option to edit it interactively before committing.
Best Practices and Considerations
Security: Always ensure that your
.genai-config.json
and.genai-usage.json
files are included in your.gitignore
file. This prevents sensitive information, such as API keys, from being exposed in your version control system.Node.js Version: Commit Sensei requires Node.js version 18 or higher, ensuring compatibility with the latest features and security updates.
Future Roadmap
1. Batch Processing
- Handle multiple commits or large diffs by summarizing changes or generating multiple commit messages.
2. Extended Emoji Support
- Expand emoji options to cover more commit types and scenarios.
3. Customizable Prompts
- Allow users to customize prompts and commit message formats according to their team's conventions.
4. Localization
- Add support for multiple languages, enabling internationalization of commit messages.
5. Enhanced Configuration Management
- Provide more robust configuration options, such as environment-based settings and secure storage.
6. Advanced Rate Limiting
- Implement more sophisticated rate limiting strategies, including user-specific limits and real-time monitoring.
7. Integration with CI/CD
- Integrate the tool with popular CI/CD pipelines to automate commit message generation.
Conclusion
Thank you for tuning in. Application will be under continuous development. Comments and Feedbacks are most welcome. Thank you, Hashnode, for the hackathon; I learned a lot in the process.
Github link: https://github.com/skarthikeyan96/commit-sensei
Social Links:
Inspiration and References: