+
    lHàjŽ6  ã                  ó*  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	H
t
HtHtHt ^ RIHt ^ RIHtHt ]P&                  ! R4      t]! 0 Rm4      tR R ltR	 R
 ltR R ltR R ltR R ltR R ltRtR R ltR R ltR R lt RR R llt!R# )zMLocal argument validation for ``tool_call`` against a deferred tool's schema.)ÚannotationsN)ÚAnyÚDictÚIterableÚListÚOptionalÚTuple©Ú
tool_error)ÚBRIDGE_TOOL_NAMESÚ_registry_entryztools.tool_searchc               ó    € V ^8„  d   QhRRRR/# )é   Únoder   Úreturn© )Úformats   "ÚA/home/ubuntu/.hermes/hermes-agent/tools/tool_search_validation.pyÚ__annotate__r      s   € ÷ 5ñ 5 sð 5¨sñ 5ó    c                ó8  € \        V \        4      '       d   V  Uu. uF  p\        V4      NK  	  up# \        V \        4      '       g   V # V P	                  4        UUu/ uF:  w  r#VR8w  g   K  Y"\
        9   d   \        P                  ! V4      M
\        V4      bK<  	  pppV P                  R4      RJd   V# VP                  R4      p\        V\        4      '       d   V.p\        V\        4      '       d   RV9  d
   . VORNVR&   V# RVRR/./# u upi u uppi )zŒJSON-Schema-compatible copy honoring OpenAPI ``nullable: true`` (the normal coercion
path accepts that shape, so local validation must too).ÚnullableTÚtypeÚnullÚanyOf)
Ú
isinstanceÚlistÚ_schema_for_local_validationÚdictÚitemsÚ_SCHEMA_LITERAL_KEYSÚcopyÚdeepcopyÚgetÚstr)r   ÚitemÚkeyÚvalueÚ
normalizedÚschema_types   &     r   r   r      s   € ô �$œ×ÒÙ?CÓD¹t°tÔ,¨TÖ2¹tÑDÐDÜ�dœD×!Ò!Øˆð %)§J¡J¤LôGá$0‘j�c°C¸:Ñ4EôA�#Ô7KÔ0KœŸš eÔ,Ü9¸%Ó@òAá$0ð ñ Gð ‡x�x�
Ó 4Ó'ØÐØ—.‘. Ó(€KÜ�+œs×#Ò#Ø"�mˆÜ�+œt×$Ò$Ø˜Ô$Ø!7 ;Ð!7°Ð!7ˆJ�vÑØÐð �j 6¨6Ð"2Ð3Ð4Ð4ùò% EùóGs   ›DÁDÁ-0Dc               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   Úboolr   )r   s   "r   r   r   ,   s   € ÷ 
,ñ 
, 3ð 
,¨4ñ 
,r   c                óô  € \        V \        4      '       d5   \        ;QJ d    R V  4       F  '       g   K   R# 	  R# ! R V  4       4      # \        V \        4      '       g   R# V P	                  R4      p\        V\
        4      ;'       d    VP                  R4      '       * ;'       gQ    \        ;QJ d*    R V P                  4        4       F  '       g   K   R# 	  R# ! R V P                  4        4       4      # )u�   True when *node* contains a non-local ``$ref`` â€” local validation must never turn a
