+
    jHàj•2  ã                   óÄ   a € R t0 t R t^ RIHt ^ RIHt ^ RIHt RtRt	]! RRR7      t
] ^ k R tR	 t]R
 4       tR tR tR tRtR tR tRRRRRR/R ltR tR tR tR# )ag  Per-admission turn inputs the classic CLI sends with ``prompt.submit`` (CALLMAP W2).

Main's HermesCLI calls ``AIAgent.run_conversation`` with an API-only message (voice prefix,
model-switch / skills-reload notes) while persisting the clean text, names the turn's author for
memory attribution, and runs ``/model --once`` and ``/moa`` as a one-turn runtime swap. Over the
session authority those are facts about ONE admitted turn, committed with the admission row as
``cli_turn_v1`` so a retry or a queued drain runs exactly what was admitted, and bound for that
admission's execution only, never for a later turn.
)Úcontextmanager)Ú
ContextVar)ÚRuntimeStoreErrori@B Úcli_turnN)Údefaultc                óV   € \          Uu/ uF  qV 9   g   K  WV,          bK  	  up# u upi )zSThe raw per-turn CLI fields of a ``prompt.submit`` request, forwarded to admission.)Ú_SUBMIT_FIELDS)ÚparamsÚkeys   & Ú=/home/ubuntu/.hermes/hermes-agent/gateway/session_cli_turn.pyÚsubmit_cli_turn_fieldsr      s(   € å(6ÓH© À¹-ÔˆC˜•Ò©ÑHÐHùÒHs   ‰&–&c                óT  € / pV P                  R4      e)   ^ RIHp V! V R,          4      pVf   \        R4      hW1R&   V P                  R4      pVeB   \	        V\
        4      '       d   \        V4      \        8”  d   \        R4      hV'       d   WAR&   V P                  R4      pVEe3   ^ RIH	p \	        V\        4      '       d¸   \        V4      0 Rm,
          '       gž   \	        VP                  R4      \
        4      '       dy   VR,          P                  4       '       d\   \	        VP                  RR
4      \
        4      '       d6   R	V9   d:   \	        VR	,          \
        4      '       d   V! VR	,          4      f   \        R4      hRVR,          P                  4       /VP                  R4      '       d   RVR,          /M/ CR	V9   d   R	VR	,          /M/ CVR&   V P                  R4      pVe   \        V4      \        Jd   \        R4      hV'       d   RVR&   V'       d   RV/# / # )z\Wire fields -> committed ``cli_turn_v1`` (``{}`` when absent); malformed values are refused.Úturn_author)Úparse_turn_authorÚinvalid_paramsÚapi_textÚmodel_override©Úparse_reasoning_effortÚmodelÚproviderÚ	reasoningÚ Úclarify_batchTÚcli_turn_v1>   r   r   r   )ÚgetÚagent.turn_authorr   r   Ú
