mirror of
https://github.com/NeuralNomadsAI/CodeNomad.git
synced 2026-11-17 05:49:28 +00:00
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.
This commit is contained in:
parent
86dd9e80c8
commit
91cf0418da
3 changed files with 40 additions and 6 deletions
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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<string>()
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue