§
    øžyjŸ  ã                   ó4  — U d Z ddlmZmZ ddlmZ d ed¦  «        iZeeef         e	d<   dZ
ee	d<   d	Zee	d
<   dZee	d<    ed¬¦  «         G d„ d¦  «        ¦   «         Z e¦   «         ZdZee	d<   dZee	d<   dZee	d<   dZee	d<   dZee	d<   dedz  defd„ZdS )z�Configurable budget constants for tool result persistence.

Per-tool resolution: pinned > config overrides > registry > default.
é    )Ú	dataclassÚfield)ÚDictÚ	read_fileÚinfÚPINNED_THRESHOLDSi † ÚDEFAULT_RESULT_SIZE_CHARSi@ ÚDEFAULT_TURN_BUDGET_CHARSiÜ  ÚDEFAULT_PREVIEW_SIZE_CHARST)Úfrozenc                   ó†   — e Zd ZU dZeZeed<   eZ	eed<   e
Zeed<    ee¬¦  «        Zeeef         ed<   dedeez  fd	„Zd
S )ÚBudgetConfiga|  Immutable budget constants for the 3-layer tool result persistence system.

    Layer 2 (per-result): resolve_threshold(tool_name) -> threshold in chars.
    Layer 3 (per-turn):   turn_budget -> aggregate char budget across all tool
                          results in a single assistant turn.
    Preview:              preview_size -> inline snippet size after persistence.
    Údefault_result_sizeÚturn_budgetÚpreview_size)Údefault_factoryÚtool_overridesÚ	tool_nameÚreturnc                 óò   — |t           v rt           |         S || j        v r| j        |         S ddlm} |                     || j        ¬¦  «        }|t          d¦  «        k    r|S t          || j        ¦  «        S )aT  Resolve the persistence threshold for a tool.

        Priority: pinned -> tool_overrides -> registry per-tool -> default.

        The registry per-tool value is capped at ``default_result_size`` so a
        context-scaled budget (small model) actually constrains tools that
        register a large fixed ``max_result_size_chars`` (web/terminal/x_search
        all register 100K). For the default budget this is a no-op because both
        equal 100K; for a scaled-down budget it prevents a per-tool registry
        value from re-inflating the cap past the model's window (#23767).
        r   )Úregistry)Údefaultr   )r   r   Útools.registryr   Úget_max_result_sizer   ÚfloatÚmin)Úselfr   r   Úregistry_values       ú9/home/ragecks/.hermes/hermes-agent/tools/budget_config.pyÚresolve_thresholdzBudgetConfig.resolve_threshold%   sŽ   € ð Õ)Ð)Ð)Ý$ YÔ/Ð/Ø˜Ô+Ð+Ð+ØÔ& yÔ1Ð1Ø+Ð+Ð+Ð+Ð+Ð+Ø!×5Ò5°iÈÔIaÐ5ÑbÔbˆØ�U 5™\œ\Ò)Ð)Ø!Ð!Ý�> 4Ô#;Ñ<Ô<Ð<ó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   ÚintÚ__annotations__r
   r   r   r   r   Údictr   r   Ústrr   r    © r!   r   r   r      sž   € € € € € € ðð ð  9Ð˜Ð8Ð8Ñ8Ø0€K�Ð0Ð0Ñ0Ø2€L�#Ð2Ð2Ñ2Ø%* U¸4Ð%@Ñ%@Ô%@€N�D˜˜c˜”NÐ@Ð@Ñ@ð=¨3ð =°3¸±;ð =ð =ð =ð =ð =ð =r!   r   é   Ú_CHARS_PER_TOKENg333333Ã?Ú_PER_RESULT_WINDOW_FRACTIONg333333Ó?Ú_PER_TURN_WINDOW_FRACTIONi@  Ú_MIN_RESULT_SIZE_CHARSi€>  Ú_MIN_TURN_BUDGET_CHARSÚcontext_lengthNr   c                 ó^  — | r| dk    rt           S | t          z  }t          |t          z  ¦  «        }t          |t          z  ¦  «        }t          t          t          |t          ¦  «        ¦  «        }t          t          t          |t          ¦  «        ¦  «        }t          ||t          ¬¦  «        S )a«  Return a BudgetConfig scaled to the active model's context window.

    The fixed defaults (100K result / 200K turn chars) are correct for large
    (200K+ token) models but blind to small ones: on a 65K-token model a single
    tool result persisted at the 100K-char threshold, or a 200K-char turn
    budget (~50K tokens), can by itself approach or exceed the whole window and
    force an oversized request (#23767).

    Scaling keeps large models byte-identical to today (the proportional value
    is clamped to the existing defaults as a CAP) while shrinking the budget for
    small models proportionally to their window, floored so a usable preview
    always survives.
    r   )r   r   r   )ÚDEFAULT_BUDGETr,   r&   r-   r.   Úmaxr/   r   r	   r0   r
   r   r   )r1   Úwindow_charsÚ
per_resultÚper_turns       r   Úbudget_for_context_windowr8   T   s¥   € ð ð ˜^¨qÒ0Ð0ÝÐà!Õ$4Ñ4€LÝ�\Õ$?Ñ?Ñ@Ô@€JÝ�<Õ";Ñ;Ñ<Ô<€Hõ Õ+­S°Õ=VÑ-WÔ-WÑXÔX€JÝÕ)­3¨xÕ9RÑ+SÔ+SÑTÔT€HåØ&ØÝ/ðñ ô ð r!   )r%   Údataclassesr   r   Útypingr   r   r   r)   r'   r	   r&   r
   r   r   r3   r,   r-   r.   r/   r0   r8   r*   r!   r   ú<module>r;      s�  ððð ð ð
 )Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø Ð Ð Ð Ð Ð ð
 ���u‘”ð'Ð �4˜˜U˜
Ô#ð ð ñ ð ")Ð ˜3Ð (Ð (Ñ (Ø!(Ð ˜3Ð (Ð (Ñ (Ø"'Ð ˜CÐ 'Ð 'Ñ 'ð €�$ÐÑÔð"=ð "=ð "=ð "=ð "=ñ "=ô "=ñ Ôð"=ðL �‘”€ð Ð �#Ð Ð Ñ ð &*Ð ˜UÐ )Ð )Ñ )Ø#'Ð ˜5Ð 'Ð 'Ñ 'ð $Ð ˜Ð #Ð #Ñ #Ø$Ð ˜Ð $Ð $Ñ $ð¨c°D©jð ¸\ð ð ð ð ð ð r!   