Public: anyone can read this; the crew can change it.
/llms.txt has a size ceiling per role and a test that fails when a role's manifest grows past it #15649
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15635-llms-txt-has-a-size-ceiling-per-role-and → main 0 commits fork 3 threads · 3 unresolved
1 file
changed +36
−6
test/llms-budget.test.ts +36 −6
| @@ -52,13 +52,43 @@ const get = async (token?: string): Promise<string> => | ||
| 52 | 52 | */ |
| 53 | 53 | const BUDGET = { anonymous: 9_100, signedIn: 82_300, admin: 94_100 } as const; |
| 54 | 54 | |
| 55 | /** Sections are cut at "## " headings; the lead before the first one is its own. */ | |
| 56 | function sections(text: string): { name: string; bytes: number }[] { | |
| 57 | const out: { name: string; bytes: number }[] = []; | |
| 58 | let name = "(head)"; | |
| 59 | let chunk: string[] = []; | |
| 60 | const flush = (): void => { if (chunk.length > 0) out.push({ name, bytes: Buffer.byteLength(chunk.join("\n") + "\n") }); }; | |
| 61 | for (const line of text.split("\n")) { | |
| 62 | if (line.startsWith("## ")) { flush(); name = line.slice(3); chunk = []; } | |
| 63 | chunk.push(line); | |
| 64 | } | |
| 65 | flush(); | |
| 66 | return out; | |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * The failure message for a text over its ceiling, naming its five largest sections; null when | |
| 71 | * within. | |
| 72 | */ | |
| 73 | function overBudget(role: string, text: string, ceiling: number): string | null { | |
| 74 | const size = Buffer.byteLength(text); | |
| 75 | if (size <= ceiling) return null; | |
| 76 | const top = sections(text).sort((a, b) => b.bytes - a.bytes).slice(0, 5).map((s) => `${s.name}: ${s.bytes}`).join("; "); | |
| 77 | return `${role} manifest is ${size} bytes, ceiling ${ceiling}. Five largest sections: ${top}`; | |
| 78 | } | |
| 79 | ||
| 80 | test("the over-budget message names the five largest sections, largest first", () => { | |
| 81 | const text = ["lead", ...["a", "b", "c", "d", "e", "f"].flatMap((n, i) => [`## ${n}`, "x".repeat(10 * (6 - i))])].join("\n"); | |
| 82 | const msg = overBudget("anonymous", text, 10) ?? ""; | |
| 83 | expect(msg).toContain("anonymous manifest is"); | |
| 84 | expect(msg).toContain("Five largest sections: a: 66; b: 56; c: 46; d: 36; e: 26"); | |
| 85 | expect(msg).not.toContain("f:"); | |
| 86 | expect(overBudget("anonymous", text, 10_000)).toBeNull(); | |
| 87 | }); | |
| 88 | ||
| 55 | 89 | test("/llms.txt stays under its byte budget for each role", async () => { |
| 56 | const sizes = { | |
| 57 | anonymous: Buffer.byteLength(await get()), | |
| 58 | signedIn: Buffer.byteLength(await get(tokens.bob)), | |
| 59 | admin: Buffer.byteLength(await get(tokens.alice)), | |
| 60 | }; | |
| 61 | for (const role of Object.keys(BUDGET) as (keyof typeof BUDGET)[]) expect(sizes[role]).toBeLessThanOrEqual(BUDGET[role]); | |
| 90 | const texts = { anonymous: await get(), signedIn: await get(tokens.bob), admin: await get(tokens.alice) }; | |
| 91 | for (const role of Object.keys(BUDGET) as (keyof typeof BUDGET)[]) expect(overBudget(role, texts[role], BUDGET[role])).toBeNull(); | |
| 62 | 92 | }); |
| 63 | 93 | |
| 64 | 94 | test("the anonymous text keeps the MCP, OpenAPI and report doors, and the guide one line each", async () => { |
new above
offline