Merge pull request 'Update src/ai-repo-commander.user.js' (#1) from changes into main

Reviewed-on: https://gitea.brrd.tech/rob/AI-Repo-Commander/pulls/1
This commit is contained in:
rob 2025-10-14 02:43:24 +00:00
commit d6f48cdeac
1 changed files with 79 additions and 4 deletions

View File

@ -2134,6 +2134,10 @@
findCommandInCodeBlock(el) { findCommandInCodeBlock(el) {
const blocks = el.querySelectorAll('pre code, pre, code'); 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) { for (const b of blocks) {
const txt = (b.textContent || '').trim(); const txt = (b.textContent || '').trim();
if (this.isCompleteCommandText(txt)) { if (this.isCompleteCommandText(txt)) {
@ -2304,10 +2308,17 @@
let deadline = Date.now() + Math.max(0, CONFIG.SETTLE_CHECK_MS); let deadline = Date.now() + Math.max(0, CONFIG.SETTLE_CHECK_MS);
let last = initialText; 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) { while (Date.now() < deadline) {
const rec = this.trackedMessages.get(messageId); const rec = this.trackedMessages.get(messageId);
if (!rec || rec.cancelToken?.cancelled) { if (!rec || rec.cancelToken?.cancelled) {
RC_DEBUG?.warn('Settle cancelled', { messageId }); RC_DEBUG?.warn('🔴 SETTLE: Cancelled', { messageId });
return ''; return '';
} }
@ -2318,20 +2329,47 @@
const hit = this.findCommandInCodeBlock(element); const hit = this.findCommandInCodeBlock(element);
const txt = hit ? hit.text : ''; 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)) { if (!txt || !this.isCompleteCommandText(txt)) {
RC_DEBUG?.verbose('🟡 SETTLE: Command not complete yet', {
messageId,
hasText: !!txt,
isComplete: this.isCompleteCommandText(txt)
});
continue; continue;
} }
if (txt === last) { if (txt === last) {
// stable; keep waiting RC_DEBUG?.trace('🟢 SETTLE: Text stable, continuing wait', { messageId });
} else { } else {
RC_DEBUG?.info('🟡 SETTLE: Text changed, resetting deadline', {
messageId,
oldLength: last.length,
newLength: txt.length,
newDeadline: CONFIG.SETTLE_CHECK_MS
});
last = txt; last = txt;
deadline = Date.now() + Math.max(0, CONFIG.SETTLE_CHECK_MS); deadline = Date.now() + Math.max(0, CONFIG.SETTLE_CHECK_MS);
} }
} }
const finalHit = this.findCommandInCodeBlock(element); // 🔧 FIX: Return the stable text we verified, not a new DOM lookup
return finalHit ? finalHit.text : ''; 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) { attachRetryUI(element, messageId) {
@ -2396,6 +2434,12 @@
let parsed; let parsed;
try { try {
parsed = CommandParser.parseYAMLCommand(message.originalText); parsed = CommandParser.parseYAMLCommand(message.originalText);
// 🔍 LOG: Parsed successfully
RC_DEBUG?.verbose('✅ PARSE: Success', {
messageId,
action: parsed.action,
textLength: message.originalText.length
});
} catch (err) { } catch (err) {
RC_DEBUG?.error(`Command parsing failed: ${err.message}`, { messageId }); RC_DEBUG?.error(`Command parsing failed: ${err.message}`, { messageId });
this.updateState(messageId, COMMAND_STATES.ERROR); this.updateState(messageId, COMMAND_STATES.ERROR);
@ -2430,15 +2474,46 @@
// 3) Debounce // 3) Debounce
this.updateState(messageId, COMMAND_STATES.DEBOUNCING); this.updateState(messageId, COMMAND_STATES.DEBOUNCING);
const before = message.originalText; 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); await this.debounceWithCancel(messageId);
if (message.cancelToken?.cancelled) { if (message.cancelToken?.cancelled) {
RC_DEBUG?.warn('Operation cancelled after debounce', { messageId }); RC_DEBUG?.warn('Operation cancelled after debounce', { messageId });
return; 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); 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) { 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); this.updateState(messageId, COMMAND_STATES.ERROR);
return; return;
} }