fix(extension): restructure DOM observer to prevent false positive triggers (v0.5.10)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"name": "gravity-bridge",
|
||||
"displayName": "Gravity Bridge",
|
||||
"description": "Antigravity ↔ Discord 브리지 연동 확장",
|
||||
"version": "0.5.9",
|
||||
"version": "0.5.10",
|
||||
"publisher": "variet",
|
||||
"engines": {
|
||||
"vscode": "^1.100.0"
|
||||
|
||||
@@ -198,7 +198,7 @@ function _handlePending(req: any, res: any, ctx: HttpBridgeContext) {
|
||||
}
|
||||
// "Run" button → step_probe handles these with full command detail
|
||||
// Only let through if session is stalled AND step_probe hasn't created a pending yet
|
||||
if (/^Run$/i.test(cmd)) {
|
||||
if (/^Run\b/i.test(cmd)) {
|
||||
if (!ctx.sessionStalled || ctx.lastPendingStepIndex >= 0) {
|
||||
ctx.logToFile(`[HTTP] filtered "Run" — ${!ctx.sessionStalled ? 'not stalled' : 'step_probe pending exists'}`);
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
|
||||
@@ -27,9 +27,21 @@ export function generateApprovalObserverScript(_port: number): string {
|
||||
// Searches: main document → iframes (contentDocument) → webview elements → shadow DOMs
|
||||
function deepFindButtons(patterns){
|
||||
var results=[];
|
||||
// 1. Main document buttons
|
||||
// 1. Prioritize Agent panel
|
||||
var panel=findPanel();
|
||||
if(panel){
|
||||
collectButtons(panel,results,patterns,'panel');
|
||||
if(results.length>0) return results;
|
||||
}
|
||||
// 2. Prioritize VS Code Toasts & Dialogs
|
||||
var toasts=document.querySelectorAll('.notifications-toasts, .monaco-dialog-box');
|
||||
for(var t=0;t<toasts.length;t++){
|
||||
collectButtons(toasts[t],results,patterns,'toast');
|
||||
}
|
||||
if(results.length>0) return results;
|
||||
// 3. Main document fallback
|
||||
collectButtons(document,results,patterns,'main');
|
||||
// 2. Iframe traversal (try contentDocument — works if same-origin or webSecurity off)
|
||||
// 4. Iframe traversal (try contentDocument — works if same-origin or webSecurity off)
|
||||
var iframes=document.querySelectorAll('iframe');
|
||||
for(var i=0;i<iframes.length;i++){
|
||||
try{
|
||||
@@ -262,11 +274,11 @@ export function generateApprovalObserverScript(_port: number): string {
|
||||
// Negative/secondary buttons (Deny, Reject, Dismiss) will be collected as siblings.
|
||||
var PATS=[
|
||||
{re:/^Run/i, type:'terminal_command'},
|
||||
{re:/^Accept all$/i, type:'diff_review'},
|
||||
{re:/^Accept$/i, type:'agent_step'},
|
||||
{re:/^(?:Always )?Allow/i, type:'permission'},
|
||||
{re:/^Accept all/i, type:'diff_review'},
|
||||
{re:/^Accept/i, type:'agent_step'},
|
||||
{re:/^(?:Always )?Allow/i, type:'permission'},
|
||||
{re:/^Approve/i, type:'agent_step'},
|
||||
{re:/^Retry$/i, type:'error_recovery'},
|
||||
{re:/^Retry/i, type:'error_recovery'},
|
||||
];
|
||||
|
||||
// ALL actionable button patterns (for grouping siblings in same container)
|
||||
@@ -400,10 +412,25 @@ export function generateApprovalObserverScript(_port: number): string {
|
||||
txt=txt.replace(/(Alt|Ctrl|Shift|Meta)\+.*/,'').trim();
|
||||
if(!txt)continue;
|
||||
|
||||
var isBodyRoot = (searchRoots[r] === document.body);
|
||||
var isVSCodeMainWindow = !!document.querySelector('.monaco-workbench');
|
||||
|
||||
// Match against patterns
|
||||
var matchedType=null;
|
||||
for(var p=0;p<PATS.length;p++){
|
||||
if(PATS[p].re.test(txt)){matchedType=PATS[p].type;break;}
|
||||
if(PATS[p].re.test(txt)){
|
||||
// STRUCTURAL CONSTRAINT: If we are scanning the main VS Code Editor body, reject Agent/Terminal buttons
|
||||
// to prevent freezing on CodeLens 'Run' or 'Accept' false positives.
|
||||
if (isVSCodeMainWindow && isBodyRoot && PATS[p].type !== 'diff_review' && PATS[p].type !== 'permission') {
|
||||
continue;
|
||||
}
|
||||
// Prevent duplicates if already scanned via panel root
|
||||
if (isBodyRoot && panel && panel.contains(b)) {
|
||||
continue;
|
||||
}
|
||||
matchedType=PATS[p].type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!matchedType)continue;
|
||||
|
||||
@@ -618,7 +645,7 @@ export function generateApprovalObserverScript(_port: number): string {
|
||||
if(!d.action)return;
|
||||
log('🔔 TRIGGER-CLICK received: action='+d.action);
|
||||
|
||||
var approveRe=[/^Run$/i,/^Run /i,/^Accept/i,/^(?:Always )?Allow/i,/^Approve/i,/^Continue$/i,/^Proceed$/i,/^Retry$/i];
|
||||
var approveRe=[/^Run/i,/^Accept/i,/^Accept all/i,/^(?:Always )?Allow/i,/^Approve/i,/^Continue$/i,/^Proceed$/i,/^Retry$/i];
|
||||
var rejectRe=[/^Reject/i,/^Cancel$/i,/^Deny$/i,/^Stop$/i,/^Decline$/i,/^Dismiss$/i];
|
||||
var patterns=(d.action==='approve')?approveRe:rejectRe;
|
||||
var emoji=(d.action==='approve')?'✅':'❌';
|
||||
|
||||
Reference in New Issue
Block a user