From 0ef429f53210ca72870f2ac2529c7ec1379be79b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 10 Jan 2026 21:02:18 +0100 Subject: [PATCH] feat: color docs search output --- src/commands/docs.ts | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/commands/docs.ts b/src/commands/docs.ts index c7689467a..94c7b3a80 100644 --- a/src/commands/docs.ts +++ b/src/commands/docs.ts @@ -1,6 +1,8 @@ import { hasBinary } from "../agents/skills.js"; import { runCommandWithTimeout } from "../process/exec.js"; import type { RuntimeEnv } from "../runtime.js"; +import { formatDocsLink } from "../terminal/links.js"; +import { isRich, theme } from "../terminal/theme.js"; const SEARCH_TOOL = "https://docs.clawd.bot/mcp.SearchClawdbot"; const SEARCH_TIMEOUT_MS = 30_000; @@ -125,6 +127,32 @@ function buildMarkdown(query: string, results: DocResult[]): string { return lines.join("\n"); } +function formatLinkLabel(link: string): string { + return link.replace(/^https?:\/\//i, ""); +} + +function renderRichResults( + query: string, + results: DocResult[], + runtime: RuntimeEnv, +) { + runtime.log(`${theme.heading("Docs search:")} ${theme.info(query)}`); + if (results.length === 0) { + runtime.log(theme.muted("No results.")); + return; + } + for (const item of results) { + const linkLabel = formatLinkLabel(item.link); + const link = formatDocsLink(item.link, linkLabel); + runtime.log( + `${theme.muted("-")} ${theme.command(item.title)} ${theme.muted("(")}${link}${theme.muted(")")}`, + ); + if (item.snippet) { + runtime.log(` ${theme.muted(item.snippet)}`); + } + } +} + async function renderMarkdown(markdown: string, runtime: RuntimeEnv) { const width = process.stdout.columns ?? 0; const args = width > 0 ? ["--width", String(width)] : []; @@ -149,8 +177,14 @@ export async function docsSearchCommand( ) { const query = queryParts.join(" ").trim(); if (!query) { - runtime.log("Docs: https://docs.clawd.bot/"); - runtime.log('Search: clawdbot docs "your query"'); + const docs = formatDocsLink("/", "docs.clawd.bot"); + if (isRich()) { + runtime.log(`${theme.muted("Docs:")} ${docs}`); + runtime.log(`${theme.muted("Search:")} clawdbot docs "your query"`); + } else { + runtime.log("Docs: https://docs.clawd.bot/"); + runtime.log('Search: clawdbot docs "your query"'); + } return; } @@ -169,6 +203,10 @@ export async function docsSearchCommand( } const results = parseSearchOutput(res.stdout); + if (isRich()) { + renderRichResults(query, results, runtime); + return; + } const markdown = buildMarkdown(query, results); await renderMarkdown(markdown, runtime); }