Plan: make 2code share the user's real Herdr session (drop the private 2code namespace)
Plan: make 2code share the user's real Herdr session
Phase 5, stacked on the phase-4 tip (task-3-prove-herdr-only after #463 Task 3 / #467).
The defect
2code runs its own Herdr server in a private session named 2code:
$XDG_CONFIG_HOME/herdr/sessions/2code/herdr.sock, and resolve_namespace in
src-tauri/crates/infra/src/herdr/process.rs hard-refuses the user's socket
(refusing the user default Herdr session). The user's own herdr is the default session
($XDG_CONFIG_HOME/herdr/herdr.sock). Two servers, two disjoint sets of workspaces, panes and tabs —
so a workspace started from 2code is invisible in the user's terminal, and the user's own workspaces
are invisible in 2code.
The owner's goal: 2code and the user's terminal Herdr are one and the same thing — same server, same session, same workspaces.
There is a second, related problem: the pinned sidecar is Herdr v0.9.0 (protocol: 22) while the
user's installed Herdr may be older (observed: 0.8.2, protocol: 20). The protocol-22 surface is a
superset of 20 (128 methods vs 117, no removals), but 2code calls pane.scroll, which is one of the
eleven methods added in 22 — so attaching to a 0.8.2 server silently breaks wheel scroll.
Goal
One Herdr server, shared. 2code attaches to the session the user's terminal is attached to, or starts that same session if it is not running — never a second, private one.
Standing constraints (every sub-issue)
- Never start a private session.
2codeas a session name,sessions/<name>/herdr.sock, and the default-socket refusal are all deleted. Nothing in 2code may spawn a server on a socket the user's ownherdrcannot see. - Never stop the user's server. GUI exit, disconnect, crash and update must not issue
herdr server stopor kill the shared server process. Existing behaviour, keep it. - Fail with an actionable message, never with silence. If the reachable server is too old
(protocol < 22) or absent, the UI shows what is wrong and what to run (
herdr update), and does not fall back to a private instance. - Do not change interaction. Same clicks and labels. Seeing the user's real workspaces in the sidebar is the point of this phase, not a redesign; if a label genuinely cannot survive, name the exception in the issue.
- Reuse the code that already works — socket client, snapshot/event sync, frame bridge, worktree and pane RPCs. This phase changes which socket 2code talks to and which server it is willing to trust, not the protocol layer.
- Do not push, do not open a PR. One task at a time, stacked on the previous accepted branch.
Tasks
- Attach to the user's Herdr session
Replace
resolve_namespacewith resolution of the user's live session: discover the running server the same way theherdrCLI does (default socket, plusherdr session list/ named sessions if the CLI exposes them), and use that socket. DeleteSESSION_NAME = "2code", the privatesessions/2code/path, the short-socket fallback, and therefusing the user default Herdr sessionguard. If no server is running, start one on the user's default socket so the user's ownherdrattaches to the same instance, and never stop it on exit. Prove it with a test that a session created through 2code's runtime appears inherdr api snapshoton the default socket. - Version policy for the shared server
Probe the reachable server's protocol/version instead of pinning the sidecar. Accept a compatible
server (protocol >= 22, i.e. Herdr >= 0.9.0) and surface an actionable error when it is older:
name the found version, the required version, and
herdr update. Prefer the user's installedherdrbinary over the bundled sidecar when both exist; keep the sidecar only as the no-installation fallback and make it start on the shared socket. Add a test for the old-server path asserting no private server is spawned and the error message namesherdr update. - Prove sharing end to end and document it
With the real Herdr v0.9.0 binary: start a workspace/pane through 2code's runtime path, then show
it in the same server's
session.snapshot/herdr api snapshotand inherdr workspace list; and the reverse — a workspace the user creates externally appears in 2code's derived list. Record the exact commands and their output indocs/herdr-integration.md, and replace the docs' "dedicated2codenamespace, never the user default session" statements with the sharing contract.
Acceptance for this phase
- No code path in 2code creates or references a private Herdr session.
- A session created through 2code is visible to the user's own
herdrclient, and vice versa, proven by command output in the task replies. - An older running server produces an actionable upgrade message, never a second server.
- GUI exit leaves the user's server running.
Base
Branch task-3-prove-herdr-only (#467 / parent #463). Do not reset that stack.