Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

raea cloud's boxes are stamped and managed: box.sh up stamps every build (BUILD.json: an id from the packed files, the commit, whether the tree was dirty and which files; the tarball kept in ~/.config/raea-cloud/builds so RAEA_CLOUD_BUILD=ID makes another box from exactly it), waits for a box's running agents to finish before rebuilding it (RAEA_BOX_FORCE=1 to cut them off), and promote/list put a box into raea cloud's list (POST /v1/admin/boxes). The box's health says its build and how many agents run. setup.sh installs raea's skills by raea's own agent names (claude-acp had never matched: no box had them), and each client's socket links them into its own config folders. (box.sh's hunks also carry the games lane's raea-games tarball put, which sat beside them.) 11-25, Shane: "make sure this mix up of boxes and versions are all managed effectively"

shinyobjectz6fb27ef9e890
diff --git a/sdk/cloud/deploy/sprites/box.sh b/sdk/cloud/deploy/sprites/box.sh
index 3b4278b6..90e95951 100755
--- a/sdk/cloud/deploy/sprites/box.sh
+++ b/sdk/cloud/deploy/sprites/box.sh
@@ -8,6 +8,10 @@
# box is set up by too), and its server started
# deploy/sprites/box.sh status NAME its URL, raea, the server's health
# deploy/sprites/box.sh token NAME its RAEA_CLOUD_TOKEN, for the TypeScript client
+# deploy/sprites/box.sh promote NAME the box into raea cloud's list of boxes, at the top: the one work runs on
+# (POST /v1/admin/boxes; its health must answer). A box below it takes over
+# by itself when it stops answering, so a box is never swapped by editing secrets
+# deploy/sprites/box.sh list raea cloud's boxes in order, each one's health and build
# deploy/sprites/box.sh key NAME a raea agent key (repos and storage scopes) from stdin, or the clipboard, onto
# the box as RAEA_AGENT_KEY: its agents clone raea projects (raea-repo clone OWNER
# PROJECT DIR, deploy/git/repo.sh), push, and send renders' media by hash (CR22, CR23)
@@ -15,12 +19,14 @@
# RAEA_VERSION (0.1.6) and AGENTS ("kimi-code claude-acp") pick what goes on, and RAEA_CLOUD_REF takes sdk/cloud from
# raea's public repo at that commit instead of this working tree; the farm comes from
# ~/.config/raea-cloud/farm.env (RAEA_CLOUD_GPU_URL, RAEA_CLOUD_GPU_TOKEN). The Sprite's URL stays private to the org.
+# Game kits need ~/.config/raea-cloud/games/raea-games-linux-x86_64.tgz (raea-decompose and unity-rs built for Linux,
+# checked against its .sha256 beside it); without it the box can fetch builds but not take them apart.
set -euo pipefail
# the org raea owns, never another business's (org.sh)
. "$(dirname "$0")/org.sh"
NAME=${2:-}
-[ -n "$NAME" ] || { echo "box: name the Sprite"; exit 2; }
+[ -n "$NAME" ] || [ "${1:-}" = list ] || { echo "box: name the Sprite"; exit 2; }
RAEA_VERSION=${RAEA_VERSION:-0.1.6}
AGENTS=${AGENTS:-kimi-code claude-acp antigravity-acp}
HERE=$(cd "$(dirname "$0")/../.." && pwd)
@@ -38,13 +44,49 @@ up)
sprite list -o "$ORG" | grep -qx "$NAME" || sprite create -o "$ORG" --skip-console --label raea --label raea-cloud "$NAME"
# sdk/cloud's files from this working tree; with RAEA_CLOUD_REF set, setup.sh takes them from raea's public repo at
# that commit instead, as a bot's box does
- if [ -z "${RAEA_CLOUD_REF:-}" ]; then
+ # Every build is stamped (BUILD.json on the box, shown in its health): the commit, and from a working tree whether it
+ # was dirty, which files, and an id from the packed files themselves; the tarball is kept under
+ # ~/.config/raea-cloud/builds/ID.tgz, so a box can be made again from exactly what another one runs (RAEA_CLOUD_BUILD=ID)
+ builds=$HOME/.config/raea-cloud/builds
+ if [ -n "${RAEA_CLOUD_BUILD:-}" ]; then
+ [ -s "$builds/$RAEA_CLOUD_BUILD.tgz" ] || { echo "box: no build $RAEA_CLOUD_BUILD in $builds"; exit 2; }
+ put "$builds/$RAEA_CLOUD_BUILD.tgz" /tmp/raea-cloud.tgz
+ put "$builds/$RAEA_CLOUD_BUILD.json" /tmp/raea-cloud-build.json
+ elif [ -z "${RAEA_CLOUD_REF:-}" ]; then
+ mkdir -p "$builds"
pack=$(mktemp)
COPYFILE_DISABLE=1 tar -czf "$pack" --no-mac-metadata -C "$HERE" server src image deploy/git package.json package-lock.json
+ # the id: the packed files' own contents (names and bytes, not their times)
+ id=$(cd "$HERE" && find server src image deploy/git package.json package-lock.json -type f -not -name '.DS_Store' -print0 | sort -z | xargs -0 shasum -a 256 | shasum -a 256 | cut -c1-12)
+ commit=$(git -C "$HERE" rev-parse HEAD)
+ dirty=$(git -C "$HERE" status --porcelain -- . | sed 's/^...//' | tr '\n' ' ')
+ printf '{"build":"%s","commit":"%s","dirty":%s,"changed":"%s","from":"%s"}\n' "$id" "$commit" "$([ -n "$dirty" ] && echo true || echo false)" "${dirty% }" "$(hostname -s)" > "$builds/$id.json"
+ cp "$pack" "$builds/$id.tgz"
+ echo "box: build $id (commit ${commit:0:10}$([ -n "$dirty" ] && echo ", dirty: ${dirty% }"))"
put "$pack" /tmp/raea-cloud.tgz
+ put "$builds/$id.json" /tmp/raea-cloud-build.json
rm -f "${pack:?}"
fi
put "$FARM" /tmp/farm.env
+ games=${RAEA_GAMES_TGZ:-$HOME/.config/raea-cloud/games/raea-games-linux-x86_64.tgz}
+ if [ -s "$games" ]; then
+ if [ -s "$games.sha256" ] && ! shasum -a 256 -c --status "$games.sha256"; then echo "box: $games doesn't match its .sha256"; exit 1; fi
+ put "$games" /tmp/raea-games.tgz
+ fi
+ # A box with agents running isn't rebuilt under them: setup.sh restarts the server, which cuts their runs off
+ # (11-25: a StreetTalk project failed mid-run). Waits for none, a quarter of an hour at most; RAEA_BOX_FORCE=1
+ # rebuilds anyway (raea cloud then resumes the cut-off runs, projects.ts resumeRequest).
+ if [ "${RAEA_BOX_FORCE:-}" != 1 ]; then
+ for i in $(seq 1 90); do
+ n=$(x ". ~/.raea-cloud.env 2>/dev/null; curl -fsS -m 5 -H \"authorization: Bearer \$RAEA_CLOUD_TOKEN\" localhost:8080/v1/health 2>/dev/null" | python3 -c 'import json,sys
+try: print(json.load(sys.stdin).get("running", 0))
+except Exception: print(0)')
+ [ "${n:-0}" = 0 ] && break
+ [ "$i" = 90 ] && { echo "box: $NAME still has $n agents running: not rebuilt (RAEA_BOX_FORCE=1 to cut them off)"; exit 1; }
+ [ "$i" = 1 ] && echo "box: $NAME has $n agents running: waiting for them to finish"
+ sleep 10
+ done
+ fi
# the box itself, set up by the one script a bot's box is set up by too
if ! sprite exec -o "$ORG" -s "$NAME" -- bash -s -- "$NAME" "$RAEA_VERSION" "$AGENTS" "${RAEA_CLOUD_REF:-}" < "$(dirname "$0")/setup.sh" 2>&1 | quiet; then
echo "box: setup.sh failed on $NAME"; exit 1
@@ -56,6 +98,24 @@ status)
x "/opt/raea/bin/raea --version; . ~/.raea-cloud.env; curl -fsS -H \"authorization: Bearer \$RAEA_CLOUD_TOKEN\" localhost:8080/v1/health | head -c 600; echo"
;;
token) x ". ~/.raea-cloud.env; echo \$RAEA_CLOUD_TOKEN" ;;
+promote | list)
+ # raea cloud's staff key: RAEA_CLOUD_ADMIN_KEY, else the Mac's keychain (raea-cloud-prod-staff-key)
+ api=${RAEA_CLOUD_API:-https://api.raea.cloud}
+ key=${RAEA_CLOUD_ADMIN_KEY:-$(security find-generic-password -s raea-cloud-prod-staff-key -w 2> /dev/null || true)}
+ [ -n "$key" ] || { echo "box: no staff key (RAEA_CLOUD_ADMIN_KEY, or raea-cloud-prod-staff-key in the keychain)"; exit 2; }
+ if [ "$1" = promote ]; then
+ url=$(sprite url -o "$ORG" -s "$NAME" 2>&1 | sed -n 's/^URL: *//p')
+ tok=$(x ". ~/.raea-cloud.env; echo \$RAEA_CLOUD_TOKEN" | tail -1 | tr -d '[:space:]')
+ [ -n "$url" ] && [ ${#tok} -ge 32 ] || { echo "box: couldn't read $NAME's address or token"; exit 1; }
+ body=$(python3 -c 'import json,sys; print(json.dumps({"name": sys.argv[1], "url": sys.argv[2], "token": sys.argv[3], "first": True}))' "$NAME" "$url" "$tok")
+ curl -fsS -X POST -H "authorization: Bearer $key" -H 'content-type: application/json' --data-binary @- "$api/v1/admin/boxes" <<< "$body" > /dev/null || { echo "box: raea cloud refused $NAME"; exit 1; }
+ fi
+ curl -fsS -H "authorization: Bearer $key" "$api/v1/admin/boxes" | python3 -c '
+import json, sys
+for b in json.load(sys.stdin)["data"]:
+ bd = b.get("build") or {}
+ print(("* " if b["runs_work"] else " ") + b["name"].ljust(10), b["note"].ljust(22), "build", bd.get("build", "?"), "commit", str(bd.get("commit", "?"))[:10], "dirty" if bd.get("dirty") else "", "raea", bd.get("raea", "?"))'
+ ;;
key)
# never echoed: from a pipe, or the clipboard when there's none
if [ -t 0 ]; then k=$(pbpaste); else k=$(cat); fi
diff --git a/sdk/cloud/deploy/sprites/setup.sh b/sdk/cloud/deploy/sprites/setup.sh
index abbeb38d..2d6a3f5b 100644
--- a/sdk/cloud/deploy/sprites/setup.sh
+++ b/sdk/cloud/deploy/sprites/setup.sh
@@ -77,7 +77,25 @@ if [ -s /tmp/farm.env ]; then
fi
grep -q '^RAEA_CLOUD_GPU_URL=' ~/.raea-cloud.env || { echo "box: no farm (write RAEA_CLOUD_GPU_URL and RAEA_CLOUD_GPU_TOKEN to /tmp/farm.env)"; exit 2; }
umask 022
-for a in $AGENTS; do raea skills install --agent "$a" > /dev/null 2>&1 || say "raea skills for $a not installed"; done
+# raea's skills by raea's own agent names (the registry's ids aren't them: 11-25, every box had gone without), into the
+# box's home; each client's socket links them into its own config folders (server/main.ts linkSkills)
+for a in $AGENTS; do
+ case "$a" in claude-acp) s=claude ;; antigravity-acp | gemini) s=gemini ;; kimi-code | kimi) s=kimi ;; codex-acp) s=codex ;; *) continue ;; esac
+ /opt/raea/bin/raea skills install --agent "$s" > /dev/null 2>&1 || say "raea skills for $a ($s) not installed"
+done
+
+# the build, as the caller stamped it (box.sh: /tmp/raea-cloud-build.json), with what this script put on: shown on
+# GET /v1/health and raea cloud's /v1/admin/boxes, so which code a box runs is never a guess
+python3 - "$NAME" "$VERSION" "$REF" << 'PY' > /opt/raea-cloud/BUILD.json
+import json, os, sys, datetime
+b = {}
+try: b = json.load(open("/tmp/raea-cloud-build.json"))
+except Exception: pass
+if sys.argv[3]: b.setdefault("commit", sys.argv[3]); b.setdefault("build", sys.argv[3][:12]); b.setdefault("dirty", False)
+b.update(box=sys.argv[1], raea=sys.argv[2], built_at=datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="seconds"))
+print(json.dumps(b))
+PY
+rm -f /tmp/raea-cloud-build.json
# the server, as the Sprite's HTTP service on 8080: raea on lavapipe (docs/cloud.feature CL13), renders to the farm
cat > /opt/raea-cloud/image/sprite-start.sh << 'EOF'
diff --git a/sdk/cloud/server/main.ts b/sdk/cloud/server/main.ts
index ac8222c5..2292db48 100644
--- a/sdk/cloud/server/main.ts
+++ b/sdk/cloud/server/main.ts
@@ -36,7 +36,7 @@
import { execFileSync, spawn } from "node:child_process"
import { timingSafeEqual } from "node:crypto"
-import { mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs"
+import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, symlinkSync, writeFileSync } from "node:fs"
import { createServer, type IncomingMessage, type ServerResponse } from "node:http"
import path from "node:path"
import { WebSocketServer } from "ws"
@@ -72,6 +72,33 @@ const AGENT_HOMES: Record<string, string> = { CLAUDE_CONFIG_DIR: "claude", CODEX
/** a Google sign-in's token file (google-token.ts), written into the socket's GEMINI_HOME rather than handed on */
const GOOGLE_CREDENTIAL = "RAEA_GOOGLE_CREDENTIAL"
+/** the agent processes running for open sockets now (GET /v1/health running) */
+const running = new Set<unknown>()
+
+/** the box's build, as setup.sh wrote it (/opt/raea-cloud/BUILD.json); null on a box made before builds were stamped */
+function buildOf(): Record<string, unknown> | null {
+ try {
+ return JSON.parse(readFileSync(path.join(process.env.RAEA_CLOUD_ROOT ?? "/opt/raea-cloud", "BUILD.json"), "utf8"))
+ } catch {
+ return null
+ }
+}
+
+/** raea's skills, installed once in the box's own home (setup.sh), linked into a socket's own config folders: each
+ * client's agent gets its own home (AGENT_HOMES), which had left them without raea's skills (11-25) */
+const SKILL_DIRS: Record<string, string> = { CLAUDE_CONFIG_DIR: ".claude/skills", GEMINI_HOME: ".gemini/skills" }
+function linkSkills(env: Record<string, string>, home: string) {
+ for (const [k, rel] of Object.entries(SKILL_DIRS)) {
+ const from = path.join(home, rel)
+ const to = path.join(env[k], "skills")
+ try {
+ if (existsSync(from) && !existsSync(to)) symlinkSync(from, to)
+ } catch {
+ // a folder of its own already there: left alone
+ }
+ }
+}
+
/** a socket's own sign-in (its headers), or null to run on the container's environment */
export function socketEnv(headers: Record<string, string | string[] | undefined>, home = process.env.HOME ?? "/root"): Record<string, string> | null {
const raw = headers["x-raea-agent-env"]
@@ -95,6 +122,7 @@ export function socketEnv(headers: Record<string, string | string[] | undefined>
env[k] = path.join(home, ".agent-homes", name, dir)
mkdirSync(env[k], { recursive: true, mode: 0o700 })
}
+ linkSkills(env, home)
if (google) {
unpackCredential(google, env.GEMINI_HOME)
env.AGY_ACP_FORCE_FILE_STORAGE = "1"
@@ -216,12 +244,16 @@ const server = createServer(async (req, res) => {
const gpu = process.env.RAEA_CLOUD_GPU_URL
return json(res, {
raea: raeaVersion(),
+ // what deploy/sprites/box.sh put here: the build's id, the commit, whether the tree was dirty (BUILD.json)
+ build: buildOf(),
agent: def,
agents: installed().map((a) => ({ id: a.id, version: a.version })),
workspace: WORK,
device: device(childEnv()),
offload: gpu ? { url: gpu, commands: (process.env.RAEA_CLOUD_GPU_COMMANDS ?? "render").split(/\s+/).filter(Boolean) } : null,
jobs: jobs.held(),
+ // agents running now: deploy/sprites/box.sh up waits for none before it restarts this server
+ running: running.size,
})
}
if (url.pathname === "/v1/files" && (req.method === "GET" || req.method === "PUT")) return await files(req, res, url)
@@ -316,6 +348,8 @@ server.on("upgrade", (req, socket, head) => {
const env = own ? { ...withoutKeys(childEnv()), ...agent.env, ...RUN_DEFAULTS, ...own } : { ...childEnv(), ...agent.env }
wss.handleUpgrade(req, socket, head, (ws) => {
const child = spawn(agent.command, agent.args, { cwd: WORK, env, stdio: ["pipe", "pipe", "inherit"] })
+ running.add(child)
+ child.on("exit", () => running.delete(child))
let buf = ""
// ACP messages are newline-delimited JSON: split on \n only
child.stdout.setEncoding("utf8").on("data", (c: string) => {