From 324aa1d6477a2c889841a720600983af49a8dc26 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 4 May 2026 00:52:56 +0200 Subject: [PATCH] fix(coding-agent): render compact read calls directly Render compact read classifications in the call row and leave the collapsed result row empty. The previous implementation used shared renderer state to let renderResult hide renderCall, which leaked an internal ReadRenderState type through the tool definition and coupled two render phases unnecessarily. The call renderer has all context needed to choose the compact presentation itself. --- packages/coding-agent/src/core/tools/read.ts | 37 ++++---------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/packages/coding-agent/src/core/tools/read.ts b/packages/coding-agent/src/core/tools/read.ts index 08e4f825..432e5254 100644 --- a/packages/coding-agent/src/core/tools/read.ts +++ b/packages/coding-agent/src/core/tools/read.ts @@ -33,20 +33,6 @@ interface CompactReadClassification { label: string; } -interface ReadRenderState { - hideCall?: boolean; -} - -class ReadCallText extends Text { - constructor(private state: ReadRenderState) { - super("", 0, 0); - } - - override render(width: number): string[] { - return this.state.hideCall ? [] : super.render(width); - } -} - const COMPACT_RESOURCE_FILE_NAMES = new Set(["AGENTS.md", "AGENTS.MD", "CLAUDE.md", "CLAUDE.MD"]); /** @@ -154,7 +140,7 @@ function getCompactReadClassification( return undefined; } -function formatCompactReadResult(classification: CompactReadClassification, theme: Theme): string { +function formatCompactReadCall(classification: CompactReadClassification, theme: Theme): string { if (classification.kind === "skill") { return ( theme.fg("customMessageLabel", `\x1b[1m[skill]\x1b[22m `) + @@ -180,11 +166,8 @@ function formatReadResult( cwd: string, isError: boolean, ): string { - if (!options.expanded && !isError) { - const classification = getCompactReadClassification(args, cwd); - if (classification) { - return formatCompactReadResult(classification, theme); - } + if (!options.expanded && !isError && getCompactReadClassification(args, cwd)) { + return ""; } const rawPath = str(args?.file_path ?? args?.path); @@ -216,7 +199,7 @@ function formatReadResult( export function createReadToolDefinition( cwd: string, options?: ReadToolOptions, -): ToolDefinition { +): ToolDefinition { const autoResizeImages = options?.autoResizeImages ?? true; const ops = options?.operations ?? defaultReadOperations; return { @@ -351,22 +334,16 @@ export function createReadToolDefinition( ); }, renderCall(args, theme, context) { - const text = - context.lastComponent instanceof ReadCallText ? context.lastComponent : new ReadCallText(context.state); - context.state.hideCall = false; - text.setText(formatReadCall(args, theme)); + const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0); + const classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined; + text.setText(classification ? formatCompactReadCall(classification, theme) : formatReadCall(args, theme)); return text; }, renderResult(result, options, theme, context) { const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0); - const hideCall = - !options.expanded && - !context.isError && - getCompactReadClassification(context.args, context.cwd) !== undefined; text.setText( formatReadResult(context.args, result, options, theme, context.showImages, context.cwd, context.isError), ); - context.state.hideCall = hideCall; return text; }, };