Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(opencode): clear the activity marker when OpenCode 1 disposes the plugin (#4129)
Worktrunk Botc83606447d5a
diff --git a/dev/opencode-plugin.ts b/dev/opencode-plugin.tsindex 4711464db..f95233bc0 100644--- a/dev/opencode-plugin.ts+++ b/dev/opencode-plugin.ts@@ -106,21 +106,42 @@ type ServerInput = { directory: string };type HookInput = { event: { type: string } };function server({ directory }: ServerInput) {+ // The host dispatches `event` without awaiting it, so a `set` can still be+ // running when the teardown below clears. Chaining every call onto one+ // promise is what puts the `clear` last; `disposed` drops the events the+ // host can still deliver, since it unsubscribes after calling `dispose`.+ let pending: Promise<void> = Promise.resolve();+ let disposed = false;+ const enqueue = (args: string[]): Promise<void> => {+ pending = pending.then(() => marker(directory, args));+ return pending;+ };+return {+ // The host runs this when it tears the plugin instance down, which is what+ // a normal session exit does. `session.deleted` below only fires when a+ // session is explicitly deleted, so without `dispose` the last `set` stays+ // the final state and `wt list` shows a finished session as still active.+ // Part of the hook interface since 1.16, the floor the `server` path targets.+ dispose: async () => {+ disposed = true;+ await enqueue(["clear"]);+ },// OpenCode 1.16+ filters events to this plugin's directory before calling// the hook, so there is nothing to match on here. 1.15.x does not — it fans// every bus event to every plugin instance — so the marker there follows the// worktree the instance was created for, whichever session is active.event: async ({ event }: HookInput) => {+ if (disposed) return;switch (event.type) {case "session.status":- await marker(directory, ["set", WORKING]);+ await enqueue(["set", WORKING]);break;case "session.idle":- await marker(directory, ["set", WAITING]);+ await enqueue(["set", WAITING]);break;case "session.deleted":- await marker(directory, ["clear"]);+ await enqueue(["clear"]);break;}},diff --git a/docs/src/content/docs/claude-code.md b/docs/src/content/docs/claude-code.mdindex e88477e95..af0bea0fa 100644--- a/docs/src/content/docs/claude-code.md+++ b/docs/src/content/docs/claude-code.md@@ -106,7 +106,7 @@ $ wt list- 🤖 — agent is working- 💬 — agent is waiting or idle-All four plugins clear the marker when a session ends. A stale marker can remain if the agent process is killed before its session-end hook runs. In every case, `wt config state marker clear` removes a marker manually.+All five plugins clear the marker when a session ends. A stale marker can remain if the agent process is killed before its session-end hook runs. In every case, `wt config state marker clear` removes a marker manually.### Manual status markersdiff --git a/plugins/worktrunk/skills/worktrunk/reference/claude-code.md b/plugins/worktrunk/skills/worktrunk/reference/claude-code.mdindex 1fd332742..8867d9c05 100644--- a/plugins/worktrunk/skills/worktrunk/reference/claude-code.md+++ b/plugins/worktrunk/skills/worktrunk/reference/claude-code.md@@ -98,7 +98,7 @@ $ wt list- 🤖 — agent is working- 💬 — agent is waiting or idle-All four plugins clear the marker when a session ends. A stale marker can remain if the agent process is killed before its session-end hook runs. In every case, `wt config state marker clear` removes a marker manually.+All five plugins clear the marker when a session ends. A stale marker can remain if the agent process is killed before its session-end hook runs. In every case, `wt config state marker clear` removes a marker manually.### Manual status markersdiff --git a/skills/worktrunk/reference/claude-code.md b/skills/worktrunk/reference/claude-code.mdindex 1fd332742..8867d9c05 100644--- a/skills/worktrunk/reference/claude-code.md+++ b/skills/worktrunk/reference/claude-code.md@@ -98,7 +98,7 @@ $ wt list- 🤖 — agent is working- 💬 — agent is waiting or idle-All four plugins clear the marker when a session ends. A stale marker can remain if the agent process is killed before its session-end hook runs. In every case, `wt config state marker clear` removes a marker manually.+All five plugins clear the marker when a session ends. A stale marker can remain if the agent process is killed before its session-end hook runs. In every case, `wt config state marker clear` removes a marker manually.### Manual status markers