Something went wrong. Try again.
Something went wrong. Try again.
coding_club dev.sh
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177#!/usr/bin/env bash# One command for the whole stack, sandboxed by default:## ./dev.sh # kill ports, build/start proxy + sandbox, run oauth/# # gate/server/watch with joint logging into data/dev.log# ./dev.sh stop # kill everything (host procs + containers)# ./dev.sh logs # show the joint log# ./dev.sh tail # follow it## The agent runs inside the pi-sandbox container (internal network, no git,# egress only via greenpt-proxy), reached by the server over `docker exec -i`.# SSH into it for Zed with the generated key:## ssh -i sandbox/.club_ed25519 -p 2223 agent@127.0.0.1## Env:# GREENPT_API_KEY the proxy injects it host-side (required)# CLUB_SSH_PUBKEY your real ssh pubkey; else a keypair is generated into# sandbox/.club_ed25519(.pub) on first run# CLUB_AUTHOR_DID DID recorded on turn commitsset -euo pipefailROOT="$(cd "$(dirname "$0")" && pwd)"
PORTS=(8000 8443 4098)LOG="$ROOT/data/dev.log"SSH_PORT=2223SSH_KEY="$ROOT/sandbox/.club_ed25519"
# ---- stop -------------------------------------------------------------------
kill_port() { local port="$1" local pids pids=$(ss -tlnp 2>/dev/null | grep ":$port " | sed -n 's/.*pid=\([0-9]*\).*/\1/p' | sort -u || true) if [ -n "$pids" ]; then echo " port $port -> killing $pids" # shellcheck disable=SC2086 kill $pids 2>/dev/null || true else echo " port $port -> free" fi}
stop() { echo "== stopping pi-collab ==" for port in "${PORTS[@]}"; do kill_port "$port" done if pgrep -f "[w]atch.mjs" >/dev/null 2>&1; then echo " watch.mjs -> killing $(pgrep -f '[w]atch.mjs')" pkill -f "[w]atch.mjs" 2>/dev/null || true fi docker rm -f pi-sandbox >/dev/null 2>&1 || true docker rm -f pi-proxy >/dev/null 2>&1 || true sleep 1}
# ---- ssh key ----------------------------------------------------------------
ensure_key() { if [ -z "${CLUB_SSH_PUBKEY:-}" ]; then if [ -f "$SSH_KEY.pub" ]; then CLUB_SSH_PUBKEY="$(cat "$SSH_KEY.pub")" else ssh-keygen -q -t ed25519 -f "$SSH_KEY" -N "" -C "pi-collab" CLUB_SSH_PUBKEY="$(cat "$SSH_KEY.pub")" echo "== generated sandbox ssh key: $SSH_KEY ==" fi fi}
# ---- containers -------------------------------------------------------------
containers_up() { echo "== networks ==" docker network create club-ext 2>/dev/null || true docker network create --internal club-int 2>/dev/null || true
echo "== proxy (egress + ssh forward) ==" docker build -q -t pi-proxy "$ROOT/proxy" >/dev/null docker rm -f pi-proxy >/dev/null 2>&1 || true docker run -d \ --name pi-proxy \ --network club-ext \ --network club-int \ -p "127.0.0.1:${SSH_PORT}:2222" \ -e GREENPT_API_KEY="${GREENPT_API_KEY:?GREENPT_API_KEY must be set}" \ -e IMPACT_LOG=/data/impact.jsonl \ -e SSH_FORWARD_TARGET=pi-sandbox \ -v "$ROOT/data:/data" \ pi-proxy >/dev/null echo " proxy up (ssh :$SSH_PORT -> pi-sandbox:22)"
echo "== sandbox (internal network only) ==" ensure_key docker build -q -t pi-sandbox "$ROOT/sandbox" >/dev/null docker rm -f pi-sandbox >/dev/null 2>&1 || true docker run -d --rm \ --name pi-sandbox \ --network club-int \ --read-only \ --cap-drop ALL \ --cap-add CHOWN \ --cap-add SETUID \ --cap-add SETGID \ --cap-add DAC_OVERRIDE \ --cap-add SYS_CHROOT \ --cap-add AUDIT_WRITE \ --security-opt no-new-privileges \ --pids-limit 256 \ --memory 2g \ -e CLUB_SSH_PUBKEY="$CLUB_SSH_PUBKEY" \ -e XDG_DATA_HOME=/home/agent \ -v club_tmp:/tmp \ -v "$ROOT/data/ssh-hostkeys:/etc/club/ssh-hostkeys" \ --tmpfs /run:rw,size=32m,nodev,nosuid \ --tmpfs /home/agent:rw,size=512m,nodev,nosuid,uid=1000,gid=1000,mode=0700 \ -v "$ROOT:/workspace" \ -v club_shadow_git:/workspace/.git:ro \ -v club_shadow_auth:/workspace/data/auth:ro \ -v club_shadow_oauth:/workspace/data/oauth:ro \ pi-sandbox >/dev/null echo " sandbox up (agent, sshd on :22)"}
containers_down() { docker rm -f pi-sandbox pi-proxy >/dev/null 2>&1 || true}
# ---- start ------------------------------------------------------------------
start() { echo "== starting pi-collab ==" mkdir -p "$ROOT/data" "$ROOT/data/pi/sessions" "$ROOT/data/chat" : > "$LOG"
# A cached chat token is useless across server restarts unless the gate # re-minted it; drop it so the client prompts for a fresh login. local token_file="${PI_TOKEN_FILE:-$HOME/.config/pi-collab/token}" if [ -f "$token_file" ]; then rm -f "$token_file" echo " cleared cached chat token ($token_file) — the client will ask you to log in" fi
containers_up
run() { local tag="$1"; shift local envs=() while [[ "$1" == ENV=* ]]; do envs+=("${1#ENV=}"); shift; done ( exec env "${envs[@]}" node "$@" >>"$LOG" 2>&1 ) & echo " started $tag (pid $!)" }
run oauth "$ROOT/oauth/server.mjs" sleep 0.3 run gate "$ROOT/gate.mjs" run server ENV=PI_SANDBOX=1 "$ROOT/server.mjs" run watch "$ROOT/watch.mjs" --repo "$ROOT" --session-dir "$ROOT/data/pi/sessions" --interval 3
sleep 1 echo echo "pi-collab is up (agent sandboxed):" echo " atproto login: http://127.0.0.1:8443/login" echo " websocket bridge: ws://127.0.0.1:8000" echo " chat: node client.mjs [--nick yourname]" echo " ssh (zed): ssh -i sandbox/.club_ed25519 -p $SSH_PORT agent@127.0.0.1" echo " joint log: tail -f $LOG"}
case "${1:-start}" in stop) stop; containers_down ;; tail) exec tail -f "$LOG" ;; logs) cat "$LOG" ;; start|restart) stop; start ;; *) echo "usage: $0 [start|restart|stop|tail|logs]" >&2; exit 1 ;;esac