Task 2: Make Herdr the default runtime
Summary
Make Herdr the production default runtime for parent plan #436. The additive stack plus Task 1 (#437 on task-1-client-mode-contract) still constructs RuntimeRouter::new as Local, leaves RuntimeBackend defaulting to Local, and does not start a Herdr listener from GUI setup (ensure_herdr_listener is explicitly forbidden on the Local-default path). This task inverts that default.
New sessions and GUI startup talk to Herdr first. Local remains only as an explicit fallback behind a flag/env until #436 Task 9 deletes it. Do not silently fail over to Local. Do not treat sqlite profiles as source of truth. Do not redesign project/profile/Git/file-tree/notes/tab interaction.
The Task 1 contract (docs/herdr-integration.md) marks #436 Task 2 proceed on Linux x86_64: no new Herdr capability. Reuse the existing sidecar pin (v0.9.0), ensure_herdr_listener, JSON client, and Herdr adapter. Do not reintroduce the #394 runtime boundary (#402 leftover).
Dependencies: Parent plan #436. Prerequisite: #437 (Task 1, accepted on task-1-client-mode-contract). Open #438 is Task 1 line-count tracking only — not a blocker and not work for this branch. Open #394 issues #395–#434 do not block this switch and must not be implemented or closed here.
Work to complete
-
Flip the production default to Herdr
RuntimeBackend:#[default]becomesHerdr. Updatedefault_backend_is_local/herdr_is_not_the_default_backend.RuntimeSelector::defaultandRuntimeRouter::newselect Herdr. Keepwith_backendfor tests and for the Local fallback.selected_backend()/discovery().selected_backendreport Herdr in production.create_sessionalready routes throughselector.default_backend(); with the flip, new tabs go to the Herdr adapter. They must not spawn a Local PTY for that id.create_with_runtimealready branches onselected_backend(). Production profile create therefore uses the existing Herdr worktree path. It may still INSERT sqliteprofileson this branch (stopping those writes is Task 4). Fail closed if the worktree client is missing — do notgit worktree addas a silent Local fallback.- Update
docs/herdr-integration.md: this branch has switched the default; Local is explicit fallback until Task 9. Do not bump the v0.9.0 pin.
-
GUI startup talks to Herdr first
bridge::build_runtime/lib.rssetup: when Herdr is selected, resolve the pinned sidecar (try_resolve_sidecar/resolve_sidecar), callensure_herdr_listeneron the dedicated2codenamespace (never the user default session), connect the JSON client, and inject terminal + worktree + CLI attach into the Herdr adapter so create/list/write/resize can succeed. TodayHerdrStubAdapter::new()is fail-closed with no client — flipping the enum without this wiring would make every new tab error.- Combine clients on one adapter (today
with_terminal_client_and_cliandwith_worktree_clientare separate). Missing that would break Herdr-default profile create. - Invert tests that currently require
lib.rsnot to containensure_herdr_listener/HerdrClient::connecton the Local-default path (e.g.gui_exit_drops_herdr_helpers_without_stopping_the_server). GUI exit must still onlyrelease_herdr_client_helpers— neverherdr server stop. - Do not start
HerdrRuntimeSync/events.subscribehere (Tasks 3/6). Do not launch/adopt workspaces on project open (Task 10).
-
Local as explicit fallback only
- Process env/flag, e.g.
TWOCODE_RUNTIME=local(match existingTWOCODE_PROFILEstyle). Not a Settings control, not sqlite, not a GUI runtime picker (#394 Task 18 leftover). - With the flag: construct
RuntimeRouteras Local, do not callensure_herdr_listener, new sessions spawn Local PTYs as today. Herdr adapter may exist unselected. Dual-ownership bind still refuses. - No silent failover: if Herdr is the selected default and the sidecar is missing or the namespace is absent/incompatible, keep Herdr selected and fail Herdr ops with existing
HerdrServerAbsent/HerdrServerIncompatible(or equivalent). Do not rewrite the selector to Local. The app may still show the sqlite project catalog. - Named behavior exception (not a click/label redesign): creating a terminal when Herdr is down surfaces that backend error instead of opening a Local PTY. Same New Tab control.
- Process env/flag, e.g.
-
Ownership and fail-closed
- Keep
RuntimeSelector::binddual-backend refusal. Local must never own a worktree/workspace Herdr already owns.backend_foron an unbound id follows the new default (Herdr), includingget_session_backend. Update the frontend comment interminalTransport.ts(“Unbound ids are Local”). Keep resolving transport via per-sessionget_session_backend, not a new discovery UI. list_project_sessionsalready lists only Herdr when the default is Herdr; keep that. Do not merge leftover Local PTYs into the Herdr-default list.- Do not write a sqlite
worktree_path/ mapping row that can disagree with live Herdr and still win. Existing mapping writes from the Herdr adapter may continue until Tasks 5–6; do not add new authority caches.
- Keep
-
Prove the switch without swallowing later tasks
- Colocated tests: production constructor/discovery is Herdr; Local flag selects Local and does not ensure a listener; Herdr-default
create_sessiondoes not increment live Local PTY count; dual bind still errors; Herdr-down does not spawn Local. - Invert or parameterize tests that hard-assert Local as production default (
selector_defaults_to_local,router_production_constructor_selects_local,local_startup_does_not_ensure_herdr_*, profile/project tests that assumeRuntimeRouter::newis Local). Local-path tests must pass throughwith_backend(Local)/ the env flag. - Existing Herdr adapter and Local PTY suites must keep passing. If the line count grows past the estimate, open a tracking issue; do not fold Task 3+ into this branch.
- Colocated tests: production constructor/discovery is Herdr; Local flag selects Local and does not ensure a listener; Herdr-default
Likely files and directories
- Update:
src-tauri/crates/model/src/runtime.rs— enum default + tests. - Update:
src-tauri/crates/service/src/runtime.rs—RuntimeRouter::new,RuntimeSelector::default, env/flag parse, startup tests that currently lock Local-default. - Update:
src-tauri/crates/service/src/runtime/herdr.rs— combined terminal+worktree+CLI constructor if missing; tests that assumelocal_default_router. - Update:
src-tauri/src/bridge.rs,src-tauri/src/lib.rs— Herdr-defaultbuild_runtimecallsensure_herdr_listenerand injects clients; Local flag skips that. - Update:
docs/herdr-integration.md— Task 2 done on this branch; Local is explicit fallback. - Update if comments/guards mention unbound=Local:
src/features/terminal/lib/terminalTransport.ts(and its test if the comment is asserted). - Update tests that construct
RuntimeRouter::newexpecting Local:src-tauri/crates/service/src/profile.rs,src-tauri/crates/service/src/project.rs,src-tauri/tests/integration_pty_db.rs. - Do not change: Diesel migrations,
profilesdrop, mapping-table deletion, sidebar profile list source, Git/file-tree path consumers,HerdrRuntimeSyncstartup, Local adapter internals, PTY spawn implementation, sidecar pin.
Estimated changes: 300–550 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
- [ ] Production default is Herdr:
RuntimeBackend::default(),RuntimeSelector::default(), andRuntimeRouter::newselect Herdr;discovery.selected_backendisherdr. - [ ] GUI Herdr-default startup resolves pinned Herdr v0.9.0,
ensure_herdr_listeneron namespace2code(not the user default session), and injects JSON terminal + worktree + CLI attach so new sessions talk to Herdr first. - [ ] New
create_session(and Herdr-selectedcreate_with_runtime) do not spawn a Local PTY or localgit worktree addfor that identity. Dual-backend bind still refuses. - [ ] Local is reachable only via an explicit env/flag (documented, e.g.
TWOCODE_RUNTIME=local). Not a Settings toggle. With the flag, startup does notensure_herdr_listenerand new sessions are Local. - [ ] Herdr-down (absent sidecar / absent or incompatible namespace) does not flip the default to Local. Ops fail closed with existing distinct absent vs incompatible errors. Creating a terminal then errors instead of opening a Local PTY (named exception; same clicks/labels).
- [ ] sqlite
profiles/ mapping tables /pty_sessionsare not dropped or made read-only here. Profile list UI still may read sqlite (Task 3). Git/file-tree paths are not retargeted (Task 7). No launch/adopt on project open (Task 10). No Local PTY deletion (Task 9). - [ ] Frontend still uses per-session
get_session_backendfor transport; unbound ids follow the new default on the backend. No runtime-picker UI. - [ ] Tests:
cargo test --workspacefromsrc-tauri(orcargo test --workspace --exclude codewhere GTK is unavailable). Frontend lint/typecheck/tests only if frontend scope is introduced.bun run typegenif IPC signatures change; do not editsrc/generated/by hand. - [ ] GUI exit still drops client helpers only (no
server stop). Pin stays v0.9.0. - [ ] Another developer can run with the Local flag and get the old default, and run without it and get Herdr-first create.
Out of scope
- Deriving the sidebar/profile switcher from
worktree.list/ snapshot (Task 3). - Create/delete profile without INSERT/DELETE
profiles(Task 4). - Stopping mapping /
worktree_pathwrites or one-shot import (Task 5). - Session restore from
session.snapshotas the store; droppingpty_sessions/session_runtime_mappingsas authority (Task 6). StartingHerdrRuntimeSync/events.subscribe. - Pointing Git, file tree, and watchers at live Herdr cwd (Task 7).
- 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.
- Remote Herdr machines. User-facing runtime health UI. Changing the v0.9.0 pin.
- Opening a pull request (parent plan: no PR until #436 is complete).
Standing constraints
- Do not treat sqlite
profilesas 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 is in scope. Deleting Local PTY /
profilesrows 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; the only named exception is fail-closed errors instead of a silent Local shell when Herdr is down.
- One task; stack on
task-1-client-mode-contract. Do not open a PR until the parent plan is complete.
Line count on task-2-herdr-default-runtime versus task-1-client-mode-contract is 624 insertions / 73 deletions (plus a small frontend comment/test follow-up), past the 300–550 estimate. Tracking: #440. Growth is tests, docs, and fail-closed GUI attach — not Task 3+ scope.