* Parses Copilot CLI debug log format and reconstructs the conversation flow * @param {string} logContent - Raw debug log content * @returns {Array} Array of log entries in structured format
(logContent)
| 501 | * @returns {Array} Array of log entries in structured format |
| 502 | */ |
| 503 | function parseDebugLogFormat(logContent) { |
| 504 | const entries = []; |
| 505 | const lines = logContent.split("\n"); |
| 506 | |
| 507 | // First pass: scan for tool errors |
| 508 | const toolErrors = scanForToolErrors(logContent); |
| 509 | |
| 510 | // Extract model information from the start |
| 511 | let model = "unknown"; |
| 512 | let sessionId = null; |
| 513 | let modelInfo = null; |
| 514 | let tools = []; |
| 515 | const modelMatch = logContent.match(/Starting Copilot CLI: ([\d.]+)/); |
| 516 | if (modelMatch) { |
| 517 | sessionId = `copilot-${modelMatch[1]}-${Date.now()}`; |
| 518 | } |
| 519 | |
| 520 | // Extract premium model info from "Got model info:" JSON block |
| 521 | // Look for a multi-line JSON block that starts with "Got model info: {" and ends with "}" |
| 522 | const gotModelInfoIndex = logContent.indexOf("[DEBUG] Got model info: {"); |
| 523 | if (gotModelInfoIndex !== -1) { |
| 524 | // Find the start of the JSON (the opening brace) |
| 525 | const jsonStart = logContent.indexOf("{", gotModelInfoIndex); |
| 526 | if (jsonStart !== -1) { |
| 527 | // Track braces to find the end of the JSON |
| 528 | let braceCount = 0; |
| 529 | let inString = false; |
| 530 | let escapeNext = false; |
| 531 | let jsonEnd = -1; |
| 532 | |
| 533 | for (let i = jsonStart; i < logContent.length; i++) { |
| 534 | const char = logContent[i]; |
| 535 | |
| 536 | if (escapeNext) { |
| 537 | escapeNext = false; |
| 538 | continue; |
| 539 | } |
| 540 | |
| 541 | if (char === "\\") { |
| 542 | escapeNext = true; |
| 543 | continue; |
| 544 | } |
| 545 | |
| 546 | if (char === '"' && !escapeNext) { |
| 547 | inString = !inString; |
| 548 | continue; |
| 549 | } |
| 550 | |
| 551 | if (inString) continue; |
| 552 | |
| 553 | if (char === "{") { |
| 554 | braceCount++; |
| 555 | } else if (char === "}") { |
| 556 | braceCount--; |
| 557 | if (braceCount === 0) { |
| 558 | jsonEnd = i + 1; |
| 559 | break; |
| 560 | } |
no test coverage detected