Task 3: Derive the profile list from Herdr
Summary
Derive the sidebar / profile-switcher list from live Herdr for parent plan #436. After Task 2 (#439 on task-2-herdr-default-runtime) Herdr is the production default, but list_projects still returns nested sqlite profiles via list_with_runtime → list_all_with_profiles. useProjectProfiles only filters that cache. This task stops reading profiles for that UI.
A profile is an open Herdr workspace. The profile id is the Herdr workspace_id (wN), not a UUID 2code mints into profiles.id. Join key: canonical projects.folder ↔ live checkout / pane cwd (Task 1 contract, docs/herdr-integration.md). Empty Herdr → empty profile list — not leftover sqlite rows, not disk git worktrees without open_workspace_id. Do not start/adopt workspaces (Task 10). Do not INSERT/DELETE profiles as the list authority (Task 4). Do not drop mapping tables (Task 5) or profiles (Task 8). Do not start HerdrRuntimeSync / events.subscribe (Task 6). Do not redesign project/profile/Git/file-tree/notes/tab clicks or labels.
The contract marks #436 Task 3 proceed on Linux x86_64: JSON worktree.list (git, repo-scoped) + session.snapshot pane cwd (including non-git). workspace.list is session-global and omits checkout path on v0.9.0 — not a path join. Reuse HerdrWorktreeClient::worktree_list / session_snapshot. Keep the v0.9.0 pin.
Dependencies: Parent plan #436. Prerequisites: #437 (Task 1, task-1-client-mode-contract), #439 (Task 2, task-2-herdr-default-runtime). Open #438 and #440 are line-count tracking only — not blockers and not work for this branch. Open #394 issues #395–#434 do not block this list rewrite and must not be implemented or closed here.
Work to complete
-
Replace the GUI catalog profiles with a Herdr-derived list
list_with_runtime/list_projects: keep loading sqlite projects (and groups). When the selected backend is Herdr, replace each project'sprofilesarray with DTOs built from live Herdr. Do not merge sqlite rows. Do not persist the derived list back intoprofiles.- Keep the existing
ProfileIPC shape (id,project_id,branch_name,worktree_path,created_at,is_default,notes) soProjectMenuItem/ProfileList/ProfileItem/useProjectProfileskeep the same clicks and labels (m.defaultProfile()for the primary,branch_namefor linked). Do not switch labels to Herdr workspace display names. - Git: JSON
worktree.listwith absolutecwd= canonicalprojects.folderandtrust_repository: true(already howHerdrClient::worktree_listbehaves). A profile ⇔ entry whoseopen_workspace_id/WorktreeListEntry.workspace_idis a non-empty string. Missing/nullopen_workspace_idis not a profile (disk checkout only). - Default checkout (
is_default): the open workspace whose listedpath(and snapshot panecwd) is the project folder andis_linked_worktree: false. Linked worktrees are additional non-default profiles; their checkout path is not the project folder. - Non-git:
worktree.liston that cwd isnot_git_worktree— not a catalog error. Joinsession.snapshotpanes whosecwd/foreground_cwdmatches the project folder toworkspace_id. Several panes in one workspace → one profile. Do not callworkspace.create. workspace.list: optional for labels of ids already joined by path. Never use it to decide membership (session-global; v0.9.0 omits checkout path).- Repo isolation: a second project's workspaces must not appear.
worktree.listwith the project foldercwdis repo-scoped; snapshot joins must still filter by the join key. - Fill
worktree_pathfrom the live listed path / pane cwd (display + DTO only). It is not sqlite authority.branch_namefromworktree.listbranch(empty string if absent). - Notes: remain a 2code feature on sqlite
profiles.notesuntil Task 8. Overlay notes onto a derived DTO when aprofile_runtime_mappingsrow exists for thatworkspace_id; otherwisenotesis empty. Mapping is not list membership. Do not store notes in Herdr. Do not move notes to a new table. - One-shot list per
list_projects(and existing invalidation). Do not startHerdrRuntimeSync/events.subscribe. Task 2 tests thatlib.rsmust not contain those names stay in force. Live event-driven sidebar refresh is Task 6.
-
Empty Herdr stays empty (named UX exception)
- No open workspaces for that path →
profiles: []for that project, even if sqlite still hasdefault-{project_id}or other rows. - Disk git worktrees without
open_workspace_idare not profiles. Listing them as sqlite-style profiles is a contract failure. - Do not synthesize an implicit workspace or seed the GUI from sqlite. Task 10 later
worktree.open/workspace.createso the GUI is not stuck empty. - Existing UI already tolerates a missing default:
HomePageonly redirects whenis_defaultexists;ProjectMenuItemfalls back to/projects/:id;ProjectDetailPagefalls back to default/profiles[0]then/;useCreateProjectonly navigates into a profile when the refetched catalog has one. Keep those clicks; do not add a new empty-state page. Stale sqlite UUIDs in the URL must not resolve via sqlite — fall back as today once the Herdr list has no match. - Named exception (not a click/label redesign): a project can appear in the sidebar with no profile sub-items until Task 10. Creating a project still INSERTs sqlite
profiles(until Tasks 4/8) but the GUI must ignore those rows. Same New Project / New Profile controls.
- No open workspaces for that path →
-
Keep Git, file tree, notes, and terminal create working with
workspace_id- Route param
/projects/:id/profiles/:profileIdbecomeswN. Same NavLinks. That id format change is required by the contract (profile id isworkspace_id); do not keep dual UUID +wNidentities in the GUI list. - Today Git/FS/PTY cwd still
repo::profile::find_by_id(sqlite UUID). That will 404 forw1. When Herdr is selected, resolve checkout by liveworktree.list(None, Some(workspace_id))or snapshot pane cwd — notprofiles.worktree_pathas authority. Reuse/extendreconcile_profile_checkout/ a sibling so existingget_git_branch({ profileId }), file-tree, and notes commands keep the same IPC. Local flag keeps sqlitefind_by_id. - Do not turn this into Task 7: no extra watcher redesign, no dropping the sqlite path cache column, no retarget of every leftover consumer beyond what the GUI profileId now is.
startwatcher already callslist_with_runtime; if that list is Herdr-derived, watch roots follow the DTO paths. Do not add new watcher policy. update_profile_notes/delete_profilestill mutate sqlite (Task 4 stops that). They must acceptworkspace_idand find the sqlite row viaprofile_runtime_mappingswhen present. Unmapped Herdr-only workspaces: notes stay empty; delete must not invent a sqlite row. Do not add a runtime-picker UI.
- Route param
-
Create/delete still write sqlite, but the list cache must not
- Task 4 still owns stopping INSERT/DELETE
profiles. Create may still create a Herdr worktree (existing Herdr-default path) and INSERT sqlite. After create,useCreateProfilemust notsetQueryDatathe returned sqlite UUID intoqueryKeys.projects.all. Invalidate, refetch the Herdr-derived list, and navigate to the newworkspace_id(match by live path / branch).CreateProfileDialogmust not route to the sqlite id. - Same for delete: invalidate/refetch; do not keep a sqlite row in the sidebar. Dual-backend bind still refuses. Do not
git worktree addas a silent Local fallback. - Do not write a new sqlite
worktree_path/ mapping row that can disagree with live Herdr and still win. Existing mapping writes from create may continue until Task 5; do not add a new authority cache. Do not use mapping membership to hide an open Herdr workspace.
- Task 4 still owns stopping INSERT/DELETE
-
Local flag and fail-closed
TWOCODE_RUNTIME=local/--twocode-runtime=local:list_with_runtimekeeps today's sqlite nested profiles (explicit fallback until Task 9). Do not call Herdr list as the Local catalog.- Herdr selected and sidecar/namespace absent or incompatible: do not fill profiles from sqlite. Project rows still come from sqlite.
profilesstays[](same visible outcome as empty Herdr). Do not flip the selector to Local. Do not add #394 Task 18 health UI. Creating a terminal still fail-closes per Task 2. - Local must never own a worktree/workspace Herdr already owns.
-
Prove the list without swallowing later tasks
- Colocated tests with a fake
HerdrWorktreeClient: sqlite leftover rows ignored; disk-onlyworktree.listentries ignored; primary + linked open workspaces; second-repo isolation; non-git snapshot cwd join; empty snapshot → empty list; Local flag still sqlite; Herdr-down does not sqlite-fill;is_defaultonly on the primary checkout. - Invert tests that assert
list_with_runtimereturns sqlite ids /default-{project_id}on a Herdr router (list_with_runtime_returns_reconciled_worktree_pathand similar). Those become Local-flag /with_backend(Local)cases, or Herdr cases that assertworkspace_id. - Frontend: keep using
queryKeys.projects.all. Add/adjust tests only if navigation/cache injection would resurrect sqlite UUIDs. Do not restyle the sidebar. - Update
docs/herdr-integration.md: Task 3 done on this branch; empty list andworkspace_idroute ids recorded. Do not bump v0.9.0. If the line count grows past the estimate, open a tracking issue; do not fold Task 4+ into this branch.
- Colocated tests with a fake
Likely files and directories
- Update:
src-tauri/crates/service/src/project.rs— Herdr-derivedlist_with_runtime; checkout resolve byworkspace_id; invert Local-default list tests. - Update:
src-tauri/crates/service/src/runtime/herdr.rs— only if list/snapshot helpers onHerdrWorktreeClientneed a thin join helper; do not start sync. - Update if Git/FS still
find_by_idthe GUI profileId:src-tauri/crates/service/src/filesystem.rs,src-tauri/src/handler/project.rs,src-tauri/src/handler/filesystem.rs,src-tauri/crates/service/src/profile.rs(notes/delete identity only). - Update:
src/features/profiles/hooks.ts,src/features/profiles/CreateProfileDialog.tsx— refetch Herdr list; do not cache/navigate sqlite UUIDs. - Update:
docs/herdr-integration.md— Task 3 done on this branch. - Touch only if empty-list / missing
is_defaultbreaks a redirect:src/features/home/HomePage.tsx,src/features/projects/ProjectDetailPage.tsx,src/layout/sidebar/ProjectMenuItem.tsx— behavior already mostly correct; no redesign. - Do not change: Diesel migrations, dropping
profiles/ mapping tables,HerdrRuntimeSyncstartup, Local adapter internals, PTY spawn, sidecar pin, Settings runtime toggle, Git/file-tree feature redesign, launch/adopt on project open.
Estimated changes: 350–600 lines total, additions plus deletions, including tests; excluding generated files, lockfile churn and binary artifacts. Material scope growth should become a separate issue.
Acceptance criteria
- [ ] Herdr-selected
list_projects/list_with_runtimereturns profiles derived from live Herdr only. Git: JSONworktree.listwithcwd= canonicalprojects.folder; membership is non-emptyopen_workspace_id. Non-git:session.snapshotpanecwd.workspace.listis not a path join. - [ ] Profile
idis Herdrworkspace_id(wN).is_defaultis the open primary checkout (project folder, not linked). Linked open worktrees are extra non-default profiles. A second repo's workspaces do not appear. - [ ] Empty Herdr, or disk git checkouts without
open_workspace_id, yieldsprofiles: []for that project even when sqliteprofilesrows exist. No sqlite fallback. No implicit workspace (Task 10). - [ ]
TWOCODE_RUNTIME=localstill lists sqlite nested profiles. Herdr-selected + absent/incompatible sidecar does not sqlite-fill profiles; project rows still load;profilesstays[]. - [ ] Sidebar / profile switcher / HomePage / project detail keep the same clicks and labels. Route ids may be
wNinstead of UUIDs (named identity exception). Empty profile list under a project until Task 10 is the only other named UX exception. - [ ] Git, file tree, notes overlay, and New Tab still function when
profileIdisworkspace_id(live checkout resolve). Create/delete may still write sqlite (Task 4) but must not inject sqlite UUID rows into the GUI list cache or navigate to them. - [ ] sqlite
profiles/ mapping tables /pty_sessionsare not dropped. NoHerdrRuntimeSync/events.subscribe. No launch/adopt. No Local PTY deletion. Pin stays v0.9.0. GUI exit still does notserver stop. - [ ] Tests:
cargo test --workspacefromsrc-tauri(orcargo test --workspace --exclude codewhere GTK is unavailable). Frontend lint/typecheck/tests if frontend scope is introduced.bun run typegenif IPC signatures change; do not editsrc/generated/by hand. - [ ] Another developer can run without the Local flag and see only open Herdr workspaces in the sidebar, and with the Local flag and see the old sqlite list.
Out of scope
- Create/delete profile without INSERT/DELETE
profiles(Task 4). - Stopping mapping /
worktree_pathwrites or one-shot import (Task 5). - Session restore from
session.snapshotas the store; droppingpty_sessions/session_runtime_mappingsas authority (Task 6). StartingHerdrRuntimeSync/events.subscribe. - Pointing every remaining Git/file-tree/watcher consumer at live cwd as a dedicated rewrite (Task 7), beyond resolving the GUI
profileIdso existing clicks still work. - Dropping sqlite
profiles(Task 8), deleting the Local PTY runtime (Task 9), launch/adopt on project open (Task 10). - Implementing or closing #394 issues #395–#434 (including leftover Tasks 18–23, gap issues, and line-count trackers) or #438 / #440.
- Remote Herdr machines. User-facing runtime health UI. Changing the v0.9.0 pin. Redesigning the sidebar.
- Opening a pull request (parent plan: no PR until #436 is complete).
Standing constraints
- Do not treat sqlite
profilesas source of truth. Do not add a path cache that can disagree with live Herdr and still win. projects(and project groups / notes-as-2code-data) remain 2code sqlite.- Join key remains path ↔ live Herdr cwd/worktree group.
- Switching the default runtime was Task 2 (already done on the base branch). Deleting Local PTY /
profilesrows is in scope for Tasks 8–9, not this task. - Never let Local and Herdr own the same worktree.
- Preserve existing 2code interaction (project list, profile switcher, create/delete profile, Git, file tree, notes, terminal tabs). Do not redesign those flows. UX change is allowed only when Herdr cannot back the old clicks/labels; named exceptions: (1) empty profile list when Herdr has no open workspace for that path (until Task 10); (2) profile route ids are Herdr
workspace_idrather than sqlite UUIDs. - One task; stack on
task-2-herdr-default-runtime. Do not open a PR until the parent plan is complete.