Public: anyone can read this; the crew can change it.

Main green: tool docs in /llms.txt cap at 800 characters (find_tool has the rest); chart tooltip clamps in CSS; doc link #16814

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

main-red-2 → main 0 commits

  • Merged. main-red-2 was merged into main as fee65f0.

Review

Sign in to review this change.
11 files changed +77 −24
docs/features/data-browser.md +1 −1
@@ -30,6 +30,6 @@ Cost of a query: `query` also returns `rowsRead` (rows the query produced, the o
3030
3131 ## The API spec as a file (#7578)
3232
33 MCP `data` with `spec: true` lists operations (`area`, `method`, `path`, `summary`; 300 at most, with `total` saying how many matched) for what the forge's contract says as your role may call it; add `q` to narrow by words, or `repo` for the document that app serves at `/openapi.json` (the same door as its API tab: a 404 where you may not enter the app, "serves no /openapi.json" when it has none). `src/data/spec_scope.ts` reads it through `reference` (`src/contract/reference.ts`), the reading the web `/api` page and the terminal API screen (`src/tui/screens/api.ts`) already use.
33 MCP `data` with `spec: true` lists operations (`area`, `method`, `path`, `summary`; 300 at most, with `total` saying how many matched) for what the forge's contract says as your role may call it; add `q` to narrow by words, or `repo` for that app's own OpenAPI document (docs/features/api-reference.md; the same door as its API tab: a 404 where you may not enter the app, and a plain answer that it serves none when it has none). `src/data/spec_scope.ts` reads it through `reference` (`src/contract/reference.ts`), the reading the web `/api` page and the terminal API screen (`src/tui/screens/api.ts`) already use.
3434
3535 Three doors, one reading. In the data tree the spec is a file named `openapi.json`: the forge's own at the bottom of `/data` and of the terminal's Data screen (only for someone who sees any file there), and each app's after its environments (the app's Data tab on the web, the app node in the terminal; Enter or `l` opens it, `y` yanks `METHOD /path`). On the web it is `?spec=1` on `/data` and on `/:owner/:name/data`; a reader and a guest get the same 404 or sign-in as for the databases, and an app's document is asked through `appSpec`, which still checks `canEnterApp`. It reads the app's production environment only; a preview's document is not read here. The canonical place to read and try operations stays `/api` and `/:owner/:name/api` (and the terminal's API screen): the `openapi.json` nodes and the MCP tool link to them and add no second listing, only the same `reference` rows.
src/http/mcp.ts +5
@@ -106,6 +106,11 @@ function forTalk<T extends { inputSchema?: unknown }>(entry: T): T {
106106 /** The entries this caller may call, `report` and `start` included: what find_tool searches. */
107107 export const entriesFor = (ctx: Ctx, user: User) => toolEntries(TOOLS.filter((t) => listable(t, ctx, user)));
108108
109 /**
110 * A tool's whole `doc`, for a caller who may call it: what /llms.txt cuts short, find_tool returns.
111 */
112 export const docFor = (ctx: Ctx, user: User, name: string): string | undefined => TOOLS.find((t) => t.name === name && listable(t, ctx, user))?.doc;
113
109114 // One page of tools/list stays within this many bytes of tools; `nextCursor`
110115 // names the rest, so adding a tool never busts one response.
111116 export const TOOLS_PAGE_BYTES = 20_000;
src/http/mcp/tools/find_tool.ts +8 −3
@@ -3,7 +3,7 @@ import { FIND_MAX, matching, QUERY_MAX, talkLists } from "../catalog.ts";
33
44 export const tool: Tool = {
55 name: "find_tool",
6 doc: "`{ query }`: the tools whose name, description or plain-word keywords match every word (else the most words); filler words are ignored, with their one-line description and schema; a tool found is callable at once, listed or not; Talk's own agent, which can call only what it is listed, is found only those. `tools/list` with `{\"all\": true}` is the full list",
6 doc: "`{ query }`: the tools whose name, description or plain-word keywords match every word (else the most words); filler words are ignored, with their one-line description and schema (and, asked by its exact name, its whole doc); a tool found is callable at once, listed or not; Talk's own agent, which can call only what it is listed, is found only those. `tools/list` with `{\"all\": true}` is the full list",
77 description: "Find a tool by what it does: name, description, schema. Any tool is callable by name.",
88 inputSchema: {
99 type: "object",
@@ -15,7 +15,7 @@ export const tool: Tool = {
1515 const query = str(args["query"]).trim();
1616 if (query === "") return bad("invalid_query", "query is a word or two about what you want to do");
1717 // Lazy: mcp.ts imports the tool table, which holds this tool.
18 const { entriesFor } = await import("../../mcp.ts");
18 const { docFor, entriesFor } = await import("../../mcp.ts");
1919 const found = matching(
2020 // Talk's agent calls only what it is listed: it is never offered a tool it cannot call.
2121 entriesFor(ctx, user)
@@ -23,8 +23,13 @@ export const tool: Tool = {
2323 .map(({ name, description, inputSchema }) => ({ name, description, inputSchema })),
2424 query,
2525 );
26 // A tool asked for by its exact name comes first with its whole doc (/llms.txt cuts a long one
27 // short).
28 const exact = found.find((t) => t.name === query);
29 const doc = exact === undefined ? undefined : docFor(ctx, user, query);
30 const ranked = exact === undefined ? found : [doc === undefined ? exact : { ...exact, doc }, ...found.filter((t) => t !== exact)];
2631 return good({
27 tools: found.slice(0, FIND_MAX),
32 tools: ranked.slice(0, FIND_MAX),
2833 ...(found.length > FIND_MAX ? { more: found.length - FIND_MAX } : {}),
2934 });
3035 },
src/web/chart_hover.ts +3 −3
@@ -28,10 +28,10 @@ export const chartHoverJs = /* js */ `
2828 }
2929 var shown = null, pending = false;
3030 function place(pt) {
31 var w = tip.offsetWidth, h = tip.offsetHeight;
32 var left = Math.min(Math.max(8, pt.x + 12), window.innerWidth - w - 8);
31 // Across, CSS keeps the tip inside the viewport (.chart-tip); only its height is read here.
32 var h = tip.offsetHeight;
3333 var top = pt.y - h - 12 < 8 ? pt.y + 16 : pt.y - h - 12;
34 tip.style.left = left + 'px'; tip.style.top = top + 'px';
34 tip.style.setProperty('--x', pt.x + 'px'); tip.style.top = top + 'px';
3535 }
3636 function open(head, rows, pt) {
3737 tip.textContent = ''; tip.appendChild(head); if (rows) tip.appendChild(rows);
src/web/llms_tools.ts +14 −1
@@ -15,12 +15,25 @@ export type Listed = Pick<Tool, "name" | "description" | "doc" | "writes" | "adm
1515
1616 const oneLine = (s: string): string => s.replace(/\s+/g, " ").trim();
1717
18 /**
19 * The most of a tool's doc one line inlines. Every tool adds its doc to this text, which has a byte
20 * budget per role (test/llms-budget.test.ts), so a long doc is cut at a word and the line names the
21 * door to the whole of it: `find_tool` with the tool's exact name returns its `doc`.
22 */
23 export const LINE_DOC_MAX = 800;
24
25 const bounded = (name: string, doc: string): string => {
26 if (doc.length <= LINE_DOC_MAX) return doc;
27 const cut = doc.slice(0, doc.lastIndexOf(" ", LINE_DOC_MAX)).replace(/[\s,;:(]+$/, "");
28 return `${cut} … (all of it: find_tool \`{ query: "${name}" }\`)`;
29 };
30
1831 export function toolLine(t: Listed): string {
1932 const admin = t.adminOnly === true || t.needsAdminScope === true ? " (admin)" : "";
2033 const writes = t.writes ? " (writes)" : "";
2134 // The same list the MCP's anonymous gate reads (core/mcp_card.ts).
2235 const open = TOKEN_FREE_TOOLS.includes(t.name) ? " (no account)" : "";
23 return `- ${t.name}: ${oneLine(t.doc ?? t.description)}${admin}${writes}${open}`;
36 return `- ${t.name}: ${bounded(t.name, oneLine(t.doc ?? t.description))}${admin}${writes}${open}`;
2437 }
2538
2639 /** What every "planned first" in a tool line means, said once at the head of the list. */
src/web/style/content.ts +1 −1
@@ -234,7 +234,7 @@ a.where-place, button.where-place { cursor: pointer; }
234234 .chart-mark-hit { stroke: transparent; stroke-width: 8; vector-effect: non-scaling-stroke; pointer-events: stroke; }
235235 .chart-mark { pointer-events: none; stroke: var(--muted-fg); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
236236 .chart-cross { stroke: var(--fg); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
237 .chart-tip { margin: 0; inset: auto; overflow: visible; max-width: min(320px, calc(100vw - 16px)); padding: 6px 8px; font-size: var(--fs-min); line-height: 16px; font-variant-numeric: tabular-nums; color: var(--fg); background: var(--muted); border: 0; border-radius: var(--radius); pointer-events: none; }
237 .chart-tip { margin: 0; inset: auto; overflow: visible; max-width: min(320px, calc(100vw - 16px)); padding: 6px 8px; font-size: var(--fs-min); line-height: 16px; font-variant-numeric: tabular-nums; color: var(--fg); background: var(--muted); border: 0; border-radius: var(--radius); pointer-events: none; left: max(8px, calc(var(--x, 0px) + 12px)); translate: min(0px, calc(100vw - 8px - 100% - max(8px, calc(var(--x, 0px) + 12px)))) 0; }
238238 .chart-tip > div > div { display: flex; justify-content: space-between; gap: 16px; }
239239 .chart-tip > div > div > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted-fg); }
240240 .chart .bar, .chart .cell { fill: currentColor; }
test/chart-hover-script.test.ts +3 −2
@@ -5,7 +5,8 @@ import { chartHoverJs } from "../src/web/chart_hover.ts";
55 type El = any;
66 function dom(chartCount = 10) {
77 const mk = (tag = "div", attrs: Record<string, string> = {}): El => {
8 const e: El = { tag, attrs: { ...attrs }, kids: [], text: "", style: {}, parent: null, open: false, offsetWidth: 100, offsetHeight: 40 };
8 const e: El = { tag, attrs: { ...attrs }, kids: [], text: "", style: {}, parent: null, open: false, offsetHeight: 40 };
9 e.style.setProperty = (k: string, v: string) => (e.style[k] = v);
910 e.setAttribute = (k: string, v: unknown) => (e.attrs[k] = String(v));
1011 e.getAttribute = (k: string) => e.attrs[k] ?? null;
1112 e.appendChild = (c: El) => (c.parent = e, e.kids.push(c), c);
@@ -48,7 +49,7 @@ function dom(chartCount = 10) {
4849 querySelectorAll: () => charts,
4950 addEventListener: (n: string, f: (e: El) => void) => (listeners[n] ??= []).push(f),
5051 };
51 new Function("document", "window", chartHoverJs)(document, { innerWidth: 800 });
52 new Function("document", "window", chartHoverJs)(document, {});
5253 const tip = body.kids[0]!;
5354 const fire = (n: string, e: El) => listeners[n]?.forEach((f) => f({ preventDefault() { e.prevented = true; }, ...e }));
5455 return { tip, hits, mark, charts, fire };
test/held.test.ts +4 −1
@@ -89,7 +89,10 @@ describe("the memory sampler", () => {
8989 try {
9090 probe.add(4);
9191 sampler.tick();
92 const lines = info.mock.calls.map((call) => String(call[0]));
92 // Only the memory and held lines: a job line joins them when any job on the thread (another
93 // test file's, in a shared process) grew by 1 MiB since the last read
94 // (test/job-alloc.test.ts).
95 const lines = info.mock.calls.map((call) => String(call[0])).filter((l) => !l.startsWith("memory allocated by jobs"));
9396 expect(lines.map((l) => l.slice(0, l.indexOf(":")))).toEqual(["memory main", "memory holds", "memory main", "memory holds"]);
9497 expect(lines[1]).toStartWith("memory holds: ");
9598 expect(lines[1]!.split(": ")[1]!.split(", ")).toContain("probe 3");
test/llms-budget.test.ts +3 −2
@@ -59,8 +59,9 @@ const get = async (token?: string): Promise<string> =>
5959 * add about 40 to 330 bytes to it. Only an agent with an admin token reads this text, and few do,
6060 * so the cost of the room is small. Raised to 98,500 for cut_wave (admin 98,345), then to 98,700
6161 * for the allocation tool (#8718; admin 98,516), then to 99,200 for the app_flags tool (#1830;
62 * admin 98,939). Raised to 100,700 for the profile tool's `gift` action (admin 99,756; 100,036 with the changes
63 * tool of #10839).
62 * admin 98,939). Raised to 100,700 for the profile tool's `gift` action (admin 99,756; 100,036 with
63 * the changes tool of #10839). Then a tool's line inlines at most `LINE_DOC_MAX` (800) characters
64 * of its doc and names find_tool, which returns the whole of it: admin 92,689, signed-in 70,251.
6465 */
6566 const BUDGET = { anonymous: 9_250, signedIn: 84_100, admin: 100_700 } as const;
6667
test/llms-tools.test.ts +25 −6
@@ -1,6 +1,6 @@
11 /**
22 * /llms.txt's `## MCP tools` section is the generated tool index and `report`, line for line, each
3 * by its `doc`.
3 * by its `doc`, a long one cut at a word with the door to the rest.
44 */
55 import { TOKEN_FREE_TOOLS } from "../src/core/mcp_card.ts";
66 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
@@ -14,7 +14,7 @@ import { OFFER_TOOL, REPORT_TOOL, START_TOOL } from "../src/http/mcp.ts";
1414 import { TOOLS } from "../src/http/mcp/tools.ts";
1515 import { createToken } from "../src/core/tokens.ts";
1616 import { createUser } from "../src/core/users.ts";
17 import { PLANNED_LINE, type Listed } from "../src/web/llms_tools.ts";
17 import { LINE_DOC_MAX, PLANNED_LINE, type Listed } from "../src/web/llms_tools.ts";
1818
1919 describe("/llms.txt MCP tools", () => {
2020 let dataDir: string;
@@ -55,11 +55,30 @@ describe("/llms.txt MCP tools", () => {
5555 expect(start).toBeGreaterThan(-1);
5656 const end = lines.findIndex((l, i) => i > start && l.startsWith("## "));
5757 const listed = lines.slice(start + 1, end).filter((l) => l.startsWith("- "));
58 const expected = [...TOOLS, REPORT_TOOL, START_TOOL, OFFER_TOOL].map((t: Listed) => {
58 const all: Listed[] = [...TOOLS, REPORT_TOOL, START_TOOL, OFFER_TOOL];
59 expect(listed.map((l) => l.slice(2, l.indexOf(":")))).toEqual(all.map((t) => t.name));
60 for (const [i, t] of all.entries()) {
5961 const admin = t.adminOnly === true || t.needsAdminScope === true ? " (admin)" : "";
60 return `- ${t.name}: ${(t.doc ?? t.description).replace(/\s+/g, " ").trim()}${admin}${t.writes ? " (writes)" : ""}${TOKEN_FREE_TOOLS.includes(t.name) ? " (no account)" : ""}`;
61 });
62 expect(listed).toEqual(expected);
62 const flags = `${admin}${t.writes ? " (writes)" : ""}${TOKEN_FREE_TOOLS.includes(t.name) ? " (no account)" : ""}`;
63 const doc = (t.doc ?? t.description).replace(/\s+/g, " ").trim();
64 // A doc within the bound is inlined whole; a longer one is cut at a word and names the door.
65 if (doc.length <= LINE_DOC_MAX) expect(listed[i]).toBe(`- ${t.name}: ${doc}${flags}`);
66 else {
67 const pointer = ` … (all of it: find_tool \`{ query: "${t.name}" }\`)${flags}`;
68 expect(listed[i]!.endsWith(pointer), t.name).toBe(true);
69 const kept = listed[i]!.slice(`- ${t.name}: `.length, -pointer.length);
70 expect(doc.startsWith(kept) && kept.length <= LINE_DOC_MAX && kept.length > LINE_DOC_MAX / 2, t.name).toBe(true);
71 }
72 }
73 // The door gives the whole doc of a tool whose line is cut.
74 const long = TOOLS.find((t) => (t.doc ?? "").length > LINE_DOC_MAX * 2)!;
75 const rpc = await fetch(`${servers.url}/mcp`, {
76 method: "POST",
77 headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` },
78 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "find_tool", arguments: { query: long.name } } }),
79 }).then((r) => r.json() as Promise<{ result: { content: { text: string }[] } }>);
80 const found = JSON.parse(rpc.result.content[0]!.text) as { tools: { name: string; doc?: string }[] };
81 expect(found.tools[0]).toMatchObject({ name: long.name, doc: long.doc });
6382 // What every "planned first" means is said once, at the head of the list, not in each line.
6483 expect(lines[start + 2]).toBe("A tool with `dryRun` only plans unless it is `false`; \"planned first\" below means that.");
6584 expect(listed.filter((l) => l.includes("unless `false`"))).toEqual([]);
test/mcp-tools.test.ts +10 −4
@@ -13,7 +13,7 @@ import { indexText, toolFiles } from "../scripts/mcp-tools.ts";
1313 import { OFFER_TOOL, REPORT_TOOL, START_TOOL, toolNames } from "../src/http/mcp.ts";
1414 import { byName } from "../src/http/mcp/shared.ts";
1515 import { TOOLS } from "../src/http/mcp/tools.ts";
16 import { toolsSection } from "../src/web/llms_tools.ts";
16 import { LINE_DOC_MAX, toolsSection } from "../src/web/llms_tools.ts";
1717
1818 const ROOT = join(import.meta.dir, "..");
1919 const read = (path: string) => readFileSync(join(ROOT, path), "utf8");
@@ -66,11 +66,17 @@ describe("the gathered tools", () => {
6666 });
6767
6868 describe("the live tool list", () => {
69 test("every tool's `doc` is its line in /llms.txt's tools section", () => {
69 // Up to LINE_DOC_MAX characters, the doc is the line; past it, the line is the doc cut at a word
70 // and the find_tool pointer, and find_tool returns the whole doc (test/llms-tools.test.ts).
71 test("every tool's `doc` is its line in /llms.txt's tools section, up to the cap and then the find_tool pointer", () => {
7072 const section = toolsSection([...TOOLS, REPORT_TOOL, START_TOOL, OFFER_TOOL]);
7173 for (const t of [...TOOLS, REPORT_TOOL, START_TOOL, OFFER_TOOL]) {
72 const line = section.find((l) => l.startsWith(`- ${t.name}: `));
73 expect([t.name, line?.includes(t.doc ?? t.description) ?? false]).toEqual([t.name, true]);
74 const line = section.find((l) => l.startsWith(`- ${t.name}: `)) ?? "";
75 const doc = (t.doc ?? t.description).replace(/\s+/g, " ").trim();
76 const pointer = ` … (all of it: find_tool \`{ query: "${t.name}" }\`)`;
77 const kept = doc.length <= LINE_DOC_MAX ? doc : line.slice(`- ${t.name}: `.length, line.indexOf(pointer));
78 const holds = doc.length <= LINE_DOC_MAX ? line.includes(doc) : line.includes(pointer) && kept.length > 0 && kept.length <= LINE_DOC_MAX && doc.startsWith(kept);
79 expect([t.name, holds]).toEqual([t.name, true]);
7480 }
7581 expect(section.filter((l) => l.startsWith("- ")).length).toBe(TOOLS.length + 3);
7682 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs