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
+18 -8
View File
@@ -85,14 +85,24 @@ read the full file around a flagged line, not just the diff hunk.
lists the changed files explicitly under "Changed files" — use that as your
focus list.
3. **Ground findings in context.** For each changed file, before finalizing any
finding, `read`/`grep` its **callers, imports, sibling functions, and type
definitions** so your findings reflect how the change is actually used, not
the hunk in isolation. The repo is checked out at the head sha, so the
surrounding code is on disk — use it. Keep it bounded: stop exploring a file
once the finding is grounded (13 related files per finding); do NOT do
unbounded whole-repo walks (token cost, and the focus is the diff's
neighbourhood).
3. **Ground findings in context — but stay bounded.** For each changed file,
before finalizing any finding, `read`/`grep` its **callers, imports, sibling
functions, and type definitions** so your findings reflect how the change
is actually used, not the hunk in isolation. The repo is checked out at the
head sha, so the surrounding code is on disk — use it.
HARD budget on reads beyond the diff (this is the single biggest driver of
token cost on long agent loops):
* ≤ 5 file reads BEYOND the diff for the entire review. Count them.
* ≤ 80 lines per `read` call — use `read --offset N --limit 80` to slice
large files; never `cat` a whole 1000-line file.
* ≤ 3 grep calls beyond the diff (use `rtk grep` if available; `grep -n`
with a precise pattern otherwise).
* Do NOT re-read a file you've already seen. The diff is the source of
truth — re-reads only confirm what you already know.
* Do NOT walk directories (`ls -R`, `find .`) — list explicitly.
* Honour `.pr-review.json:exclude_paths` — those files do not exist for
you; do not read them even if they appear in the diff.
4. **Run the repo's own checks via bash.** Detect tooling and run it on the
CHANGED files only (keep it fast, keep tokens low):