From bd4e82c12cb9dddf0d92f7f02447734228ed2ed6 Mon Sep 17 00:00:00 2001 From: Hao19911125 <99091644+Hao19911125@users.noreply.github.com> Date: Mon, 6 Apr 2026 09:13:36 +0800 Subject: [PATCH] Add diagnostic logging for user-block fallback in prompt builder When user-role blocks are missing from executionMessages, logs details about where content was lost (sanitization, blockedContents, etc.) to help diagnose why custom extract prompt falls back to hardcoded default. Co-Authored-By: Claude Opus 4.6 --- prompt-builder.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/prompt-builder.js b/prompt-builder.js index ed727b4..8c9b924 100644 --- a/prompt-builder.js +++ b/prompt-builder.js @@ -1137,7 +1137,19 @@ export async function buildTaskPrompt(settings = {}, taskType, context = {}) { } content = sanitizedBlockContent.text; - if (!String(content || "").trim()) continue; + if (!String(content || "").trim()) { + if (role === "user" && String(block.content || "").trim()) { + console.warn( + `[ST-BME] buildTaskPrompt: user block "${block.name || block.id}" ` + + `content emptied during sanitization! ` + + `original length=${String(block.content || "").length}, ` + + `dropped=${sanitizedBlockContent.dropped}, ` + + `reasons=[${(sanitizedBlockContent.reasons || []).join(", ")}], ` + + `blockedHitCount=${sanitizedBlockContent.blockedHitCount}`, + ); + } + continue; + } const mode = normalizeInjectionMode(block.injectionMode); renderedBlocks.push({ @@ -1361,6 +1373,39 @@ export function buildTaskLlmPayload(promptBuild = null, fallbackUserPrompt = "") const hasUserMessage = executionMessages.some( (message) => message.role === "user", ); + if (!hasUserMessage && rawExecutionMessages.length > 0) { + const userBlocksBefore = (promptBuild?.executionMessages || []).filter( + (m) => m?.role === "user", + ); + const userBlocksAfterRaw = rawExecutionMessages.filter( + (m) => m?.role === "user", + ); + const userBlocksAfterSanitize = executionMessages.filter( + (m) => m?.role === "user", + ); + console.warn( + `[ST-BME] buildTaskLlmPayload fallback triggered: ` + + `user blocks in promptBuild=${userBlocksBefore.length}, ` + + `after recreate=${userBlocksAfterRaw.length}, ` + + `after sanitize=${userBlocksAfterSanitize.length}, ` + + `blockedContents count=${blockedContents.length}, ` + + `total executionMessages=${executionMessages.length}`, + ); + if (userBlocksBefore.length > 0) { + for (const block of userBlocksBefore) { + console.warn( + `[ST-BME] user block "${block.blockName || block.blockId}": ` + + `content length=${String(block.content || "").length}, ` + + `content preview="${String(block.content || "").slice(0, 80)}..."`, + ); + } + } + if (blockedContents.length > 0) { + console.warn( + `[ST-BME] blockedContents lengths: [${blockedContents.map((c) => String(c || "").length).join(", ")}]`, + ); + } + } const sanitizedFallbackUserPrompt = sanitizeTaskPromptText( {}, promptBuild?.debug?.taskType || "",