Skip to content

Conversation

@joshhn
Copy link
Contributor

@joshhn joshhn commented Oct 7, 2025

Description

This pull request refactors the handling of LLM provider types across the CLI codebase, replacing string-based provider identification with a strongly-typed approach using the new LLMProvider type in pkg/types.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Other (please describe):

Related Issue

Fixes #59

Changes Made

  • Added a new LLMProvider type in pkg/types/types.go with constants for each provider, helper methods for validation, string conversion, and parsing, plus functions to list supported providers.
  • Updated all provider selection, comparison, and storage logic in cmd/cli/llmSetup.go to use the new LLMProvider type and helper functions, replacing raw string usage.
  • Ran gofmt -w . to format the code.

Testing

  • Tested with Gemini API
  • Tested with Grok API
  • Tested on Windows
  • Tested on Linux
  • Tested on macOS
  • Added/updated tests (if applicable)

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have tested this in a real Git repository
  • I have read the CONTRIBUTING.md guidelines

Screenshots (if applicable)

Additional Notes


For Hacktoberfest Participants

  • This PR is submitted as part of Hacktoberfest 2025

Thank you for your contribution! 🎉

Summary by CodeRabbit

  • New Features

    • Added a CLI command to generate commit messages from repository context, with progress feedback, change previews, and automatic copying to clipboard.
  • Improvements

    • Enhanced LLM setup: dynamic provider selection, stricter validation, clearer prompts (including Ollama URL vs API key), and streamlined update flows.
    • Broadened sensitive data scrubbing to cover more keys (e.g., OpenAI, Claude, Gemini, Grok, Groq, GitHub, AWS), database passwords, and authorization headers, with clearer redaction placeholders.
  • Bug Fixes

    • Improved user-facing error messages and handling across commit generation and provider configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

Walkthrough

Implements an end-to-end commit message generation command using repo context, introduces a type-safe LLM provider enum, refactors CLI setup and store to use it, expands secret scrubbing patterns, and makes minor formatting changes across providers and git operations.

Changes

Cohort / File(s) Summary
Commit message command
cmd/cli/createMsg.go, cmd/cli/root.go
Adds CreateCommitMsg flow: repo validation, change collection, spinner, provider-based LLM selection, error reporting, clipboard copy, and preview. Adjusts Cobra command RunE/Use formatting.
LLM provider enum + integration
pkg/types/types.go, cmd/cli/llmSetup.go, cmd/cli/store/store.go
Introduces types.LLMProvider enum with helpers; updates CLI prompts/validation to parse providers; refactors store Config/LLMProvider fields and functions to use enum; adds ListSavedModels. Updates Ollama URL/API key handling.
Secret scrubbing
internal/scrubber/scrubber.go, internal/scrubber/scrubber_test.go
Expands regex patterns and redaction placeholders for credentials (AWS, OpenAI, Anthropic, GitHub, Slack, DB URLs, etc.); preserves control flow; whitespace tweaks in tests.
Git change collection
internal/git/operations.go
Minor reformatting in untracked file handling and scrubbed output spacing; behavior unchanged.
Provider implementations (formatting)
internal/chatgpt/chatgpt.go, internal/claude/claude.go, internal/ollama/ollama.go
Whitespace/import/tag formatting adjustments; no semantic changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CLI as CLI createmsg
  participant Git as Git Ops
  participant Scrub as Scrubber
  participant LLM as LLM Provider (OpenAI/Claude/Gemini/Groq/Grok/Ollama)
  participant CB as Clipboard
  participant Term as Terminal

  User->>CLI: Run command
  CLI->>Git: Validate repo, collect changes/stats
  Git-->>CLI: Diffs + untracked text
  CLI->>Scrub: Scrub sensitive data
  Scrub-->>CLI: Redacted context
  CLI->>CLI: Select provider via types.ParseLLMProvider
  CLI->>LLM: GenerateCommitMessage(context, config)
  note over LLM,CLI: Show spinner while waiting
  LLM-->>CLI: Commit message or error
  alt Error
    CLI->>Term: Print error details
  else Success
    CLI->>CB: Copy message
    CLI->>Term: Show message and change preview
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

enhancement, hacktoberfest, go

Suggested reviewers

  • DFanso

Poem

