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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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.

Notes

shipped production is serving it deploy 11ed909

opened this

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. The code is in src/cli/commands/tell.ts, and the new src/cli/stdin_text.ts holds 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.md has the one line, in the forge tell section.

Tests

  • test/tell-stdin.test.ts spawns 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> tell exec is unchanged, and so is the in-terminal screen src/tui/screens/tell.ts, which already prompts. The forge shell 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/name

Closes #12693

2 earlier comments · 1 event
commented

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. The code is in src/cli/commands/tell.ts, and the new src/cli/stdin_text.ts holds 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.md has the one line, in the forge tell section.

Tests

  • test/tell-stdin.test.ts spawns 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> tell exec is unchanged, and so is the in-terminal screen src/tui/screens/tell.ts, which already prompts. The forge shell 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/name
commented

forge 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.

Changes requested — before the latest push

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.

commented

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.

  1. Local limit: the piped branch now checks the cleaned text against TELL_TEXT_MAX before anything is sent. A 3000-character pipe is refused with piped text is 3000 characters and the limit is 2000. The 8 KB cap stays only as the read bound, and its comment in src/cli/stdin_text.ts now says so.
  2. Oversize test: the new test pipes 3000 characters, asserts that wording and asserts nothing reached the server.
  3. CRLF, tab and newline: \r\n and a lone \r now become \n, and tabs and newlines stay. A test covers it.
  4. Bare forge tell: I documented it in docs/CLI.md rather than add a read timeout. A timeout would break a slow git diff | forge tell. The docs say stdin is read whenever it isn't a terminal, so a bare forge tell with open but silent stdin waits, and </dev/null or giving words gets the usage line.
  5. Import order: stdin_text now comes after the resolveRepo and 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.

Approved

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:

  1. Non-blocking: add a short read timeout, or a hint on stderr, when stdin is open but silent, so a bare forge tell in a script does not hang.
  2. Non-blocking: add a TTY-case test with a pty if the harness can ever provide one, so the interactive usage line is pinned.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs