+
    jHàjù}  ã                  óÖ  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
t
^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt R	R
0tR6tR7tR R ltR8R R lltR R lt^‚tR R ltR8R R lltR8R R lltR8R R lltR R ltR8R R llt R8R R llt!R9R R  llt"R! t#] ! R" R#4      4       t$R$ R% lt%R& R' lt&R( R) lt'R* R+ lt(R:R, R- llt)R. R/ lt*R0 R1 lt+R8R2 R3 llt,R4 R5 lt-R# );už  Oneshot (-z) mode: send a prompt, get the final content block, exit.

Toolsets = explicit --toolsets, else the user's "cli" toolsets from `hermes tools`. Rules /
memory / AGENTS.md / preloaded skills = same as a normal chat turn. Approvals are auto-bypassed
(HERMES_YOLO_MODE=1). Model/provider mirror `hermes chat`: both optional; only --model â†’ auto-detect
the provider; only --provider â†’ error (ambiguous).
)ÚannotationsN)Úredirect_stderrÚredirect_stdout)Ú	dataclass)ÚPath)ÚOptional)Údeclare_stateless_channel)Úget_fallback_chainÚallÚ*c               ó    € V ^8„  d   QhRRRR/# )é   Ú
session_idúOptional[str]Úreturnúdict[str, dict]© )Úformats   "Ú7/home/ubuntu/.hermes/hermes-agent/hermes_cli/oneshot.pyÚ__annotate__r   .   s   € ÷ ñ ¨]ð ¸ñ ó    c                ó˜   € V e	   V'       g   / #  V P                  V4      #   \         d    \        P                  ! RRR7       / u # i ; i)zZPer-task aux usage recorded for *session_id*'s lineage (``{}`` without a store / session).z$oneshot: auxiliary usage read failedT©Úexc_info)Úauxiliary_usage_by_taskÚ	ExceptionÚloggingÚdebug)Ú
session_dbr   s   &&r   Ú_auxiliary_usager   .   sH   € àÒ§Øˆ	ðØ×1Ñ1°*Ó=Ð=øÜô Ü�ŠÐ<ÀtÕLØŠ	ðús   �! ¡%A	ÁA	c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   ÚresultÚdictÚbeforer   Úfallback_session_idr   r   ÚNoner   )r   s   "r   r   r   9   s*   € ÷ (ñ ( Dð (¸oð (Ø1>ð(ØJNñ(r   c           	     óº  € ^ RI Hp V! 4        \        YP                  R4      ;'       g    T4      p/ pVP	                  4        FŠ  w  rxVP                  V/ 4      p	\
         U
u/ uF>  qªVP                  V
4      ;'       g    ^ V	P                  V
4      ;'       g    ^ ,
          bK@  	  pp
\        VP                  4       4      '       g   K†  W¶V&   KŒ  	  W`R&   R# u up
i )at  Store this run's auxiliary usage on *result* as the delta against the pre-turn snapshot
(a resumed session already carries earlier runs' aux rows). Waits (bounded) for the auto-title
thread first: it bills from a daemon thread and can still be in flight when the turn returns.
Failed-turn dicts carry no ``session_id``; *fallback_session_id* keeps the delta readable then.)Úwait_for_title_upgradesr   Úauxiliary_usageN)Úagent.title_generatorr'   r   ÚgetÚitemsÚ_AUX_COUNTERSÚanyÚvalues)r!   r   r#   r$   r'   ÚafterÚby_taskÚtaskÚcountersÚpriorÚkeyÚdeltas   &&&&        r   Ú_attach_auxiliary_usager6   9   s¸   € õ >áÔÜ˜Z¯©°LÓ)A×)XÐ)XÐEXÓY€EØ!€GØŸ+™+ž-‰ˆØ—
‘
˜4 Ó$ˆÝR_Ó`ÑR_È3�x—|‘| CÓ(×-Ð-¨A°%·)±)¸C³.×2EÐ2EÀAÕFÒFÑR_ˆÐ`Üˆu�|‰|‹~×ÔØ!�D‹Mñ	 (ð
 !(ÐÓùò as   Á#CÂ CÂCc               ó$   € V ^8„  d   QhRRRRRR/# )r   Úreportr"   r0   r   r   r%   r   )r   s   "r   r   r   L   s!   € ÷ 
ñ 
˜dð 
¨_ð 
Àñ 
r   c           	     óÆ  a€ \          Uau/ uF'  oS\        V3R lVP                  4        4       4      bK)  	  ppVR,          VR,          ,           VR&   / VCRV/CV R&   V P                  R4      pRVf   RMWCR,          ,           RV P                  R4      ;'       g    ^ VR,          ,           R	V P                  R	4      ;'       g    ^ VR	,          ,           /V R
&   R# u upi )zPAdd the ``auxiliary`` breakdown and ``total_including_auxiliary`` to the ledger.c              3  óX   <"  € T F  qP                  S4      ;'       g    ^ x € K!  	  R# 5i)é    N)r*   )Ú.0Útr4   s   & €r   Ú	<genexpr>Ú$_auxiliary_report.<locals>.<genexpr>N   s!   øé € ÐAÑ0@¨1—u‘u˜S“z—� Q”Ó0@ùs   ƒ*Ÿ*Úinput_tokensÚoutput_tokensÚtotal_tokensr0   Ú	auxiliaryÚestimated_cost_usdNÚ	api_callsÚtotal_including_auxiliary)r,   Úsumr.   r*   )r8   r0   r4   ÚtotalsÚ	main_costs   &&`  r   Ú_auxiliary_reportrJ   L   sÔ   ø€ åMZÔ[É]Àcˆc”3ÔA°·±Ô0@ÓAÓAÒAÉ]€FÐ[Ø# NÕ3°f¸_Õ6MÕM€Fˆ>ÑØ8˜VÐ8 Y°Ñ8€Fˆ;ÑØ—
‘
Ð/Ó0€Ià iÒ&7™d¸YÐPdÕIeÕ=eØ˜Ÿ™ NÓ3×8Ð8°q¸FÀ>Õ<RÕRØ�f—j‘j Ó-×2Ð2°°f¸[Õ6IÕIð+€FÐ&Ó'ùò	 \s   ‹-Cc               ó$   € V ^8„  d   QhRRRRRR/# )r   Úresponser   r!   r"   r   Úintr   )r   s   "r   r   r   \   s!   € ÷ ñ  ð ¸ð Àñ r   c                ó  € VP                  R4      '       d   \        # VP                  R4      '       g-   VP                  R4      '       g   VP                  R4      RJ d   ^# T ;'       g    RP                  4       '       g   ^# ^ # )aø  Map a finished ``-z`` turn onto its exit code: ``0`` only when the turn completed;
``130`` interrupted; ``2`` failed or stopped partway (``partial``, ``completed: False`` such
as the iteration budget); ``1`` a completed turn that produced no text at all.

The outcome is judged from the result, not from whether text was printed: a partial or
failed turn usually leaves an explanation on stdout, and exiting 0 for it made scripts treat
a half-done job (or a provider error summary) as success (#111770).
ÚinterruptedÚfailedÚpartialÚ	completedFÚ )r*   Ú_INTERRUPTED_EXIT_CODEÚstrip)rL   r!   s   &&r   Ú_oneshot_exit_coderV   \   se   € ð ‡z�z�-× Ò Ü%Ð%Ø‡z�z�(×Ò˜vŸz™z¨)×4Ò4¸¿
¹
À;Ó8OÐSXÓ8XÙØ�NˆN˜×!Ñ!×#Ò#ÙÙr   c               ó    € V ^8„  d   QhRRRR/# )r   ÚtoolsetsÚobjectr   zlist[str] | Noner   )r   s   "r   r   r   n   s   € ÷ Nñ N &ð NÐ4Dñ Nr   c                óš  € V '       g   R# \        V \        \        34      '       d   T MV .pV Uu. uF?  p\        V\        4      '       d   \        V4      P	                  R4      M\        V4      .NKA  	  ppV UUu. uF2  qD F*  qUP                  4       '       g   K  VP                  4       NK,  	  K4  	  upp;'       g    R# u upi u uppi )zUSplit repeated/comma-separated toolset flags into a clean list (``None`` when empty).NÚ,)Ú
isinstanceÚlistÚtupleÚstrÚsplitrU   )rX   r+   ÚitemÚpartsÚchunkÚps   &     r   Ú_normalize_toolsetsre   n   s˜   € çÙÜ" 8¬d´E¨]×;Ò;‰HÀ(À€EÙX]Ó^ÑX]ÐPT¤Z°´c×%:Ò%:ŒS�‹Y�_‰_˜SÔ!ÄÀTÃÀÒKÑX]€EÐ^Ù#(ÔE¡5˜%²%¨Q¿7¹7¿9ŒIˆA�G‰GŽI±%‰I¡5ÒE×MÐMÈÐMùò _ùÛEs   °ACÁ<CÂCc               ó    € V ^8„  d   QhRRRR/# )r   ÚskillsrY   r   z	list[str]r   )r   s   "r   r   r   w   s   € ÷ Bñ B˜fð B°	ñ Br   c                ód   € \        \        P                  \        V 4      ;'       g    . 4      4      # )zBNormalize repeated/comma-separated skill flags and preserve order.)r]   r"   Úfromkeysre   )rg   s   &r   Ú_normalize_skillsrj   w   s$   € ä”—‘Ô1°&Ó9×?Ð?¸RÓ@ÓAÐAr   c               ó    € V ^8„  d   QhRRRR/# )r   rg   rY   r   ú
str | Noner   )r   s   "r   r   r   |   s   € ÷ !ñ !¨6ð !¸Zñ !r   c                ó  € \        V 4      pV'       g   R# ^ RIHpHp V! V4      w  rEpV'       dG   V'       g   \	        V! V4      4      h\
        P                  ! RV! V4      RP                  V4      4       T;'       g    R# )zJLoad requested skills using the same partial-success contract as CLI chat.N)Úbuild_preloaded_skills_promptÚformat_missing_skillszRSkipping %s. Continuing with: %s. List available skills with `hermes skills list`.ú, )rj   Úagent.skill_commandsrn   ro   Ú
ValueErrorr   ÚwarningÚjoin)rg   Úparsed_skillsrn   ro   Úskills_promptÚloaded_skillsÚmissing_skillss   &      r   Ú_build_preloaded_skills_promptry   |   so   € ä% fÓ-€MßÙçYá3PÐQ^Ó3_Ñ0€M .ßßÜÑ2°>ÓBÓCÐCÜ�ŠØ`Ù! .Ó1Ø�I‰I�mÓ$ô	
ð
 × Ð ˜DÐ r   c               ó   € V ^8„  d   QhRR/# )r   r   ztuple[set[str], set[str]]r   )r   s   "r   r   r   �   s   € ÷ ñ Ð!:ñ r   c                 óÌ  €  ^ RI Hp  ^ RIHp V ! 4       p\	        VP                  R4      \        4      '       d   VP                  R4      M/ p\        4       p\        4       pVP                  4        FI  w  rg\	        V\        4      '       g   K  V! V4      '       d   TMTpVP                  \        V4      4       KK  	  WE3#   \         d    \        4       \        4       3u # i ; i)zN``(enabled, disabled)`` MCP server names from config; both empty on any error.)Úread_raw_config)Úmcp_server_enabledÚmcp_servers)Úhermes_cli.configr|   Útools.mcp_tool_commonr}   r\   r*   r"   Úsetr+   Úaddr_   r   )	r|   r}   Úcfgr~   ÚenabledÚdisabledÚnameÚ
server_cfgÚtargets	            r   Ú_configured_mcp_serversr‰   �   s¹   € ðÝ5Ý<áÓˆÜ0:¸3¿7¹7À=Ó;QÔSW×0XÒ0X�c—g‘g˜mÔ,Ð^`ˆÜ›EˆÜ ›UˆØ +× 1Ñ 1Ö 3ÑˆDÜ˜j¬$×/Ò/ÙÙ 2°:× >Ò >‘WÀHˆFØ�J‰J”s˜4“yÖ!ñ	 !4ð
 Ð Ð øÜô Ü‹u”c“eˆ|Òðús   ‚BC Â$C ÃC#Ã"C#c               ó    € V ^8„  d   QhRRRR/# )r   rX   rY   r   z#tuple[list[str] | None, str | None]r   )r   s   "r   r   r   ¤   s   € ÷ 0ñ 0¨&ð 0Ð<_ñ 0r   c                óL  € \        V 4      pVf   R#  ^ RIHp T Uu. uF  qB! T4      '       g   K  TNK  	  ppT Uu. uF  qDT9  g   K  TNK  	  ppT'       dY    ^ RIHp T! 4        T Uu. uF  qB! T4      '       g   K  TNK  	  ppTP                  T4       T Uu. uF  qDT9  g   K  TNK  	  pp\        ;QJ d    R T 4       F  '       g   K   RM	  RM! R T 4       4      '       dZ   T Uu. uF  qD\        9  g   K  TNK  	  p	pT	'       d3   \        P                  P                  RR	P                  T	4       R24       R# T'       d   \        4       M\        4       \        4       3w  r«T Uu. uF  qDT
9   g   K  TNK  	  ppT Uu. uF  qDT9   g   K  TNK  	  ppT Uu. uF  qDT
9  g   K  YK9  g   K  TNK  	  ppY\,           pT'       d3   \        P                  P                  R
R	P                  T4       R24       T'       d3   \        P                  P                  RR	P                  T4       R24       T'       g   R# TR 3#   \         d   pR RT R23u R p?# R p?ii ; iu upi u upi u upi   \         d    . p ELi ; iu upi u upi u upi u upi u upi )N)Úvalidate_toolsetz*hermes -z: failed to validate --toolsets: Ú
)Údiscover_pluginsc              3  ó2   "  € T F  q\         9   x € K  	  R # 5i©N)Ú_ALL_TOOLSETS)r<   r†   s   & r   r>   Ú._validate_explicit_toolsets.<locals>.<genexpr>¼   s   é € Ð
6©X T”=Ö «Xùs   ‚TFzNhermes -z: --toolsets all enables every toolset; ignoring additional entries: rp   z0hermes -z: ignoring unknown --toolsets entries: zThermes -z: ignoring disabled MCP servers (set enabled: true in config.yaml to use): )NN)Nz:hermes -z: --toolsets did not contain any valid toolsets.
)re   rX   rŒ   r   Úhermes_cli.pluginsrŽ   Úextendr-   r‘   ÚsysÚstderrÚwritert   r‰   r�   )rX   Ú
normalizedrŒ   Úexcr†   Úbuilt_inÚ
unresolvedrŽ   Úplugin_validÚignoredÚ	mcp_namesÚmcp_disabledÚ	mcp_validr…   ÚunknownÚvalids   &               r   Ú_validate_explicit_toolsetsr£   ¤   st  € Ü$ XÓ.€JØÒØÐðJÝ-ñ ",ÓF¡˜Ð/?À×/E—�¡€HÐFÙ#-ÓF¡:˜4¸XÑ1E—$�$¡:€JÐFçð	Ý;áÔÙ-7ÓR©Z TÐ;KÈD×;QŸD˜D©ZˆLÐRð 	�‰˜Ô%Ù'1ÓN¡z˜tÀÑ5M—d�d¡zˆ
ÐNç
ƒsÑ
6©XÓ
6‡s‡s‚sÑ
6©XÓ
6×6Ò6Ù$.ÓL¡J˜D¼mÑ2K—4�4¡JˆÐLßÜ�J‰J×Ñð0Ø04·	±	¸'Ó0BÐ/CÀ2ðGôð Ðç;EÔ5Ô7ÌCËEÔSVÓSXÈ>Ñ€IÙ",ÓB¡*˜$¸	Ñ0A—�¡*€IÐBÙ!+ÓD¡˜°|Ñ/C—�¡€HÐDÙ *Óa¡
˜¸)Ñ.CŒtÈÑH`�tˆt¡
€GÐaØÕ €EçÜ�
‰
×ÑÐKÈDÏIÉIÐV]ÓL^ÐK_Ð_aÐbÔcßÜ�
‰
×ÑØbØ�y‰y˜Ó"Ð# 2ð'ô	
÷ ØRÐRØ�$ˆ;ÐøôS ô JØÐAÀ#ÀÀbÐIÐIÕIûðJüò GùÚFùò SøÜô 	Ø‹Lð	üò Oùò Mùò CùÚDùÚasž   “I
 �I*±I*½I/Á
I/ÁI9 Á,I4Â I4ÂI9 ÂJÂ*JÃ0JÄJÅ1JÅ>JÆ
JÆJÆ#J!Æ0J!Æ8J!É
I'ÉI"ÉI'É"I'É4I9 É9J
Ê	J
c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úpathr   r!   r"   Úfailurer   r%   r   )r   s   "r   r   r   ×   s)   € ÷ ñ ˜Mð °4ð À-ð Ð[_ñ r   c                óV  € V '       g   R#  \          Uu/ uF  q3VP                  V4      bK  	  pp\        VP                  R4      4      ;'       g    VRJVR&   VP                  R4      VR&   \        VP                  R4      \        4      '       d   \        WAR,          4       Ve   W$R&   \        V 4      P                  4       pVP                  P                  RRR7       VP                  \        P                  ! V^R7      R	,           R
R7       R# u upi   \         d     R# i ; i)uÐ   Best-effort JSON usage report for pipelines (``-z --usage-file``).

Written even on failure so callers can always account for spend. Never raises â€” a broken usage
write must not mask the run's own outcome.
NrP   Úservice_tierr(   r¦   T)ÚparentsÚexist_ok)Úindentr�   úutf-8©Úencoding)Ú_USAGE_KEYSr*   Úboolr\   r"   rJ   r   Ú
expanduserÚparentÚmkdirÚ
write_textÚjsonÚdumpsr   )r¥   r!   r¦   r4   r8   Úouts   &&&   r   Ú_write_usage_filer¸   ×   sû   € ÷ ÙðÝ2=Ó>±+¨3�v—z‘z #“Ò&±+ˆÐ>Ü §
¡
¨8Ó 4Ó5×LÐL¸ÈÐ9LˆˆxÑØ!'§¡¨NÓ!;ˆˆ~ÑÜ�f—j‘jÐ!2Ó3´T×:Ò:Ü˜fÐ->Õ&?Ô@ØÒØ '�9ÑÜ�4‹j×#Ñ#Ó%ˆØ�
‰
×Ñ °ÐÔ5Ø�‰”t—z’z &°Ô3°dÕ:ÀWˆÖMùò ?øô ô Úðús(   ŒD ”D®"D ÁCD ÄD ÄD(Ä'D(c               ó<   € V ^8„  d   QhRRRRRRRRRRR	RR
RRRRR/	# )r   Úpromptr_   Úmodelr   ÚproviderrX   rY   rg   Ú
usage_fileÚresumeÚ	reasoningr   rM   r   )r   s   "r   r   r   î   sm   € ÷ hñ hØðhàðhð ðhð ð	hð
 ðhð ðhð ðhð ðhð 	ñhr   c                ón  € \         P                  ! \         P                  4       \        P                  ! RR4      P                  4       pV'       dJ   T;'       g    RP                  4       '       g*   V'       g"   \        P                  P                  R4       ^# \        V4      w  ršV
'       d"   \        P                  P                  V
4       ^# \        V4      RJ pR\        P                  R&   R\        P                  R&   R\        P                  R&   \        4        \        P                  p\        P                  pRp/ pRp\        \        P                  R	R
R7      ;_uu_ 4       p\!        V4      ;_uu_ 4        \#        V4      ;_uu_ 4         \%        V VVV	VVVV\'        V4      R7	      w  rïRRR4       RRR4       RRR4       Ver   \+        V\,        \.        34      '       d   \1        W_\3        V4      R7       Vh\1        W_\5        V4      R7       VP                  RV R24       VP7                  4        ^# \1        W_4       V'       dX   ^ RIHp V! V4      pVP                  V4       VP=                  R4      '       g   VP                  R4       VP7                  4        \?        Wï4      pV^8X  d"   VP                  R4       VP7                  4        V#   \(         d   pTp Rp?EL?Rp?ii ; i  + '       g   i     ELP; i  + '       g   i     EL\; i  + '       g   i     ELh; i)a¢  Execute a single prompt and print only the final content block.

Model/provider fall back to ``HERMES_INFERENCE_MODEL`` and config.yaml. ``usage_file`` gets a
JSON usage report even when the run fails. ``resume`` is a session id (already normalized by
the CLI layer: latest/title/--continue resolution) whose transcript is loaded and continued
by this turn. Returns the exit code; the caller owns process termination.
ÚHERMES_INFERENCE_MODELrS   z†hermes -z: --provider requires --model (or HERMES_INFERENCE_MODEL). Pass both explicitly, or neither to use your configured defaults.
NÚ1ÚHERMES_YOLO_MODEÚHERMES_ACCEPT_HOOKSÚHERMES_SINGLE_QUERY_SESSIONÚwr¬   r­   )r»   r¼   rX   Úuse_config_toolsetsrg   r¾   r¿   Úledger)r¦   zhermes -z: agent failed: r�   )Ú_sanitize_surrogateszGhermes -z: no final response was produced; treating the run as failed.
) r   ÚdisableÚCRITICALÚosÚgetenvrU   r•   r–   r—   r£   re   Úenvironr   ÚstdoutÚopenÚdevnullr   r   Ú
_run_agentr°   ÚBaseExceptionr\   ÚKeyboardInterruptÚ
SystemExitr¸   Úreprr_   ÚflushÚagent.message_sanitizationrÉ   ÚendswithrV   )rº   r»   r¼   rX   rg   r½   r¾   r¿   Úenv_model_earlyÚexplicit_toolsetsÚtoolsets_errorrÇ   Úreal_stdoutÚreal_stderrrL   r!   r¦   rÑ   r™   rÉ   Ú	exit_codes   &&&&&&&&             r   Úrun_oneshotrà   î   s‰  € ô& ‡O‚O”G×$Ñ$Ô%ô —i’iÐ 8¸"Ó=×CÑCÓE€Oß˜%Ÿ+˜+ 2×,Ñ,×.Ò.·/Ü�
‰
×ÑðRô	
ñ ä(CÀHÓ(MÑ%ÐßÜ�
‰
×Ñ˜Ô(ÙÜ-¨hÓ7¸4Ð?Ðð &)„B‡J�JÐ!Ñ"Ø(+„B‡J�JÐ$Ñ%ð 14„B‡J�JÐ,Ñ-ô
 Ôô —*‘*€KÜ—*‘*€Kà"€HØ€FØ$(€GÜ	Œb�j‰j˜#¨×	0Õ	0°G¼_ÈW×=UÕ=UÔWfÐgn×WoÕWoð	Ü)ØØØ!Ø*Ø$7ØØØ#Ü˜JÓ'ô
 ÑˆH÷ Xp×=U×	0ð& Òä�gÔ 1´:Ð>×?Ò?Ü˜j¼$¸w»-ÕHØˆMÜ˜*´c¸'³lÕCØ×ÑÐ5°g°Y¸bÐAÔBØ×ÑÔÙä�jÔ)çõ 	Dá'¨Ó1ˆØ×Ñ˜(Ô#Ø× Ñ  ×&Ò&Ø×Ñ˜dÔ#Ø×ÑÔä" 8Ó4€IØ�A„~Ø×ÑÐdÔeØ×ÑÔØÐøôE ô 	ð ŽGûð		ú÷ Xp×WoÐWoú×=U×=UÐ=Uú×	0×	0Ð	0ús`   Å+L#Å?L	ÆK;ÆK Æ4L	Æ<L#Ë K8Ë+K3Ë-K;Ë3K8Ë8K;Ë;LÌ	L	ÌL Ì	L#Ì#L4	c                 ó~   €  ^ RI Hp  V ! 4       #   \         d#   p\        P                  ! RT4        Rp?R# Rp?ii ; i)u^  Best-effort SessionDB â€” oneshot bypasses ``HermesCLI._init_agent()``, so it must wire the
