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/nexus-core.mjs
1// Zoo Nexus CLIENT contract (pure, testable). Zloud is a Nexus client only: it never hosts or duplicates Nexus.2// No Nexus API is documented to this project and https://nexus.zoobd.com is only a PROPOSED endpoint, so nothing here is sent anywhere: this module builds,3// validates and signs task envelopes so the adapter is ready once the real contract and a least-privilege credential exist.4import crypto from "node:crypto";5import { FORBIDDEN_KEY } from "./central-core.mjs";6export const NEXUS_SCHEMA = "zoo.nexus.task/v1";7export const PROPOSED_ENDPOINT = "https://nexus.zoobd.com";8export const OPERATIONS = ["agent.register", "capabilities.discover", "task.request", "task.status", "result.submit", "approval.request", "events.subscribe", "health.check"];9export const SCOPES = ["nexus:register", "nexus:capabilities:read", "nexus:task:write", "nexus:task:read", "nexus:result:write", "nexus:approval:write", "nexus:events:read", "nexus:health:read"];10export const OP_SCOPE = Object.fromEntries(OPERATIONS.map((o, i) => [o, SCOPES[i]]));11export const NEVER_SENT = ["customer secrets and provider API keys", "private project files and source code", "AI conversations and prompts", "terminal contents", "node credentials and enrollment tokens", "SSH access to the Zoo IAM server (never requested, never granted)"];12const ID = /^[A-Za-z0-9_.:-]{1,80}$/;13const MAX_DEADLINE_MS = 24 * 3600 * 1000;14/** Canonical JSON (sorted keys) so a signature is stable across implementations. */15export const canonical = v => Array.isArray(v) ? `[${v.map(canonical).join(",")}]` : v && typeof v === "object" ? `{${Object.keys(v).sort().map(k => JSON.stringify(k) + ":" + canonical(v[k])).join(",")}}` : JSON.stringify(v);16function scanParams(p, depth = 0) {17 if (depth > 3) throw new Error("params too deeply nested");18 if (p === null || ["boolean", "number"].includes(typeof p)) return;19 if (typeof p === "string") { if (!ID.test(p)) throw new Error("params values must be short identifiers, never free text"); return; }20 if (Array.isArray(p)) { if (p.length > 20) throw new Error("params list too long"); p.forEach(x => scanParams(x, depth + 1)); return; }21 if (typeof p === "object") { for (const [k, v] of Object.entries(p)) { if (FORBIDDEN_KEY.test(k)) throw new Error(`forbidden params field ${k}`); scanParams(v, depth + 1); } return; }22 throw new Error("unsupported params value");23}24/** Builds an unsigned task envelope. Params are identifiers only (no free text); deadlines are bounded; every task carries correlation + idempotency ids. */25export function buildEnvelope({ operation, appId, orgRef, params = {}, correlationId, idempotencyKey, deadlineMs = 300000, scopes, now = Date.now() }) {26 if (!OPERATIONS.includes(operation)) throw new Error("unknown operation");27 const need = OP_SCOPE[operation]; const granted = scopes ?? [need];28 if (!granted.includes(need)) throw new Error(`missing scope ${need}`);29 if (!ID.test(appId ?? "")) throw new Error("invalid appId");30 if (orgRef != null && !ID.test(orgRef)) throw new Error("invalid orgRef");31 if (!(deadlineMs > 0 && deadlineMs <= MAX_DEADLINE_MS)) throw new Error("deadline must be 1ms..24h");32 scanParams(params);33 const c = correlationId ?? "cor_" + crypto.randomBytes(12).toString("hex"); const i = idempotencyKey ?? "idem_" + crypto.randomBytes(12).toString("hex");34 if (!ID.test(c) || !ID.test(i)) throw new Error("invalid correlation or idempotency id");35 return { schema: NEXUS_SCHEMA, operation, scope: need, appId, orgRef: orgRef ?? null, params, correlationId: c, idempotencyKey: i, issuedAt: new Date(now).toISOString(), deadline: new Date(now + deadlineMs).toISOString() };36}37export function validateEnvelope(env, { now = Date.now(), seenIdempotency } = {}) {38 if (env?.schema !== NEXUS_SCHEMA) throw new Error("wrong schema");39 if (!OPERATIONS.includes(env.operation) || OP_SCOPE[env.operation] !== env.scope) throw new Error("operation/scope mismatch");40 if (!ID.test(env.correlationId ?? "") || !ID.test(env.idempotencyKey ?? "")) throw new Error("missing correlation or idempotency id");41 if (!(Date.parse(env.deadline) > now)) throw new Error("deadline passed");42 if (Date.parse(env.deadline) - Date.parse(env.issuedAt) > MAX_DEADLINE_MS) throw new Error("deadline too far");43 scanParams(env.params ?? {});44 if (seenIdempotency?.has(env.idempotencyKey)) throw new Error("replayed idempotency key");45 return true;46}47/** Ed25519 detached signature over the canonical envelope. The key is a Nexus-issued least-privilege credential; none exists yet. */48export const signEnvelope = (env, privateKeyPem) => crypto.sign(null, Buffer.from(canonical(env)), privateKeyPem).toString("base64url");49export const verifyEnvelope = (env, sig, publicKeyPem) => { try { return crypto.verify(null, Buffer.from(canonical(env)), publicKeyPem, Buffer.from(sig, "base64url")); } catch { return false; } };50/** MCP-compatible tool descriptors (tools/list shape). Descriptive only: no MCP transport is started. */51export const mcpTools = () => OPERATIONS.map(o => ({ name: "zloud." + o.replace(".", "_"), description: `Zloud → Nexus: ${o} (identifier-only parameters, scope ${OP_SCOPE[o]})`, inputSchema: { type: "object", additionalProperties: false, properties: { orgRef: { type: "string", pattern: ID.source }, params: { type: "object" }, deadlineMs: { type: "integer", minimum: 1, maximum: MAX_DEADLINE_MS } } } }));52
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 0eebc42 on master.
Approval requests
None pending.