Restore project grouping across hosts (#2565)
* fix(projects): restore cross-host grouping Random host-local project IDs replaced the remote-derived value that had also served as grouping identity. Persist a separate opaque group key and let normal boot reconciliation backfill older records without a migration. * fix(projects): keep ambiguous clones separate A shared remote can identify a project across hosts, but it cannot distinguish two independent clones on one host. Treat those keys as ambiguous so host-local project IDs remain separate. * fix(projects): preserve host-local project identity * fix(projects): strengthen grouping identity * test(app): update project host shape contract * fix(projects): preserve selected host identity * fix(projects): close grouped routing gaps * fix(projects): stabilize legacy subproject grouping * fix(projects): preserve selected project identity * fix(projects): isolate legacy host identity * fix(projects): preserve symlinked bootstrap roots * fix(projects): reconcile grouped custom names * fix(projects): stabilize settings and path identity * fix(projects): normalize default remote ports * fix(projects): harden host and remote identity * fix(projects): preserve host-scoped actions * fix(projects): preserve remote path semantics * fix(projects): model SCP remote semantics * fix(projects): keep settings on routed host * fix(projects): preserve SSH URL path semantics * fix(projects): separate identity from presentation * test(projects): use grouped identity in UI specs * fix(projects): harden grouped project routing * test(projects): expect framed settings route * fix(projects): preserve exact placement identity * fix(projects): harden grouping identity and routing * fix(projects): restore project key as grouping identity Random host-local project IDs had replaced the persisted cross-host value carried by projectKey. Keep projectId for routing while reconciliation owns and persists projectKey for grouping. * fix(projects): prevent project key collisions Preserve platform path semantics and generic remote transports in cross-host keys, and compare legacy checkout roots using filesystem equivalence before materializing ownership. * test(projects): assert host-scoped project keys * fix(projects): preserve project key compatibility Resolve legacy workspace project references at the daemon boundary while keeping projectKey as the cross-host identity. Complete generic SSH normalization without collapsing distinct repositories. * fix(projects): harden project reference identity * fix(projects): retain archived reference errors * fix(projects): scope legacy paths to hosts * test(app): model persisted project keys * fix(projects): retain absolute scp users * fix(projects): resolve legacy mutation aliases * fix(projects): preserve conservative identity boundaries * fix(projects): preserve legacy placement identity * test(projects): assert legacy placement identity * test(projects): expect canonical Windows keys * fix(projects): separate bootstrap identity fields * fix(projects): scope legacy paths by host * fix(projects): stabilize opaque project identity * fix(projects): preserve remaining opaque identities * fix(projects): classify forward-slash UNC roots * fix(projects): preserve opaque selection keys * fix(projects): frame host-local project keys * fix(projects): canonicalize framed identities * test(projects): isolate repeated remote fixtures * fix(projects): keep project key as UI identity * fix(projects): reconcile hydrated project references * fix(projects): preserve archived project identity * refactor(projects): group projects from project records, not workspaces Cross-host grouping had been built by hanging a projectKey off every workspace descriptor. That scoped the key to the wrong entity: the app then had to reconstruct project identity per workspace in six modules, which forced projectKey fallbacks into RPC arguments and a server-side resolver that turned grouping keys back into project ids. A workspace has a projectId. The key belongs to the project, and grouping is a display concern, so the daemon now publishes projects over project.list plus the existing project.update channel and the app groups them in one place. Projects are addressed by host-local projectId everywhere, including the settings route. Projects persisted without a key are backfilled by ordinary boot reconciliation, with no migration. Old daemons advertise no projectList capability and simply do not group. * test(projects): seed projects alongside workspaces in fixtures Sidebar fixtures seeded workspaces without their projects, which the daemon cannot produce now that projects arrive on their own channel, so nothing rendered. Adds a seeding helper that supplies both. Also drops the provisioning test for accepting a project key where a project id belongs; that resolver was removed deliberately. * fix(projects): keep derived project identity stable Four gaps left by shrinking the key derivation: Local keys used a bare path resolve, so one directory reached by a different spelling produced a different key and reset grouped identity. Windows CI caught this with the 8.3 and long-name forms of one temp path. Canonicalize through the shared realpath-aware normalization. Subproject display names lost their selected-path input, so every subproject of a monorepo rendered under the same remote-derived name. Reconciliation only ever backfilled a missing key, so a project whose remote changed stayed grouped with hosts on the old remote. Project settings kept a disconnected host selected and rendered a dead end with no way back to an editable host. * fix(projects): read scheme remotes as URLs, not scp form An `ssh://user@host:22/org/repo` remote matched the scp-form pattern first, because `[^@]+` happily eats `ssh://git`, so the port landed in the path and the project keyed as `remote:host/22/org/repo`. Two spellings of one remote therefore never grouped. Try scp form only when there is no scheme, and drop protocol-default ports so an explicitly written `:22` matches the same remote without it.
This commit is contained in:
@@ -5,10 +5,12 @@ import { useSessionStore } from "@/stores/session-store";
|
||||
import { DirectoryRefreshSupersededError, DirectorySync } from "./index";
|
||||
|
||||
type WorkspaceFetchResult = Awaited<ReturnType<DaemonClient["fetchWorkspaces"]>>;
|
||||
type ProjectListResult = Awaited<ReturnType<DaemonClient["listProjects"]>>;
|
||||
|
||||
class FakeDirectoryClient {
|
||||
fetchAgentsCalls = 0;
|
||||
fetchWorkspacesCalls = 0;
|
||||
listProjectsCalls = 0;
|
||||
private pendingWorkspaceFetch: Promise<WorkspaceFetchResult> | null = null;
|
||||
private readonly handlers = new Map<
|
||||
SessionOutboundMessage["type"],
|
||||
@@ -63,6 +65,22 @@ class FakeDirectoryClient {
|
||||
pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
|
||||
};
|
||||
}
|
||||
|
||||
async listProjects(): Promise<ProjectListResult> {
|
||||
this.listProjectsCalls += 1;
|
||||
return {
|
||||
requestId: "projects",
|
||||
projects: [
|
||||
{
|
||||
projectId: "project-1",
|
||||
projectKey: "remote:github.com/acme/app",
|
||||
projectDisplayName: "acme/app",
|
||||
projectRootPath: "/repo/app",
|
||||
projectKind: "git",
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const serverIds = new Set<string>();
|
||||
@@ -119,6 +137,28 @@ describe("DirectorySync session readiness", () => {
|
||||
directory.dispose();
|
||||
});
|
||||
|
||||
it("fetches the project descriptor channel when the daemon advertises it", async () => {
|
||||
const serverId = "project-list";
|
||||
const { client, directory } = createDirectory(serverId);
|
||||
const store = useSessionStore.getState();
|
||||
store.initializeSession(serverId, client as unknown as DaemonClient, 1);
|
||||
store.updateSessionServerInfo(serverId, {
|
||||
serverId,
|
||||
hostname: null,
|
||||
version: "test",
|
||||
features: { workspaceMultiplicity: true, projectList: true },
|
||||
});
|
||||
|
||||
await directory.refreshWorkspaces();
|
||||
|
||||
expect(client.listProjectsCalls).toBe(1);
|
||||
expect(useSessionStore.getState().sessions[serverId]?.projects.get("project-1")).toMatchObject({
|
||||
projectId: "project-1",
|
||||
projectKey: "remote:github.com/acme/app",
|
||||
});
|
||||
directory.dispose();
|
||||
});
|
||||
|
||||
it("rejects a session wait on disconnect so the reconnect can refresh", async () => {
|
||||
const serverId = "session-wait-reconnect";
|
||||
const { client, directory } = createDirectory(serverId);
|
||||
@@ -200,17 +240,14 @@ describe("DirectorySync session readiness", () => {
|
||||
});
|
||||
await refresh;
|
||||
|
||||
const emptyProjects = useSessionStore.getState().sessions[serverId]?.emptyProjects;
|
||||
expect(Array.from(emptyProjects?.keys() ?? [])).toEqual([
|
||||
"snapshot-project",
|
||||
"workspace-project",
|
||||
]);
|
||||
expect(emptyProjects?.get("snapshot-project")).toMatchObject({
|
||||
const projects = useSessionStore.getState().sessions[serverId]?.projects;
|
||||
expect(Array.from(projects?.keys() ?? [])).toEqual(["snapshot-project", "workspace-project"]);
|
||||
expect(projects?.get("snapshot-project")).toMatchObject({
|
||||
projectDisplayName: "Renamed during hydration",
|
||||
projectRootPath: "/moved/snapshot-project",
|
||||
projectKind: "directory",
|
||||
});
|
||||
expect(emptyProjects?.get("workspace-project")).toMatchObject({
|
||||
expect(projects?.get("workspace-project")).toMatchObject({
|
||||
projectDisplayName: "Project from workspace update",
|
||||
});
|
||||
directory.dispose();
|
||||
@@ -247,7 +284,7 @@ describe("DirectorySync session readiness", () => {
|
||||
|
||||
expect(useSessionStore.getState().sessions[serverId]?.hasHydratedWorkspaces).toBe(true);
|
||||
expect(
|
||||
useSessionStore.getState().sessions[serverId]?.emptyProjects.get("early-project"),
|
||||
useSessionStore.getState().sessions[serverId]?.projects.get("early-project"),
|
||||
).toMatchObject({
|
||||
projectDisplayName: "Early project",
|
||||
projectRootPath: "/repo/early-project",
|
||||
|
||||
@@ -5,10 +5,12 @@ import type {
|
||||
} from "@getpaseo/client/internal/daemon-client";
|
||||
import { fetchAgentTimelineOnce } from "@/timeline/fetch-agent-timeline-once";
|
||||
import {
|
||||
normalizeEmptyProjectDescriptor,
|
||||
normalizeProjectDescriptor,
|
||||
normalizeWorkspaceDescriptor,
|
||||
useSessionStore,
|
||||
type Agent,
|
||||
type ProjectDescriptor,
|
||||
type WorkspaceDescriptor,
|
||||
} from "@/stores/session-store";
|
||||
import {
|
||||
readLegacyDaemonWorkspaceDirectory,
|
||||
@@ -109,7 +111,7 @@ export class DirectorySync {
|
||||
const source = connection.source;
|
||||
this.workspaceTransactions.begin(source, () => ({
|
||||
workspaces: new Map(),
|
||||
emptyProjects: new Map(),
|
||||
projects: new Map(),
|
||||
}));
|
||||
const subscriptions = [
|
||||
client.on("agent_update", (message) => {
|
||||
@@ -205,8 +207,12 @@ export class DirectorySync {
|
||||
}
|
||||
if (completion.snapshot.legacy) {
|
||||
const store = useSessionStore.getState();
|
||||
store.setWorkspaces(this.serverId, buildLegacyWorkspaces(completion.snapshot.entries));
|
||||
store.setEmptyProjects(this.serverId, []);
|
||||
const workspaces = buildLegacyWorkspaces(completion.snapshot.entries);
|
||||
store.setWorkspaces(this.serverId, workspaces);
|
||||
store.setProjects(
|
||||
this.serverId,
|
||||
Array.from(workspaces.values(), legacyProjectDescriptorFromWorkspace),
|
||||
);
|
||||
store.setHasHydratedWorkspaces(this.serverId, true);
|
||||
}
|
||||
const deltas = completion.snapshot.legacy
|
||||
@@ -233,7 +239,7 @@ export class DirectorySync {
|
||||
const { client, source } = this.requireOnline();
|
||||
const transaction = this.workspaceTransactions.begin(source, () => ({
|
||||
workspaces: new Map(),
|
||||
emptyProjects: new Map(),
|
||||
projects: new Map(),
|
||||
}));
|
||||
try {
|
||||
await this.waitForSessionMetadata(client, source);
|
||||
@@ -243,7 +249,17 @@ export class DirectorySync {
|
||||
if (deltas) for (const delta of deltas) this.workspaces.applyDelta(delta);
|
||||
return;
|
||||
}
|
||||
const supportsProjectList = serverInfo.features?.projectList === true;
|
||||
if (supportsProjectList) {
|
||||
const payload = await client.listProjects();
|
||||
this.assertWorkspaceTransactionCurrent(client, source, transaction);
|
||||
for (const entry of payload.projects) {
|
||||
const project = normalizeProjectDescriptor(entry);
|
||||
transaction.snapshot.projects.set(project.projectId, project);
|
||||
}
|
||||
}
|
||||
await this.fetchWorkspaceSnapshot(client, source, transaction, input?.subscribe === true);
|
||||
if (!supportsProjectList) this.buildLegacyProjectSnapshot(transaction.snapshot);
|
||||
if (!this.isCurrent(client, source) || !this.hasMatchingSession(client, source)) {
|
||||
throw new DirectoryRefreshSupersededError("workspace completion no longer current");
|
||||
}
|
||||
@@ -279,8 +295,8 @@ export class DirectorySync {
|
||||
transaction.snapshot.workspaces.set(workspace.id, workspace);
|
||||
}
|
||||
for (const entry of payload.emptyProjects ?? []) {
|
||||
const project = normalizeEmptyProjectDescriptor(entry);
|
||||
transaction.snapshot.emptyProjects.set(project.projectId, project);
|
||||
const project = normalizeProjectDescriptor(entry);
|
||||
transaction.snapshot.projects.set(project.projectId, project);
|
||||
}
|
||||
if (!payload.pageInfo.hasMore || !payload.pageInfo.nextCursor) return;
|
||||
cursor = payload.pageInfo.nextCursor;
|
||||
@@ -288,6 +304,15 @@ export class DirectorySync {
|
||||
}
|
||||
}
|
||||
|
||||
private buildLegacyProjectSnapshot(snapshot: WorkspaceDirectorySnapshot): void {
|
||||
for (const workspace of snapshot.workspaces.values()) {
|
||||
if (!snapshot.projects.has(workspace.projectId)) {
|
||||
const project = legacyProjectDescriptorFromWorkspace(workspace);
|
||||
snapshot.projects.set(project.projectId, project);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async refreshAll(): Promise<void> {
|
||||
await Promise.all([this.refreshAgents(), this.refreshWorkspaces({ subscribe: true })]);
|
||||
}
|
||||
@@ -421,6 +446,17 @@ export class DirectorySync {
|
||||
}
|
||||
}
|
||||
|
||||
function legacyProjectDescriptorFromWorkspace(workspace: WorkspaceDescriptor): ProjectDescriptor {
|
||||
return {
|
||||
projectId: workspace.projectId,
|
||||
projectKey: null,
|
||||
projectDisplayName: workspace.projectDisplayName,
|
||||
projectCustomName: workspace.projectCustomName ?? null,
|
||||
projectRootPath: workspace.projectRootPath,
|
||||
projectKind: workspace.projectKind,
|
||||
};
|
||||
}
|
||||
|
||||
export class DirectoryRefreshSupersededError extends Error {}
|
||||
|
||||
export type { DirectorySourceToken } from "./transaction";
|
||||
|
||||
@@ -2,7 +2,7 @@ import { expect, it } from "vitest";
|
||||
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { WorkspaceDescriptorPayload } from "@getpaseo/protocol/messages";
|
||||
import {
|
||||
normalizeEmptyProjectDescriptor,
|
||||
normalizeProjectDescriptor,
|
||||
normalizeWorkspaceDescriptor,
|
||||
useSessionStore,
|
||||
} from "@/stores/session-store";
|
||||
@@ -33,7 +33,7 @@ it("commits workspace and project-parent state with filtered removals", () => {
|
||||
const store = useSessionStore.getState();
|
||||
store.initializeSession(serverId, null as unknown as DaemonClient);
|
||||
const replica = new WorkspaceDirectoryReplica(serverId);
|
||||
const empty = normalizeEmptyProjectDescriptor({
|
||||
const empty = normalizeProjectDescriptor({
|
||||
projectId: "empty",
|
||||
projectDisplayName: "Empty",
|
||||
projectRootPath: "/repo/empty",
|
||||
@@ -45,14 +45,14 @@ it("commits workspace and project-parent state with filtered removals", () => {
|
||||
["kept", normalizeWorkspaceDescriptor(workspace("kept"))],
|
||||
["filtered", normalizeWorkspaceDescriptor(workspace("filtered", "filtered-project"))],
|
||||
]),
|
||||
emptyProjects: new Map([[empty.projectId, empty]]),
|
||||
projects: new Map([[empty.projectId, empty]]),
|
||||
},
|
||||
[{ kind: "remove", id: "filtered", removedProjectId: "filtered-project" }],
|
||||
);
|
||||
|
||||
const session = useSessionStore.getState().sessions[serverId];
|
||||
expect(Array.from(session?.workspaces.keys() ?? [])).toEqual(["kept"]);
|
||||
expect(Array.from(session?.emptyProjects.keys() ?? [])).toEqual(["empty"]);
|
||||
expect(Array.from(session?.projects.keys() ?? [])).toEqual(["empty"]);
|
||||
store.clearSession(serverId);
|
||||
});
|
||||
|
||||
@@ -65,19 +65,19 @@ it("commits the authoritative snapshot before buffered project updates", () => {
|
||||
const attachedFeature = normalizeWorkspaceDescriptor(workspace("attached-feature", "attached"));
|
||||
const removed = normalizeWorkspaceDescriptor(workspace("removed", "removed"));
|
||||
const unrelated = normalizeWorkspaceDescriptor(workspace("unrelated", "unrelated"));
|
||||
const staleAttachedProject = normalizeEmptyProjectDescriptor({
|
||||
const staleAttachedProject = normalizeProjectDescriptor({
|
||||
projectId: "attached",
|
||||
projectDisplayName: "Stale attached project",
|
||||
projectRootPath: "/repo/attached",
|
||||
projectKind: "git",
|
||||
});
|
||||
const removedProject = normalizeEmptyProjectDescriptor({
|
||||
const removedProject = normalizeProjectDescriptor({
|
||||
projectId: "removed",
|
||||
projectDisplayName: "Removed project",
|
||||
projectRootPath: "/repo/removed",
|
||||
projectKind: "git",
|
||||
});
|
||||
const unchangedEmptyProject = normalizeEmptyProjectDescriptor({
|
||||
const unchangedEmptyProject = normalizeProjectDescriptor({
|
||||
projectId: "unchanged-empty",
|
||||
projectDisplayName: "Unchanged empty project",
|
||||
projectRootPath: "/repo/unchanged-empty",
|
||||
@@ -92,7 +92,7 @@ it("commits the authoritative snapshot before buffered project updates", () => {
|
||||
[removed.id, removed],
|
||||
[unrelated.id, unrelated],
|
||||
]),
|
||||
emptyProjects: new Map([
|
||||
projects: new Map([
|
||||
[staleAttachedProject.projectId, staleAttachedProject],
|
||||
[removedProject.projectId, removedProject],
|
||||
[unchangedEmptyProject.projectId, unchangedEmptyProject],
|
||||
@@ -103,6 +103,7 @@ it("commits the authoritative snapshot before buffered project updates", () => {
|
||||
kind: "upsert",
|
||||
project: {
|
||||
projectId: "attached",
|
||||
projectKey: "remote:github.com/acme/attached",
|
||||
projectDisplayName: "Renamed attached project",
|
||||
projectCustomName: "Personal name",
|
||||
projectRootPath: "/moved/attached",
|
||||
@@ -135,11 +136,29 @@ it("commits the authoritative snapshot before buffered project updates", () => {
|
||||
});
|
||||
expect(session?.workspaces.has(removed.id)).toBe(false);
|
||||
expect(session?.workspaces.get(unrelated.id)).toBe(unrelated);
|
||||
expect(Array.from(session?.emptyProjects.keys() ?? [])).toEqual(["unchanged-empty", "new-empty"]);
|
||||
expect(session?.emptyProjects.get("unchanged-empty")).toBe(unchangedEmptyProject);
|
||||
expect(session?.emptyProjects.get("new-empty")).toMatchObject({
|
||||
expect(Array.from(session?.projects.keys() ?? [])).toEqual([
|
||||
"attached",
|
||||
"unchanged-empty",
|
||||
"new-empty",
|
||||
]);
|
||||
expect(session?.projects.get("unchanged-empty")).toBe(unchangedEmptyProject);
|
||||
expect(session?.projects.get("new-empty")).toMatchObject({
|
||||
projectDisplayName: "New empty project",
|
||||
projectRootPath: "/repo/new-empty",
|
||||
});
|
||||
store.clearSession(serverId);
|
||||
});
|
||||
|
||||
it("does not invent a null-key project from a workspace update", () => {
|
||||
const serverId = "workspace-before-project-update";
|
||||
const store = useSessionStore.getState();
|
||||
store.initializeSession(serverId, null as unknown as DaemonClient);
|
||||
const replica = new WorkspaceDirectoryReplica(serverId);
|
||||
|
||||
replica.applyDelta({ kind: "upsert", workspace: workspace("main", "fresh-project") });
|
||||
|
||||
const session = useSessionStore.getState().sessions[serverId];
|
||||
expect(session?.workspaces.has("main")).toBe(true);
|
||||
expect(session?.projects.has("fresh-project")).toBe(false);
|
||||
store.clearSession(serverId);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { SessionOutboundMessage } from "@getpaseo/protocol/messages";
|
||||
import {
|
||||
normalizeEmptyProjectDescriptor,
|
||||
normalizeProjectDescriptor,
|
||||
normalizeWorkspaceDescriptor,
|
||||
useSessionStore,
|
||||
type EmptyProjectDescriptor,
|
||||
type ProjectDescriptor,
|
||||
type WorkspaceDescriptor,
|
||||
} from "@/stores/session-store";
|
||||
import { useWorkspaceSetupStore } from "@/stores/workspace-setup-store";
|
||||
@@ -20,7 +20,7 @@ type ProjectDirectoryDelta = Extract<SessionOutboundMessage, { type: "project.up
|
||||
|
||||
export interface WorkspaceDirectorySnapshot {
|
||||
workspaces: Map<string, WorkspaceDescriptor>;
|
||||
emptyProjects: Map<string, EmptyProjectDescriptor>;
|
||||
projects: Map<string, ProjectDescriptor>;
|
||||
}
|
||||
|
||||
function applyProjectDelta(
|
||||
@@ -28,18 +28,17 @@ function applyProjectDelta(
|
||||
delta: ProjectDirectoryDelta,
|
||||
): void {
|
||||
if (delta.kind === "remove") {
|
||||
snapshot.emptyProjects.delete(delta.projectId);
|
||||
snapshot.projects.delete(delta.projectId);
|
||||
for (const [workspaceId, workspace] of snapshot.workspaces) {
|
||||
if (workspace.projectId === delta.projectId) snapshot.workspaces.delete(workspaceId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const project = normalizeEmptyProjectDescriptor(delta.project);
|
||||
let hasAttachedWorkspace = false;
|
||||
const project = normalizeProjectDescriptor(delta.project);
|
||||
snapshot.projects.set(project.projectId, project);
|
||||
for (const [workspaceId, workspace] of snapshot.workspaces) {
|
||||
if (workspace.projectId !== project.projectId) continue;
|
||||
hasAttachedWorkspace = true;
|
||||
snapshot.workspaces.set(workspaceId, {
|
||||
...workspace,
|
||||
projectDisplayName: project.projectDisplayName,
|
||||
@@ -48,8 +47,6 @@ function applyProjectDelta(
|
||||
projectKind: project.projectKind,
|
||||
});
|
||||
}
|
||||
if (hasAttachedWorkspace) snapshot.emptyProjects.delete(project.projectId);
|
||||
else snapshot.emptyProjects.set(project.projectId, project);
|
||||
}
|
||||
|
||||
export class WorkspaceDirectoryReplica {
|
||||
@@ -75,7 +72,7 @@ export class WorkspaceDirectoryReplica {
|
||||
const session = useSessionStore.getState().sessions[this.serverId];
|
||||
return {
|
||||
workspaces: new Map(session?.workspaces),
|
||||
emptyProjects: new Map(session?.emptyProjects),
|
||||
projects: new Map(session?.projects),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -84,7 +81,7 @@ export class WorkspaceDirectoryReplica {
|
||||
deltas: readonly WorkspaceDirectoryDelta[],
|
||||
): WorkspaceDirectorySnapshot {
|
||||
const workspaces = new Map(snapshot.workspaces);
|
||||
const emptyProjects = new Map(snapshot.emptyProjects);
|
||||
const projects = new Map(snapshot.projects);
|
||||
for (const [workspaceId, workspace] of workspaces) {
|
||||
if (shouldSuppressWorkspaceForLocalArchive({ serverId: this.serverId, workspace })) {
|
||||
workspaces.delete(workspaceId);
|
||||
@@ -92,16 +89,18 @@ export class WorkspaceDirectoryReplica {
|
||||
}
|
||||
for (const delta of deltas) {
|
||||
if ("projectId" in delta || "project" in delta) {
|
||||
applyProjectDelta({ workspaces, emptyProjects }, delta);
|
||||
applyProjectDelta({ workspaces, projects }, delta);
|
||||
continue;
|
||||
}
|
||||
if (delta.kind === "remove") {
|
||||
workspaces.delete(delta.id);
|
||||
if (delta.emptyProject) {
|
||||
const project = normalizeEmptyProjectDescriptor(delta.emptyProject);
|
||||
emptyProjects.set(project.projectId, project);
|
||||
const project = normalizeProjectDescriptor(delta.emptyProject);
|
||||
projects.set(project.projectId, project);
|
||||
}
|
||||
if (delta.removedProjectId) {
|
||||
projects.delete(delta.removedProjectId);
|
||||
}
|
||||
if (delta.removedProjectId) emptyProjects.delete(delta.removedProjectId);
|
||||
continue;
|
||||
}
|
||||
const workspace = normalizeWorkspaceDescriptor(delta.workspace);
|
||||
@@ -109,16 +108,15 @@ export class WorkspaceDirectoryReplica {
|
||||
workspaces.delete(workspace.id);
|
||||
} else {
|
||||
workspaces.set(workspace.id, workspace);
|
||||
emptyProjects.delete(workspace.projectId);
|
||||
}
|
||||
}
|
||||
return { workspaces, emptyProjects };
|
||||
return { workspaces, projects };
|
||||
}
|
||||
|
||||
private commit(snapshot: WorkspaceDirectorySnapshot, removedWorkspaceIds: string[]): void {
|
||||
const store = useSessionStore.getState();
|
||||
store.setWorkspaces(this.serverId, snapshot.workspaces);
|
||||
store.setEmptyProjects(this.serverId, snapshot.emptyProjects.values());
|
||||
store.setProjects(this.serverId, snapshot.projects.values());
|
||||
for (const workspaceId of removedWorkspaceIds) {
|
||||
clearWorkspaceArchivePending({ serverId: this.serverId, workspaceId });
|
||||
useWorkspaceSetupStore.getState().removeWorkspace({ serverId: this.serverId, workspaceId });
|
||||
|
||||
@@ -2,7 +2,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
import type { WorkspaceDescriptorPayload } from "@getpaseo/protocol/messages";
|
||||
import { normalizeAgentSnapshot } from "@/utils/agent-snapshots";
|
||||
import {
|
||||
normalizeEmptyProjectDescriptor,
|
||||
normalizeProjectDescriptor,
|
||||
normalizeWorkspaceDescriptor,
|
||||
useSessionStore,
|
||||
} from "@/stores/session-store";
|
||||
@@ -96,8 +96,15 @@ function seedSession(): void {
|
||||
SERVER_ID,
|
||||
new Map([["workspace-1", normalizeWorkspaceDescriptor(workspace())]]),
|
||||
);
|
||||
store.setEmptyProjects(SERVER_ID, [
|
||||
normalizeEmptyProjectDescriptor({
|
||||
store.setProjects(SERVER_ID, [
|
||||
normalizeProjectDescriptor({
|
||||
projectId: "project-1",
|
||||
projectKey: "remote:github.com/getpaseo/paseo",
|
||||
projectDisplayName: "Paseo",
|
||||
projectRootPath: "/repo/paseo",
|
||||
projectKind: "git",
|
||||
}),
|
||||
normalizeProjectDescriptor({
|
||||
projectId: "empty-project",
|
||||
projectDisplayName: "Empty project",
|
||||
projectRootPath: "/repo/empty",
|
||||
@@ -162,7 +169,7 @@ describe("ReplicaCache", () => {
|
||||
expect(session?.hasHydratedWorkspaces).toBe(false);
|
||||
expect(Array.from(session?.agents.keys() ?? [])).toEqual(["agent-1"]);
|
||||
expect(Array.from(session?.workspaces.keys() ?? [])).toEqual(["workspace-1"]);
|
||||
expect(Array.from(session?.emptyProjects.keys() ?? [])).toEqual([]);
|
||||
expect(Array.from(session?.projects.keys() ?? [])).toEqual(["project-1"]);
|
||||
expect(session?.agents.get("agent-1")?.updatedAt).toBeInstanceOf(Date);
|
||||
expect(session?.workspaces.get("workspace-1")?.statusEnteredAt).toBeInstanceOf(Date);
|
||||
expect(session?.agentStreamTail.get("agent-1")).toEqual([message("message-1", "Cached")]);
|
||||
@@ -213,7 +220,7 @@ describe("ReplicaCache", () => {
|
||||
const timelines = session?.agentStreamTail;
|
||||
expect(Array.from(session?.agents.keys() ?? [])).toEqual(["agent-2"]);
|
||||
expect(Array.from(session?.workspaces.keys() ?? [])).toEqual(["workspace-2"]);
|
||||
expect(Array.from(session?.emptyProjects.keys() ?? [])).toEqual([]);
|
||||
expect(Array.from(session?.projects.keys() ?? [])).toEqual(["project-2"]);
|
||||
expect(Array.from(timelines?.keys() ?? [])).toEqual(["agent-2"]);
|
||||
expect(timelines?.get("agent-2")).toEqual(secondTimeline.slice(-50));
|
||||
});
|
||||
|
||||
@@ -9,12 +9,13 @@ import {
|
||||
type WorkspaceDescriptorPayload,
|
||||
} from "@getpaseo/protocol/messages";
|
||||
import {
|
||||
normalizeEmptyProjectDescriptor,
|
||||
normalizeProjectDescriptor,
|
||||
normalizeWorkspaceDescriptor,
|
||||
useSessionStore,
|
||||
type Agent,
|
||||
type SessionReplica,
|
||||
type SessionState,
|
||||
type ProjectDescriptor,
|
||||
type WorkspaceDescriptor,
|
||||
} from "@/stores/session-store";
|
||||
import type { StreamItem } from "@/types/stream";
|
||||
@@ -50,6 +51,7 @@ const StoredHostSchema = z.object({
|
||||
serverId: z.string(),
|
||||
agents: z.array(StoredAgentSchema),
|
||||
workspaces: z.array(WorkspaceDescriptorPayloadSchema),
|
||||
projects: z.array(WorkspaceProjectDescriptorPayloadSchema).optional().default([]),
|
||||
emptyProjects: z.array(WorkspaceProjectDescriptorPayloadSchema),
|
||||
timeline: StoredTimelineSchema.nullable(),
|
||||
});
|
||||
@@ -214,18 +216,47 @@ function serializeWorkspace(workspace: WorkspaceDescriptor): WorkspaceDescriptor
|
||||
};
|
||||
}
|
||||
|
||||
function serializeProject(project: ProjectDescriptor) {
|
||||
return {
|
||||
projectId: project.projectId,
|
||||
...(project.projectKey ? { projectKey: project.projectKey } : {}),
|
||||
projectDisplayName: project.projectDisplayName,
|
||||
projectCustomName: project.projectCustomName,
|
||||
projectRootPath: project.projectRootPath,
|
||||
projectKind: project.projectKind,
|
||||
};
|
||||
}
|
||||
|
||||
function deserializeHost(stored: StoredHost): SessionReplica {
|
||||
const agents = stored.agents.map((entry) => deserializeAgent(stored.serverId, entry));
|
||||
const workspaces = stored.workspaces.map(normalizeWorkspaceDescriptor);
|
||||
const emptyProjects = stored.emptyProjects.map(normalizeEmptyProjectDescriptor);
|
||||
const listedProjects = stored.projects.map(normalizeProjectDescriptor);
|
||||
const legacyProjects = [
|
||||
...stored.emptyProjects.map(normalizeProjectDescriptor),
|
||||
...workspaces.map(legacyProjectDescriptorFromWorkspace),
|
||||
];
|
||||
const projects = new Map(
|
||||
[...legacyProjects, ...listedProjects].map((project) => [project.projectId, project]),
|
||||
);
|
||||
return {
|
||||
agents: new Map(agents.map((agent) => [agent.id, agent])),
|
||||
workspaces: new Map(workspaces.map((workspace) => [workspace.id, workspace])),
|
||||
emptyProjects: new Map(emptyProjects.map((project) => [project.projectId, project])),
|
||||
projects,
|
||||
timeline: deserializeTimeline(stored.timeline),
|
||||
};
|
||||
}
|
||||
|
||||
function legacyProjectDescriptorFromWorkspace(workspace: WorkspaceDescriptor): ProjectDescriptor {
|
||||
return {
|
||||
projectId: workspace.projectId,
|
||||
projectKey: null,
|
||||
projectDisplayName: workspace.projectDisplayName,
|
||||
projectCustomName: workspace.projectCustomName ?? null,
|
||||
projectRootPath: workspace.projectRootPath,
|
||||
projectKind: workspace.projectKind,
|
||||
};
|
||||
}
|
||||
|
||||
export class ReplicaCache {
|
||||
private readonly activeServerIds = new Set<string>();
|
||||
private readonly storedHosts = new Map<string, StoredHost>();
|
||||
@@ -384,6 +415,11 @@ export class ReplicaCache {
|
||||
serverId,
|
||||
agents: focusedAgent ? [serializeAgent(focusedAgent)] : [],
|
||||
workspaces: focusedWorkspace ? [serializeWorkspace(focusedWorkspace)] : [],
|
||||
projects: focusedWorkspace
|
||||
? [session.projects.get(focusedWorkspace.projectId)].flatMap((project) =>
|
||||
project ? [serializeProject(project)] : [],
|
||||
)
|
||||
: [],
|
||||
emptyProjects: [],
|
||||
timeline,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user