Skip to content

Commit 34c3b9f

Browse files
docs: add prompt_guard documentation to README
- Document prompt_guard configuration option - Explain behavior for prompt sending and UI opening - Add practical examples for common use cases - Include error handling details
1 parent a98539e commit 34c3b9f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ require('opencode').setup({
240240
debug = {
241241
enabled = false, -- Enable debug messages in the output window
242242
},
243+
prompt_guard = nil, -- Optional function that returns boolean to control when prompts can be sent (see Prompt Guard section)
243244
})
244245
```
245246

@@ -537,6 +538,31 @@ The plugin defines several highlight groups that can be customized to match your
537538
- `OpencodeInputLegend`: Highlight for input window legend (default: #CCCCCC background)
538539
- `OpencodeHint`: Highlight for hinting messages in input window and token info in output window footer (linked to `Comment`)
539540

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+
return true
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.
565+
540566
## 🔧 Setting up Opencode
541567

542568
If you're new to opencode:

0 commit comments

Comments
 (0)