SQLite store itself or ``session_search`` is advertised but always unavailable. The registry
handle is the one in-process tools (delegation, goals) acquire during the run, so the process
holds one writer; ``_close_agent``'s ``close()`` releases the refcount.)Úacquirez7SQLite session store not available for oneshot mode: %sN)Úhermes_state_registryrâ   r   r   r   )râ   r™   s     r   Ú_create_session_db_for_oneshoträ   Y  s5   € ð
Ý1á‹yÐøÜô Ü�ŠÐOÐQTÔUÝûðús   ‚ �<š7·<c                  óV   € ] tR tRt$ R]R&   R]R&   RtR]R&   RtR]R&   RtR]R	&   R
tR# )Ú_ModelChoiceig  r_   r»   rl   r¼   NÚbase_urlÚapi_keyÚapi_moder   )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__annotations__rç   rè   ré   Ú__static_attributes__r   r   r   ræ   ræ   g  s+   ‡ àƒJØÓØ€HˆjÓØ€GˆZÓØ€Hˆj×r   ræ   c               ó    € V ^8„  d   QhRRRR/# )r   Ú	model_cfgrY   r   r_   r   )r   s   "r   r   r   p  s   € ÷ ñ  ð ¨Cñ r   c                ó  € \        V \        4      '       d   V # V P                  R 4      ;'       g    V P                  R4      ;'       g    Rp\        V\        4      '       d   ^ RIHp V! V4      ^ ,          # \        T;'       g    R4      # )Údefaultr»   rS   )Úsplit_model_config_default)r\   r_   r*   r"   r   rô   )rñ   Úrawrô   s   &  r   Ú_configured_modelrö   p  sl   € Ü�)œS×!Ò!ØÐØ
�-‰-˜	Ó
"×
BÐ
B i§m¡m°GÓ&<×
BÐ
BÀ€CÜ�#”t×ÒÝ@á)¨#Ó.¨qÕ1Ð1Üˆs�yˆy�b‹>Ðr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rƒ   r"   r»   r   r¼   r   ræ   r   )r   s   "r   r   r   {  s)   € ÷ 7ñ 7 Tð 7°-ð 7È=ð 7Ð]iñ 7r   c                ó¦  € ^ RI Hp V P                  R4      ;'       g    / p\        P                  ! RR4      P                  4       pT;'       g    RP                  4       ;'       g    Tp\        T;'       g    \        V4      T;'       g    RP                  4       ;'       g    R4      pVP                  f	   V'       g   V# ^ RI	H
p  VP                  4        VP                  P                  VP                  4       P                  4       4      p	V	Ef   Rp
\        V\         4      '       dA   \#        VP                  R4      ;'       g    R4      P                  4       P                  4       p
T
;'       g>    \        P                  ! RR4      P                  4       P                  4       ;'       g    R	pVP%                  WkV P                  R
4      V P                  R4      R7      pVe&   VP                  VP&                  uVn        Vn        V# V! Wk4      pV'       d   Vw  Vn        Vn        V# V	P&                  Vn        V	P                  Vn         VP)                  V	4      w  Vn        Vn        V	P,                  '       d!   V	P,                  P/                  R4      Vn        V#   \         d    Rp	 EL¥i ; i  \         d    RTn         L\i ; i)ug  Effective model = arg â†’ env â†’ config; provider = arg â†’ auto-detect â†’ config/env.

