Skip to content
Myr

Test how the platform's / reads Accept, and keep one MCP protocol constant

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- home.test.ts: each Accept a client sends picks HTML or Markdown as the header's qualities say (none, */*, a browser's full header, q-values either way, text/plain beside text/html, q=0). Seen red by planting `>` for `>=` in wantsMarkdown. - home.test.ts: on a host with no web app, the Markdown is frontLlms without a webUrl, so the platform's Option-to-optional hand-off is held. - MCP_PROTOCOL is exported from @repo/agent-kit/host-doc and home.ts imports it, so the page and the Markdown cannot name different versions. - Docstrings on rangesOf and qualityOf now say what they compute (all ranges; the highest quality among the named types).

authored by oscabriel · committed by oscabriel · parent a00d240 · Browse files · 3 files+51 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+51 added−7 removed

  • tests:+47 added−0 removed
  • other:+4 added−7 removed

3 files+51 added−7 removed

modified:apps/platform/src/home.ts+3 added-6 removed
11 unmodified lines
12 * value that reaches the HTML is escaped. Not a redirect: the web app is a13 * link (W9-D11).14 */15import { commandDocs } from "@repo/agent-kit/command-doc";16import { frontLlms } from "@repo/agent-kit/host-doc";16import { frontLlms, MCP_PROTOCOL } from "@repo/agent-kit/host-doc";17import { Brand } from "@repo/brand";18import { FrontPage } from "@repo/project/front-page";19import { Contracts } from "@repo/protocol/contracts";20import type { ProjectListing } from "@repo/protocol/domain/front-page";
1 unmodified line
2223import { escapeHtml, page } from "./auth/pages.ts";24import { HostInfo } from "./host-info.ts";2526/** The MCP protocol the platform serves over HTTP. */27const MCP_PROTOCOL = "2026-07-28";2826/** A minute: the page changes only when a project is made. */27const BRIEFLY = "public, max-age=60";2829/** The CLI's commands, as the platform's skill and the web's `llms.txt` list them. */30const commands = commandDocs(Contracts);3135/** One media range of an `Accept` header: its type and its quality. */32/** The media ranges of an `Accept` header, each its type and its quality. */33const rangesOf = (accept: string) =>34 accept.split(",").map((range) => {35 const [type = "", ...params] = range.split(";").map((part) => part.trim());36
9 unmodified lines
4647 return { quality, type: type.toLowerCase() };48 });4953/** The quality `ranges` give the first of `types` they name exactly; 0 for none. */50/** The highest quality `ranges` give any of `types` by name; 0 for none. */51const qualityOf = (52 ranges: ReturnType<typeof rangesOf>,53 types: readonly string[]54) =>
149 unmodified lines
modified:apps/platform/test/home.test.ts+47 added
158 unmodified lines
159 expect(plain.text).toBe(expected);160 })161 );162163 it.effect(164 "gives an agent the platform's own Markdown on a host with no web app",165 () =>166 Effect.gen(function* () {167 const { text, type } = yield* home(168 projects,169 { headers: { accept: "text/markdown" } },170 Option.none()171 );172173 expect({ text, type }).toStrictEqual({174 text: frontLlms({175 commands: commandDocs(Contracts),176 platformUrl: origin,177 projects,178 }),179 type: "text/markdown; charset=utf-8",180 });181 })182 );183184 it.effect.each([185 { accept: undefined, wants: "html" },186 { accept: "*/*", wants: "html" },187 {188 accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",189 wants: "html",190 },191 { accept: "text/html, text/markdown;q=0.5", wants: "html" },192 { accept: "text/html;q=0.5, text/markdown", wants: "markdown" },193 { accept: "text/plain, text/html", wants: "markdown" },194 { accept: "text/markdown;q=0, text/html;q=0.1", wants: "html" },195 ])("answers Accept $accept with $wants", ({ accept, wants }) =>196 Effect.gen(function* () {197 const { type } = yield* home(198 projects,199 accept === undefined ? {} : { headers: { accept } }200 );201202 expect(type).toBe(203 wants === "html"204 ? "text/html; charset=utf-8"205 : "text/markdown; charset=utf-8"206 );207 })208 );209210 it.effect("answers a stale credential, as every public path does", () =>211 Effect.gen(function* () {212 const { status, text } = yield* home(projects, {213 headers: { ...html.headers, authorization: "Bearer nope" },
18 unmodified lines
modified:packages/agent-kit/src/host-doc.ts+1 added-1 removed
25 unmodified lines
2627type Commands = readonly CommandDoc[];2829/** The MCP protocol the platform serves over HTTP. */30const MCP_PROTOCOL = "2026-07-28";30export const MCP_PROTOCOL = "2026-07-28";3132/** Each posture as GLOSSARY.md names it. */33const postureWords = {34 open: "Open",
312 unmodified lines