@@ -8,9 +8,11 @@ import { ProviderSettings } from "@roo-code/types"
88import type { ClineProvider } from "../../webview/ClineProvider"
99import { t } from "../../../i18n"
1010import { singleCompletionHandler } from "../../../utils/single-completion-handler"
11+ import { truncateOutput } from "../../../integrations/misc/extract-text"
1112
1213const execAsync = promisify ( exec )
1314
15+ const GIT_OUTPUT_CHAR_LIMIT = 30000
1416/**
1517 * Commit message generator service
1618 */
@@ -189,7 +191,7 @@ export class CommitMessageGenerator {
189191 // Prepare prompt for AI
190192 const systemPrompt =
191193 "You are an expert at generating concise, meaningful commit messages based on git diff information. Follow conventional commit format when appropriate."
192- const aiMessage = await singleCompletionHandler (
194+ let aiMessage = await singleCompletionHandler (
193195 apiConfiguration ! ,
194196 this . buildAIPrompt ( diffInfo , options ) ,
195197 systemPrompt ,
@@ -199,6 +201,12 @@ export class CommitMessageGenerator {
199201 modelId : options . commitModelId ,
200202 } ,
201203 )
204+
205+ if ( aiMessage . includes ( "</think>" ) ) {
206+ // Remove the <think> tag
207+ aiMessage = ( aiMessage . split ( "</think>" ) [ 1 ] || "" ) . trim ( )
208+ }
209+
202210 if ( ! aiMessage ) {
203211 throw new Error ( t ( "commit:commit.error.aiFailed" ) )
204212 }
@@ -356,11 +364,10 @@ export class CommitMessageGenerator {
356364 * Build prompt for AI commit generation
357365 */
358366 private buildAIPrompt ( diffInfo : GitDiffInfo , options : CommitGenerationOptions ) : string {
359- const { useConventionalCommits = true , language } = options
367+ const { useConventionalCommits = true } = options
360368 const lang = this . getCommitLanguage ( options )
361-
362369 // Build language-specific prompt
363- let prompt = this . getLocalizedPromptPrefix ( lang )
370+ let prompt = t ( "commit:commit.prompt.prefix" , { lng : lang } )
364371
365372 if ( diffInfo . added . length > 0 ) {
366373 prompt += `Added files:\n${ diffInfo . added . map ( ( f ) => `- ${ f } ` ) . join ( "\n" ) } \n\n`
@@ -380,15 +387,16 @@ export class CommitMessageGenerator {
380387
381388 // Filter diff content to exclude content from files that should only show filenames
382389 const filteredDiffContent = this . filterDiffContent ( diffInfo . diffContent , diffInfo )
383- prompt += `Diff content:\n${ filteredDiffContent } \n\n`
390+
391+ prompt += `Diff content:\n${ truncateOutput ( filteredDiffContent , undefined , GIT_OUTPUT_CHAR_LIMIT ) } \n\n`
384392
385393 if ( useConventionalCommits ) {
386- prompt += this . getLocalizedConventionalPrompt ( lang )
394+ prompt += t ( "commit:commit.prompt.conventional" , { lng : lang } )
387395 } else {
388- prompt += this . getLocalizedSimplePrompt ( lang )
396+ prompt += t ( "commit:commit.prompt.simple" , { lng : lang } )
389397 }
390398
391- prompt += this . getLocalizedReturnPrompt ( lang )
399+ prompt += t ( "commit:commit.prompt.return" , { lng : lang } )
392400
393401 return prompt
394402 }
@@ -759,10 +767,6 @@ export class CommitMessageGenerator {
759767 private generateBody ( diffInfo : GitDiffInfo ) : string {
760768 const lines : string [ ] = [ ]
761769
762- // const summary = `Added: ${diffInfo.added.length}, Modified: ${diffInfo.modified.length}, Deleted: ${diffInfo.deleted.length}, Renamed: ${diffInfo.renamed.length}`
763- // lines.push(summary)
764- // if (lines.length > 0) lines.push("")
765-
766770 if ( diffInfo . added . length > 0 ) {
767771 lines . push ( t ( "commit:commit.files.added" ) )
768772 diffInfo . added . forEach ( ( file ) => lines . push ( `- ${ file } ` ) )
@@ -809,60 +813,4 @@ export class CommitMessageGenerator {
809813 // Fallback to VSCode environment language
810814 return vscode . env . language || "en"
811815 }
812-
813- /**
814- * Get localized prompt prefix based on language
815- */
816- private getLocalizedPromptPrefix ( lang : string ) : string {
817- switch ( lang ) {
818- case "zh-CN" :
819- return `根据以下 git 变更生成提交信息:\n\n`
820- case "zh-TW" :
821- return `根據以下 git 變更生成提交訊息:\n\n`
822- default :
823- return `Generate a commit message based on the following git changes:\n\n`
824- }
825- }
826-
827- /**
828- * Get localized conventional commit prompt
829- */
830- private getLocalizedConventionalPrompt ( lang : string ) : string {
831- switch ( lang ) {
832- case "zh-CN" :
833- return `请生成遵循约定式提交格式的提交信息 (type(scope): description)。`
834- case "zh-TW" :
835- return `請生成遵循約定式提交格式的提交訊息 (type(scope): description)。`
836- default :
837- return `Please generate a commit message following conventional commit format (type(scope): description).`
838- }
839- }
840-
841- /**
842- * Get localized simple commit prompt
843- */
844- private getLocalizedSimplePrompt ( lang : string ) : string {
845- switch ( lang ) {
846- case "zh-CN" :
847- return `请生成简洁的提交信息。`
848- case "zh-TW" :
849- return `請生成簡潔的提交訊息。`
850- default :
851- return `Please generate a concise commit message.`
852- }
853- }
854-
855- /**
856- * Get localized return instruction
857- */
858- private getLocalizedReturnPrompt ( lang : string ) : string {
859- switch ( lang ) {
860- case "zh-CN" :
861- return ` 只返回提交信息,不要解释。`
862- case "zh-TW" :
863- return ` 只返回提交訊息,不要解釋。`
864- default :
865- return ` Return only the commit message, no explanations.`
866- }
867- }
868816}
0 commit comments