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

Plan: 2code as a Herdr client (profiles derived from Herdr)

Open AkaraChen opened this issue 2 months ago • 0 comments

Plan: 2code as a Herdr client (profiles derived from Herdr)

Phase 2 on top of the additive stack in #394 / PR #435 (task-17-shell-templates). That stack kept Local as default and persisted 2code profiles plus mapping tables. This plan inverts those constraints.

Goal

Make 2code a Herdr client with 2code-only extensions (sidebar file tree, Git UI, notes). Do not change interaction unless Herdr-derived profiles make the old UX impossible — and then change the smallest surface and document why.

  • Project stays in the 2code database (catalog, groups, repo path, notes).
  • Profile is not a 2code row. A profile is a Herdr workspace / worktree, derived live from Herdr (workspace.list / worktree.list / session.snapshot) keyed by the project's repo path.
  • Herdr owns terminals, session layout, agent state, and worktree lifecycle.
  • Delete 2code code that duplicates that: profiles as source of truth, profile_runtime_mappings / session_runtime_mappings as authority, Local PTY ownership, pty_sessions as the session store, profiles.worktree_path as the path authority.

Non-goals

  • Remote Herdr machines (later).
  • Rewriting Git / file tree / notes into Herdr. Those stay 2code features, but they must take checkout paths from live Herdr state, not from sqlite profile rows.
  • Keeping a second runtime that can own the same worktree.

Standing constraints (every sub-issue)

  1. Do not treat sqlite profiles as source of truth. Listing, creating, renaming, and deleting profiles must go through Herdr. A 2code profile id is a Herdr workspace_id (or documented equivalent), not a UUID we mint and store.
  2. projects (and project groups / notes) remain 2code sqlite.
  3. Join key: projects repo path ↔ Herdr worktree/workspace cwd. No parallel worktree_path column that can disagree with Herdr.
  4. Herdr is the default (and, once Local is deleted, only) runtime. Switching the default is in scope.
  5. Removing the Local PTY/agent path is in scope when that task says so. Until then, Local must not own a worktree that Herdr already owns.
  6. Preserve existing 2code interaction (project list, profile switcher, create/delete profile, Git, file tree, notes, terminal tabs). Do not redesign those flows. A backend swap that keeps the same clicks/labels is required. UX change is allowed only when the old interaction cannot be backed by Herdr at all; that exception must be named in the sub-issue.
  7. One task at a time, stacked on the previous accepted branch. Base of task 1 is task-17-shell-templates.
  8. Do not open a PR until the parent plan is complete.

Mapping

Thing Owner
Project catalog, groups, notes 2code sqlite
File tree, Git UI 2code, paths from live Herdr checkout
Profile list / create / delete / restore Herdr workspaces + worktrees
Terminals, panes, scrollback, agents Herdr
Default checkout for a project Herdr workspace whose path is the project folder

Implementation tasks

Each task is separately reviewable. Dependencies are prerequisites, not permission to combine.

  1. Rewrite the integration contract for client-mode Replace #394's "Local default, mapping tables, path cache" with this plan. Document how a 2code project binds to Herdr (path → worktree group), how a profile is a workspace, and which sqlite tables die. Linux live probe against pinned Herdr v0.9.0. Docs + tests only in this task if possible.
  2. Make Herdr the default runtime New sessions and GUI startup talk to Herdr first. Local remains only as an explicit fallback behind a flag/env, not the default.
  3. Derive the profile list from Herdr Sidebar/profile switcher reads worktree.list / workspace snapshot for the open project. Stop reading profiles for that UI. Empty Herdr → empty profile list (maybe one implicit workspace for the project folder), not leftover sqlite rows.
  4. Create/delete profile through Herdr only Create = worktree.create (or workspace.create when there is no git worktree). Delete = worktree.remove / workspace.close. Do not INSERT/DELETE profiles. Fail closed if Herdr is down.
  5. Stop persisting profile mappings Remove profile_runtime_mappings (and any write path to profiles.worktree_path / branch_name) as authority. One-shot import of existing sqlite profiles into Herdr is allowed in this task or the next, then those rows are ignored.
  6. Sessions from Herdr snapshot, not pty_sessions Tabs/panes restore via Herdr reattach (pane_id / snapshot). Stop treating pty_sessions + session_runtime_mappings as the session store for Herdr-backed projects.
  7. Point Git, file tree, and watchers at live Herdr cwd Every path used by Git IPC, filesystem watch, and the sidebar tree comes from the focused Herdr workspace. No sqlite cache that can go stale.
  8. Drop sqlite profiles (and mapping tables) Migration deletes or ignores the tables. Update Diesel schema, handlers, and tests. Project rows remain.
  9. Delete the Local PTY runtime Remove the Local adapter, PTY spawn path, and dead IPC once Herdr-only acceptance tests pass. Do not leave an unused dual-runtime router "just in case".
  10. Launch/adopt existing checkouts Opening a 2code project starts or adopts the Herdr workspace for that folder (worktree.open / workspace.create as appropriate) so the GUI always has a derived profile without a sqlite seed.

Acceptance for the parent plan

  • Creating a profile in the GUI does not write a profiles row.
  • Restarting 2code with Herdr still running shows the same profiles (Herdr workspaces) without reading sqlite profiles.
  • Deleting a profile removes the Herdr worktree/workspace, not a 2code row.
  • Git and the file tree still work, using Herdr's cwd.
  • projects still round-trip in sqlite.
  • Local PTY code is gone or unreachable from the GUI.
  • Existing clicks/labels for project/profile/Git/file-tree/notes/tabs stay; any UX exception is named in a sub-issue.

Base

Branch task-17-shell-templates (PR #435). Do not reset that stack; this plan stacks on it.

AkaraChen avatar Sep 16 '26 02:09 AkaraChen