
    `gj                        d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZ defdZdefdZdefd	Zd
efdZd
efdZd Zd Zd'dZded
efdZd Zded
ee   fdZded
ee   fdZd
ee   fdZded
ee   fdZd
efdZded
efdZd Zd(dZ d Z!d Z"dededed
dfdZ#dededed ed!ed
dfd"Z$ G d# d$      Z%d)d
e&fd%Z'e(d&k(  r ejR                   e'              yy)*z
Hermes Agent Uninstaller.

Provides options for:
- Full uninstall: Remove everything including configs and data
- Keep data: Remove code but keep ~/.hermes/ (configs, sessions, logs)
    N)Path)get_hermes_home)Colorscolormsgc                 T    t        t        dt        j                         d|         y )Nu   → )printr   r   CYANr   s    G/root/.hermes/venv/lib/python3.12/site-packages/hermes_cli/uninstall.pylog_infor      s!    	U5&++&'q
./    c                 T    t        t        dt        j                         d|         y )Nu   ✓r	   )r
   r   r   GREENr   s    r   log_successr      s!    	U5&,,'(#
/0r   c                 T    t        t        dt        j                         d|         y )Nu   ⚠r	   )r
   r   r   YELLOWr   s    r   log_warnr      s!    	U5&--()3%
01r   returnc                  d    t        t              j                  j                  j                         S )z'Get the project installation directory.)r   __file__parentresolve r   r   get_project_rootr      s!    >  ''//11r   c                      t        j                         } g }| dz  | dz  | dz  | dz  | dz  g}|D ]$  }|j                         s|j                  |       & |S )z<Find shell configuration files that might have PATH entries.z.bashrcz.bash_profilez.profilez.zshrcz	.zprofile)r   homeexistsappend)r   configs
candidatesconfigs       r   find_shell_configsr$   !   so    99;DG 	yzx{J  #==?NN6"# Nr   c                  @   t               } g }| D ]  }	 |j                         }|}g }d}|j                  d      D ]d  }d|v sd|v rd}|rd|j                         v rd|v rd})d}d|j                         v rd|v sd	|j                         v rT|j	                  |       f dj                  |      }d
|v r|j                  d
d      }d
|v r||k7  r"|j                  |       |j	                  |        |S # t        $ r}	t        d| d|	        Y d}	~		d}	~	ww xY w)z:Remove Hermes PATH entries from shell configuration files.F
z# Hermes Agentz# hermes-agentThermesPATHzPATH=zpath=z


z

zCould not update : N)
r$   	read_textsplitlowerr    joinreplace
write_text	Exceptionr   )
r!   removed_fromconfig_pathcontentoriginal_content	new_lines	skip_nextlinenew_contentes
             r   remove_path_from_shell_configsr:   5   s]    "GL $=#	=!++-G& IId+ '#t+/?4/G $I(djjl":v~ %I!	 tzz|+DGtzz|D[  &'  ))I.K k))11(FC k) ..&&{3##K0C$=L   	=(Rs;<<	=s   B9C8'C88	DDDc                  L   t        j                         dz  dz  dz  t        d      g} g }| D ]M  }|j                         s	 |j                         }d|v sd|v r!|j	                          |j                  |       O |S # t        $ r}t        d| d|        Y d	}~qd	}~ww xY w)
z.Remove the hermes wrapper script if it exists..localbinr'   z/usr/local/bin/hermes
hermes_clihermes-agentCould not remove r)   N)r   r   r   r*   unlinkr    r0   r   )wrapper_pathsremovedwrapperr3   r9   s        r   remove_wrapper_scriptrE   c   s     			h&1$%M
 G  	=>>=!++-7*n.GNN$NN7+	= N  =,WIRs;<<=s   9A??	B#BB#c                     t        j                         dz  dz  g} t        j                  dk(  r| j	                  t        d             t
        j                  j                  dd      }|r!d|v r| j	                  t        |      dz         | S )zFDirectories where the installer may have placed node/npm/npx symlinks.r<   r=   linuxz/usr/local/binPREFIX z
com.termux)r   r   sysplatformr    osenvironget)dirsprefixs     r   _node_symlink_candidate_dirsrQ   y   sp    		h.67D
||wD)*+ZZ^^Hb)F,&(DL5()Kr   hermes_homec           	         | dz  j                         }g }dD ]  }t               D ]  }||z  }	 |j                         st        t	        j
                  |            }|j                         s|j                  |z  }|j                         }||k(  s||j                  v r!|j                          |j                  |         |S # t        $ r}t        d| d|        Y d}~d}~ww xY w)u'  Remove the node/npm/npx symlinks the installer placed on PATH.

    The POSIX installer (``scripts/install.sh`` / ``scripts/lib/node-bootstrap.sh``)
    symlinks node/npm/npx into the same directory as the ``hermes`` command:

    - ``/usr/local/bin/`` on root FHS installs (Linux, uid 0)
    - ``$PREFIX/bin/`` on Termux
    - ``~/.local/bin/`` otherwise (the common non-root case)

    We check all candidate directories so that uninstall works regardless of
    how the install was done (e.g. a root FHS install that placed links in
    ``/usr/local/bin``, or an older install that used ``~/.local/bin`` before
    the FHS fix).  Only symlinks that resolve into this Hermes home's ``node``
    directory are removed — links the user has repointed elsewhere (nvm, fnm,
    etc.) are left untouched.
    node)rT   npmnpxr@   r)   N)r   rQ   
is_symlinkr   rL   readlinkis_absoluter   parentsrA   r    r0   r   )rR   node_dirrC   namebin_dirlinktargetr9   s           r   remove_node_symlinksr`      s    " f$--/HG& :35 	:GT>D:(
 bkk$/0))+"kkF2F)X%V^^)CKKMNN4(#	::, N  :,TF"QC899:s   CBC	C*C%%C*c                     ddl } d}	 ddlm}m}  |       }|r |       }|rt	        d| d       d}| j                         }t        j                  d	d
      }t        t        j                  d      xs d|v       }	|	r|S |dk(  r	 ddlm}
