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
+3 -1
View File
@@ -292,7 +292,7 @@ describe("steer helpers (contracts.ts)", () => {
});
it("pdf steers (sources v0): brief + page citations on success, PDF failed: shape on failure, abort wording per kind", () => {
const pdf: PdfResult = { path: "/tmp/doc.pdf", question: "q?", brief: "The formula is on p. 2.", pagesConsulted: [1, 2] };
const pdf: PdfResult = { path: "/tmp/doc.pdf", question: "q?", brief: "The formula is on p. 2.", pagesRead: [2], pagesConsulted: [1, 2] };
const ok = buildSubagentSteer({ id: "jp", kind: "pdf", toolCallId: "cp" }, pdf);
assert.ok(ok.parts[0].type === "text" && ok.parts[0].text.includes("page citations"), "the teacher is told to cite pages");
assert.ok(ok.parts[0].type === "text" && ok.parts[0].text.includes("The formula is on p. 2."));
@@ -622,6 +622,7 @@ describe("pdf runner (sources v0)", () => {
const result = done.result as PdfResult;
assert.equal(result.path, PDF_FIXTURE);
assert.match(result.brief, /integral rule/);
assert.deepEqual(result.pagesRead, [1, 2], "extracted pages are READ pages");
assert.deepEqual(result.pagesConsulted, [1, 2]);
assert.equal(delivery.steers.length, 1, "one job, one steer");
@@ -651,6 +652,7 @@ describe("pdf runner (sources v0)", () => {
assert.equal(done.status, "error", "the failure brief is a subagent failure");
const result = done.result as PdfResult;
assert.match(result.brief, /^PDF failed:/);
assert.deepEqual(result.pagesRead, []);
assert.deepEqual(result.pagesConsulted, []);
const steer = delivery.steers[0]!;