
    )j              	           d Z ddlZddlZddlmZmZ ddlmZmZ 	 	 	 ddee	         dee	         dee         de
fd	Zdefd
ZddddddddddddZ ej        dded ed           dS )u  Read the in-app terminal pane in the Hermes desktop GUI.

The embedded terminal's buffer lives in the desktop renderer (xterm.js), so this
tool round-trips through the gateway's blocking-prompt bridge — the same one
`clarify` uses: tui_gateway emits ``terminal.read.request``, the renderer answers
with ``terminal.read.respond``. This module is just schema + a thin dispatcher
over the platform-injected callback.
    N)CallableOptional)registry
tool_error
start_linecountcallbackreturnc                    |t          d          S 	 d d| dfd|dffD             }n&# t          t          f$ r t          d          cY S w xY w	  |di |}n)# t          $ r}t          d	|           cY d}~S d}~ww xY w|st          d
          S 	 t	          j        t	          j        |          d          S # t          t          f$ r( t	          j        dt          |          id          cY S w xY w)zIReturn the in-app terminal's contents (+ line metadata) as a JSON string.Nz:read_terminal is only available in the Hermes desktop app.c           	      V    i | ]&\  }}}||t          |t          |                    'S )N)maxint).0keyvalfloors       =/home/ubuntu/.hermes/hermes-agent/tools/read_terminal_tool.py
<dictcomp>z&read_terminal_tool.<locals>.<dictcomp>   s=     
 
 
S% UCHH%%    startr   r      z&start_line and count must be integers.zFailed to read terminal: z2No in-app terminal is open, or the read timed out.F)ensure_asciitext )r   	TypeError
ValueError	Exceptionjsondumpsloadsstr)r   r   r	   windowrawexcs         r   read_terminal_toolr%      su    VWWWD
 
%,j!$<wq>Q#R
 
 

 z" D D DBCCCCCD=h     = = =;c;;<<<<<<<<=  PNOOOBz$*S//>>>>z" B B Bz63s88,5AAAAAABs?   (  A
AA 
A>"A93A>9A>'B; ;6C43C4c                  z    t          j        d          pd                                                                dv S )uI   Desktop GUI only — HERMES_DESKTOP is set on the gateway the app spawns.HERMES_DESKTOP )1trueyes)osgetenvstriplowerr   r   r    check_read_terminal_requirementsr0   3   s6    I&''-24466<<>>BVVVr   read_terminala  Read what's currently shown in the in-app terminal pane of the Hermes desktop GUI (the embedded shell beside this chat). Call with no arguments to get the visible screen plus the total line count (`total_lines`). To page through scrollback, pass `start_line` (0 = oldest line) and `count`; valid lines are [0, total_lines). Returns JSON: {total_lines, start, end, viewport_rows, cursor_row, text}.objectintegerz?0-indexed first line (0 = oldest). Omit for the visible screen.)typedescriptionzALines to read from start_line. Defaults to the visible row count.)r   r   )r4   
properties)namer5   
parametersterminalc                     t          |                     d          |                     d          |                    d                    S )Nr   r   r	   )r   r   r	   )r%   get)argskws     r   <lambda>r>   V   sC    188L))hhw
##      r   u   🖥️)r7   toolsetschemahandlercheck_fnemoji)NNN)__doc__r   r,   typingr   r   tools.registryr   r   r   r!   r%   boolr0   READ_TERMINAL_SCHEMAregisterr   r   r   <module>rJ      sj     				 % % % % % % % % / / / / / / / / !%#'B BBC=B x B 		B B B BBW$ W W W W 	F  "` 
 "b 	
 	
   4  	 
 .
     r   