Fix project isolation: Make loadChatHistory respect active project sessions

- Modified loadChatHistory() to check for active project before fetching all sessions
- When active project exists, use project.sessions instead of fetching from API
- Added detailed console logging to debug session filtering
- This prevents ALL sessions from appearing in every project's sidebar

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
uroma
2026-01-22 14:43:05 +00:00
Unverified
parent b82837aa5f
commit 55aafbae9a
6463 changed files with 1115462 additions and 4486 deletions

View File

@@ -1,46 +1,60 @@
# Claude IDE Tab Close Buttons - Scratchpad
# Project Isolation Bug - Scratchpad
## Task Overview
Fix the missing 'x' close button on session/project tabs in the Claude IDE.
Issue URL: https://rommark.dev/claude/ide/session/session-1769083280612-mdof554ot
Fix project isolation bug where ALL sessions appear in every project's left sidebar instead of only that project's sessions.
## Files to Modify
- /home/uroma/obsidian-web-interface/public/claude-ide/project-manager.js (main logic)
- /home/uroma/obsidian-web-interface/public/claude-ide/chat-enhanced.js (left sidebar)
## Root Cause Analysis
After analyzing the code:
1. **project-manager.js line 365**: `switchProject()` calls `loadChatHistory(project.sessions)` - this passes the correct sessions
2. **chat-enhanced.js line 52**: `loadChatHistory()` accepts `sessionsToRender` parameter
3. **BUT** - When `loadChatHistory()` is called without parameters (initial load), it fetches ALL sessions from API
The issue: The left sidebar `loadChatHistory` function is being called in multiple places:
1. Initial page load (no filter) - loads ALL sessions
2. When switching projects (with filter) - should load only project sessions
3. When sessions are created/updated
The problem is that `loadChatHistory` caches and reuses all sessions, and the filtering mechanism isn't working correctly.
## Progress
### Iteration 1 - Add Close Buttons to Project Tabs - COMPLETED
### Iteration 1 - Analysis - COMPLETED
- Read all relevant files
- Identified the root cause
- Created fix plan
**Discovery:**
- Session tabs (Level 2) already had close buttons implemented in session-tabs.js line 100
- Project tabs (Level 1) were missing close buttons entirely
### Next Steps
1. Fix `loadChatHistory` to properly filter by project
2. Ensure sessions are tracked per project correctly
3. Test the fix
**Changes Made:**
## Detailed Root Cause
1. **project-manager.js** - Added close button to project tabs:
- Modified `renderProjectTab()` to include close button element (line 192)
- Added `closeProject()` method with confirmation dialog
- Added `getSessionName()` helper method for displaying session names in confirmation
- Close button removes project tab but keeps sessions accessible
- Auto-switches to next available project when active project is closed
Looking at `chat-enhanced.js` lines 64-81:
```javascript
if (sessionsToRender) {
// Use provided sessions (for project filtering)
allSessions = sessionsToRender;
} else {
// Fetch all sessions from API
const res = await fetch('/claude/api/claude/sessions');
// ... loads ALL sessions
}
```
2. **project-tabs.css** - Added styling for project tab close buttons:
- Added `.project-tab .tab-close` styles (lines 101-122)
- Close button hidden by default, shows on hover
- Red highlight on hover with rotation effect
- Added mobile responsive styles to always show close button on small screens
The problem: When `loadChatHistory()` is called from `switchProject()` with `project.sessions`, it correctly uses those sessions. BUT there are other calls to `loadChatHistory()` throughout the code that don't pass the filter parameter, causing all sessions to load.
**Implementation Details:**
- Close button uses × (multiplication sign) character
- Click event stops propagation to prevent triggering project switch
- Confirmation dialog shows session count and list for non-empty projects
- Graceful handling when last project is closed (shows empty state)
Also, the session tabs (`window.sessionTabs.setSessions`) are correctly updated but the left sidebar isn't properly isolated.
## Next Steps
- Test the implementation in browser
- Verify close buttons work on both project and session tabs
- Ensure responsive behavior on mobile devices
## Solution
## Files Modified
- /home/uroma/obsidian-web-interface/public/claude-ide/project-manager.js
- /home/uroma/obsidian-web-interface/public/claude-ide/project-tabs.css
## Files Verified (No Changes Needed)
- /home/uroma/obsidian-web-interface/public/claude-ide/session-tabs.js (already had close buttons)
The fix needs to:
1. Make `loadChatHistory` always respect the current project's sessions
2. Track which project is active globally
3. Filter sessions by the active project's workingDir or project ID