MCPcopy Create free account
hub / github.com/freecodexyz/free-code / findThinkingTriggerPositions

Function findThinkingTriggerPositions

src/utils/thinking.ts:36–58  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

34 * Find positions of "ultrathink" keyword in text (for UI highlighting/notification)
35 */
36export function findThinkingTriggerPositions(text: string): Array<{
37 word: string
38 start: number
39 end: number
40}> {
41 const positions: Array<{ word: string; start: number; end: number }> = []
42 // Fresh /g literal each call — String.prototype.matchAll copies lastIndex
43 // from the source regex, so a shared instance would leak state from
44 // hasUltrathinkKeyword's .test() into this call on the next render.
45 const matches = text.matchAll(/\bultrathink\b/gi)
46
47 for (const match of matches) {
48 if (match.index !== undefined) {
49 positions.push({
50 word: match[0],
51 start: match.index,
52 end: match.index + match[0].length,
53 })
54 }
55 }
56
57 return positions
58}
59
60const RAINBOW_COLORS: Array<keyof Theme> = [
61 'rainbow_red',

Callers 2

HighlightedThinkingTextFunction · 0.85
PromptInputFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected