fix: dedupe shared worktree ownership

Cherry-picked from claude branch 7b3bec48 (fix: dedupe shared worktree ownership and title sessions immediately).

Only the worktree-dedupe half applies to main: partitionWorktreesByRegisteredProject and its callers (SessionSidebar, ElectronMiniChatApp, MobileApp, MobileSessionsSheet) plus tests and sidebar docs.

The session-title half (title sessions immediately) remains on the claude branch: the session-title runtime and its claude-code transcript translator imports do not exist on main and cannot build there until the Claude harness lands.
This commit is contained in:
Serhii Dziupin
2026-08-02 09:34:49 +03:00
parent 37ff3a8164
commit 5d24d6cb2a
7 changed files with 199 additions and 22 deletions
+7 -4
View File
@@ -45,7 +45,10 @@ import { useRuntimeAPIs } from '@/hooks/useRuntimeAPIs';
import { useI18n } from '@/lib/i18n';
import { PROJECT_COLOR_MAP, PROJECT_ICON_MAP, ProjectIconImage } from '@/lib/projectMeta';
import { cn } from '@/lib/utils';
import { listProjectWorktrees } from '@/lib/worktrees/worktreeManager';
import {
listProjectWorktrees,
partitionWorktreesByRegisteredProject,
} from '@/lib/worktrees/worktreeManager';
import { useDirectoryStore } from '@/stores/useDirectoryStore';
import { mergeLiveSessionWithGlobalSession, refreshGlobalSessions, useGlobalSessionsStore } from '@/stores/useGlobalSessionsStore';
import { useMobileSessionExpansionStore } from '@/stores/useMobileSessionExpansionStore';
@@ -948,15 +951,15 @@ export const MobileSessionsSheet: React.FC<MobileSessionsSheetProps> = ({ open,
}),
);
if (cancelled) return;
const next = new Map<string, WorktreeMetadata[]>();
const discoveredWorktreesByProject = new Map<string, WorktreeMetadata[]>();
const nextGitProjectPaths = new Set<string>();
for (const entry of entries) {
if (entry) {
next.set(entry[0], entry[1]);
discoveredWorktreesByProject.set(entry[0], entry[1]);
if (entry[2]) nextGitProjectPaths.add(entry[0]);
}
}
setWorktreesByProject(next);
setWorktreesByProject(partitionWorktreesByRegisteredProject(projects, discoveredWorktreesByProject));
setGitProjectPaths(nextGitProjectPaths);
};
void run();