host-doc.ts
This file
Path
packages/agent-kit/src/host-doc.ts
307 lines · 10.2 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 1–8why, one step back1import { Brand } from "@repo/brand";2import type { AskListing } from "@repo/protocol/domain/ask";3import type { ProjectListing } from "@repo/protocol/domain/front-page";4import type { ProjectName } from "@repo/protocol/ids";5import type { Posture } from "@repo/protocol/posture";6import { Array as Arr, Option } from "effect";78import type { CommandDoc } from "./command-doc.ts";Merge redesign into mainoscabrielbefore adoptioncaedd21
line 9why, one step back9import { installCommand, pushCommand } from "./install.ts";Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 10–44why, one step back1011type Command = CommandDoc;1213type Commands = readonly CommandDoc[];1415export const MCP_PROTOCOL = "2026-07-28";1617const postureWords = {18 open: "Open",19 openCore: "Open core",20 openOnSchedule: "Open on schedule",21 openWithSealedEvidence: "Open with sealed evidence",22 sourceAvailable: "Source available",23} as const satisfies Record<Posture, string>;2425const code = (text: string) => `\`${text}\``;2627const counted = (count: number, one: string) =>28 `${count} ${one}${count === 1 ? "" : "s"}`;2930const page = (lines: readonly string[]) => `${lines.join("\n")}\n`;3132interface Known {33 readonly project?: string;34}3536const commandOf = (commands: Commands, words: string) =>37 Arr.findFirst(commands, ({ path }) => path.join(" ") === words);3839const usage = (40 command: Command,41 known: Known = {},42 flags: readonly ("ask" | "project")[] = []43) => {44 const valueOf = (name: string) =>Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
line 45why, one step back45 name === "project" ? (known.project ?? "<owner>/<name>") : `<${name}>`;Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 46–58why, one step back4647 return [48 Brand.cli,49 ...command.path,50 ...command.positional.map((name) => `<${name}>`),51 ...flags.flatMap((flag) =>52 command.flags.includes(`--${flag}`) && !command.positional.includes(flag)53 ? [`--${flag}`, valueOf(flag)]54 : []55 ),56 ].join(" ");57};58Merge build/1108 into mainoscabrielbefore adoption8d9ece9
line 59why, one step back59export const typed = (Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 60–68why, one step back60 commands: Commands,61 words: string,62 known: Known,63 flags: readonly ("ask" | "project")[] = []64) =>65 Option.map(commandOf(commands, words), (command) =>66 code(usage(command, known, flags))67 );68Merge build/1108 into mainoscabrielbefore adoption8d9ece9
line 69why, one step back69export const withCommand = (Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 70–102why, one step back70 command: Option.Option<string>,71 make: (typedCommand: string) => string72) => Option.toArray(Option.map(command, make));7374const takeAnAsk = (commands: Commands, known: Known) => {75 const front = typed(commands, "front", known);76 const asks = typed(commands, "asks", known, ["project"]);7778 const find = [79 ...Option.toArray(80 Option.map(front, (each) => `${each} lists the open asks across projects`)81 ),82 ...Option.toArray(83 Option.map(asks, (each) => `${each} lists one project's`)84 ),85 ];8687 const steps = [88 ...(find.length === 0 ? [] : [`Find one: ${find.join("; ")}.`]),89 ...withCommand(90 typed(commands, "ask", known, ["project"]),91 (each) => `Read it: ${each}.`92 ),93 ...withCommand(94 typed(commands, "claim", known, ["project"]),95 (each) =>96 `Claim it: ${each}. The claim prints your fork's remote; add it with ${code(`git remote add ${Brand.slug} <remote>`)}.`97 ),98 ...withCommand(99 typed(commands, "check", known),100 (each) =>101 `Change only the ask's territory, then run ${each} and fix everything it reports.`102 ),Merge redesign into mainoscabrielbefore adoptioncaedd21
line 103why, one step back103 `Push to your fork with ${code(pushCommand)}${Option.match(Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 104–166why, one step back104 typed(commands, "verdict", known, ["ask", "project"]),105 { onNone: () => "", onSome: (each) => `, then read the verdict: ${each}` }106 )}. A refusal names the command to run next.`,107 ];108109 return [110 "## Take an ask",111 "",112 ...steps.map((step, at) => `${at + 1}. ${step}`),113 "",114 ];115};116117const notes = ({ needsApproval, readOnly }: Command) => [118 ...(readOnly ? ["Only reads."] : []),119 ...(needsApproval ? [`Runs only with ${code("--yes")}.`] : []),120];121122const commandList = (commands: Commands) => [123 "## Commands",124 "",125 ...commands.map(126 (command) =>127 `- ${code(usage(command))}: ${[command.summary, ...notes(command)].join(" ")}`128 ),129 "",130];131132const projectPage = (webUrl: string, project: string) => `${webUrl}/${project}`;133134const projectFacts = (listing: ProjectListing) =>135 `${postureWords[listing.posture]}, ${counted(listing.openAsks, "open ask")}.`;136137const projectLine = (138 platformUrl: string,139 webUrl: Option.Option<string>,140 listing: ProjectListing141) =>142 Option.match(webUrl, {143 onNone: () =>144 `- ${listing.project}: ${projectFacts(listing)} Clone: ${code(`git clone ${platformUrl}/${listing.project}.git`)}.`,145 onSome: (web) =>146 `- [${listing.project}](${projectPage(web, listing.project)}/llms.txt): ${projectFacts(listing)}`,147 });148149export const frontLlms = (input: {150 readonly commands: Commands;151 readonly projects: readonly ProjectListing[];152 readonly platformUrl: string;153 readonly webUrl?: string;154}) => {155 const { commands, platformUrl, projects } = input;156 const webUrl = Option.fromUndefinedOr(input.webUrl);157 const served = Option.getOrElse(webUrl, () => platformUrl);158159 return page([160 `# ${Brand.name}`,161 "",162 `> ${Brand.name} is a Git platform where everything a project ships is public. A project states each change it wants as an ask, with a check that fails on main; you answer one with a commit, and the platform lands it with your credit only once its checks pass.`,163 "",164 ...Option.match(webUrl, {165 onNone: () => [],166 onSome: (web) => [Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
line 167why, one step back167 `The same facts read as Markdown: each project at ${web}/<owner>/<name>/llms.txt, and each ask at ${web}/<owner>/<name>/asks/<ask>.md. Every refusal, how git meets the platform, how a landing happens, the events and the guides are in ${web}/llms-full.txt.`,Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
line 168why, one step back168 "",Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
lines 169–170why, one step back169 `Guides and a reference written for people are at ${web}/docs, each page also as Markdown at ${web}/docs/<page>.md.`,170 "",Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 171–175why, one step back171 ],172 }),173 "## Install the CLI",174 "",175 "```sh",Merge build/1311-landing into mainoscabrielbefore adoption18b5418
line 176why, one step back176 installCommand(served),Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 177–230why, one step back177 "```",178 "",179 ...Option.match(commandOf(commands, "login"), {180 onNone: () => [],181 onSome: () => [182 "Then sign in once; git pushes to the platform with your token from then on:",183 "",184 "```sh",185 `${Brand.cli} login --url ${platformUrl}`,186 "```",187 "",188 ],189 }),190 "## Connect over MCP",191 "",192 `- Endpoint: ${platformUrl}/mcp (streamable HTTP, MCP ${MCP_PROTOCOL})${Option.match(193 webUrl,194 {195 onNone: () => "",196 onSome: (web) => `, described at ${web}/.well-known/mcp.json`,197 }198 )}.`,199 `- Auth: a bearer token from the platform's own OAuth server, which an MCP client finds at ${platformUrl}/.well-known/oauth-protected-resource; you sign in with your account on ${Brand.name}.`,200 ...withCommand(201 typed(commands, "mcp", {}),202 (each) =>203 `- Without a client that signs in: ${each} serves the same tools over stdio, with the token ${code(`${Brand.cli} login`)} stored.`204 ),205 `- Skills: ${served}/.well-known/agent-skills/index.json lists each project's contribute skill, with its digest.`,206 "",207 ...takeAnAsk(commands, {}),208 ...commandList(commands),209 "## Projects",210 "",211 ...(projects.length === 0212 ? ["No project is on the platform yet."]213 : projects.map((listing) => projectLine(platformUrl, webUrl, listing))),214 ]);215};216217const askNotes = (listing: AskListing) => [218 `Kind ${code(listing.kind)}, territory ${code(listing.territory)}.`,219 ...(listing.claimed ? ["Claimed."] : []),220 ...(listing.reserve === undefined ? [] : [`Held for ${listing.reserve}.`]),221 ...(listing.blockedBy.length === 0222 ? []223 : [`Waits for ${listing.blockedBy.map(code).join(", ")}.`]),224];225226const sentence = (text: string) => `${text.replace(/[.\s]+$/u, "")}.`;227228const askLine = (webUrl: string, project: string, listing: AskListing) =>229 `- [${listing.ask}](${projectPage(webUrl, project)}/asks/${listing.ask}.md): ${[sentence(listing.want), ...askNotes(listing)].join(" ")}`;230Merge build/1108 into mainoscabrielbefore adoption8d9ece9
lines 231–239why, one step back231export const indexBanner = (input: {232 readonly webUrl: string;233 readonly project?: ProjectName;234}) => {235 const { project, webUrl } = input;236237 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`}.`;238};239Merge fix/banner-below-title into mainoscabrielbefore adoptionca95612
lines 240–247why, one step back240export const underTitle = (text: string, banner: string) => {241 const end = text.indexOf("\n");242243 return text.startsWith("# ") && end !== -1244 ? `${text.slice(0, end)}\n\n${banner}\n\n${text.slice(end).replace(/^\n+/u, "")}`245 : `${banner}\n\n${text}`;246};247Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 248–261why, one step back248export const projectLlms = (input: {249 readonly listing: ProjectListing;250 readonly asks: readonly AskListing[];251 readonly commands: Commands;252 readonly platformUrl: string;253 readonly webUrl: string;254}) => {255 const { asks, commands, listing, platformUrl, webUrl } = input;256 const { project } = listing;257258 return page([259 `# ${project}`,260 "",261 `> A project on ${Brand.name}. Posture: ${postureWords[listing.posture]}. ${counted(asks.length, "open ask")}.`,Merge fix/banner-below-title into mainoscabrielbefore adoptionca95612
lines 262–263why, one step back262 "",263 indexBanner({ project, webUrl }),Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 264–291why, one step back264 "",265 `- Page: ${projectPage(webUrl, project)}`,266 `- Clone: ${code(`git clone ${platformUrl}/${project}.git`)}`,267 `- Everything else, and every command: ${webUrl}/llms.txt`,268 "",269 "## Open asks",270 "",271 ...(asks.length === 0272 ? ["No ask is open."]273 : asks.map((each) => askLine(webUrl, project, each))),274 "",275 ...takeAnAsk(commands, { project }).slice(0, -1),276 ]);277};278279export const missingProjectLlms = (input: {280 readonly project: Option.Option<ProjectName>;281 readonly webUrl: string;282}) =>283 page([284 "# Not found",285 "",286 `${Option.match(input.project, {287 onNone: () => "No such project",288 onSome: (project) => `No project named ${code(project)}`,289 })} is on ${Brand.name}. Every project is listed at ${input.webUrl}/llms.txt.`,290 ]);291Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
lines 292–293why, one step back292// No settled standard gives this card's shape: it follows the MCP server card293// draft, naming its authorization as RFC 9728's `resource_metadata`.Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 294–307why, one step back294export const mcpCard = (input: { readonly platformUrl: string }) => ({295 authentication: {296 required: true,297 resource_metadata: `${input.platformUrl}/.well-known/oauth-protected-resource`,298 schemes: ["bearer"],299 },300 capabilities: { prompts: {}, resources: {}, tools: {} },301 description: `The contracts of ${Brand.name} as MCP tools, each ask's brief as a resource, and the contribute skill as a prompt.`,302 name: Brand.name,303 protocolVersion: MCP_PROTOCOL,304 transport: { endpoint: `${input.platformUrl}/mcp`, type: "streamable-http" },305});306307export type McpCard = ReturnType<typeof mcpCard>;