mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 06:53:14 +00:00
Part of the domain-reorg adoption (build plan step C2): fork content,
upstream layout. Nine 1:1 module moves (reviewer_diff/eval_store/
findings/groups/publish/reconcile/trace_context + review_style_
collector/guidance) into agent/review/, with internal relative
imports re-wired to the new package depth. agent/review/__init__.py
mirrors upstream's thin re-export shim (one of the 21 verified "A"
structural adds).
Rewrote the 38 grep hits across importer files (agent/{analyzer,
ci_autofix,reviewer,webapp}.py, agent/dashboard/*, agent/middleware/
settle_review_check.py, agent/tools/*, agent/utils/github_feedback.py,
agent/webhooks/github.py, evals/reviewer/*, and the reviewer test
suite) to point at agent.review.*; 4 of the 38 hits were name
collisions (list_reviewer_findings, reviewer_outcomes,
_reviewer_thread_id, reviewer_thread_id — not the moved modules) and
were left untouched. tests/test_github_checks.py's module-alias
import (`from agent import reviewer_publish`) follows upstream's own
`from agent.review import publish as reviewer_publish` pattern so
downstream `reviewer_publish.*` call sites needed no changes.
agent/reviewer.py and agent/webapp.py stay in place per the hard
rule (fork content, import-only rewire) and are not part of this
package.
Gates: ruff check + ruff format --check, pytest --co -q (1637
collected), full unit suite (1637 passed), and the reviewer/findings
suite in isolation (pytest -k "review or finding", 421 passed).
98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from langgraph.config import get_config
|
|
|
|
from ..review.findings import (
|
|
FindingInteraction,
|
|
ReviewerThreadMissingError,
|
|
append_finding_interaction,
|
|
get_finding,
|
|
get_thread_id_from_runtime,
|
|
thread_missing_tool_result,
|
|
update_finding_fields,
|
|
)
|
|
from ..review.publish import reply_to_review_comment
|
|
from ..utils.github_token import get_github_token
|
|
|
|
|
|
async def reply_to_finding_thread(finding_id: str, body: str) -> dict[str, Any]:
|
|
"""Reply to the GitHub review thread for a tracked finding."""
|
|
if not body.strip():
|
|
return {"success": False, "error": "Reply body is required"}
|
|
|
|
config = get_config()
|
|
configurable = config.get("configurable", {}) if isinstance(config, dict) else {}
|
|
repo_config = configurable.get("repo") if isinstance(configurable, dict) else None
|
|
pr_number = configurable.get("pr_number") if isinstance(configurable, dict) else None
|
|
if (
|
|
not isinstance(repo_config, dict)
|
|
or not repo_config.get("owner")
|
|
or not repo_config.get("name")
|
|
or not isinstance(pr_number, int)
|
|
):
|
|
return {"success": False, "error": "Missing repo or PR info in run config"}
|
|
|
|
token = get_github_token()
|
|
if not token:
|
|
return {"success": False, "error": "No GitHub token available"}
|
|
|
|
try:
|
|
return await _reply_to_finding_thread_async(
|
|
finding_id=finding_id,
|
|
body=body,
|
|
owner=str(repo_config["owner"]),
|
|
repo=str(repo_config["name"]),
|
|
pr_number=pr_number,
|
|
token=token,
|
|
)
|
|
except ReviewerThreadMissingError as exc:
|
|
return thread_missing_tool_result(exc)
|
|
|
|
|
|
async def _reply_to_finding_thread_async(
|
|
*,
|
|
finding_id: str,
|
|
body: str,
|
|
owner: str,
|
|
repo: str,
|
|
pr_number: int,
|
|
token: str,
|
|
) -> dict[str, Any]:
|
|
thread_id = get_thread_id_from_runtime()
|
|
finding = await get_finding(thread_id, finding_id)
|
|
if finding is None:
|
|
return {"success": False, "error": f"No finding found with id {finding_id}"}
|
|
|
|
comment_id = finding.get("github_review_comment_id")
|
|
if not isinstance(comment_id, int):
|
|
return {"success": False, "error": "Finding has no GitHub review comment mapping"}
|
|
|
|
response = await reply_to_review_comment(
|
|
owner=owner,
|
|
repo=repo,
|
|
pr_number=pr_number,
|
|
review_comment_id=comment_id,
|
|
body=body.strip(),
|
|
token=token,
|
|
)
|
|
if response is None:
|
|
return {"success": False, "error": "GitHub did not accept the reply"}
|
|
|
|
reply_id = response.get("id")
|
|
updates: dict[str, Any] = {"last_reconciliation_note": "Replied to GitHub review thread."}
|
|
if isinstance(reply_id, int):
|
|
updates["last_review_reply_comment_id"] = reply_id
|
|
updated = await update_finding_fields(thread_id, finding_id, updates)
|
|
interaction: FindingInteraction = {
|
|
"kind": "bot_reply",
|
|
"github_comment_id": reply_id if isinstance(reply_id, int) else None,
|
|
"github_parent_comment_id": comment_id,
|
|
"author": "seahaven-openswe[bot]",
|
|
"body": body.strip(),
|
|
"created_at": "",
|
|
"needs_reassessment": False,
|
|
}
|
|
updated = await append_finding_interaction(thread_id, finding_id, interaction)
|
|
return {"success": True, "finding": updated, "reply_id": reply_id}
|