← Catalog

pi-remote-call

Call shell and file tools on SSH hosts from one local Pi, with zero remote installation.

Extension

Install

Install with PiG

pig install npm:pi-remote-call

Install with Pi

pi install npm:pi-remote-call
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./src/index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.3.4 (README.md). PiG does not review it.

pi-remote-call

A local Pi extension that exposes five typed tools for operating SSH-accessible Linux hosts. It uses local SSH exec channels and SFTP. Nothing is installed on the remote machines: no remote Pi, Node.js, npm package, MCP server, agent, or daemon.

The extension adds remote_* tools. It never replaces Pi's local bash, read, write, or edit tools.

Requirements

Local machine:

  • Pi 1.7.0 or a compatible newer release
  • Node.js 22.19+
  • OpenSSH-compatible ssh and ssh-keygen commands on PATH
  • Existing noninteractive SSH authentication and a verified known_hosts entry

Remote machine:

  • sshd, Bash, and SFTP already enabled
  • Optional but recommended: python3 3.8+ for remote-side text reads and edits. No pip packages are needed.
  • Without Python, text tools retain the SFTP behavior from version 0.1.1.
  • Standard hostname, id, uname, kill, sleep, and rm commands

Install

npm

pi install npm:pi-remote-call@0.3.4

GitHub

pi install git:github.com/therainisme/pi-remote-call@v0.3.4

Local directory

pi install /absolute/path/to/pi-remote-call

Create ~/.pi/agent/pi-remote-call.json:

{
  "version": 1,
  "hosts": ["server-a", "server-b"]
}

Only aliases in hosts[] can be used. User, hostname, port, identity files, agent, HostKeyAlias, HostKeyAlgorithms, and known-hosts paths come from the existing OpenSSH configuration via ssh -G <alias>; secrets and connection fields are not duplicated into this file.

Set PI_REMOTE_CALL_CONFIG to use a different local config path.

Restart Pi after changing the allowlist. Connections are opened lazily and are not opened by remote_hosts({action:"list"}).

File execution modes

Each new connection probes for Python 3 and reports fileMode in host status and diagnostics:

  • python: a bundled, standard-library-only helper runs once per text operation. Reads return only the requested range plus pagination metadata; edits return diff details without transferring the whole file to the local machine. Writes and edits use temporary files, metadata checks, and atomic replacement.
  • sftp: the original 0.1.1 behavior remains as a compatibility path. Pi's native read streams through SFTP, while edits are computed locally and written back through SFTP.

Python is never installed by this extension. The helper runs without a daemon, remote Pi, Node.js, or MCP server. Its source is cached at ~/.pi/agent/cache/pi-remote-call/helper-v1-<sha256>.py; the directory is mode 0700 and the helper is 0600. Each connection verifies the regular file, size, and SHA-256 before its first cached operation, and concurrent callers share that initialization. Cache installation uses a temporary file, fsync, and atomic rename. Old versions are not deleted automatically.

If the cache cannot be prepared, the helper source is sent inline instead. Fallback is selected before an operation starts: a Python operation that fails is never replayed through SFTP. Host status reports helperCache as installed, hit, or inline after initialization. Inline fallback also exposes a sanitized helperCacheError with the failed stage and reason.

Tools

Every execution tool requires host. There is no global current host, so calls to different hosts can be made independently in the same turn.

remote_hosts

{"action":"list"}
{"action":"status","host":"server-a"}
{"action":"diagnose","host":"server-a"}
  • list: list configured aliases and cached connection state.
  • status: inspect cached state without opening a connection.
  • diagnose: return per-hop stages for SSH config, security policy, known-hosts loading, transport, host-key verification, authentication, SFTP, and Bash. Failures return ok: false, preserve completed stages, and include a sanitized error without a stack or raw cause chain.

remote_bash

{
  "host": "server-a",
  "command": "pwd && uname -a",
  "cwd": "~/work",
  "timeout": 30
}

cwd defaults to the remote user's home directory. timeout is in seconds. Output streaming, tail truncation, exit status, timeout handling, and result details use Pi's native bash implementation.

remote_read

{
  "host": "server-a",
  "path": "notes/todo.md",
  "offset": 1,
  "limit": 200
}

The example reads ~/notes/todo.md. An optional cwd changes the base for relative paths. Absolute paths and ~/... ignore cwd.

Text pagination and head truncation match Pi's native read behavior. In Python mode, the remote helper scans the file and returns only the selected range and pagination metadata. In SFTP mode, native read streams the file to the local machine as in 0.1.1. Supported images are always read over SFTP and returned as native Pi image content.

remote_write

{
  "host": "server-a",
  "path": "notes/todo.md",
  "content": "new complete contents\n"
}

Creates parent directories and completely replaces the target. Python mode preserves ordinary permission bits, owner/group, and available xattrs, resolves symbolic links, and rejects unsafe hard-link or special-mode replacements. SFTP mode retains the 0.1.1 temporary-file and rename behavior. This tool is for new files or complete rewrites.

remote_edit

{
  "host": "server-a",
  "path": "notes/todo.md",
  "edits": [
    {"oldText":"before","newText":"after"}
  ]
}

