fix(opencode-plugin): correct session.messages response shape and update tests#993
Merged
nicoloboschi merged 1 commit intovectorize-io:mainfrom Apr 13, 2026
Conversation
nicoloboschi
requested changes
Apr 13, 2026
Collaborator
nicoloboschi
left a comment
There was a problem hiding this comment.
we should support 1.3.x versions still
Contributor
Author
|
Hi @nicoloboschi , the plugin is built against @opencode-ai/sdk@1.3.13. I'm not sure what you mean. |
Collaborator
I thought opencode changed the message format but I was wrong, sorry, merging now |
nicoloboschi
approved these changes
Apr 13, 2026
3 tasks
DK09876
added a commit
that referenced
this pull request
Apr 14, 2026
PR #993 added hardcoded console.error calls throughout hooks.ts for debugging the message parsing fix. These are not gated behind the debug config flag, so they spam every user's TUI with red error text on every event, message parse, and retain cycle. Replace all console.error calls with debugLog(config, ...) so they only appear when debug: true is set in plugin options. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 tasks
nicoloboschi
pushed a commit
that referenced
this pull request
Apr 14, 2026
PR #993 added hardcoded console.error calls throughout hooks.ts for debugging the message parsing fix. These are not gated behind the debug config flag, so they spam every user's TUI with red error text on every event, message parse, and retain cycle. Replace all console.error calls with debugLog(config, ...) so they only appear when debug: true is set in plugin options. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix the opencode plugin's
getSessionMessagesfunction, which had two bugs that prevented auto-retain from functioning since it was introduced in #853.The bugs
1. Wrong response shape (
hooks.ts:131)The code read
msg.rolebut the opencode SDK returns messages wrapped as{ info: { role }, parts }. This caused a runtimeTypeError: Cannot read properties of undefined (reading 'role')every timegetSessionMessageswas called.2. Mismatched TypeScript type for SDK call (
hooks.tsOpencodeClienttype)The production code correctly calls
opencodeClient.session.messages({ path: { id: sessionId } }), but the TypeScript type declaration for that function specified{ sessionID: string }— a completely different signature. The type definition did not match the actual call. This was a type error that would have been caught at compile time with stricter type checking.Impact
Auto-retain and pre-compaction retain were non-functional from the point the plugin was introduced. Every call to
getSessionMessagesthrew a TypeError that was silently caught, returning an empty array. ThehandleSessionIdleand compaction hooks then exited early at theif (!messages.length) returncheck. The tools (retain/recall/reflect) and system transform hook were unaffected.The original test mocks used the same incorrect
{ role }shape, so all tests passed despite the code not matching the real SDK contract.Changes
hooks.ts: FixOpencodeClienttype to match the real SDK, readmsg.info.roleinstead ofmsg.rolehooks.test.ts: Update all mock message shapes to{ info: { role }, parts }Testing