Skip to content

Commit a3c2f84

Browse files
committed
fix(systemPrompts): scope Piebald-AI#664 backslash-doubling to quote contexts
PR Piebald-AI#664's backslash-doubler runs before every delimiter branch, including backticks. For template-literal content, escapeDepthZeroBackticks is already parity-aware for backticks, so pre-doubling turns `\`find\`` into `\` + closing backtick + `find`, terminating the template early and breaking cli.js parsing with "Expected CommonJS module to have a function wrapper" on load. Limit doubling to " and ' contexts. Affects Piebald-AI#660.
1 parent 98b4411 commit a3c2f84

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/patches/systemPrompts.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ export const applySystemPrompts = async (
152152
// Escape literal backslashes FIRST so they survive JS string
153153
// embedding. Without this, a markdown `\"user\"` ends up as `"user"`
154154
// because the backslash is consumed as an escape character. (#660)
155-
if (delimiter === '"' || delimiter === "'" || delimiter === '`') {
155+
// Backticks are excluded: escapeDepthZeroBackticks already uses a
156+
// parity-aware algorithm that treats preceding backslashes correctly,
157+
// so pre-doubling breaks `\`` sequences (which become `\\` + closing
158+
// backtick in a template literal, terminating the template early).
159+
if (delimiter === '"' || delimiter === "'") {
156160
replacementContent = replacementContent.replace(/\\/g, '\\\\');
157161
}
158162

0 commit comments

Comments
 (0)