From 4eba8adc5105b0aa016d6b97618cca3e09f47cc8 Mon Sep 17 00:00:00 2001 From: bjoern Date: Tue, 10 Feb 2026 17:52:45 +0100 Subject: [PATCH] Strip system-reminder blocks before smart tool selection classification Problem: The CLI injects blocks into user messages containing keywords like "search", "explain", and "documentation". The smart selection classifier was scanning the full message content including these injected blocks, causing it to misclassify requests based on keywords that the user never typed. For example, a simple greeting could be classified as a "research" request because the system-reminder block contained the word "search". Changes implemented: 1. System-reminder stripping (src/tools/smart-selection.js) - Added pre-compiled SYSTEM_REMINDER_PATTERN regex to match ... blocks - Strip these blocks from message content before running classification - Pattern is compiled once at module load for performance - Only affects classification input; original message is unchanged Testing: - Messages with system-reminder blocks now classify based on actual user content - Simple greetings no longer misclassified as research/coding requests - Messages without system-reminder blocks behave identically to before - npm run test:unit passes with no regressions --- src/tools/smart-selection.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tools/smart-selection.js b/src/tools/smart-selection.js index 731e7be..67628ce 100644 --- a/src/tools/smart-selection.js +++ b/src/tools/smart-selection.js @@ -9,6 +9,9 @@ const logger = require('../logger'); +// Strip system-reminder blocks injected by the CLI before classification +const SYSTEM_REMINDER_PATTERN = /[\s\S]*?<\/system-reminder>/g; + // Pre-compiled regex patterns for performance (avoid recompiling on every request) const GREETING_PATTERN = /^(hi|hello|hey|good morning|good afternoon|good evening|howdy|greetings|sup|yo)[\s\.\!\?]*$/i; const QUESTION_PATTERN = /^(what is|what's|how does|when|where|why|explain|define|tell me about|can you explain)/i; @@ -190,7 +193,10 @@ function classifyRequestType(payload) { return { type: 'coding', confidence: 0.5, keywords: [] }; } - const content = extractContent(lastMessage); + const rawContent = extractContent(lastMessage); + // Strip blocks before classification to prevent + // CLI-injected keywords (search, explain, documentation) from polluting results + const content = rawContent.replace(SYSTEM_REMINDER_PATTERN, '').trim(); const contentLower = content.toLowerCase(); const messageCount = payload.messages?.length ?? 0;