A nibble of diffs, a hop through the repo’s glade,
I sniff out secrets—poof! neatly masked and laid.
With enums tucked snug like carrots in rows,
I summon a message from LLM snows.
Clipboard at the ready—thump, thump—commit composed! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request includes significant changes outside the scope of the LLM provider refactor, such as the new CreateCommitMsg implementation, extensive scrubber pattern updates, spinner UI additions, and unrelated formatting tweaks across multiple internal packages. These additions go beyond the objectives defined in issue #59 and introduce features and modifications that should be reviewed separately. This dilutes the focus of the refactor and complicates the review process. Consider isolating the LLM provider enum refactoring into its own pull request and moving the commit message generation, scrubber updates, and other formatting changes into separate PRs to maintain clear review boundaries and traceability against each linked issue. This will help reviewers focus on a single objective per PR and reduce the risk of unintended side effects.
Docstring Coverage ⚠️ Warning Docstring coverage is 13.79% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary change of refactoring LLM provider strings into a type-safe enum within pkg/types, matching the author’s intent and focus on this core refactor. It clearly highlights the main structural adjustment without including extraneous details or noise. This phrasing aligns well with conventional commit style and provides immediate clarity on the key modification.
Linked Issues Check ✅ Passed The changes implement the objectives of issue #59 by defining the LLMProvider enum and associated constants in pkg/types, adding validation helpers, parsing and listing functions, and updating llmSetup.go and store/store.go to replace raw strings with the new enum. This addresses all coding-related requirements for compile-time safety, provider listing, validation, and usage within the CLI setup and persistent store. Therefore the primary requirements of the linked issue are satisfied.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@joshhn joshhn marked this pull request as ready for review October 7, 2025 06:42
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/scrubber/scrubber.go (1)

30-33: Fix redaction format for authorization header.

The replacement unconditionally appends a double quote, so inputs without quotes (or with single quotes) now end up with stray characters like Authorization=[REDACTED_AUTH_TOKEN]". Please capture the trailing quote in the regex and reuse it in the replacement to keep formatting intact.

-		{
-			Name:    "Authorization Header",
-			Pattern: regexp.MustCompile(`(?i)(authorization\s*[=:]\s*["\']?)([a-zA-Z0-9_\-\.]{20,})["\']?`),
-			Redact:  "${1}[REDACTED_AUTH_TOKEN]\"",
-		},
+		{
+			Name:    "Authorization Header",
+			Pattern: regexp.MustCompile(`(?i)(authorization\s*[=:]\s*)(["\']?)([a-zA-Z0-9_\-\.]{20,})(["\']?)`),
+			Redact:  "${1}${2}[REDACTED_AUTH_TOKEN]${4}",
+		},
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86f674b and 1bb6883.

📒 Files selected for processing (11)
  • cmd/cli/createMsg.go (2 hunks)
  • cmd/cli/llmSetup.go (2 hunks)
  • cmd/cli/root.go (1 hunks)
  • cmd/cli/store/store.go (12 hunks)
  • internal/chatgpt/chatgpt.go (3 hunks)
  • internal/claude/claude.go (1 hunks)
  • internal/git/operations.go (2 hunks)
  • internal/ollama/ollama.go (3 hunks)
  • internal/scrubber/scrubber.go (8 hunks)
  • internal/scrubber/scrubber_test.go (9 hunks)
  • pkg/types/types.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (7)
internal/scrubber/scrubber_test.go (1)
internal/scrubber/scrubber.go (2)
  • ScrubDiff (143-152)
  • GetDetectedPatterns (182-190)
pkg/types/types.go (1)
cmd/cli/store/store.go (1)
  • LLMProvider (14-17)
internal/ollama/ollama.go (3)
internal/chatgpt/chatgpt.go (1)
  • GenerateCommitMessage (13-32)
internal/claude/claude.go (1)
  • GenerateCommitMessage (33-85)
pkg/types/types.go (1)
  • Config (53-56)
cmd/cli/llmSetup.go (2)
pkg/types/types.go (3)
  • GetSupportedProviderStrings (38-45)
  • ParseLLMProvider (47-50)
  • ProviderOllama (11-11)
cmd/cli/store/store.go (4)
  • ListSavedModels (182-212)
  • ChangeDefault (214-248)
  • UpdateAPIKey (303-342)
  • DeleteModel (250-301)
