import { useEffect, useRef, useState } from "react"; import { Stack, ArrowRight, X } from "@phosphor-icons/react"; import { api, factValue, type Fact, type RunSummary } from "../lib/api"; import { Empty, Note, ProvenanceList, Spinner, StatusChip } from "./common"; const FILTERS = [ { k: "", label: "all" }, { k: "verified", label: "verified" }, { k: "derived", label: "derived" }, { k: "unverified", label: "unverified" }, { k: "conflicted", label: "conflicted" }, { k: "attested", label: "attested" }, { k: "resolved", label: "resolved" }, ] as const; export function Ledger({ run, onNext }: { run: RunSummary; onNext: () => void }) { const [facts, setFacts] = useState([]); const [total, setTotal] = useState(run.fact_count); const [streaming, setStreaming] = useState(true); const [filter, setFilter] = useState(""); const [open, setOpen] = useState(null); const seen = useRef(new Set()); useEffect(() => { // Stream the ledger so the reviewer watches it being assembled from the filing. const es = new EventSource(`/api/runs/${run.id}/ledger/stream?delay_ms=14`); es.addEventListener("start", (e) => setTotal(JSON.parse((e as MessageEvent).data).total)); es.addEventListener("fact", (e) => { const { fact } = JSON.parse((e as MessageEvent).data); if (seen.current.has(fact.id)) return; seen.current.add(fact.id); setFacts((prev) => [...prev, fact]); }); es.addEventListener("done", () => { setStreaming(false); es.close(); }); es.onerror = () => { setStreaming(false); es.close(); }; return () => es.close(); }, [run.id]); const shown = filter ? facts.filter((f) => f.status === filter) : facts; const counts = facts.reduce>((a, f) => { a[f.status] = (a[f.status] ?? 0) + 1; return a; }, {}); return ( <>

Disclosure ledger

Each row is one atomic disclosure value read from the issuer's own filing, bound to the page it came from. Status is earned, never assumed: a figure is verified only when two independent sections agree or an accounting identity supports it. Everything else abstains and says what to confirm.

{facts.length}
facts extracted{streaming ? " so far" : ""}
{counts.verified ?? 0}
verified by corroboration or identity
{counts.derived ?? 0}
derived, with lineage recorded
{counts.unverified ?? 0}
abstained, awaiting confirmation
{counts.conflicted ?? 0}
sources disagree
{streaming && (
)}

Facts

{shown.length} shown
{FILTERS.map((f) => ( ))}
{shown.length === 0 && !streaming ? ( {filter ? "No figure in this filing earned that status." : "No disclosure value could be read from the source records."} ) : ( {shown.map((f, i) => ( = shown.length - 3 && streaming ? "arrived" : ""} onClick={() => setOpen(f)} style={{ cursor: "pointer" }} > ))}
Disclosure Value Status Source
{f.label}
{f.id}
{f.note &&
{f.note}
}
{factValue(f)}
{f.provenance[0]?.locator ?? "n/a"}
{f.provenance.length > 1 && (
{f.provenance.length} sources agree
)} {f.identities.length > 0 && (
{f.identities[0]}
)}
)}
{!streaming && (counts.unverified ?? 0) > 0 && ( {counts.unverified} figures abstained. The engine will list each one for attestation. )}
{open && setOpen(null)} />} ); } function FactDrawer({ fact, onClose }: { fact: Fact; onClose: () => void }) { useEffect(() => { const onKey = (e: KeyboardEvent) => e.key === "Escape" && onClose(); window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [onClose]); return (
e.stopPropagation()} role="dialog" aria-label={fact.label} >

{fact.label}

{factValue(fact)} {fact.id}
{fact.note && {fact.note}} {fact.identities.length > 0 && (
Supported by
{fact.identities.map((i) => (
{i}
))}
)} {fact.derived_from.length > 0 && (
Derived from
{fact.derived_from.map((d) => (
{d}
))}
)}
Provenance ({fact.provenance.length})
{fact.section_refs.length > 0 && (
Used in sections
{fact.section_refs.map((s) => ( {s.replace(/_/g, " ")} ))}
)}
); }