Files
rhema-together/README.md
T

175 lines
6.7 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 running inside the sandbox.
- **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.89+, 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.
## 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 host is a signed subdomain of `TOGETHER_PREVIEW_ORIGIN`:
```
http://preview.localhost:7800 local development
https://preview.together.example.com production
```
Each preview is served from
`<scheme>://r<room>-p<port>-<hmac>.<preview host>/`. The HMAC covers the
room and port and is derived from the server's master key, so a room id
alone is not enough to reach a preview. 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; treat it as a read capability for that port.
The proxy forwards ordinary HTTP through an ssh `direct-tcpip` channel
to `127.0.0.1:<port>` inside the sandbox. WebSocket upgrades (Vite HMR)
are not forwarded in v1; reload the pane after an edit.
### 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` | `true` | 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.
- 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`.