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

Plan: make 2code share the user's real Herdr session (drop the private 2code namespace)

Open AkaraChen opened this issue 2 months ago • 0 comments

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)

  1. Never start a private session. 2code as 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 own herdr cannot see.
  2. Never stop the user's server. GUI exit, disconnect, crash and update must not issue herdr server stop or kill the shared server process. Existing behaviour, keep it.
  3. 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.
  4. 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.
  5. 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.
  6. Do not push, do not open a PR. One task at a time, stacked on the previous accepted branch.

Tasks

  1. Attach to the user's Herdr session Replace resolve_namespace with resolution of the user's live session: discover the running server the same way the herdr CLI does (default socket, plus herdr session list / named sessions if the CLI exposes them), and use that socket. Delete SESSION_NAME = "2code", the private sessions/2code/ path, the short-socket fallback, and the refusing the user default Herdr session guard. If no server is running, start one on the user's default socket so the user's own herdr attaches to the same instance, and never stop it on exit. Prove it with a test that a session created through 2code's runtime appears in herdr api snapshot on the default socket.
  2. 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 installed herdr binary 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 names herdr update.
  3. 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 snapshot and in herdr workspace list; and the reverse — a workspace the user creates externally appears in 2code's derived list. Record the exact commands and their output in docs/herdr-integration.md, and replace the docs' "dedicated 2code namespace, 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 herdr client, 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.

AkaraChen avatar Sep 17 '26 02:09 AkaraChen