Compare commits

..

No commits in common. "948ab5a3826dc827c554bb119172eabf07b8c67e" and "d10218f0c8c14e238f43c28e4e0e57693088a9c6" have entirely different histories.

2 changed files with 31 additions and 55 deletions

View File

@ -149,15 +149,12 @@ AIDER_LINT = bash_cmd(
) )
LLM_MESSAGE_FORMAT = ( LLM_MESSAGE_FORMAT = """{issue}\nDo not wait for explicit approval before working on code changes."""
"""{issue}\nDo not wait for explicit approval before working on code changes."""
)
# CODE_MODEL = 'ollama/gemma3:4b' #CODE_MODEL = 'ollama/gemma3:4b'
CODE_MODEL = 'o3' CODE_MODEL = 'o3'
EVALUATOR_MODEL = 'ollama/gemma3:27b' EVALUATOR_MODEL = 'ollama/gemma3:27b'
def create_aider_command(issue: str) -> list[str]: def create_aider_command(issue: str) -> list[str]:
l = [ l = [
'aider', 'aider',
@ -238,6 +235,7 @@ def get_diff(cwd: Path, base_branch: str, current_branch: str) -> str:
return result.stdout.strip() return result.stdout.strip()
def push_changes( def push_changes(
repository_config: RepositoryConfig, repository_config: RepositoryConfig,
cwd: Path, cwd: Path,
@ -253,9 +251,7 @@ def push_changes(
# Get commit messages for PR description # Get commit messages for PR description
commit_messages = get_commit_messages( commit_messages = get_commit_messages(
cwd, cwd, repository_config.base_branch, branch_name,
repository_config.base_branch,
branch_name,
) )
description = f'This pull request resolves #{issue_number}\n\n' description = f'This pull request resolves #{issue_number}\n\n'
@ -281,9 +277,7 @@ def push_changes(
# Extract PR number and URL if available # Extract PR number and URL if available
return IssueResolution( return IssueResolution(
True, True, str(pr_response.get('number')), pr_response.get('html_url'),
str(pr_response.get('number')),
pr_response.get('html_url'),
) )
@ -320,7 +314,6 @@ def run_cmd(cmd: list[str], cwd: Path | None = None, check=True) -> bool:
result = subprocess.run(cmd, check=check, cwd=cwd) result = subprocess.run(cmd, check=check, cwd=cwd)
return result.returncode == 0 return result.returncode == 0
def issue_solution_round(repository_path, issue_content): def issue_solution_round(repository_path, issue_content):
# Primary Aider command # Primary Aider command
aider_command = create_aider_command(issue_content) aider_command = create_aider_command(issue_content)
@ -340,7 +333,6 @@ def issue_solution_round(repository_path, issue_content):
return True return True
def run_ollama(cwd: Path, texts: list[str]) -> str: def run_ollama(cwd: Path, texts: list[str]) -> str:
cmd = ['ollama', 'run', EVALUATOR_MODEL.removeprefix('ollama/')] cmd = ['ollama', 'run', EVALUATOR_MODEL.removeprefix('ollama/')]
print(cmd) print(cmd)
@ -356,7 +348,6 @@ def run_ollama(cwd: Path, texts: list[str]) -> str:
print(stdout) print(stdout)
return stdout return stdout
def parse_yes_no_answer(text: str) -> bool | None: def parse_yes_no_answer(text: str) -> bool | None:
text = text.lower().strip() text = text.lower().strip()
words = text.split('\n \t.,?-') words = text.split('\n \t.,?-')
@ -367,7 +358,6 @@ def parse_yes_no_answer(text: str) -> bool | None:
return False return False
return None return None
def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool: def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
texts = list(initial_texts) texts = list(initial_texts)
texts.append('Think through your answer.') texts.append('Think through your answer.')
@ -380,27 +370,21 @@ def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
texts.append(response) texts.append(response)
texts.append('Please answer either "yes" or "no".') texts.append('Please answer either "yes" or "no".')
def verify_solution(repository_path: Path, issue_content: str) -> bool: def verify_solution(repository_path: Path, issue_content: str) -> bool:
summary = run_ollama( summary = run_ollama(
repository_path, repository_path,
[ ['Concisely summarize following changeset',
'Concisely summarize following changeset', get_diff(repository_path, 'HEAD', 'main')
get_diff(repository_path, 'HEAD', 'main'), ])
],
)
return run_ollama_and_get_yes_or_no( return run_ollama_and_get_yes_or_no(
repository_path, repository_path,
[ ['Does this changeset accomplish the entire task?',
'Does this changeset accomplish the entire task?',
'# Change set', '# Change set',
summary, summary,
'# Issue', '# Issue',
issue_content, issue_content,
], ])
)
def get_head_commit_hash(repository_path: Path) -> str: def get_head_commit_hash(repository_path: Path) -> str:
return subprocess.run( return subprocess.run(
@ -455,8 +439,12 @@ def solve_issue_in_repository(
) )
return IssueResolution(False) return IssueResolution(False)
# Push changes and create/update the pull request on every iteration # Verify whether this is a satisfactory solution
resolution = push_changes( if verify_solution(repository_path, issue_content):
break
# Push changes
return push_changes(
repository_config, repository_config,
repository_path, repository_path,
branch_name, branch_name,
@ -464,18 +452,10 @@ def solve_issue_in_repository(
issue_title, issue_title,
gitea_client, gitea_client,
) )
if not resolution.success:
return resolution
# Verify whether this is a satisfactory solution
if verify_solution(repository_path, issue_content):
return resolution
def solve_issues_in_repository( def solve_issues_in_repository(
repository_config: RepositoryConfig, repository_config: RepositoryConfig, client, seen_issues_db,
client,
seen_issues_db,
): ):
"""Process all open issues with the 'aider' label. """Process all open issues with the 'aider' label.

View File

@ -23,9 +23,7 @@ class TestHasCommitsOnBranch:
# Verify get_commit_messages was called with correct arguments # Verify get_commit_messages was called with correct arguments
mock_get_commit_messages.assert_called_once_with( mock_get_commit_messages.assert_called_once_with(
self.cwd, self.cwd, self.base_branch, self.current_branch,
self.base_branch,
self.current_branch,
) )
@patch('aider_gitea.get_commit_messages') @patch('aider_gitea.get_commit_messages')
@ -41,9 +39,7 @@ class TestHasCommitsOnBranch:
# Verify get_commit_messages was called with correct arguments # Verify get_commit_messages was called with correct arguments
mock_get_commit_messages.assert_called_once_with( mock_get_commit_messages.assert_called_once_with(
self.cwd, self.cwd, self.base_branch, self.current_branch,
self.base_branch,
self.current_branch,
) )
@patch('aider_gitea.get_commit_messages') @patch('aider_gitea.get_commit_messages')