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-onlyapp/src/lib/gates.ts
1// Customer activation gates. Pass/fail is computed from live checks and recorded test evidence, never from typed attestations.2// Controlled activation: even when every gate passes, customers are admitted only for ORGANIZATIONS the platform owner explicitly lists (no public registration).3import fs from "node:fs";4import path from "node:path";5import { db, getSetting, setSetting, asSystem } from "./db";6import { verifyAudit } from "./audit";7const EV = path.resolve(process.cwd(), "../design/verification");8const ev = (name: string) => { try { const j = JSON.parse(fs.readFileSync(path.join(EV, name + ".json"), "utf8")); const total = Number(j.total ?? (Number(j.passed) + Number(j.failed ?? 0))); const failed = j.failed !== undefined ? Number(j.failed) : total - Number(j.passed); const when = j.finished ?? j.at ?? ""; const age = Date.now() - Date.parse(when); return { ok: failed === 0 && Number(j.passed) > 0 && age < 30 * 86400_000, passed: Number(j.passed), failed, total, finished: when as string | null, scope: j.scope as string | undefined }; } catch { return { ok: false, passed: 0, failed: -1, total: 0, finished: null as string | null, scope: undefined }; } };9export const emergencyStopped = async () => (await getSetting("emergency_stop", "0")) === "1";10export async function activationOrgs(): Promise<string[]> { try { const a = JSON.parse(await getSetting("security.activation_orgs", "[]")); return Array.isArray(a) ? a.filter((x: unknown) => typeof x === "string") : []; } catch { return []; } }11export const setActivationOrgs = (ids: string[]) => setSetting("security.activation_orgs", JSON.stringify([...new Set(ids)]));12export type Gate = { id: string; title: string; pass: boolean; detail: string; evidence?: string };13export async function gateReport(): Promise<{ gates: Gate[]; allPass: boolean }> {14 const t = ev("trusted-https"), ti = ev("tenant-isolation"), rls = ev("rls"), ow = ev("owner-auth"), g = ev("gates"), df = ev("deploy-flow");15 const rlsLive = await asSystem(async () => Number((await db().prepare("SELECT COUNT(*) n FROM pg_class WHERE relname IN ('projects','node_jobs','app_deployments','app_releases','domains','nodes','instances') AND relrowsecurity").get() as any).n));16 const caps = await asSystem(async () => await db().prepare("SELECT COUNT(*) n FROM organizations WHERE ai_monthly_cap_usd<=0 OR max_apps<=0 OR max_deploys_per_day<=0").get() as any); const au = await verifyAudit();17 const gates: Gate[] = [18 { id: "trusted-https", title: "Trusted HTTPS", pass: t.ok, detail: t.ok ? `${t.passed} checks passed` : "no passing trusted-HTTPS evidence", evidence: "trusted-https.json" },19 { id: "rls", title: "PostgreSQL RLS", pass: rls.ok && rlsLive === 7, detail: `${rlsLive}/7 key tables enforce RLS; suite ${rls.passed}/${rls.total}`, evidence: "rls.json" },20 { id: "tenant-isolation", title: "Tenant and resource isolation", pass: ti.ok, detail: `${ti.passed} checks`, evidence: "tenant-isolation.json" },21 { id: "spending", title: "Tenant spending and quota limits", pass: g.ok && Number(caps.n) === 0, detail: Number(caps.n) === 0 ? "every organization has AI-spend, app and daily-deploy limits; enforcement tested" : `${caps.n} organizations without limits`, evidence: "gates.json" },22 { id: "job-isolation", title: "Job execution isolation (per-node, per-tenant, serialized)", pass: g.ok && df.ok, detail: "one active job per node; payloads bound to node+org; forged/foreign jobs refused", evidence: "gates.json" },23 { id: "emergency-stop", title: "Emergency stop enforced", pass: g.ok, detail: "engaged stop blocks deployments, domain changes and job delivery", evidence: "gates.json" },24 { id: "secrets", title: "Secure credential handling (encrypted at rest, scrubbed from jobs, redacted from logs/audit)", pass: g.ok, detail: "tested", evidence: "gates.json" },25 { id: "agent-auth", title: "Agent authorization", pass: ti.ok && df.ok && g.ok, detail: "tenant-bound enrollment, per-node credential, rotation, revocation", evidence: "deploy-flow.json" },26 { id: "auth-session", title: "Authentication and session security", pass: ow.ok, detail: `${ow.passed} checks`, evidence: "owner-auth.json" },27 { id: "audit", title: "Audit integrity (hash chain verified live)", pass: au.ok, detail: `${au.count} entries${au.ok ? "" : `, broken at ${au.brokenAt}`}` },28 ];29 return { gates, allPass: gates.every(x => x.pass) };30}31/** Is this organization admitted? dev-override admits all (test hook); otherwise trusted-TLS mode requires an explicit allowlist entry. */32export async function orgAdmitted(orgId: string): Promise<boolean> {33 if ((await getSetting("security.dev_customer_ops", "0")) === "1") return true;34 if ((await getSetting("security.trusted_tls", "0")) !== "1") return false;35 return (await activationOrgs()).includes(orgId);36}37export async function userAdmitted(userId: string): Promise<boolean> {38 const rows = await asSystem(() => db().prepare("SELECT org_id FROM memberships WHERE user_id=?").all(userId)) as { org_id: string }[];39 for (const r of rows) if (await orgAdmitted(r.org_id)) return true; return false;40}41
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 1c27633 on master.
Approval requests
None pending.