diff --git a/src/api/providers/zgsm.ts b/src/api/providers/zgsm.ts index 0c187c20fb..bb26a29cac 100644 --- a/src/api/providers/zgsm.ts +++ b/src/api/providers/zgsm.ts @@ -538,7 +538,7 @@ export class ZgsmAiHandler extends BaseProvider implements SingleCompletionHandl "system", ), }, - timeout: 5000, + timeout: 20000, }), ) } catch (error) { diff --git a/src/core/costrict/commit/__tests__/commitGenerator.test.ts b/src/core/costrict/commit/__tests__/commitGenerator.test.ts index 5865b98a2f..a706a0b401 100644 --- a/src/core/costrict/commit/__tests__/commitGenerator.test.ts +++ b/src/core/costrict/commit/__tests__/commitGenerator.test.ts @@ -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") diff --git a/src/core/costrict/commit/commitGenerator.ts b/src/core/costrict/commit/commitGenerator.ts index f321e22490..6d6f789002 100644 --- a/src/core/costrict/commit/commitGenerator.ts +++ b/src/core/costrict/commit/commitGenerator.ts @@ -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 */ @@ -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, @@ -199,6 +201,12 @@ export class CommitMessageGenerator { modelId: options.commitModelId, }, ) + + if (aiMessage.includes("")) { + // Remove the tag + aiMessage = (aiMessage.split("")[1] || "").trim() + } + if (!aiMessage) { throw new Error(t("commit:commit.error.aiFailed")) } @@ -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` @@ -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 } @@ -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}`)) @@ -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.` - } - } } diff --git a/src/core/costrict/commit/commitService.ts b/src/core/costrict/commit/commitService.ts index 9be0a0ad1a..0e14c51d91 100644 --- a/src/core/costrict/commit/commitService.ts +++ b/src/core/costrict/commit/commitService.ts @@ -49,7 +49,7 @@ export class CommitService { const config = vscode.workspace.getConfiguration("zgsm.commit") const useConventionalCommits = config.get("useConventionalCommits", true) const commitModelId = config.get("commitModelId", "") - const maxLength = config.get("maxLength", 72) + const maxLength = config.get("maxLength", 150) const language = config.get("language", "auto") // Generate commit message diff --git a/src/i18n/costrict-i18n/locales/en/commit.json b/src/i18n/costrict-i18n/locales/en/commit.json index 17f19540b4..461829dbfd 100644 --- a/src/i18n/costrict-i18n/locales/en/commit.json +++ b/src/i18n/costrict-i18n/locales/en/commit.json @@ -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." } } } diff --git a/src/i18n/costrict-i18n/locales/zh-CN/commit.json b/src/i18n/costrict-i18n/locales/zh-CN/commit.json index c092ca8caa..35c6da638d 100644 --- a/src/i18n/costrict-i18n/locales/zh-CN/commit.json +++ b/src/i18n/costrict-i18n/locales/zh-CN/commit.json @@ -34,6 +34,12 @@ "modified": "修改的文件:", "deleted": "删除的文件:", "renamed": "重命名的文件:" + }, + "prompt": { + "prefix": "根据以下 git 变更生成提交信息:\n\n", + "conventional": "请生成遵循约定式提交格式的提交信息 (type(scope): description)。", + "simple": "请生成简洁的提交信息。", + "return": " 只返回提交信息,不要解释。" } } } diff --git a/src/i18n/costrict-i18n/locales/zh-TW/commit.json b/src/i18n/costrict-i18n/locales/zh-TW/commit.json index 3f24f4b6ae..bd4d34f5c1 100644 --- a/src/i18n/costrict-i18n/locales/zh-TW/commit.json +++ b/src/i18n/costrict-i18n/locales/zh-TW/commit.json @@ -34,6 +34,12 @@ "modified": "修改的檔案:", "deleted": "刪除的檔案:", "renamed": "重新命名的檔案:" + }, + "prompt": { + "prefix": "根據以下 git 變更生成提交訊息:\n\n", + "conventional": "請生成遵循約定式提交格式的提交訊息 (type(scope): description)。", + "simple": "請生成簡潔的提交訊息。", + "return": " 只返回提交訊息,不要解釋。" } } }