fix(observer): v30 Running command 추출 — includes 매칭 + raw fallback + 디버그 로그 (v0.5.94)
This commit is contained in:
@@ -192,20 +192,35 @@ export function generateApprovalObserverScript(_port: number): string {
|
||||
// v30: Command text is in plain divs near "Running command" header, not pre/code
|
||||
var rcDivs = node.querySelectorAll('div');
|
||||
for (var rci = 0; rci < rcDivs.length; rci++) {
|
||||
var rcTxt = (rcDivs[rci].textContent || '').trim();
|
||||
if (rcTxt === 'Running command' && rcDivs[rci].parentElement) {
|
||||
var rcP = rcDivs[rci].parentElement;
|
||||
var rcEl = rcDivs[rci];
|
||||
var rcChildCount = rcEl.children ? rcEl.children.length : 0;
|
||||
var rcTxt = (rcEl.textContent || '').trim();
|
||||
// Match leaf div with exact or near-exact "Running command" text
|
||||
if ((rcTxt === 'Running command' || (rcChildCount === 0 && rcTxt.indexOf('Running command') !== -1 && rcTxt.length < 30)) && rcEl.parentElement) {
|
||||
var rcP = rcEl.parentElement;
|
||||
log('CONTEXT-v30 found RC header at d'+depth+' siblings='+rcP.children.length);
|
||||
for (var rcsi = 0; rcsi < rcP.children.length; rcsi++) {
|
||||
if (rcP.children[rcsi] === rcDivs[rci]) continue;
|
||||
if (rcP.children[rcsi] === rcEl) continue;
|
||||
var sibT = (rcP.children[rcsi].textContent || '').trim();
|
||||
if (sibT.length < 5) continue;
|
||||
// Skip button-bar text
|
||||
if (/^(Always|Run|Allow|Cancel|Deny|keyboard_arrow)/i.test(sibT)) continue;
|
||||
if (sibT.indexOf('Always run') !== -1 && sibT.indexOf('Cancel') !== -1) continue;
|
||||
// Try prompt marker extraction
|
||||
var pM = sibT.match(/[\\u003e\\u00bb\\u276f]\\s+(.+)/);
|
||||
if (pM && pM[1].trim().length > 3) {
|
||||
var cmdV = pM[1].trim().substring(0, 300);
|
||||
if (/^(Always|Run|Allow|Cancel|Deny)/i.test(cmdV)) continue;
|
||||
log('CONTEXT-OK d='+depth+' src=running-cmd trail='+_debugTrail.join(' '));
|
||||
log('CONTEXT-OK d='+depth+' src=running-cmd cmdV='+cmdV.substring(0,60));
|
||||
_lastContextDebug = _debugTrail.join(' ');
|
||||
return 'Running command: ' + cmdV;
|
||||
}
|
||||
// Fallback: use raw sibling text if it looks like a terminal line
|
||||
if (sibT.length > 10 && /[\\u276f\\u003e]/.test(sibT)) {
|
||||
log('CONTEXT-OK d='+depth+' src=running-cmd-raw sibT='+sibT.substring(0,60));
|
||||
_lastContextDebug = _debugTrail.join(' ');
|
||||
return sibT.substring(0, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user