
    `gj              	           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l	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       y)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env_var_enabled
start_linecountcallbackreturnc                    |t        d      S 	 d| dfd|dffD ci c]  \  }}}||t        |t        |              }}}}	  |di |}|st        d	      S 	 t        j                  t        j                  |      d
      S c c}}}w # t        t        f$ r t        d      cY S w xY w# t
        $ r}t        d|       cY d}~S d}~ww xY w# 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.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   maxint	TypeError
ValueError	Exceptionjsondumpsloadsstr)	r	   r
   r   keyvalfloorwindowrawexcs	            K/root/.hermes/venv/lib/python3.12/site-packages/tools/read_terminal_tool.pyread_terminal_toolr#      s.    VWWD &-j!$<wq>Q#R
 
S% UCH%%
 
=   NOOBzz$**S/>>%

 z" DBCCD
  =5cU;<<= z" Bzz63s8,5AABsR   B #B B B, )C B B)(B),	C5CCC1DDc                      t        d      S )uI   Desktop GUI only — HERMES_DESKTOP is set on the gateway the app spawns.HERMES_DESKTOPr   r       r"    check_read_terminal_requirementsr'   4   s    +,,r&   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
   )r+   
properties)namer,   
parametersterminalc                 x    t        | j                  d      | j                  d      |j                  d            S )Nr	   r
   r   )r	   r
   r   )r#   get)argskws     r"   <lambda>r5   W   s0    188L)hhw
#  r&   u   🖥️)r.   toolsetschemahandlercheck_fnemoji)NNN)__doc__r   ostypingr   r   tools.registryr   r   utilsr   r   r   r#   boolr'   READ_TERMINAL_SCHEMAregisterr   r&   r"   <module>rC      s     	 % / ! !%#'BBC=B x B 		BB-$ - 	F  "`
 "b	
 4   	
 .
r&   