refactor(ai_review): drop AI_REVIEW/AI_USAGE label plumbing

This commit is contained in:
claude
2026-08-22 01:13:59 +00:00
parent 33e4c16782
commit e1b74d982d
2 changed files with 0 additions and 73 deletions
-44
View File
@@ -65,9 +65,6 @@ REVIEW_HEADER = "🤖 **AI Review** · pragent pilot · {model} · `{sha}` · Me
SHA_MARKER = "<!-- pragent:sha={sha} -->"
_SHA_MARKER_RE = re.compile(r"<!-- pragent:sha=([0-9a-f]{7,40}) -->")
AI_REVIEW_LABEL = "AI-REVIEW"
# Opt-in label for the token-usage block. Read at render time — see pr_has_label.
AI_USAGE_LABEL = "AI-USAGE"
SEVERITIES = ("critical", "high", "medium", "low", "trivial", "info")
# Severity rank — higher = more severe. Used by `apply_repo_config` to drop
# findings below `severity_threshold`. critical=4, high=3, medium=2, low=1,
@@ -199,33 +196,6 @@ def parse_text_blocks(content: list) -> str:
return "\n".join(out).strip()
def pr_has_label(api: str, repo: str, index: str, token: str, label: str) -> bool:
"""True if the PR currently carries `label`. False on any failure.
Read at RENDER time, not at review start. A reviewer labels AI-REVIEW and
AI-USAGE seconds apart; the review claims on the first event and the
second is dropped by the in-flight dedupe, so the trigger payload never
sees the opt-in. Re-reading when the review begins is no better — that is
still milliseconds after the first click. Only a read taken once the
review has finished (a minute or more later) reliably sees the label.
"""
try:
code, raw = gitea_get(api, repo, f"issues/{index}/labels", token)
if code >= 300:
return False
data = json.loads(raw.decode() or "[]")
except Exception as e:
print(f"pragent: could not re-read labels for {repo}#{index}: {e}",
file=sys.stderr, flush=True)
return False
if not isinstance(data, list):
return False
return any(
(isinstance(x, dict) and x.get("name") == label) or x == label
for x in data
)
def _int_env(name: str, default: int) -> int:
"""Read an int from the environment, falling back on anything unparseable.
@@ -2139,13 +2109,6 @@ def review_pr(
file=sys.stderr, flush=True,
)
salvaged = salvage_summary(stdout)
# The AI-USAGE opt-in is re-checked HERE, at render time: the label
# is usually applied moments after AI-REVIEW, long after this
# review was claimed and its trigger payload frozen.
if not report_usage:
report_usage = pr_has_label(api, repo, index, token, AI_USAGE_LABEL)
if report_usage and usage and usage.get('output'):
compute_attribution(findings, usage['output'])
usage_section = _render_collapsible_usage(usage, model, config=config) if report_usage else ""
post_review(api, repo, index, token, format_review_body(
salvaged or "AI review produced no parseable output.",
@@ -2195,13 +2158,6 @@ def review_pr(
# for it.
if report_usage and usage and usage.get("output"):
compute_attribution(findings, usage["output"])
# The AI-USAGE opt-in is re-checked HERE, at render time: the label
# is usually applied moments after AI-REVIEW, long after this
# review was claimed and its trigger payload frozen.
if not report_usage:
report_usage = pr_has_label(api, repo, index, token, AI_USAGE_LABEL)
if report_usage and usage and usage.get('output'):
compute_attribution(findings, usage['output'])
usage_section = _render_collapsible_usage(usage, model, config=config) if report_usage else ""
# Anchor against the RAW diff, never the compressed one. Compression