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/components/project-editor.tsx
1"use client";2import { useCallback, useEffect, useRef, useState } from "react";3import { FileText, Folder, FilePlus2, Trash2, Upload, Save, GitCommit, RefreshCw } from "lucide-react";45type Entry = { name: string; path: string; dir: boolean; size: number };6declare global { interface Window { require?: any; monaco?: any; MonacoEnvironment?: any } }7const LANG: Record<string, string> = { ts: "typescript", tsx: "typescript", js: "javascript", jsx: "javascript", json: "json", md: "markdown", css: "css", html: "html", py: "python", yml: "yaml", yaml: "yaml", toml: "ini", csv: "plaintext", txt: "plaintext", svg: "xml" };89function loadMonaco(): Promise<any> {10 if (window.monaco) return Promise.resolve(window.monaco);11 return new Promise((resolve, reject) => {12 window.MonacoEnvironment = { getWorkerUrl: () => "data:text/javascript;charset=utf-8," + encodeURIComponent("self.MonacoEnvironment={baseUrl:'" + location.origin + "/monaco-vs/'};importScripts('" + location.origin + "/monaco-vs/base/worker/workerMain.js');") };13 const s = document.createElement("script"); s.src = "/monaco-vs/loader.js";14 s.onload = () => { window.require.config({ paths: { vs: "/monaco-vs" } }); window.require(["vs/editor/editor.main"], () => resolve(window.monaco), reject); };15 s.onerror = () => reject(new Error("editor assets failed to load")); document.head.appendChild(s);16 });17}1819export function ProjectEditor({ projects, signedIn, secure }: { projects: { id: string; name: string }[]; signedIn: boolean; secure: boolean }) {20 const [pid, setPid] = useState(projects[0]?.id ?? ""); const [dir, setDir] = useState(""); const [entries, setEntries] = useState<Entry[]>([]); const [file, setFile] = useState(""); const [dirty, setDirty] = useState(false);21 const [msg, setMsg] = useState(""); const [git, setGit] = useState(""); const [commitMsg, setCommitMsg] = useState(""); const [ready, setReady] = useState(false);22 const host = useRef<HTMLDivElement>(null); const ed = useRef<any>(null); const fileRef = useRef(""); fileRef.current = file;23 const call = useCallback(async (url: string, init?: RequestInit) => { const r = await fetch(url, init); const j = await r.json().catch(() => ({})); if (!r.ok) throw new Error(j.error || `HTTP ${r.status}`); return j; }, []);24 const J = { "content-type": "application/json" };25 const refresh = useCallback(async () => { if (!pid) return; try { setEntries((await call(`/api/workspace/${pid}/files?dir=${encodeURIComponent(dir)}`)).entries); } catch (e) { setMsg((e as Error).message); } }, [pid, dir, call]);26 const gitRun = useCallback(async (op: string, arg = "") => { try { const j = await call(`/api/workspace/${pid}/git`, { method: "POST", headers: J, body: JSON.stringify({ op, arg }) }); setGit(j.initialized === false ? "Not a git repository yet — click Init." : j.status ?? j.diff ?? j.log ?? j.branches ?? j.out ?? "ok"); if (["commit", "init", "branch"].includes(op)) { setCommitMsg(""); void refresh(); } } catch (e) { setGit((e as Error).message); } }, [pid, call, refresh]);27 useEffect(() => { void refresh(); setFile(""); setGit(""); }, [refresh, pid]);28 useEffect(() => { let dead = false; if (!signedIn || !secure) return; loadMonaco().then(m => { if (dead || !host.current || ed.current) return;29 ed.current = m.editor.create(host.current, { value: "// Select or create a file", language: "plaintext", automaticLayout: true, minimap: { enabled: false }, theme: document.documentElement.classList.contains("dark") ? "vs-dark" : "vs", fontSize: 13, readOnly: true });30 ed.current.onDidChangeModelContent(() => { if (fileRef.current) setDirty(true); }); ed.current.addCommand(m.KeyMod.CtrlCmd | m.KeyCode.KeyS, () => void save()); setReady(true); }).catch(e => setMsg(e.message)); return () => { dead = true; }; // eslint-disable-next-line31 }, [signedIn, secure]);32 const open = async (p: string) => { try { const j = await call(`/api/workspace/${pid}/files?file=${encodeURIComponent(p)}`); const m = window.monaco; const ext = p.split(".").pop() ?? ""; const model = m.editor.createModel(j.text, LANG[ext] ?? "plaintext"); ed.current.getModel()?.dispose(); ed.current.setModel(model); ed.current.updateOptions({ readOnly: false }); setFile(p); fileRef.current = p; setDirty(false); setMsg(""); } catch (e) { setMsg((e as Error).message); } };33 const save = async () => { const p = fileRef.current; if (!p || !ed.current) return; try { await call(`/api/workspace/${pid}/files`, { method: "PUT", headers: J, body: JSON.stringify({ path: p, content: ed.current.getValue() }) }); setDirty(false); setMsg(`Saved ${p}`); void refresh(); } catch (e) { setMsg((e as Error).message); } };34 const create = async () => { const name = prompt0(); if (!name) return; const p = [dir, name].filter(Boolean).join("/"); try { await call(`/api/workspace/${pid}/files`, { method: "PUT", headers: J, body: JSON.stringify({ path: p, content: "" }) }); await refresh(); await open(p); } catch (e) { setMsg((e as Error).message); } };35 const [newName, setNewName] = useState(""); const prompt0 = () => newName.trim();36 const del = async () => { if (!file) return; try { await call(`/api/workspace/${pid}/files?path=${encodeURIComponent(file)}`, { method: "DELETE" }); setFile(""); ed.current.updateOptions({ readOnly: true }); await refresh(); setMsg("Deleted"); } catch (e) { setMsg((e as Error).message); } };37 const up = async (f: File | undefined) => { if (!f) return; const fd = new FormData(); fd.set("file", f); fd.set("dir", dir); try { const j = await call(`/api/workspace/${pid}/upload`, { method: "POST", body: fd }); setMsg(`Uploaded ${j.path}`); void refresh(); } catch (e) { setMsg((e as Error).message); } };3839 if (!secure) return <div className="p-4 text-sm text-muted">The editor needs an authenticated HTTPS session. Plain HTTP is read-only by design.</div>;40 if (!signedIn) return <div className="p-4 text-sm text-muted">Sign in to edit project files.</div>;41 if (!projects.length) return <div className="p-4 text-sm text-muted">Create a project first — each project has its own isolated file workspace.</div>;42 return <div data-testid="project-editor"><div className="flex flex-wrap items-center gap-2 border-b border-line p-3">43 <select className="input !w-auto min-w-0" aria-label="Project" value={pid} onChange={e => { setPid(e.target.value); setDir(""); }}>{projects.map(p => <option key={p.id} value={p.id}>{p.name}</option>)}</select>44 <input className="input !w-40" aria-label="New file name" placeholder="new-file.md" value={newName} onChange={e => setNewName(e.target.value)} />45 <button className="btn btn-sm" onClick={create} disabled={!newName.trim()}><FilePlus2 size={13} />New</button>46 <label className="btn btn-sm cursor-pointer"><Upload size={13} />Upload<input type="file" className="sr-only" aria-label="Upload file" onChange={e => { void up(e.target.files?.[0]); e.target.value = ""; }} /></label>47 <button className="btn btn-primary btn-sm" onClick={save} disabled={!dirty}><Save size={13} />Save</button>48 <button className="btn btn-sm" onClick={del} disabled={!file}><Trash2 size={13} />Delete</button>49 <span role="status" className="min-w-0 truncate text-xs text-muted">{msg}{dirty ? " · unsaved changes" : ""}</span></div>50 <div className="grid gap-0 lg:grid-cols-[14rem_1fr]">51 <ul className="max-h-64 overflow-auto border-b border-line p-1.5 text-sm lg:max-h-[24rem] lg:border-b-0 lg:border-r" aria-label="Project files">52 {dir && <li><button className="flex w-full items-center gap-2 rounded px-2 py-1 text-left text-muted hover:bg-surface2" onClick={() => setDir(dir.split("/").slice(0, -1).join("/"))}>..</button></li>}53 {entries.length === 0 && <li className="px-2 py-1 text-xs text-muted">Empty workspace</li>}54 {entries.map(n => <li key={n.path}><button onClick={() => n.dir ? setDir(n.path) : open(n.path)} className={`flex w-full items-center gap-2 rounded px-2 py-1 text-left hover:bg-surface2 ${n.path === file ? "bg-accentsoft text-accent" : ""}`}>{n.dir ? <Folder size={14} /> : <FileText size={14} />}<span className="truncate">{n.name}</span></button></li>)}</ul>55 <div ref={host} className="h-64 min-w-0 lg:h-[24rem]" aria-label="Code editor" />{!ready && <div className="p-3 text-xs text-muted">Loading editor…</div>}</div>56 <div className="border-t border-line p-3"><div className="flex flex-wrap items-center gap-1.5"><span className="text-xs font-medium text-muted">Git</span>57 {["init", "status", "diff", "log", "branches"].map(o => <button key={o} className="btn btn-sm" onClick={() => gitRun(o)}>{o}</button>)}58 <input className="input !w-48" aria-label="Commit message" placeholder="Commit message" value={commitMsg} onChange={e => setCommitMsg(e.target.value)} />59 <button className="btn btn-sm" disabled={!commitMsg.trim()} onClick={() => gitRun("commit", commitMsg)}><GitCommit size={13} />Commit</button><button className="btn btn-sm" aria-label="Refresh" onClick={refresh}><RefreshCw size={13} /></button></div>60 {git && <pre className="mono mt-2 max-h-48 overflow-auto rounded bg-surface2 p-2 text-xs" aria-label="Git output">{git}</pre>}</div></div>;61}62
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.