MCPcopy Create free account
hub / github.com/apache/maka / renderExpandedToolBlock

Function renderExpandedToolBlock

packages/cli/src/pi-transcript-tools.ts:140–188  ·  view source on GitHub ↗
(entry: MakaPiToolEntry, width: number)

Source from the content-addressed store, hash-verified

138}
139
140function renderExpandedToolBlock(entry: MakaPiToolEntry, width: number): string[] {
141 const duration = toolDurationText(entry);
142 let header = `${toolDisc(entry)} ${entry.title ?? entry.toolName}`;
143 if (duration) header += ` (${duration})`;
144 const lines = [fitLine(header, width)];
145
146 const inputSummary = toolInputSummary(entry);
147 if (inputSummary) lines.push(...renderIndented(inputSummary, width, 2).map(ansi.dim));
148 if (entry.progress.droppedChars > 0) {
149 lines.push(
150 ...renderIndented(
151 ansi.dim(`⋯ ${entry.progress.droppedChars} earlier progress chars truncated ⋯`),
152 width,
153 2,
154 ),
155 );
156 }
157 if (entry.progress.length > 0) {
158 lines.push(...renderCappedResultText(entry.progress.values().join(''), width, ansi.dim));
159 }
160 // A terminal snapshot is the authoritative accumulated stream. Rendering
161 // the deltas that preceded it as well would repeat every line once the Bash
162 // card settles. Compact results intentionally keep the live deltas because
163 // they may be the only output available.
164 const renderLiveOutput = !shellResultSupersedesLiveOutput(entry.result);
165 if (renderLiveOutput) {
166 if (entry.outputDeltas.droppedChars > 0) {
167 lines.push(
168 ...renderIndented(
169 ansi.dim(`⋯ ${entry.outputDeltas.droppedChars} earlier live-output chars truncated ⋯`),
170 width,
171 2,
172 ),
173 );
174 }
175 lines.push(...renderToolStreams(entry.outputDeltas.values(), width));
176 }
177 if (entry.result || entry.output) {
178 lines.push(...renderToolResult(entry, width));
179 }
180 if (
181 entry.toolName === 'Bash' &&
182 entry.status === 'running' &&
183 entry.result?.kind === 'shell_run'
184 ) {
185 lines.push(...renderIndented(ansi.dim('Ask Maka to stop this task'), width, 2));
186 }
187 return lines.map((line) => fitLine(line, width));
188}
189
190function shellResultSupersedesLiveOutput(result: ToolResultContent | undefined): boolean {
191 return (

Callers 1

renderToolBlockFunction · 0.85

Calls 12

toolDurationTextFunction · 0.85
toolDiscFunction · 0.85
fitLineFunction · 0.85
toolInputSummaryFunction · 0.85
renderIndentedFunction · 0.85
renderCappedResultTextFunction · 0.85
renderToolStreamsFunction · 0.85
renderToolResultFunction · 0.85
joinMethod · 0.80
valuesMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected