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

Task 7: Point Git, file tree, and watchers at live Herdr cwd

Open AkaraChen opened this issue 2 months ago • 0 comments

Summary

Point Git, the file tree, and watchers at live Herdr cwd for parent plan #436. After Task 6 (#448 on task-6-herdr-session-store) tabs restore from session.snapshot / pane_id, but leftover sqlite Git/FS helpers and watch roots can still use profiles.worktree_path and disagree with live Herdr. This task makes every path used by Git IPC, filesystem watch, the sidebar tree, and editor/open-in-app joins come from the focused Herdr workspace. No sqlite cache that can go stale and still win.

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). Reuse reconcile_profile_checkout / live_workspace_checkout (worktree.list then snapshot pane cwd). Do not write profiles.worktree_path. Do not DROP profiles / mapping tables (Task 8). Do not delete Local PTY (Task 9). Do not launch/adopt the project-folder default (Task 10). Do not start a second events.subscribe / name HerdrRuntimeSync in lib.rs. Do not redesign Git / file-tree / notes / tab clicks or labels. Pin stays v0.9.0. Local remains TWOCODE_RUNTIME=local until Task 9. Local must never own a worktree Herdr already owns.

Handlers already call reconcile_profile_checkout for Git IPC and most file-tree IPC (Task 3). Leftover service Git/FS functions still repo::profile::find_by_id (get_diff, search_file, delete_check, and siblings). Integration tests still exercise those sqlite paths. Watcher roots come from list_with_runtime DTOs (live at poll) but are not proven to ignore leftover sqlite /stale. This task closes those holes.

Dependencies: Parent plan #436. Prerequisites: #437 (Task 1), #439 (Task 2), #441 (Task 3), #443 (Task 4), #445 (Task 5), #448 (Task 6). Open #438, #440, #442, #444 are line-count tracking only — not blockers. Open #446 is a Task 5 Local-flag delete gap (wait for Task 8/9 or a dedicated follow-up) — not this branch. Open #447 was Task 6 session-store work — not this branch. Open #394 issues #395–#434 (including #394 Task 16 / #432) must not be implemented or closed here.

Work to complete

  1. Git IPC and leftover Git service helpers use live cwd

    • Herdr-selected Git must call reconcile_profile_checkout (live workspace_id → worktree.list path / snapshot pane cwd). Do not repo::profile::find_by_id for the checkout. sqlite profiles.worktree_path must not win over a different live path.
    • Rewire leftover service helpers that still sqlite-resolve: get_diff, get_diff_stats, get_log, get_commit_diff, get_binary_preview, commit_changes, discard_file_changes, get_ahead_count, push, and delete_check (Git stats only). Handlers may keep calling infra::git after reconcile, or go through the rewired service functions — one Herdr path, no sqlite checkout.
    • get_github_avatar stays on sqlite projects.folder (project catalog, not a profile path).
    • TWOCODE_RUNTIME=local keeps sqlite find_by_id / reconcile_local_profile_checkout.
    • Herdr-selected + absent/incompatible sidecar or unknown workspace_id: fail closed (NotFound / existing Herdr-absent errors). Do not sqlite-fill /stale. Do not flip the selector to Local.
  2. File tree, search, reveal, and editor-open paths use the same live seam

    • Delete or stop calling sqlite-only search_file / get_file_tree_git_status. Production already has *_for_profile wrappers; make those the only path. Integration tests must not keep a sqlite-winning helper alive.
    • Sidebar tree IPC already takes profileId (FileTreePanel → list_file_tree_child_paths / git status). Keep those clicks. The rootPath / worktreePath props may stay as the Herdr-derived catalog DTO for clipboard, absolute-path join, and Git discard/open — that DTO is live-listed, not sqlite authority. Do not read leftover profiles.worktree_path in the GUI.
    • Topbar editor/terminal launch (open_topbar_app via controls.tsx) may keep a path argument if it is the live catalog DTO. Do not add a sqlite lookup. Do not redesign the buttons.
    • Reveal / open-in-default-app already reconcile; keep them on that seam.
  3. Watcher roots from live Herdr cwd, not leftover sqlite

    • watcher_targets must watch Herdr-derived list_with_runtime checkouts when Herdr is selected. Leftover sqlite /stale that is not an open workspace must not be a watch root.
    • Keep today's shape: one watch per open profile, plus projects.folder only when no profile checkout is the project folder (empty Herdr until Task 10). Do not add a new watcher UI. Do not watch disk git worktrees without open_workspace_id.
    • Source roots from the live list/reconcile seam. Do not persist listed paths to sqlite. Do not add a path-cache table/column. The existing 3s list_with_runtime poll is enough if that list is Herdr-derived; do not start a second events.subscribe or name HerdrRuntimeSync in lib.rs. Task 6 already starts sync on GUI connect.
    • TWOCODE_RUNTIME=local keeps sqlite nested-profile roots.
  4. Prove without swallowing later tasks

    • Colocated / integration tests with a fake HerdrWorktreeClient: Git diff/log/status/commit/discard/ahead/push/delete-check against workspace_id use live /listed, not leftover sqlite /stale; unknown wN is NotFound (no sqlite fallback); Local flag still sqlite; Herdr-down does not sqlite-fill; watcher targets omit leftover /stale and include live listed paths; file search / tree git status same seam.
    • Invert integration_git.rs / integration_filesystem.rs callers of sqlite get_diff / search_file so they cannot pass on a Herdr router by reading leftover rows. Keep Local-flag coverage for those helpers if they remain.
    • Update docs/herdr-integration.md: Task 7 done on this branch. Do not bump v0.9.0. If line count grows past the estimate, open a tracking issue; do not fold Task 8+ into this branch.

