+
    lHàjJ   ã                   óZ   € R t ^ RIt^ RIt]! 0 R	m4      tRtR R ltR R ltR
R R lltR# )ul  macOS ``open`` frontmost raise-ladder for the terminal tool.

Split out of ``tools/terminal_tool.py`` (PR #95286, Jackal991): a pure,
deterministic string rewrite â€” no subprocess calls at transform time â€” that
appends a verified raise-ladder to file-opening ``open`` invocations so the
opened document lands in front of the Hermes window instead of behind it.
Nz"'"$_H_APP"'"c                ó0   € V ^8„  d   QhR\         R\         /# )é   ÚscriptÚreturn©Ústr)Úformats   "ÚC/home/ubuntu/.hermes/hermes-agent/tools/terminal_tool_macos_open.pyÚ__annotate__r
   .   s   € ÷ 2ñ 2œ3ð 2¤3ñ 2ó    c                ó   € RV  R2# )zÿWrap an AppleScript snippet in an `osascript -e` invocation.

``script`` may reference the target app via the ``_APP_SPLICE`` shell
splice (``$_H_APP``). Errors are suppressed so a swallowed AppleEvent
simply falls through to the next rung of the ladder.
zosascript -e 'z' 2>/dev/null© )r   s   &r	   Ú_osascript_appr   .   s   € ð ˜F˜8 =Ð1Ð1r   c                óJ   € V ^8„  d   QhR\         R,          R\         R\         /# )r   ÚappNÚfiler   r   )r   s   "r	   r
   r
   8   s*   € ÷ Jñ J¬¨d­
ð J¼#ð JÄ#ñ Jr   c                óp  € V e   R\         P                  ! V 4       2pMRp\         P                  ! V4      p\        R\        ,           R,           4      p\        R\        ,           4      p\        R4      pRpRpR	V R
2p	Rp
RV RV RV
 RV R2	pV RV RV RV RV RV RV RV	 RV RV RV RV RV 2# )a<  Build the shell raise-ladder appended after a macOS ``open`` command.

The ladder verifies the target app is frontmost and escalates through
progressively more forceful activation mechanisms, then settles ~0.8s,
re-checks ``frontmost``, and re-asserts once to absorb a queued activation
from another app. Each rung is verified before moving on.

Args:
    app: The target application name (from ``open -a <App>``), or None for
        a bare ``open <file>`` where the app is resolved at runtime from
        the frontmost process.
    file: The file path that was opened.
