Class: RubynCode::Tools::AskUser
- Defined in:
- lib/rubyn_code/tools/ask_user.rb
Constant Summary collapse
- TOOL_NAME =
'ask_user'- DESCRIPTION =
'Ask the user a question and wait for their response. ' \ 'Use this when you need clarification, want to confirm a plan before executing, ' \ 'or are stuck and need guidance. The question is displayed and the user\'s answer ' \ 'is returned as the tool result.'
- PARAMETERS =
{ question: { type: :string, description: 'The question to ask the user', required: true } }.freeze
- RISK_LEVEL =
Never needs approval — it IS the approval mechanism
:read
Constants inherited from Base
Instance Attribute Summary collapse
-
#prompt_callback ⇒ Object
writeonly
Sets the attribute prompt_callback.
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
description, #initialize, parameters, requires_confirmation?, risk_level, #safe_path, summarize, to_schema, tool_name, #truncate
Constructor Details
This class inherits a constructor from RubynCode::Tools::Base
Instance Attribute Details
#prompt_callback=(value) ⇒ Object (writeonly)
Sets the attribute prompt_callback
23 24 25 |
# File 'lib/rubyn_code/tools/ask_user.rb', line 23 def prompt_callback=(value) @prompt_callback = value end |
Instance Method Details
#execute(question:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubyn_code/tools/ask_user.rb', line 25 def execute(question:) if @prompt_callback @prompt_callback.call(question) elsif $stdin.respond_to?(:tty?) && $stdin.tty? # Interactive fallback: prompt on stdin $stdout.puts $stdout.puts " #{question}" $stdout.print ' > ' $stdout.flush $stdin.gets&.strip || '[no response]' else # Non-interactive (piped input, -p mode, daemon) — can't ask '[non-interactive session — cannot ask user. Make your best judgment and proceed.]' end end |