# v4 — the control plane **Branch: `v4`.** Everything here is additive. A user who installs v4 and changes nothing gets v3 behaviour, byte for byte. That constraint is not negotiable: this package has external users, and the whole point is that the new surface is opt-in. ## The idea v3 is an SSH engine an agent talks to. It already holds the pieces of a control plane — per-server security modes, an append-only audit log, tunnels, sessions, keys, groups — but they are invisible: configured through environment variables, observed by reading a file. v4 makes them usable, and adds the one thing missing: **the ability to stop an action and ask a human.** The engine stays MIT, headless, installable with `npm` alone. The interface is optional and never required for the engine to run. ## Status | Piece | State | |---|---| | **Encrypted vault** (`src/secret-store.js`) | **done** — AES-256-GCM, key in the OS keychain with a file fallback | | **`ssh-manager vault`** (`cli/vault.js`) | **done** — list, add, remove, import, status | | Loader integration | **done** — vault sits above files, below the process environment | | **Approval broker** (`src/approval.js`) | **done** — pause an action, ask a human, deny on any failure | | **Control plane** (`src/control-plane.js`, `cli/control.js`) | **done** — approval queue + timeline, no dependency | | **Homebrew formula** (`Formula/ssh-manager.rb`) | **done** — kept current by the release workflow | | **Desktop app** (`desktop/`) | **done** — native macOS window, 104 KB | | **Live command streaming** (`src/live-stream.js`) | **done** — watch the agent work, as it happens | | **Server health** | **done** — on-demand probes, never in the background | | **Options** (groups, host keys, tunnels) | **done** | | **Skills** (`skills/`) | **done** — three, shipped with the package | | **Interactive terminal** | **done** — a real shell in the browser, no native module in the engine; the desktop build adds one on *this* machine | ## Done: the vault The only way to give a server a password used to be clear text in a `.env`. Now: ```bash ssh-manager vault import # copy what you already have, encrypted ssh-manager vault list # see it, without ever printing a secret ssh-manager vault add prod # add one interactively ssh-manager vault status # where the vault and its key live ``` Decisions worth keeping: - **Only secret values are encrypted.** Hosts, users, ports and modes stay readable, because hiding them buys nothing and makes the file impossible to reason about or diff. - **GCM, not CBC.** Authenticated: a tampered vault throws instead of returning a wrong password that would then be sent to a production server. - **Listing never unlocks.** Asking "which servers exist" must not trigger a keychain prompt. - **`SSH_MANAGER_KEY_SOURCE=file`** skips the keychain, for CI, containers and plain SSH logins with no desktop session. - **A corrupt vault never blocks the other sources.** `.env` and TOML still load. ## Done: the approval broker It went in where predicted — inside `applyServerPolicy()`, the single choke point all sixteen handlers already call, and which was already `async`. No handler signature changed. ```env SSH_SERVER_PROD_APPROVAL=destructive # never (default) | destructive | always ``` Protocol: one JSON object per line over a local stream socket. The engine writes a request and waits for a reply carrying the same `id`, so a control plane is implementable in any language and debuggable with `nc`. ```json {"id":"…","server":"prod","host":"…","tool":"ssh_execute", "command":"rm -rf /var/www","destructive":true,"args":{…}} {"id":"…","decision":"deny","reason":"not tonight"} ``` Rules that matter more than the happy path: - **Every failure denies.** Timeout, unreachable socket, connection dropped mid-review, unreadable reply, or a reply carrying the wrong `id` — all refuse. The one exception is *approval configured but nothing listening*: that allows and says so loudly in the audit log, because failing shut would break every agent the moment the UI is closed. - **The deadline is not optional.** `SSH_MANAGER_APPROVAL_TIMEOUT_MS`, 120s by default. A crashed control plane fails one action, never the session. - **No secret leaves the engine.** The request carries the same sanitized view the audit log records — one redaction implementation, not two that drift. - **The destructive list is deliberately short.** A prompt that cries wolf gets clicked through without reading, which is worse than no prompt at all. Found while testing end to end, both now guarded: - The `approval` field existed in the module but was never parsed by the config loader. Every unit test passed because they built the config object directly. Only driving the real MCP server caught it. - A Unix socket path over 104 bytes fails `bind()` with **EADDRINUSE on a path where nothing is listening** — an hour of confusion. `isControlPlaneListening` now checks the length and says what is wrong. ## Done: the control plane ```bash ssh-manager control # prints a tokenised localhost URL, runs in the foreground ``` Seven screens: **your servers** (add, edit, delete — the vault behind a form), **what is waiting for you**, **server health**, **what your agents are doing right now**, **what they did**, **a real shell**, and **options**. No SFTP browser, and the terminal is deliberately the sixth tab rather than the first: a control plane that *opens* on a terminal is just a late SSH client, and that market has an incumbent with nine months' head start. The order says what the product is for — you come here to see what the agent is doing, and the keyboard is there for when watching is not enough. Not an Electron app, and **no new dependency**: Node's `http` and `net` plus one HTML file. It therefore runs anywhere the engine runs, including on a server reached through the tunnels this project already manages, and it can be wrapped in a desktop shell later without rewriting anything. ### The token is not decoration This process approves root shell commands, and an unauthenticated HTTP server on localhost is reachable by every process on the machine **and by any web page the user has open** — a page can POST to 127.0.0.1. Without a secret, a visited website could approve an agent's `rm -rf`. Hence, all tested: - a random token on every request, compared in constant time; - the `Host` header must be a loopback literal, which is what stops DNS rebinding (a hostile domain resolving to 127.0.0.1); - the listener binds `127.0.0.1`, never `0.0.0.0`; - the page is served `no-store` under a CSP of `default-src 'none'`, and loads nothing from the network. ### Managing servers from the page The vault is editable from the browser, not only the CLI — both drive the same `SecretStore`, so they cannot disagree about what is stored. - **A secret never travels to the page.** Listing returns `hasPassword: true`, never the value. The form cannot display one, so it does not ask for one back: editing a port keeps the stored password rather than wiping it. - **Deleting takes two clicks** on the same button, not a `confirm()` dialog — a browser modal freezes the automation this page is tested with, and the second click is enough friction. The armed state lasts 10 seconds, long enough to actually read which row it belongs to. - Names are validated server-side (`[a-z0-9_]+`), because a name is the vault key and a bad one is a second entry rather than an error. ### Behaviours that matter - **Closing the control plane refuses what is pending** rather than leaving agents to hit their own timeouts. - **Deciding twice returns 409** instead of writing to a closed socket — two browser tabs, two clicks. - **The timeline follows the audit log**, so it shows actions that never needed approval, and survives a malformed line. - The engine giving up first removes the entry, so the UI never offers a decision nobody is waiting for. Found by the test: an audit file that is empty when the control plane starts had its offset left unset, so every later line was skipped as history. ## Done: Homebrew ```bash brew tap bvisible/mcp-ssh-manager https://github.com/bvisible/mcp-ssh-manager brew install ssh-manager ``` The formula installs the **same npm package**, so `brew` and `npm install -g` give identical binaries. There is no separate desktop build to keep in step: the vault, the approval broker and the control plane all live in the engine. It sits in this repository rather than a separate tap, so it is updated in the same commit as the release that changes it — and the release workflow rewrites its `url` and `sha256` automatically. A formula pinning a stale version is worse than no formula at all: `brew install` would quietly hand people the previous release. Its `test do` block does a real MCP stdio handshake rather than checking `--version`, because a formula that only proves the binary exists proves nothing about whether the package works. > A short `brew install bvisible/tap/ssh-manager` would need a separate > `bvisible/homebrew-tap` repository. Worth doing if the formula gets traction; > not worth a second repository to maintain before then. ## Done: the desktop app ```bash ./desktop/build.sh # produces desktop/build/SSH Manager.app ``` A real window: dock icon, double-click, no terminal. It starts `ssh-manager control` as a child process, reads the tokenised URL from its output, and shows that page in a `WKWebView`. **Not Electron.** What has to be displayed is one HTML page the engine already serves over localhost; Electron's runtime alone is 19 MB before any application code, and a packaged app is well past a hundred. This bundle is **100 KB** and ships no browser of its own — one Swift file, `swiftc`, and a hand-assembled bundle, so there is no Xcode project and no package manager in the way. The trade-off is honest: **macOS only**. Elsewhere `ssh-manager control` opens the same interface in the browser. A Windows and Linux shell would need a different toolkit, and is not worth building before the app proves useful. Details that matter more than they look: - **A GUI app launched from Finder does not inherit your shell's PATH**, so `node` and `ssh-manager` are invisible to it. The app searches the usual install locations and, failing that, asks your login shell — which is how it finds anything nvm, asdf or volta set up. - **`SSH_MANAGER_CLI` overrides which CLI is launched.** Found the hard way: this machine had an older global install that predated the `control` command, so the app dutifully started the wrong binary. - **Quitting kills the child.** It holds the approval socket; leaving it running would keep agents blocked on a UI nobody can see. ## Done: watching the agent work A fourth screen — **Live** — showing what agents are running while they run it, output included. This is the thing no command line can offer, and the reason to have a window at all. ``` prod tail -f /var/log/app/deploy.log running [08:14:04] step 14/14 — deploying release 2026.08.29 warning: 2 stale releases left on disk ``` **The scrollback idea comes from TransHub's PtyService** — a bounded circular buffer per stream, so a window opened mid-command shows what came before rather than starting blank. Same author, relicensed here under MIT with the rest of the engine. Two rules the module may never break, both tested: - **Nobody watching costs nothing.** No socket → `openStream()` returns null, every call site optional-chains it away, and the command runs exactly as it did before. One `stat()` per command is the entire overhead. - **A watcher can never break or slow a command.** Fire-and-forget writes, a subscriber that throws is contained, and the control plane vanishing mid-command does not throw into the execution path. A **second socket**, next to the approval one: approval is a request/response that blocks a command, streaming is a one-way firehose. Sharing one socket would let a slow reader of the firehose delay a decision. ### What was deliberately not here, and then was This section used to say: no PTY, no xterm.js — a PTY is a different code path and xterm.js is a dependency and a bundle. Half of that was wrong, and worth recording rather than quietly deleting. **The PTY was never a dependency.** `ssh2` allocates the remote pseudo-terminal itself: `client.shell({ term: 'xterm-256color', cols, rows })` asks the far side for a terminal, which is what makes colours, `top`, `vim`, Ctrl-C and resizing work. Nothing is compiled, nothing is installed. The native module people associate with the word — `node-pty` — is for spawning a *local* shell. **Which the desktop application now does**, and that is where node-pty lives: in `desktop/electron`, never in the engine. It ships N-API prebuilds, so even there nothing is compiled — Electron loads them as they are. The engine's dependency list is still what it was, and an npm install still needs no compiler; it simply has no local shell, and the interface asks before offering one. The boundary is a function, `setLocalShellProvider`, which is also how it is tested without the module. **xterm.js was a real cost**, and it is the one we paid: 477 KB, vendored under `vendor/xterm/` with its MIT licence, loaded only by the control plane. The engine's dependency list is unchanged. ## Done: server health A fifth screen. Press the button, get CPU, memory, disk and uptime per machine, with a gauge that turns amber past 80% and red past 90%. **Nothing is probed in the background.** Each probe is an SSH handshake, and a control plane that connects to every production box on a timer is worse than no dashboard: it is a machine quietly opening sessions nobody asked for. The button is the whole scheduling policy. Almost none of this was new code — `buildComprehensiveHealthCheckCommand()` and `parseComprehensiveHealthCheck()` already existed for the `ssh_health_check` tool. The control plane opens its own connection (it holds the vault, so it has the credentials) and closes it immediately after. Two things the tests pinned down: - **Unreachable is a result, not an error.** It returns HTTP 200 with the reason and how long it took, because "prod did not answer" is exactly what an operator opened the screen to find out. - **Probes run in parallel**, asserted by comparing two servers against one. A dashboard over ten machines would otherwise take ten timeouts. And one real fix the test forced: `readyTimeout` was hard-coded at 60 seconds, so checking two unreachable servers took a full minute. Callers can now shorten it, and the probe uses 8 seconds — a machine that has not answered by then is unreachable as far as a screen is concerned. ## Done: the options screen Groups and known host keys, both of which live in files this process can read. **Forgetting a host key** is the one action here, and it earns its place: when a machine is rebuilt its host key changes, every connection then fails, and the fix is deleting a line from `~/.ssh/known_hosts` identified by a number in an error message. Two clicks, like deleting a server — silencing a machine-in-the-middle warning should not be one slip. ### Tunnels, and how they got here `tunnel-manager.js` keeps open tunnels in a `Map` inside the MCP server's process, which the control plane cannot see. The fix is a published state file: the engine writes `~/.ssh-manager/tunnels.json` whenever a tunnel opens or closes, and the control plane reads it. **The file carries the writing process's pid**, and a reader checks that pid is alive before believing the contents. Without it, an engine that crashed would leave a file claiming ports are forwarded when nothing is listening — telling an operator a tunnel is open when it is not is worse than showing no tunnels at all. A stale file is reported as stale, never rendered as open. Publishing is best-effort and swallows its own errors: it is a convenience for a window, and must never take down a tunnel that is working. No file is written at all when there are no tunnels — an empty file and a missing one mean the same thing, and removing it stops a dead pid lingering on disk. ### A security bug found while wiring it `removeHostKey()` ran `ssh-keygen -R "${hostEntry}"` **through a shell**, with `host` coming from a server config — which an operator, or the control plane's own form, can set to anything. Same class as the three advisories fixed on 2026-08-28, in a file that fix never touched. Now `execFileSync` with arguments passed directly, and guarded in the injection test. It also always returned `true`: `ssh-keygen -R` succeeds whether or not the host was there, so the control plane would have told an operator it forgot a key that is still in the file. It now checks first and answers honestly. ## Done: skills Three, shipped with the npm package, covering what an agent cannot infer from a tool description because it is judgement rather than syntax: | Skill | Fires on | |---|---| | `ssh-operations` | deploying, backing up, restarting, running commands | | `ssh-incident` | "the server is down", "the site is slow" | | `ssh-restricted` | a tool was refused — security modes and approval | They are short on purpose. A skill that reads like a manual gets skimmed, which defeats writing it; each says the few things that change what an agent does — look before you change, back up before you overwrite, read the log before restarting, and treat a refusal as the system working rather than an obstacle to route around. `ssh-restricted` is the one that matters most for this project: it tells an agent not to retry a blocked action through `ssh_execute`, not to hop to a less constrained server, and not to ask the operator to turn the mode off. Working around a control someone deliberately configured is worse than failing the task, because they will believe it held. Guarded by `npm run test:skills`. Prose type-checks against nothing, so the test does it: front matter loadable and matching the directory, descriptions that say *when* rather than *what*, **every `ssh_*` tool named actually registered** (the failure being a skill sending an agent at a renamed tool), and a length ceiling so they do not grow into manuals. ## Done: the interactive terminal The Live screen answers *what is it doing*. It does not answer *let me fix this myself*. The Terminal screen does: pick a server, open a shell, type. ``` POST /api/terminal open a shell → { id } GET /api/terminal/stream output, SSE, base64 POST /api/terminal/input keystrokes, base64 POST /api/terminal/resize cols/rows → SSH window-change DELETE /api/terminal close and release the connection ``` Output is base64 on the way out and keystrokes base64 on the way in, because terminal traffic is **bytes, not text**: escape sequences and half-delivered UTF-8 do not survive a round trip through a JSON string. **Not subject to readonly/restricted mode.** Those modes exist to constrain an *agent*. Whoever holds the control-plane token is the operator who configured them and already holds the credentials; stopping them here would be theatre, and theatre in a security feature is worse than nothing because it gets believed. ### What driving it found that reading it would not - **Output printed before anyone subscribed was lost** — which is exactly the login banner and the first prompt, so the screen opened blank. Now a bounded 64 KB backlog, replayed on subscribe. - **The `` and `