Task 10: Launch/adopt existing checkouts
Summary
Launch/adopt existing checkouts for parent plan #436. After Task 9 (#452 on task-9-delete-local-pty) Local PTY is gone, pty_sessions is DROPped, and the GUI is Herdr-only — but opening a 2code project still leaves empty profiles: [] until some other client has already opened that folder. Git New Profile can limp along with worktree.create --cwd, but HomePage / New Project / the sidebar still have no default profile, and Git New Profile has no live primary workspace_id. This task starts or adopts the Herdr workspace for projects.folder (worktree.open / workspace.create as appropriate) so the GUI always has a derived profile without a sqlite seed.
A profile remains an open Herdr workspace. The profile id is the Herdr workspace_id (wN). Join key: canonical projects.folder ↔ live checkout / pane cwd (Task 1 contract, docs/herdr-integration.md). projects / project_groups / checkout_notes stay. sqlite profiles stays absent. Do not reintroduce Local / TWOCODE_RUNTIME. Do not start a second events.subscribe / name HerdrRuntimeSync in lib.rs. Pin stays v0.9.0. GUI exit still does not server stop.
This is #436 Task 10, not #394 Task 8 (#417 sqlite-seeded adopt) and not #394 Task 10 (#396 Windows frame bridge). Do not implement those.
Dependencies: Parent plan #436. Prerequisites: #437 (Task 1), #439 (Task 2), #441 (Task 3), #443 (Task 4), #445 (Task 5), #448 (Task 6), #449 (Task 7), #451 (Task 8), #452 (Task 9). Open #438, #440, #442, #444, #450, #453 are line-count tracking only — not blockers. Open #454 is Task 9 AGENTS.md copy and does not block this task. Open #446 / #447 were resolved by Tasks 6/8/9. Open #394 issues #395–#434 (including #394 Task 8 / #417 and #394 Task 10 / #396) must not be implemented or closed here.
Work to complete
-
Idempotent adopt of the project-folder default
- New service seam (suggested name
adopt_project_checkoutsinproject.rsor a sibling module). Do not reviveruntime_adoption.rsleftover-sqlite import, and do not name itadopt_existing_profiles(#394 Task 8). - Git: JSON
worktree.listwith absolutecwd= canonicalprojects.folder. If the primary / non-linked row for that folder has noopen_workspace_id,worktree.openthat path (trust_repository: true,focus: false— already howHerdrClient::worktree_openbehaves).already_open: truewith the sameworkspace_idis success. Dirty checkouts are preserved; do not recreate the folder. - Non-git:
worktree.listisnot_git_worktree. Ifsession.snapshothas no panecwd/foreground_cwdmatching the project folder,workspace.create --cwd(absolute,focus: false). If a workspace for that cwd already exists, do not create a second one (non-git New Profile is extraworkspace.create; default adopt must not impersonate New Profile). - Do not
worktree.create. Do notgit worktree add. Do not runsetup_scripton the project folder (that stays New Profile / linked create). Do not INSERT sqliteprofiles. Do not mintdefault-{project_id}. - Uncertain JSON (
HerdrUncertainOutcome) is never auto-replayed (same as Task 4/5). Log per-project Failed outcomes. Do not fail the whole catalog or flip anything to Local (Local is gone). - Primary / project-folder delete stays refused (Task 4). Adopt does not make the default deletable.
- New service seam (suggested name
-
Git disk linked checkouts in the same
worktree.list- After the primary is open (or already open),
worktree.openevery listed disk checkout in that repo whoseopen_workspace_idis empty (linked extras). They become non-default profiles only after open succeeds. Listing them as profiles before open remains a contract failure (list_with_runtimemembership is still non-emptyopen_workspace_id). - Do not scan unrelated directories. Do not invent a 2code extras table to rediscover non-git extra folder workspaces after a Herdr cold start — only the project-folder default is
workspace.create. Linked git extras survive because they remain on-disk worktrees inworktree.list. - Skip a path that does not exist. Uncertain open: log, do not retry in that pass.
- After the primary is open (or already open),
-
When to adopt (not the watcher poll)
- After successful GUI Herdr JSON connect (
connect_gui_herdr): adopt every sqliteprojects.folder(and that project's listed git disk checkouts). Same placement as Task 5 leftover extra import — not fromlib.rs. ExistingHerdrRuntimeSyncstays the one sync;worktree.opened/workspace.createdalready flow through it. Do not start a secondevents.subscribe. list_projects: run the same idempotent adopt, then the live list, so New Project →invalidateQueries→ refetch hasis_default.create_from_folderstays aprojectsINSERT only; wiringRuntimeHandleinto that handler is allowed only if refetch cannot see the default otherwise.list_with_runtimeused by the watcher stays a read. Do notworktree.open/workspace.createon the 3s poll (would retry uncertain opens). Empty Herdr watcher fallback toprojects.folderremains only when Herdr is down / adopt failed; once the default is open, watch roots follow the live default profile.- Production source guards:
lib.rsstill must not containHerdrRuntimeSync,events.subscribe,adopt_existing_profiles, orruntime_adoption.
- After successful GUI Herdr JSON connect (
-
Close the empty-list exception without a UI redesign
- Same clicks/labels: New Project, sidebar Default / branch names, HomePage redirect to
/projects/:id/profiles/:workspaceId, CreateProjectDialog navigate when the refetched catalog has a profile (CreateProjectDialog.tsxalready no-ops whenprofiles.length === 0). - Close the Task 3 named exception (“project with no profile sub-items until Task 10”) for the Herdr-up path. Herdr-down / absent sidecar still yields
profiles: [](fail-closed, already named). Do not add a new empty-state page. Do not switch labels to Herdr display names. - Notes overlay by live cwd on
checkout_notesafter adopt (path = project folder). Do not store notes in Herdr.
- Same clicks/labels: New Project, sidebar Default / branch names, HomePage redirect to
-
Prove without swallowing leftovers
- Colocated tests with a fake
HerdrWorktreeClient: git empty list → oneworktree.openof the folder → derivedis_defaultworkspace_id; second adopt isalready_open/ skip, same id; disk linked withoutopen_workspace_idis opened and then listed as non-default;list_with_runtimewithout adopt still ignores disk-only; non-git empty →workspace.create --cwd, notworktree.*; non-git snapshot already matching cwd → no second create; dirty folder not recreated; Herdr-down catalog stays[]and does not sqlite-fill;create_from_folderstill does not create aprofilestable/row; watcher source does not callworktree.open; production guards (noworktree.create/git worktree add/insert_default/adopt_existing_profilesinlib.rs/ secondevents.subscribe). - Invert tests whose production assertion is “live Herdr + real project folder ⇒
profiles: []” (herdr_empty_watcher_targets_fall_back_to_project_folderstays valid for readlist_with_runtime/ Herdr-down, not forlist_projectsafter adopt). - Update
docs/herdr-integration.md: Task 10 done on this branch; empty-list exception closed when Herdr is up; disk git checkouts are opened; watcher fallback only when Herdr-down. Do not bump v0.9.0. If line count grows past the estimate, open a tracking issue; there is no Task 11 on this plan. - Frontend tests only if HomePage / CreateProjectDialog / sidebar would still treat an adopted default as empty. Do not restyle.
- Colocated tests with a fake
Likely files and directories
- Update:
src-tauri/crates/service/src/project.rs—adopt_project_checkouts;list_projectspath adopts then lists;list_with_runtimestays read-only; invert empty-list-as-success tests for the adopt path. - Update:
src-tauri/crates/service/src/runtime.rs— call adopt after successfulconnect_gui_herdr(not fromlib.rs). - Update if the handler must see a default before refetch:
src-tauri/src/handler/project.rs(list_projects/ optionallycreate_project_from_folder). - Reuse:
HerdrWorktreeClient::worktree_open/workspace_create,open_existing_checkoutpatterns (uncertain → no replay). Do not route default adopt throughcreate_with_runtime/worktree.create. - Update:
docs/herdr-integration.md— Task 10 done on this branch. - Update tests: colocated project/runtime tests;
src-tauri/tests/integration_project.rsif create/list coverage lives there. - Touch only if navigation still misses the default:
src/features/projects/CreateProjectDialog.tsx,src/features/home/HomePage.tsx,src/layout/sidebar/ProjectMenuItem.tsx— no redesign. - Do not change: Local adapter (gone), sidecar pin, Settings runtime toggle, Git/file-tree/notes/tab UI,
lib.rsnamingHerdrRuntimeSync, frontenddetector/, Diesel schema (no new sqlite profile catalog).
Estimated changes: 400–700 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
- [ ] With Herdr up, opening/listing a 2code project always has a derived default profile whose
idis the liveworkspace_idforprojects.folder. Git:worktree.open(or skip if already open). Non-git:workspace.create --cwd(or skip if snapshot cwd already matches).already_openkeeps the sameworkspace_id. sqliteprofilesis not source of truth and is not a table. - [ ] Git
worktree.listdisk checkouts in that repo withoutopen_workspace_idareworktree.open’d and then appear as non-default profiles. They are not listed until open succeeds. Noworktree.create,git worktree add, or sqlite profile INSERT. Non-git extra folder workspaces are not rediscovered from disk. - [ ]
list_with_runtime(watcher) does not adopt. Disk-only entries remain non-profiles on the read path. Herdr-down / absent sidecar:profiles: [], project rows still sqlite, no sqlite-fill. - [ ]
create_from_folderstill writes onlyprojects. Afterlist_projectsrefetch, New Project navigates to the defaultworkspace_id. HomePage redirects; sidebar shows Default. Task 3 empty-list exception is closed when Herdr is up. Herdr-down empty list stays fail-closed. - [ ] Named UX exceptions that remain: route ids are
workspace_id; tab ids arepane_id; splits flattened as extra tabs; non-git New Profile is extra folderworkspace.create; Herdr-down New Tab errors. No new click/label exception. Default Herdr New Profile / Delete Profile / tab clicks stay. Primary delete still refused. - [ ] No second
events.subscribe.lib.rsstill does not nameHerdrRuntimeSync. Pin stays v0.9.0. GUI exit still does notserver stop. No Local /TWOCODE_RUNTIME/ Settings runtime toggle.projects/checkout_notesstill round-trip in sqlite. - [ ] 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. - [ ] No pull request until parent #436 is complete.
Out of scope
- Reintroducing Local PTY,
TWOCODE_RUNTIME, a sqliteprofilescatalog, or mapping tables. - #394 Task 8 sqlite-seeded adopt (#417) and #394 Task 10 frame bridge (#396).
- Starting a new
HerdrRuntimeSync/events.subscribe, changing the v0.9.0 pin, or #394 Task 16 / #432. - Fixing #454 (Task 9 AGENTS.md copy) or line-count trackers.
- Implementing or closing #394 issues #395–#434.
- Remote Herdr machines. Redesigning sidebar / Git / file tree / notes / tabs.
- Opening a pull request.
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.
- Never let Local and Herdr own the same worktree (Local is removed).
- Preserve existing 2code interaction. UX change is allowed only when Herdr cannot back the old clicks/labels; this task closes the empty-profile-list exception and names no new GUI exception. Herdr-down empty list is fail-closed, not a redesign.
- One task; stack on
task-9-delete-local-pty. Do not open a PR until the parent plan is complete.
Why this is next
#436 has ten tasks. 1–9 are implemented on stacked branches through task-9-delete-local-pty. Task 10 is the only remaining plan item and is not tracked by an in-flight gap issue (#454 does not block it).