Skip to content
Myr

platform.ts

This file

Path

packages/agent-kit/src/platform.ts

205 lines · 7.2 KiB · TypeScript

Last changed by

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

lines 1–3why, one step back
1// Claude Code reads `.claude-plugin/plugin.json`, `.mcp.json` and
2// `hooks/hooks.json`; Agent Plugins 1.0 reads `plugin.json` and `mcp.json`.3// No path is read by both, so the two manifests share one directory.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 4–75why, one step back
4import { Brand } from "@repo/brand";
5import { Array as Arr, Effect, Option, Order } from "effect";67import type { CommandDoc } from "./command-doc.ts";8import { frontmatter } from "./generated-file.ts";9import type { GeneratedFile } from "./generated-file.ts";10import { claudeEventOf, guardedTools, HookEvent } from "./hook-events.ts";11import { refusalSection } from "./refusals.ts";12import { loopSteps, unfencedSection } from "./sections.ts";13import { code, page, printJson, table } from "./text.ts";1415export interface PlatformInput {16 readonly commands: readonly CommandDoc[];17 readonly platformUrl?: string;18}1920const SKILL = `skills/${Brand.slug}/SKILL.md`;2122const PLUGIN = `plugins/${Brand.slug}`;2324const description = `Contribute to projects on ${Brand.name} with the \`${Brand.cli}\` CLI: find an ask, claim it, check your answer locally, push it to your fork, and read the verdict. Use when a repo's remote is on ${Brand.name}, or when a push was refused with a refusal such as OutOfScope or StaleBase.`;2526const usage = ({ path, positional }: CommandDoc) =>27 code(28 [Brand.cli, ...path, ...positional.map((name) => `<${name}>`)].join(" ")29 );3031const notes = ({ needsApproval, readOnly }: CommandDoc) =>32 [33 ...(readOnly ? ["Only reads."] : []),34 ...(needsApproval ? ["Runs only with `--yes`."] : []),35 ].join(" ");3637const byWords = Order.mapInput(Order.String, (command: CommandDoc) =>38 command.path.join(" ")39);4041const commandsSection = (commands: readonly CommandDoc[]) => [42 "## Commands",43 "",44 ...table(45 ["Command", "Flags", "What it does"],46 Arr.sort(commands, byWords).map((command) => [47 usage(command),48 command.flags.map(code).join(" "),49 [command.summary, notes(command)].filter((text) => text !== "").join(" "),50 ])51 ),52 "",53];5455const mcpSection = (platformUrl: string | undefined) => [56 "## MCP",57 "",58 platformUrl === undefined59 ? `${code(`${Brand.cli} mcp`)} serves the platform's contracts as MCP tools over stdio, with your stored token.`60 : `The platform serves its contracts as MCP tools at ${code(`${platformUrl}/mcp`)}; ${code(`${Brand.cli} mcp`)} serves the same tools over stdio, with your stored token.`,61 "",62];6364const platformBody = (input: PlatformInput) =>65 page([66 `# ${Brand.name}`,67 "",68 `${Brand.name} is a git platform where a change lands only by passing a typed gate. A project states each change it wants as an ask; you answer one with a commit pushed to your claim's fork, and the platform checks it and lands it, or answers with refusals that say what to do next.`,69 "",70 "## The loop",71 "",72 `Find an ask with ${code(`${Brand.cli} asks`)}, then, in the project's repo:`,73 "",74 ...loopSteps(),75 "",

Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e

line 76why, one step back
76 `A project's own \`<key>-contribute\` skill (its key: the name with each \`/\` as \`__\`, as in \`oscabriel__foo-contribute\`, or for a project made before owners its old one-word key, as in \`datekit-contribute\`) and the block in its AGENTS.md give its territories, its run block and its ask kinds.`,

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 77–87why, one step back
77 "",
78 "## Output",79 "",80 "A command whose flags list `--json` prints Markdown, or one versioned JSON envelope with `--json`. A command that needs a person's approval runs only with `--yes`, and `--dry-run` prints what it would send.",81 "",82 ...commandsSection(input.commands),83 ...mcpSection(input.platformUrl),84 ...refusalSection(),85 ...unfencedSection(),86 ]);87

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

lines 88–89why, one step back
88// Synchronous: the platform builds the prompt at module load, where nothing
89// may be awaited, and `SKILL.md`'s hash is a WebCrypto promise.

Merge build/1007oscabrielbefore adoption77fa97a

