"use client"; import { useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { inline } from "./inlineMarks"; // THE CHANNEL CONTEXT NOTES (lib/digestContextReview.mjs; /tools/digest-context): // each candidate note as it would reach the digest prompt, beside what the plan // says it rests on, and the operator's Yes or No. Yes is asked twice -- the // cost is every digest already made for that channel -- and only then sent to // the one route. Nothing here decides anything by itself. export type DigestNote = { slug: string; state: "pending" | "refused" | "active"; rank: number | null; chunks: number | null; active: boolean; text: string | null; sha256: string | null; chars: number; refusal: { at: string; by: string } | null; evidence: { heading: string; flag: string | null; bullets: string[] } | null; }; const day = (iso: string) => { const d = new Date(iso); return Number.isNaN(d.getTime()) ? iso : d.toISOString().slice(0, 10); }; export default function DigestContextReview({ initial, promptChars }: { initial: DigestNote[]; promptChars: number }) { const [notes, setNotes] = useState(initial); const [confirming, setConfirming] = useState(null); const [busy, setBusy] = useState(null); const [errors, setErrors] = useState>({}); const decide = async (n: DigestNote, decision: "yes" | "no") => { setBusy(n.slug); setErrors((e) => ({ ...e, [n.slug]: "" })); try { const r = await fetch("/api/digest-context", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ slug: n.slug, decision, sha256: n.sha256 }), }); const j = (await r.json().catch(() => ({}))) as { note?: DigestNote | null; error?: string }; if (!r.ok) { setErrors((e) => ({ ...e, [n.slug]: j.error ?? `HTTP ${r.status}` })); return; } setNotes((all) => (j.note ? all.map((x) => (x.slug === n.slug ? j.note! : x)) : all.filter((x) => x.slug !== n.slug))); setConfirming(null); } catch (e) { setErrors((x) => ({ ...x, [n.slug]: e instanceof Error ? e.message : String(e) })); } finally { setBusy(null); } }; const pending = notes.filter((n) => n.state === "pending"); const decided = notes.filter((n) => n.state !== "pending"); return (

{pending.length} pending · {notes.filter((n) => n.state === "refused").length} refused ·{" "} {notes.filter((n) => n.state === "active").length} active

{pending.length === 0 && (

No note is waiting on you.

)} {[...pending, ...decided].map((n) => { const ask = confirming === n.slug; return (

{n.slug}

{n.rank !== null && ( #{n.rank} in the sweep's queue{n.chunks !== null ? ` · ${n.chunks.toLocaleString("en-US")} chunks to generate` : ""} )} {n.evidence?.flag && ( {n.evidence.flag} )} {n.state === "pending" ? "pending" : n.state === "refused" ? `refused ${day(n.refusal?.at ?? "")}` : "active: digest-context.md"}
{n.state !== "active" && (
what it asserts — digest-context.suggested.md
                    {n.text}
                  
{n.chars > promptChars && (

{n.chars} characters: only the first {promptChars} reach the prompt.

)}
what it rests on — the plan's evidence
{n.evidence ? (
    {n.evidence.bullets.map((b, i) => (
  • {inline(b)}
  • ))}
) : (

The plan gives no evidence for this channel: judge the note on its own.

)}
)} {n.state !== "active" && (
{!ask ? ( <> {n.state === "pending" && ( )} {n.active && This channel already has an active digest-context.md: it is never overwritten.} ) : ( <> {/* The confirming press sits where the first press was: the sentence follows the buttons, so a second click in place confirms. */} {n.slug}'s note becomes digest-context.md: every digest already made for this channel goes stale and regenerates. )} {errors[n.slug] && ( {errors[n.slug]} )}
)}
); })}
); }