+
    jHàj" ã                   ó”  a € ERC Et»0 t R t^ RIt^ RIt^ RIHt ^ RIHtHt ^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIHtHt ]P6                  R8X  d²   0 ERDmt]! ]P<                  P?                  RR	4      PA                  ]PB                  4      4      t"]]",
          t#]#'       da   ]P<                  P?                  RR	4      ]PB                  ,           ]PB                  PI                  ]%! ]#4      4      ,           ]P<                  R&   ]! ]&4      PN                  PN                  PQ                  4       t)^ R
I*H+t+H,t, ^ RI-H.t. ^ RI/H0t0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8H9t9 ^ RI:H;t;H<t<H=t=H>t>H?t?H@t@HAtA ^ RIBHCtCHDtDHEtEHFtFHGtGHHtHHItIHJtJ ^ RIKHLtLHMtM ^ RINHOtP ]
P¢                  ! ]R4      tS]T! RRRRR7      tU]! RR7       ! R R4      4       tV]! RR7       ! R R4      4       tW]! RR7       ! R R4      4       tXERER R lltYR R  ltZR! R" lt[R# R$ lt\R%R/R& R' llt]R%R/R( R) llt^R*t_R+t`R,taR-tb]c! 4       tdERFR/ R0 llteR1 R2 ltfERFR3 R4 lltgR5R.R6^R7R8R9R/R: R; llthR<]bR=RR>R.R?^R@R8/RA RB lltiRCRDRERD/RF RG lltjRH RI ltkRJ RK ltlRL RM ltmERGRN RO lltnRP RQ ltoRR RS ltpRT RU ltqRV RW ltrERHRX RY lltsERIRZR/R[ R\ lllttR] R^ ltuR_RR`R/Ra Rb lltvRc Rd ltwRe Rf ltxRg Rh ltyERIRi Rj lltzRk Rl lt{^xt| Rm Rn lt}Ro Rp lt~RqRR=R/Rr Rs lltRt Ru lt€ERERv Rw llt�Rx Ry lt‚Rz R{ ltƒR| R} lt„R~ R lt…ERER€ R� llt†R‚ Rƒ lt‡ERJR„ R… lltˆR† R‡ lt‰Rˆ R‰ ltŠRŠ R‹ lt‹ERERŒ R� lltŒRŽ R� lt�R� R‘ ltŽR’RR“RR5RR”R/R• R– llt�ERER— R˜ llt�R™ Rš lt‘R› Rœ lt’ERER� Rž llt“ERERŸ R  llt”ERKR¡ R¢ llt•R£ R¤ lt–R¥ R¦ lt—R§ R¨ lt˜R5^/R© Rª llt™R« R¬ ltšR­ R® lt›R¯ R° ltœERER± R² llt�R³^/R´ Rµ lltžR¶ R· ltŸR¸ R¹ lt ERIRº R» llt¡R¼ R½ lt¢R¾ R¿ lt£RÀ RÁ lt¤RÂ RÃ lt¥ERLRÄ RÅ llt¦^t§RÆ RÇ lt¨ERIRÈRÉ/RÊ RË lllt©RÌ RÍ ltªRÎt«R8t¬RÏRRÐ]«RÑ]¬/RÒ RÓ llt­RÔR/RÕ RÖ llt®^ R×INH¯t° RØ RÙ lt±RÚ RÛ lt²^ RÜI³H´t´HµtµH¶t¶ RÝ RÞ lt·ERERß Rà llt¸Rá Râ lt¹Rã Rä ltºRå Ræ lt»Rç t¼]½! 0 ERMm4      t¾Rè Ré lt¿Rê Rë ltÀRì Rí ltÁRî Rï ltÂRð Rñ ltÃRò Ró ltÄRô Rõ ltÅRötÆR÷tÇ]! Rø4      tÈRù Rú ltÉRû Rü ltÊRý Rþ ltËRÿ ER  ltÌER ER ltÍER ER ltÎERNER ER lltÏER ER ltÐER	 ER
 ltÑEREER ER lltÒ ! ER ER]Ó4      tÔ ! ER ER]Ó4      tÕER ER ltÖER ER lt×ER ER ltØER ER ltÙER ER ltÚER ER ltÛER ER ltÜEROER ER  lltÝERPER! ER" lltÞER# ER$ ltßER% ER& ltàER'R/ER( ER) lltáER* ER+ ltâEREER, ER- lltãR’R/ER. ER/ lltäEREER0 ER1 lltåER2 ER3 ltæER4 ER5 ltçERQtè] ^ k ERRté] ^k ER6 ER7 ltêER8 ER9 ltëER: ER; ltìER< ER= ltíERSER> ER? lltîER@ ERA ltïERB ERC ltðERD ERE ltñERIERF ERG lltòERH ERI ltóERJ ERK ltôERL ERM ltõERTERN ERO lltöERIERP ERQ llt÷ERR ERS ltøERT ERU ltùERUERV ERW lltúERX ERY ltûERZ ER[ ltüER\ ER] ltýER^ ER_ ltþER` ERa ltÿERb ERc lEt ERIERd ERe llEtERf ERg lEtERIERh ERi llEtERj ERk lEtERIERl ERm llEtERn ERo lEtERIERp ERq llEtERr ERs lEtR’RERtR/ERu ERv llEt	ERKERw ERx llEt
ERy ERz lEtERVEtER{ ER| lEtER} ER~ lEtEREER ER€ llEtEREER� ER‚ llEtEREERƒ ER„ llEtERIR’R/ER… ER† lllEtERIR’R/ER‡ ERˆ lllEtER‰ ERŠ lEtEREER‹ ERŒ llEtEREER� ERŽ llEtER� ER� lEtER‘ ER’ lEtER“ ER” lEtER• ER– lEtER— ER˜ lEtERWER™ ERš llEtER›RERœR/ER� ERž llEtEREERŸ ER  llEtEREER¡ ER¢ llEtER£ ER¤ lEt EREER¥ ER¦ llEt!EREER§ ER¨ llEt"EREER© ERª llEt#EREER« ER¬ llEt$ER­ ER® lEt%ER¯ ER° lEt&ERXER± ER² llEt'^ ER³EI(EH)Et)EH*Et*EH+Et+EH,Et,EH-Et-EH.Et.EH/Et/EH0Et0EH1Et1EH2Et2EH3Et3EH4Et4EH5Et5EH6Et6EH7Et7EH8Et8EH9Et9EH:Et:EH;Et;EH<Et<EH=Et=EH>Et>EH?Et?EH@Et@EHAEtAEHBEtBEHCEtCEHDEtDEHEEtEEHFEtFEHGEtGEHHEtHEHIEtIEHJEtJEHKEtKEHLEtLEHMEtMEHNEtNEHOEtOEHPEtPEHQEtQ ^ ER´EIREHSEtS REtT] ^k ERYER¶ ER· llEtUR5ERµ/ER¸ ER¹ llEtVR5ERµ/ERº ER» llEtWER¼ ER½ lEtXER¾ ER¿ lEtYERÀ ERÁ lEtZERIERÂ ERÃ llEt[ERIERÄ ERÅ llEt\ERIERÆ ERÇ llEt]ERÈ ERÉ lEt^EREERÊ ERË llEt_EREERÌ ERÍ llEt`ERÎ ERÏ lEtaERGERÐ ERÑ llEtbEREERÒ ERÓ llEtcEREERÔ ERÕ llEtdERÖ ER× lEteERØ ERÙ lEtfERÚ ERÛ lEtgERÜ EthERÝ ERÞ lEtiERZERß ERà llEtj^ ERáEIkEHlEtlEHmEtmEHnEtnEHoEtoEHpEtpEHqEtqEHrEtrEHsEtsEHtEttEHuEtuEHvEtvEHwEtwEHxEtxEHyEtyEHzEtzEH{Et{EH|Et|EH}Et}EH~Et~EHEtEH€Et€EH�Et�EH‚Et‚EHƒEtƒEH„Et„EH…Et…EH†Et† ERâERã]3 ERä2ERåERæ/Et‡ERç ERè lEtˆERé ERê lEt‰ERë ERì lEtŠERí ERî lEt‹ERï ERð lEtŒERñ ERò lEt�E]Ž3ERó ERô llEt�ERõR/ERö ER÷ llEt�EREERø ERù llEt‘ERIERú ERû llEt’ERü ERý lEt“ERþ Et”ERÿ ER  lEt•ER ER lEt–ER ER lEt—ER ER lEt˜ER ER lEt™ER	 ER
 lEtšER ER lEt›ER ER lEtœER Et�ER EtžER[EtŸER\ER]ER^. ER_OE]ŸO5ER`ERaERbERcERdEReERfERgERhERiERjERkERlERmERnERoERp. ERqOE]ŸOR	NERN5ERrERsERtERu/Et ER ER lEt¡ER ER lEt¢ER ER lEt£ER ER lEt¤ER ER  lEt¥ER! Et¦ER" Et§ER# Et¨ER$ ER% lEt©ER& ER' lEtªER( Et«ER) Et¬ER* ER+ lEt­EREER, ER- llEt®EREER. ER/ llEt¯ER0 Et°ERERvERERwERõERxER1ERy/Et±ERERzERER{ERõER|ER1ER}/Et²ER2 ER3 lEt³ER4 Et´ER5 EtµER6 Et¶ER7 Et·RE]�ER8E]�ER9E]žERE]¦ERE]§ERE]«ER:E]¬ER;E]°ER<E]´ER=E]µER>E]¶ER?E]·/Et¸ER@ Et¹ERIERA ERB llEtºR# (~  ztGateway subcommand for hermes CLI.

Handles: hermes gateway [run|start|stop|restart|status|install|uninstall|setup]
N)Ú
line_input)Ú_discard_dead_host_recordÚ_forget_host_gateway_probe)Ú	dataclass©ÚPath)Úgateway_service_ownerÚsetup_platformsÚposixÚPATHÚ )Úcoerce_systemd_watchdog_secondsÚload_gateway_config)Úterminate_pid)
Ú%DEFAULT_GATEWAY_RESTART_DRAIN_TIMEOUTÚEXTERNAL_GATEWAY_SUPERVISOR_ENVÚGATEWAY_FATAL_CONFIG_EXIT_CODEÚ!GATEWAY_SERVICE_RESTART_EXIT_CODEÚis_gateway_supervisor_processÚparse_cron_drain_timeoutÚ parse_restart_after_turn_timeoutÚparse_restart_drain_timeoutÚ resolve_restart_exit_wait_budgetÚ resolve_systemd_timeout_stop_sec)Úget_env_valueÚget_hermes_homeÚ
is_managedÚmanaged_errorÚread_raw_configÚsave_env_valueÚwrite_platform_config_field)Úprint_headerÚ
print_infoÚprint_successÚprint_warningÚprint_errorÚpromptÚprompt_choiceÚprompt_yes_no)ÚColorsÚcolor)Úowned_gateway_pidTúutf-8Úreplace)Úcapture_outputÚtextÚencodingÚerrors)Úfrozenc                   ót   a € ] tR t^Rt o RtRtRtRt]V 3R lR l4       t	]V 3R lR l4       t
V 3R ltRtV tR# )	ÚGatewayRuntimeSnapshotFNc                ó    <€ V ^8„  d   QhRS[ /# ©é   Úreturn©Úbool)ÚformatÚ__classdict__s   "€Ú7/home/ubuntu/.hermes/hermes-agent/hermes_cli/gateway.pyÚ__annotate__Ú#GatewayRuntimeSnapshot.__annotate__[   s   ø€ ÷ ?ñ ?™ñ ?ó    c                óT   € V P                   ;'       g    \        V P                  4      # ©N)Úservice_runningr:   Úgateway_pids©Úselfs   &r=   ÚrunningÚGatewayRuntimeSnapshot.runningZ   s!   € à×#Ñ#×>Ð>¤t¨D×,=Ñ,=Ó'>Ð>r@   c                ó    <€ V ^8„  d   QhRS[ /# r6   r9   )r;   r<   s   "€r=   r>   r?   _   s   ø€ ÷ Tñ T©dñ Tr@   c                ót   € V P                   ;'       d&    V P                  ;'       d    V P                  '       * # rB   )Úservice_installedrG   rC   rE   s   &r=   Úhas_process_service_mismatchÚ3GatewayRuntimeSnapshot.has_process_service_mismatch^   s+   € à×%Ñ%×SÐS¨$¯,©,×SÐS¸t×?SÑ?SÔ;SÐSr@   c                óx   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[S[R3,          ;R&   S[ R,          ;R&   # )r7   ÚmanagerrK   rC   .rD   NÚservice_scope)Ústrr:   ÚtupleÚint)r;   r<   s   "€r=   r>   r?   R   sO   ø‡ ‚ á�Lñ ñ Ñ#ñ ñ Ñ!ñ	 ñ
 ™˜S˜•/Ñ&ñ ñ ˜•:Ñ$ò r@   © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__rK   rC   rD   rP   ÚpropertyrG   rL   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r<   s   @r=   r4   r4   R   sK   ø‡ € ð $ÐØ!€OØ$&€LØ $€Mà÷?ó ð?ð ÷Tó ðT÷ ƒ r@   r4   c                   ó0   a € ] tR t^ct o RtV 3R ltRtV tR# )ÚProfileGatewayProcessç        c                óJ   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[;R&   # )r7   ÚprofileÚpathÚpidÚcreate_time)rQ   r   rS   Úfloat)r;   r<   s   "€r=   r>   Ú"ProfileGatewayProcess.__annotate__c   s4   ø‡ ‚ á�Lñ ñ �Jñ ñ 
�Hñ	 ñ
 Ñò r@   rT   N)rU   rV   rW   rX   re   rZ   r[   r\   r]   s   @r=   r_   r_   c   s   ø‡ € ð
 €K÷ ƒ r@   r_   c                   ó8   a € ] tR t^kt o RtRtRtV 3R ltRtV t	R# )ÚWindowsGatewayServicezBA real Windows service supervising a profile gateway process tree.r`   c                ó´   <€ V ^8„  d   Qh/ S[ ;R&   S[ ;R&   S[;R&   S[;R&   S[S[,          ;R&   S[S[S[S[3,          R3,          ;R&   S[;R&   S[;R	&   # )
r7   Únamerb   Úservice_pidÚgateway_pidÚdescendant_pids.Údescendant_identitiesÚservice_create_timeÚgateway_create_time)rQ   rS   Ú	frozensetrR   rf   )r;   r<   s   "€r=   r>   Ú"WindowsGatewayService.__annotate__k   s‚   ø‡ ‚ ñ �Iñ	 ñ
 �Lñ ñ Ññ ñ Ññ ñ ™s•^Ñ#ñ ñ !¡¡s©E zÕ!2°CÐ!7Õ8Ñ8ñ ñ Ñ$ñ ñ Ñ$ò r@   rT   N)
rU   rV   rW   rX   Ú__doc__rp   rq   rZ   r[   r\   r]   s   @r=   ri   ri   k   s   ø‡ € áLð "%ÐØ!$Ð÷ ƒ r@   ri   Fc                ó0   € V ^8„  d   QhR\         R\        /# )r7   Úall_profilesr8   )r:   Úset)r;   s   "r=   r>   r>   y   s   € ÷ Yñ Y¤Dð Y´Sñ Yr@   c           	     óv  € \        4       p\        4       '       Ed-   V '       d   RM	\        4       pRR.R.3 EF  p \        P                  ! VRVRRR.,           3R^/\
        BR	R
/B pVP                  P                  4       P                  4        F®  pVP                  4       pV'       d   V^ ,          P                  R4      '       g   K;  V^ ,          p \        P                  ! VRVRR.,           3R^/\
        BR	R
/B p\        VP                  P                  4       4      p	V	^ 8”  d   VP                  V	4       K®  K°  	  EK  	  \!        4       '       EdJ   \#        4       0p
V '       d   V
P%                  \'        4       4       \)        V
4       F1  p \+        V4      w  rÉT	f   K  T	^ 8”  g   K   TP                  T	4       K3  	  V '       dÖ    \        P                  ! RR.3R^/\
        BR	R
/B pVP,                  ^ 8X  dŸ   VP                  P                  4       P                  4        Fr  pVP                  4       p\/        V4      ^8¼  g   K%  VR,          P1                  R4      '       g   KE   \        V^ ,          4      p	V	^ 8”  d   VP                  V	4       Kr  Kt  	  V# V#   \        \        P                  3 d     EK2  i ; i  \        \        P                  3 d     EK¯  i ; i  \        P                   d     EKs  i ; i  \         d     Kë  i ; i  \        \        P                  3 d     T# i ; i)uü  PIDs managed by systemd/launchd gateway services (excluded from stale-process sweeps).

Relies on the service manager committing the new PID before the restart command returns.
``all_profiles`` widens the current profile's unit/label to the whole ``hermes-gateway*`` /
``ai.hermes.gateway*`` fleet so update/reaper never kill a sibling's service gateway as "manual".

``all_profiles`` widens the launchd branch to every installed ``ai.hermes.gateway*`` LaunchAgent â€” the
update path needs the whole fleet excluded from its sweep (#41403, #73626): sibling-profile launchd
gateways found by the (BSD-fixed) ps scan must not be misclassified as manual processes and killed.
Default-scope callers (``gateway status``, cron checks) keep seeing only the current profile's service;
the orphan reaper passes all_profiles=True for the same friendly-fire reason. The systemd branch mirrors
this: default scope filters to the current profile's exact unit name; ``all_profiles=True`` widens to
the ``hermes-gateway*`` fleet glob.
zhermes-gateway*Ú	systemctlú--userz
list-unitsz--plainz--no-legendú
--no-pagerÚtimeoutÚcheckFú.serviceÚshowz--property=MainPIDú--valueÚ	launchctlÚlistúai.hermes.gatewayéÿÿÿÿ)rw   Úsupports_systemd_servicesÚget_service_nameÚ
subprocessÚrunÚ_CAPTURE_TEXTÚstdoutÚstripÚ
splitlinesÚsplitÚendswithrS   ÚaddÚ
ValueErrorÚTimeoutExpiredÚFileNotFoundErrorÚis_macosÚget_launchd_labelÚupdateÚ"launchd_gateway_labels_for_installÚsortedÚ_locate_launchd_gateway_serviceÚ
returncodeÚlenÚ
startswith)rv   ÚpidsÚpatternÚ
scope_argsÚresultÚlineÚpartsÚsvcr   rd   ÚlabelsÚlabelÚ_domains   &            r=   Ú_get_service_pidsr¦   y   së  € ô “€Dô !×"Ó"ß'3Ñ#Ô9IÓ9KˆØ'¨Ð2°[°MÔBˆJðô $ŸšØØ# W¨i¸ÈÐUõVñð ðô $ñ	ð
  ò�ð #ŸM™M×/Ñ/Ó1×<Ñ<Ö>�DØ ŸJ™J›L�Eß ¨¨a­×(9Ñ(9¸*×(EÒ(EÙ Ø �(�CðÜ)Ÿ~š~Ø&¨&°#Ð7KÈYÐ)WÕWñ à$%ð ô ,ñ ð #(ò	 ˜ô " $§+¡+×"3Ñ"3Ó"5Ó6˜Ø œ7Ø ŸH™H SžMñ #ô ?ñ CôF ‡zƒzÜ#Ó%Ð&ˆßð �M‰MÔ<Ó>Ô?Ü˜F–^ˆEðÜ>¸uÓE‘�ð Œ 3¨¦7Ø—‘˜–ñ $÷ ðÜ#Ÿš¨°fÐ(=ÑgÀqÐgÌMÑgÐafÒg�Ø×$Ñ$¨Ô)Ø &§¡× 3Ñ 3Ó 5× @Ñ @Ö B˜Ø $§
¡
£˜Ü˜u›:¨ž?¨u°R­y×/CÑ/CÐDW×/XÔ/Xð%Ü&)¨%°­(£m Ø#&¨¤7Ø$(§H¡H¨S¦Mñ $+ñ !Cð €Kˆ4€KøôQ '¬
×(AÑ(AÐBô Ûðûä%¤z×'@Ñ'@ÐAô Ûðûô  ×,Ñ,ô Ûðûô" $.ô %Ú $ð%ûä%¤z×'@Ñ'@ÐAô Øà€KðúsŒ   ¼BKÃ
KÃA'J$Ä=KÆK*ÇA<L ÉL É0*LÊL Ê$KÊ?KËKËKËK'Ë&K'Ë*LÌLÌLÌL ÌLÌL ÌL8Ì7L8c                ó>   € V ^8„  d   QhR\         R\         R,          /# ©r7   rd   r8   N©rS   )r;   s   "r=   r>   r>   Õ   s   € ÷ 2ñ 2œð 2¤ t¥ñ 2r@   c           	     ó²  € V ^8:  d   R#  ^ RI pVP                  V 4      P                  4       ;'       g    R#   \         d     M\         d     R# i ; i\        4       '       g   \        P                  ! R4      '       g   R#  \        P                  ! RRRR\        T 4      .3R^/\        BRR/B pM"  \        \        P                  3 d     R# i ; iTP                  P                  4       pTP                   ^ 8w  g	   T'       g   R#  \#        TP%                  4       R	,          P                  4       4      pM  \&         d     R# i ; iT^ 8”  d   T# R# )
zWParent PID for ``pid``, or None. psutil first (works on Windows, where ``ps`` doesn't).NÚpsú-ozppid=ú-pr|   r}   Fr„   )ÚpsutilÚProcessÚppidÚImportErrorÚ	ExceptionÚ
is_windowsÚshutilÚwhichr‡   rˆ   rQ   r‰   r’   r‘   rŠ   r‹   r™   rS   rŒ   r�   )rd   r®   rŸ   ÚrawÚ
parent_pids   &    r=   Ú_get_parent_pidr¸   Õ   s'  € à
ˆa„xÙðÛØ�~‰~˜cÓ"×'Ñ'Ó)×1Ð1¨TÐ1øÜô ÙÜô Úðúô ‡|‚|œ6Ÿ<š<¨×-Ò-ÙðÜ—’  t¨W°d¼CÀ»HÐ EÑoÈqÐoÔTaÑoÐinÒo‰øÜœz×8Ñ8Ð9ô Úðúà
�-‰-×
Ñ
Ó
€CØ×Ñ˜AÔ§SÙðÜ˜Ÿ™Ó)¨"Õ-×3Ñ3Ó5Ó6‰
øÜô Úðúà# aœˆ:Ð1¨TÐ1sC   ‹)8 µ8 ¸AÁAÁAÁAÂ/B5 Â5CÃCÄ.D< Ä<EÅ
Ec                ó0   € V ^8„  d   QhR\         R\        /# )r7   Ú
target_pidr8   ©rS   r:   )r;   s   "r=   r>   r>   ñ   s   € ÷ ñ ´Cð ¼Dñ r@   c                óÒ   € V ^ 8:  d   R# \         P                  ! 4       p\        4       pV'       d7   W9  d1   W8X  d   R# VP                  V4       \	        V4      ;'       g    ^ pK>  R# )zHReturn True when ``target_pid`` is this process or one of its ancestors.FT)ÚosÚgetpidrw   r�   r¸   )rº   rd   Úseens   &  r=   Ú#_is_pid_ancestor_of_current_processrÀ   ñ   sN   € à�Q„Ùä
�)Š)‹+€CÜ“U€Dß
�#”/ØÔÙØ�‰�ŒÜ˜cÓ"×'Ð' aŠÙr@   c                ó0   € V ^8„  d   QhR\         R\        /# ©r7   rd   r8   r»   )r;   s   "r=   r>   r>      s   € ÷ ñ ¤sð ¬tñ r@   c                óÞ   € \        \        R4      '       d   \        V 4      '       g   R#  \        P                  ! V \        P
                  4       R#   \        \        \        3 d     R# i ; i)z@Ask a running gateway ancestor to restart itself asynchronously.ÚSIGUSR1FT)	ÚhasattrÚsignalrÀ   r½   ÚkillrÄ   ÚProcessLookupErrorÚPermissionErrorÚOSError)rd   s   &r=   Ú_request_gateway_self_restartrË      sU   € ä”6˜9×%Ò%Ô-PÐQT×-UÒ-UÙðÜ
�Š�”V—^‘^Ô$ñ øô ¤´Ð9ô Úðús   «%A ÁA,Á+A,Úon_progressc                ó<   € V ^8„  d   QhR\         R\        R\        /# )r7   rd   Údrain_timeoutr8   ©rS   rf   r:   )r;   s   "r=   r>   r>     s'   € ÷ Uñ U¤sð U¼5ð UÔZ^ñ Ur@   c               ó  € \        \        R4      '       d   V ^ 8:  d   R#  \        P                  ! V \        P                  4       \        T \        TR4      TR7      #   \
         d     R# \        \        3 d     R# i ; i)uÿ  SIGUSR1 (drain-aware restart) a gateway PID and wait for exit; False if unsent or it outlived the timeout.

gateway/run.py maps SIGUSR1 to ``request_restart(via_service=True)``: refuse new turns, drain,
``stop()``, exit; the supervisor relaunches. ``drain_timeout`` must cover after-turn wait + the full stop
envelope â€” pass ``resolve_restart_exit_wait_budget(...)``. ``on_progress`` (zero-arg) runs on every poll so
a long wait can report what the gateway is still holding for (``update_cmd_drain_report``).
rÄ   FTç      ð?©rÌ   )
rÅ   rÆ   r½   rÇ   rÄ   rÈ   rÉ   rÊ   Ú_wait_for_pid_exitÚmax)rd   rÎ   rÌ   s   &&$r=   Ú_graceful_restart_via_sigusr1rÕ     sm   € ô ”6˜9×%Ò%¨°¬ÙðÜ
�Š�”V—^‘^Ô$ô ˜c¤3 }°cÓ#:ÈÔTÐTøô ô ÚÜœWÐ%ô Úðús   ¡%A ÁB Á,B Á;B Á?B c                ó<   € V ^8„  d   QhR\         R\        R\        /# )r7   rd   r|   r8   rÏ   )r;   s   "r=   r>   r>     s!   € ÷ ñ œCð ¬%ð Ìñ r@   c               ó  € V ^ 8:  d   R# ^ RI Hp \        P                  ! 4       \	        VR4      ,           p V! V 4      '       g   R# \        P                  ! 4       V8¼  d   R# Ve   V! 4        \        P
                  ! R4       KP  )z»Wait up to ``timeout``s for ``pid`` to exit; True once gone. (``launchctl bootstrap`` fails EIO
while the previous instance still drains, so teardown callers must wait for the real exit.)T©Ú_pid_existsr`   Fç      à?)Úgateway.statusrÙ   ÚtimeÚ	monotonicrÔ   Úsleep)rd   r|   rÌ   rÙ   Údeadlines   &&$  r=   rÓ   rÓ     sb   € ð ˆa„xÙå*Ü�~Š~Ó¤# g¨sÓ"3Õ3€HØ
Ù˜3×ÒÙÜ�>Š>Ó˜xÔ'ÙØÒ"ÙŒMÜ�
Š
�3Žr@   ÚaliveÚwedgedÚunknowng     €V@rÑ   c          	      ód   € V ^8„  d   QhR\         R\        R,          R\        R\        R,          /# )r7   rd   ÚhomeNr|   r8   ©rS   r   rf   r:   )r;   s   "r=   r>   r>   e  s9   € ÷ 	Gñ 	G¤ð 	G¬D°4­Kð 	GÄ%ð 	GÔRVÐY]ÕR]ñ 	Gr@   c                ó¾   €  ^ RI Hp V! W4      pVP                  4       '       g   R#  \	        \
        P                  \        T4      T4      #   \         d     R# i ; i)zmPing the loop-tick witness socket: True answered, False node present but silent, None no node (not evidence).)Úget_loop_tick_socket_pathN)Úgateway.shutdown_watchdogrç   Ú	is_socketr²   Ú_ping_loop_tick_witnessÚsocketÚAF_UNIXrQ   )rd   rä   r|   rç   rc   s   &&&  r=   Ú_probe_loop_tick_socketrí   e  sV   € ðÝGÙ(¨Ó3ˆØ�~‰~×ÒÙð  ô #¤6§>¡>´3°t³9¸gÓFÐFøô ô Úðús   ‚$A ÁAÁAc                ó<   € V ^8„  d   QhR\         R\        R\        /# )r7   Úfamilyr|   r8   rÏ   )r;   s   "r=   r>   r>   q  s!   € ÷ ñ ¤Cð ¼5ð ÄTñ r@   c           	     ó  € Rp \         P                   ! V \         P                  4      pVP                  \        \	        V4      R4      4       VP                  V4       VP                  ^4      R8H  Ve=   \        P                  ! \        4      ;_uu_ 4        VP                  4        RRR4       # #   + '       g   i     # ; i  \         dZ     TeR   \        P                  ! \        4      ;_uu_ 4        TP                  4        RRR4       R#   + '       g   i     R# ; iR# i ; i  TeP   \        P                  ! \        4      ;_uu_ 4        TP                  4        RRR4       i   + '       g   i     i ; ii ; i)z_Connect to a loop-tick witness and expect one byte ``"1"``; False on refusal/timeout/any error.Nr`   ó   1F)rë   ÚSOCK_STREAMÚ
settimeoutrÔ   rf   ÚconnectÚrecvÚ
contextlibÚsuppressr²   Úclose)rï   Úaddressr|   Úsocks   &&& r=   rê   rê   q  s	  € à€Dð
Ü�}Š}˜V¤V×%7Ñ%7Ó8ˆØ�‰œœE '›N¨CÓ0Ô1Ø�‰�WÔØ�y‰y˜‹|˜tÑ#ð ÒÜ×$Ò$¤Y×/Õ/Ø—
‘
”÷ 0Ð/ð ß/×/ûô	 ô ØàÒÜ×$Ò$¤Y×/Õ/Ø—
‘
”÷ 0×/×/Ò/úñ ðûð ÒÜ×$Ò$¤Y×/Õ/Ø—
‘
”÷ 0×/×/Ð/úð úsT   „A-C ÂB2Â2CÃD)ÃD, Ã7DÄD#	Ä(D)Ä)D, Ä,'FÅE-	Å$	FÅ-E=Å8	Fc                óJ   € V ^8„  d   QhR\         R\        R\        R,          /# )r7   Úportr|   r8   NrÏ   )r;   s   "r=   r>   r>   �  s*   € ÷ 	Uñ 	Uœsð 	U¬Uð 	U¼TÀD½[ñ 	Ur@   c                ó¦   €  \        V 4      pV^ 8:  g   VR8”  d   R#  \        \        P
                  RT3T4      #   \        \        3 d     R# i ; i)zqTCP-loopback variant of the tick probe for Windows (no AF_UNIX in asyncio); same semantics, None
on invalid port.iÿÿ  Nz	127.0.0.1)rS   Ú	TypeErrorr�   rê   rë   ÚAF_INET)rü   r|   Úport_nums   && r=   Ú_probe_loop_tick_tcpr  �  sY   € ðÜ�t“9ˆØ�qŒ=˜H uÔ,Ùð -ô #¤6§>¡>°KÀÐ3JÈGÓTÐTøô ”zÐ"ô Úðús   ‚; »AÁAr|   ÚstrikesÚgap_sçš™™™™™É?Útcp_portc                ó–   € V ^8„  d   QhR\         R\        R,          R\        R\         R\        R\         R,          R\        R,          /# )	r7   rd   rä   Nr|   r  r  r  r8   rå   )r;   s   "r=   r>   r>   �  sR   € ÷ ñ Ü	ðÜ˜4•KðÜ-2ðÜCFðÜSXðä�D�jðô 
ˆD…[ñr@   c               ó  € \        \        V4      ^ 4      p\        V4       F_  pVe   \        WRR7      pM\	        WVR7      pVRJ d    R# Vf    R# Wv^,
          8  g   K@  V^ 8”  g   KI  \
        P                  ! V4       Ka  	  R# )u<  Probe the tick socket up to ``strikes`` times, ``gap_s`` apart: True once answered, False if a node
stayed silent the whole window, None if the node vanished (not evidence). One silent probe is not
destructive evidence â€” a transient synchronous stall can outlast one recv timeout.

A single silent probe is NOT destructive evidence: the loop may be in a short transient synchronous
stall (a reconnect storm, a heavy synchronous callback, scheduler delay) that outlasts one recv timeout.
Killing a gateway on that would be a false wedge â€” the exact class of false positive #90502 exists to
prevent. Destructive authority therefore requires the loop to fail to answer across a bounded window of
``strikes`` consecutive misses, ``gap_s`` apart; any answer inside the window proves the loop is
dispatching and returns ``True``.
N©r|   TF)rÔ   rS   Úranger  rí   rÜ   rÞ   )	rd   rä   r|   r  r  r  ÚtotalÚattemptrŸ   s	   &&$$$$   r=   Ú!_probe_loop_tick_socket_sustainedr  �  sq   € ô ”�G“˜aÓ €EÜ˜–<ˆØÒÜ)¨(ÔD‰Fä,¨SÀÔHˆFØ�T‹>ÚØŠ>âØ˜Q•YÖ 5¨1¦9Ü�JŠJ�uÖñ  ñ r@   Ústale_afterrä   Útick_timeoutÚtick_strikesÚ
tick_gap_sc                óz   € V ^8„  d   QhR\         R\        R\        R,          R\        R\         R\        R\        /# )	r7   rd   r  rä   Nr  r  r  r8   )rS   rf   r   rQ   )r;   s   "r=   r>   r>   ¬  sU   € ÷ K ñ K Ü	ðK Ü#ðK ÜQUÐX\ÕQ\ðK äðK ä-0ðK äBGðK ô 	ñK r@   c          	     óò  €  \        \        V4      R4      p ^ RIHp V! V4      pVP                  4       P                  p	\        P                  ! VP                  RR7      4      p
\        V
P                  R^ 4      4      pT^ 8:  g!   \        T 4      ^ 8:  g   T\        T 4      8w  d   \        # T
P                  R4      p Te   \        T4      MRpTe   T^ 8”  d   \!        YÓR7      pR	pM#\#        YTR7      pT
P                  R
\$        4      pTR	J d   \&        # \(        P(                  ! 4       T	,
          pTT8:  d   TRJ d   \        # \&        # T\$        J d   \*        # TR	Jd   \        # TRJ d4   \-        YY4^,
          Y]R7      pTRJ d   \*        # TR	J d   \&        # \        # \        #   \        \        3 d    \        p EL­i ; i  \         d
    \        u # i ; i  \        \        3 d    Rp EL$i ; i)un  Classify a gateway PID's event loop as alive / wedged / unknown (see block comment above).
Stale heartbeat is ``wedged`` only when the payload declares the tick socket armed AND it stays
silent across ``tick_strikes`` misses; any answer is ``alive``; ambiguity is ``unknown``.

- the loop-tick socket (``state/gateway.loop-tick.<pid>.sock``): answered by the gateway loop itself, so
a reply is direct proof that the loop is dispatching. It is never refreshed by the heartbeat executor
thread and never stalled by a filesystem that is slow to fsync. - the heartbeat file
(``state/gateway.heartbeat``): rewritten every 30s on a thread since #90502, so freshness alone is no
longer proof of loop schedulability â€” a stalled write (measured at 112.6s max on the incident box) or a
saturated executor can age the file while the loop runs, and a write can land after the loop froze.
r`   )Úget_loop_heartbeat_pathú	utf-8-sig©r0   rd   Úloop_tick_tcp_portNr  TÚloop_tick_socketF)r|   r  r  r  )rÔ   rf   rþ   r�   Ú#DEFAULT_LOOP_LIVENESS_STALE_AFTER_Srè   r  ÚstatÚst_mtimeÚjsonÚloadsÚ	read_textrS   Úgetr²   ÚGATEWAY_LOOP_UNKNOWNr  rí   Ú_LOOP_TICK_ABSENTÚGATEWAY_LOOP_ALIVErÜ   ÚGATEWAY_LOOP_WEDGEDr  )rd   r  rä   r  r  r  Ústale_budgetr  rc   ÚmtimeÚpayloadÚheartbeat_pidr  Útcp_port_intÚwitnessÚ
tick_armedÚageÚ	sustaineds   &$$$$$            r=   Úprobe_gateway_loop_livenessr,  ¬  sÞ  € ð;Üœ5 Ó-¨sÓ3ˆð$ÝEÙ& tÓ,ˆØ—	‘	“×$Ñ$ˆÜ—*’*˜TŸ^™^°[˜^ÓAÓBˆÜ˜GŸK™K¨¨qÓ1Ó2ˆð ˜ÔœS ›X¨œ]¨m¼sÀ3»xÔ.Gä#Ð#ð �{‰{Ð/Ó0€HðØ(0Ò(<”s˜8”}À$ˆð Ò L°1Ô$4Ü& |ÔJˆØ‰
ä)¨#¸\ÔJˆØ—[‘[Ð!3Ô5FÓGˆ
Ø�$ƒä!Ð!ä
�)Š)‹+˜Õ
€CØ
ˆlÔØ�eÓä'Ð'Ü!Ð!ð Ô&Ó&ä"Ð"Ø˜Óä#Ð#Ø�%Óô
 6Ø˜|ÀAÕ5EÈZô
ˆ	ð ˜ÓÜ&Ð&Ø˜ÓÜ%Ð%Ü#Ð#ÜÐøôu ”zÐ"ô ;Ü:‹ð;ûô ô $Ü#Ò#ð$ûô ”zÐ"ô Ø‹ðús5   ‚F* ˜A)G Ã G Æ*GÇGÇGÇGÇG6Ç5G6Ú
term_graceç      @Ú	kill_waitc                óH   € V ^8„  d   QhR\         R\        R\        R\        /# )r7   rd   r-  r/  r8   rÏ   )r;   s   "r=   r>   r>   ú  s)   € ÷ ?ñ ?¤#ð ?´eð ?Ìeð ?Ô^bñ ?r@   c               óŠ  € ^ RI Hp V! V 4      p \        V RR7       \        T \        \        T4      R4      4      '       d   R#  \        T RTR7       \        RT  R	24       \        T \        \        T4      R4      4      #   \        \        \
        3 d    \        T R4      u # i ; i  \        \        \
        3 d     L_i ; i)
a	  Bounded stop (SIGTERM, ``term_grace``, SIGKILL, ``kill_wait``) for a provably dead loop; True once gone.
Callers MUST have classified ``GATEWAY_LOOP_WEDGED`` first: escalating a merely busy gateway
bypasses the cron drain floor and SIGKILLs live work.

See #86684.
©Úget_process_start_timeF©ÚforcerÑ   r`   T©r5  Úexpected_start_timeõ   âš  Gateway PID z& unresponsive to SIGTERM; sent SIGKILL)
rÛ   r3  r   rÈ   rÉ   rÊ   rÓ   rÔ   rf   Úprint)rd   r-  r/  r3  r7  s   &$$  r=   Ú_escalate_wedged_gatewayr:  ú  s¾   € õ 6Ù0°Ó5Ðð,Ü�c Õ'ô ˜#œs¤5¨Ó#4°cÓ:×;Ò;ÙðÜ�c Ð;NÕOÜÐ   Ð%KÐLÔMô ˜c¤3¤u¨YÓ'7¸Ó#=Ó>Ð>øô ¤´Ð9ô ,Ü! # sÓ+Ò+ð,ûô ¤´Ð9ô Ùðús#   �B ÁB) Â"B&Â%B&Â)CÃCc                ó:   € V ^8„  d   QhR\         \        ,          /# r6   ©rw   rS   )r;   s   "r=   r>   r>     s   € ÷ ñ œC¤�Hñ r@   c                 óÌ   € \        4       p \        P                  ! 4       p\        ^@4       F5  pV P	                  V4       \        V4      pVe   V^ 8:  g   W09   d    V # TpK7  	  V # )az  PIDs of this process and its ancestors, so scans never count the invoking ``hermes`` CLI as a gateway.

Walks from the current PID up to PID 1 (init) so that process-table scans never match the calling CLI
process or any of its parents. This prevents ``hermes gateway status`` from falsely counting the
``hermes`` CLI that invoked it as a running gateway instance (see #13242).
)rw   r½   r¾   r	  r�   r¸   )Ú	ancestorsrd   Ú_Úparents       r=   Ú_get_ancestor_pidsrA    sb   € ô ›%€IÜ
�)Š)‹+€CÜ�2ŽYˆØ�‰�cÔÜ  Ó%ˆØŠ>˜V qœ[¨FÔ,?ØàÐð Šñ ð Ðr@   c                óz   € V ^8„  d   QhR\         \        ,          R\        R,          R\        \        ,          RR/# )r7   rœ   rd   NÚexclude_pidsr8   )r‚   rS   rw   )r;   s   "r=   r>   r>   #  s5   € ÷ ñ œT¤#�Yð ¬S°4­Zð ÄsÌ3Åxð ÐTXñ r@   c                 ó¦   € V'       dI   V^ 8”  d@   V\         P                  ! 4       8w  d$   W9  d   W9  d   V P                  V4       R# R# R# R# R# R# ©é    N)r½   r¾   Úappend)rœ   rd   rC  s   &&&r=   Ú_append_unique_pidrH  #  s>   € ß
ˆs�QŒw˜3¤"§)¢)£+Ô-°#Ô2IÈcÌoØ�‰�CÖñ O^Ñ2IÑ-‰w�sr@   c                ó:   € V ^8„  d   QhR\         \        ,          /# )r7   rC  r<  )r;   s   "r=   r>   r>   (  s   € ÷ 0ñ 0¤c¬#¥hñ 0r@   c              #  óÜ  "  € \         P                  ! 4       p\         P                  ! R4       F�  pVP                  4       '       g   K  \	        V4      pW18X  g   W09   d   K4   \        RV R2R4      ;_uu_ 4       pVP                  4       P                  RRR7      pRRR4       TXP                  R	R
4      3x € K�  	  R#   + '       g   i     L,; i  \        \        3 d     Kº  i ; i5i)z]Yield ``(pid, cmdline)`` from ``/proc`` (Docker without procps); raises if /proc is unusable.ú/procz/proc/z/cmdlineÚrbr,   r-   ©r1   NÚ Ú )r½   r¾   ÚlistdirÚisdigitrS   ÚopenÚreadÚdecoderÊ   rÉ   r-   )rC  Úmy_pidÚentryrd   Ú_fÚcmdlines   &     r=   Ú_iter_proc_cmdlinesrY  (  sº   é € ä�YŠY‹[€FÜ—’˜GÖ$ˆØ�}‰}�ŠÙÜ�%‹jˆØŒ=˜CÔ/Ùð	Ü˜˜s˜e 8Ð,¨d×3Ô3°rØŸ'™'›)×*Ñ*¨7¸9Ð*ÓE�÷ 4ð �7—?‘? 6¨3Ó/Ð/Ô/ó %÷ 4×3ûäœÐ)ô 	Úð	üsN   ‚A C,Á#CÁ;"CÂCÂ%C,ÃCÃCÃC,ÃCÃC)Ã%C,Ã(C)Ã)C,c          	      ót   € V ^8„  d   QhR\         \        ,          R\        R\        R\        \        ,          /# )r7   rC  rv   Úinclude_restart_managersr8   )rw   rS   r:   r‚   )r;   s   "r=   r>   r>   9  s:   € ÷ cñ cÜ”c•(ðcÜ*.ðcÜRVðcä	Œ#…Yñcr@   c                óÐ  a aaaaaaaaaaaaaaaaa€ S \        4       ,          o . o^ RIHoHoHoHoHo ^ RIHoH	o ^ RI
Ho \        4       P                  4       p\        V4      oSP                  4       P!                  RR4      P#                  R4      o\%        S4      pV'       d   VP'                  4       R,          MRoSP                  4       oS'       * ;'       d    \)        V4      oR VVVVVVVVVV3
R lloR	 VVV VVVVV3R
 llp \+        4       '       d.   \-        4       pVf   . # \/        V4       F  w  rxV! Wx4       K  	  M½Rp	\0        P2                  P5                  R4      '       d     \7        S 4       F  w  rxV! Wx4       K  	  Rp	V	'       gp   \:        P<                  ! . RO3R^
/\>        BRR/B p
V
P@                  ^ 8w  d   . # V
PB                  P'                  R4       F  p\E        V4      pVf   K  V! V!   K  	  \+        4       '       d   \K        S4      ^8”  d   \M        S4      oS#   \8         d     L±i ; i  \F        \:        PH                  3 d    . u # i ; i)zfBest-effort process-table scan for gateway PIDs (backs up a stale/missing PID file; ``--all`` sweeps).)Úlooks_like_gateway_command_lineÚ'looks_like_gateway_runtime_command_lineÚprofile_flag_valueÚhermes_home_assignmentsÚcommand_line_names_hermes_home)Ú_hermes_home_for_pidÚ_normalized_home_for_compare)Úpid_is_other_usersÚ\Ú/r   c                ó<   € V ^8„  d   QhR\         R\        R\        /# )r7   rd   Úcommandr8   )rS   rQ   r:   )r;   s   "r=   r>   Ú(_scan_gateway_pids.<locals>.__annotate__X  s!   € ÷ &ñ &¤cð &´Cð &¼Dñ &r@   c                 ó  <
€ VP                  4       P                  R R4      pS
'       d   S! V4      S8X  d   R# S! VS	4      # S! V4      R9  d   R# S! V4      '       d
   S! VS	4      # S! V 4      pVe   S! V4      S! S4      8H  # S# )re  rf  TF©NÚdefault)Úlowerr-   )rd   rh  Ú
command_lcÚ
owner_homerb  rc  ra  Úcurrent_homeÚcurrent_home_is_nativeÚcurrent_home_lcÚcurrent_profile_nameÚcurrent_profile_name_lcr`  r_  s   &&  €€€€€€€€€€r=   Ú_matches_current_profileÚ4_scan_gateway_pids.<locals>._matches_current_profileX  s˜   ø€ Ø—]‘]“_×,Ñ,¨T°3Ó7ˆ
ßá! 'Ó*Ð.EÔEÙÙ1°*¸oÓNÐNñ ˜gÓ&Ð.?Ô?ÙÙ" :×.Ò.Ù1°*¸oÓNÐNñ *¨#Ó.ˆ
ØÒ!Ù/°
Ó;Ñ?[Ð\hÓ?iÑiÐið &Ð%r@   c                ó4   € V ^8„  d   QhR\         R\        RR/# )r7   rd   rh  r8   N)rS   rQ   )r;   s   "r=   r>   ri  r  s!   € ÷ 8ñ 8”sð 8¤Sð 8¨Tñ 8r@   c                 óÊ   <€ S! V4      ;'       g    S;'       d	    S! V4      pV'       d8   S	! V 4      '       g(   S'       g   S! W4      '       d   \        S
V S4       R # R # R # R # rB   )rH  )rd   rh  Úmatches_runtimeru  rv   rC  r[  r]  r^  rd  rœ   s   && €€€€€€€€r=   Ú	_considerÚ%_scan_gateway_pids.<locals>._considerr  sb   ø€ Ù9¸'ÓB÷ 
ð 
Ø$×YÐYÑ)PÐQXÓ)Yð 	÷ Ñ#5°c×#:Ò#:ÇÑPhÐil×PvÒPvÜ˜t S¨,Ö7ñ QwÑ#:‰?r@   FrK  Tr|   r}   Ú
r„   )r«   z-Awwr¬   zpid=,command=)'rA  rÛ   r]  r^  r_  r`  ra  Úhermes_cli.dashboard_procsrb  rc  Ú!hermes_cli.gateway_migrate_guardsrd  r   ÚresolverQ   rm  r-   ÚrstripÚ_profile_argr�   Ú_home_owns_bare_service_namer³   Ú_windows_process_listingÚ_iter_windows_list_processesr½   rc   ÚisdirrY  r²   r‡   rˆ   r‰   r™   rŠ   Ú_parse_ps_linerÊ   r‘   rš   Ú_filter_venv_launcher_stubs)rC  rv   r[  Úcurrent_home_pathÚcurrent_profile_argrz  Úlistingrd   rh  Ú_found_via_procrŸ   r    Úparsedrb  ru  rc  ra  rp  rq  rr  rs  rt  r`  r]  r^  rd  rœ   r_  s   fff          @@@@@@@@@@@@@@@r=   Ú_scan_gateway_pidsr�  9  s  ÿÿù€ ð
  Ô"4Ó"6Õ6€LØ€D÷õ ÷ ^ÝDÜ'Ó)×1Ñ1Ó3ÐÜÐ(Ó)€Lð #×(Ñ(Ó*×2Ñ2°4¸Ó=×DÑDÀSÓI€OÜ& |Ó4Ðß>QÐ.×4Ñ4Ó6°rÖ:ÐWYÐØ2×8Ñ8Ó:Ðð "6Ô5×iÐiÔ:VÐWhÓ:iÐ÷&÷ &ñ &÷48÷ 8ðÜ�<Š<Ü.Ó0ˆGØŠØ�	Ü <¸WÖ E‘�Ù˜#Ö'ò !Fð $ˆOÜ�w‰w�}‰}˜W×%Ò%ðÜ(;¸LÖ(I™˜Ù! #Ö/ñ )Jà&*�O÷ #ä#ŸšÒ(MÑxÐWYÐxÔ]jÑxÐrwÒx�Ø×$Ñ$¨Ô)Ø�IØ"ŸM™M×/Ñ/°Ö5�DÜ+¨DÓ1�FØÔ)Ù! 6Ô*ñ 6ô ‡|‚|œ˜D›	 AœÜ*¨4Ó0ˆà€Køô) !ô Ùðûô ”Z×.Ñ.Ð/ô ØŠ	ðúsT   ÄI Ä-I Å
&I Å2H4 ÆI Æ5I Ç*I Ç=
I È4IÈ?I ÉIÉI ÉI%É$I%c                ó`   € V ^8„  d   QhR\         R\        \        \         3,          R,          /# )r7   r    r8   N©rQ   rR   rS   )r;   s   "r=   r>   r>   Ÿ  s'   € ÷ ñ œð ¤¤s¬C x¥°4Õ!7ñ r@   c                ó  € V P                  4       pV'       d   RV9   d   R# VP                  R^4      p\        V4      ^8X  dI   \        P                  ! \
        4      ;_uu_ 4        \        V^ ,          4      V^,          3uuRRR4       # VP                  4       p\        V4      ^
8”  dH   V^,          P                  4       '       d+   \        V^,          4      RP                  VR,          4      3# R#   + '       g   i     Ly; i)zW``(pid, command)`` from one ``ps -o pid=,command=`` line; also accepts ``ps aux`` rows.ÚgrepNrO  :é
   NN)	r‹   r�   rš   rö   r÷   r�   rS   rQ  Újoin)r    Ústrippedr¡   Ú	aux_partss   &   r=   r†  r†  Ÿ  s¹   € à�z‰z‹|€Hß�v Ô)ÙØ�N‰N˜4 Ó#€EÜ
ˆ5ƒz�Q„Ü× Ò ¤×,Õ,Ü�u˜Q•x“= %¨¥(Ð*÷ -Ò,à—‘Ó €IÜ
ˆ9ƒ~˜Ô˜y¨�|×3Ñ3×5Ò5Ü�9˜Q•<Ó  #§(¡(¨9°S­>Ó":Ð:Ð:Ù÷ -×,ús   Á&C5Ã5D	c                ó$   € V ^8„  d   QhR\         /# )r7   rŠ  ©rQ   )r;   s   "r=   r>   r>   ®  s   € ÷ 
ñ 
¬#ñ 
r@   c           	   #  ó˜  "  € RpV P                  R4       F›  pVP                  4       pVP                  R4      '       d   V\        R4      R pK:  VP                  R4      '       g   KS  \        P
                  ! \        4      ;_uu_ 4        \        V\        R4      R 4      V3x € RRR4       RpK�  	  R#   + '       g   i     L; i5i)zDYield ``(pid, command_line)`` from wmic/CIM ``/FORMAT:LIST`` output.r   r|  zCommandLine=Nz
ProcessId=)r�   r‹   r›   rš   rö   r÷   r�   rS   )rŠ  Úcurrent_cmdr    s   &  r=   r„  r„  ®  s˜   é € à€KØ—‘˜dÖ#ˆØ�z‰z‹|ˆØ�?‰?˜>×*Ò*Øœs >Ó2Ð4Ð5ŠKØ�_‰_˜\×*Ô*Ü×$Ò$¤Z×0Õ0Ü˜$œs <Ó0Ð2Ð3Ó4°kÐAÒA÷ 1àŠKó $÷
 1×0üs$   ‚A"C
Á)"C
ÂB7Â'C
Â7CÃC
c                ó2   € V ^8„  d   QhR\         R,          /# ©r7   r8   Nr—  )r;   s   "r=   r>   r>   »  s   € ÷ !Vñ !V¤#¨¥*ñ !Vr@   c                 ó²  € ^ RI Hp  \        P                  ! R4      pRpVe   V ! VRRRR.^
RR	7      pVe%   VP                  ^ 8w  g   VP
                  '       gS    \        P                  ! R
4      ;'       g    \        P                  ! R4      pVf   R# RpV ! VRRV.^RR	7      pVf   R# VP                  ^ 8w  g   VP
                  f   R# VP
                  # )ax  ``CommandLine=``/``ProcessId=`` LIST output for every Windows process (wmic, else Get-CimInstance), or None.
``bounded_probe_run``, NOT ``subprocess.run(timeout=...)``: run()'s post-timeout cleanup joins pipe
readers unbounded and a conhost.exe holding duplicated handles wedges the caller forever; it also
hides the console window this windowless pythonw backend would flash.)Úbounded_probe_runÚwmicNÚprocessr  zProcessId,CommandLinez/FORMAT:LISTÚignore)r|   r1   Ú
powershellÚpwshz¡Get-CimInstance Win32_Process | ForEach-Object {   'CommandLine=' + ($_.CommandLine -replace "`r`n",' ' -replace "`n",' ');   'ProcessId=' + $_.ProcessId;   '' }ú
-NoProfileú-Command)Úhermes_cli._subprocess_compatr�  r´   rµ   r™   rŠ   )r�  Ú	wmic_pathrŸ   r¡  Úps_cmds        r=   rƒ  rƒ  »  sØ   € õ @Ü—’˜VÓ$€IØ€FØÒÙ"Ø˜	 5Ð*AÀ>ÐRÐ\^Ðgoô
ˆð ‚~˜×*Ñ*¨aÔ/¸¿¿¸ÈÜ—\’\ ,Ó/×GÐG´6·<²<ÀÓ3Gˆ
ØÒÙðð 	ñ # J°¸jÈ&Ð#QÐ[]ÐfnÔoˆØŠ>ÙØ×$Ñ$¨Ô)¨V¯]©]Ò-Bˆ4ÐUÈÏÉÐUr@   c                ó\   € V ^8„  d   QhR\         \        ,          R\         \        ,          /# )r7   rœ   r8   )r‚   rS   )r;   s   "r=   r>   r>   ß  s"   € ÷ .ñ .¤d¬3¥ið .´D¼µIñ .r@   c                ór  €  ^ RI p\        T 4      p\        4       pT  FB  p TP                  T4      P	                  4       pTf   K)  YR9   g   K1  TP                  T4       KD  	  T  Uu. uF  qfT9  g   K  TNK  	  up#   \         d    T u # i ; i  TP
                  TP                  3 d     K“  i ; iu upi )zfDrop venv-launcher ``pythonw.exe`` stubs that parent another matched PID (see ``_scan_gateway_pids``).N)r®   r±   rw   r¯   r°   ÚNoSuchProcessÚAccessDeniedr�   )rœ   r®   Úpid_setÚdroprd   r°   Úps   &      r=   r‡  r‡  ß  s´   € ðÛô �$‹i€GÜ“U€DÛˆð	Ø—>‘> #Ó&×+Ñ+Ó-ˆDð Ô ¦Ø�H‰H�TŽNñ ñ Ó-‘t�!¨™}�AˆA‘tÑ-Ð-øô ô ØŠðûð ×$Ñ$ f×&9Ñ&9Ð:ô 	Úð	üò .s.   ‚A= ¡BÁ'B4Á4B4Á=BÂBÂB1Â0B1c                óJ   € V ^8„  d   QhR\         R,          R\        R\        /# )r7   rC  Nrv   r8   )rw   r:   r‚   )r;   s   "r=   r>   r>   ò  s&   € ÷ ñ ¤C¨$¥Jð ÄTð ÔVZñ r@   c                óf  € \        T ;'       g    \        4       4      p. pV'       g    \        V\        4       V4       \	        VR7       F  p\        W4V4       K  	   \        4       '       * p\        W!VR7       F  p\        W4V4       K  	  V#   \         d     L^i ; i  \         d    Rp LBi ; i)znFind running gateway PIDs for the current profile, or every profile with ``all_profiles`` (``hermes update``).©rv   F)rv   r[  )rw   rH  Ú_owned_gateway_pidr²   r¦   r…   r�  )rC  rv   Ú_excluderœ   rd   r[  s   &&    r=   Úfind_gateway_pidsr´  ò  s­   € ä�<×(Ð(¤3£5Ó)€HØ€Dßð	Ü˜tÔ%7Ó%9¸8ÔDô !¨l×;ˆÜ˜4 hÖ/ñ <ð)Ü'@Ó'BÔ#BÐ ô " (Ð`x×yˆÜ˜4 hÖ/ñ zà€Køô ô 	Ùð	ûô ô )Ø#(Ò ð)ús#   ©B ÁB  ÂBÂBÂ B0Â/B0Ústrictc                ó`   € V ^8„  d   QhR\         R,          R\        R\        \        ,          /# )r7   rC  Nrµ  r8   )rw   r:   r‚   r_   )r;   s   "r=   r>   r>     s,   € ÷ $ñ $´°tµð $Ìtð $Ô`dÔezÕ`{ñ $r@   c          
     ó  € \        T ;'       g    \        4       4      p. p ^ RIHpHp ^ RIHp \        4       p T! 4       pT FÅ  p	 T'       dA   T! T	P                  R,          4      p
T
'       d
   T
^ ,          MRpT
'       d
   T
^,          MRpMT! T	P                  R,          RR7      pRp Te   T^ 8:  g   Y²9   g   Y·9   d   Kƒ  TP                  T4       TP                  \        T	P                  T	P                  Y¼R	7      4       KÇ  	  T#   \         d    T'       d   h Tu # i ; i  \         d    T'       d   h Tu # i ; i  \         d.   pT'       d   \        RT	P                   24      Th Rp?EK6  Rp?ii ; i)
zDReturn running gateway PIDs mapped to Hermes profiles via PID files.)Úget_running_pidÚget_running_pid_identity_strict©Úlist_profilesúgateway.pidNr`   F©Úcleanup_stalez*Could not inspect gateway PID for profile )rb   rc   rd   re   )rw   rÛ   r¸  r¹  Úhermes_cli.profilesr»  r²   rc   ÚRuntimeErrorrk   r�   rG  r_   )rC  rµ  r³  Ú	processesr¸  r¹  r»  r¿   Úprofilesrb   Úidentityrd   re   Úexcs   &$            r=   Úfind_profile_gateway_processesrÅ    sP  € ä�<×(Ð(¤3£5Ó)€HØ-/€IðßSÝ5ô “U€DðÙ “?ˆó
 ˆð	ßÙ:¸7¿<¹<È-Õ;WÓX�ß%-�h˜q–k°4�ß-5˜h qžk¸3‘á% g§l¡l°]Õ&BÐRWÔX�Ø!‘ð
 Š;˜# œ( c¤o¸¼ÙØ�‰�ŒØ×ÑÔ.°w·|±|È'Ï,É,Ð\_ÔyÖzñ! ð" Ðøô; ô ßØØÒðûô ô ßØØÒðûô ô 	ßÜ"Ð%OÐPW×P\ÑP\È~Ð#^Ó_ÐehÐhÞûð	úsX   ¡D ºD* Á(EÁ0EÂEÂEÄD'Ä!D'Ä&D'Ä*EÄ=EÅEÅE>Å!E9Å9E>c                ó$   € V ^8„  d   QhR\         /# )r7   Úfieldr—  )r;   s   "r=   r>   r>   -  s   € ÷ Jñ J¤sñ Jr@   c                óˆ   € \        WR4      p\        V4      '       d   V! 4       # V P                  4       P                  V4      # )z`psutil ``WindowsService`` exposes getters as methods; ``as_dict()`` covers objects without them.N)ÚgetattrÚcallableÚas_dictr  )ÚservicerÇ  Úgetters   && r=   Ú_scm_service_fieldrÎ  -  s7   € ä�W TÓ*€FÜ ×'Ò'‰6‹8ÐI¨W¯_©_Ó->×-BÑ-BÀ5Ó-IÐIr@   Úpsutil_moduleÚprofile_processesc                ój   € V ^8„  d   QhR\         \        ,          R,          R\         \        ,          /# )r7   rÐ  Nr8   )r‚   r_   ri   )r;   s   "r=   r>   r>   3  s1   € ÷ i3ñ i3Ü.2Ô3HÕ.IÈDÕ.Pði3ä	Ô
Õ ñi3r@   c                óV	  a€ \         P                  R8w  d   . #  V f   ^ RIp Vf   \        RR7      p^ RIHpHp V! 4       p/ o/ pV P                  4        EF!  p \        \        VR4      ;'       g    R4      pV'       g   \        R4      hV! VRV4      pV'       g*    \        \        VR	4      ;'       g    R4      p	T! YyT4      pV'       g   K|  \        VR
4      p
\        \        VR4      ;'       g    ^ 4      pT
R8X  d   K°  T
R8w  d,   T^ 8”  d#   TP!                  T. 4      P#                  Yz34       Kâ  T^ 8:  d   \        RT R24      hSP!                  T\%        4       4      P'                  T4       EK$  	  / pT EFT  p T P)                  \        TP*                  4      4      p\-        TP/                  4       4      pTP.                  ^ 8:  g"   \1        TTP.                  ,
          4      R8”  d   \        R4      hTP3                  4        Uu. uF  p\        TP*                  4      NK  	  ppT F9  pTP5                  T. 4      pT'       g   K  T^ ,          w  rz\        RT RT
 24      h	  T Uu. uF/  p\7        SP5                  T\%        4       4      4      ^8”  g   K-  TNK1  	  ppT'       d)   \        RRP9                  R T 4       4      ,           4      h\;        T3R lT 4       R4      pTf   EKx  \;        \=        ST,          4      4      pT P)                  T4      p\-        TP/                  4       4      pTP?                  RR7      p\A        R T 4       4      p\        TP*                  4      T9  d   EKþ  \C        \E        R T 4       4      4      p\G        T\        TPH                  4      T\        TP*                  4      TTTTR7      Y×&   EKW  	  \E        T4       Uu. uF  pTT,          NK  	  up#   T P                  \        3 d     EKÀ  i ; i  \         d     EKÓ  \         d   p\        R4      ThRp?ii ; i  \         d   p\        R4      ThRp?ii ; iu upi u upi   \         d    h \         d   p\        RTPH                   24      ThRp?ii ; iu upi )aõ  Profile gateways supervised by real, Hermes-owned Windows services. Service-logon processes may
hide their command lines, so identity = Hermes's own PID file + a parent chain ending at a running
SCM service PID whose name or binary path is Hermes's (``gateway_windows.hermes_owns_windows_service``).
The whole service subtree is returned so the Desktop preflight exempts exactly what the updater stops
through the SCM; a gateway under any other service (a Scheduled Task's svchost) is a plain process.Úwin32NT)rµ  )Úhermes_owns_windows_serviceÚhermes_service_rootsrk   r   zSCM service has an empty nameÚbinpathÚstatusrd   zSCM service inspection failedÚstoppedrG   zRunning SCM service z has no valid process IDzSCM service enumeration failedgü©ñÒMbP?z5Gateway process identity changed during SCM discoveryzSCM service z has indeterminate status: z=Gateway ownership is ambiguous under shared SCM host PID(s): ú, c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5irB   r—  )Ú.0rd   s   & r=   Ú	<genexpr>Ú0find_windows_gateway_services.<locals>.<genexpr>  s   é € ÐHÑ4G¨S¤ C§ Ó4Gùó   ‚c              3   ó|   <"  € T F1  p\        SP                  V\        4       4      4      ^8X  g   K-  Vx € K3  	  R# 5i)é   N)rš   r  rw   )rÛ  rd   Úservice_names_by_pids   & €r=   rÜ  rÝ  �  s3   øé € Ðo©}¨ÄÐDX×D\ÑD\Ð]`ÔbeÓbgÓDhÓ@iÐmnÑ@n§¢«}ùs   ƒ*<²
<)Ú	recursivec              3   óL   "  € T F  p\        VP                  4      x € K  	  R # 5irB   )rS   rd   ©rÛ  Úchilds   & r=   rÜ  rÝ  ˆ  s   é € Ð#UÑ@T°u¤C¨¯	©	§N NÓ@Tùs   ‚"$c              3   ó~   "  € T F3  p\        VP                  4      \        VP                  4       4      3x € K5  	  R # 5irB   )rS   rd   rf   re   rä  s   & r=   rÜ  rÝ  Œ  s-   é € ÐfÑQeÈœ˜EŸI™I›¬¨e×.?Ñ.?Ó.AÓ(BÕCÓQeùs   ‚;=)rk   rb   rl   rm   rn   ro   rp   rq   z6Could not determine SCM ownership for gateway profile )%ÚsysÚplatformr®   rÅ  Úhermes_cli.gateway_windowsrÔ  rÕ  Úwin_service_iterrQ   rÎ  rÀ  r«  rÊ   rS   r’   r²   Ú
setdefaultrG  rw   r�   r¯   rd   rf   re   ÚabsÚparentsr  rš   r“  ÚnextÚiterÚchildrenrr   rR   r—   ri   rb   )rÏ  rÐ  rÔ  rÕ  Úhermes_rootsÚindeterminate_services_by_pidrÌ  Úservice_nameÚownedÚservice_binpathÚservice_statusrl   rÄ  ÚfoundÚprofile_processÚgateway_processrq   r@  Úancestor_pidsrd   Úindeterminate_servicesÚshared_service_pidsÚservice_processrp   Údescendant_processesÚdescendantsro   rk   rá  s   $$                          @r=   Úfind_windows_gateway_servicesr   3  sŒ  ø€ ô ‡|�|�wÔØˆ	ð/FØÒ Û*ØÒ$Ü >ÀdÔ KÐß`á+Ó-ˆØ46ÐØMOÐ%Ø$×5Ñ5×7ˆGðMÜ"Ô#5°g¸vÓ#F×#LÐ#LÈ"ÓM�ß#Ü&Ð'FÓGÐGñ 4°LÀ"ÀlÓS�ßð!Ü*-Ô.@ÀÈ)Ó.T×.ZÐ.ZÐXZÓ*[˜ñ 8¸ÐWcÓd�EßÙÜ!3°G¸XÓ!F�Ü!Ô"4°W¸eÓ"D×"IÐ"IÈÓJ�ð  Ô*ÙØ Ô*Ø ”?Ø1×<Ñ<¸[È"ÓM×TÑTÐVbÐUsÔtÙØ˜aÔÜ"Ð%9¸,¸ÐG_Ð#`ÓaÐaØ ×+Ñ+¨K¼»Ó?×CÑCÀL×QñG 8ðN /1€EÜ,ˆð+	|Ø+×3Ñ3´C¸×8KÑ8KÓ4LÓMˆOÜ"'¨×(CÑ(CÓ(EÓ"FÐØ×*Ñ*¨aÔ/´3Ð7JÈ_×MhÑMhÕ7hÓ3iÐlqÔ3qÜ"Ð#ZÓ[Ð[Ø;J×;RÑ;RÔ;TÓUÑ;T°œS §¡ž_Ñ;TˆMÐUÛ$�Ø)F×)JÑ)JÈ3ÐPRÓ)SÐ&ß)Ñ)Ø3IÈ!Õ3LÑ0�LÜ&¨°l°^ÐC^Ð_mÐ^nÐ'oÓpÐpñ	 %ñ
 3@Ó"q±-¨3Ä3ÐG[×G_ÑG_Ð`cÔehÓejÓGkÓClÐopÑCp§3 3±-ÐÐ"qß"Ü"ØSØ—i‘iÑHÑ4GÓHÓHõIóð ô Ôo©}ÓoÐquÓvˆKØÒ"ÚÜ¤Ð%9¸+Õ%FÓ GÓHˆLØ+×3Ñ3°KÓ@ˆOÜ"'¨×(CÑ(CÓ(EÓ"FÐØ#2×#;Ñ#;ÀdÐ#;Ó#KÐ Ü#Ñ#UÑ@TÓ#UÓUˆKÜ�?×&Ñ&Ó'¨{Ô:ÚÜ$)ÜÑfÑQeÓfÓfó%Ð!ô #8Ø!Ü˜O×3Ñ3Ó4Ø'Ü × 3Ñ 3Ó4Ø +Ø&;Ø$7Ø$7ô	#ˆEÔñ? -ôZ %+¨5¤MÓ2¡M˜DˆE�$�KˆK¡MÑ2Ð2øðM *×6Ñ6¼Ð@ô !Û ð!ûô %ô ãÜô MÜ"Ð#BÓCÈÐLûðMûô ô FÜÐ;Ó<À#ÐEûðFüò Vùò #røô: ô 	ØÜô 	|ÜÐ!WÐXg×XoÑXoÐWpÐqÓrÐx{Ð{ûð	|üâ2sî   š?Q Á&PÂPÂO:Â7O:Â>PÃQ Ã+PÃ<A?Q ÆBQ/ÈQ%È.Q/É"Q/É3*Q*Ê"Q*Ê(AQ/Ë7BQ/Í=AQ/Ï%R&Ï:PÐPÐQ ÐPÐPÐQÐ$Q Ð(QÐ1QÐ2P>Ð>QÑQ ÑQ"ÑQÑQ"Ñ%
Q/Ñ/R#ÒR#ÒRÒR#c                óF   € V ^8„  d   QhR\         R\        \         ,          /# )r7   rb   r8   )rQ   r‚   )r;   s   "r=   r>   r>   Ÿ  s   € ÷ /ñ /¬3ð /´4¼µ9ñ /r@   c                 ó†   € ^ RI Hp . pV R8w  d   VP                  RV .4       VP                  . RO4       V! \        V4      # )rF  )Úruntime_commandrl  ú	--profile)Úgatewayrˆ   ú	--replace)Úhermes_cli._launchersr  ÚextendÚPROJECT_ROOT)rb   r  Úargss   &  r=   Ú_gateway_run_args_for_profiler  Ÿ  s=   € Ý5Ø€DØ�)ÔØ�‰�[ 'Ð*Ô+Ø‡K�KÒ/Ô0Ùœ<¨Ó.Ð.r@   c                óT   € V ^8„  d   QhR\         R\        \        ,          R,          /# r¨   )rS   r‚   rQ   )r;   s   "r=   r>   r>   ¨  s#   € ÷ ñ œsð ¤t¬C¥y°4Õ'7ñ r@   c                óV  € V ^8:  d   R#  ^ RI p \        TP                  T 4      P	                  4       ;'       g    . 4      pT'       g   R#  ^ RIHp T! RP                  T4      4      '       g   R#  T#   \         d     R# i ; i  \
         d     R# i ; i  \
         d     T# i ; i)zÂLive argv of a running gateway (snapshotted before update kills so unmapped gateways can respawn);
None if psutil is unavailable, the process is gone/denied, or the argv isn't a gateway command.N)r]  rO  )	r®   r±   r‚   r¯   rX  r²   rÛ   r]  r“  )rd   r®   Úargvr]  s   &   r=   Ú_capture_gateway_argvr  ¨  s°   € ð ˆa„xÙðÛðÜ�F—N‘N 3Ó'×/Ñ/Ó1×7Ð7°RÓ8ˆ÷ ÙðÝBÙ.¨s¯x©x¸«~×>Ò>Ùð ?ð €Køô ô Úðûô ô Úðûô ô ØØ€Kðús9   ‹A5 �*B »B Á"B Á5BÂBÂBÂBÂB(Â'B(c                óJ   € V ^8„  d   QhR\         R\        R\         R,          /# )r7   rb   rd   r8   N©rQ   rS   )r;   s   "r=   r>   r>   Á  s%   € ÷ ñ ´Sð ¼sð ÄsÈTÅzñ r@   c                ó®   € \        V4      pV'       d
   RV9   d   R# \        W4      '       d   R# V'       d   \        V\        V4      4      '       d   R# R# )am  Choose who relaunches a profile gateway after ``hermes update``: ``--external-supervisor`` gateways
exit back to their manager (a detached watcher would race its replacement); otherwise arm the
profile-derived detached watcher, falling back to replaying the captured command line.

When the profile-derived relaunch cannot be armed -- typically because ``_gateway_run_args_for_profile``
cannot rebuild a run argv for this profile -- fall back to replaying the process's own captured command
line, which is what ``launch_detached_gateway_restart_by_cmdline`` exists for and what the Windows
post-update path already does for its unmapped gateways. Without this the caller has no way to relaunch
the process and (before #88654) silently left it running pre-update modules against post-update code on
disk. ``argv`` is already captured above, so the fallback costs nothing extra.
z--external-supervisorzexternal-supervisorÚdetachedzdetached-cmdlineN)r  Ú'launch_detached_profile_gateway_restartÚ*launch_detached_gateway_restart_by_cmdliner‚   )rb   rd   r  s   && r=   Ú'_prepare_profile_gateway_update_restartr  Á  sD   € ô ! Ó%€DßÐ'¨4Ô/Ù$Ü.¨w×<Ò<ÙßÔ:¸3ÄÀTÃ
×KÒKÙ!Ùr@   c                ól   € V ^8„  d   QhR\         R\        \        ,          R\        R,          R\        /# )r7   Úold_pidÚrun_argvrä   Nr8   ©rS   r‚   rQ   r:   )r;   s   "r=   r>   r>   ×  s:   € ÷ qñ q¼ð qÄtÌCÅyð qÔX[Ð^bÕXbð qÔnrñ qr@   c                óp   € V ^ 8„  ;'       d+    \        V4      ;'       d    \        V \        V4      VR7      # )u�   Relaunch a gateway with no profileâ†’PID-file mapping by replaying its captured argv (on Windows under ``home``, the one it ran on) after exit.©rä   )r:   Ú_spawn_gateway_restart_watcherr‚   )r  r  rä   s   &&&r=   r  r  ×  s2   € à�Q‰;×pÐpœ4 ›>×pÐpÔ.LÈWÔVZÐ[cÓVdÐkoÔ.pÐpr@   c                ó<   € V ^8„  d   QhR\         R\        R\        /# )r7   rb   r  r8   ©rQ   rS   r:   )r;   s   "r=   r>   r>   Ü  s!   € ÷ ñ ´Sð Ä3ð Ì4ñ r@   c                óP   € V^ 8„  ;'       d    \        V\        V 4      V R8H  R7      # )zDRelaunch a manually-run profile gateway after its current PID exits.rl  )Úhost)r  r  )rb   r  s   &&r=   r  r  Ü  s3   € à�Q‰;÷ ð Ô9ØÜ% gÓ.Ø˜	Ñ!ôð r@   c                óF   € V ^8„  d   QhR\         \        ,          R\        /# ©r7   r  r8   )r‚   rQ   r:   )r;   s   "r=   r>   r>   î  s   € ÷ ,ñ ,¬¬S­	ð ,´dñ ,r@   c                ób  € V '       d   RV 9  d   R# R FI  pW9   g   K  V P                  V4      pV^,           \        V 4      8  d   W^,           ,          MRpVR8H  u # 	  \        ;QJ d    R V  4       F  '       g   K   RM	  RM! R V  4       4      '       d   R# \        ;QJ d    R V  4       F  '       g   K   RM	  RM! R V  4       4      '       d   R#  ^ RIHp V! 4       '       d   R#   ^ R	IHp VP                  VP                  4      pVe4   VP                  V4      '       d   \        VP                  4      ^8”  d   R#  ^ R
IHpHp T! 4       P                  4       T! 4       P                  4       8H  #   \
         d     Lši ; i  \
         d     LRi ; i  \
         d     R# i ; i)u©  True when *argv* relaunches the host multiplexer, not a named profile's own gateway.

``--profile <name>`` (other than default) is that profile. A selector-less argv is
decided by ALREADY-SETTLED identity, never ambient coordinates alone (#93943):

1. this process's own settled multiplex verdict (``is_multiplex_active`` â€” set by
   boot after ``resolve_multiplex_mode``; the gateway replaying its own restart);
2. the live host gateway's published rendezvous record (proof the RUNNING owner
   settled multiplex â€” the update/fleet process replaying a foreign gateway's
   captured argv has no settled flag of its own);
3. only then the compatibility default-root comparison.
r  Fr   rl  c              3   ó*   "  € T F	  qR 8H  x € K  	  R# 5i)z--profile=defaultNrT   ©rÛ  Úparts   & r=   rÜ  Ú0_restart_argv_is_host_gateway.<locals>.<genexpr>  s   é € Ð
8±4¨4Ð&Ö&³4ùó   ‚Tc              3   ó~   "  € T F3  qP                  R 4      ;'       d    VP                  R4      '       * x € K5  	  R# 5i)z
--profile=z=defaultN)r›   rŽ   r&  s   & r=   rÜ  r(    s0   é € Ð
\ÑW[Èt�?‰?˜<Ó(×JÐJ°·±¸zÓ1JÔ-JÔJÓW[ùs   ‚=ž=)Úis_multiplex_active)Úhost_rendezvous)Úget_default_hermes_rootr   )r  r­   )Úindexrš   ÚanyÚagent.secret_scoper+  r²   r  r,  Úread_recordÚROLE_GATEWAYÚrecord_names_live_ownerrÂ  Úhermes_constantsr-  r   r  )	r  ÚflagÚidxrk   r+  ÚhrÚrecordr-  r   s	   &        r=   Ú_restart_argv_is_host_gatewayr9  î  sd  € ÷ �9 DÔ(ÙÛ#ˆØŽ<Ø—*‘*˜TÓ"ˆCØ$'¨!¥G¬c°$«iÔ$7�4˜a�–=¸RˆDØ˜9Ñ$Ò$ñ	 $÷
 ƒsÑ
8±4Ó
8‡s‡s‚sÑ
8±4Ó
8×8Ò8Ùß
ƒsÑ
\ÑW[Ó
\‡s‡s‚sÑ
\ÑW[Ó
\×\Ò\ÙðÝ:Ù× Ò Ùð !ðÝ1Ø—‘ §¡Ó0ˆØÒ "×"<Ñ"<¸V×"DÒ"DÌÈVÏ_É_ÓI]Ð`aÔIaÙðßMÙÓ ×(Ñ(Ó*Ñ.EÓ.G×.OÑ.OÓ.QÑQÐQøô ô Ùðûô ô Ùðûô
 ô Úðús<   ÃE= Ã1;F Ä-F Å
2F Å=FÆ
FÆFÆFÆF.Æ-F.c                óF   € V ^8„  d   QhR\         \        \        3,          /# r6   ©ÚdictrQ   )r;   s   "r=   r>   r>     s   € ÷ ñ ¤4¬¬S¨¥>ñ r@   c                 óD   € ^ RI Hp  V ! 4       pVP                  RR4       V# )zIScrubbed default-profile env for a detached host-gateway respawn watcher.)Úhost_gateway_child_envÚ_HERMES_GATEWAYN)Útools.environments.localr>  Úpop)r>  Úenvs     r=   Ú_host_gateway_watcher_envrC    s!   € å?Ù
 Ó
"€CØ‡G�GÐ˜tÔ$Ø€Jr@   r!  c          
      ó†   € V ^8„  d   QhR\         R\        \        ,          R\        R,          R\        R,          R\        /# )r7   r  r  r!  Nrä   r8   r  )r;   s   "r=   r>   r>   %  sK   € ÷ Bñ B¬Cð B¼4Ä½9ð BÌtÐVZÍ{ð BÔilÐosÕisð Bô  @Dñ Br@   c          
     óò  € V ^ 8:  g	   V'       g   R# ^ RI HpHp Rp/ p\        P                  R8X  d    ^ RIHp V! \        V4      VR7      w  rp\        P                  ! R4      P                  4       P                  \        P                  ! V4      \        P                  ! V4      \        P                  ! \        4      \        P                  ! \!        \"        4      4      R7      p	\        P$                  R	V	\!        V 4      .VOp
R
\&        P(                  R\&        P(                  /pVf   \+        V4      '       d   MV'       d   \-        4       MRpVe   RV/M/ p \&        P.                  ! V
3/ VBVBV! 4       B  R#   \         d	    Rp/ p ELBi ; i  \0         dV    \        P                  R8X  d
   RT! 4       /MRR/p \&        P.                  ! T
3/ TBTBTB   R#   \0         d      R# i ; ii ; i)a*  Spawn the detached watcher that respawns ``run_argv`` once ``old_pid`` exits. Watcher and respawn
both need platform-appropriate detach: POSIX setsid; on Windows ``start_new_session`` does NOT detach
(the watcher would die with the CLI console), so ``windows_detach_popen_kwargs()`` supplies flags.F)Ú&windows_detach_flags_without_breakawayÚwindows_detach_popen_kwargsr   rÓ  )Úwindowless_gateway_restart_specr  u  
        import os
        import subprocess
        import sys
        import time
        # Stdlib-only imports: the watcher runs on the updater's interpreter, which after the
        # package-manager handoff is the bare store Python without the dependency environment.
        # ``-c`` only puts the cwd on sys.path, so name the checkout explicitly.
        sys.path.insert(0, {project_root_literal})
        from hermes_cli._subprocess_compat import (
            _WINDOWS_GATEWAY_BREAKAWAY_ENV, pid_exists_stdlib, windows_detach_flags,
            windows_detach_flags_without_breakaway,
        )

        pid = int(sys.argv[1])
        cmd = sys.argv[2:]
        _respawn_cwd = {respawn_cwd_literal}
        _respawn_env_overlay = {respawn_env_literal}
        deadline = time.monotonic() + {watcher_timeout_literal}
        while time.monotonic() < deadline:
            # ``os.kill(pid, 0)`` is not a no-op on Windows â€” use the cross-platform existence check.
            if not pid_exists_stdlib(pid):
                break
            time.sleep(0.2)

        # Route the respawned gateway's stray stdout/stderr to the same sidecar log _spawn_detached
        # uses: with DEVNULL a gateway killed moments after respawn (parent Job Object teardown when
        # breakaway is denied) left ZERO trace. Best-effort: DEVNULL when the log dir is unavailable.
        _stdio_target = subprocess.DEVNULL
        _stdio_fh = None
        try:
            from hermes_constants import get_hermes_home
            from pathlib import Path
            _log_dir = Path(get_hermes_home()) / "logs"
            _log_dir.mkdir(parents=True, exist_ok=True)
            _stdio_fh = open(_log_dir / "gateway-stdio.log", "ab", buffering=0)
            _stdio_target = _stdio_fh
        except Exception:
            pass

        # Platform-appropriate detach for the respawned gateway: POSIX start_new_session (setsid);
        # Windows needs explicit creationflags. CREATE_BREAKAWAY_FROM_JOB is critical: the watcher may
        # itself sit inside a job object (Electron/Tauri parent) and without breakaway the respawned
        # gateway dies when that job tears down. See _subprocess_compat.windows_detach_flags().
        _popen_kwargs = {{"stdout": _stdio_target, "stderr": _stdio_target}}
        # Anchor at the stable working dir and overlay the env (VIRTUAL_ENV / PYTHONPATH /
        # HERMES_HOME) the windowless base interpreter needs to import hermes_cli. Empty on POSIX.
        if _respawn_cwd:
            _popen_kwargs["cwd"] = _respawn_cwd
        _base_env = {{**os.environ, **_respawn_env_overlay}}
        try:
            if sys.platform == "win32":
                try:
                    _popen_kwargs["creationflags"] = windows_detach_flags()
                    # Stamp the breakaway state exactly like gateway_windows._spawn_detached so the
                    # respawned gateway's exit-diag / lifecycle records show whether it escaped the
                    # parent Job Object (a job-teardown kill is otherwise indistinguishable).
                    _popen_kwargs["env"] = {{**_base_env, _WINDOWS_GATEWAY_BREAKAWAY_ENV: "1"}}
                    subprocess.Popen(cmd, **_popen_kwargs)
                except OSError:
                    # CREATE_BREAKAWAY_FROM_JOB is rejected with ERROR_ACCESS_DENIED when the parent's
                    # job object refuses breakaway; retry without it (mirrors _spawn_detached).
                    _popen_kwargs["creationflags"] = windows_detach_flags_without_breakaway()
                    _popen_kwargs["env"] = {{**_base_env, _WINDOWS_GATEWAY_BREAKAWAY_ENV: "0"}}
                    subprocess.Popen(cmd, **_popen_kwargs)
            else:
                if _respawn_env_overlay:
                    _popen_kwargs["env"] = _base_env
                _popen_kwargs["start_new_session"] = True
                subprocess.Popen(cmd, **_popen_kwargs)
        finally:
            if _stdio_fh is not None:
                try:
                    _stdio_fh.close()
                except OSError:
                    pass
        )Úrespawn_cwd_literalÚrespawn_env_literalÚwatcher_timeout_literalÚproject_root_literalz-crŠ   ÚstderrNrB  ÚcreationflagsÚstart_new_sessionT)r¥  rF  rG  rç  rè  ré  rH  r‚   r²   ÚtextwrapÚdedentr‹   r;   r  ÚdumpsÚ!GATEWAY_RESTART_WATCHER_TIMEOUT_SrQ   r	  Ú
executabler‡   ÚDEVNULLr9  rC  ÚPopenrÊ   )r  r  r!  rä   rF  rG  Úrespawn_cwdÚrespawn_env_overlayrH  ÚwatcherÚwatcher_argvÚdevnullÚwatcher_envÚ	popen_envÚfallback_kwargss   &&$$           r=   r  r  %  sæ  € ð �!„|Ÿ8Ùßqð €Kà*,ÐÜ
‡|�|�wÔð	%ÝRÙ9XÔY]Ð^fÓYgÐnrÔ9sÑ6ˆHÐ#6ô �oŠoðL	óN÷\ �eƒg�f‰f¬¯ª°KÓ)@ÔVZ×V`ÒV`ÐatÓVuÜ-1¯ZªZÔ8YÓ-ZÜ*.¯*ª*´S¼Ó5FÓ*Gð ó Ið] ôd —N‘N D¨'´3°w³<ÐKÀ(ÐK€LØœ×+Ñ+¨X´z×7IÑ7IÐJ€Gð 48²<Ô% h×/Ó/ÇTô ,Ô-àð ð )4Ò(?�˜Ñ$ÀR€IðÜ×Ò˜Ñ_¨Ð_°IÐ_ÑA\ÓA^Ò_ñ øô] ô 	%àˆKØ"$Óð	%ûôF ô 
ô LOÏ<É<Ð[bÔKbˆ_ÑDÓFÑGØ% tÐ,ð 	ð	Ü×Ò˜\ÑU¨WÐU¸	ÐUÀ_ÓUñ øô ô 	Ûð	úð
ús;   ´F  Å F Æ FÆFÆ-G6ÇG"Ç"G2Ç-G6Ç1G2Ç2G6c                ó0   € V ^8„  d   QhR\         R\         /# ©r7   Úsystemr8   r9   )r;   s   "r=   r>   r>   ª  s   € ÷ -ñ -¤Dð -¬Tñ -r@   c                ó  € \        V R7      P                  4       '       g   R#  \        R\        4       .3RV R^
/\        B pTP                  P                  4       R8H  #   \
        \        P                  3 d     R# i ; i)z[``systemctl is-active`` == "active" for the installed unit in ``system`` scope, else False.©ra  Fú	is-activera  r|   Úactive)
Úget_systemd_unit_pathÚexistsÚ_run_systemctlr†   r‰   rÀ  r‡   r‘   rŠ   r‹   ©ra  rŸ   s   & r=   Ú_systemd_unit_is_activerj  ª  s{   € ä ¨Ô/×6Ñ6×8Ò8ÙðÜ Ô.>Ó.@Ð AÑnÈ&ÐnÐZ\ÐnÔ`mÑnˆð �=‰=×ÑÓ  HÑ,Ð,øô œ*×3Ñ3Ð4ô Úðús   ¤A ÁA>Á=A>c                óR   € V ^8„  d   QhR\         R\        \         \         3,          /# r`  )r:   rR   )r;   s   "r=   r>   r>   µ  s'   € ÷ Eñ E¬4ð E¼EÄ$ÌÀ*Õ<Mñ Er@   c                 ó2   € \        V 4      pV\        V4      3# rB   )Ú_select_systemd_scoperj  )ra  Úselected_systems   & r=   Ú_probe_systemd_service_runningro  µ  s   € Ü+¨FÓ3€OØÔ3°OÓDÐDÐDr@   c                óF   € V ^8„  d   QhR\         \        \        3,          /# r6   r;  )r;   s   "r=   r>   r>   º  s   € ÷ \ñ \œd¤3¬ 8�nñ \r@   c                ód   € R V  4        UUu/ uF  w  rWP                  4       bK  	  upp# u uppi )zN``{key: value}`` from ``KEY=VALUE`` strings (later keys win; values stripped).c              3   óX   "  € T F   pR V9   g   K  VP                  R ^4      x € K"  	  R# 5i)Ú=N)r�   )rÛ  Úitems   & r=   rÜ  Ú"_parse_kv_pairs.<locals>.<genexpr>¼  s(   é € Ð%ZÁU¸TÈcÐUYÉkÔ&8 d§j¡j°°a×&8Ð&8ÃUùs   ‚	*�*)r‹   )ÚitemsÚkÚvs   &  r=   Ú_parse_kv_pairsry  º  s+   € á%ZÁUÔ%ZÔ[Ñ%Z™T˜QˆA�w‰w‹yŠLÑ%ZÒ[Ð[ùÓ[s   �,c                óx   € V ^8„  d   QhR\         \        R3,          R\        R\        \        \        3,          /# )r7   Ú
properties.ra  r8   )rR   rQ   r:   r<  )r;   s   "r=   r>   r>   ¿  s6   € ÷ 	Yñ 	Y¤¤c¨3 h¥ð 	Y¼Dð 	YÄTÌ#ÌsÈ(Å^ñ 	Yr@   c          	     ó2  €  \        R\        4       RRRP                  V 4      .3R\        V4      R^
/\        B pTP                  ^ 8X  d$   \        TP                  P                  4       4      # / #   \
        \        P                  \        3 d    / u # i ; i)zZ``systemctl show --property a,b`` for the gateway unit as ``{key: value}``; {} on failure.r   r{   z
--propertyÚ,ra  r|   )rh  r†   r“  rm  r‰   rÀ  r‡   r‘   rÊ   r™   ry  rŠ   rŒ   )r{  ra  rŸ   s   &$ r=   Ú_systemctl_showr~  ¿  sš   € ðÜØÔ%Ó'¨°|ÀSÇXÁXÈjÓEYÐZñ
ä(¨Ó0ð
à:<ð
ä@Mñ
ˆð ;A×:KÑ:KÈqÔ:PŒ?˜6Ÿ=™=×3Ñ3Ó5Ó6ÐXÐVXÐXøô œ*×3Ñ3´WÐ=ô ØŠ	ðús   ‚9A1 Á1"BÂBc                óJ   € V ^8„  d   QhR\         R\        R\        R,          /# )r7   Ú	unit_pathrk   r8   N©r   rQ   )r;   s   "r=   r>   r>   Ë  s%   € ÷ ñ ¤tð ´3ð ¼3À½:ñ r@   c                óh  €  V P                  RR7      pTP                  4        Fø  pTP                  4       pTP	                  R4      '       g   K,  T\        R4      R P                  4       pTP	                  R4      '       dM   TP                  R4      '       d6   T^R P                  RR4      P                  RR4      P                  R	R
4      pTP	                  T R24      '       g   KÇ  TP                  R^4      ^,          P                  4       ;'       g    Ru # 	  R#   \         d     R# i ; i)u¯   Value of one ``Environment="NAME=â€¦"`` directive in the unit file at *unit_path*, with
systemd's ``\"``/``\\``/``%%`` quoting undone; None when the file or the key is absent.r  r  NzEnvironment=Ú"ú\"ú\\re  ú%%Ú%rs  r„   )	r  rÊ   rŒ   r‹   r›   rš   rŽ   r-   r�   )r€  rk   r/   r    Úbodys   &&   r=   Ú_unit_environment_valuer‰  Ë  s  € ðØ×"Ñ"¨KÐ"Ó8ˆð —‘Ö!ˆØ�z‰z‹|ˆØ�‰˜~×.Ò.ÙØ”C˜Ó'Ð)Ð*×0Ñ0Ó2ˆØ�?‰?˜3×Ò D§M¡M°#×$6Ò$6Ø˜˜"�:×%Ñ% e¨SÓ1×9Ñ9¸&À$ÓG×OÑOÐPTÐVYÓZˆDØ�?‰?˜d˜V 1˜:×&Ô&Ø—:‘:˜c 1Ó% aÕ(×.Ñ.Ó0×8Ð8°DÒ8ñ "ñ øô ô Úðús   ‚D" Ä"D1Ä0D1c                ó>   € V ^8„  d   QhR\         R\        R,          /# ©r7   r€  r8   Nr�  )r;   s   "r=   r>   r>   Þ  s   € ÷ =ñ =¬4ð =´C¸$µJñ =r@   c                ó   € \        V R4      # )zW``HERMES_HOME`` pinned by the unit file at *unit_path*, or None when absent/unreadable.ÚHERMES_HOME)r‰  )r€  s   &r=   Ú_hermes_home_pinned_by_unitrŽ  Þ  s   € ä" 9¨mÓ<Ð<r@   c                ó>   € V ^8„  d   QhR\         R\        R,          /# ©r7   ra  r8   N©r:   rQ   )r;   s   "r=   r>   r>   ã  s"   € ÷ Mñ M´ð MÄÀtÅñ Mr@   c                ó,   € \        \        V R7      4      # )zl``HERMES_HOME`` from the on-disk unit file - what refresh/compare already read, and reliable under ``sudo``.rc  )rŽ  rf  rc  s   &r=   Ú#_hermes_home_from_systemd_unit_filer“  ã  s   € ä&Ô'<ÀFÔ'KÓLÐLr@   c                ó(   € V ^8„  d   QhR\         RR/# r�  r9   )r;   s   "r=   r>   r>   è  s   € ÷ .ñ .´ð .¸ñ .r@   c                ó¾  € V '       g   R# \        RR7      ;'       g    RP                  4       pV'       gU   \        RRR7      P                  RR4      p\	        VP                  4       4      P                  RR4      P                  4       pV'       dK   \        P                  P                  RR4      P                  4       V8w  d   V\        P                  R&   R# R# R# )zªAdopt a system-scope unit's ``HERMES_HOME``: under ``sudo`` it is stripped and HOME=/root, so
get_hermes_home() would pick the wrong profile for runtime-status/PID reads.NTrc  r   ÚEnvironmentr�  )r–  )r“  r‹   r~  r  ry  r�   r½   Úenviron)ra  Ú	unit_homeÚenv_lines   &  r=   Ú#_sync_hermes_home_from_systemd_unitrš  è  s¢   € ÷ Ùä4¸DÔA×GÐGÀR×NÑNÓP€IßÜ"Ð#3¸DÔA×EÑEÀmÐUWÓXˆÜ# H§N¡NÓ$4Ó5×9Ñ9¸-ÈÓL×RÑRÓTˆ	ß”R—Z‘Z—^‘^ M°2Ó6×<Ñ<Ó>À)ÔKØ$-Œ�
‰
�=Ó!ñ L�yr@   c                óx   € V ^8„  d   QhR\         R\        \        R3,          R\        \        \        3,          /# )r7   ra  r{  .r8   )r:   rR   rQ   r<  )r;   s   "r=   r>   r>   ö  s6   € ÷ 6ñ 6Üð6ä”c˜3�h•ð6ô 
Œ#Œsˆ(…^ñ6r@   c                ó   € \        WR7      # )zCReturn selected ``systemctl show`` properties for the gateway unit.rc  )r~  ©ra  r{  s   &&r=   Ú_read_systemd_unit_propertiesrž  ö  s   € ô
 ˜:Ô5Ð5r@   c                ó2   € V ^8„  d   QhR\         R,          /# r›  r©   )r;   s   "r=   r>   r>   þ  s   € ÷ $ñ $œC $�Jñ $r@   c                ót   €  \        T ;'       g    ^ 4      pT^ 8”  d   T# R#   \        \        3 d     R# i ; i)z4``int(value)`` when it parses and is > 0, else None.N)rS   rþ   r�   )Úvaluerd   s   & r=   Ú_positive_pidr¢  þ  sB   € ðÜ�%—*�*˜1‹oˆð ˜”'ˆ3Ð#˜tÐ#øô ”zÐ"ô Úðús   ‚" �" ¢7¶7c                ó`   € V ^8„  d   QhR\         \        \        3,          R\        R,          /# )r7   Úpropsr8   N)r<  rQ   rS   )r;   s   "r=   r>   r>     s&   € ÷ ;ñ ;¬¬S´#¨X­ð ;¼3À½:ñ ;r@   c                 óL   € \        V P                  R R4      ;'       g    R4      # )ÚMainPIDÚ0©r¢  r  ©r¤  s   &r=   Ú_systemd_main_pid_from_propsrª    s    € Ü˜Ÿ™ 9¨cÓ2×9Ð9°cÓ:Ð:r@   c                ó>   € V ^8„  d   QhR\         R,          R\        /# )r7   ÚstateNr8   )r<  rS   )r;   s   "r=   r>   r>     s   € ÷ ;ñ ;œd T�kð ;¬cñ ;r@   c                ó`   € \        T ;'       g    / P                  R^ 4      4      ;'       g    ^ # )zV``pid`` recorded in a runtime-status dict; 0 when absent, unparsable, or non-positive.rd   r¨  )r¬  s   &r=   Ú_runtime_state_pidr®    s(   € ä˜%Ÿ+˜+ 2×*Ñ*¨5°!Ó4Ó5×:Ð:¸Ð:r@   c                ó>   € V ^8„  d   QhR\         R\        R,          /# r�  ©r:   rS   )r;   s   "r=   r>   r>     s"   € ÷ Vñ Vœdð V¬s°T­zñ Vr@   c                 ó,   € \        \        V R 7      4      # ©rc  )rª  rž  rc  s   &r=   Ú_systemd_main_pidr³    s   € Ü'Ô(EÈVÔ(TÓUÐUr@   c                ó2   € V ^8„  d   QhR\         R,          /# r›  )r<  )r;   s   "r=   r>   r>     s   € ÷ 6ñ 6¤d¨T¥kñ 6r@   c                  óv   €  ^ RI Hp  V ! 4       p\        T\        4      '       d   T# R#   \         d     R# i ; i)rF  ©Úread_runtime_statusN)rÛ   r·  r²   Ú
isinstancer<  )r·  r¬  s     r=   Ú_read_gateway_runtime_statusr¹    s?   € ðÝ6Ù#Ó%ˆô ˜u¤d×+Ò+ˆ5Ð5°Ð5øô ô Úðús   ‚) ©8·8c                ó\   € V ^8„  d   QhR\         R\        \        \        \        3,          /# r`  ©r:   rR   rQ   )r;   s   "r=   r>   r>     s)   € ÷ Iñ Iœdð I¤u¬S´#´s¨]Õ';ñ Ir@   c                ó   € V '       d   R# R# )z’``(sudo_prefix, scope_flag, user_flag)`` for printed hints: ``("sudo ", " --system", "")`` in
system scope, ``("", "", "--user ")`` in user scope.)zsudo z	 --systemr   )r   r   z--user rT   rc  s   &r=   Ú_systemd_cli_bitsr½    s   € ÷ *0Ð%ÐHÐ5HÐHr@   ra  Úprevious_pidÚreplacement_observedc          
      ó”   € V ^8„  d   QhR\         R\        R,          R\        R,          R\        \         ,          R,          R\         /# )r7   ra  r¾  Nr|   r¿  r8   )r:   rS   rf   r‚   )r;   s   "r=   r>   r>   #  sT   € ÷ Kñ KäðKô ˜•*ðKô �T�\ð	Kô
 œt�* tÕ+ðKô 
ñKr@   c                óÊ  a€ \        4       p\        V 4      P                  4       pVf   \        V R7      p\        P
                  ! 4       V,           pRp\        P
                  ! 4       V8  Ed/   \        V R7      pVP                  RR4      p	VP                  RR4      p
 ^ RIH	p V! 4       pT;'       g    \        V4      p\        4       p\        V4      pSev   Ver   V'       gj   \        ;QJ d+    V3R lT;'       g    ^ V3 4       F  '       g   K   R	M 	  RM! V3R lT;'       g    ^ V3 4       4      '       d   VP                  R	4       V	R
8X  dè   V'       dà   Se   VS8w  dÕ   Wì8w  d%   \        4       pV'       d   \        V4      V8w  d   RpT;'       g    / P                  R4      pVR!9   d+   \!        RV RV R24       VR8X  d   \!        RV R24       R	# VR8X  d<   T;'       g    / P                  R4      ;'       g    Rp\!        RV RV RV 24       R# V'       g   \!        RV RV R24       R	pV	R8X  d!   V
R8X  d   \        P"                  ! ^4       EK  \%        V4      '       d   \'        V R7       R# \        P"                  ! ^4       EKI  \)        V 4      w  ppp\!        RV R\+        V4       RV RV RV R 24       R#   \         d    Rp EL5i ; i)"zFWait for the gateway service to become active after a restart handoff.Nrc  FÚActiveStater   ÚSubState©r¸  c              3   óF   <"  € T F  q^ 8„  ;'       d    VS8g  x € K  	  R# 5irE  rT   )rÛ  r®  r¾  s   & €r=   rÜ  Ú4_wait_for_systemd_service_restart.<locals>.<genexpr>C  s%   øé € ÐUÑ9T°A˜‘E×/Ð/˜a <Ñ/Ô/Ó9Tùs   ƒ!“!Tre  Úgateway_stateÚdegradedõ   âœ“ z service restarted (PID Ú)õ   âš  u4    gateway is DEGRADED â€” see `hermes gateway status`Ústartup_failedÚexit_reasonzstartup failedz  service process restarted (PID z), but gateway startup failed: õ   â�³ z service process started (PID z!); waiting for gateway runtime...Ú
activatingúauto-restartz& service did not become active within zs.
  Check status: z1hermes gateway status
  Check logs:   journalctl ú-u z -l --since '2 min ago')rG   rÈ  )r†   Ú_service_scope_labelÚ
capitalizeÚ_systemd_restart_wait_timeoutrÜ   rÝ   rž  r  rÛ   r¸  r²   rª  r¹  r®  r/  rG  r9  rÞ   Ú_systemd_unit_is_start_limitedÚ_print_systemd_start_limit_waitr½  rS   )ra  r¾  r|   r¿  r¢   Úscope_labelrß   Úprinted_runtime_waitr¤  Úactive_stateÚ	sub_stater¸  Únew_pidÚruntime_stateÚruntime_pidrÇ  ÚreasonÚsudor?  Ú	user_flags   $d$$                r=   Ú!_wait_for_systemd_service_restartrá  #  s¸  ø€ ô Ó
€CÜ& vÓ.×9Ñ9Ó;€KØ‚Ü/°vÔ>ˆÜ�~Š~Ó 'Õ)€HØ Ðä
�.Š.Ó
˜XÕ
%Ü-°VÔ<ˆØ—y‘y °Ó3ˆØ—I‘I˜j¨"Ó-ˆ	ð	Ý6Ù%Ó'ˆGð ×@Ð@Ô9¸%Ó@ˆä4Ó6ˆÜ(¨Ó7ˆàÒ$Ø$Ò0ß(ß“ÔU¸'¿,¸,ÀQÈÑ9TÓU——’ÔU¸'¿,¸,ÀQÈÑ9TÓU×UÒUà ×'Ñ'¨Ô-à˜8Ô#¯°\Ò5IÈWÐXdÔMdØÔ%Ü <Ó >�ß Ô%7¸Ó%FÈ'Ô%QØ$(�MØ*×0Ð0¨b×5Ñ5°oÓFˆMØÐ 7Ô7Ü˜˜[˜MÐ)AÀ'ÀÈ!ÐLÔMØ  JÔ.ô ˜D  Ð-aÐbÔcÙØÐ 0Ô0Ø'×-Ð-¨2×2Ñ2°=ÓA×UÐUÐEU�ÜØ˜;˜-Ð'GÈÀyÐPoÐpvÐowÐxôñ ß'Ü˜˜[˜MÐ)GÈÀyÐPqÐrÔsØ'+Ð$à˜<Ô'¨I¸Ô,GÜ�JŠJ�qŒMÚä)¨%×0Ò0Ü+°6Õ:Ùä�
Š
�1�ä*¨6Ó2Ñ€Dˆ!ˆYÜ	Ø
ˆ{ˆmÐAÄ#ÀgÃ,Àð PØ˜&ð !&Ø&/ [°°C°5Ð8Oð	Qôñ
 øôk ô 	Ø‹Gð	ús   ÂK ËK"Ë!K"c                ó0   € V ^8„  d   QhR\         R\        /# r`  )r:   rf   )r;   s   "r=   r>   r>   q  s   € ÷ 
$ñ 
$¬$ð 
$¼5ñ 
$r@   c                óð   € ^ RI Hp \        V RR7      pRpR FS  pVP                  VR4      pVP	                  4       '       d   \        V4      MV! V4      pVf   KD  W6R,          ,          pKU  	  RV,           # )zGCover systemd's relaunch delays before applying the runtime wait floor.)Úparse_systemd_duration_to_usr�  r`   r   i@B g      N@)ÚRestartUSecÚTimeoutStartUSec)Úgateway.shutdown_forensicsrä  rž  r  rQ  rS   )ra  rä  r¤  Úsupervisor_budgetrk   r¶   Úduration_uss   &      r=   rÔ  rÔ  q  sp   € åGÜ)°ÐDgÔh€EØÐÛ3ˆØ�i‰i˜˜bÓ!ˆØ"%§+¡+§-¢-”c˜#”hÑ5QÐRUÓ5VˆØÔ"Ø¨yÕ!8Õ8Òñ	 4ð
 Ð#Õ#Ð#r@   c                óR   € V ^8„  d   QhR\         \        \        3,          R\        /# )r7   r¤  r8   )r<  rQ   r:   )r;   s   "r=   r>   r>   ~  s&   € ÷ eñ e¬$¬s´C¨x­.ð e¼Tñ er@   c                 óˆ   € R V P                  RR4      P                  4       V P                  RR4      P                  4       39   # )ústart-limit-hitÚResultr   rÃ  )r  rm  r©  s   &r=   rÕ  rÕ  ~  s;   € Ø §¡¨8°RÓ!8×!>Ñ!>Ó!@À%Ç)Á)ÈJÐXZÓB[×BaÑBaÓBcÐ dÑdÐdr@   c                óD   € V ^8„  d   QhR\         P                  R\        /# )r7   rÄ  r8   )r‡   ÚCalledProcessErrorr:   )r;   s   "r=   r>   r>   ‚  s%   € ÷ nñ n¬j×.KÑ.Kð nÔPTñ nr@   c                 óD  € . pR F[  p\        WR4      pV'       g   K  TP                  \        V\        4      '       d   VP	                  RR7      M
\        V4      4       K]  	  RP                  V4      P                  4       pRV9   ;'       g    RV9   ;'       g    RV9   # )	rM  Nr-   rM  r|  rì  z"start request repeated too quicklyzstart-limit)rM  rŠ   Úoutput)rÉ  rG  r¸  ÚbytesrT  rQ   r“  rm  )rÄ  r¡   Úattrr¡  r/   s   &    r=   Ú$_systemd_error_indicates_start_limitrô  ‚  s�   € Ø€EÛ.ˆÜ˜ 4Ó(ˆß‰5Ø�L‰L¼:ÀeÌU×;SÒ;S˜Ÿ™¨Y˜Ô7ÔY\Ð]bÓYcÖdñ /ð �9‰9�UÓ×!Ñ!Ó#€DØ Ñ$×mÐmÐ(LÐPTÑ(T×mÐmÐXeÐimÑXmÐmr@   c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>   Œ  s   € ÷ Xñ X¬dð X¼tñ Xr@   c                 ó,   € \        \        V R 7      4      # r²  )rÕ  rž  rc  s   &r=   Ú!_systemd_service_is_start_limitedr÷  Œ  s   € Ü)Ô*GÈvÔ*VÓWÐWr@   c                ó(   € V ^8„  d   QhR\         RR/# r�  r9   )r;   s   "r=   r>   r>   �  s   € ÷ Rñ R¬Dð R¸Tñ Rr@   c                 ó  € \        4       p\        V 4      P                  4       p\        V 4      w  r4p\	        R V R24       \	        R4       \	        RV RV 24       \	        RV RV 24       \	        RV RV R	24       R
# )rÎ  z0 service is temporarily rate-limited by systemd.zC  systemd is refusing another immediate start after repeated exits.z7  Wait for the start-limit window to expire, then run: úhermes gateway restartz0  Or clear the failed state manually: systemctl úreset-failed z  Check logs: journalctl rÑ  z -l --since '5 min ago'N)r†   rÒ  rÓ  r½  r9  )ra  r¢   r×  rß  Ú
scope_flagrà  s   &     r=   rÖ  rÖ  �  s‘   € Ü
Ó
€CÜ& vÓ.×9Ñ9Ó;€KÜ"3°FÓ";Ñ€D�iÜ	ˆD��ÐMÐ
NÔOÜ	Ð
OÔPÜ	ÐCÀDÀ6ÐI_Ð`jÐ_kÐ
lÔmÜ	Ð<¸Y¸KÀ}ÐUXÐTYÐ
ZÔ[Ü	Ð% i [°°C°5Ð8OÐ
PÖQr@   c                óJ   € V ^8„  d   QhR\         R\        R,          R\         /# )r7   ra  r¾  Nr8   r°  )r;   s   "r=   r>   r>   ›  s&   € ÷ ñ ¬Tð ÌÈtÍð Ô_cñ r@   c                óf  € \        V R7      pV'       g   R#  ^ RIHp T! 4       ;'       g    / P	                  R4      '       g   R# TP	                  RR4      pTR8X  d/   TP	                  RR4      R	8X  d   \        R
4       \        YR7      # TR8X  dŒ   TP	                  RR4      \        \        4      8X  g   TP	                  RR4      R8X  dQ   \        4       p\        R\        T 4       R24       \        RT.T R^R7       \        RT.T R^ZR7       \        YR7      # R#   \         d     R# i ; i)zARecover a planned service restart that is stuck in systemd state.rc  Fr¶  Úrestart_requestedrÂ  r   rÏ  rÃ  rÐ  uG   â�³ Service restart already pending â€” waiting for systemd relaunch...©ra  r¾  ÚfailedÚExecMainStatusrí  z	exit-codeu&   â†» Clearing failed state for pending z service restart...úreset-failed©ra  r}   r|   Ústart)rž  rÛ   r·  r²   r  r9  rá  rQ   r   r†   rÒ  rh  )ra  r¾  r¤  r·  rÙ  r¢   s   &&    r=   Ú _recover_pending_systemd_restartr  ›  s  € ä)°Ô8€EßÙðÝ6ñ  Ó!×'Ð' R×,Ñ,Ð-@×AÒAÙà—9‘9˜]¨BÓ/€LØ�|Ô#¨¯	©	°*¸bÓ(AÀ^Ô(SÜÐWÔXÜ0¸ÔZÐZà�xÔØ�	‰	Ð" BÓ'¬3Ô/PÓ+QÔQØ�9‰9�X˜rÓ" kÔ1äÓ ˆÜÐ6Ô7KÈFÓ7SÐ6TÐTgÐhÔiÜ˜¨Ð,°VÀ5ÐRTÕUÜ˜ �~¨f¸EÈ2ÕNÜ0¸ÔZÐZáøô+ ô Úðús   ˜D! Ä!D0Ä/D0c                ó>   € V ^8„  d   QhR\         R\        R,          /# ©r7   rñ  r8   Nr  )r;   s   "r=   r>   r>   »  s   € ÷ ñ ´ð ¼¸d½
ñ r@   c                ó4  € V P                  4        Fƒ  pVP                  4       pVP                  R4      '       g   K,  RV9   g   K5  \        VP	                  R^4      ^,          P                  4       P                  R4      P                  R4      4      u # 	  R# )z{PID from ``launchctl list <label>`` (``"PID" = <n>;``); None if absent (registered, not running)
or non-positive (crashed).rs  Ú;rƒ  N)z"PID"ÚPID)rŒ   r‹   r›   r¢  r�   r€  ©rñ  r    r”  s   &  r=   Ú#_parse_launchd_pid_from_list_outputr  »  sz   € ð ×!Ñ!Ö#ˆØ—:‘:“<ˆØ×ÑÐ/×0Ô0°S¸H¶_Ü  §¡°°QÓ!7¸Õ!:×!@Ñ!@Ó!B×!IÑ!IÈ#Ó!N×!TÑ!TÐUXÓ!YÓZÒZñ $ñ r@   c                ó>   € V ^8„  d   QhR\         R\        R,          /# r  r  )r;   s   "r=   r>   r>   Å  s   € ÷ ñ ´ð ¼¸t½ñ r@   c                óÐ   € V P                  4        FQ  pVP                  4       pVP                  R4      '       g   K,  \        V\	        R4      R P                  4       4      u # 	  R# )zbLive PID from ``launchctl print`` (first ``pid = <N>`` line wins); None if absent or non-positive.zpid = N)rŒ   r‹   r›   r¢  rš   r  s   &  r=   Ú$_parse_launchd_pid_from_print_outputr  Å  sU   € à×!Ñ!Ö#ˆØ—:‘:“<ˆØ×Ñ˜x×(Ô(Ü  ¬#¨h«-¨.Ð!9×!?Ñ!?Ó!AÓBÒBñ $ñ r@   c          	      ól   € V ^8„  d   QhR\         R\         R\        \        \        R,          3,          /# )r7   Údomainr¤   r8   N)rQ   rR   r:   rS   )r;   s   "r=   r>   r>   Î  s4   € ÷ Gñ G¤sð G´3ð G¼5ÄÄsÈTÅzÐAQÕ;Rñ Gr@   c                óÐ   €  \         P                  ! RRV  RV 2.3R^/\        BRR/B pTP                  ^ 8w  d   R# R\        TP                  4      3#   \         d    Ru # i ; i)	u.  ``(loaded, pid)`` for ``domain/label`` via ``launchctl print`` (domain-explicit; ``launchctl list``
infers it from caller context). ``TimeoutExpired`` propagates: a wedged launchctl is not "unloaded".

Domain-explicit on purpose: legacy ``launchctl list`` infers its domain from the caller's execution
context, which is exactly the ambiguity that sank the first fleet-restart attempt (#41403 review).
``TimeoutExpired`` propagates â€” fleet-restart callers own per-label failure accounting (a wedged
launchctl call must be reported, not read as "unloaded").
r�   r9  rf  r|   r}   FT©FN)r‡   rˆ   r‰   r’   r™   r  rŠ   )r  r¤   rŸ   s   && r=   Ú_launchd_print_service_pidr  Î  s{   € ðÜ—’ ¨g¸&¸ÀÀ5À'Ð7JÐ KÑuÐUVÐuÔZgÑuÐotÒuˆð ×Ñ˜AÔØÐØÔ6°v·}±}ÓEÐFÐFøô	 ô ØÒðús   ‚)A ÁA%Á$A%c                ó<   € V ^8„  d   QhR\         R\        R\        /# )r7   r¤   r|   r8   r  )r;   s   "r=   r>   r>   à  s!   € ÷ "ñ "¤sð "¼ð "ÄDñ "r@   c               óh   € \         P                  ! RRV .3RV/\        BRR/B pVP                  ^ 8H  # )zÆTrue when launchd knows ``label`` (``launchctl list`` exit 0). Domain-agnostic, so still true on
macOS 26+ hosts whose per-user domains reject management. FileNotFoundError/TimeoutExpired propagate.r�   r‚   r|   r}   F)r‡   rˆ   r‰   r™   )r¤   r|   rŸ   s   &$ r=   Ú_launchd_service_registeredr  à  s:   € ô �^Š^˜[¨&°%Ð8ÑhÀ'ÐhÌ]ÑhÐbgÒh€FØ×Ñ Ñ!Ð!r@   c                ón   € V ^8„  d   QhR\         R\        \         R,          \        R,          3,          /# )r7   r¤   r8   Nr�  )r;   s   "r=   r>   r>   ç  s,   € ÷ ñ ¬3ð ´5¼¸t½ÄSÈ4ÅZÐ9OÕ3Pñ r@   c                ó†   € \         P                  ! 4       pRV 2RV 23 F  p\        W 4      w  r4V'       g   K  W$3u # 	  R# )uÅ   ``(domain, pid)`` for ``label``, probing ``gui/<uid>`` then ``user/<uid>``. Never uses the current
profile's cached ``_launchd_domain()`` â€” a fleet can mix domains. ``TimeoutExpired`` propagates.zgui/zuser/©NN)r½   Úgetuidr  )r¤   Úuidr  Úloadedrd   s   &    r=   r˜   r˜   ç  sK   € ô �)Š)‹+€CØ˜#˜�< 5¨¨ Ó/ˆÜ0°Ó?‰ˆß‰6Ø�=Ò ñ 0ð Ðr@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   ò  s   € ÷ kñ k¬ñ kr@   c                 óh   € \        4       P                  4       ;'       d    \        \        4       4      # )zRTrue when the plist exists AND launchd is running a process for the current label.)Úget_launchd_plist_pathrg  Ú$_launchctl_label_supervising_processr”   rT   r@   r=   Ú_probe_launchd_service_runningr#  ò  s&   € ä!Ó#×*Ñ*Ó,×jÐjÔ1UÔVgÓViÓ1jÐjr@   c                óX   € V ^8„  d   QhR\         \        R3,          R\        R,          /# )r7   rD   .r8   N)rR   rS   r4   )r;   s   "r=   r>   r>   ÷  s)   € ÷ ñ ¤u¬S°#¨X¥ð Ô;QÐTXÕ;Xñ r@   c                ó^  € ^ RI HpHp V! 4       R8w  d   R# R\        4        2pV! 4       pR;rV \	        VRR4      pVe   Ws,          P                  4       pT'       d    \        TP                  T4      4      p\        RTTT RR7      #   \         d    Rp LBi ; i  \         d    Rp L2i ; i)	z[Snapshot for an s6-supervised container gateway, or None when s6 isn't the service manager.©Údetect_service_managerÚget_service_managerÚs6Núgateway-FÚscandirzs6 (container supervisor)©rO   rK   rC   rD   rP   )
Úhermes_cli.service_managerr'  r(  Ú_current_profile_namerÉ  Úis_dirr²   r:   Ú
is_runningr4   )rD   r'  r(  ró  ÚmgrrK   rC   Úservice_dirs   &       r=   Ú_s6_gateway_snapshotr3  ÷  sÇ   € çVÙÓ 4Ô'ÙØÔ3Ó5Ð6Ð7€LÙ
Ó
€CØ*/Ð/Ðð"Ü˜c 9¨dÓ3ˆØÒ"Ø!,Õ!;× CÑ CÓ EÐ÷ ð	$Ü" 3§>¡>°,Ó#?Ó@ˆOô "Ø+Ø+Ø'Ø!Øôð øô ô "Ø!Òð"ûô
 ô 	$Ø#ŠOð	$ús#   ¯'B	 ÁB Â	BÂBÂB,Â+B,c                ó0   € V ^8„  d   QhR\         R\        /# r`  )r:   r4   )r;   s   "r=   r>   r>     s   € ÷ %Wñ %W¬ð %WÔ:Pñ %Wr@   c                óJ  € \        \        4       4      p\        4       '       d   \        RVR7      # ^ RIHp \        4       '       d.   V! 4       '       d!    \        V4      pVe   V#  \        RVR7      # \        4       '       dF   \        V R7      w  rE\        V4      p\        RV R2\        VR7      P                  4       VVVR7      # \        4       '       d/   \        R	\        4       P                  4       \!        4       VR	R7      # \        R
VR7      #   \         d     Lºi ; i)zBReturn a unified view of gateway liveness for the current profile.zTermux / manual process)rO   rD   )Úis_containerzdocker (foreground)rc  z	systemd (rÊ  r,  Úlaunchdzmanual process)rR   r´  Ú	is_termuxr4   r4  r6  Úis_linuxr3  r²   r…   ro  rÒ  rf  rg  r“   r!  r#  )ra  rD   r6  Úsnapshotrn  rC   r×  s   &      r=   Úget_gateway_runtime_snapshotr;    s  € äÔ*Ó,Ó-€LÜ‡{‚{Ü%Ð.GÐVbÔcÐcå-Ü‡z‚z‘l—n’nð	Ü+¨LÓ9ˆHØÒ#Ø�ð $ô &Ð.CÐR^Ô_Ð_ä ×"Ò"Ü+IÐQWÔ+XÑ(ˆÜ*¨?Ó;ˆÜ%Ø ˜}¨AÐ.Ü3¸?ÔK×RÑRÓTØ+Ø%Ø%ô
ð 	
ô ‡z‚zÜ%ØÜ4Ó6×=Ñ=Ó?Ü:Ó<Ø%Ø#ô
ð 	
ô "Ð*:ÈÔVÐVøô1 ô 	Ùð	ús   ÁD ÄD"Ä!D"Úlimitc                ó�   € V ^8„  d   QhR\         \        R3,          \        \        ,          ,          R\        R,          R\        /# )r7   rœ   .r<  Nr8   )rR   rS   r‚   rQ   )r;   s   "r=   r>   r>   ;  s7   € ÷ ñ œu¤S¨# X�´´cµÕ:ð ÄcÈDÅjð ÔY\ñ r@   c                óÎ   € Vf   T MV R V  Uu. uF  q"^ 8”  g   K  \        V4      NK  	  ppVe"   \        V 4      V8”  d   VP                  R4       RP                  V4      # u upi )Nz...rÙ  )rQ   rš   rG  r“  )rœ   r<  rd   Úrendereds   &$  r=   Ú_format_gateway_pidsr@  ;  se   € Ø-2ª]¡TÀÀVÀeÀÐ%LÓYÑ%L˜SÐWXÑQX””�C–Ñ%L€HÐYØÒœS ›Y¨Ô.Ø�‰˜ÔØ�9‰9�XÓÐùò Zs
   ŽA"›A"c                ó(   € V ^8„  d   QhR\         RR/# )r7   r:  r8   N)r4   )r;   s   "r=   r>   r>   B  s   € ÷ Nñ NÔ.Dð NÈñ Nr@   c                 óJ  € V P                   '       g   R # \        4        R\        V P                  R R7       2p\	        4       '       d/   \        R4       \        V4       \        R4       \        R4       R # \        R4       \        V4       \        R4       \        R4       R # )	Nz
  PID(s): )r<  uU   âš  Gateway is running as a detached fallback process â€” launchd cannot supervise itzB  Auto-start at login and auto-restart on crash are NOT available.z#  Stop it with: hermes gateway stopuN   âš  Gateway process is running for this profile, but the service is not activezI  This is usually a manual foreground/tmux/nohup run, so `hermes gateway`z<  can refuse to start another copy until this process stops.)rL   r9  r@  rD   Ú"_launchd_unsupported_marker_exists)r:  Ú	pids_lines   & r=   Ú_print_gateway_process_mismatchrE  B  s€   € Ø×0×0Ð0ÙÜ	„GØÔ1°(×2GÑ2GÈtÔTÐUÐV€Iä)×+Ò+ÜÐeÔfÜˆiÔÜÐRÔSÜÐ3Ö4äÐ^Ô_ÜˆiÔÜÐYÔZÜÐLÖMr@   c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   T  s   € ÷ ñ ¨Dñ r@   c                 óD   € ^ RI Hp  V ! 4        F  p\        V4       K  	  R# )z[The boot guard kept an unset-default gateway standalone: say so in status, with the remedy.)Ú!recorded_standalone_warning_linesN)Ú!hermes_cli.gateway_multiplex_moderH  r9  )rH  r    s     r=   Ú"_print_multiplex_standalone_reasonrJ  T  s   € åSÙ1Ö3ˆÜˆdŽó 4r@   c                ó6   € V ^8„  d   QhR\         R,          RR/# ©r7   rb   Nr8   r—  )r;   s   "r=   r>   r>   [  s   € ÷ ñ ¬¨d­
ð ¸dñ r@   c                ó   €  ^ RI HpHp V! V 4      pT'       g   R# \	        4        \	        R4       \        TP                  4       4       F.  w  rET! YP'       g   RT R2MRR7       F  p\	        T4       K  	  K0  	  R#   \         d     R# i ; i)z¥Callback URLs of inbound-port platforms the live multiplexer serves for secondary profiles
(the value to paste into the Twilio / LINE / Teams / BlueBubbles console).)Úformat_ingress_url_linesÚserved_profile_ingress_urlsNz-Inbound callback URLs on the shared listener:ú  rf  )Úindent)Ú#hermes_cli.gateway_multiplex_servedrN  rO  r²   r9  r—   rv  )rb   rN  rO  Úurlsrk   Úper_platformr    s   &      r=   Ú_print_served_ingress_urlsrU  [  s}   € ðßmÙ*¨7Ó3ˆ÷ ÙÜ	„GÜ	Ð
9Ô:Ü$ T§Z¡Z£\Ö2ÑˆÙ,¨\ÖV]ÀBÀtÀfÈAÁ,Ðcg×hˆDÜ�$ŽKó ió 3øô ô Úðús   ‚A> Á>BÂBc                ó6   € V ^8„  d   QhR\         R,          RR/# rL  r—  )r;   s   "r=   r>   r>   l  s"   € ÷ kñ k¬C°$­Jð k¸4ñ kr@   c                ó   €  ^ RI Hp T! T ;'       g    R4      pT'       g   R# \        4        \	        TP                  4       4       F  w  r4\        RT RT 24       K  	  \        R4       R#   \         d     R# i ; i)u²   Shared-ingress platforms (WhatsApp/Relay) this served profile enabled that the multiplexer runs
only on the default profile â€” the ``whatsapp: not served under multiplex`` line.)Ú!served_profile_unserved_platformsr   Nu     âš  ú: z]  Enable it on the default profile (shared ingress serves every profile), or disable it here.)rR  rX  r²   r9  r—   rv  )rb   rX  Úunservedrè  rÞ  s   &    r=   Ú_print_unserved_shared_ingressr[  l  sr   € ðÝYÙ4°W·]°]ÀÓCˆ÷ ÙÜ	„GÜ" 8§>¡>Ó#3Ö4ÑˆÜ��x�j  6 (Ð+Ö,ñ 5ä	Ð
iÖjøô ô Úðús   ‚A. “A. Á.A=Á<A=c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   |  s   € ÷ ñ ¨dñ r@   c                 óB  €  ^ RI Hp  V ! 4       p\        4        Uu. uF  q"P                  V8w  g   K  VNK  	  ppV'       g   R# \	        4        \	        R4       V F)  p\	        RVP                  R RVP
                   24       K+  	  R# u upi   \         d     R# i ; i)zRPrint other profiles' running gateways at the bottom of ``hermes gateway status``.)Úget_active_profile_nameNzOther profiles:u     âœ“ z<16su	    â€” PID )r¿  r^  rÅ  rb   r9  rd   r²   )r^  Úcurrentr®  Úother_processesÚprocs        r=   Ú$_print_other_profiles_gateway_statusrb  |  s�   € ðÝ?Ù)Ó+ˆÜ&DÔ&FÓ_Ñ&F Ï)É)ÐW^ÑJ^Ÿ1˜1Ñ&FˆÐ_ßÙÜŒÜÐÔ Û#ˆDÜ�F˜4Ÿ<™<¨Ð-¨Y°t·x±x°jÐAÖBó $ùò `øô ô Úðús-   ‚B ›B
²B
¸
B ÁAB Â
B ÂBÂBc                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   Œ  s   € ÷ 	%ñ 	%¨dñ 	%r@   c                 óð   € \         P                  ! \        4      ;_uu_ 4        ^ RIHp  V ! 4       pV'       d"   \        4        V F  p\        RV 24       K  	  RRR4       R#   + '       g   i     R# ; i)z¼The migrate preflight's duplicate-credential findings, so ``gateway status`` explains a parked
or racing bot (and why the fleet will not fold) with the same words as ``migrate --dry-run``.)Úduplicate_credential_findingsrË  N)rö   r÷   r²   Úhermes_cli.gateway_migratere  r9  )re  Úlinesr    s      r=   Ú$_print_duplicate_credential_warningsrh  Œ  sO   € ô 
×	Ò	œY×	'Õ	'ÝLÙ-Ó/ˆßÜŒGÛ�Ü˜˜T˜F�mÖ$ñ ÷ 
(×	'×	'Ò	'ús   £7A$Á$A5	c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   ˜  s   € ÷ !#ñ !#�tñ !#r@   c                 óÄ  €  ^ RI Hp Hp T ! 4       pT'       g   \	        R4       R# T! 4       p\	        R4       T Fô  pTP
                  '       d   RMRpTP                  TP                  T8X  d   RMR	,           pR
T RTR 2.pTP
                  '       do   Rp ^ RIHp	 T	! TP                  R,          RR7      pT'       d   TP                  RT 24       M>\        TP                  4      '       d   TP                  R4       MTP                  R4       \	        RP                  T4      4       Kö  	  R#   \         d    \	        R4        R# i ; i  \         d     L¥i ; i)z6List every profile and whether its gateway is running.)r»  r^  zUnable to list profiles.NzNo profiles found.z	Gateways:u   âœ“u   âœ—z
 (current)r   rP  rO  z<24srÄ  r¼  Fr½  zPID z!served by the default multiplexerznot runningu    â€” )r¿  r»  r^  r²   r9  Úgateway_runningrk   rÛ   r¸  rc   rG  Ú+named_profile_served_by_running_multiplexerr“  )
r»  r^  rÂ  r_  ÚprofÚmarkerr¤   r¡   rd   r¸  s
             r=   Ú_gateway_listro  ˜  s/  € ðßNñ
 ‹€HßÜÐ"Ô#Ùá%Ó'€Gä	ˆ+ÔÛˆØ×.×.Ð.‘°EˆØ—	‘	¨T¯Y©Y¸'Ô-A™\ÀrÕJˆØ�f�X˜Q˜u T˜lÐ+Ð,ˆØ××ÐØˆCðÝ:Ù% d§i¡i°-Õ&?ÈuÔU�÷ Ø—‘˜t C 5˜\Õ*Ü<¸T¿Y¹Y×GÒGØ—‘Ð@ÔAøà�L‰L˜Ô'Üˆg�l‰l˜5Ó!Ö"ó# øô ô ÜÐ(Ô)Úðûô* ô Ùðús#   ‚D4 Â!EÄ4EÅEÅEÅEc                óV   € V ^8„  d   QhR\         R\        R,          R\         R\        /# )r7   r5  rC  Nrv   r8   )r:   rw   rS   )r;   s   "r=   r>   r>   ¼  s.   € ÷ !ñ !¤$ð !¼cÀD½jð !Ô_cð !Ôpsñ !r@   c                óî  € ^ p\        WR7      pV'       dF   ^ RIHp V! V4      w  rFV F/  w  rx\        RT RV'       d   RV,           R,           MR R24       K1  	  V FA  p R	p	V '       d   \	        V4      f   K  ^ R
IHp
 V
! V4      p	\        WpV	R7       V^,          pKC  	  V#   \         d     KU  \         d    \        RT 24        Kp  \         d   p\        RT RT 24        R	p?K‘  R	p?ii ; i)an  Kill running gateway processes (force-kill if ``force``); ``exclude_pids`` skips e.g. just-
restarted service PIDs. Returns count killed. ``all_profiles`` sweeps only gateways whose live home
is this install's root or one of its profiles: the process scan is account-wide, and a scratch-home
``gateway stop --all`` would otherwise SIGTERM the account's real gateway.)rC  rv   )Úpartition_gateway_pids_by_scopeu   â†· PID z: gateway of zanother Hermes home (rÊ  zan unreadable homeu    â€” left aloneNr2  r6  õ"   âš  Permission denied to kill PID zFailed to kill PID rY  )r´  Úhermes_cli.update_fleet_scoperr  r9  r  rÛ   r3  r   rÈ   rÉ   rÊ   )r5  rC  rv   Úkilledrœ   rr  Úforeignrd   rä   r7  r3  rÄ  s   &&&         r=   Úkill_gateway_processesrw  ¼  s  € ð
 €FÜ¨,ÔR€DßÝQÙ7¸Ó=‰ˆÛ ‰IˆCÜ�H˜S˜E ×W[Ð/FÈÕ/MÐPSÖ/SÐauÐ.vð  wFð  Gö  Hñ !ãˆð	6Ø"&Ðßô )¨Ó-Ò5ÙÝAÙ&<¸SÓ&AÐ#Ü˜#Ð@SÕTØ�a�KŠFñ ð* €Møô "ô 	ÚÜô 	>ÜÐ6°s°eÐ<×=Üô 	6ÜÐ'¨ u¨B¨s¨eÐ4×5Ò5ûð	6ús6   Á"B%Á;$B%Â%C4Â3C4Â<C4ÃC4ÃC4ÃC/Ã/C4c                ó0   € V ^8„  d   QhR\         R\        /# rÂ   r»   )r;   s   "r=   r>   r>   ã  s   € ÷ ñ ¬sð ´tñ r@   c                óâ  € \        4       '       g   R#  ^ RIpVP                  V 4      P                  4       p\	        \
        4       F  pVf    R# \        P                  ! \        4      ;_uu_ 4        VP                  4       ;'       g    RP                  4       R8X  d    RRR4        R#  RRR4       VP                  4       pK�  	   R#   + '       g   i     L'; i  \         d     R# i ; i)u*  True when ``pid``'s parent chain reaches ``services.exe`` (Task Scheduler-owned gateway). Windows-only
reaper backstop: ``_get_service_pids()`` is empty there, so a Scheduled-Task gateway with a stale
pidfile would look like an orphan. Fail-open once the Task's bootstrap parent exits. Not applied
on POSIX, where everything descends from PID 1 and would look supervised.

See #83683, #86098.
This check is deliberately NOT applied on POSIX: there, every process has PID 1 (launchd / init /
systemd) in its ancestry â€” and a genuine orphan is *reparented directly to PID 1* â€” so supervisor-name
ancestry carries zero signal and would spare every orphan the reaper exists to kill (#51325, 75936).
POSIX supervised gateways are already covered pidfile- independently by the ``_get_service_pids()``
exclusion.
FNr   zservices.exeT)r³   r®   r¯   r@  r	  Ú_REAPER_SUPERVISOR_WALK_LIMITrö   r÷   r²   rk   rm  )rd   r®   r@  r?  s   &   r=   Ú%_reaper_candidate_is_supervisor_ownedr{  ã  sÀ   € ô �<Š<ÙðÛØ—‘ Ó$×+Ñ+Ó-ˆÜÔ4Ö5ˆAØŠ~Øñ ô ×$Ò$¤Y×/Õ/Ø—K‘K“M×'Ð' R×.Ñ.Ó0°NÔBØ÷ 0Ò/ØB÷ 0ð —]‘]“_ŠFò 6ñ ÷ 0×/ûô ô ØÙðús5   ”:C Á"C Á2/CÂ!	C Â-C ÃCÃC ÃC.Ã-C.Ú	min_age_sr`   c                óJ   € V ^8„  d   QhR\         R,          R\        R\        /# )r7   Úextra_excludeNr|  r8   )rw   rf   r:   )r;   s   "r=   r>   r>     s-   € ÷ añ aÜ˜•:ðaÜ49ðaä	ñar@   c               óŒ  aa€  \        4       pV'       d   R# \        4       '       d"    ^ RIHp V! 4       p\        V4      '       d   R# ^ RIHpHpH	p \        V 4      p \        VR7       U	u. uF*  q™'       g   K  V	^ 8”  g   K  \        V	4      '       d   K(  V	NK,  	  p
p	S^ 8”  d1   ^ RIHo R TT3R	 llpT
 U	u. uF  q›! T	4      '       g   K  T	NK  	  p
p	T
'       g   R# / pT
 F  pT! T4      pTf   K  YìT&   K  	  RpT
 Fr  p\        P                   ! \        4      ;_uu_ 4        T! T4       R
R
R
4       \        4       '       d   RpKJ   \"        P$                  ! T\&        P(                  4       RpKt  	  \1        \3        Y¥R7       Uu. uF"  pYÜ9   g   K  T! T4      YÍ,          8X  g   K   TNK$  	  up4       T#   \         d    Rp EL½i ; i  \         d    Rp EL©i ; iu up	i   \         d     R# i ; iu up	i   + '       g   i     LØ; i  \*         d     EK   \,         d    \/        RT 24        EK<  i ; iu upi )u¥  Kill no-supervisor gateway orphans the pidfile/runtime record can't see. On WSL/no-systemd hosts
the restart fallback runs the gateway in-process under a ``gateway restart`` argv; a stale pidfile
then lets a live orphan keep the webhook port while a restart stacks a duplicate. No-op where a
supervisor exists (there ``gateway restart`` is a transient command). ``extra_exclude``: already killed.

``min_age_s`` spares a candidate younger than the grace: a gateway claims
``gateway.pid``/``gateway.lock`` only after imports + runner setup, so a process
that a previous Desktop generation (or a concurrent ``gateway start``) just launched
is scan-visible but not yet record-visible, and the argv sweep cannot tell it from
a corpse. Reaping it writes a planned-stop marker it consumes seconds later â€” a clean
exit 0 with no supervisor to revive it (#122533). The Desktop boot sweep passes a
grace; stop/restart keep reaping at once.
TF)Úget_task_nameÚHermes_Gateway)rÙ   r3  Úwrite_planned_stop_marker)rC  )Ú_process_age_secondsc                ó0   € V ^8„  d   QhR\         R\        /# rÂ   r»   )r;   s   "r=   r>   Ú8_reap_unsupervised_gateway_orphans.<locals>.__annotate__3  s   € ÷ 	ñ 	œSð 	¤Tñ 	r@   c                 ó@   <€  S! V 4      S8¬  #   \          d     R # i ; i©F)r²   )rd   rƒ  r|  s   &€€r=   Ú_old_enoughÚ7_reap_unsupervised_gateway_orphans.<locals>._old_enough3  s*   ø€ ðÙ+¨CÓ0°IÑ=Ð=øÜô Úðús   ƒ
 ŽœNu3   âš  Permission denied to kill orphaned gateway PID )Ú
pid_exists)r…   r²   r³   ré  r€  Ú"_windows_scheduled_task_supervisesrÛ   rÙ   r3  r‚  Ú_reaper_exclusion_pidsr´  r{  r}  rƒ  rö   r÷   r½   rÇ   rÆ   ÚSIGTERMrÈ   rÉ   r9  Ú_force_kill_survivorsÚ_await_gateway_exit)r~  r|  Úsupervised_hostr€  Ú
_task_namerÙ   r3  r‚  Úownr®  Úorphansrˆ  Úorphan_identityrd   r  Úreapedrƒ  s   &d              @r=   Ú"_reap_unsupervised_gateway_orphansr–    s"  ù€ ð Ü3Ó5ˆ÷ Ùô ‡|‚|ð	*Ý@Ù&›ˆJô .¨j×9Ò9Ùç]Ñ]Ü
  Ó
/€Cðô )°cÕ:ó
Ù:�!»aŒAÀAÈÁEŒAÔRwÐxy×Rz�AˆAÑ:ð 	ð 
ð
 �1„}ÝC÷	ñ 	ñ &Ó8™g˜¨°Q¯—1�1™gˆÐ8ßÙð ')€OÛˆÙ& sÓ+ˆØÔØ#(˜CÓ ñ ð
 €FÛˆÜ× Ò ¤×+Õ+Ù% cÔ*÷ ,ô
 �<Š<ØˆFÙð	Ü�GŠG�CœŸ™Ô(ð Šñ! ô( Ü*¨7ÕKóÙK�ØÑ!ô 	Ù&<¸SÓ&AÀ_ÕEYÑ&Y÷ 	ˆÑKñô ð €Møô_ ô Ø‹ðûô ô 	*Ø)‹Jð	*üò
øô ô Úðüò 9÷$ ,×+ûô "ô 	ÛÜô 	ÜÐGÈÀuÐMÔNÛð	üòs    „
F; ©G ÁG( Á-	G#Á;G#ÂG#ÂG#ÂG( Â:G:ÃG:Ä&	G?Å%HÆ
IÆIÆ,IÆ;GÇGÇG ÇG Ç#G( Ç(G7Ç6G7Ç?HÈH>È!H>È*H>È=H>c                óT   € V ^8„  d   QhR\         R,          R\         \        ,          /# )r7   r~  Nr8   r<  )r;   s   "r=   r>   r>   e  s"   € ÷ (ñ (¬#°­*ð (¼¼S½ñ (r@   c                óæ  € \         P                  ! 4       0T ;'       g    \        4       ,          p\        P                  ! \
        4      ;_uu_ 4        V\        RR7      ,          pRRR4        ^ RIHpH	pH
pHp V! 4       V! 4       3 Uu0 uF
  qb! V4      kK  	  ppVP                  V! RR7      4       V Fz  pV'       d   V^ 8:  d   K  VP                  V4        ^ RIp	V	P                  V4      P                  4       p
V
e.   VP                  V
P                   4       V
P                  4       p
K1  K|  	  V#   + '       g   i     LÙ; iu upi   \
         d     K¦  i ; i  \
         d     T# i ; i)zWPIDs the orphan reaper must never kill: self, caller extras, service-managed, recorded.Tr±  N)Ú_pid_from_recordÚ_read_gateway_lock_recordÚ_read_pid_recordr¸  Fr½  )r½   r¾   rw   rö   r÷   r²   r¦   rÛ   r™  rš  r›  r¸  r�   r®   r¯   r@  rd   )r~  r’  r™  rš  r›  r¸  ÚrecÚrecorded_pidsÚrecordedr®   r@  s   &          r=   rŒ  rŒ  e  s5  € ä�9Š9‹;ˆ-˜=×1Ð1¬C«EÕ
2€Cô 
×	Ò	œY×	'Õ	'ð 	Ô ¨dÔ3Õ3ˆ÷ 
(ð"ßqÓqÙ;KÓ;MÑOhÓOjÑ:kÓlÑ:k°3Ð)¨#Ö.Ñ:kˆÐlØ×Ñ™/¸Ô>Ô?Û%ˆHß˜x¨1œ}ÙØ�G‰G�HÔðÛØŸ™¨Ó1×8Ñ8Ó:�ØÒ(Ø—G‘G˜FŸJ™JÔ'Ø#Ÿ]™]›_’Fñ )ñ &ð €J÷G 
(×	'üò& møô ô Úðûäô ØØ€JðúsV   ÁD7Á/E! ÂE
ÂAE! ÃAEÄ1E! Ä7E	Å
E! ÅEÅE! ÅEÅE! Å!E0Å/E0g      >@rÞ   Úgrace_sÚpoll_sc                ó0   € V ^8„  d   QhR\         R\         /# )r7   rŸ  r   ©rf   )r;   s   "r=   r>   r>   –  s   € ÷ ñ Ü.3ðÜZ_ñr@   c          	     óT  € Vf   \         P                  p\        V 4      p\        \	        ^\        W4,          4      4      4       F6  pV Uu. uF  qq! V4      '       g   K  VNK  	  ppV'       g    V# V! V4       K8  	  V Uu. uF  qq! V4      '       g   K  VNK  	  ppV# u upi u upi )ziPoll up to *grace_s* for *pids* to exit; return survivors. ``pid_exists``/``sleep`` injectable for tests.)rÜ   rÞ   r‚   r	  rÔ   rS   )rœ   rŠ  rÞ   rŸ  r   Ú	survivorsr?  r®  s   &$$$$   r=   r�  r�  –  sš   € ð ‚}Ü—
‘
ˆÜ�T“
€IÜ”3�qœ#˜gÕ.Ó/Ó0Ö1ˆÙ )Ó;¡	˜1¨Z¸¯]—Q�Q¡	ˆ	Ð;ßØð
 Ðñ	 	ˆfŽñ	 2ñ !*Ó;¡	˜1¨Z¸¯]—Q�Q¡	ˆ	Ð;ØÐùò <ùò <s   ÁB ÁB ÂB%ÂB%rÇ   c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   ¨  s   € ÷ Bñ B°dñ Br@   c               ób  € T;'       g    \         P                  pV  Fz  p\        P                  RV\        4       \
        P                  ! \        \        \        34      ;_uu_ 4        V! V\        \        R\        P                  4      4       RRR4       K|  	  R#   + '       g   i     K‘  ; i)ux   SIGKILL processes that outlasted the grace period, loudly â€” a force-kill can tear the store, so
it must leave a trace.uã   Gateway PID %s did not exit within %.0fs of the stop request (SIGTERM, or the planned-stop marker on Windows) â€” sending SIGKILL. A kill during a WAL checkpoint can corrupt state.db; the next start will run an integrity check.ÚSIGKILLN)r½   rÇ   ÚloggerÚwarningÚ_ORPHAN_EXIT_GRACE_SECONDSrö   r÷   rÈ   rÉ   rÊ   rÉ  rÆ   r�  )r¤  rÇ   rd   s   &$ r=   rŽ  rŽ  ¨  s~   € ð �?ˆ?”2—7‘7€DÛˆÜ�‰ð:ð Ô+ô	
ô × Ò Ô"4´oÄwÐ!O×PÕPÙ�”gœf i´·±Ó@ÔA÷ QÑPó ÷ Q×PÐPús   Á('BÂB.)Úmark_planned_stopc                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   »  s   € ÷ =ñ =œdñ =r@   c                 óð  €  ^ RI Hp Hp \	        4       pTf   T ! 4       e   R# \        4       # \        4       '       d6   ^ RI Hp ^ RIH	pH
pHp T! T4      pT! Y&! 4       4      '       g
   T! Y'/4       M1\        T4        \        P                  ! T\        P                   4       ^ RI Hp \+        ^4       F)  p	T! T4      '       g    M\,        P.                  ! R4       K+  	  T ! 4       f   T! 4         \        T'       d   T0MRR	7       R#   \         d     R# i ; i  \"         d     L‡\$         d    \'        RT 24        R# i ; i  \0         d"   p
\2        P5                  R
T
4        Rp
?
R# Rp
?
ii ; i)a!  Stop only this profile's gateway via its PID file; True if a process was stopped. Without a
supervisor the pidfile can be stale while a live orphan holds the webhook port, so fall back to
the orphan-aware scan rather than stacking a duplicate.

Even when the pid file is valid and points to the current gateway, older orphans may linger from prior
restarts that overwrote the pid file before the old process exited. After killing the recorded PID, also
sweep for any remaining orphans so each restart produces at most one live gateway (#75936).
)r¸  Úremove_pid_fileFNr2  )Ú_drain_gateway_pidÚ#_force_terminate_known_gateway_pidsÚ_windows_stop_drain_timeoutrs  rØ   rÚ   )r~  z1orphan reap after stop_profile_gateway failed: %sT)rÛ   r¸  r®  r±   r²  r–  r³   r3  ré  r¯  r°  r±  Ú_mark_planned_stopr½   rÇ   rÆ   r�  rÈ   rÉ   r9  rÙ   r	  rÜ   rÞ   r²   r¨  Údebug)r¸  r®  rd   r3  r¯  r°  r±  r7  rÙ   r?  rÄ  s              r=   Ústop_profile_gatewayr´  »  sR  € ðßCô Ó
€CØ
‚{Ù'Ó)Ò5ˆuÐ_Ô;]Ó;_Ð_ä‡|‚|õ 	:÷	
ñ 	
ñ 5°SÓ9ÐÙ! #Ð'BÓ'D×EÒEÙ/°Ð0JÔKøä˜3Ôð	Ü�GŠG�CœŸ™Ô(õ +Ü�2ŽYˆÙ˜3×ÒÙÜ�
Š
�3Žñ ñ
 ÓÒ ÙÔðOô 	+Ç#¸#¹È4ÕPñ øôe ô Úðûô6 "ô 	ÙÜô 	ÜÐ6°s°eÐ<Ô=Úð	ûô& ô OÜ�‰ÐHÈ#×NÐNÙûðOúsG   ‚D Á>%D Ã2E	 ÄDÄDÄEÄ*EÄ3EÅEÅ	E5ÅE0Å0E5c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   û  s   € ÷ ,ñ ,”$ñ ,r@   c                  ó@   € \         P                  P                  R 4      # )Úlinux)rç  rè  r›   rT   r@   r=   r9  r9  û  s   € Ü�<‰<×"Ñ" 7Ó+Ð+r@   )r6  r8  Úis_wslc                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>     s   € ÷ -ñ -¤$ñ -r@   c                 ó   € \        RR7      # )zUWSL2 with ``systemd=true`` in wsl.conf has working systemd; WSL1/without it does not.Trc  )Ú_systemd_operationalrT   r@   r=   Ú_wsl_systemd_operationalr¼    s   € ä tÔ,Ð,r@   c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>     s   € ÷ `ñ `¤ð `´$ñ `r@   c                óÒ   €  \        R.3RV R^/\        B pTP                  P                  4       P                  4       R9   #   \        \        P                  \
        3 d     R# i ; i)z7Return True when the requested systemd scope is usable.zis-system-runningra  r|   F>   rG   rÈ  ÚstartingÚinitializing)	rh  r‰   rÀ  r‡   r‘   rÊ   rŠ   r‹   rm  ri  s   & r=   r»  r»    sj   € ðÜÐ!4Ð 5Ña¸fÐaÈaÐaÔS`Ñaˆð �=‰=×ÑÓ ×&Ñ&Ó(Ð,_Ñ_Ð_øô œ*×3Ñ3´WÐ=ô Úðús   ‚A Á A&Á%A&c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>     s   € ÷ ñ ¤4ñ r@   c                  ó  € \        4       '       d)   \        4       '       g   \        P                  ! R 4      f   R# \	        4       '       d   \        4       # \        4       '       d!   \        RR7      ;'       g    \        RR7      # R# )ry   Frc  T)r9  r8  r´   rµ   r¸  r¼  r6  r»  rT   r@   r=   r…   r…     sT   € Ü�:Š:œŸš¬¯ª°[Ó(AÒ(IÙÜ‡x‚xÜ'Ó)Ð)Ü‡~‚~ä#¨5Ô1×VÐVÔ5IÐQUÔ5VÐVÙr@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>     s   € ÷ $ñ $”$ñ $r@   c                  ó(   € \         P                  R 8H  # )Údarwin©rç  rè  rT   r@   r=   r“   r“     s   € Ü�<‰<˜8Ñ#Ð#r@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>      s   € ÷ #ñ #”Dñ #r@   c                  ó(   € \         P                  R 8H  # )rÓ  rÆ  rT   r@   r=   r³   r³      s   € Ü�<‰<˜7Ñ"Ð"r@   c                 ó   € ^ RI Hp  V # )zOLazily import :mod:`hermes_cli.gateway_windows` (Windows-only service backend).©Úgateway_windows)Ú
hermes_clirË  rÊ  s    r=   Ú_gw_windowsrÍ  $  s   € å*ØÐr@   c                ó>   € V ^8„  d   QhR\         R\         R,          /# )r7   Ú	task_namer8   Nr—  )r;   s   "r=   r>   r>   0  s   € ÷ (ñ (¬Sð (´S¸4µZñ (r@   c                óî  € \        4       '       g   R# V P                  RR4      pRV R2p \        P                  ! R4      ;'       g    \        P                  ! R4      pVf   R# ^ RIHp \        P                  ! VR	R
RV.RRRR^
V! 4       RR7      pVP                  ^ 8w  d   R# VP                  ;'       g    RP                  4       ;'       g    R#   \        \        P                  3 d     R# i ; i)a  Locale-independent Task Scheduler state, or None on failure.

Query the COM API directly: Get-ScheduledTask auto-loads the CIM module,
which can stall desktop backend startup for the entire ten-second timeout.
Keep the existing supervisor semantics (Ready and Queued count as owned).
NÚ'z''z¦$ErrorActionPreference = 'Stop'; $s = [Activator]::CreateInstance([type]::GetTypeFromProgID('Schedule.Service')); $s.Connect(); try { $t = $s.GetFolder('\').GetTask('zë'); @('Unknown', 'Disabled', 'Queued', 'Ready', 'Running')[[int]$t.State] } catch { $e = $_.Exception; while ($e.InnerException) { $e = $e.InnerException }; if ($e.HResult -in @(-2147024894, -2147024893)) { 'MISSING' } else { throw } }r¡  r¢  )Úwindows_hide_flagsr£  z-NonInteractiver¤  Tr,   r   F)r.   r/   r0   r1   r|   rN  r}   r   )r³   r-   r´   rµ   r¥  rÒ  r‡   rˆ   r™   rŠ   r‹   rÊ   r‘   )rÏ  Úquoted_namer§  r¡  rÒ  rŸ   s   &     r=   Ú_windows_scheduled_task_staterÔ  0  só   € ô �<Š<ÙØ×#Ñ# C¨Ó.€Kð	,ð -8¨=ð 9ð	
	ð ðÜ—\’\ ,Ó/×GÐG´6·<²<ÀÓ3Gˆ
ØÒÙõ 	EÜ—’Ø˜Ð'8¸*ÀfÐMØ d°WÀXÐWYÙ,Ó.Øô	
ˆð ×Ñ Ô!ÙØ—‘×#Ð# ×*Ñ*Ó,×4Ð4°Ð4øÜ”Z×.Ñ.Ð/ô Úðús/   ¬C Á	C Á&?C Â'C Â:C ÃC ÃC4Ã3C4c                ó0   € V ^8„  d   QhR\         R\        /# )r7   rÏ  r8   ©rQ   r:   )r;   s   "r=   r>   r>   [  s   € ÷ 
Wñ 
W´#ð 
W¼$ñ 
Wr@   c                ó&   € \        V 4      \        9   # )u  True when Task Scheduler still owns this profile's gateway (Ready counts: the task is Ready, not
Running, after bootstrap exits). Any failure returns False so callers fall back to pidfile / parent-chain.

Used to treat Task Scheduler as a gateway supervisor on Windows: the orphan-reap sweep must not kill a
gateway that a scheduled task launched and left detached. After the bootstrap exits the task is Ready,
not Running; a Running-only check still writes the planned-stop marker, the gateway exits cleanly with
code 0, and the scheduler never restarts it â€” silently killing A2A/messaging on every desktop-app launch
(#86098, #87001).
)rÔ  Ú_WINDOWS_TASK_SUPERVISOR_STATES)rÏ  s   &r=   r‹  r‹  [  s   € ô )¨Ó3Ô7VÑVÐVr@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   h  s   € ÷ =ñ =œtñ =r@   c                  ó@   € \        \        P                  ! R 4      4      # )ÚHERMES_GATEWAY_DETACHED)Ú_truthy_envr½   ÚgetenvrT   r@   r=   Ú_gateway_detached_envrÞ  h  s   € Ü”r—y’yÐ!:Ó;Ó<Ð<r@   c                ó2   € V ^8„  d   QhR\         R,          /# r›  r9   )r;   s   "r=   r>   r>   l  s   € ÷ ñ ”t˜d•{ñ r@   c                 ó²   €  \        \        P                  ;'       d    \        P                  P                  4       4      #   \        \
        3 d     R# i ; i)z:``sys.stdin.isatty()``; None when stdin is closed/invalid.N)r:   rç  ÚstdinÚisattyr�   rÊ   rT   r@   r=   Ú_stdin_is_ttyrã  l  sB   € ðÜ”C—I‘I×4Ð4¤#§)¡)×"2Ñ"2Ó"4Ó5Ð5øÜœÐ ô Úðús   ‚A ž"A ÁAÁAc                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   t  s   € ÷ ñ ¼ñ r@   c                 óh   € \        4       '       g   R# \        4       '       d   R# \        4       '       * # )z�True for detached Windows gateway runs that should ignore Ctrl+C (``HERMES_GATEWAY_DETACHED=1``
or no interactive stdin); foreground runs stay interruptible.FT)r³   rÞ  rã  rT   r@   r=   Ú/_windows_gateway_should_absorb_console_controlsræ  t  s%   € ô �<Š<ÙÜ×ÒÙÜ‹ÔÐr@   c                ó2   € V ^8„  d   QhR\         R,          /# r›  r9   )r;   s   "r=   r>   r>   ~  s   € ÷ ñ ¬$°­+ñ r@   c                 óº   € \        4       '       g   R#  ^ RIp \        V P                  P                  P                  4       4      #   \        \        3 d     R# i ; i)z>Return whether Windows assigned this process a console window.N)r³   Úctypesr:   ÚwindllÚkernel32ÚGetConsoleWindowrÊ   ÚAttributeError©ré  s    r=   Ú _windows_console_window_attachedrï  ~  sI   € ä�<Š<ÙðÛÜ�F—M‘M×*Ñ*×;Ñ;Ó=Ó>Ð>øÜ”^Ð$ô Úðús   ”0A ÁAÁAc                ó2   € V ^8„  d   QhR\         R,          /# r›  r9   )r;   s   "r=   r>   r>   ‰  s   € ÷ ]ñ ]¬$°­+ñ ]r@   c                 ó˜   € \        4       '       g   R# ^ RIHp  RRRR/P                  \        P
                  P                  V R4      4      # )zDConsume private spawn metadata without guessing for older launchers.N©Ú_WINDOWS_GATEWAY_BREAKAWAY_ENVÚ1Tr§  F)r³   r¥  ró  r  r½   r—  rA  rò  s    r=   Ú _windows_gateway_breakaway_staterõ  ‰  s:   € ä�<Š<ÙÝLØ��s˜EÐ"×&Ñ&¤r§z¡z§~¡~Ð6TÐVZÓ'[Ó\Ð\r@   zhermes-gatewayz5Hermes Agent Gateway - Messaging Platform Integrationz/etc/systemd/systemc                óJ   € V ^8„  d   QhR\         R\         R\        R,          /# )r7   rä   rl  r8   Nr�  )r;   s   "r=   r>   r>   ›  s%   € ÷ 	ñ 	¤$ð 	´ð 	¼#À½*ñ 	r@   c                ó  € ^ RI p V P                  VR,          P                  4       4      P                  p\        T4      ^8X  d)   TP                  RT^ ,          4      '       d
   T^ ,          # R#   \         d     R# i ; i)z`Profile name when ``home`` is ``<default>/profiles/<name>`` with a service-safe name, else None.NrÂ  ú^[a-z0-9][a-z0-9_-]{0,63}$)ÚreÚrelative_tor  r¡   r�   rš   Úmatch)rä   rl  rù  r¡   s   &&  r=   Ú_profile_name_from_homerü  ›  sp   € ãðØ× Ñ  '¨JÕ"6×!?Ñ!?Ó!AÓB×HÑHˆô ˆ5ƒz�Q„˜2Ÿ8™8Ð$AÀ5ÈÅ8×LÒLØ�Q�xˆÙøô	 ô Úðús   †0A0 Á0A?Á>A?c                ó:   € V ^8„  d   QhR\         \        ,          /# r6   )rw   r   )r;   s   "r=   r>   r>   §  s   € ÷ ñ œs¤4�yñ r@   c                 ó–   € ^ RI Hp Hp V ! 4       P                  4       0pV! 4       pVe    VP	                  VP                  4       4       V# )aY  The account's native default home plus, when root under sudo, the invoking user's (see
``_profile_suffix`` for why sudo matters). The ACCOUNT home, not the process HOME: the unit dir
follows the account (``user_systemd_unit_dir``), so a scratch ``HOME`` that called its own
``.hermes`` native resolved the bare name onto the account's real unit.)Úaccount_default_hermes_homeÚsudo_invoker_default_home)r4  rÿ  r   r  r�   )rÿ  r   ÚhomesÚ	sudo_homes       r=   Ú_native_service_homesr  §  sD   € ÷
 Xá(Ó*×2Ñ2Ó4Ð5€EÙ)Ó+€IØÒØ�	‰	�)×#Ñ#Ó%Ô&Ø€Lr@   c                ó2   € V ^8„  d   QhR\         R,          /# r›  r   )r;   s   "r=   r>   r>   µ  s   € ÷ ñ ¤ t¥ñ r@   c                 ó@  € \        4       '       g   R# \        P                  ! 4       ^ 8X  d   \        M	\	        4       p \        V \         R2,          4      pV'       g   R#  \        V4      P                  4       P                  4       #   \        \        3 d     R# i ; i)u  Resolved ``HERMES_HOME`` pinned by an installed ``hermes-gateway.service``, or None. The unit is the
one naming basis that holds still across the sudo mid-command switch (see ``_profile_suffix``) and it
covers every elevated identity â€” ``sudo -i`` and cron included, where SUDO_USER is absent.

Root reads the system unit; an unprivileged process reads only its own user unit, never the system
one â€” a bare system unit pinning ``profiles/<name>`` would otherwise alias that profile onto the
user's default unit. The user unit matters for a custom root: the ``hermes-gateway-<hash>`` naming
(#105525) left a bare user unit installed before it pinning that same root, so lifecycle commands
saw "no unit", ``gateway restart`` fell through to a foreground run, and the still-enabled legacy
unit's ``Restart=always`` looped on the instance lock (#109476). A unit pinning THIS home is this
home's service, whatever it is named.

Linux-gated: a systemd unit is not an identity authority for launchd labels, Windows scheduled tasks,
or s6 slots, which share ``_profile_suffix()``. ``is_linux()`` is a plain ``sys.platform`` test;
``supports_systemd_services()`` would be wrong here, since it can shell out to ``systemctl
is-system-running`` on WSL/containers and this runs on every name resolution.
Nr~   )r9  r½   ÚgeteuidÚ_SYSTEM_UNIT_DIRÚuser_systemd_unit_dirrŽ  Ú_SERVICE_BASEr   Ú
expanduserr  rÀ  r�   )Úunit_dirÚpinneds     r=   Ú_bare_unit_pinned_homer  µ  s{   € ô$ �:Š:ÙÜ#%§:¢:£<°1Ô#4ÕÔ:OÓ:Q€HÜ(¨´}°oÀXÐ4NÕ)NÓO€FßÙðÜ�F‹|×&Ñ&Ó(×0Ñ0Ó2Ð2øÜœ*Ð%ô Úðús   Á!&B ÂBÂBc                ó0   € V ^8„  d   QhR\         R\        /# ©r7   rä   r8   ©r   r:   )r;   s   "r=   r>   r>   Ó  s   € ÷ Oñ O¤tð O´ñ Or@   c                óF   € V \        4       9   ;'       g    V \        4       8H  # )zYTrue for the resolved ``home`` that owns the bare service name (see ``_profile_suffix``).)r  r  r  s   &r=   r‚  r‚  Ó  s"   € àÔ(Ó*Ñ*×NÐN¨dÔ6LÓ6NÑ.NÐNr@   c                ó$   € V ^8„  d   QhR\         /# r6   r—  )r;   s   "r=   r>   r>   Ø  s   € ÷ Fñ Fœñ Fr@   c                 ó6  € ^ RI p ^ RIHp \        4       P	                  4       p\        V4      '       d   R# \        W!! 4       P	                  4       4      pT;'       g>    V P                  \        V4      P                  4       4      P                  4       R,          # )u3  Service-name suffix for HERMES_HOME: "" for a home that owns the bare name, the profile name for
``<root>/profiles/<name>``, else a short hash of the path.

Bare-name owners: this process's platform-native default (``~/.hermes``), under sudo the invoking
user's native default, and the home pinned by an installed ``hermes-gateway.service``. Under sudo the
naming basis moves MID-COMMAND â€” sudo strips HERMES_HOME and sets HOME=/root, then
``_sync_hermes_home_from_systemd_unit()`` adopts the unit's own HERMES_HOME into ``os.environ`` â€” so a
basis derived from the process alone names one unit before the adoption and another after it. The
unit-pinned check must precede the profile branch: ``sudo hermes gateway install --system`` resolves
the BARE name from root's default, then pins the invoking user's remapped home, so the bare unit
legitimately carries a ``<root>/profiles/<name>`` home.

The bare name is deliberately NOT tied to ``get_default_hermes_root()``: that helper treats any
HERMES_HOME outside ``~/.hermes`` (Docker ``/opt/data``, a temp dir) as "the root itself", which let a
temp-home harness resolve to the default profile's ``hermes-gateway`` unit and uninstall the
production gateway. Service names are host-wide identities; a home with no installed bare unit and
no native default keeps its own suffix.
N©r-  r   :Né   N)Úhashlibr4  r-  r   r  r‚  rü  Úsha256rQ   ÚencodeÚ	hexdigest)r  r-  rä   rk   s       r=   Ú_profile_suffixr  Ø  st   € ó& Ý8ÜÓ×$Ñ$Ó&€DÜ# D×)Ò)ÙÜ" 4Ð)@Ó)B×)JÑ)JÓ)LÓM€DØ×EÐE�7—>‘>¤# d£)×"2Ñ"2Ó"4Ó5×?Ñ?ÓAÀ"ÕEÐEr@   c                ó$   € V ^8„  d   QhR\         /# r6   r—  )r;   s   "r=   r>   r>   ô  s   € ÷ Iñ Iœsñ Ir@   c                 óR   € ^ RI Hp  V ! \        4       4      ;'       g    \        4       # )a  Profile id relative to the profile ROOT: ``default`` for the root itself (Docker's ``/opt/data``
included), ``<name>`` for ``<root>/profiles/<name>``, else the service hash. s6 slots and the
multiplexer ask which PROFILE this is; ``_profile_suffix()`` answers which HOST SERVICE this is.©Úprofile_name_for_home)r4  r  r   r  r  s    r=   r.  r.  ô  s    € õ 7Ù ¤Ó!2Ó3×HÐH´Ó7HÐHr@   c                ón   € V ^8„  d   QhR\         R,          R\         \        ,          R,          R\         /# )r7   Úhermes_homeNÚdefault_rootr8   )rQ   r   )r;   s   "r=   r>   r>   ü  s/   € ÷ 	/ñ 	/œc D�jð 	/¼sÄT½zÈDÕ?Pð 	/Ô\_ñ 	/r@   c                ó&  € ^ RI Hp \        T ;'       g    \        \	        4       4      4      P                  4       pV'       d   \        V4      P                  4       MV! 4       P                  4       pW48X  d   R# \        W44      pV'       d   RV 2# R# )z·``--profile <name>`` for ``<root>/profiles/<name>``, else "". *hermes_home*/*default_root* let a
sudo/root process generate a unit for another user (the defaults would refer to root).r  r   z
--profile )r4  r-  r   rQ   r   r  rü  )r   r!  r-  rä   rl  rk   s   &&    r=   r�  r�  ü  st   € õ 9Ü�×5Ð5œs¤?Ó#4Ó5Ó6×>Ñ>Ó@€Dß.:Œd�<Ó ×(Ñ(Ô*Ñ@WÓ@Y×@aÑ@aÓ@c€GØ„ÙÜ" 4Ó1€Dß"&ˆZ˜�vÐÐ.¨BÐ.r@   c                ó$   € V ^8„  d   QhR\         /# r6   r—  )r;   s   "r=   r>   r>   	  s   € ÷ Dñ Dœ#ñ Dr@   c                 óH   € \        4       p V '       d   \         RV  2# \        # )zxSystemd service name: ``hermes-gateway`` for default HERMES_HOME, ``hermes-gateway-<profile>``
or ``-<hash>`` otherwise.Ú-)r  r	  )Úsuffixs    r=   r†   r†   	  s$   € ô Ó€Fß*0Œmˆ_˜A˜f˜XÐ&ÐC´mÐCr@   c                ó$   € V ^8„  d   QhR\         /# r6   r   )r;   s   "r=   r>   r>   	  s   € ÷ %ñ %œtñ %r@   c                 óÞ   € ^ RI Hp  \        P                  P	                  RR4      P                  4       pV'       d   \        V4      M\        V ! 4       4      R,          pVR,          R,          # )u6  ``$XDG_CONFIG_HOME/systemd/user`` (``~/.config`` only as the spec's default), ``~`` being the
ACCOUNT home, not the process HOME.

Hardcoding ``~/.config`` made every unit probe silently false-negative on a host that moves
XDG_CONFIG_HOME â€” doctor then reported no gateway unit while systemd was running ours. And
``Path.home()`` trusts a process HOME that profile isolation may point at ``{HERMES_HOME}/home`` â€” the
ACTIVE profile's, not even the one selected with ``-p`` â€” so ``gateway install`` wrote the unit under
``~/.hermes/profiles/<active>/home/.config/systemd/user/`` where ``systemctl --user`` never looks and
``enable`` failed with "Unit ... does not exist" (#98699). ``systemctl --user`` targets the login
user's session, so the unit dir follows the account home like ``get_launchd_plist_path()`` does.
©Úget_real_homeÚXDG_CONFIG_HOMEr   z.configÚsystemdÚuser)r4  r*  r½   r—  r  r‹   r   )r*  Úconfig_homeÚbases      r=   r  r  	  sO   € õ /Ü—*‘*—.‘.Ð!2°BÓ7×=Ñ=Ó?€Kß +Œ4�Ô´±m³oÓ1FÈÕ1R€DØ�)Õ˜fÕ$Ð$r@   c                ó0   € V ^8„  d   QhR\         R\        /# r`  )r:   r   )r;   s   "r=   r>   r>   !	  s   € ÷ 7ñ 7¤$ð 7´4ñ 7r@   c                 ón   € \        4       pV '       d   \        V R 2,          # \        4       V R 2,          # )r~   )r†   r  r  )ra  rk   s   & r=   rf  rf  !	  s4   € ÜÓ€DßÜ T F¨(Ð"3Õ3Ð3Ü Ó"¨ v¨XÐ%6Õ6Ð6r@   c                   ó   € ] tR tRtRtRtR# )ÚUserSystemdUnavailableErrori(	  z¸``systemctl --user`` cannot reach the user D-Bus session (fresh SSH sessions with linger off,
so ``/run/user/$UID/bus`` never exists). ``args[0]`` is a user-facing remediation message.rT   N)rU   rV   rW   rX   rt   r[   rT   r@   r=   r3  r3  (	  s   † õbr@   r3  c                   ó6   a € ] tR tRt o RtV 3R lR ltRtV tR# )ÚSystemScopeRequiresRootErrori-	  z½System-scope gateway operation attempted as non-root. Typed (not ``sys.exit(1)``) so the setup
wizard can print remediation; ``args`` = (message, action) and ``str(e)`` is the message only.c                ó    <€ V ^8„  d   QhRS[ /# r6   r—  )r;   r<   s   "€r=   r>   Ú)SystemScopeRequiresRootError.__annotate__1	  s   ø€ ÷ 1ñ 1™ñ 1r@   c                óP   € V P                   '       d   V P                   ^ ,          # R# )rF  r   ©r
  rE   s   &r=   Ú__str__Ú$SystemScopeRequiresRootError.__str__1	  s   € Ø#ŸyŸy˜yˆt�y‰y˜�|Ð0¨bÐ0r@   rT   N)rU   rV   rW   rX   rt   r:  r[   r\   r]   s   @r=   r5  r5  -	  s   ø‡ € ñf÷1ö 1r@   r5  c                ó$   € V ^8„  d   QhR\         /# r6   r   )r;   s   "r=   r>   r>   5	  s   € ÷ Qñ Qœ4ñ Qr@   c                 ó’   € \        \        P                  P                  R4      ;'       g    R\        P                  ! 4        24      # )zF``$XDG_RUNTIME_DIR`` or ``/run/user/<uid>`` (regardless of existence).ÚXDG_RUNTIME_DIRú
/run/user/)r   r½   r—  r  r  rT   r@   r=   Ú_user_runtime_dirr@  5	  s0   € ä”—
‘
—‘Ð0Ó1×OÐO°zÄ"Ç)Â)Ã+ÀÐ5OÓPÐPr@   c                ó$   € V ^8„  d   QhR\         /# r6   r   )r;   s   "r=   r>   r>   :	  s   € ÷ 'ñ '¤ñ 'r@   c                 ó$   € \        4       R,          # )zIReturn the expected per-user D-Bus socket path (regardless of existence).Úbus©r@  rT   r@   r=   Ú_user_dbus_socket_pathrE  :	  s   € äÓ Õ&Ð&r@   c                ó$   € V ^8„  d   QhR\         /# r6   r   )r;   s   "r=   r>   r>   ?	  s   € ÷ 7ñ 7¬4ñ 7r@   c                 ó2   € \        4       R,          R,          # )zJReturn the per-user systemd private socket path (regardless of existence).r,  ÚprivaterD  rT   r@   r=   Ú!_user_systemd_private_socket_pathrI  ?	  s   € äÓ Õ*¨YÕ6Ð6r@   c                ó0   € V ^8„  d   QhR\         R\        /# ©r7   rc   r8   r  )r;   s   "r=   r>   r>   D	  s   € ÷ ñ œDð ¤Tñ r@   c                óH   €  V P                  4       #   \         d     R# i ; i)uy  ``Path.exists()`` treating an inaccessible path as absent: a leaked ``XDG_RUNTIME_DIR`` from
another user (``/run/user/0`` is 0700) would otherwise crash the preflight with EACCES.

``Path.exists()`` only swallows a subset of ``OSError`` (ENOENT/ENOTDIR/ EBADF/ELOOP); ``EACCES`` still
propagates. When ``XDG_RUNTIME_DIR`` leaks from another user â€” the classic ``su``/``sudo -u`` from a
root shell case, where ``/run/user/0`` is ``0700 root:root`` â€” stat-ing a socket underneath it raises
``PermissionError`` that escapes the systemd preflight as a raw traceback (#86558). An unreadable path
is, for our purposes, not reachable.
F)rg  rÊ   ©rc   s   &r=   Ú_path_exists_saferN  D	  s%   € ðØ�{‰{‹}ÐøÜô Úðúó   ‚ ’! !c                ó0   € V ^8„  d   QhR\         R\        /# )r7   Úruntime_dirr8   rÖ  )r;   s   "r=   r>   r>   T	  s   € ÷ ñ ¤cð ¬dñ r@   c                óš   €  \        V 4      P                  4       P                  \        P                  ! 4       8H  #   \
         d     R# i ; i)znTrue when *runtime_dir* exists and is owned by our uid (a leaked foreign XDG_RUNTIME_DIR must not be trusted).F)r   r  Úst_uidr½   r  rÊ   )rQ  s   &r=   Ú_runtime_dir_is_oursrT  T	  s>   € ðÜ�KÓ ×%Ñ%Ó'×.Ñ.´"·)²)³+Ñ=Ð=øÜô Úðús   ‚8; »A
Á	A
c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   \	  s   € ÷ qñ q¤Dñ qr@   c                 ó^   € \        \        4       4      ;'       g    \        \        4       4      # )z»True when the user D-Bus socket OR the per-user systemd private socket exists (some distros
expose only the latter and ``systemctl --user`` still works). Inaccessible counts as not-ready.)rN  rE  rI  rT   r@   r=   Ú_user_systemd_socket_readyrW  \	  s%   € ô Ô3Ó5Ó6×pÐpÔ:KÔLmÓLoÓ:pÐpr@   c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   b	  s   € ÷ Mñ M $ñ Mr@   c                 óÚ  € \         P                  ! 4       p \         P                  P                  R4      pV'       d   \	        V4      '       g+   \	        RV  24      '       d   RV  2\         P                  R&   R\         P                  9  d_   \        \         P                  P                  RRV  24      4      R,          p\        V4      '       d   RV 2\         P                  R&   R# R# R# )aÝ  Set XDG_RUNTIME_DIR / DBUS_SESSION_BUS_ADDRESS so ``systemctl --user`` works on headless (SSH)
hosts; an XDG_RUNTIME_DIR leaked from another user is replaced with our own ``/run/user/{uid}``.

An ``XDG_RUNTIME_DIR`` that leaked from another user (``su``/``sudo -u`` from root, where the env still
points at ``/run/user/0``) is dropped in favour of our own ``/run/user/{uid}`` so ``systemctl --user``
targets the right instance instead of an unreadable foreign socket (#86558).
r>  r?  ÚDBUS_SESSION_BUS_ADDRESSrC  z
unix:path=N)r½   r  r—  r  rT  r   rN  )r  ÚxdgÚbus_paths      r=   Ú_ensure_user_systemd_envr]  b	  s¸   € ô �)Š)‹+€CÜ
�*‰*�.‰.Ð*Ó
+€CßÔ+¨C×0Ò0Ô6JÈZÐX[ÐW\ÐK]×6^Ò6^Ø*4°S°EÐ(:Œ�
‰
Ð$Ñ%à!¬¯©Ô3ÜœŸ
™
Ÿ™Ð'8¸JÀsÀeÐ:LÓMÓNÐQVÕVˆÜ˜X×&Ò&Ø7AÀ(ÀÐ5LŒB�J‰JÐ1Ó2ñ 'ñ 4r@   c                ó0   € V ^8„  d   QhR\         R\        /# ©r7   r|   r8   ©rf   r:   )r;   s   "r=   r>   r>   u	  s   € ÷ (ñ (¬ð (¼ñ (r@   c                óê   € \         P                  ! 4       V ,           p\         P                  ! 4       V8  d5   \        4       '       d   \        4        R# \         P                  ! R4       KN  \        4       # )znPoll up to ``timeout`` s for a user systemd control socket (user@.service takes a moment after enable-linger).Tr  )rÜ   rÝ   rW  r]  rÞ   )r|   rß   s   & r=   Ú_wait_for_user_dbus_socketrb  u	  sH   € ä�~Š~Ó 'Õ)€HÜ
�.Š.Ó
˜XÔ
%Ü%×'Ò'Ü$Ô&ÙÜ�
Š
�3ŽÜ%Ó'Ð'r@   c                ó<   € V ^8„  d   QhR\         R\        R\        /# )r7   r  r|   r8   rÏ   )r;   s   "r=   r>   r>   €	  s!   € ÷ 
"ñ 
"¤3ð 
"´ð 
"Äñ 
"r@   c                óø   € \        RV  R24      p\        P                  ! 4       V,           p\        P                  ! 4       V8  d,   \        V4      '       d   R# \        P                  ! R4       KE  \        V4      # )u/  Poll for ``/run/user/<uid>/bus`` of ANOTHER account (the system unit's ``User=`` while root installs).
Only the D-Bus socket counts â€” ``systemd/private`` alone is enough for ``systemctl --user`` but not for
the ``systemd-run --user`` that restart-safe workers need. Never adopts anything into our env.r?  z/busTr  )r   rÜ   rÝ   rN  rÞ   )r  r|   rC  rß   s   &&  r=   Ú_wait_for_target_user_busre  €	  s[   € ô �˜C˜5 Ð%Ó
&€CÜ�~Š~Ó 'Õ)€HÜ
�.Š.Ó
˜XÔ
%Ü˜S×!Ò!ÙÜ�
Š
�3ŽÜ˜SÓ!Ð!r@   c                óD   € V ^8„  d   QhR\         R\        P                  /# )r7   Úusernamer8   )rQ   r‡   ÚCompletedProcess)r;   s   "r=   r>   r>   �	  s$   € ÷ mñ m¤cð m¬j×.IÑ.Iñ mr@   c                óF   € \         P                  ! RRV .3RRR^/\        B # )z]``loginctl enable-linger <username>`` (check=False, 30s); exceptions propagate to the caller.Úloginctlzenable-lingerr}   Fr|   )r‡   rˆ   r‰   )rg  s   &r=   Ú_loginctl_enable_lingerrk  �	  s)   € ä�>Š>˜: ¸ÐAÑlÈÐlÐXZÐlÔ^kÑlÐlr@   c                ó$   € V ^8„  d   QhR\         /# r6   r—  )r;   s   "r=   r>   r>   ’	  s   € ÷ Sñ S¬ñ Sr@   c                óŒ   € V P                   ;'       g$    V P                  ;'       g    RV P                   2P                  4       # )u5   stderr, else stdout, else ``exit <rc>`` â€” stripped.zexit )rM  rŠ   r™   r‹   )rŸ   s   &r=   Ú_completed_process_detailrn  ’	  s7   € à�M‰M×IÐI˜VŸ]™]×IÐI°°f×6GÑ6GÐ5HÐ.I×PÑPÓRÐRr@   Úauto_enable_lingerc                ó(   € V ^8„  d   QhR\         RR/# )r7   ro  r8   Nr9   )r;   s   "r=   r>   r>   —	  s   € ÷ 9ñ 9´4ð 9À4ñ 9r@   c                óÀ  € \        4        \        4       '       d   R# ^ RIpVP                  4       p\	        4       w  r4RV 2pVRJ d:   \        RR7      '       d   R# \        VRR\        P                  ! 4        R2R	7       V '       d�   \        P                  ! R
4      '       dt    \        V4      pVP                  ^ 8X  d=   \        RR7      '       d   \        RV R24       R# \        VRR\        4        2R	7       \        VR\        V4       2VR	7       \        TRT;'       g    R R2VR	7       R#   \          d   p\        TRT R2TR	7        Rp?L@Rp?ii ; i)a  Ensure ``systemctl --user`` can reach user-scope systemd; raise UserSystemdUnavailableError otherwise.
No-op when a control socket exists; else wait briefly if linger is on, or (``auto_enable_linger``)
try ``loginctl enable-linger`` (non-root works when polkit permits).Nz  sudo loginctl enable-linger Tç      @r  zGUser systemd control sockets are missing even though linger is enabled.z  systemctl start user@zC.service
  (may require sudo; try again after the command succeeds))rÞ  Úfix_hintrj  r.  õ   âœ“ Enabled linger for u    â€” user D-Bus now availablez=Linger was enabled, but the user D-Bus socket did not appear.z`  Log out and log back in, then re-run the command.
  Or reboot and run: systemctl --user start z#loginctl enable-linger was denied: zloginctl enable-linger failed (ú).z%User D-Bus session is not available (zlinger disabled)r]  rW  ÚgetpassÚgetuserÚget_systemd_linger_statusrb  Ú_raise_user_systemd_unavailabler½   r  r´   rµ   rk  r™   r9  r†   rn  r²   )ro  rv  rg  Úlinger_enabledÚlinger_detailÚ	sudo_hintrŸ   rÄ  s   $       r=   Ú_preflight_user_systemdr}  —	  si  € ô ÔÜ!×#Ò#ÙãØ�‰Ó €HÜ$=Ó$?Ñ!€NØ0°°
Ð;€Ià˜ÓÜ%¨c×2Ó2Ùä'ØØ\à)¬"¯)ª)«+¨ð 7Mð Mõ		
÷ œfŸlšl¨:×6Ò6ð	Ü,¨XÓ6ˆFð × Ñ  AÔ%Ü-°c×:Ó:ÜÐ3°H°:Ð=ZÐ[Ô\Ùä/ØØZðGÜGWÓGYÐFZð\õ	ô ,ØØ<Ô=VÐW]Ó=^Ð<_Ð`Ø"õô $ØØ6°}×7YÐ7YÐHYÐ6ZÐZ\Ð]Ø÷øô1 ô 	Ü+ØÐ#BÀ3À%ÀrÐ!JÐU^÷ò ûð	ús   Â&D6 Ä6EÅEÅEc                ó@   € V ^8„  d   QhR\         R\         R\         RR/# )r7   rg  rÞ  rs  r8   Nr—  )r;   s   "r=   r>   r>   Ó	  s)   € ÷ +ñ +¬cð +¼cð +ÌSð +ÐUYñ +r@   c               ó(   € V RV R2p\        V4      h)zHBuild a user-facing error message and raise UserSystemdUnavailableError.zR
  systemctl --user cannot reach the user D-Bus session in this shell.

  To fix:
z{

  Alternative: run the gateway in the foreground (stays up until
  you exit / close the terminal):
    hermes gateway run)r3  )rg  rÞ  rs  Úmsgs   &$$ r=   ry  ry  Ó	  s1   € ð ˆ(ð ð ˆ*ð !ð		!ð ô & cÓ
*Ð*r@   c                óF   € V ^8„  d   QhR\         R\        \        ,          /# r`  )r:   r‚   rQ   )r;   s   "r=   r>   r>   ã	  s"   € ÷ @ñ @œ4ð @¬D´­Iñ @r@   c                 óD   € V '       g   \        4        V '       d   R .# R R.# )ry   rz   )r]  rc  s   &r=   Ú_systemctl_cmdrƒ  ã	  s   € ßÜ Ô"ß"ˆKˆ=Ð?¨°hÐ(?Ð?r@   c                óf   € V ^8„  d   QhR\         \        ,          R\        R\        P                  /# )r7   r
  ra  r8   )r‚   rQ   r:   r‡   rh  )r;   s   "r=   r>   r>   é	  s+   € ÷ 4ñ 4œœc�ð 4¬tð 4Ì*×JeÑJeñ 4r@   c               óŒ   €  \         P                  ! \        V4      V ,           3/ VB #   \         d    ^ RIHp T! 4       Rhi ; i)z€Run systemctl; raise RuntimeError (not raw FileNotFoundError) if missing, for callers bypassing
``supports_systemd_services()``.)ÚSystemctlUnavailableErrorN)r‡   rˆ   rƒ  r’   Ú!hermes_cli.gateway_command_errorsr†  )r
  ra  Úkwargsr†  s   &$, r=   rh  rh  é	  sB   € ð4Ü�~Š~œn¨VÓ4°tÕ;ÑF¸vÑFÐFøÜô 4ÝOÙ'Ó)¨tÐ3ð4ús	   ‚&) ©Ac                ó0   € V ^8„  d   QhR\         R\        /# r`  r‘  )r;   s   "r=   r>   r>   ó	  s   € ÷ *ñ *¤ð *´#ñ *r@   c                 ó   € V '       d   R # R# )ra  r-  rT   rc  s   &r=   rÒ  rÒ  ó	  s   € ßˆ8Ð) 6Ð)r@   c                ó:   € V ^8„  d   QhR\         \        ,          /# r6   ©r‚   rQ   )r;   s   "r=   r>   r>   ÷	  s   € ÷ ñ ¤d¬3¥iñ r@   c                  óÐ   € . p \        4       pR FS  w  r#\        VR7      pWA9  g   K  VP                  4       '       g   K1  V P                  V4       VP	                  V4       KU  	  V # )Frc  ))Fr-  )Tra  )rw   rf  rg  rG  r�   )ÚscopesÚ
seen_pathsra  r¤   r€  s        r=   Úget_installed_systemd_scopesr�  ÷	  sW   € Ø€FÜ›E€JÛ<‰ˆÜ)°Ô8ˆ	ØÖ&¨9×+;Ñ+;×+=Ô+=Ø�M‰M˜%Ô Ø�N‰N˜9Ö%ñ	 =ð
 €Mr@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   
  s   € ÷ 3ñ 3¤tñ 3r@   c                  ó.   € \        \        4       4      ^8„  # )rà  )rš   r�  rT   r@   r=   Úhas_conflicting_systemd_unitsr“  
  s   € ÜÔ+Ó-Ó.°Ñ2Ð2r@   c                ó\   € V ^8„  d   QhR\         \        \        \        3,          ,          /# r6   )r‚   rR   r:   r   )r;   s   "r=   r>   r>   
  s$   € ÷ Hñ H¤4¬¬d´D¨jÕ(9Õ#:ñ Hr@   c                 ó*   € R\        4       3R\        3.# )za``[(is_system, base_dir), ...]`` to scan for legacy units; factored out so tests can monkeypatch.FT)r  r  rT   r@   r=   Ú_legacy_unit_search_pathsr–  
  s   € àÔ)Ó+Ð,¨tÔ5EÐ.FÐGÐGr@   c                óf   € V ^8„  d   QhR\         \        \        \        \        3,          ,          /# r6   ©r‚   rR   rQ   r   r:   )r;   s   "r=   r>   r>   
  s#   € ÷ ñ ¤4¬¬c´4¼¨oÕ(>Õ#?ñ r@   c                 óž  a€ . p \        4        F£  w  r\         F”  pW#,          p VP                  4       '       g   K$  VP                  RRR7      o\        ;QJ d#    T3R l\         4       F  '       g   K   RM	  RM! T3R l\         4       4      '       g   K�  T P                  Y4T34       K–  	  K¥  	  V #   \        \
        3 d     K²  i ; i)u1  ``[(unit_name, unit_path, is_system)]`` for legacy gateway units (e.g. ``hermes.service``), which
fight the current unit for the bot token (SIGTERM flap loop). Explicit name allowlist + ExecStart
marker check so profile/third-party units never match; no mutation.

Detects unit files installed by older Hermes versions that used a different service name (e.g. When both
a legacy unit and the current ``hermes-gateway.service`` are active, they fight over the same bot token
â€” the PR #5646 signal-recovery change turns this into a 30-second SIGTERM flap loop.
r  r   )r0   r1   c              3   ó,   <"  € T F	  qS9   x € K  	  R # 5irB   rT   )rÛ  rn  r/   s   & €r=   rÜ  Ú,_find_legacy_hermes_units.<locals>.<genexpr>+
  s   øé € ÐOÑ0N f˜T–>Ó0Nùó   ƒTF)	r–  Ú_LEGACY_SERVICE_NAMESrg  r  rÊ   rÉ   r/  Ú_LEGACY_UNIT_EXECSTART_MARKERSrG  )ÚresultsÚ	is_systemr/  rk   r€  r/   s        @r=   Ú_find_legacy_hermes_unitsr¡  
  s¬   ø€ ð -/€GÜ4Ö6‰ˆ	ß)ˆDØ�ˆIðØ ×'Ñ'×)Ò)ÙØ ×*Ñ*°KÈÐ*ÓQ�÷ ‹sÔOÕ0NÓO�s�sŠsÔOÕ0NÓO×OÔOØ—‘ °Ð;Ö<ó *ñ 7ð €Nøô	 œ_Ð-ô Úðús   ¥B7½B7Â7CÃCc                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   0
  s   € ÷ -ñ -¤ñ -r@   c                 ó(   € \        \        4       4      # )z<Return True when any legacy Hermes gateway unit files exist.)r:   r¡  rT   r@   r=   Úhas_legacy_hermes_unitsr¤  0
  s   € äÔ)Ó+Ó,Ð,r@   c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   5
  s   € ÷ 4ñ 4 4ñ 4r@   c            	     óê   € \        4       p V '       g   R# \        R4       V  F!  w  rp\        RV R\        V4       R24       K#  	  \        R4       \        R4       \        R4       \        R	4       R# )
zNWarn about installed legacy gateway units; prints nothing when there are none.Nz=Legacy Hermes gateway unit(s) detected from an older install:ú    ú  (ú scope)z<  These run alongside the current hermes-gateway service anduB     cause SIGTERM flap loops â€” both try to use the same bot token.z  Remove them with:z!    hermes gateway migrate-legacy)r¡  r$   r"   rÒ  )Úlegacyrk   rc   r   s       r=   Úprint_legacy_unit_warningr«  5
  sj   € ä&Ó(€FßÙÜÐQÔRÛ!'Ñˆ�IÜ�T˜$˜˜sÔ#7¸	Ó#BÐ"CÀ7ÐKÖLñ "(äÐMÔNÜÐSÔTÜÐ$Ô%ÜÐ2Ö3r@   c          	      ót   € V ^8„  d   QhR\         R\         R\        \        \        \        ,          3,          /# )r7   ÚinteractiveÚdry_runr8   )r:   rR   rS   r‚   r   )r;   s   "r=   r>   r>   C
  s4   € ÷ =ñ =¬Dð =Ä$ð =ÔSXÔY\Ô^bÔcgÕ^hÐYhÕSiñ =r@   c           	     óê  aa€ \        4       pV'       g   \        R4       ^ . 3# \        4        \        R4       V F!  w  r4p\        RV R\        V4       R24       K#  	  \        4        V'       d$   \        R4       ^ V UUu. uF  w  rgqgNK	  	  upp3# V '       d6   \        RR4      '       g$   \        R	4       ^ V UUu. uF  w  rgqgNK	  	  upp3# ^ o. oR
 VV3R llpV U	UU
u. uF  w  r—qª'       d   K  W—3NK  	  ppp	p
V U	UU
u. uF  w  r—qª'       g   K  W—3NK  	  ppp	p
V'       d   V! VRR7       V'       d^   \        P
                  ! 4       ^ 8w  d:   \        4        \        R4       \        R4       SP                  R V 4       4       M
V! VRR7       \        4        S'       d   \        \        S4       R24       SS3# \        RS R24       SS3# u uppi u uppi u up
pp	i u up
pp	i )zÊStop, disable, and remove legacy gateway units. ``interactive=False`` skips the prompt; ``dry_run``
only lists. Returns ``(removed_count, remaining_paths)`` (remaining: e.g. system-scope when not root).z%No legacy Hermes gateway units found.z$Legacy Hermes gateway unit(s) found:rP  r¨  r©  u   (dry-run â€” nothing removed)zRemove these legacy units?Tz6Skipped. Run again with: hermes gateway migrate-legacyc                ól   € V ^8„  d   QhR\         \        \        \        3,          ,          R\        RR/# )r7   Úunitsra  r8   Nr˜  )r;   s   "r=   r>   Ú0remove_legacy_hermes_units.<locals>.__annotate__\
  s4   € ÷ Vñ VœT¤%¬¬T¨	Õ"2Õ3ð VÄð VÈñ Vr@   c          	      óÖ  <€ V  FQ  w  r# \        R V.VR^ZR7       \        RV.VR^R7       VP                  RR7       \        RV 24       S^,          oKS  	  \        P                  ! \        4      ;_uu_ 4        \        R
.VR^R7       R	R	R	4       R	#   \        \        3 d.   p\        RT RT 24       SP                  T4        R	p?KË  R	p?ii ; i  + '       g   i     R	# ; i)ÚstopFr  ÚdisableT)Ú
missing_oku     âœ“ Removed u     âš  Could not remove rY  Núdaemon-reload)rh  Úunlinkr9  rÊ   rÀ  rG  rö   r÷   )r±  ra  rk   rc   ÚeÚ	remainingÚremoveds   &$   €€r=   Ú_remove_unitsÚ1remove_legacy_hermes_units.<locals>._remove_units\
  sØ   ø€ ã‰JˆDð'Ü ¨˜~°fÀEÐSUÕVÜ 	¨4Ð0¸ÀuÐVXÕYØ—‘ t�Ô,Ü˜ t fÐ-Ô.Ø˜1•’ñ  ô × Ò ¤×.Õ.Ü˜OÐ,°VÀ5ÐRTÕU÷ /Ñ.øô œ\Ð*ô 'ÜÐ/°¨v°R¸°sÐ;Ô<Ø× Ñ  ×&Ò&ûð'ú÷ /×.Ð.ús$   ŠABÁ;CÂCÂ'"CÃCÃC(	Frc  z1System-scope legacy units require root to remove.z1  Re-run with: sudo hermes gateway migrate-legacyc              3   ó*   "  € T F	  w  rVx € K  	  R # 5irB   rT   )rÛ  r?  rc   s   &  r=   rÜ  Ú-remove_legacy_hermes_units.<locals>.<genexpr>v
  s   é € Ð>±¡g a�T³ùr)  u5    legacy unit(s) still present â€” see messages above.zRemoved z legacy unit(s).)r¡  r9  rÒ  r(   r½   r  r$   r"   r  rš   r#   )r­  r®  rª  rk   rc   r   r?  r®  r¼  ÚnÚis_sysÚ
user_unitsÚsystem_unitsrº  r»  s   &&           @@r=   Úremove_legacy_hermes_unitsrÄ  C
  sÉ  ù€ ô 'Ó(€FßÜÐ5Ô6Ø�"ˆuˆä	„GÜ	Ð
0Ô1Û!'Ñˆ�IÜ��4�&˜Ô0°Ó;Ð<¸GÐDÖEñ "(ä	„GçÜÐ-Ô.Ø¡FÔ+¡F™˜˜q’1¡FÒ+Ð+Ð+çœ=Ð)EÀt×LÒLÜÐFÔGØ¡FÔ+¡F™˜˜q’1¡FÒ+Ð+Ð+à€GØ€I÷Vñ Vñ .4ÕB©V™\˜Q 6»6”&�1“&©V€JÒBÙ/5Õ@©v™|˜q V»”F�Q“F©v€LÒ@ßÙ�j¨Õ/÷ Ü�:Š:‹<˜1ÔÜŒGÜÐMÔNÜÐJÔKØ×ÑÑ>±Ó>Õ>á˜,¨tÕ4ä	„GßÜœ˜Y›Ð(Ð(]Ð^Ô_ð �IÐÐô 	˜  	Ð)9Ð:Ô;à�IÐÐùó[ ,ùó ,ùô( CùÜ@s$   ÂGÃ G!Ã&G'Ã7G'ÄG.ÄG.c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   ƒ
  s   € ÷ 
=ñ 
=¨dñ 
=r@   c                  óè   € \        4       p \        V 4      ^8  d   R# \        RRP                  V 4       R24       \	        R4       \	        R4       \	        R4       \	        R4       \	        R	4       R# )
r7   Nz5Both user and system gateway services are installed (z + ru  zF  This is confusing and can make start/stop/status behavior ambiguous.zL  Default gateway commands target the user service unless you pass --system.z  Keep one of these:z    hermes gateway uninstallz*    sudo hermes gateway uninstall --system)r�  rš   r$   r“  r"   )rŽ  s    r=   Ú$print_systemd_scope_conflict_warningrÇ  ƒ
  sc   € Ü)Ó+€FÜ
ˆ6ƒ{�Q„ÙäÐIÈ%Ï*É*ÐU[ÓJ\ÐI]Ð]_Ð`ÔaÜÐWÔXÜÐ]Ô^ÜÐ%Ô&ÜÐ-Ô.ÜÐ;Ö<r@   c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>   �
  s   € ÷ ñ ´ð ¼$ñ r@   c                óx   € V '       g   \        4       '       g   R# \        R4       \        RRRRRRR	RR
R4
       R# )uJ  True (after printing the guidance) when a fresh USER-scope unit was requested inside a container.

A systemd container passes ``supports_systemd_services()`` on purpose so ``--system`` keeps working,
but a user unit there is not container-scoped: the unit file and its ``default.target.wants`` symlink
land in ``~/.config/systemd/user`` â€” commonly the host's own home bind-mounted in â€” so the host's
``systemd --user`` enables it too and a second gateway polls the same bot token outside the container.
Callers decide between ``sys.exit(1)`` (CLI) and skipping the install (wizard).FzLRefusing to install a user-scope systemd gateway service inside a container.zUThe unit file and its enable symlink would be written to the home directory, which isuY   commonly the host's own home bind-mounted in â€” the host's user manager then enables andzXstarts the same unit, so a second gateway polls the same bot token outside the containerz?(Telegram: 'Conflict: terminated by other getUpdates request').r   zY  hermes gateway run                                # run as the container's main processzN  docker run --restart unless-stopped ...           # container restart policyzaIf systemd manages this container (systemd as PID 1), install an isolated system service instead:z;  sudo hermes gateway install --system --run-as-user <user>T)r6  r%   Ú_print_info_linesrc  s   &r=   Ú$refuses_container_user_scope_installrË  �
  sD   € ÷ ”\—^’^ÙÜÐ^Ô_ÜØ_ØcØbØIØ
ØcØXØ
ØkØEôñ r@   c                ó(   € V ^8„  d   QhR\         RR/# ©r7   Úactionr8   Nr—  )r;   s   "r=   r>   r>   ª
  s   € ÷ pñ p¬Sð p°Tñ pr@   c                 óZ   € \         P                  ! 4       ^ 8w  d   \        RV  R2V 4      hR# )rF  zSystem gateway z! requires root. Re-run with sudo.N)r½   r  r5  ©rÎ  s   &r=   Ú _require_root_for_system_servicerÑ  ª
  s-   € Ü	‡z‚zƒ|�qÔÜ*¨_¸V¸HÐDeÐ+fÐhnÓoÐoñ r@   c                ót   € V ^8„  d   QhR\         R,          R\        \         \         \         \        3,          /# )r7   Úrun_as_userNr8   r�  )r;   s   "r=   r>   r>   ¯
  s2   € ÷ `ñ `¬#°­*ð `ÄÄcÌ3ÔPSÔUXÐFXÕ@Yñ `r@   c                 ó’  € ^ RI p^ RIp^ RIpT ;'       gk    \        P                  ! R4      ;'       gM    \        P                  ! R4      ;'       g/    \        P                  ! R4      ;'       g    VP                  4       P                  4       pV'       g   \        R4      hVR8X  d   V '       g   \        R4      hVR8X  d   \        R4       \        R	4        VP                  V4      pYBP                  TP                  4      P                  TP                  TP                   3#   \         d   p\        R
T 24      ThRp?ii ; i)rF  NÚ	SUDO_USERÚUSERÚLOGNAMEz@Could not determine which user the gateway service should run asÚrootztRefusing to install the gateway system service as root; pass --run-as-user root to override (e.g. in LXC containers)z*Installing gateway service to run as root.zV  This is fine for LXC/container environments but not recommended on bare-metal hosts.zUnknown user: )rv  ÚgrpÚpwdr½   rÝ  rw  r‹   r�   r$   r"   ÚgetpwnamÚKeyErrorÚgetgrgidÚpw_gidÚgr_nameÚpw_dirÚpw_uid)rÓ  rv  rÙ  rÚ  rg  Ú	user_infor¹  s   &      r=   Ú_system_service_identityrã  ¯
  s  € ÛÛÛà×oÐo”r—y’y Ó-×oÐo´·²¸6Ó1B×oÐoÄbÇiÂiÐPYÓFZ×oÐoÐ^e×^mÑ^mÓ^oß�eƒgð ÷ ÜÐ[Ó\Ð\Ø�6Ô§+Üð Có
ð 	
ð �6ÔÜÐBÔCÜÐkÔlð=Ø—L‘L Ó*ˆ	ð —\‘\ )×"2Ñ"2Ó3×;Ñ;¸Y×=MÑ=MÈy×O_ÑO_Ð_Ð_øô ô =Ü˜>¨(¨Ð4Ó5¸1Ð<ûð=ús   ÃD' Ä'EÄ2EÅEc                ó>   € V ^8„  d   QhR\         R\        R,          /# r‹  r�  )r;   s   "r=   r>   r>   Ç
  s   € ÷ ñ ¬Dð ´S¸4µZñ r@   c                 ó  € V P                  4       '       g   R # V P                  RR7      P                  4        FM  pVP                  R4      '       g   K  VP	                  R^4      ^,          P                  4       ;'       g    R u # 	  R # )Nr  r  úUser=rs  )rg  r  rŒ   r›   r�   r‹   )r€  r    s   & r=   Ú_read_systemd_user_from_unitrç  Ç
  sq   € Ø×Ñ×ÒÙØ×#Ñ#¨[Ð#Ó9×DÑDÖFˆØ�?‰?˜7×#Ô#Ø—:‘:˜c 1Ó% aÕ(×.Ñ.Ó0×8Ð8°DÒ8ñ Gñ r@   c                ó2   € V ^8„  d   QhR\         R,          /# r›  r—  )r;   s   "r=   r>   r>   Ð
  s   € ÷ ñ ¤c¨D¥jñ r@   c                  óô   € \         P                  ! R 4      \         P                  ! R4      \         P                  ! R4      3 F2  p T ;'       g    RP                  4       p V '       g   K'  V R8w  g   K0  V u # 	  R# )rÕ  rÖ  r×  r   rØ  N)r½   rÝ  r‹   )Ú	candidates    r=   Ú_default_system_service_userrë  Ð
  sZ   € Ü—i’i Ó,¬b¯iªi¸Ó.?ÄÇÂÈ9ÓAUÓVˆ	Ø—_�_ "×+Ñ+Ó-ˆ	ß‰9˜ fÖ,ØÒñ Wñ r@   c                ó2   € V ^8„  d   QhR\         R,          /# r›  r—  )r;   s   "r=   r>   r>   Ø
  s   € ÷ ñ ¬C°$­Jñ r@   c                  ó6  € \         P                  ! 4       ^ 8H  p R.pR.pV '       d#   VP                  R4       VP                  R4       VP                  R4       VP                  R4       \        RV^ R7      pV '       g   V^ 8X  d   \	        R	4       W#,          # )
rF  zPUser service (no sudo; best for laptops/dev boxes; may need linger after logout)r-  z9System service (starts on boot; runs as your chosen user)ra  zSkip service install for nowNz6  Choose how the gateway should run in the background:©rl  zb  Tip: for a boot-time system service, re-run setup as root (e.g. from a root shell or `sudo -i`).)r½   r  rG  r'   r"   )Úis_rootÚoptionsÚvaluesÚchoices       r=   Ú"prompt_linux_gateway_install_scoperó  Ø
  s�   € ä�jŠj‹l˜aÑ€GØaÐb€GØ &˜x€FßØ�‰ÐRÔSØ�‰�hÔØ‡N�NÐ1Ô2Ø
‡M�M�$ÔÜÐSÐU\ÐfgÔh€Fß�v ”{ÜÐwÔxØ�>Ðr@   c                ól   € V ^8„  d   QhR\         R\         R\        \        R,          \         3,          /# )r7   r5  Úenable_on_startupr8   Nr»  )r;   s   "r=   r>   r>   è
  s4   € ÷ ñ ¬Dð ÌTð Ô]bÔcfÐimÕcmÔosÐcsÕ]tñ r@   c                 ó’  € \        4       pVf   R# VR8X  dŠ   \        4       p\        P                  ! 4       ^ 8w  d   \	        R4       VR3# V'       g=   \        RRR7      ;'       g    RP                  4       pV'       d   K7  \        R4       KD  \        V RW1R	7       VR3# \        RR
7      '       d   VR3# \        V RVR7       VR3# )NFra  z�  System service install requires root. Re-run setup from a root shell, or install a user service instead: hermes gateway installz/  Run the system gateway service as which user?r   rî  z  Enter a username.T)r5  ra  rÓ  rõ  rc  )r5  ra  rõ  ©NF)
ró  rë  r½   r  r$   r&   r‹   r%   Úsystemd_installrË  )r5  rõ  ÚscoperÓ  s   &&  r=   Ú install_linux_gateway_from_setuprú  è
  sÀ   € Ü.Ó0€EØ‚}ØÐà�ÔÜ2Ó4ˆÜ�:Š:‹<˜1ÔäðXôð ˜%�<ÐçÜ!Ð"SÐ]_Ô`×fÐfÐdf×mÑmÓoˆKß‘;ÜÐ1Ö2ä˜e¨D¸kÕoØ�dˆ{Ðä+°5×9Ó9Ø�eˆ|ÐÜ˜%¨ÐARÕSØ�$ˆ;Ðr@   c                ón   € V ^8„  d   QhR\         R,          R\        \        R,          \         3,          /# )r7   rg  Nr8   )rQ   rR   r:   )r;   s   "r=   r>   r>     s1   € ÷ 'Eñ 'E¬¨d­
ð 'E¼eÄDÈ4ÅKÔQTÐDTÕ>Uñ 'Er@   c                ó   € \        4       '       d   R# \        4       '       g   R# \        P                  ! R4      '       g   R# V f5   \        P
                  ! R4      ;'       g    \        P
                  ! R4      p V '       g4    ^ RIpVP                  \        P                  ! 4       4      P                  p  \        P                  ! RRV RR.3RR	R
^
/\        B pTP                  ^ 8w  d   R\!        T4      ;'       g    R3# TP"                  ;'       g    RP%                  4       P'                  4       pTR9   d   R# TR9   d   R# RRT;'       g    R 23#   \         d    Ru # i ; i  \         d   pR\        T4      3u Rp?# Rp?ii ; i)zßLinger status for *username* or the current user when omitted.

System-scope gateway installation runs as root but the service runs as a
configured target user, so querying the caller would validate the wrong
user manager.
Nrj  rÖ  r×  z	show-userz--property=Lingerr€   r}   Fr|   zloginctl query failedr   zunexpected loginctl output: z<empty>)Nznot supported in Termux)Nznot supported on this platform)Núloginctl not found)Nz could not determine current user>   rô  ÚyesÚtrue)Tr   >   r§  ÚnoÚfalse)Fr   )r8  r9  r´   rµ   r½   rÝ  rÚ  Úgetpwuidr  Úpw_namer²   r‡   rˆ   r‰   rQ   r™   rn  rŠ   r‹   rm  )rg  rÚ  rŸ   r¹  r¡  s   &    r=   rx  rx    ss  € ô ‡{‚{Ø.Ð.Ü�:Š:Ø5Ð5Ü�<Š<˜
×#Ò#Ø)Ð)àÒÜ—9’9˜VÓ$×<Ð<¬¯	ª	°)Ó(<ˆßð	<ÛØ—|‘|¤B§I¢I£KÓ0×8Ñ8ˆHðÜ—’Ø˜ hÐ0CÀYÐOñ
àð
à!#ð
ä'4ñ
ˆð ×Ñ˜AÔØÔ.¨vÓ6×QÐQÐ:QÐQÐQà�]‰]× Ð ˜b×'Ñ'Ó)×/Ñ/Ó1€EØÐ$Ô$ØˆØÐ$Ô$ØÐØÐ/°×0BÐ0B¸Ð/CÐDÐDÐDøô' ô 	<Ø;Ò;ð	<ûô ô Ø”S˜“Vˆ|Õûðús0   Â2E Â7$E+ ÅE(Å'E(Å+FÅ6FÆFÆFc                ó$   € V ^8„  d   QhR\         /# r6   r   )r;   s   "r=   r>   r>   0  s   € ÷ ?ñ ?¤ñ ?r@   c                 óD  € ^ RI p \        4       pV'       d   RV 2MRp \        V P                  \        P
                  ! 4       4      P                  4      pVR,          R,          V R2,          #   \        \        \        3 d    ^ RI
Hp \        T! 4       4      p LHi ; i)z[``~/Library/LaunchAgents/ai.hermes.gateway[-<profile>].plist`` under the real account home.Núai.hermes.gateway-rƒ   r)  ÚLibraryÚLaunchAgentsz.plist)rÚ  r  r   r  r½   r  rà  rÜ  r±   rÊ   r4  r*  )rÚ  r&  rk   rä   r*  s        r=   r!  r!  0  s‡   € ãÜÓ€Fß,2Ð ˜xÑ(Ð8K€Dð
%Ü�C—L‘L¤§¢£Ó-×4Ñ4Ó5ˆð
 �)Õ˜nÕ,°$°°v¨Õ>Ð>øô	 ”k¤7Ð+ô %Ý2ä‘M“OÓ$Šð%ús   Ÿ7A0 Á0,BÂBc                ó:   € V ^8„  d   QhR\         \        ,          /# r6   rŒ  )r;   s   "r=   r>   r>   B  s   € ÷ /ñ /¬D´­Iñ /r@   c                 ó,  € ^ RI p ^ RIHp . p. pV! 4        Fj  pVP                  '       d   VP	                  R4       K(  V P                  RVP                  4      '       g   KL  VP	                  RVP                   24       Kl  	  V\        V4      ,           # )a  Launchd labels for every profile of THIS install (root first, then profiles by name). Derived from
the profile layout, NOT by globbing ``~/Library/LaunchAgents``, so a sandboxed HERMES_HOME never
restarts another install's fleet. Names that can't map to a suffix are skipped.Nrº  rƒ   rø  r  )rù  r¿  r»  Ú
is_defaultrG  rû  rk   r—   )Ú_rer»  Ú
root_labelÚprofile_labelsrb   s        r=   r–   r–   B  s}   € ó Ý1Ø€JØ "€NÙ –?ˆØ××ÐØ×ÑÐ1Ö2Ø�Y‰YÐ4°g·l±l×CÔCØ×!Ñ!Ð$6°w·|±|°nÐ"EÖFñ	 #ð
 œ˜~Ó.Õ.Ð.r@   c                ó:   € V ^8„  d   QhR\         \        ,          /# r6   rŒ  )r;   s   "r=   r>   r>   R  s   € ÷ &ñ &´T¼#µYñ &r@   c                óº  € ^ RI p^ RIp^ RIHp  \	        VP                  \        P                  ! 4       4      P                  4      pV! 4       P                  4       pTR,          R,          pTP                  4       '       g   . # \        T 4      p\        4       p\        TP                  R4      4       Fõ  p	 TP                  T	P!                  4       4      p
T
R,          p\	        \#        T
R,          R,          4      4      P%                  4       P                  4       pTP'                  T4      P(                  p\+        T\"        4      '       d   Y·9   g   TP-                  R	4      '       g   Kº  T'       d#   \/        T4      ^8X  g   KÔ  T^ ,          R
8X  g   Kä  TP1                  T4       K÷  	  \        T4      #   \         d    . u # i ; i  \         d     EK&  i ; i)uØ  Launchd labels of THIS install that the profile-layout derivation can't map (#115254).

A unit whose label predates the profile-name suffix scheme (``ai.hermes.gateway-<8hex>`` from the
historical hash suffix) is invisible to ``launchd_gateway_labels_for_install()`` and therefore to
the update restart pass. This reads the account's LaunchAgents and credits a plist only when its
pinned ``HERMES_HOME`` is this install's root or one of its ``profiles/<name>`` homes â€” ownership
judged from the plist's content, never from label shape or directory membership â€” so the
derivation's boundary holds: a sandboxed HERMES_HOME (tests, side-by-side installs) never
enumerates, let alone restarts, another install's fleet (#41403).
Nr  r  r  zai.hermes.gateway*.plistÚLabelÚEnvironmentVariablesr�  rƒ   rÂ  )ÚplistlibrÚ  r4  r-  r   r  r½   r  rà  r  r²   r/  rw   r—   Úglobr  Ú
read_bytesrQ   r
  rú  r¡   r¸  r›   rš   r�   )Úexcluder  rÚ  r-  rä   rØ  Ú
agents_dirÚexcludedr£   Ú
plist_pathÚdatar¤   r  Úrels   &             r=   Ú!legacy_launchd_labels_for_installr  R  sy  € ó Ûå8ðÜ�C—L‘L¤§¢£Ó-×4Ñ4Ó5ˆÙ&Ó(×0Ñ0Ó2ˆð ˜	Õ! NÕ2€JØ×Ñ×ÒØˆ	Ü�7‹|€HÜ“u€FÜ˜ZŸ_™_Ð-GÓHÖIˆ
ð	Ø—>‘> *×"7Ñ"7Ó"9Ó:ˆDØ˜•MˆEÜœ#˜dÐ#9Õ:¸=ÕIÓJÓK×VÑVÓX×`Ñ`ÓbˆFØ×$Ñ$ TÓ*×0Ñ0ˆCô ˜%¤×%Ò%¨Ô):À%×BRÑBRÐSf×BgÒBgÙß”s˜3“x 1–}¨¨Q­°:Ö)=Ø�J‰J�uÖñ Jô �&‹>Ðøô' ô ØŠ	ðûô ô 	Ûð	ús%   �AF7 Â7BG
Æ7GÇGÇ
GÇGc                ó$   € V ^8„  d   QhR\         /# r6   r—  )r;   s   "r=   r>   r>   {  s   € ÷ Eñ Eœñ Er@   c                  óh   € ^ RI Hp  \        V ! \        4      ;'       g    \        P
                  4      # )rF  ©Úresolve_store_python)r  r   rQ   r	  rç  rT  r  s    r=   Úget_python_pathr!  {  s"   € Ý:äÑ#¤LÓ1×CÐC´S·^±^ÓDÐDr@   c                óh   € V ^8„  d   QhR\         R\        \        ,          R\        \        ,          /# )r7   rä   Úpath_entriesr8   ©r   r‚   rQ   )r;   s   "r=   r>   r>   †  s.   € ÷ Qñ Q¤$ð Q´d¼3µið QÄDÌÅIñ Qr@   c                óF  € \        V R,          R,          4      \        V R,          R,          4      \        V R,          R,          4      \        V R,          R,          4      .pV Uu. uF.  q3V9  g   K  \        V4      P                  4       '       g   K,  VNK0  	  up# u upi )zKReturn user-local bin dirs that exist and aren't already in *path_entries*.z.localÚbinz.cargoÚgoz.npm-global)rQ   r   rg  )rä   r#  Ú
candidatesr®  s   &&  r=   Ú_build_user_local_pathsr)  †  s€   € ô 	ˆD�8�O˜eÕ#Ó$ÜˆD�8�O˜eÕ#Ó$ÜˆD�4�K˜%ÕÓ ÜˆD�=Õ  5Õ(Ó)ð	€Jñ "ÓP‘z�!¨lÑ%:ŒA¼tÀA»w¿~¹~×?O�AˆA‘zÑPÐPùÒPs   Á'BÁ4BÂBc                ó\   € V ^8„  d   QhR\         \        ,          R\         \        ,          /# )r7   r#  r8   rŒ  )r;   s   "r=   r>   r>   ‘  s"   € ÷ #ñ #¬4´­9ð #¼¼c½ñ #r@   c                óì  € \        4       '       g   . # . pR FP  p\        P                  ! V4      pV'       g   K#  VP                  \	        \        V4      P                  4      4       KR  	  TR Uu. uF&  p\        V4      P                  4       '       g   K$  VNK(  	  up,          p. p\        V 4      pV F7  pV'       g   K  WF9  g   K  VP                  V4       VP                  V4       K9  	  V# u upi )u„  WSL Windows-interop PATH entries for generated units: systemd services don't inherit the
Windows PATH (``/mnt/c/WINDOWS/System32``â€¦), so ``powershell.exe``/``cmd.exe`` break unless persisted.

Only the which()-resolved tool dirs and the hardcoded System32 family belong here. The
shell PATH is deliberately NOT scraped: WSL appends every Windows PATH entry (Desktop app,
git, node dirs under ``/mnt/``) ahead of the interop defaults, and persisting those into the
unit makes the gateway open 9p (Plan 9 interop) connections to each of them at start â€” enough
to exhaust the 9p server connection limit (#73163). Interop tools don't need them.)zpowershell.exezcmd.exezexplorer.exezwsl.exe)z/mnt/c/WINDOWS/system32z/mnt/c/WINDOWSz/mnt/c/WINDOWS/System32/Wbemz//mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/z /mnt/c/WINDOWS/System32/OpenSSH/)
r¸  r´   rµ   rG  rQ   r   r@  rg  rw   r�   )r#  r(  rT  ÚresolvedrV  rŸ   r¿   s   &      r=   Ú_build_wsl_interop_pathsr-  ‘  sÙ   € ô �8Š8Øˆ	à€JÛNˆ
Ü—<’< 
Ó+ˆß‰8Ø×Ñœc¤$ x£.×"7Ñ"7Ó8Ö9ñ Oð ñ
ó
ñ
ˆEô �‹;×Ñ×÷ 	ˆñ
ñ
õ 
€Jð €FÜˆ|Ó€DÛˆß‰5�UÖ&Ø�H‰H�UŒOØ�M‰M˜%Ö ñ ð €Mùò%
s   Á0!C1ÂC1c                ó<   € V ^8„  d   QhR\         R\         R\         /# )r7   rc   Útarget_home_dirr8   r—  )r;   s   "r=   r>   r>   ·  s!   € ÷ 	ñ 	œsð 	´Sð 	¼Sñ 	r@   c                óð   € \         P                  ! 4       p\        V 4      P                  4       p VP                  V4      p\	        \        V4      V,          4      #   \
         d    \	        T4      u # i ; i)z‡Swap the ``Path.home()`` prefix of *path* for *target_home_dir*; other paths return unchanged.
Intentionally does NOT resolve symlinks.)r   rä   r
  rú  rQ   r�   )rc   r/  rp  r®  Úrelatives   &&   r=   Ú_remap_path_for_userr2  ·  sa   € ô —9’9“;€LÜˆT‹
×ÑÓ€AðØ—=‘= Ó.ˆÜ”4˜Ó(¨8Õ3Ó4Ð4øÜô Ü�1‹vŠðús   °+A ÁA5Á4A5c                ó<   € V ^8„  d   QhR\         R\         R\         /# )r7   rk   r¡  r8   r—  )r;   s   "r=   r>   r>   Å  s!   € ÷ /ñ /œCð /¬ð /´ñ /r@   c                óx   € VP                  RR4      P                  RR4      P                  RR4      pRV  RV R	2# )
z’One ``Environment="NAME=value"`` line: ``\`` and ``"`` escaped for systemd's quoting, ``%``
doubled so specifier expansion leaves the value alone.re  r…  rƒ  r„  r‡  r†  zEnvironment="rs  ú"
©r-   )rk   r¡  Úescapeds   && r=   Ú_systemd_env_liner8  Å  sC   € ð �m‰m˜D &Ó)×1Ñ1°#°uÓ=×EÑEÀcÈ4ÓP€GØ˜4˜&  ' ¨#Ð.Ð.r@   c                ó0   € V ^8„  d   QhR\         R\        /# r`  r‘  )r;   s   "r=   r>   r>   Ì  s   € ÷ bñ b¬Dð b´Sñ br@   c                óB   € \        \        V R7      R4      ;'       g    R# )zF``LD_LIBRARY_PATH`` baked into the installed unit; ``""`` when absent.rc  ÚLD_LIBRARY_PATHr   )r‰  rf  rc  s   &r=   Ú_installed_unit_ld_library_pathr<  Ì  s   € ä"Ô#8ÀÔ#GÐIZÓ[×aÐaÐ_aÐar@   c                óJ   € V ^8„  d   QhR\         R\        R,          R\        /# )r7   ra  r/  Nr8   r‘  )r;   s   "r=   r>   r>   Ñ  s*   € ÷ \ñ \¤$ð \¼¸t½ð \Ìsñ \r@   c                óT  € \         P                  P                  RR4      ;'       g    \        V 4      pVP	                  R4       Uu. uF  q3'       g   K  VNK  	  ppVe   V Uu. uF  p\        W14      NK  	  ppV'       d   \        RRP                  V4      4      # R# u upi u upi )uŸ  Carry the installer's LD_LIBRARY_PATH into the unit (glibc reads it only at process start, so
~/.hermes/.env is too late for CUDA libs â€” #14613); system units remap caller-home components.

The installed unit is the fallback source: the unit is regenerated and compared on every
start/restart/status, and a shell without the export (ssh, cron, ``sudo`` strips ``LD_*``)
must not be able to "repair" the line away.r;  r   Ú:)r½   r—  r  r<  r�   r2  r8  r“  )ra  r/  r¶   r®  Ú
componentss   &&   r=   Ú_ld_library_path_linerA  Ñ  s�   € ô �*‰*�.‰.Ð*¨BÓ
/×
ZÐ
ZÔ3RÐSYÓ3Z€CØ ŸY™Y sœ^Ó1™^˜«q—!�!™^€JÐ1ØÒ"ÙHRÓSÉ
À1Ô*¨1Ö>É
ˆ
ÐSßISÔÐ.°·±¸Ó0DÓEÐ[ÐY[Ð[ùò 2ùâSs   Á	B ÁB Á%B%c                ó0   € V ^8„  d   QhR\         R\         /# )r7   r/  r8   r—  )r;   s   "r=   r>   r>   ß  s   € ÷ #ñ #´#ð #¼#ñ #r@   c                óŠ  € \         P                  P                  RR4      P                  4       pV'       d   \	        V4      P                  4       M	\        4       p\        P                  ! 4       R,          p\	        V 4      R,          p \        WBP                  V4      ,          4      #   \         d    \        T4      u # i ; i)uµ   Remap the current HERMES_HOME (root's, under sudo) to the target user's equivalent:
``/root/.hermes[/profiles/x]`` â†’ ``/home/alice/.hermes[/profiles/x]``; custom paths kept as-is.r�  r   ú.hermes)r½   r—  r  r‹   r   r
  r   rä   rQ   rú  r�   )r/  Úcurrent_hermes_rawÚcurrent_hermesÚcurrent_defaultÚtarget_defaults   &    r=   Ú_hermes_home_for_target_userrI  ß  s•   € ô Ÿ™Ÿ™¨°rÓ:×@Ñ@ÓBÐß>P”TÐ,Ó-×8Ñ8Ô:ÔVeÓVg€Nä—i’i“k IÕ-€OÜ˜/Ó*¨YÕ6€Nð#ä�>×$>Ñ$>¸Ó$OÕOÓPÐPøÜô #Ü�>Ó"Ò"ð#ús   Â	B) Â)CÃCc                óT   € V ^8„  d   QhR\         R,          R\        \        ,          /# ©r7   Úproject_rootNr8   r$  )r;   s   "r=   r>   r>   î  s"   € ÷ ñ ¬4°$­;ð Ä$ÄsÅ)ñ r@   c                ó  € V f   \         p R R lp. p\        4       pV R,          R,          VR,          R,          VR,          R,          3pV F-  pV! V4      '       g   K  VP                  \        V4      4       K/  	  V# )zIBuild PATH directory list for service units, excluding non-existent dirs.c                ó0   € V ^8„  d   QhR\         R\        /# rK  r  )r;   s   "r=   r>   Ú._build_service_path_dirs.<locals>.__annotate__ó  s   € ÷ ñ ”dð œtñ r@   c                 óH   €  V P                  4       #   \         d     R # i ; ir‡  )r/  rÊ   rM  s   &r=   Ú_is_dirÚ)_build_service_path_dirs.<locals>._is_diró  s%   € ð	Ø—;‘;“=Ð øÜô 	Úð	úrO  Únode_modulesz.binÚnoder&  )r	  r   rG  rQ   )rL  rQ  r(  r   ÚextrasÚextras   &     r=   Ú_build_service_path_dirsrW  î  s}   € àÒÜ#ˆõð €Jô "Ó#€KØ˜^Õ+¨fÕ4°kÀFÕ6JÈUÕ6RÐT_ÐbpÕTpÐsyÕTyÐz€FÛˆÙ�5�>Œ>Ø×Ñœc %›jÖ)ñ ð Ðr@   c                ó$   € V ^8„  d   QhR\         /# r6   r—  )r;   s   "r=   r>   r>     s   € ÷ 
ñ 
¤Sñ 
r@   c                 óê   €  \        4       p V '       dB   \        V 4      P                  4       '       d#   \        \        V 4      P	                  4       4      # \        \        4      #   \
         d     Li ; i)a  WorkingDirectory that won't disappear under systemd (HERMES_HOME, else PROJECT_ROOT). cwd is
irrelevant to ``-m`` resolution, and a pinned transient checkout rots: systemd fails at CHDIR
(status=200) before Python loads, so the unit self-heal never runs and Restart=always crash-loops.)r   r   r/  rQ   r  r²   r	  r  s    r=   Ú_stable_service_working_dirrZ    s]   € ðÜÓ ˆß”D˜“J×%Ñ%×'Ò'Ü”t˜D“z×)Ñ)Ó+Ó,Ð,ô Œ|ÓÐøô ô Ùðús   ‚AA$ Á$A2Á1A2c                óT   € V ^8„  d   QhR\         \        ,          R,          R\        /# )r7   r   Nr8   )rQ   r   rS   )r;   s   "r=   r>   r>     s#   € ÷ 0ñ 0¬3´­:¸Õ+<ð 0Ìñ 0r@   c                óB  € R;rV e   ^ RI HpHp V! V 4      pTp \        4       p\	        \        VR^ 4      4      Ve   Ve
   V! V4       # # #   \         d0    \        P                  RRR7        Te   Te   T! T4       ^ # ^ # ^ # i ; i  Te   Te
   T! T4       i i i ; i)zFResolve the managed-overlay-aware watchdog setting for a service home.N)Úreset_hermes_home_overrideÚset_hermes_home_overrideÚsystemd_watchdog_secondsz:Could not resolve effective systemd watchdog configurationT©Úexc_info)	r4  r]  r^  r   r   rÉ  r²   r¨  r³  )r   Úoverride_tokenÚreset_home_overrider]  r^  Úconfigs   &     r=   Ú_systemd_watchdog_secondsre    sÅ   € à+/Ð/€NØÒß[Ù1°+Ó>ˆØ8Ðð0Ü$Ó&ˆÜ.¬w°vÐ?YÐ[\Ó/]Ó^ð
 Ò%Ð*=Ò*IÙ Õ/ð +JÐ%øô	 ô Ü�‰ÐQÐ\`ˆÔaØàÒ%Ð*=Ò*IÙ Ö/ñ +JÑ%ð	ûð Ò%Ð*=Ò*IÙ Õ/ð +JÐ%ús#   ›A Á"BÁ/B
 ÂBÂB
 Â
Bc                óF   € V ^8„  d   QhR\         R\        \        ,          /# r  r$  )r;   s   "r=   r>   r>   #  s   € ÷ ñ ¤ð ¬¬c­ñ r@   c                óV  € ^ RI Hp \        V 4      R,          pV! VR,          4      p. pR Fy  pVP                  WR4      P	                  R4      ;'       g    .  FH  pV'       g   K  \        V4      P                  4       '       g   K.  VP                  \        V4      4       KJ  	  K{  	  V# )züNode dirs pm's installed-state records under *home*'s store, resolved
via ``Facts.env_for`` (``{{store}}`` templates against the store beside
the recorded facts). Only dirs present on disk count; a record whose
store dirs are gone vouches for nothing.
)ÚFactsÚtoolsz
facts.jsonr   )rT  ÚnpmÚnpx)Úpm.lockrh  r   Úenv_forr  r/  rG  rQ   )rä   rh  ÚstoreÚfactsÚdirsrk   r¡  s   &      r=   Ú_pm_managed_node_dirsrq  #  s‹   € õ ä�‹J˜Õ €EÙ�%˜,Õ&Ó'€EØ€DÛ&ˆØ—]‘] 4Ó/×3Ñ3°FÓ;×AÐA¸rÒAˆEß‰uœ˜e›×+Ñ+×-Ô-Ø—‘œC ›JÖ'ó Bñ 'ð €Kr@   c                óX   € V ^8„  d   QhR\         \        ,          R\        R,          RR/# )r7   r#  Úhermes_rootNr8   )r‚   rQ   r   )r;   s   "r=   r>   r>   5  s*   € ÷ 'ñ '¬t´C­yð 'ÄtÈdÅ{ð 'Ð^bñ 'r@   c                óÖ  € Ve   \        V4      M\        \        4       4      p \        V4      pV F  pW@9  g   K  V P	                  V4       K  	  V'       d   R# ^ RIHpHp V! V4      pV'       d	   V! V4      MR FB  p\        V4      p VP                  4       p	V	'       g   K)  W@9  g   K1  V P	                  V4       KD  	  R#   \         d    . p L¥i ; i  \         d    Rp	 LKi ; i)uã  Append the Node dir a service unit should use.

PM's installed-state is the owner: facts.json under the target hermes
home's store records node/npm PATH entries, and those dirs â€” resolved via
Facts.env_for â€” are used verbatim. With managed Node recorded, consulting
the invoker's PATH would make a system unit depend on who ran sudo, so
lookup stops there. The legacy ``<hermes>/node`` tree is the only fallback,
for installs pm never recorded; the invoker's PATH node never is.
N)Ú hermes_managed_node_tree_presentÚiter_hermes_node_dirsFrT   )r   r   rq  r²   rG  r4  ru  rv  rQ   r/  rÊ   )
r#  rs  rä   Úmanaged_dirsrV  ru  rv  Úmanaged_node_presentÚ	directoryÚpresents
   &&        r=   Ú_append_node_dir_for_servicer{  5  sÜ   € ð !,Ò 7Œ4�Ô¼TÄ/ÓBSÓ=T€DðÜ,¨TÓ2ˆó ˆØÖ$Ø×Ñ Ö&ñ ÷ ÙçZÙ;¸KÓHÐß;OÑ*¨;Ô7ÐUWÒWˆ	Ü�I“ˆð	Ø×&Ñ&Ó(ˆG÷ ‰7�uÖ0Ø×Ñ Ö&ó Xøô ô ØŠðûô ô 	ØŠGð	ús#   ¤C ÂCÃCÃCÃC(Ã'C(c                óF   € V ^8„  d   QhR\         \        ,          R\        /# r#  rŒ  )r;   s   "r=   r>   r>   V  s"   € ÷ Sñ Sœ4¤�9ð S¬ñ Sr@   c                ó2   € RP                  R V  4       4      # )zDQuote argv for systemd, including its non-shell specifier expansion.rO  c              3   óÂ   "  € T FU  pR VP                  RR4      P                  R R4      P                  RR4      P                  RR4      ,           R ,           x € KW  	  R# 5i)	rƒ  re  r…  r„  r‡  r†  Ú$z$$Nr6  r&  s   & r=   rÜ  Ú#_systemd_command.<locals>.<genexpr>X  s]   é € ð SÙMQÀTð ˜$Ÿ,™, t¨VÓ4×<Ñ<¸SÀ%ÓHß‘W˜S $Ó'¯©°°TÓ(:õ;Ø=@÷Aò AÛMQùs   ‚AA)r“  )r  s   &r=   Ú_systemd_commandr�  V  s$   € à�8‰8ñ SÙMQóSó Sð Sr@   rÓ  c                óB   € V ^8„  d   QhR\         R\        R,          RR/# ©r7   ra  rÓ  Nr8   r‘  )r;   s   "r=   r>   r>   \  s&   € ÷ *ñ *¬ð *ÄCÈ$ÅJð *ÐZ^ñ *r@   c                óŒ  € ^ RI HpHpHp ^ RIHpHp \        \        4       r‡Rp	V '       dD   \        V4      w  r«rÍ\        \        \        V4      V4      4      p\        \        V4      4      pWÚ3p	V! V4      p V! VRR7      f    V! V4       R# VR,          R,          pV! W4      p\        V4      \        V4      8w  d   \        R4      hV	ea   ^ RIpV	w  rÚVP#                  V
4      P$                  pVP&                  V.\)        \        V4      O F  p\*        P,                  ! VVV4       K  	  V! V4       R#   T! T4       i ; i)	zEPublish the source command before a service definition references it.)ÚENTRY_POINTSÚensure_install_launchersr   )r^  r]  NT)ÚpublicationrD  r&  z3Could not publish the gateway installation launcher)r  r…  r†  r   r4  r^  r]  r	  r   rã  r   r2  rQ   rI  rš   rÀ  rÚ  rÛ  rÞ  r@  Úmapr½   Úchown)ra  rÓ  r…  r†  r   r^  r]  rØ  rä   Úownerrg  Ú_groupÚhome_dirr  ÚtokenÚlocalÚpathsrÚ  Úgidrc   s   $$                  r=   Ú_prepare_service_launcherr‘  \  s$  € çbÑbßUäœÓ0ˆ$Ø€EßÜ*BÀ;Ó*OÑ'ˆ˜(ÜÔ(¬¨T«°HÓ=Ó>ˆÜÔ0°Ó:Ó;ˆØ�ˆÙ$ TÓ*€Eð*ñ   °$Ô7Ò?Øñ 	# 5Ö)ð �yÕ  5Õ(ˆÙ(¨Ó5ˆÜˆu‹:œ˜\Ó*Ô*ÜÐTÓUÐUØÒÛØ!‰MˆCØ—,‘,˜xÓ(×/Ñ/ˆCØŸ™ uÐ@¬s´4¸Ó/?Ó@�Ü—’˜˜s CÖ(ñ Añ 	# 5Ö)øÑ" 5Õ)ús   Á8D9 ÂB D9 Ä9
Ec                óJ   € V ^8„  d   QhR\         R\        R,          R\        /# rƒ  r‘  )r;   s   "r=   r>   r>   |  s+   € ÷ bñ b¤$ð b¼SÀ4½Zð bÔSVñ br@   c                 óà  € ^ RI Hp \        4       p\        4       p\        p\        4       pV '       g   \        V4       \        \        4       \        4       4      pV '       EdQ   \        V4      w  r‰r«\        V
4      p\        V
4      R,          p \        V4      P                  4       P                  VP                  4       4       \        WÍR7      p\#        W:4      pV'       d   \%        V4      M
\#        WJ4      p\        \#        \%        V4      V
4      4      pV Uu. uF  p\#        Wú4      NK  	  pp. p\        TV'       d   \        V4      MR4       V Uu. uF  pVV9  g   K  VNK  	  upV,           p\        V
4      pRV RV	 R2pRV R	V R
2pRV
 RV RV R2\'        RV
R7      ,           pRpMS\%        \)        4       P                  4       4      p\        V4      p\        P*                  ! 4       pR;pp\'        RR7      pRp\-        V4      pRRppV^ 8”  d	   RRV R2ppVP/                  \1        VV4      4       VP/                  \3        V4      4       VP/                  . R/O4       RP5                  V4      pV! V. \6        P8                  ! V4      ORNRNW<R7      pV! VRW<R7      pV! VR W<R7      pRP5                  . R!N\:         NR"NV NR#NV NRNV NV NR$N\=        V4       NR%NV NRNV NR&NV NR'NV NR(N\>         NR)N\>         NR*N\@         NR+N\=        V4       NR,N\=        V4       NR-NV NR.NV NRN4      #   \          d    \        T4      p EL‘i ; iu upi u upi )0rF  )Úinstallation_commandrD  )r!  Nræ  z
Group=r|  zAfter=user@z.service
Wants=user@z	.service
zEnvironment="HOME=z"
Environment="USER=z"
Environment="LOGNAME=r5  T)ra  r/  zmulti-user.targetr   Frc  zdefault.targetÚsimpleÚnotifyzNotifyAccess=main
WatchdogSec=zs
r?  r  rˆ   )Úpythonrä   zgateway.cgroup_cleanup)Úmoduler—  rä   zgateway.systemd_stop_markz[Unit]
Description=z9
After=network-online.target
Wants=network-online.target
z(StartLimitIntervalSec=0

[Service]
Type=ú
ExecStart=z
WorkingDirectory=zEnvironment="PATH=z"

Environment="HERMES_HOME=z]"
Environment="HERMES_SUPERVISED_CHILD=1"
Restart=always
RestartSec=5
RestartForceExitStatus=z
SuccessExitStatus=z
RestartPreventExitStatus=zQ
KillMode=mixed
KillSignal=SIGTERM
ExecReload=/bin/kill -USR1 $MAINPID
ExecStop=-z
ExecStopPost=-z
TimeoutStopSec=zB
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=)z/usr/local/sbinz/usr/local/binú	/usr/sbinú/usr/binú/sbinú/bin)!r  r”  r!  rZ  r	  rW  r{  r   Ú_get_restart_drain_timeoutÚ_get_cron_drain_timeoutrã  rI  r   r  rú  r�  r�   r2  rQ   rA  r   rä   re  r  r)  r-  r“  Úshlexr�   ÚSERVICE_DESCRIPTIONr�  r   r   )ra  rÓ  r”  Úpython_pathÚworking_dirrL  r#  Úrestart_timeoutrg  Ú
group_namerŒ  r  r   Útarget_rootÚprofile_argr®  Ú_target_node_entriesr¹  Ú	user_homeÚidentity_linesÚordering_linesÚ	env_linesÚ	wanted_byÚwatchdog_secondsÚsystemd_typeÚsystemd_watchdog_directivesÚ	sane_pathr  ÚcleanupÚ	stop_marks   &&                            r=   Úgenerate_systemd_unitr´  |  s~  € Ý:ä!Ó#€KÜ-Ó/€KÜ€Lä+Ó-€Lßä$ \Ô2ô 7Ô7QÓ7SÔUlÓUnÓo€Oç€vÜ.FÀ{Ó.SÑ+ˆ˜hÜ2°8Ó<ˆä˜8“n yÕ0ˆð	4Ü�Ó×%Ñ%Ó'×3Ñ3°K×4GÑ4GÓ4IÔJÜ& {ÔMˆKô +¨;ÓAˆß*5”c˜+Ô&Ô;OÐP[Ó;fˆÜÔ0´°\Ó1BÀHÓMÓNˆÙCOÓPÁ<¸aÔ,¨QÖ9Á<ˆÐPà*,ÐÜ$Ð%9×P[¼4ÀÔ;LÐaeÔfÙ#7ÓQÑ#7˜a¸1ÀLÑ;PŸ˜Ñ#7ÑQÐT`Õ`ˆÜ˜“Nˆ	Ø   
¨(°:°,¸bÐAˆð ' s eÐ+@ÀÀÀZÐPˆà   
ð +!Ø!) 
ð +$Ø$, :¨Sð2ô "¨¸xÔHõ	Iˆ	ð
 (‰	äœ/Ó+×3Ñ3Ó5Ó6ˆÜ" ;Ó/ˆÜ—I’I“Kˆ	Ø*,Ð,ˆ˜Ü)°Ô7ˆ	Ø$ˆ	ä0°Ó=ÐØ08¸"Ð-€LØ˜!ÔØ4<Ð@_Ð`pÐ_qÐqtÐ>uÐ1ˆØ×ÑÔ/°	¸<ÓHÔIØ×ÑÔ0°Ó>Ô?Ø×ÑÒgÔhØ—‘˜Ó&€IÙ  Ð/\´·²¸[Ó1IÐ/\È9Ð/\ÐV[Ð/\Ø#.ôB€Eá" <Ð8PØ%0ôD€Gá$ \Ð:UØ'2ôF€I÷ó ð ð Ü Ð!ðð"ðð Ð ð	ðð	ð €^ðððð Ð ðð -Ð-ðð .8ðô 9IÈÓ8OÐ7PððQðð �ðððð €ðð ðð (˜[ðð)ðð &˜ðð'ðô  :Ð:ð!ð ;ð!ô" 5Ð5ð#ð"6ð#ô$ 9Ð9ð%ð$:ð%ô, ˜IÓ&Ð
'ð-ð,(ð-ô.   Ó(Ð)ð/ð.*ð/ð0  Ð ð1ð0!
ð1ð: ˆð;ð:ô;ð øô[ ô 	4Ü& {Ó3‹Kð	4üò Qùò Rs%   ÂAM	 ÄM&Å	M+Å%M+Í	M#Í"M#c                ó0   € V ^8„  d   QhR\         R\         /# ©r7   r/   r8   r—  )r;   s   "r=   r>   r>   á  s   € ÷ Jñ J¬ð J´ñ Jr@   c                 ój   € R P                  R V P                  4       P                  4        4       4      # )r|  c              3   ó@   "  € T F  qP                  4       x € K  	  R # 5irB   )r€  )rÛ  r    s   & r=   rÜ  Ú0_normalize_service_definition.<locals>.<genexpr>â  s   é € ÐIÑ/H t—[‘[—]�]Ó/Hùs   ‚)r“  r‹   rŒ   ©r/   s   &r=   Ú_normalize_service_definitionr»  á  s&   € Ø�9‰9ÑI¨t¯z©z«|×/FÑ/FÔ/HÓIÓIÐIr@   c                ó0   € V ^8„  d   QhR\         R\         /# r¶  r—  )r;   s   "r=   r>   r>   é  s   € ÷ ñ ¬Sð ´Sñ r@   c                óL  € . pV P                  4        F~  pVP                  4       pT;'       d    VP                  R4      '       * pV'       d3   VP                  R^4      ^ ,          P                  4       \        9   d   Km  VP                  V4       K€  	  RP                  V4      # )z9Remove systemd directives that older hosts silently drop.Ú#rs  r|  )rŒ   r‹   r›   r�   Ú_SYSTEMD_OPTIONAL_DIRECTIVESrG  r“  )r/   Úfilteredr    r”  Úis_directives   &    r=   Ú"_strip_optional_systemd_directivesrÂ  é  s   € à€HØ—‘Ö!ˆØ—:‘:“<ˆØ×@Ð@¨×(;Ñ(;¸CÓ(@Ô$@ˆß §¡°°QÓ!7¸Õ!:×!@Ñ!@Ó!BÔFbÖ!bØ�O‰O˜DÖ!ñ	 "ð
 �9‰9�XÓÐr@   c                ó0   € V ^8„  d   QhR\         R\         /# r¶  r—  )r;   s   "r=   r>   r>   ô  s   € ÷ ñ ´#ð ¼#ñ r@   c                óZ   € ^ RI pVP                  RR\        V 4      VP                  R7      # )z–Normalize plist text for staleness checks, ignoring the PATH payload: the generated PATH is
captured from the invoking shell and varies across shells.Nz,(<key>PATH</key>\s*<string>)(.*?)(</string>)z\1__HERMES_PATH__\3)Úflags)rù  Úsubr»  ÚDOTALL)r/   rù  s   & r=   Ú'_normalize_launchd_plist_for_comparisonrÈ  ô  s1   € ó Ø�6‰6Ø7Ð9OÜ% dÓ+°2·9±9ð ó ð r@   c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>   þ  s   € ÷ -ñ -¤Dð -´Tñ -r@   c                 óð   € \        V R 7       \        V R 7      pVP                  4       '       g   R# VP                  RR7      pV '       d   \	        V4      MRp\        WR7      pR pV! V4      V! V4      8H  # )rc  Fr  r  N©ra  rÓ  c                 ó*   € \        \        V 4      4      # rB   )r»  rÂ  rº  s   &r=   Ú<lambda>Ú)systemd_unit_is_current.<locals>.<lambda>  s   € Ô5Ô6XÐY]Ó6^Ô_r@   )rš  rf  rg  r  rç  r´  )ra  r€  Ú	installedÚexpected_userÚexpectedÚnorms   &     r=   Úsystemd_unit_is_currentrÓ  þ  sl   € ô (¨vÕ6ä%¨VÔ4€IØ×Ñ×ÒÙà×#Ñ#¨[Ð#Ó9€Iß?EÔ0°Ô;È4€MÜ$¨FÔN€Há_€DÙ�	‹?™d 8›nÑ,Ð,r@   c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>     s   € ÷ ñ ¬$ð ¼4ñ r@   c                ó\  a€ \        V R7      pVP                  VP                   R2,          R,          p VP                  RR7      o\
        ;QJ d    T3R lR	 4       F  '       d   K   RM	  RM! T3R lR	 4       4      '       g   R# TP                  4        R#   \         d     R# i ; i)
z?Remove only the legacy ``--replace`` drop-in written by Hermes.rc  z.dz20-replace.confr  r  Fc              3   ó,   <"  € T F	  qS9   x € K  	  R # 5irB   rT   )rÛ  r�  r/   s   & €r=   rÜ  Ú0_retire_hermes_replace_dropin.<locals>.<genexpr>  s   øé € ÐpÑ*o ˜Ž}Ó*oùrœ  T)z&Added to end the gateway respawn stormr  r™  )rf  r@  rk   r  rÊ   Úallr¸  )ra  r€  Údropinr/   s   &  @r=   Ú_retire_hermes_replace_dropinrÚ    s�   ø€ ä%¨VÔ4€IØ×Ñ 9§>¡>Ð"2°"Ð 5Õ5Ð8IÕI€FðØ×Ñ¨ÐÓ5ˆ÷ ‹3ÔpÑ*oÓp�3�3Š3ÔpÑ*oÓp×pÒpÙØ
‡M�M„OÙøô ô Úðús   ¶B ÂB+Â*B+c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>     s   € ÷ %ñ %¬4ð %¼Dñ %r@   c                óÖ  a€ \        V R7      pVP                  4       '       g   R# ^ RIHp V! WR4      '       g   R# \	        V R7      p\        V R7      '       d4   \        R.V R^R7       \        R\        V 4       R	24       V'       d   R# M
V'       d   R# V '       d   \        V4      MR
p\        WR7      oV '       gC   \        ;QJ d    V3R lR 4       F  '       g   K   RM	  RM! V3R lR 4       4      '       d   R# \        P                  ! SR4      '       d   R# \        WR7       VP                  SRR7       \        R.V R^R7       \        R\        V 4       R24       R# )zMRewrite the installed systemd unit when the generated definition has changed.rc  F©Úunit_belongs_to_callerÚrewriter·  Tr  u@   â†» Removed the stale Hermes --replace drop-in from the gateway ú serviceNrË  c              3   ó,   <"  € T F	  qS9   x € K  	  R # 5irB   rT   )rÛ  ÚmÚnew_units   & €r=   rÜ  Ú1refresh_systemd_unit_if_needed.<locals>.<genexpr>8  s   øé € ÐcÑ1b¨A˜xž-Ó1bùrœ  úsystemd unitr,   r  u   â†» Updated gateway z7 service definition to match the current Hermes install)z/pytest-of-z/hermes_test"z/hermes_test/)rf  rg  Ú hermes_cli.gateway_service_ownerrÞ  rÓ  rÚ  rh  r9  rÒ  rç  r´  r/  r   Úrefuse_temp_home_service_writer‘  Ú
write_text)ra  r€  rÞ  r_  rÐ  rã  s   &    @r=   Úrefresh_systemd_unit_if_neededré    s+  ø€ ä%¨VÔ4€IØ×Ñ×ÒÙõ HÙ! )°Y×?Ò?Ùä%¨VÔ4€GÜ$¨F×3Ó3Ü˜Ð(°¸tÈRÕPÜÐPÔQeÐflÓQmÐPnÐnvÐwÔxßÙð ç	Ùç?EÔ0°Ô;È4€MÜ$¨FÔN€H÷ —c“cÔcÑ1bÓc—c—c’cÔcÑ1bÓc×cÒcÙô ×;Ò;¸HÀn×UÒUÙä VÕGØ×Ñ˜¨GÐÔ4Ü�OÐ$¨V¸4ÈÕLÜ	Ð Ô!5°fÓ!=Ð >Ð>uÐ
vÔwÙr@   c                óN   € V ^8„  d   QhR\         R\         R,          R\        RR/# )r7   rg  ÚdetailNra  r8   rÖ  )r;   s   "r=   r>   r>   F  s.   € ÷ ñ ¬3ð ¼¸d½
ð ÔVZð Ðgkñ r@   c          	      óz  € \        4        V'       d   \        R V  R24       M\        R4       V'       d   \        RV 24       \        4        \        V'       d   RMR4       \        RV  24       \        4        \        R4       \        V4      w  r4p\        RV R	V R
\        4        R24       \        4        R# )u   âš  Linger not enabled for u:    â€” cron and Kanban workers cannot start (no user D-Bus).uI   âš  Linger not enabled â€” gateway may stop when you close this terminal.z  Auto-enable failed: z  Enable it manually:z1  On headless servers (VPS, cloud instances) run:z     sudo loginctl enable-linger ú  Then restart the gateway:r§  z
systemctl zrestart r~   N)r9  r½  r†   )rg  rë  ra  rß  r?  rà  s   &&$   r=   Ú_print_linger_enable_warningrî  F  s    € Ü	„GßÜÐ+¨H¨:Ð5oÐpÕqäÐYÔZßÜÐ& v hÐ/Ô0Ü	„GÜ	§VÑ
!Ð1dÔeÜ	Ð,¨X¨JÐ
7Ô8Ü	„GÜ	Ð
'Ô(Ü*¨6Ó2Ñ€DˆYÜ	ˆD���j  ¨8Ô4DÓ4FÐ3GÀxÐ
PÔQÜ	†Gr@   c                óJ   € V ^8„  d   QhR\         R,          R\        R\        /# )r7   rg  Nra  r8   rÖ  )r;   s   "r=   r>   r>   X  s&   € ÷ -ñ -¤S¨4¥Zð -Ä4ð -ÔTXñ -r@   c               óø  € \        4       '       g   \        4       '       g   R# V f   ^ RIpVP                  4       p V'       d   RV  R2MRp\	        RV  24      P                  4       '       d   \        V4       R# \        V 4      w  rEVRJ d   \        V4       R# \        P                  ! R4      '       g   \        Y;'       g    R	VR
7       R# V'       d   \        RV  R24       M\        R4        \        V 4      pTP                  ^ 8w  d$   \        T \        T4      ;'       g    TTR
7       R# \        T'       d   RT  2MR4       R#   \         d#   p\        T \        T4      TR
7        Rp?R# Rp?ii ; i)u‹  Enable linger for *username* (default: the current user) when possible.

A user unit needs linger so the gateway survives logout. A system unit (``system=True``) needs
it for its ``User=`` so ``user@<uid>.service`` provides the D-Bus that ``systemd-run --user
--scope`` â€” every restart-safe cron/Kanban worker â€” connects to (#104893). Returns True only
when linger was enabled by this call.
FNu"   âœ“ Systemd linger is enabled for z (worker D-Bus available)õ7   âœ“ Systemd linger is enabled (service survives logout)z/var/lib/systemd/linger/Trj  rý  rc  zEnabling linger for z; so cron and Kanban workers can reach systemd-run --user...z5Enabling linger so the gateway survives SSH logout...rt  u8   âœ“ Linger enabled â€” gateway will persist after logout)r8  r9  rv  rw  r   rg  r9  rx  r´   rµ   rî  rk  r²   rQ   r™   rn  )rg  ra  rv  Úenabled_msgrz  r{  rŸ   r¹  s   &$      r=   Ú_ensure_linger_enabledró  X  sJ  € ô ‡{‚{œ(Ÿ*š*ÙàÒÛØ—?‘?Ó$ˆçTZÐ
,¨X¨JÐ6OÑPØFð ô Ð& x jÐ1Ó2×9Ñ9×;Ò;ÜˆkÔÙä$=¸hÓ$GÑ!€NØ˜ÓÜˆkÔÙä�<Š<˜
×#Ò#Ü$ X×/TÐ/TÐ@TÐ]cÕdÙçÜÐ$ X JÐ.iÐjÕkäÐEÔFðÜ(¨Ó2ˆð
 ×Ñ˜AÔÜ$ XÔ/HÈÓ/P×/aÐ/aÐTaÐjpÕqÙÜ	·&Ð# H :Ñ
.Ð>xÔyÙøô ô Ü$ X¬s°1«v¸fÕEÝûðús   Ã3E ÅE9ÅE4Å4E9c                ó(   € V ^8„  d   QhR\         RR/# )r7   rg  r8   Nr—  )r;   s   "r=   r>   r>   ˆ  s   € ÷ Jñ J¬Cð J°Dñ Jr@   c                óX  € \        V RR7      '       g   R# ^ RIpVP                  V 4      P                  p\	        V4      '       d   \        RV R24       M\        RV R24       \        RV R	24       \        RR7      '       d%   \        R
4       \        R\        4        R	24       R# R# )u  Enable linger for the installed unit's ``User=`` (root included: restart-safe workers always cross
``systemd-run --user``, so a root gateway needs ``user@0.service`` just the same).

After a fresh enable, wait for the TARGET user's bus: logind starts ``user@<uid>.service``
asynchronously and ``--start-now`` boots the gateway immediately. A gateway that was already running
keeps its bus-less environment and ``systemctl start`` on an active unit is a no-op â€” say so rather
than let the repair silently not take.Trc  Nu   âœ“ /run/user/uA   /bus is up â€” cron and Kanban workers can use systemd-run --useru   âš  /run/user/z/bus did not appear within 5s.z4  Start the user manager: sudo systemctl start user@r~   zR  The running gateway was started without a user D-Bus; restart it to pick one up:z    sudo systemctl restart )ró  rÚ  rÛ  rá  re  r9  rj  r†   )rg  rÚ  r  s   &  r=   Ú_ensure_system_service_lingerrö  ˆ  sœ   € ô " (°4×8Ó8ÙÛØ
�,‰,�xÓ
 ×
'Ñ
'€CÜ  ×%Ò%Ü�˜s˜eÐ#dÐeÕfä�˜s˜eÐ#AÐBÔCÜÐDÀSÀEÈÐRÔSÜ d×+Ó+ÜÐbÔcÜÐ+Ô,<Ó,>Ð+?¸xÐHÖIñ ,r@   c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>   ž  s   € ÷ xñ x¤$ð x´4ñ xr@   c                 ó˜   € T ;'       gB    \        R R7      P                  4       ;'       d     \        RR7      P                  4       '       * # )Trc  F)rf  rg  rc  s   &r=   rm  rm  ž  s:   € Ø×wÐwÔ+°4Ô8×?Ñ?ÓA×vÐvÔJ_ÐglÔJm×JtÑJtÓJvÔFvÐwr@   c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>   ¢  s   € ÷ 0ñ 0´ð 0Ä$ñ 0r@   c                óR   € \         P                  ! 4       ^ 8X  d   R# \        V R7      # )u›   True when the wizard would trigger a system-scope operation as non-root â€” mirrors
``_select_systemd_scope`` so the dead-end is detected BEFORE prompting.Frc  )r½   r  rm  rc  s   &r=   Ú$_system_scope_wizard_would_need_rootrû  ¢  s    € ô 
‡z‚zƒ|�qÔÙÜ ¨Ô/Ð/r@   c                ó(   € V ^8„  d   QhR\         RR/# rÍ  r—  )r;   s   "r=   r>   r>   ª  s   € ÷ 	0ñ 	0¬Cð 	0°Dñ 	0r@   c                óþ   € \        RV  R24       \        R4       \        RV P                  4        R24       \        RV  R\        4        24       \        R4       \        R	4       \        R
4       \        R4       R# )zZPrint remediation when the wizard skips a system-scope action because the user isn't root.u2   Gateway is installed as a system-wide service â€” z requires root.z
  Options:z    1. z it this time:z         sudo systemctl rO  zC    2. Switch to a per-user service (recommended for personal use):z/         sudo hermes gateway uninstall --systemz         hermes gateway installz         hermes gateway startN)r$   r"   rÓ  r†   rÐ  s   &r=   Ú_print_system_scope_remediationrþ  ª  sv   € äÐFÀvÀhÈoÐ^Ô_Üˆ|ÔÜ�˜×*Ñ*Ó,Ð-¨^Ð<Ô=ÜÐ)¨&¨°Ô3CÓ3EÐ2FÐGÔHÜÐTÔUÜÐ@ÔAÜÐ0Ô1ÜÐ.Ö/r@   c                ó$   € V ^8„  d   QhR\         /# r6   r¢  )r;   s   "r=   r>   r>   ¶  s   € ÷ ,ñ ,¤Eñ ,r@   c                 ó  € \         P                  ! RR4      P                  4       p V '       gT   \        4       p\	        V\
        4      '       d   VP                  R/ 4      M/ p\        VP                  R\        4      4      p \        V 4      # )z?Return the configured gateway restart drain timeout in seconds.ÚHERMES_RESTART_DRAIN_TIMEOUTr   ÚagentÚrestart_drain_timeout)
r½   rÝ  r‹   r   r¸  r<  r  rQ   r   r   )r¶   ÚcfgÚ	agent_cfgs      r=   rž  rž  ¶  sg   € ä
�)Š)Ð2°BÓ
7×
=Ñ
=Ó
?€CßÜÓˆÜ,6°s¼D×,AÒ,A�C—G‘G˜G RÔ(Àrˆ	Ü�)—-‘-Ð 7Ô9^Ó_Ó`ˆÜ& sÓ+Ð+r@   c                ó<   € V ^8„  d   QhR\         R\         R\        /# )r7   Úenv_varÚkeyr8   )rQ   rf   )r;   s   "r=   r>   r>   À  s!   € ÷ 	ñ 	¤Cð 	¬cð 	¼Uñ 	r@   c                ó`  € \         P                  ! V 4      pVe'   \        V4      P                  4       R8w  d	   V! V4      # \	        4       p\        V\        4      '       d   VP                  R/ 4      M/ p\        V\        4      '       d   W9   d   V! VP                  V4      4      # V! R4      # )zZ``parse(env)`` when the env var is non-empty, else ``parse(agent.<key>)`` (None if unset).Nr   r  )r½   rÝ  rQ   r‹   r   r¸  r<  r  )r  r  ÚparseÚenv_rawr  r  s   &&&   r=   Ú_agent_timeout_settingr  À  sŠ   € ä�iŠi˜Ó €GØÒœs 7›|×1Ñ1Ó3°rÔ9Ù�W‹~ÐÜ
Ó
€CÜ(2°3¼×(=Ò(=�—‘˜ Ô$À2€IÜ�)œT×"Ò" sÔ'7Ù�Y—]‘] 3Ó'Ó(Ð(Ù�‹;Ðr@   c                ó$   € V ^8„  d   QhR\         /# r6   r¢  )r;   s   "r=   r>   r>   Ì  s   € ÷ oñ o¤ñ or@   c                 ó$   € \        RR\        4      # )zUReturn the configured cron and api_server (/v1) drain floor in seconds.

See #82161.
ÚHERMES_CRON_DRAIN_TIMEOUTÚcron_drain_timeout)r  r   rT   r@   r=   rŸ  rŸ  Ì  s   € ô
 "Ð"=Ð?SÔUmÓnÐnr@   c                ó$   € V ^8„  d   QhR\         /# r6   r¢  )r;   s   "r=   r>   r>   Ô  s   € ÷ ñ ¤uñ r@   c                 óZ   € \        \        4       \        RR\        4      \	        4       4      # )z@CLI wait for gateway exit after SIGUSR1 / self-restart (#77184).Ú!HERMES_RESTART_AFTER_TURN_TIMEOUTÚrestart_after_turn_timeout)r   rž  r  r   rŸ  rT   r@   r=   Ú_get_restart_exit_wait_budgetr  Ô  s.   € ä+Ü"Ó$ÜØ/Ð1MÔOoó	
ô 	 Ó!óð r@   c                ón   € V ^8„  d   QhR\         R\         R\        R,          R\         R\         R\         /# )r7   r5  ra  rÓ  Nrõ  Únon_interactiveÚforce_unit_pathr‘  )r;   s   "r=   r>   r>   ß  sP   € ÷ \ ñ \ Üð\ äð\ ô �t•ð\ ô ð	\ ô
 ð\ ô ñ\ r@   c                 ó’  € V'       d   \        R 4       \        VR7      p^ RIHp V'       g'   V! WaRV4      '       g   \        P
                  ! ^4       \        4       '       dO   \        4        \        4        \        4        V'       g   \        RR4      '       d   \        RR7       \        4        \        V4      p\        V4      w  ršpVP                  4       '       d   V'       g   \        VR7       VP                  4       '       Ed/   V '       Eg&   V'       Eg   \        VR7      '       g]   \        RV R	V 24       \!        VR7       V'       d   \#        R
\%        4       .VR^R7       \        RVP'                  4        R24       Mp\        RV 24       \        R4       V'       dP   \#        R
\%        4       .VR^R7      p\)        VR^ 4      ^ 8w  d%   \+        R\%        4        RVP,                   R24       V'       d   \/        V4      MRpV'       d   \1        V4       R# V'       g   \3        4        R# VP4                  P7                  RRR7       \9        WR7      p\:        P<                  ! VR4      '       d   R# \        RV RV 24       \?        WR7       VPA                  VRR7       \#        R.VR^R7       V'       d   \#        R
\%        4       .VR^R7       \        4        \        RVP'                  4        RV'       d   RMR R 24       \        4        \        R!4       \        R"V	 R#V
 R$24       \        R"V	 R%V
 R&24       \        R'V R(\%        4        R)24       \        4        V'       d.   \/        V4      pV'       d   \        R*V 24       \1        V4       M
\3        4        \C        4        \        4        R# )+Úinstallrc  rÝ  Ú	overwritez,Remove the legacy unit(s) before installing?TF)r­  u   â†» Repairing outdated z systemd service at: Úenabler  rÉ  z service definition updatedzService already installed at: zUse --force to reinstallr™   zcould not enable z" at boot (systemctl enable exited z'); a reboot may come up with no gatewayN©rí  Úexist_okrË  rå  zInstalling z systemd service to: r,   r  r·  z	 service zinstalled and enabledrÏ  Ú!zNext steps:rP  úhermes gateway startz!              # Start the servicezhermes gateway statusz             # Check statusz  journalctl rÑ  z -f  # View logsúConfigured to run as: )"rÑ  rf  ræ  rÞ  rç  Úexitr¤  r9  r«  r(   rÄ  rÒ  r½  rg  rš  rÓ  ré  rh  r†   rÓ  rÉ  r$   r™   rç  rö  ró  r@  Úmkdirr´  r   rç  r‘  rè  rÇ  )r5  ra  rÓ  rõ  r  r  r€  rÞ  r×  rß  rü  rà  ÚenabledÚconfigured_userrã  s   &&&&&&         r=   rø  rø  ß  s1  € ÷ Ü(¨Ô3ô &¨VÔ4€IÝGßÑ#9¸)È[ÐZe×#fÒ#fÜ�Š�Œô × Ò ÜŒÜ!Ô#ÜŒßœmÐ,ZÐ\`×aÒaÜ&°5Õ9ÜŒGä& vÓ.€KÜ"3°FÓ";Ñ€D�ið ×Ñ×Ò§/Ü+°6Õ:à×Ñ×Ó§5 5¯O¨OÜ&¨f×5Ó5ÜÐ+¨K¨=Ð8MÈiÈ[ÐYÔZÜ*°&Õ9ß Ü Ô*:Ó*<Ð=ÀfÐTXÐbdÕeÜ�D˜×/Ñ/Ó1Ð2Ð2MÐNÕOäÐ2°9°+Ð>Ô?ÜÐ,Ô-÷ !Ü(¨(Ô4DÓ4FÐ)GÐPVÐ^cÐmoÔp�Ü˜7 L°!Ó4¸Ô9Ü!Ð$5Ô6FÓ6HÐ5Ið J>Ø>E×>PÑ>PÐ=QÐQxð#zô {÷ FLÔ6°yÔAÐQUˆßÜ)¨/Ô:ñ 	÷ Ü"Ô$Ùà×Ñ×Ñ 4°$ÐÔ7Ü$¨FÔL€HÜ×;Ò;¸HÀn×UÒUÙÜ	ˆK˜�}Ð$9¸)¸Ð
EÔFÜ VÕEØ×Ñ˜¨GÐÔ4ä�OÐ$¨V¸4ÈÕLßÜ˜Ô"2Ó"4Ð5¸fÈDÐZ\Õ]ä	„GÜ	ˆD�×'Ñ'Ó)Ð*¨)×O`Ñ4KÐfqÐ3rÐrsÐ
tÔuÜ	„GÜ	ˆ-ÔÜ	ˆBˆtˆfÐ(¨¨Ð4UÐ
VÔWÜ	ˆBˆtˆfÐ)¨*¨Ð5PÐ
QÔRÜ	ˆM˜)˜ CÔ(8Ó(:Ð';Ð;KÐ
LÔMÜ	„GçÜ6°yÓAˆßÜÐ*¨?Ð*;Ð<Ô=Ü)¨/Ô:øäÔ ä(Ô*ÜÖr@   Úrequire_installedÚpreflight_userc          
      óT   € V ^8„  d   QhR\         R\        R\        R\        R\        /# )r7   rÎ  ra  r&  r'  r8   rÖ  )r;   s   "r=   r>   r>   >  s4   € ÷ ñ ÜðÜðÜ59ðÜRVðä	ñr@   c               ó�   € \        V4      pV'       d   \        V 4       MV'       d   \        4        V'       d   \        WR7       V# )uÁ   Resolve the effective scope, then enforce root (system) / user D-Bus reachability (user, when
``preflight_user``) and â€” when ``require_installed`` â€” that the unit exists. Returns the scope.rc  )rm  rÑ  r}  Ú_require_service_installed)rÎ  ra  r&  r'  s   &&$$r=   Ú_systemd_scope_preambler+  >  s2   € ô
 # 6Ó*€FßÜ(¨Õ0ß	äÔ!ßÜ" 6Õ9Ø€Mr@   c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>   N  s   € ÷ ñ ´$ð Ä4ñ r@   c           	     ó–  € \         P                  ! V 4      pVe)   \        R\        V R7       RV R\	        4        24       R# \        V R7       \        V R7      pVeC   \        V4      P                  4       P                  4       \	        4       P                  4       8X  d   R# \        R\        V R7       RV R\	        4        24       R# )zÅFalse (with a warning) when the installed unit pins a HERMES_HOME other than this process's: the
service name then resolved to ANOTHER install's gateway, and stop/disable/unlink would take it down.zRefusing to remove rc  z: it runs HERMES_HOME=z#, but this process has HERMES_HOME=FT)
r   Úforeign_systemd_unit_homer$   rf  r   rš  r“  r   r
  r  )ra  rv  r˜  s   &  r=   Ú%_systemd_unit_belongs_to_current_homer/  N  sÐ   € ô $×=Ò=¸fÓE€GØÒÜØ!Ô"7¸vÔ"FÐ!GÐG]Ð^eÐ]fð g0Ü0?Ó0AÐ/BðDô	
ñ Ü'¨vÕ6Ü3¸6ÔB€IØÒœD ›O×6Ñ6Ó8×@Ñ@ÓBÄoÓFW×F_ÑF_ÓFaÔaÙÜØ
Ô3¸6ÔBÐCÐCYÐZcÐYdð e,Ü,;Ó,=Ð+>ð	@ôñ r@   c                ó$   € V ^8„  d   QhR\         /# ©r7   ra  r9   )r;   s   "r=   r>   r>   c  s   € ÷ Rñ Rœdñ Rr@   c                 ó˜  € \        R V RR7      p \        V 4      '       g   R# \        R\        4       .V R^ZR7       \        R\        4       .V R^R7       \	        V R7      pVP                  4       '       d   VP                  4        \        RV 24       \        R	.V R
^R7       \        R\        V 4      P                  4        R24       R# )Ú	uninstallF)r&  Nr´  r  rµ  rc  u   âœ“ Removed r·  TrÉ  z service uninstalled)
r+  r/  rh  r†   rf  rg  r¸  r9  rÒ  rÓ  )ra  r€  s   & r=   Úsystemd_uninstallr4  c  sµ   € Ü$ [°&ÈEÔR€FÜ0°×8Ò8ÙÜ�FÔ,Ó.Ð/¸ÀeÐUWÕXÜ�IÔ/Ó1Ð2¸6ÈÐXZÕ[ä%¨VÔ4€IØ×Ñ×ÒØ×ÑÔÜ�˜Y˜KÐ(Ô)ä�OÐ$¨V¸4ÈÕLÜ	ˆDÔ% fÓ-×8Ñ8Ó:Ð;Ð;OÐ
PÖQr@   c                ó(   € V ^8„  d   QhR\         RR/# r�  r9   )r;   s   "r=   r>   r>   s  s   € ÷ >ñ >¬ð >°$ñ >r@   c                 óZ   € \        V 4      w  rp\        R 4       \        RV RV 24       R# )u$   âœ— Gateway service is not installedú  Run: zhermes gateway installN)r½  r9  )ra  rß  rü  r?  s   &   r=   Ú_print_service_not_installedr8  s  s0   € Ü+¨FÓ3Ñ€D�aÜ	Ð
0Ô1Ü	ˆG�D�6Ð/°
¨|Ð
<Ö=r@   c                ó4   € V ^8„  d   QhR\         R\        RR/# ©r7   rÎ  ra  r8   NrÖ  )r;   s   "r=   r>   r>   y  s!   € ÷ ñ ¤sð ´Dð ÀTñ r@   c                 óŒ   € \        VR 7      P                  4       '       g$   \        V4       \        P                  ! ^4       R# R# ©rc  N)rf  rg  r8  rç  r"  )rÎ  ra  s   &&r=   r*  r*  y  s.   € Ü ¨Ô/×6Ñ6×8Ò8Ü$ VÔ,Ü�Š�Žñ 9r@   c                ó$   € V ^8„  d   QhR\         /# r1  r9   )r;   s   "r=   r>   r>     s   € ÷ Nñ Nœ$ñ Nr@   c                 óæ   € \        R V RR7      p \        P                  ! R V 4       \        V R7       \	        R \        4       .V R^R7       \        R\        V 4      P                  4        R24       R# )r  T©r'  rc  r  rÉ  z service startedN)	r+  r   Úrefuse_foreign_systemd_unitré  rh  r†   r9  rÒ  rÓ  rc  s   &r=   Úsystemd_startrA    sb   € Ü$ W¨fÀTÔJ€FÜ×5Ò5°g¸vÔFä"¨&Õ1Ü�GÔ-Ó/Ð0¸ÀtÐUWÕXÜ	ˆDÔ% fÓ-×8Ñ8Ó:Ð;Ð;KÐ
LÖMr@   c                ó$   € V ^8„  d   QhR\         /# r1  r9   )r;   s   "r=   r>   r>   ˆ  s   € ÷ Nñ Nœñ Nr@   c                 ó`  € \        R V 4      p \        P                  ! R V 4       \        V R7       \	        4         \        R \        4       .V R^ZR7       \        R\        T 4      P                  4        R24       R#   \        P                   d    \        R\        T 4       R24        R# i ; i)	r´  rc  Tr  úGateway ze service is still stopping after 90s; check `hermes gateway status` or logs for final shutdown state.NrÉ  z service stopped)r+  r   r@  rš  r²  rh  r†   r‡   r‘   r9  rÒ  rÓ  rc  s   &r=   Úsystemd_stoprE  ˆ  s«   € Ü$ V¨VÓ4€FÜ×5Ò5°f¸fÔEÜ'¨vÕ6ÜÔðÜ˜Ô 0Ó 2Ð3¸FÈ$ÐXZÕ[ô 
ˆDÔ% fÓ-×8Ñ8Ó:Ð;Ð;KÐ
LÖMøô ×$Ñ$ô ÜØÔ+¨FÓ3Ð4ð 5Nð Nô	
ò 	ðús   »A< Á<-B-Â,B-c                ó$   € V ^8„  d   QhR\         /# r1  r9   )r;   s   "r=   r>   r>   ˜  s   € ÷ %Gñ %GœDñ %Gr@   c                 ó  € \        R V RR7      p \        P                  ! R V 4       \        V R7       ^ RIHp V! 4       ;'       g    \        V R7      pVei   \        V4      \        8X  dU   \        RV R24       \        V4       \        4       p\        RV.V R	^R
7       \        R V.V R	^ZR
7       \        WR7       R# Ve#   \        W4      pV'       d   \        W@VR7       R# \!        WR7      '       d   R# \        R WR7       R# )ÚrestartTr?  rc  rÄ  Nr8  uU    event loop is unresponsive â€” skipping graceful drain and forcing a bounded stop...r  Fr  r   )r+  r   r@  ré  rÛ   r¸  r³  r,  r"  r9  r:  r†   rh  rá  Ú _systemd_graceful_restart_actionÚ_systemd_reset_and_runr  )ra  r¸  rd   r¢   Úservice_actions   &    r=   Úsystemd_restartrL  ˜  sî   € Ü$ Y°ÀtÔL€FÜ×5Ò5°iÀÔHô #¨&Õ1Ý.Ù
Ó
×
?Ð
?Ô0¸Ô?€CØ
‚Ô6°sÓ;Ô?RÔRäð ˜s˜eð $Dð Dô	
ô 	! Ô%ÜÓ ˆÜ˜¨Ð,°VÀ5ÐRTÕUÜ˜	 3Ð'°¸eÈRÕPÜ)°ÕJÙØ
‚Ü9¸&ÓFˆßÜ" >ÈsÕSÙä'¨v×HÓHÙÜ˜9¨V×Fr@   c                óJ   € V ^8„  d   QhR\         R\        R\        R,          /# )r7   ra  rd   r8   N)r:   rS   rQ   )r;   s   "r=   r>   r>   À  s%   € ÷ .ñ .¬Tð .¼ð .ÄÀdÅ
ñ .r@   c           	     ó  € \        V 4      P                  4       p\        4       p\        RV RV RVR R24       ^ RIHp \        WV! VR7      R7      '       g   \        R	\        V4       R
24       R# . p\        WVR7      '       d   R# V'       g   \        V R7      '       d   R# \        V R7      pV'       g   R# \        V4      pVP                  R4      R9   g!   VP                  R4      R8X  g   Ve	   Wq8w  d   R# \        R4       R# )zºSIGUSR1-drain the live gateway ``pid``; return the follow-up ``systemctl`` verb (``"start"`` /
``"restart"``) the caller must still issue, or None when systemd already owns the relaunch.rÎ  z$ service restarting gracefully (PID u   ) â€” waiting up to z.0fz s for in-flight turns + drain...)Údrain_progress_reporter)Úbudget_srÒ   u-   âš  Graceful restart did not complete within zs; forcing a service restart...rH  )ra  r¾  r¿  Nrc  rÂ  rÃ  rÐ  ub   âš  Systemd did not relaunch the gateway after its graceful exit; starting the inactive service...r  >   re  Ú	reloadingrÏ  )rÒ  rÓ  r  r9  Ú"hermes_cli.update_cmd_drain_reportrO  rÕ   rS   rá  r÷  rž  rª  r  )ra  rd   r×  Úwait_budgetrO  r¿  r¤  Úreplacement_pids   &&      r=   rI  rI  À  s  € ô ' vÓ.×9Ñ9Ó;€Kô 0Ó1€KÜ	Ø
ˆ{ˆmÐ?À¸uð EØ$ SÐ)Ð)Ið	Kôõ KÜ(¨ÑG^ÐhsÔGt×uÓuÜÐ=¼cÀ+Ó>NÐ=OÐOnÐoÔpÙð (*ÐÜ(°Ð_s×tÓtÙßÔ@È×OÓOÙô *°Ô8€EßÙÜ2°5Ó9€Oà�	‰	�-Ó Ð$IÔIØ�9‰9�ZÓ  NÔ2ØÒ'¨OÔ,Báä	Ð
nÔoár@   c                ó4   € V ^8„  d   QhR\         R\        RR/# r:  rÖ  )r;   s   "r=   r>   r>   ñ  s&   € ÷ Pñ P¤3ð P´4ð PÈ$ñ Pr@   c               óz  € \        4       p\        RV.VR^R7        \        W.VR^ZR7       \        YR	7       R#   \        P                   d<   p\	        T4      '       g   \        TR7      '       d   \        TR7        Rp?R# h Rp?i\        P                   d    \        R\        T4       R24        R# i ; i)
z¬``reset-failed`` then ``systemctl <action>``, then wait for the relaunch. Start-limit
rejection prints the wait hint instead of raising; a 90s timeout prints where to look.r  Fr  Trc  NrD  z^ service is still restarting after 90s; check `hermes gateway status` or logs for final state.r   )r†   rh  r‡   rï  rô  r÷  rÖ  r‘   r9  rÒ  rá  )rÎ  ra  r¾  r¢   rÄ  s   &$$  r=   rJ  rJ  ñ  s°   € ô Ó
€CÜ�N CÐ(°¸uÈbÕQðÜ˜�}¨V¸4ÈÕLô &¨V×Oøô ×(Ñ(ô Ü/°×4Ò4Ô8YÐag×8hÓ8hÜ+°6Õ:ÝØûÜ×$Ñ$ô ÜØÔ+¨FÓ3Ð4ð 5Eð Eô	
ò 	ðús'   �; »B:Á/BÂBÂB:ÂB:Â9B:c                ó<   € V ^8„  d   QhR\         R\         R\         /# )r7   Údeepra  Úfullr9   )r;   s   "r=   r>   r>     s&   € ÷ J9ñ J9œð J9¬tð J9Ä4ñ J9r@   c           
      óB  € \        V4      p\        VR 7      p\        4       p\        V4      P	                  4       p\        V4      w  rgpVP                  4       '       g   \        V4       R# \        4       '       d   \        4        \        4        \        4       '       d   \        4        \        4        \        VR 7      '       g(   \        R4       \        RV RV R24       \        4        RVR.V'       d   R.M. ,           p	\        W‘R	^
R
7       \        RV.3RVR^
/\        B p
V
P                   P#                  4       R8X  d   \        RV R24       M \        RV R24       \        RV RV 24       V'       d   \%        V4      MRpV'       d   \        RV 24       \'        4        \)        VR 7      pVP+                  RR4      pVP+                  RR4      pVR8X  d$   VP+                  RR4      R8X  d   \        R4       Mª\-        V4      '       d/   \        R4       \        RV RV 24       \        RV RV 24       MkVR 8X  dH   VP+                  R!R4      \/        \0        4      8X  d$   \        R"4       \        R#V RV R$V RV 24       MVR 8X  d   V'       d   \        R%V 24       V'       d   \        R&4       Mi\3        4       w  ppVR'J d   \        R(4       MJVR	J d   \        R)4       \        R*4       M-V '       d&   \        R+V R,24       \        R-4       \        R.4       V '       dk   \        4        \        R/4       R0.V'       d   . MR1.,           R2VR3R4R.,           pV'       d   VP5                  R4       \6        P8                  ! V^
R	R57       R# R# )6rc  Nu4   âš  Installed gateway service definition is outdatedr7  rú  z  # auto-refreshes the unitr×  r{   z-lF)ra  r.   r|   rd  ra  r|   re  rÉ  z gateway service is runningõ   âœ— z gateway service is stoppedr   r!  rÂ  r   rí  rÏ  rÃ  rÐ  uA     â�³ Restart pending: systemd is waiting to relaunch the gatewayuB     â�³ Restart pending: systemd is temporarily rate-limiting startsz,  Run after the start-limit window expires: z"  Or clear it manually: systemctl rû  r  r  u@     âš  Planned restart is stuck in systemd failed state (exit 75)z  Run: systemctl z && u     âš  Systemd unit result: uB   âœ“ System service starts at boot without requiring systemd lingerTrñ  uB   âš  Systemd linger is disabled (gateway may stop when you log out)z(  Run: sudo loginctl enable-linger $USERu%   âš  Could not verify systemd linger (rÊ  z>  If you want the gateway user service to survive logout, run:z#  sudo loginctl enable-linger $USERzRecent logs:Ú
journalctlrz   z-uz-nÚ20)r|   r}   )rm  rf  r†   rÒ  rÓ  r½  rg  r8  r“  rÇ  r9  r¤  r«  rÓ  rh  r‰   rŠ   r‹   rç  Ú_print_runtime_healthrž  r  rÕ  rQ   r   rx  rG  r‡   rˆ   )rX  ra  rY  r€  r¢   r×  rß  rü  rà  Ú
status_cmdrŸ   r%  Ú
unit_propsrÙ  Úresult_coderz  r{  Úlog_cmds   &&&               r=   Úsystemd_statusrc    s*  € Ü" 6Ó*€FÜ%¨VÔ4€IÜ
Ó
€CÜ& vÓ.×9Ñ9Ó;€KÜ"3°FÓ";Ñ€D�ià×Ñ×ÒÜ$ VÔ,Ùä$×&Ò&Ü,Ô.ÜŒä× Ò Ü!Ô#ÜŒä"¨&×1Ó1ÜÐDÔEÜ�˜�vÐ3°J°<Ð?ZÐ[Ô\ÜŒà˜C Ð.¿D°4±&ÀbÕI€JÜ�:¸UÈBÕOÜ˜[¨#Ð.Ñ[°vÐ[ÀrÐ[Ì]Ñ[€FØ‡}�}×ÑÓ Ô(Ü��[�MÐ!<Ð=Õ>ä��[�MÐ!<Ð=Ô>Ü�˜�vÐ1°*°Ð>Ô?çAGÔ2°9Ô=ÈT€OßÜÐ& Ð&7Ð8Ô9äÔä.°fÔ=€JØ—>‘> -°Ó4€LØ—.‘. ¨2Ó.€KØ�|Ô#¨
¯©°zÀ2Ó(FÈ.Ô(XÜÐQÕRÜ	'¨
×	3Ò	3ÜÐRÔSÜÐ<¸T¸FÐBXÐYcÐXdÐeÔfÜÐ2°9°+¸]È3È%ÐPÕQØ	˜Ô	! j§n¡nÐ5EÀrÓ&JÌcÔRsÓNtÔ&tÜÐPÔQÜÐ! ) ¨M¸#¸¸dÀ4À&ÐH\Ð]gÐ\hÐiÕjØ	˜Ô	!§kÜÐ+¨K¨=Ð9Ô:çÜÐRÕSä(AÓ(CÑ%ˆ˜Ø˜TÓ!ÜÐKÕLØ˜uÓ$ÜÐVÔWÜÐ<Õ=ßÜÐ9¸-¸ÈÐJÔKÜÐRÔSÜÐ7Ô8çÜŒÜˆnÔØ�.¯&¡B°x°jÕAÀTÈ3ÐPTÐVZÐ\hÐDiÕiˆßØ�N‰N˜4Ô Ü�Š�w¨°%×8ñ r@   ))r”   Ú_probe_launchd_domain_for_labelÚ_launchd_domainÚ _LAUNCHD_JOB_UNLOADED_EXIT_CODESÚ#_LAUNCHCTL_DOMAIN_UNSUPPORTED_CODESÚ!_launchd_error_indicates_unloadedÚ_launchctl_domain_unsupportedÚ_LAUNCHCTL_BOOTSTRAP_EIOÚ_launchctl_bootstrapÚ_launchd_reload_log_pathÚ_append_launchd_reload_logÚ_launchd_reload_budgetÚ_launchctl_supervised_pidr"  Ú+_retry_launchctl_bootstrap_until_registeredÚ _launchd_unsupported_marker_pathÚ!_write_launchd_unsupported_markerÚ!_clear_launchd_unsupported_markerrC  Ú_gateway_run_commandÚ#_timestamped_stderr_gateway_commandÚ_spawn_detached_gatewayÚ_launchd_fallback_to_detachedÚ_launchd_degrade_or_raiseÚgenerate_launchd_plistÚlaunchd_plist_is_currentÚ_spawn_deferred_launchd_reloadÚrefresh_launchd_plist_if_neededÚlaunchd_installÚlaunchd_uninstallÚlaunchd_startÚ_launchctl_kickstart_currentÚ _launchd_bootstrap_and_kickstartÚ_launchd_okÚlaunchd_stopÚ_launchd_kickstartÚ_wait_for_launchd_service_pidÚlaunchd_restartÚ"LAUNCHD_SUPERVISION_VERIFY_TIMEOUTÚ$wait_for_launchd_gateway_supervisionÚlaunchd_status)ÚUTCç      $@c                óJ   € V ^8„  d   QhR\         R\         R,          R\        /# )r7   r|   Úforce_afterNr8   r`  )r;   s   "r=   r>   r>   ‹  s&   € ÷ ñ ¤Eð ¼uÀt½|ð ÔVZñ r@   c                ó$  € ^ RI HpHp \        P                  ! 4       V ,           pVe   \        P                  ! 4       V,           MRpRp\        P                  ! 4       V8  dr   V! 4       pVf   R# VeI   V'       gA   \        P                  ! 4       V8¼  d'    \        VRV! V4      R7       \        RV R24       Rp\        P                  ! R4       K‹  V! 4       pVe   \        RV R	V  R
24       R# R#   \        \        \        3 d     R# i ; i)z­Wait up to ``timeout`` s for the gateway (by gateway.pid, not launchd labels, so multiple
HERMES_HOMEs work) to exit; SIGKILL it after ``force_after`` s of graceful waiting.)r3  r¸  NFTr6  r8  z& did not exit gracefully; sent SIGKILLg333333Ó?z still running after u   s â€” restart may fail)rÛ   r3  r¸  rÜ   rÝ   r   r9  rÈ   rÉ   rÊ   rÞ   )	r|   r�  r3  r¸  rß   Úforce_deadlineÚ
force_sentrd   Úremaining_pids	   &&       r=   Ú_wait_for_gateway_exitr’  ‹  sô   € ÷ GÜ�~Š~Ó 'Õ)€HØ9DÒ9P”d—n’nÓ&¨Ö4ÐVZ€NØ€Jä
�.Š.Ó
˜XÔ
%ÙÓˆØŠ;ÙàÒ"¯:¼$¿.º.Ó:JÈnÔ:\ðÜ˜c¨ÑCYÐZ]ÓC^Õ_ÜÐ(¨¨Ð-SÐTÔUð ˆJä�
Š
�3Žñ $Ó%€MØÒ ÜÐ   Ð/DÀWÀIÐMcÐdÔeÙÙøô '¬¼ÐAô Úðús   Â#C5 Ã5DÄDc                óH   € V ^8„  d   QhR\         R\        R\        R\        /# )r7   r!  rü   r|   r8   )rQ   rS   rf   r:   )r;   s   "r=   r>   r>   «  s(   € ÷ ñ ¤#ð ¬Sð ¼eð Ìtñ r@   c               óv  € \         P                  ! 4       V,           p\         P                  ! 4       V8  dE    \        P                  ! W3RR7      ;_uu_ 4         RRR4       \         P                  ! R4       K^  R#   + '       g   i     L*; i  \         d     R# \
         d     LG\         d     R# i ; i)a<  Wait until nothing accepts TCP connections on host:port.

PID exit is not enough on macOS: api_server disables SO_REUSEADDR, so a restart that wins
the race logs EADDRINUSE and keeps running with no API. Connection-refused means the
listener is gone; a timed-out connect is a live listener with a slow accept queue.
r  r  NTgš™™™™™¹?F)rÜ   rÝ   rë   Úcreate_connectionÚConnectionRefusedErrorÚTimeoutErrorrÊ   rÞ   )r!  rü   r|   rß   s   &&$ r=   Ú_wait_for_tcp_port_freer˜  «  sˆ   € ô �~Š~Ó 'Õ)€HÜ
�.Š.Ó
˜XÔ
%ð	Ü×)Ò)¨4¨,À×DÖDØ÷ Eô 	�
Š
�3ŽÙ÷ E×Dûä%ô 	ÚÜô 	ÙÜô 	Úð	úsG   ¸!B ÁA=ÁB Á=B	ÂB ÂB ÂB8ÂB8Â'B8Â*B8Â3B8Â7B8c                ó0   € V ^8„  d   QhR\         R\        /# r_  r`  )r;   s   "r=   r>   r>   Á  s   € ÷ ñ ¬uð Äñ r@   c                ó2  € ^ RI Hp ^ RIHp \	        4       P
                  P                  VP                  4      pVe   VP                  '       g   R# T! VP                  ;'       g    / 4      w  rE\        WEV R7      pV'       g   \        RV RV R24       V# )zÕWait for the configured api_server listen address to stop accepting.

Only when api_server is enabled: with the platform off, a foreign listener on the default
port is nobody's race and must not delay the restart.)ÚPlatform)Úlisten_addressTr  rË  r?  u@    still accepting connections â€” new api_server may fail to bind)Úgateway.configr›  Úgateway.platforms.api_serverrœ  r   Ú	platformsr  Ú
API_SERVERr$  rV  r˜  r9  )r|   r›  rœ  Úpconfigr!  rü   Úfreeds   $      r=   Ú_wait_for_api_server_port_freer£  Á  s†   € õ
 (Ý;Ü!Ó#×-Ñ-×1Ñ1°(×2EÑ2EÓF€GØ‚˜gŸoŸo˜oÙÙ §¡× 3Ð 3°Ó4�J€DÜ# D¸Ô@€EßÜØ�4�&˜˜$˜ð  .ð .ô	
ð €Lr@   c                ó>   € V ^8„  d   QhR\         R,          R\        /# )r7   r¡  Nr8   rÖ  )r;   s   "r=   r>   r>   Û  s"   € ÷ Jñ J”s˜T•zð J¤dñ Jr@   c                 ój   € \        T ;'       g    R 4      P                  4       P                  4       R9   # )r   >   rô  Úonrþ  rÿ  )rQ   r‹   rm  )r¡  s   &r=   rÜ  rÜ  Û  s+   € Üˆu�{ˆ{˜Ó×!Ñ!Ó#×)Ñ)Ó+Ð/IÑIÐIr@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   ß  s   € ÷ hñ h¤dñ hr@   c                  óz   € \        \        4      R 8H  ;'       d#    \        R,          R,          P                  4       # )z/opt/hermesÚdockerzentrypoint.sh)rQ   r	  Úis_filerT   r@   r=   Ú_is_official_docker_checkoutr«  ß  s-   € ÜŒ|Ó Ñ-×gÐg´<À(Õ3JÈ_Õ3\×2eÑ2eÓ2gÐgr@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   ã  s   € ÷ +ñ +¬4ñ +r@   c                 ó   € \        4       # )a  True when this process IS the supervisor-launched gateway, so the conflict guard never wedges
the service into a respawn/refuse loop. Markers: systemd INVOCATION_ID, launchd XPC_SERVICE_NAME
(shells inherit "0"), s6 HERMES_S6_SUPERVISED_CHILD, or ``--external-supervisor``.)r   rT   r@   r=   Ú!_running_under_gateway_supervisorr®  ã  s   € ô )Ó*Ð*r@   c                ó2   € V ^8„  d   QhR\         R,          /# ©r7   Úprofile_nameNr—  )r;   s   "r=   r>   r>   ê  s   € ÷ ñ ¬3°­:ñ r@   c                óP  €  ^ RI Hp V e   T M	\        4       pT! T;'       g    R4      pVf   R# ^ RI Hp V! VP                  \        4       4      '       d'   \        P                  RVP                  4       4       R# V#   \         d    \        P                  RRR7        R# i ; i)	u)  The ONE live host gateway when it serves ``profile_name`` (default: the current profile).

Companion to :func:`named_profile_served_by_running_multiplexer`, which answers the narrower
"is this a SATELLITE of the default's multiplexer" and is hard-False for ``default`` â€” the
profile that usually owns the shared process. Every lifecycle guard built on it was therefore
blind to the host process itself. This one is true for ``default`` too, and it reports WHICH
profiles the host process serves. Returns a ``gateway.host_attach.HostGateway`` or None.
)Úhost_gateway_servingNrl  )Úlaunched_by_other_tenantz8Host gateway %s belongs to another Hermes home; not ourszHost multiplexer probe failedTr`  )
Úgateway.host_attachr³  r.  r´  rä   r   r¨  r³  Údescriber²   )r±  r³  rk   r  r´  s   &    r=   Úhost_multiplexer_servingr·  ê  s’   € ðÝ<Ø+Ò7‰|Ô=RÓ=TˆÙ& t×'8Ð'8¨yÓ9ˆØŠ?Ùõ 	AÙ# G§L¡L´/Ó2C×DÒDÜ�L‰LÐSÐU\×UeÑUeÓUgÔhÙØˆøÜô Ü�‰Ð4¸tˆÔDÚðús"   ‚ A? £A? °AA? Á=A? Á?"B%Â$B%c                ó2   € V ^8„  d   QhR\         R,          /# r°  r—  )r;   s   "r=   r>   r>     s   € ÷ ñ ´#¸µ*ñ r@   c                óÎ   € \        V 4      pVf   R#  ^ RIHpHp V! VP                  V! 4       4      '       d   R#  V#   \
         d    \        P                  RRR7        T# i ; i)aW  The host gateway serving ``profile_name`` when it is NOT this home's own process.

The owner must never be guarded out of restarting itself: a refusal keyed on "something serves
you" would make `hermes gateway restart` impossible for the profile that launched the host
process. Guards want "ANOTHER process already serves you", which is this.
N©Ú_get_process_hermes_homeÚ_same_hermes_homez'Host multiplexer home comparison failedTr`  )r·  rÛ   r»  r¼  rä   r²   r¨  r³  )r±  r  r»  r¼  s   &   r=   Ú_served_by_another_host_gatewayr½    sm   € ô ' |Ó4€GØ‚ÙðOßNÙ˜WŸ\™\Ñ+CÓ+E×FÒFÙð Gð €Nøô ô OÜ�‰Ð>ÈˆÕNØ€NðOús   “%> ¾"A$Á#A$c                ó>   € V ^8„  d   QhR\         R,          R\        /# )r7   r±  Nr8   rÖ  )r;   s   "r=   r>   r>     s   € ÷ 0ñ 0¼cÀD½jð 0ÔTXñ 0r@   c                ó  €  V e   T M	\        4       pT'       d   TR8X  d   R# \        T4      pTe&   ^ RIHp T! TP
                  4      T! T4      8w  d   R#  ^ RIHp T! 4       p ^ RIH	pH
p T! 4       f   R# ^ RIHp T! T4      pTe!   T! T4      T U	u0 uF
  q“! T	4      kK  	  up	9   # ^ RIHp
 T
! T4      RJ #   \         d     R# i ; i  \         d     R# i ; iu up	i   \         d    \        P                  RRR	7        R# i ; i)
z×True when a live default multiplexer already ticks this named profile (a satellite profile has no
gateway.pid; the multiplexer fires its jobs and serves its platforms). Defaults to the current profile.

See #97120.
Frl  )Únormalize_profile_nameTr  )Úlive_default_gateway_pidÚrecorded_served_profiles)Úexplicit_multiplex_flagz Multiplexer-serving probe failedr`  )r.  r²   r·  r¿  rÀ  Úprofile_labelr4  r-  rR  rÁ  rÂ  rI  rÃ  r¨  r³  )r±  r&  r  rÀ  r-  r!  rÁ  rÂ  rž  r®  rÃ  s   &          r=   rl  rl    s"  € ðØ!-Ò!9‘Ô?TÓ?Vˆ÷ �V˜yÔ(Ùô ' vÓ.€GØÒÝ>Ù! '×"7Ñ"7Ó8Ñ<RÐSYÓ<ZÔZÙðÝ<Ù.Ó0ˆðßjÙ#Ó%Ò-ÙÝ>ñ ,¨LÓ9ˆØÒÙ)¨&Ó1ÑYaÓ5bÑYaÐTUÐ6LÈQÖ6OÑYaÑ5bÑbÐbõ 	NÙ& |Ó4¸Ð<Ð<øôK ô Úðûô& ô Úðüò 6cøô ô Ü�‰Ð7À$ˆÔGÚðúsS   ‚B; ÁC Á&C$ Á9C$ ÂCÂ&C$ Â+C$ Â;C
Ã	C
ÃCÃCÃC$ Ã$"D
Ä	D
c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   K  s   € ÷ ñ ¬$ñ r@   c                 ó  € \        4       '       g   \        4       # ^ RIHp  V ! \	        4       4      '       d"   ^ RIHp \        V! \        4       4      4       R# \        R\        4        R24       \        R4       \        R4       R# )a½  Print the "already served" note and return True when a setup flow must not install a standalone
service: a live multiplexing default gateway already serves this named profile, so the unit/plist it
would register can only sit dead (the start guard refuses it) or double-bind its platforms.
Shared by ``hermes setup gateway`` / ``hermes setup`` / ``hermes import`` (``ensure_gateway_service``)
and the ``hermes gateway setup`` wizard. See #111958.©Úprofile_is_standalone©Ústandalone_rescan_messageTú	Profile 'z/' is already served by the default multiplexer.uW     (served now by the running multiplexed gateway â€” add its bot token and it connects)z9  No standalone gateway service was installed or started.)
rl  Ú(_named_profile_refused_under_multiplexerr¿  rÈ  r   rµ  rÊ  r"   r.  r#   )rÈ  rÊ  s     r=   Ú _served_profile_needs_no_servicerÍ  K  sr   € ô 7×8Ò8ô 8Ó9Ð9Ý9Ùœ_Ó.×/Ò/ÝAÜÑ,Ô-BÓ-DÓEÔFÙÜØ
Ô)Ó+Ð,Ð,[Ð\ôô ÐhÔiÜÐJÔKÙr@   c                ó0   € V ^8„  d   QhR\         R\         /# )r7   r5  r8   r9   )r;   s   "r=   r>   r>   b  s   € ÷ Kñ K´Dð KÄTñ Kr@   c                óz  € V '       d   R#  \        4       p^ RIHp ^ RIHp V! \        4       4      R 9  ;'       d    V! \        4       4      pV! \        4       4      R 9  ;'       d    \        4       '       * p\        4       pTRJ;'       g    \        4       pT'       d$   T'       g   R# ^ RI
Hp \        T! T4      4       R# T'       g   T'       g   R# T'       d1   \        RT R	24       Te   \        R
TP                  4        24       M\        RT R24       \        R4       T'       d6   \        R4       \        4        \        RTe   TP                  MR R24       MJ\        R4       \        4        \        R4       \        4        \        R4       \        4        \        R4       \        4        \        R4       \        RT R24       \        4        ^ RIHp	 ^ RIHp
 \        R4       \        RT	! \        4       4       R24       \        R4       \        RT
 R24       R#   \         d     R# i ; i)!u  Print the refusal and return True when a NAMED profile must not get a gateway of its own.

One gateway per host serves every profile, so a ``<root>/profiles/<name>`` home never installs or
starts a standalone gateway: either the host gateway already serves it (a second one would
double-bind its platforms: two pollers on one token, port fights) or no host gateway runs yet and
the DEFAULT profile is where it is installed. Refusing only the served case let a host with no
multiplexer running (or one that had not rescanned yet) grow a brand-new per-profile fleet member.
``--force`` is the one escape (a fleet split across UNIX users or a ``HERMES_HOME`` outside
``profiles/``); a service it already installed stays startable without it. Shared by ``run`` and the service verbs (``start``/``install``/``restart``): a
refusal only inside ``gateway run`` leaves the service manager to discover it â€” systemd parks the
unit on exit 78 while the CLI prints "started"; launchd (KeepAlive, no exit-status gating)
respawns it every ThrottleInterval forever.Fr  rÇ  Nrl  rÉ  Tz)The host gateway already serves profile 'ú'.rP  rË  z$' does not get a gateway of its own.zÌ  Exactly one gateway per host is the inbound process for every
  profile. Starting a separate gateway for this profile would
  double-bind its platforms (two pollers on one bot token, port
  conflicts).
z"  Manage the host gateway instead:ú    hermes -p z gateway restartzU  Install or start the host gateway from the default profile; it serves this one too:z    hermes gateway installz>  Or fold an existing per-profile fleet onto one host gateway:z&    hermes gateway migrate --multiplexzJ  A separate per-profile gateway (for a fleet split across UNIX users or az;  HERMES_HOME outside profiles/) needs --force:  hermes -p z gateway install --force)Údisplay_hermes_home©ÚSTANDALONE_DEPRECATION_NOTICEzF  Temporary compatibility path while multiplexing gaps are closed: setz  gateway.standalone: true in z/config.yaml,z\  then wait for the host gateway to rescan (<=30s) or send its rescan-profiles control verb.r¨  rÊ  rk  )r.  r4  r  r¿  rÈ  r   Ú_is_service_installedr²   r½  rl  rµ  rÊ  r%   r9  r¶  rÄ  rÒ  rI  rÔ  )r5  r&  r  rÈ  Ú
standaloneÚnew_standalonerŠ  ÚservedrÊ  rÒ  rÔ  s   &          r=   rÌ  rÌ  b  sú  € ÷ ÙðÜ&Ó(ˆÝ:Ý=ñ ,¬OÓ,=Ó>ÐFWÑW÷ Cð CÙ/´Ó0AÓBð 	ñ 0´Ó0AÓBÐJ[Ñ[÷ :ð :Ü"7Ó"9Ô9ð 	ô ,Ó-€EØ˜$Ð×OÐOÔ"MÓ"O€FßßÙÝAÜÑ-¨fÓ5Ô6ÙßŸ.ÙçÜÐ?À¸xÀrÐJÔKØÒÜ�B�u—~‘~Ó'Ð(Ð)Ô*øä�i ˜xÐ'KÐLÔMÜ	ð	ô÷ ÜÐ2Ô3ÜŒÜ�°eÒ6G˜u×2Ò2ÈYÐWÐWgÐhÕiäÐeÔfÜŒÜÐ*Ô+ÜŒÜÐNÔOÜŒÜÐ6Ô7Ü	„GÜ	Ð
VÔWÜ	ÐGÈÀxÐOgÐ
hÔiÜ	„GÝ4ÝOÜ	Ð
RÔSÜ	Ð*Ñ+>¼Ó?PÓ+QÐ*RÐR_Ð
`ÔaÜ	Ð
hÔiÜ	ˆCÐ-Ð.¨aÐ
0Ô1Ùøô_ ô Úðús   ŒA+H+ È+H:È9H:c                ó(   € V ^8„  d   QhR\         RR/# ©r7   r5  r8   Nr9   )r;   s   "r=   r>   r>   °  s   € ÷ -ñ -´$ð -À4ñ -r@   c                ób   € \        V R7      '       g   R# \        P                  ! \        4       R# )zVExit-78 form of ``_named_profile_refused_under_multiplexer`` for the CLI entry points.r4  N)rÌ  rç  r"  r   r4  s   &r=   Ú&_guard_named_profile_under_multiplexerrÜ  °  s   € ä3¸%×@Ó@Ùô ‡H‚HÔ+Ö,r@   c                ó$   € V ^8„  d   QhR\         /# r6   r©   )r;   s   "r=   r>   r>   Ã  s   € ÷ *ñ *¬#ñ *r@   c                ó@   € \        V RR4      '       d   \        # \        # )u?  Exit code for a host-attach verdict a supervisor may be watching.

``GATEWAY_FATAL_CONFIG_EXIT_CODE`` (78) is the PERMANENT refusal: systemd parks the unit on it
(``RestartPreventExitStatus``), the s6 finish script maps it to 125, launchd maps it to a
deliberate stop. That is right for a config-derived refusal and wrong for a runtime one â€” "some
other process serves me right now" ends the moment that process goes away, and parking the unit
on it strands the profile until a human notices. Transient verdicts therefore use
``GATEWAY_SERVICE_RESTART_EXIT_CODE`` (75, EX_TEMPFAIL), which every supervisor we generate
already retries: systemd has ``RestartForceExitStatus=75`` with ``RestartSec=5``, the s6 finish
script passes it through, and launchd relaunches a non-78 failure. Exit 0 would NOT do: s6
parks a clean exit too.
Ú	transientF)rÉ  r   r   )Údecisions   &r=   Ú_host_decision_exit_coderá  Ã  s   € ô ˆx˜ e×,Ò,Ü0Ð0Ü)Ð)r@   c                ó4   € V ^8„  d   QhR\         R\         RR/# )r7   r5  r-   r8   Nr9   )r;   s   "r=   r>   r>   Õ  s"   € ÷ !8ñ !8¬Dð !8Ä4ð !8ÐTXñ !8r@   c                óz  € V '       d   R#  ^ RI HpHpHpHp V! \        4       VR7      pVe   VP                  X8X  d   R# VeÀ   VP                  XX39   d­   \        VP                  4       VP                  V8X  dB   \        V4      p\        P                  RWvP                  4       \        P                  ! V4       \!        4       '       d    \        P                  ! \        V4      4       \        P                  ! ^ 4       \#        V R7       R#   \         d    \        P                  RRR7       Rp ELi ; i)	a  ``gateway run`` against the ONE host gateway: attach, rescan-then-attach, replace, or refuse.

A profile the host process already serves has nothing to run: print who serves it and exit 0
without spawning anything. Under a service supervisor the SAME situation exits 75 instead, so
the unit is RETRIED rather than parked (see :func:`_host_decision_exit_code`).

``--replace`` and ``--force`` are the two escape hatches this guard must not eat: both return
here so ``start_gateway`` can act on them (it owns the signalling and the PID claim).
N)ÚATTACHÚREFUSEÚREPLACE_HOSTÚdecider6  z Host gateway attach probe failedTr`  z!gateway run refused (exit %d): %sr4  )rµ  rä  rå  ræ  rç  r   r²   r¨  r³  Úoutcomer9  Úmessagerá  r©  rç  r"  r®  rÜ  )r5  r-   rä  rå  ræ  rç  rà  Úcodes   &&      r=   Ú _attach_to_host_gateway_or_guardrë  Õ  sñ   € ÷ ÙðßLÓLÙœ/Ó+°WÔ=ˆð Ò × 0Ñ 0°LÔ @ÙØÒ × 0Ñ 0°V¸VÐ4DÔ DÜˆh×ÑÔØ×Ñ˜vÔ%Ü+¨HÓ5ˆDô �N‰NÐ>À×FVÑFVÔWÜ�HŠH�TŒNÜ,×.Ò.Ü�HŠHÔ-¨hÓ7Ô8Ü�Š�Œä*°×7øô% ô Ü�‰Ð7À$ˆÔGØ‹ðús   ŒD Ä$D:Ä9D:c                ó(   € V ^8„  d   QhR\         RR/# rÚ  r9   )r;   s   "r=   r>   r>   ù  s   € ÷ $ñ $¬dð $¸tñ $r@   c                óÚ  € V '       g   \        4       '       d   R# \        4       '       g   R#  \        4       pTP                  '       d   TP                  '       g   R# \        RTP                   R24       \        R4       \        4        \        R4       \        4        \        R	4       \        P                  ! ^4       R#   \         d    \        P                  RRR7        R# i ; i)
a0  Refuse a foreground gateway when a service manager already supervises one: a shell-launched run
becomes a second dispatcher that escapes the cgroup, survives ``systemctl restart``, and writes the
shared kanban DB concurrently (multi-writer SQLite WAL corruption). ``--force`` starts anyway.

See #35240.
Nz(Supervised-gateway conflict probe failedTr`  z#A gateway is already running under z for this profile.uâ     Starting another one from a shell leaves an orphan dispatcher that
  escapes the service, survives restarts, and writes to the same kanban
  DB concurrently â€” which can corrupt it. Restart the supervised gateway
  instead:ú    hermes gateway restartze  Pass --force to start a foreground gateway anyway (not recommended
  while the service is running).)r®  rÕ  r;  r²   r¨  r³  rK   rC   r%   rO   r9  rç  r"  )r5  r:  s   & r=   Ú"_guard_supervised_gateway_conflictrï  ù  sÅ   € ÷ Ô1×3Ò3Ùô !×"Ò"ÙðÜ/Ó1ˆð ×&×&Ð&¨8×+C×+CÐ+CÙäÐ5°h×6FÑ6FÐ5GÐGYÐZÔ[Ü	ð	ôô 
„GÜ	Ð
&Ô'Ü	„GÜ	ð	+ôô ‡H‚HˆQ†Køô) ô Ü�‰Ð?È$ˆÔOÚðús   ®
C Ã"C*Ã)C*c                ó(   € V ^8„  d   QhR\         RR/# )r7   r-   r8   Nr9   )r;   s   "r=   r>   r>      s   € ÷  ñ  ´dð  Àtñ  r@   c                óô  € V '       g   \        4       '       d   R#  ^ RIHp V! 4       pTfK    ^ RIHpHp T! 4       pTe5   T! T4      '       g'   \        P                  RTP                  RR	4      4       R# \        R
T R24       \        R4       \        R4       \        R4       \        P                  ! ^4       R#   \         d    \        P                  RRR7        R# i ; i  \         d     R# i ; i)a  Cheap PID-file preflight before the expensive ``gateway.run`` import (the authoritative lock check):
supervisor loops re-running bare ``gateway run`` burned memory on plugin discovery just to fail
"already running". Same user-facing contract; never scans other HERMES_HOME roots.NrÄ  z%Existing-gateway process probe failedTr`  )r›  Ú&_pid_record_belongs_to_current_profileznPID file belongs to another profile (hermes_home=%s). The old gateway may still be running under that profile.r   z	<unknown>z"A gateway is already running (PID z/), so your bots are most likely online already.z%  Check with `hermes gateway status`.zM  To restart it: `hermes gateway restart`. To stop it: `hermes gateway stop`.z:  To replace it from here: `hermes gateway run --replace`.)r®  rÛ   r¸  r²   r¨  r³  r›  rò  r©  r  r%   r9  rç  r"  )r-   r¸  rd   r›  rò  Ústales   &     r=   Ú(_guard_existing_gateway_process_conflictrô     så   € ÷ Ô3×5Ò5ÙðÝ2ÙÓˆð ‚{ð
	ß_Ù$Ó&ˆEØÒ Ñ)OÐPU×)VÒ)VÜ—‘ðOà—I‘I˜m¨[Ó9ôñ 	äÐ4°S°EÐ9hÐiÔjÜ	Ð
1Ô2Ü	Ð
YÔZÜ	Ð
FÔGÜ‡H‚HˆQ†Køô/ ô Ü�‰Ð<ÀtˆÔLÚðûô ô 	ØÙð	ús(   œB? ® C( Á&C( Â?"C%Ã$C%Ã(C7Ã6C7c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   C  s   € ÷ ñ ¨Tñ r@   c                 ó\  € \        \        R4      '       d@   \        P                  ! 4       ^ 8w  g&   \        \        P                  ! R4      4      '       d   R# \        4       '       g   R# \        R4       \        R4       \        R4       \        R4       \        P                  ! ^4       R# )zLRefuse gateway startup when the official Docker privilege drop was bypassed.r  ÚHERMES_ALLOW_ROOT_GATEWAYNzLRefusing to run the Hermes gateway as root inside the official Docker image.z¸  The image entrypoint normally drops privileges to the 'hermes' user. If you override entrypoint in Docker Compose, include /opt/hermes/docker/entrypoint.sh before the Hermes command.zy  Running the gateway as root can leave root-owned files in $HERMES_HOME and break later non-root dashboard/gateway runs.zM  Set HERMES_ALLOW_ROOT_GATEWAY=1 only if you intentionally accept this risk.)
rÅ   r½   r  rÜ  rÝ  r«  r%   r9  rç  r"  rT   r@   r=   Ú#_guard_official_docker_root_gatewayrø  C  s|   € ä”2�y×!Ò!¤R§Z¢Z£\°QÔ%6¼+ÄbÇiÂiÐPkÓFl×:mÒ:mÙÜ'×)Ò)ÙäÐ^Ô_Ü	ð	Fôô
 
ð	Hôô 
Ð
YÔZÜ‡H‚HˆQ†Kr@   c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   X  s   € ÷ ñ ¨ñ r@   c                 ó:  €  ^ RI Hp HpHpHpHp Rp ^ RIHp V! 4       ;'       g    / P                  R/ 4      ;'       g    / pV \        P                  9  d,   VP                  RR4      '       g   R\        P                  V &   VP                  R4      pV\        P                  9  d#   Ve   \        V4      \        P                  V&   RpT! 4       '       d
   T! 4        R	# T'       d   T! 4        T! 4        R	#   \         d     L;i ; i  \         d     R	# i ; i)
aŠ  Idempotent backstop arming of the startup-liveness watchdog. Must run AFTER the conflict guards (a
--replace loser must not arm one). config.yaml gateway.startup_watchdog* is the user surface; env
vars bridge it because the argv fast-path arms before config loads, and explicit env wins. arm() is
idempotent, so a config timeout needs disarm+re-arm. GatewayRunner disarms once the loop is live.)ÚENV_STARTUP_WATCHDOGÚENV_STARTUP_WATCHDOG_TIMEOUT_SÚarm_startup_watchdogÚdisarm_startup_watchdogÚstartup_watchdog_disabledF©Úload_configr  Ústartup_watchdogTr§  Ú startup_watchdog_timeout_secondsN)Úhermes_startup_watchdogrû  rü  rý  rþ  rÿ  Úhermes_cli.configr  r  r½   r—  rQ   r²   )	rû  rü  rý  rþ  rÿ  Ú_sw_timeout_bridgedÚ_sw_load_configÚ_gw_cfgÚ_sw_timeouts	            r=   Ú_apply_startup_watchdog_configr
  X  sô   € ð
÷	
õ 	
ð $Ðð
	ÝHÙ&Ó(×.Ð.¨B×3Ñ3°I¸rÓB×HÐHÀbˆGØ#¬2¯:©:Ô5¸g¿k¹kÐJ\Ð^b×>cÒ>cØ36”—
‘
Ð/Ñ0Ø!Ÿ+™+Ð&HÓIˆKØ-´R·Z±ZÔ?ÀKÒD[Ü=@ÀÓ=M”—
‘
Ð9Ñ:Ø&*Ð#ñ %×&Ò&Ù#Ö%ç"Ù'Ô)Ù Ö"øô ô 	Ùð	ûô ô ÚðúsX   ‚D “C: §C: Á/C: Á1AC: ÃD ÃD Ã"D Ã*D Ã:DÄD ÄDÄD ÄDÄDc                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   x  s   € ÷ ñ ¨$ñ r@   c                 ó´  €  \         P                   ! \         P                  \         P                  4       \        \         R4      '       d4   \         P                   ! \         P                  \         P                  4        ^ RIp T P                  P                  P                  R^4       R#   \
        \        3 d     L@i ; i  \
        \        3 d     R# i ; i)zTMake a detached Windows gateway ignore console-control broadcasts from sibling CLIs.ÚSIGBREAKN)rÆ   ÚSIGINTÚSIG_IGNrÅ   r  rÊ   r�   ré  rê  rë  ÚSetConsoleCtrlHandlerrí  rî  s    r=   Ú _absorb_windows_console_controlsr  x  s“   € ðÜ�Š”f—m‘m¤V§^¡^Ô4Ü”6˜:×&Ò&Ü�MŠMœ&Ÿ/™/¬6¯>©>Ô:ð
ÛØ�‰×Ñ×4Ñ4°T¸1Ö=øô ”ZÐ ô Ùðûô ”^Ð$ô Úðús$   ‚A<B+ Á?*C Â+B?Â>B?ÃCÃCc                 ó*   a€ ^ RI H oHp  R V3R llpV# )uÑ   ``_exit_diag(tag, **extra)`` recorder writing ``logs/gateway-exit-diag.log`` â€” captures every way
``asyncio.run()`` can return, for chasing silent Windows gateway deaths. HERMES_GATEWAY_EXIT_DIAG=0 opts out.©ÚdatetimeÚtimezonec                ó4   € V ^8„  d   QhR\         R\        RR/# )r7   ÚtagrV  r8   N)rQ   Úobject)r;   s   "r=   r>   Ú%_make_exit_diag.<locals>.__annotate__Ž  s!   € ÷ ñ œð ¤fð °ñ r@   c           
      óˆ  <€ \         P                  P                  R R4      R8w  d   R#  ^ RIHp V! 4       R,          pVP                  RRR7       RSP                  \        4      P                  4       RV R	\         P                  ! 4       R
\        P                  P                  4       ^ ,          R\        P                  /VCp\        VR,          RRR7      ;_uu_ 4       pVP                  \         P"                  ! V\$        R7      R,           4       RRR4       R#   + '       g   i     R# ; i  \&         d     R# i ; i)ÚHERMES_GATEWAY_EXIT_DIAGrô  N)r   ÚlogsTr  Útsr  rd   r—  rè  zgateway-exit-diag.logÚar,   r  rî  r|  )r½   r—  r  r4  r   r#  ÚnowrŠ  Ú	isoformatr¾   rç  Úversionr�   rè  rR  Úwriter  rR  rQ   r²   )r  rV  Ú_ghhÚlog_dirr    ÚfÚ_dts   &,    €r=   Ú
_exit_diagÚ#_make_exit_diag.<locals>._exit_diagŽ  sê   ø€ Ü�:‰:�>‰>Ð4°cÓ:¸cÔAÙð	Ý@Ù“f˜v•oˆGØ�M‰M $°ˆMÔ6à�c—g‘gœc“l×,Ñ,Ó.°°s¸EÄ2Ç9Â9Ã;Øœ#Ÿ+™+×+Ñ+Ó-¨aÕ0°*¼c¿l¹lðàNSðˆDô �gÐ 7Õ7¸Àw×OÕOÐSTØ—‘œŸ
š
 4´Ô5¸Õ<Ô=÷ P×O×OÒOûäô 	Úð	ús0   ªB7D2 Ã!3DÄD2 ÄD/	Ä)D2 Ä/D2 Ä2EÅ Er  )Ú_tzr'  r&  s     @r=   Ú_make_exit_diagr*  ‰  s   ø€ ÷ :÷ð ð  Ðr@   c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   ¡  s   € ÷ *Pñ *P ñ *Pr@   c                 óp  €  ^ RI Hp  ^pRp ^ RIHp V! 4       p\	        V\
        4      '       d   VP                  R4      MRp\	        V\
        4      '       d   VP                  R4      MRp\	        V\
        4      '       dl   \	        VP                  R4      \        4      '       d
   VR,          p\	        VP                  R4      \        \        34      '       d   \        VR,          4      p \        \        P                  R	,          4      p \        \        P                  R
,          4      pT^ 8”  d
   T ! YR7      MRpTes   \        P                  RTP                   TP"                  TP$                  4        ^ RIHp T! TP$                  R7       \*        P,                  ! TP$                  4       R# R#   \         d     LÙi ; i  \        \        3 d     LÏi ; i  \        \        3 d     LÅi ; i  \         d     Lpi ; i  \         d"   p	\        P/                  RT	4        Rp	?	R# Rp	?	ii ; i)zùPortable app-level respawn-storm breaker (for supervisors without a floor). Defaults mirror
DEFAULT_CONFIG ``gateway.respawn_storm``; HERMES_GATEWAY_MAX_STARTS / HERMES_GATEWAY_START_WINDOW_S
override; max_starts <= 0 disables. Never blocks startup.)Úrecord_start_and_check_stormg      ^@r   r  NÚrespawn_stormÚ
max_startsÚwindow_secondsÚHERMES_GATEWAY_MAX_STARTSÚHERMES_GATEWAY_START_WINDOW_S)r/  Úwindow_suU   Gateway (re)started %d times in %.0fs â€” backing off %.0fs to break a respawn storm.)Úkick_startup_watchdog)Úextra_sz2respawn-storm breaker check failed (non-fatal): %s)rÛ   r-  r  r  r¸  r<  r  rS   rf   r²   r½   r—  rÜ  r�   r¨  r©  Úcountr3  Ú	backoff_sr  r4  rÜ   rÞ   r³  )
r-  Ú_max_startsÚ_winr  Ú_cfgÚ_gwÚ_rsÚ_stormr4  Ú_bes
             r=   Ú_respawn_storm_backoffr?  ¡  sÕ  € ð&PÝ?ØˆØˆð	Ý5Ù“=ˆDÜ)3°D¼$×)?Ò)?�$—(‘(˜9Ô%ÀTˆCÜ.8¸¼d×.CÒ.C�#—'‘'˜/Ô*ÈˆCÜ˜#œt×$Ò$Ü˜cŸg™g lÓ3´S×9Ò9Ø"% lÕ"3�KÜ˜cŸg™gÐ&6Ó7¼#¼u¸×FÒFÜ  Ð%5Õ!6Ó7�Dð	ÜœbŸj™jÐ)DÕEÓFˆKð	ÜœŸ™Ð$CÕDÓEˆDð YdÐfgÔXgÑ-¸ÕTÐmqˆØÒÜ�N‰NØgØ—‘˜fŸo™o¨v×/?Ñ/?ôð
ÝIÙ%¨f×.>Ñ.>Õ?ô �JŠJ�v×'Ñ'Ö(ñ øô ô 	Ùð	ûô œ*Ð%ô 	Ùð	ûô œ*Ð%ô 	Ùð	ûô ô Ùðûô ô PÜ�‰ÐIÈ3×OÒOûðPúsœ   ‚
H	 �C F9 Ã. G
 Ä G! Ä/AH	 Å<G8 Æ H	 Æ9GÇH	 ÇGÇH	 Ç
GÇH	 ÇGÇH	 Ç!G5Ç2H	 Ç4G5Ç5H	 Ç8HÈH	 ÈHÈH	 È	H5ÈH0È0H5c          
      óT   € V ^8„  d   QhR\         R\        R\        R\        R\        /# )r7   ÚverboseÚquietr-   r5  Ú	idle_exitr»   )r;   s   "r=   r>   r>   Î  s8   € ÷ \)ñ \)œð \)¬ð \)Äð \)ÔUYð \)Üñ\)r@   c                óž  a€ \        4        \        W2R7       \        VR7       \        VR7       \        P
                  P                  ^ \        \        4      4       \        4        ^ RI
Hp V! R4       \        \        4       4      p\        4       p\        4       p\!        4       p	V	'       d   \#        4        \%        4       '       d0   \&        P(                  P+                  R4      '       d   \-        4        \/        4       '       d    \1        RR7       \5        4       '       d   ^ R	IHp
 V
! 4        ^ R
IHp \?        R4       \?        R4       \?        R4       \?        R4       \?        R4       \?        R4       \?        4        V'       d   RMT p^ RI p^ RI!p\E        4       oS! RV\        PF                  VV\5        4       W‰R7       VPI                  V3R l4       \K        4        R R lpRp \L        PN                  ! V! W#VVR7      4      pS! RVR7       T'       g   S! R!4       T! ^4       S! R"4       T! ^ 4       R#   \2         d     EL;i ; i  \P         d0    S! RTPS                  4       R7       \?        R4       T! ^ 4        R# \T         dr   pS! RTPV                  TPS                  4       R7       T! TPV                  f   ^ M-\Y        TPV                  \Z        4      '       d   TPV                  M^4        Rp?LëRp?i\\         d=   pS! R\_        T4      P`                  \c        T4      TPS                  4       R 7       h Rp?ii ; i)#a@  Run the gateway in foreground. verbose 1=INFO/2+=DEBUG on stderr; quiet: no stderr logs; replace:
kill an existing instance first (avoids systemd restart loops); force: skip the supervised guard;
idle_exit: a client auto-started this unsupervised gateway, so it exits once idle
(``gateway.unmanaged_idle_exit_seconds``).)r5  r-   r4  r6  )Úbegin_processr  ÚINVOCATION_IDFrc  )Úredact_detached_stdio)Ústart_gatewayu±   â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”�u@   â”‚           â˜¤ Hermes Gateway Starting...                 â”‚u±   â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤u@   â”‚  Messaging platforms + cron scheduler                    â”‚u?   â”‚  Press Ctrl+C to stop                                   â”‚u±   â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜Nzgateway.start)r-   r  Ústdin_is_ttyÚconsole_window_attachedr  Ú	breakawayÚabsorb_windows_console_controlsc                  óP   <€ S ! R \        \        P                  ! 4       4      R7      # )zatexit.hook)Úsys_exc)Úreprrç  ra  )r'  s   €r=   rÍ  Úrun_gateway.<locals>.<lambda>
  s   ø€ ™Z¨¼tÄCÇLÂLÃNÓ?SÕTr@   c                ó(   € V ^8„  d   QhR\         RR/# )r7   rê  r8   Nr©   )r;   s   "r=   r>   Ú!run_gateway.<locals>.__annotate__  s   € ÷ ,ñ ,´ð ,¸ñ ,r@   c                 ó"   € ^ RI Hp V! V 4       R# )rF  )Ú_exit_after_graceful_shutdownN)Úgateway.runrT  )rê  rT  s   & r=   Ú!_hard_exit_after_gateway_teardownÚ6run_gateway.<locals>._hard_exit_after_gateway_teardown  s   € õ 	>Ù% dÖ+r@   )r-   r5  Ú	verbosityrC  zasyncio.run.returned)Úsuccesszasyncio.run.KeyboardInterrupt)Ú	tracebackz
Gateway stopped.zasyncio.run.SystemExit)rê  rZ  zasyncio.run.exception)Úexc_typeÚexc_reprrZ  zgateway.exit_nonzerozgateway.exit_clean)2rø  rë  rï  rô  rç  rc   ÚinsertrQ   r	  r
  Ú/hermes_cli.observability.shared_metrics_processrE  r:   rã  rï  rõ  ræ  r  r9  r½   r—  r  r]  r…   ré  r²   rÞ  Úhermes_loggingrG  rU  rH  r9  ÚatexitrZ  r*  r  Úregisterr?  Úasynciorˆ   ÚKeyboardInterruptÚ
format_excÚ
SystemExitrê  r¸  rS   ÚBaseExceptionÚtyperU   rO  )rA  rB  r-   r5  rC  rE  rI  Ú_console_window_attachedÚ
_breakawayÚ_absorbrG  rH  rX  Ú_atexitÚ
_tracebackrV  rY  r¹  r'  s   &&&&&             @r=   Úrun_gatewayrm  Î  s£  ø€ ô (Ô)Ü$¨5ÕBÜ&¨UÕ3Ü,°WÕ=Ü‡H�H‡O�O�A”sœ<Ó(Ô)Ü"Ô$ÝMÙ�)Ôô œ›Ó(€LÜ?ÓAÐÜ1Ó3€JÜ=Ó?€GßÜ(Ô*ô ‡z‚z”b—j‘j—n‘n _×5Ò5Ü Ô"ô !×"Ò"ð	Ü*°%Õ8ô ×ÒÝ8ÙÔÝ)Ü	ð  ~ô  Ü	Ð
LÔMÜ	ð  ~ô  Ü	Ð
LÔMÜ	Ð
KÔLÜ	ð  ~ô  Ü	„G÷ ‘ 7€IãÛ"Ü Ó"€JÙØ ¬s¯x©xÀlØ 8ÔCXÓCZØõð
 ×ÑÔTÔUäÔõ,ð €GðÜ—+’+™m°GÐT]Ø6?ôAó BˆáÐ)°7Õ;÷ ÙÐ)Ô*Ù)¨!Ô,ÙÐ#Ô$Ù% aÖ(øôu ô 	Úð	ûôR ô áÐ2¸j×>SÑ>SÓ>UÕVÜÐ"Ô#Ù)¨!Ô,ÚÜô mÙÐ+°!·&±&ÀJ×DYÑDYÓD[Õ\Ù)¨q¯v©vª~©!ÌZÐXY×X^ÑX^Ô`c×MdÒMdÀ1Ç6Â6Ðjk×lÑlûÜô áÐ*´T¸!³W×5EÑ5EÔPTÐUVÓPWÐcm×cxÑcxÓczÕ{ØûðúsI   ÄI Ç.)I ÉIÉIÉ6MÊMÊMÊA'LÌMÌMÌ7MÍM)Ú
_PLATFORMSÚ_all_platformsÚ_platform_statusÚ&_set_platform_unauthorized_dm_behaviorÚprint_setup_headerÚconfirm_reconfigureÚoffer_home_channelÚsave_env_valuesÚ
prompt_csvÚ_UNAUTHORIZED_ACCESS_CHOICESÚ_prompt_unauthorized_accessÚ_telegram_auto_setupÚ_clean_discord_idsÚ_prompt_allowlist_varÚ_setup_standard_platformÚ_builtin_setup_fnÚ_configure_platformÚ_wizard_offer_service_actionÚ_setup_service_actionÚ_WIZARD_BANNERÚ_WIZARD_BACKEND_LABELSÚ_WIZARD_NO_SERVICE_LINESÚ_wizard_service_status_blockÚ_wizard_platform_loopÚ_wizard_install_serviceÚ_wizard_post_setupÚgateway_setupÚloop_liveness_watchdogz|event loop stopped dispatching (housekeeping, cron and the kanban dispatcher froze); the liveness watchdog exited with code z! for the supervisor to restart itÚshutdown_watchdogzeshutdown drain wedged; the shutdown watchdog forced the exit (see logs/gateway-shutdown-watchdog.log)c                ó:   € V ^8„  d   QhR\         \        ,          /# r6   rŒ  )r;   s   "r=   r>   r>   Z  s   € ÷ 8ñ 8œt¤C�yñ 8r@   c            
     óÜ  a€  ^ RI Hp HpHpHp T ! 4       pT'       g   . # TP                  R4      pTP                  R4      pTP                  R/ 4      ;'       g    / P                  4        UUu. uF>  w  rxTP                  R4      R8X  g   K  RT RTP                  R	4      ;'       g    R
 2NK@  	  p	ppTR#9   dn   T! T4      '       d`   T! T4      '       g   T	P                  RT R24       T	# T! T4      p
TR8w  d,   T
e(   T	P                  RT
 RTP                  R4       R24       TR8X  d   T'       d   T	P                  RT 24       T	# TR8X  d2   T'       d*   T	P                  R\        P                  Yf4       24       T	# TR8X  d£   TP                  R4      '       d   RMRp^ RI H
p T! TP                  R4      4      pT	P                  RT RT R24       TP                  R4      p\        T\        4      '       d*   T'       d"   ^ RIHo T	P                  T3R  lT 4       4       T	# TR!8X  d   T'       d   T	P                  R"T 24       T	#   \
         d    . u # i ; iu uppi )$z<Summarize the latest persisted gateway runtime health state.)r·  Úruntime_status_heartbeat_age_sÚruntime_status_is_staleÚruntime_status_pid_is_liverÇ  rÍ  rŸ  r¬  ÚfatalrË  rY  Úerror_messagezunknown errorrÈ  Údrainingu.   âš  Stale gateway_state.json: recorded state 'zB' but the recorded process is gone (likely an ungraceful shutdown)uS   âš  Gateway heartbeat stale: housekeeping has not refreshed gateway_state.json for z+ s (event loop or housekeeping wedged; pid rd   u    alive) â€” restart the gatewayrÌ  u   âš  Last startup issue: u   âš  Gateway exited degraded: rÿ  rH  Úshutdown)Úparse_active_agentsÚactive_agentsu   â�³ Gateway draining for z (z active agent(s))Úactive_work)Údescribe_active_work_unitc              3   ój   <"  € T F(  p\        V\        4      '       g   K  R S! V4       2x € K*  	  R# 5i)u	        â€¢ N)r¸  r<  )rÛ  Úur—  s   & €r=   rÜ  Ú(_runtime_health_lines.<locals>.<genexpr>Ž  s.   øé € ÐiÉTÈÔU_Ð`aÔcg×UhÔC˜9Ñ%>¸qÓ%AÐ$BÕCËTùs   ƒ3 3rØ  u   âš  Last shutdown reason: )rG   rÈ  r¿  r’  )rÛ   r·  r�  rŽ  r�  r²   r  rv  rG  Ú_WATCHDOG_EXIT_REASONSr”  r¸  r‚   rR  r—  r  )r·  r�  rŽ  r�  r¬  rÇ  rÍ  rè  Úpdatarg  r*  rÎ  r”  r6  Úworkr—  s                  @r=   Ú_runtime_health_linesrž  Z  st  ø€ ð÷	vó 	vñ
  Ó!€EßØˆ	à—I‘I˜oÓ.€MØ—)‘)˜MÓ*€Kð !&§	¡	¨+°rÓ :× @Ð @¸b×GÑGÔIôáI‰OˆHØ�9‰9�WÓ Ñ(ô 	Kˆ$ˆxˆj˜˜5Ÿ9™9 _Ó5×HÐH¸ÐIÓJÙIð 
ñ ð ÐGÔGÑLcÐdi×LjÒLjÙ)¨%×0Ò0Ø�L‰LØ@ÀÀð PKð Kôð ˆLñ -¨UÓ3ˆØ˜JÔ&¨3ª?Ø�L‰LØeÐfiÐejð k;Ø;@¿9¹9ÀUÓ;KÐ:LÐLkðmôð
 Ð(Ô(¯[Ø�‰Ð/°¨}Ð=Ô>ð" €Lð! 
˜*Ô	$¯ð 	�‰Ð4Ô5K×5OÑ5OÐP[Ó5iÐ4jÐkÔlð €Lð 
˜*Ô	$Ø#Ÿi™iÐ(;×<Ò<‘À*ˆÝ6Ù# E§I¡I¨oÓ$>Ó?ˆØ�‰Ð0°°¸¸5¸'ÐARÐSÔTØ�y‰y˜Ó'ˆÜ�dœD×!Ò!§dÝTØ�L‰LÔiÉTÓiÔið €Lð 
˜)Ô	#¯Ø�‰Ð1°+°Ð?Ô@à€Løôg ô ØŠ	ðüós#   ƒI Á/I(ÂI(Â*	I(ÉI%É$I%c                ó(   € V ^8„  d   QhR\         RR/# ©r7   rg  r8   Nr—  )r;   s   "r=   r>   r>   –  s   € ÷ ñ œcð  dñ r@   c                  ó.   € V  F  p\        V4       K  	  R # rB   )r"   ©rg  r    s   * r=   rÊ  rÊ  –  s   € ÛˆÜ�4Öó r@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   Ÿ  s   € ÷ ,ñ ,œ4ñ ,r@   c                  ó"   € ^ RI Hp  V ! 4       R8H  # )rF  ©r'  r)  )r-  r'  r¥  s    r=   Ú_running_under_s6r¦  Ÿ  s   € ÝAÙ!Ó# tÑ+Ð+r@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   ¤  s   € ÷ 'ñ '¤ñ 'r@   c                 óŽ   € \        4       '       g   R# \        ;QJ d    R R 4       F  '       g   K   R# 	  R# ! R R 4       4      # )zÝA unit at either scope that serves THIS home. A unit pinned to another install's home is not
ours, so stop/restart/start fall through to this home's own gateway (PID path) instead of
operating the other install's service.Fc              3   ó–   "  € T F?  p\        VR 7      P                  4       ;'       d    \        P                  ! V4      RJ x € KA  	  R# 5ir<  )rf  rg  r   r.  )rÛ  Úss   & r=   rÜ  Ú*_systemd_unit_installed.<locals>.<genexpr>ª  sC   é € ð 'Ù%�1ô %¨AÔ.×5Ñ5Ó7×vÐvÔ<Q×<kÒ<kÐlmÓ<nÐrvÐ<vÔvÛ%ùs
   ‚%A	¨!A	T©FT)r…   r/  rT   r@   r=   Ú_systemd_unit_installedr­  ¤  sK   € ô %×&Ò&Ùß‹3ñ 'Ù%ó'�3Œ3ð 'Š3ð 'ˆ3ñ 'Ù%ó'ó 'ð 'r@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   ®  s   € ÷ 1ñ 1œtñ 1r@   c                  ó   € \        4       R J# rB   )Ú_installed_service_kindrT   r@   r=   rÕ  rÕ  ®  s   € Ü"Ó$¨DÐ0Ð0r@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   ²  s   € ÷ 
(ñ 
(œTñ 
(r@   c                 óJ  € \        4       '       d   \        R4      ;'       g    \        R4      # \        4       '       d5   \        4       P	                  4       '       d    \        \        4       ^
R7      # \        \        4       4      ^ 8„  #   \        P                   d     R# i ; i)z2Check if the gateway service is currently running.FTr  )r…   rj  r“   r!  rg  r  r”   r‡   r‘   rš   r´  rT   r@   r=   Ú_is_service_runningr³  ²  sƒ   € ä ×"Ò"Ü& uÓ-×NÐNÔ1HÈÓ1NÐNÜ‡z‚zÔ,Ó.×5Ñ5×7Ò7ð	Ü.Ô/@Ó/BÈBÔOÐOô Ô Ó"Ó# aÑ'Ð'øô ×(Ñ(ô 	Úð	ús   ÁB	 Â	B"Â!B"c                ó(   € V ^8„  d   QhR\         RR/# )r7   r/   r8   Nr—  )r;   s   "r=   r>   r>   À  s   € ÷ ñ œ#ð ¨dñ r@   c                 óJ   € V P                  4        F  pV! R V 24       K  	  R# )rP  N)rŒ   )r/   Úemitr    s   && r=   Ú_print_indentedr·  À  s!   € Ø—‘Ö!ˆÙˆr�$�ˆ[Öó "r@   Úwindowsc                ó>   € V ^8„  d   QhR\         R\        R,          /# )r7   r¸  r8   Nr‘  )r;   s   "r=   r>   r>   Å  s   € ÷ 	ñ 	¤ð 	´°tµñ 	r@   c                ó‚   € \        4       '       d   R# \        4       '       d   R# V '       d   \        4       '       d   R# R# )z¹Host service manager: ``"systemd"`` / ``"launchd"`` / ``"windows"`` / None, in the canonical
predicate order every subcommand routes on. ``windows=False`` never probes ``is_windows()``.r,  r7  r¸  N)r…   r“   r³   ©r¸  s   $r=   Ú_service_backendr¼  Å  s)   € ô !×"Ò"ÙÜ‡z‚zÙß”:—<’<ÙÙr@   c                óN   € V ^8„  d   QhR\         R\         R\        R,          RR/# )r7   ÚbackendÚverbra  Nr8   rÖ  )r;   s   "r=   r>   r>   Ñ  s,   € ÷ 	9ñ 	9œ3ð 	9¤cð 	9´4¸$µ;ð 	9È4ñ 	9r@   c                óÒ   € V R8X  d   \        \        4       V4      ! 4       # V R8X  d   \        4       RV 2,          ! 4       # \        4       RV 2,          pVf   V! 4       # V! VR7      # )a  Run ``verb`` (start/stop/restart/uninstall) on ``backend``. Names resolve at call time so tests
can monkeypatch them; only systemd takes a scope, and ``system=None`` omits it (wizard restart).
Each systemd/launchd verb refuses a definition pinning another HERMES_HOME itself.r¸  r7  Úlaunchd_Úsystemd_rc  )rÉ  rÍ  Úglobals)r¾  r¿  ra  Úfns   &&& r=   Ú_service_callrÅ  Ñ  sf   € ð �)ÔÜ”{“} dÔ+Ó-Ð-Ø�)ÔÜ‹y˜8 D 6Ð*Ö+Ó-Ð-Ü	‹�X˜d˜VÐ$Õ	%€BØ’>‰2‹4Ð8¡r°Ô'8Ð8r@   c                óJ   € V ^8„  d   QhR\         R\         R,          R\        /# )r7   rÎ  rb   Nr8   rÖ  )r;   s   "r=   r>   r>   â  s&   € ÷ ñ ´ð ¼cÀD½jð ÔTXñ r@   c                ó¾  € ^ RI HpHpHpHp V! 4       R8w  d   R# Vf   \        4       pV! 4       pV R
9  d   R# RV 2p  \        W`4      ! V4       R	#   T d;    T R8w  g   T! Ya4      '       g   h \        RT: 24       TP                  T4        R	# i ; i  \        \        \        3 d0   p\        RT 24       \        P                  ! ^4        Rp?R	# Rp?ii ; i)z¾Dispatch start/stop/restart via s6 inside an s6 container; True iff dispatched (caller returns).
Profile defaults to the current one; missing slot / s6 errors become actionable CLI messages.)ÚGatewayNotRegisteredErrorr'  r(  Ú%register_unregistered_profile_gatewayr)  FNr  r*  u/   âœ“ registered the s6 gateway slot for profile r[  T)r  r´  rH  )r-  rÈ  r'  r(  rÉ  r.  rÉ  r9  r  rÀ  r�   rÊ   rç  r"  )	rÎ  rb   rÈ  r'  r(  rÉ  r1  rÌ  rÄ  s	   &&       r=   Ú#_dispatch_via_service_manager_if_s6rÊ  â  så   € ÷ó ñ
 Ó 4Ô'ÙØ‚Ü'Ó)ˆÙ
Ó
€CØÐ1Ô1ÙØ˜˜	Ð"€Gðð		Ü�CÔ  Ô)ñ øð )ô 	ð ˜Ô Ñ(MÈc×([Ò([ØÜÐCÀGÁ;ÐOÔPØ�I‰I�gÕñ ð	ûô œ*¤gÐ.ô Ü��S�EˆlÔÜ�Š��ˆÙûðús0   Á A Á=BÂB ÂBÂB ÂCÂ-$CÃCc                ó0   € V ^8„  d   QhR\         R\        /# )r7   rÎ  r8   rÖ  )r;   s   "r=   r>   r>     s   € ÷ ñ ´Cð ¼Dñ r@   c           	     ó4  € ^ RI HpHp V! 4       R8w  g   V R9  d   R# V! 4       pVP                  4       pV'       g   \	        R4       R# V R8X  d   VP
                  MVP                  p. pV F  p V! RV 24       K  	  \        V4      \        V4      ,
          p	V R8X  d   R	MR
p
V	'       d!   \	        RV
P                  4        RV	 R24       V F  w  rx\	        RV  RV RV 24       K  	  R#   \         d   pTP                  Yx34        Rp?K¥  Rp?ii ; i)a  Dispatch ``--all`` stop/restart to every registered profile gateway under s6; True iff dispatched.
A bare pkill is seen by s6-supervise as a crash and restarted ~1s later; the service manager flips
``want up``/``want down`` correctly. ``start --all`` is not a CLI surface.r&  r)  r´  Fu+   âœ— No profile gateways registered under s6Tr*  NrØ  Ú	restartedrÉ  rO  z profile gateway(s) under s6u   âœ— Could not z	 gateway-rY  )r´  rH  )r-  r'  r(  Úlist_profile_gatewaysr9  r´  rH  r²   rG  rš   rÓ  )rÎ  r'  r(  r1  rÂ  rÄ  r1   rb   rÄ  Ú	succeededr¿  s   &          r=   Ú'_dispatch_all_via_service_manager_if_s6rÐ    s  € ÷ YÙÓ 4Ô'¨6Ð9LÔ+LÙÙ
Ó
€CØ×(Ñ(Ó*€HßÜÐ;Ô<ÙØ˜vÔ%ˆ�Š¨3¯;©;€BØ*,€FÛˆð	*Ù�˜'˜Ð#Ö$ñ ô
 �H“¤ F£Õ+€IØ &Ô(‰9¨k€DßÜ��T—_‘_Ó&Ð' q¨¨Ð3OÐPÔQÛ‰ˆÜ�˜v˜h i°¨y¸¸3¸%Ð@ÖAñ áøô ô 	*Ø�M‰M˜7˜.×)Ò)ûð	*ús   Á1C/Ã/DÃ:DÄDc                ó2  €  \        V 4      #   \         dA   p\        R4       \        \	        T4      4       \
        P                  ! ^4        Rp?R# Rp?i\         d6   p\        \	        T4      4       \
        P                  ! ^4        Rp?R# Rp?i\        P                  \        3 dh   p^ RIHp T! T4      pTf   h \        T^ ,          4       \        RP                  TR,          4      4       \
        P                  ! ^4        Rp?R# Rp?ii ; i)zHandle gateway subcommands.zUser systemd not reachable:N)Úexplain_service_failurer|  :rà  NN)Ú_gateway_command_innerr3  r%   r·  rQ   rç  r"  r5  r9  r‡   rï  rÀ  r‡  rÒ  r“  )r
  r¹  rÒ  rg  s   &   r=   Úgateway_commandrÔ    s¼   € ðÜ% dÓ+Ð+øÜ&ô äÐ1Ô2Üœ˜A›ÔÜ�Š��ŠûÜ'ô äŒc�!‹fŒÜ�Š��ŠûÜ×)Ñ)¬<Ð8ô åMÙ'¨Ó*ˆØŠ=ØÜ�E˜!•HÔÜ˜Ÿ	™	 %¨¥)Ó,Ô-Ü�Š��Šûðús9   ‚
 �D˜5AÁDÁ DÁ!*BÂDÂ.DÂ/ADÄDc                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   7  s   € ÷ 5ñ 5´4ñ 5r@   c                ó  € \        V RR4      ;'       g2    \        P                  P                  RR4      P	                  4       R9   pV'       g&   \        P                  P                  R4      '       d   R# \        R4      '       g   R# ^ RIHp V! 4        \        R\        P                  R	R
7        \        P                  ! RRR.4       R	#   \         d+    \        R\        P                  R	R
7       \        4         R	# i ; i)uj  Inside an s6 container, upgrade bare ``gateway run`` to the supervised s6 longrun; True iff dispatched.
``HERMES_S6_SUPERVISED_CHILD`` (set by ``S6ServiceManager._render_run_script``) marks the supervised
child, which must run in foreground or we'd recurse run â†’ start â†’ run; ``--no-supervise`` /
HERMES_GATEWAY_NO_SUPERVISE=1 opts out (CI smoke, debugging).Úno_superviseFÚHERMES_GATEWAY_NO_SUPERVISEr   ÚHERMES_S6_SUPERVISED_CHILDr  )rþ  uo  â†’ gateway is now running under s6 supervision (auto-restart on crash,
  dashboard supervised alongside if HERMES_DASHBOARD is set).
  This is the recommended setup for the s6 container image â€” the
  gateway will keep running even if it crashes.
  Use `--no-supervise` (or HERMES_GATEWAY_NO_SUPERVISE=1) to opt out
  and get the pre-s6 foreground behavior instead.T)ÚfileÚflushrÞ   Úinfinityug   â†’ `sleep` is unavailable; keeping the s6 CMD process alive in-process until the container is stopped.)rô  rÿ  rþ  )rÉ  r½   r—  r  rm  rÊ  r  rþ  r9  rç  rM  ÚexecvprÊ   Ú_block_until_terminated)r
  r×  rþ  s   &  r=   Ú%_maybe_redirect_run_to_s6_supervisionrß  7  sã   € ô
 ˜4 °Ó7÷ Zð ZÜ
�
‰
�‰Ð4°bÓ9×?Ñ?ÓAÐEYÑYð ÷ ”r—z‘z—~‘~Ð&B×CÒCÙÜ.¨w×7Ò7Ùõ @áÔä	ð	<ô �Z‰ZØõ	ð"ô 	�	Š	�'˜G ZÐ0Ô1ñ øô ô "Üð9ä—‘Øõ		
ô 	 Õ!Ùð"ús   Â3C Ã1DÄDc                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   o  s   € ÷ !ñ ! ñ !r@   c                 óÔ   € \         P                   ! \         P                  R 4       \        \         RR4      p V e    V ! 4        K
  ^ RIpVP	                  4       P                  4        R# )uJ  Heartbeat when ``execvp("sleep")`` fails. SIGTERM exits 128+signum so ``docker stop`` is clean;
``Event().wait()`` covers platforms without ``signal.pause()``.

Fallback heartbeat for when ``os.execvp("sleep", ...)`` can't run (``sleep`` missing from PATH â€” issue
#36208). Installs a SIGTERM handler that exits with the conventional 128+signum code so ``docker stop``
produces a clean, expected exit, then blocks on ``signal.pause()``. Windows) â€” although this path only
runs inside the s6 Linux container image, the fallback keeps the helper safe to import and unit-test
anywhere.
c                 ó<   € \         P                  ! ^€V ,           4      # )é€   )rç  r"  )ÚsignumÚ_frames   &&r=   rÍ  Ú)_block_until_terminated.<locals>.<lambda>y  s   € ¼¿ºÀ#ÈÅ,Ô9Or@   ÚpauseN)rÆ   r�  rÉ  Ú	threadingÚEventÚwait)rç  rè  s     r=   rÞ  rÞ  o  sI   € ô ‡M‚M”&—.‘.Ñ"OÔPÜ”F˜G TÓ*€EØÒØÙŽGãØ�‰Ó×ÑÖ r@   c                ó2   € V ^8„  d   QhR\         R,          /# r›  r—  )r;   s   "r=   r>   r>   ƒ  s   € ÷ ,ñ ,¬C°$­Jñ ,r@   c                ó¨   € \        4       '       d   R# \        4       '       d!   \        4       P                  4       '       d   R# V ! 4       '       d   R# R# )z©``"systemd"`` / ``"launchd"`` when the unit/plist exists, else ``"windows"`` iff ``windows()``
(a thunk so it runs last, like every caller's original ladder), else None.r,  r7  r¸  N)r­  r“   r!  rg  r»  s   &r=   Ú_installed_service_kind_forrí  ƒ  s=   € ô × Ò ÙÜ‡z‚zÔ,Ó.×5Ñ5×7Ò7ÙÙŸ	š	ˆ9Ð+ tÐ+r@   c                ó2   € V ^8„  d   QhR\         R,          /# r›  r—  )r;   s   "r=   r>   r>   �  s   € ÷ ^ñ ^¤ t¥ñ ^r@   c                 ó   € \        R 4      # )zXInstalled service kind; stricter than ``_service_backend`` (unit/plist/task must exist).c                  óV   € \        4       ;'       d    \        4       P                  4       # rB   )r³   rÍ  Úis_installedrT   r@   r=   rÍ  Ú)_installed_service_kind.<locals>.<lambda>�  s   € ¬z«|×/\Ð/\ÄÃ×@ZÑ@ZÓ@\Ð/\r@   )rí  rT   r@   r=   r°  r°  �  s   € ä&Ñ'\Ó]Ð]r@   c                ó0   € V ^8„  d   QhR\         R\         /# r`  r9   )r;   s   "r=   r>   r>   ’  s   € ÷ 
ñ 
¤Dð 
¬Tñ 
r@   c                óž   € \        4       pVf   R#  \        VRV 4       R#   \        P                  .TR8X  d   \        3MRO5 d     R# i ; i)zTStop the installed systemd/launchd/Windows service. Returns True if one was stopped.Fr´  Tr¸  rT   )r°  rÅ  r‡   rï  rÀ  )ra  Úkinds   & r=   Ú_stop_installed_servicerö  ’  sR   € ä"Ó$€DØ‚|ÙðÜ�d˜F FÔ+ÙøÜ×)Ñ)Ð[ÀÈ	Ô@Q¬l©_ÐWYÑ[ô Úðús   ’! ¡%AÁAÁAc                ó4   € V ^8„  d   QhR\         R\         RR/# )r7   r¿  rÞ  r8   Nr—  )r;   s   "r=   r>   r>   Ÿ  s!   € ÷ 	ñ 	¤cð 	´3ð 	¸4ñ 	r@   c           	     ó†   € ^ RI Hp V! 4       '       d.   \        RV  RV RV  R24       \        P                  ! ^4       R# R# )zVRefuse self-targeting stop/restart/uninstall from inside the gateway process (#92560).)Ú_is_supervised_gateway_processzRefusing to zR the gateway from inside the gateway process.
This command was blocked to prevent z.
Use `hermes gateway z+` from a shell outside the running gateway.N)Útools.process_registryrù  r%   rç  r"  )r¿  rÞ  rù  s   && r=   Ú_refuse_from_inside_gatewayrû  Ÿ  sL   € åEÙ%×'Ò'ÜØ˜4˜&ð !3Ø39°(ð ;#Ø#' &Ð(SðUô	
ô
 	�Š�Žñ (r@   c                ó(   € V ^8„  d   QhR\         RR/# r   r—  )r;   s   "r=   r>   r>   «  s   € ÷ ñ œð  ñ r@   c                  ó.   € V  F  p\        V4       K  	  R # rB   )r9  r¢  s   * r=   Ú_print_linesrþ  «  s   € ÛˆÜˆdŽó r@   c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   °  s   € ÷ ñ ˜tñ r@   c                  ó†   € \        4       p V '       d/   \        4        \        R 4       V  F  p\        RV 24       K  	  R# R# )zRecent gateway health:rP  N)rž  r9  )Úruntime_linesr    s     r=   r^  r^  °  s8   € Ü)Ó+€MßÜŒÜÐ&Ô'Û!ˆDÜ�B�t�f�+Öó "ñ r@   c                 ó  € \        V 4      '       d   R # \        V RR4      '       d   R\        P                  \        &   \        \        V R^ 4      \        V RR4      \        V RR4      \        V RR4      \        V RR4      R	7       R # )
NÚexternal_supervisorFrô  rA  rB  r-   r5  rC  )rB  r-   r5  rC  )rß  rÉ  r½   r—  r   rm  r9  s   &r=   Ú_cmd_runr  ¹  sq   € Ü,¨T×2Ò2ÙÜˆtÐ*¨E×2Ò2Ø69Œ�
‰
Ô2Ñ3ÜÜ��i Ó#¬7°4¸À%Ó+HÜ˜˜i¨Ó/´w¸tÀWÈeÓ7TÜ˜$ ¨UÓ3÷r@   c                 ó   € \        4        R # rB   )rˆ  r9  s   &r=   Ú
_cmd_setupr  Å  ó   € Ü†Or@   r  ÚtermuxÚwslr3  r  z^To enable systemd: add systemd=true to /etc/wsl.conf and run 'wsl --shutdown' from PowerShell.c                ó4   € V ^8„  d   QhR\         R\         RR/# )r7   Ú
subcommandrÞ  r8   Nr—  )r;   s   "r=   r>   r>     s!   € ÷ ñ ¤ð ¬cð °dñ r@   c                 ón   € \         W3,          vr#\        V!   Ve   \        P                  ! V4       R # R # rB   )Ú_NO_BACKEND_MESSAGESrþ  rç  r"  )r  rÞ  rê  rg  s   &&  r=   Ú_no_backend_exitr    s/   € Ü'¨Ð(<Õ=€L€DÜ�%ÒØÒÜ�Š�Žñ r@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>     s   € ÷ >ñ >¤ñ >r@   c                 ó0   € ^ RI Hp Hp V! \        4      V 8H  # )a  True when this install is a sealed ``apt-termux`` tree.

A Termux APT package is a sealed tree owned by the package manager with
no service manager behind it. Keyed on the steward stamp
(``sealed_steward``), never a platform probe, so the refusal follows the
INSTALL PROVENANCE (our apt distribution's own stamp) rather than the
ambient environment; the platform-shaped ``is_termux()`` lanes stay
for generic on-device installs. Foreground process management (stop/
status via the PID registry) is NOT gated: it works on every install.
©ÚSTEWARD_APT_TERMUXÚsealed_steward)Úhermes_cli.stewardr  r  r	  r  s     r=   Ú_is_apt_termux_installr    s   € ÷ Fáœ,Ó'Ð+=Ñ=Ð=r@   c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>     s   € ÷ 3ñ 3œtñ 3r@   c                 ó:   € \        4       ;'       g    \        4       # )z¸Service lanes are unavailable: a Termux device (platform probe) or a
sealed apt-termux install (provenance probe). One predicate so a fourth
service gate cannot forget the disjunction.)r8  r  rT   r@   r=   Ú_service_mgmt_blockedr    s   € ô ‹;×2Ð2Ô0Ó2Ð2r@   c                ó@   € V ^8„  d   QhR\         R\        R\        RR/# )r7   r  r	  r)  r8   NrÖ  )r;   s   "r=   r>   r>   &  s(   € ÷ 
)ñ 
)¤3ð 
)´ð 
)¼$ð 
)À4ñ 
)r@   c               ó°   € V'       d   \        4       '       d   RpM/\        4       '       d   V'       d   \        4       '       d   RMRpMRp\        W4       R# )zÅFallthrough when no service backend matched. Predicate order: WSL (only when ``wsl``) ->
container (s6 slot hint only when ``s6``; ``start`` reaches here only when s6 isn't running) ->
unsupported.r	  r)  Ú	containerÚunsupportedN)r¸  r6  r¦  r  )r  r	  r)  rÞ  s   &$$ r=   Ú_handle_no_backendr  &  s8   € ÷ Œv�xŠxØ‰Ü	�ŠßÔ 1× 3Ò 3‘¸‰àˆÜ�ZÖ(r@   c                ó4   € V ^8„  d   QhR\         R\         RR/# )r7   r5  ra  r8   Nr9   )r;   s   "r=   r>   r>   3  s"   € ÷ %ñ %¬dð %¼Dð %ÐRVñ %r@   c                ó�  a a€ \        4       '       d"   \        R 4       \        RR4       \        4        \	        \
        P                  R4      ;'       d    \
        P                  P                  4       '       * oR V V3R llpV! RR4      pV! RR	4      p\        WVVS\        S R
R4      R7       V'       d   \        VR7       R# R# )u?   WSL detected â€” systemd services may not survive WSL restarts.z<  Consider running in foreground instead: hermes gateway runzM  Or use tmux/screen for persistence: tmux new -s hermes 'hermes gateway run'râ  c                ó<   € V ^8„  d   QhR\         R\         R\        /# )r7   rk   Úquestionr8   rÖ  )r;   s   "r=   r>   Ú/_install_systemd_from_cli.<locals>.__annotate__>  s&   € ÷ Nñ N”Cð N¤3ð N¬4ñ Nr@   c                 óV   <€ \        SV R 4      pVe   V# S'       g   \        VR4      # R# )NT)rÉ  r(   )rk   r!  r¡  r
  r  s   && €€r=   Ú_flagÚ(_install_systemd_from_cli.<locals>._flag>  s0   ø€ Ü˜˜d DÓ)ˆØÒØˆLß4CŒ}˜X tÓ,ÐMÈÐMr@   Ú	start_nowz3Start the gateway now after installing the service?Ústart_on_loginz;Start the gateway automatically on login/boot with systemd?r  F)r5  ra  rÓ  rõ  r  r  rc  N)r¸  r$   rÊ  r9  rÅ   rç  rá  râ  rø  rÉ  rA  )r
  r5  ra  rÓ  r$  r&  r'  r  s   f$$$   @r=   Ú_install_systemd_from_clir(  3  sª   ù€ Ü‡x‚xÜÐWÔXÜØJØ[ô	
ô 	Œä"¤3§9¡9¨hÓ7×NÐN¼C¿I¹I×<LÑ<LÓ<NÔO€O÷Nñ Nñ �kÐ#XÓY€IÙÐ+Ð-jÓk€NÜØ°Ø(¸/Ü Ð&7¸Ó?õ÷
 Ü˜V×$ñ r@   c           
      ó  € \        4       '       d   \        R 4       R# \        V RR4      '       d   \        4       '       d   \	        R4       R# \        V RR4      p\        VR7       \        V RR4      p\        V RR4      p\        4       '       d   \        R	R
4       \        4       pVR8X  d6   \        V4      '       d   \        P                  ! ^4       \        WW#R7       M‚VR8X  d(   \        V\        V RR4      RJ\        V RR4      R7       MTVR8X  d@   \        4       P                  V\        V RR4      \        V RR4      \        V RR4      R7       M\!        R	RRR7       Ve#   \        4       '       d   ^ RIHp V! R	4       R# R# R# )zinstall gateway serviceNÚ
if_missingFu%   âœ“ Gateway service already installedr5  r4  ra  rÓ  r  r  r,  )r5  ra  rÓ  r7  r&  r  )r&  r  r¸  r'  Úelevated_handoff)r5  r&  r'  r+  T©r	  r)  )Úrecord_service_choice)r   r   rÉ  rÕ  r9  rÜ  r  r  r¼  rË  rç  r"  r(  r}  rÍ  r  r  Ú hermes_cli.gateway_setup_servicer-  )r
  r5  ra  rÓ  r¾  r-  s   &     r=   Ú_cmd_installr/  O  sU  € Ü‡|‚|ÜÐ/Ô0ÙÜˆt�\ 5×)Ò)Ô.C×.EÒ.EÜÐ5Ô6ÙÜ�D˜' 5Ó)€Eä*°Õ7Ü�T˜8 UÓ+€FÜ˜$ ¨tÓ4€KÜ×ÒÜ˜ HÔ-ÜÓ €GØ�)ÔÜ/°×7Ò7Ü�HŠH�QŒKÜ! $¸FÖ\Ø	�IÔ	Ü˜¬°°{ÀDÓ)IÐQVÐ)VÜ(/°Ð6GÈÓ(Oö	Qà	�IÔ	Ü‹×ÑØÜ˜d K°Ó6Ü" 4Ð)9¸4Ó@Ü$ TÐ+=¸uÓEð	 	õ 	
ô 	˜9¨$°4Õ8ØÒÔ4×6Ò6ÝJÙ˜iÖ(ñ  7Ñr@   c                 ó   € \        R R4       \        4       '       d   \        R4       R# \        V RR4      p\	        4       '       d   \        R R4       \        4       pVe   \        VR V4       R# \        R RRR7       R# )	r3  z#the gateway from terminating itselfzuninstall gateway serviceNra  Fr  Tr,  )	rû  r   r   rÉ  r  r  r¼  rÅ  r  )r
  ra  r¾  s   &  r=   Ú_cmd_uninstallr1  s  sg   € Ü Ð-RÔSÜ‡|‚|ÜÐ1Ô2ÙÜ�T˜8 UÓ+€FÜ×ÒÜ˜ hÔ/ÜÓ €GØÒÜ�g˜{¨FÖ3ä˜;¨E°d×;r@   c                 óp   €  ^ RI Hp  V ! 4       #   \         d    \        P	                  RRR7        R# i ; i)a`  The live host gateway a ``--all`` verb must target instead of sweeping every profile.

``--all`` means "the ONE host multiplexer", not "every gateway process on this box": sweeping
killed a multiplexer serving N profiles and started a single gateway in its place, so a
per-profile command caused a host-wide outage and left exactly one profile served.
©Úhost_gatewayzHost gateway probe failedTr`  N)rµ  r4  r²   r¨  r³  r3  s    r=   Ú_host_multiplexer_for_all_verbr5  ‚  s5   € ðÝ4Ù‹~ÐøÜô Ü�‰Ð0¸4ˆÔ@Úðús   ‚ �"5´5c                ó$   € V ^8„  d   QhR\         /# r6   r9   )r;   s   "r=   r>   r>   ‘  s   € ÷ ñ ¬ñ r@   c                 óz   €  ^ RI HpHp \        V! V P                  V! 4       4      4      #   \
         d     R# i ; i)rF  rº  F)rÛ   r»  r¼  r:   rä   r²   )rŠ  r»  r¼  s   &  r=   Ú_host_multiplexer_is_oursr8  ‘  s7   € ðßNÜÑ% e§j¡jÑ2JÓ2LÓMÓNÐNøÜô Úðús   ‚(+ «:¹:c                ó   € V ^8„  d   QhRR/# r›  rT   )r;   s   "r=   r>   r>   ™  s   € ÷ 
]ñ 
]¨4ñ 
]r@   c           	     ó  €  \        RR7       Uu. uF  qV P                  8w  g   K  VNK  	  ppT'       g   R# \        R\	        T4       RRP                  R T 4       4       R24       \        R	4       R# u upi   \         d     R# i ; i)
z]Detect-and-converge: name the per-profile gateways `--all` no longer sweeps, never kill them.Tr±  NrP  z< per-profile gateway process(es) still run beside it (PIDs: rÙ  c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5irB   r—  )rÛ  r®  s   & r=   rÜ  Ú/_print_unfolded_gateway_note.<locals>.<genexpr>¢  s   é € Ð5©f¨œc !Ÿf˜f«fùrÞ  ru  zO  They were left running; fold them in with: hermes gateway migrate --multiplex)r´  rd   r²   r9  rš   r“  )rŠ  rd   Úotherss   &  r=   Ú_print_unfolded_gateway_noter>  ™  sŒ   € ðÜ!2ÀÕ!EÓZÑ!E˜#ÐPU×PYÑPYÑIY—#�#Ñ!EˆÐZ÷ ÙÜ	ˆBŒs�6‹{ˆmð Ø—I‘IÑ5©fÓ5Ó5Ð6°bð:ô ;ä	Ð
[Ö\ùò [øÜô Úðús&   ‚A< �A7§A7­A< Á7A< Á<BÂ
Bc                 ó  € ^ RI HpHp V! RV 4      '       d   R# \        V RR4      p\        V RR4      p\        V RR4      pV'       dV   V'       d   RM	\	        4       pVe5   \        RVP                  4        24       \        R	4       \        V4       R# V! V4      pM4\        VR
7       \        R4      '       d   R# \        P                  ! 4       pT;_uu_ 4        V'       d;   \        RR7      pV'       d'   \        RV R24       \        RRR7       \        4        \        4       '       d   \!        RR4       \#        4       p	V	e   \%        V	RV4       M\'        RRRR7       RRR4       R#   + '       g   i     R# ; i)rF  )Úhost_scope_for_all_verbÚprofile_lifecycler  Nra  FrØ  r5  u,   âœ“ The host gateway is already running â€” z>  One gateway per host serves every profile; nothing to start.r4  Tr±  u   âœ“ Killed z. stale gateway process(es) across all profilesr‹  r.  ©r|   r�  r  r,  )Ú$hermes_cli.gateway_profile_lifecycler@  rA  rÉ  r5  r9  r¶  r>  rÜ  rÊ  rö   Únullcontextrw  r’  r£  r  r  r¼  rÅ  r  )
r
  r@  rA  ra  Ú	start_allr5  rŠ  Ústart_scoperu  r¾  s
   &         r=   Ú
_cmd_startrG  ¦  s/  € ß_Ù˜ $×'Ò'ÙÜ�T˜8 UÓ+€FÜ˜˜e UÓ+€IÜ�D˜' 5Ó)€Eßß‘Ô#AÓ#CˆØÒô Ð@ÀÇÁÓAQÐ@RÐSÔTÜÐRÔSÜ(¨Ô/Ùñ .¨eÓ4‰ä.°UÕ;Ü.¨w×7Ò7ÙÜ ×,Ò,Ó.ˆç	ŠßÜ+¸Ô>ˆFßÜ˜ F 8Ð+YÐZÔ[Ü&¨tÀÕEÜ.Ô0Ü ×"Ò"Ü˜W hÔ/Ü"Ó$ˆØÒÜ˜' 7¨FÕ3ä˜w¨D°UÕ;÷ 
��Šús   ÃB	E/Å/F 	c                 óz  € \        R R4       ^ RIHpHpHp V! R V 4      '       d   R# \        V RR4      p\        V RR4      pV'       gÕ   \        4       '       gÅ   \        4       '       g   \        4       '       d¥   \        4       p\        R\        4        R24       Ve   \        R	VP                  4        24       \        R
4       \        4        Ve   RVP                   R2MRp\        RV R24       \        RV R24       \        P                  ! \         4       ^ RIHp V! R V 4       V'       d   \'        R 4      '       d   R# V'       g   \)        R 4      '       d   R# V'       dp   V! \+        4       4      ;_uu_ 4        \-        V4      p	RRR4       \/        RR7      X	'       d   ^M^ ,           p
V
'       d   \        RV
 R24       R# \        R4       R# \-        V4      '       d   \        R\1        4        R24       R# \3        4       '       d   \        R4       R# V! 4        R#   + '       g   i     L£; i)r´  úrestart loops)r@  rA  Úreport_profile_stop_failureNrØ  Fra  z!The host gateway serves profile 'u<   ' â€” there is no separate gateway for this profile to stop.rP  z+  Stop or restart the host gateway instead:z-p rO  r   z    hermes z6gateway stop      # takes every served profile offlinezgateway restart©Úrefuse_while_sessions_liveTr±  õ   âœ“ Stopped ú( gateway process(es) across all profilesu   âœ— No gateway processes foundrà  õ$   âœ“ Stopped gateway for this profile)rû  rC  r@  rA  rJ  rÉ  r´  r½  rl  r%   r.  r9  r¶  rÄ  rç  r"  r   Ú#hermes_cli.gateway_lifecycle_guardsrL  rÐ  rÊ  r5  rö  rw  r†   r´  )r
  r@  rA  rJ  Ústop_allra  rŠ  Ú
owner_flagrL  Úservice_availabler
  s   &          r=   Ú	_cmd_stoprT  Ð  sÐ  € Ü ¨Ô8ß|Ñ|Ù˜ ×&Ò&ÙÜ�t˜U EÓ*€HÜ�T˜8 UÓ+€FßÔ-×/Ò/Ü+×-Ò-Ô1\×1^Ò1^ä/Ó1ˆÜØ/Ô0EÓ0GÐ/Hð I0ð 1ô	
ð ÒÜ�B�u—~‘~Ó'Ð(Ð)Ô*ÜÐ;Ô<ÜŒØ5:Ò5F�s˜5×.Ñ.Ð/¨qÑ1ÈBˆ
Ü�˜J˜<Ð']Ð^Ô_Ü�˜J˜< Ð7Ô8Ü�ŠÔ/Ô0ÝNÙ˜v tÔ,çÔ;¸F×CÒCÙßÔ;¸F×CÒCÙçñ %Ô%CÓ%E×FÕFÜ 7¸Ó ?Ð÷ Gä&°DÔ9×BS¹QÐYZÕ[ˆßÜ�L  Ð'OÐPÔQñ 	ô Ð2Ô3ÙÜ˜v×&Ò&Ü�Ô-Ó/Ð0°Ð9Ö:Ü	×	Ò	ÜÐ4Ö5á#Ö%÷ G×Fús   ÆH*È*H:	c                ó$   € V ^8„  d   QhR\         /# r6   r©   )r;   s   "r=   r>   r>     s   € ÷ 	ñ 	¤Sñ 	r@   c                ó˜   € \        4       pV'       d   V#  \        V P                  RR7       ^#   \        \        \
        3 d     ^ # i ; i)zUSIGTERM the host gateway and nothing else; returns how many processes were signalled.Fr4  )rw  r   rd   rÈ   rÉ   rÊ   )rŠ  rØ  s   & r=   Ú_stop_host_multiplexerrW    sA   € ä$Ó&€GßØˆðÜ�e—i‘i uÕ-ÙøÜ¤´Ð9ô Úðús   –/ ¯A	ÁA	c                ó4   € V ^8„  d   QhR\         R\         RR/# ©r7   ra  Údetachr8   Nr9   )r;   s   "r=   r>   r>     s!   € ÷ 4ñ 4œð 4¤tð 4¸ñ 4r@   c                 ó¼  € ^ RI Hp \        4       pVe�   \        V4      '       g~   \	        RVP
                   R24       \        RVP                  4        24       \        R4       \        4        \        RVP
                   R24       \        P                  ! \        4       V! V4      ;_uu_ 4        \        W0V4       RRR4       R#   + '       g   i     R# ; i)	rF  )r@  Nz%The host gateway runs under profile 'rÐ  rP  zO  `--all` restarts the one host multiplexer, and this profile is not its owner.rÑ  z gateway restart --all)rC  r@  r5  r8  r%   rÄ  r9  r¶  rç  r"  r   Ú_restart_all_as_host)ra  rZ  r@  rŠ  s   &&  r=   Ú_restart_allr]    s«   € ÝLÜ*Ó,€EØÒÔ!:¸5×!AÒ!Aô 	Ð;¸E×<OÑ<OÐ;PÐPRÐSÔTÜ��5—>‘>Ó#Ð$Ð%Ô&ÜÐ_Ô`ÜŒÜ�˜u×2Ñ2Ð3Ð3IÐJÔKÜ�ŠÔ/Ô0ñ 
! ×	'Õ	'Ü˜U¨FÔ3÷ 
(×	'×	'Ò	'ús   Â3C
Ã
C	c                ó4   € V ^8„  d   QhR\         R\         RR/# rY  r9   )r;   s   "r=   r>   r>   !  s!   € ÷ *)ñ *)¬ð *)´dð *)Àtñ *)r@   c                 óð  € \        V4      pV eq   \        V 4      pYC'       d   ^M^ ,           pV'       d@   \        RV P                   RRP	                  V P
                  4      ;'       g    R R24       \        V 4       M4\        RR7      V'       d   ^M^ ,           pV'       d   \        RV R	24       \        R
RR7       \        4        \        4        \        4        \        R4       \        \        4      pVe   \        VRV4       R # ^ RIHpHp V'       g   V! V! 4       4      e?   \%        4       '       g"   \'        R4       \(        P*                  ! ^4       \        R4       R # \-        ^ RR7       R # )Nu"   âœ“ Stopped the host gateway (PID z	; serves rÙ  râ   rÊ  Tr±  rM  rN  r‹  r.  rB  úStarting gateway...r  )Úget_routing_process_hermes_homeÚnamed_profile_homez9Failed to start the host gateway as a background process.u4   âœ“ Started the host gateway as a background process)rA  r-   )rö  rW  r9  rd   r“  rÂ  r>  rw  r’  r£  r   r   rí  r³   rÅ  r4  ra  rb  rv  r%   rç  r"  rm  )	rŠ  ra  rZ  Úservice_stoppedrØ  r
  rõ  ra  rb  s	   &&&      r=   r\  r\  !  s*  € Ü-¨fÓ5€OØÒô )¨Ó/ˆØ¦™1°QÕ7ˆßÜÐ6°u·y±y°kÀØ—Y‘Y˜uŸ~™~Ó.×;Ð;°)Ð<¸Að?ô @ä$ UÕ+ä&°DÔ9Ç/¹QÐWXÕYˆßÜ�L  Ð'OÐPÔQÜ 4°SÕ9Ü"Ô$ô ÔäÔ ä	Ð
Ô ä&¤zÓ2€DØÒÜ�d˜G VÔ,ÙßTßÑ#Ñ$CÓ$EÓFÒRô
 '×(Ò(ÜÐSÔTÜ�HŠH�QŒKÜÐDÔEÙô ˜ 4×(r@   c           
      ó2  € \        R R4       ^ RIHp V! R V 4      '       d   R# \        V RR4      p\        V RR4      p\        V RR4      pV'       g   \	        VR7       ^ R	IHp V! R V 4       V'       d   \        R 4      '       d   R# V'       g   \        R 4      '       d   R# V'       d   \        V\        V R
R4      4       R#  \        4        \        \        4      pVRJ;'       d&    VR8g  ;'       g    \!        4       P#                  4       pVe&   VR8X  d   \$        \&        3MRp	 \)        VR V4       R# VR8X  dL   \/        4       '       d<   \1        4       w  r«V
RJd*   ^ RIp\5        RRRRRVP7                  4        2RRR4       R# V'       d%   \5        RRRR4       \8        P:                  ! ^4       ^ RIHp ^ RI H!pH"pH#pH$p V! 4       pV'       d   V! V4      '       d   V! V4       R# V! V4       \K        4       '       d   \M        R4       \O        RRR7       \Q        4        \S        4        \M        R4       V! WR7       R#   \         d"   p\        P                  RT4        Rp?EL¡Rp?ii ; i  \*        P,                  .T	O5 d     EL\i ; i) rH  rI  )rA  Nra  FrØ  r5  r4  rK  rZ  z-orphan reap before gateway restart failed: %sr¸  r,  Tr   uB   âš  Cannot restart gateway as a service â€” linger is not enabled.zK  The gateway user service requires linger to function on headless servers.z$  Run:  sudo loginctl enable-linger rí  rî  u#   âœ— Gateway service restart failed.zL  The service definition exists, but the service manager did not recover it.z3  Fix the service, then retry: hermes gateway startrÄ  )Ú$gateway_declares_external_supervisorÚ)refuse_restart_of_service_managed_gatewayÚ%restart_externally_supervised_gatewayÚstart_restart_replacementrO  r‹  r.  rB  r`  rT   )*rû  rC  rA  rÉ  rÜ  rP  rL  rÐ  rÊ  r]  r–  r²   r¨  r³  rí  r³   rÍ  rñ  rÀ  rÊ   rÅ  r‡   rï  r…   rx  rv  rþ  rw  rç  r"  rÛ   r¸  Ú%hermes_cli.gateway_supervised_restartre  rf  rg  rh  r´  r9  r’  r£  r   )r
  rA  ra  Úrestart_allr5  rL  rÄ  rõ  Úservice_configuredÚswallowÚ	linger_okÚ_detailrv  r¸  re  rf  rg  rh  Úsupervised_pids   &                  r=   Ú_cmd_restartrp  N  sI  € Ü 	¨?Ô;ÝFÙ˜ D×)Ò)ÙÜ�T˜8 UÓ+€FÜ˜$  uÓ-€KÜ�D˜' 5Ó)€E÷ Ü.°UÕ;ÝNÙ˜y¨$Ô/ßÔ>¸y×IÒIÙßÔ>¸y×IÒIÙßÜ�VœW T¨8°UÓ;Ô<ÙðKÜ*Ô,ô
 '¤zÓ2€DØ TÐ)×aÐa¨t°yÑ/@×/`Ð/`ÄKÃM×D^ÑD^ÓD`ÐØÒØ-1°YÔ->”<¤Ñ)ÀBˆð	Ü˜$ 	¨6Ô2Ùð ˆyÔÔ6×8Ò8Ü6Ó8Ñˆ	Ø˜DÓ ÛÜØÐXØ]Ð_aØ6°w·±Ó7HÐ6IÐJÈBØ-Ð/Kô	ñ çÜØÐ5ØZØAô	
ô
 	�Š�Œõ
 /÷ó ñ %Ó&€NßÑ>¸~×NÒNÙ-¨nÔ=ÙÙ-¨nÔ=ä×ÒÜÐ4Ô5Ü 4°SÕ9Ü"Ô$ÜÔ Ü	Ð
Ô Ù˜d×0øôs ô KÜ�‰ÐDÀc×JÒJûðKûô ×-Ñ-Ð8°Ñ8ô 	Úð	ús*   Ã
I
 Ä*I9 É
I6ÉI1É1I6É9JÊJÚotherc                ó$   € V ^8„  d   QhR\         /# r6   r—  )r;   s   "r=   r>   r>   Ã  s   € ÷ 2ñ 2œ3ñ 2r@   c                  ór   € \        4       '       d   R # \        4       '       d   R# \        4       '       d   R# R# )r  r	  r¸  rq  )r8  r¸  r³   rT   r@   r=   Ú_status_host_kindrt  Ã  s'   € Ü‡{‚{ÙÜ‡x‚xÙÜ"Ÿšˆ9Ð1¨'Ð1r@   c           	      ód  a€ ^ RI Hp ^ RIHpHp \        V RR4      p\        V RR4      p\        V RR4      p\        VR7      pV! 4       '       d   VP                  '       g   R# ^ R	IH	pH
p	 V! 4       ;'       g    R
R
8g  ;'       d    V	! \        4       4      p
V
'       d    ^ RIHp \        R4       \        RV 24       \        4       ;'       d    \!        4       P#                  4       oV
'       g[   VP                  '       gI   \%        4       '       d9   \        R4       \        R4       \'        V! 4       4       \)        V! 4       4       EMÊ\+        V3R l4      ;pel   VR8X  d   \-        WFVR7       M-VR8X  d   \/        V4       M\!        4       P1                  VR7       \3        V4       V! R4       \5        4        \'        4        EML\7        VP8                  4      pV'       d   V! V4      '       d   EMV'       d}   \        RRP;                  \=        \>        V4      4       R24       \        R4       \A        4        \5        4        \'        4        \        4        \C        \D        \G        4       ,          !   M›VPH                  '       d9   \        RVPJ                   R24       \A        4        \5        4        \'        4        MQ\        R4       \A        4        \        4        \        R4       \        R4       \C        \L        \G        4       ,          !   \O        4        \Q        4        V! 4        R# )rF  )Úprint_parked_status)Úprint_standalone_by_configÚreport_incompatible_ownerrX  FrY  ra  rc  N)r^  rÈ  rl  rÓ  uP   standalone by config (gateway.standalone: true) â€” temporary compatibility shimrP  u:   âœ“ Gateway is running via the default-profile multiplexerz;  Manage it from the default profile: hermes gateway statusc                  ó   <€ S # rB   rT   )Ú_windows_service_installeds   €r=   rÍ  Ú_cmd_status.<locals>.<lambda>å  s   ø€ Ñ6Pr@   r,  )ra  rY  r7  )rX  u   âœ“ Gateway is running (PID: rÙ  rÊ  z-  (Running manually, not as a system service)u&   âœ“ Gateway is running (supervised by u   âœ— Gateway is not runningz	To start:z-  hermes gateway run      # Run in foregroundrT   ))rC  rv  Úhermes_cli.gateway_status_notesrw  rx  rÉ  r;  rG   r¿  r^  rÈ  r   rI  rÔ  r9  r³   rÍ  rñ  rl  rU  r[  rí  rc  r‰  r×  rE  rJ  r‚   rD   r“  rˆ  rQ   r^  rþ  Ú_STATUS_RUNNING_HINTSrt  rC   rO   Ú_STATUS_STOPPED_HINTSrh  rb  )r
  rv  rw  rx  rX  rY  ra  r:  r^  rÈ  Úactive_standalonerÔ  rõ  rœ   rz  s   &             @r=   Ú_cmd_statusr€  Ë  s`  ø€ ÝHßeÜ�4˜ Ó'€DÜ�4˜ Ó'€DÜ�T˜8 UÓ+€FÜ+°6Ô:€Hñ ×Ò X×%5×%5Ð%5ÙßRá1Ó3×@Ð@°yÀYÑN÷ Fð FÙ2´?Ó3DÓEð çÝSÜÐ`ÔaÜ�Ð0Ð1Ð2Ô3Ü!+£×!NÐ!N´+³-×2LÑ2LÓ2NÐß X×%5×%5Ð%5Ô:e×:gÒ:gäÐJÔKÜÐKÔLÜ"Ñ#:Ó#<Ô=Ü&Ñ'>Ó'@ÖAÜ-Ô.PÓQÐ
Qˆ$Ò	^Ø�9ÔÜ˜4°TÖ:Ø�YÔÜ˜4Õ ä‹M× Ñ  dÐ Ô+Ü'¨Ô1Ù! "Ô%Ü*Ô,Ü"Ö$ä�H×)Ñ)Ó*ˆßÑ-¨d×3Ò3ÙßÜÐ1°$·)±)¼CÄÀT»NÓ2KÐ1LÈAÐNÔOÜÐAÔBÜ!Ô#Ü.Ô0Ü&Ô(ÜŒGÜÔ/Ô0AÓ0CÕDÓEØ×%×%Ð%ô Ð:¸8×;KÑ;KÐ:LÈAÐNÔOÜ!Ô#Ü.Ô0Ü&Õ(äÐ.Ô/Ü!Ô#ÜŒGÜ�+ÔÜÐAÔBÜÔ/Ô0AÓ0CÕDÒEä(Ô*Ü(Ô*ÙÖ r@   c                 ó   € \        4        R # rB   )ro  r9  s   &r=   Ú	_cmd_listr‚    r  r@   c                ó¸   € \        V RR4      p\        V RR4      p\        4       '       g   \        4       '       g   \        R4       R# \	        V'       * VR7       R# )zQStop, disable, and remove legacy Hermes gateway unit files (e.g. hermes.service).r®  Frþ  z@Legacy unit migration only applies to systemd-based Linux hosts.N)r­  r®  )rÉ  r…   r“   r9  rÄ  )r
  r®  rþ  s   &  r=   Ú_cmd_migrate_legacyr„    sE   € ä�d˜I uÓ-€GÜ
�$˜˜uÓ
%€CÜ$×&Ò&¬x¯zªzÜÐPÔQÙÜ¨s¬7¸G×Dr@   c                 ó"   € ^ RI Hp V! V 4       R# )rF  )Úcmd_migrateN)rf  r†  )r
  r†  s   & r=   Ú_cmd_migrater‡    s   € Ý6Ù�Ör@   rˆ   Úsetupr´  rH  r×  r‚   zmigrate-legacyÚmigratec                 ób   € \         P                  \        V R R4      4      pVe   V! V 4       R# R# )rÔ  N)Ú_GATEWAY_SUBCOMMANDSr  rÉ  )r
  Úhandlers   & r=   rÓ  rÓ  *  s.   € Ü"×&Ñ&¤w¨tÐ5FÈÓ'MÓN€GØÒÙ�Žñ r@   c                óL   € V ^8„  d   QhR\         R,          R\         R,          /# rK  r   )r;   s   "r=   r>   r>   0  s"   € ÷ +ñ +¤t¨d¥{ð +¼dÀT½kñ +r@   c                ó|   € V e   \        V 4      M\        p^ RIHp V! V4      pVP	                  4       '       d   V# R# )u„  The venv pm provisioned for this install, resolved through
``runtime_paths.selected_venv`` â€” the committed-environment contract â€”
never from interpreter state.

Under no-boot-through-venv the gateway runs the store python with the
venv's site-packages on PYTHONPATH, so ``sys.prefix`` always equals
``sys.base_prefix`` and ``VIRTUAL_ENV`` is unset in bundled installs;
prefix/env probing silently degrades. Resolution follows the committed-
environment contract: a committed selection is returned as-is, a host
with nothing committed yields nothing launchable, and a malformed
selection raises â€” fail closed, never a silently wrong venv.
N)Úselected_venv)r   r	  Úpm.environmentsr�  r/  )rL  rØ  r�  Úvenvs   &   r=   Ú_pm_runtime_venv_dirr’  0  s7   € ð ".Ò!9Œ4�Ô¼|€DÝ-á˜Ó€DØ—;‘;—=’=ˆ4Ð* dÐ*r@   c                óÒ   € V ^8„  d   Qh/ ^ \         9   d   \        \        R3,          ;R&   ^\         9   d   \        \        R3,          ;R&   ^\         9   d   \        R,          ;R&   # )r7   .r�  rž  NÚ_resolved_launchd_domain)Ú__conditional_annotations__rR   rQ   )r;   s   "r=   r>   r>      sf   € ÷ ñ ÷LP =Ò <”uœS #˜X•Ñ <ñMP÷RPò ¤¤c¨3 h¥ñ ñSP÷L| ,Ò +œ# �*Ñ +òM|r@   >   r�  rœ  r›  rš  r‡  )rÑ   )FFr÷  rB   )F)rÂ  rÃ  rí  r  r¦  r  )FNF>   ÚReadyÚQueuedÚRunningr  )rr  )r.  )zhermes.service)zhermes_cli.main gatewayzhermes_cli/main.py gatewayzgateway/run.pyz hermes gateway z/hermes gateway )TFr¬  )rT   )ÚRestartMaxDelaySecÚRestartSteps)FFNTFF)FFF)r‹  r.  )rF  FFFF)r   zE  hermes gateway run                              # direct foregroundúG  tmux new -s hermes 'hermes gateway run'         # persistent via tmuxúL  nohup hermes gateway run > ~/.hermes/logs/gateway.log 2>&1 &  # background)r  r  )rà  z8Gateway service installation is not supported on Termux.úRun manually: hermes gateway)r  r	  )rà  z(WSL detected but systemd is not running.zIEither enable systemd (add systemd=true to /etc/wsl.conf and restart WSL)z&or run the gateway in foreground mode:)r  r)  )NzCPer-profile gateways are auto-registered when you create a profile.r   z@  hermes profile create <name>     # creates the s6 service slotz7  hermes -p <name> gateway start   # bring it up via s6zF  hermes status                    # see currently-supervised gateways)r  r  )rF  z=Service installation is not needed inside a Docker container.uV   The container runtime is your service manager â€” use Docker restart policies instead:r   zJ  docker run --restart unless-stopped ...   # auto-restart on crash/rebootz<  docker restart <container>                # manual restartr   z&To run the gateway: hermes gateway run)r  r  )rà  z4Service installation not supported on this platform.z Run manually: hermes gateway run)r3  r  )rà  zcGateway service uninstall is not supported on Termux because there is no managed service to remove.z*Stop manual runs with: hermes gateway stop)r3  r)  )NzGPer-profile gateways are auto-unregistered when you delete the profile.r   zC  hermes profile delete <name>     # tears down the s6 service slotzF  hermes -p <name> gateway stop    # stop without deleting the profile)r3  r  )rF  z>Service uninstall is not applicable inside a Docker container.z2To stop the gateway, stop or remove the container:r   z  docker stop <container>z  docker rm <container>)r3  r  )rà  z™Running the gateway as a background service is not available on this platform (no systemd, launchd or Scheduled Tasks), so there is nothing to uninstall.z9Stop a manually started gateway with: hermes gateway stop)r  r  )rà  z\Gateway service start is not supported on Termux because there is no system service manager.r�  )r  r	  )rà  z*WSL detected but systemd is not available.z+Run the gateway in foreground mode instead:)r  r  )rF  z:Service start is not applicable inside a Docker container.z1The gateway runs as the container's main process.r   z:  docker start <container>     # start a stopped containerz<  docker restart <container>   # restart a running containerr   z/Or run the gateway directly: hermes gateway run)r  r  )rà  zwRunning the gateway as a background service is not available on this platform (no systemd, launchd or Scheduled Tasks).z(Run it directly with: hermes gateway run)zTermux note:z;  Android may stop background jobs when Termux is suspended)z	WSL note:zI  The gateway is running in foreground/manual mode (recommended for WSL).z<  Use tmux or screen for persistence across terminal closes.)z=To install as a Windows Scheduled Task (auto-start on login):ú  hermes gateway install)zTo install as a service:rž  z&  sudo hermes gateway install --system)z^  nohup hermes gateway run > ~/.hermes/logs/gateway.log 2>&1 &  # Best-effort background start)r›  rœ  )zS  hermes gateway install  # Install as Windows Scheduled Task (auto-start on login))z3  hermes gateway install  # Install as user servicezM  sudo hermes gateway install --system  # Install as boot-time system service(¼  r•  rt   rb  rö   Úhermes_cli.cli_outputr   Úhermes_cli.gateway_host_recordr   r   r  Úloggingr½   r´   rÆ   rë   r   r‡   rç  rP  rÜ   Údataclassesr   Úpathlibr   rÌ  r   r	   rk   Ú	_sys_dirsrw   r—  r  r�   ÚpathsepÚ
_path_dirsÚ_missingr“  r—   Ú__file__r@  r  r	  r�  r   r   rÛ   r   Úgateway.restartr   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r    Úhermes_cli.setupr!   r"   r#   r$   r%   r&   r'   r(   Úhermes_cli.colorsr)   r*   rC  r+   r²  Ú	getLoggerrU   r¨  r<  r‰   r4   r_   ri   r¦   r¸   rÀ   rË   rÕ   rÓ   r!  r"  r  r  r  r   rí   rê   r  r  r,  r:  rA  rH  rY  r�  r†  r„  rƒ  r‡  r´  rÅ  rÎ  r   r  r  r  r  r  rS  r9  rC  r  rj  ro  ry  r~  r‰  rŽ  r“  rš  rž  r¢  rª  r®  r³  r¹  r½  rá  rÔ  rÕ  rô  r÷  rÖ  r  r  r  r  r  r˜   r#  r3  r;  r@  rE  rJ  rU  r[  rb  rh  ro  rw  rz  r{  r–  rŒ  rª  Ú_ORPHAN_EXIT_POLL_SECONDSr�  rŽ  r«  r²  r´  r9  r4  r6  r8  r¸  r¼  r»  r…   r“   r³   rÍ  rr   rØ  rÔ  r‹  rÞ  rã  ræ  rï  rõ  r	  r¡  r  rü  r  r  r‚  r  r.  r�  r†   r  rf  rÀ  r3  r5  r@  rE  rI  rN  rT  rW  r]  rb  re  rk  rn  r}  ry  rƒ  rh  rÒ  r�  r“  r�  rž  r–  r¡  r¤  r«  rÄ  rÇ  rË  rÑ  rã  rç  rë  ró  rú  rx  r!  r–   r  r!  r)  r-  r2  r8  r<  rA  rI  rW  rZ  re  rq  r{  r�  r‘  r´  r»  r¿  rÂ  rÈ  rÓ  rÚ  ré  rî  ró  rö  rm  rû  rþ  rž  r  rŸ  r  rø  r+  r/  r4  r8  r*  rA  rE  rL  rI  rJ  rc  Úhermes_cli.gateway_launchdr”   rd  re  rf  rg  rh  ri  rj  rk  rl  rm  rn  ro  r"  rp  rq  rr  rs  rC  rt  ru  rv  rw  rx  ry  rz  r{  r|  r}  r~  r  r€  r�  r‚  rƒ  r„  r…  r†  r‡  rˆ  r‰  r  rŠ  r”  r’  r˜  r£  rÜ  r«  r®  r·  r½  rl  rÍ  rÌ  rÜ  rá  rë  rï  rô  rø  r
  r  r*  r?  rm  Úhermes_cli.gateway_setup_wizardrn  ro  rp  rq  rr  rs  rt  ru  rv  rw  rx  ry  rz  r{  r|  r}  r~  r  r€  r�  r‚  rƒ  r„  r…  r†  r‡  rˆ  r›  rž  rÊ  r¦  r­  rÕ  r³  r9  r·  r¼  rÅ  rÊ  rÐ  rÔ  rß  rÞ  rí  r°  rö  rû  rþ  r^  r  r  Ú_WSL_FOREGROUND_HINTr  r  r  r  r  r(  r/  r1  r5  r8  r>  rG  rT  rW  r]  r\  rp  r}  r~  rt  r€  r‚  r„  r‡  r‹  rÓ  r’  r>   )r•  s   @r=   Ú<module>r±     sâ  øð÷ð ó
 Û Ý ,ß `Û Û Û 	Û Û Û Û Û Û 
Û Û Ý !Ý ß =ð ‡7�7ˆgÔÛ:€IÙ�R—Z‘Z—^‘^ F¨BÓ/×5Ñ5°b·j±jÓAÓB€JØ˜:Õ%€HßØŸZ™ZŸ^™^¨F°BÓ7¸"¿*¹*ÕDÀrÇzÁzÇÁÑW]Ð^fÓWgÓGhÕhˆ�
‰
�6Ñá�H‹~×$Ñ$×+Ñ+×3Ñ3Ó5€ç OÝ (÷÷ ÷ ÷÷ ñ ÷	÷ 	ó 	÷ ,Ý XØ	×	Ò	˜8Ó	$€ñ  D¨t¸gÈiÔX€ñ �$Ô÷Tð Tó ðTñ  �$Ô÷ð ó ðñ �$Ô÷
%ð 
%ó ð
%÷Yð Yõx2õ8õðUÐQU÷ Uð(À÷ ðv Ð ØÐ Ø Ð ð '+Ð #ñ “HÐ ÷	Gð 	Gõ÷ 	Uð 	UðØ58ðØIJðØ[^ðà÷ð>K Ø&IðK Ø_cðK àðK à34ðK àJM÷K ð\?¸cð ?ÐVY÷ ?õ.õ$õ
0÷"cð cõLõ
õ!VõH.÷&ð ò($ÐV[÷ $ð $õNJði3Øði3ØSW÷i3õX/õõ2÷,qð qõ
ð %(Ð !ðõ,õ^ðBÐ]að BÐvz÷ BõJ-÷Eð Eõ
\õ
	Yõõ&=÷
Mð Mõ
.÷6ð 6õ$õ;õ;÷
Vð Võ6õIðKàðKð  $ðKð !ð	Kð
 /3÷K÷\
$ð 
$õeõn÷Xð X÷Rð R÷ð õ@õõGð$"¸a÷ "õõkõ
÷8%Wð %WðPÐST÷ õNõ$÷ð õ"kõ õ 	%õ!#÷H!ð !ðH !#Ð õò<aØ<?÷að aõH(ðZ "Ð ØÐ ðØ#ðØ6PðØb{÷ð$B¨T÷ Bõ  Yõ=õ@,÷ =Ñ <õ-÷
`ð `õõ$õ#òñ #,Ó,JÓ"KÐ õ(õV
Wõ=õõõõ]ð !€ØMÐ áÐ-Ó.Ð õ	õõö<O÷
F÷8I÷	/ò 	/÷D÷%÷$7ò 7öb ,ô bö
1 <ô 1÷Q÷
'÷
7÷
÷ ÷q÷M÷&(ò (÷
"ò 
"÷m÷
Sñ
9¸$÷ 9ñ 9÷x+÷ @ò @ð4°e÷ 4ñ 4÷*ò *÷÷3ñ
 *=Ð Ó <ñ3Ð ó ÷H÷
÷0-÷
4÷=ò =÷@
=÷÷4p÷
`ò `÷0÷÷÷ ò ÷<'Eò 'E÷T?÷$/÷ &ò &÷RE÷Q÷#÷L	÷/÷bð b÷
\ó \÷#ð #÷ó ÷,
ð 
÷0ó 0÷$ð ÷$'ó '÷BSð Sð*°ñ *ÐQU÷ *ò *÷@bó b÷JJð Jñ
  FÑ ÷ð ÷ð ÷-ó -÷$ó ÷%ó %òPÐ]b÷ ó ò$-È%÷ -ó -÷`Jð J÷,xó x÷0ó 0÷	0ð 	0÷,ð ,÷	ð 	÷oð o÷ð ÷\ ó \ ñ~Ø<@ñØY^÷ò ÷ ó ÷*Ró R÷ >ð >÷ó ÷Nó N÷Nó N÷ %Gó %G÷P.ð .÷bPð P÷*J9ó J9÷d*÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *÷ *ñ *÷V Ñ ð (,Ñ Ó +÷ó ð@Ád÷ ò ð,±t÷ ò ÷4Jð J÷hð h÷+ð +÷ó ÷6ó ÷&0ó 0÷fð ÷.Kó K÷\-ó -÷&*ð *÷$!8ó !8÷H$ó $÷N ó  ÷Fð ÷*ð ÷@ð ô"÷0*Pð *P÷Z\)ó \)÷F÷ ÷ ÷ ÷ ÷ ÷ ÷ ÷ ÷ ÷ ÷ ÷ ÷ ñ ñB ñ	2Ø2SÐ1TÑTuð	wñ ñ  AðÑ ÷8ð 8÷xð ÷,ð ,÷
'ð '÷1ð 1÷
(ð 
(ñ %*÷ ò ñ
	¨÷ 	ò 	÷	9ó 	9÷"ó ÷Bð ô8÷05ð 5÷p!ð !÷(,ð ,÷^ð ^÷

ð 
÷	ð 	÷ð ÷
ð ô	ôñÑ ñ ñ dáó Iñ 4HñIñ ñ Rñ
 ñ 2ñ ñ !dáñ 6ñ ñ Rñ ñ !@ñ !ñ #Eñ ñ (ñ ó já8LðjàNPðjñ 	iñjñ ñ ;ñ ñ 4ða4Ñ ÷nð ÷>ð >÷ 3ð 3÷
)ð 
)÷%ð %ô8!)ôH<ô÷ð ÷
]ð 
]ô'<ôT/&÷d	ð 	÷4ó 4÷&*)ó *)ôZV1ñv Ñ]Ù	ñ ñ ÑlÙñ ð
Ñ ñ ñ ñ 
ñ ñ ÑgÙñ ðÑ ÷ 2ð 2ôB!ôJôEôð 	‰(‘E™8¡W©j¹)Á\Ù‘¡©*±f¹iÉÑT`Ù‰k™6¡9Ñ.>Ñ@SÑU^Ñ`lðÑ ô÷+õ +r@   