Tracking issue for safe pipeline rewriting
Context
Automatic rewriting previously could rewrite a pipeline producer, changing the bytes consumed by downstream commands.
PR #3128 introduces a first step:
-
Keep producers and intermediate stages raw.
-
Rewrite only a verified-safe final stage.
-
Initially allow ordinary
grepandrg. -
Keep
-f/--filesearches raw. -
Keep
wcraw because pipeline-final rewriting provides no meaningful savings. -
Keep malformed, grouped, and
|&pipelines raw. -
Continue rewriting commands in independent
&&,||, and;clauses. -
Stream piped grep/rg matches so long-running input works:
tail -f app.log | grep ERROR -> tail -f app.log | rtk grep ERROR
Follow-ups
- [ ] Treat |& consistently with 2>&1 | after adding combined-stream coverage.
- [ ] Support producer rewriting before display-only head, cat, and non-following tail.
- [ ] Treat bare newlines as clause boundaries.
- [ ] Replace command-string comparisons with structured safety policies such as Never, Always, and Conditional.
- [ ] Consider a consumable token iterator or cursor as pipeline analysis grows.
- [ ] Add more final commands only after verifying stdin, streaming, exit-code, interactivity, argument, and output semantics.
- [ ] Handle redirects and explicit RTK pipeline producers separately.
- [ ] Consider nonstandard streaming inputs such as /dev/stdin, file descriptors, and FIFOs.
- [ ] Define the long-term streaming compression contract, including caps, line truncation, grouping, and tee behavior.
The goal is to grow pipeline rewriting incrementally while keeping every newly eligible rewrite demonstrably safe.
wshm · Automated triage by AI
🔍 Automated Triage
| ✨ Category | feature |
| 🟡 Priority | medium |
| 🎯 Confidence | 72% |
Summary
Tracking issue for incremental, safety-verified pipeline rewriting (grep/rg final stages so far); PR #3128 covers the first step, list of follow-up work items remains open
Triaged automatically by wshm · This is an automated analysis, not a human review.
wshm · Automated triage by AI
🔍 Automated Triage
| ✨ Category | feature |
| 🟡 Priority | medium |
| 🎯 Confidence | 86% |
Summary
Meta/tracking issue for incrementally expanding safe pipeline-rewriting (PR #3128 already lands the first safe subset); track remaining follow-up items as future work, no immediate action needed beyond the linked PR.
Triaged automatically by wshm · This is an automated analysis, not a human review.
Data point from rtk 0.51.0 (Linux x86_64, musl release), Claude Code hook. We promoted the hook for all sessions and agents on a workstation, then rolled it back within the hour: agent scripts that parse piped output got compacted results.
The real case was grep -E pattern file.log | tail -4. It became rtk grep … | tail -4, so tail cut rtk's grouped output, including its "+N more … rtk recall" marker, and returned the earliest matches instead of the last ones. That is #4207.
To see what the hook does without running anything, we piped {"tool_name":"Bash","tool_input":{"command":"…"}} into rtk hook claude and checked whether updatedInput.command changed. "producer" means <cmd> | tail -3; "filter" means printf x | <cmd>.
| command | standalone | producer | filter |
|---|---|---|---|
git log -n 20 |
rewritten | rewritten | n/a |
git status |
rewritten | rewritten | n/a |
git diff HEAD~1 |
rewritten | rewritten | n/a |
git show HEAD |
rewritten | rewritten | n/a |
gh pr list |
rewritten | unchanged | n/a |
grep -n foo f.txt |
rewritten | rewritten | rewritten |
rg foo |
rewritten | rewritten | rewritten |
go test ./... |
rewritten | rewritten | n/a |
go build ./... |
rewritten | rewritten | n/a |
cargo test |
rewritten | rewritten | n/a |
ls -la d |
rewritten | rewritten | n/a |
find . -name x |
rewritten | rewritten | n/a |
wc -l f |
rewritten | rewritten | unchanged |
cat f.txt |
rewritten | unchanged | unchanged |
curl -s https://x |
rewritten | unchanged | n/a |
diff a b |
rewritten | rewritten | unchanged |
docker ps |
rewritten | unchanged | n/a |
pytest |
rewritten | rewritten | n/a |
tree d |
rewritten | rewritten | unchanged |
gh, cat, curl and docker already leave piped producers alone, so the detection exists. Applying the same rule to every producer and every filter position would make the hook safe for automation: a command whose stdout goes to a pipe or a redirect is left native. We will re-run this matrix when a release carries #4382 or an equivalent fix.
A shape for the producer side, from the git ls-tree fold in #1816. The guard that keeps a folding producer raw before a line-reading consumer judges the words as typed, so a flag that arrives through a shell expansion reads as a positional:
MODE=--name-only; git ls-tree -r $MODE HEAD | head -3
-> MODE=--name-only; rtk git ls-tree -r $MODE HEAD | head -3
In a clone of this repo, native git hands head 78 bytes (three paths); the rewritten command hands it 312 bytes of folded lines. set -- --name-only; git ls-tree -r "$@" HEAD | head -3 behaves the same. F=-r; git ls-tree $F --name-only HEAD | head -3 and ${MODE:---name-only} are left raw, because the typed --name-only or the braces are enough for the guard.
One way to read it: when a word that the guard needs to classify contains an expansion, treat the producer as not line-faithful and leave it raw.