Class: RubyCode::Client::ApprovalHandler
- Inherits:
-
Object
- Object
- RubyCode::Client::ApprovalHandler
- Defined in:
- lib/rubycode/client/approval_handler.rb
Overview
Handles user approval prompts for tools
Instance Attribute Summary collapse
-
#auto_approve_write_enabled ⇒ Object
readonly
Returns the value of attribute auto_approve_write_enabled.
Instance Method Summary collapse
- #disable_auto_approve_write ⇒ Object
- #enable_auto_approve_write ⇒ Object
-
#initialize(tty_prompt:, config:) ⇒ ApprovalHandler
constructor
A new instance of ApprovalHandler.
- #request_bash_approval(command, base_command, safe_commands) ⇒ Object
- #request_update_approval(file_path, old_string, new_string) ⇒ Object
- #request_web_search_approval(query, max_results) ⇒ Object
- #request_write_approval(file_path, content) ⇒ Object
Constructor Details
#initialize(tty_prompt:, config:) ⇒ ApprovalHandler
Returns a new instance of ApprovalHandler.
9 10 11 12 13 |
# File 'lib/rubycode/client/approval_handler.rb', line 9 def initialize(tty_prompt:, config:) @prompt = tty_prompt @config = config @auto_approve_write_enabled = false end |
Instance Attribute Details
#auto_approve_write_enabled ⇒ Object (readonly)
Returns the value of attribute auto_approve_write_enabled.
7 8 9 |
# File 'lib/rubycode/client/approval_handler.rb', line 7 def auto_approve_write_enabled @auto_approve_write_enabled end |
Instance Method Details
#disable_auto_approve_write ⇒ Object
19 20 21 |
# File 'lib/rubycode/client/approval_handler.rb', line 19 def disable_auto_approve_write @auto_approve_write_enabled = false end |
#enable_auto_approve_write ⇒ Object
15 16 17 |
# File 'lib/rubycode/client/approval_handler.rb', line 15 def enable_auto_approve_write @auto_approve_write_enabled = true end |
#request_bash_approval(command, base_command, safe_commands) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rubycode/client/approval_handler.rb', line 23 def request_bash_approval(command, base_command, safe_commands) display = Views::BashApproval.build( command: command, base_command: base_command, safe_commands: safe_commands ) puts display approved = request_approval("Execute this command?") puts Views::SkipNotification.build(message: "User declined to execute '#{base_command}'") unless approved approved end |
#request_update_approval(file_path, old_string, new_string) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rubycode/client/approval_handler.rb', line 54 def request_update_approval(file_path, old_string, new_string) return true if @auto_approve_write_enabled display = Views::UpdateApproval.build( file_path: file_path, old_string: old_string, new_string: new_string ) puts display approved = request_approval("Apply this update?") puts Views::SkipNotification.build(message: "User declined to update #{file_path}") unless approved approved end |
#request_web_search_approval(query, max_results) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubycode/client/approval_handler.rb', line 71 def request_web_search_approval(query, max_results) display = Views::WebSearchApproval.build( query: query, max_results: max_results ) puts display approved = request_approval("Perform this web search?") puts Views::SkipNotification.build(message: "User declined web search for '#{query}'") unless approved approved end |
#request_write_approval(file_path, content) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rubycode/client/approval_handler.rb', line 38 def request_write_approval(file_path, content) return true if @auto_approve_write_enabled display = Views::WriteApproval.build( file_path: file_path, content: content ) puts display approved = request_approval("Create this file?") puts Views::SkipNotification.build(message: "User declined to create #{file_path}") unless approved approved end |