commitmsg

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package commitmsg implements AI-powered conventional commit message generation. It reads staged git changes and the active PM task, then asks the configured provider to produce a Conventional Commits spec message.

Git hook integration:

To use as a prepare-commit-msg hook, create .git/hooks/prepare-commit-msg:

  #!/bin/sh
  # Only run when there is no commit message yet (interactive commit)
  case "$2" in
    merge|squash) exit 0 ;;
  esac
  msg=$(cloop commit-msg 2>/dev/null)
  if [ -n "$msg" ]; then
    echo "$msg" > "$1"
  fi

Make it executable: chmod +x .git/hooks/prepare-commit-msg

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(c *CommitContext) string

BuildPrompt constructs the AI prompt from the commit context.

func CollectDiff

func CollectDiff(workDir string) (string, error)

CollectDiff runs `git diff --cached` in workDir and returns the output. If there are no staged changes the returned string is empty.

Types

type CommitContext

type CommitContext struct {
	// StagedDiff is the output of `git diff --cached`.
	StagedDiff string
	// ActiveTask is the currently in-progress PM task, if any.
	ActiveTask *pm.Task
	// Goal is the project goal from state.
	Goal string
	// TypeOverride, when non-empty, forces a specific Conventional Commits type
	// (e.g. "feat", "fix", "chore").
	TypeOverride string
}

CommitContext holds the data used to generate a commit message.

type Result

type Result struct {
	// Message is the full Conventional Commits message (subject + optional body).
	Message string
}

Result holds the generated commit message.

func Generate

func Generate(ctx context.Context, prov provider.Provider, model string, timeout time.Duration, c *CommitContext) (*Result, error)

Generate calls the provider to produce a commit message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL