@@ -146,7 +146,7 @@ func CreateCommitMsg(Store *store.StoreMethods, dryRun bool, autoCommit bool, ve
146146 // Handle dry-run mode: display what would be sent to LLM without making API call
147147 if dryRun {
148148 pterm .Println ()
149- displayDryRunInfo (commitLLM , config , changes , apiKey , verbose )
149+ displayDryRunInfo (commitLLM , Store , config , changes , apiKey , verbose )
150150 return
151151 }
152152
@@ -355,45 +355,47 @@ func generateMessage(ctx context.Context, provider llm.Provider, changes string,
355355// generateMessageWithCache generates a commit message with caching support.
356356func generateMessageWithCache (ctx context.Context , provider llm.Provider , store * store.StoreMethods , providerType types.LLMProvider , changes string , opts * types.GenerationOptions ) (string , error ) {
357357 startTime := time .Now ()
358-
358+
359359 // Determine if this is a first attempt (cache check eligible)
360360 isFirstAttempt := opts == nil || opts .Attempt <= 1
361-
361+
362362 // Check cache first (only for first attempt to avoid caching regenerations)
363363 if isFirstAttempt {
364364 if cachedEntry , found := store .GetCachedMessage (providerType , changes , opts ); found {
365365 pterm .Info .Printf ("Using cached commit message (saved $%.4f)\n " , cachedEntry .Cost )
366-
366+
367367 // Record cache hit event
368368 event := & types.GenerationEvent {
369369 Provider : providerType ,
370370 Success : true ,
371371 GenerationTime : float64 (time .Since (startTime ).Nanoseconds ()) / 1e6 , // Convert to milliseconds
372- TokensUsed : 0 , // No tokens used for cached result
373- Cost : 0 , // No cost for cached result
372+ TokensUsed : 0 , // No tokens used for cached result
373+ Cost : 0 , // No cost for cached result
374374 CacheHit : true ,
375375 CacheChecked : true ,
376376 Timestamp : time .Now ().UTC ().Format (time .RFC3339 ),
377377 }
378-
378+
379379 if err := store .RecordGenerationEvent (event ); err != nil {
380380 // Log the error but don't fail the operation
381381 fmt .Printf ("Warning: Failed to record usage statistics: %v\n " , err )
382382 }
383-
383+
384384 return cachedEntry .Message , nil
385385 }
386386 }
387387
388388 // Generate new message
389389 message , err := provider .Generate (ctx , changes , opts )
390390 generationTime := float64 (time .Since (startTime ).Nanoseconds ()) / 1e6 // Convert to milliseconds
391-
391+
392+ customTemplate , _ := store .GetTemplate ()
393+
392394 // Estimate tokens and cost
393- inputTokens := estimateTokens (types .BuildCommitPrompt (changes , opts ))
395+ inputTokens := estimateTokens (types .BuildCommitPromptWithTemplate (changes , opts , customTemplate ))
394396 outputTokens := 100 // Estimate output tokens
395397 cost := estimateCost (providerType , inputTokens , outputTokens )
396-
398+
397399 // Record generation event
398400 event := & types.GenerationEvent {
399401 Provider : providerType ,
@@ -405,17 +407,17 @@ func generateMessageWithCache(ctx context.Context, provider llm.Provider, store
405407 CacheChecked : isFirstAttempt , // Only first attempts check cache
406408 Timestamp : time .Now ().UTC ().Format (time .RFC3339 ),
407409 }
408-
410+
409411 if err != nil {
410412 event .ErrorMessage = err .Error ()
411413 }
412-
414+
413415 // Record the event regardless of success/failure
414416 if statsErr := store .RecordGenerationEvent (event ); statsErr != nil {
415417 // Log the error but don't fail the operation
416418 fmt .Printf ("Warning: Failed to record usage statistics: %v\n " , statsErr )
417419 }
418-
420+
419421 if err != nil {
420422 return "" , err
421423 }
@@ -630,7 +632,7 @@ func displayMissingCredentialHint(provider types.LLMProvider) {
630632}
631633
632634// displayDryRunInfo shows what would be sent to the LLM without making an API call
633- func displayDryRunInfo (provider types.LLMProvider , config * types.Config , changes string , apiKey string , verbose bool ) {
635+ func displayDryRunInfo (provider types.LLMProvider , storeMethods * store. StoreMethods , config * types.Config , changes string , apiKey string , verbose bool ) {
634636 pterm .DefaultHeader .WithFullWidth ().
635637 WithBackgroundStyle (pterm .NewStyle (pterm .BgBlue )).
636638 WithTextStyle (pterm .NewStyle (pterm .FgWhite , pterm .Bold )).
@@ -665,7 +667,8 @@ func displayDryRunInfo(provider types.LLMProvider, config *types.Config, changes
665667
666668 // Build and display the prompt
667669 opts := & types.GenerationOptions {Attempt : 1 }
668- prompt := types .BuildCommitPrompt (changes , opts )
670+ customTemplate , _ := storeMethods .GetTemplate ()
671+ prompt := types .BuildCommitPromptWithTemplate (changes , opts , customTemplate )
669672
670673 pterm .DefaultSection .Println ("Prompt That Would Be Sent" )
671674 pterm .Println ()
0 commit comments