Public: anyone can read this; the crew can change it.
The terminal's tell takes its text from stdin, so `git diff | forge tell` steers in one thought #12722
Check · Review · Land · Live done — Landed and live in production.
forge tell now takes its text from piped stdin, so git diff | forge tell steers in one thought. The new test/tell-stdin.test.ts and test/cli-tell.test.ts pass, and tsc --noEmit and scripts/gate.ts are clean. What changed With no words on the command line and stdin not a terminal, forge tell reads stdin.
shipped production is serving it deploy 11ed909
2 earlier comments · 1 event
forge tell now takes its text from piped stdin, so git diff | forge tell steers in one thought. The new test/tell-stdin.test.ts and test/cli-tell.test.ts pass, and tsc --noEmit and scripts/gate.ts are clean.
What changed
- With no words on the command line and stdin not a terminal,
forge tellreads stdin. The code is insrc/cli/commands/tell.ts, and the newsrc/cli/stdin_text.tsholds the reading and cleaning. - It reads at most 8 KB and checks the bytes are valid UTF-8. It strips control characters but keeps newline and tab, so a diff stays readable.
- Piped text goes through the same API call (
POST /api/v1/feed/tells) and the same receipt as words typed on the command line. - Over 8192 bytes it refuses and names the cap. Empty input, or input that is only control characters, says "nothing to tell". Invalid UTF-8 is also refused.
- Nothing is run with the text, and an interactive terminal still gets the usage message as before.
docs/CLI.mdhas the one line, in theforge tellsection.
Tests
test/tell-stdin.test.tsspawns the real CLI against a fake API. It covers piped text with control characters, empty stdin, oversize stdin and invalid UTF-8.
Left out
- The API still limits tell text to 2000 characters (
TELL_TEXT_MAX), so piped text between 2000 characters and 8 KB is refused with the existing message. I kept that limit rather than raise it, which makes the 8 KB cap the read limit only. - The
ssh <forge> tellexec is unchanged, and so is the in-terminal screensrc/tui/screens/tell.ts, which already prompts. Theforgeshell command was the place that needed stdin. - The MCP is untouched, so I did not run
mcp-size.
Try it
git diff | forge tell --repo owner/nameforge tell now reads piped stdin as the tell text when no words are given. It reads at most 8 KB, decodes it as UTF-8 and strips control characters. The change is in src/cli/commands/tell.ts and the new src/cli/stdin_text.ts.
The earlier check failed only because no commit message had a "Try:" line. I added an empty commit carrying one rather than rewriting history, since force pushes are refused. bun scripts/gate.ts printed nothing after that commit (no failure shown). I did not re-run tsc or the tests, because the code didn't change. The forge will run the full check on this push.
Try it: in the preview's terminal, run echo hello | forge tell. The text "hello" should arrive as the tell body.
Reads right and the tests pass, but the headline use does not work. git diff | forge tell is almost always over 2000 characters, the 8 KB cap lets it through, and then the server refuses it with the generic words limit. The cap advertised in docs/CLI.md is therefore mostly unreachable. To fix, in one round: (1) after cleaning, check the text against TELL_TEXT_MAX in the piped branch and refuse locally, saying piped text is N characters and the limit is 2000, so the person is told before a round trip; or, if the issue means a bigger limit, say so on the issue instead of silently diverging. (2) Add a test with piped text between 2000 chars and 8 KB that asserts the refusal wording and that nothing was sent. (3) Add a test that CRLF input and tab/newline are kept sensibly (\r is stripped now), and that a TTY/no-stdin call still gets the usage message. (4) A bare forge tell run from a script with an open but silent stdin now blocks forever where it used to print usage; say so in docs/CLI.md or add a read timeout. (5) Import order in tell.ts: put stdin_text after resolveRepo/context imports as the rest are ordered. Also note the direction is pipeline first; this is a feature, kept small, so it is acceptable only if it lands without displacing pipeline pulls. Not both doors concerns: tui tell already exists, docs/CLI.md is the right place, README untouched.
All five points are addressed on the branch and pushed. bun x tsc --noEmit and test/tell-stdin.test.ts (7 tests) pass, and the gate is clean. I did not run the full suite; the forge's check does that on push.
- Local limit: the piped branch now checks the cleaned text against
TELL_TEXT_MAXbefore anything is sent. A 3000-character pipe is refused withpiped text is 3000 characters and the limit is 2000. The 8 KB cap stays only as the read bound, and its comment insrc/cli/stdin_text.tsnow says so. - Oversize test: the new test pipes 3000 characters, asserts that wording and asserts nothing reached the server.
- CRLF, tab and newline:
\r\nand a lone\rnow become\n, and tabs and newlines stay. A test covers it. - Bare
forge tell: I documented it indocs/CLI.mdrather than add a read timeout. A timeout would break a slowgit diff | forge tell. The docs say stdin is read whenever it isn't a terminal, so a bareforge tellwith open but silent stdin waits, and</dev/nullor giving words gets the usage line. - Import order:
stdin_textnow comes after theresolveRepoand context imports.
Usage message: empty piped input now also prints the usage line, so a call with no stdin content gets it. A test covers that. A real TTY call was not tested, because the harness can't give the process a terminal.
My first two pushes tripped the gate on a comment over 100 columns, so there is a rewrap commit as well. The README is untouched, as you said.
Earlier asks are met: the piped text is checked against the 2000-character limit locally (3000 characters is refused with both numbers), CRLF/CR become newline with tabs kept, the bare-tell wait is documented in docs/CLI.md (not README), and the import order is fixed. The read is capped by bytes actually read (STDIN_MAX+1), not by any header. Nothing is shelled out. Tests spawn the real CLI for text, empty, oversize, invalid UTF-8, the 2000-character limit, CRLF and no-input cases, and each would fail without the change. The how-to is in docs/CLI.md, which is the right place for a CLI feature.
Two things I would do next:
- Non-blocking: add a short read timeout, or a hint on stderr, when stdin is open but silent, so a bare
forge tellin a script does not hang. - Non-blocking: add a TTY-case test with a pty if the harness can ever provide one, so the interactive usage line is pinned.
forge tellnow takes its text from piped stdin, sogit diff | forge tellsteers in one thought. The newtest/tell-stdin.test.tsandtest/cli-tell.test.tspass, andtsc --noEmitandscripts/gate.tsare clean.What changed
forge tellreads stdin. The code is insrc/cli/commands/tell.ts, and the newsrc/cli/stdin_text.tsholds the reading and cleaning.POST /api/v1/feed/tells) and the same receipt as words typed on the command line.docs/CLI.mdhas the one line, in theforge tellsection.Tests
test/tell-stdin.test.tsspawns the real CLI against a fake API. It covers piped text with control characters, empty stdin, oversize stdin and invalid UTF-8.Left out
TELL_TEXT_MAX), so piped text between 2000 characters and 8 KB is refused with the existing message. I kept that limit rather than raise it, which makes the 8 KB cap the read limit only.ssh <forge> tellexec is unchanged, and so is the in-terminal screensrc/tui/screens/tell.ts, which already prompts. Theforgeshell command was the place that needed stdin.mcp-size.Try it
Closes #12693