increased logging
This commit is contained in:
parent
2a57fcf4ab
commit
f49d61f14d
|
|
@ -242,8 +242,14 @@
|
||||||
|
|
||||||
// Log level selector
|
// Log level selector
|
||||||
const sel = root.querySelector('.rc-level');
|
const sel = root.querySelector('.rc-level');
|
||||||
sel.value = String(cfg().get('debug.level'));
|
const currentLevel = cfg().get('debug.level');
|
||||||
sel.addEventListener('change', () => log().setLevel(parseInt(sel.value, 10)));
|
sel.value = String(currentLevel);
|
||||||
|
log().trace(`[Debug Panel] Current log level: ${currentLevel}`);
|
||||||
|
sel.addEventListener('change', () => {
|
||||||
|
const newLevel = parseInt(sel.value, 10);
|
||||||
|
log().setLevel(newLevel);
|
||||||
|
log().info(`[Debug Panel] Log level changed to ${newLevel}`);
|
||||||
|
});
|
||||||
|
|
||||||
// Copy buttons
|
// Copy buttons
|
||||||
root.querySelector('.rc-copy').addEventListener('click', (e) => {
|
root.querySelector('.rc-copy').addEventListener('click', (e) => {
|
||||||
|
|
|
||||||
|
|
@ -41,73 +41,139 @@
|
||||||
this.clusterWindowMs = 1000;
|
this.clusterWindowMs = 1000;
|
||||||
}
|
}
|
||||||
start() {
|
start() {
|
||||||
|
if (this.observer) {
|
||||||
|
log().warn('[Detector] Already started, skipping');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log().info('[Detector] Starting advanced detector with settle/debounce');
|
||||||
|
|
||||||
this.observer = new MutationObserver((mutations) => {
|
this.observer = new MutationObserver((mutations) => {
|
||||||
if (cfg().get('runtime.paused')) return;
|
if (cfg().get('runtime.paused')) {
|
||||||
let should = false;
|
log().trace('[Detector] Mutations ignored (paused)');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let assistantMsgs = 0;
|
||||||
for (const m of mutations) {
|
for (const m of mutations) {
|
||||||
if (m.type === 'childList') {
|
if (m.type === 'childList') {
|
||||||
for (const n of m.addedNodes) {
|
for (const n of m.addedNodes) {
|
||||||
if (n.nodeType === 1 && isAssistantMsg(n)) { void this._handle(n); should = true; }
|
if (n.nodeType === 1 && isAssistantMsg(n)) {
|
||||||
|
assistantMsgs++;
|
||||||
|
void this._handle(n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m.type === 'characterData') {
|
if (m.type === 'characterData') {
|
||||||
const el = m.target?.parentElement;
|
const el = m.target?.parentElement;
|
||||||
if (el && isAssistantMsg(el)) should = true;
|
if (el && isAssistantMsg(el)) {
|
||||||
|
log().trace('[Detector] Text changed in assistant message');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (should) {/* no-op: _handle already queued */}
|
|
||||||
|
if (assistantMsgs > 0) {
|
||||||
|
log().verbose(`[Detector] Detected ${assistantMsgs} new assistant message(s)`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.observer.observe(document.body, { childList: true, subtree: true, characterData: true, attributes: true });
|
this.observer.observe(document.body, { childList: true, subtree: true, characterData: true, attributes: true });
|
||||||
|
log().verbose('[Detector] MutationObserver attached (childList, subtree, characterData, attributes)');
|
||||||
|
|
||||||
if (cfg().get('ui.processExisting')) {
|
if (cfg().get('ui.processExisting')) {
|
||||||
document.querySelectorAll('[data-message-author-role], .chat-message, .message-content')
|
log().verbose('[Detector] Processing existing messages on page');
|
||||||
.forEach(el => isAssistantMsg(el) && void this._handle(el));
|
const nodes = document.querySelectorAll('[data-message-author-role], .chat-message, .message-content');
|
||||||
|
log().trace(`[Detector] Found ${nodes.length} potential message nodes`);
|
||||||
|
nodes.forEach(el => {
|
||||||
|
if (isAssistantMsg(el)) {
|
||||||
|
void this._handle(el);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
log().info('Detector started');
|
|
||||||
|
log().info('[Detector] Detector started and monitoring');
|
||||||
}
|
}
|
||||||
|
|
||||||
async _handle(el) {
|
async _handle(el) {
|
||||||
if (this.processed.has(el)) return;
|
if (this.processed.has(el)) {
|
||||||
|
log().trace('[Detector] Message already processed by detector');
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.processed.add(el);
|
this.processed.add(el);
|
||||||
|
|
||||||
|
log().verbose('[Detector] Processing new assistant message');
|
||||||
|
|
||||||
// Debounce complete generation
|
// Debounce complete generation
|
||||||
const debounce = cfg().get('execution.debounceDelay') || 0;
|
const debounce = cfg().get('execution.debounceDelay') || 0;
|
||||||
if (debounce > 0) await new Promise(r => setTimeout(r, debounce));
|
if (debounce > 0) {
|
||||||
|
log().trace(`[Detector] Debouncing for ${debounce}ms`);
|
||||||
|
await new Promise(r => setTimeout(r, debounce));
|
||||||
|
}
|
||||||
|
|
||||||
// Settle
|
// Settle
|
||||||
const baseText = el.textContent || '';
|
const baseText = el.textContent || '';
|
||||||
|
log().trace('[Detector] Starting text settle check', { textLength: baseText.length });
|
||||||
const stable = await settleText(el, baseText, cfg().get('execution.settleCheckMs') || 1200, cfg().get('execution.settlePollMs') || 250);
|
const stable = await settleText(el, baseText, cfg().get('execution.settleCheckMs') || 1200, cfg().get('execution.settlePollMs') || 250);
|
||||||
|
|
||||||
const blocks = extractAllBlocks(stable);
|
const blocks = extractAllBlocks(stable);
|
||||||
if (!blocks.length) { this.processed.delete(el); return; } // not a command after all
|
log().verbose(`[Detector] Found ${blocks.length} command block(s) after settling`);
|
||||||
|
|
||||||
|
if (!blocks.length) {
|
||||||
|
log().trace('[Detector] No command blocks found, removing from processed set');
|
||||||
|
this.processed.delete(el);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const maxPerMsg = cfg().get('queue.maxPerMessage') || 5;
|
const maxPerMsg = cfg().get('queue.maxPerMessage') || 5;
|
||||||
blocks.slice(0, maxPerMsg).forEach((cmdText, idx) => this._enqueueOne(el, cmdText, idx));
|
if (blocks.length > maxPerMsg) {
|
||||||
|
log().warn(`[Detector] Message has ${blocks.length} commands, limiting to ${maxPerMsg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
blocks.slice(0, maxPerMsg).forEach((cmdText, idx) => {
|
||||||
|
log().verbose(`[Detector] Enqueueing command #${idx + 1}`);
|
||||||
|
this._enqueueOne(el, cmdText, idx);
|
||||||
|
});
|
||||||
|
|
||||||
// Cluster rescan: look ahead a few assistant messages for chained blocks
|
// Cluster rescan: look ahead a few assistant messages for chained blocks
|
||||||
|
log().trace(`[Detector] Scheduling cluster rescan in ${this.clusterWindowMs}ms`);
|
||||||
setTimeout(() => this._clusterRescan(el), this.clusterWindowMs);
|
setTimeout(() => this._clusterRescan(el), this.clusterWindowMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
_enqueueOne(el, commandText, idx) {
|
_enqueueOne(el, commandText, idx) {
|
||||||
const history = window.AI_REPO_HISTORY;
|
const history = window.AI_REPO_HISTORY;
|
||||||
|
|
||||||
if (history.isProcessed(el, idx)) {
|
if (history.isProcessed(el, idx)) {
|
||||||
|
log().verbose(`[Detector] Command #${idx + 1} already processed, adding retry button`);
|
||||||
this._addRunAgain(el, commandText, idx);
|
this._addRunAgain(el, commandText, idx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log().trace(`[Detector] Marking command #${idx + 1} as processed in history`);
|
||||||
history.markProcessed(el, idx);
|
history.markProcessed(el, idx);
|
||||||
|
|
||||||
|
log().verbose(`[Detector] Pushing command #${idx + 1} to queue`);
|
||||||
window.AI_REPO_QUEUE.push(async () => {
|
window.AI_REPO_QUEUE.push(async () => {
|
||||||
try {
|
try {
|
||||||
|
log().trace(`[Detector] Parsing command #${idx + 1}`);
|
||||||
const parsed = window.AI_REPO_PARSER.parse(commandText);
|
const parsed = window.AI_REPO_PARSER.parse(commandText);
|
||||||
|
log().verbose(`[Detector] Parsed: ${parsed.action}`, { repo: parsed.repo, path: parsed.path });
|
||||||
|
|
||||||
const v = window.AI_REPO_PARSER.validate(parsed);
|
const v = window.AI_REPO_PARSER.validate(parsed);
|
||||||
if (!v.isValid) {
|
if (!v.isValid) {
|
||||||
// Handle validation failures inline instead of throwing; avoid local throw/catch
|
log().warn('[Detector] Validation failed', { errors: v.errors, action: parsed.action });
|
||||||
try { log().warn?.('Validation failed', { errors: v.errors }); } catch {}
|
|
||||||
this._addRunAgain(el, commandText, idx);
|
this._addRunAgain(el, commandText, idx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (v.example) { log().info('Example command skipped'); return; }
|
|
||||||
|
if (v.example) {
|
||||||
|
log().info('[Detector] Example command skipped', { action: parsed.action });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log().verbose(`[Detector] Executing command #${idx + 1}: ${parsed.action}`);
|
||||||
await window.AI_REPO_EXECUTOR.execute(parsed, el, `[${idx + 1}] ${parsed.action}`);
|
await window.AI_REPO_EXECUTOR.execute(parsed, el, `[${idx + 1}] ${parsed.action}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log().error('Command failed', { error: e.message });
|
log().error('[Detector] Command execution failed', { error: e.message, stack: e.stack?.slice(0, 150) });
|
||||||
this._addRunAgain(el, commandText, idx);
|
this._addRunAgain(el, commandText, idx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
setLevel(n) {
|
setLevel(n) {
|
||||||
const lv = Math.max(0, Math.min(4, n));
|
const lv = Math.max(0, Math.min(5, n));
|
||||||
this.config.set('debug.level', lv);
|
this.config.set('debug.level', lv);
|
||||||
this.info(`Log level => ${lv}`);
|
this.info(`Log level => ${lv}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue