-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Parent
Part of #204 (Phase 4: Hardening)
Problem
When using the pr merge strategy, PRs created by the refinery receive human review comments. Nobody addresses them. The PR sits with unresolved threads until someone manually intervenes. The refinery currently only polls for merge/close status �¢ it doesn't detect or act on review comments.
Solution
Extend the PR polling loop to detect new review comments and dispatch agents to address them in batches. The agent reads all unresolved comments, fixes the code or replies explaining why no change is needed, pushes updates, and resolves each thread.
Flow
- TownDO alarm polls open PRs (already exists in
pollPendingPRs()). Extend to also fetch review comments via the GitHub/GitLab API. - New unresolved comments detected �¢ create a
pr_reviewbead (or sub-bead of the MR bead) with the comment context. - Agent dispatched �¢ a polecat (or the refinery, since it already has the review context) gets a focused prompt with all pending comments.
- Agent processes each comment:
- If relevant: fix the code, push, reply with how it was fixed, resolve the thread
- If not relevant: reply explaining why, resolve the thread
- If architectural/out-of-scope: reply acknowledging, escalate to Mayor
- Thread resolution is critical �¢ resolve the full thread, not just reply to the base comment. GitHub's GraphQL
resolveReviewThreadmutation handles this.
Agent prompt template
You are addressing review feedback on PR #42 for bead "Fix token refresh".
Unresolved review comments:
1. @sarah on src/auth.ts:15-20:
"This function doesn't handle the case where the token is expired
but the refresh endpoint is down. We should return a 503 here."
2. @mike on src/auth.ts:47:
"nit: prefer const over let"
For each comment:
- If it's a valid code fix: make the change, push, reply explaining what you did, resolve the thread
- If it's a question: reply with an explanation, resolve the thread
- If it's not relevant or already addressed: reply explaining why, resolve the thread
- If it's an architectural concern beyond your scope: reply acknowledging it, and escalate
Always resolve the full thread (not just the comment) after addressing it.
Platform API calls
GitHub:
GET /repos/{owner}/{repo}/pulls/{number}/comments�¢ list review commentsPOST /repos/{owner}/{repo}/pulls/{number}/comments/{id}/replies�¢ reply- GraphQL
resolveReviewThread(input: { threadId })�¢ resolve thread
GitLab:
GET /projects/{id}/merge_requests/{iid}/discussions�¢ list discussionsPOST /projects/{id}/merge_requests/{iid}/discussions/{discussion_id}/notes�¢ replyPUT /projects/{id}/merge_requests/{iid}/discussions/{discussion_id}?resolved=true�¢ resolve
New tools needed
The agent needs platform-specific tools (or the existing gh / glab CLIs installed in the container):
| Tool | Purpose |
|---|---|
gh pr view --comments / API call |
Fetch unresolved comments |
gh pr comment --reply-to / API call |
Reply to a thread |
| GraphQL mutation / API call | Resolve thread |
Alternatively, add a gt_pr_comment_resolve tool to the plugin that handles the API calls server-side via the TownDO (using the rig's integration token).
Acceptance Criteria
- PR polling detects new unresolved review comments
- Agent dispatched to address comment batches
- Agent fixes code issues, pushes changes, replies to threads
- Agent resolves full threads (not just base comments) after addressing
- Non-relevant comments get explanatory replies and are resolved
- Out-of-scope concerns are escalated to the Mayor
- Works with both GitHub and GitLab integrations
- Comment resolution tracked as bead events
Notes
- No data migration needed
- The
platform-pr.util.tsfrom Configurable merge strategy: direct push vs pull request #473 already hasparseGitUrl(), GitHub/GitLab auth patterns, and Zod response parsing Ã�¢ comment fetching/replying are natural extensions pollPendingPRs()already iterates open PRs on every alarm tick Ã�¢ adding comment detection is an additional API call per open PR- This was originally described in Cloud Gastown: Future ideas — capabilities unique to or enhanced by the cloud model #447 (Future Ideas: "Automated PR Review Response") Ã�¢ this issue promotes it to a concrete Phase 4 deliverable
- Rate limiting: don't dispatch an agent for every single comment. Batch all unresolved comments on a PR into one agent session.