m}m}  |       }dD ]  } |
|      }|j                         s|rdnd}	 |r't        j                         dk7  rt        d| d       M ||      }t!        j"                  |d|gz   dd       t!        j"                  |d|gz   dd       |j%                          t!        j"                  |dgz   dd       t	        d| d| d       d} 	 |S |dk(  re	 dd lm}  |       }|j                         rEt!        j"                  d!d"t)        |      gdd       |j%                          t	        d#| d       d}|S |d%k(  rk	 dd&lm} |j/                         s |j1                         s|j3                         r1	 |j5                          	 |j7                          t	        d(       d}|S 	 |S |S # t
        $ r}t        d|        Y d}~4d}~ww xY w# t
        $ r}t        d| d|        Y d}~d}~ww xY w# t
        $ r}t        d|        Y d}~|S d}~ww xY w# t
        $ r}t        d$|        Y d}~|S d}~ww xY w# t
        $ r}t        d'|        Y d}~d}~ww xY w# t
        $ r}t        d)|        Y d}~|S d}~ww xY w# t
        $ r}t        d*|        Y d}~|S d}~ww xY w)+a  Stop and uninstall the gateway service (systemd, launchd, Windows
    Scheduled Task / Startup folder) and kill any standalone gateway processes.

    Delegates to the gateway module which handles:
    - Linux: user + system systemd services (with proper DBUS env setup)
    - macOS: launchd plists
    - Windows: Scheduled Task + Startup-folder fallback, via ``gateway_windows``
    - All platforms: standalone ``hermes gateway run`` processes
    - Termux/Android: skips systemd (no systemd on Android), still kills standalone processes
    r   NF)kill_gateway_processesfind_gateway_pidszKilled z running gateway process(es)Tz'Could not check for gateway processes: rH   rI   TERMUX_VERSIONzcom.termux/files/usrLinux)get_systemd_unit_pathget_service_name_systemctl_cmd)FT)systemri   userz!System gateway service exists at z but needs sudo to removestop)capture_outputcheckdisablezdaemon-reloadRemoved z gateway service ()r@   z gateway service: z*Could not check systemd gateway services: Darwin)get_launchd_plist_path	launchctlunloadzRemoved macOS gateway service (z*Could not remove launchd gateway service: Windows)gateway_windowsz(Could not stop Windows gateway cleanly: z8Removed Windows gateway (Scheduled Task + Startup entry)z+Could not fully uninstall Windows gateway: z)Could not check Windows gateway service: )rK   hermes_cli.gatewayrb   rc   r   r0   r   ri   rL   getenvboolrf   rg   rh   r   geteuid
