diff --git a/lib/messages/utils.ts b/lib/messages/utils.ts index 004de9a5..14f05cf6 100644 --- a/lib/messages/utils.ts +++ b/lib/messages/utils.ts @@ -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) - } } } } diff --git a/tests/message-priority.test.ts b/tests/message-priority.test.ts index d6105eae..84519092 100644 --- a/tests/message-priority.test.ts +++ b/tests/message-priority.test.ts @@ -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 { @@ -845,6 +845,28 @@ test("hallucination stripping removes trailing mXXXX artifact (issue ) }) +test("hallucination stripping keeps dcp tags in tool output (issue #657)", () => { + const sessionID = "ses_tool_output_tags" + const output = "AAA\n\n\nHELLO-INSIDE\n\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[] = [ diff --git a/tests/v2-ids.test.ts b/tests/v2-ids.test.ts index eb1b5a32..eac6dd71 100644 --- a/tests/v2-ids.test.ts +++ b/tests/v2-ids.test.ts @@ -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)