Skip to content

refactor(cli): one run-prompt parser, and strip the mouse flags - #1420

Merged
will-lamerton merged 1 commit into
mainfrom
refactor/one-run-prompt-parser
Sep 21, 2026
Merged

will-lamerton merged 1 commit into
mainfrom
refactor/one-run-prompt-parser

Conversation

@will-lamerton

Copy link
Copy Markdown
Member

Description

Follow-up to #1415, and a correction. I claimed there that a test now stopped the CLI parsing mirror from drifting again. It did not.

What I actually added enumerated the six flags I happened to have found and checked them against the hand-written copy. A seventh flag added to cli.tsx tomorrow would drift exactly as before and that test would pass, happily, because it was testing the copy.

Resyncing a duplicate does not fix a duplicate. So there is one parser now, in run-prompt-args.ts, imported by cli.tsx and by cli.spec.ts. There is nothing left to drift.

The tests are derived, not typed

  • The first reads the parser's own flag lists, so a flag added to the parser is covered the moment it is added — no second list to keep in step.
  • The second reads the long flags out of the --help text and fails if one is documented but not filtered.

That second test found two more flags

--mouse and --no-mouse are documented and were never stripped. So:

nanocoder run "fix the failing tests" --mouse

sent the model a prompt beginning with the word --mouse. Harmless in effect — nobody passes a mouse flag to a non-interactive run — but they are display concerns exactly like the --alt-screen pair that was already stripped, and my hand-written enumeration had missed them twice.

--preset and --lean also came up and are correctly excluded: they belong to nanocoder init and cannot follow run.

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 (61 passing) plus test:types, test:lint, format:check, test:knip and build; the full suite is long-running and left to CI
  • Tests cover both success and error scenarios

Manual Testing

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

Re-ran the real binary after the extraction to confirm behaviour is unchanged — a 187 KB --prompt-file prompt still returns {"kind":"success","finalText":"ACCEPTED"}.

run-prompt-args.ts is deliberately import-free so cli.tsx's --version/--help fast path is untouched.

The parser lived in cli.tsx with a hand-written copy in cli.spec.ts. The
copy had fallen six flags behind the original — --mode, --json,
--output-format, --trust-directory and the alt-screen pair were removed by
the parser and left in the prompt by the copy — so those tests passed
against a parser nobody ships.

Resyncing the copy, which is what I did first, does not fix that. A
duplicate that can drift will, and no test written against the duplicate can
notice, because it is testing the duplicate. So there is one parser now, in
run-prompt-args.ts, imported by cli.tsx and by the spec.

The tests derive their cases from the parser's own flag lists rather than a
list typed beside them, so a flag added to the parser is covered the moment
it is added. A second test reads the long flags out of the --help text and
fails when one is documented but not filtered.

That second test immediately found --mouse and --no-mouse, which a
hand-written enumeration had missed twice: they were documented, never
stripped, and would arrive as the first words of the user's prompt. Display
flags are meaningless on a non-interactive run, exactly like the alt-screen
pair already handled.

Kept free of imports so cli.tsx's --version/--help fast path stays intact.

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

Copy link
Copy Markdown
Contributor

nc-review: nothing to raise

@will-lamerton — nothing to raise from the automated review.

The PR consolidates the run-prompt flag parser into source/run-prompt-args.ts, removes the drifting hand-written copy in cli.spec.ts, and correctly fixes the --mouse/--no-mouse leak that its own new derived test surfaced. The behavior matches the pre-change parser, the integration test in cli-value-flags.cli-integration.spec.ts continues to cover the binary end-to-end, and the changeset is well-formed.


🔴 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:clean nc-review had nothing to raise label Sep 21, 2026
will-lamerton added a commit to soumojit-D48/nanocoder that referenced this pull request Sep 21, 2026
…mpt parser

Nano-Collective#1420 landed while this PR was open and removed the duplicated run-flag
list, leaving one parser in run-prompt-args.ts. This branch had added a
third copy in utils/cli-flags.ts, which is the thing Nano-Collective#1420 exists to
prevent, and it had already drifted: it did not know --mouse/--no-mouse,
so `nanocoder review --mouse main` filtered nothing, kept main as a
second positional, and told the user their own branch name was an extra
argument. Post-merge it would also have missed --prompt-file.

So cli-flags.ts is gone. parseReviewCliArgs filters against the lists
run-prompt-args.ts exports, and cli.tsx takes main's parseRunPrompt and
--prompt-file handling unchanged.

The spec keeps main's version of the shared tests, including the
derived-from-the-parser coverage that replaced the hand-written mirror.
The review guard tests and the flags-before-run tests come across as
they were, and the filterCliFlags tests are replaced by one that walks
RUN_FLAGS_WITH_VALUES/RUN_FLAGS_STANDALONE through the review parser, so
the next flag added is covered the moment it is added.

tsc, biome and knip clean; 112 tests pass across cli, review, review-cli
and run-prompt-args.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:clean nc-review had nothing to raise

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant