refactor(review): always render usage; drop report_usage flag

This commit is contained in:
claude
2026-08-22 01:18:34 +00:00
parent e1b74d982d
commit 86352a3771
3 changed files with 53 additions and 37 deletions
+6 -11
View File
@@ -16,7 +16,6 @@ Service pragent-webhook.pragent.svc.cluster.local (ClusterIP, ns pragent)
│ → gate: action ≠ closed AND pull_request.labels ∋ AI-REVIEW
│ → claim (repo, index, sha) in-flight (closes the dedupe race)
│ → bounded worker (PRAGENT_MAX_CONCURRENT_REVIEWS, default 2)
│ (report_usage ← pull_request.labels ∋ AI-USAGE, optional)
ai_review.review_pr() (same core the CI-step uses)
1. fetch existing reviews → dedupe: skip if a review already carries
@@ -67,10 +66,10 @@ No workflow file, no repo secret, no act-runner needed. (The owner must already
be covered by a user-level webhook — see below. If not, do the one-time
per-owner setup first.)
## AI-USAGE label — token-usage reporting (optional, opt-in)
## Token-usage reporting (always on)
A review always fires on `AI-REVIEW`. Adding a second label **`AI-USAGE`** on
the same PR opts the review into appending a token-usage report:
Every opencode review now appends a token-usage report — no label, no env var
needed:
- a `## 🔋 AI usage` section on the review summary body with the **measured**
review total — input / output / reasoning / cache read+write / total tokens,
@@ -88,12 +87,8 @@ rendered-body weight (`len(problem)+len(fix)+len(suggestion)`) — an honest
attribution, labelled as such. The totals are real measurements summed from
opencode's `step_finish` events.
`PRAGENT_USAGE_ALWAYS=1` on the Deployment forces usage reporting on for every
review (testing / a future default-on) regardless of the label.
Without `AI-USAGE` (regression): no usage section, no 🪙 lines — behaviour
identical to before the feature. The usage section is part of the review body,
so it's covered by the existing sha-marker dedupe.
No-op on the ollama fallback (no usage available). The usage section is part
of the review body, so it's covered by the existing sha-marker dedupe.
## Repo-provided static context (`ADDITIONAL_CONTEXT_URL`)
@@ -483,7 +478,7 @@ cramped model call. `pilot/opencode_review.py` is the glue:
It does **no Gitea I/O and no parsing** — `review_pr` parses the stdout into
`(summary, findings)`, validates findings against diff anchors, and posts. So
all v2 logic (dedupe marker, anchor validation, language-tagged suggestion
fencing, posting, optional AI-USAGE attribution) is reused and never depends on
fencing, posting, token-usage attribution) is reused and never depends on
the model remembering it.
The factory lives in the pragent repo root: `opencode.json` (provider/model/