xonecas.io
64875
Mc

mini-coder / commit 7f1d998

refactor: consolidate tool-result renderers into single file

- Merge 9 tiny tool-result files into tool-result-renderers.ts
- Remove duplicate StatusBarData interface from status-bar.ts
- Reduces total file count from 148 to 139
- Reduces code duplication from 3 clones to 2

xonecas2026-03-14 7f1d9986dcf48d02db6650595774e1f55b8e8278 parent 59eb1c3

13 files changed

src/cli/status-bar.ts+3−17
@@ -1,4 +1,5 @@
11 import * as c from "yoctocolors";
2+import type { StatusBarData } from "../agent/reporter.ts";
23 import { terminal } from "./terminal-io.ts";
34
45 const ANSI_ESCAPE = "\u001b";
@@ -47,22 +48,7 @@ function renderStatusLine(segments: string[]): string {
4748 return segments.join(STATUS_SEP);
4849 }
4950
50-interface StatusBarRenderData {
51- model: string;
52- provider: string;
53- cwd: string;
54- gitBranch: string | null;
55- sessionId: string;
56- inputTokens: number;
57- outputTokens: number;
58- contextTokens: number;
59- contextWindow: number | null;
60- thinkingEffort?: string | null;
61- activeAgent?: string | null;
62- showReasoning?: boolean;
63-}
64-
65-export function buildStatusBarSignature(opts: StatusBarRenderData): string {
51+export function buildStatusBarSignature(opts: StatusBarData): string {
6652 return JSON.stringify({
6753 model: opts.model,
6854 provider: opts.provider,
@@ -104,7 +90,7 @@ function fitStatusSegments(
10490 return `${required[0]}${STATUS_SEP}${c.dim(truncatedTail)}`;
10591 }
10692
107-export function renderStatusBar(opts: StatusBarRenderData): void {
93+export function renderStatusBar(opts: StatusBarData): void {
10894 const cols = Math.max(20, terminal.stdoutColumns || 80);
10995 const required = [c.cyan(opts.model), c.dim(opts.cwd)];
11096 const optional: string[] = [];
src/cli/tool-result-handlers.ts+1−1
@@ -1 +1 @@
1-export { renderToolResultByName } from "./tool-results/index.ts";
1+export { renderToolResultByName } from "./tool-result-renderers.ts";
src/cli/tool-result-renderers.ts+309−0
@@ -0,0 +1,309 @@
1+import * as c from "yoctocolors";
2+import { G, writeln } from "./output.ts";
3+
4+// ─── Shared helpers ───────────────────────────────────────────────────────────
5+
6+const MAX_DIFF_PREVIEW_LINES = 24;
7+
8+function colorizeDiffLine(line: string): string {
9+ if (line.startsWith("+++") || line.startsWith("---")) return c.dim(line);
10+ if (line.startsWith("+")) return c.green(line);
11+ if (line.startsWith("-")) return c.red(line);
12+ if (line.startsWith("@@")) return c.cyan(line);
13+ return c.dim(line);
14+}
15+
16+function renderDiff(diff: string): void {
17+ if (!diff || diff === "(no changes)") return;
18+
19+ const normalized = diff.replace(/[\r\n]+$/, "");
20+ if (!normalized) return;
21+
22+ const lines = normalized.split("\n");
23+ const shown = lines.slice(0, MAX_DIFF_PREVIEW_LINES);
24+ for (const line of shown) {
25+ writeln(` ${colorizeDiffLine(line)}`);
26+ }
27+ if (lines.length > shown.length) {
28+ writeln(
29+ ` ${c.dim(`… +${lines.length - shown.length} more diff lines`)}`,
30+ );
31+ }
32+}
33+
34+function writePreviewLines(opts: {
35+ label: string;
36+ value: string;
37+ lineColor: (input: string) => string;
38+ maxLines: number;
39+}): void {
40+ if (!opts.value.trim()) return;
41+ const lines = opts.value.split("\n");
42+ writeln(` ${c.dim(opts.label)} ${c.dim(`(${lines.length} lines)`)}`);
43+ for (const line of lines.slice(0, opts.maxLines)) {
44+ writeln(` ${opts.lineColor("│")} ${line}`);
45+ }
46+ if (lines.length > opts.maxLines) {
47+ writeln(
48+ ` ${opts.lineColor("│")} ${c.dim(`… +${lines.length - opts.maxLines} lines`)}`,
49+ );
50+ }
51+}
52+
53+function truncateOneLine(value: string, max = 100): string {
54+ return value.length > max ? `${value.slice(0, max - 1)}…` : value;
55+}
56+
57+// ─── Tool result renderers ────────────────────────────────────────────────────
58+
59+type ToolResultRenderer = (result: unknown, toolName?: string) => boolean;
60+
61+function renderReadResult(result: unknown): boolean {
62+ const r = result as {
63+ path: string;
64+ line: number;
65+ totalLines: number;
66+ truncated: boolean;
67+ content?: string;
68+ };
69+ if (!r || typeof r.path !== "string") return false;
70+
71+ const linesReturned = r.content ? r.content.split("\n").length : 0;
72+ const endLine = linesReturned > 0 ? r.line + linesReturned - 1 : r.line;
73+ const range =
74+ r.line === 1 && endLine === r.totalLines
75+ ? `${r.totalLines} lines`
76+ : `lines ${r.line}–${endLine} of ${r.totalLines}`;
77+ writeln(
78+ ` ${G.info} ${c.dim(`${r.path} ${range}${r.truncated ? " (truncated)" : ""}`)}`,
79+ );
80+ return true;
81+}
82+
83+function renderCreateResult(result: unknown): boolean {
84+ const r = result as { path: string; diff: string; created: boolean };
85+ if (!r || typeof r.path !== "string") return false;
86+ const verb = r.created ? c.green("created") : c.dim("overwritten");
87+ writeln(` ${G.ok} ${verb} ${r.path}`);
88+ renderDiff(r.diff);
89+ return true;
90+}
91+
92+function renderReplaceOrInsertResult(
93+ toolName: string,
94+ result: unknown,
95+): boolean {
96+ const r = result as { path: string; diff: string; deleted?: boolean };
97+ if (!r || typeof r.path !== "string") return false;
98+ const verb =
99+ toolName === "insert" ? "inserted" : r.deleted ? "deleted" : "replaced";
100+ writeln(` ${G.ok} ${c.dim(verb)} ${r.path}`);
101+ renderDiff(r.diff);
102+ return true;
103+}
104+
105+function renderShellResult(result: unknown): boolean {
106+ const r = result as {
107+ stdout: string;
108+ stderr: string;
109+ exitCode: number;
110+ success: boolean;
111+ timedOut: boolean;
112+ };
113+ if (!r || typeof r.stdout !== "string" || typeof r.stderr !== "string") {
114+ return false;
115+ }
116+
117+ const badge = r.timedOut
118+ ? c.yellow("timeout")
119+ : r.success
120+ ? c.green("success")
121+ : c.red("error");
122+
123+ const stdoutNormalized = r.stdout.replace(/[\r\n]+$/, "");
124+ const stderrNormalized = r.stderr.replace(/[\r\n]+$/, "");
125+ const stdoutLines = stdoutNormalized
126+ ? stdoutNormalized.split(/\r?\n/).length
127+ : 0;
128+ const stderrLines = stderrNormalized
129+ ? stderrNormalized.split(/\r?\n/).length
130+ : 0;
131+ const stdoutSingleLine =
132+ stdoutLines === 1 ? (stdoutNormalized.split(/\r?\n/)[0] ?? "") : null;
133+
134+ const parts = [
135+ `exit ${r.exitCode}`,
136+ `stdout ${stdoutLines}L`,
137+ `stderr ${stderrLines}L`,
138+ ];
139+
140+ if (
141+ r.success &&
142+ !r.timedOut &&
143+ stderrLines === 0 &&
144+ stdoutSingleLine !== null &&
145+ stdoutSingleLine.length > 0
146+ ) {
147+ parts.push(`out: ${truncateOneLine(stdoutSingleLine)}`);
148+ }
149+
150+ writeln(` ${badge} ${c.dim(parts.join(" · "))}`);
151+
152+ if (r.success && !r.timedOut) {
153+ return true;
154+ }
155+
156+ writePreviewLines({
157+ label: "stderr",
158+ value: r.stderr,
159+ lineColor: c.red,
160+ maxLines: 6,
161+ });
162+ writePreviewLines({
163+ label: "stdout",
164+ value: r.stdout,
165+ lineColor: c.dim,
166+ maxLines: 4,
167+ });
168+
169+ return true;
170+}
171+
172+function renderSubagentResult(result: unknown): boolean {
173+ const r = result as {
174+ inputTokens?: number;
175+ outputTokens?: number;
176+ agentName?: string;
177+ };
178+ if (!r || typeof r !== "object") return false;
179+ const label = r.agentName ? ` ${c.dim(c.cyan(`[@${r.agentName}]`))}` : "";
180+ writeln(
181+ ` ${G.agent}${label} ${c.dim(`subagent done (${r.inputTokens ?? 0}in / ${r.outputTokens ?? 0}out tokens)`)}`,
182+ );
183+ return true;
184+}
185+
186+function renderReadSkillResult(result: unknown): boolean {
187+ const r = result as {
188+ skill?: {
189+ name?: string;
190+ description?: string;
191+ source?: "local" | "global";
192+ };
193+ };
194+ if (!r || typeof r !== "object") return false;
195+ if (!r.skill) {
196+ writeln(` ${G.info} ${c.dim("skill")} ${c.dim("(not found)")}`);
197+ return true;
198+ }
199+ const name = r.skill.name ?? "(unknown)";
200+ const source = r.skill.source ?? "unknown";
201+ const description = r.skill.description?.trim();
202+ const descPart = description
203+ ? ` ${c.dim("·")} ${c.dim(description.length > 60 ? `${description.slice(0, 57)}…` : description)}`
204+ : "";
205+ writeln(
206+ ` ${G.info} ${c.dim("skill")} ${name} ${c.dim("·")} ${c.dim(source)}${descPart}`,
207+ );
208+ return true;
209+}
210+
211+function renderWebSearchResult(result: unknown): boolean {
212+ const r = result as {
213+ results?: Array<{ title?: string; url?: string; score?: number }>;
214+ };
215+ if (!Array.isArray(r?.results)) return false;
216+ if (r.results.length === 0) {
217+ writeln(` ${G.info} ${c.dim("no results")}`);
218+ return true;
219+ }
220+
221+ for (const item of r.results.slice(0, 5)) {
222+ const title = (item.title?.trim() || item.url || "(untitled)").replace(
223+ /\s+/g,
224+ " ",
225+ );
226+ const score =
227+ typeof item.score === "number"
228+ ? c.dim(` (${item.score.toFixed(2)})`)
229+ : "";
230+ writeln(` ${c.dim("•")} ${title}${score}`);
231+ if (item.url) writeln(` ${c.dim(item.url)}`);
232+ }
233+
234+ if (r.results.length > 5) {
235+ writeln(` ${c.dim(` +${r.results.length - 5} more`)}`);
236+ }
237+ return true;
238+}
239+
240+function renderWebContentResult(result: unknown): boolean {
241+ const r = result as {
242+ results?: Array<{ url?: string; title?: string; text?: string }>;
243+ };
244+ if (!Array.isArray(r?.results)) return false;
245+ if (r.results.length === 0) {
246+ writeln(` ${G.info} ${c.dim("no pages")}`);
247+ return true;
248+ }
249+
250+ for (const item of r.results.slice(0, 3)) {
251+ const title = (item.title?.trim() || item.url || "(untitled)").replace(
252+ /\s+/g,
253+ " ",
254+ );
255+ writeln(` ${c.dim("•")} ${title}`);
256+ if (item.url) writeln(` ${c.dim(item.url)}`);
257+ const preview = (item.text ?? "").replace(/\s+/g, " ").trim();
258+ if (preview) {
259+ const trimmed =
260+ preview.length > 220 ? `${preview.slice(0, 217)}…` : preview;
261+ writeln(` ${c.dim(trimmed)}`);
262+ }
263+ }
264+
265+ if (r.results.length > 3) {
266+ writeln(` ${c.dim(` +${r.results.length - 3} more`)}`);
267+ }
268+ return true;
269+}
270+
271+function renderMcpResult(result: unknown): boolean {
272+ const content = Array.isArray(result) ? result : [result];
273+ for (const block of (
274+ content as Array<{ type?: string; text?: string }>
275+ ).slice(0, 5)) {
276+ if (block?.type === "text" && block.text) {
277+ const lines = block.text.split("\n").slice(0, 6);
278+ for (const line of lines) writeln(` ${c.dim("│")} ${line}`);
279+ }
280+ }
281+ return true;
282+}
283+
284+// ─── Registry ─────────────────────────────────────────────────────────────────
285+
286+const TOOL_RESULT_RENDERERS: Readonly<Record<string, ToolResultRenderer>> = {
287+ read: renderReadResult,
288+ create: renderCreateResult,
289+ replace: (result) => renderReplaceOrInsertResult("replace", result),
290+ insert: (result) => renderReplaceOrInsertResult("insert", result),
291+ shell: renderShellResult,
292+ subagent: renderSubagentResult,
293+ readSkill: renderReadSkillResult,
294+ webSearch: renderWebSearchResult,
295+ webContent: renderWebContentResult,
296+};
297+
298+export function renderToolResultByName(
299+ toolName: string,
300+ result: unknown,
301+): boolean {
302+ if (toolName.startsWith("mcp_")) {
303+ return renderMcpResult(result);
304+ }
305+
306+ const renderer = TOOL_RESULT_RENDERERS[toolName];
307+ if (!renderer) return false;
308+ return renderer(result, toolName);
309+}
src/cli/tool-result-shared.ts+0−49
@@ -1,49 +0,0 @@
1-import * as c from "yoctocolors";
2-import { writeln } from "./output.ts";
3-
4-const MAX_DIFF_PREVIEW_LINES = 24;
5-
6-function colorizeDiffLine(line: string): string {
7- if (line.startsWith("+++") || line.startsWith("---")) return c.dim(line);
8- if (line.startsWith("+")) return c.green(line);
9- if (line.startsWith("-")) return c.red(line);
10- if (line.startsWith("@@")) return c.cyan(line);
11- return c.dim(line);
12-}
13-
14-export function renderDiff(diff: string): void {
15- if (!diff || diff === "(no changes)") return;
16-
17- const normalized = diff.replace(/[\r\n]+$/, "");
18- if (!normalized) return;
19-
20- const lines = normalized.split("\n");
21- const shown = lines.slice(0, MAX_DIFF_PREVIEW_LINES);
22- for (const line of shown) {
23- writeln(` ${colorizeDiffLine(line)}`);
24- }
25- if (lines.length > shown.length) {
26- writeln(
27- ` ${c.dim(`… +${lines.length - shown.length} more diff lines`)}`,
28- );
29- }
30-}
31-
32-export function writePreviewLines(opts: {
33- label: string;
34- value: string;
35- lineColor: (input: string) => string;
36- maxLines: number;
37-}): void {
38- if (!opts.value.trim()) return;
39- const lines = opts.value.split("\n");
40- writeln(` ${c.dim(opts.label)} ${c.dim(`(${lines.length} lines)`)}`);
41- for (const line of lines.slice(0, opts.maxLines)) {
42- writeln(` ${opts.lineColor("│")} ${line}`);
43- }
44- if (lines.length > opts.maxLines) {
45- writeln(
46- ` ${opts.lineColor("│")} ${c.dim(`… +${lines.length - opts.maxLines} lines`)}`,
47- );
48- }
49-}
src/cli/tool-results/file-edits.ts+0−25
@@ -1,25 +0,0 @@
1-import * as c from "yoctocolors";
2-import { G, writeln } from "../output.ts";
3-import { renderDiff } from "../tool-result-shared.ts";
4-
5-export function renderCreateResult(result: unknown): boolean {
6- const r = result as { path: string; diff: string; created: boolean };
7- if (!r || typeof r.path !== "string") return false;
8- const verb = r.created ? c.green("created") : c.dim("overwritten");
9- writeln(` ${G.ok} ${verb} ${r.path}`);
10- renderDiff(r.diff);
11- return true;
12-}
13-
14-export function renderReplaceOrInsertResult(
15- toolName: string,
16- result: unknown,
17-): boolean {
18- const r = result as { path: string; diff: string; deleted?: boolean };
19- if (!r || typeof r.path !== "string") return false;
20- const verb =
21- toolName === "insert" ? "inserted" : r.deleted ? "deleted" : "replaced";
22- writeln(` ${G.ok} ${c.dim(verb)} ${r.path}`);
23- renderDiff(r.diff);
24- return true;
25-}
src/cli/tool-results/index.ts+0−36
@@ -1,36 +0,0 @@
1-import {
2- renderCreateResult,
3- renderReplaceOrInsertResult,
4-} from "./file-edits.ts";
5-import { renderMcpResult } from "./mcp.ts";
6-import { renderReadResult } from "./read.ts";
7-import { renderShellResult } from "./shell.ts";
8-import { renderReadSkillResult } from "./skills.ts";
9-import { renderSubagentResult } from "./subagent.ts";
10-import type { ToolResultRenderer } from "./types.ts";
11-import { renderWebContentResult, renderWebSearchResult } from "./web.ts";
12-
13-const TOOL_RESULT_RENDERERS: Readonly<Record<string, ToolResultRenderer>> = {
14- read: renderReadResult,
15- create: renderCreateResult,
16- replace: (result) => renderReplaceOrInsertResult("replace", result),
17- insert: (result) => renderReplaceOrInsertResult("insert", result),
18- shell: renderShellResult,
19- subagent: renderSubagentResult,
20- readSkill: renderReadSkillResult,
21- webSearch: renderWebSearchResult,
22- webContent: renderWebContentResult,
23-};
24-
25-export function renderToolResultByName(
26- toolName: string,
27- result: unknown,
28-): boolean {
29- if (toolName.startsWith("mcp_")) {
30- return renderMcpResult(result);
31- }
32-
33- const renderer = TOOL_RESULT_RENDERERS[toolName];
34- if (!renderer) return false;
35- return renderer(result, toolName);
36-}
src/cli/tool-results/mcp.ts+0−15
@@ -1,15 +0,0 @@
1-import * as c from "yoctocolors";
2-import { writeln } from "../output.ts";
3-
4-export function renderMcpResult(result: unknown): boolean {
5- const content = Array.isArray(result) ? result : [result];
6- for (const block of (
7- content as Array<{ type?: string; text?: string }>
8- ).slice(0, 5)) {
9- if (block?.type === "text" && block.text) {
10- const lines = block.text.split("\n").slice(0, 6);
11- for (const line of lines) writeln(` ${c.dim("│")} ${line}`);
12- }
13- }
14- return true;
15-}
src/cli/tool-results/read.ts+0−24
@@ -1,24 +0,0 @@
1-import * as c from "yoctocolors";
2-import { G, writeln } from "../output.ts";
3-
4-export function renderReadResult(result: unknown): boolean {
5- const r = result as {
6- path: string;
7- line: number;
8- totalLines: number;
9- truncated: boolean;
10- content?: string;
11- };
12- if (!r || typeof r.path !== "string") return false;
13-
14- const linesReturned = r.content ? r.content.split("\n").length : 0;
15- const endLine = linesReturned > 0 ? r.line + linesReturned - 1 : r.line;
16- const range =
17- r.line === 1 && endLine === r.totalLines
18- ? `${r.totalLines} lines`
19- : `lines ${r.line}–${endLine} of ${r.totalLines}`;
20- writeln(
21- ` ${G.info} ${c.dim(`${r.path} ${range}${r.truncated ? " (truncated)" : ""}`)}`,
22- );
23- return true;
24-}
src/cli/tool-results/shell.ts+0−74
@@ -1,74 +0,0 @@
1-import * as c from "yoctocolors";
2-import { writeln } from "../output.ts";
3-import { writePreviewLines } from "../tool-result-shared.ts";
4-
5-function truncateOneLine(value: string, max = 100): string {
6- return value.length > max ? `${value.slice(0, max - 1)}…` : value;
7-}
8-
9-export function renderShellResult(result: unknown): boolean {
10- const r = result as {
11- stdout: string;
12- stderr: string;
13- exitCode: number;
14- success: boolean;
15- timedOut: boolean;
16- };
17- if (!r || typeof r.stdout !== "string" || typeof r.stderr !== "string") {
18- return false;
19- }
20-
21- const badge = r.timedOut
22- ? c.yellow("timeout")
23- : r.success
24- ? c.green("success")
25- : c.red("error");
26-
27- const stdoutNormalized = r.stdout.replace(/[\r\n]+$/, "");
28- const stderrNormalized = r.stderr.replace(/[\r\n]+$/, "");
29- const stdoutLines = stdoutNormalized
30- ? stdoutNormalized.split(/\r?\n/).length
31- : 0;
32- const stderrLines = stderrNormalized
33- ? stderrNormalized.split(/\r?\n/).length
34- : 0;
35- const stdoutSingleLine =
36- stdoutLines === 1 ? (stdoutNormalized.split(/\r?\n/)[0] ?? "") : null;
37-
38- const parts = [
39- `exit ${r.exitCode}`,
40- `stdout ${stdoutLines}L`,
41- `stderr ${stderrLines}L`,
42- ];
43-
44- if (
45- r.success &&
46- !r.timedOut &&
47- stderrLines === 0 &&
48- stdoutSingleLine !== null &&
49- stdoutSingleLine.length > 0
50- ) {
51- parts.push(`out: ${truncateOneLine(stdoutSingleLine)}`);
52- }
53-
54- writeln(` ${badge} ${c.dim(parts.join(" · "))}`);
55-
56- if (r.success && !r.timedOut) {
57- return true;
58- }
59-
60- writePreviewLines({
61- label: "stderr",
62- value: r.stderr,
63- lineColor: c.red,
64- maxLines: 6,
65- });
66- writePreviewLines({
67- label: "stdout",
68- value: r.stdout,
69- lineColor: c.dim,
70- maxLines: 4,
71- });
72-
73- return true;
74-}
src/cli/tool-results/skills.ts+0−27
@@ -1,27 +0,0 @@
1-import * as c from "yoctocolors";
2-import { G, writeln } from "../output.ts";
3-
4-export function renderReadSkillResult(result: unknown): boolean {
5- const r = result as {
6- skill?: {
7- name?: string;
8- description?: string;
9- source?: "local" | "global";
10- };
11- };
12- if (!r || typeof r !== "object") return false;
13- if (!r.skill) {
14- writeln(` ${G.info} ${c.dim("skill")} ${c.dim("(not found)")}`);
15- return true;
16- }
17- const name = r.skill.name ?? "(unknown)";
18- const source = r.skill.source ?? "unknown";
19- const description = r.skill.description?.trim();
20- const descPart = description
21- ? ` ${c.dim("·")} ${c.dim(description.length > 60 ? `${description.slice(0, 57)}…` : description)}`
22- : "";
23- writeln(
24- ` ${G.info} ${c.dim("skill")} ${name} ${c.dim("·")} ${c.dim(source)}${descPart}`,
25- );
26- return true;
27-}
src/cli/tool-results/subagent.ts+0−16
@@ -1,16 +0,0 @@
1-import * as c from "yoctocolors";
2-import { G, writeln } from "../output.ts";
3-
4-export function renderSubagentResult(result: unknown): boolean {
5- const r = result as {
6- inputTokens?: number;
7- outputTokens?: number;
8- agentName?: string;
9- };
10- if (!r || typeof r !== "object") return false;
11- const label = r.agentName ? ` ${c.dim(c.cyan(`[@${r.agentName}]`))}` : "";
12- writeln(
13- ` ${G.agent}${label} ${c.dim(`subagent done (${r.inputTokens ?? 0}in / ${r.outputTokens ?? 0}out tokens)`)}`,
14- );
15- return true;
16-}
src/cli/tool-results/types.ts+0−4
@@ -1,4 +0,0 @@
1-export type ToolResultRenderer = (
2- result: unknown,
3- toolName?: string,
4-) => boolean;
src/cli/tool-results/web.ts+0−62
@@ -1,62 +0,0 @@
1-import * as c from "yoctocolors";
2-import { G, writeln } from "../output.ts";
3-
4-export function renderWebSearchResult(result: unknown): boolean {
5- const r = result as {
6- results?: Array<{ title?: string; url?: string; score?: number }>;
7- };
8- if (!Array.isArray(r?.results)) return false;
9- if (r.results.length === 0) {
10- writeln(` ${G.info} ${c.dim("no results")}`);
11- return true;
12- }
13-
14- for (const item of r.results.slice(0, 5)) {
15- const title = (item.title?.trim() || item.url || "(untitled)").replace(
16- /\s+/g,
17- " ",
18- );
19- const score =
20- typeof item.score === "number"
21- ? c.dim(` (${item.score.toFixed(2)})`)
22- : "";
23- writeln(` ${c.dim("•")} ${title}${score}`);
24- if (item.url) writeln(` ${c.dim(item.url)}`);
25- }
26-
27- if (r.results.length > 5) {
28- writeln(` ${c.dim(` +${r.results.length - 5} more`)}`);
29- }
30- return true;
31-}
32-
33-export function renderWebContentResult(result: unknown): boolean {
34- const r = result as {
35- results?: Array<{ url?: string; title?: string; text?: string }>;
36- };
37- if (!Array.isArray(r?.results)) return false;
38- if (r.results.length === 0) {
39- writeln(` ${G.info} ${c.dim("no pages")}`);
40- return true;
41- }
42-
43- for (const item of r.results.slice(0, 3)) {
44- const title = (item.title?.trim() || item.url || "(untitled)").replace(
45- /\s+/g,
46- " ",
47- );
48- writeln(` ${c.dim("•")} ${title}`);
49- if (item.url) writeln(` ${c.dim(item.url)}`);
50- const preview = (item.text ?? "").replace(/\s+/g, " ").trim();
51- if (preview) {
52- const trimmed =
53- preview.length > 220 ? `${preview.slice(0, 217)}…` : preview;
54- writeln(` ${c.dim(trimmed)}`);
55- }
56- }
57-
58- if (r.results.length > 3) {
59- writeln(` ${c.dim(` +${r.results.length - 3} more`)}`);
60- }
61- return true;
62-}