refactor(bridge): migrate gravity bridge to pure websocket gateway architecture, deleting legacy local file scanners and dependencies
This commit is contained in:
@@ -86,13 +86,7 @@ function detectProjectName(): string {
|
||||
|
||||
// ─── Bridge File I/O ───
|
||||
|
||||
function ensureBridgeDir() {
|
||||
const dirs = ['', 'response', 'commands', 'chat_snapshots'];
|
||||
for (const d of dirs) {
|
||||
const p = path.join(bridgePath, d);
|
||||
if (!fs.existsSync(p)) { fs.mkdirSync(p, { recursive: true }); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Module-level activeSessionId so writeChatSnapshot can register sessions lazily
|
||||
let activeSessionId = '';
|
||||
@@ -102,34 +96,15 @@ const recentDiscordSentTexts: Map<string, number> = new Map();
|
||||
|
||||
function writeChatSnapshot(text: string) {
|
||||
try {
|
||||
// WS route (preferred) — skip file write to prevent duplicate Discord delivery
|
||||
if (wsBridge && wsBridge.isConnected()) {
|
||||
wsBridge.sendChat({
|
||||
content: text,
|
||||
conversation_id: activeSessionId,
|
||||
conversation_id: getStepProbeSessionId(),
|
||||
project_name: projectName,
|
||||
});
|
||||
logToFile(`[SNAPSHOT-WS] sent (${text.length} chars)`);
|
||||
if (activeSessionId) { writeRegistration(activeSessionId); }
|
||||
return;
|
||||
if (getStepProbeSessionId()) { writeRegistration(getStepProbeSessionId()); }
|
||||
}
|
||||
// File route (fallback — only when WS is NOT connected)
|
||||
const snapshotDir = path.join(bridgePath, 'chat_snapshots');
|
||||
if (!fs.existsSync(snapshotDir)) { fs.mkdirSync(snapshotDir, { recursive: true }); }
|
||||
const id = Date.now().toString();
|
||||
const data = {
|
||||
id,
|
||||
project_name: projectName,
|
||||
content: text,
|
||||
timestamp: Date.now() / 1000,
|
||||
};
|
||||
const filePath = path.join(snapshotDir, `${id}.json`);
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');
|
||||
console.log(`Gravity Bridge: chat snapshot written (${text.length} chars) → ${id}.json`);
|
||||
logToFile(`[SNAPSHOT] written ${id}.json (${text.length} chars)`);
|
||||
logToFile(`[SNAPSHOT] content: ${text.substring(0, 200)}`);
|
||||
// Lazily register session → project mapping (correct because projectName is per-window)
|
||||
if (activeSessionId) { writeRegistration(activeSessionId); }
|
||||
} catch (e: any) {
|
||||
console.log(`Gravity Bridge: snapshot write error: ${e.message}`);
|
||||
}
|
||||
@@ -137,33 +112,16 @@ function writeChatSnapshot(text: string) {
|
||||
|
||||
function writeChatSnapshotWithFiles(text: string, files: Array<{ name: string, content: string }>) {
|
||||
try {
|
||||
// WS route (preferred) — skip file write to prevent duplicate Discord delivery
|
||||
if (wsBridge && wsBridge.isConnected()) {
|
||||
wsBridge.sendChat({
|
||||
content: text,
|
||||
attached_files: files,
|
||||
conversation_id: activeSessionId,
|
||||
conversation_id: getStepProbeSessionId(),
|
||||
project_name: projectName,
|
||||
});
|
||||
logToFile(`[SNAPSHOT-WS] sent with ${files.length} files (${text.length} chars)`);
|
||||
if (activeSessionId) { writeRegistration(activeSessionId); }
|
||||
return;
|
||||
if (getStepProbeSessionId()) { writeRegistration(getStepProbeSessionId()); }
|
||||
}
|
||||
// File route (fallback — only when WS is NOT connected)
|
||||
const snapshotDir = path.join(bridgePath, 'chat_snapshots');
|
||||
if (!fs.existsSync(snapshotDir)) { fs.mkdirSync(snapshotDir, { recursive: true }); }
|
||||
const id = Date.now().toString();
|
||||
const data = {
|
||||
id,
|
||||
project_name: projectName,
|
||||
content: text,
|
||||
attached_files: files,
|
||||
timestamp: Date.now() / 1000,
|
||||
};
|
||||
const filePath = path.join(snapshotDir, `${id}.json`);
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');
|
||||
logToFile(`[SNAPSHOT] written ${id}.json (${text.length} chars, ${files.length} files)`);
|
||||
if (activeSessionId) { writeRegistration(activeSessionId); }
|
||||
} catch (e: any) {
|
||||
console.log(`Gravity Bridge: snapshot+files write error: ${e.message}`);
|
||||
}
|
||||
@@ -383,7 +341,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
const config = vscode.workspace.getConfiguration('gravityBridge');
|
||||
const configPath = config.get<string>('bridgePath');
|
||||
bridgePath = configPath || path.join(os.homedir(), '.gemini', 'antigravity', 'bridge');
|
||||
ensureBridgeDir();
|
||||
|
||||
console.log(`Gravity Bridge: bridge path: ${bridgePath}`);
|
||||
|
||||
// ── WebSocket Hub Connection ──
|
||||
@@ -527,6 +485,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
get activeSessionId() { return getStepProbeContext().activeSessionId; },
|
||||
get sessionStalled() { return getStepProbeContext().sessionStalled; },
|
||||
get lastPendingStepIndex() { return getStepProbeContext().lastPendingStepIndex; },
|
||||
writeChatSnapshot,
|
||||
};
|
||||
const bridgePort = await startHttpBridge(httpBridgeCtx, sdk);
|
||||
let localPort = bridgePort;
|
||||
|
||||
Reference in New Issue
Block a user