2code icon indicating copy to clipboard operation
2code copied to clipboard

Task 10: Launch/adopt existing checkouts

Open AkaraChen opened this issue 2 months ago • 0 comments

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

  1. Idempotent adopt of the project-folder default

    • New service seam (suggested name adopt_project_checkouts in project.rs or a sibling module). Do not revive runtime_adoption.rs leftover-sqlite import, and do not name it adopt_existing_profiles (#394 Task 8).
    • Git: JSON worktree.list with absolute cwd = canonical projects.folder. If the primary / non-linked row for that folder has no open_workspace_id, worktree.open that path (trust_repository: true, focus: false — already how HerdrClient::worktree_open behaves). already_open: true with the same workspace_id is success. Dirty checkouts are preserved; do not recreate the folder.
    • Non-git: worktree.list is not_git_worktree. If session.snapshot has no pane cwd / foreground_cwd matching 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 extra workspace.create; default adopt must not impersonate New Profile).
    • Do not worktree.create. Do not git worktree add. Do not run setup_script on the project folder (that stays New Profile / linked create). Do not INSERT sqlite profiles. Do not mint default-{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.
  2. Git disk linked checkouts in the same worktree.list

    • After the primary is open (or already open), worktree.open every listed disk checkout in that repo whose open_workspace_id is empty (linked extras). They become non-default profiles only after open succeeds. Listing them as profiles before open remains a contract failure (list_with_runtime membership is still non-empty open_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 in worktree.list.
    • Skip a path that does not exist. Uncertain open: log, do not retry in that pass.
  3. When to adopt (not the watcher poll)

    • After successful GUI Herdr JSON connect (connect_gui_herdr): adopt every sqlite projects.folder (and that project's listed git disk checkouts). Same placement as Task 5 leftover extra import — not from lib.rs. Existing HerdrRuntimeSync stays the one sync; worktree.opened / workspace.created already flow through it. Do not start a second events.subscribe.
    • list_projects: run the same idempotent adopt, then the live list, so New Project → invalidateQueries → refetch has is_default. create_from_folder stays a projects INSERT only; wiring RuntimeHandle into that handler is allowed only if refetch cannot see the default otherwise.
    • list_with_runtime used by the watcher stays a read. Do not worktree.open / workspace.create on the 3s poll (would retry uncertain opens). Empty Herdr watcher fallback to projects.folder remains only when Herdr is down / adopt failed; once the default is open, watch roots follow the live default profile.
    • Production source guards: lib.rs still must not contain HerdrRuntimeSync, events.subscribe, adopt_existing_profiles, or runtime_adoption.
  4. 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.tsx already no-ops when profiles.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_notes after adopt (path = project folder). Do not store notes in Herdr.
  5. Prove without swallowing leftovers

    • Colocated tests with a fake HerdrWorktreeClient: git empty list → one worktree.open of the folder → derived is_default workspace_id; second adopt is already_open / skip, same id; disk linked without open_workspace_id is opened and then listed as non-default; list_with_runtime without adopt still ignores disk-only; non-git empty → workspace.create --cwd, not worktree.*; non-git snapshot already matching cwd → no second create; dirty folder not recreated; Herdr-down catalog stays [] and does not sqlite-fill; create_from_folder still does not create a profiles table/row; watcher source does not call worktree.open; production guards (no worktree.create / git worktree add / insert_default / adopt_existing_profiles in lib.rs / second events.subscribe).
    • Invert tests whose production assertion is “live Herdr + real project folder ⇒ profiles: []” (herdr_empty_watcher_targets_fall_back_to_project_folder stays valid for read list_with_runtime / Herdr-down, not for list_projects after 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.

Likely files and directories

  • Update: src-tauri/crates/service/src/project.rs — adopt_project_checkouts; list_projects path adopts then lists; list_with_runtime stays read-only; invert empty-list-as-success tests for the adopt path.
  • Update: src-tauri/crates/service/src/runtime.rs — call adopt after successful connect_gui_herdr (not from lib.rs).
  • Update if the handler must see a default before refetch: src-tauri/src/handler/project.rs (list_projects / optionally create_project_from_folder).
  • Reuse: HerdrWorktreeClient::worktree_open / workspace_create, open_existing_checkout patterns (uncertain → no replay). Do not route default adopt through create_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.rs if 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.rs naming HerdrRuntimeSync, frontend detector/, 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 id is the live workspace_id for projects.folder. Git: worktree.open (or skip if already open). Non-git: workspace.create --cwd (or skip if snapshot cwd already matches). already_open keeps the same workspace_id. sqlite profiles is not source of truth and is not a table.
  • [ ] Git worktree.list disk checkouts in that repo without open_workspace_id are worktree.open’d and then appear as non-default profiles. They are not listed until open succeeds. No worktree.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_folder still writes only projects. After list_projects refetch, New Project navigates to the default workspace_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 are pane_id; splits flattened as extra tabs; non-git New Profile is extra folder workspace.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.rs still does not name HerdrRuntimeSync. Pin stays v0.9.0. GUI exit still does not server stop. No Local / TWOCODE_RUNTIME / Settings runtime toggle. projects / checkout_notes still round-trip in sqlite.
  • [ ] Tests: cargo test --workspace from src-tauri (or cargo test --workspace --exclude code where GTK is unavailable). Frontend lint/typecheck/tests if frontend scope is introduced. bun run typegen if IPC signatures change; do not edit src/generated/ by hand.
  • [ ] No pull request until parent #436 is complete.

Out of scope

  • Reintroducing Local PTY, TWOCODE_RUNTIME, a sqlite profiles catalog, 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 profiles as 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).

AkaraChen avatar Sep 16 '26 11:09 AkaraChen