22 releases (8 breaking)

new 0.9.1 Nov 29, 2024
0.8.7 Nov 21, 2024

#48 in Configuration

Download history 318/week @ 2024-09-15 228/week @ 2024-09-22 82/week @ 2024-09-29 6/week @ 2024-10-06 176/week @ 2024-10-13 12/week @ 2024-10-20 504/week @ 2024-10-27 344/week @ 2024-11-03 254/week @ 2024-11-10 545/week @ 2024-11-17 207/week @ 2024-11-24

1,577 downloads per month

MIT license

91KB
2K SLoC

Shelf: AI-based command-line tools for developers

Shelf CI

Shelf is a command-line tool for managing what we called dotfiles in the system, generating git commit messages, and reviewing code using AI. It provides a simple interface to track files across your system and integrates with multiple AI providers to automatically generate meaningful commit messages through git hooks and perform comprehensive code reviews. With support for local and cloud-based AI models, Shelf makes configuration files management, git commits, and code reviews effortless.

Features

  • Track dotfiles from anywhere in your file system recursively
  • List all tracked dotfiles
  • Remove dotfiles recursively from database
  • AI-powered git commit message generation with multiple providers:
    • Groq
    • Google Gemini
    • Anthropic Claude
    • OpenAI
    • Xai grok
    • Ollama (local)
  • Git hooks integration for automatic commit message generation

Installation

To install Shelf, you need to have Rust and Cargo installed on your system. If you don't have them, you can install them from rustup.rs.

Once you have Rust and Cargo installed, you can build and install Shelf using the following command:

cargo install --path .

Usage

Shelf provides commands for both dotfile management and git integration:

Dotfile Management

# Add a new dotfile to track
shelf df tarck ~/.bashrc

# List all tracked dotfiles
shelf df list

# Remove a dotfile from tracking
shelf df untarck ~/.bashrc

# Interactive selection of dotfiles to track
shelf df suggest -i

# Show help
shelf --help

Each command can be run with -h or --help for more information.

Git AI Integration

The ai subcommand provides AI-powered features:

# Generate commit message for staged changes
shelf ai commit

# Install git hook for automatic message generation
shelf ai commit --install-hook

# Remove git hook
shelf ai commit --remove-hook

# Configure AI provider
shelf ai config set provider openai
shelf ai config set openai_api_key "your-api-key"

# Use specific provider for one commit
shelf ai commit -p openai

# List current configuration
shelf ai config list

The AI-powered features support diffrent AI providers:

  • Groq (default): GroqCloud-based models
  • Google Gemini: Cloud-based using Gemini models
  • OpenAI: Cloud-based using GPT models
  • Anthropic Claude: Cloud-based using Claude models
  • XAI Grok: Cloud-based using Grok models
  • Ollama: Local, privacy-friendly AI using models like Qwen

The git hook integrates seamlessly with your normal git workflow:

# Hook will automatically generate message if none provided
git commit

# Your message takes precedence
git commit -m "feat: your message"

# AI helps with amending
git commit --amend

Code Review with AI

Shelf can assist in code review by analyzing pull requests and providing AI-powered feedback:

# Review the current staged branch's changes
shelf ai review

# Review with specific provider
shelf ai review -p openai

The AI review provides:

  • Code quality analysis
  • Potential bug detection
  • Style guide compliance checks
  • Security vulnerability scanning
  • Performance improvement suggestions
  • Best practice recommendations

Migration from v0.8.7 to newer versions

If you're upgrading from a v0.8.7 version of Shelf, here are the key changes and migration steps:

Migration Steps

  1. Convert your existing config:
# Migration hints
shelf migrate

# Apply changes
shelf migrate --fix

Prompts

Prompt templates for commit messages and code reviews are stored in the user's configuration directory. You can customize these templates to tailor the AI's output to your specific needs.

Shell Completion

Shelf supports generating shell completion scripts for various shells. You can generate these scripts using the completion subcommand:

# Generate completion script for Bash
shelf completion bash > shelf.bash

# Generate completion script for Zsh
shelf completion zsh > _shelf

# Generate completion script for Fish
shelf completion fish > shelf.fish

To use the completion scripts:

  • For Bash, add the following line to your ~/.bashrc:

    source /path/to/shelf.bash
    
  • For Zsh, place the _shelf file in ~/.zfunc, then add source ~/.zfunc/_shelf in ~/.zshrc.

  • For Fish, place the shelf.fish file in ~/.config/fish/completions.

After setting up the completion script, restart your shell or source the respective configuration file to enable completions for the shelf command.

Configuration

AI settings are stored in ~/.config/shelf/ai.json (or $XDG_CONFIG_HOME/shelf/ai.json if set). You can configure:

  • provider: AI provider to use (openai, anthropic, gemini, groq, xai and ollama)
  • model: Ollama model to use (default: qwen2.5-coder)
  • openai_api_key: OpenAI API key for GPT models
  • ollama_host: Ollama server URL (default: http://localhost:11434)

Example configuration:

{
  "provider": "ollama",
  "model": "qwen2.5-coder",
  "ollama_host": "http://localhost:11434" // Only if you are using custom host,
}

Development

To build the project locally:

cargo build

To run tests:

cargo test

To run the project directly without installing:

cargo run --bin shelf -- [SUBCOMMAND]

Replace [SUBCOMMAND] with the command you want to run, such as dotfile or ai.

Contributing

Contributions are welcome! Please feel free tor submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

~62MB
~1M SLoC