Auto-detection only runs when the model was explicitly requested (arg or env var) â€” same
semantic as ``/model <name>`` â€” because the configured default provider may not host it.
Config-sourced models are the "use my defaults" path and keep the configured provider.
)Údetect_provider_for_modelr»   rÁ   rS   N)Úmodel_switchr¼   ÚHERMES_INFERENCE_PROVIDERÚautoÚ	providersÚcustom_providers)Úcurrent_providerÚuser_providersrþ   Ú/)Úhermes_cli.modelsrù   r*   rÌ   rÍ   rU   ræ   rö   r¼   Ú
hermes_clirú   Ú_ensure_direct_aliasesÚDIRECT_ALIASESÚlowerr   r\   r"   r_   Úresolve_startup_model_router»   Údirect_alias_runtime_requestrè   rç   Úrstrip)rƒ   r»   r¼   rù   rñ   Ú	env_modelÚexplicit_modelÚchoiceÚ_msÚdirectÚcfg_providerrÿ   ÚrouteÚdetecteds   &&&           r   Ú_resolve_model_and_providerr  {  sQ  € õ <à—‘˜Ó ×&Ð& B€IÜ—	’	Ð2°BÓ7×=Ñ=Ó?€IØ—k�k˜r×(Ñ(Ó*×7Ð7¨i€NÜ˜.×HÐHÔ,=¸iÓ,HÈ8Ï>È>ÐWY×J`ÑJ`ÓJb×JjÐJjÐfjÓk€FØ‡�Ò"¯.Øˆõ /ðØ×"Ñ"Ô$Ø×#Ñ#×'Ñ'¨×(<Ñ(<Ó(>×(DÑ(DÓ(FÓGˆð ƒ~ØˆÜ�i¤×&Ò&Ü˜yŸ}™}¨ZÓ8×>Ð>¸BÓ?×EÑEÓG×MÑMÓOˆLØ'×oÐo¬2¯9ª9Ð5PÐRTÓ+U×+[Ñ+[Ó+]×+cÑ+cÓ+e×oÐoÐioÐð ×/Ñ/ØØŸ7™7 ;Ó/À#Ç'Á'ÐJ\ÓB]ð 0ó _ˆð ÒØ,1¯N©N¸E¿K¹KÐ)ˆFŒO˜Vœ\ØˆMÙ,¨^ÓNˆßØ,4Ñ)ˆFŒO˜Vœ\Øˆà—<‘<€F„LØ—o‘o€F„Oð
Ø*-×*JÑ*JÈ6Ó*RÑ'ˆŒ˜œð ‡‡€Ø Ÿ/™/×0Ñ0°Ó5ˆŒØ€MøôC ô Ø‹ðûô: ô ØˆŽðús%   ÃAJ' ÉJ; Ê'J8Ê7J8Ê;KËKc               ó    € V ^8„  d   QhRRRR/# )r   r¾   r   r   z*tuple[Optional[str], list, Optional[dict]]r   )r   s   "r   r   r   µ  s   € ÷ &+ñ &+¨Mð &+Ð>hñ &+r   c                ó2  € V'       g   R. R3# V f   \        RV R24      hV P                  V4      ;'       g    TpV P                  V4      pV'       g   \        RV 24      h^ RIHp V! W4      ;pe   \        RV RV 24      hV P                  VRR7       V P                  V4      w  rgV Uu. uF  qˆP                  R	4      R
8w  g   K  VNK  	  p	p V P                  V4       W)V3# u upi   \         d    \        P                  ! RTRR7        L/i ; i)u¯  Resolve ``resume`` to ``(session_id, conversation_history, session_meta)`` for a oneshot turn.

Follows the same contract as the interactive CLI resume: compression-chain redirect via
``resolve_resume_session_id``, safe-resume guard, model-projection history with
``session_meta`` rows dropped. An unknown session raises (the user passed an explicit id;
silently starting a fresh session is the resume-dropped failure mode this exists to fix â€”
see #105892). An empty stored transcript still returns the resolved id: the turn replays
nothing but is recorded under the requested session â€” ``hermes -z "hello" -c <title>
--create-if-missing`` must fill the titled session it created, not mint a fresh id
(same contract as the interactive /resume of an empty session).

The resolved row is also reopened (best effort): the previous run stamped ``ended_at``,
the existing-row upsert never clears the end fields, and ``end_session()`` only writes
rows whose ``ended_at`` is null â€” so without this step the resumed turn would be recorded
under a session that stays closed and its new lifecycle boundary would be lost (same
reason the interactive resume calls ``reopen_session()`` before continuing).
Nzcannot resume session z: session store unavailablezsession not found: )Úkanban_resume_refusalz: T)Útip_onlyÚroleÚsession_metaz5reopen_session failed for resumed one-shot session %sr   )ÚRuntimeErrorÚresolve_resume_session_idÚget_sessionÚhermes_cli.kanban_resume_guardr  Úassert_resume_safeÚget_resume_conversationsr*   Úreopen_sessionr   r   r   )
r   r¾   Úresolvedr  r  Úkanban_refusalÚrestoredÚ_displayÚmÚhistorys
   &&        r   Ú_load_resume_targetr&  µ  s2  € ÷$ Ø�R˜ˆ~ÐØÒÜÐ3°F°8Ð;VÐWÓXÐXØ×3Ñ3°FÓ;×EÐE¸v€HØ×)Ñ)¨(Ó3€LßÜÐ0°°Ð9Ó:Ð:õ EÙ/°
ÓEÐEˆÒRÜÐ3°F°8¸2¸nÐ=MÐNÓOÐOØ×!Ñ! (°TÐ!Ô:Ø#×<Ñ<¸XÓFÑ€HÙ"ÓF™(�Q§e¡e¨F£m°~Ñ&E�qˆq™(€GÐFðhØ×!Ñ! (Ô+ð ˜lÐ*Ð*ùò Gøô ô hÜ�ŠÐMÈxÐbf×gðhús   Â0C*ÃC*ÃC/ Ã/$DÄDc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r  ræ   r  zOptional[dict]r  r°   r   r   )r   s   "r   r   r   Þ  s,   € ÷ ñ ØðØ(6ðØKOðàñr   c               óê   € V'       d   V # ^ RI Hp V! WP                  V P                  R7      pVf   V # Vw  V n        rVrxV'       d   WPn        W`n        RV n        V'       d   \        V4      V n        V # )u¤  Run a resumed one-shot on the session's stored runtime, not the ambient config â€” the same
contract as the interactive ``_restore_session_model``, via the shared ``stored_session_route``.
An explicit ``--model`` keeps the ambient choice. A changed provider drops the resolved
``api_key``: it belongs to the ambient endpoint and is never persisted, so runtime resolution
re-fetches credentials for the restored provider.)Ústored_session_route)Úcurrent_modelrÿ   N)Ú!hermes_cli.cli_model_switch_mixinr)  r»   r¼   rç   rè   r_   ré   )	r  r  r  r)  r  Ústored_providerÚstored_base_urlÚstored_api_modeÚprovider_changeds	   &&$      r   Ú_apply_stored_session_runtimer0  Þ  sf   € ÷ ØˆÝFá  ¿\¹\Ð\b×\kÑ\kÔl€EØ‚}ØˆØX]ÑU€F„L�/°OßØ)ŒØ)ŒØˆŒßÜ˜oÓ.ˆŒØ€Mr   c               ó@   € V ^8„  d   QhRRRRRRRRRR	R
RRRRRRR	RR/
# )r   rº   r_   r»   r   r¼   rX   rY   rÇ   r°   rg   r¾   r¿   rÈ   r   ztuple[str, dict]r   )r   s   "r   r   r   ÷  sx   € ÷ p:ñ p:Øðp:àðp:ð ðp:ð ð	p:ð
 ðp:ð ðp:ð ðp:ð ðp:ð ðp:ð ñp:r   c	                óœ  € ^ RI Hp	 ^ RIHp
 ^ RIHp ^ RIHp V	! 4       p\        WÑV4      p\        4       p\        Wö4      w  ppp\        TT\        T;'       g    RP                  4       4      R7      pT
