-
Notifications
You must be signed in to change notification settings - Fork 35
feat: add prompt_guard callback mechanism #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a98539e
feat: add prompt_guard callback mechanism
guillaumeboehm 34c3b9f
docs: add prompt_guard documentation to README
guillaumeboehm 88edc4e
feat: prompt_guard: Let the buffer open and warn if prompt_guard will
guillaumeboehm 8cb171f
feat: Add prompt_guard status indicator to output buffer topbar
guillaumeboehm 8f16faf
feat: pass mentioned files to prompt_guard callback
guillaumeboehm 517c656
fix: promtp_guard: Use the defined function to get the status icon
guillaumeboehm 09c33d5
fix: merge error on topbar mode_info
guillaumeboehm 6c4b737
feat: Use proper guard icon for the topbar
guillaumeboehm 40f33a8
fix: Replace prompt guard timer with observer on opencode window focus
guillaumeboehm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| local M = {} | ||
|
|
||
| local config = require('opencode.config') | ||
| local util = require('opencode.util') | ||
| local icons = require('opencode.ui.icons') | ||
| local context = require('opencode.context') | ||
|
|
||
| ---Get the current prompt guard status | ||
| ---@return boolean allowed | ||
| ---@return string|nil error_message | ||
| function M.get_status() | ||
| local mentioned_files = context.context.mentioned_files or {} | ||
| return util.check_prompt_allowed(config.prompt_guard, mentioned_files) | ||
| end | ||
|
|
||
| ---Check if guard will deny prompts | ||
| ---@return boolean denied | ||
| function M.is_denied() | ||
| local allowed, _ = M.get_status() | ||
| return not allowed | ||
| end | ||
|
|
||
| ---Get formatted indicator string with highlight (empty if allowed) | ||
| ---@return string formatted_indicator | ||
| function M.get_formatted() | ||
| if not M.is_denied() then | ||
| -- Prompts are allowed - don't show anything | ||
| return '' | ||
| end | ||
|
|
||
| -- Prompts will be denied - show red indicator | ||
| local icon = icons.get('guard_on') | ||
| return string.format('%%#OpencodeGuardDenied#%s%%*', icon) | ||
| end | ||
|
|
||
| return M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.