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/design.ts
1import fs from "node:fs";2import path from "node:path";3import crypto from "node:crypto";45export const DESIGN_ROOT = path.resolve(process.env.STUDIO_DESIGN_DIR || path.join(process.cwd(), "..", "design"));6export const ALLOWED_DIRS = ["references", "prototypes", "assets", "brand", "manifests", "screenshots", "verification"] as const;7const MIME: Record<string, string> = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp",8 ".svg": "image/svg+xml", ".json": "application/json", ".md": "text/markdown; charset=utf-8", ".html": "text/html; charset=utf-8", ".txt": "text/plain; charset=utf-8" };9export const MAX_BYTES = 5 * 1024 * 1024;10export const mimeFor = (f: string) => MIME[path.extname(f).toLowerCase()];1112export type ManifestEntry = { path: string; sha256: string; bytes: number; type: string; version: number; updated: string };13const manifestPath = () => path.join(DESIGN_ROOT, "manifests", "manifest.json");1415export function readManifest(): { version: number; generated: string; files: ManifestEntry[] } {16 try { return JSON.parse(fs.readFileSync(manifestPath(), "utf8")); } catch { return { version: 0, generated: "", files: [] }; }17}1819/** Only files listed in the manifest (with matching hash) are ever served publicly. */20export function rebuildManifest() {21 const old = new Map(readManifest().files.map(f => [f.path, f]));22 const files: ManifestEntry[] = [];23 const top = ["MASTER-DESIGN.md", "design-tokens.json", "components.md"];24 const consider: string[] = top.filter(f => fs.existsSync(path.join(DESIGN_ROOT, f)));25 for (const d of ALLOWED_DIRS) {26 if (d === "manifests") continue;27 const dir = path.join(DESIGN_ROOT, d);28 if (!fs.existsSync(dir)) continue;29 for (const f of fs.readdirSync(dir)) if (fs.statSync(path.join(dir, f)).isFile() && mimeFor(f)) consider.push(`${d}/${f}`);30 }31 for (const rel of consider) {32 const buf = fs.readFileSync(path.join(DESIGN_ROOT, rel));33 const sha = crypto.createHash("sha256").update(buf).digest("hex");34 const prev = old.get(rel);35 files.push({ path: rel, sha256: sha, bytes: buf.length, type: mimeFor(rel)!, version: prev ? (prev.sha256 === sha ? prev.version : prev.version + 1) : 1,36 updated: prev && prev.sha256 === sha ? prev.updated : new Date().toISOString() });37 }38 const m = { version: (readManifest().version || 0) + 1, generated: new Date().toISOString(), files };39 fs.mkdirSync(path.join(DESIGN_ROOT, "manifests"), { recursive: true });40 fs.writeFileSync(manifestPath(), JSON.stringify(m, null, 2));41 return m;42}4344/** Resolve a public request path to an approved file, or null. Prevents traversal and unlisted access. */45export function resolveApproved(parts: string[]): { file: string; entry: ManifestEntry } | null {46 if (parts.some(p => !p || p === "." || p === ".." || p.includes("\0") || p.includes("\\") || p.startsWith("."))) return null;47 const rel = parts.join("/");48 const entry = readManifest().files.find(f => f.path === rel);49 if (!entry) return null;50 const abs = path.resolve(DESIGN_ROOT, rel);51 if (!abs.startsWith(DESIGN_ROOT + path.sep)) return null;52 try {53 const real = fs.realpathSync(abs);54 if (!real.startsWith(fs.realpathSync(DESIGN_ROOT) + path.sep)) return null;55 const sha = crypto.createHash("sha256").update(fs.readFileSync(real)).digest("hex");56 if (sha !== entry.sha256) return null; // integrity: modified since approval57 return { file: real, entry };58 } catch { return null; }59}6061const MAGIC: [string, number[]][] = [["image/png", [0x89, 0x50, 0x4e, 0x47]], ["image/jpeg", [0xff, 0xd8, 0xff]], ["image/webp", [0x52, 0x49, 0x46, 0x46]]];62export function validateUpload(dir: string, name: string, buf: Buffer): string | null {63 if (!(ALLOWED_DIRS as readonly string[]).includes(dir) || dir === "manifests") return "destination directory not allowed";64 if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/.test(name) || name.includes("..")) return "invalid file name";65 const mime = mimeFor(name);66 if (!mime) return "file type not allowed";67 if (buf.length === 0 || buf.length > MAX_BYTES) return "file empty or larger than 5 MB";68 const magic = MAGIC.find(([m]) => m === mime);69 if (magic && !magic[1].every((b, i) => buf[i] === b)) return "file content does not match its extension";70 if (mime === "application/json") { try { JSON.parse(buf.toString("utf8")); } catch { return "invalid JSON"; } }71 if (mime === "image/svg+xml" && /<script|onload=|javascript:/i.test(buf.toString("utf8"))) return "active content in SVG rejected";72 return null;73}74export function saveAsset(dir: string, name: string, buf: Buffer) {75 fs.mkdirSync(path.join(DESIGN_ROOT, dir), { recursive: true });76 fs.writeFileSync(path.join(DESIGN_ROOT, dir, name), buf);77 return rebuildManifest();78}79export function listDir(dir: string): string[] {80 try { return fs.readdirSync(path.join(DESIGN_ROOT, dir)).sort(); } catch { return []; }81}82
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.