isinstanceÚstrÚlenÚ_API_TEXT_LIMITÚhermes_constantsr   ÚdictÚsetÚstripÚtypeÚbool)r	   Ú	committedr   Úauthorr   Úoverrider   Úbatchs   &       r   Úadmit_cli_turnr+      sæ  € à€IØ‡z�z�-Ó Ò,Ý7Ù" 6¨-Õ#8Ó9ˆØŠ>Ü#Ð$4Ó5Ð5Ø#)�-Ñ Ø�z‰z˜*Ó%€HØÒÜ˜(¤C×(Ò(¬C°«M¼OÔ,KÜ#Ð$4Ó5Ð5ßØ$,�jÑ!Ø�z‰zÐ*Ó+€HØÓÝ;Ü˜8¤T×*Ò*¬c°(«mÒ>`×.`Ô.`Ü! (§,¡,¨wÓ"7¼×=Ò=ÀXÈgÕEV×E\ÑE\×E^ÒE^Ü! (§,¡,¨z¸2Ó">Ä×DÒDØ 8Ô+´ZÀÈÕ@UÔWZ×5[Ò5[Ù4JÈ8ÐT_ÕK`Ó4aÒ4iÜ#Ð$4Ó5Ð5ð (/°¸Õ0A×0GÑ0GÓ0Ið 'tØPX×P\ÑP\Ð]g×PhÒPh¨:°xÀ
Õ7KÑ*LÐnpð'tàR]ÐaiÔRi¨;¸ÀÕ8MÑ*NÐoqð'tˆ	Ð"Ñ#ð �J‰J�Ó'€EØÒœT %›[´Ó4ÜÐ 0Ó1Ð1ßð &*ˆ	�/Ñ"ß)2ˆM˜9Ð%Ð:¸Ð:ó    c              #   ó¶   "  € \         P                  V'       d   W3MR 4      p R x € \         P                  V4       R #   \         P                  T4       i ; i5i)N)Ú	_cli_turnr#   Úreset)Úadmission_idr'   Útokens   && r   Úcli_turn_scoper2   A   s:   é € ä�M‰M·y˜<Ñ3ÀdÓK€EðÛä�‰˜ÖøŒ	�‰˜Õüs   ‚!A¤? ¨A¿AÁAc                ó~   € \         P                  4       pVe   V e   \        V 4      V^ ,          8w  d   / # V^,          # )z¨The committed CLI turn fields of the admission whose event id is ``message_id``; ``{}`` for
any other turn, so a follow-up drained on the same task never inherits them.)r.   r   r   )Ú
message_idÚbounds   & r   r   r   J   s6   € ô �M‰M‹O€EØ‚}˜
Ò*¬c°*«oÀÀqÅÔ.IØˆ	Ø��8€Or,   c                óÎ   € \         P                  4       pVeM   V eG   \        V 4      V^ ,          8X  d.   \         P                  V^ ,          / V^,          CRV/C34       R# R# R# R# )zçThis admission's ``api_text`` with its ``@`` references expanded, for the rest of this execution
(``session_context_refs.turn_references``). The committed row keeps what the CLI sent, so a retry
expands it afresh rather than twice.Nr   )r.   r   r   r#   )r4   Útextr5   s   && r   Úrebind_api_textr8   S   s\   € ô �M‰M‹O€EØÒ˜ZÒ3¼¸J»È5ÐQRÍ8Ô8SÜ�‰�u˜Q•xÐ!? E¨!¥HÐ!?¨j¸$Ñ!?Ð@ÖAñ 9TÑ3Ñr,   c                óÖ  € ^ RI Hp ^ RIHp T! V R,          VP	                  R4      ;'       g    RT;'       g    RVP	                  R4      ;'       g    RVP	                  R4      ;'       g    RRV P	                  RR4      T;'       g    / P	                  R	4      T! T;'       g    / 4      R
7	      pVP
                  '       g,   \        VP                  ;'       g    RV R,          : R24      h\        V4      pVP	                  R4      ;'       g    RpVP                  ;'       g    RP                  4       P                  4       VP                  4       P                  4       8H  p	V	'       dÍ   VP                  '       g»   ^ RIHp
 ^ RIHpHp V
