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

Task 3: Derive the profile list from Herdr

Open AkaraChen opened this issue 2 months ago • 0 comments

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

  1. 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's profiles array with DTOs built from live Herdr. Do not merge sqlite rows. Do not persist the derived list back into profiles.
    • Keep the existing Profile IPC shape (id, project_id, branch_name, worktree_path, created_at, is_default, notes) so ProjectMenuItem / ProfileList / ProfileItem / useProjectProfiles keep the same clicks and labels (m.defaultProfile() for the primary, branch_name for linked). Do not switch labels to Herdr workspace display names.
    • Git: JSON worktree.list with absolute cwd = canonical projects.folder and trust_repository: true (already how HerdrClient::worktree_list behaves). A profile ⇔ entry whose open_workspace_id / WorktreeListEntry.workspace_id is a non-empty string. Missing/null open_workspace_id is not a profile (disk checkout only).
    • Default checkout (is_default): the open workspace whose listed path (and snapshot pane cwd) is the project folder and is_linked_worktree: false. Linked worktrees are additional non-default profiles; their checkout path is not the project folder.
    • Non-git: worktree.list on that cwd is not_git_worktree — not a catalog error. Join session.snapshot panes whose cwd / foreground_cwd matches the project folder to workspace_id. Several panes in one workspace → one profile. Do not call workspace.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.list with the project folder cwd is repo-scoped; snapshot joins must still filter by the join key.
    • Fill worktree_path from the live listed path / pane cwd (display + DTO only). It is not sqlite authority. branch_name from worktree.list branch (empty string if absent).
    • Notes: remain a 2code feature on sqlite profiles.notes until Task 8. Overlay notes onto a derived DTO when a profile_runtime_mappings row exists for that workspace_id; otherwise notes is 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 start HerdrRuntimeSync / events.subscribe. Task 2 tests that lib.rs must not contain those names stay in force. Live event-driven sidebar refresh is Task 6.
  2. Empty Herdr stays empty (named UX exception)

    • No open workspaces for that path → profiles: [] for that project, even if sqlite still has default-{project_id} or other rows.
    • Disk git worktrees without open_workspace_id are 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.create so the GUI is not stuck empty.
    • Existing UI already tolerates a missing default: HomePage only redirects when is_default exists; ProjectMenuItem falls back to /projects/:id; ProjectDetailPage falls back to default/profiles[0] then /; useCreateProject only 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.
  3. Keep Git, file tree, notes, and terminal create working with workspace_id

    • Route param /projects/:id/profiles/:profileId becomes wN. Same NavLinks. That id format change is required by the contract (profile id is workspace_id); do not keep dual UUID + wN identities in the GUI list.
    • Today Git/FS/PTY cwd still repo::profile::find_by_id (sqlite UUID). That will 404 for w1. When Herdr is selected, resolve checkout by live worktree.list(None, Some(workspace_id)) or snapshot pane cwd — not profiles.worktree_path as authority. Reuse/extend reconcile_profile_checkout / a sibling so existing get_git_branch({ profileId }), file-tree, and notes commands keep the same IPC. Local flag keeps sqlite find_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. start watcher already calls list_with_runtime; if that list is Herdr-derived, watch roots follow the DTO paths. Do not add new watcher policy.
    • update_profile_notes / delete_profile still mutate sqlite (Task 4 stops that). They must accept workspace_id and find the sqlite row via profile_runtime_mappings when present. Unmapped Herdr-only workspaces: notes stay empty; delete must not invent a sqlite row. Do not add a runtime-picker UI.
  4. 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, useCreateProfile must not setQueryData the returned sqlite UUID into queryKeys.projects.all. Invalidate, refetch the Herdr-derived list, and navigate to the new workspace_id (match by live path / branch). CreateProfileDialog must 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 add as 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.
  5. Local flag and fail-closed

    • TWOCODE_RUNTIME=local / --twocode-runtime=local: list_with_runtime keeps 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. profiles stays [] (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.
  6. Prove the list without swallowing later tasks

    • Colocated tests with a fake HerdrWorktreeClient: sqlite leftover rows ignored; disk-only worktree.list entries 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_default only on the primary checkout.
    • Invert tests that assert list_with_runtime returns sqlite ids / default-{project_id} on a Herdr router (list_with_runtime_returns_reconciled_worktree_path and similar). Those become Local-flag / with_backend(Local) cases, or Herdr cases that assert workspace_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 and workspace_id route 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.

Likely files and directories

  • Update: src-tauri/crates/service/src/project.rs — Herdr-derived list_with_runtime; checkout resolve by workspace_id; invert Local-default list tests.
  • Update: src-tauri/crates/service/src/runtime/herdr.rs — only if list/snapshot helpers on HerdrWorktreeClient need a thin join helper; do not start sync.
  • Update if Git/FS still find_by_id the 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_default breaks 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, HerdrRuntimeSync startup, 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_runtime returns profiles derived from live Herdr only. Git: JSON worktree.list with cwd = canonical projects.folder; membership is non-empty open_workspace_id. Non-git: session.snapshot pane cwd. workspace.list is not a path join.
  • [ ] Profile id is Herdr workspace_id (wN). is_default is 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, yields profiles: [] for that project even when sqlite profiles rows exist. No sqlite fallback. No implicit workspace (Task 10).
  • [ ] TWOCODE_RUNTIME=local still lists sqlite nested profiles. Herdr-selected + absent/incompatible sidecar does not sqlite-fill profiles; project rows still load; profiles stays [].
  • [ ] Sidebar / profile switcher / HomePage / project detail keep the same clicks and labels. Route ids may be wN instead 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 profileId is workspace_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_sessions are not dropped. No HerdrRuntimeSync / events.subscribe. No launch/adopt. No Local PTY deletion. Pin stays v0.9.0. GUI exit still does not server stop.
  • [ ] 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.
  • [ ] 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_path writes or one-shot import (Task 5).
  • Session restore from session.snapshot as the store; dropping pty_sessions / session_runtime_mappings as authority (Task 6). Starting HerdrRuntimeSync / events.subscribe.
  • Pointing every remaining Git/file-tree/watcher consumer at live cwd as a dedicated rewrite (Task 7), beyond resolving the GUI profileId so 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 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.
  • Switching the default runtime was Task 2 (already done on the base branch). Deleting Local PTY / profiles rows 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_id rather than sqlite UUIDs.
  • One task; stack on task-2-herdr-default-runtime. Do not open a PR until the parent plan is complete.

AkaraChen avatar Sep 16 '26 03:09 AkaraChen