Skip to content

fix: stop re-tokenising the prompt body — flag-like words in briefs survive verbatim - #28

Merged
freema merged 2 commits into
freema:mainfrom
hrkzogw:fix/prompt-retokenise
Sep 3, 2026
Merged

freema merged 2 commits into
freema:mainfrom
hrkzogw:fix/prompt-retokenise

Conversation

@hrkzogw

@hrkzogw hrkzogw commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Problem

collapseCommandArgv re-splits everything after -- and feeds it back through parseArgv. Any --word inside the user's free text — a delegate brief, a review focus, or a browser test description — is consumed as a flag: it silently disappears from the prompt, and a non-boolean one also eats the next word as its "value".

/cursor:delegate Run the installer with --config custom.yaml --no-index then report

The brief that reaches cursor-agent has lost --config custom.yaml and --no-index, with no error and no visible trace. Long real-world briefs (install instructions, CLI reproduction steps) hit this constantly.

Fix

New collapsePromptArgv in lib/args.mjs with a leading-flags contract: only a leading run of flag tokens is parsed as flags; the first non-flag span ends flag parsing and everything from there on is kept as ONE verbatim positional — flag-like words, quotes and backslashes in the body survive untouched. A body that itself starts with -- can be forced verbatim with -- --.

  • delegate.mjs: switched to the new collapse; the prompt already travelled to the background worker via CURSOR_PLUGIN_CC_PROMPT env.
  • review.mjs: same switch for the focus text; the focus now also reaches the background worker over CURSOR_PLUGIN_CC_PROMPT instead of argv, so the re-spawn no longer collapses it a second time.
  • browser.mjs: same leading-flags contract; the verbatim rest is split at most once — the first span becomes the URL only when it looks like one, the remainder stays untouched as the description.
  • from-plan.mjs is intentionally unchanged: its positional is a file path, not free text.

Behaviour notes

  • Flags must precede the free text. A flag typed after the body is now part of the body (previously it was silently consumed — that was the bug).
  • Quotes inside the body are preserved verbatim (previously stripped by the re-split).

Tests

Regression tests for splitLeadingFlags / collapsePromptArgv (delegate and review shapes) and a behavioural browser test asserting --config / --no-index survive into the job prompt — all of them fail on the old implementation. Full suite: 168 tests, lint, typecheck green.

🤖 Generated with Claude Code

…vive verbatim

collapseCommandArgv re-split everything after -- and dropped the delimiter,
so parseArgv consumed flag-like words (--config, --no-index, %~dp0\bin …)
out of long briefs, with non-boolean flags eating the following word as a
value and backslash escapes mangling Windows-style paths.

Add collapsePromptArgv/splitLeadingFlags: only a leading run of flags is
parsed; the first non-flag span starts the verbatim body (raw slice — quotes
and backslashes intact). Consumed values are folded into --name=value so
parseArgv re-derives identical pairings. delegate.mjs switches to it;
id-style commands (status/result/cancel/setup) and from-plan/browser keep
the old collapse (they rely on trailing flags / positional splitting).
…e words survive verbatim

review.mjs: parse only a leading run of flags via collapsePromptArgv; the
focus text is one verbatim operand, and it now reaches the background
worker over CURSOR_PLUGIN_CC_PROMPT env (same contract as delegate.mjs)
instead of being re-collapsed from argv.

browser.mjs: same leading-flags contract; the verbatim rest is split at
most once — the first span becomes the URL only when it looks like one,
everything after it stays untouched as the description.
@freema
freema merged commit 7050401 into freema:main Sep 3, 2026
freema added a commit that referenced this pull request Sep 18, 2026
Cut the 0.6.2 changelog section covering #29 (closes #27) and #28 and
bump the version in package.json, package-lock.json, and plugin.json.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

2 participants