open-swe/agent/tools/list_review_findings.py
Adam Moussa 62d9945df4
refactor: consolidate reviewer modules into agent/review/
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).
2026-07-17 13:52:03 -04:00

70 lines
2.3 KiB
Python

"""Tool: ``list_review_findings``. Read the published review's findings.
The PR chat agent runs on its own thread; the findings live on the canonical
reviewer thread for the PR. The reviewer thread id is seeded into the run config
by the dashboard chat proxy.
"""
from __future__ import annotations
from typing import Any
from langgraph.config import get_config
from ..review.findings import list_findings as list_findings_async
_COMPACT_FIELDS = (
"id",
"severity",
"confidence",
"category",
"title",
"description",
"suggestion",
"file",
"start_line",
"end_line",
"side",
"status",
"resolution_note",
)
def _compact(finding: dict[str, Any]) -> dict[str, Any]:
return {key: finding.get(key) for key in _COMPACT_FIELDS if finding.get(key) is not None}
async def list_review_findings(status_filter: str | None = None) -> dict[str, Any]:
"""List the findings the reviewer published for this PR.
Use this to ground answers about the review — what was flagged, the
severity/confidence, and any resolution notes. Prefer quoting these over
re-deriving issues from the diff.
Args:
status_filter: One of ``open``, ``resolved``, ``dismissed``. ``None``
(default) returns findings of every status.
Returns:
``{findings, count}``; ``{findings: [], count: 0, error}`` on failure.
"""
if status_filter is not None and status_filter not in {"open", "resolved", "dismissed"}:
return {"findings": [], "count": 0, "error": f"Invalid status_filter: {status_filter}"}
config = get_config()
configurable = config.get("configurable", {}) if isinstance(config, dict) else {}
reviewer_thread_id = (
configurable.get("reviewer_thread_id") if isinstance(configurable, dict) else None
)
if not isinstance(reviewer_thread_id, str) or not reviewer_thread_id:
return {"findings": [], "count": 0, "error": "reviewer thread unavailable"}
try:
findings = await list_findings_async(reviewer_thread_id)
except Exception as exc: # noqa: BLE001
return {"findings": [], "count": 0, "error": f"could not load findings: {exc!s}"}
if status_filter is not None:
findings = [f for f in findings if f.get("status") == status_filter]
compact = [_compact(f) for f in findings]
return {"findings": compact, "count": len(compact)}