subprocessrunrA   rr   strr>   rv   is_installedis_task_registeredis_startup_entry_installedrk   	uninstall)rK   stopped_somethingrb   rc   pidskilledr9   ri   rP   	is_termuxrf   rg   rh   svc_name	is_system	unit_pathscopecmdrr   
plist_pathrv   s                        r   uninstall_gateway_servicer      s    	@P "+-FgfX-IJK$(! __F YYx$FRYY/0T4Jf4TUI   !	G 
 ()H* O	1C	 '')$-6O RZZ\Q%6 #DYK P< "= > (3CNN3&();#;26eENN3)X)>#>26eE$$&NN3/):#:26eE(5'1CI;a PQ(,%+O@ I 
8	
	GA/1J  "Xs:G.2%A!!#=j\KL$(!6 % 
9		F2++-1S1S1U&AACM#((*P#--/ Z[(,%  D k  @:1#>??@V ! O07I!MNNO 	GA!EFFN Q	G  	GA!EFF2 5	G ! MGsKLLM ! PJ1#NOO P 	F@DEE	Fs   +I
 6J >(I/&J 'BI/)J 4A"J< 6L* K! &L 
	I,I''I,/	J8J	J JJ 	J9 J44J9<	KKK!	L*K=8L* =LL* 	L'L"L* "L''L* *	M3MMc                 ^    t        |       j                  d      }|dz   |dz   |dz   |dz   g}|S )zCPath-entry substrings that identify Hermes-owned User-PATH entries.\/z\hermes-agentz\gitz\nodez\venv)r}   rstrip)rR   rootmarkerss      r   _hermes_path_markersr   B  sA    {""5)D &&wxPXYG
 Nr   c                    	 ddl }g }d}	 |j                  |j                  |d|j                  |j
                  z        5 }	 |j                  |d      \  }}|j                  d      D cg c]  }|s|	 }}t        |       }	g }
|D ]L  }|j                  d      t        fd|	D              }|r|j                  |       <|
j                  |       N |r&dj                  |
      }|j                  |dd||       ddd       |S # t        $ r g cY S w xY w# t        $ r g cY cddd       S w xY wc c}w # 1 sw Y   |S xY w# t        $ r}t!        d|        Y d}~|S d}~ww xY w)	zStrip Hermes-owned entries from User-scope PATH in the registry.

    Returns the list of removed path entries.  Operates on HKCU\Environment,
    same key the installer wrote to via ``[Environment]::SetEnvironmentVariable``.
    r   NEnvironmentr   ;r   c              3   x   K   | ]1  }j                         j                  |j                                3 y wN)r,   
