feat(T2b): sources v0 — read tool + pdf-reader sub-agent

Learner source files, on the teacher's own terms (nothing auto-injects):

- read tool (src/agent/tools/read.ts): pi-read port — path/offset/limit,
  2000-line/50KB truncation with use-offset continuation notices, image
  files (jpg/png/gif/webp/bmp) returned as native image content parts
  (new LhToolImageResult escape hatch in lh-tool.ts). Always-on in both
  the prober and teacher registries (user-decided 2026-09).
- pdf-reader sub-agent (JobKind 'pdf', toggleable, ack-and-steer): triage
  via pdf_info (pdfjs text layer: per-page text/image/math-density),
  targeted pdf_extract, regex pdf_search (hits count as consultation),
  and pdf_render — pages painted by pdfjs onto a canvas shim in headless
  Chrome (the pdfium viewer doesn't paint headless), screenshot fed back
  image-in-the-loop (visual-maker idiom, providerSafePng applied). The
  unread-finish gate bounces a zero-consultation brief once. Teacher gets
  a text brief with page citations only; renders never leave the loop.
- MODELS.pdfReader = qwen/qwen3.8-flash (user override 2026-09-19: the
  look-at-renders workload wants the vision-proven model; catalog listed
  glm-5.3-flash as image-capable but qwen is the known-good daily driver).
- UI: PdfCompleteBadge + PdfBriefCard (steer-card, job-card), dispatch
  card + activity-dock kind entries (type-forced, flagged for UI review).
- Prompts: 'Learner source files' section in teacher/30-jobs.md; read
  line in prober/10-probe-doctrine.md. Doctrine rides tool descriptions
  per the self-contained-tools principle.
This commit is contained in:
amosblomqvist
2026-09-19 15:24:26 +03:00
parent bc2c02b865
commit 9a90dd51d9
27 changed files with 1970 additions and 55 deletions
+1
View File
@@ -21,6 +21,7 @@ const KIND_LABEL: Record<JobKind, string> = {
research: "Research agent",
demo: "Demo agent",
visual: "Figure agent",
pdf: "PDF reader",
// The injection is server-initiated — it has no tool part, so never a
// dispatch card. The entry exists only for the exhaustive record.
"graph-context": "Graph context",
+34 -1
View File
@@ -2,7 +2,7 @@
import { DispatchCard } from "@/components/artifacts/dispatch-card";
import { MessageResponse } from "@/components/ai-elements/message";
import type { ArtifactPartProps, ResearchResult } from "@/src/core";
import type { ArtifactPartProps, PdfResult, ResearchResult } from "@/src/core";
/**
* The research tool-call box (contracts.ts "THE ASYNC PROTOCOL" §4).
@@ -18,6 +18,39 @@ export function JobCard({ part }: ArtifactPartProps) {
return <DispatchCard toolCallId={part.toolCallId} kind="research" />;
}
/**
* The PDF reading brief (sources v0) — markdown body + the consulted-pages
* line. Exported: the steer card renders it under the PDF-complete badge,
* the same expand-on-demand idiom as research.
*/
export function PdfBriefCard({ output }: { output: unknown }) {
const result = output as PdfResult | undefined;
if (!result || typeof result.brief !== "string") {
return (
<div className="rounded-xl border bg-card p-4 text-sm text-muted-foreground">
PDF reading completed, but the result could not be displayed.
</div>
);
}
const failed = result.brief.startsWith("PDF failed");
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">
PDF brief
{failed && <span className="rounded bg-red-500/15 px-1.5 py-0.5 text-red-500">failed</span>}
</div>
<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 && (
<div className="mt-3 border-t pt-2 text-xs text-muted-foreground">
Pages consulted: {result.pagesConsulted.join(", ")}
</div>
)}
</div>
);
}
/**
* The research brief — markdown body + a small source link list. Exported:
* the steer card (sub-agent result delivery) renders the same artifact.
+34 -2
View File
@@ -1,10 +1,10 @@
"use client";
import { CheckIcon, CircleX } from "lucide-react";
import type { ResearchResult, SubagentArtifactData, TeacherUIMessage } from "@/src/core";
import type { PdfResult, ResearchResult, SubagentArtifactData, TeacherUIMessage } from "@/src/core";
import { isSubagentFailure } from "@/src/core";
import { DemoOutputCard } from "@/components/artifacts/demo-card";
import { ResearchBriefCard } from "@/components/artifacts/job-card";
import { PdfBriefCard, ResearchBriefCard } from "@/components/artifacts/job-card";
import { VisualOutputCard } from "@/components/artifacts/visual-card";
/**
@@ -48,6 +48,12 @@ export function SubagentSteerCard({ message }: { message: TeacherUIMessage }) {
) : (
<ResearchCompleteBadge result={data.result as ResearchResult} />
);
case "pdf":
return isSubagentFailure("pdf", data.result as PdfResult) ? (
<PdfBriefCard output={data.result} />
) : (
<PdfCompleteBadge result={data.result as PdfResult} />
);
case "demo":
return <DemoOutputCard output={data.result} />;
case "visual":
@@ -68,6 +74,32 @@ function AbortedBadge({ kind }: { kind: string }) {
);
}
/** Quiet one-liner, the research-badge idiom ported to PDF: the brief is
* too long to inline by default and the teacher's wake turn weaves it in;
* the badge marks delivery, the collapsed details carries the full text
* + consulted pages. */
function PdfCompleteBadge({ result }: { result: PdfResult }) {
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 && (
<span>
· {result.pagesConsulted.length} page{result.pagesConsulted.length === 1 ? "" : "s"} consulted
</span>
)}
<span className="ml-1 text-xs text-muted-foreground/70 group-open:hidden">view brief</span>
<span className="ml-1 hidden text-xs text-muted-foreground/70 group-open:inline">hide brief</span>
</summary>
<div className="mt-2">
<PdfBriefCard output={result} />
</div>
</details>
);
}
/** Quiet one-liner, the dispatch-settled idiom — the lesson lives in the
* teacher's wake turn; the badge just marks delivery. The persisted brief
* rides along in a collapsed <details> (the wave-1 "view full research"