Class: Kward::CLI::Tabs::TabQuestionPrompt
- Inherits:
-
Object
- Object
- Kward::CLI::Tabs::TabQuestionPrompt
- Defined in:
- lib/kward/cli/tabs.rb
Instance Attribute Summary collapse
-
#tab ⇒ Object
Returns the value of attribute tab.
Instance Method Summary collapse
- #ask_tool_approval(tool_name:, args:, reason: nil) ⇒ Object
- #ask_user_question(questions, cancellation: nil) ⇒ Object
- #edit_file(path, base_dir:, allow_new:) ⇒ Object
-
#initialize(cli) ⇒ TabQuestionPrompt
constructor
A new instance of TabQuestionPrompt.
Constructor Details
#initialize(cli) ⇒ TabQuestionPrompt
Returns a new instance of TabQuestionPrompt.
109 110 111 |
# File 'lib/kward/cli/tabs.rb', line 109 def initialize(cli) @cli = cli end |
Instance Attribute Details
#tab ⇒ Object
Returns the value of attribute tab.
107 108 109 |
# File 'lib/kward/cli/tabs.rb', line 107 def tab @tab end |
Instance Method Details
#ask_tool_approval(tool_name:, args:, reason: nil) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/kward/cli/tabs.rb', line 121 def ask_tool_approval(tool_name:, args:, reason: nil) answers = ask_user_question([ { header: "Approval required · #{tool_name.to_s.tr("_", " ").capitalize}", question: (["The agent wants to use #{tool_name}.", "Arguments:\n#{JSON.pretty_generate(args.to_h)}", reason].compact).join("\n"), options: [ { label: "Allow once", description: "Run this tool call." }, { label: "Allow this tool for this session", description: "Run this call and future calls to #{tool_name}." }, { label: "Deny", description: "Do not run this tool call." } ] } ]) answer = answers&.first return { denied_message: answer[:answer] } if answer&.fetch(:custom, false) && !answer[:answer].to_s.empty? case answer&.fetch(:answer, nil) when "Allow once" then true when "Allow this tool for this session" then :allow_for_session else false end end |
#ask_user_question(questions, cancellation: nil) ⇒ Object
113 114 115 |
# File 'lib/kward/cli/tabs.rb', line 113 def ask_user_question(questions, cancellation: nil) @cli.send(:ask_tab_user_question, @tab, questions, cancellation: cancellation) end |
#edit_file(path, base_dir:, allow_new:) ⇒ Object
117 118 119 |
# File 'lib/kward/cli/tabs.rb', line 117 def edit_file(path, base_dir:, allow_new:) @cli.send(:open_editor_for_agent, path, base_dir: base_dir, allow_new: allow_new) end |