Merge fix/banner-below-title into main
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parents 57bb629, 53896c9 · Browse files · 7 files·+65 added−32 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+65 added−32 removed
- tests:+34 added−16 removed
- other:+31 added−16 removed
Provenance
- Commit
ca95612- Tree
00dd2e0- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent 1
57bb629- Parent 2
53896c9
7 files changed+65 added−32 removed
modified:apps/web/src/features/agents/llms.ts+2 added-2 removed
1234545678910 unmodified lines/** * What an agent, or a person, reads first on the web host: `/llms.txt`, * `/llms-full.txt`, `/<project>/llms.txt` and the MCP card at * `/.well-known/mcp.json`, and the banner that opens the web's other * Markdown. The text lives in `@repo/agent-kit` (`host-doc`, which the * `/.well-known/mcp.json`, and the banner under the title of the web's * other Markdown. The text lives in `@repo/agent-kit` (`host-doc`, which the * platform's own `/` serves too, so both hosts say the same thing, and * `full-llms`, which only the web serves); the routes import it from here. */export { fullLlms } from "@repo/agent-kit/full-llms";10 unmodified linesmodified:apps/web/src/features/ask/markdown.ts+10 added-6 removed
2 unmodified lines3 * fetch, either with `Accept: text/markdown` on the ask's own URL or at the4 * same URL with `.md`. The request decides; no user-agent list does.5 *6 * The brief is the platform's: `showAsk` renders it once, and the web only7- * serves it, under the banner that names the web's indexes. A refusal is7+ * serves it, with the banner that names the web's indexes under its title. A refusal is8 * set the way `git push` printed it, from `@repo/protocol/render`9 * (AGENTS.md principle 3), then its next command.10 * Pure: a `Request` or an `Exit` in, a string or a `Response` out.11 */12-import { indexBanner } from "@repo/agent-kit/host-doc";12+import { indexBanner, underTitle } from "@repo/agent-kit/host-doc";13 import { Brand } from "@repo/brand";14 import type { Visibility } from "@repo/protocol/annotations";15 import type { ProjectName } from "@repo/protocol/ids";16 import { Refusal } from "@repo/protocol/refusal";135 unmodified lines152 "The platform did not answer, so the web cannot read this ask now. Ask again in a moment.",153 "",154 ].join("\n");155 156-/** Where the web's indexes are, for the banner over an ask's brief. */156+/** Where the web's indexes are, for the banner under an ask's title. */157 export interface AskIndex {158 readonly project: ProjectName;159 readonly webUrl: string;160 }161 162 /**163 * How reading an ask ended, as the Markdown response: the brief (200,164- * cacheable as its contract's visibility allows), opened by the banner165- * naming `index`'s `llms.txt` files; a refusal (404, its164+ * cacheable as its contract's visibility allows), with the banner naming165+ * `index`'s `llms.txt` files under its title; a refusal (404, its166 * Markdown, no banner); or no answer from the platform (502). Only a brief167 * is cached.168 */169 export const askMarkdownResponse = <E>(8 unmodified lines178 onSome: (refusal) =>179 markdown(refusalsMarkdown([refusal]), 404, "no-store"),180 }),181 onSuccess: ({ brief }) =>182- markdown(`${indexBanner(index)}\n\n${brief}`, 200, cacheFor(visibility)),182+ markdown(183+ underTitle(brief, indexBanner(index)),184+ 200,185+ cacheFor(visibility)186+ ),187 });188 189 /**190 * The answer to a path that can name no ask: a project's and an ask's names21 unmodified linesmodified:apps/web/src/routes/$project/asks/{$ask}[.]md.ts+2 added-2 removed
31 unmodified lines32333435363736373839404133 unmodified lines31 unmodified linesconst visibility = Context.get(ShowAsk.annotations, Visibility);
/** * The `.md` route's handler as a function of its client, which its test * drives with a stub platform: the brief `showAsk` gives, under the banner * naming this host's indexes, a refusal as a 404, or a 404 without asking * drives with a stub platform: the brief `showAsk` gives, with the banner * naming this host's indexes under its title, a refusal as a 404, or a 404 without asking * when the path can name no ask. */export const askMarkdownHandler = (clientFor: ClientFor) =>33 unmodified linesmodified:apps/web/test/ask-markdown.test.ts+9 added-6 removed
1 /**2 * An ask answers as Markdown, so a harness reads it with one plain fetch:3 * the ask's URL with `Accept: text/markdown`, or the same URL with `.md`.4- * The body is the banner naming the web's indexes, then the brief the5- * platform rendered (`showAsk`), untouched; an unknown ask is a 404 whose4+ * The body is the brief the platform rendered (`showAsk`), with the banner5+ * naming the web's indexes under its title; an unknown ask is a 404 whose6 * body is the refusal, as git would print it.7 * A browser asking for HTML gets the page.8 */9 import { describe, expect, it } from "@effect/vitest";23 unmodified lines33 34 /** Where the web's indexes are for datekit's asks, as the routes find them. */35 const index = { project, webUrl: WEB };36 37-/** An ask's Markdown as served: the banner naming the indexes, then the brief unchanged. */38-const served = `${indexBanner(index)}\n\n${brief}`;37+/** An ask's Markdown as served: the brief's title, the banner naming the indexes, then the rest of the brief unchanged. */38+const [title = "", ...rest] = brief.split("\n");39 40+const served = [title, "", indexBanner(index), ...rest].join("\n");41+42 const MARKDOWN = "text/markdown; charset=utf-8";43 44 const BROWSER =45 "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";264 unmodified lines310 });311 312 describe("an ask's Markdown with the index named", () => {313 it.effect(312- "opens with the banner naming its project's llms.txt, then the brief unchanged",314+ "opens with the brief's title, then the banner naming its project's llms.txt",315 () =>316 Effect.gen(function* () {317 const seen = yield* read(318 askMarkdownResponse(Exit.succeed({ brief }), "public", index)319 );320 321 expect(seen.status).toBe(200);322 expect(seen.body).toBe(served);323+ expect(seen.body.startsWith("# ")).toBeTruthy();321- expect(seen.body.split("\n")[0]).toContain(324+ expect(seen.body.split("\n")[2]).toContain(325 `${WEB}/${project}/llms.txt`326 );327 })328 );65 unmodified linesmodified:apps/web/test/llms.test.ts+3 added-3 removed
236 unmodified lines237 });238 239 const lines = linesOf(text);240 241- it("opens with the banner, then the project, its posture and how many asks are open", () => {241+ it("opens with the project, its posture and how many asks are open, then the banner", () => {242 expect(lines.slice(0, 5)).toStrictEqual([243- indexBanner({ project: datekit, webUrl }),244- "",243 "# datekit",244 "",245 `> A project on ${Brand.name}. Posture: Open with sealed evidence. 3 open asks.`,246+ "",247+ indexBanner({ project: datekit, webUrl }),248 ]);249 });250 251 it("gives its page, its clone URL and the platform's llms.txt", () => {189 unmodified linesmodified:packages/agent-kit/src/host-doc.ts+17 added-6 removed
6 unmodified lines7 * at `/` for an agent, with no web app's pages named when it knows of none.8 * `projectLlms` is the web's `/<project>/llms.txt`, with the project's open9 * asks, and `mcpCard` its `/.well-known/mcp.json`. With a web app,10 * `frontLlms` names `/llms-full.txt` (`full-llms.ts`), and `indexBanner`11- * opens every other Markdown answer the web serves, so a reader that lands11+ * sits under the title of every other Markdown answer the web serves, so a reader that lands12 * on one finds the rest.13 *14 * Pure: the hosts hand in what the platform lists and the CLI's commands15 * as this package's one list holds them, so no command is written here263 unmodified lines279 const askLine = (webUrl: string, project: string, listing: AskListing) =>280 `- [${listing.ask}](${projectPage(webUrl, project)}/asks/${listing.ask}.md): ${[sentence(listing.want), ...askNotes(listing)].join(" ")}`;281 282 /**283- * The line that opens a Markdown answer the web serves: where the index is,284- * where the full text is, and, for a project's answer, the project's own285- * index. One blockquote, so a reader that lands on any page finds the rest.283+ * The line under the title of a Markdown answer the web serves: where the284+ * index is, where the full text is, and, for a project's answer, the285+ * project's own index. One blockquote, so a reader that lands on any page286+ * finds the rest. It never comes first: an `llms.txt` opens with its `#`287+ * heading.288 */289 export const indexBanner = (input: {290 readonly webUrl: string;291 readonly project?: ProjectName;2 unmodified lines294 295 return `> For agents: the index is ${webUrl}/llms.txt, and everything beyond it (refusals, git, landings, events, guides) is ${webUrl}/llms-full.txt${project === undefined ? "" : `; this project's index is ${projectPage(webUrl, project)}/llms.txt`}.`;296 };297 298+/** `banner` under `text`'s `#` title, or on top of a text that has none. */299+export const underTitle = (text: string, banner: string) => {300+ const end = text.indexOf("\n");301+302+ return text.startsWith("# ") && end !== -1303+ ? `${text.slice(0, end)}\n\n${banner}\n\n${text.slice(end).replace(/^\n+/u, "")}`304+ : `${banner}\n\n${text}`;305+};306+307 /** `/<project>/llms.txt`: the project, its posture, how to clone it, its open asks and how to take one. */308 export const projectLlms = (input: {309 readonly listing: ProjectListing;310 readonly asks: readonly AskListing[];4 unmodified lines315 const { asks, commands, listing, platformUrl, webUrl } = input;316 const { project } = listing;317 318 return page([308- indexBanner({ project, webUrl }),309- "",319 `# ${project}`,320 "",321 `> A project on ${Brand.name}. Posture: ${postureWords[listing.posture]}. ${counted(asks.length, "open ask")}.`,322 "",323+ indexBanner({ project, webUrl }),324+ "",325 `- Page: ${projectPage(webUrl, project)}`,326 `- Clone: ${code(`git clone ${platformUrl}/${project}.git`)}`,327 `- Everything else, and every command: ${webUrl}/llms.txt`,328 "",48 unmodified linesmodified:packages/agent-kit/test/host-doc.test.ts+22 added-7 removed
10 unmodified lines11 import { ProjectName } from "@repo/protocol/ids";12 import { Effect } from "effect";13 14 import type { CommandDoc } from "../src/command-doc.ts";15-import { frontLlms, indexBanner, projectLlms } from "../src/host-doc.ts";15+import {16+ frontLlms,17+ indexBanner,18+ projectLlms,19+ underTitle,20+} from "../src/host-doc.ts";21 import { expectGolden } from "./golden.ts";22 23 const platformUrl = "https://platform-test.example.workers.dev";24 136 unmodified lines161 expect(banner).toContain(`${webUrl}/llms.txt`);162 expect(banner).toContain(`${webUrl}/llms-full.txt`);163 });164 165+ it("goes under a page's title, and on top of a page without one", () => {166+ const banner = indexBanner({ webUrl });167+168+ expect(underTitle("# A title\n\nThe body.\n", banner)).toBe(169+ `# A title\n\n${banner}\n\nThe body.\n`170+ );171+ expect(underTitle("No title here.\n", banner)).toBe(172+ `${banner}\n\nNo title here.\n`173+ );174+ });175+176 it("names a project's own index when it has one", () => {177 expect(178 indexBanner({ project: ProjectName.make("datekit"), webUrl })179 ).toContain(`${webUrl}/datekit/llms.txt`);180 });181 166- it("opens a project's llms.txt, then its heading", () => {182+ it("follows a project's heading and summary in its llms.txt", () => {183 const lines = linesOf(184 projectLlms({185 asks: [],186 commands,6 unmodified lines193 webUrl,194 })195 );196 197+ expect(lines[0]).toBe("# datekit");198+ expect(lines[2]?.startsWith("> A project on ")).toBeTruthy();181- expect(lines.slice(0, 3)).toStrictEqual([199+ expect(lines.slice(3, 6)).toStrictEqual([200+ "",201 indexBanner({ project: ProjectName.make("datekit"), webUrl }),202 "",184- "# datekit",203 ]);186- expect(lines[0]).toContain(`${webUrl}/llms.txt`);187- expect(lines[0]).toContain(`${webUrl}/llms-full.txt`);188- expect(lines[0]).toContain(`${webUrl}/datekit/llms.txt`);204 });205 });