fix(extension): v0.3.8 — workspace URI 기반 세션 필터링 (멀티프로젝트 격리)

This commit is contained in:
2026-03-10 19:28:32 +09:00
parent c9524fc8a8
commit ae91134ff2
2 changed files with 36 additions and 14 deletions

View File

@@ -2,7 +2,7 @@
"name": "gravity-bridge", "name": "gravity-bridge",
"displayName": "Gravity Bridge", "displayName": "Gravity Bridge",
"description": "Antigravity ↔ Discord 브리지 연동 확장", "description": "Antigravity ↔ Discord 브리지 연동 확장",
"version": "0.3.7", "version": "0.3.8",
"publisher": "variet", "publisher": "variet",
"engines": { "engines": {
"vscode": "^1.100.0" "vscode": "^1.100.0"

View File

@@ -38,6 +38,7 @@ let sdk: any;
let statusBar: vscode.StatusBarItem; let statusBar: vscode.StatusBarItem;
let bridgePath: string; let bridgePath: string;
let projectName: string; let projectName: string;
let workspaceUri: string = ''; // filesystem path of the workspace folder (for session filtering)
let isActive = false; let isActive = false;
let deterministicPort = 0; // derived from projectName, consistent across restarts let deterministicPort = 0; // derived from projectName, consistent across restarts
let watcher: fs.FSWatcher | null = null; let watcher: fs.FSWatcher | null = null;
@@ -1448,14 +1449,31 @@ function setupMonitor() {
} }
// ── Filter to sessions owned by THIS window ── // ── Filter to sessions owned by THIS window ──
// Each window claims sessions it sees first via writeRegistration(). // PRIMARY: Use trajectoryMetadata.workspaces URI to match sessions to this workspace.
// Only process sessions registered to THIS projectName (or unclaimed ones). // FALLBACK: Use bridge/register/ files for sessions without metadata.
// This prevents cross-window session grabbing when multiple AG instances run.
let bestSession: any = null; let bestSession: any = null;
let bestSessionId = ''; let bestSessionId = '';
let bestModTime = ''; let bestModTime = '';
const regDir = path.join(bridgePath, 'register'); const regDir = path.join(bridgePath, 'register');
const normalizedWorkspace = workspaceUri.replace(/\\/g, '/').toLowerCase();
for (const [sid, data] of Object.entries(allTraj.trajectorySummaries) as [string, any][]) { for (const [sid, data] of Object.entries(allTraj.trajectorySummaries) as [string, any][]) {
// Check if this session is claimed by another project // PRIMARY FILTER: Check workspace URI from trajectoryMetadata
const trajMeta = data.trajectoryMetadata;
if (trajMeta?.workspaces?.length > 0 && normalizedWorkspace) {
const sessionWorkspaceRaw = trajMeta.workspaces[0]?.workspaceFolderAbsoluteUri || '';
// Convert file:///c:/Users/... URI to c:/Users/... path for comparison
const sessionWorkspace = sessionWorkspaceRaw
.replace(/^file:\/\/\//, '')
.replace(/%3A/gi, ':')
.replace(/\\/g, '/')
.toLowerCase();
if (sessionWorkspace && !sessionWorkspace.includes(normalizedWorkspace) && !normalizedWorkspace.includes(sessionWorkspace)) {
// Session belongs to a different workspace — skip
continue;
}
} else {
// FALLBACK: Check registration file (for sessions without metadata)
const regFile = path.join(regDir, `${sid}.json`); const regFile = path.join(regDir, `${sid}.json`);
if (fs.existsSync(regFile)) { if (fs.existsSync(regFile)) {
try { try {
@@ -1466,6 +1484,7 @@ function setupMonitor() {
} }
} catch { } } catch { }
} }
}
const modTime = data.lastModifiedTime || ''; const modTime = data.lastModifiedTime || '';
if (!bestSession || modTime > bestModTime) { if (!bestSession || modTime > bestModTime) {
@@ -2669,7 +2688,10 @@ export async function activate(context: vscode.ExtensionContext) {
// Project detection // Project detection
projectName = detectProjectName(); projectName = detectProjectName();
console.log(`Gravity Bridge: project "${projectName}"`); // Store workspace folder path for session filtering (prevents cross-window session grabbing)
const folders = vscode.workspace.workspaceFolders;
workspaceUri = folders && folders.length > 0 ? folders[0].uri.fsPath : '';
console.log(`Gravity Bridge: project "${projectName}" workspace="${workspaceUri}"`);
// Bridge path // Bridge path
const config = vscode.workspace.getConfiguration('gravityBridge'); const config = vscode.workspace.getConfiguration('gravityBridge');