fix(insights): count read-shaped shell commands as reads, not as verification - #954
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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.