Skip to content

fix: keep every word of an unquoted prompt, and stop a typo from starting a session - #96

Merged
hbrooks merged 1 commit into
mainfrom
fix/prompt-shorthand-word-loss-and-typo-guard
Jul 31, 2026
Merged

fix: keep every word of an unquoted prompt, and stop a typo from starting a session#96
hbrooks merged 1 commit into
mainfrom
fix/prompt-shorthand-word-loss-and-typo-guard

Conversation

@hbrooks

@hbrooks hbrooks commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

Two problems with the bare-prompt shorthand, found while asking how to prevent typos from starting sessions.

1. Unquoted prompts lost every word but the first. agent fix the tests started a session with the prompt "fix". The rest was dropped silently, no error. [prompt] was a single positional, and commander does not complain about excess args. session handoff <prompt> had the identical bug.

Now [prompt...], joined on spaces. This also gives -- a useful meaning for free, which was the sticking point on the original idea of requiring agent -- <prompt>:

agent fix the tests                    -> "fix the tests"
agent fix the tests --model claude-fable-5   -> prompt and flag split correctly
agent -- why does -m fail              -> "why does -m fail"
agent --model z -- why does -m fail    -> flag parsed, rest is prompt

2. A mistyped command started a session. agent sesion ran as a prompt. Now:

$ agent sesion
error: unknown command "sesion"
  did you mean "agent session"?
  to start a session with that prompt: agent -p sesion
  to see every command: agent --help

Exits 1. Nothing starts. With no near match (agent xyzzy) the suggestion line is omitted and the rest stays.

The guard keys on shape, not edit distance

One bare word with no whitespace and no leading dash is a typo. Anything longer is a prompt. Edit distance only picks the wording of the hint; it never decides whether to block.

That distinction matters. Gating on distance alone would have been much worse than the bug it fixes. Measured against 68 common prompt-opening words, 23 fall within commander's own match threshold of a command name:

typed matches would have been refused
revert review agent revert the migration
audit budget agent audit the deps
test host agent test the parser
log / logs login agent logs are missing
find ping agent find the leak

Also: update/usage, make/me, explain/template, look/hook, list/host, mock/hook, lint/ping, delete/template.

Known gap, left in deliberately

agent sesion list still starts a session. I prototyped the obvious fix, a near-miss first word plus a known subcommand, and it false-positived on revert list, audit list, test run, and port get. Refusing a real prompt is worse than missing a typo, so the single-token rule stands alone. Easy to revisit.

Notes

  • Suggestions only name documented spellings. Hidden plural aliases still dispatch but never appear in a hint.
  • Quoting a single word cannot get through, since the shell strips the quotes. That is why the error names -p and not quoting.
  • The similarCommands helper is a local Damerau-Levenshtein. Commander has one internally but does not export it, and its top-level unknown-command error is unreachable here anyway, because the shorthand intercepts first.

Test plan

  • vitest run green: 421 tests, 23 files. 13 new.
  • tsc --noEmit clean.
  • Prompt joining covered end to end, stubbing startAgentSession and parsing real argv: unquoted, quoted, trailing flags, promptless.
  • Typo guard unit-tested: single word, multi-word prompt, leading dash, --, one word plus a flag.
  • Driven against the real CLI: sesion, reveiw, instal, confg all blocked with exit 1; xyzzy blocked with no suggestion; session, sessions, --version, --help dispatch unchanged; -p refactor and -- refactor both get through.

Verified by unit test and by tsx src/cli.tsx rather than a live session, because the shorthand path hardcodes --connect and cannot run headless.

…nd from starting a session

`agent fix the tests` sent just "fix". The positional was a single
argument, so commander bound the first word and dropped the rest with no
error. Making it variadic and joining on spaces fixes that, and gives
`--` a useful meaning for free: `agent -- why does -m fail` now sends the
whole line. `session handoff` had the same truncation.

A bare word is also treated as a prompt, so `agent sesion` used to start
a session instead of failing. The guard keys on shape, not edit distance:
one word with no spaces and no leading dash is a mistake, and anything
longer is a prompt. Edit distance decides only the wording of the hint,
never whether to block. Gating on it would have been much worse. Of 68
common prompt-opening words, 23 land within commander's match threshold
of a command name (revert/review, audit/budget, test/host), so
`agent revert the migration` would have been refused.

`agent sesion list` still slips through. A near-miss plus a known
subcommand looked like the fix, but it also caught `revert list` and
`audit list`. Blocking a real prompt is worse than missing a typo.

Forcing a one-word prompt through: `agent -p refactor` or
`agent -- refactor`. Quoting cannot work, since the shell strips it,
which is why the error names `-p`.
@hbrooks
hbrooks merged commit cdf8274 into main Jul 31, 2026
1 check passed
@hbrooks
hbrooks deleted the fix/prompt-shorthand-word-loss-and-typo-guard branch July 31, 2026 14:48

@ellipsis-dev ellipsis-dev Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to fd2daae in 15 minutes, 30 seconds. Click to view more information.

Review ID: crun_EIXaEiWgQgnEuBn73s4mr2wd6hzgc34Ekyqe0pkNBEz

This review was created by Ellipsis. You can tag @ellipsis in this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant