Add detailed console logging for project isolation debugging

- Added logging to loadProjects() to trace session assignment
- Added logging to show manually created projects and their workingDirs
- Added logging to virtual session matching logic
- This will help identify where sessions are being incorrectly assigned

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
uroma
2026-01-22 14:44:39 +00:00
Unverified
parent ec790a2de6
commit 9107b3db85

View File

@@ -150,14 +150,23 @@ class ProjectManager {
const grouped = new Map();
console.log('[ProjectManager] Processing', allSessions.length, 'total sessions');
console.log('[ProjectManager] Existing manually created projects:', Array.from(this.projects.entries()).filter(([k, p]) => p.manuallyCreated).map(([k, p]) => ({key: k, name: p.name, workingDir: p.workingDir})));
allSessions.forEach(session => {
const dir = session.workingDir || 'default';
const projectKey = dir.replace(/\//g, '-').replace(/^-/, '') || 'default';
console.log('[ProjectManager] Processing session:', {
id: session.id.substring(0, 8),
workingDir: dir,
projectKey: projectKey,
project: session.metadata?.project
});
// Check if this is a virtual workingDir
if (dir.startsWith('/virtual/projects/')) {
virtualSessions.push(session);
console.log('[ProjectManager] -> Virtual session, will add to manually created project');
return; // Don't add to grouped, will handle in manually created projects
}
@@ -172,9 +181,11 @@ class ProjectManager {
createdAt: this.getOldestSessionTime(allSessions.filter(s => s.workingDir === dir))
};
grouped.set(projectKey, project);
console.log('[ProjectManager] -> Created new project group:', projectKey, projectName);
}
grouped.get(projectKey).sessions.push(session);
console.log('[ProjectManager] -> Added to project group:', projectKey, 'total sessions:', grouped.get(projectKey).sessions.length);
});
console.log('[ProjectManager] Separated', virtualSessions.length, 'virtual sessions and', grouped.size, 'real projects');
@@ -206,7 +217,12 @@ class ProjectManager {
const manuallyCreated = Array.from(this.projects.entries())
.filter(([key, p]) => p.manuallyCreated === true);
console.log('[ProjectManager] Processing', manuallyCreated.length, 'manually created projects');
console.log('[ProjectManager] Virtual sessions to assign:', virtualSessions.map(s => ({id: s.id.substring(0, 8), workingDir: s.workingDir, project: s.metadata?.project})));
manuallyCreated.forEach(([key, manualProject]) => {
console.log('[ProjectManager] Processing manually created project:', key, manualProject.name, 'workingDir:', manualProject.workingDir);
if (!filtered.has(key)) {
// Project doesn't exist in filtered, just add it
filtered.set(key, manualProject);
@@ -216,12 +232,14 @@ class ProjectManager {
if (manualProject.isVirtual) {
// Replace with manually created version (which has correct name, etc.)
filtered.set(key, manualProject);
console.log('[ProjectManager] Replaced with manually created version:', manualProject.name);
}
}
// Add virtual sessions that belong to this project
const projectVirtualSessions = virtualSessions.filter(s => {
const sessionProjectKey = s.workingDir?.replace('/virtual/projects/', '') || '';
console.log('[ProjectManager] Checking if session', s.id.substring(0, 8), 'belongs to project', key, ':', sessionProjectKey, '===', key, '?', sessionProjectKey === key);
return sessionProjectKey === key;
});
@@ -231,7 +249,7 @@ class ProjectManager {
projectVirtualSessions.forEach(session => {
if (!existingSessionIds.has(session.id)) {
manualProject.sessions.push(session);
console.log('[ProjectManager] Added session', session.id, 'to virtual project:', manualProject.name);
console.log('[ProjectManager] Added session', session.id.substring(0, 8), 'to virtual project:', manualProject.name);
}
});
// Sort sessions
@@ -244,6 +262,8 @@ class ProjectManager {
if (manualProject.sessions.length > 0) {
manualProject.activeSessionId = manualProject.sessions[0].id;
}
} else {
console.log('[ProjectManager] No virtual sessions found for project:', manualProject.name);
}
});