fix: skip echo relay for Discord-origin user messages
This commit is contained in:
@@ -115,6 +115,8 @@ function ensureBridgeDir() {
|
|||||||
// Module-level activeSessionId so writeChatSnapshot can register sessions lazily
|
// Module-level activeSessionId so writeChatSnapshot can register sessions lazily
|
||||||
let activeSessionId = '';
|
let activeSessionId = '';
|
||||||
let activeTrajectoryId = '';
|
let activeTrajectoryId = '';
|
||||||
|
// Track recently sent Discord→AG texts to avoid echo relay
|
||||||
|
const recentDiscordSentTexts = new Map();
|
||||||
function writeChatSnapshot(text) {
|
function writeChatSnapshot(text) {
|
||||||
try {
|
try {
|
||||||
// Write to chat_snapshots/*.json for Bot's chat_snapshot_scanner to pick up
|
// Write to chat_snapshots/*.json for Bot's chat_snapshot_scanner to pick up
|
||||||
@@ -186,6 +188,7 @@ function processCommandFile(filePath) {
|
|||||||
}
|
}
|
||||||
else if (text) {
|
else if (text) {
|
||||||
// Send message to Antigravity — use VS Code command (most reliable)
|
// Send message to Antigravity — use VS Code command (most reliable)
|
||||||
|
recentDiscordSentTexts.set(text.trim(), Date.now());
|
||||||
vscode.commands.executeCommand('antigravity.sendPromptToAgentPanel', text)
|
vscode.commands.executeCommand('antigravity.sendPromptToAgentPanel', text)
|
||||||
.then(() => console.log(`Gravity Bridge: ✅ sent "${text.substring(0, 50)}" via sendPromptToAgentPanel`), (e) => console.log(`Gravity Bridge: sendPrompt failed: ${e.message}`));
|
.then(() => console.log(`Gravity Bridge: ✅ sent "${text.substring(0, 50)}" via sendPromptToAgentPanel`), (e) => console.log(`Gravity Bridge: sendPrompt failed: ${e.message}`));
|
||||||
}
|
}
|
||||||
@@ -1896,7 +1899,14 @@ function setupMonitor() {
|
|||||||
const clientType = ui?.clientType || '';
|
const clientType = ui?.clientType || '';
|
||||||
const isFromIDE = clientType.includes('IDE');
|
const isFromIDE = clientType.includes('IDE');
|
||||||
logToFile(`[USER-MSG] step=${userInputIdx} type=${umStep?.type} client=${clientType} text=${umText.substring(0, 100)}`);
|
logToFile(`[USER-MSG] step=${userInputIdx} type=${umStep?.type} client=${clientType} text=${umText.substring(0, 100)}`);
|
||||||
if (umText.length > 2) {
|
// Skip echo: if this text was recently sent from Discord, don't relay back
|
||||||
|
const trimmed = umText.trim();
|
||||||
|
const sentAt = recentDiscordSentTexts.get(trimmed);
|
||||||
|
if (sentAt && (Date.now() - sentAt) < 60_000) {
|
||||||
|
recentDiscordSentTexts.delete(trimmed);
|
||||||
|
logToFile(`[USER-MSG] skipped echo relay (Discord origin, ${Math.round((Date.now() - sentAt) / 1000)}s ago)`);
|
||||||
|
}
|
||||||
|
else if (umText.length > 2) {
|
||||||
const truncated = umText.length > 800
|
const truncated = umText.length > 800
|
||||||
? umText.substring(0, 800) + '\n\n_(이하 생략)_'
|
? umText.substring(0, 800) + '\n\n_(이하 생략)_'
|
||||||
: umText;
|
: umText;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -82,6 +82,8 @@ function ensureBridgeDir() {
|
|||||||
// Module-level activeSessionId so writeChatSnapshot can register sessions lazily
|
// Module-level activeSessionId so writeChatSnapshot can register sessions lazily
|
||||||
let activeSessionId = '';
|
let activeSessionId = '';
|
||||||
let activeTrajectoryId = '';
|
let activeTrajectoryId = '';
|
||||||
|
// Track recently sent Discord→AG texts to avoid echo relay
|
||||||
|
const recentDiscordSentTexts: Map<string, number> = new Map();
|
||||||
|
|
||||||
function writeChatSnapshot(text: string) {
|
function writeChatSnapshot(text: string) {
|
||||||
try {
|
try {
|
||||||
@@ -156,6 +158,7 @@ function processCommandFile(filePath: string) {
|
|||||||
console.log(`Gravity Bridge: auto-approve → ${mode}`);
|
console.log(`Gravity Bridge: auto-approve → ${mode}`);
|
||||||
} else if (text) {
|
} else if (text) {
|
||||||
// Send message to Antigravity — use VS Code command (most reliable)
|
// Send message to Antigravity — use VS Code command (most reliable)
|
||||||
|
recentDiscordSentTexts.set(text.trim(), Date.now());
|
||||||
vscode.commands.executeCommand('antigravity.sendPromptToAgentPanel', text)
|
vscode.commands.executeCommand('antigravity.sendPromptToAgentPanel', text)
|
||||||
.then(() => console.log(`Gravity Bridge: ✅ sent "${text.substring(0, 50)}" via sendPromptToAgentPanel`),
|
.then(() => console.log(`Gravity Bridge: ✅ sent "${text.substring(0, 50)}" via sendPromptToAgentPanel`),
|
||||||
(e: any) => console.log(`Gravity Bridge: sendPrompt failed: ${e.message}`));
|
(e: any) => console.log(`Gravity Bridge: sendPrompt failed: ${e.message}`));
|
||||||
@@ -1863,7 +1866,13 @@ function setupMonitor() {
|
|||||||
|
|
||||||
logToFile(`[USER-MSG] step=${userInputIdx} type=${umStep?.type} client=${clientType} text=${umText.substring(0, 100)}`);
|
logToFile(`[USER-MSG] step=${userInputIdx} type=${umStep?.type} client=${clientType} text=${umText.substring(0, 100)}`);
|
||||||
|
|
||||||
if (umText.length > 2) {
|
// Skip echo: if this text was recently sent from Discord, don't relay back
|
||||||
|
const trimmed = umText.trim();
|
||||||
|
const sentAt = recentDiscordSentTexts.get(trimmed);
|
||||||
|
if (sentAt && (Date.now() - sentAt) < 60_000) {
|
||||||
|
recentDiscordSentTexts.delete(trimmed);
|
||||||
|
logToFile(`[USER-MSG] skipped echo relay (Discord origin, ${Math.round((Date.now()-sentAt)/1000)}s ago)`);
|
||||||
|
} else if (umText.length > 2) {
|
||||||
const truncated = umText.length > 800
|
const truncated = umText.length > 800
|
||||||
? umText.substring(0, 800) + '\n\n_(이하 생략)_'
|
? umText.substring(0, 800) + '\n\n_(이하 생략)_'
|
||||||
: umText;
|
: umText;
|
||||||
|
|||||||
Reference in New Issue
Block a user