+
    jHàjJ%  ã                  óâ  a€ 0 t $ R t^ RIHt ^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
 ^ RIHtHtHtHtHtHtHt ]P&                  ! ]4      t]! RR7       ! R R	4      4       tR&t] U UUu/ uF  w  rq ]! WV4      bK  	  uppp tR
]R&   ]! ]4      tRtRtR'R R lltR R ltR R lt R(R R llt!R(R R llt"R R lt#R(R R llt$R R lt%R R lt&R(R  R! llt'R(R" R# llt(R(R$ R% llt)R# u uppp i ))zÉPlugin capability declarations + consent state.

Every capability id maps 1:1 to a trust gate that already exists on the enforcing surface; ids
without an enforcing gate are deliberately never minted.
)ÚannotationsN)Ú	dataclass)ÚdatetimeÚtimezoneÚUTC)ÚAnyÚDictÚIterableÚListÚMappingÚOptionalÚTupleT)Úfrozenc                  ó:   € ] tR t^t$ RtR]R&   R]R&   R]R&   RtR# )	ÚCapabilitySpecz9One declarable capability and the legacy gate it maps to.ÚstrÚidztuple[str, ...]Úlegacy_pathÚdescription© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   ó    ÚC/home/ubuntu/.hermes/hermes-agent/hermes_cli/plugin_capabilities.pyr   r      s   ‡ áCàƒGØ Ó Ø×r   r   zdict[str, CapabilitySpec]ÚCAPABILITY_REGISTRYÚgranted_capabilitiesÚcapabilities_consentc               ó$   € V ^8„  d   QhRRRRRR/# )é   Úrawr   Úplugin_namer   Úreturnú	list[str]r   )Úformats   "r   Ú__annotate__r)   :   s!   € ÷ ñ  Sð °sð ÀYñ r   c                óî  € V '       g   . # \        V \        \        34      '       g-   \        P	                  RV\        V 4      P                  4       . # . pV  Fš  p\        V\        4      '       g   \        P	                  RW4       K1  VP                  4       pV\        9  d6   \        P	                  RWRP                  \        \        4      4      4       K�  WB9  g   K‰  VP                  V4       Kœ  	  V# )a  Normalize a manifest ``capabilities:`` value into known capability ids.

Unknown ids are dropped with a warning: they can never be granted by this build, so hiding
them from the consent screen is the fail-closed choice (the plugin must degrade gracefully).
uF   Plugin %s: manifest 'capabilities' must be a list, got %s â€” ignoringz2Plugin %s: ignoring non-string capability entry %ru9   Plugin %s: unknown capability %r (known: %s) â€” ignoringz, )Ú
isinstanceÚlistÚtupleÚloggerÚwarningÚtyper   r   ÚstripÚVALID_CAPABILITY_IDSÚjoinÚsortedÚappend)r$   r%   ÚoutÚitemÚcaps   &&   r   Úparse_declared_capabilitiesr9   :   sÂ   € ÷ Øˆ	Ü�cœD¤%˜=×)Ò)Ü�‰ØTØœ˜c›×+Ñ+ô	-ð ˆ	Ø€CÛˆÜ˜$¤×$Ò$Ü�N‰NÐOÐQ\ÔcÙØ�j‰j‹lˆØÔ*Ô*Ü�N‰NØKØ $§)¡)¬FÔ3GÓ,HÓ"IöKð Ž^Ø�J‰J�sŽOñ ð €Jr   c               ó    € V ^8„  d   QhRRRR/# )r#   ÚcapabilitiesúIterable[str]r&   r'   r   )r(   s   "r   r)   r)   V   s   € ÷ Qñ Q˜ð Q¨9ñ Qr   c                ón   € \         P                  V 4       Uu. uF  q\        9   g   K  VNK  	  up# u upi )zODeduplicated (order-preserving) subset of *capabilities* with a registry entry.)ÚdictÚfromkeysr2   )r;   Úcs   & r   Ú_knownrA   V   s-   € ä—}‘} \Ô2ÓPÑ2�!Ô;OÑ6O�AˆAÑ2ÑPÐPùÒPs   ˜2©2c               ó    € V ^8„  d   QhRRRR/# )r#   r;   r<   r&   r   r   )r(   s   "r   r)   r)   [   s   € ÷ =ñ = mð =¸ñ =r   c                ó®   € RP                  \        \        V 4      4      4      p\        P                  ! VP                  R4      4      P                  4       # )z?Deterministic sha256 over a capability set (order-insensitive).Ú
zutf-8)r3   r4   ÚsetÚhashlibÚsha256ÚencodeÚ	hexdigest)r;   Úcanons   & r   Úcapability_set_hashrK   [   s;   € à�I‰I”fœS Ó.Ó/Ó0€EÜ�>Š>˜%Ÿ,™, wÓ/Ó0×:Ñ:Ó<Ð<r   c               ó$   € V ^8„  d   QhRRRRRR/# )r#   Ú	plugin_idr   ÚconfigúOptional[Mapping[str, Any]]r&   r>   r   )r(   s   "r   r)   r)   c   s#   € ÷ 
ñ 
˜Sð 
Ð*Eð 
ÐQUñ 
r   c                ó2  €  TpVf   ^ RI Hp V! 4       ;'       g    / pVP                  R4      ;'       g    / P                  R4      ;'       g    / P                  V 4      ;'       g    / p\        V\        4      '       d   V# / #   \
         d    / u # i ; i)u\   ``plugins.entries.<plugin_id>`` or ``{}`` â€” never raises (unreadable state = not granted).)Úload_configÚpluginsÚentries)Úhermes_cli.configrQ   Úgetr+   r>   Ú	Exception)rM   rN   ÚcfgrQ   Úentrys   &&   r   Ú_plugin_entryrY   c   s‹   € ðØˆØŠ;Ý5Ù“-×%Ð% 2ˆCØ—'‘'˜)Ó$×*Ð*¨×/Ñ/°	Ó:×@Ð@¸b×EÑEÀiÓP×VÐVÐTVˆÜ" 5¬$×/Ò/ˆuÐ7°RÐ7øÜô ØŠ	ðús-   ‚B œB ·B ÁB Á)B ÂB ÂBÂBc               ó$   € V ^8„  d   QhRRRRRR/# )r#   rM   r   rN   rO   r&   Ú	frozensetr   )r(   s   "r   r)   r)   p   s(   € ÷ Kñ K Cð KÐ1Lð KÐXañ Kr   c                ó´   € \        W4      P                  \        4      p\        V\        4      '       g   \        4       # \        \        R V 4       4      4      # )z9The set of capabilities the user has granted this plugin.c              3  ór   "  € T F-  p\        V\        4      '       g   K  VP                  4       x € K/  	  R # 5i©N)r+   r   r1   ©Ú.0r@   s   & r   Ú	<genexpr>Ú'granted_capabilities.<locals>.<genexpr>u   s#   é € ÐI©s¨!´jÀÄC×6HœI˜AŸG™GŸI˜I«sùs   ‚7Ÿ7)rY   rU   ÚGRANTED_KEYr+   r,   r[   rA   )rM   rN   r$   s   && r   r    r    p   sB   € ä
˜	Ó
*×
.Ñ
.¬{Ó
;€CÜ�cœ4× Ò Ü‹{ÐÜ”VÑI©sÓIÓIÓJÐJr   c               ó$   € V ^8„  d   QhRRRRRR/# )r#   rX   zMapping[str, Any]Úspecr   r&   Úboolr   )r(   s   "r   r)   r)   x   s"   € ÷ ñ Ð-ð °^ð Èñ r   c                ó–   € T pVP                    F-  p\        V\        4      '       g    R# VP                  V4      pK/  	  \	        V4      # )z>True when the deprecated ``allow_*`` key for *spec* is truthy.F)r   r+   r   rU   rf   )rX   re   ÚnodeÚparts   &&  r   Ú_legacy_gate_setrj   x   s@   € à€DØ× Ô ˆÜ˜$¤×(Ò(ÚØ�x‰x˜‹~Šñ !ô �‹:Ðr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r#   rM   r   Ú
capabilityrN   rO   r&   rf   r   )r(   s   "r   r)   r)   ‚   s*   € ÷ ñ ¨ð ¸#ð ÐGbð Ðnrñ r   c                óh  € \         P                  V4      pVf   \        P                  RW4       R# \	        W4      pV\        V RRW///R7      9   d   RRreM8\        WC4      '       d%   RRV  R	R	P                  VP                  4       R
2reMRRre\        P                  RYV'       d   RMRV4       V# )z·Canonical check: is *capability* live for *plugin_id*? True via ``granted_capabilities`` OR
the deprecated-but-honored legacy ``allow_*`` key. Unknown ids / unreadable state -> False.u9   capability check for unknown id %r (plugin %s) â€” deniedFrR   rS   )rN   Tr    zlegacy key plugins.entries.Ú.z (deprecated)znot grantedzecapability_check plugin=%s capability=%s decision=%s checked_by=plugin_capability_granted evidence=%sÚallowÚdeny)
r   rU   r.   ÚdebugrY   r    rj   r3   r   Úinfo)rM   rl   rN   re   rX   ÚallowedÚevidences   &&&    r   Úplugin_capability_grantedru   ‚   s¹   € ô ×"Ñ" :Ó.€DØ‚|Ü�‰ÐPÐR\ÔhÙÜ˜)Ó,€EØÔ)¨)¸YÈÐU^ÐTfÐHgÐ<hÔiÔiØ Ð"8‘Ü	˜%×	&Ò	&Ø Ð$?À	¸{È!ÈCÏHÉHÐUY×UeÑUeÓLfÐKgÐgtÐ"u‘à! =�Ü
‡K�KØoØ¯'™w°v¸xôIð €Nr   c               ó$   € V ^8„  d   QhRRRRRR/# )r#   Úparentr>   Úkeyr   r&   r   )r(   s   "r   r)   r)   ˜   s!   € ÷ ñ ˜ð  3ð ¨4ñ r   c                ób   € V P                  V/ 4      p\        V\        4      '       g   / pW V&   V# )zA``parent[key]`` as a dict, replacing any non-dict value in place.)Ú
setdefaultr+   r>   )rw   rx   Úchilds   && r   Ú_child_dictr|   ˜   s2   € à×Ñ˜c 2Ó&€EÜ�eœT×"Ò"ØˆØˆs‰Ø€Lr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r#   rM   r   Úgrantedr<   Údeclaredr&   ÚNoner   )r(   s   "r   r)   r)   ¡   s/   € ÷ Sñ S˜cð S¨Mð SÀ]ð SÐW[ñ Sr   c                ó  € ^ RI HpHp V! 4       p\        \        \        VR4      R4      V 4      pVP	                  \
        4      p\        V\        4      '       d   \        V4      M. \        V4      ,           p\        \        R V 4       4      4      V\
        &   R\        \        V4      4      R\        P                  ! \        4      P                  RR7      /V\        &   V\
        ,           F6  p	\         V	,          P"                  Ev r«TpV
 F  p\        WÍ4      pK  	  R	WË&   K8  	  V! V4       \$        P'                  R
