Skip to content

Add OpenCode support to winui-session-report - #147

Open
Zhanyuanium (Zhanyuanium) wants to merge 1 commit into
microsoft:stagingfrom
Zhanyuanium:zhanyuanium-opencode-session-report
Open

Add OpenCode support to winui-session-report#147
Zhanyuanium (Zhanyuanium) wants to merge 1 commit into
microsoft:stagingfrom
Zhanyuanium:zhanyuanium-opencode-session-report

Conversation

@Zhanyuanium

@Zhanyuanium Zhanyuanium (Zhanyuanium) commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Description

winui-session-report can now analyze OpenCode sessions in addition to GitHub Copilot CLI and Claude Code. It parses the official opencode export JSON and emits the same normalized markdown report.

-Format OpenCode accepts two inputs:

  • -SessionId <ses_...> — shells out to opencode session list + opencode export.
  • -EventsFile <path> — a saved opencode export JSON 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: the task tool 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

  • ✨ New skill or feature

Affected area

  • Skill: winui-session-report
  • Repo-level docs / governance

Checklist

  • Tested locally on Windows (validated against real opencode export output)
  • If a skill changed: SKILL.md frontmatter still valid; cross-references to other skills still resolve
  • If a .ps1 script changed: tested under default RemoteSigned execution policy
  • If user-facing: added a bullet to ## [Unreleased] in CHANGELOG.md
  • Did not edit any version field in plugins/winui/plugin.json, .github/plugin/marketplace.json, or .claude-plugin/marketplace.json (versions bump only on the staging → main promotion PR — see RELEASING.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.

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>

@nmetulev Nikola Metulev (nmetulev) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add cross-parameter validation for OpenCode.

Today this command:

.\Analyze-Session.ps1 -Format OpenCode

falls 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 }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json

without -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants