Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions lib/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,6 @@ export const stripHallucinations = (messages: WithParts[], format: IdFormat = "x
if (part.type === "text" && typeof part.text === "string") {
part.text = stripHallucinationsFromString(part.text, format)
}

if (
part.type === "tool" &&
part.state?.status === "completed" &&
typeof part.state.output === "string"
) {
part.state.output = stripHallucinationsFromString(part.state.output, format)
}
}
}
}
24 changes: 23 additions & 1 deletion tests/message-priority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { injectMessageIds } from "../lib/messages/inject/inject"
import { applyAnchoredNudges } from "../lib/messages/inject/utils"
import { prune } from "../lib/messages/prune"
import { buildPriorityMap } from "../lib/messages/priority"
import { stripHallucinationsFromString } from "../lib/messages/utils"
import { stripHallucinations, stripHallucinationsFromString } from "../lib/messages/utils"
import { createSessionState, type WithParts } from "../lib/state"

function buildConfig(mode: "message" | "range" = "message"): PluginConfig {
Expand Down Expand Up @@ -845,6 +845,28 @@ test("hallucination stripping removes trailing mXXXX</parameter> artifact (issue
)
})

test("hallucination stripping keeps dcp tags in tool output (issue #657)", () => {
const sessionID = "ses_tool_output_tags"
const output = "AAA\n\n<dcp-system-reminder>\nHELLO-INSIDE\n</dcp-system-reminder>\n\nZZZ"
const messages: WithParts[] = [
buildMessage("msg-user-1", "user", sessionID, "cat /tmp/t.txt", 1),
{
info: {
id: "msg-assistant-1",
role: "assistant",
sessionID,
agent: "assistant",
time: { created: 2 },
} as WithParts["info"],
parts: [toolPart("msg-assistant-1", sessionID, "call-1", "bash", output)],
},
]

stripHallucinations(messages)

assert.equal((messages[1]?.parts[0] as any).state.output, output)
})

test("injectMessageIds skips empty assistant messages to avoid prefill (issue #463)", () => {
const sessionID = "ses_empty_assistant"
const messages: WithParts[] = [
Expand Down
2 changes: 1 addition & 1 deletion tests/v2-ids.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ test("V2 cleans echoed IDs and priorities before injecting correct protected/mes
] as WithParts["parts"]
stripHallucinations(raw, state.idFormat)
assert.equal((raw[1]!.parts[0] as any).text, "It’s 2026.\n")
assert.doesNotMatch(JSON.stringify(raw), /@94@|@b9@|@blocked@|\[high\]/)
assert.equal((raw[1]!.parts[1] as any).state.output, "Result @b9@ @blocked@")
const settings = config("message")
settings.compress.protectUserMessages = true
assignMessageRefs(state, raw)
Expand Down
Loading