惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
量子位
D
DataBreaches.Net
博客园 - 司徒正美
J
Java Code Geeks
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
B
Blog
The Cloudflare Blog
D
Docker
I
InfoQ
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
腾讯CDC
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
S
SegmentFault 最新的问题
GbyAI
GbyAI
有赞技术团队
有赞技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor(agents): dedupe thinking tag scanner · openclaw/...
obviyus · 2026-04-26 · via Recent Commits to openclaw:main

@@ -181,6 +181,25 @@ type ThinkTaggedSplitBlock =

181181

| { type: "thinking"; thinking: string }

182182

| { type: "text"; text: string };

183183184+

const THINKING_TAG_NAME_PATTERN = String.raw`(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)`;

185+

const THINKING_TAG_OPEN_RE = new RegExp(String.raw`<\s*${THINKING_TAG_NAME_PATTERN}\s*>`, "i");

186+

const THINKING_TAG_CLOSE_RE = new RegExp(

187+

String.raw`<\s*\/\s*${THINKING_TAG_NAME_PATTERN}\s*>`,

188+

"i",

189+

);

190+

const THINKING_TAG_OPEN_GLOBAL_RE = new RegExp(

191+

String.raw`<\s*${THINKING_TAG_NAME_PATTERN}\s*>`,

192+

"gi",

193+

);

194+

const THINKING_TAG_CLOSE_GLOBAL_RE = new RegExp(

195+

String.raw`<\s*\/\s*${THINKING_TAG_NAME_PATTERN}\s*>`,

196+

"gi",

197+

);

198+

export const THINKING_TAG_SCAN_RE = new RegExp(

199+

String.raw`<\s*(\/?)\s*${THINKING_TAG_NAME_PATTERN}\s*>`,

200+

"gi",

201+

);

202+184203

export function splitThinkingTaggedText(text: string): ThinkTaggedSplitBlock[] | null {

185204

const trimmedStart = text.trimStart();

186205

// Avoid false positives: only treat it as structured thinking when it begins

@@ -189,16 +208,13 @@ export function splitThinkingTaggedText(text: string): ThinkTaggedSplitBlock[] |

189208

if (!trimmedStart.startsWith("<")) {

190209

return null;

191210

}

192-

const openRe = /<\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\s*>/i;

193-

const closeRe = /<\s*\/\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\s*>/i;

194-

if (!openRe.test(trimmedStart)) {

211+

if (!THINKING_TAG_OPEN_RE.test(trimmedStart)) {

195212

return null;

196213

}

197-

if (!closeRe.test(text)) {

214+

if (!THINKING_TAG_CLOSE_RE.test(text)) {

198215

return null;

199216

}

200217201-

const scanRe = /<\s*(\/?)\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\s*>/gi;

202218

let inThinking = false;

203219

let cursor = 0;

204220

let thinkingStart = 0;

@@ -218,7 +234,7 @@ export function splitThinkingTaggedText(text: string): ThinkTaggedSplitBlock[] |

218234

blocks.push({ type: "thinking", thinking: cleaned });

219235

};

220236221-

for (const match of text.matchAll(scanRe)) {

237+

for (const match of text.matchAll(THINKING_TAG_SCAN_RE)) {

222238

const index = match.index ?? 0;

223239

const isClose = match[1]?.includes("/") ?? false;

224240

@@ -299,11 +315,10 @@ export function extractThinkingFromTaggedText(text: string): string {

299315

if (!text) {

300316

return "";

301317

}

302-

const scanRe = /<\s*(\/?)\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\s*>/gi;

303318

let result = "";

304319

let lastIndex = 0;

305320

let inThinking = false;

306-

for (const match of text.matchAll(scanRe)) {

321+

for (const match of text.matchAll(THINKING_TAG_SCAN_RE)) {

307322

const idx = match.index ?? 0;

308323

if (inThinking) {

309324

result += text.slice(lastIndex, idx);

@@ -324,13 +339,11 @@ export function extractThinkingFromTaggedStream(text: string): string {

324339

return closed;

325340

}

326341327-

const openRe = /<\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\s*>/gi;

328-

const closeRe = /<\s*\/\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\s*>/gi;

329-

const openMatches = [...text.matchAll(openRe)];

342+

const openMatches = [...text.matchAll(THINKING_TAG_OPEN_GLOBAL_RE)];

330343

if (openMatches.length === 0) {

331344

return "";

332345

}

333-

const closeMatches = [...text.matchAll(closeRe)];

346+

const closeMatches = [...text.matchAll(THINKING_TAG_CLOSE_GLOBAL_RE)];

334347

const lastOpen = openMatches[openMatches.length - 1];

335348

const lastClose = closeMatches[closeMatches.length - 1];

336349

if (lastClose && (lastClose.index ?? -1) > (lastOpen.index ?? -1)) {