fix: support gemini transcript parsing in summarize hook#1804
fix: support gemini transcript parsing in summarize hook#1804themactep wants to merge 2 commits intothedotmack:mainfrom
Conversation
- detect platform source from hook metadata and include platform fields in summarize/complete requests - parse both JSON and JSONL transcript formats with cross-platform role mappings - rebuild generated plugin artifacts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Summary by CodeRabbit
WalkthroughThe summarize handler now derives and includes a platform source ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/shared/transcript-parser.ts (1)
30-42: Avoid exception-driven format detection on the hot path.Claude JSONL still pays for a full
JSON.parse(...)failure before the real parse. A cheap first-character check would keep the common path out of exception handling.♻️ Possible simplification
- // Try parsing as standard JSON (Gemini CLI format) - try { - const data = JSON.parse(rawContent); - if (Array.isArray(data.messages)) { - messages = data.messages; - } else if (Array.isArray(data)) { - messages = data; - } else { - isJSONL = true; - } - } catch { - isJSONL = true; - } + // Try parsing as standard JSON (Gemini CLI format) + const firstChar = rawContent[0]; + if (firstChar === '{' || firstChar === '[') { + try { + const data = JSON.parse(rawContent); + if (Array.isArray(data.messages)) { + messages = data.messages; + } else if (Array.isArray(data)) { + messages = data; + } else { + isJSONL = true; + } + } catch { + isJSONL = true; + } + } else { + isJSONL = true; + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/shared/transcript-parser.ts` around lines 30 - 42, The current code always calls JSON.parse(rawContent) inside a try/catch which is expensive on the hot path; replace that with a cheap first-character check on rawContent (e.g., const first = rawContent.trimStart()[0]) and only attempt JSON.parse when first === '[' or first === '{' (then run the existing JSON.parse block to populate messages or mark isJSONL accordingly); otherwise set isJSONL = true immediately. Update the logic around the JSON.parse call and variables rawContent, isJSONL, and messages so you avoid throwing/handling exceptions for non-JSON transcripts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/shared/transcript-parser.ts`:
- Around line 68-75: The loop over messages should skip non-object/nullable
entries before accessing msg.type; inside the for loop that iterates messages
(the block using foundMatchingRole and calling targetTypes.includes(msg.type)),
add a guard like if (typeof msg !== 'object' || msg === null) continue so
primitive/null entries are skipped, then proceed to use
targetTypes.includes(msg.type) and extract msg.message?.content or msg.content
safely (refer to variables/functions: messages, targetTypes, foundMatchingRole,
msgContent, msg.message?.content).
---
Nitpick comments:
In `@src/shared/transcript-parser.ts`:
- Around line 30-42: The current code always calls JSON.parse(rawContent) inside
a try/catch which is expensive on the hot path; replace that with a cheap
first-character check on rawContent (e.g., const first =
rawContent.trimStart()[0]) and only attempt JSON.parse when first === '[' or
first === '{' (then run the existing JSON.parse block to populate messages or
mark isJSONL accordingly); otherwise set isJSONL = true immediately. Update the
logic around the JSON.parse call and variables rawContent, isJSONL, and messages
so you avoid throwing/handling exceptions for non-JSON transcripts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b522b3c7-2340-4d47-91ff-b77069ae4ee4
📒 Files selected for processing (5)
plugin/scripts/mcp-server.cjsplugin/scripts/worker-service.cjsplugin/ui/viewer-bundle.jssrc/cli/handlers/summarize.tssrc/shared/transcript-parser.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Closed during the April 2026 backlog cleanup. The underlying bug is now tracked in #1909, which is the single canonical issue being addressed by the maintainer. Thanks for taking the time to report — your symptoms and repro are captured in the consolidated ticket. |
This PR adds support for gemini transcript parsing in the summarize hook, detecting platform source and handling both JSON and JSONL formats with cross-platform role mappings.