// A /sweep REPORT (markdown) → `report.json` (kind "sweep"). // // What /sweep writes (mcp/src/instructions.ts): `## sections` of findings, // each cited as `[title @ mm:ss](/?v=%2F&t=)` // for a video and `[post by , ]()` for a post — the url an // archive post (`…&vm=post`) or the post on its platform. The engine // (./convertShared.ts `structureMarkdown`) makes the document's first `#` // heading the title, the text before the first section the summary, each // section a section, and each list item or paragraph that cites a claim; every // citing link becomes `[label](cite:)`. // // A citation's quote is the quoted words nearest before its link (`"…"` or // `“…”`, several joined by an ellipsis), else the claim's text — VERBATIM is // the model's rule, and compose checks it against the cues. Its span is the // cited second widened through the record's cues when the caller can read // them (`ctx.cuesOf`), else the second plus `ctx.spanSeconds`. A post on its // platform is cited only when `ctx.postChannelOf` finds the archive channel // that keeps it; otherwise its link stays a plain link, with a warning. import { CitationRegistry, emptyReport, finish, reportIdOf, structureMarkdown, type ConvertContext, type Converted, } from "./convertShared"; export type SweepConvertOptions = ConvertContext & { // The report's id; default: the title's slug. id?: string; // The report's title; default: the markdown's first `#` heading. title?: string; // The one section of a sweep with no section headings. sectionTitle?: string; }; export async function sweepToReport(md: string, opts: SweepConvertOptions = {}): Promise { const warnings: string[] = []; const registry = new CitationRegistry(opts, warnings); const doc = await structureMarkdown(md, (link) => registry.link(link.href, link.label, link.quote), { defaultSection: opts.sectionTitle ?? "Findings", }); const title = opts.title ?? doc.title ?? "Sweep"; const report = emptyReport(reportIdOf(opts.id, title), "sweep", title); if (doc.summary) report.summary = doc.summary; report.citations = registry.citations; report.sections = doc.sections; if (!Object.keys(registry.citations).length) warnings.push("the markdown cites nothing the citation model knows"); return finish(report, warnings); }