Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(projects): reopen closed group from folder (#1303)

Lan011fff902350
diff --git a/apps/desktop/src/stores/slices/project-slice.ts b/apps/desktop/src/stores/slices/project-slice.ts
index 3717af893..9206675e3 100644
--- a/apps/desktop/src/stores/slices/project-slice.ts
+++ b/apps/desktop/src/stores/slices/project-slice.ts
@@ -96,6 +96,28 @@ async function createNamedProjectGroup(
),
];
const intent = runtime.beginNavigationIntent();
+ // Closing a project only removes it from the sidebar. Its host-owned group
+ // remains durable, so choosing that one folder again means reopen the group
+ // instead of trying to create a duplicate owner for the same path.
+ if (orderedFolders.length === 1) {
+ const { groups } = await api.listProjectGroups();
+ if (!runtime.navigationIntentIsCurrent(intent)) return;
+ const selectedPath = normalizeProjectPath(orderedFolders[0]);
+ const existing = groups.find((group) =>
+ group.roots.some((root) => normalizeProjectPath(root.path) === selectedPath),
+ );
+ if (existing) {
+ const existingPrimary = existing.primaryPath || orderedFolders[0];
+ const workspace = await get().activateProject(existingPrimary, {
+ navigationIntent: intent,
+ });
+ if (!workspace || !runtime.navigationIntentIsCurrent(intent)) return;
+ const onboarding = await api.getOnboarding();
+ if (!runtime.navigationIntentIsCurrent(intent)) return;
+ set({ createProjectDialogOpen: false, onboarding, page: "chat" });
+ return;
+ }
+ }
const created = await api.createProjectGroup(normalizedName, orderedFolders);
if (!runtime.navigationIntentIsCurrent(intent)) return;
const groupPrimary = created.group.primaryPath || primary;
diff --git a/apps/desktop/test/project-create-dialog.test.mjs b/apps/desktop/test/project-create-dialog.test.mjs
index b81ae5e6a..64c043b44 100644
--- a/apps/desktop/test/project-create-dialog.test.mjs
+++ b/apps/desktop/test/project-create-dialog.test.mjs
@@ -67,6 +67,10 @@ test("project creation creates one logical group with a primary workspace", () =
assert.match(store, /createProjectFromFolders: async \(\{ name, folders, primaryPath \}\)/);
assert.match(store, /const orderedFolders = \[/);
assert.match(store, /api\.createProjectGroup\(normalizedName, orderedFolders\)/);
+ assert.match(store, /const \{ groups \} = await api\.listProjectGroups\(\)/);
+ assert.match(store, /group\.roots\.some\(\(root\) => normalizeProjectPath\(root\.path\) === selectedPath\)/);
+ assert.match(store, /const existingPrimary = existing\.primaryPath \|\| orderedFolders\[0\]/);
+ assert.match(store, /get\(\)\.activateProject\(existingPrimary/);
assert.match(store, /created\.group\.primaryPath/);
assert.doesNotMatch(store, /for \(const path of orderedFolders\)/);
assert.match(store, /get\(\)\.renameProject\(groupPrimary, normalizedName\)/);
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index a378a05ee..88cd18252 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -525,7 +525,12 @@ visually distinct from list content.
one logical project group: the primary folder is activated and names the
group, while every other selected folder is retained as a group root and is
shown in Project archive details, not as an open project tab. Group chats,
- instructions, and memory use the same group identity. A source selector
+ instructions, and memory use the same group identity. If a local selection
+ contains exactly one root already owned by a durable group, Create reopens
+ that group at its primary root instead of creating a duplicate group; this
+ applies when the group was closed from the sidebar. A multi-folder selection
+ that overlaps an existing group remains subject to host duplicate-root
+ validation. A source selector
offers This computer and Git repository: the git source swaps the folder
list for a repository URL field plus a clone destination row and creates
the project by cloning into the chosen folder first. The dialog follows
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 2b394fe74..a8b7f613a 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -14559,6 +14559,21 @@ plugin-form fixtures in an isolated temporary directory at runtime.
- **Status**: Unit-covered (`apps/desktop/test/project-create-dialog.test.mjs`,
`apps/desktop/test/git-clone.test.mjs`); full UI scenario Draft (run only in a
capable environment when this surface changes)
+
+#### E2E-261: Creating from a closed project folder reopens its group
+
+- **Preconditions**: A durable project group exists for a local folder and is
+ closed from the sidebar; its directory remains available.
+- **Steps**: Open Create project, select only that folder, and click Create.
+- **Expected**: The existing group reopens at its primary root, appears in the
+ sidebar, and the dialog closes. Its existing name, roots, chats, instructions,
+ and memory remain intact; no duplicate project group is created.
+- **Specs linked**: `04-ux/08-component-spec.md`, ADR 0249.
+- **Acceptance**: The production creation action resolves the host group before
+ attempting creation and activates the existing primary path.
+- **Milestone**: M5 (project organization maintenance).
+- **Status**: Unit/source-contract covered (`apps/desktop/test/project-create-dialog.test.mjs`);
+ full UI scenario remains Draft.
#### E2E-257: Importing into an archived project restores its visibility
- **Preconditions**: A durable project has been archived in the renderer