! VP                  VP"                  4      e"   VP$                  '       d   VP$                  VR&   VP	                  R4      ;'       g    RpW×R&   VP	                  R4      '       d6   V! VP                  4      '       d   V! VP                  W×R,          4      VR&   M{TP'                  RR. VP(                  VP*                  VP$                  ;'       g    R\        VP,                  ;'       g    / 4      \        VP.                  ;'       g    / 4      R7       VP'                  VP                  VP                  R7       VP"                  V3# )aÐ  ``(model, runtime_kwargs)`` of a committed ``model_override`` for this one turn, resolved by the
same ``switch_model`` pipeline ``/model`` uses against the session's current route. Nothing is
written: the session's route, policy and cached agent are untouched, so the next turn runs its own
route again (main's ``/model --once`` restore). Raises ``RuntimeError`` with the switch's own
sentence when the target cannot be resolved; the caller fails the turn with it.)Úget_compatible_custom_providers)Úswitch_modelr   r   r   Úbase_urlÚapi_keyFÚ	providers)	Ú	raw_inputÚcurrent_providerÚcurrent_modelÚcurrent_base_urlÚcurrent_api_keyÚ	is_globalÚexplicit_providerÚuser_providersÚcustom_providerszmodel z could not be resolved)Úmodel_derived_api_mode)Únormalize_opencode_base_urlÚopencode_provider_familyNÚapi_mode)Úcredential_poolÚcommandÚargsr=   r<   rK   Úrequest_overridesÚcapabilities)r   Úrequested_provider)Úhermes_cli.configr:   Úhermes_cli.model_switchr;   r   ÚsuccessÚRuntimeErrorÚerror_messager"   Útarget_providerr$   ÚlowerÚalias_endpoint_appliedrH   Úhermes_cli.modelsrI   rJ   Ú	new_modelrK   Úupdater=   r<   rO   Úruntime_capabilities)r)   r   Úruntime_kwargsÚconfigr:   r;   ÚresultÚruntimer@   Úsame_providerrH   rI   rJ   rK   s   &&&&          r   Úone_turn_runtimerc   \   sm  € õ BÝ4ÙØ˜7Õ#°n×6HÑ6HÈÓ6T×6ZÐ6ZÐXZØ—k�k˜r°N×4FÑ4FÀzÓ4R×4XÐ4XÐVXØ&×*Ñ*¨9Ó5×;Ð;¸ÀuØ"Ÿ,™, z°2Ó6ÈÏÈÐRT×GYÑGYÐZeÓGfÙ8¸¿¸À2ÓFôH€Fð �>�>ˆ>Ü˜6×/Ñ/×gÐg°V¸HÀWÕ<MÑ;PÐPfÐ3gÓhÐhÜ�>Ó"€GØ%×)Ñ)¨*Ó5×;Ð;¸ÐØ×+Ñ+×1Ð1¨r×8Ñ8Ó:×@Ñ@ÓBÐFV×F\ÑF\ÓF^×FdÑFdÓFfÑf€M÷ ˜V×:×:Ð:õ 	Cß[Ù! &×"8Ñ"8¸&×:JÑ:JÓKÒWÐ\b×\k×\kÐ\kØ"(§/¡/ˆG�JÑØ—;‘;˜zÓ*×2Ð2¨dˆØ&�
ÑØ�;‰;�z×"Ò"Ñ'?À×@VÑ@V×'WÒ'WÙ"=¸f×>TÑ>TÐV^ÐhrÕ`sÓ"tˆG�JÑøð 	�‰ t°TÀØ%Ÿ~™~¸¿¹ÐRX×RaÑRa×RiÐRiÐeiÜ)-¨f×.FÑ.F×.LÐ.LÈ"Ó)MÜ$(¨×)DÑ)D×)JÐ)JÈÓ$Kð 	ô 	Mð ‡N�N˜F×2Ñ2Àv×G]ÑG]€NÔ^Ø×Ñ˜WÐ$Ð$r,   c                óä   € ^ RI Hp V! V 4      '       g   R# ^ RIHp  V! V P                  V P
                  P                  4      pTRJ;'       d    TP                  R8H  #   \         d     R# i ; i)z¯A local-viewer turn on a classic-CLI surface session (``cli`` / ``oneshot`` / ``tool``): the
viewer is main's HermesCLI, which reads the run_conversation-shaped result itself.©Úlocal_viewer_turnF)Úpolicy_for_sourceNÚcli)	Úgateway.run_turn_progressrf   Úgateway.session_policyrg   Ú_runnerÚ_ctxÚsourcer   Úplatform)Úturnrf   rg   Úpolicys   &   r   Úclassic_cli_turnrq   ’   si   € õ <Ù˜T×"Ò"ÙÝ8ðÙ" 4§<¡<°·±×1AÑ1AÓBˆð ˜Ð×:Ð: &§/¡/°UÑ":Ð:øô ô Úðús   ž'A  Á A/Á.A/c           	     óž   € ^ RI Hp V! V 4      ;'       d9    \        \        \	        V P
                  RR4      4      P                  R4      4      # )a�  The clarify tool's batch goes to main's batch panel as one request: a local-viewer turn whose
submitter declared it answers the whole set (``clarify_batch`` committed with its admission).
Main's classic CLI, Ink TUI and Desktop all showed every question at once (TUI-18); a viewer that
never asks (an ACP editor, a raw WebSocket client) keeps one ``clarify.request`` card per question.re   Úinbound_message_idNr   )ri   rf   r&   r   Úgetattrrl   r   )ro   rf   s   & r   Úclarify_batch_turnru       sJ   € õ
 <Ù˜TÓ"÷ Wð W¤tÜ”˜Ÿ™Ð$8¸$Ó?Ó@×DÑDÀ_ÓUó(Wð Wr,   Ú
aux_beforeÚ
session_dbÚ
session_idc               ó´  € \        V \        4      '       g   / # \         Uu/ uF  qDV 9   g   K  W@P                  V4      bK  	  ppV P                  R4      ;'       g    RVR&   V P	                  RR4      pT;'       g    RVR&   VeL   ^ RIHp RV P                  R4      ;'       g    T/pV! W‚WR7       VP                  R4      ;'       g    / VR&   V# u upi )	a¶  The receipt-only fields of a classic CLI turn, taken from the agent's raw result.

