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

Task 5: Stop persisting profile mappings

Open AkaraChen opened this issue 2 months ago • 0 comments

Summary

Stop persisting profile mappings as authority for parent plan #436. After Task 4 (#443 on task-4-herdr-create-delete) create/delete go through Herdr without INSERT/DELETE sqlite profiles, but leftover profile_runtime_mappings and writes to profiles.worktree_path can still disagree with live Herdr and win. This task stops treating those rows/columns as identity or path authority.

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). One-shot import of leftover sqlite extras into Herdr is this task (worktree.open only). Default / project-folder checkouts stay unopened until Task 10. Do not DROP profiles / mapping tables (Task 8). Do not drop session_runtime_mappings / pty_sessions as the session store (Task 6). Do not start HerdrRuntimeSync / events.subscribe. Do not redesign project/profile/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.

Dependencies: Parent plan #436. Prerequisites: #437 (Task 1), #439 (Task 2), #441 (Task 3), #443 (Task 4). Open #438, #440, #444 are line-count tracking only — not blockers. Open #394 issues #395–#434 must not be implemented or closed here.

Work to complete

  1. Stop mapping / worktree_path authority

    • Herdr list/create/close/identity join live workspace_id or leftover sqlite checkout path. Do not bind/unbind/replace profile_runtime_mappings on those paths. Do not write profiles.worktree_path from worktree.list.
    • Notes overlay leftover sqlite profiles.notes when worktree_path matches the live checkout. Mapping rows that point at a different workspace must not win. Herdr-only workspaces with no leftover path stay empty until Task 8.
    • Local list (TWOCODE_RUNTIME=local) keeps the sqlite cache and does not call Herdr to refresh it.
    • Mapping, if present, is a dual-ownership lock on Local-flag GUI delete (delete_sqlite_identity / refuse_mapped_without_runtime), not a Herdr workspace_id. Do not git worktree remove a leftover checkout that this task opened. Do not route Local delete through Herdr worktree.remove because a leftover mapping exists.
  2. One-shot leftover extra import

    • After successful GUI Herdr JSON connect (connect_gui_herdr), import leftover sqlite extras with JSON worktree.open. already_open is success. Skip the default / project-folder checkout (Task 10). Do not INSERT mapping rows. Do not retry uncertain worktree.open. Do not worktree.create / git worktree add / workspace.create.
    • Log per-profile Failed outcomes (including uncertain open) and outer import errors. Do not fail Herdr connect or flip the selector to Local.
    • TWOCODE_RUNTIME=local skips import. Do not call import from lib.rs setup.
  3. Prove without swallowing later tasks

    • Colocated tests: notes overlay by path; Local list does not persist listed paths; leftover mapping is not identity; extras import without mapping writes; default skipped; uncertain open not retried; Local-flag mapped delete fails closed without git remove; production source guards (no mapping writes, no HerdrRuntimeSync / events.subscribe in lib.rs).
    • Update docs/herdr-integration.md: Task 5 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 6+ into this branch.

Acceptance criteria

  • [ ] Herdr list/create/close/import do not write profile_runtime_mappings or profiles.worktree_path. sqlite profiles is not source of truth.
  • [ ] Notes overlay leftover sqlite profiles.notes by checkout path, not mapping membership.
  • [ ] GUI Herdr connect imports leftover extras via worktree.open (already_open ok), skips the project-folder checkout, does not retry uncertain opens, and logs per-profile Failed outcomes plus outer import errors without flipping the selector.
  • [ ] Local-flag GUI delete (delete_with_runtime → delete_sqlite_identity) fails closed when a leftover mapping exists: no git worktree remove, no Herdr worktree.remove. Unmapped Local extras still use today’s git delete.
  • [ ] sqlite profiles / mapping tables are not DROPped. session_runtime_mappings / pty_sessions stay the session store. No launch/adopt of the project-folder default. No HerdrRuntimeSync / events.subscribe. No Local PTY deletion. Pin stays v0.9.0. GUI clicks/labels stay New Profile / Delete Profile. GUI exit still does not server stop.
  • [ ] Tests: cargo test --workspace from src-tauri (or cargo test --workspace --exclude code where GTK is unavailable).
  • [ ] No pull request until parent #436 is complete.

Out of scope

  • Sessions from session.snapshot; dropping pty_sessions / session_runtime_mappings as authority (Task 6). Starting HerdrRuntimeSync / events.subscribe.
  • Pointing every Git/file-tree/watcher consumer at live cwd (Task 7).
  • DROP sqlite profiles / mapping tables (Task 8), deleting the Local PTY runtime (Task 9), launch/adopt on project open (Task 10).
  • Live path join so Local-flag delete of unmapped leftover extras cannot git-remove a Herdr-open checkout (follow-up; mapping lock only covers mapped rows).
  • leftover_sqlite_id pinning New Tab pty_sessions.profile_id to a leftover sqlite UUID (Task 6).
  • 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; named exceptions remain route ids as workspace_id and empty profile list until Task 10.
  • One task; stack on task-4-herdr-create-delete. Do not open a PR until the parent plan is complete.

Estimated changes: 400–700 lines total, additions plus deletions, including tests; excluding generated files. Material scope growth should become a separate issue.

AkaraChen avatar Sep 16 '26 05:09 AkaraChen