Skip to content

Commit 338610a

Browse files
AnasAnas
authored andcommitted
fix(permission): trigger permission.ask plugin hook in PermissionNext
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
1 parent 0b02f6d commit 338610a

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

  • packages/opencode/src/permission

‎packages/opencode/src/permission/next.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BusEvent } from "@/bus/bus-event"
33
import { Config } from "@/config/config"
44
import { Identifier } from "@/id/id"
55
import { Instance } from "@/project/instance"
6+
import { Plugin } from "@/plugin"
67
import { Storage } from "@/storage/storage"
78
import { fn } from "@/util/fn"
89
import { Log } from "@/util/log"
@@ -127,11 +128,24 @@ export namespace PermissionNext {
127128
throw new DeniedError(ruleset.filter((r) => Wildcard.match(request.permission, r.permission)))
128129
if (rule.action === "ask") {
129130
const id = input.id ?? Identifier.ascending("permission")
131+
const info: Request = {
132+
id,
133+
...request,
134+
}
135+
136+
// Allow plugins to intercept permission requests (fixes #7006)
137+
const hookStatus = await Plugin.trigger("permission.ask", info, { status: "ask" as const }).then((x) => x.status)
138+
if (hookStatus === "allow") {
139+
log.info("plugin auto-approved", { permission: request.permission, pattern })
140+
continue // Auto-approve
141+
}
142+
if (hookStatus === "deny") {
143+
log.info("plugin auto-denied", { permission: request.permission, pattern })
144+
throw new DeniedError(ruleset.filter((r) => Wildcard.match(request.permission, r.permission)))
145+
}
146+
147+
// If hook returns "ask" or nothing, proceed with UI prompt
130148
return new Promise<void>((resolve, reject) => {
131-
const info: Request = {
132-
id,
133-
...request,
134-
}
135149
s.pending[id] = {
136150
info,
137151
resolve,

0 commit comments

Comments
 (0)