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
+17 -12
View File
@@ -326,15 +326,18 @@ def test_inline_comment_body_severity_emoji_mapping():
assert badge in inline_comment_body(f), f"{sev}{badge}"
def test_inline_comment_body_no_token_attribution():
# Per spec: no per-comment 🪙 token attribution line.
def test_inline_comment_body_with_token_attribution():
# Operator wants per-comment attribution back: every inline comment shows
# the attributed output tokens + share of total. Hidden only when no
# attribution data was computed (legacy callers / ollama path without
# usage metering).
f = {"severity": "high", "path": "a", "line": 1, "problem": "p",
"fix": "f", "suggestion": "", "reference": "",
"_tok_attrib": 1234, "_tok_pct": 0.3}
"_tok_attrib": 1234, "_tok_pct": 0.30}
body = inline_comment_body(f)
assert "🪙" not in body
assert "tok" not in body.lower().split("fix")[0] # only in fix is OK
assert "attributed" not in body
assert "🪙 ~1234 tok" in body
assert "30%" in body
assert "attributed output" in body
def test_summary_bullets_format():
@@ -673,15 +676,17 @@ def test_compute_attribution_noop_on_empty_or_zero_budget():
assert "_tok_attrib" not in fs[0]
def test_inline_comment_body_no_attribution_line():
# Per spec: NO per-comment token attribution — that telemetry lives in the
# collapsible block on the PR-level comment.
def test_inline_comment_body_with_attribution_line():
# Operator wants per-comment attribution back: every inline comment shows
# the attributed output tokens + share of total. Hidden only when no
# attribution data was computed (legacy callers / ollama path without
# usage metering).
f = {"severity": "high", "path": "a", "line": 1, "problem": "bad", "fix": "swap",
"suggestion": "", "_tok_attrib": 180, "_tok_pct": 0.29}
body = inline_comment_body(f)
assert "🪙" not in body
assert "tok" not in body
assert "attributed" not in body
assert "🪙 ~180 tok" in body
assert "29%" in body
assert "attributed output" in body
def test_inline_comment_body_no_attribution_no_coin_line():
+3 -1
View File
@@ -226,7 +226,9 @@ def test_observed_report_prices_every_model():
text = cm.observed_report(["claude-opus-5", "gpt-5.6-luna"])
assert "Claude Opus 5" in text
assert "GPT-5.6 Luna" in text
assert "pragent#7" in text
# Labels are generic (no internal repo names) for commercialization.
assert "gitea_admin" not in text
assert "internal/hardening-PR" in text
def test_model_is_within_an_order_of_magnitude_of_the_measurement():