From 3b6c6d8bb9a41e163391ea09aebee7cb90ff668d Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 14 Oct 2025 00:13:27 +0000 Subject: [PATCH] Update src/ai-repo-commander.user.js Added a bunch of new debug code. Fixed bug - new commands were getting debouncing errors. --- src/ai-repo-commander.user.js | 83 +++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/src/ai-repo-commander.user.js b/src/ai-repo-commander.user.js index 79365f3..db6076d 100644 --- a/src/ai-repo-commander.user.js +++ b/src/ai-repo-commander.user.js @@ -2134,6 +2134,10 @@ findCommandInCodeBlock(el) { const blocks = el.querySelectorAll('pre code, pre, code'); + // 🔍 LOG: What we found + RC_DEBUG?.trace('🔍 DOM: Searching for command block', { + blocksFound: blocks.length + }); for (const b of blocks) { const txt = (b.textContent || '').trim(); if (this.isCompleteCommandText(txt)) { @@ -2304,10 +2308,17 @@ let deadline = Date.now() + Math.max(0, CONFIG.SETTLE_CHECK_MS); let last = initialText; + RC_DEBUG?.info('🔵 SETTLE: Starting stability check', { + messageId, + initialLength: initialText.length, + initialPreview: initialText.substring(0, 100), + settleWindow: CONFIG.SETTLE_CHECK_MS + }); + while (Date.now() < deadline) { const rec = this.trackedMessages.get(messageId); if (!rec || rec.cancelToken?.cancelled) { - RC_DEBUG?.warn('Settle cancelled', { messageId }); + RC_DEBUG?.warn('🔴 SETTLE: Cancelled', { messageId }); return ''; } @@ -2318,20 +2329,47 @@ const hit = this.findCommandInCodeBlock(element); const txt = hit ? hit.text : ''; + RC_DEBUG?.trace('🔵 SETTLE: Poll iteration', { + messageId, + foundCommand: !!hit, + textLength: txt.length, + textPreview: txt.substring(0, 80), + isComplete: this.isCompleteCommandText(txt), + unchanged: txt === last, + timeRemaining: deadline - Date.now() + }); + if (!txt || !this.isCompleteCommandText(txt)) { + RC_DEBUG?.verbose('🟡 SETTLE: Command not complete yet', { + messageId, + hasText: !!txt, + isComplete: this.isCompleteCommandText(txt) + }); continue; } if (txt === last) { - // stable; keep waiting + RC_DEBUG?.trace('🟢 SETTLE: Text stable, continuing wait', { messageId }); } else { + RC_DEBUG?.info('🟡 SETTLE: Text changed, resetting deadline', { + messageId, + oldLength: last.length, + newLength: txt.length, + newDeadline: CONFIG.SETTLE_CHECK_MS + }); last = txt; deadline = Date.now() + Math.max(0, CONFIG.SETTLE_CHECK_MS); } } - const finalHit = this.findCommandInCodeBlock(element); - return finalHit ? finalHit.text : ''; + // 🔧 FIX: Return the stable text we verified, not a new DOM lookup + RC_DEBUG?.info('🔵 SETTLE: Deadline reached, returning stable text', { + messageId, + stableTextLength: last.length, + stablePreview: last.substring(0, 100) + }); + + return last; // ← FIXED: Return what we verified as stable } attachRetryUI(element, messageId) { @@ -2396,6 +2434,12 @@ let parsed; try { parsed = CommandParser.parseYAMLCommand(message.originalText); + // 🔍 LOG: Parsed successfully + RC_DEBUG?.verbose('✅ PARSE: Success', { + messageId, + action: parsed.action, + textLength: message.originalText.length + }); } catch (err) { RC_DEBUG?.error(`Command parsing failed: ${err.message}`, { messageId }); this.updateState(messageId, COMMAND_STATES.ERROR); @@ -2430,15 +2474,46 @@ // 3) Debounce this.updateState(messageId, COMMAND_STATES.DEBOUNCING); const before = message.originalText; + // 🔍 LOG: Before debounce + RC_DEBUG?.info('⏳ DEBOUNCE: Starting wait', { + messageId, + delay: CONFIG.DEBOUNCE_DELAY, + textLength: before.length, + isAlreadyComplete: this.isCompleteCommandText(before) + }); await this.debounceWithCancel(messageId); if (message.cancelToken?.cancelled) { RC_DEBUG?.warn('Operation cancelled after debounce', { messageId }); return; } + // 🔍 LOG: Before settle + RC_DEBUG?.info('🔵 Starting settle check', { + messageId, + beforeTextLength: before.length, + beforePreview: before.substring(0, 100) + }); const stable = await this.waitForStableCompleteBlock(message.element, before, messageId); + // 🔍 LOG: After settle - THIS IS THE KEY ONE + RC_DEBUG?.info('🔵 SETTLE: Returned from stability check', { + messageId, + beforeTextLength: before.length, + stableTextLength: stable.length, + stablePreview: stable.substring(0, 100), + isEmpty: !stable, + textChanged: stable !== before + }); if (!stable) { + // 🔍 LOG: This is where your error happens + RC_DEBUG?.error('❌ SETTLE: Returned empty string - FAILING', { + messageId, + originalTextLength: before.length, + originalPreview: before.substring(0, 100), + // This will help us understand WHY it's empty + elementStillExists: !!message.element, + elementHasCodeBlocks: message.element?.querySelectorAll('pre code, pre, code').length + }); this.updateState(messageId, COMMAND_STATES.ERROR); return; }