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
This PR adds a plugin option to run a callback before sending promts to the LLM or before opening the opencode window.
In my use case I want to be able to exclude some directories of my computer with sensitive information in order to not mistakenly send them to the LLM.
I've mostly vibe-coded this and then went back on the code to check what it did, I'm not super well versed in lua so I might have missed things.
Implementation details:
Add prompt_guard configuration option (function that returns boolean)
Check guard before sending prompts (ERROR notification if denied)
Check guard before opening buffer first time (WARN notification if denied)
Add util.check_prompt_allowed() helper functions
Guard has no parameters, users can access vim state directly
Proper error handling for guard callback failures
Co-authored-by: Guillaume BOEHM <[email protected]>
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