tool call into an implicit network/file fetch (fail open).c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5i©N)Ú_schema_has_external_ref)Ú.0r%   s   & r   Ú	<genexpr>Ú+_schema_has_external_ref.<locals>.<genexpr>0   s   é € ÐC¹d°dÔ+¨D×1Ð1»dùó   ‚TFz$refÚ#c              3  óV   "  € T F  w  rV\         9  g   K  \        V4      x € K!  	  R # 5ir.   )r    r/   )r0   r&   r'   s   &  r   r1   r2   4   s-   é € ð E,Ù:F©J¨CØÔ*Ñ*ô 	(Ô  ×'Ð'»,ùs   ‚)–))r   r   Úanyr   r#   r$   Ú
startswithr   )r   Úrefs   & r   r/   r/   ,   sË   € ô �$œ×Òß‹sÑC¹dÓC�sŒsÐCŠsÐCˆsÑC¹dÓCÓCÐCÜ�dœD×!Ò!ÙØ
�(‰(�6Ó
€CÜ�sœCÓ ×<Ð<¨¯©¸Ó)<Ô%<÷ ,ð ,ÇÃñ E,Ø:>¿*¹*¼,óE,ÇÄð ,Âð ,Àñ E,Ø:>¿*¹*¼,óE,ó B,ð ,r   c               ó    € V ^8„  d   QhRRRR/# )r   Úerrorr   r   r$   r   )r   s   "r   r   r   9   s   € ÷ ñ ˜Cð  Cñ r   c                ó*  € Rp\        V RR	4       F  p\        V\        4      '       d,   \        P                  ! RV4      '       d   VRV 2,          pKD  TR\        V\
        4      '       d   TM\        P                  ! VRR7       R2,          pK�  	  V# )
z:Format a jsonschema error path as a compact argument path.Ú	argumentsÚabsolute_pathz[A-Za-z_][A-Za-z0-9_]*Ú.Ú[F©Úensure_asciiÚ]r   )Úgetattrr   r$   ÚreÚ	fullmatchÚintÚjsonÚdumps)r:   ÚpathÚparts   &  r   Ú_validation_pathrK   9   s~   € à€DÜ˜˜°Ö3ˆÜ�dœC× Ò ¤R§\¢\Ð2KÈT×%RÒ%RØ�a˜�v�JÕŠDà�a¤
¨4´× 5Ò 5™¼4¿:º:ÀdÐY^Ô;_Ð`Ð`aÐbÕbŠDñ	 4ð
 €Kr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )r   Úmessager$   rI   Ú
constraintÚ
parametersr   r   r   )r   s   "r   r   r   D   s7   € ÷ Wñ W˜sð W¨Sð W¸cð WÈsð WÐWZñ Wr   c               ó   € \        WW#R R7      # )zFRetry tool_call with 'arguments' matching the parameters schema above.)rI   rN   rO   Úhintr	   )rM   rI   rN   rO   s   &$$$r   Ú_validation_errorrR   D   s   € ÜØ zØUôWð Wr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Únamer$   Úargsúdict[str, Any]r   úOptional[str]r   )r   s   "r   r   r   J   s!   € ÷ >ñ > cð >°ð >ÀMñ >r   c                óÊ  €  ^ RI Hp VP                  V 4      p\        V\        4      '       g   R# VP                  R4      R8X  d   VP                  R4      MTp\        V\        4      '       d   VP                  R4      MRp\        V\        4      '       g   R# VP                  R4      p\        V\        4      '       d3   V Uu. uF%  p\        V\        4      '       g   K  Wq9  g   K#  VNK'  	  upM. pV'       d&   \        RV  RR	P                  V4       R
2RRVR7      # \        V4      p	\        V	4      '       d   \        P                  RV 4       R#  ^ RIHp
 V
! V \	        V4      4      p ^ RIHp ^ RIHp T! T	4      pTP-                  T	4       T! T! T	4      P/                  T4      4      pTf   R# \1        T4      p\        \3        TRR4      ;'       g    R4      p\4        P6                  ! RR\        TP8                  4      4      P;                  4       p\=        T4      R8”  d   TR,          R,           p\        RT  RT RT RT R
2	TTTR7      # u upi   \          d(    \        P                  RT RR7       \	        T4      p ELi ; i  \*         d    \        P                  RT 4        R# i ; i  \          d    \        P                  RT RR7        R# i ; i) a{  Validate ``tool_call`` arguments against the deferred tool's schema. Models invoke
deferred tools "blind" (schema unseen) and omit required args; without this, the opaque
downstream failure makes cheap models loop. Required-field probe first, then the same
schema-guided coercion normal dispatch applies, then jsonschema on the repaired copy.
Missing/malformed schemas, no validator, and external refs all fail OPEN. Returns a JSON
error string when invalid, ``None`` when the call should dispatch.