startswith).0m
entry_norms     r   	<genexpr>z4remove_path_from_windows_registry.<locals>.<genexpr>i  s+     X1j..0;;AGGIFXs   7:z&Could not edit User PATH in registry: )winregImportErrorOpenKeyHKEY_CURRENT_USERKEY_READ	KEY_WRITEQueryValueExFileNotFoundErrorr+   r   r   anyr    r-   
SetValueExOSErrorr   )rR   r   rC   key_pathkey
path_value	path_typer9   entriesr   keptentrymatched	new_valuer   s                 @r   !remove_path_from_windows_registryr   O  s    GH?^^F44h"OOf.>.>>@ 	HCF(.(;(;C(H%
I #-"2"23"7=Q1q=G=*;7G D  '"\\%0
XPWXXNN5)KK&' HHTN	!!#vq)YG'	H, N9  	 % 		H 	H >	H, N  ?9!=>>N?s   D	 5E D9DD9+D43D47BD9?E 	DDD1%D9&	E 0D11D99E>E E 	E(E##E(c            	         	 ddl } g }	 | j                  | j                  dd| j                  | j
                  z        5 }dD ]9  }	 | j                  ||       	 | j                  ||       |j                  |       ; 	 ddd       |S # t        $ r g cY S w xY w# t        $ r Y cw xY w# t        $ r}t        d| d|        Y d}~d}~ww xY w# 1 sw Y   |S xY w# t        $ r}t        d|        Y d}~|S d}~ww xY w)zEDelete HERMES_HOME and HERMES_GIT_BASH_PATH from User-scope env vars.r   Nr   )HERMES_HOMEHERMES_GIT_BASH_PATHzCould not delete z from User env: z%Could not open User Environment key: )r   r   r   r   r   r   r   r   DeleteValuer    r   r   )r   rC   r   r\   r9   s        r   remove_hermes_env_vars_windowsr   v  s,    G>^^F44mQ"OOf.>.>>@ 	LCF? 	L''T2L&&sD1NN4(	L	L N'  	 ) 
  L06FqcJKKL	L N  >8<==N>s   B 5C CB#B(;C>C BB	B%"C$B%%C(	C1CCCCCC C 	C>%C99C>c                     g }dD ]A  }| |z  }|j                         s	 t        j                  |d       |j                  |       C |S # t        $ r}t        d| d|        Y d}~ed}~ww xY w)zDelete PortableGit and Node installs the Windows installer created under
    ``%LOCALAPPDATA%\hermes\``.  Only called on full uninstall; they're
    isolated from any system Git / Node so they cannot break other tools.)gitrT   zgateway-serviceF)ignore_errorsr@   r)   N)r   shutilrmtreer    r0   r   )rR   rC   subr_   r9   s        r   remove_portable_tooling_windowsr     s|     G1 <s"==?<fE:v&< N  <,VHBqc:;;<s   (A	A/A**A/c                  (    dd l } | j                  dk(  S )Nr   win32)rJ   rK   )rJ   s    r   _is_windowsr     s    <<7""r   c                 z    	 ddl m} | j                          |       j                         k(  S # t        $ r Y yw xY w)zJReturn True when ``hermes_home`` points at the default (non-profile) root.r   )get_default_hermes_rootF)hermes_constantsr   r   r0   )rR   r   s     r   _is_default_hermes_homer     s=    <""$(?(A(I(I(KKK s   +. 	::c                      	 ddl m}  	  |        D cg c]  }t        |dd      r| c}S # t        $ r g cY S w xY wc c}w # t        $ r}t	        d|        g cY d}~S d}~ww xY w)zReturn a list of ``ProfileInfo`` for every non-default profile, or ``[]``
    if profile support is unavailable or nothing is installed beyond the
    default root.r   )list_profiles
is_defaultFzCould not enumerate profiles: N)hermes_cli.profilesr   r0   getattrr   )r   pr9   s      r   _discover_named_profilesr     sm    5(?Ra'!\52QRR  	 S 1!56	s;   , 	A ==A ::A 	A%A A% A%c           
         ddl }| j                  }| j                  }t        d| d       |j                  ddd|g}dD ]"  }	 t        j                  |d	|gz   d
d
dd       $ t        | dd      }|r/|j                         r	 |j                          t        d|        	 |j                         r$t        j                  |       t        d|        yy# t
        j                  $ r t        d| d| d       Y t        $ r}t        d| d| d|        Y d}~d}~ww xY w# t        $ r}t        d| d|        Y d}~d}~ww xY w# t        $ r}t        d| d|        Y d}~yd}~ww xY w)aZ  Fully uninstall a single named profile: stop its gateway service,
    remove its alias wrapper, and wipe its HERMES_HOME directory.

    We shell out to ``hermes -p <name> gateway stop|uninstall`` because
    service names, unit paths, and plist paths are all derived from the
    current HERMES_HOME and can't be easily switched in-process.
    r   NzUninstalling profile 'z'...z-mzhermes_cli.mainz	--profile)rk   r   gatewayT<   F)rl   texttimeoutrm   z
  Gateway z timed out for ''z  Could not run gateway z for 'z': 
alias_pathz  Removed alias z  Could not remove alias r)   z
  Removed z  Could not remove )rJ   r\   pathr   
executabler{   r|   TimeoutExpiredr   r0   r   r   rA   r   r   r   )profile_sysr\   profile_homehermes_invocationsubcmdr9   r   s           r   _uninstall_profiler     s    <<D<<L%dV401
 $0A;PTU' L	LNN!Y$77#L ,5Jj'')	D*:,78
