Add OpenCode support to winui-session-report - #147
Add OpenCode support to winui-session-report#147Zhanyuanium (Zhanyuanium) wants to merge 1 commit into
Conversation
Parse OpenCode sessions from the official opencode export JSON and emit the same normalized report as Copilot CLI and Claude Code. -Format OpenCode accepts either -SessionId (shells out to opencode session list + opencode export) or -EventsFile (a saved export JSON, format-sniffed). Includes OpenCode tool-name normalization, skill and task (subagent) detection, and cache-token reporting. README skill/tool tables updated to reflect OpenCode. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Nikola Metulev (nmetulev)
left a comment
There was a problem hiding this comment.
Thanks for adding OpenCode support. I did not find malware-like or destructive behavior: there is no transcript exfiltration, persistence, privilege change, unexpected file deletion, or shell injection in this change.
I am requesting changes for four concrete correctness and safety gaps. The first two can run an unrequested executable or generate a report from the wrong private session; the other two make failures hard to diagnose and leave the new parser unprotected against regressions. Please address all four inline comments before merging.
| if ($session -and -not $detectedFormat) { $detectedFormat = 'ClaudeCode' } | ||
| } | ||
| if (-not $session) { | ||
| $session = Find-OpenCodeSessionById -Id $SessionId |
There was a problem hiding this comment.
The documentation says OpenCode is opt-in, but this fallback launches the PATH-resolved opencode executable whenever an ID is not found in Copilot or Claude.
For example:
.\Analyze-Session.ps1 -SessionId "missing-session"currently does this:
Search Copilot -> not found
Search Claude -> not found
Run `opencode session list --format json`
Please remove the implicit OpenCode fallback and invoke OpenCode only when the caller explicitly supplies -Format OpenCode. This is surprising process execution, even though the argument handling itself is not vulnerable to shell injection.
| [string]$EventsFile, | ||
| [string]$OutputFile, | ||
| [ValidateSet('Copilot', 'ClaudeCode')] | ||
| [ValidateSet('Copilot', 'ClaudeCode', 'OpenCode')] |
There was a problem hiding this comment.
Please add cross-parameter validation for OpenCode.
Today this command:
.\Analyze-Session.ps1 -Format OpenCodefalls through to the no-input default, selects the latest Copilot or Claude transcript, and can generate a report for that unrelated session.
It should terminate immediately with something like:
OpenCode requires either -SessionId or -EventsFile.
Please require one of those inputs whenever -Format OpenCode is selected.
| if (-not $cli) { return $null } | ||
| $json = & $cli session list --format json 2>$null | ||
| if ($LASTEXITCODE -ne 0 -or -not $json) { return $null } | ||
| try { $sessions = ($json -join "`n") | ConvertFrom-Json } catch { return $null } |
There was a problem hiding this comment.
This path collapses several distinct failures into the later “session ID was not found” message:
| Actual problem | Reported result |
|---|---|
opencode is not installed |
Session ID not found |
session list exits nonzero |
Session ID not found |
| Output is empty or invalid JSON | Session ID not found |
| The ID genuinely does not exist | Session ID not found |
Please preserve the actionable cause. One simple approach is to skip the session list preflight after explicit OpenCode selection, call Invoke-OpenCodeExport directly, and let its missing-CLI, export, and JSON diagnostics surface. Otherwise, throw distinct errors here.
| # ----------------------------------------------------------------------------- | ||
| # OpenCode parser | ||
| # ----------------------------------------------------------------------------- | ||
| function Parse-OpenCodeEvents { |
There was a problem hiding this comment.
Please add a fixture-backed smoke test for this new parser rather than leaving the OpenCode export contract untested.
For example, commit a small synthetic export containing info.id, an assistant modelID, cache/output token counts, a bash tool, a task tool, and an errored tool. Then run:
.\Analyze-Session.ps1 -EventsFile .\fixtures\opencode.jsonwithout -Format, and assert that the report contains:
Harness: OpenCode
Session ID: ses_test
Model: example-model
Output/cache token totals
Normalized shell and agent tools
The errored tool in build/tooling analysis
That exercises format sniffing and the most failure-prone normalization paths, not just the happy-path parser entry point.
Description
winui-session-reportcan now analyze OpenCode sessions in addition to GitHub Copilot CLI and Claude Code. It parses the officialopencode exportJSON and emits the same normalized markdown report.-Format OpenCodeaccepts two inputs:-SessionId <ses_...>— shells out toopencode session list+opencode export.-EventsFile <path>— a savedopencode exportJSON file, format-sniffed.OpenCode exposes no "current session" environment variable, so its sessions are only analyzed when explicitly requested via
-Format OpenCode(no auto-detect). Subagents are spawn-only: thetasktool is reported as an agent dispatch with no recursive child-session export, matching Copilot behavior. Existing Copilot/Claude parsers are unchanged.Related Issue
Part of #149
Type of Change
Affected area
Checklist
opencode exportoutput)SKILL.mdfrontmatter still valid; cross-references to other skills still resolve.ps1script changed: tested under defaultRemoteSignedexecution policy## [Unreleased]inCHANGELOG.mdversionfield inplugins/winui/plugin.json,.github/plugin/marketplace.json, or.claude-plugin/marketplace.json(versions bump only on thestaging → mainpromotion PR — seeRELEASING.md)Screenshots / Demo
Additional Notes
Base branch is
staging.AI Description
This section is auto-generated by AI when the PR is opened or updated. To opt out, delete this entire section including the marker comments.