This restores the concrete-schema checks that the provider cannot perform through the generic
``arguments: object`` bridge. See #5149.
©ÚregistryNr   ÚfunctionrO   Úrequiredztool_call to 'z#' is missing required argument(s): ú, z. The tool was NOT invoked.r<   )rI   rN   rO   zASkipping local deferred-argument validation for %s: external $ref)Úcoerce_tool_argsz(Deferred-argument coercion failed for %sT)Úexc_info)Ú
best_match)Úvalidator_forz?jsonschema unavailable; keeping required-only validation for %sÚ	validatorÚschemaz\s+Ú iX  :NiU  Nz...z ' failed argument validation at z (z): z)validate_deferred_call_args failed for %s)Útools.registryrZ   Ú
get_schemar   r   r#   r   r$   rR   Újoinr   r/   ÚloggerÚdebugÚmodel_toolsr^   Ú	ExceptionÚjsonschema.exceptionsr`   Újsonschema.validatorsra   ÚImportErrorÚcheck_schemaÚiter_errorsrK   rC   rD   ÚsubrM   ÚstripÚlen)rT   rU   Ú	_registryrc   ÚfnÚparamsr\   ÚrÚmissingÚvalidation_schemar^   Úcandidate_argsr`   ra   Úvalidator_clsÚvalidation_errorrI   rN   Údetails   &&                 r   Úvalidate_deferred_call_argsr~   J   s¯  € ð3Ý8Ø×%Ñ% dÓ+ˆÜ˜&¤$×'Ò'ÙØ'-§z¡z°&Ó'9¸ZÔ'GˆV�Z‰Z˜
Ô#ÈVˆÜ)3°B¼×)=Ò)=�—‘˜Ô%À4ˆÜ˜&¤$×'Ò'ÙØ—:‘:˜jÓ)ˆä  ¬4×0Ò0ñ  (ÓP™x˜!¬:°a¼×+=”AÀ!Á-—A�A™xÒPØ68ð 	çÜ$Ø   Ð&IØ—9‘9˜WÓ%Ð&Ð&AðCà ¨ZÀFôLð Lô 9¸Ó@ÐÜ#Ð$5×6Ò6Ü�L‰LÐ\Ð^bÔcÙð	(Ý4Ù-¨d´D¸³JÓ?ˆNð	Ý8Ý;ñ &Ð&7Ó8ˆØ×"Ñ"Ð#4Ô5Ù%¡mÐ4EÓ&F×&RÑ&RÐSaÓ&bÓcÐØÒ#ÙÜÐ 0Ó1ˆÜœÐ!1°;ÀÓE×QÐQÈÓRˆ
Ü—’˜ ¤SÐ)9×)AÑ)AÓ%BÓC×IÑIÓKˆÜˆv‹;˜ÔØ˜D•\ EÕ)ˆFÜ Ø˜T˜FÐ"BÀ4À&ð IØˆ|˜3˜v˜hÐ&AðCà *¸ôAð 	AùòG Qøô  ô 	(Ü�L‰LÐCÀTÐTXˆLÔYÜ! $›Z‹Nð	(ûô ô 	Ü�L‰LÐZÐ\`ÔaÚð	ûô" ô Ü�‰Ð@À$ÐQUˆÔVÚðús�   ‚-J; ±A(J; Â+J; ÃIÃ#IÃ+IÃ1J; Ã>$J; Ä#2J; ÅI Å1J Å=:J; Æ9BJ; ÉJ; É.JÊJ; ÊJÊJ; Ê!J8Ê4J; Ê7J8Ê8J; Ê;#K"Ë!K"c               ó    € V ^8„  d   QhRRRR/# )r   rU   rV   r   z*tuple[list[dict[str, Any]], Optional[str]]r   )r   s   "r   r   r   ‹   s   € ÷ 3ñ 3 nð 3Ð9cñ 3r   c                óà  € V P                  R4      pVfb   \        V P                  R4      ;'       g    R4      P                  4       '       g   . R3# RV P                  R4      RV P                  R4      /.p\        V\        4      '       d    \        P
                  ! V4      p\        V\        4      '       d   V.p\        V\        4      '       d	   V'       g   . R3# . p\        V4       EF$  w  rE\        V\        4      '       g   . R	V R
23u # \        VP                  R4      ;'       g    R4      P                  4       pV'       g   . R	V R23u # V\        9   d   . RV R23u # VP                  R4      pVe-   \        V\        4      '       d   VP                  4       '       g   / p\        V\        4      '       d    \        P
                  ! V4      p\        V\        4      '       g   . R	V R23u # VP                  RVRV/4       EK'  	  VR3#   \        P                   d   p. RT 23u Rp?# Rp?ii ; i  \        P                   d   p. R	T RT 23u Rp?u # Rp?ii ; i)uš  Normalize ``tool_call`` arguments into a ``calls[]`` list of entries.

Accepts the advertised batch shape ``{"calls": [{"name", "arguments"}, ...]}``
and, tolerantly, the legacy single shape ``{"name": ..., "arguments": ...}``
(a single call is a batch of one). Each entry's ``arguments`` is coerced to
a dict (JSON strings parsed, ``None`` â†’ ``{}``). Returns ``(entries, None)``
or ``([], error_message)``.
ÚcallsNrT   Ú z:tool_call requires 'calls' (an array of {name, arguments})r<   z%tool_call 'calls' is not valid JSON: z@tool_call 'calls' must be a non-empty array of {name, arguments}ztool_call calls[z/] must be an object with 'name' and 'arguments'z] requires a 'name'ztool_call cannot invoke 'z' (it is itself a bridge tool)z].arguments is not valid JSON: z].arguments must be an object)r#   r$   rr   r   rG   ÚloadsÚJSONDecodeErrorr   r   Ú	enumerater   Úappend)rU   Ú	raw_callsÚeÚentriesÚpositionÚrawrT   Úraw_argss   &       r   Únormalize_tool_call_entriesr�   ‹   sN  € ð —‘˜Ó!€IØÒä�4—8‘8˜FÓ#×)Ð) rÓ*×0Ñ0×2Ò2ØÐSÐSÐSØ˜dŸh™h vÓ.°¸T¿X¹XÀkÓ=RÐSÐTˆ	Ü�)œS×!Ò!ð	CÜŸ
š
 9Ó-ˆIô �)œT×"Ò"Ø�Kˆ	Ü�i¤×&Ò&¯iØÐUÐUÐUà$&€GÜ" 9×-‰ˆÜ˜#œt×$Ò$ØÐ)¨(¨Ð3bÐcÐcÒcÜ�3—7‘7˜6“?×(Ð( bÓ)×/Ñ/Ó1ˆßØÐ)¨(¨Ð3FÐGÐGÒGØÔ$Ô$ØÐ2°4°&Ð8VÐWÐWÒWØ—7‘7˜;Ó'ˆØÒ¤
¨8´S× 9Ò 9À(Ç.Á.×BRÒBRð
 ˆHÜ�h¤×$Ò$ð[ÜŸ:š: hÓ/�ô ˜(¤D×)Ò)ØÐ)¨(¨Ð3PÐQÐQÒQØ�‰˜  k°8Ð<×=ñ- .ð. �Dˆ=Ðøô? ×#Ñ#ô 	CØÐ>¸q¸cÐBÐBÕBûð	Cûô4 ×'Ñ'ô [ØÐ-¨h¨ZÐ7VÐWXÐVYÐZÐZ×Zûð[ús<   ÂH ÇIÈH?È.H:È4H?È:H?ÉI-É	I(É I-É(I-iÜ  c               ó    € V ^8„  d   QhRRRR/# )r   r‰   zlist[dict[str, Any]]r   r$   r   )r   s   "r   r   r   Ä   s   € ÷ ñ Ð3ð ¸ñ r   c                óh  € V ^ ,          p\         P                  ! VP                  R/ 4      RRR7      p\        V4      \        8”  d   RpRP                  \         P                  ! VR,          RR7      V4      p\        V 4      ^8”  d   R\        V 4      ^,
           R	2MR
pR\        V 4       RV V R2# )zïRejection for a multi-entry batch that names a local tool. Restates the valid
shape with the caller's OWN first entry: small models re-send an identical batch
when told only the constraint, and the echoed payload is what gets them unstuck.r<   F)rA   Ú
separatorsz{...}z*{{"calls":[{{"name":{},"arguments":{}}}]}}rT   r@   z then issue the remaining z* call(s) as separate tool_call invocationsr‚   z<tool_call takes exactly one entry for local tools; you sent z. Retry with only: z2. Only connectors__ names may be batched together.)Ú,Ú:)rG   rH   r#   rs   Ú_ECHO_ARGS_MAX_CHARSr   )r‰   ÚfirstrU   ÚretryÚ	remainings   &    r   Úlocal_batch_errorr—   Ä   s¹   € ð �A�J€EÜ�:Š:�e—i‘i ¨RÓ0¸uÐQ[Ô\€DÜ
ˆ4ƒyÔ'Ô'ØˆØ8×?Ñ?ÄÇ
Â
È5ÐQWÍ=ÐglÔ@mÐosÓt€Eä˜“L 1Ô$ð .¬c°'«l¸QÕ.>Ð-?Ð?iÑjØ*,ð ð GÄsÈ7Ã|Ànð UØ!˜7 9 +Ð-_ð	aðr   c               ó    € V ^8„  d   QhRRRR/# )r   rT   r$   r   r   )r   s   "r   r   r   Õ   s   € ÷ Rñ R¨ð R°ñ Rr   c                ó   € RV  R2# )aJ  Why a registered tool absent from THIS session cannot be reached, whatever its door.

