Skip to content
  1. Home
  2. workspace
Checking…
Public 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/app/api/projects/[id]/tasks/route.ts

1import { db, now, uid } from "@/lib/db";
2import { auditT, projectOf, tenant, notFound } from "@/lib/tenant";
3export const dynamic = "force-dynamic";
4type T = { id: string; title: string; done: number; depends_on: string; milestone_id: string | null };
5const parse = (s: string): string[] => { try { const a = JSON.parse(s); return Array.isArray(a) ? a.map(String) : []; } catch { return []; } };
6/** true if making `id` depend on `deps` would create a cycle */
7function cycle(all: T[], id: string, deps: string[]): boolean {
8 const g = new Map(all.map(t => [t.id, t.id === id ? deps : parse(t.depends_on)])); const seen = new Set<string>(); const stack = [...deps];
9 while (stack.length) { const n = stack.pop()!; if (n === id) return true; if (seen.has(n)) continue; seen.add(n); stack.push(...(g.get(n) ?? [])); } return false;
10}
11export async function POST(req: Request, { params }: { params: Promise<{ id: string }> }) {
12 const g = await tenant("developer", { write: true }); if (g.res) return g.res; const ctx = g.ctx; const { id } = await params;
13 const b = await req.json().catch(() => ({})); const d = db();
14 if (!(await projectOf(ctx, id))) return notFound();
15 const all = await d.prepare("SELECT id,title,done,depends_on,milestone_id FROM tasks WHERE project_id=?").all(id) as T[]; const byId = new Map(all.map(t => [t.id, t]));
16 if (b.toggle) {
17 const t = byId.get(String(b.toggle)); if (!t) return Response.json({ error: "task not found" }, { status: 404 });
18 if (!t.done) { const open = parse(t.depends_on).map(x => byId.get(x)).filter(x => x && !x.done); if (open.length) return Response.json({ error: `Blocked by unfinished dependencies: ${open.map(x => x!.title).join(", ")}` }, { status: 409 }); }
19 await d.prepare("UPDATE tasks SET done=1-done WHERE id=? AND project_id=?").run(t.id, id); return Response.json({ ok: true });
20 }
21 if (b.update) { // {update: taskId, depends_on?: string[], milestone_id?: string|null, blocked_reason?: string|null}
22 const t = byId.get(String(b.update)); if (!t) return Response.json({ error: "task not found" }, { status: 404 });
23 if (b.depends_on !== undefined) {
24 const deps: string[] = Array.isArray(b.depends_on) ? [...new Set<string>(b.depends_on.map(String))] : []; if (deps.length > 20 || deps.some(x => !byId.has(x) || x === t.id)) return Response.json({ error: "invalid dependency" }, { status: 422 });
25 if (cycle(all, t.id, deps)) return Response.json({ error: "dependency cycle rejected" }, { status: 422 });
26 await d.prepare("UPDATE tasks SET depends_on=? WHERE id=?").run(JSON.stringify(deps), t.id);
27 }
28 if (b.milestone_id !== undefined) { if (b.milestone_id && !await d.prepare("SELECT 1 FROM milestones WHERE id=? AND project_id=?").get(String(b.milestone_id), id)) return Response.json({ error: "milestone not found" }, { status: 404 }); await d.prepare("UPDATE tasks SET milestone_id=? WHERE id=?").run(b.milestone_id ? String(b.milestone_id) : null, t.id); }
29 if (b.blocked_reason !== undefined) await d.prepare("UPDATE tasks SET blocked_reason=? WHERE id=?").run(b.blocked_reason ? String(b.blocked_reason).slice(0, 200) : null, t.id);
30 await auditT(ctx, "task.update", id, { task: t.id }); return Response.json({ ok: true });
31 }
32 const title = String(b.title ?? "").trim(); if (title.length < 1 || title.length > 200) return Response.json({ error: "title required (≤200 chars)" }, { status: 422 });
33 const tid = uid("t_"); await d.prepare("INSERT INTO tasks(id,project_id,title,created_at) VALUES(?,?,?,?)").run(tid, id, title, now());
34 await auditT(ctx, "task.create", id, { title }); return Response.json({ id: tid }, { status: 201 });
35}
36

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 915def0 on master.

Approval requests

None pending.