-
Notifications
You must be signed in to change notification settings - Fork 0
fix(supervisor): resolve each item's own project dir, not the daemon's cwd #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a561916
fix(supervisor): discovery/dispatch/execution resolve each item's own…
25a098d
Merge origin/master into task/63
6209e2d
Merge branch 'master' into task/63
getappz 2726c62
Merge origin/master into task/63
3861689
Merge remote-tracking branch 'origin/task/63' into task/63
cd3bf00
Merge branch 'master' into task/63
getappz 4e2905d
Merge branch 'master' into task/63
getappz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
crates/agentflare-backend/src/migrations/0010_project_dirs.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE TABLE IF NOT EXISTS project_dirs ( | ||
| project_id TEXT PRIMARY KEY REFERENCES projects(id) ON DELETE CASCADE, | ||
| folder_path TEXT NOT NULL, | ||
| updated_at INTEGER NOT NULL | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| use crate::error::Result; | ||
| use rusqlite::{Connection, params}; | ||
|
|
||
| /// One project's on-disk repo root — the reverse of `.agentflare/project.json` | ||
| /// (folder → project), indexed by project instead so a process with no | ||
| /// reliable cwd of its own (the daemon's background discovery loop) can | ||
| /// enumerate every project's folder it should operate against. Refreshed by | ||
| /// `resolve_project` wherever an agentflare CLI/MCP call runs inside a | ||
| /// linked repo. Unlike `bridge_repo`, not limited to GitHub-hosted repos — | ||
| /// every linked project gets a row here, regardless of its remote. | ||
| #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)] | ||
| pub struct ProjectDir { | ||
| pub project_id: String, | ||
| pub folder_path: String, | ||
| pub updated_at: i64, | ||
| } | ||
|
|
||
| fn from_row(row: &rusqlite::Row) -> rusqlite::Result<ProjectDir> { | ||
| Ok(ProjectDir { | ||
| project_id: row.get(0)?, | ||
| folder_path: row.get(1)?, | ||
| updated_at: row.get(2)?, | ||
| }) | ||
| } | ||
|
|
||
| pub fn upsert(conn: &Connection, project_id: &str, folder_path: &str, now: i64) -> Result<()> { | ||
| conn.execute( | ||
| "INSERT INTO project_dirs (project_id, folder_path, updated_at) | ||
| VALUES (?1, ?2, ?3) | ||
| ON CONFLICT(project_id) DO UPDATE SET | ||
| folder_path = excluded.folder_path, | ||
| updated_at = excluded.updated_at", | ||
| params![project_id, folder_path, now], | ||
| )?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn list(conn: &Connection) -> Result<Vec<ProjectDir>> { | ||
| let mut stmt = conn.prepare( | ||
| "SELECT project_id, folder_path, updated_at FROM project_dirs ORDER BY project_id", | ||
| )?; | ||
| let rows = stmt.query_map([], from_row)?; | ||
| Ok(rows.collect::<rusqlite::Result<Vec<_>>>()?) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| fn seed_project(conn: &Connection, name: &str) -> String { | ||
| let workspace = crate::workspace::create( | ||
| conn, | ||
| crate::workspace::CreateWorkspace { | ||
| name: name.into(), | ||
| slug: name.into(), | ||
| owner_agent: None, | ||
| item_label: None, | ||
| }, | ||
| ) | ||
| .unwrap(); | ||
| let project = crate::project::create( | ||
| conn, | ||
| crate::project::CreateProject { | ||
| workspace_id: workspace.id, | ||
| name: name.into(), | ||
| identifier: name.into(), | ||
| external_source: None, | ||
| external_id: None, | ||
| }, | ||
| ) | ||
| .unwrap(); | ||
| project.id | ||
| } | ||
|
|
||
| #[test] | ||
| fn upsert_then_list_round_trips() { | ||
| let conn = crate::db::open_in_memory().unwrap(); | ||
| let pid = seed_project(&conn, "proj"); | ||
| upsert(&conn, &pid, "/home/avihs/projects/agentflare", 100).unwrap(); | ||
|
|
||
| let rows = list(&conn).unwrap(); | ||
| assert_eq!(rows.len(), 1); | ||
| assert_eq!(rows[0].project_id, pid); | ||
| assert_eq!(rows[0].folder_path, "/home/avihs/projects/agentflare"); | ||
| assert_eq!(rows[0].updated_at, 100); | ||
| } | ||
|
|
||
| #[test] | ||
| fn upsert_on_existing_project_updates_in_place() { | ||
| let conn = crate::db::open_in_memory().unwrap(); | ||
| let pid = seed_project(&conn, "proj"); | ||
| upsert(&conn, &pid, "/old/path", 100).unwrap(); | ||
| upsert(&conn, &pid, "/new/path", 200).unwrap(); | ||
|
|
||
| let rows = list(&conn).unwrap(); | ||
| assert_eq!(rows.len(), 1, "same project must not create a second row"); | ||
| assert_eq!(rows[0].folder_path, "/new/path"); | ||
| assert_eq!(rows[0].updated_at, 200); | ||
| } | ||
|
|
||
| #[test] | ||
| fn list_returns_every_registered_project() { | ||
| let conn = crate::db::open_in_memory().unwrap(); | ||
| let p1 = seed_project(&conn, "one"); | ||
| let p2 = seed_project(&conn, "two"); | ||
| upsert(&conn, &p1, "/repo/one", 1).unwrap(); | ||
| upsert(&conn, &p2, "/repo/two", 2).unwrap(); | ||
|
|
||
| let rows = list(&conn).unwrap(); | ||
| assert_eq!(rows.len(), 2); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: getappz/agentflare
Length of output: 35424
🏁 Script executed:
Repository: getappz/agentflare
Length of output: 50374
🏁 Script executed:
Repository: getappz/agentflare
Length of output: 50375
🏁 Script executed:
Repository: getappz/agentflare
Length of output: 9269
Use the scoped repository root for both registry refreshes.
for_project_dirsets the target root, butregister_bridge_repoandregister_project_dirstill callSelf::repo_root(). A daemon worker can overwrite the target project's registry entries with the daemon's repository. Later dispatches can create worktrees in the wrong repository.Add a context-aware root helper. Use it in both methods. Add a regression test with different process and scoped roots.
🤖 Prompt for AI Agents