Add repository: - New remote verb `add-repo KEY OWNER/NAME`. Off unless config.toml has [repo_add] (base_url + owners). Only listed owners; the dev box builds the URL itself, checks it with `git ls-remote` (bot access), then appends to [repos] under the lock. No URL crosses the SSH link. - `repos` also reports where adding is allowed, so the page shows the form only when it's on and rejects other hosts before calling SSH. - set_toml_string inserts after the section's last key, not after trailing blank lines / the next section's comments. Responsiveness: - web/static/app.js (progressive enhancement; every form still works without JS): forms go via fetch and get a JSON answer instead of POST-redirect-GET; buttons/cards show the change immediately; the list refreshes itself (15 s, 3 s while something is starting). - `repos` is cached for 5 min (refreshed on add-repo), so a page view is one SSH call instead of two. - `list` reads all unit states with one `systemctl show` instead of one per session: 676 -> 374 ms on the dev box with 21 sessions. - Static assets are content-hashed and cached immutably. Design: slate greys, hairline borders, black primary action, tinted status badges, monospace repo/branch, two columns on desktop, stacked on phones, light and dark. Docs: README security model, AGENTS.md (JS convention, add-repo invariant), config.example.toml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MCUMXh8zZConC75Mptbeou
3.7 KiB
3.7 KiB
AGENTS.md — sessions
A remote session manager: a web page on prod that starts Claude Code sessions on the dev box through one locked-down SSH key. Read the README's "Security model" before changing anything that touches the SSH boundary.
Layout
dev/runs on the dev box:sessions_ctl.py(installed as~/.local/bin/sessions-ctl), systemd user units,install.sh.web/runs on prod in a rootless Podman container:app.py,Containerfile.compose.yamlat the root is what prod's panel deploys. Configured only through env vars;sessions-ctl keygenprints them.
Stack and conventions
- Python ≥ 3.11, standard library only on both sides. No pip install, so there's no supply chain to audit. Keep it that way unless there's a strong reason.
- The web page works without JavaScript: plain forms, POST, then a
redirect.
web/static/app.jsis progressive enhancement on top (fetch + JSON answers, self-refreshing list). Keep it that way: one same-origin script, no inline script or handlers (the CSP forbids them), no third-party code, never insert server data as HTML except the same-origin page itself. Static files are served with a content-hash?v=and cached immutably. sessions-ctlprints exactly one JSON object (exceptkeygen: KEY=VALUE lines on stdout, human note on stderr); exit 0/1/2.- The web app has no login: Authelia (Caddy forward_auth) in front of it is the login. It must keep refusing requests without the auth header, and refusing cross-site POSTs.
- The dev port for local work on the web app is 8470, bound to 127.0.0.1.
Preview via
ssh -p 14922 -L 8470:localhost:8470 <dev box>.
Invariants — do not break
- Nothing received over SSH reaches a shell or Claude. No "initial prompt"
feature, no free-text arguments. The session title (
TITLE_RE: letters, digits,-, single spaces) is the only argument with a space; it becomes claude's--nameviashlex.joinand nothing else. New remote verbs need validation and a test indev/tests/test_sessions_ctl.py. Validate withfullmatch:re.match(...$)accepts a trailing newline. - The web app reaches the dev box over one multiplexed SSH connection. The
dev box's UFW
limitrefuses a 6th connection in 30 s, so don't dropControlMaster, and keepinit: trueso the master gets reaped. - Local-only verbs (
delete,refresh-access,keygen,_launch) stay out ofREMOTE_VERBS.add-repois remote but stays off unless[repo_add]is configured, takesOWNER/NAME(never a URL), accepts only listed owners, and checks the repo withgit ls-remotebefore writing config. - The private key is never written to disk on the dev box outside a temp dir
in
XDG_RUNTIME_DIR(RAM), whichkeygenremoves. refresh-accessnever writes an emptyfrom=, and never touches lines other than the one ending insessions-manager.- The session unit keeps
DBUS_SESSION_BUS_ADDRESSpointed at nothing. Otherwise tmux moves claude into its owntmux-spawn-*.scopeand it escapesMemoryMaxand clean stops (checked 2026-09-30 with tmux 3.6). - The container publishes to
127.0.0.1only.
Test
python3 -m unittest discover -s dev/tests
python3 -m unittest discover -s web/tests
To test end to end on the dev box, add a throwaway key with
from="127.0.0.1",restrict,command=".../sessions-ctl --remote" … sessions-selftest,
run the container with --network host, SESSIONS_DEV_HOST=127.0.0.1 and the
key as SESSIONS_SSH_KEY_B64, send requests with a Remote-User header, then
remove the key line again. Never run the real keygen from an agent session:
its output is a private key and would end up in the transcript.