2code
2code copied to clipboard
Plan: 2code as a Herdr client (profiles derived from Herdr)
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:
profilesas source of truth,profile_runtime_mappings/session_runtime_mappingsas authority, Local PTY ownership,pty_sessionsas the session store,profiles.worktree_pathas 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)
- Do not treat sqlite
profilesas source of truth. Listing, creating, renaming, and deleting profiles must go through Herdr. A 2code profile id is a Herdrworkspace_id(or documented equivalent), not a UUID we mint and store. projects(and project groups / notes) remain 2code sqlite.- Join key:
projectsrepo path ↔ Herdr worktree/workspace cwd. No parallelworktree_pathcolumn that can disagree with Herdr. - Herdr is the default (and, once Local is deleted, only) runtime. Switching the default is in scope.
- 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.
- 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.
- One task at a time, stacked on the previous accepted branch. Base of task 1 is
task-17-shell-templates. - 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.
- 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.
- 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.
- Derive the profile list from Herdr
Sidebar/profile switcher reads
worktree.list/ workspace snapshot for the open project. Stop readingprofilesfor that UI. Empty Herdr → empty profile list (maybe one implicit workspace for the project folder), not leftover sqlite rows. - Create/delete profile through Herdr only
Create =
worktree.create(orworkspace.createwhen there is no git worktree). Delete =worktree.remove/workspace.close. Do not INSERT/DELETEprofiles. Fail closed if Herdr is down. - Stop persisting profile mappings
Remove
profile_runtime_mappings(and any write path toprofiles.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. - Sessions from Herdr snapshot, not
pty_sessionsTabs/panes restore via Herdr reattach (pane_id/ snapshot). Stop treatingpty_sessions+session_runtime_mappingsas the session store for Herdr-backed projects. - 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.
- Drop sqlite
profiles(and mapping tables) Migration deletes or ignores the tables. Update Diesel schema, handlers, and tests. Project rows remain. - 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".
- Launch/adopt existing checkouts
Opening a 2code project starts or adopts the Herdr workspace for that folder (
worktree.open/workspace.createas 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
profilesrow. - 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.
projectsstill 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.