[Bug] Prompt templates alter literal dollar sequences in arguments #2106
Replies: 4 comments 2 replies
|
I’m taking a look at this. |
|
Hi, I reproduced this issue and have a fix ready following the suggested approach. I validated the root cause (JS replacement-string sequences + multi-pass substitution) and implemented the single-pass solution with a replacer function. Changes:
Validation:
Branch ready if maintainers would like an implementation invite. Happy to adjust scope before opening a PR. |
|
I can confirm this reproduction and have implemented the single-pass fix described. Happy to collaborate if maintainers approve implementation. Validation:
Implementation available at:
The core change replaces the multi-pass Thanks for the excellent bug analysis and reproduction case—made the fix straightforward to validate. |
|
Merged in #2128; this fix should be released in the next version |
Uh oh!
There was an error while loading. Please reload this page.
Affected area: Coding agent and CLI — prompt templates.
Prompt-template expansion changes literal dollar sequences in argument values. This can alter shell or JavaScript snippets supplied to a template:
$$becomes$,$&becomes the template placeholder, and$@can duplicate following arguments.Reproduced from source at
9c8230df67b378aaedc032f90e1ae8ba687cfe4a(currentmain, package version 0.9.3), on Ubuntu 24.04.4 LTS, aarch64, Node 26.8.1, npm 11.19.0, Bash 5.2.21 in a noninteractive shell. No model credentials or daemon are needed.From the repository root after
npm ci:['$$']Explain: $$Explain: $['$&']Explain: $&Explain: $ARGUMENTS['$@', 'tail']Explain: $@ tailExplain: $@ tail tailI also loaded an
explain.mdcontainingExplain: $ARGUMENTSwithloadPromptTemplatesand passed/explain $$,/explain $&, and/explain $@ tailthroughexpandPromptTemplate; they produce the same results. An ordinary-text control expands correctly.The current implementation says argument patterns remain literal. Its ordered replacement passes can process text inserted by an earlier pass, while the wildcard replacements also interpret JavaScript replacement-string sequences. The existing nonrecursive-substitution tests do not cover these cases.
Proposed scope, subject to maintainer invitation and contributor approval: substitute placeholders only in the original template and insert argument text literally, retaining existing positional, wildcard, and slice semantics. Add regression coverage for these examples, interactions between placeholder forms, and the loaded-template path, plus the required coding-agent changelog fragment.
Validation already run: all 81 existing tests pass with
npx tsx ../../node_modules/vitest/dist/cli.js --run test/prompt-templates.test.tsfrompackages/coding-agent; the separate reproduction confirms the gap. An approved fix would run that focused suite andnpm run check, with no live provider calls.I found no matching Discussion or issue, and no open PR changes the substitution implementation or its test file. No implementation changes have been made. I would like to take this scope if maintainers invite it and approve PR submission.
All reactions