feat(agent): tighten prompt to bound beyond-diff reads + de-generalize cost-model labels

Three changes from operator feedback:

1. Per-comment � attribution restored on inline comments (operator wants
   it back — the PR-level collapsible is collapsed by default, so the
   attribution is the visible signal of per-finding cost share).
   Hidden only when no _tok_attrib was computed (legacy callers / ollama
   path without usage metering).

2. Agent prompt now bounds reads beyond the diff — the single biggest
   driver of input-token bloat on long agent loops:
     * ≤ 5 file reads beyond the diff for the entire review
     * ≤ 80 lines per read (use --offset + --limit)
     * ≤ 3 grep calls beyond the diff (prefer rtk grep)
     * no re-reads of files already seen
     * no directory walks (ls -R, find .)
     * honor .pr-review.json:exclude_paths

3. De-generalize cost_model calibration labels. The OBSERVED_RUNS list
   referred to `gitea_admin/pragent#7` — a real internal repo path that
   blocks commercialization. Replaced with `internal/hardening-PR (16
   files, 1020 insertions / 91 deletions)`. The numbers (input/output
   tokens, steps, duration) are unchanged — only the labels are
   generic.

Tests:
  * test_inline_comment_body_with_attribution_line — asserts 🪙 line
    shows when _tok_attrib is set
  * test_inline_comment_body_no_attribution_no_coin_line — still
    verifies the line is hidden when no attribution data
  * test_observed_report_prices_every_model — asserts no internal
    repo name appears in the rendered report
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Marcos
2026-08-20 17:35:06 +00:00
parent f6be2b3c61
commit 998f793ec2
5 changed files with 48 additions and 25 deletions
+8 -2
View File
@@ -1002,8 +1002,10 @@ def inline_comment_body(f: dict) -> str:
produced replacement code. Language-tagged fences are reserved for
cross-file patterns the suggestion block can't carry.
* Reference as a Markdown hyperlink (``[label](url)``) — never a raw URL.
* No per-comment token attribution: the PR-level collapsible carries
all telemetry; inline comments stay focused on the code.
* Per-comment attributed output tokens (`🪙 ~N tok (P% · attributed)`)
when the caller passed `compute_attribution` data. Hidden when the
finding has no attributed tokens (e.g. legacy callers / ollama path
without usage metering).
"""
badge = _severity_badge(f.get("severity", "medium"))
body = f"{badge} {f.get('problem', '').strip()}"
@@ -1019,6 +1021,10 @@ def inline_comment_body(f: dict) -> str:
ref_md = _format_reference(f.get("reference", ""))
if ref_md:
body += f"\n\n🔗 **Reference:** {ref_md}"
tok = f.get("_tok_attrib")
if tok is not None:
pct = (f.get("_tok_pct", 0.0) or 0.0) * 100
body += f"\n\n🪙 ~{tok} tok ({pct:.0f}% · attributed output)"
return body
+2 -2
View File
@@ -176,7 +176,7 @@ DEFAULT_TIERS = [
# from a guess, and the first entry corrected the tier assumptions by ~15x.
OBSERVED_RUNS: list[dict] = [
{
"label": "gitea_admin/pragent#7 (the hardening PR)",
"label": "internal/hardening-PR (16 files, 1020 insertions / 91 deletions)",
"date": "2026-08-18",
"tier": "full",
"diff_tokens": 17_600, # 16 files, 1020 insertions / 91 deletions
@@ -189,7 +189,7 @@ OBSERVED_RUNS: list[dict] = [
"subagents": 0,
},
{
"label": "gitea_admin/pragent#7 (+ cost-model calibration + salvage fix)",
"label": "internal/hardening-PR (same PR, two commits later)",
"date": "2026-08-18",
"tier": "full",
"diff_tokens": 21_000, # same PR, two commits later