internal/git/operations.go (2)
internal/utils/utils.go (2)
  • IsTextFile (19-35)
  • IsSmallFile (38-47)
internal/scrubber/scrubber.go (1)
  • ScrubEnvFile (193-231)
cmd/cli/store/store.go (1)
pkg/types/types.go (1)
  • LLMProvider (3-3)
cmd/cli/createMsg.go (8)
cmd/cli/store/store.go (2)
  • DefaultLLMKey (142-180)
  • Config (19-22)
internal/git/operations.go (2)
  • IsRepository (16-23)
  • GetChanges (26-130)
pkg/types/types.go (8)
  • Config (53-56)
  • RepoConfig (59-62)
  • ProviderGemini (8-8)
  • ProviderOpenAI (6-6)
  • ProviderClaude (7-7)
  • ProviderGroq (10-10)
  • ProviderOllama (11-11)
  • ProviderGrok (9-9)
internal/stats/statistics.go (1)
  • GetFileStatistics (14-74)
internal/display/display.go (3)
  • ShowFileStatistics (20-96)
  • ShowCommitMessage (99-115)
  • ShowChangesPreview (118-133)
internal/chatgpt/chatgpt.go (1)
  • GenerateCommitMessage (13-32)
internal/claude/claude.go (1)
  • GenerateCommitMessage (33-85)
internal/ollama/ollama.go (1)
  • GenerateCommitMessage (23-74)

Comment on lines +105 to +117
apiKeyPrompt := promptui.Prompt{
Label: "Enter API Key",
}
}


if model == "Ollama" {
prompt = promptui.Select{
if model == types.ProviderOllama.String() {
prompt = promptui.Select{
Label: "Select Option",
Items: options2,
}

apiKeyPrompt = promptui.Prompt {
Label: "Enter URL",
}
Items: options2,
}

apiKeyPrompt = promptui.Prompt{
Label: "Enter URL",
}
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 | 🟠 Major

Restore masked input for API keys.

Line 105 now collects API keys without a mask, so secrets are echoed back on screen. That’s a regression from the previous masked prompt and leaks credentials over the shoulder or into screen recordings. Please add Mask: '*' (while leaving the Ollama URL prompt unmasked).

-	apiKeyPrompt := promptui.Prompt{
-		Label: "Enter API Key",
-	}
+	apiKeyPrompt := promptui.Prompt{
+		Label: "Enter API Key",
+		Mask:  '*',
+	}
📝 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
apiKeyPrompt := promptui.Prompt{
Label: "Enter API Key",
}
}
if model == "Ollama" {
prompt = promptui.Select{
if model == types.ProviderOllama.String() {
prompt = promptui.Select{
Label: "Select Option",
Items: options2,
}
apiKeyPrompt = promptui.Prompt {
Label: "Enter URL",
}
Items: options2,
}
apiKeyPrompt = promptui.Prompt{
Label: "Enter URL",
}
apiKeyPrompt := promptui.Prompt{
Label: "Enter API Key",
Mask: '*',
}
if model == types.ProviderOllama.String() {
prompt = promptui.Select{
Label: "Select Option",
Items: options2,
}
apiKeyPrompt = promptui.Prompt{
Label: "Enter URL",
}
}
🤖 Prompt for AI Agents
In cmd/cli/llmSetup.go around lines 105 to 117, the API key prompt no longer
masks input so secrets are echoed; restore masking by setting Mask: '*' on the
apiKeyPrompt definition (keep the Ollama URL prompt unmasked for the model ==
ProviderOllama branch). Update the initial promptui.Prompt and the alternative
assignment inside the Ollama conditional so the API key prompt includes Mask:
'*' while leaving the URL prompt unchanged.

Copy link
Owner

@DFanso DFanso left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@DFanso DFanso added enhancement New feature or request hacktoberfest Eligible for Hacktoberfest hacktoberfest-accepted Approved Hacktoberfest contribution go Pull requests that update go code labels Oct 7, 2025
@DFanso DFanso merged commit 90459f3 into DFanso:main Oct 7, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code hacktoberfest Eligible for Hacktoberfest hacktoberfest-accepted Approved Hacktoberfest contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] Move LLM provider strings to type-safe enum in pkg/types

2 participants