Skip to content

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

fix(host-core): allow removing single-folder project groups

vastsaaa3f1fb4ef01
diff --git a/crates/host-core/src/db/project_groups.rs b/crates/host-core/src/db/project_groups.rs
index e72750b80..c57db08ec 100644
--- a/crates/host-core/src/db/project_groups.rs
+++ b/crates/host-core/src/db/project_groups.rs
@@ -142,13 +142,23 @@ impl Database {
.find(|group| group.roots.iter().any(|root| root.path == canonical)))
}
- /// Whether the path is a root of a stored (non-legacy) project group. A
- /// legacy group is only the projection of the project row itself, so it
- /// must not block removing that project.
- pub fn path_is_in_stored_project_group(&self, path: &str) -> Result<bool> {
+ /// The stored (non-legacy) project group that owns `path` as one of its
+ /// roots, if any. A legacy group is only the projection of the project row
+ /// itself, so it is never returned here.
+ pub fn stored_project_group_for_path(&self, path: &str) -> Result<Option<ProjectGroupRecord>> {
Ok(self
.project_group_for_path(path)?
- .is_some_and(|group| !group.legacy))
+ .filter(|group| !group.legacy))
+ }
+
+ /// Delete a stored project group record together with its group-scoped
+ /// memory and instructions. The underlying project rows are left untouched;
+ /// callers remove those separately when appropriate.
+ pub fn delete_project_group_record(&self, id: &str) -> Result<()> {
+ self.kv_delete(GROUP_NAMESPACE, id)?;
+ self.kv_delete(GROUP_MEMORY_NAMESPACE, id)?;
+ self.kv_delete(GROUP_INSTRUCTIONS_NAMESPACE, id)?;
+ Ok(())
}
pub fn create_project_group(&self, name: &str, paths: &[String]) -> Result<ProjectGroupRecord> {
diff --git a/crates/host-core/src/rpc/mod.rs b/crates/host-core/src/rpc/mod.rs
index 22570fd72..2ee2ab4dc 100644
--- a/crates/host-core/src/rpc/mod.rs
+++ b/crates/host-core/src/rpc/mod.rs
@@ -1554,16 +1554,26 @@ async fn handle_request(
let path = crate::db::canonical_project_path(path)
.ok_or_else(|| rpc_err(1002, "path required", "INVALID_PARAMS"))?;
let st = state.lock().await;
- if st
+ // A path that belongs to a multi-folder project group must stay put:
+ // deleting one root would orphan the rest of the group, so callers
+ // remove the folder from the group first. A single-folder stored
+ // group is just a wrapper around one project, so removing that
+ // project also removes the now-empty group record.
+ if let Some(group) = st
.db
- .path_is_in_stored_project_group(&path)
+ .stored_project_group_for_path(&path)
.map_err(|e| rpc_err(1000, e.to_string(), "INTERNAL"))?
{
- return Err(rpc_err(
- 1002,
- "project belongs to a multi-folder project group; remove the folder from the group first",
- "INVALID_PARAMS",
- ));
+ if group.roots.len() > 1 {
+ return Err(rpc_err(
+ 1002,
+ "project belongs to a multi-folder project group; remove the folder from the group first",
+ "INVALID_PARAMS",
+ ));
+ }
+ st.db
+ .delete_project_group_record(&group.id)
+ .map_err(|e| rpc_err(1000, e.to_string(), "INTERNAL"))?;
}
let session_ids = st
.db
@@ -5130,6 +5140,51 @@ mod tests {
.any(|project| project["path"].as_str() == Some(canonical.as_str())));
}
+ /// A single-folder stored project group is just a wrapper around one
+ /// project. Removing that project must succeed and delete the now-empty
+ /// group record instead of locking the project in place (issue #572).
+ #[tokio::test]
+ async fn projects_remove_deletes_single_folder_stored_group() {
+ let data_dir = tempfile::tempdir().unwrap();
+ let solo_dir = data_dir.path().join("solo");
+ fs::create_dir_all(&solo_dir).unwrap();
+ let mut app_state = AppState::open(data_dir.path()).unwrap();
+ app_state.handshook = true;
+ let solo_path = solo_dir.to_string_lossy().to_string();
+ let group = app_state
+ .db
+ .create_project_group("Solo", std::slice::from_ref(&solo_path))
+ .unwrap();
+ assert!(!group.legacy);
+ assert_eq!(group.roots.len(), 1);
+ let state = Arc::new(Mutex::new(app_state));
+
+ let result = handle_request(
+ state.clone(),
+ "projects.remove",
+ json!({ "path": solo_path }),
+ mpsc::unbounded_channel().0,
+ )
+ .await
+ .expect("a single-folder stored group must be removable");
+ assert_eq!(result["removed"], json!(true));
+
+ let canonical =
+ crate::db::canonical_project_path(&solo_path).expect("canonical project path");
+ let st = state.lock().await;
+ assert!(st
+ .db
+ .stored_project_group_for_path(&canonical)
+ .unwrap()
+ .is_none());
+ assert!(st
+ .db
+ .list_projects()
+ .unwrap()
+ .iter()
+ .all(|project| project.path != canonical));
+ }
+
/// A running turn owns its session's tools, working directory, and
/// transcript writes, so the bulk delete waits until the project is idle.
#[tokio::test]