From 5ded27b0b15604d571a207d7fcd86fccc2efcd37 Mon Sep 17 00:00:00 2001 From: can1357 Date: Fri, 24 Jul 2026 01:19:29 +0200 Subject: [PATCH] fix(cli): stopped $-pattern expansion when injecting cache prefix --- packages/coding-agent/src/cli/bench-cli.ts | 4 +++- packages/coding-agent/test/bench-cache.test.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/coding-agent/src/cli/bench-cli.ts b/packages/coding-agent/src/cli/bench-cli.ts index 836890615..60b880083 100644 --- a/packages/coding-agent/src/cli/bench-cli.ts +++ b/packages/coding-agent/src/cli/bench-cli.ts @@ -352,7 +352,9 @@ function renderCacheBenchmarkPrefix(prefix: string, namespace: string): string { } // Render the static wrapper first, then inject caller bytes so prompt // normalization cannot trim spaces or collapse blank lines in prefix files. - return rendered.replace(CACHE_PREFIX_PLACEHOLDER, prefix); + // Function replacer: a prefix containing `$&`/`$'`/`` $` `` must not be + // expanded as a string-replacement pattern. + return rendered.replace(CACHE_PREFIX_PLACEHOLDER, () => prefix); } async function resolveCachePrefix( diff --git a/packages/coding-agent/test/bench-cache.test.ts b/packages/coding-agent/test/bench-cache.test.ts index 26cad8383..9bbb91af6 100644 --- a/packages/coding-agent/test/bench-cache.test.ts +++ b/packages/coding-agent/test/bench-cache.test.ts @@ -494,10 +494,10 @@ describe("bench cache mode", () => { expect(stablePrefixes[0]).not.toContain("\uFFFD"); }); - it("preserves significant whitespace from the default prefix-file reader", async () => { + it("preserves significant whitespace and replacement patterns from the default prefix-file reader", async () => { const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "omp-bench-cache-prefix-whitespace-")); const prefixPath = path.join(tempDir, "prefix.txt"); - const exactPrefix = "line one \n\n\nline two\t\n"; + const exactPrefix = "line one \n\n\n$& $' $` $$ line two\t\n"; const stablePrefixes: string[] = []; await Bun.write(prefixPath, exactPrefix); try {