+
    „WÝj|}  ã                  óf  € R t ^ RIHt ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHt ]P$                  ! R	4      t]'       d   ^ R
IHt R R ltR R ltR$R R lltR R ltR R lt^ RIHt ^ RIHt RRRR/R R llt R%R lt!R t"R t#R t$R  R! lt%R&R" R# llt&R# )'ak  Single-query (``-q`` / one-shot) helpers: kanban goal loops, exit-code mapping, quiet single-query runner, image routing, signal handlers and the single-query mode orchestrator.

Split out of ``cli.py``; ``cli`` re-exports every public name and moved bodies late-bind
cli-level names through ``from cli import ...`` at call time so facade monkeypatch seams hold.
)Úannotations)ÚTYPE_CHECKINGN)Út)Úrequest_hard_interrupt)Úsuppress)ÚPath)ÚAnyÚcli)Ú	HermesCLIc               ó    € V ^8„  d   QhRRRR/# )é   ÚdefaultÚintÚreturn© )Úformats   "ÚOC:\Users\johnn\AppData\Local\hermes\hermes-agent\hermes_cli\cli_single_query.pyÚ__annotate__r      s   € ÷ ñ ˜Cð  Cñ ó    c                óL   €  \        V 4      #   \        \        3 d    Tu # i ; i)z6``int(value)``, or ``default`` when it does not parse.)r   Ú	TypeErrorÚ
ValueError)Úvaluer   s   &&r   Ú_int_orr      s*   € ðÜ�5‹zÐøÜ”zÐ"ô ØŠðús   ‚
 �#¢#c               ó   € V ^8„  d   QhRR/# ©r   r   ÚNoner   )r   s   "r   r   r   $   s   € ÷ ñ °$ñ r   c                ó²   € ^ RI Hp  V e:   \        V RV 24       V! RR4      pV^ 8”  d   \        P                  ! V4       R# R# R#   \
         d     R# i ; i)zëHard-interrupt ``agent`` for a shutdown signal, then sleep ``HERMES_SIGTERM_GRACE`` (1.5 s).

The grace lets the agent thread kill the tool's setsid subprocess group before the
main thread unwinds (else an orphan child). Never raises.
)Ú
_float_envNzreceived signal ÚHERMES_SIGTERM_GRACEg      ø?)r	   r   r   ÚtimeÚsleepÚ	Exception)ÚagentÚsignumr   Ú_graces   &&  r   Ú_interrupt_agent_for_signalr&   $   sb   € õ ðØÒÜ" 5Ð,<¸V¸HÐ*EÔFÙÐ 6¸Ó<ˆFØ˜ŒzÜ—
’
˜6Ö"ñ ñ øô
 ô Úðús   ˆ9A ÁAÁAc               ó$   € V ^8„  d   QhRRRRRR/# ©r   r	   r
   Úfirst_responseÚstrr   r   r   )r   s   "r   r   r   5   s"   € ÷ 9ñ 9 ð 9¸Cð 9Ð]añ 9r   c                ó¢  a aaaaa€ ^ RI HpHo \        P                  P                  R4      ;'       g    RP                  4       oS'       g   R# \        P                  P                  R4      ;'       g    RP                  4       pV'       d
   V! VR4      MRoV'       d   Sf   \        P                  RV4       ^ RI	H
o ^ RI	Ho ^ R	IHpHp SP                  4       ;_uu_ 4       pSP!                  VS4      p	RRR4       X	f   R# R
P#                  R V	P$                  ;'       g    RV	P&                  3 4       4      P                  4       p
V
'       g   R# R VV 3R llpR VVVV3R llpR VVVV3R llpT! SY¢;'       g    TYÍV	P(                  ;'       g    TT;'       g    RT;'       g    R R7       R#   + '       g   i     LË; i)aq  Drive a kanban goal_mode worker through ``goals.run_kanban_goal_loop`` after its first turn.

``run_turn`` defaults to the bare ``-Q`` turn (final answer only). The ``-q`` worker path
passes ``cli.chat`` so every follow-up turn keeps the tool activity feed that the Kanban
worker log is made of. The caller swallows all errors: a broken loop must never wedge a worker.
)r   Ú_sync_cli_session_id_from_agentÚHERMES_KANBAN_TASKÚ NÚHERMES_KANBAN_RUN_IDzinvalid HERMES_KANBAN_RUN_ID=%r©Ú	kanban_db©Úkanban_db_connect)Úrun_kanban_goal_loopÚDEFAULT_MAX_TURNSz

c              3  ó8   "  € T F  q'       g   K  Vx € K  	  R # 5i©Nr   ©Ú.0Úps   & r   Ú	<genexpr>Ú*_run_kanban_goal_loop_q.<locals>.<genexpr>O   s   é € ÐJÑ'D !ËŸAšAÓ'Dùs   ‚	�
c               ó    € V ^8„  d   QhRRRR/# )r   Úpromptr*   r   Údictr   )r   s   "r   r   Ú-_run_kanban_goal_loop_q.<locals>.__annotate__S   s   € ÷ 
ñ 
˜Cð 
 Dñ 