< MM,'*\N34 !! (( 	Cz&)9$qAB 	L/xvdV3qcJKK	L  	D0BqcBCC	D  <&|nBqc:;;<sN   CD( #3E %D%?D%D  D%(	E1EE	E3E..E3c                 h   ddl m}m}m} t	               } ||      }t        t        | dd            }t                t        t        dt        j                  t        j                               t        t        dt        j                  t        j                               t        t        dt        j                  t        j                               t                |d   st        d	       t        d
| d       yt        t        dt        j                               t                t        t        dt        j                  t        j                               |d   D ]  }t        d|         |d   D ]  }t        d|         |d   rt        d|d    d       t                 ||      r[t        t        dt        j                  t        j                               t        d|dz          t        d|        t                |s_	 t        dt        dt        j                         d      j!                         j#                         }|dk7  rt                t        d       yt                t        t        dt        j                  t        j                               t                 ||       t                t        t        dt        j                  t        j                               t        t        dt        j                  t        j                               t        t        dt        j                  t        j                               t                t        d       t        d        t                y# t$        t&        f$ r t                t        d       Y yw xY w)!uR  GUI-only uninstall: remove the Chat GUI, leave the agent + data intact.

    Mirrors ``hermes uninstall --gui``. Removes the desktop app's built
    artifacts, the packaged app bundle (best-effort), and the Electron
    userData dir — nothing under ``$HERMES_HOME`` config/sessions/.env, and
    never the Python agent or its venv.
    r   )agent_is_installedgui_install_summaryuninstall_guiyesF   ┌─────────────────────────────────────────────────────────┐u@   │         ⚕ Hermes Chat GUI Uninstaller                  │   └─────────────────────────────────────────────────────────┘gui_installedz*No Hermes Chat GUI installation was found.z  Checked: z-, and the standard app locations for this OS.NzAThis removes the Chat GUI only. The Hermes agent stays installed.zWill remove:source_built_artifacts     • packaged_app_pathsuserdata_existsuserdata_dirz  (desktop app data)zKept intact:u     • The Hermes agent at r?   u/     • Your config, sessions, and secrets under Type 'z' to remove the Chat GUI: 
Cancelled.Uninstall cancelled.zUninstalling Chat GUI...uA   │            ✓ Chat GUI Uninstalled!                      │zAThe Hermes agent is still installed. Run 'hermes' to use the CLI,z.or 'hermes uninstall' to remove the agent too.)hermes_cli.gui_uninstallr   r   r   r   ry   r   r
   r   r   MAGENTABOLDr   r   r   inputstripr,   KeyboardInterruptEOFError)	argsr   r   r   rR   summaryskip_confirmr   confirms	            r   run_gui_uninstallr     s\     "#K!+.GeU34L	G	%  D  FL  FT  FT  V\  Va  Va  b  c	%RTZTbTbdjdodo
