-
Notifications
You must be signed in to change notification settings - Fork 7.8k
fix(permission): trigger permission.ask plugin hook in PermissionNext #7077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The permission.ask hook was defined in the plugin SDK types but never triggered in PermissionNext.ask(), preventing plugins from intercepting permission requests. This fix adds the Plugin.trigger() call before showing the UI prompt, allowing plugins like oh-my-opencode to auto-approve or auto-deny based on custom logic (e.g., PreToolUse hooks for delegation enforcement). Fixes anomalyco#7006
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: Related PR: This PR may be related as it also deals with plugin interactions around permission asking in the tool context. However, it appears to be a different approach (adding The other search results only returned PR #7077 itself (the current PR), which is expected. |
Clarification: Relationship to PR #6042After deeper investigation, I want to clarify how this PR relates to #6042: This PR (#7077) and PR #6042 are complementary, not duplicates:
Different Use Cases:
Note on oh-my-opencode:The original description mentioned oh-my-opencode PreToolUse hooks. To clarify:
Both approaches are valid and serve different purposes in the plugin ecosystem. |
The `forceZsh` option on Linux/macOS would use a hardcoded zshPath without checking if zsh actually exists on the system. This caused hook commands to fail silently with exit code 127 on systems without zsh installed. The fix ensures `findZshPath()` is always called to verify the shell exists before wrapping commands. If zsh is not found, commands fall through to use the default shell via `spawn` with `shell: true`. Tested with patched opencode (anomalyco/opencode#7077) - PreToolUse hooks now execute correctly on systems without zsh.
|
Closing this PR after further investigation. FindingsThe original issue (oh-my-opencode PreToolUse hooks not firing) was caused by a different problem: oh-my-opencode's The FixThe actual fix is in oh-my-opencode, not opencode:
Why This PR Isn't Needed
TestingVerified with stock opencode v1.1.3 + patched oh-my-opencode:
Apologies for the noise - the root cause investigation led us down the wrong path initially. |
The `forceZsh` option on Linux/macOS would use a hardcoded zshPath without checking if zsh actually exists on the system. This caused hook commands to fail silently with exit code 127 on systems without zsh installed. The fix ensures `findZshPath()` is always called to verify the shell exists before wrapping commands. If zsh is not found, commands fall through to use the default shell via `spawn` with `shell: true`. Tested with patched opencode (anomalyco/opencode#7077) - PreToolUse hooks now execute correctly on systems without zsh.
The `forceZsh` option on Linux/macOS would use a hardcoded zshPath without checking if zsh actually exists on the system. This caused hook commands to fail silently with exit code 127 on systems without zsh installed. The fix ensures `findZshPath()` is always called to verify the shell exists before wrapping commands. If zsh is not found, commands fall through to use the default shell via `spawn` with `shell: true`. Tested with patched opencode (anomalyco/opencode#7077) - PreToolUse hooks now execute correctly on systems without zsh.
Summary
Implements the
permission.askplugin hook that was defined but never triggered inPermissionNext.ask().Problem
Issue #7006: Plugins cannot intercept permission requests because
Plugin.trigger("permission.ask", ...)is never called in the permission system.This prevents plugins like oh-my-opencode from implementing PreToolUse hooks for:
Solution
Add
Plugin.trigger("permission.ask", info, { status: "ask" })call inPermissionNext.ask()before showing the UI prompt:"allow"→ auto-approve (continue)"deny"→ throw DeniedError"ask"or unchanged → proceed with existing UI prompt flowTesting
This change follows the exact same pattern used in
permission/index.tswhich already has workingPlugin.trigger("permission.ask", ...)integration.Impact
Fixes #7006