refactor: raise error on auth failure and clean up meeks-ai fallback
This commit is contained in:
@@ -5,7 +5,7 @@ You are an autonomous AI Software Engineer working on the `meeks` organization's
|
||||
|
||||
### 🎯 SCOPE & BOUNDARIES
|
||||
- **Organization**: You ONLY work on repositories under the `meeks` organization (e.g., `meeks/ai-electronbun-todo-app`).
|
||||
- **DO NOT work on**: `meeks-ai`, `michael`, or any other organization/personal repos.
|
||||
- **DO NOT work on**: any other organization/personal repos.
|
||||
- **DO NOT create new repositories**. The repo already exists. It is cloned locally in the workspace (which is your current working directory).
|
||||
- **DO NOT edit `.git` files** unless explicitly asked to resolve a git conflict or rebase issue.
|
||||
|
||||
|
||||
+24
-14
@@ -22,7 +22,6 @@ from gitea.models import CommentModel, PullRequestFileModel, PullRequestModel, I
|
||||
|
||||
logger: logging.Logger = logging.getLogger("agent-dispatcher")
|
||||
|
||||
AGENT_USERNAMES: frozenset[str] = frozenset({"meeks-ai", "agent-bot"})
|
||||
|
||||
CLOSE_KEYWORDS_PATTERN: re.Pattern[str] = re.compile(
|
||||
rf"\b(?:close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s+#(\d+)\b",
|
||||
@@ -58,7 +57,7 @@ def _find_issues_for_pr_helper(pr_body: str) -> list[int]:
|
||||
return list(set(int(m) for m in matches))
|
||||
|
||||
|
||||
def _is_awaiting_reply_helper(comments: list[CommentModel]) -> bool:
|
||||
def _is_awaiting_reply_helper(comments: list[CommentModel], ai_username: str) -> bool:
|
||||
"""Return True if the agent's most recent comment contains the
|
||||
awaiting-reply marker AND no human has commented after it.
|
||||
"""
|
||||
@@ -66,8 +65,9 @@ def _is_awaiting_reply_helper(comments: list[CommentModel]) -> bool:
|
||||
return False
|
||||
# Find the last agent comment index
|
||||
last_agent_idx: int = -1
|
||||
agent_usernames = {ai_username, "agent-bot"}
|
||||
for i, c in enumerate(comments):
|
||||
if c.user and c.user.login in AGENT_USERNAMES:
|
||||
if c.user and c.user.login in agent_usernames:
|
||||
last_agent_idx = i
|
||||
if last_agent_idx == -1:
|
||||
return False
|
||||
@@ -78,7 +78,7 @@ def _is_awaiting_reply_helper(comments: list[CommentModel]) -> bool:
|
||||
return False
|
||||
# Check if any human replied AFTER the last agent comment
|
||||
for c in comments[last_agent_idx + 1:]:
|
||||
if c.user and c.user.login not in AGENT_USERNAMES:
|
||||
if c.user and c.user.login not in agent_usernames:
|
||||
return False # Human replied — we can proceed
|
||||
return True # Agent signalled wait, no human replied yet
|
||||
|
||||
@@ -344,7 +344,7 @@ class PRTaskProcessor(TaskProcessor):
|
||||
pr_comments = self.client.get_pull_request_comments(self.owner, self.repo_name, self.item.task_number)
|
||||
except Exception:
|
||||
pass
|
||||
if _is_awaiting_reply_helper(pr_comments):
|
||||
if _is_awaiting_reply_helper(pr_comments, self.ai_username):
|
||||
logger.info(f"PR #{self.item.task_number}: agent asked a question and is awaiting a human reply. Skipping.")
|
||||
return f"SKIP: Awaiting human reply on PR #{self.item.task_number}."
|
||||
|
||||
@@ -482,7 +482,7 @@ class IssueTaskProcessor(TaskProcessor):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if _is_awaiting_reply_helper(issue_comments) or _is_awaiting_reply_helper(pr_comments):
|
||||
if _is_awaiting_reply_helper(issue_comments, self.ai_username) or _is_awaiting_reply_helper(pr_comments, self.ai_username):
|
||||
logger.info(f"Issue #{self.item.task_number}: awaiting human reply. Skipping.")
|
||||
return f"SKIP: Awaiting human reply on issue #{self.item.task_number} or PR."
|
||||
|
||||
@@ -678,13 +678,14 @@ class AgentDispatcher:
|
||||
|
||||
results: list[str] = []
|
||||
# Get authenticated username for reviewer filter
|
||||
ai_username = "meeks-ai"
|
||||
try:
|
||||
user = self._client.get_authenticated_user()
|
||||
if user:
|
||||
ai_username = user.login
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
raise RuntimeError("No authenticated user found.") from e
|
||||
|
||||
if not user or not user.login:
|
||||
raise RuntimeError("No authenticated user found.")
|
||||
ai_username = user.login
|
||||
|
||||
for item in work_items:
|
||||
processor: TaskProcessor
|
||||
@@ -722,19 +723,25 @@ class AgentDispatcher:
|
||||
return _find_pr_for_issue_helper(self._client, repo_full_name, issue_number)
|
||||
|
||||
def _is_awaiting_reply(self, comments: list[CommentModel]) -> bool:
|
||||
return _is_awaiting_reply_helper(comments)
|
||||
user = self._client.get_authenticated_user()
|
||||
if not user or not user.login:
|
||||
raise RuntimeError("No authenticated user found.")
|
||||
return _is_awaiting_reply_helper(comments, user.login)
|
||||
|
||||
def _build_pr_mission(self, item: WorkItem) -> str:
|
||||
pr_info = item.task_info
|
||||
if not isinstance(pr_info, PullRequestModel):
|
||||
raise TypeError("Expected task_info to be a PullRequestModel")
|
||||
user = self._client.get_authenticated_user()
|
||||
if not user or not user.login:
|
||||
raise RuntimeError("No authenticated user found.")
|
||||
processor = PRTaskProcessor(
|
||||
client=self._client,
|
||||
tools=self._tools,
|
||||
model_name=self._model_name,
|
||||
repo=item.repo_full_name,
|
||||
item=item,
|
||||
ai_username="meeks-ai",
|
||||
ai_username=user.login,
|
||||
)
|
||||
return processor._build_pr_mission(pr_info, is_own_pr=False)
|
||||
|
||||
@@ -742,12 +749,15 @@ class AgentDispatcher:
|
||||
issue_info = item.task_info
|
||||
if not isinstance(issue_info, IssueModel):
|
||||
raise TypeError("Expected task_info to be an IssueModel")
|
||||
user = self._client.get_authenticated_user()
|
||||
if not user or not user.login:
|
||||
raise RuntimeError("No authenticated user found.")
|
||||
processor = IssueTaskProcessor(
|
||||
client=self._client,
|
||||
tools=self._tools,
|
||||
model_name=self._model_name,
|
||||
repo=item.repo_full_name,
|
||||
item=item,
|
||||
ai_username="meeks-ai",
|
||||
ai_username=user.login,
|
||||
)
|
||||
return processor._build_issue_mission(issue_info, "dummy-branch")
|
||||
|
||||
Reference in New Issue
Block a user