pq	%  D  FL  FT  FT  V\  Va  Va  b  c	G?#:;K=(UVW	%SU[U`U`
ab	G	%v{{
;<-. qcl)* qcl !w~.//CDE	G+&eNFLL&++>?*;+G*HIJ?}MN	fU5&--%@$AA[\]ccekkmG
 eG()	G	%*FKK
EF	G+	G	%  D  FL  FR  FR  TZ  T_  T_  `  a	%SU[UaUacicncn
op	%  D  FL  FR  FR  TZ  T_  T_  `  a	G	
MN	
:;	G+ "8, 	G,	s   AN
 
$N10N1c                 (   t               }t               }t        t        | dd            r#t	        ||t        t        | dd                   yt        |      }|r
t               ng }t        t        | dd            }|r't        t        | dd            }t        |||d|       yt                t        t        dt        j                  t        j                               t        t        d	t        j                  t        j                               t        t        d
t        j                  t        j                               t                t        t        dt        j                  t        j                               t        d|        t        d|dz          t        d|dz          t        d|dz   d|dz   d|dz          t                |r{t        t        dt        j                  t        j                               |D ]:  }t        |dd      rdnd}t        d|j                   | d|j                          < t                t        t        dt        j                   t        j                               t                t        dt        dt        j"                        z   dz          t        d        t                t        d!t        d"t        j$                        z   d#z          t        d$       t                t        d%t        d&t        j                        z   d'z          t                	 t'        t        d(t        j                              j)                         }	|	d*k(  s|	j/                         d+v rt                t        d,       y|	d-k(  }d}
|r|rt                t        t        d.t        j                                t        d/t1        |       d0dj3                  d1 |D              z          t                	 t'        t        d2t1        |       d3t        j                              j)                         j/                         }|d4v }
t                |rt        t        d5t        j$                  t        j                               t        t        d6t        j$                               |
rUt        t        d7t1        |       d8dj3                  d9 |D              z   t        j$                               nt        d:       t                	 t'        d;t        dt        j                          d<      j)                         j/                         }|dk7  rt                t        d,       yt        ||||
|       y# t*        t,        f$ r t                t        d)       Y yw xY w# t*        t,        f$ r t                t        d)       Y yw xY w# t*        t,        f$ r t                t        d)       Y yw xY w)=z
    Run the uninstall process.
    
    Options:
    - Full uninstall: removes code + ~/.hermes/ (configs, data, logs)
    - Keep data: removes code but keeps ~/.hermes/ for future reinstall
    dry_runFfull)project_rootrR   full_uninstallNr   )r   rR   r   remove_profilesnamed_profilesr   u@   │            ⚕ Hermes Agent Uninstaller                  │r   zCurrent Installation:z  Code:    z  Config:  zconfig.yamlz  Secrets: z.envz  Data:    zcron/z, z	sessions/zlogs/zOther profiles detected:gateway_runningz (gateway running)rI   r   r)   zUninstall Options:z  1) z	Keep dataz/ - Remove code only, keep configs/sessions/logszF     (Recommended - you can reinstall later with your settings intact)z  2) zFull uninstallz' - Remove everything including all datazH     (Warning: This deletes all configs, sessions, and logs permanently)z  3) Cancelz - Don't uninstallzSelect option [1/2/3]: r   3>   cnqnoquitcancelr   2z.Other profiles will NOT be removed by default.zFound z named profile(s): c              3   4   K   | ]  }|j                     y wr   r\   r   r   s     r   r   z run_uninstall.<locals>.<genexpr>  s     717   zAlso stop and remove these z profile(s)? [y/N]: >   yr   u>   ⚠️  WARNING: This will permanently delete ALL Hermes data!z?   Including: configs, API keys, sessions, scheduled jobs, logsz   Plus z profile(s): c              3   4   K   | ]  }|j                     y wr   r
  r  s     r   r   z run_uninstall.<locals>.<genexpr>  s     9Q!&&9r  zFThis will remove the Hermes code but keep your configuration and data.r   z' to confirm: )r   r   ry   r   _print_uninstall_dry_runr   r   _perform_uninstallr
   r   r   r   r   r   r\   r   r   r   REDr   r   r   r   r,   lenr-   )r   r   rR   is_default_profiler   r   r   r   runningchoicer   respr   s                r   run_uninstallr  7  sN    $%L!#KGD)U+, %#fe <=	

 	
 1=3E-/2N eU34LgdFE:;%#)!)	
 		G	%  D  FL  FT  FT  V\  Va  Va  b  c	%RTZTbTbdjdodo
pq	%  D  FL  FT  FT  V\  Va  Va  b  c	G 
%'fkk
BC	K~
&'	Km34
56	Kf,-
./	Kg-.b{1J0K2k\cNcMd
ef	Ge.V[[IJ 	8A.5a9JE.R*XZGF166(7)2affX67	8 	 
%$fmmV[[
AB	G	'E+v||4
47h
hi	
RS	G	'E*FJJ7
7:c
cd	
TU	G	'E(FKK0
03G
GH	Gu6DEKKM }*QQ$%mN O.eDfmmTUs>*++>?ii7778 	9	-c..A-BBVW  uwuuw  ,. 
GeTV\V`V`bhbmbmnoeUW]WaWabc%3~./}=		9.99:

  	VW	G&ufmm!< =^LMSSU[[] %$%!%'%{ x( l8 "8, 	G,	. x( ls8   1V AW  'AW* $V=<V= $W'&W'*$XXr   r   c                 j   t                t        t        dt        j                  t        j                               t                t        t        dt        j
                  t        j                               t        d       t        d       t        d       t        d       t        d|         |rgt        d|        t        |      r\t               }|rPt        d	       |D ]'  }t        d
|j                   d|j                          ) t                yt        d|        t                y)zEPrint the uninstall plan without stopping services or deleting files.zDDry run: no files, services, or environment entries will be changed.zWould inspect/remove:u7     • Gateway services and standalone gateway processesu@     • Hermes PATH entries from shell configs / Windows User PATHuE     • Hermes wrapper scripts and Hermes-managed node/npm/npx symlinksu      • Desktop Chat GUI artifactsu     • Code checkout: u     • Hermes config/data: uB     • Named profiles (interactive uninstall asks before removing):z    - r)   u     • Keep Hermes config/data: N)
r
   r   r   r   r   r   r   r   r\   r   )r   rR   r   profilesprofs        r   r  r    s    	G	%VX^XcXcekepep
qr	G	%'
DE	
CD	
LM	
QR	
,-	!,
01*;-89";//1HZ[$ =DF499+R		{;<= 
G 	/}=>	Gr   r   r   c           	         t                t        t        dt        j                  t        j                               t                t        d       t               st        d       t        d       t               }|r|D ]  }t        d|         nt        d       t               rt        d       t        t        t        j                  j                  t        |                        }|r|D ]  }t        d|         nt        d	       t        d
       t!               }	|	r|	D ]  }
t        d|
         nt        d       t        d       t#               }|r|D ]  }t        d|         nt        d       t        d       t%        |      }|r|D ]  }t        d|         nt        d       t        d       	 ddlm}  ||      }|st        d       t        d       	 | j/                         rd|| j0                  v s| j2                  |k(  r$t5        j6                  |        t        d|         n#t5        j6                  |        t        d|         t               r9t        d       t9        |      }|r|D ]  }t        d|         nt        d       |rV|r|r|D ]  }t;        |        t        d       	 |j/                         r#t5        j6                  |       t        d|        nt        d|        t                t        t        d t        j<                  t        j                               t        t        d!t        j<                  t        j                               t        t        d"t        j<                  t        j                               t                |st        t        d#t        j                               t        d$| d%       t                t        d&       t               r$t        t        d't        j>                               n#t        t        d(t        j>                               t                t               rGt        t        d)t        j@                               t        t        d*t        j@                               n.t        t        d+t        j@                               t        d,       t                t        d-       t                y# t*        $ r}t-        d|        Y d}~3d}~ww xY w# t*        $ r'}t-        d|  d|        t        d       Y d}~d}~ww xY w# t*        $ r'}t-        d| d|        t        d       Y d}~pd}~ww xY w).u  Execute the uninstall steps. Shared by the interactive and ``--yes``
    paths so the destructive sequence lives in exactly one place.

    Steps: stop gateway → strip PATH (rc files + Windows registry) → remove the
    ``hermes`` wrapper + node symlinks → remove the desktop Chat GUI artifacts →
    delete the code checkout → (Windows) remove PortableGit/Node → optionally
    wipe ``$HERMES_HOME`` data and named profiles on full uninstall.
    zUninstalling...zChecking for running gateway...z%No gateway service or processes foundz+Removing PATH entries from shell configs...zUpdated z1No PATH entries found to remove in shell rc filesz6Removing PATH entries from Windows User environment...zRemoved from User PATH: z0No Hermes-owned PATH entries in User environmentz<Removing HERMES_HOME / HERMES_GIT_BASH_PATH User env vars...zRemoved User env var: z%No Hermes-set User env vars to removezRemoving hermes command...ro   zNo wrapper script foundz0Removing Hermes-managed node/npm/npx symlinks...z-No Hermes-managed node/npm/npx symlinks foundz&Removing desktop Chat GUI artifacts...r   )r   zNo desktop GUI artifacts foundz(Could not remove desktop GUI artifacts: Nz"Removing installation directory...zCould not fully remove r)   z"You may need to manually remove itzLRemoving Windows installer artifacts (PortableGit, Node, gateway-service)...z(No Windows installer artifacts to removez"Removing configuration and data...z"Keeping configuration and data in r   uA   │              ✓ Uninstall Complete!                      │r   z0Your configuration and data have been preserved:z  /z/To reinstall later with your existing settings:z=  iex (irm https://hermes-agent.nousresearch.com/install.ps1)zD  curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bashz>Open a new terminal (PowerShell / Windows Terminal) to pick upz0the updated User PATH and environment variables.z*Reload your shell to complete the process:z!  source ~/.bashrc  # or ~/.zshrcu%   Thank you for using Hermes Agent! ⚕)!r
   r   r   r   r   r   r   r:   r   r   r   r   rL   r   
expandvarsr}   r   rE   r`   r   r   r0   r   r   rZ   r   r   r   r   r   r   DIMr   )r   rR   r   r   r   removed_configsr#   removed_path_entriesr   removed_envr\   removed_wrappersrD   removed_node_linksr^   r   gui_removedr9   removed_artifactsr   r  s                        r   r  r    s     
G	%!6;;
<=	G ./$&89
 :;46O% 	-F(6(+,	- 	DE}IJ  AbggFXFXY\]hYiFjAkl- @6ug>?@ GHOP46# =4TF;<= <= )*,.' 	.G(7),-	. 	*+
 ?@-k:& 	+D(4&)*	+ 	@A 56A:#K056
 127 l222l6I6I[6Xl+h|n56 l+h|n56 }_`;KH) /htf-./ ?@  ~& )"4() 	56	;!!#k*h{m45
 	5k]CD 
