import { projectRef } from "@/lib/projects"; import { readManifest } from "@/lib/projects/report.mjs"; import { marksAgainst, readReviewPass, setReviewMark } from "@/lib/report/reviewPass.mjs"; import { refuseCaller } from "@/lib/report/caller"; import { crossSiteRefusal } from "@/lib/report/sameOrigin.mjs"; export const dynamic = "force-dynamic"; // THE REVIEW PASS's marks (lib/report/reviewPass.mjs; the workspace's `?mode=review`): any block's Fix (a clip's // too: never its verdict), a post's or a card's Keep. A clip's Keep is its walk verdict, written through the window // writer (PUT /api/report/window); the draft's verdict is POST /api/report/review-pass/verdict. // // GET ?project= /review-pass.json, as read // POST { project, block, mark: "keep"|"fix"|null, note? } one block's mark (null clears it); a Fix says what // needs fixing. Terminal twin: `umtool review-pass

mark`. export async function GET(request: Request) { const url = new URL(request.url); const project = await projectRef(url.searchParams.get("project") ?? ""); if (!project) return Response.json({ error: "no such project" }, { status: 404 }); // The marks against the cut as it is now: a block changed since it was reviewed is `stale` (unanswered again). const [doc, manifest] = await Promise.all([readReviewPass(project.dir), readManifest(project.dir).catch(() => null)]); return Response.json({ ...doc, marks: marksAgainst(doc, manifest) }, { headers: { "cache-control": "no-store" } }); } export async function POST(request: Request) { const refused = refuseCaller(request, "/api/report/review-pass"); if (refused) return refused; const cross = crossSiteRefusal(request.headers); if (cross) return Response.json({ error: cross }, { status: 403 }); const body = (await request.json().catch(() => null)) as { project?: string; block?: string; mark?: string | null; note?: string } | null; if (!body || typeof body !== "object" || typeof body.block !== "string") return Response.json({ error: "bad json: { project, block, mark }" }, { status: 400 }); const project = await projectRef(String(body.project ?? "")); if (!project) return Response.json({ error: "no such project" }, { status: 404 }); const manifest = await readManifest(project.dir); if (!manifest) return Response.json({ error: "no video.manifest.json" }, { status: 404 }); const mark = body.mark === null || body.mark === undefined || body.mark === "" ? null : body.mark; try { const r = await setReviewMark(project.dir, manifest, body.block, mark as "keep" | "fix" | null, { note: typeof body.note === "string" ? body.note : undefined }); return Response.json({ ok: true, mark: r.mark, doc: { ...r.doc, marks: marksAgainst(r.doc, manifest) } }, { headers: { "cache-control": "no-store" } }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400 }); } }