fix(bot,extension): prevent dual delivery of commands and responses via WS+file

This commit is contained in:
Variet Worker
2026-03-17 20:30:37 +09:00
parent 6640d42449
commit 302d21d35c
2 changed files with 19 additions and 47 deletions

View File

@@ -405,8 +405,11 @@ export async function activate(context: vscode.ExtensionContext) {
.catch(err => logToFile(`[WS-RESPONSE] Approval error: ${err.message}`));
},
onCommand: (data: WSCommandData) => {
logToFile(`[WS-CMD] ${data.text?.substring(0, 50)}`);
// Process command directly (same logic as processCommandFile)
logToFile(`[WS-CMD] ${data.text?.substring(0, 50)}`);
handleWSCommand({
bridgePath, projectName, sdk, autoApproveEnabled, logToFile,
onAutoApproveChanged: (enabled: boolean) => { autoApproveEnabled = enabled; },
recentDiscordSentTexts,
}, data);
},
onInstanceUpdate: (count, instances) => {
@@ -609,41 +612,3 @@ export function deactivate() {
if (sdk) {
try { sdk.dispose(); } catch { }
}
}
// ─── WS Command Handler ───
function _handleWSCommand(data: WSCommandData) {
const text = data.text || '';
if (!text) return;
// Project filtering (WS already routes by project, but double-check)
if (data.project_name && data.project_name !== projectName) {
logToFile(`[WS-CMD] Ignoring command for ${data.project_name} (we are ${projectName})`);
return;
}
if (text === '!stop') {
logToFile('[WS-CMD] !stop — cancelling AG task');
if (sdk) {
try { sdk.cascade.cancelCurrentTask(); } catch { }
}
return;
}
if (text.startsWith('!auto')) {
const parts = text.split(' ');
autoApproveEnabled = parts[1] !== 'off';
logToFile(`[WS-CMD] auto_approve=${autoApproveEnabled}`);
return;
}
// General text → send as user message to AG
logToFile(`[WS-CMD] Sending text to AG: ${text.substring(0, 80)}`);
if (sdk) {
try {
sdk.cascade.sendPrompt(text);
} catch (e: any) {
logToFile(`[WS-CMD] SDK sendPrompt error: ${e.message}`);
}
}