lines 90–95why, one step back
90export const platformSkillParts = (input: PlatformInput) => ({
91 body: platformBody(input),92 description,93 name: Brand.slug,94});95

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

line 96why, one step back
96const skillFile = (input: PlatformInput) =>

Merge build/1007oscabrielbefore adoption77fa97a

line 97why, one step back
97 frontmatter({ ...platformSkillParts(input), landed: Option.none() });

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 98–103why, one step back
98
99export const platformSkill = (100 input: PlatformInput101): Effect.Effect<readonly GeneratedFile[]> =>102 skillFile(input).pipe(Effect.map((content) => [{ content, path: SKILL }]));103

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

line 104why, one step back
104// Cursor's remote entry is a bare `url`: its docs give a `type` only for stdio.

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

lines 105–131why, one step back
105const servers = {
106 "agent-plugins": {107 remote: (url: string) => ({ type: "streamable-http", url }),108 stdio: { args: ["mcp"], command: Brand.cli, type: "stdio" },109 },110 claude: {111 remote: (url: string) => ({ type: "http", url }),112 stdio: { args: ["mcp"], command: Brand.cli },113 },114 cursor: {115 remote: (url: string) => ({ url }),116 stdio: { args: ["mcp"], command: Brand.cli, type: "stdio" },117 },118} as const;119120export type McpFlavour = keyof typeof servers;121122export const mcpServersFor = (123 platformUrl: string | undefined,124 flavour: McpFlavour125) => ({126 [Brand.slug]:127 platformUrl === undefined128 ? servers[flavour].stdio129 : servers[flavour].remote(`${platformUrl}/mcp`),130});131

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 132–135why, one step back
132const hookCommand = (event: HookEvent) => ({
133 hooks: [{ command: `${Brand.cli} hook ${event} --json`, type: "command" }],134});135

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

line 136why, one step back
136// Each hook fails open: hooks are early feedback, and the gateway decides.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 137–171why, one step back
137const hooksJson = () =>
138 printJson({139 hooks: Object.fromEntries(140 HookEvent.literals.map((event) => [141 claudeEventOf[event],142 [143 event === "pre-tool-use"144 ? { ...hookCommand(event), matcher: guardedTools.join("|") }145 : hookCommand(event),146 ],147 ])148 ),149 });150151const pluginDescription = `The ${Brand.name} CLI's skill, MCP server and hooks: the gate's scope guard before an edit, the claimed ask's brief at the start, and its verdict before you stop.`;152153const homepage = (platformUrl: string | undefined) =>154 platformUrl === undefined ? {} : { homepage: platformUrl };155156export const claudePlugin = (157 input: PlatformInput158): Effect.Effect<readonly GeneratedFile[]> =>159 skillFile(input).pipe(160 Effect.map((skill) => [161 {162 content: printJson({163 description: pluginDescription,164 name: Brand.slug,165 ...homepage(input.platformUrl),166 }),167 path: `${PLUGIN}/.claude-plugin/plugin.json`,168 },169 { content: skill, path: `${PLUGIN}/${SKILL}` },170 {171 content: printJson({

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

line 172why, one step back
172 mcpServers: mcpServersFor(input.platformUrl, "claude"),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 173–199why, one step back
173 }),
174 path: `${PLUGIN}/.mcp.json`,175 },176 { content: hooksJson(), path: `${PLUGIN}/hooks/hooks.json` },177 ])178 );179180const SCHEMAS = "https://agent-plugins.org/schemas/1.0.0";181182export const agentPluginsBundle = (183 input: PlatformInput184): Effect.Effect<readonly GeneratedFile[]> =>185 skillFile(input).pipe(186 Effect.map((skill) => [187 {188 content: printJson({189 $schema: `${SCHEMAS}/plugin.schema.json`,190 description: `The ${Brand.name} CLI's skill and MCP server: find an ask, claim it, check your answer locally, push it, and read the verdict.`,191 name: Brand.slug,192 ...homepage(input.platformUrl),193 }),194 path: `${PLUGIN}/plugin.json`,195 },196 { content: skill, path: `${PLUGIN}/${SKILL}` },197 {198 content: printJson({199 $schema: `${SCHEMAS}/mcp.schema.json`,

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

line 200why, one step back
200 mcpServers: mcpServersFor(input.platformUrl, "agent-plugins"),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 201–205why, one step back
201 }),
202 path: `${PLUGIN}/mcp.json`,203 },204 ])205 );