Plan: Remote execution phase 2b — pi’s tools on the remote, at parity
Closes: #490 (phase 2b). Relates to: #488 (meta plan), #496 (2a), #498 (2c). Branch: feat/pi-ssh-tools. Status: Done (2026-10-26) — implemented as planned, with the errata below
Design
What this phase is for
Phase 2a made a Workspace that acts on another host. This phase makes pi’s tools use it: read, write, edit, ls, find, grep, bash, and ! (user_bash). The bar is the meta plan’s: functions identically. Here that means a parity test for each tool: the same fixture tree, pi’s own tool run locally against it and ours run through an SSH workspace against it, and the text the model sees compared exactly. Where pi’s output includes a local path the remote cannot know, the plan says what differs and why.
How each tool reaches the remote
pi’s tools take an operations object (node_modules/@earendil-works/pi-coding-agent/dist/core/tools/*.d.ts). Where the operations cover everything the tool touches, ours wraps pi’s tool with operations over the workspace, and pi’s own formatting stays. Where they do not, ours re-states the tool, with the helpers pi exports from its package root (dist/index.d.ts, line 26: truncateHead, truncateTail, truncateLine, formatSize, DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, and the create*ToolDefinition factories) and a parity test.
| Tool | How | Notes |
|---|---|---|
|
pi’s tool, |
|
|
pi’s tool, |
|
|
pi’s tool, |
|
|
pi’s tool, |
|
|
ours, |
pi’s |
|
ours, |
pi’s |
|
pi’s tool, |
|
|
|
The same |
What pi passes as env, and what crosses. pi’s bash tool builds env from the local shell environment plus PI_SESSION_ID, PI_SESSION_FILE, PI_PROVIDER, PI_MODEL, PI_REASONING_LEVEL (bash.js:135-152) and hands it to exec. The adapter forwards only the PI_* keys as env additions; everything else is dropped, and workspace.exec adds its allowlist (2a). So the remote command gets its own login environment, the terminal and locale, and pi’s session markers. Pinned by a test with a stubbed local GITLAB_TOKEN.
Truncated bash output. When output exceeds pi’s limits, pi writes the full output to a local temp file and names it in three places of the result (bash.js: the content[0].text notice, details.fullOutputPath, structuredContent.full_output_path). In a remote session the read tool reads the remote, so that path would be unreadable. The wrapper copies the local temp file to the remote (<home>/.pi-ssh/tmp/pi-bash-<id>.txt, home from the remote’s hello, through writeFile) and rewrites all three. Parity test: a command printing past the limit yields a full_output_path that read (remote) reads in full.
Paths. pi’s tools resolve relative paths against ctx.cwd, which in a remote session is the local anchor (2c). workspace.resolve maps an anchor path under the remote root and passes a remote absolute path through (2a), so both the model’s src/x.ts and its /srv/app/src/x.ts reach the right file. Output paths are relative to the search root (find, grep) or absent (read, edit), so they read the same.
Switching: extension.ts
registerRemoteTools(pi, deps) registers the seven tools under pi’s names and the user_bash handler. Each tool’s execute asks deps.workspace() (currentWorkspace() from @gadhs/pi-workspace, slot.ts): remote, and the call goes through the remote tool; otherwise through pi’s own local tool, unchanged.
The host facts the tools need. Workspace (types.ts) says nothing about the host, and sshWorkspace keeps its connection private. This phase widens sshWorkspace’s return type to `RemoteWorkspace extends Workspace with destination and host(): Promise<HostFacts> ({ platform, arch, home, node }, from the connection’s hello, connecting if needed), exported from ssh-workspace.ts; extension.ts narrows with "host" in ws. The hello gains arch: process.arch (protocol.ts Hello, helper.mjs, additive; protocol stays 1). Every remote path the tools write to is built from home, absolute, never $HOME in a string. The decision is per call, so a session that connects (2c) or loses its remote switches without re-registration. The default export is the extension factory; the loader in @gadhs/pi is 2c’s, so in this phase nothing loads it for a user.
rg and fd on the remote: remote-tools.ts
pi provisions rg and fd for the local machine from their GitHub releases (dist/utils/tools-manager.js: BurntSushi/ripgrep, sharkdp/fd, static linux-musl, apple-darwin and windows-msvc assets by architecture, cached under the agent dir, skipped under PI_OFFLINE). The remote needs the same, for its own platform and architecture. ensureRemoteTool(workspace: RemoteWorkspace, "rg" | "fd"), in order:
-
command -v rgon the remote: present, use it. -
<home>/.pi-ssh/bin/rgon the remote with the pinned version (rg --version): use it. -
Otherwise download the asset for the remote’s
platformandarch(fromhost()) locally, from the same release URLs pi uses, at versions pinned inremote-tools.ts(ripgrep 14.1.1, fd 10.2.0; achore:bumps them), extract with the systemtaras pi does, cache under<agentDir>/gadhs-pi-ssh/tools/, andwriteFilethe binary to<home>/.pi-ssh/bin/on the remote with mode0o755. Once per remote. -
Under
PI_OFFLINE, or a download failure, or a platform with no static asset: the tool’s result is an error naming the host and what to install (apt install ripgrep, say). Fail closed: never a localrgon local files.
The download runs on the developer’s machine because that is the one with the credentials and, often, the internet.
Fail modes
-
The workspace is lost mid-call: the tool result is the connection’s error (fail-closed, loud); pi’s tool shows it as any failed tool; the next call reconnects (2a).
-
rgorfdcannot be had on the remote: the tool errors with the reason and the remedy; nothing searches locally instead (fail-closed). -
A download is tampered with in transit: each pinned version carries the asset’s SHA-256 beside it, checked before upload; a mismatch is refused and named (fail-closed).
-
full_output_pathupload fails: the result keeps pi’s text with the local path and adds one line saying the full output stayed on the local machine (fail-open on the detail, loud). -
A remote whose
bash -lprints to stdout on login (a chatty profile): the output precedes the command’s, as it would for anyssh host bash -lc(silent, by design; documented, the same as running pi there with that profile). -
A parity test’s fixture depends on the local
rgorfd: pi’s own tools download them on first use; where that cannot happen (offline CI), the parity cases forfindandgrepskip visibly, never pass empty (fail-closed for the test: a skip is reported, not a pass).
Scope
In
-
This plan as
docs/modules/ROOT/pages/plans/remote-2b-tools.adoc, nav entry,In progressat the start. -
packages/pi-ssh/:tools.ts(the operations objects and the two re-stated tools),remote-tools.ts(rg and fd),extension.ts(registerRemoteTools, theuser_bashhandler, the default export),index.tsexports,package.jsonexportsgaining./extension,peerDependencies@earendil-works/pi-coding-agentas the other extension packages declare it;helper.mjshello gainsarch. -
Tests, by category:
-
Parity (contract):
test/parity.test.tsbuilds one fixture tree (text files, nested directories, a.gitignoreand ignored files,node_modules, a PNG, a long-lined file, a file with a BOM) and, for each tool and the inputs named in the table, asserts our result’scontenttext equals pi’s local tool’s on the same tree.bashcompares output, exit code and the truncation shape.findandgrepskip visibly without a localfdorrg. -
Security (contract): the bash adapter forwards only
PI_*of pi’s env; a stubbed localGITLAB_TOKENandAWS_SECRET_ACCESS_KEYnever reach the remote command; thePI_*markers do. -
Unit: the bash contract (aborted, timeout, missing cwd, signal exit code), the
full_output_pathrelocation and its fail-open line, image sniffing,ensureRemoteTool’s four branches with a fake downloader and a fake remote (`command -vfound, cached, downloaded and uploaded with0o755and the checksum, refused offline and on a bad checksum), the per-call switch between local and remote. -
Mutation check: the
PI_*filter, the checksum check, the offline refusal, the per-call switch,find’s `--no-require-gitbranch, `grep’s limit; each killed before the MR.
-
-
Docs: a section in the package README;
packages.adoc’s row updated; `CHANGELOG.adocAdded; the meta plan gains anErratumline re-scoping phase 2 into 2a (#496), 2b (#490: the tools) and 2c (#498:/ssh, anchor, safeguards, loader, release), since its first erratum still describes 2b as carrying/sshand the loader. -
Named but not supplied to the cold reviewer:
CHANGELOG.adoc,docs/modules/ROOT/nav.adoc,docs/modules/ROOT/pages/packages.adoc,packages/pi-ssh/{index,protocol}.ts,packages/pi-workspace/slot.ts, and pi’sdist/core/tools/{read}.js,dist/utils/tools-manager.jsanddist/index.d.ts(untrackednode_modules; the line numbers above are pi 1.1.0’s, the repository’s pinned copy). -
Delivery: one MR,
Closes #490,Relates to #488; the merge SHA on #488; 2c’s plan next. Released with 2c.
Out
-
/ssh, the anchor, the session switch, the system prompt, the status line, the loader, the commit refusal and judge safeguards, docs page and release (2c, #498). The guards and containment (phases 3 and 4). Port forwarding (5). PowerShell as a remote shell (a Windows remote is out of scope). Chunked uploads of large binaries:rgandfdare a few MB each and go in onewriteFile.
Erratum (2026-10-26): the operations are ops.ts and the re-stated grep and find remote-search.ts, not one tools.ts; detectImageMimeType reads the first 16 bytes with the remote’s head -c.
Erratum (2026-10-26): pinned at ripgrep 15.2.0 and fd 10.5.0, the current releases when implemented, not 14.1.1 and 10.2.0.
Erratum (2026-10-26): grep passes --no-config first, as pi 1.4.0’s does (the repository’s pi 1.1.0 lacks it), so a remote’s ripgrep config cannot change results.
Erratum (2026-10-26): an uploaded tool is <home>/.pi-ssh/bin/<tool>-<tag>, reused when present rather than asked --version, and written to a .part name then renamed, so an interrupted upload is never run.
Erratum (2026-10-26): the forwarded markers are PI_SESSION_ID, PI_PROVIDER, PI_MODEL and PI_REASONING_LEVEL; PI_SESSION_FILE is a local path and stays local.
Erratum (2026-10-26): the full output’s remote copy keeps pi’s temp file name, <home>/.pi-ssh/tmp/<name>, and a thrown abort or timeout naming it is rewritten too.
Erratum (2026-10-26): a remote call sees the remote root as ctx.cwd (a proxy over pi’s context), not the anchor, so its messages name remote paths as pi’s do locally; a leading ~ in a path is the remote’s home.