Skip to content
  1. Home
  2. workspace
Checking…
Demo view — sanitized data only. Sign in over HTTPS to create projects and manage the workspace.

AI Engineering Workspace

Partial

Chat, 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-only

app/src/lib/metrics.ts

1import fs from "node:fs";
2import os from "node:os";
3
4export type Sample = { t: number; cpu: number; mem: number; rx: number; tx: number };
5const g = globalThis as unknown as { __zcsHist?: Sample[]; __zcsTimer?: NodeJS.Timeout; __zcsPrev?: any };
6
7function readCpu(): { idle: number; total: number } {
8 const l = fs.readFileSync("/proc/stat", "utf8").split("\n")[0].split(/\s+/).slice(1).map(Number);
9 const idle = l[3] + (l[4] || 0);
10 return { idle, total: l.reduce((a, b) => a + b, 0) };
11}
12function readNet(): { rx: number; tx: number } {
13 let rx = 0, tx = 0;
14 for (const line of fs.readFileSync("/proc/net/dev", "utf8").split("\n").slice(2)) {
15 const [name, rest] = line.split(":");
16 if (!rest || name.trim() === "lo") continue;
17 const f = rest.trim().split(/\s+/).map(Number);
18 rx += f[0]; tx += f[8];
19 }
20 return { rx, tx };
21}
22function memInfo() {
23 const m: Record<string, number> = {};
24 for (const l of fs.readFileSync("/proc/meminfo", "utf8").split("\n")) {
25 const [k, v] = l.split(":"); if (v) m[k] = parseInt(v) * 1024;
26 }
27 return { total: m.MemTotal, avail: m.MemAvailable, used: m.MemTotal - m.MemAvailable };
28}
29
30function sample() {
31 const c = readCpu(), n = readNet(), p = g.__zcsPrev, t = Date.now();
32 if (p) {
33 const dt = Math.max((t - p.t) / 1000, 0.001);
34 const cpu = 100 * (1 - (c.idle - p.c.idle) / Math.max(c.total - p.c.total, 1));
35 const mi = memInfo();
36 (g.__zcsHist ||= []).push({ t, cpu: Math.max(0, Math.min(100, cpu)), mem: (100 * mi.used) / mi.total,
37 rx: Math.max(0, (n.rx - p.n.rx) / dt), tx: Math.max(0, (n.tx - p.n.tx) / dt) });
38 if (g.__zcsHist.length > 90) g.__zcsHist.shift();
39 }
40 g.__zcsPrev = { t, c, n };
41}
42
43function ensureSampler() {
44 if (g.__zcsTimer) return;
45 sample();
46 g.__zcsTimer = setInterval(sample, 2000);
47 g.__zcsTimer.unref?.();
48}
49
50/** Listening TCP ports, read from /proc (no shell, no privileges). */
51function listeningPorts(): number[] {
52 const out = new Set<number>();
53 for (const f of ["/proc/net/tcp", "/proc/net/tcp6"]) {
54 try {
55 for (const l of fs.readFileSync(f, "utf8").split("\n").slice(1)) {
56 const c = l.trim().split(/\s+/);
57 if (c[3] === "0A") out.add(parseInt(c[1].split(":")[1], 16));
58 }
59 } catch {}
60 }
61 return [...out].sort((a, b) => a - b);
62}
63
64export function snapshot() {
65 ensureSampler();
66 const hist = g.__zcsHist || [];
67 const last = hist[hist.length - 1];
68 const mi = memInfo();
69 const st = fs.statfsSync("/");
70 const disk = { total: st.blocks * st.bsize, free: st.bavail * st.bsize };
71 return {
72 ts: Date.now(),
73 host: { os: (fs.readFileSync("/etc/os-release", "utf8").match(/PRETTY_NAME="(.+)"/) || [])[1] || os.type(),
74 kernel: os.release(), cpus: os.cpus().length, uptimeSec: Math.round(os.uptime()), load: os.loadavg() },
75 cpu: last?.cpu ?? 0,
76 mem: { ...mi, pct: (100 * mi.used) / mi.total },
77 disk: { ...disk, pct: (100 * (disk.total - disk.free)) / disk.total },
78 net: { rx: last?.rx ?? 0, tx: last?.tx ?? 0 },
79 ports: listeningPorts(),
80 history: hist.slice(-60),
81 };
82}
83export type Snapshot = ReturnType<typeof snapshot>;
84

Conversation

Partial
Sign in to start AI sessions.

Task checklist

  • Application shell deployed
  • Persistent projects
  • Agent runtime
  • Sandboxed terminal

Execution activity

No agent sessions. Git HEAD 1c27633 on master.

Approval requests

None pending.