feat(sources v1): the agent locates files itself — ls/find/grep + tool-call cards

User pivot (2026-09-19): no attachments UI at all. Pasting paths is native
for technical users and alien for everyone else - so the agent gets the
tools to find what the learner merely NAMES. The learner communicates in
messages; the agent locates and reads. Zero cross-stream seams: paths
already live in tool parts, so the sources "list" is the transcript.

- ls/find/grep: pi-verbatim schemas, descriptions, and output formats
  (fd's glob semantics, rg's path:line: match format, pi's truncation
  notices), ported to pure Node - no binaries, no shell-out, read-only by
  construction. Deltas from pi: home-anchored resolution (the harness has
  no cwd), .gitignore replaced by hard noise exclusions
  (node_modules/.git/Library/.Trash), 10s walk timeout with partial results.
- read: description swapped to pi-verbatim (doctrine moved to the prompt);
  relative paths now resolve against the learner's home like the rest.
- prompts/shared/05-learner-files.md: one minimal doctrine fragment
  composed into BOTH agents (composeInstructions grew a shared/ dir,
  before the agent's own fragments). teacher/30-jobs.md keeps only the
  pdf-dispatch addendum.
- ToolCallCard: the generic quiet tool-call card the user specced -
  collapsed one-liner (tool name + headline argument), expandable to full
  input/output, errors red, image payloads never render. Registered for
  read/ls/find/grep.
- ui-message.ts: TeacherUITools entries for the four tools (mechanical).
- tests: fs-tools suite (glob semantics, pi formats, exclusions, limits),
  registry/card renders, shared-fragment composition pins, tool-registry
  key updates, read re-anchor.
This commit is contained in:
amosblomqvist
2026-09-19 16:50:20 +03:00
parent dfe1a21989
commit 7a3e19e95f
18 changed files with 977 additions and 41 deletions
+63
View File
@@ -41,6 +41,7 @@ import { sanitizeSvg, VisualCard } from "../components/artifacts/visual-card.tsx
import { SubagentSteerCard } from "../components/artifacts/steer-card.tsx";
import { DispatchCard } from "../components/artifacts/dispatch-card.tsx";
import { JobCard, PdfJobCard } from "../components/artifacts/job-card.tsx";
import { ToolCallCard } from "../components/artifacts/tool-call-card.tsx";
import { JobsContext } from "../components/jobs-context.ts";
import { demoInputSchema, jobTools, pdfInputSchema, visualInputSchema } from "../src/agent/tools/jobs.ts";
import { runDemoBuilder } from "../src/agent/subagents/demo-builder.ts";
@@ -846,5 +847,67 @@ describe("tool + renderer registry wiring", () => {
assert.equal(artifactRenderers.visual, VisualCard);
// sources v0 — pdf maps to its dispatch card (the live-smoke gap)
assert.equal(artifactRenderers.pdf, PdfJobCard);
// sources v1 — the learner-filesystem set maps to the generic tool-call card
for (const t of ["read", "ls", "find", "grep"]) {
assert.equal(artifactRenderers[t], ToolCallCard, `${t} renders the tool-call card`);
}
});
it("the tool-call card: collapsed one-liner with the tool name + headline arg; expand shows input and output", () => {
const part = {
type: "tool-read",
state: "output-available",
toolCallId: "c1",
input: { path: "notes/calculus.md", offset: 1, limit: 20 },
output: "Calculus notes\nThe derivative measures force.",
};
const html = renderToStaticMarkup(<ToolCallCard part={part as never} />);
// collapsed headline: tool name + path as given
assert.match(html, /read/);
assert.match(html, /notes\/calculus\.md/);
// expandable payload: input JSON + output text
assert.match(html, /Input/);
assert.match(html, /Output/);
assert.match(html, /The derivative measures force\./);
assert.ok(html.includes("<details"), "collapsed by default via a details element");
});
it("the tool-call card: image-bearing read results note the attachment; errors render red", () => {
const imgPart = {
type: "tool-read",
state: "output-available",
toolCallId: "c2",
input: { path: "shot.png" },
output: { text: "Read image file [image/png].", images: [{ data: "AAAA", mimeType: "image/png" }] },
};
const html = renderToStaticMarkup(<ToolCallCard part={imgPart as never} />);
assert.match(html, /Read image file \[image\/png\]\./);
assert.match(html, /1 image attached to the model/);
assert.ok(!html.includes("AAAA"), "the image payload itself never renders");
const errPart = {
type: "tool-read",
state: "output-error",
toolCallId: "c3",
input: { path: "/gone.md" },
errorText: "ENOENT: no such file",
};
const errHtml = renderToStaticMarkup(<ToolCallCard part={errPart as never} />);
assert.match(errHtml, /Error/);
assert.match(errHtml, /ENOENT/);
assert.match(errHtml, /text-red-500/);
});
it("the tool-call card: find/grep headline the pattern, ls defaults to ~", () => {
const findHtml = renderToStaticMarkup(
<ToolCallCard part={{ type: "tool-find", state: "output-available", toolCallId: "c", input: { pattern: "*calculus*" }, output: "notes/calculus.md" } as never} />,
);
assert.match(findHtml, /find/);
assert.match(findHtml, /\*calculus\*/);
const lsHtml = renderToStaticMarkup(
<ToolCallCard part={{ type: "tool-ls", state: "output-available", toolCallId: "c", input: {}, output: "notes/" } as never} />,
);
assert.match(lsHtml, /ls/);
assert.match(lsHtml, /~/);
});
});