| 1 | import releasedIndex from "../data/agent-docs.release-index.json"; |
| 2 | import { claimAvailability, releaseView, runtimeCapabilityContext } from "./capabilities"; |
| 3 | import { APP_COPY } from "./content/app-page"; |
| 4 | import { INSTALL_COMMANDS, INSTALL_COPY as I, INSTALL_PAGE_COMMANDS as C } from "./content/install"; |
| 5 | import { PRODUCT_MAP_STATE_KEY, PRODUCT_MAP_TEXT_KEYS, productMap } from "./content/product-map"; |
| 6 | import { DOC_TOPICS, REPO_DOCS_BASE, docTopicHref, getTopic, type DocTopic } from "./docs-map"; |
| 7 | import { BUILD_FACTS, type RepoFacts } from "./facts"; |
| 8 | import { EN_HOME as home, fill } from "./i18n/dictionaries"; |
| 9 | import { computerUse } from "./i18n/dictionaries/en/computer-use"; |
| 10 | import { DISCORD_URL, REPO_RELEASES_URL, REPO_URL } from "./i18n/links"; |
| 11 | import { SITE_NAME, SITE_URL } from "./page-meta"; |
| 12 | import { stateLabel, surfaceState, type SurfaceContext } from "./surface-states"; |
| 13 | |
| 14 | export interface AgentTextInput { |
| 15 | facts?: RepoFacts; |
| 16 | surface?: SurfaceContext; |
| 17 | } |
| 18 | |
| 19 | type Copy = { readonly en: string }; |
| 20 | |
| 21 | /** |
| 22 | * First-party routes that are in the sitemap but are not a docs-map topic. |
| 23 | * English canonicals only — this file is the machine-readable index. |
| 24 | */ |
| 25 | const EXTRA_PAGES: readonly { path: string; title: string; description: string }[] = [ |
| 26 | { |
| 27 | path: "/docs", |
| 28 | title: "Documentation", |
| 29 | description: |
| 30 | "Documentation hub: install, guide, configuration, providers, modes, tools, MCP, sandbox, Fleet, and the Runtime API.", |
| 31 | }, |
| 32 | { |
| 33 | path: "/faq", |
| 34 | title: "FAQ", |
| 35 | description: |
| 36 | "Frequently asked questions: install, config, providers, models, modes, security, and privacy.", |
| 37 | }, |
| 38 | { |
| 39 | // The page's own English copy, so the index cannot drift from it (W01-03). |
| 40 | path: "/computer-use", |
| 41 | title: computerUse.title, |
| 42 | description: computerUse.metaDescription, |
| 43 | }, |
| 44 | { |
| 45 | path: "/contribute", |
| 46 | title: "Contribute", |
| 47 | description: "The pull-request workflow: scoped issue, fork, test the change, explain the result.", |
| 48 | }, |
| 49 | { |
| 50 | path: "/changelog", |
| 51 | title: "Changelog", |
| 52 | description: |
| 53 | "Codewhale release record: the latest published release, the unreleased source candidate, and the notes for each version, drawn from CHANGELOG.md in the repository.", |
| 54 | }, |
| 55 | { |
| 56 | path: "/ratatui", |
| 57 | title: "Codewhale Ratatui", |
| 58 | description: |
| 59 | "Explore Codewhale’s reusable Ratatui components. Compare terminal themes and widths, inspect real rendered previews, and use the Rust examples in your app.", |
| 60 | }, |
| 61 | { |
| 62 | path: "/legal/terms", |
| 63 | title: "Terms of service", |
| 64 | description: "Terms that govern your use of Codewhale, a Shannon Labs product.", |
| 65 | }, |
| 66 | { |
| 67 | path: "/legal/privacy", |
| 68 | title: "Privacy policy", |
| 69 | description: "How Shannon Labs handles information when you use Codewhale.", |
| 70 | }, |
| 71 | ]; |
| 72 | |
| 73 | function appPage(surface: SurfaceContext): string { |
| 74 | const state = (id: "desktop" | "hosted-web") => stateLabel(surfaceState(id, surface), "en"); |
| 75 | return `- [Desktop and browser apps](${SITE_URL}/en/app): ${APP_COPY.surfaces.desktop.en}: ${state("desktop")}. ${APP_COPY.surfaces.browser.en}: ${state("hosted-web")}.`; |
| 76 | } |
| 77 | |
| 78 | function installLines(facts: RepoFacts): string[] { |
| 79 | const release = facts.latestPublishedRelease; |
| 80 | const version = release?.version ?? null; |
| 81 | const ref = release?.tag ?? "main"; |
| 82 | const uninstallReleased = claimAvailability({ feature: "unix-uninstall" }, runtimeCapabilityContext(facts)) === "released"; |
| 83 | const t = (copy: Copy) => fill(copy.en, { version: version ?? "" }); |
| 84 | const p = (copy: Copy) => [t(copy), ""]; |
| 85 | const h = (copy: Copy, level = 2) => [`${"#".repeat(level)} ${t(copy)}`, ""]; |
| 86 | const code = (cmd: string) => ["```", cmd, "```", ""]; |
| 87 | const link = (copy: Copy, href: string) => [`[${t(copy)}](${href})`, ""]; |
| 88 | const bullets = (rows: readonly Copy[]) => [...rows.map((row) => `- ${t(row)}`), ""]; |
| 89 | return [ |
| 90 | `- macOS and Linux: \`${INSTALL_COMMANDS.shell}\``, |
| 91 | `- ${t(I.windowsTitle)}: \`${INSTALL_COMMANDS.windows}\``, |
| 92 | ` ${t(I.windowsNote)}`, |
| 93 | `- ${t(I.npmTitle)}: \`${INSTALL_COMMANDS.npm}\``, |
| 94 | `- ${t(I.cargoTitle)}: \`${INSTALL_COMMANDS.cargo}\``, |
| 95 | ` ${t(I.cargoNote)}`, |
| 96 | "", |
| 97 | ...link(I.scriptLink, `${SITE_URL}/install.sh`), |
| 98 | ...(version ? p(I.releaseLine) : []), |
| 99 | ...h(I.newTitle), |
| 100 | ...p(I.newLead), |
| 101 | ...h(I.newMacTitle, 3), |
| 102 | `1. ${t(I.newMac1)}`, |
| 103 | `2. ${t(I.newMac2)}`, |
| 104 | "", |
| 105 | ...code(INSTALL_COMMANDS.shell), |
| 106 | `3. ${t(I.newMac3)}`, |
| 107 | "", |
| 108 | ...h(I.newLinuxTitle, 3), |
| 109 | `1. ${t(I.newLinux1)}`, |
| 110 | `2. ${t(I.newLinux2)}`, |
| 111 | "", |
| 112 | ...code(INSTALL_COMMANDS.shell), |
| 113 | `3. ${t(I.newLinux3)}`, |
| 114 | "", |
| 115 | ...h(I.newWinTitle, 3), |
| 116 | `1. ${t(I.newWin1)}`, |
| 117 | `2. ${t(I.newWin2)}`, |
| 118 | "", |
| 119 | ...code(INSTALL_COMMANDS.windows), |
| 120 | `3. ${t(I.newWin3)}`, |
| 121 | "", |
| 122 | ...link(I.newNext, `${SITE_URL}/en/docs/first-time`), |
| 123 | ...h(I.pathTitle), |
| 124 | ...p(I.pathPlaces), |
| 125 | ...bullets([I.pathZsh, I.pathBashLinux, I.pathBashMac, I.pathOther, I.pathFish]), |
| 126 | ...p(I.pathBlockIntro), |
| 127 | ...code(C.pathBlock), |
| 128 | ...p(I.pathBlockAfter), |
| 129 | ...code(C.pathNow), |
| 130 | ...p(I.pathOptOut), |
| 131 | ...code(C.noModifyPath), |
| 132 | ...p(I.pathManualIntro), |
| 133 | ...p(I.pathManualBash), |
| 134 | ...code(C.pathManualBash), |
| 135 | ...p(I.pathManualZsh), |
| 136 | ...code(C.pathManualZsh), |
| 137 | ...h(I.verifyTitle), |
| 138 | ...p(version ? I.verifyBody : I.verifyBodyUnknown), |
| 139 | ...code(C.version), |
| 140 | ...h(I.firstTitle), |
| 141 | ...[I.firstStep1, I.firstStep2, I.firstStep3].map((row, index) => `${index + 1}. ${t(row)}`), |
| 142 | "", |
| 143 | ...link(I.quickstart, `${SITE_URL}/en/docs/guide`), |
| 144 | ...h(I.usageTitle), |
| 145 | ...p(I.usageBody), |
| 146 | ...code(C.telemetryOff), |
| 147 | ...p(I.usageInstaller), |
| 148 | ...link(I.usageLink, `${SITE_URL}/en/legal/privacy#usage-counting`), |
| 149 | ...h(I.updateTitle), |
| 150 | ...p(I.updateBody), |
| 151 | ...code(C.update), |
| 152 | ...h(I.removeTitle), |
| 153 | ...(uninstallReleased |
| 154 | ? [...p(I.removeNow), ...code(C.uninstall), ...p(I.removeFilesNow)] |
| 155 | : p(version ? I.removeFilesOnly : I.removeFilesOnlyUnknown)), |
| 156 | ...code(C.removeFiles), |
| 157 | ...p(I.removePath), |
| 158 | ...p(I.removeData), |
| 159 | ...code(C.removeData), |
| 160 | ...(version ? p(I.removeGuide) : []), |
| 161 | ...h(I.troubleTitle), |
| 162 | ...bullets([I.troubleNotFound, I.troubleQueued, I.troubleLegacy]), |
| 163 | ...link(I.troubleMore, `${SITE_URL}/en/docs/troubleshooting`), |
| 164 | ...h(I.channelsTitle), |
| 165 | ...p(version ? I.channelsLead : I.channelsLeadUnknown), |
| 166 | ...h(I.windowsTitle, 3), |
| 167 | ...code(INSTALL_COMMANDS.windows), |
| 168 | ...p(I.windowsVerify), |
| 169 | ...p(I.windowsPackage), |
| 170 | ...p(I.windowsSandbox), |
| 171 | ...p(I.windowsUpdate), |
| 172 | ...h(I.npmTitle, 3), |
| 173 | ...code(INSTALL_COMMANDS.npm), |
| 174 | ...p(I.npmBody), |
| 175 | ...p(I.npmEacces), |
| 176 | ...code(C.npmPrefix), |
| 177 | ...p(I.npmScripts), |
| 178 | ...p(I.npmUpdate), |
| 179 | ...h(I.cargoTitle, 3), |
| 180 | ...code(INSTALL_COMMANDS.cargo), |
| 181 | ...p(I.cargoBody), |
| 182 | ...p(I.cargoUpdate), |
| 183 | ...code(C.cargoUpdate), |
| 184 | ...h(I.brewTitle, 3), |
| 185 | ...code(C.brewInstall), |
| 186 | ...p(I.brewBody), |
| 187 | ...p(I.brewUpdate), |
| 188 | ...code(C.brewRemove), |
| 189 | ...h(I.mirrorsTitle), |
| 190 | ...p(I.mirrorsNpm), |
| 191 | ...p(I.mirrorsCnb), |
| 192 | ...code(C.cnbVerify), |
| 193 | ...link(I.mirrorsGuide, `${REPO_URL}/blob/${ref}/docs/CNB_MIRROR.md`), |
| 194 | ...link(I.fullGuide, `${REPO_URL}/blob/${ref}/docs/INSTALL.md`), |
| 195 | ]; |
| 196 | } |
| 197 | |
| 198 | function mapLines(facts: RepoFacts, surface: SurfaceContext): string[] { |
| 199 | return productMap({ surface, capabilities: runtimeCapabilityContext(facts) }).map((row) => { |
| 200 | const keys = PRODUCT_MAP_TEXT_KEYS[row.id]; |
| 201 | return `- ${home[keys.name]}: ${home[PRODUCT_MAP_STATE_KEY[row.state]]}.${row.sentenceHolds ? ` ${home[keys.sentence]}` : ""}`; |
| 202 | }); |
| 203 | } |
| 204 | |
| 205 | function sitePage(id: string): string { |
| 206 | const topic = getTopic(id); |
| 207 | if (!topic) throw new Error(`missing docs topic: ${id}`); |
| 208 | return `- [${topic.label.en}](${SITE_URL}${docTopicHref(topic, "en")})`; |
| 209 | } |
| 210 | |
| 211 | function topicDescription(topic: DocTopic): string { |
| 212 | return topic.id === "install" ? I.metaDescription.en : topic.description.en; |
| 213 | } |
| 214 | |
| 215 | function provenance(facts: RepoFacts): string { |
| 216 | const read = facts.latestPublishedRelease?.readAt; |
| 217 | return `Facts generated ${facts.generatedAt.slice(0, 10)}${facts.sourceRevision ? ` from source revision ${facts.sourceRevision}` : ""}${read ? `; published release read ${read.slice(0, 10)}` : ""}`; |
| 218 | } |
| 219 | |
| 220 | function factLines(facts: RepoFacts): string[] { |
| 221 | const release = facts.latestPublishedRelease; |
| 222 | const lines: string[] = []; |
| 223 | if (release) lines.push(`- Published release: ${release.tag} (${release.url}).`); |
| 224 | if (facts.license) lines.push(`- License: ${facts.license} (${REPO_URL}/blob/main/LICENSE). Free to use; you pay your model provider directly, and local models need no key.`); |
| 225 | if (facts.defaultModel) lines.push(`- Default model id: \`${facts.defaultModel}\` (DeepSeek). Every provider and model is selectable with /provider and /model.`); |
| 226 | const released = releaseView(facts); |
| 227 | if (released.counts) { |
| 228 | lines.push(`- Built-in provider routes in ${release?.tag ?? "the published release"} (${released.counts.providerRoutes}): ${released.providers.map((provider) => provider.label).join(", ")}. Any OpenAI-compatible endpoint also works.`); |
| 229 | } |
| 230 | if (facts.sandboxBackends.length > 0) lines.push(`- OS command sandbox backends: ${facts.sandboxBackends.join("; ")}.`); |
| 231 | lines.push(`- ${provenance(facts)}; feature registry: ${SITE_URL}/features.json.`); |
| 232 | return lines; |
| 233 | } |
| 234 | |
| 235 | export function buildInstallMarkdown(input: AgentTextInput = {}): string { |
| 236 | const facts = input.facts ?? BUILD_FACTS; |
| 237 | return [ |
| 238 | `# ${I.metaTitle.en}`, "", |
| 239 | `${home.sectionStartHeading} ${home.sectionStartBody}`, "", |
| 240 | ...installLines(facts), |
| 241 | `${provenance(facts)}.`, "", |
| 242 | ].join("\n"); |
| 243 | } |
| 244 | |
| 245 | export function buildLlmsTxt(input: AgentTextInput = {}): string { |
| 246 | const facts = input.facts ?? BUILD_FACTS; |
| 247 | const surface = input.surface ?? {}; |
| 248 | const release = facts.latestPublishedRelease; |
| 249 | const lines = [ |
| 250 | `# ${SITE_NAME}`, "", `> ${home.heroTitle}`, "", |
| 251 | fill(home.heroIntro, { brand: SITE_NAME }), "", |
| 252 | release ? `The latest release is v${release.version}.` : `The latest release is unknown; see ${REPO_RELEASES_URL}.`, "", |
| 253 | "## Install", "", |
| 254 | ...installLines(facts), |
| 255 | `## ${home.mapHeading}`, "", |
| 256 | home.sectionDirectionBody, "", |
| 257 | ...mapLines(facts, surface), "", |
| 258 | "## Main pages", "", |
| 259 | sitePage("install"), |
| 260 | sitePage("guide"), |
| 261 | sitePage("providers"), |
| 262 | `- [Changelog](${SITE_URL}/en/changelog)`, |
| 263 | `- [${home.readTheCode}](${REPO_URL})`, "", |
| 264 | "## Facts", "", |
| 265 | ...factLines(facts), "", |
| 266 | "## Agent entry points", "", |
| 267 | `- [Feature catalogue](${SITE_URL}/en/features): Source capabilities, status, surfaces and documentation.`, |
| 268 | `- [Feature JSON](${SITE_URL}/features.json): The generated feature registry, including its source hash.`, |
| 269 | `- [Full documentation](${SITE_URL}/llms-full.txt): Every documentation topic as plain text.`, |
| 270 | `- [Runtime API](${SITE_URL}/docs-markdown/runtime-api.md): HTTP/SSE API and ACP integration.`, |
| 271 | `- [MCP](${SITE_URL}/docs-markdown/mcp.md): Connect tools or run codewhale mcp-server / codewhale serve --mcp. Default server tools are read-only file_read and search.`, |
| 272 | "", "## Plugins and MCP", "", |
| 273 | `- [Choose an integration](${SITE_URL}/en/plugins): Skills are instructions; plugins package reviewed capabilities; MCP servers supply external tools, resources and prompts.`, |
| 274 | `- [Connect MCP servers](${SITE_URL}/en/docs/mcp): Local stdio and remote Streamable HTTP, legacy SSE, environment-backed tokens and direct-server OAuth. Plugin-bundled MCP does not support OAuth.`, |
| 275 | `- [Computer Use](${SITE_URL}/en/computer-use): Mac helper setup, CLI-version limitations and its separate open-source repository.`, |
| 276 | `- [Public plugin catalog](https://github.com/codewhale-hq/codewhale-plugin-marketplace): Installed CLI releases bundle a dated snapshot; current catalog entries are not proof of installed versions or end-to-end qualification.`, |
| 277 | "", "## Documentation", "", |
| 278 | ]; |
| 279 | for (const topic of DOC_TOPICS.filter((entry) => releasedIndex.slugs.includes(entry.slug))) { |
| 280 | lines.push(`- [${topic.label.en}](${SITE_URL}/docs-markdown/${topic.slug}.md): ${topicDescription(topic)}`); |
| 281 | } |
| 282 | lines.push("", "## Optional", ""); |
| 283 | for (const topic of DOC_TOPICS) { |
| 284 | lines.push(`- [${topic.label.en} on the site](${topic.hasPage ? `${SITE_URL}${docTopicHref(topic, "en")}` : `${REPO_DOCS_BASE}/${Array.isArray(topic.repoSource) ? topic.repoSource[0] : topic.repoSource}`}): ${topicDescription(topic)}`); |
| 285 | } |
| 286 | lines.push(appPage(surface)); |
| 287 | for (const page of EXTRA_PAGES) { |
| 288 | lines.push(`- [${page.title}](${SITE_URL}/en${page.path}): ${page.description}`); |
| 289 | } |
| 290 | lines.push(`- [GitHub](${REPO_URL})`, `- [Discord](${DISCORD_URL})`, ""); |
| 291 | return lines.join("\n"); |
| 292 | } |
| 293 |