You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26Lines changed: 26 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -240,6 +240,7 @@ require('opencode').setup({
240
240
debug= {
241
241
enabled=false, -- Enable debug messages in the output window
242
242
},
243
+
prompt_guard=nil, -- Optional function that returns boolean to control when prompts can be sent (see Prompt Guard section)
243
244
})
244
245
```
245
246
@@ -537,6 +538,31 @@ The plugin defines several highlight groups that can be customized to match your
537
538
-`OpencodeInputLegend`: Highlight for input window legend (default: #CCCCCC background)
538
539
-`OpencodeHint`: Highlight for hinting messages in input window and token info in output window footer (linked to `Comment`)
539
540
541
+
## 🛡️ Prompt Guard
542
+
543
+
The `prompt_guard` configuration option allows you to control when prompts can be sent to Opencode. This is useful for preventing accidental or unauthorized AI interactions in certain contexts.
544
+
545
+
### Configuration
546
+
547
+
Set `prompt_guard` to a function that returns a boolean:
548
+
549
+
```lua
550
+
require('opencode').setup({
551
+
prompt_guard=function()
552
+
-- Your custom logic here
553
+
-- Return true to allow, false to deny
554
+
returntrue
555
+
end,
556
+
})
557
+
```
558
+
559
+
### Behavior
560
+
561
+
-**Before sending prompts**: The guard is checked before any prompt is sent to the AI. If denied, an ERROR notification is shown and the prompt is not sent.
562
+
-**Before opening UI**: The guard is checked when opening the Opencode buffer for the first time. If denied, a WARN notification is shown and the UI is not opened.
563
+
-**No parameters**: The guard function receives no parameters. Access vim state directly (e.g., `vim.fn.getcwd()`, `vim.bo.filetype`).
564
+
-**Error handling**: If the guard function throws an error or returns a non-boolean value, the prompt is denied with an appropriate error message.
---@fieldinputTaskToolInput|BashToolInput|FileToolInput|TodoToolInput|GlobToolInput|GrepToolInput|WebFetchToolInput|ListToolInput Input data for the tool
0 commit comments