-
Notifications
You must be signed in to change notification settings - Fork 421
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
Merged
+530
−305
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
78fe74e
Plan log parser event-format refactor
Copilot bb3e105
Refactor parsers to emit Copilot event entries
Copilot f4ec735
Update; rm -rf /
Copilot 82b4c14
Finalize copilot event log parser refactor
Copilot 61e5c21
Remove unused initEntry variable; fix perfsprint lint in action_resol…
Copilot 1a9d5d7
Add changeset
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.