From fe66422f3104520574bdfc8b370aff0b4a9d4745 Mon Sep 17 00:00:00 2001 From: Aqsa Aqeel Date: Thu, 23 Oct 2025 03:07:55 +0530 Subject: [PATCH] Feat: Add verbose mode for debugging and diff stats - Adds a flag for verbose output, including - diff statistics, repository details, and prompt info. - This helps debug LLM commit message generation issues. --- cmd/cli/createMsg.go | 23 ++++++++++++++++++++--- cmd/cli/root.go | 17 +++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/cmd/cli/createMsg.go b/cmd/cli/createMsg.go index 4d2c759..d31f535 100644 --- a/cmd/cli/createMsg.go +++ b/cmd/cli/createMsg.go @@ -23,7 +23,8 @@ 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(Store *store.StoreMethods, dryRun bool, autoCommit bool) { +// If verbose is true, shows detailed diff statistics and processing info. +func CreateCommitMsg(Store *store.StoreMethods, dryRun bool, autoCommit bool, verbose bool) { // Validate COMMIT_LLM and required API keys useLLM, err := Store.DefaultLLMKey() if err != nil { @@ -67,6 +68,12 @@ func CreateCommitMsg(Store *store.StoreMethods, dryRun bool, autoCommit bool) { pterm.Println() display.ShowFileStatistics(fileStats) + if verbose { + pterm.Info.Printf("Repository: %s\n", currentDir) + pterm.Info.Printf("File summary: %d staged, %d unstaged, %d untracked\n", + len(fileStats.StagedFiles), len(fileStats.UnstagedFiles), len(fileStats.UntrackedFiles)) + } + if fileStats.TotalFiles == 0 { pterm.Warning.Println("No changes detected in the Git repository.") pterm.Info.Println("Tips:") @@ -124,12 +131,16 @@ func CreateCommitMsg(Store *store.StoreMethods, dryRun bool, autoCommit bool) { pterm.Info.Printf("Truncated diff to %d lines, %d characters.\n", actualLineCount, len(changes)) pterm.Info.Println("Consider committing smaller changes for more accurate commit messages.") + } else if verbose { + pterm.Info.Printf("Diff statistics: %d lines, %d characters (within limits).\n", len(diffLines), len(changes)) + inputTokens := estimateTokens(changes) + pterm.Info.Printf("Estimated tokens for LLM: %d input tokens.\n", inputTokens) } // Handle dry-run mode: display what would be sent to LLM without making API call if dryRun { pterm.Println() - displayDryRunInfo(commitLLM, config, changes, apiKey) + displayDryRunInfo(commitLLM, config, changes, apiKey, verbose) return } @@ -561,7 +572,7 @@ func displayMissingCredentialHint(provider types.LLMProvider) { } // displayDryRunInfo shows what would be sent to the LLM without making an API call -func displayDryRunInfo(provider types.LLMProvider, config *types.Config, changes string, apiKey string) { +func displayDryRunInfo(provider types.LLMProvider, config *types.Config, changes string, apiKey string, verbose bool) { pterm.DefaultHeader.WithFullWidth(). WithBackgroundStyle(pterm.NewStyle(pterm.BgBlue)). WithTextStyle(pterm.NewStyle(pterm.FgWhite, pterm.Bold)). @@ -633,11 +644,17 @@ func displayDryRunInfo(provider types.LLMProvider, config *types.Config, changes } statsData = append(statsData, []string{"Estimated Processing Time", fmt.Sprintf("%d-%d seconds", minTime, maxTime)}) + if verbose { + statsData = append(statsData, []string{"Prompt Length", fmt.Sprintf("%d characters", len(prompt))}) + } pterm.DefaultTable.WithHasHeader(false).WithData(statsData).Render() pterm.Println() pterm.Success.Println("Dry-run complete. To generate actual commit message, run without --dry-run flag.") + if !verbose { + pterm.Info.Println("Use --toggle flag to see debug details.") + } } // maskAPIKey masks the API key for display purposes diff --git a/cmd/cli/root.go b/cmd/cli/root.go index 65b9b51..6e417b6 100644 --- a/cmd/cli/root.go +++ b/cmd/cli/root.go @@ -29,6 +29,10 @@ var rootCmd = &cobra.Command{ # Generate a commit message and automatically commit it commit . --auto + + # Show verbose debug information (diff stats, full prompts, repository details) + commit . --toggle + commit . --dry-run --toggle `, // Uncomment the following line if your bare application // has an action associated with it: @@ -108,7 +112,13 @@ var creatCommitMsg = &cobra.Command{ if err != nil { return err } - CreateCommitMsg(Store, dryRun, autoCommit) + + verbose, err := cmd.Flags().GetBool("toggle") + if err != nil { + return err + } + + CreateCommitMsg(Store, dryRun, autoCommit, verbose) return nil }, } @@ -123,11 +133,10 @@ func init() { // Cobra also supports local flags, which will only run // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") - - // Add --dry-run and --auto as persistent flags so they show in top-level help + // Add --dry-run, --auto, and --toggle as persistent flags so they show in top-level help rootCmd.PersistentFlags().Bool("dry-run", false, "Preview the prompt that would be sent to the LLM without making an API call") rootCmd.PersistentFlags().Bool("auto", false, "Automatically commit with the generated message") + rootCmd.PersistentFlags().BoolP("toggle", "t", false, "Show verbose debug information (diff stats, full prompts, repository details)") rootCmd.AddCommand(creatCommitMsg) rootCmd.AddCommand(llmCmd)