agent-setup.ts
This file
Path
packages/agent-kit/src/agent-setup.ts
351 lines · 10.2 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 1why, one step back1import { Brand } from "@repo/brand";Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 2–4why, one step back2import { PolicyInput } from "@repo/protocol/domain/policy";3import { groups } from "@repo/protocol/refusal";4import { Array as Arr, Schema } from "effect";Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 5–6why, one step back56import type { CommandDoc } from "./command-doc.ts";Merge build/1311-landing into mainoscabrielbefore adoption18b5418
line 7why, one step back7import { installCommand } from "./install.ts";Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 8why, one step back8import { mcpServersFor } from "./platform.ts";Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 9–10why, one step back9import { span } from "./sections.ts";10import { code, listed, page, printJson, table } from "./text.ts";Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 11–12why, one step back1112export interface SetupSnippet {Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 13–14why, one step back13 /** A short name, for a tab or a list of choices: "Cursor", "npm". */14 readonly name: string;Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 15–31why, one step back15 readonly label: string;16 readonly language: "sh" | "json" | "text";17 readonly text: string;18}1920export interface SetupChannel {21 readonly title: string;22 readonly useWhen: string;23 readonly snippets: readonly SetupSnippet[];24}2526export interface SetupInput {27 readonly commands: readonly CommandDoc[];28 readonly platformUrl: string;29 readonly webUrl: string;30}31Merge redesign into mainoscabrielbefore adoptioncaedd21
line 32why, one step back32export const hasCommand = (commands: readonly CommandDoc[], words: string) =>Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 33–37why, one step back33 Arr.some(commands, ({ path }) => path.join(" ") === words);3435const json = (value: Parameters<typeof printJson>[0]) =>36 printJson(value).trimEnd();37Merge redesign into mainoscabrielbefore adoptioncaedd21
line 38why, one step back38export const remoteMcp = ({ platformUrl }: SetupInput): SetupChannel => ({Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 39–42why, one step back39 snippets: [40 {41 label: "Claude Code, then /mcp in a session to sign in",42 language: "sh",Merge redesign into mainoscabrielbefore adoptioncaedd21
line 43why, one step back43 name: "Claude Code",Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 44–48why, one step back44 text: `claude mcp add --transport http ${Brand.slug} ${platformUrl}/mcp`,45 },46 {47 label: "Cursor, in .cursor/mcp.json",48 language: "json",Merge redesign into mainoscabrielbefore adoptioncaedd21
line 49why, one step back49 name: "Cursor",Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 50–54why, one step back50 text: json({ mcpServers: mcpServersFor(platformUrl, "cursor") }),51 },52 {53 label: "VS Code, in .vscode/mcp.json",54 language: "json",Merge redesign into mainoscabrielbefore adoptioncaedd21
line 55why, one step back55 name: "VS Code",Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 56–62why, one step back56 text: json({ servers: mcpServersFor(platformUrl, "claude") }),57 },58 ],59 title: "Remote MCP",60 useWhen: `Your client signs in over OAuth: it opens a browser once, you sign in with your account on ${Brand.name}, and it calls the platform's tools at ${platformUrl}/mcp.`,61});62Merge redesign into mainoscabrielbefore adoptioncaedd21
line 63why, one step back63export const stdioMcp = (): SetupChannel => ({Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 64–67why, one step back64 snippets: [65 {66 label: "The server's command, once you have signed in with the CLI",67 language: "sh",Merge redesign into mainoscabrielbefore adoptioncaedd21
line 68why, one step back68 name: "stdio",Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 69–75why, one step back69 text: `${Brand.cli} mcp`,70 },71 ],72 title: "MCP over stdio",73 useWhen: `Your client starts its MCP servers as local commands, or cannot sign in over OAuth: the CLI serves the same tools over stdio, with the token the CLI stored when you signed in.`,74});75Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 76–87why, one step back76/** The install script's snippet, the CLI's first step on `/agents.md` and the Install page alike. */77export const installScript = ({78 webUrl,79}: Pick<SetupInput, "webUrl">): SetupSnippet => ({80 label: "Install",81 language: "sh",82 name: "Install script",83 text: installCommand(webUrl),84});8586/** Signing in with the CLI, once its commands have `login`; none otherwise. */87export const signIn = ({Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 88–89why, one step back88 commands,89 platformUrl,Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 90–103why, one step back90}: Pick<SetupInput, "commands" | "platformUrl">): readonly SetupSnippet[] =>91 hasCommand(commands, "login")92 ? [93 {94 label: "Sign in once; git pushes with your token from then on",95 language: "sh",96 name: "Sign in",97 text: `${Brand.cli} login --url ${platformUrl}`,98 },99 ]100 : [];101102export const theCli = (input: SetupInput): SetupChannel => ({103 snippets: [installScript(input), ...signIn(input)],Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 104–107why, one step back104 title: "The CLI",105 useWhen: `Your agent has a shell: it finds and claims asks, checks an answer before it pushes and reads verdicts with the CLI, and pushes with git.`,106});107Merge redesign into mainoscabrielbefore adoptioncaedd21
line 108why, one step back108export const anyAgent = ({ webUrl }: SetupInput): SetupChannel => ({Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 109–112why, one step back109 snippets: [110 {111 label: "Paste into the agent's prompt",112 language: "text",Merge redesign into mainoscabrielbefore adoptioncaedd21
line 113why, one step back113 name: "Prompt",Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
line 114why, one step back114 text: `Use ${webUrl}/llms.txt as the source of truth for ${Brand.name}: it says how to take an ask and lists every command and project. Each ask reads as Markdown at ${webUrl}/<owner>/<name>/asks/<ask>.md.`,Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 115–121why, one step back115 },116 ],117 title: "Text for any agent",118 useWhen:119 "Your agent can fetch a URL but has no MCP client or CLI set up: hand it the platform's index and it reads the rest as Markdown.",120});121Merge redesign into mainoscabrielbefore adoptioncaedd21
line 122why, one step back122export const skills = ({ webUrl }: SetupInput): SetupChannel => ({Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 123–126why, one step back123 snippets: [124 {125 label: "Add every project's contribute skill",126 language: "sh",Merge redesign into mainoscabrielbefore adoptioncaedd21
line 127why, one step back127 name: "Skills",Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 128–136why, one step back128 text: `npx skills add ${webUrl}`,129 },130 ],131 title: "Skills",132 useWhen: `Your agent loads skills: each project's contribute skill is listed, with its digest, at ${webUrl}/.well-known/agent-skills/index.json.`,133});134135export const agentSetup = (input: SetupInput): readonly SetupChannel[] => [136 remoteMcp(input),Merge redesign into mainoscabrielbefore adoptioncaedd21
line 137why, one step back137 ...(hasCommand(input.commands, "mcp") ? [stdioMcp()] : []),Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 138–142why, one step back138 theCli(input),139 anyAgent(input),140 skills(input),141];142Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 143–147why, one step back143export interface SynopsisLine {144 readonly usage: string;145 readonly summary: string;146}147Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 148–165why, one step back148/** One command as the synopsis writes it: its words, positionals, then optional flags. */149export const synopsisLine = ({150 flags,151 path,152 positional,153 summary,154}: CommandDoc): SynopsisLine => ({155 summary,156 usage: [157 Brand.cli,158 ...path,159 ...positional.map((name) => `<${name}>`),160 ...flags161 .filter((flag) => !positional.includes(flag.replace(/^--/u, "")))162 .map((flag) => `[${flag}]`),163 ].join(" "),164});165Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 166–167why, one step back166export const synopsis = (167 commands: readonly CommandDoc[]Merge redesign into mainoscabrielbefore adoptioncaedd21
line 168why, one step back168): readonly SynopsisLine[] => commands.map((command) => synopsisLine(command));Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 169–191why, one step back169170export interface Endpoint {171 readonly url: string;172 readonly what: string;173 readonly readable: boolean;174}175176export const agentEndpoints = ({177 platformUrl,178 webUrl,179}: Pick<SetupInput, "platformUrl" | "webUrl">): readonly Endpoint[] => [180 {181 readable: true,182 url: `${webUrl}/llms.txt`,183 what: "The index: how to take an ask, every command and every project.",184 },185 {186 readable: true,187 url: `${webUrl}/llms-full.txt`,188 what: "The rest in one file: every refusal, git here, how a landing happens, the events a watcher hears.",189 },190 {191 readable: false,Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
line 192why, one step back192 url: `${webUrl}/<owner>/<name>/llms.txt`,Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 193–196why, one step back193 what: "One project: its posture, how to clone it and its open asks.",194 },195 {196 readable: false,Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
line 197why, one step back197 url: `${webUrl}/<owner>/<name>/asks/<ask>.md`,Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 198–202why, one step back198 what: "One ask's brief as Markdown.",199 },200 {201 readable: true,202 url: `${webUrl}/agents.md`,Merge redesign into mainoscabrielbefore adoptioncaedd21
line 203why, one step back203 what: "Setup, the endpoints, the limits and the refusals as one Markdown file.",Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 204–257why, one step back204 },205 {206 readable: true,207 url: `${webUrl}/.well-known/mcp.json`,208 what: "The MCP server's card: its endpoint, transport and protocol, and how to sign in.",209 },210 {211 readable: true,212 url: `${webUrl}/.well-known/agent-skills/index.json`,213 what: "Every project's contribute skill, with its digest.",214 },215 {216 readable: false,217 url: `${platformUrl}/mcp`,218 what: "MCP over streamable HTTP, signed in over OAuth.",219 },220 {221 readable: false,222 url: `${platformUrl}/<repo>.git`,223 what: "Git over smart HTTP: clone a project, push an answer to your fork.",224 },225];226227export interface Limit {228 readonly limit: string;229 readonly value: string;230}231232const policyDefaults = () =>233 Schema.decodeSync(234 Schema.Struct({235 budget: PolicyInput.fields.budget,236 caps: PolicyInput.fields.caps,237 claims: PolicyInput.fields.claims,238 })239 )({});240241export const agentLimits = (): readonly Limit[] => {242 const { budget, caps, claims } = policyDefaults();243244 return [245 {246 limit: "Claims one person holds at once, in a project",247 value: `${caps.claimsPerPerson} by default`,248 },249 {250 limit: "Open proposals one person holds, in a project",251 value: `${caps.proposalsPerPerson} by default; 0 turns proposals off`,252 },253 {254 limit: "A claim without a push",255 value: `Warned after ${span(claims.warnAfterMs)}, lapses after ${span(claims.lapseAfterMs)}, by default`,256 },257 {Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 258why, one step back258 limit: "Decisions a maintainer takes a day",Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 259–272why, one step back259 value: `${budget.decisionsPerDay} by default`,260 },261 {262 limit: "A decision nobody takes",263 value: `${span(budget.expireDays * 86_400_000)} by default, then it takes its default`,264 },265 {266 limit: "Claims, proposals and drafts across the platform, per person",267 value:268 "A set number a minute; past it, CapReached says when to try again",269 },270 ];271};272Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 273–282why, one step back273const snippetLines = ({ label, language, text }: SetupSnippet) => [274 `${label}:`,275 "",276 `\`\`\`${language}`,277 text,278 "```",279 "",280];281282const channelLines = ({ snippets, title, useWhen }: SetupChannel) => [Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 283why, one step back283 `### ${title}`,Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 284–289why, one step back284 "",285 `Use this when ${useWhen.charAt(0).toLowerCase()}${useWhen.slice(1)}`,286 "",287 ...snippets.flatMap(snippetLines),288];289Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 290–298why, one step back290const synopsisLines = (commands: readonly CommandDoc[]) => [291 "## Synopsis",292 "",293 ...synopsis(commands).map(294 ({ summary, usage }) => `- ${code(usage)}: ${summary}`295 ),296 "",297];298Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 299–302why, one step back299/** The endpoints as a section, for `/agents.md` and the docs' Limits and endpoints page alike: one a reader can open is a link, a template or a protocol's address is not. */300export const endpointLines = (301 input: Pick<SetupInput, "platformUrl" | "webUrl">302) => [Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 303–306why, one step back303 "## Endpoints",304 "",305 ...table(306 ["Address", "What it is"],Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 307–310why, one step back307 agentEndpoints(input).map(({ readable, url, what }) => [308 readable ? `[${code(url)}](${url})` : code(url),309 what,310 ])Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 311–314why, one step back311 ),312 "",313];314Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 315–316why, one step back315/** The limits as a section, for `/agents.md` and the docs' Limits and endpoints page alike. */316export const limitLines = () => [Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 317–337why, one step back317 "## Limits",318 "",319 ...table(320 ["Limit", "Value"],321 agentLimits().map(({ limit, value }) => [limit, value])322 ),323 "",324];325326const refusalLines = ({ webUrl }: SetupInput) => [327 "## Refusals",328 "",329 `Every refusal the platform gives, by group. Each one's row in ${webUrl}/llms-full.txt says whether retrying helps, its \`next\` and what to do.`,330 "",331 ...groups.map(332 ({ members, name }) =>333 `- ${name}: ${listed(members.map((member) => code(member.identifier)))}`334 ),335 "",336];337Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 338–339why, one step back338export const agentSetupMarkdown = (input: SetupInput) =>339 page([Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 340why, one step back340 "# For agents",Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 341why, one step back341 "",Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 342why, one step back342 `> How an agent reaches ${Brand.name}: the CLI's commands, the ways to connect (over MCP, through the CLI, with a sentence to paste, or as skills), the endpoints, the limits and the refusals.`,Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 343why, one step back343 "",Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 344–346why, one step back344 ...synopsisLines(input.commands),345 "## Connect",346 "",Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 347why, one step back347 ...agentSetup(input).flatMap(channelLines),Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 348–350why, one step back348 ...endpointLines(input),349 ...limitLines(),350 ...refusalLines(input),Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 351why, one step back351 ]);