fix: keep every word of an unquoted prompt, and stop a typo from starting a session - #96
Merged
Merged
Conversation
…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`.
Contributor
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to fd2daae in 15 minutes, 30 seconds. Click to view more information.
- Reviewed
283lines of code in5files - View this review on Ellipsis
Review ID: crun_EIXaEiWgQgnEuBn73s4mr2wd6hzgc34Ekyqe0pkNBEz
This review was created by . You can tag
@ellipsis in this pull request.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 testsstarted 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 requiringagent -- <prompt>:2. A mistyped command started a session.
agent sesionran as a prompt. Now: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:
revertagent revert the migrationauditagent audit the depstestagent test the parserlog/logsagent logs are missingfindagent find the leakAlso:
update/usage,make/me,explain/template,look/hook,list/host,mock/hook,lint/ping,delete/template.Known gap, left in deliberately
agent sesion liststill starts a session. I prototyped the obvious fix, a near-miss first word plus a known subcommand, and it false-positived onrevert list,audit list,test run, andport get. Refusing a real prompt is worse than missing a typo, so the single-token rule stands alone. Easy to revisit.Notes
-pand not quoting.similarCommandshelper 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 rungreen: 421 tests, 23 files. 13 new.tsc --noEmitclean.startAgentSessionand parsing real argv: unquoted, quoted, trailing flags, promptless.--, one word plus a flag.sesion,reveiw,instal,confgall blocked with exit 1;xyzzyblocked with no suggestion;session,sessions,--version,--helpdispatch unchanged;-p refactorand-- refactorboth get through.Verified by unit test and by
tsx src/cli.tsxrather than a live session, because the shorthand path hardcodes--connectand cannot run headless.