r   c           	     ó²  <€ SP                   P                  V SP                  R 7      pS! S4       \        V\        4      '       d   VP                  RR4      M
\        V4      pV'       d   \        V4       RT;'       g    RR\        V\        4      '       d   VP                  RR4      MRR\        V\        4      '       d   VP                  R4      /# R/# ))Úuser_messageÚconversation_historyÚfinal_responser.   ÚresponseÚfailedFÚfailure_reasonN)r#   Úrun_conversationrC   Ú
isinstancer?   Úgetr*   Úprint)r>   ÚresultÚrespr,   r	   s   &  €€r   Ú_quiet_turnÚ,_run_kanban_goal_loop_q.<locals>._quiet_turnS   s¾   ø€ Ø—‘×+Ñ+¸ÐVY×VnÑVnÐ+ÓoˆÙ'¨Ô,Ü3=¸fÄd×3KÒ3Kˆv�z‰zÐ*¨BÔ/ÔQTÐU[ÓQ\ˆßÜ�$ŒKð ˜Ÿ
˜
 Ø´ZÀÌ×5MÒ5M�f—j‘j ¨5Ô1ÐSXØ¼jÈÔQU×>VÒ>V˜fŸj™jÐ)9Ó:ð
ð 	
ð ]að
ð 	
r   c               ó   € V ^8„  d   QhRR/# )r   r   z
str | Noner   )r   s   "r   r   r@   a   s   € ÷ Bñ B˜*ñ Br   c                 ó˜   <€ SP                  4       ;_uu_ 4       p SP                  V SS4      uuR R R 4       #   + '       g   i     R # ; ir7   )Úconnect_closingÚgoal_run_status)ÚcÚ_kbÚ_kbcÚtask_idÚworker_run_ids    €€€€r   Ú_task_statusÚ-_run_kanban_goal_loop_q.<locals>._task_statusa   s5   ø€ Ø×!Ñ!×#Ô# qØ×&Ñ& q¨'°=ÓA÷ $×#×#Ó#ús	   š8¸A		c               ó    € V ^8„  d   QhRRRR/# )r   Úreasonr*   r   r   r   )r   s   "r   r   r@   e   s   € ÷ Uñ U�sð U˜tñ Ur   c           	     óœ   <€ SP                  4       ;_uu_ 4       pSP                  VSV SR 7       RRR4       R#   + '       g   i     R# ; i))r\   Úexpected_run_idN)rR   Ú
block_task)r\   rT   rU   rV   rW   rX   s   & €€€€r   Ú_blockÚ'_run_kanban_goal_loop_q.<locals>._blocke   s7   ø€ Ø×!Ñ!×#Ô# qØ�N‰N˜1˜g¨fÀmˆNÔT÷ $×#×#Ò#ús	   š:ºA	c                ó.   € \         P                  R V 4      # )ú%s)ÚloggerÚinfo)Úms   &r   Ú<lambda>Ú)_run_kanban_goal_loop_q.<locals>.<lambda>m   s   € œfŸk™k¨$°Ô2r   )rW   Ú	goal_textÚrun_turnÚtask_status_fnÚblock_fnÚ	max_turnsr)   Úlog)r	   r   r,   ÚosÚenvironrJ   Ústriprd   ÚwarningÚ
hermes_clir1   r3   Úhermes_cli.goalsr4   r5   rR   Úget_taskÚjoinÚtitleÚbodyÚgoal_max_turns)r	   r)   rj   rn   r   Ú
raw_run_idÚ	_run_loopÚ
_DEF_TURNSÚconnÚtaskri   rN   rY   r`   rU   rV   r,   rW   rX   s   f&&&          @@@@@r   Ú_run_kanban_goal_loop_qr   5   s[  ý€ ÷ =Ü�z‰z�~‰~Ð2Ó3×9Ð9°r×@Ñ@ÓB€GßÙÜ—*‘*—.‘.Ð!7Ó8×>Ð>¸B×EÑEÓG€Jß1;‘G˜J¨Ô-À€Mß�mÒ+Ü�‰Ð8¸*ÔEå+Ý4ßcð 
×	Ñ	×	Ô	 4Ø�|‰|˜D 'Ó*ˆ÷ 
 à‚|Ùà—‘ÑJ¨¯
©
×(8Ð(8°b¸$¿)¹)Ñ'DÓJÓJ×PÑPÓR€IßÙ÷
ñ 
÷Bó B÷Uó Uñ Ø 9×7NÐ7NÀ;Ø#Ø×%Ñ%×3Ð3¨ÀN×DXÐDXÐVXØ×3Ð3Ñ2÷	÷? 
 ×	ús   Ã(F>Æ>G	c               ó$   € V ^8„  d   QhRRRRRR/# r(   r   )r   s   "r   r   r   q   s&   € ÷ 
añ 
a Ið 
a¸sð 
aÀtñ 
ar   c                ó@   a € ^ RI Hp R R lpV! S VV 3R lVR7       R# )a  ``-q`` worker variant: follow-up turns go through ``cli.chat`` (tool feed stays on stdout,
which is the Kanban worker log) and judge verdicts are printed there too, so a goal_mode card's
log reads like any other worker's instead of staying blank until the final answer.)r   c               ó    € V ^8„  d   QhRRRR/# )r   Úmsgr*   r   r   r   )r   s   "r   r   Ú0_run_kanban_goal_loop_chat.<locals>.__annotate__w   s   € ÷ ñ �#ð ˜$ñ r   c                óL   € \         P                  R V 4       \        V RR7       R# )rc   T)ÚflushN)rd   re   rK   ©rƒ   s   &r   Ú_logÚ(_run_kanban_goal_loop_chat.<locals>._logw   s   € Ü�‰�D˜#ÔÜˆc˜×r   c                ó:   <€ SP                  V 4      ;'       g    R # )r.   ©Úchat)r:   r	   s   &€r   rg   Ú,_run_kanban_goal_loop_chat.<locals>.<lambda>{   s   ø€ ÀCÇHÁHÈQÃK×DUÐDUÐSUÐDUr   )rj   rn   N)r	   r   )r	   r)   r   rˆ   s   f&  r   Ú_run_kanban_goal_loop_chatrŽ   q   s   ø€ õ ,õñ ˜C Ô:UÐ[_×`r   c               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   r   ~   s   € ÷ .ñ .¨Dñ .r   c                óÈ   € \        V P                  RR4      '       dE   V P                  P                  V P                  8w  d   V P                  P                  V n        R# R# R# )zUKeep ``cli.session_id`` in sync when mid-run compression rotated the agent's session.Ú
session_idN)Úgetattrr#   r‘   ©r	   s   &r   r,   r,   ~   sD   € äˆs�y‰y˜,¨×-Ò-°#·)±)×2FÑ2FÈ#Ï.É.Ô2XØŸ™×-Ñ-ˆŽñ 3YÑ-r   )ÚTRANSIENT_PROVIDER_REASONS)ÚTERMINAL_PROVIDER_REASONSÚcredentials_rate_limitedFÚcredentials_terminalc               ó$   € V ^8„  d   QhRRRRRR/# )r   r–   Úboolr—   r   r   r   )r   s   "r   r   r   ”   s#   € ÷  ñ  Àð  Ø26ð ØCFñ r   c          	     óZ   € ^ RI Hp ^ RI Hp ^ RIHp ^ RIHp V! W! 4       RJVVVVR7      # )u  Map a one-shot turn result onto a process exit code, for both `-q` and `-Q`.

