MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / stripThinkingForDisplay

Function stripThinkingForDisplay

src/llm/thinking.ts:89–103  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

87 * render. For append-only stdout streams use {@link StreamDisplayFilter} instead.
88 */
89export function stripThinkingForDisplay(text: string): string {
90 if (!text) return text;
91 // Fast path: no tags to extract, but STILL collapse runaway blank lines and
92 // trim. Some local models emit long runs of newlines before their answer;
93 // without this they'd render as a huge gap (the old early-return skipped it).
94 if (!text.includes('<')) {
95 return text.replace(/\n{3,}/g, '\n\n').replace(/^\s+/, '');
96 }
97 let s = extractThinking(text).visibleText;
98 // An unclosed block mid-stream: cut from the opening tag to the end, dropping the
99 // now-dangling whitespace that preceded it.
100 const open = s.match(/<(thinking|think|reasoning|reflection)>[\s\S]*$/i);
101 if (open && open.index !== undefined) s = s.slice(0, open.index).trimEnd();
102 return trimTrailingPartialTag(s);
103}
104
105// Tag-delimited spans we suppress from display. Two kinds leak from local models that
106// emit tool calls (or reasoning) as plain text instead of via the structured field:

Callers 2

AppFunction · 0.85

Calls 2

extractThinkingFunction · 0.85
trimTrailingPartialTagFunction · 0.85

Tested by

no test coverage detected