From 8317ee82a0a4677164beaa3bc38949752d57c4a2 Mon Sep 17 00:00:00 2001 From: Tom <37050939+tomolom@users.noreply.github.com> Date: Sat, 11 Apr 2026 06:30:59 +0100 Subject: [PATCH] fix: preserve redacted thinking blocks during reasoning cleanup Avoid stripping Anthropic redacted_thinking parts during stripClearedReasoning and add regression coverage for the preserved assistant content path. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../hooks/magic-context/strip-content.test.ts | 20 +++++++++++++++++++ .../src/hooks/magic-context/strip-content.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/plugin/src/hooks/magic-context/strip-content.test.ts b/packages/plugin/src/hooks/magic-context/strip-content.test.ts index 09794ee..1db6157 100644 --- a/packages/plugin/src/hooks/magic-context/strip-content.test.ts +++ b/packages/plugin/src/hooks/magic-context/strip-content.test.ts @@ -193,6 +193,26 @@ describe("strip-content", () => { }); }); }); + + describe("#given assistant messages with redacted thinking parts", () => { + describe("#when stripping cleared reasoning", () => { + it("#then preserves redacted thinking blocks unchanged", () => { + const redactedPart = { + type: "redacted_thinking", + data: "opaque-provider-payload", + }; + const textPart = { type: "text", text: "visible response" }; + const msg = message("m-1", "assistant", [redactedPart, textPart]); + + const stripped = stripClearedReasoning([msg]); + + expect(stripped).toBe(0); + expect(msg.parts).toHaveLength(2); + expect(msg.parts[0]).toBe(redactedPart); + expect(msg.parts[1]).toBe(textPart); + }); + }); + }); }); describe("stripInlineThinking", () => { diff --git a/packages/plugin/src/hooks/magic-context/strip-content.ts b/packages/plugin/src/hooks/magic-context/strip-content.ts index 634daa9..5ae7344 100644 --- a/packages/plugin/src/hooks/magic-context/strip-content.ts +++ b/packages/plugin/src/hooks/magic-context/strip-content.ts @@ -279,7 +279,7 @@ function findMaxTag(messageTagNumbers: Map): number { return max; } -const CLEARED_REASONING_TYPES = new Set(["thinking", "reasoning", "redacted_thinking"]); +const CLEARED_REASONING_TYPES = new Set(["thinking", "reasoning"]); export function stripClearedReasoning(messages: MessageLike[]): number { let stripped = 0;