opencode
opencode copied to clipboard
[BUG]: Plugin Registering Twice
Description
If you make a new plugin that has a session.idle hook, the plugin appears to be registering twice, with the session.idle hook being called twice.
OpenCode version
1.0.223
Steps to reproduce
Make a plugin like this:
export const MyPlugin: Plugin = async (ctx: PluginInput) => {
let times = 0;
return {
event: async ({ event }) => {
if (event.type === "session.idle") {
console.log("Hello" + times++);
}
},
};
}
You will observe the logs happening twice:
Hello0
Hello0
However, now move the declaration of times outside the plugin: let times = 0;
export const MyPlugin: Plugin = async (ctx: PluginInput) => {
return {
event: async ({ event }) => {
if (event.type === "session.idle") {
console.log("Hello" + times++);
}
},
};
}
You will now observe logs as such:
Hello0
Hello1
For one, this is unexpected because the event listener seems to be triggering twice. But based off these logs, it seems like the plugin itself is registering twice?