Skip to content

fix: universal no-bloat guard — filters never emit more than raw - #98

Merged
thehoff merged 2 commits into
developfrom
fix/no-bloat-guard-95
May 20, 2026
Merged

thehoff merged 2 commits into
developfrom
fix/no-bloat-guard-95

Conversation

@thehoff

@thehoff thehoff commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #95. Several filters produced output larger than the raw command — negative savings on the dashboard (tsc -b −94%, gh pr create −23%, git push −7%, small/no-match grep negative). Same class as #89.

Design — three emit shapes, one guard each

Filters emit in three ways; no single layer is universal, so the guard is matched per shape:

  • core::runner::no_bloat(baseline, filtered) — shared helper, returns the smaller by byte length.
  • Buffered filters (RunMode::Filtered) — swap to raw before the print* call. One change covers pytest, gh pr create, lint, vitest, etc.
  • Ad-hoc filters (grep, git add, git pull) — call no_bloat directly so print and track agree.
  • Streaming filters (tsc, git push) — output is already on the terminal when track runs; can't un-print. TimedExecution::track instead clamps recorded output tokens to input — tracking math is honest (0%, never negative).

git add's synthetic --stat baseline (#89) is preserved — compact shortstat is always shorter, guard returns it unchanged. Codex review caught one edge: a no-op git add has an empty baseline; the guard short-circuits on empty so ok (nothing to add) is not silenced.

Test plan

  • cargo test --workspace — 2265 pass, 0 fail
  • New tests: guard picks raw on inflation, normal filter unaffected, git add synthetic baseline, empty-baseline no-op, streaming-clamp 0% floor
  • cargo build --release clean
  • Codex review — one IMPORTANT (empty-baseline) found and fixed; rest clean

🤖 Generated with Claude Code

thehoff and others added 2 commits May 20, 2026 15:14
…n they save

Several filters produced output larger than the raw command (negative
savings): tsc -b -94%, pytest --verbose -75%, gh pr create -23%,
git push -7%, no-match grep emitting a ~13-token convenience message
where raw grep emits nothing.

The guard is applied at the layer that matches each filter's emit path:

- core::runner::no_bloat(baseline, filtered) — picks the smaller of the
  two by byte length. Callers emit AND track the same value, so print
  and tracking always agree.
- RunMode::Filtered in core::runner::run — buffered filters (pytest, gh,
  lint, vitest, etc.) swap to raw *before* printing when the filtered
  form is >= the baseline. This is the universal fix: every run_filtered
  caller is covered with no per-filter change.
- Ad-hoc filters that don't use runner::run (grep, git add, git pull)
  call no_bloat directly before their println! + track.
- Streaming filters (tsc, git push) print line-by-line and cannot be
  un-printed; TimedExecution::track now clamps recorded output tokens to
  input tokens, so reported savings are honest (0%, never negative).

git add's intentional informational summary (issue #89) is preserved:
its guard runs against the synthetic git-diff--cached--stat baseline it
already tracks against, not raw git-add output, so the compact shortstat
— always shorter than the multi-line stat — survives untouched.

The no-match grep "0 matches for '<pattern>'" message is now dropped in
favour of raw empty output: consistency over a 13-token convenience line.

Tests: no_bloat picks raw on inflate/equal, keeps filtered on real
saving, preserves the synthetic-baseline summary; grep no-match emits
empty; the track() clamp pins output<=input while leaving real savings
intact.

Closes #95.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codex review of #95: when `git add` stages nothing, the synthetic
--stat baseline is empty, so no_bloat picked the empty string and
suppressed the `ok (nothing to add)` message — a successful no-op
add went silent. Short-circuit the guard on an empty baseline.

Adds the missing regression tests: empty-baseline git add, and the
streaming-clamp 0%-floor path.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thehoff
thehoff merged commit 6131a99 into develop May 20, 2026
4 checks passed
@thehoff
thehoff deleted the fix/no-bloat-guard-95 branch May 20, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filters: universal no-bloat guard — never emit output larger than raw

1 participant