-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
Description
Problem
Currently we maintain two sources of truth for workspace lists:
workspaceMetadataMap - updated via metadata events from backendprojectsMap - manually reloaded when workspaces change
This requires careful coordination to keep them in sync. Recent bug: forked workspace didn't appear in sidebar until we added special "detect new workspace" logic.
Proposed Solution
Derive projects from workspace metadata. All information in ProjectConfig exists in WorkspaceMetadata:
function deriveProjectsFromMetadata(
workspaceMetadata: Map<string, FrontendWorkspaceMetadata>
): Map<string, ProjectConfig> {
const projects = new Map<string, ProjectConfig>();
for (const metadata of workspaceMetadata.values()) {
if (!projects.has(metadata.projectPath)) {
projects.set(metadata.projectPath, {
path: metadata.projectPath,
workspaces: [],
});
}
projects.get(metadata.projectPath)!.workspaces.push({
path: metadata.namedWorkspacePath,
id: metadata.id,
name: metadata.name,
createdAt: metadata.createdAt,
});
}
return projects;
}Benefits
- β Single source of truth (workspaceMetadata)
- β Projects always in sync (derived on-demand)
- β Eliminates entire class of synchronization bugs
- β ~155 LoC reduction (remove useProjectManagement, manual reloading)
- β Simpler mental model
Implementation
Phase 1: Add derivation
- Create
src/utils/deriveProjects.ts - Use in App.tsx:
const projects = useMemo(() => deriveProjectsFromMetadata(workspaceMetadata), [workspaceMetadata]) - Verify UI works identically
Phase 2: Remove dead code
- Delete
useProjectManagementhook - Remove
onProjectsUpdatecallback machinery - Remove manual project reloading from create/remove/rename
- Remove "detect new workspace" logic (lines 58-75 in useWorkspaceManagement.ts)
Phase 3: Update tests
- Update tests to use derivation
- Document pattern
Unresolved: Empty Projects
Current behavior: Config can have projects with no workspaces, shown in sidebar
New behavior: Projects only appear when they have β₯1 workspace
Question: Is this acceptable?
Arguments for yes:
- Empty projects have no actions, just take space
- Creating first workspace brings project back
- Cleaner UX (only show active projects)
Arguments for no:
- User adds project, expects to see it immediately
- Breaks expectation that "added = visible"
Recommendation: Try it, see if users complain. Empty projects are edge case.
Alternative: Keep Project Registration
If empty projects must be visible:
- Keep project list in config as
projects: ['/path/to/project'](just paths) - Derive workspaces from metadata
- Show project if in list OR has workspaces
- Smaller win (~80 LoC instead of ~155 LoC) but still valuable
Estimated Effort
1-2 hours, mostly deleting code. Low risk (type system catches issues).
Related
- Current workaround: useWorkspaceManagement detects new workspaces and triggers reload (lines 58-75)
- This issue proposes eliminating the root cause instead of patching symptoms
Generated with cmux