+
    iw%                     |    R t ^ RIt^ RIt^ RIt^ RIHtHtHt ^ RI	H
t
 ^ RIHt R tR R ltRR R	 lltR
 R ltR# )a2  Interactive prompt callbacks for terminal_tool integration.

These bridge terminal_tool's interactive prompts (clarify, sudo, approval)
into prompt_toolkit's event loop. Each function takes the HermesCLI instance
as its first argument and uses its state (queues, app reference) to coordinate
with the TUI.
N)cprint_DIM_RST)save_env_value_secure)display_hermes_homec                   ^ RI Hp VP                  R/ 4      P                  R^x4      p\        P                  ! 4       pV'       * ;'       g    \        V4      ^ 8H  pRTRV'       g   TM. R^ RV/V n        \        P                  ! 4       V,           V n	        W`n
        \        V R4      '       d-   V P                  '       d   V P                  P                  4          VP                  ^R	7      p^ V n	        V#   \        P                   dx    T P                  \        P                  ! 4       ,
          pT^ 8:  d    MK\        T R4      '       d3   T P                  '       d   T P                  P                  4         K   K   K  i ; iR
T n        RT n
        ^ T n	        \        T R4      '       d-   T P                  '       d   T P                  P                  4        \        R\          RT R\"         24        R# )zPrompt for clarifying question through the TUI.

Sets up the interactive selection UI, then blocks until the user
responds. Returns the user's choice or a timeout message.

CLI_CONFIGclarifytimeoutquestionchoicesselectedresponse_queue_appr   NF
z(clarify timed out after u   s — agent will decide)zrThe user did not provide a response within the time limit. Use your best judgement to make the choice and proceed.)clir	   getqueueQueuelen_clarify_state_time	monotonic_clarify_deadline_clarify_freetexthasattrr   
invalidateEmptyr   r   r   )	r   r   r   r	   r   r   is_open_endedresult	remainings	   &&&      1/home/ubuntu/hermes-agent/hermes_cli/callbacks.pyclarify_callbackr$      s    nnY+//	3?G[[]NK443w<1#4M 	H-7RA.	C "OO-7C)sF
		&#'''2F$%C!M{{ 	&--0AAIA~sF####% )1#		& C!CCsF
