fix(pdf): split pagesRead from pagesConsulted — the honest badge count

Live-smoke follow-up the user approved (2026-09-19): the GEB read showed
"78 pages consulted" when the reader genuinely READ ~12 - pdf_search hit
snippets inflated the count. PdfResult now carries both:

- pagesRead: extract/render output entered the loop - the honest count
  the badge and brief footer show ("read N pages", "Pages read: ...").
- pagesConsulted: every page whose content entered the loop, search-hit
  context lines included - unchanged, still the citation audit set (the
  reader's instructions still say "Pages consulted: N, N, ..." and the
  footer still lists it when it exceeds the read set).

The unread-finish gate deliberately stays on CONSULTED: search hits are
genuine consultation (anti-fabrication duty), so a search-only brief is
honest and must deliver - pagesRead is a reporting refinement, not a
delivery gate. Pinned by the search-only faux test (read [], consulted
[1], delivered).

UI tolerates pre-split persisted records via ?? fallbacks (old steers
lack pagesRead).
This commit is contained in:
amosblomqvist
2026-09-19 16:52:09 +03:00
parent 7a3e19e95f
commit 1b9122c88b
8 changed files with 57 additions and 14 deletions
+12 -2
View File
@@ -44,6 +44,11 @@ export function PdfBriefCard({ output }: { output: unknown }) {
);
}
const failed = result.brief.startsWith("PDF failed");
// Read = extract/render output entered the loop; consulted = every page
// incl. search hits (the full audit set — the brief's citations may point
// there). The ?? fallbacks tolerate pre-split persisted records.
const readList = result.pagesRead ?? result.pagesConsulted ?? [];
const consultedList = result.pagesConsulted ?? [];
return (
<div className="rounded-xl border bg-card p-4 text-card-foreground" data-testid="pdf-brief-card">
<div className="mb-1 flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground">
@@ -53,9 +58,14 @@ export function PdfBriefCard({ output }: { output: unknown }) {
<div className="text-sm [&_p:first-child]:mt-0 [&_p:last-child]:mb-0">
<MessageResponse>{result.brief}</MessageResponse>
</div>
{!failed && result.pagesConsulted && result.pagesConsulted.length > 0 && (
{!failed && readList.length > 0 && (
<div className="mt-3 border-t pt-2 text-xs text-muted-foreground">
Pages consulted: {result.pagesConsulted.join(", ")}
Pages read: {readList.join(", ")}
</div>
)}
{!failed && consultedList.length > readList.length && (
<div className="mt-3 border-t pt-2 text-xs text-muted-foreground">
Pages consulted: {consultedList.join(", ")}
</div>
)}
</div>
+5 -2
View File
@@ -79,15 +79,18 @@ function AbortedBadge({ kind }: { kind: string }) {
* the badge marks delivery, the collapsed details carries the full text
* + consulted pages. */
function PdfCompleteBadge({ result }: { result: PdfResult }) {
// The honest count is READ pages (extract/render — sources v1 split);
// the ?? is runtime tolerance for pre-split persisted steers.
const readPages = result.pagesRead ?? result.pagesConsulted;
return (
<details data-testid="pdf-complete-badge" className="group w-full text-xs text-muted-foreground">
<summary className="flex cursor-pointer select-none list-none items-center gap-2 [&::-webkit-details-marker]:hidden">
<CheckIcon className="size-3.5" />
<span className="font-medium uppercase tracking-wide">PDF</span>
<span>reading complete</span>
{result.pagesConsulted.length > 0 && (
{readPages.length > 0 && (
<span>
· {result.pagesConsulted.length} page{result.pagesConsulted.length === 1 ? "" : "s"} consulted
· read {readPages.length} page{readPages.length === 1 ? "" : "s"}
</span>
)}
<span className="ml-1 text-xs text-muted-foreground/70 group-open:hidden">view brief</span>