Skip to content

fix(opencode): report committed hook failures in tool results - #49

Merged
nexxeln merged 2 commits into
devfrom
nxl/tool-hook-warnings
Oct 5, 2026
Merged

nexxeln merged 2 commits into
devfrom
nxl/tool-hook-warnings

Conversation

@nexxeln

@nexxeln nexxeln commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Stack: #49 ← #50

Why the change

When a postcreate or postremove hook failed after Rift had already created or removed the workspace, rift.create and rift.remove still told the agent everything worked, because the warning only went to the server's stderr.

Special things to note

  • Both tools now return an optional warning field and add a Warning: line to their text. The workspace still counts as created or removed, which matches what's on disk.
  • Creates and removes started from the OpenCode UI still only log to stderr. The plugin API has no logger or toast for server plugins.
  • The tests drive the plugin's real setup with a fake host and a fake rift. I haven't checked this against a running OpenCode yet.

Change outline

The strategy reports committed hook failures through its warning callback while the host's worktree call is still running. Each tool call adds a listener for the length of that call, then keeps only the warning for its own directory. Concurrent calls and UI-driven operations can't leak into each other's results.

 setup(ctx)
+  listeners = Set<(warning) => void>
   strategy.warning(warning)
     console.error(...)
+    notify every listener
-  registerTools(ctx)
+  registerTools(ctx, listeners)

 rift.create / rift.remove
-  await ctx.worktree.create(...) / remove(...)
-  return { directory }
+  watch(listeners, () => ctx.worktree.create(...) / remove(...))
+  return { directory, warning? }, content + "\n\nWarning: <message>"

What the agent sees after a failing pnpm install postcreate hook:

Created /worktrees/task. Use opencode.session_move to move a session into it.

Warning: postcreate hook failed: ERR_PNPM_FETCH_401 token expired

@nexxeln
nexxeln added this pull request to stack #51 October 5, 2026 07:51
@nexxeln nexxeln changed the title nxl/tool hook warnings fix(opencode): report committed hook failures in tool results Oct 5, 2026
@nexxeln
nexxeln merged commit 7516251 into dev Oct 5, 2026
9 checks passed
@nexxeln nexxeln mentioned this pull request Oct 5, 2026
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.

1 participant