
⚠️ A local session is not bound to a remote workspace. Opening a remote workspace in
Presence does not turn a local agent session into a remote one. When your session's
working directory is outside the presence mounts root,presence_execand every other
presence_*tool require an explicithost(orPRESENCE_HOST); without one they refuse
with the session's cwd instead of silently running on the last-activated machine. Sessions
started inside a remote workspace resolve to that machine automatically. See
Known limits.
Why
Running an agent on every remote machine means installing it N times, upgrading it N
times and configuring proxies per host. Running ssh host '<command>' from the local
agent means a new handshake per command, no native file tools and no continuity.
Presence keeps the agent local and extends its reach through one persistent SSH
connection per host. The remote side is still plain sshd: SFTP, exec and a PTY.
| Approach | Cost |
|---|---|
| Install the agent on every host | N installs, N upgrades, per-host proxying |
ssh host '<command>' per call |
Handshake per command, no file tools, no sessions |
| Presence | One connection per host, native tools, nothing installed remotely |
Features
- Remote zero-install — uses only
sshdbuilt-ins: the SFTP subsystem, exec channels and a PTY. - One handshake — a pool keeps one connection per host; every later call is a request on it.
- Native remote tools —
rg/grepruns on the target, commands run in the target shell; path, permission and encoding semantics are the remote ones. - Local-like edits — atomic writes, mode preservation, ambiguity refusal, read-before-write guard,
presence_editwith dry-run diffs. - Real workspaces — a remote directory becomes a normal DSH workspace with a file tree and terminals that open on the remote machine.
- Sessions are scoped (0.20 hotfix) — a local session no longer silently borrows the last-activated remote workspace:
presence_*needs an explicithostorPRESENCE_HOST, and the system prompt tells each session whether it is local or remote. - Conditions instead of sleeps —
presence_waitblocks on a file (exists/minBytes/mtimeAfter), a grep match count, a process (pid/pattern), a port state or a job id; a timeout ismet:false, not an error. - Jobs that survive a restart — background jobs are persisted to
~/.dsh/presence/jobs.jsonwith pid/pgid.logPathis the job log to tail;commandLogPathis the command's own log and equalslogPathon current kernels (a separate wrapper log only exists when a kernel records one) — usecommandLogPath ?? logPath. After a restart their state isunknownuntil probed — never a falserunning, and an exit code may be missing. - Batch transfer and append —
presence_import/presence_exporttakepaths[](1–50) or a glob and return per-file results;presence_write { mode:"append" }appends without rewriting the file. - Recoverable deletes — destructive shell commands dry-run first;
presence_trashmoves paths to a remote trash with restore. @completes remote files — inside a remote workspace, file-reference completion indexes the machine itself (rg --files,findfallback), not a local mirror.- File operations, not just reads —
presence_mkdir/move/copy/chmodplus a right-click menu in the file tree; deletes go to the recoverable trash. - Diff and live logs — unified diff between two remote files or a remote file and a local one; follow a log file from the panel without keeping a
tail -fjob around. - Ports that come back — save forwards with auto-restore on reconnect, and let the Ports panel discover newly listening ports and forward them with one click.
- Job notifications — a toast (and desktop notification) when a background job finishes, plus an optional local
notifyCommandfor daemons and phones. - Two shells, one kernel — the DSH plugin and a standalone MCP server (
presence-mcp, 20 core tools) share the same kernel.
Screenshots
![]() |
![]() |
| Settings — every host and folder is a local tab | Remote workspace — the file tree and editor are on the host |
![]() |
![]() |
| @ files — completion indexes the remote machine itself | Terminal — the shell runs on the host, not locally |
A real trajectory
These three figures are rendered from a recorded 22-call session: train an MNIST
classifier twice on a remote 64-core host, compare two learning rates, and export
the result. Every row is one tool call with its measured duration; red rows are
real failures kept verbatim.



Figure 3 stacks end-to-end time into think / wait / tool. The same task through
bare ssh/scp takes 452.5 s versus 272.8 s, with a 10.4×
higher median interaction latency.
Quick start
1. Install the DSH plugin
dsh plugin add @rjfan/dsh-presence@0.20.0
From a source checkout:
dsh plugin add /path/to/dsh-presence
2. Pick a host and open a workspace
Open Settings → Presence → New, choose a host from ~/.ssh/config (or paste a
manual ssh command), then pick a remote folder. It appears as a workspace; the
left sidebar, file tree, terminal and agent tools all use that remote directory.
A session started in that workspace is remote. A session started anywhere else (for
example a normal local project) stays local: it must pass host explicitly — or set
PRESENCE_HOST — before calling presence_exec / presence_*.
3. Work
You: 把远程 8000 端口转发到本地,然后打开看看
Agent: presence_forward { remotePort: 8000 }
→ http://127.0.0.1:8000
MCP server
The same kernel is available to agents that cannot install DSH plugins (Codex CLI,
Claude Code, OpenCode, Cursor, …).
npx -y presence-mcp # 20 tools over stdio
// Claude Desktop / OpenCode style
{
"mcpServers": {
"presence": {
"command": "npx",
"args": ["-y", "presence-mcp"],
"env": {
"PRESENCE_HOST": "server",
"PRESENCE_WORKSPACE": "server:/srv/app"
}
}
}
}
See mcp/README.md for Codex TOML, Claude Code, OpenCode and
Cursor/Windsurf examples.
How it works
┌───────────────────────────────┐
│ DSH plugin / MCP server │ two shells, one kernel
└──────────────┬────────────────┘
│
Presence kernel
├── ssh-config hosts, ports, users, keys, jumps from ~/.ssh/config
├── connection one persistent connection: SFTP / exec / PTY + pool + cancel
└── host pool one connection per host, created on demand, idle-collected
│
SSH (your existing keys, known_hosts, jumps, proxies)
│
target: Linux / macOS, stock sshd
| Agent operation | Channel | Remote dependency |
|---|---|---|
| read / write / edit / list / stat | SFTP subsystem | sftp-server (stock sshd) |
exec, search (rg/grep), git |
exec channel | commands already on the host |
| interactive terminal | shell channel + PTY | the host's login shell |
Measured on a Linux host:
| Operation | Latency |
|---|---|
ssh host '<cmd>' (new connection every time) |
520–540 ms |
| Presence connect (one handshake, key auth) | 145 ms |
Presence sftp stat |
p50 0.6 ms / p95 0.9 ms |
Presence exec true (new channel + shell) |
p50 7.6 ms |
| 8 concurrent exec channels | 15 ms total |
Keep TCP_NODELAY on: without it, request/response hits delayed ACK and p95 goes
from 0.9 ms to 48 ms.
Tools
The DSH plugin exposes 25 tools. Inside a remote-workspace session relative paths
resolve against that workspace and host is optional; a local session must pass
host explicitly (or configure PRESENCE_HOST) — there is no fallback to the globally
last-activated workspace. Argument aliases are accepted at execute time
(path/file_path/filePath, old/oldString, new/newString, cwd/workdir, …),
so an agent's habitual spelling still works.
Show all tools
| Tool | What it does | | --- | --- | | `presence_hosts` | List SSH hosts, connection state and default host (`format:"json"` supported); `workspace:true` marks this session's machine and `degraded` rows carry the last error. `default` is session-scoped: this session's mounted host or `PRESENCE_HOST`, never a global last-active workspace. | | `presence_connect` | Open/reuse a host connection and report the remote identity. | | `presence_exec` | Run a remote command; `pipefail`, `background`, `waitForPort`, structured JSON, `saveStdout`; timeout defaults to 300 s; `progress` normalizes `\r` progress bars; long output spills to a remote file whose path is returned (`tailLines`); text reports start with `host:Batch transfer and append
presence_export { paths: ["/data/a.pt", "/data/b.pt"] } # files:[{remotePath, localPath, bytes, sha256}]
presence_export { glob: "/data/ckpt-*.pt" } # every match; name-<sha8>.ext on collision
presence_import { glob: "dist/*.whl", to: "/data/wheels" } # local → remote, one result per file
presence_write { path: "/data/train.log", mode: "append", content: "epoch 6 done\n" }
Single-path calls keep the existing path/to behaviour, so none of this is required for
one file.
Which tool for which path
| Where the path lives | Use | Why |
|---|---|---|
under the workspace mount (~/.dsh/presence/mounts/...) |
built-in read / write / edit / grep / glob |
they reach the remote machine; grep/glob are routed to it automatically |
remote absolute path outside the workspace (/data, /scratch, GPFS) |
presence_read / write / edit / stat / search / glob (list a directory with presence_exec) |
the built-in tools only see the mount, not the rest of the machine |
| local file, for preview or Office | presence_export first, then present / native open |
the mount path is virtual; only a real local file can be opened natively |
In a local session (cwd outside the mounts root) the built-in tools only touch local
files; every presence_* call needs host explicitly, or configure PRESENCE_HOST once.
Long-running tasks
presence_exec waits for the command, so it is the wrong tool for a training run, a
build or a server. The recipe:
1. presence_exec { command: "python train.py --lr 3e-4", background: true, label: "train-3e-4" }
→ { id: "j7", pid: 4242, pgid: 4242, logPath: ".../job.log", commandLogPath: ".../job.out" }
2. presence_jobs { action: "wait", jobId: "j7" } # or presence_wait { job: { jobId: "j7" } }
3. presence_tail { path: <logPath>, follow: true } # watch progress
presence_wait { grep: { path: <logPath>, pattern: "epoch 6", count: 1 } } # readiness
presence_jobs { action: "status" }gives a snapshot;stopterminates the process
group and verifies the port was released. Jobs persist to~/.dsh/presence/jobs.json:
after a DSH restart a job showsunknownuntil a liveness probe succeeds (never a false
running) and its exit code may be missing.logPathis the job log to tail — the command's stdout/stderr on current kernels.
commandLogPathis the command's own log; it equalslogPathunless the kernel records
a separate wrapper log, so tailcommandLogPath ?? logPath.presence_waitreplaces hand-written sleep+tail loops: wait for a port
(presence_wait { port: { port: 8000, state: "open" } }), a checkpoint
(presence_wait { file: { path: "/data/ckpt.pt", minBytes: 1000000 } }), a log line or
a process. A timeout returnsmet:false— a normal answer, not an error.- Interactive work:
presence_terminal { action: "open", session: "train" }— the
tmux-backed session survives a reconnect. - Do not start
nohup,tmux new-sessionor a trailing&inside a foreground
presence_execfor long jobs: when the login-node session ends, the cluster may clean
up what it left behind.background: truealready detaches throughsetsid; on
scheduler-managed clusters start the job with the cluster's own launcher
(rlaunch -d …,salloc/sbatch) so the scheduler owns it.
Safety and recovery
- Destructive commands never run unconfirmed.
rm -r/-f,git clean -fdx,
find -delete,shred,truncateanddd of=are first replayed with
no-op shims to expand their real targets; unset variables and protected paths
(workspace root, home,/,.git) are refused. A second call with
confirm:trueis required to execute. A rejected mixed command also lists the
segments that are safe on their own (Safe segments you can run separately:);
confirm:"partial"runs only those. Removing one file with a literal
rm -f <path>inside the workspace is exempt — it cannot remove a tree. - Prefer
presence_trashfor anything under a workspace: it moves the path to
~/.dsh/presence-trash/<timestamp>/and returns a restore hint. - Writes are atomic and keep the original file mode;
presence_editrefuses
ambiguous anchors instead of guessing. - Read before write: built-in
read/write/editshare a read-before-write
guard. Path keys are canonicalised acrosspresence://, mount paths, workspace-relative
and absolute remote paths, and successfulpresence_read/presence_write/
presence_editcalls count as a read (a write counts too).presence_execrunning
cat filedoes not count — the guard cannot see shell output; read with
presence_reador the built-inreadbefore editing.
Configuration
The plugin reads these environment variables on the host process:
| Variable | Default | Meaning |
|---|---|---|
PRESENCE_HOST |
— | Default SSH host for local sessions (explicit opt-in; also used by the MCP server). Remote-workspace sessions ignore it in favour of their mounted host. |
PRESENCE_WORKSPACE |
— | host:/abs/path to bind a remote workspace. |
PRESENCE_JOBS_FILE |
~/.dsh/presence/jobs.json |
Override the persisted background-job registry path. |
PRESENCE_PASSWORD_<ALIAS> |
— | Password for a host; <ALIAS> is uppercase with non-alphanumerics replaced by _. |
PRESENCE_MAX_CHANNELS |
8 | Concurrent channels per connection. |
PRESENCE_CONNECT_TIMEOUT_MS |
25000 | Connection attempt timeout. |
PRESENCE_IDLE_TIMEOUT_MS |
900000 | Idle connection timeout (connections with terminals are kept). |
PRESENCE_READ_ONLY |
false | Refuse writes/edits; reads, search and exec still work. |
Full configuration and the path/permission matrix are in
docs/VERIFICATION.md and docs/HANDOFF.md.
Development
npm install
npm install --prefix .dev --ignore-scripts rollup @rollup/plugin-node-resolve \
@rollup/plugin-commonjs @rollup/plugin-terser codemirror @codemirror/language-data \
@codemirror/theme-one-dark
node scripts/build-client.mjs
powershell -NoProfile -ExecutionPolicy Bypass -File scripts/package.ps1 -Version 0.20.0
# → dist/presence-plugin-0.20.0.zip
Tests need one SSH-reachable host unless noted:
node scripts/regression.mjs server # transport, symlinks, timeouts, binary
node scripts/job-probe.mjs server # jobs + port forwarding
node scripts/feature-probe.mjs server # wait, sessions, pgid, readiness, search
node scripts/import-probe.mjs server # local→remote binary, mode, sha256
node scripts/safety-probe.mjs server # destructive guard + observation store
node scripts/p0-guard-probe.mjs # guard split/partial/single-rm (no host needed)
node scripts/p1-docs-probe.mjs # README/zh/RELEASE anchors (no host needed)
Known limits
- Local sessions. A local session calling
presence_*withouthostnow raises
this session is local (cwd=...); pass an explicit host .... That is the intended 0.20
behavior, not a bug: the old silent fallback to the last-activated remote workspace could
run commands on another session's machine. Passhostper call, or setPRESENCE_HOST
once as the explicit opt-in default; a local session still never inherits another
session's workspace, andpresence_hosts'defaultis session-scoped for the same reason. - The read-before-write guard cannot observe shell output:
presence_exec { command: "cat file" }(orsed -n) does not mark the file as read;presence_readand the
built-inreaddo, andpresence_write/presence_editcount as reads. A guarded
built-ineditafter onlyexec catcan still fail. - The mount path (
~/.dsh/presence/mounts/...) is virtual: it works through
ctx.fs/ agent tools, but native apps (Explorer, Office, host Python) cannot
see it — usepresence_exportfirst. presence_execdefaults to a 300 s timeout; longer work must usebackground: true
(foreground output over the cap is spilled to a remote file, andtailLineskeeps the
end of a long report). Background jobs persist to~/.dsh/presence/jobs.json; after a
DSH restart their state isunknownuntil a liveness probe succeeds — never assume a
persisted job is still running, and its exit code may be missing. Tail
commandLogPath ?? logPath(logPathholds the command output on current kernels).- A login node may clean up processes left behind when a session closes: do not rely on
nohup/tmux new-session/&started inside a foregroundpresence_execfor long
jobs. Usebackground: true(detached withsetsid) orpresence_terminal(tmux),
and let the cluster scheduler own the job where required (rlaunch -d,salloc/sbatch). - Argument aliases are accepted (
path/file_path/filePath,old/oldString,
new/newString,replaceAll/replace_all,dryRun/dry_run,cwd/workdir);
the canonical name is what the tool schema documents. - SSH
MaxSessions(default 10) bounds concurrent channels; the pool uses at most 8. - PTY terminals follow the connection; cross-reconnect shells need
tmuxon the target
(used automatically bypresence_terminal { session }). - ProxyJump/ProxyCommand are parsed and warned about, but not used for dialing yet.
@file completion indexes the remote tree lazily (about 10 s per workspace);
on a very large tree the first query can take a few seconds.- Port auto-restore runs when the connection is re-established; a forward whose
saved local port is already taken falls back to another free port.
Contributing
Issues and PRs are welcome. For a feature, open an issue describing the remote
workflow you want; for a fix, keep the diff focused and add a probe under
scripts/ when behavior changes.




