Skip to content

fix(insights): count read-shaped shell commands as reads, not as verification - #954

Merged
iamtoruk merged 1 commit into
mainfrom
fix/941-bash-read-verify
Aug 10, 2026
Merged

fix(insights): count read-shaped shell commands as reads, not as verification#954
iamtoruk merged 1 commit into
mainfrom
fix/941-bash-read-verify

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Fixes #941.

Two detectors treated the same Bash call inconsistently: READ_TOOL_NAMES ignored shell reads entirely (a session searching with rg read nothing as far as read-edit-ratio was concerned), while countRetries treated every Bash call as a verification step (edit -> grep -> edit scored as rework). Both feed the Optimize tab and the health grade, so bash-first workflows scored worse the more disciplined they were about looking before editing.

One shared classifier fixes both sides: isReadShapedBashCommand (bash-utils) accepts a command only when every segment (split on &&, ;, |) is a read-only inspection command - rg/grep/cat/head/ls/find/wc/jq and friends, plus git subcommands that cannot mutate under any flag (log, diff, status, show, blame, grep, shortlog, describe, rev-parse, ls-files). Unknown or mixed commands stay non-read, the conservative default both call sites want.

  • detectLowReadEditRatio now counts read-shaped bash calls as reads; compactOptimizeInput retains the (capped) command for bash tool_use blocks so the detector can classify them.
  • countRetries no longer takes a read-shaped shell step as verification; a command-less bash step keeps the old behavior.
  • No cache bump needed: classification runs at serve time from cached turns (cachedTurnToClassified), so the corrected retry counts apply to existing caches immediately.

Measured on a real 7-day corpus (3,928 sessions): 1,053 previously-invisible shell reads (ratio 1.70:1 -> 2.01:1 against the 4:1 threshold) and 14 phantom retries removed (770 -> 756). The issue reporter's rg-first corpus shows a much larger swing (0.34:1 -> 3.72:1); this corpus is echo/git/python3-heavy, so the honest effect here is smaller but directionally identical.

Tests: read-shaped-bash ratio positive/negative in tests/optimize.test.ts, retry positive/negative/unknown-conservative in tests/classifier.test.ts, and the command classifier's accept/reject/quoting matrix in tests/bash-commands.test.ts. tsc clean; 147 tests green across the three suites.

@iamtoruk
iamtoruk merged commit 0af7c00 into main Aug 10, 2026
5 checks passed
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.

Bash-heavy workflows are misread: shell reads uncounted, retries overcounted

1 participant