forked from vhaudiquet/rhema-together
A sandbox behind NAT could not reach the room. A reverse target dials a tunnel-only sshd on the server, forwards localhost:22 to a loopback port, and the worker connects there. The server assigns the port and writes one authorized_keys line per tunnel target. The key carries permitlisten for that port; the sshd allows remote forwarding only, with no shell or local forwarding. The tunnel private key is shown once and never stored; rotating it rewrites the file. The target list and setup dialog carry the command, and the docs include the sshd config and sidecar requirements.
277 lines
12 KiB
Markdown
277 lines
12 KiB
Markdown
# rhema-together
|
|
|
|
A shared room where people and a [Rhema](../rhema) coding agent work on
|
|
the same code. One conversation, one workspace, one agent; the people
|
|
and the agent see the same sandbox.
|
|
|
|
The room is a browser workspace:
|
|
|
|
- **Chat** with the room and with `@rhema`. Human messages carry their
|
|
author's name; the agent speaks through a `message` tool so that its
|
|
private reasoning never leaks into the room.
|
|
- **Preview** iframe for a dev server or a static build, set from the
|
|
chat by the agent's `preview` tool.
|
|
- **Files** pane: the tree, a read-only file view, `git status`, and
|
|
`git diff`.
|
|
- **Terminal**: a real PTY in the sandbox, same target and key as the
|
|
agent, rendered with xterm.js.
|
|
- **Presence**: who is online, who is typing.
|
|
|
|
Accounts own rooms, plans, and providers. Friends join by a single-use
|
|
magic link and a display name; joining a room is the trust boundary, and
|
|
members can run commands in the room's sandbox. Use a dedicated machine
|
|
or account for a sandbox.
|
|
|
|
## What is here
|
|
|
|
```
|
|
src/ the Axum server (Rust)
|
|
web/ the Nuxt 4 client (Vue, no SSR)
|
|
specs/ the design document
|
|
AGENTS.md working conventions
|
|
```
|
|
|
|
The server serves the built client, so production is one process and
|
|
one SQLite file.
|
|
|
|
## Build
|
|
|
|
Requirements: Rust 1.98+, Node 22+, pnpm, and an SSH server reachable
|
|
from the machine that runs rhema-together.
|
|
|
|
```sh
|
|
cargo build --release
|
|
cd web && pnpm install && pnpm build && cd ..
|
|
```
|
|
|
|
The client lands in `web/.output/public`; that is `TOGETHER_WEB_DIR`.
|
|
|
|
## Run
|
|
|
|
```sh
|
|
TOGETHER_LISTEN=127.0.0.1:7800 \
|
|
TOGETHER_PUBLIC_URL=http://localhost:7800 \
|
|
TOGETHER_PREVIEW_ORIGIN=http://preview.localhost:7800 \
|
|
./target/release/rhema-together
|
|
```
|
|
|
|
Open <http://localhost:7800>. The first visit sends you to `/setup` to
|
|
create the first account. The server log also prints a one-time setup
|
|
link, in case someone already opened the app before the database
|
|
existed.
|
|
|
|
For a local-network test, bind `0.0.0.0:7800` and set
|
|
`TOGETHER_PUBLIC_URL` to the machine's LAN address, for example
|
|
`http://10.4.1.222:7800`. Invite links and cookies then use that
|
|
address. Preview hosts need a name that resolves from the other device;
|
|
`TOGETHER_PREVIEW_ORIGIN=http://preview.10.4.1.222.nip.io:7800` works
|
|
when the network can reach a public DNS resolver.
|
|
|
|
During client development, run `pnpm dev` in `web/` (port 3000) and
|
|
keep the server on port 7800; the Nuxt dev proxy forwards `/api`,
|
|
including the terminal WebSocket.
|
|
|
|
## Deploy
|
|
|
|
The repository builds a self-contained image. The Dockerfile clones the
|
|
Rhema framework at the tag it names, builds the client and server, and
|
|
runs the result as UID 10001 with a writable `/data` volume.
|
|
|
|
```sh
|
|
docker build -t registry.example.com/rhema-together:0.1.0 .
|
|
docker run --rm -p 7800:7800 -v together-data:/data \
|
|
-e TOGETHER_PUBLIC_URL=https://together.example.com \
|
|
-e TOGETHER_ALLOW_REGISTRATION=false \
|
|
-e TOGETHER_PREVIEW_ORIGIN=https://preview.together.example.com \
|
|
registry.example.com/rhema-together:0.1.0
|
|
```
|
|
|
|
For Kubernetes, the chart in `deploy/helm/rhema-together` adds the
|
|
deployment, service, ingress, and persistent volume. It also documents
|
|
the wildcard DNS, wildcard TLS certificate, proxy buffering, and body
|
|
size the app needs. Read that README before exposing the service.
|
|
|
|
CI publishes the image and chart to the home Gitea registry on every
|
|
push to `main`; a `v*` tag publishes the exact version. The chart
|
|
repository is
|
|
`https://git.vhaudiquet.fr/api/packages/vhaudiquet/helm`.
|
|
|
|
The preview host is a signed subdomain, so the ingress must route all
|
|
of `*.preview.<your-domain>` to the same service. The app does not
|
|
issue certificates.
|
|
|
|
## First room
|
|
|
|
1. **Settings → Providers.** Add a provider kind and its key, address,
|
|
or sign-in. For GitHub Copilot, ChatGPT, and Mistral Vibe the dialog
|
|
runs the provider's sign-in. The credential is sealed with the
|
|
server's master key before it touches SQLite. A new provider stores
|
|
no model; the room picks one.
|
|
2. **Settings → Sandboxes.** Add a target. Leave the private key empty
|
|
and the server generates an ed25519 pair and shows the public key.
|
|
Append that line to `~/.ssh/authorized_keys` on the target. Set the
|
|
workspace root to a directory the ssh user can write (for a normal
|
|
user, `/home/<name>`; the default is `/root`). Test the target; a
|
|
green check means ssh works. For a machine behind NAT, choose
|
|
**Reverse SSH** instead; see below.
|
|
3. **New room.** Pick the target and provider, give the workspace
|
|
directory (for example `/home/me/rooms/demo`), and optionally a git
|
|
URL. The workspace is created on the first mention and seeded from
|
|
the repository or a README. The Model field opens the provider's
|
|
model list with context, output, price, and vision. Pick a row, or
|
|
type an id the list does not carry.
|
|
4. **Invite.** The room's invite dialog creates a single-use link such
|
|
as `https://together.example.com/join/<token>`. A friend opens it,
|
|
picks a display name, and lands in the room as a guest.
|
|
5. Say `@rhema start a small Vite app on port 5173`, then open the
|
|
Preview pane on 5173.
|
|
|
|
The agent always runs with the room's sandbox, and every command is an
|
|
ordinary ssh command. There is no approval prompt: the sandbox is the
|
|
boundary.
|
|
|
|
## Reverse SSH
|
|
|
|
A machine behind NAT can dial the server instead of accepting a
|
|
connection. This is the fallback for an account that will not install a
|
|
connector; the server still speaks ssh to the sandbox.
|
|
|
|
Reverse SSH needs a tunnel-only sshd in the app's network namespace.
|
|
`deploy/tunnel` has a config and the setup steps. The app writes the
|
|
sshd's `authorized_keys` file: one key per target, restricted to the
|
|
target's loopback port with `permitlisten`, no shell, no local
|
|
forwarding, and no non-loopback bind.
|
|
|
|
In **Settings → Sandboxes**, choose **Reverse SSH**. The server assigns
|
|
the loopback port. Save the tunnel private key shown once as
|
|
`rhema-tunnel-<target-id>` and run `chmod 600` on it. Add the target's
|
|
public key to the sandbox's `~/.ssh/authorized_keys`, then run the
|
|
command from the target's **Setup** dialog:
|
|
|
|
```sh
|
|
autossh -M 0 -N -R 127.0.0.1:22000:localhost:22 -p 2222 \
|
|
tunnel@together.example.com -i ./rhema-tunnel-<target-id> \
|
|
-o ExitOnForwardFailure=yes -o ServerAliveInterval=30
|
|
```
|
|
|
|
The sandbox needs an sshd on `localhost:22`. The tunnel key is a
|
|
credential; rotating it invalidates the old key. The tunnel sshd is
|
|
internet-facing, so patch it and rate-limit it.
|
|
|
|
## Preview
|
|
|
|
The preview shows one target per room. It is either a port inside the
|
|
sandbox, or a static HTML file or folder read over ssh and served by the
|
|
app. The agent sets it with the `preview` tool, and the choice is stored
|
|
with the room, so a later visitor sees the same target.
|
|
|
|
A static target does not start a process. Point it at a build folder
|
|
(`dist`, `web/.output/public`) or a single HTML file. The app reads files
|
|
over the same ssh target the agent uses, refuses `..` and dotfiles, and
|
|
stops at 16 MiB per file. Point it at a build folder rather than the
|
|
repository root unless the whole tree is meant to be public.
|
|
|
|
The preview host is a signed subdomain of `TOGETHER_PREVIEW_ORIGIN`:
|
|
|
|
```
|
|
http://preview.localhost:7800 local development
|
|
https://preview.together.example.com production
|
|
```
|
|
|
|
A port is served from
|
|
`<scheme>://r<room>-p<port>-<expiry>-<hmac>.<preview host>/`.
|
|
A static target is served from
|
|
`<scheme>://r<room>-s<hash>-<expiry>-<hmac>.<preview host>/`, where
|
|
`hash` covers the target's root and entry file. A link minted for one
|
|
static target stops working when the preview moves. The HMAC covers the
|
|
target and expiry and is derived from the server's master key, so a room
|
|
id alone is not enough to reach a preview. The address expires after 24
|
|
hours; loading the pane mints a new one. DNS must resolve every subdomain
|
|
of the preview host to the server (a wildcard `*.preview` record), and
|
|
TLS must cover the wildcard. A copied preview URL works for anyone who
|
|
has it until it expires; treat it as a read capability for that target.
|
|
|
|
For a port, the proxy forwards ordinary HTTP through an ssh
|
|
`direct-tcpip` channel to `127.0.0.1:<port>` inside the sandbox. For a
|
|
static target, each request runs one short read over ssh. WebSocket
|
|
upgrades (Vite HMR) are not forwarded in v1; reload the pane after an
|
|
edit, and disable HMR for the preview when a dev server insists on it.
|
|
|
|
### Caddy
|
|
|
|
```
|
|
together.example.com {
|
|
reverse_proxy 127.0.0.1:7800
|
|
}
|
|
*.preview.example.com {
|
|
tls {
|
|
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
|
|
}
|
|
reverse_proxy 127.0.0.1:7800
|
|
}
|
|
```
|
|
|
|
Set `TOGETHER_PUBLIC_URL=https://together.example.com` and
|
|
`TOGETHER_PREVIEW_ORIGIN=https://preview.example.com`. Cookies become
|
|
`Secure` automatically from the public URL.
|
|
|
|
## Configuration
|
|
|
|
Every field can be set in the YAML file (`TOGETHER_CONFIG`, default
|
|
`config.yaml` when present) or overridden by an environment variable.
|
|
|
|
| variable | default | meaning |
|
|
|---|---|---|
|
|
| `TOGETHER_LISTEN` | `127.0.0.1:7800` | bind address |
|
|
| `TOGETHER_PUBLIC_URL` | `http://localhost:7800` | browser origin; invite links and cookies |
|
|
| `TOGETHER_PREVIEW_ORIGIN` | `http://preview.localhost:7800` | wildcard parent for previews; empty disables them |
|
|
| `TOGETHER_DATABASE` | `data/together.db` | SQLite file |
|
|
| `TOGETHER_SECRET_KEY_FILE` | `data/secret.key` | 32-byte master key (created, mode 0600) |
|
|
| `TOGETHER_WEB_DIR` | `web/.output/public` | built client |
|
|
| `TOGETHER_MAX_TURN_STEPS` | `48` | step cap per turn |
|
|
| `TOGETHER_ALLOW_REGISTRATION` | `false` | whether `/register` works |
|
|
| `TOGETHER_ALLOW_PRIVATE_TARGETS` | `false` | whether a direct sandbox target may use a loopback or private address |
|
|
| `TOGETHER_TUNNEL_AUTHORIZED_KEYS` | `data/tunnel/authorized_keys` | file the tunnel sshd reads; the app writes it |
|
|
| `TOGETHER_TUNNEL_SSH_HOST` | host from `TOGETHER_PUBLIC_URL` | host shown in the reverse ssh command |
|
|
| `TOGETHER_TUNNEL_SSH_PORT` | `2222` | tunnel sshd port |
|
|
| `TOGETHER_TUNNEL_USER` | `tunnel` | account the tunnel sshd accepts |
|
|
| `TOGETHER_TUNNEL_PORT_START` | `22000` | first loopback port assigned to a reverse target |
|
|
| `TOGETHER_TUNNEL_PORT_END` | `22999` | last loopback port assigned to a reverse target |
|
|
|
|
## Security model
|
|
|
|
- The sandbox is remote and the target's account is the boundary. Give
|
|
the room a dedicated user/machine.
|
|
- Provider keys and ssh private keys are encrypted with
|
|
ChaCha20-Poly1305 under the master key. No API returns them.
|
|
- Session cookies are `HttpOnly`; CSRF is a double-submit cookie for
|
|
mutating calls.
|
|
- Guests can chat, interrupt, use the terminal, and read files. Only
|
|
full accounts create rooms, providers, and targets.
|
|
- Registration is closed by default; setup and invite links work
|
|
without it. A full account can make the server open an SSH connection
|
|
to a host it names, so open signup also makes the server reachable
|
|
from anywhere as a port scanner. Turn it on only when you trust
|
|
everyone who can reach `/register`.
|
|
- A preview host is a signed capability for one room and one target,
|
|
either a port or a static tree. It expires after 24 hours, and preview
|
|
responses carry `Referrer-Policy: no-referrer`. A copied URL works
|
|
until it expires.
|
|
- Removing a member or archiving a room ends that account's event feed,
|
|
presence socket, and terminal within a few seconds. The terminal and
|
|
preview proxy pin the SSH host key on first login and refuse a
|
|
changed key.
|
|
- Preview URLs are signed capabilities, not authenticated pages.
|
|
- The app sets a CSP that frames only `*.<preview host>`, and refuses
|
|
to frame itself elsewhere.
|
|
- The server must be reachable by the friends you invite. The default
|
|
bind is loopback; put a TLS reverse proxy in front.
|
|
|
|
## Roadmap
|
|
|
|
The spec's `§12. Phases` lists the path from this v1: ecrou live
|
|
sandboxes, multiple checkouts in the UI, port discovery, HMR, terminal
|
|
scrollback on reconnect, editor cursors, and co-editing. `HostAgent::step`
|
|
in the framework is the one upstream change still deferred; until then
|
|
steering is turn-level, the same pattern as `rhema-code`.
|