fix(opencode): initialize plugin hooks correctly#21
Conversation
Review Summary by QodoFix plugin initialization and add obsxa tool hook WalkthroughsDescription• Export instantiated plugin instance instead of factory function • Add comprehensive obsxa tool hook for observation management • Update agent instruction to reference obsxa tool explicitly • Fix wrapper typings to properly reflect plugin instance export Diagramflowchart LR
A["Plugin Factory"] -->|"instantiate"| B["Plugin Instance"]
B -->|"register hooks"| C["system.transform Hook"]
B -->|"register hooks"| D["obsxa Tool Hook"]
D -->|"supports"| E["add/get/list/search/stats"]
C -->|"injects"| F["Agent Instructions"]
File Changes1. opencode/index.mjs
|
Code Review by Qodo
1.
|
|
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 (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🧰 Additional context used📓 Path-based instructions (2)**/*.{ts,tsx,js,mjs}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (3)📓 Common learnings📚 Learning: 2026-03-12T11:16:05.994ZApplied to files:
📚 Learning: 2026-03-11T19:03:02.039ZApplied to files:
🧬 Code graph analysis (1)src/opencode.ts (1)
🔇 Additional comments (8)
📝 WalkthroughWalkthroughDefault export for the OpenCode wrapper now exports an instantiated plugin (createObsxaPlugin()) instead of the factory; a dynamic obsxa tool integration and loader option were added, and tests updated to reflect the new "" token and tool usage. Changes
Sequence Diagram(s)sequenceDiagram
participant Host as OpenCode Host
participant Wrapper as opencode/index (default export)
participant Plugin as Obsxa Plugin (createObsxaPlugin())
participant ToolPkg as `@opencode-ai/plugin/tool` (loaded via toolLoader)
participant ObsxaAPI as Obsxa backend/API
Host->>Wrapper: import default (plugin instance)
Host->>Plugin: call plugin(input) -> receives hooks
Plugin->>ToolPkg: toolLoader?() (async) / createObsxaTool()
ToolPkg-->>Plugin: tool config { obsxa: { schema, execute } }
Host->>Plugin: chat.message / system.transform triggers
Plugin->>ToolPkg: tool.execute({ operation, params })
ToolPkg->>ObsxaAPI: call API (add/get/list/search/stats)
ObsxaAPI-->>ToolPkg: results (JSON)
ToolPkg-->>Plugin: execute returns JSON string
Plugin->>Host: hooks persist observations / return enriched context
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
✨ Simplify code
📝 Coding Plan for PR comments
Comment |
Sequence DiagramThis PR fixes the wrapper default export to return an instantiated plugin so OpenCode registers hooks correctly at startup. It also adds an obsxa tool hook, enabling both normal hook-driven ingestion and explicit tool based observation writes to persist in real sessions. sequenceDiagram
participant OpenCode
participant Wrapper
participant ObsxaPlugin
participant Agent
participant ObsxaStore
OpenCode->>Wrapper: Load default plugin export
Wrapper-->>OpenCode: Return instantiated plugin
OpenCode->>ObsxaPlugin: Initialize plugin for session
ObsxaPlugin-->>OpenCode: Register hooks and obsxa tool
Agent->>OpenCode: Send message or obsxa add request
OpenCode->>ObsxaPlugin: Trigger hook or tool execution
ObsxaPlugin->>ObsxaStore: Write observation
ObsxaStore-->>ObsxaPlugin: Observation persisted
Generated by CodeAnt AI |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e275a5246
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
1 issue found across 3 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="opencode/index.d.mts">
<violation number="1" location="opencode/index.d.mts:1">
P1: The declaration file imports `createObsxaPlugin` from `../src/opencode.ts`, but that path is not shipped by the wrapper package, so TypeScript consumers cannot resolve this module’s types.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Pull request
What
OpenCode was receiving the plugin factory as default export instead of a plugin instance, so hooks were never registered and observations were not persisted; this switches the wrapper default to
createObsxaPlugin(), aligns wrapper typings, and adds anobsxatool hook with updated tests so both automatic hook ingestion and explicit observation writes work in real sessions.Closes
Closes #20