AI-powered Go CLI tool that generates commit messages from staged git changes using Ollama.
Snippety automatically detects your branch, analyzes changes, and generates structured commit messages with both title and description.
- π€ AI-Generated Messages: Uses Ollama to generate meaningful commit messages with both title and detailed description
- π« Smart Branch Detection: Automatically detects ticket prefixes from branch names (e.g.,
BP-1234-featureβBP-1234: commit title) - π Conventional Commits: Follows conventional commit format (Add, Fix, Update, Remove)
- π Flexible Tones: Choose from built-in tones (professional, fun, pirate, haiku, serious) or specify custom tones
- π€ Interactive Mode: Optionally confirm before creating and pushing commits with generated messages
- π Auto-staging: Automatically stages all changes with
git add -Abefore analysis (can be disabled) - π Fallback Support: Falls back to rule-based generation if Ollama is unavailable
- π Smart Push Handling: Automatically sets upstream for new branches during push
- βοΈ Configurable: Supports custom Ollama endpoints and models
- π§ͺ Well-Tested: Comprehensive unit test coverage for reliability
- π Fast & Lightweight: Built with Go and Cobra CLI framework
- Ollama installed and running
- Go 1.21 or later
- Git repository with staged changes
# Clone the repository
git clone https://github.com/tahcohcat/snippety/snippety
cd snippety
# Build the binary
go mod tidy
go build -o snippety ./cmd/snippety
# Optional: Install globally
go install ./cmd/snippety- Start Ollama:
ollama serve- Pull a model (if not already available):
ollama pull llama3.2- Generate commit message (auto-stages changes by default):
./snippety
# Or with interactive confirmation:
./snippety --interactive./snippety# Custom Ollama server URL
./snippety --ollama-url http://localhost:11434
# Different model
./snippety --model llama3.1
# Custom tone
./snippety --tone fun
# Interactive mode
./snippety --interactive
# Disable auto-staging (manual git add required)
./snippety --auto-stage=false
# Combined options
./snippety --ollama-url http://remote-server:11434 --model codellama --tone pirate --interactive# Professional tone (default)
./snippety --tone professional
# Fun tone with emojis and creative language
./snippety --tone fun
# Pirate speak with nautical terminology
./snippety --tone pirate
# Haiku poem with 5-7-5 syllable structure (single line)
./snippety --tone haiku
# Serious, formal tone with technical precision
./snippety --tone seriousYou can also specify any custom tone as a string:
# Custom tones - the AI will interpret and apply the tone
./snippety --tone casual
./snippety --tone dramatic
./snippety --tone technical
./snippety --tone poetic
./snippety --tone "like a tech startup CEO"
./snippety --tone "in the style of Shakespeare"| Flag | Default | Description |
|---|---|---|
--ollama-url |
http://localhost:11434 |
Ollama server URL |
--model |
llama3.2 |
Ollama model to use for generation |
--tone |
professional |
Tone for commit messages (professional, fun, pirate, haiku, serious, or custom) |
--interactive |
false |
Interactively confirm before creating and pushing the git commit |
--auto-stage |
true |
Automatically stage all changes with 'git add -A' before analysis |
$ ./snippety
Staging all changes...
Generating commit message with Ollama...
Making request to: http://localhost:11434/api/generate
Generated commit message:
Add user authentication middleware
$ ./snippety --tone fun
Generating commit message with Ollama...
Generated commit message:
β¨ Add shiny new user auth middleware π
$ ./snippety --tone pirate
Generating commit message with Ollama...
Generated commit message:
Hoist new authentication middleware aboard! β
$ ./snippety --tone haiku
Generating commit message with Ollama...
Generated commit message:
Auth middleware flows / Through the codebase like fresh streams / Security blooms bright
$ ./snippety --interactive
Staging all changes...
Generating commit message with Ollama...
Generated commit message:
Add user authentication middleware
Do you want to create a commit with this message? (y/N): y
β
Commit created successfully!
π Commit pushed successfully!- Branch Detection: Detects current branch and extracts ticket prefixes (e.g.,
FEAT-1234-featureβFEAT-1234:) - Auto-staging: Automatically runs
git add -Ato stage all changes (unless disabled) - Git Diff Analysis: Retrieves staged changes using
git diff --staged - AI Processing: Sends the diff to Ollama with a specialized prompt for title and description generation
- Tone Application: Applies built-in or custom tone instructions to the AI prompt
- Commit Generation: Returns a structured commit message with title and detailed description
- Prefix Integration: Automatically prepends ticket prefix to commit title
- Interactive Confirmation: Optionally prompts user to create commit and push
- Smart Push: Automatically sets upstream for new branches during push
- Fallback: Uses rule-based analysis if Ollama is unavailable
Any Ollama model should work, but these are recommended:
llama3.2(default) - Good balance of speed and qualityllama3.1- Larger model for better accuracycodellama- Specialized for code analysismistral- Fast and efficientqwen2.5-coder- Excellent for code understanding
# Check if Ollama is running
curl http://localhost:11434/api/tags
# Start Ollama if not running
ollama serve
# Verify model availability
ollama list- "connection refused": Ollama service is not running
- "405 Method Not Allowed": Wrong URL or port
- "No staged changes found": Run
git addto stage your changes first
snippety/
βββ cmd/main.go # Entry point
βββ internal/
β βββ cmd/ # Cobra CLI commands
β β βββ root.go # Root command setup
β β βββ generate.go # Core generation logic
β βββ ollama/ # Ollama client
β βββ client.go # HTTP client for Ollama API
βββ go.mod # Go module definition
βββ README.md # This file
# Using Make (recommended)
make dev # Install deps, build, and test
make build # Build binary only
make test # Run tests
make test-coverage # Run tests with coverage report
# Or manually with Go commands
go mod tidy # Get dependencies
go test ./... # Run tests
go build -o snippety ./cmd/snippety # Build binary
# Cross-compile for different platforms
make build-all # Build for all platforms (Linux, macOS, Windows)The project includes comprehensive unit tests covering:
- Ticket prefix extraction from branch names
- Commit message parsing with various LLM response formats
- Fallback message generation when Ollama is unavailable
- CLI flag parsing and validation
- Client configuration and setup
# Run all tests
make test
# Run tests with verbose output
make test-verbose
# Generate coverage report
make test-coverageTest Coverage:
internal/cli/git: ~30% (core git functionality, branch detection, fallback generation)internal/client/ollama: ~48% (LLM client, response parsing, tone handling)internal/cli/cobra: ~44% (CLI command parsing, flag validation, custom tones)
Key Test Areas:
- β Ticket prefix extraction from 17+ branch name patterns
- β Commit message parsing with 11 different LLM response formats
- β Fallback message generation for 8 git diff scenarios
- β Custom and built-in tone instruction generation
- β CLI flag parsing and validation
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Ollama for the local LLM runtime
- Cobra for the CLI framework
- Conventional Commits for the commit format standard
