
    Pmj                        d Z ddlmZ ddlmZ dZdZ eh d          ZdZ	dZ
 eh d	          Z eh d
          Z eh d          Z eddh          ZdZd*d+dZd,dZd-dZ	 d.d/d"Zd0d%Zd1d'Zd2d(Zd2d)ZdS )3u	  Focus view — a display-only reduced-output mode.

``/focus`` answers one question the existing ``/verbose`` cycle cannot:
*"just show me my prompt and the answer — and tell me what you hid."*

``/verbose off`` already silences per-tool progress lines (the
``tool_progress_mode == "off"`` gate in ``agent/tool_executor.py`` and the
scrollback gate in ``HermesCLI._on_tool_progress``).  Focus view **composes
with** that machinery instead of duplicating it:

* turning focus ON snaps ``tool_progress_mode`` to ``"off"`` and remembers the
  mode the user had configured, so the *existing* suppression path does the
  actual hiding;
* turning focus OFF restores that remembered mode verbatim;
* on top of that, focus view adds the two things ``/verbose off`` lacks —
  a per-turn count of what was hidden plus a recovery hint, and a persistent
  ``focus`` segment in the status bar so the reduced mode is never invisible.

Everything in this module is **display-only**.  Nothing here reads or mutates
conversation history, the system prompt, tool schemas, or any request payload.
Flipping focus view must never change a single byte of what is sent to the
model — that invariant is covered by
``tests/cli/test_focus_view.py::test_model_facing_messages_identical_with_focus_on_vs_off``.
    )annotations)Optionalzdisplay.focus_viewoff>   allnewverbose)r   r   r   r   u	   ◉ focus>   1onyestrueenableenabled>   0nor   falsedisabledisabled>   showstatus? togglezUsage: /focus [on|off|status]r   modeobjectdefaultstrreturnc                    | du rdS | du rdS t          | pd                                                                          }|t          v r|S |dk    rdS |S )zCoerce a raw config/attr value into a known tool-progress mode.

    YAML 1.1 parses a bare ``off`` as ``False``, and older configs stored
    ``True``/``False`` booleans, so this mirrors ``cli.py``'s normalisation.
    Fr   Tr   r   log)r   striplowerTOOL_PROGRESS_MODES)r   r   texts      ;/home/thesage/.hermes/hermes-agent/hermes_cli/focus_view.pynormalize_tool_progress_moder%   9   sk     u}}ut||utzr??  ""((**D"""u}}uN    argcurrentbooltuple[str, Optional[bool]]c                    t          | pd                                                                          }|t          v rdS |t          v rdS |t
          v rdS |t          v rdt          |           fS dS )a`  Map a ``/focus`` argument onto an action, following the sibling toggles.

    Returns ``(action, target)`` where ``action`` is one of ``"set"``,
    ``"status"`` or ``"usage"``.  ``target`` is the requested enabled-state for
    ``"set"`` and ``None`` otherwise.  Bare ``/focus`` toggles, matching
    ``/footer`` / ``/battery`` / ``/timestamps``.
    r   )r   N)setT)r,   Fr,   )usageN)r   r    r!   _STATUS_WORDS	_ON_WORDS
_OFF_WORDS_TOGGLE_WORDSr)   )r'   r(   r#   s      r$   resolve_focus_argr2   L   s     syb>>!!''))D}~y{z|}$w--'''=r&   focus_enabledconfigured_modec                6    t          |          }| rt          S |S )uN  Return the tool-progress mode that should actually be in force.

    Focus view wins while it is on (it *is* "tool progress off" plus reporting).
    When focus is off the user's configured mode is returned untouched — this is
    what makes ``/focus off`` restore ``/verbose verbose`` rather than clobbering
    it to ``all``.
    )r%   FOCUS_TOOL_PROGRESS_MODE)r3   r4   
normalizeds      r$   effective_tool_progress_moder8   `   s%     .o>>J (''r&   Nfunction_namelast_tool_nameOptional[str]c                ^    |sdS t          |           }|t          vrdS |dk    r||k    rdS dS )a2  Would the CLI have committed a scrollback line for this tool call?

    Used to count *honestly*: if the user already had ``/verbose off``, focus
    view is hiding nothing extra and must not claim otherwise.  ``new`` mode
    skips consecutive repeats of the same tool, so the counter skips them too.
    Fr   T)r%   TOOL_PROGRESS_VISIBLE_MODES)r   r9   r:   r7   s       r$   would_display_tool_liner>   n   sN      u-d33J444uU}>>u4r&   countintc                    	 t          |           }n# t          t          f$ r Y dS w xY w|dk    rdS |dk    rdnd}d| d| dS )	zADim post-turn recovery line, or ``None`` when nothing was hidden.Nr      z	tool linez
tool linesu   ⋯  u    hidden · /focus off to show)r@   	TypeError
ValueError)r?   nnouns      r$   format_hidden_linerH      ss    JJz"   ttAvvtq&&;;lD9!99d9999s    ''r   c                    | rt           ndS )z8Status-bar segment text for focus view (empty when off).r   )FOCUS_STATUSBAR_LABEL)r   s    r$   focus_statusbar_segmentrK      s    $+3  3r&   c                    | rdnd}| r)t          |          }d| d|                                 S t          |          }d| d|                                 S )uF   Human-readable ``/focus status`` body (no ANSI — callers colour it).ONOFFzFocus view: uS    — only your prompt and the final response.
  /focus off restores tool progress: u    — tool progress: r%   upper)r   r4   staterestorer   s        r$   format_focus_statusrS      s    &DDE 
.??F5 F F4;MMOOF F	
 (88DC%CCTZZ\\CCCr&   c                V    | rdS t          |          }d|                                 S )z@Confirmation line printed when focus view is switched (no ANSI).u>   Focus view enabled — just your prompt and the final responseu'   Focus view disabled — tool progress: rO   )r   r4   r   s      r$   format_focus_toggle_messagerU      s4     POO'88DCTZZ\\CCCr&   )r   )r   r   r   r   r   r   )r'   r   r(   r)   r   r*   )r3   r)   r4   r   r   r   )N)r   r   r9   r   r:   r;   r   r)   )r?   r@   r   r;   )r   r)   r   r   )r   r)   r4   r   r   r   )__doc__
__future__r   typingr   FOCUS_CONFIG_KEYr6   	frozensetr=   r"   rJ   r/   r0   r.   r1   FOCUS_USAGEr%   r2   r8   r>   rH   rK   rS   rU    r&   r$   <module>r]      s   2 # " " " " "       (  ! 
 (i(A(A(ABB  7  $ IEEEFF	YIIIJJ
	11122	2x.))-    &   (   " %)    *	: 	: 	: 	:4 4 4 4

D 
D 
D 
DD D D D D Dr&   