From e4eb7565eaad732a462875bed896da9045f1688e Mon Sep 17 00:00:00 2001 From: CD Date: Sat, 7 Mar 2026 16:09:05 +0900 Subject: [PATCH] feat: use antigravity.sendTextToChat native API for chat submission --- extension/src/extension.ts | 59 ++++++++------------------------------ 1 file changed, 12 insertions(+), 47 deletions(-) diff --git a/extension/src/extension.ts b/extension/src/extension.ts index c2e8d59..e52c68b 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -263,57 +263,22 @@ async function handleCommand(filePath: string) { return; } - // General text: send to chat panel with query + submit - let chatOpened = false; - - // Method 1: Try opening chat with query parameter (fills + auto-focuses) - const chatOpenCommands = [ - { cmd: 'workbench.action.chat.open', args: { query: command.text } }, - { cmd: 'workbench.panel.chat.view.copilot.focus', args: undefined }, - ]; - - for (const { cmd, args } of chatOpenCommands) { + // General text: use Antigravity native API to send to chat + try { + await vscode.commands.executeCommand('antigravity.sendTextToChat', true, command.text); + console.log(`Gravity Bridge: ✅ sent via antigravity.sendTextToChat: "${command.text.substring(0, 50)}"`); + } catch (e) { + console.log(`Gravity Bridge: antigravity.sendTextToChat failed: ${e}, trying fallback`); + // Fallback: open chat with query parameter try { - await vscode.commands.executeCommand(cmd, args); - chatOpened = true; - console.log(`Gravity Bridge: chat opened with "${cmd}"`); - break; - } catch { /* try next */ } - } - - if (chatOpened) { - await new Promise(resolve => setTimeout(resolve, 300)); - - // Paste text into chat input - const oldClipboard = await vscode.env.clipboard.readText(); - await vscode.env.clipboard.writeText(command.text); - await vscode.commands.executeCommand('editor.action.clipboardPasteAction'); - await vscode.env.clipboard.writeText(oldClipboard); - await new Promise(resolve => setTimeout(resolve, 300)); - - // Try to submit: carriage return, then keyboard Enter simulation - let submitted = false; - const submitMethods = [ - { cmd: 'type', args: { text: '\r' } }, // carriage return - { cmd: 'default:Enter', args: undefined }, // Enter keybinding - { cmd: 'type', args: { text: '\u000d' } }, // CR unicode - ]; - for (const { cmd, args } of submitMethods) { - try { - await vscode.commands.executeCommand(cmd, args); - console.log(`Gravity Bridge: ✅ Enter sent via "${cmd}"`); - submitted = true; - break; - } catch (e) { - console.log(`Gravity Bridge: "${cmd}" failed: ${e}`); - } - } - if (!submitted) { - console.log('Gravity Bridge: ⚠️ all submit methods failed — text pasted but not submitted'); + await vscode.commands.executeCommand('workbench.action.chat.open', { query: command.text }); + console.log('Gravity Bridge: fallback to workbench.action.chat.open with query'); + } catch (e2) { + console.error('Gravity Bridge: all chat send methods failed', e2); } } - // Always mark as consumed (no toast notification) + // Always mark as consumed command.consumed = true; fs.writeFileSync(filePath, JSON.stringify(command, null, 2), 'utf-8'); } catch (err) {