This commit is contained in:
Jon Michael Aanes 2025-04-21 10:21:24 +02:00
parent d196155bf7
commit 727b788d01

View File

@ -149,20 +149,9 @@ AIDER_LINT = bash_cmd(
) )
LLM_MESSAGE_FORMAT = """ LLM_MESSAGE_FORMAT = """/code {issue}"""
{issue}
# Solution Details
For code tasks:
1. Create a plan for how to solve the issue.
2. Write unit tests that proves that your solution works.
3. Then, solve the issue by writing the required code.
"""
MODEL = None
MODEL = 'ollama/gemma3:27b'
def create_aider_command(issue: str) -> list[str]: def create_aider_command(issue: str) -> list[str]:
l = [ l = [
@ -171,6 +160,7 @@ def create_aider_command(issue: str) -> list[str]:
'english', 'english',
'--no-stream', '--no-stream',
'--no-analytics', '--no-analytics',
'--no-check-update',
'--test-cmd', '--test-cmd',
AIDER_TEST, AIDER_TEST,
'--lint-cmd', '--lint-cmd',
@ -309,7 +299,7 @@ SKIP_AIDER = False
def solve_issue_in_repository( def solve_issue_in_repository(
repository_config: RepositoryConfig, repository_config: RepositoryConfig,
tmpdirname: Path, repository_path: Path,
branch_name: str, branch_name: str,
issue_title: str, issue_title: str,
issue_description: str, issue_description: str,
@ -319,32 +309,31 @@ def solve_issue_in_repository(
logger.info('### %s #####', issue_title) logger.info('### %s #####', issue_title)
# Setup repository # Setup repository
run_cmd(['git', 'clone', repository_config.repo_url(), tmpdirname]) run_cmd(['git', 'clone', repository_config.repo_url(), repository_path])
run_cmd(['bash', '-c', AIDER_TEST], tmpdirname) run_cmd(['bash', '-c', AIDER_TEST], repository_path)
run_cmd(['git', 'checkout', repository_config.base_branch], tmpdirname) run_cmd(['git', 'checkout', repository_config.base_branch], repository_path)
run_cmd(['git', 'checkout', '-b', branch_name], tmpdirname) run_cmd(['git', 'checkout', branch_name], repository_path)
# Run initial ruff pass before aider # Run initial ruff pass before aider
run_cmd(['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX], tmpdirname, check=False) run_cmd(['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX], repository_path, check=False)
run_cmd(['git', 'add', '.'], tmpdirname) run_cmd(['git', 'add', '.'], repository_path)
run_cmd(['git', 'commit', '-m', 'Initial ruff pass'], tmpdirname, check=False) run_cmd(['git', 'commit', '-m', 'Initial ruff pass'], repository_path, check=False)
# Save the commit hash after ruff but before aider # Save the commit hash after ruff but before aider
result = subprocess.run( pre_aider_commit = subprocess.run(
['git', 'rev-parse', 'HEAD'], ['git', 'rev-parse', 'HEAD'],
check=True, check=True,
cwd=tmpdirname, cwd=repository_path,
capture_output=True, capture_output=True,
text=True, text=True,
) ).stdout.strip()
pre_aider_commit = result.stdout.strip()
# Run aider # Run aider
issue_content = f'# {issue_title}\n{issue_description}' issue_content = f'# {issue_title}\n{issue_description}'
if not SKIP_AIDER: if not SKIP_AIDER:
succeeded = run_cmd( succeeded = run_cmd(
create_aider_command(issue_content), create_aider_command(issue_content),
tmpdirname, repository_path,
check=False, check=False,
) )
else: else:
@ -355,21 +344,12 @@ def solve_issue_in_repository(
return IssueResolution(False) return IssueResolution(False)
# Auto-fix standard code quality stuff after aider # Auto-fix standard code quality stuff after aider
run_cmd(['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX], tmpdirname, check=False) run_cmd(['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX], repository_path, check=False)
run_cmd(['git', 'add', '.'], tmpdirname) run_cmd(['git', 'add', '.'], repository_path)
run_cmd(['git', 'commit', '-m', 'Ruff after aider'], tmpdirname, check=False) run_cmd(['git', 'commit', '-m', 'Ruff after aider'], repository_path, check=False)
# Check if aider made any changes beyond the initial ruff pass # Check if aider made any changes beyond the initial ruff pass
result = subprocess.run( if not has_commits_on_branch(repository_path, repository_config.base_branch, branch_name) and not SKIP_AIDER:
['git', 'diff', pre_aider_commit, 'HEAD', '--name-only'],
check=True,
cwd=tmpdirname,
capture_output=True,
text=True,
)
files_changed = result.stdout.strip()
if not files_changed and not SKIP_AIDER:
logger.info( logger.info(
'Aider did not make any changes beyond the initial ruff pass for issue #%s', 'Aider did not make any changes beyond the initial ruff pass for issue #%s',
issue_number, issue_number,
@ -379,7 +359,7 @@ def solve_issue_in_repository(
# Push changes # Push changes
return push_changes( return push_changes(
repository_config, repository_config,
tmpdirname, repository_path,
branch_name, branch_name,
issue_number, issue_number,
issue_title, issue_title,
@ -417,10 +397,10 @@ def solve_issues_in_repository(
continue continue
branch_name = generate_branch_name(issue_number, title) branch_name = generate_branch_name(issue_number, title)
with tempfile.TemporaryDirectory() as tmpdirname: with tempfile.TemporaryDirectory() as repository_path:
issue_resolution = solve_issue_in_repository( issue_resolution = solve_issue_in_repository(
repository_config, repository_config,
Path(tmpdirname), Path(repository_path),
branch_name, branch_name,
title, title,
issue_description, issue_description,