feat: Add user language instruction to commit prompt

This commit is contained in:
Paul Gauthier (aider) 2025-05-09 06:17:49 -07:00
parent 81b86441fd
commit 23714d7db6
2 changed files with 15 additions and 3 deletions

View file

@ -13,11 +13,13 @@ Generate a one-line commit message for those changes.
The commit message should be structured as follows: <type>: <description>
Use these for <type>: fix, feat, build, chore, ci, docs, style, refactor, perf, test
Ensure the commit message:
Ensure the commit message:{language_instruction}
- Starts with the appropriate prefix.
- Is in the imperative mood (e.g., \"add feature\" not \"added feature\" or \"adding feature\").
- Does not exceed 72 characters.
Reply only with the one-line commit message, without any additional text, explanations, or line breaks.
Reply only with the one-line commit message, without any additional text, explanations, \
or line breaks.
"""

View file

@ -207,7 +207,12 @@ class GitRepo:
if message:
commit_message = message
else:
commit_message = self.get_commit_message(diffs, context)
user_language = None
if coder:
user_language = coder.get_user_language()
commit_message = self.get_commit_message(diffs, context, user_language)
# Retrieve attribute settings, prioritizing coder.args if available
if coder and hasattr(coder, "args"):
@ -319,7 +324,7 @@ class GitRepo:
except (ValueError, OSError):
return self.repo.git_dir
def get_commit_message(self, diffs, context):
def get_commit_message(self, diffs, context, user_language=None):
diffs = "# Diffs:\n" + diffs
content = ""
@ -328,6 +333,11 @@ class GitRepo:
content += diffs
system_content = self.commit_prompt or prompts.commit_system
language_instruction = ""
if user_language:
language_instruction = f"\n- Is written in {user_language}."
system_content = system_content.format(language_instruction=language_instruction)
messages = [
dict(role="system", content=system_content),
dict(role="user", content=content),