From b89e100077ac6b3c35e35d83c94c8cce655423b7 Mon Sep 17 00:00:00 2001 From: Hesham Salman Date: Thu, 11 Dec 2025 17:32:02 -0500 Subject: [PATCH] Updated prompts --- .../Core/BatchCombinationPromptBuilder.swift | 9 +++------ .../SwiftCommitGen/Core/DiffSummarizer.swift | 4 ++-- Sources/SwiftCommitGen/Core/LLMClient.swift | 12 +++++------- .../Core/OverviewPromptBuilder.swift | 15 ++++----------- .../SwiftCommitGen/Core/PromptBuilder.swift | 19 ++++++------------- 5 files changed, 20 insertions(+), 39 deletions(-) diff --git a/Sources/SwiftCommitGen/Core/BatchCombinationPromptBuilder.swift b/Sources/SwiftCommitGen/Core/BatchCombinationPromptBuilder.swift index 60d6af2..a5af193 100644 --- a/Sources/SwiftCommitGen/Core/BatchCombinationPromptBuilder.swift +++ b/Sources/SwiftCommitGen/Core/BatchCombinationPromptBuilder.swift @@ -62,13 +62,10 @@ struct BatchCombinationPromptBuilder { let systemPrompt = Instructions { """ - You are an AI assistant merging multiple partial commit drafts into a single, well-structured commit message. - Preserve all important intent from the inputs, avoid redundancy, and keep the final subject concise (<= 50 characters). - The title should succinctly describe the change in a specific and informative manner. - Provide an optional body only when useful for additional context. - If a body is present, it should describe the _purpose_ of the change, not just _what_ was changed: focus on the reasoning behind the changes rather than a file-by-file summary. + Combine these partial commit drafts into one commit message. - Be clear and concise, but do not omit critical information. + Subject: max 50 chars, imperative mood, summarize the shared purpose. + Body: optional, explain WHY if helpful. """ "" metadata.style.styleGuidance diff --git a/Sources/SwiftCommitGen/Core/DiffSummarizer.swift b/Sources/SwiftCommitGen/Core/DiffSummarizer.swift index 286d0d3..9c07bd5 100644 --- a/Sources/SwiftCommitGen/Core/DiffSummarizer.swift +++ b/Sources/SwiftCommitGen/Core/DiffSummarizer.swift @@ -73,11 +73,11 @@ struct ChangeSummary: Hashable, Codable, PromptRepresentable { } private static let largeChangeThreshold = 400 - private static let largeDiffLineThreshold = 200 private var diffIsLarge: Bool { + // Only consider actual changes (additions + deletions), not context lines + // This prevents --function-context from falsely marking small changes as "large" additions + deletions >= Self.largeChangeThreshold - || diffLineCount >= Self.largeDiffLineThreshold } private var shouldRenderSnippet: Bool { diff --git a/Sources/SwiftCommitGen/Core/LLMClient.swift b/Sources/SwiftCommitGen/Core/LLMClient.swift index 0454a7f..fba7243 100644 --- a/Sources/SwiftCommitGen/Core/LLMClient.swift +++ b/Sources/SwiftCommitGen/Core/LLMClient.swift @@ -13,18 +13,16 @@ struct OverviewGenerationResult: Sendable { var diagnostics: PromptDiagnostics } -@Generable(description: "A commit for changes made in a git repository.") +@Generable(description: "A git commit message with subject and optional body.") /// Model representation for the subject/body pair returned by the language model. struct CommitDraft: Hashable, Codable, Sendable { @Guide( - description: - "The title of a commit. It should be no longer than 50 characters and should summarize the contents of the changeset for other developers reading the commit history. It should describe WHAT was changed." + description: "Subject line (max 50 chars). Imperative mood: 'Add X' not 'Added X'. Describe WHAT changed." ) var subject: String @Guide( - description: - "A detailed description of the the purposes of the changes. It should describe WHY the changes were made." + description: "Optional body explaining WHY the change was made. Omit if subject is clear enough." ) var body: String? @@ -103,8 +101,8 @@ struct FoundationModelsClient: LLMClient { init( generationOptions: GenerationOptions = GenerationOptions( sampling: nil, - temperature: 0.3, - maximumResponseTokens: 512 + temperature: 0.4, + maximumResponseTokens: 256 ), configuration: Configuration = Configuration(), modelProvider: @escaping () -> SystemLanguageModel = { SystemLanguageModel.default } diff --git a/Sources/SwiftCommitGen/Core/OverviewPromptBuilder.swift b/Sources/SwiftCommitGen/Core/OverviewPromptBuilder.swift index 516e80f..7f2a3ba 100644 --- a/Sources/SwiftCommitGen/Core/OverviewPromptBuilder.swift +++ b/Sources/SwiftCommitGen/Core/OverviewPromptBuilder.swift @@ -2,24 +2,17 @@ import Foundation import FoundationModels /// LLM output structure for the overview pass. -@Generable(description: "A high-level overview of a large changeset.") +@Generable(description: "High-level overview of a large changeset.") struct ChangesetOverview: Hashable, Codable, Sendable { - @Guide( - description: - "A concise summary (2-3 sentences) describing the overall purpose and scope of the changes." - ) + @Guide(description: "2-3 sentence summary of the overall purpose of the changes.") var summary: String @Guide( - description: - "The primary category of this changeset: feature, bugfix, refactor, test, docs, or chore." + description: "Category: feature, bugfix, refactor, test, docs, or chore." ) var category: String - @Guide( - description: - "List of the most important files that are central to understanding the changeset (up to 5 paths)." - ) + @Guide(description: "1-5 most important file paths for understanding the change.") var keyFiles: [String] init(summary: String = "", category: String = "", keyFiles: [String] = []) { diff --git a/Sources/SwiftCommitGen/Core/PromptBuilder.swift b/Sources/SwiftCommitGen/Core/PromptBuilder.swift index 40c3fc8..d311032 100644 --- a/Sources/SwiftCommitGen/Core/PromptBuilder.swift +++ b/Sources/SwiftCommitGen/Core/PromptBuilder.swift @@ -183,8 +183,8 @@ struct DefaultPromptBuilder: PromptBuilder { init( maxFiles: Int = 12, - maxSnippetLines: Int = 25, - maxPromptLineEstimate: Int = 400, + maxSnippetLines: Int = 50, + maxPromptLineEstimate: Int = 600, minFiles: Int = 3, minSnippetLines: Int = 6, snippetReductionStep: Int = 4, @@ -295,19 +295,12 @@ struct DefaultPromptBuilder: PromptBuilder { private func buildSystemPrompt(style: CommitGenOptions.PromptStyle) -> Instructions { Instructions { """ - You're an AI assistant whose job is to concisely summarize code changes into short, useful commit messages, with a title and a description. - A changeset is given in the git diff output format, affecting one or multiple files. + Write a git commit message for the code changes shown. - The commit title should be no longer than 50 characters and should summarize the contents of the changeset for other developers reading the commit history. - The commit description can be longer, and should provide more context about the changeset, including why the changeset is being made, and any other relevant information. - The commit description is optional, so you can omit it if the changeset is small enough that it can be described in the commit title or if you don't have enough context. + Subject: max 50 chars, imperative mood ("Add X" not "Added X"), describe WHAT changed. + Body: optional, explain WHY if helpful. - Be brief and concise. - - Do NOT include a description of changes in "lock" files from dependency managers like npm, yarn, or pip (and others), unless those are the only changes in the commit. - - When more explanation is helpful, provide a short body with full sentences. - Leave the body empty when the subject already captures the change or the context is unclear. + Read the diff carefully. Lines with + are additions, - are deletions. """ "" style.styleGuidance