! TVP                  VP                  ;'       g    RVP                   VP"                  R7      w  ppVe1   \$        P&                  ! VVR	,          VP)                  R
4      RR7      pVP*                  '       d   VP*                  VR&   ^ RIHpHp V! WÞP                  4      pVeF   \3        V4      P                  4       '       d'   V! V4      pVf   \4        P6                  ! RV4       MTp\9        V4      pVf   V'       d   \;        V! VR4      4      p^ RIHp V! \4        P@                  ! \B        4      RR7       \E        V4      pR;pp T! R$/ RVP)                  R4      bRVP)                  R4      bR
VP)                  R
4      bRVP)                  R4      bRVP)                  R4      bR	VP                  bRVbRRbRRbRVbRVbRVP)                  R4      bR\G        V4      ;'       g    RbRVP)                  R4      bRVbRVbR \H        b pRVn%        RVn&        RVn'        V'       d   \Q        VV4      M/ p\S        VRR4      pTPU                  T T;'       g    RR!7      pV'       d$   \W        TTTVPX                  ;'       g    TR"7       VP)                  R#4      ;'       g    RV3\[        VVV4       #   \[        TTT4       i ; i)%a
  Build an AIAgent exactly like a normal CLI chat turn, run one conversation, and return
``(final_response, run_result)``. Imports are local to keep CLI startup cheap. *ledger* (set when
``--usage-file`` is requested) attaches this run's auxiliary usage to the result.)Úload_config)Úresolve_runtime_with_fallback)Ú_get_platform_tools)ÚAIAgentrS   )r  N)Ú	requestedÚtarget_modelÚexplicit_base_urlÚexplicit_api_keyr»   r¼   )r»   r¼   ré   ré   )Úparse_reasoning_effortÚresolve_reasoning_configz6Unknown --reasoning '%s', keeping the configured levelÚcli)Ú'ensure_mcp_discovery_before_agent_buildT)ÚloggerÚsingle_queryrè   rç   Úrequested_providerÚenabled_toolsetsÚ
quiet_modeÚplatformr   r   Úcredential_poolÚfallback_modelÚrequest_overridesÚephemeral_system_promptÚreasoning_configÚclarify_callback)Úconversation_history)r$   Úfinal_responser   ).r   r3  Úhermes_cli.runtime_providerr4  Úhermes_cli.tools_configr5  Ú	run_agentr6  r  rä   r&  r0  r°   rU   r¼   r»   rç   rè   ÚdataclassesÚreplacer*   ré   Úhermes_constantsr;  r<  r_   r   rs   re   ÚsortedÚhermes_cli.mcp_startupr>  Ú	getLoggerrê   ry   r	   Ú_oneshot_clarify_callbackÚsuppress_status_outputÚstream_delta_callbackÚtool_gen_callbackr   ÚgetattrÚrun_conversationr6   r   Ú_close_agent) rº   r»   r¼   rX   rÇ   rg   r¾   r¿   rÈ   r3  r4  r5  r6  rƒ   r  r   Ú
resume_sidrK  Úresume_metaÚruntimeÚfallback_entryr;  r<  rI  Úparsed_reasoningÚtoolsets_listr>  rv   ÚagentÚrelay_session_idÚ
aux_beforer!   s    &&&&&&&&&                       r   rÒ   rÒ   ÷  sN  € õ .ÝIÝ;Ý!á
‹-€CÜ(¨°XÓ>€Fô 0Ó1€JÜ4GÈ
Ó4[Ñ1€JÐ$ kÜ*¨6°;ÌtÐUZ×U`ÐU`Ð^`×TgÑTgÓTiÓOjÔk€Fñ <ØØ—/‘/Ø—\‘\×)Ð) TØ Ÿ/™/ØŸ™ôÑ€Gˆ^ð Ò!ä×$Ò$ V°>À'Õ3JÐU\×U`ÑU`ÐakÓUlØ.2ô4ˆà‡‡€Ø$Ÿo™oˆ�
ÑçQá/°·\±\ÓBÐØÒ¤ Y£×!5Ñ!5×!7Ò!7Ù1°)Ó<ÐØÒ#Ü�OŠOÐTÐV_Õ`à/Ðô (¨Ó1€MØÒ×!4ÜÑ2°3¸Ó>Ó?ˆõ Oá+´7×3DÒ3DÄXÓ3NÐ]aÕbä2°6Ó:€Mð  $Ð#€EÐð':Ùò 
Ø—K‘K 	Ô*ð
à—[‘[ Ô,ð
ð —[‘[ Ô,ð
ð  'Ÿ{™{Ð+?Ô@ð	
ð
 —[‘[ Ô,ð
ð —,’,ð
ñ +ð
ñ ð
ñ ð
ñ "ð
ñ "ð
ð $ŸK™KÐ(9Ô:ð
ô .¨cÓ2×:Ð:°døð
ð &Ÿk™kÐ*=Ô>ð
ñ  %2ð!
ñ" .ð#
õ* 7ð+
ˆð0 (,ˆÔ$Ø&*ˆÔ#Ø"&ˆÔçAGÔ% j°*Ô=ÈRˆ
ô # 5¨,¸Ó=ÐØ×'Ñ'¨ÐEY×EaÐEaÐ]aÐ'ÓbˆßÜ# F¨J¸
Ø8=×8HÑ8H×8VÐ8VÈJõXà—
‘
Ð+Ó,×2Ð2°°FÐ;ä�U˜JÐ(8Õ9øŒ�U˜JÐ(8Õ9ús2   ÇBL< É.A L< Ê//L< ËL< Ë/L< Ì
L< Ì*L< Ì<Mc               ó    € V ^8„  d   QhRRRR/# )r   Úwhatr_   r   r%   r   )r   s   "r   r   r   j  s   € ÷ @ñ @�3ð @˜tñ @r   c                ól   €  V! 4        R#   \          d    \        P                  ! RT RR7        R# i ; i)z7Run a cleanup step, logging (never raising) on failure.zoneshot %s failedTr   N)r   r   r   )rg  Úfns   &&r   Ú_quietlyrj  j  s2   € ð@Ù
ŽøÜô @Ü�ŠÐ)¨4¸$×?Ð?ð@ús   ‚ ‹$3²3c               ó   € V ^8„  d   QhRR/# ©r   r   r%   r   )r   s   "r   r   r   r  s   € ÷ 8ñ 8¨Dñ 8r   c                 ó4   € ^ RI Hp  V P                  R4       R# )r;   ©Úprocess_registryN)Útools.process_registryro  Úwait_for_pending_completionsrn  s    r   Ú"_linger_for_background_completionsrr  r  s   € õ
 8à×1Ñ1°$Ö7r   c               ó   € V ^8„  d   QhRR/# rl  r   )r   s   "r   r   r   |  s   € ÷ Fñ F¸dñ Fr   c                ó6  a aaaa€ S ez   \        R\        4       S'       d   ^ RIHo \        RV VV3R l4       \	        S RR4      p\        V\        4      '       d   V3MRo\        RV V3R l4       \        R	V 3R
 l4       Se   \        RV3R l4       R# R# )zŸTeardown mirroring gateway/run.py:_cleanup_agent_resources (NOT cli.py:_run_cleanup):
oneshot has no _active_agent_ref and the hard-exit path skips finalizers.Nzbackground completion wait)Úfinalize_sessionzsession finalizec                 óD   <€ S! S\        S R R4      ;'       g    RRR7      # )rD  Nr=  Úshutdown)r   rD  Úreason)rZ  )rc  ru  rd  s   €€€r   Ú<lambda>Ú_close_agent.<locals>.<lambda>‰  s&   ø€ Ñ1AØ+´g¸eÀZÐQUÓ6V×6_Ð6_ÐZ_Ø!õ2#r   Ú_session_messageszmemory/context cleanupc                 ó$   <€ S P                   ! S!  # r�   )Úshutdown_memory_provider)rc  Úmemory_argss   €€r   ry  rz  Ž  s   ø€ °5×3QÒ3QÐS^Ò3_r   zagent cleanupc                 ó$   <€ S P                  4       # r�   ©Úclose)rc  s   €r   ry  rz  �  s   ø€ ¨%¯+©+¬-r   zsession store cleanupc                 ó$   <€ S P                  4       # r�   r€  )r   s   €r   ry  rz  ’  s   ø€ °*×2BÑ2BÔ2Dr   r   )rj  rr  Úhermes_cli.lifecycleru  rZ  r\   r]   )rc  r   rd  Úsession_messagesru  r~  s   fff @@r   r\  r\  |  sŠ   ü€ ð Òô 	Ð-Ô/QÔRßõ >äÐ'ö *#ô $ô # 5Ð*=¸tÓDÐÜ-7Ð8HÌ$×-OÒ-OÐ'Ñ)ÐUWˆÜÐ)Õ+_Ô`Ü�Ô"7Ô8àÒÜÐ(Ô*DÖEñ r   c               ó    € V ^8„  d   QhRRRR/# )r   Ú	questionsr]   r   r"   r   )r   s   "r   r   r   •  s   € ÷ Jñ J¨ð J°$ñ Jr   c                ó   € R/ RRRR/# )uU   Clarify is disabled in oneshot mode â€” tell the agent to pick a default and proceed.ÚanswersÚoutcomeÚundeliveredÚnoticez�oneshot mode: no user available. Pick the best choices using your own judgment, or make the most reasonable assumption you can, and continue.r   )r†  s   &r   rV  rV  •  s   € à�r˜9 m°Xð	HðJð Jr   )rD   Úcost_statusÚcost_sourcer@   rA   Úcache_read_tokensÚcache_write_tokensÚreasoning_tokensrB   rE   r»   r¼   r   rR   rQ   rO   Úturn_exit_reason)rE   r@   rA   rŽ  r�  r�  rD   r�   )NNNNNNN)NNNTNNNF).Ú__doc__Ú
__future__r   rµ   r   rÌ   r•   Ú
contextlibr   r   rP  r   Úpathlibr   Útypingr   Úgateway.session_contextr   Úhermes_cli.fallback_configr	   r‘   r¯   r,   r   r6   rJ   rT   rV   re   rj   ry   r‰   r£   r¸   rà   rä   ræ   rö   r  r&  r0  rÒ   rj  rr  r\  rV  r   r   r   Ú<module>r™     sÝ   ðñõ #ã Û Û 	Û 
ß 7Û Ý !Ý Ý å =Ý 9à˜�€ð€ð€õ÷(õ&
ð Ð õ÷$N÷B÷
!õ(÷(0÷f÷.hòVð ÷ ð  ó ð õõ7õt&+õR÷2p:õf@õ8÷F÷2Jr   