All replacements must exactly and uniquely match disjoint regions of the same original file. Empty, missing, duplicate, overlapping, and no-op edits fail before writing. BOM and existing LF/CRLF line endings are preserved. Results contain Pi-native diff, patch, and firstChangedLine details. Python mode performs the edit remotely and checks the file hash and metadata again immediately before replacement; a changed file is left untouched and returns E_REMOTE_FILE_CHANGED.

Command

/remote-call
/remote-call list
/remote-call status server-a
/remote-call disconnect server-a

Connections also close during Pi session shutdown. A later call reconnects on demand.

Failure behavior

  • Unknown or changed host keys fail. The extension never disables host-key checks or automatically trusts a new key.
  • Effective HostKeyAlgorithms are enforced on every hop. If no configured algorithm is supported by the transport, the connection fails closed. Non-none RevokedHostKeys/KRL configuration is also refused before connection setup because full KRL evaluation is not implemented; @revoked known-hosts entries remain supported.
  • Passwords, private-key passphrases, interactive 2FA, and keyboard-interactive authentication are not requested. Fix ssh <alias> so it works noninteractively first.
  • A failed command or write is not automatically replayed after reconnecting.
  • Bash commands use a random stderr completion marker to recover the real exit code if SSH omits exit-status. If both are absent, the outcome remains unknown. A Python helper success is accepted without either status only when its complete JSON envelope contains result; writes are never replayed.
  • Once a write or edit has started, cancellation, timeout, transport loss, or an untrustworthy helper response returns E_REMOTE_FILE_UNKNOWN with outcome: "unknown". Inspect the target before retrying. Pre-start cancellation and explicit helper validation errors keep their original meanings; a confirmed successful write remains successful if cancellation arrives afterward.
  • Python is probed when a connection opens. There is no mid-operation fallback: once a helper starts, its failure is returned and the operation is not replayed through SFTP.
  • There are deliberately no request queues, concurrency limits, file locks, or forced serial writes. Avoid conflicting parallel edits. Concurrent writes to one path can overwrite one another.

Limitations

  • ProxyJump (including comma-separated hops) and ProxyCommand are supported. Every SSH hop requires noninteractive authentication and its own verified known_hosts entry. ProxyCommand supports %h, %p, %r, %n, and %% expansion.
  • Standard known_hosts public keys are supported. CA-based @cert-authority trust fails explicitly: the current ssh2 transport cannot verify certificate host-key handshakes. It must not be bypassed with a plain-key assumption.
  • Remote targets are Linux/Bash systems, not Windows shells.
  • Remote paths use POSIX /. Local Windows is supported. However, when Pi runs on Windows, remote_read cannot address a remote POSIX file name containing a literal backslash (\), because Pi's native read parser treats it as a path separator. Normal / paths and the other remote tools are unaffected.
  • No interactive terminal, port forwarding, remote Pi worker, or separate search tool. Use remote_bash with existing remote tools such as rg for search.
  • SFTP compatibility mode retains 0.1.1 behavior, including whole-file network reads and whole-file edit download/upload. Use Python mode for large remote text files.
  • Python edit loads file content into remote memory. Read retains only the requested lines but scans to EOF for exact totalFileLines, matching Pi's native read behavior. Atomic rename reduces partial-file writes but cannot eliminate the small check/rename race or make a disconnected operation's outcome certain.
  • Python mode refuses hard-linked files, special mode bits, and metadata it cannot preserve. SFTP mode has the original 0.1.1 metadata and race limitations.

Development

npm install
npm run check

npm run check typechecks, builds, and runs unit/integration tests. It does not open SSH connections unless PI_REMOTE_CALL_E2E=1 is explicitly set on Linux.

Helper integration tests run when python3 is available. Set PI_REMOTE_CALL_PYTHON to select a specific local interpreter; CI provisions Python explicitly. Ordinary local tests do not open SSH connections. Ubuntu CI additionally installs OpenSSH server and sets PI_REMOTE_CALL_E2E=1 to run direct, ProxyJump, ProxyCommand, file-operation, host-key diagnostics, session loss, cancellation, disconnects immediately before/after atomic rename, cache corruption/fallback, and injected fsync failure against temporary local sshd instances with generated keys and random ports.

Package layout:

src/index.ts          extension entry and /remote-call command
src/tools.ts          five typed tool registrations
src/host-manager.ts   per-alias lazy connection reuse
src/transport.ts      SSH authentication, host-key verification, Bash channels
src/sftp.ts           SFTP streams, directories, atomic writes
src/file-tools.ts     remote POSIX paths, exact edits, native result details
src/config.ts         allowlist-only configuration
src/python-files.ts    Python result validation and native read formatting
src/remote_helper.py   one-shot remote text read/write/edit helper
src/remote-helper.ts   helper source identity and versioned cache path
src/python-protocol.ts helper stdout/stderr and JSON response handling
src/exit-marker.ts   streaming watchdog completion-marker recovery
src/proxy.ts         ProxyJump destinations and ProxyCommand streams

MIT