Rv.wi7OPTvVW	Bs   C6 6AF:#FFFc                $    V ^8  d   QhR\         /# )   returnstr)formats   "r#   __annotate__r+   B   s     & &3 &    c                .   ^-p\         P                  ! 4       pRV/V n        \        P                  ! 4       V,           V n        \        V R4      '       d-   V P                  '       d   V P                  P                  4          VP                  ^R7      pRV n        ^ V n        \        V R4      '       d-   V P                  '       d   V P                  P                  4        V'       d   \        R\         R\         24       V# \        R\         R\         24       V#   \         P                   d{    T P
                  \        P                  ! 4       ,
          pT^ 8:  d    MN\        T R4      '       d5   T P                  '       d   T P                  P                  4         EK$   EK(   EK,  i ; iRT n        ^ T n        \        T R4      '       d-   T P                  '       d   T P                  P                  4        \        R\         R\         24       R	# )
zmPrompt for sudo password through the TUI.

Sets up a password input area and blocks until the user responds.
r   r   r   Nr   u,     ✓ Password received (cached for session)u     ⏭ Skippedu)     ⏱ Timeout — continuing without sudo )r   r   _sudo_stater   r   _sudo_deadliner   r   r   r   r   r   r   r   )r   r   r   r!   r"   s   &    r#   sudo_password_callbackr1   B   s   
 G[[]N'8CO*W4CsF
	&#'''2F"CO!"CsF####%D6!MdVTU M D6tf56M{{ 	&**U__->>IA~sF####%% )1#		& COCsF
Rv>tfEFs2   AD !D (D D AF-"#F-F-,F-c                <    V ^8  d   QhR\         R\         R\        /# )r&   var_namepromptr'   )r)   dict)r*   s   "r#   r+   r+   k   s&     u uS u# u ur,   c                   \        V RR4      '       g   \        V R4      '       g   RV n        \        V R4      '       g   ^ V n         \        P                  ! V R24      pV'       g(   \        R\         R\         24       R	R
RRRVRRRR
RR/# \        W4      p\        4       p\        R\         RV RV \         24       / VCRRRR/C# ^xp\        P                  ! 4       pRTRTRT;'       g    / RV/V n        \        P                  ! 4       V,           V n        \        V R4      '       d    V P!                  4        MI\        V R4      '       d8   V P$                  '       d&    V P$                  P&                  P)                  4        \        V R4      '       d-   V P$                  '       d   V P$                  P+                  4          VP-                  ^R7      pRV n        ^ V n        \        V R4      '       d-   V P$                  '       d   V P$                  P+                  4        V'       g(   \        R\         R\         24       R	R
RRRVRRRR
RR/# \        W4      p\        4       p\        R\         RV RV \         24       / VCRRRR/C#   \
        \        3 d    Rp ELJi ; i  \"         d     EL2i ; i  \"         d     ELDi ; i  \        P.                   d{    T P                  \        P                  ! 4       ,
          p	T	^ 8:  d    MN\        T R4      '       d5   T P$                  '       d   T P$                  P+                  4         EK   EK   EK  i ; iRT n        ^ T n        \        T R4      '       d$    T P!                  4        Ml  \"         d     M_i ; i\        T R4      '       dJ   T P$                  '       d8    T P$                  P&                  P)                  4        M  \"         d     Mi ; i\        T R4      '       d-   T P$                  '       d   T P$                  P+                  4        \        R\         R\         24       R	R
RRRTRRRR
RR/# )zPrompt for a secret value through the TUI (e.g. API keys for skills).

Returns a dict with keys: success, stored_as, validated, skipped, message.
The secret is stored in ~/.hermes/.env and never exposed to the model.
r   N_secret_state_secret_deadlinez (hidden, Enter to skip): r.   r   u     ⏭ Secret entry cancelledsuccessTreason	cancelled	stored_as	validatedFskippedmessagezSecret setup was skipped.u     ✓ Stored secret in z	/.env as zFSecret stored securely. The secret value was not exposed to the model.r3   r4   metadatar   _clear_secret_input_bufferr   u*     ⏱ Timeout — secret capture cancelledr   z'Secret setup timed out and was skipped.)getattrr   r7   r8   getpassEOFErrorKeyboardInterruptr   r   r   r   r   r   r   r   r   rA   	Exceptionr   current_bufferresetr   r   r   )
r   r3   r4   r@   valuestored_dhhr   r   r"   s
   &&&&      r#   prompt_for_secretrL   k   s4    3%%sO,, $Cs.//#$C 	OOvh.H$IJE Rv9$@A4+XU46  'x7"$D60iz$PQ

u_
 	
 G[[]N 	H&HNN.	C !??,w6Cs011	**, 
f		#(((	HH##))+ sF
	&"&&q&1E $C#$C sF####%D6!=dVDEtkt:  +8;F&(DRv4TF)H:dVTU5c M +, 	E	J  		
  		B {{ 	&,,u/@@IA~sF####%% )1#		& CCs011	**, 			f		#(((	HH##))+ 		sF
Rv?vFG4)XU4< s   J 0J. &$K  
AK !K 0&K <K J+*J+.J=<J= KKAM!#M!:M! M!N N$#N$$O1 1O?>O?c                <    V ^8  d   QhR\         R\         R\         /# )r&   commanddescriptionr'   r(   )r*   s   "r#   r+   r+      s!     8 8C 8c 8c 8r,   c                &   \        V RR4      pVf&   ^ RIpVP                  4       V n        V P                  pT;_uu_ 4        ^ RIHp VP                  R/ 4      P                  R^<4      p\        P                  ! 4       p. ROp\        V4      ^F8  d   VP                  R4       RVR	VR
VR^ RV/V n        \        P                  ! 4       V,           V n        \        V R4      '       d-   V P                   '       d   V P                   P#                  4          VP                  ^R7      p	RV n        ^ V n        \        V R4      '       d-   V P                   '       d   V P                   P#                  4        V	uuRRR4       #   \        P$                   dx    T P                  \        P                  ! 4       ,
          p
T
^ 8:  d    MK\        T R4      '       d3   T P                   '       d   T P                   P#                  4         K   K   K  i ; iRT n        ^ T n        \        T R4      '       d-   T P                   '       d   T P                   P#                  4        \'        R\(         R\*         24        RRR4       R#   + '       g   i     R# ; i)a  Prompt for dangerous command approval through the TUI.

Shows a selection UI with choices: once / session / always / deny.
When the command is longer than 70 characters, a "view" option is
included so the user can reveal the full text before deciding.

Uses cli._approval_lock to serialize concurrent requests (e.g. from
parallel delegation subtasks) so each prompt gets its own turn.
_approval_lockNr   	approvalsr   denyviewrN   rO   r   r   r   r   r   r   u!     ⏱ Timeout — denying command)oncesessionalwaysrS   )rB   	threadingLockrQ   r   r	   r   r   r   r   append_approval_stater   r   _approval_deadliner   r   r   r   r   r   r   )r   rN   rO   lockrX   r	   r   r   r   r!   r"   s   &&&        r#   approval_callbackr^      s    3($/D|&^^-!!	"..b155iD7w<"NN6" w;wn
 "'!2W!<3CHHHHH!*'++A+6&*#)*&3''CHHHHH'')7 
8 ;; *22U__5FF	>3''CHHHHH'') -5'	* #!"3CHHHHH!D6:4&ABQ 
sQ   B8I?:I?AF F  AHI?#H(H	I?H4I?4I??J	)N)__doc__r   timer   rC   hermes_cli.bannerr   r   r   hermes_cli.configr   hermes_constantsr   r$   r1   rL   r^    r,   r#   <module>re      s9       0 0 3 0-`&Rup8r,   