+
    lHàj5  ã                  óh   € R t ^ RIHt ^ RIt^ RIt^ RIHt ]P                  ! ]4      t	R t
R R ltR# )a–  Propagate agent-turn context into worker threads that dispatch Hermes tools.

A bare ``threading.Thread`` / ``ThreadPoolExecutor`` worker starts with an empty
``contextvars.Context`` and no thread-local approval/sudo callbacks, so tool dispatch inside it
silently loses the approval ContextVars (gateway sessions then auto-approve dangerous commands)
and the CLI callbacks (``prompt_dangerous_approval`` cannot reach the user, GHSA-qg5c-hvr5-hjgr).
Call :func:`propagate_context_to_thread` **on the parent thread** (it snapshots at call time) and
use the result as the worker target; callbacks are installed for the worker's lifetime and
always cleared on exit.
)ÚannotationsN)ÚCallablec                 ó  € ^ RI Hp  ^ RIHp VP                  VP
                  3VP                  VP                  3V P                  V P                  3V P                  V P                  3V P                  V P                  33# )uZ  (getter, setter) pairs for every thread-local prompt callback a tool may need mid-dispatch
(lazy: terminal_tool imports tools.approval at load, so a top-level import risks a cycle).
Add a new per-thread prompt here â€” a callback missing from this table is silently absent on
every parallel/timeout worker, so the tool believes nobody can answer.)Úunlock)Úterminal_tool)Úagent.vault_backendsr   Útoolsr   Ú_get_approval_callbackÚset_approval_callbackÚ_get_sudo_password_callbackÚset_sudo_password_callbackÚget_unlock_prompt_callbackÚset_unlock_prompt_callbackÚget_save_login_prompt_callbackÚset_save_login_prompt_callbackÚget_code_prompt_callbackÚset_code_prompt_callback)Úvault_unlockÚtts     Ú9/home/ubuntu/.hermes/hermes-agent/tools/thread_context.pyÚ_callback_apir      sz   € õ
 <Ý)à×&Ñ&¨×(@Ñ(@ÐAØ×+Ñ+¨R×-JÑ-JÐKØ×4Ñ4°l×6]Ñ6]Ð^Ø×8Ñ8¸,×:eÑ:eÐfØ×2Ñ2°L×4YÑ4YÐZð	\ð \ó    c               ó    € V ^8„  d   QhRRRR/# )é   Útargetr   Úreturn© )Úformats   "r   Ú__annotate__r   $   s   € ÷ &ñ &¨ð &°Xñ &r   c                ó  a aa€ \         P                  ! 4       oRo \        ;QJ d    . R \        4        4       F  NK  	  5M! R \        4        4       4      oVVV 3R lpV#   \         d    \
        P                  RRR7        L.i ; i)u8  Wrap *target* to run with the *current* thread's ContextVars and per-thread prompt callbacks
(approval, sudo, password-manager unlock).

Fail-closed: if callback installation raises they stay ``None`` â€” dangerous commands are then
denied by ``prompt_dangerous_approval`` and the gateway approval queue blocks.
Nc              3  ó6   "  € T F  w  rW!! 4       3x € K  	  R # 5i)Nr   )Ú.0ÚgetterÚsetters   &  r   Ú	<genexpr>Ú.propagate_context_to_thread.<locals>.<genexpr>/   s   é € ÐRÁ/±°˜& &£(Õ+Ã/ùs   ‚z0Could not capture parent approval/sudo callbacksT©Úexc_infoc                 ó<   <a a€ V VVV3R  lpSP                  V4      # )c                 ó¬  <€ Sf	   S! S/ SB #  S F  w  rVf   K  V ! V4       K  	   S! S/ SB  S F  w  rV ! R 4       K  	  #   \          d    \        P                  RRR7        LAi ; i  \          d    \        P                  RRR7        # i ; i   S F  w  rT ! R 4       K  	  i   \          d    \        P                  RRR7        i i ; i; i)NzaFailed to install propagated approval/sudo callbacks; dangerous-command approval will fail closedTr&   z2Failed to clear propagated approval/sudo callbacks)Ú	ExceptionÚloggerÚdebug)r#   ÚcbÚ_cbÚargsÚinstallsÚkwargsr   s      €€€€r   Ú_innerÚ<propagate_context_to_thread.<locals>._runner.<locals>._inner4   sô   ø€ ØÒÙ˜tÐ. vÑ.Ð.ð[Û"*‘J�FØ”~Ù˜rž
ñ #+ð0Ù˜tÐ. vÑ.ð0Û'/™˜Ù˜tžò (0øô ô [Ü—‘ð KØUYð ö [ð[ûô !ô 0Ü—L‘LÐ!UØ*.ð !ö 0ð0ûð0Û'/™˜Ù˜tžò (0øä ô 0Ü—L‘LÐ!UØ*.ð !ö 0ð0ýsV   �A œA ©B ±A-Á"A*Á)A*Á-"BÂBÂCÂB+Â*CÂ+"CÃCÃCÃC)Úrun)r/   r1   r2   Úctxr0   r   s   jl €€€r   Ú_runnerÚ,propagate_context_to_thread.<locals>._runner3   s   ú€ ÷	0ð 	0ð( �w‰w�v‹Ðr   )ÚcontextvarsÚcopy_contextÚtupler   r*   r+   r,   )r   r6   r5   r0   s   f @@r   Úpropagate_context_to_threadr;   $   sq   ú€ ô ×
"Ò
"Ó
$€Cà€HðXß”5ÑRÄ-Ä/ÓR—5‘5ÑRÄ-Ä/ÓRÓRˆ÷ð. €Nøô5 ô XÜ�‰ÐGÐRVˆÖWðXús   œ
A" §1A" Á""BÂB)Ú__doc__Ú
__future__r   r8   ÚloggingÚtypingr   Ú	getLoggerÚ__name__r+   r   r;   r   r   r   Ú<module>rB      s3   ðñ	õ #ã Û Ý à	×	Ò	˜8Ó	$€ò\÷&r   