Skip to content

Commit 20a0a7d

Browse files
authored
fix(opencode-plugin): make the package loadable by opencode (alpha.3) (#868)
1 parent 90ed0fb commit 20a0a7d

6 files changed

Lines changed: 41 additions & 8 deletions

File tree

integrations/opencode-plugin/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [0.1.0-alpha.3] - 2026-06-16
1111

12+
First version OpenCode can actually load (alpha.1/alpha.2 could not — see Fixed).
13+
14+
### Fixed
15+
16+
- **OpenCode can now load the plugin.** Three problems blocked it when installed from npm:
17+
- **`node:sqlite` in the import graph.** The recorder imported `DaemonEmitter` from the `@obsigna/sdk-ts` barrel, which re-exports the SQLite store (`node:sqlite`) and undici; opencode's loader could not resolve `node:sqlite`. Now imports from the `@obsigna/sdk-ts/emitter` subpath (added in sdk-ts 0.14.1), which pulls only the daemon emitter — no `node:sqlite`/undici. Dependency bumped to `^0.14.1`.
18+
- **No server entry point.** opencode resolves `server` plugins via `exports["./server"]` (or `main`); the package exposed neither. Added a `./server` export (and `main`) pointing at a dedicated entry.
19+
- **Entry exported non-function values.** The library barrel exports `DEFAULT_ACTION_MAP`, `ReceiptRecorder`, config helpers, etc.; opencode's legacy loader throws "Plugin export is not a function" on the first such export. The new `src/server.ts` default-exports only `{ server: ObsignaPlugin }` (V1 shape), keeping opencode on the V1 path. The `.` barrel is unchanged for programmatic use.
20+
1221
### Changed
1322

1423
- **Renamed the plugin exports to the Obsigna brand**, matching the `@obsigna` package scope: `createAgentReceiptsPlugin``createObsignaPlugin`, the prebuilt `AgentReceiptsPlugin``ObsignaPlugin`, and the `AgentReceiptsPluginConfig` type → `ObsignaPluginConfig`. Breaking for the named exports only; the `AGENT_RECEIPTS_*` / `AGENTRECEIPTS_SOCKET` environment variables are unchanged. Update imports from `@obsigna/opencode-plugin`.

integrations/opencode-plugin/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
"directory": "integrations/opencode-plugin"
1111
},
1212
"type": "module",
13+
"main": "./dist/server.js",
1314
"exports": {
1415
".": {
1516
"types": "./dist/index.d.ts",
1617
"default": "./dist/index.js"
18+
},
19+
"./server": {
20+
"types": "./dist/server.d.ts",
21+
"default": "./dist/server.js"
1722
}
1823
},
1924
"files": [
@@ -33,7 +38,7 @@
3338
},
3439
"packageManager": "pnpm@10.33.0",
3540
"dependencies": {
36-
"@obsigna/sdk-ts": "^0.14.0"
41+
"@obsigna/sdk-ts": "^0.14.1"
3742
},
3843
"peerDependencies": {
3944
"@opencode-ai/plugin": ">=0.1.0"

integrations/opencode-plugin/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integrations/opencode-plugin/src/recorder.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EmitEvent } from "@obsigna/sdk-ts";
1+
import type { EmitEvent } from "@obsigna/sdk-ts/emitter";
22
import { describe, expect, it, vi } from "vitest";
33
import { type ResolvedConfig, resolveConfig } from "./config.js";
44
import {

integrations/opencode-plugin/src/recorder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* guessing.
2525
*/
2626

27-
import { DaemonEmitter, type EmitEvent } from "@obsigna/sdk-ts";
27+
import { DaemonEmitter, type EmitEvent } from "@obsigna/sdk-ts/emitter";
2828
import { resolveActionType } from "./actions.js";
2929
import { type ResolvedConfig, shouldEmit } from "./config.js";
3030

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ObsignaPlugin } from "./plugin.js";
2+
3+
/**
4+
* OpenCode server-plugin entry point.
5+
*
6+
* opencode resolves a `kind: "server"` plugin through this package's
7+
* `exports["./server"]` and reads the module's **default** export, expecting a
8+
* V1 plugin descriptor: an object whose `server` field is the plugin function
9+
* (see opencode's `readV1Plugin` / `resolvePackageEntrypoint`).
10+
*
11+
* This entry deliberately default-exports *only* `{ server }`. The library
12+
* barrel (`./index.ts`) also exports values that are not plugin functions
13+
* (`DEFAULT_ACTION_MAP`, `ReceiptRecorder`, config helpers, the factory); if
14+
* opencode fell back to its legacy loader — which iterates `Object.values(mod)`
15+
* and calls each as a plugin — those would throw "Plugin export is not a
16+
* function". Providing a valid V1 default export keeps opencode on the V1 path
17+
* and never reaches that fallback.
18+
*/
19+
export default { server: ObsignaPlugin };

0 commit comments

Comments
 (0)