diag(observer): v10-diag — extractContextFromNearby trail logging for context extraction failure analysis #task-619

This commit is contained in:
Variet Worker
2026-04-14 07:38:01 +09:00
parent a9c64e6716
commit 02d9799f20
4 changed files with 82 additions and 2 deletions

View File

@@ -110,12 +110,15 @@ export function generateApprovalObserverScript(_port: number): string {
}
// v9: Climb DOM tree to find pre/code content near the button (no data-step-index needed)
// v10-diag: Added diagnostic trail logging
function extractContextFromNearby(btn) {
var node = btn;
var _debugTrail = [];
for (var depth = 0; depth < 20 && node; depth++) {
if (!node.querySelector) { node = node.parentElement; continue; }
if (!node.querySelector) { _debugTrail.push('d'+depth+':noQS'); node = node.parentElement; continue; }
// Look for code/pre blocks (actual command text)
var codeEls = node.querySelectorAll('pre, code, [class*="terminal"]');
_debugTrail.push('d'+depth+':tag='+((node.tagName||'?').toLowerCase())+',cls='+(((typeof node.className==='string')?node.className:'').substring(0,60))+',codeEls='+codeEls.length);
for (var ci = 0; ci < codeEls.length; ci++) {
var codeText = cleanLines((codeEls[ci].textContent || '').trim().substring(0, 500));
if (codeText && codeText.length > 5 && !/^Running\\s*\\d/i.test(codeText)) {
@@ -133,16 +136,35 @@ export function generateApprovalObserverScript(_port: number): string {
var parts = [];
if (headerText) parts.push(headerText);
parts.push(codeText);
log('CONTEXT-OK d='+depth+' trail='+_debugTrail.join(' > '));
return parts.join(' — ');
}
}
// v10-diag: also look for any text-bearing elements (span, div, p) with substantial text
if (depth <= 5) {
var textEls = node.querySelectorAll('span, div, p');
var foundTexts = [];
for (var ti = 0; ti < Math.min(textEls.length, 10); ti++) {
var tText = (textEls[ti].textContent || '').trim();
if (tText.length > 10 && tText.length < 300 && !isNoiseLine(tText)) {
foundTexts.push(tText.substring(0, 80));
}
}
if (foundTexts.length > 0) {
_debugTrail.push('texts=['+foundTexts.join('|')+']');
}
}
node = node.parentElement;
}
// Last resort: try aria-label or title on the button
var ariaLabel = btn.getAttribute('aria-label') || btn.getAttribute('title') || '';
log('CONTEXT-FAIL trail='+_debugTrail.join(' > '));
// v10-diag: dump button ancestor chain as diagnostic
_lastContextDebug = _debugTrail.join(' > ');
if (ariaLabel && ariaLabel.length > 5) return ariaLabel;
return cleanButtonText(btn);
}
var _lastContextDebug = '';
function extractStepContext(btn) {
var stepEl = getStepContainer(btn);
@@ -625,7 +647,8 @@ export function generateApprovalObserverScript(_port: number): string {
command:txt2,
description:desc2,
step_type:type2,
buttons:buttonsArr2
buttons:buttonsArr2,
_debug_trail:_lastContextDebug||''
};
fetch(BASE+'/pending',{
method:'POST',