* Generates information section markdown from the last log entry * @param {any} lastEntry - The last log entry with metadata (num_turns, duration_ms, etc.) * @param {Object} options - Configuration options * @param {Function} [options.additionalInfoCallback] - Optional callback for additional inf
(lastEntry, options = {})
| 270 | * @returns {string} Information section markdown |
| 271 | */ |
| 272 | function generateInformationSection(lastEntry, options = {}) { |
| 273 | const { additionalInfoCallback } = options; |
| 274 | |
| 275 | let markdown = "\n## 📊 Information\n\n"; |
| 276 | |
| 277 | if (!lastEntry) { |
| 278 | return markdown; |
| 279 | } |
| 280 | |
| 281 | if (lastEntry.num_turns) { |
| 282 | markdown += `**Turns:** ${lastEntry.num_turns}\n\n`; |
| 283 | } |
| 284 | |
| 285 | if (lastEntry.duration_ms) { |
| 286 | const durationSec = Math.round(lastEntry.duration_ms / 1000); |
| 287 | const minutes = Math.floor(durationSec / 60); |
| 288 | const seconds = durationSec % 60; |
| 289 | markdown += `**Duration:** ${minutes}m ${seconds}s\n\n`; |
| 290 | } |
| 291 | |
| 292 | if (lastEntry.total_cost_usd) { |
| 293 | markdown += `**Total Cost:** $${lastEntry.total_cost_usd.toFixed(4)}\n\n`; |
| 294 | } |
| 295 | |
| 296 | // Call additional info callback if provided (for engine-specific info) |
| 297 | if (additionalInfoCallback) { |
| 298 | const additionalInfo = additionalInfoCallback(lastEntry); |
| 299 | if (additionalInfo) { |
| 300 | markdown += additionalInfo; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | if (lastEntry.usage) { |
| 305 | const usage = lastEntry.usage; |
| 306 | if (usage.input_tokens || usage.output_tokens) { |
| 307 | // Calculate total tokens (matching Go parser logic) |
| 308 | const inputTokens = usage.input_tokens || 0; |
| 309 | const outputTokens = usage.output_tokens || 0; |
| 310 | const cacheCreationTokens = usage.cache_creation_input_tokens || 0; |
| 311 | const cacheReadTokens = usage.cache_read_input_tokens || 0; |
| 312 | const totalTokens = inputTokens + outputTokens + cacheCreationTokens + cacheReadTokens; |
| 313 | |
| 314 | markdown += `**Token Usage:**\n`; |
| 315 | if (totalTokens > 0) markdown += `- Total: ${totalTokens.toLocaleString()}\n`; |
| 316 | if (usage.input_tokens) markdown += `- Input: ${usage.input_tokens.toLocaleString()}\n`; |
| 317 | if (usage.cache_creation_input_tokens) markdown += `- Cache Creation: ${usage.cache_creation_input_tokens.toLocaleString()}\n`; |
| 318 | if (usage.cache_read_input_tokens) markdown += `- Cache Read: ${usage.cache_read_input_tokens.toLocaleString()}\n`; |
| 319 | if (usage.output_tokens) markdown += `- Output: ${usage.output_tokens.toLocaleString()}\n`; |
| 320 | markdown += "\n"; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | if (lastEntry.errors && Array.isArray(lastEntry.errors) && lastEntry.errors.length > 0) { |
| 325 | markdown += `**Errors:**\n`; |
| 326 | for (const error of lastEntry.errors) { |
| 327 | markdown += `- ${error}\n`; |
| 328 | } |
| 329 | markdown += "\n"; |
no outgoing calls
no test coverage detected