0 only when the turn completed; 130 when it was interrupted; 1 when it failed, stopped
partway (`partial`, `completed: False`) or never ran at all (credentials / agent init
failed, so ``result`` is not a dict). A Kanban worker (``HERMES_KANBAN_TASK`` set) that
failed purely on a provider rate-limit / billing wall exits ``KANBAN_RATE_LIMIT_EXIT_CODE``
(EX_TEMPFAIL): the dispatcher books that run ``rate_limited`` and requeues the task
WITHOUT counting a failure, so a quota window or a provider outage cannot trip the breaker.
The same sentinel applies when credential resolution itself is a quota/rate-limit
AuthError (no turn result object is produced). One that failed on a terminal provider
error (credential revoked, model gone) exits ``KANBAN_TERMINAL_PROVIDER_EXIT_CODE``
(EX_CONFIG): the dispatcher blocks the card at once. The same code applies
before a turn when credential resolution explicitly requires re-authentication;
unknown startup failures retain exit 1.

The worker predicate is the STRIPPED ``kanban_task_id()`` (from
``agent.kanban_turn_recovery``) so a whitespace-only value is not a worker here
either â€” the exit mapping and the recovery gate must agree on what a worker is.
)Ú_TERMINAL_PROVIDER_REASONS)Ú_TRANSIENT_PROVIDER_REASONS)Úkanban_task_id)Úturn_exit_codeN)Úkanban_workerr–   r—   Útransient_reasonsÚterminal_reasons)r	   r›   rœ   Úagent.kanban_turn_recoveryr�   Úhermes_cli.turn_exitrž   )rL   r–   r—   r¡   r    r�   rž   s   &$$    r   Ú_single_query_exit_coder¤   ”   s7   € õ, CÝDÝ9Ý3ÙØ˜nÓ.°dÐ:Ø!9Ø1Ø+Ø)ôð r   c                óþ  a aaaaaaa€ ^ RI HpHpHoHo ^ RIHp ^ RIHp ^ RI	H
pHpHp	Hp
HpHo V! 4       pV! 4       oVe(   V! S P                   P"                  R4      '       d   RV/M/ oT! \%        S RR4      ;'       g    R	4      ;_uu_ 4         S P                   P"                  ! R'R
VRS P&                  /SB oS! S 4       ^ RIHp VVV V3R lpV! VV3R lR R7       R VVV3R llpV! S4       \9        S\:        4      '       dŸ   SP=                  R4      '       gˆ   SP=                  R4      ;'       g    S P&                  oVVV V3R lp T! \%        S RR4      ;'       g    RV\%        S RR4      V
! 4       R7      pRS n        \9        V\:        4      '       d   VoV! S4       \9        S\:        4      '       d   SP=                  R R4      M
\A        S4      pRRR4       Ve   M¤X'       gŠ   \9        S\:        4      '       dt   SP=                  R4      '       d]   SP=                  R4      '       g   SP=                  R!4      '       d/   \/        \C        R"SR,          R#7      \0        P2                  R7       MV'       d   \/        V4       S! S4      p\D        PF                  P=                  R$4      R%8X  d   V^ 8X  d    V! S X4       Vf)   \/        RS P,                   2\0        P2                  R7       Ve)   TP+                  SS P,                  ;'       g    RVR7      pV	! V4       R#   \(         du    T! S RR7       Te3   T	! TP+                  RRRR/S P,                  ;'       g    R^‚R7      4       \/        RS P,                   2\0        P2                  R7       T	! ^‚4        ELïi ; i  RS n        i ; i  + '       g   i     ELç; i  \H         d"   p\J        PM                  R&T4        Rp?EL+Rp?ii ; i)(a1  Quiet (-Q) one-shot turn: run, print the response (stderr for errors/session_id), then sys.exit with the automation exit code.
With a ``StreamJsonEmitter`` the final answer and the exit line become the terminal ``result`` JSONL record instead.
HERMES_TURN_AUTHOR (set only by a bot-to-bot dispatcher) is consumed here so tool subprocesses do not inherit it.
Nested Bot Mode notifies bind this session's key (not the dispatcher's) and resume in-process
before stdout is printed, so a teammate reply is the quiet run's final answer rather than a
stranded receipt.)Ú_emit_interrupted_session_endr   r¤   r,   )Ú_accepts_keyword)Útake_turn_author_from_env)Úbind_quiet_session_keyÚ!continue_quiet_notify_completionsÚexit_single_queryÚquiet_notify_linger_secondsÚtake_turn_report_pathÚwrite_turn_reportNÚturn_authorr‘   r.   r   rB   rC   Úkeyboard_interrupt)r\   rF   TÚerrorÚInterrupted©r‘   Ú	exit_codez
session_id: ©Úfile©Úrecover_failed_kanban_turnsc                óÒ   <€ \        S\        4      '       d   SP                  R 4      MRpSP                  P                  ! RRT RT;'       g    SP
                  /SB oS! S4       R# )ÚmessagesNrB   rC   r   )rI   r?   rJ   r#   rH   rC   )ÚnudgeÚ_historyr,   Úauthor_kwargsr	   rL   s   & €€€€r   Ú_quiet_recover_turnÚ4_run_quiet_single_query.<locals>._quiet_recover_turnà   se   ø€ ä1;¸FÄD×1IÒ1I�v—z‘z *Ô-ÈtˆHØ—Y‘Y×/Ò/ñ Ø"ðà%-×%IÐ%I°×1IÑ1Iðð  ñˆFñ
 ,¨CÖ0r   c                 ó   <€ S # r7   r   )rL   s   €r   rg   Ú)_run_quiet_single_query.<locals>.<lambda>ì   s   ø€ ‘Fr   c                ó:   € \        V \        P                  R R7      # ©T)r¶   r†   ©rK   ÚsysÚstderrr‡   s   &r   rg   rÁ   í   ó   € œU 3¬S¯Z©Z¸tÕDr   ©Úemitc               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   Ú-_run_quiet_single_query.<locals>.__annotate__ó   s   € ÷ 	ñ 	 ñ 	r   c           	     ó  <€ S! SS! V 4      \        V \        4      '       d%   \        V P                  R 4      ;'       g    R4      MR\        V \        4      '       d   V P                  RR4      M
