import { errorResponse, targetFrom } from "@/lib/annotations/server"; import { digest } from "@/lib/annotations/digest.mjs"; import { readNotes } from "@/lib/annotations/store.mjs"; export const dynamic = "force-dynamic"; // The agent brief: the same markdown `umtool notes ` prints, as // text/plain, so "Copy agent brief" and `curl` hand over the words an agent // would read on the command line. // // /api/notes/context?article=/[&status=open|resolved|all] // /api/notes/context?project=[&status=…] export async function GET(request: Request) { try { const url = new URL(request.url); const target = await targetFrom({ article: url.searchParams.get("article"), project: url.searchParams.get("project") }); const s = url.searchParams.get("status"); const status = s === "resolved" || s === "all" ? s : "open"; const read = await readNotes(target.file); const cli = `umtool notes ${target.id}`; const body = !read.doc && !read.error ? `No notes on ${target.id}.\n` : `${await digest( { kind: target.kind as "article" | "video-project", id: target.id, file: target.file, doc: read.doc, ...(read.error ? { error: read.error } : {}) }, { status, projectDir: "dir" in target ? target.dir : undefined }, )}\n\nRead these again with \`${cli}\` (from the repo checkout).\n`; return new Response(body, { headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" } }); } catch (err) { return errorResponse(err); } }