Repository navigation
feat(builtins): stream grep and tr through pipelines - #2587
Merged
Merged
Conversation
grep and tr read their input pipe in record/UTF-8 aligned pieces and write results as they go, so `loop | grep y | head -2` and `yes | tr y n | head -1` end with SIGPIPE like bash. grep -m stops reading at its budget. Summarizing options stay buffered and drain the pipe (Context::stdin_to_end). Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 9388c4a | Commit Preview URL Branch Preview URL |
Oct 07 2026, 07:02 PM |
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.
Requested by Михайло · project thread
What changed
grepandtrnow stream when they are a pipeline stage, following plaincat(#2584). They read input in ~4 KiB pieces and write results as they go.grepcuts its pieces on record ends andtron UTF-8 character ends.grep -mstops reading once its budget is spent. Options that need the whole input stay buffered and drain the pipe first:grep -c/-l/-L/-q, context lines,-b,-rtr -sThe shared piece reader (
InputChunks) lives inbuiltins/mod.rsso more filters can adopt it.Why
This is roadmap step 2 (concurrent/streaming execution).
producer | grep pat | headis one of the most common agent pipelines. Before this change, agreportrstage downstream of an endless or large producer read everything, so it ran until a limit fired instead of stopping at SIGPIPE.Before / After
while :; do echo y; done | grep y | head -2y y,PIPESTATUS141 141 0yes | tr y n | head -1n,141 141 0yes | tr -d '\n' | head -c 5yyyyy,141 141 0grep . big | head -1; echo ${PIPESTATUS[*]}0 0141 0yes | grep -o -m3 y | cat141 0 0Proof:
l_pipe_001_grep_tr_streamandl_pipe_001_buffered_filter_options_drain_pipe(bash-verified). I also ran a differential script over grep-c/-v/-n/-i/-H/-z/-a, multiple files, a missing file, binary input and the tr variants. Its only differences are existing ones outside streaming: stderr ordering, byte-wisetr 'é' e, and\rstripping.Risk
Medium-low. The buffered paths are unchanged apart from draining a streaming pipe.
tr's logic moved intoTrSpec::applyunchanged. Binary input in a stream is reported once withbinary file matchesfrom the point the NUL is seen.Checklist
cargo test -p bashkit --lib/--test integration/bash_comparison-D warnings, fmt,check-okf,check-doc-linkshttps://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
Generated by Claude Code