Files
rhema-together/README.md
T
vhaudiquet 36de0aace7 feat: add static previews to the room pane
The preview tool could only name a port, so a static build needed a
server the terminal had to keep alive. `preview` now accepts a path:
the app reads the file or folder over the room's ssh sandbox and serves
it from a signed host, with `..` and dotfiles refused and a 16 MiB cap.

The target is stored with the room and replayed as a durable event. The
pane shows a static path with a reload control and keeps the port field
as a local fallback.
2026-11-28 11:24:57 +01:00

231 lines
9.5 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.
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, model, and key. Keys
are sealed with the server's master key before they touch SQLite.
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.
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.
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.
## 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 |
## 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`.