-
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
Conversation
|
Thanks for the PR. I like the idea, it gives a lot of flexibility. I will have a look at the PR and come back to you |
|
Sounds good |
sudo-tee
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, I left a couple of questions/suggestions
|
I'm trying some stuff with the mentioned files, so I'm marking this as draft for now. |
- 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
- Document prompt_guard configuration option - Explain behavior for prompt sending and UI opening - Add practical examples for common use cases - Include error handling details
- Create new prompt_guard_indicator module to track prompt guard status - Display guard status icon on top left of output buffer when denied - Add 1-second timer to update indicator when output buffer is visible - Add OpencodeGuardDenied highlight group for guard status - Support both light and dark themes with appropriate colors The indicator helps users quickly see if their prompts will be accepted before attempting to send a message to the opencode server.
The prompt_guard callback now receives the list of mentioned files from the opencode context as a parameter. This allows users to make decisions based on which files are included in the context. Changes: - Updated prompt_guard type signature from `fun(): boolean` to `fun(mentioned_files: string[]): boolean` - Modified util.check_prompt_allowed to accept and pass mentioned_files parameter - Updated prompt_guard_indicator to retrieve mentioned files from context - Updated core.lua toggle and send_message to pass mentioned files to guard callback This enables use cases like denying prompts when certain sensitive files are mentioned, or allowing prompts only when specific files are included.
dd69a45 to
8f16faf
Compare
|
Alright, I think the PR is ready. |
sudo-tee
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this better, and the icon in the topbar is a nice touch.
However I would avoid having a timer running. A simple event subscription would be cleaner.
|
Ok, I think I understood what you meant with the is_focused subscription. I think it's a pretty good compromise actually. |
|
Thanks for your effort on the PR, I just merged it |
commit 7653234 Author: Guillaume BOEHM <github@mail.gboehm.com> Date: Wed Oct 29 10:27:47 2025 +0000 feat: add prompt_guard callback mechanism (sudo-tee#78) 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 <git@mail.gboehm.com> commit 0dc254b Author: Francis Belanger <francis.belanger@gmail.com> Date: Tue Oct 28 12:01:42 2025 -0400 fix(run): context args not passed in run new session commit 6eb7354 Author: Francis Belanger <francis.belanger@gmail.com> Date: Tue Oct 28 11:18:48 2025 -0400 chore(icons): deprecate emoji icons in favor of nerdfonts commit 3dea370 Author: Francis Belanger <francis.belanger@gmail.com> Date: Tue Oct 28 08:49:27 2025 -0400 chore(emmyrc): fix broken .emmyrc.json commit c07f293 Author: Cameron Ring <cameron@cs.stanford.edu> Date: Mon Oct 27 17:32:50 2025 -0700 fix(renderer): render errors after last part commit bebe01c Author: Francis Belanger <francis.belanger@gmail.com> Date: Mon Oct 27 15:56:57 2025 -0400 feat(rendering): incremental rendering (sudo-tee#62) Introduces an incremental rendering that updates only the changed portion(s) of the buffer instead of re-rendering everything on every change. This reduces CPU usages for large sessions. This PR also incorporate a functional test suite in `tests/manual` where you can record a run snapshot tests. This is a major revision of the rendering system. Co-authored-by: Cameron Ring <cameron@cs.stanford.edu> commit 0f2d1e5 Author: Francis Belanger <francis.belanger@gmail.com> Date: Thu Oct 23 07:32:58 2025 -0400 feat(blink): enable other completion sources for blink This should fix sudo-tee#65 commit e06f651 Author: Francis Belanger <francis.belanger@gmail.com> Date: Thu Oct 23 07:31:11 2025 -0400 fix(cmp): fix file mention closing when typing for nvim_cmp commit 84d9ae0 Author: Francis Belanger <francis.belanger@gmail.com> Date: Thu Oct 23 06:32:17 2025 -0400 fix(mentions): letter `a` appended when triggering mentions commit 44d22ba Author: Francis Belanger <francis.belanger@gmail.com> Date: Thu Oct 23 06:23:49 2025 -0400 test(toggle): fix tests for api.open commit 826341d Author: Francis Belanger <francis.belanger@gmail.com> Date: Thu Oct 23 06:18:09 2025 -0400 fix(toggle): toggle keymap was always triggering insert mode This should fix sudo-tee#77 commit 803eb3e Author: Francis Belanger <francis.belanger@gmail.com> Date: Wed Oct 22 15:53:52 2025 -0400 docs(session_picker): add config for delete session in README commit edba833 Author: Francis Belanger <francis.belanger@gmail.com> Date: Wed Oct 22 15:50:21 2025 -0400 feat(session_picker): add keybind in title commit 357ef3c Author: Cameron Ring <cameron@cs.stanford.edu> Date: Fri Oct 17 18:37:41 2025 -0700 feat(session_picker): Fixes sudo-tee#68 commit fed6941 Author: Francis Belanger <francis.belanger@gmail.com> Date: Mon Oct 20 15:19:21 2025 -0400 fix(completion): completion were broken after last change commit c505554 Author: Francis Belanger <francis.belanger@gmail.com> Date: Mon Oct 20 14:53:50 2025 -0400 fix(focus_input): fix focusing input on window opening commit 4824151 Author: Francis Belanger <francis.belanger@gmail.com> Date: Mon Oct 20 14:37:36 2025 -0400 fix(input_window): properly restore input text when reopening the window commit ca62c0c Author: Francis Belanger <francis.belanger@gmail.com> Date: Mon Oct 20 14:24:17 2025 -0400 fix(bash-tool): properly shown bash command on permission prompt This should fix sudo-tee#74 commit 28d6379 Author: Francis Belanger <francis.belanger@gmail.com> Date: Mon Oct 20 14:08:45 2025 -0400 fix: focusing input window in insert mode The shortcut <C-i> is interpreted as <tab> by terminals I moved it to i. sudo-tee#72 focusing the input_window should restore to the previous position not the char before sudo-tee#64 commit 946af3a Author: Francis Belanger <francis.belanger@gmail.com> Date: Sat Oct 18 15:11:17 2025 -0400 fix(slash_commands): allow slash_commands to be entered in input window This should fix sudo-tee#71 commit abc1e2a Author: Francis Belanger <francis.belanger@gmail.com> Date: Sat Oct 18 11:25:55 2025 -0400 feat(completion): add folder icon kind commit 031bf0a Author: Francis Belanger <francis.belanger@gmail.com> Date: Sat Oct 18 11:12:19 2025 -0400 feat: support for folder mentions commit e99a463 Author: Francis Belanger <francis.belanger@gmail.com> Date: Thu Oct 16 16:34:41 2025 -0400 feat(completion): add file search from server api commit 601cc82 Author: Cameron Ring <cameron@cs.stanford.edu> Date: Thu Oct 9 15:52:47 2025 -0700 fix(config): add config metatable (sudo-tee#59) Fixes sudo-tee#58 Makes config access less error prone and more ergonomic commit ca0ff90 Author: Francis Belanger <francis.belanger@gmail.com> Date: Thu Oct 9 09:50:28 2025 -0400 chore: update .luarc.json for better support of emmylua_ls commit a82b08c Author: Francis Belanger <francis.belanger@gmail.com> Date: Thu Oct 9 09:49:28 2025 -0400 fix: prefix replacement not working properly commit 9d949e7 Author: Francis Belanger <francis.belanger@gmail.com> Date: Thu Oct 9 08:43:57 2025 -0400 feat: add a keymap_prefix to configure the default `<leader>o` commit 8c65d9b Author: Cameron Ring <cameron@cs.stanford.edu> Date: Thu Oct 9 03:29:02 2025 -0700 feat(config)!: modern keymap format + mode support (sudo-tee#52) This is a complete overhaul of the keymaps, The old config should still work but with a warning for migration The new format shoud now be: ```lua keymap = { editor = { ['<leader>og'] = { 'toggle' }, -- I don't think we really need to support just string, it makes things more complex for nothing ['<leader>oi'] = { 'open_input' }, ['<leader>oI'] = { 'open_input_new_session' }, ['<leader>oo'] = { 'open_output' }, ['<leader>ot'] = { 'toggle_focus' }, ['<leader>oq'] = { 'close' }, ['<leader>os'] = { 'select_session' }, ['<leader>op'] = { 'configure_provider' }, ['<leader>od'] = { 'diff_open' }, ['<leader>o]'] = { 'diff_next' }, ['<leader>o['] = { 'diff_prev' }, ['<leader>oc'] = { 'diff_close' }, ['<leader>ora'] = { 'diff_revert_all_last_prompt' }, ['<leader>ort'] = { 'diff_revert_this_last_prompt' }, ['<leader>orA'] = { 'diff_revert_all' }, ['<leader>orT'] = { 'diff_revert_this' }, ['<leader>orr'] = { 'diff_restore_snapshot_file' }, ['<leader>orR'] = { 'diff_restore_snapshot_all' }, ['<leader>oC'] = { 'open_configuration_file' }, ['<leader>ox'] = { 'swap_position' }, ['<leader>opa'] = { 'permission_accept' }, ['<leader>opA'] = { 'permission_accept_all' }, ['<leader>opd'] = { 'permission_deny' }, }, output_window = { ['<leader>something'] = {function () -- custom code end}, ['<esc>'] = { 'close' }, ['<C-c>'] = { 'stop' }, [']]'] = { 'next_message' }, ['[['] = { 'prev_message' }, ['<tab>'] = { 'toggle_pane', mode = { 'n', 'i' } }, ['<C-i>'] = { 'focus_input' }, ['<leader>oS'] = { 'select_child_session' }, ['<leader>oD'] = { 'debug_message' }, ['<leader>oO'] = { 'debug_output' }, ['<leader>ods'] = { 'debug_session' }, }, input_window = { ['<cr>'] = { 'submit_input_prompt', mode = { 'n', 'i' } }, ['<esc>'] = { 'close' }, ['<C-c>'] = { 'stop' }, ['~'] = { 'mention_file', mode = 'i' }, ['@'] = { 'mention', mode = 'i' }, ['/'] = { 'slash_commands', mode = 'i' }, ['<tab>'] = { 'toggle_pane', mode = { 'n', 'i' } }, ['<up>'] = { 'prev_prompt_history', mode = { 'n', 'i' } }, ['<down>'] = { 'next_prompt_history', mode = { 'n', 'i' } }, ['<M-m>'] = { 'switch_mode' }, ['<leader>oS'] = { 'select_child_session' }, ['<leader>oD'] = { 'debug_message' }, ['<leader>oO'] = { 'debug_output' }, ['<leader>ods'] = { 'debug_session' }, }, permission = { accept = 'a', accept_all = 'A', deny = 'd', }, ``` commit fb33ce6 Author: Francis Belanger <francis.belanger@gmail.com> Date: Tue Oct 7 10:22:36 2025 -0400 refactor: simplify keymaps by having a corresponding api function commit fa31457 Author: Francis Belanger <francis.belanger@gmail.com> Date: Tue Oct 7 13:23:32 2025 -0400 feat: restore mentions when navigating history
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: