refactor(plugin): migrate to V1 PluginModule format
Convert the default export from the legacy callable Plugin to the V1 PluginModule shape (`{ id, server }`) documented by opencode's plugin SDK. This aligns oh-my-openagent with the canonical plugin entry format and removes plugin-format legacy debt.
Drop the module-level `let activePluginDispose` cleanup guard: opencode instantiates plugins in a scope-bound Layer per server and dynamic-imports fresh modules on reload, so module-level state is not preserved across reloads. Individual managers already register their own SIGINT/SIGTERM cleanup (skill-mcp-manager, background-agent process-cleanup), so the orphaned createPluginDispose call provided no runtime value.
Remove the non-standard `name` return field that opencode's Hooks interface does not include. The PluginModule's `id` now carries the plugin identity instead.
Drop the unused `lspManager` import that only fed the orphaned createPluginDispose.
Update src/index.test.ts and src/index.telemetry.test.ts to call `plugin.server(ctx)` instead of `plugin(ctx)`, and assert the V1 shape.
This commit is contained in:
+15
-6
@@ -257,7 +257,7 @@ const mockCreatePluginInterface = mock(() => ({}))
|
||||
const mockInitializeOpenClaw = mock(async () => {})
|
||||
const mockStartTmuxCheck = mock(() => {})
|
||||
|
||||
let OhMyOpenCodePlugin: (typeof import("./index"))["default"]
|
||||
let pluginModule: (typeof import("./index"))["default"]
|
||||
|
||||
function installIndexModuleMocks(): void {
|
||||
mock.module("./cli/config-manager/config-context", () => ({
|
||||
@@ -337,7 +337,7 @@ describe("OhMyOpenCodePlugin", () => {
|
||||
beforeEach(async () => {
|
||||
mock.restore()
|
||||
installIndexModuleMocks()
|
||||
;({ default: OhMyOpenCodePlugin } = await importFreshIndexModule())
|
||||
;({ default: pluginModule } = await importFreshIndexModule())
|
||||
mockInitConfigContext.mockClear()
|
||||
mockDetectExternalSkillPlugin.mockClear()
|
||||
mockGetSkillPluginConflictWarning.mockClear()
|
||||
@@ -375,10 +375,10 @@ describe("OhMyOpenCodePlugin", () => {
|
||||
})
|
||||
|
||||
// when
|
||||
await OhMyOpenCodePlugin({
|
||||
await pluginModule.server({
|
||||
directory: "/tmp/project",
|
||||
client: {},
|
||||
} as Parameters<typeof OhMyOpenCodePlugin>[0])
|
||||
} as Parameters<typeof pluginModule.server>[0])
|
||||
|
||||
// then
|
||||
expect(mockInitializeOpenClaw).toHaveBeenCalledTimes(1)
|
||||
@@ -390,12 +390,21 @@ describe("OhMyOpenCodePlugin", () => {
|
||||
mockLoadPluginConfig.mockReturnValue({})
|
||||
|
||||
// when
|
||||
await OhMyOpenCodePlugin({
|
||||
await pluginModule.server({
|
||||
directory: "/tmp/project",
|
||||
client: {},
|
||||
} as Parameters<typeof OhMyOpenCodePlugin>[0])
|
||||
} as Parameters<typeof pluginModule.server>[0])
|
||||
|
||||
// then
|
||||
expect(mockInitializeOpenClaw).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("exports a V1 PluginModule shape with id and server", () => {
|
||||
// given the plugin module is loaded
|
||||
// when inspecting the default export
|
||||
// then it has the expected V1 shape
|
||||
expect(typeof pluginModule).toBe("object")
|
||||
expect(pluginModule.id).toBe("oh-my-openagent")
|
||||
expect(typeof pluginModule.server).toBe("function")
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user