Plan: Remote execution — pi here, the work over there (meta plan)
Closes: #488 (tracking; phases #489, #490, #491, #492, #493, #494). Relates to: #483. Branch: one per phase. Status: Done (2026-10-27) — pi over SSH shipped in 0.128.3; the LAN and WAN figures are #512
Design
Why
Today pi runs on the box where the code is, and the developer reaches it over SSH with a terminal. Every keystroke and every mouse movement crosses the link as raw escape sequences, which is where today’s spurious aborts came from (#483). More: clipboard images, drag-and-drop, desktop notifications and the model credentials all live on the wrong side of the link. The developer wants the VS Code Remote-SSH shape: install pi once, locally, and point it at a machine. pi becomes a window onto that machine.
The end result should behave as if pi ran on the remote, to the greatest extent possible, and the limitations are named below rather than discovered.
The architecture: agent local, workspace remote
Three shapes were compared (Research helper, 2026-10-26; sources on the tracking issue):
| Shape | Who does it | Why not / why |
|---|---|---|
Whole agent on the remote, thin UI local |
Claude Desktop SSH sessions, Codex |
Model calls and credentials stay on the remote, so none of the local wins arrive; and a thin client that re-renders pi’s whole TUI is a large build with nothing of pi’s to reuse. It is also what the developer has today, minus the terminal. |
Fix the terminal link |
mosh, Eternal Terminal |
Neither carries port forwards or a structured channel; mosh explicitly does no forwarding. They fix roaming, not the escape-sequence problem, and change nothing else. |
Agent local, tools remote |
Zed (system ssh, one multiplexed connection, a headless server it uploads), VS Code |
pi has the seam: every built-in tool takes a swappable operations object ( |
The connection: system OpenSSH, one channel, a helper on the remote
Compared (details and sources on the tracking issue):
-
One
ssh host cmdper operation (pi’sssh.tsexample): honours~/.ssh/config, but every file read is a process spawn and a channel open, there is no shared state for port watching, and Windows clients have no ControlMaster to amortise it (Win32-OpenSSH #1328 still open, 2026-07). -
The
ssh2npm package: one persistent connection with many channels and works on Windows, but re-implements SSH config (noProxyJump,Include,Match, certificates, FIDO keys), leaves host-key handling to us, and its maintenance is marked inactive (last release 2025-08). -
System
sshrunning one long-lived helper on the remote (Zed’s shape):ssh host node ~/.pi-workspace/helper.mjs, a newline-delimited JSON protocol on its stdin/stdout carrying every operation (file reads and writes, stat and realpath, directory listing, glob, exec with streamed output and cancellation, a port watch). Honours the user’s SSH config, agent, jump hosts and host keys; one authentication per session; needs no ControlMaster so a Windows client works; one process to supervise and reconnect. The helper is a single file uploaded over the same connection when missing or outdated. Chosen. Port forwards are separatessh -N -Lchildren, one per forward, which also needs no ControlMaster.
Requirement this creates: Node 20 or later on the remote, and a POSIX remote. The remote is a machine pi would otherwise run on, so Node is a fair ask; it is checked at connect and refused with the reason.
The one abstraction: Workspace
Every place our packages touch the workspace goes through one interface, with a local implementation and the SSH one:
-
Files:
readFile,writeFile,mkdir,stat/lstat,realpath,readdir,exists,glob,rm,rename. -
Processes:
exec(file, args, { cwd, env, signal, timeout, onData })with streamed output and an exit code;git(args, cwd)as a convenience over it. -
Identity:
root(the workspace path on the host that holds it),label(local, oruser@host:/path),isRemote.
Where it lives: ADR-004 forbids pi-modes and pi-workflow importing each other, and both need it. ADR-004’s amendment of 2026-09-26 made a library package the answer for shared logic (@gadhs/pi-bash: no extension, no loader, a regular dependency of both), and says a new package is its own decision. So: a library @gadhs/pi-workspace holds the Workspace interface, the local implementation and the slot (Symbol.for("gadhs:workspace") on globalThis, as the runtime bridge does; workspaceFor(cwd) looks it up per call and falls back to local), and pi-modes and pi-workflow depend on it by name. The SSH implementation, the helper and the extension that wires them are an extension package, @gadhs/pi-ssh, loaded by the meta package as ./loaders/11-ssh.ts: after 10-modes.ts, which stays first because its factory seeds the permission system’s config (packages/pi/package.json //order; distribution.test.ts:66 asserts modes first and is unchanged), and before 12-workflow.ts. Order does not otherwise matter: the workspace slot is read per call, never at load, and pi lets an extension’s registered tool replace a built-in whatever the load order. The pi.extensions list and the filename prefixes move together, as that test holds. ADR-006 (below) records both packages as that decision.
Three reads of the local cwd feed the system prompt from session-wiring.ts: contextFiles(ctx.cwd, agentDir) (the context budget, line 254), and from @gadhs/pi-guidance’s `payload.ts, detectLanguages(ctx.cwd) (the language profiles, line 316; it tests for marker files in cwd and its first-level directories) and readProjectGuidance(ctx.cwd) (<cwd>/.pi/gadhs-guidance.md, line 318). Under the anchor (below) they see the mirrored AGENTS.md but no source. Phase 2’s mirror therefore also copies the remote’s .pi/gadhs-guidance.md and the language marker files' names (empty files suffice: detectLanguages only tests existence), so all three read right with no code change; phase 4 points detectLanguages at the workspace instead and drops the marker mirror.
What stays local, by design
Sessions and their JSONL, memory, plan drafts and approvals, standing approvals, diagnostics, the modes overlay and config, the agent files, guidance, the model registry and every credential, the title and nudges, pi-remote’s phone link, dropped files (a local file the human drops is attached from where it is). Nothing of these crosses the link, and two contract tests pin it: the protocol has no message that carries a path outside the workspace root or an environment value, and exec sends the remote no local environment (the remote command gets its login environment plus an allowlist of TERM, LANG, LC_*, COLUMNS), so a local ANTHROPIC_*, GOOGLE_* or GITLAB_TOKEN can never reach the remote through pi.
What must act on the remote
pi’s seven built-in tools and user_bash (!); codemode follows them for free. Then ours: workspace-write and workspace-read containment (real-path resolution must happen where the symlinks are, or containment is weakened); count; generate_image saving its file; monitors (spawned commands); helper worktrees (git worktree on the remote); session facts (git); and the whole commit path in pi-workflow: the guard’s staged diff, the review snapshot, review context, review rules, the approved-plan check, the SPDX authoring guard, the git-dir reader, the workspace audit. Today these are synchronous node:fs and execFileSync calls (about 20 files, listed per phase); all run inside hooks that are already async.
Helpers: pi-subagents builds each helper session with a fresh resource loader that re-instantiates the installed extensions, so the workspace extension loads in every helper too, and finds the parent’s connection in the shared slot. A helper therefore acts on the same remote with no change to pi-subagents. Its worktree needs the remote variant.
The local anchor
pi keys sessions, trust, AGENTS.md and .pi/ discovery by the local cwd. A remote session must not borrow those from whatever local directory pi was started in. So a launcher, pi-ssh user@host:/path, runs pi in an anchor directory, ~/.pi/agent/remotes/<host>/<path-slug>/, with --ssh user@host:/path. Sessions for that remote project live under the anchor. On connect the extension mirrors the remote project’s AGENTS.md (and its ancestors' within the repository) into the anchor so pi’s own discovery reads the right one, rewrites the working directory in the system prompt, and shows ssh user@host:/path in the status line. Trusting the anchor is trusting that remote project.
Port forwarding
/ssh forward <port>[:<local>] starts an ssh -N -L child; /ssh forwards lists; /ssh unforward. The helper watches listening TCP ports on the remote (ss -ltnH, polled every 2 s, as VS Code scans the remote’s processes) and reports new ones; pi notifies ("port 3000 is listening on the remote; /ssh forward 3000`"), and `autoForward: true in config forwards them without asking. Forwards are torn down at shutdown.
Honest limitations
-
Latency. Every operation is a round trip on one channel; an
editis two. On a LAN this is milliseconds; on a slow link the agent is slower than a local pi. The helper keeps it to one round trip per operation and streams output, which is the best this shape allows. -
A dropped link. Phase 2: the channel is re-established and a command that was running is reported failed, not resumed. Phase 5 daemonises the helper with an output buffer so a command survives the link.
-
The remote project’s own
.pi/extras. ItsAGENTS.mdis mirrored. Project-local pi extensions, skills and prompts on the remote are not loaded: they would run locally against the wrong filesystem. Documented, with the workaround of installing them locally. -
Windows. Client: supported (no ControlMaster needed; pi-win verifies). Remote host: POSIX only; a Windows remote is out of scope.
-
Credentials on the remote.
git push,glaband anything the remote runs still use the remote’s own credentials, as they would under a local pi there. Model credentials never leave the local machine, which is a feature. -
pi-subagents' own env probe runs local
gitagainst the remote path and will show no branch for a helper; cosmetic, documented. -
Interactive programs in
bashdo not work, exactly as today.
ADR-006
Written with phase 1: "Remote execution runs the agent locally and the workspace over system SSH with a remote helper." It records the three shapes and the three connections above, the Node requirement, the anchor, and the amendment to ADR-004’s package ceiling. Hard to reverse: the Workspace interface becomes the seam every workspace-touching file depends on.
Scope
The phases
Each phase is its own issue, branch, plan (written in plan mode when it starts, under 300 lines, reviewed as any plan), MR and release note. This meta plan is the design they share; a phase plan says how, within it.
| Phase | Delivers | Done when |
|---|---|---|
1. |
The library: the |
Published; nothing else changed yet; every later phase builds on it. |
2. |
The helper (one file, uploaded), the protocol, the connection with reconnect-and-report, the SSH |
A session over |
3. pi-workflow on the seam |
|
A commit made over SSH is guarded, snapshotted and reviewed exactly as a local one. |
4. pi-modes on the seam |
|
A helper over SSH works in a remote worktree; containment holds against remote symlinks. |
5. Ports, resilience, Windows |
|
The developer runs a dev server on the remote and opens it locally; a Wi-Fi drop mid-command resumes. |
6. Docs and release |
One canonical page, |
Installed on the developer’s machine and in daily use. |
Ordering and risk
1 and 2 give a usable, if guard-blind, remote pi quickly; 3 and 4 are the bulk (about 20 files, sync to async) and carry the regression risk, which the existing suites bound. 5 is independent of 3 and 4 and can interleave. The developer’s own terminal problem is addressed by #483’s fix meanwhile.
The risks, each with its mode and mitigation; a phase plan refines its own:
-
Guards blind between phases 2 and 3 (fail-open: a commit over SSH would pass the commit guard unreviewed, since the guard reads a local
.gitthat is not there). Mitigation: phase 2 ships with thetool_callguards refusinggit commitwhen the workspace is remote ("not yet guarded over SSH: commit from a local checkout"), so the gap is a refusal, never a pass. Lifted in phase 3. -
Containment weakened (fail-open:
realLocationresolving symlinks on the wrong machine). Mitigation: until phase 4 moves it, every workspace write over SSH is treated as outside the workspace and goes to the judge; phase 4’s test puts a symlink out of the remote workspace and asserts the deny. -
The link drops mid-command (fail-closed, loud: the tool result is an error naming the drop; nothing is retried blind). Phase 5 makes it resume.
-
The helper is outdated or missing (fail-closed: the version handshake refuses and says which to update; no silent fallback to a local tool).
-
A local environment value leaks to the remote (silent by nature). Mitigation: the allowlist above, and its contract test.
-
Wrong machine (silent: a session believed remote acting locally). Mitigation: the status line names the host, every tool result carries no path the model could mistake for local (paths are the remote’s), and
session.startin diagnostics records the workspace label.
Out of scope, named
A Windows remote host; the remote project’s pi extensions, skills and prompts; agent forwarding of local credentials to the remote; syncing files between the two machines beyond the AGENTS.md mirror; a thin-client mode; mosh or ET as the transport; ssh2.
Delivery
-
The tracking issue holds the research sources, one issue per phase, and each phase’s merge SHA. Each phase MR says
Relates to #<tracking>andCloses #<phase>. -
This meta plan is committed as
docs/modules/ROOT/pages/plans/remote-execution.adoc,In progressfrom phase 1’s start until phase 6 lands, when it isDoneand the tracking issue is closed with the last merge SHA. Each phase plan isplans/remote-<n>-<name>.adoc, written in plan mode when the phase starts. -
Each phase carries its own
CHANGELOG.adocUnreleasedentry (Added for phases 1, 2, 5, 6; Changed for 3 and 4, which change where the guards read) and its own release note. Phases 1 and 2 release together; 3 and 4 together; 5 and 6 as they land. -
Files this plan names that the cold reviewer was not handed (the review budget is twelve), all existing today and each supplied with the phase plan that touches it:
packages/pi-workflow/{review-rules,approved-plan,commit-message,workspace-audit,authoring-guard,git-dir,glab-ambient,plan-pause,workflow-config}.ts,packages/pi-modes/{count-tool,image-tool,monitor-process,yield-tool}.ts,packages/pi-guidance/payload.ts,docs/modules/ROOT/pages/remote.adoc,CHANGELOG.adoc, and pi’sdist/core/tools/*.d.ts, which are untracked (node_modules).
Erratum (2026-10-26): the remote needs Node 22 or later, not 20: the helper’s glob is fs.promises.glob, Node 22’s, and Node 20 has been end-of-life since 2026-04 (#490; phase 2a, plans/remote-2a-ssh-workspace.adoc). Phase 2 is split into 2a (#496: helper, protocol, SSH workspace) and 2b (#490: tools, /ssh, anchor, safeguards, loader).
Erratum (2026-10-26): phase 2 is three parts, not two: 2a (#496: helper, protocol, SSH workspace), 2b (#490: pi’s tools on the remote, at parity) and 2c (#498: /ssh, the anchor, the safeguards, the loader and the release); plans/remote-2b-tools.adoc.
Erratum (2026-10-26): there is no pi-ssh launcher and no --ssh flag. /ssh user@host:/path writes the anchor and a session file whose cwd is the anchor, and switches into it (ctx.switchSession); pi "/ssh …" starts straight in one (phase 2c, #498; plans/remote-2c-session.adoc).
Erratum (2026-10-26): containment on the remote (realLocation, the workspace-write and workspace-read stages, a redirect’s destination) moved from phase 4 to phase 2c on the operator’s choice, in place of 2c’s "every remote write goes to the judge" rule. Phase 4 keeps count, generate_image, monitors, session facts, helper worktrees and detectLanguages (#492). ssh.adoc starts with 2c, which turns remote execution on; phase 6 completes it.
Erratum (2026-10-26): phase 3 moved pi-workflow onto the seam as a pure core and one async shell per module, not as an await on each call: the guard’s decisions are functions of facts already read, and the reads go through the workspace (plans/remote-3-workflow.adoc). Its suites run twice in validate, locally and over the SSH route; the "contract: the same suites against a fake remote workspace" is that second run, against the real SSH workspace over a local helper.
Erratum (2026-10-27): the slot holds one workspace per anchor, not one in all. workspaceFor(cwd) takes the longest anchor or root holding cwd, and Workspace.at(root, anchor) gives a view over the same connection. A remote helper’s worktree is such a view, published under an anchor inside its parent’s (phase 4, #492; plans/remote-4-modes.adoc).
Erratum (2026-10-27): phase 5 is three units (plans/remote-5-ssh.adoc): 5a the Windows client (#501), 5b port forwarding and the remote port watch, and 5c the helper as a daemon with a relay per connection. Its "measured per-operation cost on LAN and WAN" is in two parts. 5c measures pi’s own overhead per operation and a drop’s cost, on one machine without ssh, because this box cannot ssh to itself. The LAN and WAN figures come from the operator’s sessions with the release (phase 6).
Erratum (2026-10-27): the release that flips it on is 0.128.3. Its rehearsal, once it packed every package (#510), found pi refusing pi-workflow beside pi-ssh, because both registered bash. pi-ssh now owns the one bash, which is sequential and built with pi’s shell settings, and pi-workflow registers its own only when unclaimed (#511, ADR-006 amendment).