\        V 4      R7       R# )r±   r.   zagent turn did not runrD   )r´   r±   ÚreplyN)rI   r?   r*   rJ   )Úresr¤   Úturn_report_pathr®   s   &€€€r   Ú_report_turnÚ-_run_quiet_single_query.<locals>._report_turnó   sb   ø€ ÙØ Ñ,CÀCÓ,HÜ5?ÀÄT×5JÒ5J”c˜#Ÿ'™' 'Ó*×0Ð0¨bÔ1ÐPhÜ7AÀ#Ät×7LÒ7L�c—g‘gÐ.°Ô3ÔRUÐVYÓRZ÷r   rº   c                óÄ   <€ SP                   P                  ! RR V RS/SB p\        V\        4      '       d!   VP	                  R4      '       d
   VR,          oS! S4       V# )rB   rC   rº   r   )r#   rH   rI   r?   rJ   )ÚtextÚfollowr,   r½   r	   Úhistorys   & €€€€r   Ú
_follow_upÚ+_run_quiet_single_query.<locals>._follow_upþ   se   ø€ àŸ™×3Ò3ñ Ø!%ðØ<CðØGTñ�ô ˜f¤d×+Ò+°·
±
¸:×0FÒ0FØ$ ZÕ0�Gñ 0°Ô4Ø�r   Ú_owns_process_notification)Ú
owns_eventÚlinger_budgetrD   Úpartialzgateway.model.error_prefix)r±   ÚHERMES_KANBAN_GOAL_MODEÚ1úkanban goal loop failed: %sr   )'r	   r¦   r   r¤   r,   Úagent.interrupt_compatr§   Úagent.turn_authorr¨   Úhermes_cli.quiet_single_queryr©   rª   r«   r¬   r­   r®   r#   rH   r’   rC   ÚKeyboardInterruptÚemit_resultr‘   rK   rÅ   rÆ   r¢   r¸   rI   r?   rJ   Ú_quiet_notify_linger_doner*   r   ro   rp   r"   rd   Údebug)r	   Úeffective_queryÚemitterr¦   r   r§   r¨   r©   rª   r«   r¬   r­   ÚauthorÚ_recover_turnsr¾   rÐ   rÖ   Ú	continuedrE   Ú
_exit_codeÚ	_goal_excr¤   r,   r½   rÕ   rL   rÏ   r®   s   f&&                  @@@@@@@r   Ú_run_quiet_single_queryrí   ·   s‹  ÿ€ ÷ Eó  EÝ7Ý;÷÷ ñ 'Ó(€Fñ -Ó.ÐØ/5Ò/AÑFVÐWZ×W`ÑW`×WqÑWqð  tA÷  GBò  GB�] FÑ+ð  HJ€MÙ	¤¨¨\¸2Ó >× KÐ KÀ)×	LÕ	Lð		#Ø—Y‘Y×/Ò/ñ Ø,ðØCF×C[ÑC[ðØ_lñˆFñ 	(¨Ô,õ 	]÷	1ð 	1ñ 	ØÜÙDõ	
÷	ò 	ñ 	�VÔÜ�fœd×#Ò#¨F¯J©J°x×,@Ò,@Ø—j‘j Ó,×HÐH°×0HÑ0HˆG÷
ð 
ð$5Ù=Ü˜C ¨rÓ2×8Ð8°bØÜ& sÐ,HÈ$ÓOÙ"=Ó"?ô	�	ð 15�Ô-Ü˜)¤T×*Ò*Ø"�á˜VÔ$Ü7AÀ&Ì$×7OÒ7O�6—:‘:Ð.°Ô3ÔUXÐY_ÓU`ˆ÷g 
Mðl ÒØçœ F¬D×1Ò1°f·j±jÀ×6IÒ6IØ�Z‰Z˜×!Ò! V§Z¡Z°	×%:Ò%:äŒaÐ,°F¸7µOÔDÌ3Ï:É:ÖVß	ÜˆhŒñ )¨Ó0€Jô 
‡z�z‡~�~Ð/Ó0°CÔ7¸JÈ!¼Oð	CÙ# C¨Ô2ð ‚Ü�˜sŸ~™~Ð.Ð/´c·j±jÕAàÒØ×(Ñ(¨¸C¿N¹N×<PÐ<PÈbÐ\fÐ(Ógˆ
Ù�jÖ!øôo !ô 	#Ù)¨#Ð6JÕKØÒ"Ù! '×"5Ñ"5°xÀÀwÐP]Ð6^Ðkn×kyÑky×kÐkÐ}ð  LOÐ"5ó  #Pô  QÜ�N 3§>¡>Ð"2Ð3¼#¿*¹*ÕEÙ˜c×"ð	#ûðR 15�Õ-ú÷] 
M×	LÐ	Lûôh ô 	CÜ�L‰LÐ6¸	×BÒBûð	Cúsz   ÂN<Â*L.Â=A&N<Ä$N<Ä<N<ÅN0Å)N0ÆAN<Ë	O Ì.=N-Í,=N-Î)N<Î,N-Î-N<Î0	N9Î9N<Î<O	ÏO<ÏO7Ï7O<c           	     ó
  a aaa€ S'       g   V'       g   S# RpRp ^ RI Hp ^ RI Hp ^ RIHp T! S P
                  ;'       g    RP                  4       S P                  ;'       g    RP                  4       V! 4       S P                  ;'       g    RP                  4       R7      pV VVV3R lp	VR	8w  g   Vf   V	! 4       #  T! \        S\        4      '       d   SMRS U
