+
    lHàj9#  ã                  ó  € R t ^ RIHt ^ RIt^ RIHt ^ RIHt ^ RIH	t	H
t
HtHt ]! 0 Rm4      t]! 0 Rm4      t ! R R]4      tR R ltR	R
/R R lltR R ltR	R
R^ /R R lltR R ltRR	R
/R R llltR	R
/R R lltR# )aü  Delegation-owned output projections, using the existing text redactor.

Child output is scrubbed before it is shortened or handed to another consumer.
Parent-authored instructions and delivery coordinates retain their exact values.
Live streamed text needs its own buffering policy and does not pass through here.

Policy (``force``): copies that leave the process or persist (spill files, the
async_delegations rows and their replay/recovery, worker IPC, memory providers,
lifecycle hooks) are always scrubbed (``force=True``, the default). The parent
model's own in-process copy and live progress honour ``security.redact_secrets:
false`` (``force=False``), the same as any other tool result the parent reads.
Registered vault values are scrubbed in both modes.
)ÚannotationsN)ÚAny)ÚREDACTION_UNAVAILABLEÚis_secret_field_nameÚredact_for_egressÚredact_sensitive_textc                  ó&   € ] tR t^7t$ RtR]R&   RtR# )Ú_ParentCopyaJ  The parent's own (opt-out) text carrying the forced projection of the same output.

The forced copy is made from the complete output *before* the parent's copy is
budget-trimmed: a head/tail cut can drop a PEM ``BEGIN`` marker and leave a key body
the text redactor no longer recognizes. Persistent/external sinks read ``forced``.ÚstrÚforced© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   ó    Ú?/home/ubuntu/.hermes/hermes-agent/tools/delegation_redaction.pyr	   r	   7   s   ‡ ñZð ‡Kr   r	   c               ó$   € V ^8„  d   QhRRRRRR/# )é   Útextr
   r   Úreturnr   )Úformats   "r   Ú__annotate__r   A   s!   € ÷ ñ �cð  3ð ¨3ñ r   c                ó8   € W8X  d   V # \        V 4      pWn        V# )z\``text`` for the parent, remembering ``forced`` for persistent sinks (plain str when equal).)r	   r   )r   r   Úcarriers   && r   Úparent_copyr   A   s    € à„~ØˆÜ˜$Ó€GØ„NØ€Nr   ÚforceTc               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r   Úboolr   r
   r   )r   s   "r   r   r   J   s!   € ÷ 	%ñ 	%˜Cð 	%¨4ð 	%¸3ñ 	%r   c               ó"  € \        V \        4      '       d   V'       d   V P                  # T # V'       g   \        P                  ! 4       '       d   \        V 4      #  \        \        T ;'       g    R4      4      #   \         d
    \        u # i ; i)zLScrub one child-produced string. ``force=False`` honours the user's opt-out.Ú )
Ú
isinstancer	   r   Ú_redactÚ_redact_enabledr   r   r
   Ú	Exceptionr   )r   r   s   &$r   Úredact_child_textr(   J   sk   € ä�$œ×$Ò$ß#ˆt�{‰{Ð-¨Ð-ß”×'Ò'×)Ò)Ü  Ó&Ð&ð%Ü$¤S¨¯¨°£_Ó5Ð5øÜô %Ü$Ò$ð%ús   ÁA: Á/
A: Á:BÂBc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úkeyr
   Úvaluer   r!   r   r   )r   s   "r   r   r   V   s.   € ÷ Dñ D�sð D 3ð D¨tð D¸ñ Dr   c                óÐ  € \        WR7      pW18w  g   \        V 4      '       g   V# \        P                  ! W/4      p\        WBR7      pWT8X  d   V#  \        P                  ! V4      p\        T\        4      '       d4   \        T4      ^8X  d$   \        \        TP                  4       4      R4      MRp\        T\        4      '       d   T# \        #   \
         d
    \        u # i ; i)zþRedact a string value with its key as context: once a JSON summary is parsed apart, the
key-gated ``"api_key": "<opaque>"`` rule no longer sees the key, so credential-named fields
get that pass on a one-field document. Fails closed for those fields only.©r   N)r(   r   ÚjsonÚdumpsÚloadsÚ
ValueErrorr   r$   ÚdictÚlenÚnextÚiterÚvaluesr
   )r*   r+   r   ÚcleanedÚrawÚscrubbedÚprobeÚonlys   &&&     r   Ú_redact_fieldr<   V   s½   € ô   Ô3€GØÔÔ3°C×8Ò8ØˆÜ
�*Š*�c�\Ó
"€CÜ  Ô2€HØ„Øˆð%Ü—
’
˜8Ó$ˆô 0:¸%Ä×/FÒ/FÌ3ÈuË:ÐYZÌ?Œ4”�U—\‘\“^Ó$ dÔ+Ð`d€DÜ˜d¤C×(Ò(ˆ4ÐCÔ.CÐCøô ô %Ü$Ò$ð%ús   ÁC ÃC%Ã$C%Ú_depthc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r+   r   r   r!   r=   Úintr   r   )r   s   "r   r   r   i   s(   € ÷ !ñ !˜cð !¨Tð !À#ð !Ècñ !r   c               óh  € V^@8”  d   \         # \        V \        4      '       d   \        WR7      # \        V \        4      '       dw   V P                  4        UUu/ uFY  w  r4\        \        V4      VR7      \        V\        4      '       d   \        \        V4      WA4      M\        WAV^,           R7      bK[  	  upp# \        V \        \        34      '       d%   V  Uu. uF  p\        WAV^,           R7      NK  	  up# V e"   \        V \        \        \        34      '       d   V # \         # u uppi u upi )zQCopy JSON-shaped child data; unsupported or excessively deep values are withheld.r-   )r   r=   )r   r$   r
   r(   r2   Úitemsr<   Úredact_child_valueÚlistÚtupler!   r?   Úfloat)r+   r   r=   r*   Úitems   &$$  r   rB   rB   i   s  € à�„{Ü$Ð$Ü�%œ×ÒÜ  Ô4Ð4Ü�%œ×Òð #Ÿ[™[œ]ô
ñ +‘	�ô œc #›h¨eÔ4ä˜d¤C×(Ò(ô œc #›h¨Ô4ä'¨À&È1Å*ÔMòNñ
 +ò
ð 	
ô �%œ$¤˜×'Ò'ÙUZÓ[ÑUZÈTÔ" 4¸VÀa½Z×HÑUZÑ[Ð[Ø‚}œ
 5¬4´´eÐ*<×=Ò=ØˆÜ Ð ùó
ùò \s   ÁAD)ÃD/c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úsummaryr   Ú
structuredr!   r   r   r   )r   s   "r   r   r      s(   € ÷ 4ñ 4˜Cð 4¨Tð 4¸$ð 4À3ñ 4r   c                ó4  € \        V \        4      '       d   \        WR7      # V'       dÑ   \        V \        4      '       d»   ^ RIHp V! V 4      pV'       d   V P                  V4      MRpRp V^ 8¼  d   \        P                  ! V4      MRpV^ 8¼  di   V RV W\        V4      ,           R r‡\        WbR7      p	W–8X  d   TM\        P                  ! V	RR7      p
\        WrR7      V
,           \        W‚R7      ,           # \        WR7      #   \         d    Rp LŠi ; i)aí  Structured (schema) summaries are redacted per value and re-serialized: a text
pass can eat JSON delimiters (``KEY=***`` swallowing the closing quote and comma)
and break an answer that was valid. The JSON is located with the validator's own
extraction grammar (code fence / surrounding prose), so every wrapper the validator
accepts stays accepted; the wrapper text gets the text pass. Unchanged output keeps
its original formatting; anything without a parseable candidate gets the text pass.r-   )Úextract_json_candidateNF)Úensure_asciiéÿÿÿÿ)r$   r	   r(   r
   Útools.delegation_output_schemarK   Úfindr.   r0   r1   r3   rB   r/   )rH   rI   r   rK   Ú	candidateÚstartÚparsedÚprefixÚsuffixr7   Úbodys   &&&        r   Úredact_summaryrV      sî   € ô �'œ;×'Ò'Ü  Ô6Ð6ß”j ¬#×.Ò.ÝIá*¨7Ó3ˆ	ß+4�—‘˜YÔ'¸"ˆØˆð	Ø.3°q¬j”T—Z’Z 	Ô*¸dˆFð �AŒ:Ø$ V e˜_¨g¼cÀ)»nÕ6LÐ6MÐ.N�FÜ(¨Ô=ˆGØ 'Ô 1‘9´t·z²zÀ'ÐX]Ô7^ˆDÜ$ VÔ9¸DÕ@ÔCTÐU[ÔCiÕiÐiÜ˜gÔ3Ð3øô ô 	ØŠEð	ús   Á-D ÄDÄDc               ó$   € V ^8„  d   QhRRRRRR/# )r   Úresultúdict[str, Any]r   r!   r   r   )r   s   "r   r   r   š   s"   € ÷ 1ñ 1 ð 1Èdð 1Ð^lñ 1r   c          	     óT  € \        V\        4      ;'       g    RV 9   p/ pV P                  4        F–  w  rVVR8X  dY   \        V\        4      '       dC   V Uu. uF1  p\        V\        4      '       d   \	        WrR7      M\        WrR7      NK3  	  upWE&   Kd  VR8X  d   \        WcV4      WE&   K{  V\        9   d   TM\        WbR7      WE&   K˜  	  RV 9   d¿   VP                  R4      V P                  R4      8w  dš   RR.r˜\        V\        4      '       d<   ^ RI	H
p
  VP                  R4      pT
! \        V\        4      '       d   TMRV4      w  r‰W„R&   VP                  R
R4       VP                  RR4       V'       g   \        W’R7      VR
&   RVR&   V# u upi   \         d    R	.p	 L[i ; i)ak  Project a result or batch, preserving accounting and host-owned model/task identity.

Revalidation here is only for a summary changed by redaction. General schema
revalidation after annotations/truncation belongs to the output-schema owner.
Old durable entries do not retain the schema, so their previous positive verdict
cannot certify a newly redacted summary.
Úschema_validÚresultsr-   rH   FzOThe redacted summary has not been validated against the original output_schema.)Úvalidate_outputr#   z9Output validation was unavailable after secret redaction.Úschema_errorsNÚschema_notezTSecret redaction changed the delivered summary; do not treat it as validated output.)r$   r2   rA   rC   Úredact_child_resultrB   rV   Ú_RESULT_METADATAÚgetrN   r]   r
   r'   Úpop)rX   Úoutput_schemar   rI   r7   r*   r+   ÚentryÚvalidÚerrorsr]   rH   s   &&$         r   r`   r`   š   s§  € ô ˜M¬4Ó0×LÐL°NÀfÑ4L€JØ€GØ—l‘l–n‰
ˆØ�)Ô¤
¨5´$× 7Ò 7ñ
 #ó	ñ #�Eô ˜e¤T×*Ò*ô $ EÕ7ä'¨Ô;ò<ñ #ñ	ˆG‹Lð �IÔÜ)¨%¸UÓCˆG‹Lð Ô 0Ô0‘Ô6HÈÔ6\ð ‹Lñ %ð ˜Ô G§K¡K°	Ó$:¸f¿j¹jÈÓ>SÔ$Sààaðð ô �m¤T×*Ò*ÝFðWØ!Ÿ+™+ iÓ0�Ù /Ü)¨'´3×7Ò7‘G¸RÀó!‘�ð
 #(�ÑØ�‰�O TÔ*Ø�‰�M 4Ô(ßÜ'9¸&Ô'NˆG�OÑ$àfð �MÑ"ð €NùòKøô6 ô WØUÐV’ðWús   Á7FÄ4F ÆF'Æ&F'c               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚeventrY   r   r!   r   r   )r   s   "r   r   r   Î   s!   € ÷ ñ  >ð ¸Tð È^ñ r   c               ó  € \        V P                  4        UUu/ uF  w  r#V\        9  g   K  W#bK  	  uppVR7      pTP                  V P                  4        UUu/ uF  w  r#V\        9   g   K  W#bK  	  upp4       V# u uppi u uppi )zRScrub output while leaving parent instructions and routing outside the projection.r-   )r`   rA   Ú_PARENT_EVENT_FIELDSÚupdate)ri   r   r*   r+   r7   s   &$   r   Úredact_completion_eventrm   Î   s|   € ä!Ø&+§k¡k¤mÔW¡m™
˜°sÔBVÑ7VŒˆŠ¡mÒWÐ_dô€Gð ‡N�NØ&+§k¡k¤mÔS¡m™
˜°sÔ>RÑ7RŒˆŠ¡mÒSôð €Nùó 	Xùó 	Ts   ™A?
­A?
ÁB
Á/B
>   ÚgoalÚroleÚtypeÚgoalsÚgroupÚmodelÚcontextÚuser_idÚscope_idÚtoolsetsÚ	user_nameÚsession_keyÚcompleted_atÚdelegation_idÚdispatched_atÚorigin_session_idÚparent_session_idÚorigin_ui_session_id>   rr   rs   ÚstatusÚ
task_indexÚ_child_roleÚexit_reason)N)r   Ú
__future__r   r.   Útypingr   Úagent.redactÚredactr%   r   r   r   r   Ú	frozensetrk   ra   r
   r	   r   r(   r<   rB   rV   r`   rm   r   r   r   Ú<module>r‰      s£   ðñõ #ã Ý å ÷ó ñ !òóÐ ñ, ÚLóÐ ô
�#ô õð	%°$÷ 	%õDð&!°Dð !È÷ !õ,4ñ61ÐUY÷ 1ð 1ðhÀD÷ ñ r   