Multiple workspaces can share one checkout directory. Agent and terminal status, sidebar tabs, and ownership now attribute strictly by workspace ID, so a running or blocked agent in one workspace no longer shows up on its same-directory siblings. A one-time startup migration backfills workspace IDs onto legacy agents, and every agent and terminal is created with one thereafter. Directory lookups remain only for genuinely folder-derived git facts (branch, diff) and the archive-by-path adapter.
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import type { WorkspaceDescriptor } from "@/stores/session-store";
|
|
import { normalizeWorkspaceOpaqueId } from "@/utils/workspace-identity";
|
|
|
|
const pendingWorkspaceArchivesByServer = new Map<string, Set<string>>();
|
|
|
|
function pendingArchiveKey(input: { serverId: string; workspaceId: string }): string {
|
|
return `${input.serverId.trim()}::${input.workspaceId.trim()}`;
|
|
}
|
|
|
|
export function markWorkspaceArchivePending(input: {
|
|
serverId: string;
|
|
workspaceId: string;
|
|
}): void {
|
|
const serverId = input.serverId.trim();
|
|
const workspaceId = normalizeWorkspaceOpaqueId(input.workspaceId);
|
|
if (!serverId || !workspaceId) {
|
|
return;
|
|
}
|
|
|
|
const archives = pendingWorkspaceArchivesByServer.get(serverId) ?? new Set<string>();
|
|
archives.add(pendingArchiveKey({ serverId, workspaceId }));
|
|
pendingWorkspaceArchivesByServer.set(serverId, archives);
|
|
}
|
|
|
|
export function clearWorkspaceArchivePending(input: {
|
|
serverId: string;
|
|
workspaceId: string;
|
|
}): void {
|
|
const serverId = input.serverId.trim();
|
|
const workspaceId = normalizeWorkspaceOpaqueId(input.workspaceId);
|
|
if (!serverId || !workspaceId) {
|
|
return;
|
|
}
|
|
|
|
const archives = pendingWorkspaceArchivesByServer.get(serverId);
|
|
if (!archives) {
|
|
return;
|
|
}
|
|
archives.delete(pendingArchiveKey({ serverId, workspaceId }));
|
|
if (archives.size === 0) {
|
|
pendingWorkspaceArchivesByServer.delete(serverId);
|
|
}
|
|
}
|
|
|
|
export function isWorkspaceArchivePending(input: {
|
|
serverId: string;
|
|
workspaceId?: string | null;
|
|
}): boolean {
|
|
const serverId = input.serverId.trim();
|
|
const workspaceId = normalizeWorkspaceOpaqueId(input.workspaceId);
|
|
if (!serverId || !workspaceId) {
|
|
return false;
|
|
}
|
|
|
|
const archives = pendingWorkspaceArchivesByServer.get(serverId);
|
|
return archives?.has(pendingArchiveKey({ serverId, workspaceId })) ?? false;
|
|
}
|
|
|
|
export function shouldSuppressWorkspaceForLocalArchive(input: {
|
|
serverId: string;
|
|
workspace: WorkspaceDescriptor;
|
|
}): boolean {
|
|
return isWorkspaceArchivePending({
|
|
serverId: input.serverId,
|
|
workspaceId: input.workspace.id,
|
|
});
|
|
}
|