``pending_steer`` is REMOVED from ``result``: main's CLI queues a leftover /steer as its own
next turn (``delivering leftover steer``), so the gateway must not also run it as a follow-up
inside this admission. ``final_response`` is the agent's raw text: main renders its own
``chat_error_copy`` for an empty failed turn instead of the gateway's chat copy.Úfinal_responser   Úpending_steerN)Ú_attach_auxiliary_usagerx   )Úfallback_session_idÚauxiliary_usage)r   r"   Ú_RESULT_PASSTHROUGHr   ÚpopÚhermes_cli.oneshotr|   )	r`   rv   rw   rx   r
   ÚfieldsÚsteerr|   Úholders	   &$$$     r   Útake_cli_result_fieldsr…   ª   sÑ   € ô �fœd×#Ò#Øˆ	Ý.AÓSÑ.A sÈFÁ]Ô"ˆc—:‘:˜c“?Ò"Ñ.A€FÐSØ%Ÿz™zÐ*:Ó;×AÐA¸r€FÐÑØ�J‰J�¨Ó-€EØ#Ÿm˜m t€Fˆ?ÑØÒÝ>Ø §
¡
¨<Ó 8× FÐ F¸JÐGˆÙ °JÕ_Ø$*§J¡JÐ/@Ó$A×$GÐ$GÀRˆÐ Ñ!Ø€Mùò Ts
   ¡C®Cc                ó  € \        V P                  P                  4      P                  R4      pV'       g   W#3# ^ RIHp V'       d"   VP                  V! V P                  4      4      MV P                  P                  p\        WBW64      # )zcThe executing admission's ``model_override`` applied to the resolved route (unchanged without one).r   )Úactive_authority)
r   rl   rs   r   Úgateway.session_authoritiesr‡   r_   rk   Úuser_configrc   )ro   rp   r   r^   r)   r‡   r_   s   &&&&   r   Úone_turn_routerŠ   ¿   sd   € ä˜Ÿ	™	×4Ñ4Ó5×9Ñ9Ð:JÓK€HßØÐ$Ð$Ý<ß>DˆV�]‰]Ñ+¨D¯L©LÓ9Ô:È$Ï)É)×J_ÑJ_€FÜ˜H¨^ÓDÐDr,   c                óÂ   € \        V P                  P                  4      P                  R4      ;'       g    / pRV9  d   V# ^ RIHp V! VR,          4      ;'       g    T# )z{The executing admission's one-turn reasoning level (``model_override.reasoning``), else
*reasoning_config* (the session's).r   r   r   )r   rl   rs   r   r!   r   )ro   Úreasoning_configr)   r   s   &&  r   Úone_turn_reasoningr�   É   sV   € ô ˜Ÿ	™	×4Ñ4Ó5×9Ñ9Ð:JÓK×QÐQÈr€HØ˜(Ô"ØÐÝ7Ù! (¨;Õ"7Ó8×LÐLÐ<LÐLr,   c                óB  € \        V 4      '       g   V! 4       # ^ RIHp R;r4V! 4       RJ dF   ^ RIHp V P
                  P                  p\        VRV4      pV! W@P                  P                  4      pV! 4       p\        WsW@P                  P                  R7      V n        V# )z±``run()`` (the turn's run_conversation) for any turn; on a classic CLI turn the receipt-only
fields are taken from its raw result and kept on ``turn`` for the committed receipt.)Úfinite_turn_requiredNT)Ú_auxiliary_usageÚ_db)rv   rw   rx   )rq   Úgateway.session_finiter�   r�   r�   rk   Ú_session_dbrt   rl   rx   r…   Ú_cli_result_fields)ro   Úrunr�   rv   Úcli_dbr�   Ú	runner_dbr`   s   &&      r   Úrun_classic_cli_turnr˜   Ó   s‰   € ô ˜D×!Ò!Ù‹uˆÝ;ØÐ€JÙÓ Ó%å7Ø—L‘L×,Ñ,ˆ	Ü˜ E¨9Ó5ˆÙ% f¯i©i×.BÑ.BÓCˆ
Ù‹U€FÜ4Ø°&ÇYÁY×EYÑEYô[€DÔà€Mr,   c                ód   € V ^8„  d   Qh/ ^ \         9   d   \        \        R,          ,          ;R&   # )é   Nr.   )Ú__conditional_annotations__r   Útuple)Úformats   "r   Ú__annotate__rž      s(   € ÷ ñ ÷  KÒ JŒ:”e˜d•lÕ#Ñ Jò!r,   )r   r   r   r   )Úpre_transform_responseÚbilling_blockÚlast_reasoningÚresponse_previewedÚresponse_transformedÚturn_exit_reason)r›   Ú__doc__Ú
contextlibr   Úcontextvarsr   Úhermes_state_runtimer   r   r    r.   r   r+   r2   r   r8   rc   r   rq   ru   r…   rŠ   r�   r˜   rž   )r›   s   @r   Ú<module>r©      s    øðöõ &Ý "å 2àO€Ø€Ù&0°ÀTÔ&J€	Ó JòIò
%;ðP ñó ðòòBò,%ðdCÐ ò;òWð°ð À$ð ÐSWô ò*EòMôr,   