nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Feature] nanocoder run should use piped stdin as input

Open akramcodez opened this issue 3 weeks ago • 4 comments

Description

Make nanocoder run use piped stdin as extra input, so that things like git diff | nanocoder run "write a commit message" or npm test 2>&1 | nanocoder run "why did this fail" work.

Use Case

run only takes its prompt from the arguments or from --prompt-file. source/cli.tsx never reads process.stdin for the run command, so whatever is piped in is ignored and the model answers without ever seeing it. There is no error, which makes it look like it worked.

The only workaround is to save the output to a file first and pass --prompt-file, or to embed it in a shell string, which runs into the argument size limit that --prompt-file was added to avoid.

Piping into a one-shot agent is the most common way to use it in scripts and CI, so this is something people try on the first day.

Proposed Solution

When run is used and stdin is not a TTY:

  • If there is also a prompt (argument or --prompt-file), append the stdin text to it, wrapped in a clear block, for example:

    <prompt text>
    
    <stdin>
    ...piped text...
    </stdin>
    
  • If there is no prompt, use the stdin text as the prompt. This also removes the current "run with nothing to run" usage error for the pipe case.

  • Allow --prompt-file - to mean stdin explicitly.

  • Cap the amount read (with a visible note when cut) so a huge pipe cannot blow the context window.

Alternatives Considered

  • --prompt-file /dev/stdin already works on Unix, but it replaces the prompt rather than adding to it, does not exist on Windows, and is not discoverable.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] This feature aligns with the project's goals (local-first AI assistance)

Implementation Notes (optional)

The prompt is resolved in one place in source/cli.tsx (the --prompt-file block), so reading stdin there, before the plain or Ink branch is chosen, covers both runtimes. Codex (codex exec reads stdin) and Gemini CLI (cat file | gemini -p "...") both support this.

akramcodez avatar Nov 06 '26 09:11 akramcodez

Hi, I'd like to pick this up too. Here's my read of it and the plan.

1. Understanding of the issue

nanocoder run only takes its prompt from argv or --prompt-file. In source/cli.tsx the prompt is resolved in one place (parseRunPrompt → --prompt-file), and process.stdin is never read, so anything piped in (git diff | nanocoder run "...", npm test 2>&1 | nanocoder run "why did this fail") is silently ignored, no error, so it looks like it worked. The only workarounds (--prompt-file, embedding in a shell string) either need a temp file or hit the argv size limit --prompt-file exists to avoid.

2. Approach

When run is used and stdin is not a TTY, read stdin in that same resolution block (before the plain/Ink branch is chosen, so both runtimes are covered):

  • Prompt + stdin → append the piped text to the prompt, wrapped:
    <prompt text>
    
    <stdin>
    ...piped text...
    </stdin>
    
  • stdin only → use it as the prompt (and drop the current "needs a prompt" error for the pipe case).
  • --prompt-file - → read stdin explicitly as the prompt source.
  • Cap the amount read, with a visible note when it's cut, so a huge pipe can't blow the context window.

Implementation notes:

  • Read via fs fd 0 (readFileSync(0, …)) rather than /dev/stdin, so it works on Windows too.
  • Combine/truncate logic goes in a small pure helper (unit-tested); the fd read stays in cli.tsx to keep the --help/--version fast path import-free.
  • Help text + a git diff | nanocoder run "write a commit message" example, tests (incl. a piped-stdin integration test), and a changeset included. No behavior change when nothing is piped.
  • Matches how codex exec and cat file | gemini -p "..." already behave.

3. Does this match the intent?

Two things I'd like to confirm before starting:

  • A sensible cap for the stdin read, I'm leaning ~100 KB (roughly matches the existing URL-content limit). Open to a different ceiling.
  • Scope: I'd keep this to run only and leave review out (its "prompt" is a branch/PR target). Let me know if you'd want review covered too.

Anything you'd change here?

If this looks right, @akramcodez or @addyCooks could you assign this to me? I'll open a PR.

SamanPandey-in avatar Nov 07 '26 14:11 SamanPandey-in

Hi @SamanPandey-in, thanks for the PR! Please don't open PRs before you're assigned to the issue. Comment on the issue first and wait for the assignment, then start working on it. This keeps things fair and avoids duplicate work. Thanks for understanding.

addyCooks avatar Nov 10 '26 07:11 addyCooks

Thanks @addyCooks, and sorry for opening the PR early. I'm new to the repo and missed the assignment flow. Going forward I'll comment and wait to be assigned before starting.

The plan is in my earlier comment. Two open questions are still there if you have a view: the stdin read cap (I'm leaning ~100 KB) and keeping scope to run only. Happy to adjust either.

I'll hold off on further changes to #2001 until I'm assigned.

SamanPandey-in avatar Nov 10 '26 07:11 SamanPandey-in

Thanks @SamanPandey-in. On your two questions:

  1. Cap: the issue asks for a cap with a visible note when the input is cut, but doesn't give a number. ~100 KB is a reasonable starting point; I'll confirm it when I review the PR.
  2. Scope: the issue is about nanocoder run only, so keeping review out is correct.

I've assigned this to you, so you can continue on #2001.

addyCooks avatar Nov 12 '26 06:11 addyCooks