MCPcopy Create free account
hub / github.com/cortexkit/magic-context / extractUserPromptText

Function extractUserPromptText

packages/pi-plugin/src/auto-search-pi.ts:181–202  ·  view source on GitHub ↗
(message: UserMessage)

Source from the content-addressed store, hash-verified

179}
180
181function extractUserPromptText(message: UserMessage): string {
182 return (
183 stripNestedSystemReminders(collectUserPromptParts(message))
184 // HTML comments — covers temporal markers, OMO/ALFONSO internal
185 // initiators, and any other commented-out extension markup.
186 .replace(/<!--[\s\S]*?-->/g, "")
187 // Plugin-owned injected blocks should be removed with their content.
188 .replace(/<ctx-search-hint>[\s\S]*?<\/ctx-search-hint>/g, "")
189 .replace(/<ctx-search-auto>[\s\S]*?<\/ctx-search-auto>/g, "")
190 .replace(/<instruction[^>]*>[\s\S]*?<\/instruction>/g, "")
191 .replace(/<sidekick-augmentation>[\s\S]*?<\/sidekick-augmentation>/g, "")
192 // Generic XML/HTML tags — opening, closing, and self-closing.
193 // Preserve text between paired tags so pasted content still embeds.
194 .replace(/<\/?[a-zA-Z][^<>]*>/g, "")
195 // Magic Context tag prefix: "§123§ " at any position.
196 .replace(/§\d+§\s*/g, "")
197 // Collapse whitespace runs that the strippings may leave behind.
198 .replace(/[ \t]+\n/g, "\n")
199 .replace(/\n{3,}/g, "\n\n")
200 .trim()
201 );
202}
203
204function findLatestMeaningfulUserMessage(
205 messages: AgentMessage[],

Callers 1

runAutoSearchHintForPiFunction · 0.70

Calls 2

collectUserPromptPartsFunction · 0.70

Tested by

no test coverage detected