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
2 changes: 1 addition & 1 deletion src/api/providers/zgsm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export class ZgsmAiHandler extends BaseProvider implements SingleCompletionHandl
"system",
),
},
timeout: 5000,
timeout: 20000,
}),
)
} catch (error) {
Expand Down
68 changes: 0 additions & 68 deletions src/core/costrict/commit/__tests__/commitGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,74 +206,6 @@ describe("CommitMessageGenerator", () => {
})
})

describe("getLocalizedPromptPrefix", () => {
it("should return Chinese prompt for zh-CN", () => {
const result = (generator as any).getLocalizedPromptPrefix("zh-CN")
expect(result).toContain("根据以下 git 变更生成提交信息")
})

it("should return Traditional Chinese prompt for zh-TW", () => {
const result = (generator as any).getLocalizedPromptPrefix("zh-TW")
expect(result).toContain("根據以下 git 變更生成提交訊息")
})

it("should return English prompt for other languages", () => {
const result = (generator as any).getLocalizedPromptPrefix("en")
expect(result).toContain("Generate a commit message based on the following git changes")
})
})

describe("getLocalizedConventionalPrompt", () => {
it("should return Chinese conventional prompt for zh-CN", () => {
const result = (generator as any).getLocalizedConventionalPrompt("zh-CN")
expect(result).toContain("约定式提交格式")
})

it("should return Traditional Chinese conventional prompt for zh-TW", () => {
const result = (generator as any).getLocalizedConventionalPrompt("zh-TW")
expect(result).toContain("約定式提交格式")
})

it("should return English conventional prompt for other languages", () => {
const result = (generator as any).getLocalizedConventionalPrompt("en")
expect(result).toContain("conventional commit format")
})
})

describe("getLocalizedSimplePrompt", () => {
it("should return Chinese simple prompt for zh-CN", () => {
const result = (generator as any).getLocalizedSimplePrompt("zh-CN")
expect(result).toContain("简洁的提交信息")
})

it("should return Traditional Chinese simple prompt for zh-TW", () => {
const result = (generator as any).getLocalizedSimplePrompt("zh-TW")
expect(result).toContain("簡潔的提交訊息")
})

it("should return English simple prompt for other languages", () => {
const result = (generator as any).getLocalizedSimplePrompt("en")
expect(result).toContain("concise commit message")
})
})

describe("getLocalizedReturnPrompt", () => {
it("should return Chinese return prompt for zh-CN", () => {
const result = (generator as any).getLocalizedReturnPrompt("zh-CN")
expect(result).toContain("只返回提交信息")
})

it("should return Traditional Chinese return prompt for zh-TW", () => {
const result = (generator as any).getLocalizedReturnPrompt("zh-TW")
expect(result).toContain("只返回提交訊息")
})

it("should return English return prompt for other languages", () => {
const result = (generator as any).getLocalizedReturnPrompt("en")
expect(result).toContain("Return only the commit message")
})
})

