Repository navigation
fix(wc): preserve filenames containing spaces in wc filter - #8
Merged
Merged
Conversation
The wc output filter parsed each line with split_whitespace() and assumed
the filename was a single trailing token (parts.last() / parts[3]). GNU wc
prints the filename verbatim, so `wc -l "my file.txt"` emits `3 my file.txt`
and the filter silently corrupted the name the model then reads:
- Lines/Words/Bytes/Chars multi-file: "my file.txt" -> "file.txt"
(only the last path segment survived)
- Full multi-file: "30 96 978 my file.txt" -> took parts[3] = "my",
dropping "file.txt" entirely
- Mixed single-file: leaked a filename fragment into the counts
("30 96 my" instead of "30 96")
This is the same class of defect as the grep BRE-pipe bug (#6): a filter
that mangles output the model reasons over.
Fix: add split_counts_and_name(line, max_counts) which peels off exactly the
known number of leading numeric count columns and treats the remainder as one
opaque, verbatim filename (spaces preserved). All multi/single formatters and
the common-prefix scan now use it.
Adds regression tests for every affected mode (proven to fail pre-fix) plus
direct contract tests for the helper, including the count-column cap and
trailing-name edge cases.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
👋 Thanks for the PR! It looks like this targets Please update the base branch:
See CONTRIBUTING.md for details. |
ryanmurf
enabled auto-merge (squash)
May 30, 2026 01:17
ryanmurf
added a commit
that referenced
this pull request
May 30, 2026
#9) The tree filter stripped any line matching the loose substring heuristic `line.contains("director") && line.contains("file")`, intended to drop tree's trailing summary line (e.g. "5 directories, 23 files"). But this silently dropped legitimate entries whose filenames contain both words, e.g. `director-files.txt`, `file_directory.json`, or a path segment like `my directory with files` — the model never saw those files existed. Same bug class as the grep BRE-pipe over-match (#6) and the wc space-filename drop (#8): an output transform that over-matches and silently strips real content the model reasons over. Fix: anchor the summary detector to tree's exact summary shape with a whole-line regex (`^\d+ director(y|ies)(, N files)?(, N links)?$`) instead of a substring contains-check. Regression tests prove the dropped filenames now survive and the real summary line is still stripped, including the `, N links` platform variation. Co-authored-by: rtk-sweep-agent <agent@herodevs.dev>
This was referenced May 30, 2026
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.
Problem
The
wcoutput filter (src/cmds/system/wc_cmd.rs) parsed each line withsplit_whitespace()and assumed the filename was a single trailing token (parts.last()/parts[3]). GNUwcprints the filename verbatim, sowc -l "my file.txt"emits3 my file.txt— and the filter silently corrupted the name the model then reads.Verified against real GNU
wc:Corruption observed (proven failing pre-fix)
30 my file.txt30 file.txt30 my file.txt30 96 978 my file.txt30L 96W 978B my30L 96W 978B my file.txt30 96 978 src/my file.txt30L 96W 978B src/my30L 96W 978B my file.txt30 96 my file.txt30 96 my30 96This is the same defect class as the grep BRE-pipe bug (#6): a filter that mangles output the model reasons over. A truncated/renamed file can send the model to act on the wrong path.
Fix
Added
split_counts_and_name(line, max_counts)— peels off exactly the known number of leading numeric count columns (1 for-l/-w/-c/-m, 3 for Full, up to 4 for Mixed-lwcm) and treats the remainder as one opaque, verbatim filename with internal spaces preserved. All single/multi formatters and the common-prefix scan now route through it. No change to the compact output format for ordinary (space-free) filenames.Tests
totalline, and tabs/extra spacing.wc_cmdtests pass; fullcargo test --allgreen.CI gates run locally
cargo fmt --all -- --check✅cargo clippy --all-targets -- -D unsafe_code✅ (exit 0; only pre-existing warnings, no new ones)cargo test --all✅ (0 failures)cargo build --release✅🤖 Generated with Claude Code