Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,36 @@ Perfect for:
- 🔒 **Privacy** - Verify what data would be shared with external APIs
- 🧪 **Development** - Test prompt changes without API calls

### Auto Commit Mode

Automatically commit with the generated message without manual confirmation:

```bash
commit . --auto
```

This will:
- Generate the commit message using your configured LLM
- Automatically execute `git commit` with the generated message
- Skip the interactive review and manual confirmation step

**Note**: The `--auto` flag cannot be combined with `--dry-run`. Dry run mode takes precedence and will only preview without committing.

**Platform Support**: Works on Linux, macOS, and Windows.

### Combining Flags

```bash
# Preview only (no commit, no API call)
commit . --dry-run

# Generate and auto-commit
commit . --auto

# Generate with interactive review (default behavior)
commit .
```

Comment on lines +137 to +166
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clarify auto-commit behavior regarding interactive review.

The documentation states that --auto will "Skip the interactive review and manual confirmation step" (line 148), but the implementation in cmd/cli/createMsg.go still presents the interactive loop (accept/regenerate/edit/exit) and only auto-commits after the user accepts the message.

The actual behavior is:

  1. Generate commit message
  2. Present interactive review (user must accept, regenerate, edit, or exit)
  3. If user accepts, copy to clipboard AND auto-commit (if --auto was passed)

This is safer than skipping review entirely, but the documentation should accurately reflect this flow.

Consider revising the documentation to clarify:

 ### Auto Commit Mode
 
 Automatically commit with the generated message without manual confirmation:
 
 ```bash
 commit . --auto

This will:

  • Generate the commit message using your configured LLM
    +- Present the interactive review for you to accept, regenerate, or edit
  • Automatically execute git commit with the generated message
    -- Skip the interactive review and manual confirmation step
    +- Skip the manual git commit step after acceptance

<details>
<summary>🤖 Prompt for AI Agents</summary>

In README.md around lines 137 to 166, the docs incorrectly state that --auto
skips the interactive review; update the text to reflect the actual flow:
generate the commit message, present the interactive review
(accept/regenerate/edit/exit), and if the user accepts, automatically run git commit (i.e., skip the manual git commit step only after acceptance). Replace
the line that says "Skip the interactive review and manual confirmation step"
with wording that clarifies the interactive review is still shown and that
--auto only bypasses the manual git commit after acceptance; keep the note
about --dry-run precedence and platform support as-is.


</details>

<!-- This is an auto-generated comment by CodeRabbit -->

### Setup LLM and API Key

```bash
Expand Down
36 changes: 34 additions & 2 deletions cmd/cli/createMsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// CreateCommitMsg launches the interactive flow for reviewing, regenerating,
// editing, and accepting AI-generated commit messages in the current repo.
// If dryRun is true, it displays the prompt without making an API call.
func CreateCommitMsg(dryRun bool) {
func CreateCommitMsg(dryRun bool, autoCommit bool) {
// Validate COMMIT_LLM and required API keys
useLLM, err := store.DefaultLLMKey()
if err != nil {
Expand Down Expand Up @@ -208,6 +208,38 @@ interactionLoop:

pterm.Println()
display.ShowChangesPreview(fileStats)

// Auto-commit if flag is set (cross-platform compatible)
if autoCommit && !dryRun {
pterm.Println()
spinner, err := pterm.DefaultSpinner.
WithSequence("⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏").
Start("Automatically committing with generated message...")
if err != nil {
pterm.Error.Printf("Failed to start spinner: %v\n", err)
return
}

cmd := exec.Command("git", "commit", "-m", finalMessage)
cmd.Dir = currentDir
// Ensure git command works across all platforms
cmd.Env = os.Environ()

output, err := cmd.CombinedOutput()
if err != nil {
spinner.Fail("Commit failed")
pterm.Error.Printf("Failed to commit: %v\n", err)
if len(output) > 0 {
pterm.Error.Println(string(output))
}
return
}

spinner.Success("Committed successfully!")
if len(output) > 0 {
pterm.Info.Println(strings.TrimSpace(string(output)))
}
}
}

type styleOption struct {
Expand All @@ -234,6 +266,7 @@ var (
}
errSelectionCancelled = errors.New("selection cancelled")
)

// resolveOllamaConfig returns the URL and model for Ollama, using environment variables as fallbacks
func resolveOllamaConfig(apiKey string) (url, model string) {
url = apiKey
Expand All @@ -250,7 +283,6 @@ func resolveOllamaConfig(apiKey string) (url, model string) {
return url, model
}


func generateMessage(provider types.LLMProvider, config *types.Config, changes string, apiKey string, opts *types.GenerationOptions) (string, error) {
switch provider {
case types.ProviderGemini:
Expand Down
10 changes: 9 additions & 1 deletion cmd/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ var creatCommitMsg = &cobra.Command{
if err != nil {
return err
}
CreateCommitMsg(dryRun)

autoCommit, err := cmd.Flags().GetBool("auto")
if err != nil {
return err
}
CreateCommitMsg(dryRun, autoCommit)
return nil
},
}
Expand All @@ -76,6 +81,9 @@ func init() {
// Add --dry-run flag to the commit command
creatCommitMsg.Flags().Bool("dry-run", false, "Preview the prompt that would be sent to the LLM without making an API call")

// Add --auto flag to the commid command
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in comment.

"commid" should be "commit".

Apply this diff:

-	// Add --auto flag to the commid command
+	// Add --auto flag to the commit command
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Add --auto flag to the commid command
// Add --auto flag to the commit command
🤖 Prompt for AI Agents
In cmd/cli/root.go around line 84, the inline comment contains a typo: "commid"
should read "commit"; update the comment text to "Add --auto flag to the commit
command" (or equivalent) ensuring only the spelling is corrected and no other
code or formatting is changed.

creatCommitMsg.Flags().Bool("auto", false, "Automatically commit with the generated message")

rootCmd.AddCommand(creatCommitMsg)
rootCmd.AddCommand(llmCmd)
llmCmd.AddCommand(llmSetupCmd)
Expand Down
10 changes: 8 additions & 2 deletions internal/groq/groq.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"os"

httpClient "github.com/dfanso/commit-msg/internal/http"
internalHTTP "github.com/dfanso/commit-msg/internal/http"
"github.com/dfanso/commit-msg/pkg/types"
)

Expand Down Expand Up @@ -39,8 +39,14 @@ const defaultModel = "llama-3.3-70b-versatile"
var (
// allow overrides in tests
baseURL = "https://api.groq.com/openai/v1/chat/completions"
// httpClient can be overridden in tests; defaults to the internal http client
httpClient *http.Client
)

func init() {
httpClient = internalHTTP.GetClient()
}

// GenerateCommitMessage calls Groq's OpenAI-compatible chat completions API.
func GenerateCommitMessage(_ *types.Config, changes string, apiKey string, opts *types.GenerationOptions) (string, error) {
if changes == "" {
Expand Down Expand Up @@ -82,7 +88,7 @@ func GenerateCommitMessage(_ *types.Config, changes string, apiKey string, opts
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))

resp, err := httpClient.GetClient().Do(req)
resp, err := httpClient.Do(req)
if err != nil {
return "", fmt.Errorf("failed to call Groq API: %w", err)
}
Expand Down
Loading