z_H_APP=zˆ_H_APP="$(osascript -e 'tell application "System Events" to get name of first application process whose frontmost is true' 2>/dev/null)"ztell application z to activatezItell application "System Events" to get frontmost of application process zHtell application "System Events" to set visible of every process to truez7lsappinfo find "$_H_APP" 2>/dev/null | awk '{print $1}'z<[ -n "$_H_ASN" ] && lsappinfo setfront "$_H_ASN" 2>/dev/nullzopen -a "$_H_APP" z 2>/dev/nullz|osascript -e 'tell application "System Events" to get name of first application process whose frontmost is true' 2>/dev/nullzif z; then echo open: z# is now frontmost; else _H_FOCUS=$(z); echo open: zL opened but another application holds focus; echo "frontmost: $_H_FOCUS"; fiz; if ! z; then z; sleep 0.2; if ! z; then _H_ASN=$(z); z; sleep 0.2; ú; z; fi; fi; fi; sleep 0.8; if ! z; sleep 0.4; fi; )ÚshlexÚquoter   Ú_APP_SPLICE)r   r   Ú
app_assignÚfile_qÚactivateÚ	frontmostÚ
unminimiseÚasnÚsetfrontÚreopenÚfrontmost_nameÚreports   &&          r	   Ú_build_macos_open_raise_ladderr!   8   sA  € ð ‚ØœuŸ{š{¨3Ó/Ð0Ð1‰
ðð 	ô
 �[Š[˜Ó€FäÐ1´KÕ?À.ÕPÓQ€HÜØSÜ
õ	ó€Iô  ØRó€Jð
 F€CØM€Hð $ F 8¨<Ð8€Fð	Ið ð
 ˆiˆ[Ð*¨6¨(ð 3Ø)Ð*ð +Ø�Xð *ð	+ð ð ˆ,ð Øˆ{˜'Øˆ*ð Øˆ{ð Ø�5˜˜H˜:ð &Øˆ{˜'Øˆ(�- 
˜|¨2¨h¨Zð 8ð
 ˆ{˜' ( Ð+<Øˆ(ð	ðr   c                óf   € V ^8„  d   QhR\         R,          R\         R,          R\         R,          /# )r   ÚcommandNÚsystemr   r   )r   s   "r	   r
   r
   …   s0   € ÷ ;"ñ ;"¬3°­:ð ;"¼sÀT½zð ;"ÔUXÐ[_ÕU_ñ ;"r   c                óV  € Ve   TM\         P                  ! 4       R8w  d   V # V f   V #  \        P                  ! V 4      pT'       d   T^ ,          R8w  d   T # TR,          pT'       g   T # T^ ,          pTP                  R4      '       df   T\        9   d   T # TR8X  dP   \        T4      ^8  d   T # T^,          T^,          reTP                  R4      '       d   T # \        T4      ^8w  d   T # MT # TpRp\        T4      ^8w  d   T # \        YV4      pT  RT 2#   \         d    T u # i ; i)a6  Append a frontmost raise-ladder to a macOS ``open`` command.

On macOS, ``open <file>`` / ``open -a <App> <file>`` returns exit 0 and
genuinely opens the document, but the window can land BEHIND the Hermes
desktop window (Hermes is typically maximised), so the user sees nothing
happen while the agent reports success. This transform appends a verified
raise-ladder that brings the opened app to the front.

The transform is a pure, deterministic string rewrite (no subprocess calls
at transform time) so it is unit-testable on any OS by passing ``system``
as data (``"Darwin"`` to exercise the ladder, ``"Linux"`` to prove the
no-op). The actual osascript/lsappinfo calls happen at runtime inside the
rewritten shell command.

Conservative: only transforms a bare ``open <file>`` or
``open -a <App> <file>``. Never transforms ``open`` with no args, the
non-file-opening flags (``-R``/``-e``/``-t``/``-f``/``-W``/``-n``/``-g``/
``-h``/``-b``/``-D``), ``open -a <App>`` with no file, compound commands,
or any non-``open`` command. The original ``open`` runs exactly as written.
NÚDarwinÚopen:é   NNÚ-z-ar   )	Úplatformr$   r   ÚsplitÚ
ValueErrorÚ
startswithÚ_MACOS_OPEN_NO_TRANSFORM_FLAGSÚlenr!   )r#   r$   ÚtokensÚargsÚfirstr   r   Úladders   &&      r	   Ú_transform_macos_open_commandr4   …   s0  € ð* Ò$‰¬(¯/ª/Ó*;ÀÔHØˆØ‚ØˆðÜ—’˜WÓ%ˆ÷ �V˜A•Y &Ô(Øˆà�"�:€DßØˆØ��G€Eà×Ñ˜×ÒØÔ2Ô2ØˆNØ�DŒ=ä�4‹y˜1Œ}Ø�Ø˜Q�  a¥�Ø�‰˜s×#Ò#Ø�Ü�6‹{˜aÔØ�ð  ð ˆNð ˆØˆÜˆv‹;˜!ÔØˆNä+¨CÓ6€FØˆY�b˜˜Ð!Ð!øôA ô ØŠðús   ªD ÄD(Ä'D(>
   ú-Dú-Rú-Wú-bú-eú-fú-gú-hú-nú-t)N)	Ú__doc__r*   r   Ú	frozensetr.   r   r   r!   r4   r   r   r	   Ú<module>rA      s?   ðñó Û ñ4 "+Ú@ó"Ð ð  €õ2õJ÷Z;"ñ ;"r   