Commit 3fb824c
authored
Fix ask for permissions (#268)
## Root Cause
OpenCode PR [#21986](anomalyco/opencode#21986) (merged **April 10, 2026**, commit `bfef334b`) deliberately changed `ToolContext.ask` in the plugin SDK from returning `Promise<void>` to `Effect.Effect<void>`:
```diff
- ask(input: AskInput): Promise<void>
+ ask(input: AskInput): Effect.Effect<void>
```
This broke the previous fix from commit `9e92eb3` (April 1, 2026), which used `await context.ask(...)` and worked correctly at the time. After the opencode change, `await`-ing an Effect object is a no-op — the Effect is never executed, so the permission prompt was silently skipped.
## Fix
Add `effect` as a peer dependency (it is always present in the process since the plugin runs inside opencode) and a dev dependency for local type checking. Use `Effect.runPromise()` to bridge the Effect into the async/await context of the plugin's `execute` functions.
The `ask` call is centralised in the `wrap()` decorator in `plugin.ts` so all five tools get permission enforcement without duplicating the call in each handler.
## Changes
- `package.json`: add `effect >=3.0.0` as peer + dev dependency
- `src/types.ts`: fix local `ToolContext.ask` type to match real SDK (`Effect.Effect<void>`)
- `src/plugin.ts`: use `Effect.runPromise(ctx.ask(...))` in the `wrap()` decorator; import `Effect` from `effect`
- `test/e2e/plugin.test.ts`: update `createMockToolContext()` helper; mock `ask` returns `Effect.void` instead of a resolved Promise1 parent 90e9f34 commit 3fb824c
5 files changed
Lines changed: 54 additions & 16 deletions
File tree
- packages/opencode-plugin
- src
- test/e2e
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
652 | 653 | | |
653 | 654 | | |
654 | 655 | | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
661 | 664 | | |
662 | 665 | | |
663 | 666 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
| |||
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments