Skip to content
Kward Search API index

Class: Kward::CLI::Tabs::TabQuestionPrompt

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/cli/tabs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli) ⇒ TabQuestionPrompt

Returns a new instance of TabQuestionPrompt.



121
122
123
# File 'lib/kward/cli/tabs.rb', line 121

def initialize(cli)
  @cli = cli
end

Instance Attribute Details

#tab ⇒ Object

Returns the value of attribute tab.



119
120
121
# File 'lib/kward/cli/tabs.rb', line 119

def tab
  @tab
end

Instance Method Details

#ask_tool_approval(tool_name:, args:, reason: nil) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/kward/cli/tabs.rb', line 133

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



125
126
127
# File 'lib/kward/cli/tabs.rb', line 125

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



129
130
131
# File 'lib/kward/cli/tabs.rb', line 129

def edit_file(path, base_dir:, allow_new:)
  @cli.send(:open_editor_for_agent, path, base_dir: base_dir, allow_new: allow_new)
end