MCPcopy Create free account
hub / github.com/github/gh-aw / formatToolUse

Function formatToolUse

actions/setup/js/log_parser_format.cjs:249–383  ·  view source on GitHub ↗

* Formats a tool use entry with its result into markdown * @param {any} toolUse - The tool use object containing name, input, etc. * @param {any} toolResult - The corresponding tool result object * @param {Object} options - Configuration options * @param {boolean} [options.includeDetaile

(toolUse, toolResult, options = {})

Source from the content-addressed store, hash-verified

247 * @returns {string} Formatted markdown string
248 */
249 function formatToolUse(toolUse, toolResult, options = {}) {
250 const { includeDetailedParameters = false } = options;
251 const toolName = toolUse.name;
252 const input = toolUse.input || {};
253
254 if (toolName === "TodoWrite") {
255 return "";
256 }
257
258 function getStatusIcon() {
259 if (toolResult) {
260 return toolResult.is_error === true ? "❌" : "✅";
261 }
262 return "❓";
263 }
264
265 const statusIcon = getStatusIcon();
266 let summary = "";
267 let details = "";
268
269 if (toolResult && toolResult.content) {
270 if (typeof toolResult.content === "string") {
271 details = toolResult.content;
272 } else if (Array.isArray(toolResult.content)) {
273 details = toolResult.content.map(c => (typeof c === "string" ? c : c.text || "")).join("\n");
274 }
275 }
276
277 const inputText = JSON.stringify(input);
278 const outputText = details;
279 const totalTokens = estimateTokens(inputText) + estimateTokens(outputText);
280
281 let metadata = "";
282 if (toolResult && toolResult.duration_ms) {
283 metadata += `<code>${formatDuration(toolResult.duration_ms)}</code> `;
284 }
285 if (totalTokens > 0) {
286 metadata += `<code>~${totalTokens}t</code>`;
287 }
288 metadata = metadata.trim();
289
290 switch (toolName) {
291 case "Bash": {
292 const command = input.command || "";
293 const description = input.description || "";
294 const formattedCommand = formatBashCommand(command);
295
296 if (description) {
297 summary = `${description}: <code>${formattedCommand}</code>`;
298 } else {
299 summary = `<code>${formattedCommand}</code>`;
300 }
301 break;
302 }
303
304 case "Read": {
305 const filePath = input.file_path || input.path || "";
306 const relativePath = filePath.replace(/^\/[^\/]*\/[^\/]*\/[^\/]*\/[^\/]*\//, "");

Callers 5

parseClaudeLogFunction · 0.85
parseGeminiLogFunction · 0.85
parseCopilotLogFunction · 0.85
parsePiLogFunction · 0.85

Calls 8

getStatusIconFunction · 0.85
formatBashCommandFunction · 0.85
truncateStringFunction · 0.85
formatMcpNameFunction · 0.85
formatMcpParametersFunction · 0.85
formatToolCallAsDetailsFunction · 0.85
estimateTokensFunction · 0.70
formatDurationFunction · 0.70

Tested by

no test coverage detected