refactor(bridge): migrate gravity bridge to pure websocket gateway architecture, deleting legacy local file scanners and dependencies
This commit is contained in:
@@ -9,6 +9,7 @@ import * as path from 'path';
|
||||
import { WSBridgeClient } from './ws-client';
|
||||
import { extractPlannerText, extractToolCommand, extractToolDescription } from './step-utils';
|
||||
import { initApprovalHandler, setupResponseWatcher } from './approval-handler';
|
||||
import { BrainWatcher } from './brain-watcher';
|
||||
|
||||
// Re-export from approval-handler for backward compatibility with extension.ts imports
|
||||
export { handleDiffReviewResponse, tryApprovalStrategies } from './approval-handler';
|
||||
@@ -35,6 +36,7 @@ export interface BridgeContext {
|
||||
|
||||
let ctx: BridgeContext;
|
||||
let responseWatcher: fs.FSWatcher | null = null;
|
||||
let brainWatcher: BrainWatcher | null = null;
|
||||
let activeTrajectoryId = '';
|
||||
const recentPendingSteps = new Map<string, number>();
|
||||
const PENDING_MEMORY_TTL_MS = 60_000;
|
||||
@@ -276,15 +278,16 @@ function setupMonitor() {
|
||||
} catch (e: any) {
|
||||
if (pollCount <= 30) ctx.logToFile(`[POLL] Fallback 2 error for sid=${sid}: ${e.message}`);
|
||||
// If trajectory explicitly does not exist, it might be an Antigravity or non-Cascade session directory.
|
||||
if (e.message?.includes('trajectory not found')) {
|
||||
continue;
|
||||
}
|
||||
// FIXED: known-issues "AI Response Missing for New Sessions" -> Force register to prevent session loss on proto/UTF-8 parse errors
|
||||
// We MUST register it so activeSessionId tracks it properly.
|
||||
// To prevent old ghost sessions from hijacking, we only mark it RUNNING if it was recently modified.
|
||||
const ageMs = Date.now() - brainDirs[i].time;
|
||||
const isFresh = ageMs < 120_000; // updated within 2 mins
|
||||
|
||||
allTraj.trajectorySummaries[sid] = {
|
||||
status: 'CASCADE_RUN_STATUS_RUNNING',
|
||||
status: isFresh ? 'CASCADE_RUN_STATUS_RUNNING' : 'CASCADE_RUN_STATUS_IDLE',
|
||||
stepCount: 1, // Assume progressing to allow loop delta>0 trigger
|
||||
lastModifiedTime: new Date(brainDirs[i].time).toISOString(),
|
||||
summary: 'Discovered via brain/ scan (Fallback Error)',
|
||||
summary: 'Discovered via brain/ scan (Antigravity Native)',
|
||||
trajectoryMetadata: { workspaces: [{ workspaceFolderAbsoluteUri: ctx.workspaceUri.replace(/\\/g, '/') }] }
|
||||
};
|
||||
}
|
||||
@@ -381,6 +384,9 @@ function setupMonitor() {
|
||||
// Session changed?
|
||||
if (bestSessionId !== ctx.activeSessionId) {
|
||||
ctx.activeSessionId = bestSessionId;
|
||||
if (brainWatcher) {
|
||||
brainWatcher.updateSession(bestSessionId);
|
||||
}
|
||||
activeTrajectoryId = (bestSession as any).trajectoryId || '';
|
||||
activeSessionTitle = currentTitle;
|
||||
lastKnownStepCount = currentCount;
|
||||
@@ -1261,6 +1267,13 @@ export function writePendingApproval(data: { conversation_id: string; command: s
|
||||
*/
|
||||
export function initStepProbe(context: BridgeContext) {
|
||||
ctx = context;
|
||||
if (ctx.wsBridge) {
|
||||
brainWatcher = new BrainWatcher({
|
||||
logToFile: ctx.logToFile,
|
||||
wsBridge: ctx.wsBridge,
|
||||
projectName: ctx.projectName
|
||||
});
|
||||
}
|
||||
initApprovalHandler(context, () => activeTrajectoryId);
|
||||
setupMonitor();
|
||||
setupResponseWatcher();
|
||||
|
||||
Reference in New Issue
Block a user