Skip to content

feat(cli): read the run prompt from a file with --prompt-file - #1415

Merged
will-lamerton merged 1 commit into
mainfrom
feat/prompt-file
Sep 21, 2026
Merged

will-lamerton merged 1 commit into
mainfrom
feat/prompt-file

Conversation

@will-lamerton

Copy link
Copy Markdown
Member

Description

nanocoder run --prompt-file <path> reads the prompt from a file instead of the command line.

Linux caps a single argv entry at MAX_ARG_STRLEN — 32 pages, 131072 bytes — independently of the much larger ARG_MAX total, and execve fails with E2BIG before the process starts. macOS has no equivalent per-argument cap.

That combination is a trap for any caller that assembles a prompt rather than typing one: it passes throughout local development on a Mac and then cannot spawn at all on a Linux CI runner.

Sentinel embeds the files it audits into the prompt and hit exactly this. Its first scheduled run on ubuntu-latest returned:

pack: silent-failure    audited nothing — run error: Error: spawnSync nanocoder E2BIG
pack: untrusted-content audited nothing — run error: Error: spawnSync nanocoder E2BIG

at 314 KiB and 218 KiB, having passed on macOS all the way through development. Tracked as Nano-Collective/sentinel#59.

A file has no such ceiling.

  • Takes precedence over a positional prompt — passing both is a caller bug, and the file is the one asked for explicitly.
  • A missing or unreadable path exits with a message rather than running against an empty prompt.
  • --prompt-file outside run exits with a message.

A second thing, found while adding the test

cli.spec.ts duplicates the argv filter by hand ("mimics the logic in cli.tsx") and had fallen six flags behind it: --mode, --json, --output-format, --trust-directory and the alt-screen pair are stripped by the real parser and were left in the prompt by the mirror. Those tests were passing against a parser that is not shipped.

The mirror is back in step, and a test now asserts the two agree — so the next divergence fails rather than going quiet.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully) — ran cli.spec.ts (60 passing), test:types, test:lint, format:check and build locally; left the full suite to CI as it is long-running
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API

Verified end to end with a 187055-byte prompt file — comfortably past the 131072-byte cap:

$ node dist/cli.js run --prompt-file /tmp/p.txt --provider ollama \
    --model gpt-oss:120b-cloud --mode yolo --trust-directory --json
{ "kind": "success", "exitCode": 0, "finalText": "ACCEPTED", ... }

--help documents the flag and says why it exists.

Linux caps a single argv entry at MAX_ARG_STRLEN — 32 pages, 131072 bytes —
independently of the much larger ARG_MAX total, and execve fails with E2BIG
before the process starts. macOS has no equivalent per-argument cap.

That combination is a trap for any caller that assembles a prompt rather
than typing one: it works throughout local testing on a Mac and then cannot
spawn at all on a Linux CI runner. Sentinel embeds the files it audits into
the prompt and hit exactly this — every pack returned "spawnSync nanocoder
E2BIG" on ubuntu-latest at 314 KiB and 218 KiB, after passing on macOS all
the way through development.

A file has no such ceiling. --prompt-file takes precedence over a positional
prompt, since passing both is a caller bug and the file is the one asked for
explicitly, and an unreadable path exits with a message rather than running
against an empty prompt.

Also brings the parsing test mirror back in step. cli.spec.ts duplicates the
argv filter by hand and had fallen six flags behind it: --mode, --json,
--output-format, --trust-directory and the alt-screen pair were stripped by
the real parser and left in the prompt by the mirror, so those tests were
passing against a parser that is not shipped. A test now asserts the two
agree.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@will-lamerton
will-lamerton merged commit bd271c4 into main Sep 21, 2026
16 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

nc-review: comments — 1 important, 2 nits

@will-lamerton — a few things worth a look, none blocking.

PR adds a useful --prompt-file flag that sidesteps Linux's 128 KiB per-argv E2BIG limit, following the existing value-flag pattern, handling the fused form, and erroring on missing files or use outside run. It also fixes a real divergence bug in the parsePrompt test mirror. The implementation is correct and well-documented, but the new tests for --prompt-file only exercise the mirror helper's filter loop — none of them would fail if the actual file-reading logic in cli.tsx regressed.

🟠 important · tests · source/cli.spec.ts:607

The three new tests for --prompt-file only exercise the parsePrompt mirror helper's filter loop, not the actual new behavior in cli.tsx (reading the file, erroring on a missing file, erroring when --prompt-file is used outside run, or the file-takes-precedence-over-positional rule). If the readFileSync block in cli.tsx were deleted or broken, every test would still pass — the project rubric calls this exact failure mode out as one that has shipped here before. A meaningful test for this feature needs to drive the real parser, e.g. via the existing cli-value-flags.cli-integration.spec.ts pattern (spawn the CLI with a temp file and assert nonInteractivePrompt equals the file contents), or a direct unit test of the new code path. Bonus coverage: missing-file error message, --prompt-file outside run error message, file-vs-positional precedence.

