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

Function appendHintToUserMessage

packages/pi-plugin/src/auto-search-pi.ts:240–265  ·  view source on GitHub ↗
(message: UserMessage, hint: string)

Source from the content-addressed store, hash-verified

238}
239
240function appendHintToUserMessage(message: UserMessage, hint: string): boolean {
241 if (hint.length === 0) return false;
242
243 const rawText = collectUserPromptParts(message);
244 if (rawText.includes(hint) || rawText.includes("<ctx-search-hint>")) {
245 return false;
246 }
247
248 if (typeof message.content === "string") {
249 message.content += hint;
250 return true;
251 }
252
253 const firstTextIndex = message.content.findIndex(
254 (part) => part.type === "text",
255 );
256 if (firstTextIndex >= 0) {
257 const part = message.content[firstTextIndex];
258 if (part?.type !== "text") return false;
259 message.content[firstTextIndex] = { ...part, text: part.text + hint };
260 return true;
261 }
262
263 message.content.push({ type: "text", text: hint.trimStart() });
264 return true;
265}
266
267/**
268 * Run Pi auto-search hinting against the latest meaningful user message.

Callers 2

runAutoSearchHintForPiFunction · 0.85
writeNoHintAndReconcileFunction · 0.85

Calls 1

collectUserPromptPartsFunction · 0.70

Tested by

no test coverage detected