
    (Gjg
                         d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	 de
de
fdZdefd	Zd
ddddddidgddZ ej        d
ded ed           dS )u{  Close a read-only agent terminal tab in the Hermes desktop GUI.

Each ``terminal(background=true)`` process is mirrored as a read-only tab in the
desktop's terminal pane. This tool lets the agent drop a tab it no longer needs
to show — WITHOUT killing the process (use ``process(action='kill')`` for that).
The output keeps buffering and the user can reopen the tab from the status stack.

It routes through the process registry's ``on_close`` sink, which the desktop
gateway wires to emit a ``terminal.close`` event the renderer handles. Like
``read_terminal`` it is gated on ``HERMES_DESKTOP`` so it never appears outside
the GUI.
    Nenv_var_enabled)process_registry)registry
tool_error
process_idreturnc                     | pd                                 }|st          d          S t          j        t	          j        |          d          S )zBAsk the desktop GUI to close a background process's read-only tab. zCprocess_id is required (the background process whose tab to close).F)ensure_ascii)stripr   jsondumpsr   request_close_terminal)r   pids     ?/home/rurouni/.hermes/hermes-agent/tools/close_terminal_tool.pyclose_terminal_toolr      sR    
"
"
$
$C a_```:&=cBBQVWWWW    c                       t          d          S )uI   Desktop GUI only — HERMES_DESKTOP is set on the gateway the app spawns.HERMES_DESKTOPr    r   r   !check_close_terminal_requirementsr   !   s    +,,,r   close_terminalu  Close the read-only terminal tab for one of your background processes in the Hermes desktop GUI (the tabs mirroring terminal(background=true) runs). This does NOT kill the process — it only drops the tab/view; the output keeps buffering and the user can reopen it from the status stack. Use it to tidy up when a background process's live terminal is no longer worth showing. To actually stop the process, use process(action='kill') instead.objectstringzThe background process's session id (from terminal(background=true) output or process(action='list')) whose tab should be closed.)typedescription)r   
propertiesrequired)namer   
parametersterminalc                 J    t          |                     dd                    S )Nr   r   )r   )r   get)argskws     r   <lambda>r'   D   s!    2dhh|UW>X>XYYY r   u   🖥️)r    toolsetschemahandlercheck_fnemoji)__doc__r   osutilsr   tools.process_registryr   tools.registryr   r   strr   boolr   CLOSE_TERMINAL_SCHEMAregisterr   r   r   <module>r6      s(     				 ! ! ! ! ! ! 3 3 3 3 3 3 / / / / / / / /XC XC X X X X-4 - - - - 	U  T 
 "N   4  	 YY.
     r   