* 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 = {})
| 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(/^\/[^\/]*\/[^\/]*\/[^\/]*\/[^\/]*\//, ""); |
no test coverage detected