-
Notifications
You must be signed in to change notification settings - Fork 419
Refactor engine log parsing to canonical Copilot event format #38781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
78fe74e
bb3e105
f4ec735
82b4c14
61e5c21
1a9d5d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ | |
| * @property {(text: string) => number} estimateTokens | ||
| * @property {(ms: number) => string} formatDuration | ||
| * @property {(text: string) => string} unfenceMarkdown | ||
| * @property {(entries: Array<any>) => boolean} isCopilotEventLogEntries | ||
| * @property {(entries: Array<any>) => Array<any>} convertCopilotEventsToLegacyLogEntries | ||
| * @property {number} MAX_AGENT_TEXT_LENGTH | ||
| * @property {string} SIZE_LIMIT_WARNING | ||
| */ | ||
|
|
@@ -48,12 +50,21 @@ function createLogParserFormatters(deps) { | |
| estimateTokens, | ||
| formatDuration, | ||
| unfenceMarkdown, | ||
| isCopilotEventLogEntries, | ||
| convertCopilotEventsToLegacyLogEntries, | ||
| MAX_AGENT_TEXT_LENGTH, | ||
| SIZE_LIMIT_WARNING, | ||
| } = deps; | ||
|
|
||
| const INTERNAL_TOOLS = ["Read", "Write", "Edit", "MultiEdit", "LS", "Grep", "Glob", "TodoWrite"]; | ||
|
|
||
| function normalizeEntriesForRendering(logEntries) { | ||
| if (isCopilotEventLogEntries(logEntries)) { | ||
| return convertCopilotEventsToLegacyLogEntries(logEntries); | ||
| } | ||
| return logEntries; | ||
| } | ||
|
|
||
| /** | ||
| * Generates markdown summary from conversation log entries | ||
| * This is the core shared logic between Claude and Copilot log parsers | ||
|
|
@@ -70,8 +81,9 @@ function createLogParserFormatters(deps) { | |
| */ | ||
| function generateConversationMarkdown(logEntries, options) { | ||
| const { formatToolCallback, formatInitCallback, summaryTracker } = options; | ||
| const renderEntries = normalizeEntriesForRendering(logEntries); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call normalizing once before collectToolUsePairs; avoids repeated conversion downstream. |
||
|
|
||
| const toolUsePairs = collectToolUsePairs(logEntries); | ||
| const toolUsePairs = collectToolUsePairs(renderEntries); | ||
|
|
||
| let markdown = ""; | ||
| let sizeLimitReached = false; | ||
|
|
@@ -85,7 +97,7 @@ function createLogParserFormatters(deps) { | |
| return true; | ||
| } | ||
|
|
||
| const initEntry = logEntries.find(entry => entry.type === "system" && entry.subtype === "init"); | ||
| const initEntry = renderEntries.find(entry => entry.type === "system" && entry.subtype === "init"); | ||
|
|
||
| if (initEntry && formatInitCallback) { | ||
| if (!addContent("## 🚀 Initialization\n\n")) { | ||
|
|
@@ -110,7 +122,7 @@ function createLogParserFormatters(deps) { | |
| return { markdown, commandSummary: [], sizeLimitReached }; | ||
| } | ||
|
|
||
| for (const entry of logEntries) { | ||
| for (const entry of renderEntries) { | ||
| if (sizeLimitReached) break; | ||
|
|
||
| if (entry.type === "assistant" && entry.message?.content) { | ||
|
|
@@ -158,7 +170,7 @@ function createLogParserFormatters(deps) { | |
|
|
||
| const commandSummary = []; | ||
|
|
||
| for (const entry of logEntries) { | ||
| for (const entry of renderEntries) { | ||
| if (entry.type === "assistant" && entry.message?.content) { | ||
| for (const content of entry.message.content) { | ||
| if (content.type === "tool_use") { | ||
|
|
@@ -522,8 +534,9 @@ function createLogParserFormatters(deps) { | |
| } | ||
|
|
||
| function generateSummaryLines(logEntries) { | ||
| const renderEntries = normalizeEntriesForRendering(logEntries); | ||
| const lines = []; | ||
| const toolUsePairs = collectToolUsePairs(logEntries); | ||
| const toolUsePairs = collectToolUsePairs(renderEntries); | ||
|
|
||
| const state = { | ||
| conversationLineCount: 0, | ||
|
|
@@ -532,7 +545,7 @@ function createLogParserFormatters(deps) { | |
| traceEventCount: 0, | ||
| }; | ||
|
|
||
| for (const entry of logEntries) { | ||
| for (const entry of renderEntries) { | ||
| if (state.conversationLineCount >= state.maxConversationLines) { | ||
| state.conversationTruncated = true; | ||
| break; | ||
|
|
@@ -569,7 +582,7 @@ function createLogParserFormatters(deps) { | |
| lines.push(""); | ||
| } | ||
|
|
||
| appendStatistics(lines, logEntries, toolUsePairs); | ||
| appendStatistics(lines, renderEntries, toolUsePairs); | ||
|
|
||
| return lines; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice extraction of normalizeEntriesForRendering — keeps the conversion concern in one place.