u. uF  p
\        V
4      NK  	  up
\        V4      ;'       g    RR
7      w  r¼\        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   V# V	! 4       #   \         d    Rp L¿i ; iu up
i   \         d    T	! 4       u # i ; i)z_Attach one-shot images natively when the model supports vision, else pre-describe them as text.rÓ   N)Úbuild_native_content_parts)Údecide_image_input_mode)Úload_configr.   )Úrequested_providerc                 ó@   <€ S'       d   S P                  SSR R7      # S# )F)Úannounce)Ú_preprocess_images_with_vision)r	   ræ   ÚqueryÚsingle_query_imagess   €€€€r   Ú_text_fallbackÚ2_route_single_query_images.<locals>._text_fallback_  s(   ø€ ÷ Ø×5Ñ5°eÐ=PÐ[`Ð5ÓaÐaØÐr   Únative)Ú
image_urlsc              3  óH   "  € T F  qP                  R 4      R8H  x € K  	  R# 5i)ÚtypeÚ	image_urlN)rJ   r8   s   & r   r;   Ú-_route_single_query_images.<locals>.<genexpr>n  s   é € Ð<±V°�u‰u�V‹} Ö+³Vùs   ‚ "TF)Úagent.image_routingrï   rð   Úhermes_cli.configrñ   Úproviderrq   Úmodelrò   r"   rI   r*   ÚlistÚany)r	   rö   ræ   r÷   Úsingle_query_image_urlsÚ	_img_modeÚ_build_partsrð   rñ   rø   r:   Ú_partsÚ_skippeds   ffff&        r   Ú_route_single_query_imagesr  I  sQ  û€ ç×#:ØÐð
 €IØ€Lð