⚪ nit · design · source/cli.tsx:489

nanocoder run --prompt-file with no path following the flag silently produces an empty prompt instead of erroring: args[promptFileIndex + 1] is undefined, so promptFile stays undefined, the read branch is skipped, and the prompt falls through as ''. This is consistent with how --provider and --model without a value behave in this file, so it is defensible, but a short if (promptFile === '') check that prints --prompt-file requires a path would match the spirit of the other --prompt-file error paths added here.

⚪ nit · tests · source/cli.spec.ts:627

The third new test ('the mirror above strips every flag the real parser strips') asserts only that the mirror helper strips the six flags. That guards against future mirror drift, which is useful and addresses the bug described in the PR — but it does not assert that the real parser in cli.tsx strips the same flags. If someone later deletes one of those branches from cli.tsx, this test still passes. Pairing the mirror assertion with one assertion against the real CLI (e.g. via the existing integration spec) would make it a real regression test rather than a self-consistency check.


🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional

Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with /re-review.

@github-actions github-actions Bot added the agent:comments nc-review left non-blocking findings label Sep 21, 2026
will-lamerton added a commit to Nano-Collective/sentinel that referenced this pull request Nov 25, 2026
The entire prompt — pack body plus every matched file — was passed as one
command-line argument. Linux caps a single argv entry at MAX_ARG_STRLEN (32
pages, 131072 bytes) independently of the far larger ARG_MAX, and execve
fails with E2BIG before the process starts.

128 KiB is about 3000 lines, so a pack scoped src/**/*.ts exceeds it on most
real projects, and every production install runs on Linux. Sentinel could
not audit a repository of ordinary size in the environment it ships for, and
never had — the first scheduled run to get far enough to try returned
"spawnSync nanocoder E2BIG" for both packs, at 314 KiB and 218 KiB. macOS
has no equivalent per-argument cap, which is exactly why every local
exercise passed and this reached production.

The prompt goes through a temporary file now, written outside the audited
repository — it contains that repository's source — and removed on the way
out.

That needs Nanocoder 1.31, which added --prompt-file
(Nano-Collective/nanocoder#1415). The scaffolded workflow pins it, and the
runner probes the capability from --help before spawning, because an older
Nanocoder does not reject an unknown flag: it folds it into the prompt, and
the model is left answering a question made of command-line flags while the
run reports malformed output with no hint of why.

E2BIG is handled explicitly as well. It should now be unreachable, but an
errno is not an explanation.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
will-lamerton added a commit to Nano-Collective/sentinel that referenced this pull request Nov 25, 2026
* fix(orchestrator): the prompt must not travel through argv

The entire prompt — pack body plus every matched file — was passed as one
command-line argument. Linux caps a single argv entry at MAX_ARG_STRLEN (32
pages, 131072 bytes) independently of the far larger ARG_MAX, and execve
fails with E2BIG before the process starts.

128 KiB is about 3000 lines, so a pack scoped src/**/*.ts exceeds it on most
real projects, and every production install runs on Linux. Sentinel could
not audit a repository of ordinary size in the environment it ships for, and
never had — the first scheduled run to get far enough to try returned
"spawnSync nanocoder E2BIG" for both packs, at 314 KiB and 218 KiB. macOS
has no equivalent per-argument cap, which is exactly why every local
exercise passed and this reached production.

The prompt goes through a temporary file now, written outside the audited
repository — it contains that repository's source — and removed on the way
out.

That needs Nanocoder 1.31, which added --prompt-file
(Nano-Collective/nanocoder#1415). The scaffolded workflow pins it, and the
runner probes the capability from --help before spawning, because an older
Nanocoder does not reject an unknown flag: it folds it into the prompt, and
the model is left answering a question made of command-line flags while the
run reports malformed output with no hint of why.

E2BIG is handled explicitly as well. It should now be unreachable, but an
errno is not an explanation.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(orchestrator): a missing nanocoder is "not on PATH", not "too old"

The --prompt-file probe ran `nanocoder --help` and cached any failure as
"no --prompt-file support", so with Nanocoder not installed every run
reported "upgrade nanocoder" instead of the documented "not on PATH"
error. A probe that cannot spawn Nanocoder is now no answer: the spawn
reports the real error, and the next call probes again.

Also drops an unrelated rewrite of an old run record from this branch, and
notes in the dedup changeset that its fix already shipped in alpha.7 (it
merged seconds before that release was cut, so only its entry was left).

Verified on Linux (node:22, aarch64) with a 307 KiB prompt:
alpha.7 fails with E2BIG; this branch reaches Nanocoder 1.32.0; no
nanocoder gives "not on PATH"; Nanocoder 1.30.0 gives the upgrade message.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:comments nc-review left non-blocking findings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant