AI Engineering Workspace
PartialChat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.
Project files
read-onlyscripts/edge.mjs
1// Edge proxy (user-space; no root for :80/:443). :8080 plain HTTP (read-only demo) and :8443 TLS -> app on 127.0.0.1:3000.2// It OVERWRITES x-zcs-proto so the app can trust it: sign-in and all writes are honoured only when proto === "https".3import http from "node:http"; import https from "node:https"; import tls from "node:tls"; import crypto from "node:crypto"; import fs from "node:fs"; import os from "node:os"; import path from "node:path";4const UP = { host: "127.0.0.1", port: Number(process.env.APP_PORT || 3000) };5let trustedSni = () => false; // set once TLS is up: true only when the SNI-selected certificate is the publicly trusted, unexpired one6const dir = path.join(os.homedir(), ".config/zoo-cloud-studio/tls");7function handler(proto) {8 return (req, res) => {9 const headers = { ...req.headers };10 for (const k of Object.keys(headers)) if (k.toLowerCase().startsWith("x-zcs-") || k.toLowerCase() === "x-forwarded-for") delete headers[k];11 headers["x-zcs-proto"] = proto; headers["x-zcs-sni"] = proto === "https" ? String(req.socket.servername || "").toLowerCase() : ""; headers["x-zcs-cert"] = proto === "https" && trustedSni(req.socket.servername) ? "trusted" : "selfsigned"; headers["x-forwarded-for"] = req.socket.remoteAddress || "";12 const up = http.request({ ...UP, method: req.method, path: req.url, headers }, r => { res.writeHead(r.statusCode || 502, r.headers); r.pipe(res); });13 up.on("error", () => { if (!res.headersSent) res.writeHead(502, { "content-type": "text/plain" }); res.end("upstream unavailable"); });14 req.on("aborted", () => up.destroy()); res.on("close", () => up.destroy());15 req.pipe(up);16 };17}18http.createServer(handler("http")).listen(Number(process.env.HTTP_PORT || 8080), "0.0.0.0", () => console.log("edge http up"));19try {20 // Default certificate = the self-signed preview pair. If a publicly trusted pair exists (issued by scripts/acme-dns01.mjs) it is served for its DNS names via SNI21 // and re-read when the file changes (renewals need no restart). IP-address access keeps the self-signed certificate.22 const def = tls.createSecureContext({ key: fs.readFileSync(path.join(dir, "key.pem")), cert: fs.readFileSync(path.join(dir, "cert.pem")) });23 const tdir = path.join(dir, "trusted"); let tctx = null, tm = 0, names = [], validTo = 0;24 const loadTrusted = () => { try { const m = fs.statSync(path.join(tdir, "fullchain.pem")).mtimeMs; if (m === tm) return; tm = m; tctx = tls.createSecureContext({ key: fs.readFileSync(path.join(tdir, "key.pem")), cert: fs.readFileSync(path.join(tdir, "fullchain.pem")) }); names = fs.readFileSync(path.join(tdir, "names.txt"), "utf8").split(/\s+/).filter(Boolean); validTo = Date.parse(new crypto.X509Certificate(fs.readFileSync(path.join(tdir, "fullchain.pem"))).validTo); console.log("edge: trusted certificate loaded for", names.join(",")); } catch { tctx = null; names = []; validTo = 0; } };25 trustedSni = sn => { loadTrusted(); return !!tctx && validTo > Date.now() && names.includes(String(sn || "").toLowerCase()); };26 loadTrusted();27 const opts = { SNICallback: (sn, cb) => { loadTrusted(); cb(null, tctx && names.includes(String(sn).toLowerCase()) ? tctx : def); }, key: fs.readFileSync(path.join(dir, "key.pem")), cert: fs.readFileSync(path.join(dir, "cert.pem")), minVersion: "TLSv1.2" };28 https.createServer(opts, handler("https")).listen(Number(process.env.HTTPS_PORT || 8443), "0.0.0.0", () => console.log("edge https up"));29} catch (e) { console.error("TLS disabled:", e.message); }30
Conversation
PartialSign in to start AI sessions.
Task checklist
- Application shell deployed
- Persistent projects
- Agent runtime
- Sandboxed terminal
Execution activity
No agent sessions. Git HEAD 692573d on master.
Approval requests
None pending.