
    i[              	           d Z ddlZddlmZmZmZ dZ	 	 ddedeee                  dee         defd	Zde	fd
Z
dddddddddieddddgddZddlmZmZ  ej        dded e
d           dS )a  
Clarify Tool Module - Interactive Clarifying Questions

Allows the agent to present structured multiple-choice questions or open-ended
prompts to the user. In CLI mode, choices are navigable with arrow keys. On
messaging platforms, choices are rendered as a numbered list.

The actual user-interaction logic lives in the platform layer (cli.py for CLI,
gateway/run.py for messaging). This module defines the schema, validation, and
a thin dispatcher that delegates to a platform-provided callback.
    N)ListOptionalCallable   questionchoicescallbackreturnc                 T   | r|                                  st          d          S |                                  } |[t          |t                    st          d          S d |D             }t	          |          t
          k    r|dt
                   }|sd}|t          j        ddid          S 	  || |          }n2# t          $ r%}t          j        dd	| id          cY d}~S d}~ww xY wt          j        | |t          |                                           d
d          S )a  
    Ask the user a question, optionally with multiple-choice options.

    Args:
        question: The question text to present.
        choices:  Up to 4 predefined answer choices. When omitted the
                  question is purely open-ended.
        callback: Platform-provided function that handles the actual UI
                  interaction. Signature: callback(question, choices) -> str.
                  Injected by the agent runner (cli.py / gateway).

    Returns:
        JSON string with the user's response.
    zQuestion text is required.Nz"choices must be a list of strings.c                     g | ]D}t          |                                          #t          |                                          ES  )strstrip).0cs     7/home/ubuntu/.hermes/hermes-agent/tools/clarify_tool.py
<listcomp>z clarify_tool.<locals>.<listcomp>3   s9    EEEac!ffllnnE3q66<<>>EEE    errorz8Clarify tool is not available in this execution context.F)ensure_asciizFailed to get user input: )r   choices_offereduser_response)
r   
tool_error
isinstancelistlenMAX_CHOICESjsondumps	Exceptionr   )r   r   r	   r   excs        r   clarify_toolr"      s   &  88>>++ 86777~~H '4(( 	DBCCCEE7EEEw<<+%%l{l+G 	GzPQ
 
 
 	


 733 
 
 
z83889
 
 
 	
 	
 	
 	
 	
 	

 :"]++1133  	   s   2B? ?
C.	C)#C.)C.c                      dS )z>Clarify tool has no external requirements -- always available.Tr   r   r   r   check_clarify_requirementsr$   N   s    4r   clarifyu  Ask the user a question when you need clarification, feedback, or a decision before proceeding. Supports two modes:

1. **Multiple choice** — provide up to 4 choices. The user picks one or types their own answer via a 5th 'Other' option.
2. **Open-ended** — omit choices entirely. The user types a free-form response.

Use this tool when:
- The task is ambiguous and you need the user to choose an approach
- You want post-task feedback ('How did that work out?')
- You want to offer to save a skill or update memory
- A decision has meaningful trade-offs the user should weigh in on

Do NOT use this tool for simple yes/no confirmation of dangerous commands (the terminal tool handles that). Prefer making a reasonable default choice yourself when the decision is low-stakes.objectstringz$The question to present to the user.)typedescriptionarrayr(   zUp to 4 answer choices. Omit this parameter entirely to ask an open-ended question. When provided, the UI automatically appends an 'Other (type your answer)' option.)r(   itemsmaxItemsr)   )r   r   )r(   
propertiesrequired)namer)   
parameters)registryr   c                     t          |                     dd          |                     d          |                    d                    S )Nr    r   r	   )r   r   r	   )r"   get)argskws     r   <lambda>r7      sD    |*b))##
## %  %  % r   u   ❓)r/   toolsetschemahandlercheck_fnemoji)NN)__doc__r   typingr   r   r   r   r   r"   boolr$   CLARIFY_SCHEMAtools.registryr1   r   registerr   r   r   <module>rC      ss  
 
  + + + + + + + + + +
 
 $(#'4 44d3i 4 x 4 		4 4 4 4nD     	C   !E 
   (+'R	 	
 
   L% %& &T 0 / / / / / / /  	% % (

 
 
 
 
 
r   