Create a global git hook to auto-generate commit messages via llama-swap #99
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Create a
prepare-commit-msggit hook that runs globally and calls the local llama-swap endpoint onenergon.home.arpato auto-generate conventional commit messages from the staged diff.Background
Three approaches from the community:
git diff HEADpiped in, using jq to build the JSON payloadprepare-commit-msghook calling thellmCLI with a system prompt file, with spinner animation and error handling/api/generateendpoint with Conventional Commits formatAll three use the
prepare-commit-msghook, which fires after git creates the default commit message file but before the editor opens — perfect for pre-filling with an AI-generated message.Approach
Architecture
Implementation options
Option A: Shell script (simplest, no deps)
curl+jqgit diff --cachedinto a curl POST to llama-swapOption B: Python script (more robust)
subprocess+urllib(stdlib only)llama-swap endpoint
llama-swap exposes a chat completions API compatible with OpenAI's format:
Response:
System prompt (draft)
Hook setup (global)
Prompt file (
~/.config/prompts/commit-system-prompt.txt)Store the system prompt in a separate file so it can be iterated without touching the hook:
Environment variables
SKIP_LLM_GITHOOKAI_COMMIT_MODELqwen2.5-coder:7bAI_COMMIT_URLhttp://energon.home.arpa:8080Spinner (optional polish)
As Harper Reed's approach shows, a background spinner animation gives feedback while the model generates:
Acceptance Criteria
prepare-commit-msghook is installed at~/.git-hooks/prepare-commit-msggit config --global core.hooksPathpoints to the global hooks directoryhttp://energon.home.arpallama-swap endpoint with staged diffSKIP_LLM_GITHOOKenv var can disable the hook