fix: extension fs.watch accepts all event types + debounce (Windows compatibility)
This commit is contained in:
@@ -96,9 +96,12 @@ function startBridge() {
|
|||||||
statusBar.command = 'gravityBridge.stop';
|
statusBar.command = 'gravityBridge.stop';
|
||||||
// Watch bridge/response/ for Discord user responses
|
// Watch bridge/response/ for Discord user responses
|
||||||
const responsePath = path.join(bridgePath, 'response');
|
const responsePath = path.join(bridgePath, 'response');
|
||||||
|
const processedFiles = new Set(); // Debounce: prevent double-processing
|
||||||
try {
|
try {
|
||||||
watcher = fs.watch(responsePath, { persistent: false }, (eventType, filename) => {
|
watcher = fs.watch(responsePath, { persistent: false }, (eventType, filename) => {
|
||||||
if (eventType === 'rename' && filename && filename.endsWith('.json')) {
|
if (filename && filename.endsWith('.json') && !processedFiles.has(filename)) {
|
||||||
|
processedFiles.add(filename);
|
||||||
|
setTimeout(() => processedFiles.delete(filename), 2000);
|
||||||
handleResponse(path.join(responsePath, filename));
|
handleResponse(path.join(responsePath, filename));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -111,7 +114,9 @@ function startBridge() {
|
|||||||
const commandsPath = path.join(bridgePath, 'commands');
|
const commandsPath = path.join(bridgePath, 'commands');
|
||||||
try {
|
try {
|
||||||
fs.watch(commandsPath, { persistent: false }, (eventType, filename) => {
|
fs.watch(commandsPath, { persistent: false }, (eventType, filename) => {
|
||||||
if (eventType === 'rename' && filename && filename.endsWith('.json')) {
|
if (filename && filename.endsWith('.json') && !processedFiles.has(filename)) {
|
||||||
|
processedFiles.add(filename);
|
||||||
|
setTimeout(() => processedFiles.delete(filename), 2000);
|
||||||
handleCommand(path.join(commandsPath, filename));
|
handleCommand(path.join(commandsPath, filename));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -176,7 +181,7 @@ async function handleResponse(filePath) {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Handle a text command from Discord.
|
* Handle a text command from Discord.
|
||||||
* Types the text into the active editor or chat input.
|
* Supports special commands (!auto on/off) and general text relay.
|
||||||
*/
|
*/
|
||||||
async function handleCommand(filePath) {
|
async function handleCommand(filePath) {
|
||||||
try {
|
try {
|
||||||
@@ -189,12 +194,20 @@ async function handleCommand(filePath) {
|
|||||||
if (command.consumed || !command.text) {
|
if (command.consumed || !command.text) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(`Gravity Bridge: command received — "${command.text.substring(0, 50)}..."`);
|
const text = command.text.trim();
|
||||||
// Type into the active text input (chat panel)
|
console.log(`Gravity Bridge: command received — "${text.substring(0, 50)}"`);
|
||||||
|
// Special command: auto-approve toggle
|
||||||
|
if (text === '!auto on' || text === '!auto off') {
|
||||||
|
const enabled = text === '!auto on';
|
||||||
|
await toggleAutoApprove(enabled);
|
||||||
|
// Mark as consumed
|
||||||
|
command.consumed = true;
|
||||||
|
fs.writeFileSync(filePath, JSON.stringify(command, null, 2), 'utf-8');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// General text: type into chat panel
|
||||||
await vscode.commands.executeCommand('workbench.action.chat.open');
|
await vscode.commands.executeCommand('workbench.action.chat.open');
|
||||||
// Small delay for chat panel to open
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
// Type the text using clipboard
|
|
||||||
const oldClipboard = await vscode.env.clipboard.readText();
|
const oldClipboard = await vscode.env.clipboard.readText();
|
||||||
await vscode.env.clipboard.writeText(command.text);
|
await vscode.env.clipboard.writeText(command.text);
|
||||||
await vscode.commands.executeCommand('editor.action.clipboardPasteAction');
|
await vscode.commands.executeCommand('editor.action.clipboardPasteAction');
|
||||||
@@ -208,6 +221,43 @@ async function handleCommand(filePath) {
|
|||||||
console.error('Gravity Bridge: error handling command', err);
|
console.error('Gravity Bridge: error handling command', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Toggle Antigravity's auto-approve settings.
|
||||||
|
*/
|
||||||
|
async function toggleAutoApprove(enabled) {
|
||||||
|
const config = vscode.workspace.getConfiguration();
|
||||||
|
try {
|
||||||
|
// Core auto-approve settings
|
||||||
|
await config.update('chat.tools.autoApprove', enabled, vscode.ConfigurationTarget.Global);
|
||||||
|
await config.update('chat.agent.autoApprove', enabled, vscode.ConfigurationTarget.Global);
|
||||||
|
// Terminal auto-execution
|
||||||
|
if (enabled) {
|
||||||
|
await config.update('chat.tools.terminal.enableAutoApprove', true, vscode.ConfigurationTarget.Global);
|
||||||
|
}
|
||||||
|
// File edits auto-accept
|
||||||
|
await config.update('autoAcceptV2.autoAcceptFileEdits', enabled, vscode.ConfigurationTarget.Global);
|
||||||
|
// Update status bar
|
||||||
|
statusBar.text = enabled
|
||||||
|
? '$(radio-tower) Bridge: Auto ✅'
|
||||||
|
: '$(radio-tower) Bridge: Manual 🔒';
|
||||||
|
const mode = enabled ? '자동 승인 ON 🟢' : '수동 승인 OFF 🔴';
|
||||||
|
vscode.window.showInformationMessage(`Gravity Bridge: ${mode}`);
|
||||||
|
console.log(`Gravity Bridge: auto-approve set to ${enabled}`);
|
||||||
|
// Write status back to bridge for bot to report
|
||||||
|
const statusPath = path.join(bridgePath, 'commands', `auto-status-${Date.now()}.json`);
|
||||||
|
fs.writeFileSync(statusPath, JSON.stringify({
|
||||||
|
id: `auto-status-${Date.now()}`,
|
||||||
|
text: `[SYSTEM] Auto-approve: ${enabled ? 'ON' : 'OFF'}`,
|
||||||
|
timestamp: Date.now() / 1000,
|
||||||
|
consumed: true,
|
||||||
|
auto_approve: enabled,
|
||||||
|
}, null, 2), 'utf-8');
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error('Gravity Bridge: failed to toggle auto-approve', err);
|
||||||
|
vscode.window.showErrorMessage(`Auto-approve toggle failed: ${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Simulate approval — try multiple strategies.
|
* Simulate approval — try multiple strategies.
|
||||||
*/
|
*/
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -75,9 +75,12 @@ function startBridge() {
|
|||||||
|
|
||||||
// Watch bridge/response/ for Discord user responses
|
// Watch bridge/response/ for Discord user responses
|
||||||
const responsePath = path.join(bridgePath, 'response');
|
const responsePath = path.join(bridgePath, 'response');
|
||||||
|
const processedFiles = new Set<string>(); // Debounce: prevent double-processing
|
||||||
try {
|
try {
|
||||||
watcher = fs.watch(responsePath, { persistent: false }, (eventType, filename) => {
|
watcher = fs.watch(responsePath, { persistent: false }, (eventType, filename) => {
|
||||||
if (eventType === 'rename' && filename && filename.endsWith('.json')) {
|
if (filename && filename.endsWith('.json') && !processedFiles.has(filename)) {
|
||||||
|
processedFiles.add(filename);
|
||||||
|
setTimeout(() => processedFiles.delete(filename), 2000);
|
||||||
handleResponse(path.join(responsePath, filename));
|
handleResponse(path.join(responsePath, filename));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -90,7 +93,9 @@ function startBridge() {
|
|||||||
const commandsPath = path.join(bridgePath, 'commands');
|
const commandsPath = path.join(bridgePath, 'commands');
|
||||||
try {
|
try {
|
||||||
fs.watch(commandsPath, { persistent: false }, (eventType, filename) => {
|
fs.watch(commandsPath, { persistent: false }, (eventType, filename) => {
|
||||||
if (eventType === 'rename' && filename && filename.endsWith('.json')) {
|
if (filename && filename.endsWith('.json') && !processedFiles.has(filename)) {
|
||||||
|
processedFiles.add(filename);
|
||||||
|
setTimeout(() => processedFiles.delete(filename), 2000);
|
||||||
handleCommand(path.join(commandsPath, filename));
|
handleCommand(path.join(commandsPath, filename));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user