pi-collab #
A small terminal-based chat where multiple people can talk in a shared room, and an AI assistant joins the conversation. Access is gated by atproto login, identity is your DID, and every turn of work is committed to git — the session JSONL in the repo is the conversation record.
How it works #
oauth/is the atproto OAuth sidecar — the only process that holds a user's credential.gate.mjsis the auth gate: atproto login happens here, and it mints chat tokens that the terminal client uses.server.mjsbridges a WebSocket chat room to a shared agent session. Joining requires a valid chat token; the sender's DID is the identifier (the chat shows their handle or an optional nick).client.mjsis a TUI client built on@earendil-works/pi-tuithat renders the chat and the assistant's (markdown) replies.- The agent runs on the pi backend (
backends/pi.mjs): a@earendil-works/pi-coding-agentprocess in RPC mode. Its session is written as JSONL intodata/pi/sessions/inside the repo — that file is the conversation record. watch.mjswatches that JSONL and commits each turn to git: when the agent edits files, the turn closes and the whole tree (code + growing JSONL) is committed. Chat-only turns close on idle so nothing is lost.sandbox/runs the agent in a container with no direct internet — egress goes through the GreenPT proxy (proxy/), which holds the API key host-side. The pi agent package is baked into the image; the server bridges to it overdocker exec -i(stdio RPC).
The stack (all components) #
member terminal ─login─▶ gate.mjs (atproto login — the only way in)
│ mints a chat token (/auth/shell)
▼
ws:// server.mjs ──► pi agent (RPC, JSONL → data/pi/sessions/)
│ │
│ ▼
│ greenpt-proxy ──► api.greenpt.ai
▼
watch.mjs ──► git commit per turn (code + session JSONL)
Getting started #
One command starts the whole stack — proxy, sandboxed agent, oauth, gate, server, watch — with joint logging into data/dev.log:
./dev.sh # kill ports 8000/8443/4098, build/start containers, run everything
./dev.sh stop # kill host processes + containers
./dev.sh logs # show the joint log (data/dev.log)
./dev.sh tail # follow it
Needs GREENPT_API_KEY in your shell (the proxy injects it host-side; the sandbox never sees it).
On first run a sandbox SSH keypair is generated into sandbox/.club_ed25519(.pub) (or set CLUB_SSH_PUBKEY to your real key). Then:
ssh -i sandbox/.club_ed25519 -p 2223 agent@127.0.0.1 # shell into the sandbox
zed ssh://agent@127.0.0.1:2223 # or open it in Zed
Then log in and chat:
npm run client # shows your handle (or the nick from --nick)
npm run client -- --nick johan
On first run the client prints a link. Open http://127.0.0.1:8443/auth/shell in a browser, log in with your atproto handle, copy the token it shows, paste it back — it is cached in ~/.config/pi-collab/token.
Then log in and chat:
npm run client # shows your handle (or the nick from --nick)
npm run client -- --nick johan
On first run the client prints a link. Open http://127.0.0.1:8443/auth/shell in a browser, log in with your atproto handle, copy the token it shows, paste it back — it is cached in ~/.config/pi-collab/token.
Web client #
The bridge also serves a web chat client on the same port, so there is no extra process to run:
open http://localhost:8000/ # the room, in your browser
It renders the same room with the same look as the TUI — same markdown theme
(client.mjs → web/index.html, using the same marked parser as the TUI), same
[handle] time headers, tool lines, thinking indicator, and user list.
Signing in is a normal atproto login: type your handle, get sent to your own
server, and come back to the room. The gate mints a chat token from the resulting
session cookie. The page normalizes itself to 127.0.0.1 (localhost:8000
redirects) because the OAuth callback — and with it the session cookie — lives on
127.0.0.1:8443, and localhost and 127.0.0.1 are different sites for cookies.
An optional nick is shown in the room. If you already have a chat token (e.g. for
the terminal), "have a chat token instead?" still accepts it.
The page is a single self-contained web/index.html plus a vendored marked.min.js
in web/vendor/. Point it anywhere with WEB_DIR=<path> if you'd rather serve it
from a CDN or your own static host.
Identity #
- DID is the identifier. The agent sees
[did:plc:…]prefixes in the session record; turn commits carry the author DID. This is stable — handles can change. - Handle or nick is display only. The chat shows each sender's atproto handle, or their
--nickif given. /whoamishows your DID, handle, and nick.
Turn recording (the git thing) #
A turn is a work unit: the exchanges since the last commit are buffered, and when the agent edits files the turn closes — the working tree (code + the growing session JSONL) is committed. The JSONL file IS the conversation record; git history IS the record of the work.
node watch.mjs --dry-run # preview
node watch.mjs --author-did did:plc:xyz # explicit turn author (DID)
Sessions live in <repo>/data/pi/sessions/ (the pi backend writes there via --session-dir). The watcher follows the active session file; if more sessions appear later it picks up the newest one for the session id. State lives in .club-state.json (gitignored).
The stack #
./dev.sh brings up every component:
pi-proxy— GreenPT egress proxy + SSH forward (127.0.0.1:2223 → pi-sandbox:22). The only container on both networks; it holds the API key host-side.pi-sandbox— the agent in a container: read-only rootfs, caps dropped, internal network only, no git installed (versioning is done host-side bywatch.mjs;.gitis shadow-mounted read-only out of the sandbox). sshd on :22 so you can log in (or open it in Zed) asagent.- oauth / gate / server / watch run as host processes with joint logging into
data/dev.log; the server reaches the agent overdocker exec -i.
The sandbox mounts this repo at /workspace; watch.mjs runs on the host and commits turns from the same tree. .git, data/auth and data/oauth are shadow-mounted out of the sandbox.
Configuration #
| Setting | Env var | Default |
|---|---|---|
| Bridge port | PORT |
8000 |
| Backend | BACKEND |
pi (or opencode) |
| Web client dir | WEB_DIR |
web |
| Room name | ROOM |
shared |
| PI provider | PI_PROVIDER |
greenpt |
| PI model | PI_MODEL |
deepseek-v4-flash-0731 |
| PI session id | PI_SESSION_ID |
pi-collab |
| PI session dir | PI_SESSION_DIR |
data/pi/sessions |
| Sandbox the agent | PI_SANDBOX |
1 = via docker exec -i pi-sandbox |
| Sandbox container | PI_SANDBOX_CONTAINER |
pi-sandbox |
| SSH port | SSH_PORT (dev.sh) |
2223 |
| SSH pubkey | CLUB_SSH_PUBKEY |
generated into sandbox/.club_ed25519 |
| Chat token file | CHAT_TOKENS |
data/chat/tokens.json |
| Gate port | PORT (gate.mjs) |
8443 |
| OAuth URL | OAUTH_URL |
http://127.0.0.1:4098 |
| Client gate | PI_GATE |
http://127.0.0.1:8443 |
| Client token file | PI_TOKEN_FILE |
~/.config/pi-collab/token |
Controls #
- Type and press Enter to send a message.
- Press
Ctrl+C(orCtrl+D) to quit.
Commands #
/new— start a fresh shared session/compact— compact the session context/model <id>— switch model/users— who's online/whoami— your DID, handle, and nick/help— this list
test marker: edit timestamp 2026-09-03 (workspace pick-up check)