Likely files and directories

  • Update: src-tauri/crates/service/src/project.rs — Git helpers on reconcile_profile_checkout; invert sqlite-winning tests.
  • Update: src-tauri/crates/service/src/filesystem.rs — remove or Local-only the sqlite search_file / get_file_tree_git_status helpers.
  • Update: src-tauri/crates/service/src/watcher.rs — prove / keep roots from live list DTOs; no leftover sqlite /stale.
  • Update if delete-check still sqlite-resolves: src-tauri/crates/service/src/profile.rs (delete_check only).
  • Update: src-tauri/tests/integration_git.rs, src-tauri/tests/integration_filesystem.rs.
  • Update: docs/herdr-integration.md — Task 7 done on this branch.
  • Touch only if a command still find_by_id the GUI profileId: src-tauri/src/handler/project.rs, src-tauri/src/handler/filesystem.rs, src-tauri/src/handler/profile.rs, src-tauri/src/handler/topbar.rs.
  • Do not change: Diesel migrations, dropping profiles / mapping tables, Local adapter internals, PTY spawn, sidecar pin, Settings runtime toggle, Herdr create/delete/list/session-store behavior, launch/adopt on project open, Git/file-tree feature redesign.

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 Git IPC and leftover Git service helpers resolve checkout via live worktree.list / snapshot pane cwd (reconcile_profile_checkout). sqlite profiles.worktree_path is not consulted and cannot win over a different live path. sqlite profiles is not source of truth.
  • [ ] File tree, search, reveal, open-in-app, and editor-launch paths use that same live seam (or the Herdr-derived catalog DTO). No sqlite find_by_id checkout on the Herdr path.
  • [ ] Watcher roots are live Herdr checkouts from list_with_runtime. Leftover sqlite /stale that is not an open workspace is not watched. Empty Herdr still falls back to projects.folder only (until Task 10). No persisted path cache.
  • [ ] TWOCODE_RUNTIME=local still uses sqlite nested-profile paths for Git/FS/watcher. Herdr-selected + absent/incompatible sidecar or unknown workspace_id fail closed; they do not sqlite-fill.
  • [ ] Git / file-tree / notes / tab clicks and labels stay. No new named UX exception. Prior exceptions remain: route ids are workspace_id; tab ids are pane_id; empty profile list until Task 10; splits flattened as extra tabs.
  • [ ] sqlite profiles / mapping tables / pty_sessions are not DROPped. No launch/adopt of the project-folder default. No Local PTY deletion. No second events.subscribe. lib.rs still does not name HerdrRuntimeSync. 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.
  • [ ] No pull request until parent #436 is complete.

Out of scope

  • DROP sqlite profiles / mapping tables, or moving notes off profiles (Task 8).
  • Deleting the Local PTY runtime (Task 9).
  • Launch/adopt of the project-folder default (worktree.open / workspace.create on project open) (Task 10).
  • Live path join so Local-flag delete of unmapped leftover extras cannot git-remove a Herdr-open checkout (#446).
  • Session store / leftover sqlite UUID on New Tab (#447; Task 6).
  • Starting a new HerdrRuntimeSync / events.subscribe, changing the v0.9.0 pin, or #394 Task 16 / #432.
  • Implementing or closing #394 issues #395–#434 or line-count trackers.
  • 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.
  • Preserve existing 2code interaction. UX change is allowed only when Herdr cannot back the old clicks/labels; this task names no new exception.
  • One task; stack on task-6-herdr-session-store. Do not open a PR until the parent plan is complete.

AkaraChen avatar Sep 16 '26 07:09 AkaraChen