G	%  D  FL  FR  FR  TZ  T_  T_  `  a	%SU[UaUacicncn
op	%  D  FL  FR  FR  TZ  T_  T_  `  a	GeFTU;-q!"?@=%WY_YcYcde%^`f`j`jkl}eTV\VcVcdeeFVWe@&--PQ12	G	
12	Gk  A;A3?@@A$  7*<.1#>?5667F  	;.{m2aSAB9::	;sI   S7 -A4T 3U 7	T TT	U%UU	U?U::U?c                       e Zd ZdZdefdZy)_UninstallArgsz;Lightweight args namespace for the module entrypoint below.modec                H    |dk(  | _         d| _        |dk(  | _        d| _        y )NguiFr   T)r*  gui_summaryr   r   )selfr(  s     r   __init__z_UninstallArgs.__init__  s'    5= FN	r   N)__name__
__module____qualname____doc__r}   r-  r   r   r   r'  r'    s    E r   r'  c                     ddl }|j                  d      }|j                  dg ddd	       |j                  |       }t	        |j
                  
      }|j                  rt        |       yt        |       y)u  Module entrypoint: ``python -m hermes_cli.uninstall --mode <gui|lite|full>``.

    Exists so the desktop app can run the uninstall under a Python interpreter
    OUTSIDE the venv being deleted. On Windows, ``lite``/``full`` rmtree the
    venv that contains the running ``python.exe`` — and a running .exe is
    mandatory-locked, so doing that from the venv's own interpreter half-fails.
    The desktop launches this with the system Python + ``PYTHONPATH=<agentRoot>``
    so ``import hermes_cli`` resolves from source while the venv is torn down.

    This module imports only stdlib + ``hermes_constants`` + ``hermes_cli.colors``
    (and lazily ``hermes_cli.gui_uninstall``), so it runs fine under a bare
    system Python with no site-packages from the venv.
    r   Nzpython -m hermes_cli.uninstall)progz--mode)r*  liter   TzEgui = Chat GUI only; lite = GUI + agent, keep data; full = everything)choicesrequiredhelp)r(  )	argparseArgumentParseradd_argument
parse_argsr'  r(  r*  r   r  )argvr8  parsernsr   s        r   mainr?    s{     $$*J$KF
'T	   
		4	 Brww'Dxx$  	dr   __main__)r   z
list[Path])r   Nr   )*r1  rL   r   r{   rJ   pathlibr   r   r   hermes_cli.colorsr   r   r}   r   r   r   r   listr$   r:   rE   rQ   r`   r   r   r   r   r   ry   r   r   r   r   r   r  r  r  r'  intr?  r.  exitr   r   r   <module>rF     s   
   
  , +0# 01S 12# 22$ 2
D (+\,
*d *t *Zl^
d 
tCy 
$4 $DI $NS	 4 $t*  #T #
 $ /<dEPQhd  W[ `d 0pp p 	p
 p p 
pf s B zCHHTV r   