describe("shouldFilterFileContent", () => {
it("should return true for image files", () => {
const result = (generator as any).shouldFilterFileContent("image.png")
Expand Down
84 changes: 16 additions & 68 deletions src/core/costrict/commit/commitGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { ProviderSettings } from "@roo-code/types"
import type { ClineProvider } from "../../webview/ClineProvider"
import { t } from "../../../i18n"
import { singleCompletionHandler } from "../../../utils/single-completion-handler"
import { truncateOutput } from "../../../integrations/misc/extract-text"

const execAsync = promisify(exec)

const GIT_OUTPUT_CHAR_LIMIT = 30000
/**
* Commit message generator service
*/
Expand Down Expand Up @@ -189,7 +191,7 @@ export class CommitMessageGenerator {
// Prepare prompt for AI
const systemPrompt =
"You are an expert at generating concise, meaningful commit messages based on git diff information. Follow conventional commit format when appropriate."
const aiMessage = await singleCompletionHandler(
let aiMessage = await singleCompletionHandler(
apiConfiguration!,
this.buildAIPrompt(diffInfo, options),
systemPrompt,
Expand All @@ -199,6 +201,12 @@ export class CommitMessageGenerator {
modelId: options.commitModelId,
},
)

if (aiMessage.includes("</think>")) {
// Remove the <think> tag
aiMessage = (aiMessage.split("</think>")[1] || "").trim()
}

if (!aiMessage) {
throw new Error(t("commit:commit.error.aiFailed"))
}
Expand Down Expand Up @@ -356,11 +364,10 @@ export class CommitMessageGenerator {
* Build prompt for AI commit generation
*/
private buildAIPrompt(diffInfo: GitDiffInfo, options: CommitGenerationOptions): string {
const { useConventionalCommits = true, language } = options
const { useConventionalCommits = true } = options
const lang = this.getCommitLanguage(options)

// Build language-specific prompt
let prompt = this.getLocalizedPromptPrefix(lang)
let prompt = t("commit:commit.prompt.prefix", { lng: lang })

if (diffInfo.added.length > 0) {
prompt += `Added files:\n${diffInfo.added.map((f) => `- ${f}`).join("\n")}\n\n`
Expand All @@ -380,15 +387,16 @@ export class CommitMessageGenerator {

// Filter diff content to exclude content from files that should only show filenames
const filteredDiffContent = this.filterDiffContent(diffInfo.diffContent, diffInfo)
prompt += `Diff content:\n${filteredDiffContent}\n\n`

prompt += `Diff content:\n${truncateOutput(filteredDiffContent, undefined, GIT_OUTPUT_CHAR_LIMIT)}\n\n`

if (useConventionalCommits) {
prompt += this.getLocalizedConventionalPrompt(lang)
prompt += t("commit:commit.prompt.conventional", { lng: lang })
} else {
prompt += this.getLocalizedSimplePrompt(lang)
prompt += t("commit:commit.prompt.simple", { lng: lang })
}

prompt += this.getLocalizedReturnPrompt(lang)
prompt += t("commit:commit.prompt.return", { lng: lang })

return prompt
}
Expand Down Expand Up @@ -759,10 +767,6 @@ export class CommitMessageGenerator {
private generateBody(diffInfo: GitDiffInfo): string {
const lines: string[] = []

// const summary = `Added: ${diffInfo.added.length}, Modified: ${diffInfo.modified.length}, Deleted: ${diffInfo.deleted.length}, Renamed: ${diffInfo.renamed.length}`
// lines.push(summary)
// if (lines.length > 0) lines.push("")

if (diffInfo.added.length > 0) {
lines.push(t("commit:commit.files.added"))
diffInfo.added.forEach((file) => lines.push(`- ${file}`))
Expand Down Expand Up @@ -809,60 +813,4 @@ export class CommitMessageGenerator {
// Fallback to VSCode environment language
return vscode.env.language || "en"
}

/**
* Get localized prompt prefix based on language
*/
private getLocalizedPromptPrefix(lang: string): string {
switch (lang) {
case "zh-CN":
return `根据以下 git 变更生成提交信息:\n\n`
case "zh-TW":
return `根據以下 git 變更生成提交訊息:\n\n`
default:
return `Generate a commit message based on the following git changes:\n\n`
}
}

/**
* Get localized conventional commit prompt
*/
private getLocalizedConventionalPrompt(lang: string): string {
switch (lang) {
case "zh-CN":
return `请生成遵循约定式提交格式的提交信息 (type(scope): description)。`
case "zh-TW":
return `請生成遵循約定式提交格式的提交訊息 (type(scope): description)。`
default:
return `Please generate a commit message following conventional commit format (type(scope): description).`
}
}

/**
* Get localized simple commit prompt
*/
private getLocalizedSimplePrompt(lang: string): string {
switch (lang) {
case "zh-CN":
return `请生成简洁的提交信息。`
case "zh-TW":
return `請生成簡潔的提交訊息。`
default:
return `Please generate a concise commit message.`
}
}

/**
* Get localized return instruction
*/
private getLocalizedReturnPrompt(lang: string): string {
switch (lang) {
case "zh-CN":
return ` 只返回提交信息,不要解释。`
case "zh-TW":
return ` 只返回提交訊息,不要解釋。`
default:
return ` Return only the commit message, no explanations.`
}
}
}
2 changes: 1 addition & 1 deletion src/core/costrict/commit/commitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class CommitService {
const config = vscode.workspace.getConfiguration("zgsm.commit")
const useConventionalCommits = config.get<boolean>("useConventionalCommits", true)
const commitModelId = config.get<string>("commitModelId", "")
const maxLength = config.get<number>("maxLength", 72)
const maxLength = config.get<number>("maxLength", 150)
const language = config.get<string>("language", "auto")

// Generate commit message
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/costrict-i18n/locales/en/commit.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
"modified": "Modified files:",
"deleted": "Deleted files:",
"renamed": "Renamed files:"
},
"prompt": {
"prefix": "Generate a commit message based on the following git changes:\n\n",
"conventional": "Please generate a commit message following conventional commit format (type(scope): description).",
"simple": "Please generate a concise commit message.",
"return": " Return only the commit message, no explanations."
}
}
}
6 changes: 6 additions & 0 deletions src/i18n/costrict-i18n/locales/zh-CN/commit.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/costrict-i18n/locales/zh-TW/commit.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.