From a580639abfc4ff00f1ec1c73dd5eae95391de8a5 Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Sat, 10 Jan 2026 21:59:28 +0000 Subject: [PATCH] fix(agents): strip and tags from output --- src/agents/pi-embedded-subscribe.ts | 8 ++++---- src/agents/pi-embedded-utils.ts | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/agents/pi-embedded-subscribe.ts b/src/agents/pi-embedded-subscribe.ts index 1c92d65e89..a48a2de71c 100644 --- a/src/agents/pi-embedded-subscribe.ts +++ b/src/agents/pi-embedded-subscribe.ts @@ -32,10 +32,10 @@ import { promoteThinkingTagsToBlocks, } from "./pi-embedded-utils.js"; -const THINKING_TAG_RE = /<\s*\/?\s*think(?:ing)?\s*>/gi; -const THINKING_OPEN_RE = /<\s*think(?:ing)?\s*>/i; -const THINKING_CLOSE_RE = /<\s*\/\s*think(?:ing)?\s*>/i; -const THINKING_TAG_SCAN_RE = /<\s*(\/?)\s*think(?:ing)?\s*>/gi; +const THINKING_TAG_RE = /<\s*\/?\s*(?:think(?:ing)?|thought|antthinking)\s*>/gi; +const THINKING_OPEN_RE = /<\s*(?:think(?:ing)?|thought|antthinking)\s*>/i; +const THINKING_CLOSE_RE = /<\s*\/\s*(?:think(?:ing)?|thought|antthinking)\s*>/i; +const THINKING_TAG_SCAN_RE = /<\s*(\/?)\s*(?:think(?:ing)?|thought|antthinking)\s*>/gi; const TOOL_RESULT_MAX_CHARS = 8000; const log = createSubsystemLogger("agent/embedded"); const RAW_STREAM_ENABLED = process.env.CLAWDBOT_RAW_STREAM === "1"; diff --git a/src/agents/pi-embedded-utils.ts b/src/agents/pi-embedded-utils.ts index 370be2d4e8..f52ccbe40c 100644 --- a/src/agents/pi-embedded-utils.ts +++ b/src/agents/pi-embedded-utils.ts @@ -52,12 +52,12 @@ export function splitThinkingTaggedText( // with a think tag (common for local/OpenAI-compat providers that emulate // reasoning blocks via tags). if (!trimmedStart.startsWith("<")) return null; - const openRe = /<\s*think(?:ing)?\s*>/i; - const closeRe = /<\s*\/\s*think(?:ing)?\s*>/i; + const openRe = /<\s*(?:think(?:ing)?|thought|antthinking)\s*>/i; + const closeRe = /<\s*\/\s*(?:think(?:ing)?|thought|antthinking)\s*>/i; if (!openRe.test(trimmedStart)) return null; if (!closeRe.test(text)) return null; - const scanRe = /<\s*(\/?)\s*think(?:ing)?\s*>/gi; + const scanRe = /<\s*(\/?)\s*(?:think(?:ing)?|thought|antthinking)\s*>/gi; let inThinking = false; let cursor = 0; let thinkingStart = 0; @@ -136,7 +136,7 @@ export function promoteThinkingTagsToBlocks(message: AssistantMessage): void { export function extractThinkingFromTaggedText(text: string): string { if (!text) return ""; - const scanRe = /<\s*(\/?)\s*think(?:ing)?\s*>/gi; + const scanRe = /<\s*(\/?)\s*(?:think(?:ing)?|thought|antthinking)\s*>/gi; let result = ""; let lastIndex = 0; let inThinking = false; @@ -157,8 +157,8 @@ export function extractThinkingFromTaggedStream(text: string): string { const closed = extractThinkingFromTaggedText(text); if (closed) return closed; - const openRe = /<\s*think(?:ing)?\s*>/gi; - const closeRe = /<\s*\/\s*think(?:ing)?\s*>/gi; + const openRe = /<\s*(?:think(?:ing)?|thought|antthinking)\s*>/gi; + const closeRe = /<\s*\/\s*(?:think(?:ing)?|thought|antthinking)\s*>/gi; const openMatches = [...text.matchAll(openRe)]; if (openMatches.length === 0) return ""; const closeMatches = [...text.matchAll(closeRe)];