fix: panel focus before approval

This commit is contained in:
2026-03-08 09:43:55 +09:00
parent e7bc4046a4
commit 0bf3217ae1
3 changed files with 57 additions and 116 deletions

View File

@@ -403,72 +403,42 @@ async function processResponseFile(filePath) {
catch { } catch { }
} }
if (resp.approved) { if (resp.approved) {
// STRATEGY: Try SDK rawRPC first (has CSRF auth), then VS Code commands // Step 1: Focus Antigravity panel — webview MUST be active for commands to work
// Phase 1: SDK rawRPC (requires active SDK connection with CSRF) // acceptAgentStep dispatches via postMessage to Chat Client webview
if (sdk && sessionId) { try {
const rpcMethods = [ await vscode.commands.executeCommand('antigravity.agentPanel.focus');
{ method: 'HandleCascadeUserInteraction', params: { cascadeId: sessionId, approved: true } }, logToFile('[RESPONSE] panel focused');
{ method: 'ResolveOutstandingSteps', params: { cascadeId: sessionId } },
];
for (const { method, params } of rpcMethods) {
try {
const result = await sdk.ls.rawRPC(method, params);
const log = `[RESPONSE] RPC OK ${method}: ${JSON.stringify(result).substring(0, 100)}`;
logToFile(log);
}
catch (e) {
const log = `[RESPONSE] RPC FAIL ${method}: ${e.message}`;
logToFile(log);
}
}
} }
else { catch (e) {
logToFile(`[RESPONSE] SDK unavailable (sdk=${!!sdk}, session=${sessionId})`); logToFile(`[RESPONSE] panel focus failed: ${e.message}`);
} }
// Phase 2: VS Code commands (may or may not work depending on UI focus) // Wait for webview to initialize
const cmds = [ await new Promise(r => setTimeout(r, 500));
'antigravity.terminalCommand.run', // Step 2: Accept — only acceptAgentStep (the universal approval command)
'antigravity.terminalCommand.accept', try {
'antigravity.command.accept', await vscode.commands.executeCommand('antigravity.agent.acceptAgentStep');
'antigravity.agent.acceptAgentStep', logToFile('[RESPONSE] acceptAgentStep sent');
];
for (const cmd of cmds) {
try {
await vscode.commands.executeCommand(cmd);
logToFile(`[RESPONSE] CMD OK ${cmd}`);
}
catch (e) {
logToFile(`[RESPONSE] CMD FAIL ${cmd}: ${e.message}`);
}
} }
logToFile('[RESPONSE] all approve attempts done'); catch (e) {
logToFile(`[RESPONSE] acceptAgentStep failed: ${e.message}`);
}
logToFile('[RESPONSE] approve done');
} }
else { else {
// REJECT // REJECT — same pattern: focus first, then reject
if (sdk && sessionId) { try {
try { await vscode.commands.executeCommand('antigravity.agentPanel.focus');
await sdk.ls.rawRPC('HandleCascadeUserInteraction', { cascadeId: sessionId, approved: false });
logToFile('[RESPONSE] RPC reject OK');
}
catch (e) {
logToFile(`[RESPONSE] RPC reject FAIL: ${e.message}`);
}
} }
const cmds = [ catch { }
'antigravity.terminalCommand.reject', await new Promise(r => setTimeout(r, 500));
'antigravity.command.reject', try {
'antigravity.agent.rejectAgentStep', await vscode.commands.executeCommand('antigravity.agent.rejectAgentStep');
]; logToFile('[RESPONSE] rejectAgentStep sent');
for (const cmd of cmds) {
try {
await vscode.commands.executeCommand(cmd);
logToFile(`[RESPONSE] CMD OK ${cmd}`);
}
catch (e) {
logToFile(`[RESPONSE] CMD FAIL ${cmd}: ${e.message}`);
}
} }
logToFile('[RESPONSE] all reject attempts done'); catch (e) {
logToFile(`[RESPONSE] rejectAgentStep failed: ${e.message}`);
}
logToFile('[RESPONSE] reject done');
} }
try { try {
fs.unlinkSync(filePath); fs.unlinkSync(filePath);

File diff suppressed because one or more lines are too long

View File

@@ -381,67 +381,38 @@ async function processResponseFile(filePath: string) {
} }
if (resp.approved) { if (resp.approved) {
// STRATEGY: Try SDK rawRPC first (has CSRF auth), then VS Code commands // Step 1: Focus Antigravity panel — webview MUST be active for commands to work
// Phase 1: SDK rawRPC (requires active SDK connection with CSRF) // acceptAgentStep dispatches via postMessage to Chat Client webview
if (sdk && sessionId) { try {
const rpcMethods = [ await vscode.commands.executeCommand('antigravity.agentPanel.focus');
{ method: 'HandleCascadeUserInteraction', params: { cascadeId: sessionId, approved: true } }, logToFile('[RESPONSE] panel focused');
{ method: 'ResolveOutstandingSteps', params: { cascadeId: sessionId } }, } catch (e: any) {
]; logToFile(`[RESPONSE] panel focus failed: ${e.message}`);
for (const { method, params } of rpcMethods) {
try {
const result = await sdk.ls.rawRPC(method, params);
const log = `[RESPONSE] RPC OK ${method}: ${JSON.stringify(result).substring(0, 100)}`;
logToFile(log);
} catch (e: any) {
const log = `[RESPONSE] RPC FAIL ${method}: ${e.message}`;
logToFile(log);
}
}
} else {
logToFile(`[RESPONSE] SDK unavailable (sdk=${!!sdk}, session=${sessionId})`);
} }
// Wait for webview to initialize
await new Promise(r => setTimeout(r, 500));
// Phase 2: VS Code commands (may or may not work depending on UI focus) // Step 2: Accept — only acceptAgentStep (the universal approval command)
const cmds = [ try {
'antigravity.terminalCommand.run', await vscode.commands.executeCommand('antigravity.agent.acceptAgentStep');
'antigravity.terminalCommand.accept', logToFile('[RESPONSE] acceptAgentStep sent');
'antigravity.command.accept', } catch (e: any) {
'antigravity.agent.acceptAgentStep', logToFile(`[RESPONSE] acceptAgentStep failed: ${e.message}`);
];
for (const cmd of cmds) {
try {
await vscode.commands.executeCommand(cmd);
logToFile(`[RESPONSE] CMD OK ${cmd}`);
} catch (e: any) {
logToFile(`[RESPONSE] CMD FAIL ${cmd}: ${e.message}`);
}
} }
logToFile('[RESPONSE] all approve attempts done'); logToFile('[RESPONSE] approve done');
} else { } else {
// REJECT // REJECT — same pattern: focus first, then reject
if (sdk && sessionId) { try {
try { await vscode.commands.executeCommand('antigravity.agentPanel.focus');
await sdk.ls.rawRPC('HandleCascadeUserInteraction', { cascadeId: sessionId, approved: false }); } catch { }
logToFile('[RESPONSE] RPC reject OK'); await new Promise(r => setTimeout(r, 500));
} catch (e: any) { try {
logToFile(`[RESPONSE] RPC reject FAIL: ${e.message}`); await vscode.commands.executeCommand('antigravity.agent.rejectAgentStep');
} logToFile('[RESPONSE] rejectAgentStep sent');
} catch (e: any) {
logToFile(`[RESPONSE] rejectAgentStep failed: ${e.message}`);
} }
const cmds = [ logToFile('[RESPONSE] reject done');
'antigravity.terminalCommand.reject',
'antigravity.command.reject',
'antigravity.agent.rejectAgentStep',
];
for (const cmd of cmds) {
try {
await vscode.commands.executeCommand(cmd);
logToFile(`[RESPONSE] CMD OK ${cmd}`);
} catch (e: any) {
logToFile(`[RESPONSE] CMD FAIL ${cmd}: ${e.message}`);
}
}
logToFile('[RESPONSE] all reject attempts done');
} }
try { fs.unlinkSync(filePath); } catch { } try { fs.unlinkSync(filePath); } catch { }