Files
roast-room/app/server.mjs
T
Nate HerkandClaude Opus 5.5 8891669056 Rebrand to Roast Room; add waiting card, guide, and verdict PDF
- /founder-council is now /roast-room (skill folder, README, CLAUDE.md, package name)
- Room shows a waiting card between rounds: round, elapsed time, what each
  advisor is weighing, and a nudge to check Claude Code after 4 minutes
- Idle side panel is a getting-started guide: steps, what to put in your
  question, and a copyable example
- Download PDF on the verdict and in Past sessions: a two-page branded report
  built in the browser (vendored jsPDF, Montserrat subset), nothing to install
- .claude/settings.json pre-allows writes to sessions/ and the quote check,
  so a council runs without a stream of permission prompts
- Quote check falls back to searching the brains when Python is missing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 19:56:37 -05:00

79 lines
4.4 KiB
JavaScript

import http from "node:http";
import fs from "node:fs";
import path from "node:path";
import { APP_ROOT, env } from "./lib/env.mjs";
import { SEATS } from "./lib/seats.mjs";
import { startCouncil, getSession, subscribe, listSaved, loadSaved, MODELS } from "./lib/council.mjs";
import { usage } from "./lib/anthropic.mjs";
import * as watch from "./lib/watch.mjs";
const PORT = Number(process.env.PORT) || 4730;
const PUBLIC = path.join(APP_ROOT, "public");
const TYPES = { ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8", ".svg": "image/svg+xml", ".png": "image/png", ".webp": "image/webp", ".ico": "image/x-icon", ".json": "application/json", ".ttf": "font/ttf", ".txt": "text/plain; charset=utf-8" };
let running = null; // one council at a time (API runner)
// "viewer" (default): the room plays councils that /roast-room runs in Claude Code.
// "api": the room can also run councils itself on ANTHROPIC_API_KEY (COUNCIL_RUNNER=api in .env).
const RUNNER = (process.env.COUNCIL_RUNNER || env("COUNCIL_RUNNER") || "viewer").toLowerCase() === "api" ? "api" : "viewer";
watch.startWatching();
function send(res, code, body, type = "application/json") {
res.writeHead(code, { "content-type": type, "cache-control": "no-store" });
res.end(typeof body === "string" ? body : JSON.stringify(body));
}
async function readJson(req) {
let raw = "";
for await (const c of req) { raw += c; if (raw.length > 1e5) throw new Error("body too large"); }
return raw ? JSON.parse(raw) : {};
}
const server = http.createServer(async (req, res) => {
const url = new URL(req.url, `http://${req.headers.host}`);
const p = url.pathname;
try {
if (p === "/api/seats") return send(res, 200, { seats: SEATS, models: MODELS, runner: RUNNER, hasKey: Boolean(env("ANTHROPIC_API_KEY")) });
if (p === "/api/usage") return send(res, 200, usage);
if (p === "/api/council" && req.method === "POST") {
if (RUNNER !== "api") return send(res, 403, { error: "This room is a viewer. Run /roast-room in Claude Code, or set COUNCIL_RUNNER=api in .env." });
if (running && getSession(running)?.status === "running") return send(res, 409, { error: "A council is already in session. Wait for its verdict." });
const { prompt, mode } = await readJson(req);
if (!prompt || prompt.trim().length < 10) return send(res, 400, { error: "Give the council a real decision (at least a sentence)." });
const s = startCouncil(prompt.trim().slice(0, 4000), mode === "quick" ? "quick" : "full");
running = s.id;
return send(res, 200, { id: s.id });
}
if (p.startsWith("/api/stream/")) {
const id = decodeURIComponent(p.split("/").pop());
const s = getSession(id) || watch.getLive(id);
if (!s) return send(res, 404, { error: "no such session" });
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", connection: "keep-alive" });
res.write(": connected\n\n");
const ping = setInterval(() => res.write(": ping\n\n"), 15000);
res.on("close", () => clearInterval(ping));
return subscribe(s, res);
}
if (p === "/api/sessions") {
const all = [...listSaved(), ...watch.listLive()].sort((a, b) => (a.id < b.id ? 1 : -1));
const apiRunning = running && getSession(running)?.status === "running" ? running : null;
return send(res, 200, { sessions: all, running: apiRunning, live: watch.runningId() });
}
if (p.startsWith("/api/sessions/")) {
const id = decodeURIComponent(p.split("/").pop());
const x = watch.getLive(id);
const j = loadSaved(id) || (x && { id, title: x.title, mode: x.mode, status: x.status, events: x.events });
return j ? send(res, 200, j) : send(res, 404, { error: "not found" });
}
// static
const file = path.normalize(path.join(PUBLIC, p === "/" ? "index.html" : p));
if (!file.startsWith(PUBLIC) || !fs.existsSync(file) || fs.statSync(file).isDirectory()) return send(res, 404, "Not found", "text/plain");
res.writeHead(200, { "content-type": TYPES[path.extname(file)] || "application/octet-stream", "cache-control": "no-store" });
fs.createReadStream(file).pipe(res);
} catch (e) {
send(res, 500, { error: String(e.message || e) });
}
});
server.listen(PORT, "127.0.0.1", () => console.log(`Roast Room on http://localhost:${PORT} (${RUNNER === "api" ? "viewer + API runner" : "viewer: run /roast-room in Claude Code"})`));