rtk wc does not read stdin — silent false zero on redirect and pipe
Description
rtk wc does not read stdin at all — neither via redirect (<) nor pipe (|). When no file operand is given, it prints 0 and exits 0, making it indistinguishable from a real empty file.
This is the same class as #4084 (rtk curl drops stdin body), but worse: wc is a counting instrument, and 0 is a fully plausible answer to nearly every question it gets pointed at. A false zero from wc reads as "nothing there", not as an error.
Reproduction
Each command must be alone and first in its block (see "position-dependent" note below):
# Setup
printf 'a\nb\nc\n' > /tmp/wc-test.txt
# BUG: redirect stdin — should be 3, returns 0
rtk wc -l < /tmp/wc-test.txt
# Output: 0 (rc=0)
# BUG: pipe stdin — should be 3, returns 0
printf 'a\nb\nc\n' | rtk wc -l
# Output: 0 (rc=0)
# CORRECT: file argument
rtk wc -l /tmp/wc-test.txt
# Output: 3 (rc=0)
# CORRECT: native wc
/usr/bin/wc -l < /tmp/wc-test.txt
# Output: 3 (rc=0)Position-dependent trigger (why it looks intermittent)
rtk rewrite rewrites only the first matched command in a block. So:
wc -l < falone → rewritten → 0 (wrong)wc -l f; wc -l < f→ firstwcabsorbs the rewrite → second runs native → 75 (correct)
This means a "characterization re-run" that adds the suspect command to an existing block will defeat reproduction. The command must be isolated.
Environment
- rtk 0.38.0
- Linux 6.6.87.2 (WSL2), x86-64
Expected behavior
Either:
rtk wcshould forward stdin to nativewcwhen no file arguments are given, ORrtk wcshould exit non-zero when stdin would be needed but isn't handled
Never: print 0 with rc=0.
Workaround
We guard this in our hook (rtk-rewrite.sh) by matching on $REWRITTEN to skip rewriting standalone wc commands while preserving pipeline upstream savings (e.g., rtk ls | wc -l still works because only ls is rewritten).
Source: rtk-ai/rtk