ÝRÝ?Ý1á+Ø�\‰\×Ð˜R×&Ñ&Ó(¨3¯9©9¯?¨?¸×*AÑ*AÓ*CÁ[Ã]Ø #× 6Ñ 6× <Ð <¸"×CÑCÓEô
ˆ	÷ð ð �HÔ Ò 4ÙÓÐð
 Ù'Ü ¤s×+Ò+‰E°Ù0Ó1Ñ0˜ŒS�ŽVÑ0Ñ1ÜÐ3Ó4×<Ð<¸ô
Ñˆ÷
 ‹3Ñ<±VÓ<�3�3Š3Ñ<±VÓ<×<Ò<ØˆMÙÓÐøô) ô ØŠ	ðüò 2øô ô  ÙÓÒð ús_   œ&E Á"E Á&(E ÂE ÃE- Ã E(
Ã4E- Ä&E- Ä1E- ÅE- ÅE- ÅE%Å$E%Å(E- Å-FÆFc                óª  € . p\         P                  P                  RR4      P                  4       pV'       g   V#  ^ RIHp ^ RIHp ^ RIHp VP                  4       ;_uu_ 4       pVP                  Wb4      pRRR4       Xe   \        VRR4      MRpV'       dr   V! V4      w  ršV  Uu0 uF  p\        V4      kK  	  ppV	 F6  pWÜ9  g   K  VP                  V4       V P                  \        V4      4       K8  	  VP!                  V
4       V#   + '       g   i     Lž; iu upi   \"         d"   p\$        P'                  RT4        Rp?T# Rp?ii ; i)	zTKanban workers: image paths/URLs in the task body join the first turn's attachments.r-   r.   r0   r2   )Úextract_image_refsNrx   z&kanban image-ref extraction failed: %s)ro   rp   rJ   rq   rs   r1   r3   r   r  rR   ru   r’   r*   ÚaddÚappendr   Úextendr"   rd   rå   )r÷   r  Ú_kanban_task_idrU   rV   Ú_extract_refsÚ_connÚ_taskÚ_bodyÚ	_kb_pathsÚ_kb_urlsr:   Ú_seenÚ_pÚ_excs   &              r   Ú_collect_kanban_task_imagesr  u  s  € à)+ÐÜ—j‘j—n‘nÐ%9¸2Ó>×DÑDÓF€OßØ&Ð&ðEÝ/Ý8ÝKà×!Ñ!×#Ô# uØ—L‘L Ó8ˆE÷ $à.3Ò.?”˜˜v rÔ*ÀRˆßÙ"/°Ó"6ÑˆIá%8Ó9Ñ%8 ”S˜–VÑ%8ˆEÐ9Û�Ø–?Ø—I‘I˜b”MØ'×.Ñ.¬t°B«xÖ8ñ  ð $×*Ñ*¨8Ô4ð #Ð"÷ $×#üò :øô ô Eä�‰Ð=¸t×DÐDØ"Ð"ûðEúsH   ¼*D& Á&DÁ8"D& ÂD& Â)D!Â=
D& ÃA D& ÄD	ÄD& Ä&EÄ1EÅEc           	     ó,  a aaaaaa€ ^ RI HoHoHoHo ^ RIoR oVVVVVVV 3R lp\        \        4      ;_uu_ 4        R F3  p\        SV4      '       g   K  SP                  \        SV4      V4       K5  	  RRR4       R#   + '       g   i     R# ; i)a  Route SIGINT/SIGTERM/SIGHUP through agent.interrupt() before unwinding; kanban workers hard-exit.

A plain KeyboardInterrupt only unwinds the main thread, so tool worker threads
would orphan the setsid child; the interrupt + grace window lets them kill it.
)Ú%_arm_exit_watchdog_on_shutdown_signalÚ_flush_logging_and_stdioÚ_flush_one_shot_session_storer&   Nc                 ó¶   € \        \        4      ;_uu_ 4        ^ RIHp V! RR7       RRR4       \        P
                  ! ^ 4       R#   + '       g   i     L(; i)é    )Úkill_live_foreground_processesT)ÚnowN)r   r"   Útools.environments.baser"  ro   Ú_exit)Ú_r"  s   * r   Ú_kill_foreground_and_exitÚH_install_single_query_signal_handlers.<locals>._kill_foreground_and_exit›  s3   € ä”i× Õ ÝNÙ*¨tÕ4÷ !ô 	�Š�Ž÷ !× ús   ˜AÁA	c                ó:  <€ \         P                  R V 4       S! 4        S! \        SRR4      V 4       \        P                  P                  R4      '       d–   \        \        4      ;_uu_ 4        \        SR4      '       d.   SP                  SP                  S4       SP                  ^4       RRR4       \        \        4      ;_uu_ 4        S! S4       RRR4       S! 4        S! 4        \        4       h  + '       g   i     LP; i  + '       g   i     L;; i)z'Received signal %s in single-query moder#   Nr-   ÚSIGALRM)rd   rå   r’   ro   rp   rJ   r   r"   ÚhasattrÚsignalr*  Úalarmrâ   )	r$   Úframer  r  r  r&   r'  Ú_signalr	   s	   &&€€€€€€€r   Ú_signal_handler_qÚ@_install_single_query_signal_handlers.<locals>._signal_handler_q¢  sÂ   ø€ Ü�‰Ð>ÀÔGÙ-Ô/Ù#¤G¨C°¸$Ó$?ÀÔHô �:‰:�>‰>Ð.×/Ò/Üœ)×$Õ$Ü˜7 I×.Ò.Ø—N‘N 7§?¡?Ð4MÔNØ—M‘M !Ô$÷ %ô œ)×$Õ$ñ .¨cÔ2÷ %ñ %Ô&Ù%Ô'ÜÓ!Ð!÷ %×$ú÷ %×$ús   Á/A C7Ã	D
