Skip to content

fix(plugin): restore OpenCode 1.3 loader compatibility#81

Merged
NaNomicon merged 1 commit intomainfrom
issue/73-opencode-update-memory-regression
Apr 3, 2026
Merged

fix(plugin): restore OpenCode 1.3 loader compatibility#81
NaNomicon merged 1 commit intomainfrom
issue/73-opencode-update-memory-regression

Conversation

@NaNomicon
Copy link
Copy Markdown
Collaborator

Summary

Fixes #73opencode-mem was silently skipped by OpenCode ≥ 1.3.8 due to a plugin entrypoint/module-shape incompatibility.

Root Cause

OpenCode v1.3.x introduced a PluginModule contract: the plugin loader (readV1Plugin) now expects the module default export to be an object with a server property — { server: Plugin }. The previous opencode-mem@2.12.1 published dist/plugin.js with a bare function as the default export. The loader's isRecord(mod.default) check returned false, so it logged "No plugin targets found" and skipped the plugin entirely — without throwing an error.

Additionally, OpenCode v1.3.x resolves plugins via exports["./server"] in package.json. The published package had no exports map at all, so the loader fell back to main — but the module shape mismatch meant it was still rejected.

Consequence: Plugin hooks never fired → no memory saves, no web UI, /memory add had no visible effect (though user-prompts.db was modified by the module-level constructor).

Changes

File Change
package.json Add exports map with "." and "./server" entries; bump @opencode-ai/plugin ^1.0.162^1.3.0 and @opencode-ai/sdk ^1.2.26^1.3.0
src/plugin.ts Replace bare default function export with { server: OpenCodeMemPlugin } satisfies PluginModule; add import type { PluginModule } for compile-time validation; remove stale shebang
tests/plugin-loader-contract.test.ts Add regression guard: 4 assertions verifying exports map, default export shape, .server callable surface, and hook return values
bun.lock Updated for dependency bumps

Verification

  • bun run typecheck → exit 0 (no errors)
  • bun run build → exit 0
  • Regression guard: 4/4 tests pass
  • Built artifact: typeof mod.default === "object", typeof mod.default.server === "function"
  • Loader-parity smoke check: simulated OpenCode 1.3.11 readV1Plugin logic confirms isRecord(mod.default) === true → plugin would be loaded via v1 path (NOT skipped)

Backward Compatibility

  • main: "dist/plugin.js" is preserved for loaders that fall back to main
  • Named export OpenCodeMemPlugin is preserved
  • Runtime behavior in src/index.ts is unchanged — only the module entrypoint shape and dependencies were updated
  • OpenCode < 1.3.x (pre-PluginModule) is no longer supported by this package; the minimum required OpenCode version is 1.3.x

- Add package.json exports map with ./server and . targets
- Bump @opencode-ai/plugin and @opencode-ai/sdk to ^1.3.0 (resolves to 1.3.13)
- Update src/plugin.ts to export PluginModule { server: OpenCodeMemPlugin }
  instead of bare function default export; use satisfies PluginModule
- Add tests/plugin-loader-contract.test.ts regression guard

Fixes #73: opencode-mem@2.12.1 was silently skipped by the OpenCode 1.3.x plugin
loader because dist/plugin.js exported a bare default function. The loader now
expects a PluginModule object with a server() entrypoint (readV1Plugin v1 path).
Adding exports["./server"] and the { server: Plugin } default export satisfies
the contract unambiguously.
@NaNomicon NaNomicon marked this pull request as draft April 2, 2026 12:56
@NaNomicon NaNomicon marked this pull request as draft April 2, 2026 12:56
@NaNomicon NaNomicon self-assigned this Apr 2, 2026
@NaNomicon
Copy link
Copy Markdown
Collaborator Author

NaNomicon commented Apr 2, 2026

After installing the local build and fighting my own environment, I got it working and believe this PR is enough to get opencode-mem to the working state with OpenCode v1.3.x. I did encountered some errors in the testing phase but I believe they're not related and opened follow-up issue about it. This PR will require the owner or someone with previous successful operations of the plugin to check before merge.

@NaNomicon NaNomicon marked this pull request as ready for review April 2, 2026 17:23
@NaNomicon NaNomicon requested a review from tickernelz April 2, 2026 17:23
@tickernelz
Copy link
Copy Markdown
Owner

Bro you already have direct access to the repo.

@NaNomicon NaNomicon merged commit b190922 into main Apr 3, 2026
1 check passed
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.

[Bug] opencode-mem stopped working after OpenCode update

2 participants