Deferral is a property of the tool, availability one of the session: a deferred tool the
session does not carry (``defer: [delegate_task]`` in a worker) is no more findable through
``tool_search`` than a stripped core tool is callable directly.Ú'up   ' is not available in this execution context. Don't retry it â€” state the assumption and proceed with the work.r   )rT   s   &r   Úunavailable_in_session_reasonr›   Õ   s   € ð �ˆvð Qð Qð Rr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rT   r$   Úsession_tool_namesúOptional[Iterable[str]]r   rW   r   )r   s   "r   r   r   ß   s(   € ÷ 
Lñ 
L Cð 
LÐ=Tð 
LÐYfñ 
Lr   c                ó¨   € Ve   V \        V4      9   d   R# ^ RIHpHp W! 4       9  g   \	        V 4      f   R# V! V 4      ;'       g    \        V 4      # )ai  The unavailability message when a core tool is missing from the session's own tool list,
whether or not ``defer:`` moved it behind the bridge; None without session context, when
the session carries it, or for MCP/plugin/unregistered names (an absent one may be a stale
catalog that ``tool_search`` can still refresh). A missing GUI surface keeps its own reason.N)Ú_core_tool_namesÚout_of_scope_reason)ÚsetÚtools.tool_searchr    r¡   r   r›   )rT   r�   r    r¡   s   &&  r   Úsession_unavailable_errorr¤   ß   sO   € ð
 Ò! T¬SÐ1CÓ-DÔ%DÙßGØÐ#Ó%Ô%¬¸Ó)>Ò)FÙÙ˜tÓ$×KÐKÔ(EÀdÓ(KÐKr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rT   r$   r�   rž   r   r   )r   s   "r   r   r   ì   s(   € ÷ \ñ \˜sð \Ð8Oð \Ð[^ñ \r   c                ój  a€ ^ RI Hp W! 4       9   g   \        V 4      e&   Ve   V \        V4      9  d   \	        V 4      # RV  R2# RV  2o ^ RIHp \        V3R lVP                  4        4       4      pV'       d   RRP                  R	 V 4       4       R