Ã7D	Ä
D	)ÚSIGINTÚSIGTERMÚSIGHUP)
r	   r  r  r  r&   r,  r   r"   r+  r’   )	r	   r0  Ú_namer  r  r  r&   r'  r/  s	   f  @@@@@@r   Ú%_install_single_query_signal_handlersr6  ’  sj   þ€ ÷ Pó  PÛò÷"ó "ô> 
”)×	Õ	Û4ˆEÜ�w ×&Ô&Ø—‘œw w°Ó6Ð8IÖJñ 5÷ 
×	×	Ò	ús   ¾BÁ BÂB	c               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   r   Ç  s   € ÷ %ñ % Tñ %r   c                ó„   € RV n         RV n        RV n        RV n        RV n        RV n        RV n        RV n        RV n        R# )zVNeutralize every stdout-writing callback so -Q stdout carries only the final response.TNÚoff)	Ú
quiet_modeÚsuppress_status_outputÚstream_delta_callbackÚtool_gen_callbackÚreasoning_callbackÚtool_progress_callbackÚtool_start_callbackÚtool_complete_callbackÚtool_progress_mode)r#   s   &r   Ú_configure_quiet_agentrC  Ç  sL   € à€EÔØ#'€EÔ Ø"&€EÔØ"€EÔØ#€EÔð $(€EÔ Ø $€EÔØ#'€EÔ Ø$€EÖr   c               ó   € V ^8„  d   QhRR/# )r   Ústream_jsonr™   r   )r   s   "r   r   r   Ö  s   € ÷ t$ñ t$È4ñ t$r   c                óx  a a € ^ RI HpHpHpHp	Hp
HpHpHpH	pH
p V! WW44      '       d]   V! W4      w  pp\        P                  R\        T;'       g    R4      \        V4      4       V! VV4      S n        S P                  4       # RS n        R\"        P$                  R&   ^ RIHp \"        P$                  P+                  R4      '       dN   ^ R	IHp V! 4       '       g;   \1        \3        R
4      \4        P6                  R7       \4        P8                  ! ^ 4       S P;                  R\=        V4      R7      '       g	   V! ^4        V! W4      w  ppV! V4      p^ RIH p V! 4        V'       Edh   RS n!        RpV'       d:   ^ RI"H#p T! \I        S RR4      ;'       g    RS PJ                  ;'       g    RR7      pS PM                  4       '       d¯   V! S WVV4      pS PO                  V4      pVR,          S PP                  8w  d   RS n)        S PU                  VR,          VR,          VP+                  R4      R7      '       d=   V	! S PR                  4       Ve   VPW                  S PR                  4       V! S VVR7       V! R\I        S RR4      \I        S RR4      R7      pVe-   TPY                  RRRR/S PJ                  ;'       g    RVR 7       V! V4       T;'       g    V'       d   R!MRpV'       d+   S PZ                  P1                  R"\3        R#4       R$V 24       S P]                  4        S P_                  TT;'       g    RR%7      o ^ R&I0H1p V V 3R' lpV! VV 3R( lR) R*7       \"        P$                  P+                  R+4      R8X  d,   V! S Pd                  4      ^ 8X  d    T! S S ;'       g    R4       S Pk                  RR-7       V! V! S Pd                  \I        S RR4      \I        S RR4      R7      4       V
! S 4       R#   \f         d!   p\        Pi                  R,T4        Rp?LsRp?ii ; i  T
! S 4       i ; i).zÄ``-q``/``--image`` entry: seed an interactive session on a TTY, else run the one-shot turn and exit.
``stream_json`` (implies quiet) swaps the plain-text final answer for the JSONL event protocol.)
Ú_SeededQueryMessager  Ú_collect_query_imagesrC  Ú_finalize_single_queryr  rŽ   rí   Ú_should_seed_interactiver¤   z@Seeding interactive session with -q prompt (%d chars, %d images)r.   TrÝ   ÚHERMES_SINGLE_QUERY_SESSION)r«   r-   )Ú register_current_worker_from_envz%cli.single_query.kanban_run_reclaimedrµ   r	   )rÆ   )Úrecord_cli_one_shot_readyr9  N)ÚStreamJsonEmitterr  )r  r‘   Ú	signatureÚruntimeÚrequest_overrides)Úmodel_overrideÚruntime_overriderQ  )rç   Ú_credentials_rate_limitedFÚ_credentials_terminal)r–   r—   rF   r±   z credentials or agent init failedr³   z[image attached]z[bold blue]zcli.single_query.query_labelz[/] )Úimagesr·   c                ó*   <€ SP                  V 4      oS# r7   r‹   )r»   r	   rE   s   &€€r   Ú_nonquiet_recover_turnÚ6_run_single_query_mode.<locals>._nonquiet_recover_turn+  s   ø€ à—x‘x “ˆHØˆOr   c                 ó   <€ \        S R R4      # )Ú_last_turn_resultN)r’   r“   s   €r   rg   Ú(_run_single_query_mode.<locals>.<lambda>2  s   ø€ ”G˜CÐ!4°dÔ;r   c                ó:   € \        V \        P                  R R7      # rÃ   rÄ   r‡   s   &r   rg   r\  3  rÇ   r   rÈ   rÜ   rÞ   )Úclear_screen)6r	   rG  r  rH  rC  rI  r  rŽ   rí   rJ  r¤   rd   re   ÚlenÚ_seeded_first_messageÚrunÚ_single_query_modero   rp   rá   r«   rJ   Útools.kanban_toolsrL  rK   r   rÅ   rÆ   ÚexitÚ_claim_active_sessionr™   Ú/hermes_cli.observability.shared_metrics_startuprM  rB  Úhermes_cli.stream_jsonrN  r’   r‘   Ú_ensure_runtime_credentialsÚ_resolve_turn_agent_configÚ_active_agent_route_signaturer#   Ú_init_agentÚattachrã   ÚconsoleÚ_show_security_advisoriesrŒ   r¢   r¸   r[  r"   rå   Ú_print_exit_summary)!r	   rö   ÚimageÚquietÚoneshotrE  rG  r  rH  rC  rI  r  rŽ   rí   rJ  r¤   Úseeded_queryÚseeded_imagesr«   rL  r÷   r  rM  rç   rN  ræ   Ú
turn_routeÚ	fail_codeÚ_query_labelr¸   rX  rì   rE   s!   f&&&&&                          @r   Ú_run_single_query_moderx  Ö  sÌ  ù€ ÷ P÷  P÷  PÙ ¨e×=Ò=Ù&;¸EÓ&IÑ#ˆ�mÜ�‰ØNÜ�×"Ð" Ó#¤S¨Ó%7ô	
ñ %8¸ÀmÓ$TˆÔ!Ø�w‰w‹yÐØ!€CÔð 14„B‡J�JÐ,Ñ-Ý?Ü	‡z�z‡~�~Ð*×+Ò+ÝGÙ/×1Ò1ä”!Ð;Ó<Ä3Ç:Á:ÕNÜ�HŠH�QŒKØ×$Ñ$ U´4¸³;Ð$×?Ò?Ù˜!ÔðS$Ù%:¸5Ó%HÑ"ˆÐ"Ù"=Ð>QÓ"RÐÝ]Ù!Ô#ßˆ5à%*ˆCÔ"ØˆGßõ EÙ+´'¸#¸wÈÓ2K×2QÐ2QÈrÐ^a×^lÑ^l×^rÐ^rÐprÔs�Ø×.Ñ.×0Ò0Ù'AØ˜Ð':Ð<Só(�ð !×;Ñ;¸OÓL�
Ø˜kÕ*¨c×.OÑ.OÔOØ $�C”IØ—?‘?Ø#-¨gÕ#6Ø%/°	Õ%:Ø&0§n¡nÐ5HÓ&Ið #÷ ò ñ
 +¨3¯9©9Ô5ØÒ*ØŸ™ s§y¡yÔ1Ù+¨C°È'ÕRá/Ø¬w°sÐ<WÐY^Ó/_Ü%,¨SÐ2IÈ5Ó%QôSˆIð Ò"Ø×#Ñ# X¨t°WÐ>`Ð$aØ/2¯~©~×/CÐ/CÀÈyð $ô Zá˜iÔ(à×SÐS×7JÑ!3ÐPRˆßØ�K‰K×Ñ ¬AÐ.LÓ,MÐ+NÈdÐS_ÐR`ÐaÔbØ×%Ñ%Ô'Ø—8‘8˜EÐ*=×*EÐ*EÀ�8ÓFˆõ 	Kö	ñ
 	$Ø"Ü;ÙDõ	
