
    iN
                         d Z ddlZddlZ ej        d          ZddlmZ  e            Zedz  Zde	de	fdZ
de	ddfd	Zd
e	deddfdZdS )ua  Built-in boot-md hook — run ~/.hermes/BOOT.md on gateway startup.

This hook is always registered. It silently skips if no BOOT.md exists.
To activate, create ``~/.hermes/BOOT.md`` with instructions for the
agent to execute on every gateway restart.

Example BOOT.md::

    # Startup Checklist

    1. Check if any cron jobs failed overnight
    2. Send a status update to Discord #general
    3. If there are errors in /opt/app/deploy.log, summarize them

The agent runs in a background thread so it doesn't block gateway
startup. If nothing needs attention, it replies with [SILENT] to
suppress delivery.
    Nzhooks.boot-md)get_hermes_homezBOOT.mdcontentreturnc                     d|  dS )z3Wrap BOOT.md content in a system-level instruction.z^You are running a startup boot checklist. Follow the BOOT.md instructions below exactly.

---
z
---

Execute each instruction. If you need to send a message to a platform, use the send_message tool.
If nothing needs attention and there is nothing to report, reply with ONLY: [SILENT] )r   s    E/home/agentuser/.hermes/hermes-agent/gateway/builtin_hooks/boot_md.py_build_boot_promptr	      s     	$ 	$ 	$ 	$
    c                    	 ddl m} t          |           } |dddd          }|                    |          }|                    dd          }|r)d|vr%t
                              d	|d
d                    d
S t
                              d           d
S # t          $ r&}t
                              d|           Y d
}~d
S d
}~ww xY w)z@Spawn a one-shot agent session to execute the boot instructions.r   )AIAgentT   )
quiet_modeskip_context_filesskip_memorymax_iterationsfinal_response z[SILENT]zboot-md completed: %sN   z%boot-md completed (nothing to report)zboot-md agent failed: %s)		run_agentr   r	   run_conversationgetloggerinfo	Exceptionerror)r   r   promptagentresultresponsees          r   _run_boot_agentr!   -   s   4%%%%%%#G,,#	
 
 
 ''//::.33 	A
(22KK/$3$@@@@@KK?@@@@@ 4 4 4/3333333334s   A8B <B 
C"CC
event_typecontextc                 V  K   t                                           sdS t                               d                                          }|sdS t                              dt          |                     t          j        t          |fdd          }|
                                 dS )u5   Gateway startup handler — run BOOT.md if it exists.Nzutf-8)encodingzRunning BOOT.md (%d chars)zboot-mdT)targetargsnamedaemon)	BOOT_FILEexists	read_textstripr   r   len	threadingThreadr!   start)r"   r#   r   threads       r   handler3   C   s       !!7!3399;;G 
KK,c'll;;; Z	  F LLNNNNNr
   )__doc__loggingr/   	getLoggerr   hermes_constantsr   HERMES_HOMEr*   strr	   r!   dictr3   r   r
   r   <module>r;      s    &     		?	+	+ , , , , , ,o)#	     4S 4T 4 4 4 4,S 4 D      r
   