Skip to content
Myr

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

7 files+65 added−32 removed

modified:apps/web/src/features/agents/llms.ts+2 added-2 removed
modified:apps/web/src/features/ask/markdown.ts+10 added-6 removed
2 unmodified lines
3 * 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 */12import { indexBanner } from "@repo/agent-kit/host-doc";12import { indexBanner, underTitle } from "@repo/agent-kit/host-doc";13import { Brand } from "@repo/brand";14import type { Visibility } from "@repo/protocol/annotations";15import type { ProjectName } from "@repo/protocol/ids";16import { Refusal } from "@repo/protocol/refusal";
135 unmodified lines
152 "The platform did not answer, so the web cannot read this ask now. Ask again in a moment.",153 "",154].join("\n");155156/** 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. */157export interface AskIndex {158 readonly project: ProjectName;159 readonly webUrl: string;160}161162/**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 */169export const askMarkdownResponse = <E>(
8 unmodified lines
178 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 });188189/**190 * The answer to a path that can name no ask: a project's and an ask's names
21 unmodified lines
modified:apps/web/src/routes/$project/asks/{$ask}[.]md.ts+2 added-2 removed
modified: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 */9import { describe, expect, it } from "@effect/vitest";
23 unmodified lines
3334/** Where the web's indexes are for datekit's asks, as the routes find them. */35const index = { project, webUrl: WEB };3637/** An ask's Markdown as served: the banner naming the indexes, then the brief unchanged. */38const 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. */38const [title = "", ...rest] = brief.split("\n");3940const served = [title, "", indexBanner(index), ...rest].join("\n");4142const MARKDOWN = "text/markdown; charset=utf-8";4344const BROWSER =45 "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
264 unmodified lines
310});311312describe("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 );320321 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 lines
modified:apps/web/test/llms.test.ts+3 added-3 removed
236 unmodified lines
237 });238239 const lines = linesOf(text);240241 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 });250251 it("gives its page, its clone URL and the platform's llms.txt", () => {
189 unmodified lines
modified:packages/agent-kit/src/host-doc.ts+17 added-6 removed
6 unmodified lines
7 * 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 here
263 unmodified lines
279const askLine = (webUrl: string, project: string, listing: AskListing) =>280 `- [${listing.ask}](${projectPage(webUrl, project)}/asks/${listing.ask}.md): ${[sentence(listing.want), ...askNotes(listing)].join(" ")}`;281282/**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 */289export const indexBanner = (input: {290 readonly webUrl: string;291 readonly project?: ProjectName;
2 unmodified lines
294295 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};297298/** `banner` under `text`'s `#` title, or on top of a text that has none. */299export const underTitle = (text: string, banner: string) => {300 const end = text.indexOf("\n");301302 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};306307/** `/<project>/llms.txt`: the project, its posture, how to clone it, its open asks and how to take one. */308export const projectLlms = (input: {309 readonly listing: ProjectListing;310 readonly asks: readonly AskListing[];
4 unmodified lines
315 const { asks, commands, listing, platformUrl, webUrl } = input;316 const { project } = listing;317318 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 lines
modified:packages/agent-kit/test/host-doc.test.ts+22 added-7 removed
10 unmodified lines
11import { ProjectName } from "@repo/protocol/ids";12import { Effect } from "effect";1314import type { CommandDoc } from "../src/command-doc.ts";15import { frontLlms, indexBanner, projectLlms } from "../src/host-doc.ts";15import {16 frontLlms,17 indexBanner,18 projectLlms,19 underTitle,20} from "../src/host-doc.ts";21import { expectGolden } from "./golden.ts";2223const platformUrl = "https://platform-test.example.workers.dev";24
136 unmodified lines
161 expect(banner).toContain(`${webUrl}/llms.txt`);162 expect(banner).toContain(`${webUrl}/llms-full.txt`);163 });164165 it("goes under a page's title, and on top of a page without one", () => {166 const banner = indexBanner({ webUrl });167168 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 });175176 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 });181166 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 lines
193 webUrl,194 })195 );196197 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});