ô �:‰:�>‰>Ð3Ó4¸Ô;Ñ@WÐX[×XmÑXmÓ@nÐrsÔ@sðGÙ*¨3°·°¸BÔ?ð 	×Ñ¨UÐÔ3ñ 	Ñ1Ø×!Ñ!Ü%,¨SÐ2MÈuÓ%UÜ!(¨Ð.EÀuÓ!MôOô 	Pñ
 	˜sÖ#øô ô GÜ—‘Ð:¸I×FÑFûðGûñ 	˜sÕ#ús}   Å9P/ Å=P/ ÆP/ Æ.P/ ÇA1P/ È>BP/ ËP/ ËP/ Ë%P/ Ë1AP/ Í A P/ Î!P Î-P Î4AP/ ÐP,ÐP'Ð"P/ Ð'P,Ð,P/ Ð/
P9)NNr7   )F)'Ú__doc__Ú
__future__r   Útypingr   Úloggingro   rÅ   r    Ú
agent.i18nr   rß   r   Ú
contextlibr   Úpathlibr   r   Ú	getLoggerrd   r	   r
   r   r&   r   rŽ   r,   r£   r”   rœ   r•   r›   r¤   rí   r  r  r6  rC  rx  r   r   r   Ú<module>r�     s«   ðñõ #å  ã Û 	Û 
Û Ý Ý 9Ý Ý Ý ð 
×	Ò	˜5Ó	!€çÝõõ÷"9õx
aõ.õ [õ Yð Èð  Ø9>÷ ôFO"òd) òX#ò:2Kõj%÷t$ñ t$r   