Skip to content

Commit c90a32b

Browse files
authored
Generation commit (#503)
* feat: add commit message generation feature * feat: enhance commit message generation with i18n support and API improvements * fix(i18n): update parameter placeholder syntax in commit localization files * feat(types): add isRateLimitRetry metadata field for rate limiting handling * fix(modelCache): change method call from getInstance to getAllInstance * refactor(commit): implement singleton pattern and execution lock
1 parent 22e9448 commit c90a32b

File tree

9 files changed

+41
-15
lines changed

9 files changed

+41
-15
lines changed

src/api/providers/zgsm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ export class ZgsmAiHandler extends BaseProvider implements SingleCompletionHandl
521521
"system",
522522
),
523523
},
524-
timeout: 10_000,
524+
timeout: 5000,
525525
}),
526526
)
527527
} catch (error) {

src/core/costrict/commit/commitGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class CommitMessageGenerator {
112112
const aiSuggestion = await this.generateCommitMessageWithAI(diffInfo, options)
113113
return aiSuggestion
114114
} catch (error) {
115-
console.log("AI generation failed, falling back to rule-based:", error)
115+
this.provider?.log("AI generation failed, falling back to rule-based: " + error?.message)
116116
// Fallback to rule-based analysis
117117
const suggestion = this.analyzeChanges(diffInfo, options)
118118
return suggestion

src/core/costrict/commit/index.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* Provides functionality to generate commit messages based on local changes
55
* and populate them in VSCode's SCM input.
66
*/
7+
import * as vscode from "vscode"
8+
import { CommitService } from "./commitService"
9+
import { t } from "../../../i18n"
10+
import { type ClineProvider } from "../../webview/ClineProvider"
711

812
export * from "./types"
913
export * from "./commitGenerator"
@@ -12,12 +16,12 @@ export * from "./commitService"
1216
/**
1317
* Commit generation command handler
1418
*/
15-
export async function handleGenerateCommitMessage(
16-
provider: import("../../webview/ClineProvider").ClineProvider,
17-
): Promise<void> {
18-
const { CommitService } = await import("./commitService")
19-
const { t } = await import("../../../i18n")
19+
// Singleton instance
20+
let commitServiceInstance: CommitService | null = null
21+
// Execution lock to prevent concurrent calls
22+
let isExecuting = false
2023

24+
export async function handleGenerateCommitMessage(provider: ClineProvider): Promise<void> {
2125
const workspaceRoot = CommitService.getWorkspaceRoot()
2226
if (!workspaceRoot) {
2327
throw new Error(t("commit:commit.error.noWorkspace"))
@@ -28,8 +32,27 @@ export async function handleGenerateCommitMessage(
2832
throw new Error(t("commit:commit.error.notGitRepo"))
2933
}
3034

31-
const commitService = new CommitService()
32-
commitService.initialize(workspaceRoot, provider)
35+
// Check if execution is already in progress
36+
if (isExecuting) {
37+
vscode.window.showInformationMessage(t("commit:commit.message.executing"))
38+
return
39+
}
40+
41+
try {
42+
// Set execution lock
43+
isExecuting = true
3344

34-
await commitService.generateAndPopulateCommitMessage()
45+
// Singleton pattern: reuse existing instance or create new one
46+
if (!commitServiceInstance) {
47+
commitServiceInstance = new CommitService()
48+
commitServiceInstance.initialize(workspaceRoot, provider)
49+
}
50+
51+
await commitServiceInstance.generateAndPopulateCommitMessage()
52+
isExecuting = false
53+
} catch (error) {
54+
// Reset instance on error to allow recovery
55+
isExecuting = false
56+
throw error
57+
}
3558
}

src/core/task/Task.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
22312231

22322232
// Now abort (emits TaskAborted which provider listens to)
22332233
await this.abortTask()
2234-
22352234
this?.api?.cancelChat?.(cancelReason)
22362235
// Do not rehydrate here; provider owns rehydration to avoid duplication races
22372236
}

src/core/webview/ClineProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,6 +2680,7 @@ export class ClineProvider
26802680
},
26812681
).catch(() => {
26822682
console.error("Failed to abort task")
2683+
task?.api?.cancelChat?.(task.abortReason)
26832684
})
26842685

26852686
task?.api?.cancelChat?.(task.abortReason)

src/i18n/costrict-i18n/locales/en/commit.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"message": {
1616
"copiedToClipboard": "Commit message generated but could not be automatically populated in the input box. The commit message has been copied to clipboard.",
17-
"generationFailed": "Failed to generate commit message: {{error}}"
17+
"generationFailed": "Failed to generate commit message: {{error}}",
18+
"executing": "Please wait, commit generation is already in progress"
1819
},
1920
"action": {
2021
"addFile": "add {{0}}",

src/i18n/costrict-i18n/locales/zh-CN/commit.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"message": {
1616
"copiedToClipboard": "提交消息已生成,但无法自动填充到输入框中。提交消息已复制到剪贴板。",
17-
"generationFailed": "生成提交消息失败:{{error}}"
17+
"generationFailed": "生成提交消息失败:{{error}}",
18+
"executing": "点击过于频繁,请等待当前提交生成完成"
1819
},
1920
"action": {
2021
"addFile": "添加 {{0}}",

src/i18n/costrict-i18n/locales/zh-TW/commit.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"message": {
1616
"copiedToClipboard": "提交訊息已生成,但無法自動填充到輸入框中。提交訊息已複製到剪貼簿。",
17-
"generationFailed": "生成提交訊息失敗:{{error}}"
17+
"generationFailed": "生成提交訊息失敗:{{error}}",
18+
"executing": "點擊過於頻繁,請等待當前提交生成完成"
1819
},
1920
"action": {
2021
"addFile": "添加 {{0}}",

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ export const ChatRowContent = ({
14131413
message={message.text || ""}
14141414
apiConfiguration={apiConfiguration}
14151415
additionalContent={
1416-
!message?.metadata?.isRateLimit ? (
1416+
!message?.metadata?.isRateLimit && !message?.metadata?.isRateLimitRetry ? (
14171417
<>
14181418
<br />
14191419
<br />

0 commit comments

Comments
 (0)