@@ -1,7 +1,15 @@
11 import * as c from "yoctocolors";
22 import { G, writeln } from "./output.ts";
33
4-type ToolResultRenderer = (result: unknown, toolName?: string) => boolean;
4+interface ToolResultRenderOptions {
5+ verboseOutput?: boolean;
6+}
7+
8+type ToolResultRenderer = (
9+ result: unknown,
10+ opts?: ToolResultRenderOptions,
11+ toolName?: string,
12+) => boolean;
513 function writePreviewLines(opts: {
614 label: string;
715 value: string;
@@ -11,17 +19,35 @@ function writePreviewLines(opts: {
1119 if (!opts.value.trim()) return;
1220 const lines = opts.value.split("\n");
1321 writeln(` ${c.dim(opts.label)} ${c.dim(`(${lines.length} lines)`)}`);
14- for (const line of lines.slice(0, opts.maxLines)) {
22+ if (!Number.isFinite(opts.maxLines) || lines.length <= opts.maxLines) {
23+ for (const line of lines) {
24+ writeln(` ${opts.lineColor("│")} ${line}`);
25+ }
26+ return;
27+ }
28+
29+ const headCount = Math.max(1, Math.ceil(opts.maxLines / 2));
30+ const tailCount = Math.max(0, Math.floor(opts.maxLines / 2));
31+ for (const line of lines.slice(0, headCount)) {
1532 writeln(` ${opts.lineColor("│")} ${line}`);
1633 }
17- if (lines.length > opts.maxLines) {
18- writeln(
19- ` ${opts.lineColor("│")} ${c.dim(`… +${lines.length - opts.maxLines} lines`)}`,
20- );
34+ const hiddenLines = Math.max(0, lines.length - (headCount + tailCount));
35+ if (hiddenLines > 0) {
36+ writeln(` ${opts.lineColor("│")} ${c.dim(`… +${hiddenLines} lines`)}`);
37+ }
38+ if (tailCount > 0) {
39+ for (const line of lines.slice(-tailCount)) {
40+ writeln(` ${opts.lineColor("│")} ${line}`);
41+ }
2142 }
2243 }
2344
24-function truncateOneLine(value: string, max = 100): string {
45+function truncateOneLine(
46+ value: string,
47+ max = 100,
48+ verboseOutput = false,
49+): string {
50+ if (verboseOutput) return value;
2551 return value.length > max ? `${value.slice(0, max - 1)}…` : value;
2652 }
2753
@@ -47,6 +73,7 @@ function buildShellSummaryParts(opts: {
4773 stderrLines: number;
4874 stdoutSingleLine: string | null;
4975 streamedOutput: boolean;
76+ verboseOutput: boolean;
5077 }): string[] {
5178 const parts = [`exit ${opts.exitCode}`];
5279 if (opts.streamedOutput) {
@@ -64,7 +91,9 @@ function buildShellSummaryParts(opts: {
6491 opts.stdoutSingleLine !== null &&
6592 opts.stdoutSingleLine.length > 0
6693 ) {
67- parts.push(`out: ${truncateOneLine(opts.stdoutSingleLine)}`);
94+ parts.push(
95+ `out: ${truncateOneLine(opts.stdoutSingleLine, 100, opts.verboseOutput)}`,
96+ );
6897 return parts;
6998 }
7099
@@ -91,7 +120,10 @@ function shouldPreviewShellStdout(opts: {
91120 return opts.stdoutSingleLine === null;
92121 }
93122
94-function renderShellResult(result: unknown): boolean {
123+function renderShellResult(
124+ result: unknown,
125+ opts?: ToolResultRenderOptions,
126+): boolean {
95127 const r = result as {
96128 stdout: string;
97129 stderr: string;
@@ -105,6 +137,7 @@ function renderShellResult(result: unknown): boolean {
105137 }
106138
107139 const streamedOutput = r.streamedOutput === true;
140+ const verboseOutput = opts?.verboseOutput === true;
108141 const stdoutLines = countShellLines(r.stdout);
109142 const stderrLines = countShellLines(r.stderr);
110143 const stdoutSingleLine = getSingleShellLine(r.stdout);
@@ -119,6 +152,7 @@ function renderShellResult(result: unknown): boolean {
119152 stderrLines,
120153 stdoutSingleLine,
121154 streamedOutput,
155+ verboseOutput,
122156 });
123157
124158 writeln(` ${badge} ${c.dim(parts.join(" · "))}`);
@@ -131,7 +165,7 @@ function renderShellResult(result: unknown): boolean {
131165 label: "stderr",
132166 value: r.stderr,
133167 lineColor: c.red,
134- maxLines: 6,
168+ maxLines: verboseOutput ? Number.POSITIVE_INFINITY : 6,
135169 });
136170 if (
137171 shouldPreviewShellStdout({
@@ -145,13 +179,16 @@ function renderShellResult(result: unknown): boolean {
145179 label: "stdout",
146180 value: r.stdout,
147181 lineColor: c.dim,
148- maxLines: 4,
182+ maxLines: verboseOutput ? Number.POSITIVE_INFINITY : 4,
149183 });
150184 }
151185
152186 return true;
153187 }
154-function renderSubagentResult(result: unknown): boolean {
188+function renderSubagentResult(
189+ result: unknown,
190+ _opts?: ToolResultRenderOptions,
191+): boolean {
155192 const r = result as {
156193 inputTokens?: number;
157194 outputTokens?: number;
@@ -165,9 +202,13 @@ function renderSubagentResult(result: unknown): boolean {
165202 return true;
166203 }
167204
168-function buildSkillDescriptionPart(description: string | undefined): string {
205+function buildSkillDescriptionPart(
206+ description: string | undefined,
207+ verboseOutput = false,
208+): string {
169209 const trimmed = description?.trim();
170210 if (!trimmed) return "";
211+ if (verboseOutput) return ` ${c.dim("·")} ${c.dim(trimmed)}`;
171212 return ` ${c.dim("·")} ${c.dim(trimmed.length > 60 ? `${trimmed.slice(0, 57)}…` : trimmed)}`;
172213 }
173214
@@ -177,17 +218,20 @@ function renderSkillSummaryLine(
177218 description?: string;
178219 source?: "local" | "global";
179220 },
180- label?: string,
221+ opts?: { label?: string; verboseOutput?: boolean },
181222 ): void {
182223 const name = skill.name ?? "(unknown)";
183224 const source = skill.source ?? "unknown";
184- const labelPrefix = label ? `${c.dim(label)} ` : "";
225+ const labelPrefix = opts?.label ? `${c.dim(opts.label)} ` : "";
185226 writeln(
186- ` ${G.info} ${labelPrefix}${name} ${c.dim("·")} ${c.dim(source)}${buildSkillDescriptionPart(skill.description)}`,
227+ ` ${G.info} ${labelPrefix}${name} ${c.dim("·")} ${c.dim(source)}${buildSkillDescriptionPart(skill.description, opts?.verboseOutput === true)}`,
187228 );
188229 }
189230
190-function renderListSkillsResult(result: unknown): boolean {
231+function renderListSkillsResult(
232+ result: unknown,
233+ opts?: ToolResultRenderOptions,
234+): boolean {
191235 const r = result as {
192236 skills?: Array<{
193237 name?: string;
@@ -201,17 +245,23 @@ function renderListSkillsResult(result: unknown): boolean {
201245 return true;
202246 }
203247
204- for (const skill of r.skills.slice(0, 6)) {
205- renderSkillSummaryLine(skill);
248+ const maxSkills = opts?.verboseOutput ? r.skills.length : 6;
249+ for (const skill of r.skills.slice(0, maxSkills)) {
250+ renderSkillSummaryLine(skill, {
251+ verboseOutput: opts?.verboseOutput === true,
252+ });
206253 }
207254
208- if (r.skills.length > 6) {
209- writeln(` ${c.dim(`+${r.skills.length - 6} more skills`)}`);
255+ if (r.skills.length > maxSkills) {
256+ writeln(` ${c.dim(`+${r.skills.length - maxSkills} more skills`)}`);
210257 }
211258 return true;
212259 }
213260
214-function renderReadSkillResult(result: unknown): boolean {
261+function renderReadSkillResult(
262+ result: unknown,
263+ _opts?: ToolResultRenderOptions,
264+): boolean {
215265 const r = result as {
216266 skill?: {
217267 name?: string;
@@ -224,11 +274,17 @@ function renderReadSkillResult(result: unknown): boolean {
224274 writeln(` ${G.info} ${c.dim("skill")} ${c.dim("(not found)")}`);
225275 return true;
226276 }
227- renderSkillSummaryLine(r.skill, "skill");
277+ renderSkillSummaryLine(r.skill, {
278+ label: "skill",
279+ verboseOutput: _opts?.verboseOutput === true,
280+ });
228281 return true;
229282 }
230283
231-function renderWebSearchResult(result: unknown): boolean {
284+function renderWebSearchResult(
285+ result: unknown,
286+ opts?: ToolResultRenderOptions,
287+): boolean {
232288 const r = result as {
233289 results?: Array<{ title?: string; url?: string; score?: number }>;
234290 };
@@ -238,7 +294,8 @@ function renderWebSearchResult(result: unknown): boolean {
238294 return true;
239295 }
240296
241- for (const item of r.results.slice(0, 5)) {
297+ const maxResults = opts?.verboseOutput ? r.results.length : 5;
298+ for (const item of r.results.slice(0, maxResults)) {
242299 const title = (item.title?.trim() || item.url || "(untitled)").replace(
243300 /\s+/g,
244301 " ",
@@ -251,13 +308,16 @@ function renderWebSearchResult(result: unknown): boolean {
251308 if (item.url) writeln(` ${c.dim(item.url)}`);
252309 }
253310
254- if (r.results.length > 5) {
255- writeln(` ${c.dim(` +${r.results.length - 5} more`)}`);
311+ if (r.results.length > maxResults) {
312+ writeln(` ${c.dim(` +${r.results.length - maxResults} more`)}`);
256313 }
257314 return true;
258315 }
259316
260-function renderWebContentResult(result: unknown): boolean {
317+function renderWebContentResult(
318+ result: unknown,
319+ opts?: ToolResultRenderOptions,
320+): boolean {
261321 const r = result as {
262322 results?: Array<{ url?: string; title?: string; text?: string }>;
263323 };
@@ -267,7 +327,8 @@ function renderWebContentResult(result: unknown): boolean {
267327 return true;
268328 }
269329
270- for (const item of r.results.slice(0, 3)) {
330+ const maxPages = opts?.verboseOutput ? r.results.length : 3;
331+ for (const item of r.results.slice(0, maxPages)) {
271332 const title = (item.title?.trim() || item.url || "(untitled)").replace(
272333 /\s+/g,
273334 " ",
@@ -277,24 +338,31 @@ function renderWebContentResult(result: unknown): boolean {
277338 const preview = (item.text ?? "").replace(/\s+/g, " ").trim();
278339 if (preview) {
279340 const trimmed =
280- preview.length > 220 ? `${preview.slice(0, 217)}…` : preview;
341+ opts?.verboseOutput || preview.length <= 220
342+ ? preview
343+ : `${preview.slice(0, 217)}…`;
281344 writeln(` ${c.dim(trimmed)}`);
282345 }
283346 }
284347
285- if (r.results.length > 3) {
286- writeln(` ${c.dim(` +${r.results.length - 3} more`)}`);
348+ if (r.results.length > maxPages) {
349+ writeln(` ${c.dim(` +${r.results.length - maxPages} more`)}`);
287350 }
288351 return true;
289352 }
290353
291-function renderMcpResult(result: unknown): boolean {
354+function renderMcpResult(
355+ result: unknown,
356+ opts?: ToolResultRenderOptions,
357+): boolean {
292358 const content = Array.isArray(result) ? result : [result];
359+ const maxBlocks = opts?.verboseOutput ? content.length : 5;
293360 for (const block of (
294361 content as Array<{ type?: string; text?: string }>
295- ).slice(0, 5)) {
362+ ).slice(0, maxBlocks)) {
296363 if (block?.type === "text" && block.text) {
297- const lines = block.text.split("\n").slice(0, 6);
364+ const maxLines = opts?.verboseOutput ? Number.POSITIVE_INFINITY : 6;
365+ const lines = block.text.split("\n").slice(0, maxLines);
298366 for (const line of lines) writeln(` ${c.dim("│")} ${line}`);
299367 }
300368 }
@@ -313,12 +381,13 @@ const TOOL_RESULT_RENDERERS: Readonly<Record<string, ToolResultRenderer>> = {
313381 export function renderToolResultByName(
314382 toolName: string,
315383 result: unknown,
384+ opts?: ToolResultRenderOptions,
316385 ): boolean {
317386 if (toolName.startsWith("mcp_")) {
318- return renderMcpResult(result);
387+ return renderMcpResult(result, opts);
319388 }
320389
321390 const renderer = TOOL_RESULT_RENDERERS[toolName];
322391 if (!renderer) return false;
323- return renderer(result, toolName);
392+ return renderer(result, opts, toolName);
324393 }