From 91cf0418dab514b9904fdaf8a7c91a34d4983931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Andr=C3=A9?= Date: Tue, 6 Oct 2026 19:32:15 +0200 Subject: [PATCH] fix(prompt): resolve repeated root mentions without sentinels Resolve each @./ and @. mention directly in the shared prompt preparation helper. Previously every occurrence became a temporary root marker but only the first marker was restored, so later references could reach the model as ___ROOT___. Removing the sentinels also preserves literal marker text written by the user. Keep parent-path matching, attached-path handling and verbatim pasted content unchanged. Add regression checks for repeated references, pasted display metadata, message history, shell submission and slash-command arguments. The three new tests fail on the unchanged helper and pass with this fix; all 21 targeted tests and UI typechecking pass. --- .../prompt-input/submitPrompt.test.ts | 13 ++++++++++ .../src/lib/prompt-display-metadata.test.ts | 26 ++++++++++++++++++- .../ui/src/lib/prompt-display-metadata.ts | 7 ++--- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/components/prompt-input/submitPrompt.test.ts b/packages/ui/src/components/prompt-input/submitPrompt.test.ts index 4129b2db9..2d9e2c78e 100644 --- a/packages/ui/src/components/prompt-input/submitPrompt.test.ts +++ b/packages/ui/src/components/prompt-input/submitPrompt.test.ts @@ -15,6 +15,19 @@ describe("resolvePromptDelivery", () => { }) describe("preparePromptSubmission", () => { + it("resolves repeated root mentions in history, shell input and command arguments", () => { + const text = "@./a @./b @. @." + const expected = "./a ./b ./ ./" + + const message = preparePromptSubmission({ mode: "message", text, attachments: [] }) + assert.equal(message.historyEntry, expected) + assert.equal(message.submitPrompt, text) + assert.equal(preparePromptSubmission({ mode: "shell", text, attachments: [] }).submitPrompt, expected) + const command = preparePromptSubmission({ mode: "slash", text, attachments: [], commandToken: "/review", commandArgs: text }) + assert.equal(command.resolvedCommandArgs, expected) + assert.equal(command.submitPrompt, `/review ${expected}`) + }) + it("keeps placeholder-backed pasted text intact for message submission while resolving history text", () => { const attachment = createTextAttachment("alpha\nbeta\ngamma\ndelta", "pasted #1 (4 lines)", "paste-1.txt") diff --git a/packages/ui/src/lib/prompt-display-metadata.test.ts b/packages/ui/src/lib/prompt-display-metadata.test.ts index 0a59cd65e..4114399d2 100644 --- a/packages/ui/src/lib/prompt-display-metadata.test.ts +++ b/packages/ui/src/lib/prompt-display-metadata.test.ts @@ -1,10 +1,34 @@ import assert from "node:assert/strict" import { describe, it } from "node:test" -import { createTextAttachment } from "../types/attachment" +import { createFileAttachment, createTextAttachment } from "../types/attachment" import { preparePromptDisplayText, resolvePastedPlaceholders, splitPromptDisplaySections } from "./prompt-display-metadata" describe("preparePromptDisplayText", () => { + it("resolves every root mention without changing parent paths or literal marker text", () => { + const prompt = "@./a @./b @. @. @.. @../c ___ROOT___ ___ROOT_NOSLASH___" + const expected = "./a ./b ./ ./ @.. @../c ___ROOT___ ___ROOT_NOSLASH___" + const attachments = [createFileAttachment("./a", "a"), createTextAttachment(".", "path:.", ".")] + + assert.equal(resolvePastedPlaceholders(prompt, attachments), expected) + assert.equal(preparePromptDisplayText(prompt, attachments).promptToSend, expected) + }) + + it("preserves pasted text and display sections alongside repeated root mentions", () => { + const pasted = "@./verbatim ___ROOT___ ___ROOT_NOSLASH___" + const attachment = createTextAttachment(pasted, "pasted #1", "paste-1.txt") + const prompt = "@./a @./b\n[pasted #1]\n@. @." + const prepared = preparePromptDisplayText(prompt, [attachment]) + + assert.equal(prepared.promptToSend, `./a ./b\n${pasted}\n./ ./`) + assert.equal(resolvePastedPlaceholders(prompt, [attachment]), prepared.promptToSend) + assert.deepEqual(splitPromptDisplaySections(prepared.promptToSend, prepared.displayMetadata), [ + { kind: "inline", text: "./a ./b\n" }, + { kind: "pasted", text: pasted }, + { kind: "inline", text: "\n./ ./" }, + ]) + }) + it("keeps pasted text fully visible to the model while storing display metadata", () => { const attachment = createTextAttachment("line 1\nline 2\nline 3\nline 4", "pasted #1 (4 lines)", "paste-1.txt") diff --git a/packages/ui/src/lib/prompt-display-metadata.ts b/packages/ui/src/lib/prompt-display-metadata.ts index 9f1fa46cb..e49e6d54b 100644 --- a/packages/ui/src/lib/prompt-display-metadata.ts +++ b/packages/ui/src/lib/prompt-display-metadata.ts @@ -67,8 +67,8 @@ function resolvePathMentions(prompt: string, attachments: Attachment[] = []): st let result = prompt - result = result.replace(/@(\.\/)/g, "___ROOT___") - result = result.replace(/@(\.)(?!\.)/g, "___ROOT_NOSLASH___") + result = result.replace(/@(\.\/)/g, "./") + result = result.replace(/@(\.)(?!\.)/g, "./") const allPaths = new Set() for (const path of fileAttachments) { @@ -85,9 +85,6 @@ function resolvePathMentions(prompt: string, attachments: Attachment[] = []): st result = result.replace(`@${withoutPrefix}/`, `${withPrefix}/`) } - result = result.replace("___ROOT___", "./") - result = result.replace("___ROOT_NOSLASH___", "./") - return result }