2MRpRV  RV 2#   \         d    . p L=i ; i)u—  Rejection for a ``tool_call`` naming something that is not a deferred tool.
Two different mistakes reach here and need opposite corrections: a directly-listed
tool (call it without the bridge) vs. an unknown name â€” typically a deferred MCP tool
cited by its bare suffix instead of the full ``mcp__<server>__{tool}`` name. Telling
the second group 'call it directly' is the opposite of what they must do.

``_HERMES_CORE_TOOLS`` is a *static* list, so a core tool stripped from this session's
toolset (clarify in a subagent, kanban worker) otherwise gets told "call it directly"
â€” an instruction that can never resolve, burning a turn on a confident wrong answer.
When the caller passes the session-scoped names, absence is reported as unavailability
instead. Stays None for callers with no session context; deliberately never consults the
global blocklist, because a top-level session legitimately has these tools.
)r    rš   z[' is a directly-listed tool, not a deferred one. Call it directly instead of via tool_call.Ú__rY   c              3  óX   <"  € T F  qP                  S4      '       g   K  Vx € K!  	  R # 5ir.   )Úendswith)r0   ÚnÚsuffixs   & €r   r1   Ú'not_deferrable_error.<locals>.<genexpr>  s   øé € Ð[Ñ'D !Ï
É
ÐSY×HZŸAšAÓ'Dùs   ƒ* 
*z Did you mean r]   c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ir.   )Úrepr)r0   Úcs   & r   r1   r¬     s   é € Ð&C¹
°1¤t¨A§w w»
ùr3   Ú?z( Use tool_search to find the exact name.z�' is not a known tool name. Deferred tools must be invoked through tool_call by the exact name tool_search returns (e.g. mcp__<server>__{tool}).)r£   r    r   r¢   r›   re   rZ   ÚsortedÚget_all_tool_namesrk   rg   )rT   r�   r    rZ   Ú
candidatesrQ   r«   s   &&    @r   Únot_deferrable_errorr´   ì   sÝ   ø€ õ 3ØÐÓ!Ô!¤_°TÓ%:Ò%FØÒ)¨d¼#Ð>PÓ:QÔ.QÜ0°Ó6Ð6Ø�D�6ð =ð =ð 	>à�$�ˆ[€FðÝ+ÜÔ[ x×'BÑ'BÔ'DÓ[Ó[ˆ
÷ KUˆn˜TŸY™YÑ&C¹
Ó&CÓCÐDÀAÑFØ;ð 	à�ˆvð TØTXÐSYð[ð \øô	 ô ØŠ
ðús   Á)B" Â"B2Â1B2>   ÚenumÚconstÚdefaultÚexampleÚexamplesr.   )"Ú__doc__Ú
__future__r   r!   rG   ÚloggingrD   Útypingr   r   r   r   r   r   re   r
   Útools.tool_search_catalogr   r   Ú	getLoggerrh   Ú	frozensetr    r   r/   rK   rR   r~   r�   r“   r—   r›   r¤   r´   r   r   r   Ú<module>rÁ      s†   ðÙ Så "ã Û Û Û 	ß =× =å %ß Hà	×	Ò	Ð.Ó	/€á Ò!TÓUÐ õ5õ2
,õõWõ>õB3ðl Ð õõ"Rõ
L÷\ñ \r   