Module: RubynCode::Permissions::Prompter

Defined in:
lib/rubyn_code/permissions/prompter.rb

Class Method Summary collapse

Class Method Details

.confirm(tool_name, tool_input) ⇒ Boolean

Ask the user to confirm a regular tool invocation.

Parameters:

  • tool_name (String)
  • tool_input (Hash)

Returns:

  • (Boolean)

    true if the user approved



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubyn_code/permissions/prompter.rb', line 15

def self.confirm(tool_name, tool_input)
  prompt = build_prompt
  pastel = Pastel.new

  display_tool_summary(pastel, tool_name, tool_input)

  prompt.yes?(
    pastel.yellow('Allow this tool call?'),
    default: true
  )
rescue TTY::Prompt::Reader::InputInterrupt
  false
end

.confirm_destructive(tool_name, tool_input) ⇒ Boolean

Ask the user to confirm a destructive tool invocation. Requires the user to type “yes” explicitly rather than just pressing Enter.

Parameters:

  • tool_name (String)
  • tool_input (Hash)

Returns:

  • (Boolean)

    true if the user approved



35
36
37
38
39
40
41
42
43
# File 'lib/rubyn_code/permissions/prompter.rb', line 35

def self.confirm_destructive(tool_name, tool_input)
  pastel = Pastel.new
  display_destructive_warning(pastel, tool_name, tool_input)

  answer = build_prompt.ask(pastel.red.bold('Type "yes" to confirm this destructive action:'))
  answer&.strip&.downcase == 'yes'
rescue TTY::Prompt::Reader::InputInterrupt
  false
end

.display_destructive_warning(pastel, tool_name, tool_input) ⇒ Object



45
46
47
48
49
50
# File 'lib/rubyn_code/permissions/prompter.rb', line 45

def self.display_destructive_warning(pastel, tool_name, tool_input)
  $stdout.puts pastel.red.bold('WARNING: Destructive operation requested')
  $stdout.puts pastel.red('=' * 50)
  display_tool_summary(pastel, tool_name, tool_input)
  $stdout.puts pastel.red('=' * 50)
end