T RP)                  V\
        ,          4      ;'       g    RV\        ,          R,          R,          4       R# )zÿPersist a consent decision: ``granted_capabilities`` (union with prior grants), the consent
record (hash of the declared set the user saw + UTC timestamp), and the legacy ``allow_*`` key
for each grant so existing enforcement sites keep working unchanged.)rQ   Úsave_configrR   rS   c              3  óV   "  € T F  p\        V\        4      '       g   K  Vx € K!  	  R # 5ir^   )r+   r   r_   s   & r   ra   Ú!record_consent.<locals>.<genexpr>ª   s   é € Ð&O±&¨Q¼JÀqÌ#×<N§q¢q³&ùs   ‚)Ÿ
)ÚhashÚ
granted_atÚseconds)ÚtimespecTz8capability_consent plugin=%s granted=%s declared_hash=%sÚ,z(none):Né   NN)rT   rQ   r‚   r|   rU   rc   r+   r,   rA   r4   rK   r   Únowr   Ú	isoformatÚCONSENT_KEYr   r   r.   rr   r3   )rM   r~   r   rQ   r‚   rN   rX   ÚpreviousÚmergedr8   ÚparentsÚleafrh   ri   s   &&&           r   Úrecord_consentr’   ¡   s5  € ÷ ;Ù‹]€FÜœ¤K°¸	Ó$BÀIÓNÐPYÓZ€EØ�y‰yœÓ%€HÜ *¨8´T× :Ò :Œd�8ŒnÀÄfÈWÃoÕU€FÜ¤Ñ&O±&Ó&OÓ OÓP€EŒ+ÑàÔ#¤F¨8Ó$4Ó5Ø”h—l’l¤3Ó'×1Ñ1¸9Ð1ÓEð€EŒ+Ñð
 ”[×!Ð!ˆÜ,¨SÕ1×=Ñ=‰ˆØˆÛˆDÜ˜tÓ*ŠDñ àˆ‹
ñ "ñ �ÔÜ
‡K�KØBÀIØ�‰�”{Õ#Ó$×0Ð0¨°%¼Õ2DÀVÕ2LÈSÕ2QöSr   c               ó$   € V ^8„  d   QhRRRRRR/# )r#   rM   r   rN   rO   r&   zOptional[str]r   )r(   s   "r   r)   r)   ½   s#   € ÷ 3ñ 3˜Cð 3Ð)Dð 3ÐP]ñ 3r   c                óÔ   € \        W4      P                  \        4      p\        V\        4      '       d   VP                  R4      MRp\        V\
        4      '       d   V'       d   V# R# )z<Return the stored consent hash, or None when absent/corrupt.r…   N)rY   rU   r�   r+   r>   r   )rM   rN   ÚconsentÚhs   &&  r   Úconsent_hashr—   ½   sL   € ä˜IÓ.×2Ñ2´;Ó?€GÜ)¨'´4×8Ò8ˆ�‰�FÔ¸d€AÜ˜1œc×"Ò"§qˆ1Ð2¨dÐ2r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r#   rM   r   r   r<   rN   rO   r&   r'   r   )r(   s   "r   r)   r)   Ä   s,   € ÷ =ñ =Øð=Ø+ð=Ø5Pð=àñ=r   c                óh   € \        W4      p\        V4       Uu. uF  qDV9  g   K  VNK  	  up# u upi )z›Declared-but-ungranted capabilities: everything at first consent, only the additions on an
update re-consent (they must be re-consented before going live).)r    rA   )rM   r   rN   r~   r@   s   &&&  r   Úpending_capabilitiesrš   Ä   s4   € ô
 # 9Ó5€GÜ˜hÔ'Ó<Ñ'�!°GÑ+;�AˆAÑ'Ñ<Ð<ùÒ<s   ™/¦/c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r#   rM   r   r   r<   rN   rO   r&   rf   r   )r(   s   "r   r)   r)   Í   s2   € ÷ Mñ MØðMØ+ðMØ5PðMà	ñMr   c                ó^   € \        W4      pVRJ ;'       g    V\        \        V4      4      8g  # )zXTrue when the declared set differs from what the user consented to (or never consented).N)r—   rK   rA   )rM   r   rN   Ústoreds   &&& r   Údeclared_set_changedrž   Í   s0   € ô ˜)Ó,€FØ�Tˆ>×LÐL˜VÔ':¼6À(Ó;KÓ'LÑLÐLr   ))ztools.override)Úallow_tool_overrideuv   Replace built-in tools (e.g. shell_exec, write_file) â€” an override can intercept everything routed through that tool)zllm.provider_override)ÚllmÚallow_provider_overridez^Run host-owned LLM calls against a provider other than your active one (uses your credentials))zllm.model_override)r    Úallow_model_overridezLChoose which model host-owned LLM calls use (spend follows the chosen model))zllm.agent_id_override)r    Úallow_agent_id_overridez/Attribute its LLM calls to a different agent id)zllm.profile_override)r    Úallow_profile_overridez,Run LLM calls under a different auth profile)zllm.task_override)r    Úallow_task_overridezDRoute its LLM calls through the host's built-in auxiliary task lanes)zgateway.platform_actions)Úallow_platform_actionszkAct on connected chat platforms as the gateway bot (add reactions, rename threads) via ctx.platform_actions)Ú?r^   )*Ú__conditional_annotations__r   Ú
__future__r   rF   ÚloggingÚdataclassesr   r   r   r   Útypingr   r   r	   r
   r   r   r   Ú	getLoggerr   r.   r   Ú_CAPABILITY_ROWSr   r   r[   r2   rc   r�   r9   rA   rK   rY   r    rj   ru   r|   r’   r—   rš   rž   )ÚcidÚpathÚdescr¨   s   000@r   Ú<module>r²      sú   øðôõ #ã Û Ý !ß ,Ñ ,ß F× FÑ Fà	×	Ò	˜8Ó	$€ñ �$Ô÷ð ó ððBÐ ñ* AQõ2Ù@P©_¨S¸‰˜ 4Ó	(Ò(Ñ@Pó2Ð Ð.ó ñ !Ð!4Ó5Ð ð %€Ø$€÷õ8Qõ
=÷
÷Kõ÷õ,õS÷83÷=÷Mñ Mùô{2s   Á'C*