
    iL                    t   U d Z ddlm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mZ ddlmZ d:dZd;d<dZd=dZd=dZd=dZd>dZdaded<   d?dZd@dZd@dZdAdZd;dBd ZdCd!ZdDdEd&ZdFd'Zd=d(Z d?d)Z!dGd+Z"d=d,Z#d=d-Z$d=d.Z%d=d/Z&d=d0Z'd=d1Z(d=d2Z)d=d3Z*d=d4Z+d=d5Z,d=d6Z-d=d7Z.d=d8Z/d=d9Z0dS )HzoCLI commands for Honcho integration management.

Handles: hermes honcho setup | status | sessions | map | peer
    )annotationsNPathget_hermes_home)resolve_active_hostresolve_config_pathHOST)cfg_getprofile_namestrreturnboolc                   t                      }|sdS |                    di           }|                    t          i           }t          |                    d          pt          j                            d                    }|s|sdS t           d|  }||v rdS i }dD ]}|                    |          }||||<   |                    d          p|                    d          }	|	r|	|d<   | |d	<   |                    d
          p|                    d
          pt          |d
<   |                    dd          |d<   ||                    di           |<   t          |           t          |           dS )a[  Auto-clone Honcho config for a new profile from the default host block.

    Called during profile creation. If Honcho is configured on the default
    host, creates a new host block for the profile with inherited settings
    and auto-derived workspace/aiPeer.

    Returns True if a host block was created, False if Honcho isn't configured.
    FhostsapiKeyHONCHO_API_KEY.)
recallModewriteFrequencysessionStrategysessionPeerPrefixcontextTokensdialecticReasoningLeveldialecticDynamicdialecticMaxCharsmessageMaxCharsdialecticMaxInputCharssaveMessagesobservationNpeerNameaiPeer	workspaceenabledT)	_read_configgetr
   r   osenviron
setdefault_write_config_ensure_peer_exists)
r   cfgr   default_blockhas_keynew_host	new_blockkeyval	peer_names
             >/home/ubuntu/.hermes/hermes-agent/plugins/memory/honcho/cli.pyclone_honcho_for_profiler5      s    ..C uGGGR  EIIdB''M 3778$$H
7G(H(HIIG  u''''H5u II ! ! $$? IcN !!*--D1D1DI * )	* 'Ih*..{;;[sww{?S?S[W[Ik(,,Y==Ii,5CNN7B)# !!!4    host_key
str | Nonec                    	 ddl m}m} |                    |           }|j        r|j        s	|j        sdS  ||          }|                    |j                   |j	        r|                    |j	                   dS # t          $ r Y dS w xY w)zCreate the AI peer in Honcho if it doesn't already exist.

    Idempotent -- safe to call multiple times. Returns True if the peer
    was created or already exists, False on failure.
    r   HonchoClientConfigget_honcho_clienthostFT)plugins.memory.honcho.clientr;   r<   from_global_configr$   api_keybase_urlpeerai_peerr3   	Exception)r7   r;   r<   hcfgclients        r4   r+   r+   J   s    VVVVVVVV!44(4CC| 	DL 	DM 	5""4((DL!!!> 	(KK'''t   uus   3A? AA? ?
BBNonec           	     4   t                      }t                      }|dk    rd| dnd}|                    di                               |i           }|                    d          du rt	          d| d	           d
S d|d<   |                    d          st          |dt          i           }dD ]"}|                    |          }|	||vr|||<   #|                    d          p|                    d          }|r	d|vr||d<   d|v r|                    dd          d         n|}	|                    d|	           |                    d|                    d          p|                    d          pt                     t          |           t	          d| d           t          |          r+t	          d| d|                    d|           d           nt	          d| d           t	          dt                       d           d
S )z%Enable Honcho for the active profile.hermes[]  r   r$   T  zHoncho is already enabled.
Nr"   default)r   r   r   r   r   r   r   r   r   r   r    r!   r      r#   zHoncho enabled.zPeer 'z' ready.z'Peer creation deferred (no connection).  Saved to 
)r%   	_host_keyr)   r&   printr   r
   splitr*   r+   _config_path)
argsr,   r>   labelblockr-   r1   r2   r3   rD   s
             r4   
cmd_enabler[   _   sa   
..C;;D H,,LLLLL"ENN7B''224<<Eyyt##65666777E) 99X fWdB???3 	! 	!C  ##C((C3e#3#3 c
!%%j11HSWWZ5H5H	 	*500 )E*+.$;;$**S!$$Q''D7+++m&7&7&D&D&dP[H\H\&d`deee#	
%u
%
%
%&&& 4   CC5CC		(D 9 9CCCDDDDA5AAABBB	
*
*
*
*+++++r6   c                h   t                      }t                      }|dk    rd| dnd}t          |d|i           }|r|                    d          du rt	          d	| d
           dS d|d<   t          |           t	          d	| d           t	          dt                       d           dS )z&Disable Honcho for the active profile.rJ   rK   rL   rM   r   rO   r$   FrN   zHoncho is already disabled.
NzHoncho disabled.rR   rS   )r%   rT   r   r&   rU   r*   rW   )rX   r,   r>   rY   rZ   s        r4   cmd_disabler]      s    
..C;;D H,,LLLLL"EC$333E EIIi((E1175777888E)#	
&u
&
&
&'''	
*
*
*
*+++++r6   c                   	 ddl m}  |            }n+# t          $ r}t          d| d           Y d}~dS d}~ww xY wt	                      }|st          d           dS |                    di           }|                    t          i           }t          |                    d          pt          j	                            d	                    }|s|st          d
           dS d}d}	|D ]L}
|
j
        dk    rt          |
j
                  r%t          d|
j
         d|
j
                    |dz  }G|	dz  }	M|rt          d| d           nt          d           |	rt          d|	 d           t                       dS )zSync Honcho config to all existing profiles.

    Scans all Hermes profiles and creates host blocks for any that don't
    have one yet. Inherits settings from the default host block.
    r   list_profilesz  Could not list profiles: rS   Nz;  No Honcho config found. Run 'hermes honcho setup' first.
r   r   r   zM  Honcho not configured on default profile. Run 'hermes honcho setup' first.
rP   z  + z -> hermes.rQ   z
  z profile(s) synced.z*  All profiles already have Honcho config.rN   z) profile(s) already configured (skipped).)hermes_cli.profilesr`   rE   rU   r%   r&   r
   r   r'   r(   namer5   )rX   r`   profileser,   r   r-   r.   createdskippedps              r4   cmd_syncrh      s   555555 =??   1A111222 ..C LMMMGGGR  EIIdB''M3778$$H
7G(H(HIIG  ^___GG  6Y#AF++ 	444AF44555qLGGqLGG <1W1112222:;;; GE7EEEFFF	GGGGGs    
;6;intc                    	 ddl m}   |             }n# t          $ r Y dS w xY wt                      }|sdS t	          |dt
          i           }t          |                    d          pt          j	                            d                    }|s|sdS d}|D ]'}|j
        dk    rt          |j
                  r|dz  }(|S )	zSync Honcho host blocks for all profiles. Returns count of newly created blocks.

    Called from `hermes update` -- no output, no exceptions.
    r   r_   r   rO   r   r   rP   rQ   )ra   r`   rE   r%   r   r
   r   r&   r'   r(   rb   r5   )r`   rc   r,   r-   r.   re   rg   s          r4   sync_honcho_profiles_quietrk      s    
555555 =??   qq ..C qC$;;;M3778$$H
7G(H(HIIG  qG  6Y#AF++ 	qLGNs    
!!_profile_overridec                 n    t           r!t           dv rt          S t           dt            S t                      S )zKReturn the active Honcho host key, derived from the current Hermes profile.)rP   customr   )rl   r
   r    r6   r4   rT   rT      s<     - 555K,,*,,,   r6   r   c                     t                      S )zLReturn the active Honcho config path for reading (instance-local or global).)r	   ro   r6   r4   rW   rW      s       r6   c                 $    t                      dz  S )a  Return the instance-local Honcho config path for writing.

    Always returns $HERMES_HOME/honcho.json so each profile/instance gets
    its own config file.  The global ~/.honcho/config.json is only used as
    a read fallback (via resolve_config_path) for cross-app interop.
    zhoncho.jsonr   ro   r6   r4   _local_config_pathrr      s     },,r6   dictc                     t                      } |                                 r9	 t          j        |                     d                    S # t
          $ r Y nw xY wi S )Nutf-8encoding)rW   existsjsonloads	read_textrE   )paths    r4   r%   r%     sc    >>D{{}} 	:dnngn>>??? 	 	 	D	Is   'A 
AAr,   r|   Path | Nonec                    |pt                      }|j                            dd           |                    t	          j        | dd          dz   d           d S )	NT)parentsexist_ok   F)indentensure_asciirS   ru   rv   )rr   parentmkdir
write_textry   dumps)r,   r|   s     r4   r*   r*     so    '%''DKdT222OO
3qu555<      r6   c                   |                      d          pi                      t                                pi                      d          }|p5|                      dd          pt          j                             dd          }|s|                      d          p4|                      d          pt          j                             dd          pd                                rdd	lm} 	  |          }n# t          t          f$ r d
}Y nw xY w|r|j	        dv r	|j
        rdS                                 }|dvr1t          fddD                       r                                sdS |S )u5  Resolve API key with host -> root -> env fallback.

    For self-hosted instances configured with ``baseUrl`` instead of an API
    key, returns ``"local"`` so that credential guards throughout the CLI
    don't reject a valid configuration.  The ``baseUrl`` is scheme-validated
    (http/https only) so that a typo like ``baseUrl: true`` can't silently
    pass the guard.  Schemeless strings that look like host:port (legacy
    config shapes, e.g. ``localhost:8000``) still pass — the Honcho SDK
    will reject them itself with a clearer error than ours.
    r   r   rM   r   baseUrlrB   HONCHO_BASE_URLr   )urlparseN)httphttpslocal)truefalsenonenullc              3      K   | ]}|v V  	d S Nro   ).0crB   s     r4   	<genexpr>z#_resolve_api_key.<locals>.<genexpr>0  s@       H H"#XH H H H H Hr6   z.:)r&   rT   r'   r(   stripurllib.parser   	TypeError
ValueErrorschemenetlocloweranyisdigit)r,   r7   r1   r   parsedloweredrB   s         @r4   _resolve_api_keyr     s    !!'R,,Y[[99?RDDXNNH

Scggh++
Srz~~>NPR/S/SC 779%%e)<)<e
O`bd@e@eN))++ 	------!(++z*    &-+<<<<w nn&&G???C H H H H'+H H H E E?&&(( @ wJs   0C< <DDFrY   rP   secretc                   |rd| dnd}t           j                            d|  | d           t           j                                         |rjt           j                                        rdd l}|                    d          }nat           j                                                                        }n0t           j                                                                        }|p|pdS )N []rM   rN   : r   )prompt)	sysstdoutwriteflushstdinisattygetpassreadliner   )rY   rP   r   suffixr   r2   s         r4   _promptr   7  s     '/_'____RFJ+%++++,,,J +9 	/NNN///,,CC )$$&&,,..CCi  ""((**!7=b!r6   c                    	 ddl } dS # t          $ r Y nw xY wt          d           t          dd          }|                                dvrt          d	           d
S ddl}t          dd           |                    t          j        ddddgdd          }|j	        dk    rt          d           dS t          d|j
                                                    t          d           d
S )zNCheck honcho-ai is importable; offer to install if not. Returns True if ready.r   NTz  honcho-ai is not installed.z"Install it now? (honcho-ai>=2.0.1)yrO   r   yesz8  Skipping install. Run: pip install 'honcho-ai>=2.0.1'
Fz  Installing honcho-ai...)r   z-mpipinstallzhoncho-ai>=2.0.1)capture_outputtextz  Installed.
z  Install failed:
z/  Run manually: pip install 'honcho-ai>=2.0.1'
)honchoImportErrorrU   r   r   
subprocessrunr   
executable
returncodestderrr   )r   answerr   results       r4   _ensure_sdk_installedr   G  s,   t    

)***93GGGF||~~\))IJJJu	
%T2222^^	ui1CD   F
 At;FM$7$7$9$9;;<<<@AAAus    
c                0  , t                      ,t                      }t                      }t          d           t          d           t          d|            ||k    r'|                                rt          d| d           t                       t                      sdS ,                    di           }|                    t                      i           }t          d           t          d	           t          d
           t          ,fddD                       rdnd}t          d|          }|
                                dv },                    dd           |rx,                    d          pd}t          d|pd          }	|	r|	,d<   ,                    dd          }
|
rt          d           t          d           nt          d           n,                    dd           ,                    dd          }
t          |
          dk    rd|
dd          n|
rdnd}t          d |            t          d!d"#          }|r|,d<   ,                    d          s t          d$           t          d%           dS |                    d&          p,                    d&d          }t          d'|pt          j        d(d)                    }|r||d&<   |                    d*          p,                    d*d+          }t          d,|          }|r||d*<   |                    d-          p,                    d-d+          }t          d.|          }|r||d-<   |                    d/          p,                    d/d0          }t          d1           t          d2           t          d3           t          d4|          }|d5v r||d/<   nd0|d/<   t!          |                    d6          p,                    d6d7                    }t          d8           t          d9           t          d:           t          d;           t          d<           t          d=|          }	 t#          |          |d6<   n"# t$          t&          f$ r |d>v r|nd7|d6<   Y nw xY w|                    d?          p,                    d?d@          }|dAvrd@n|}t          dB           t          dC           t          dD           t          dE           t          dF|          }|dAv r||d?<   |                    dG          p,                    dG          }|rt!          |          ndH}t          dI           t          dJ           t          dK           t          dL|          }|                                
                                dMv r|                    dGd           nL|                                dk    rn3	 t#          |          }|dNk    r||dG<   n# t$          t&          f$ r Y nw xY wt!          |                    dO          p,                    dO          pdP          }t          dQ           t          dR           t          dS           t          dT           t          dU|          }	 t#          |          }|dVk    r||dO<   n# t$          t&          f$ r dW|dO<   Y nw xY w|                    dX          p,                    dX          pdY} t          dZ           t          d[           t          d\           t          d]           t          d^           t          d_           t          d`           t          da|           }!|!dbv r|!|dX<   ndY|dX<   |                    dc          p,                    dcdd          }"t          de           t          df           t          dg           t          dh           t          di           t          dj|"          }#|#dkv r|#|dc<   d"|dl<   |                    dmd"           t+          ,           t          dn|            	 dNdolm}$m}%  |$            }&dp|&                    dqi           dr<    |%|&           t          ds           n8# t2          $ r+}'t          dt|'            t          du           Y d}'~'nd}'~'ww xY wt          dvdd"w           	 dNdxlm}(m})m}*  |*             |(                    t                      y          }+ |)|+           t          dz           n*# t2          $ r}'t          d{|'            Y d}'~'dS d}'~'ww xY wt          d|           t          d}|+                                            t          d~|+j                     t          d|+j!                    t          d|+j"                    t          d|+j#                    t          d|+j$                    t          d|+j%                    t          d|+j&                    t          d           t          d           t          d           t          d           t          d           t          d           t          d           t          d           t          d           t          d           t          d           t          d           dS )z Interactive Honcho setup wizard.u   
Honcho memory setup
────────────────────────────────────────z6  Honcho gives Hermes persistent cross-session memory.z
  Config: z#  (seeding from existing config at )Nr   z  Deployment:z*    cloud -- Honcho cloud (api.honcho.dev)z&    local -- self-hosted Honcho serverc              3  t   K   | ]2}|                     d           p                     d          pdv V  3dS )r   rB   rM   N)r&   )r   hr,   s     r4   r   zcmd_setup.<locals>.<genexpr>|  s^       $ $ 	
cggi  =CGGJ$7$7=2>$ $ $ $ $ $r6   )	localhostz	127.0.0.1z::1r   cloudzCloud or local?rO   )r   lrB   r   rM   zBase URLzhttp://localhost:8000r   z9
  API key present in config (kept for cloud/hybrid use).z1  Local connections will skip auth automatically.z'
  No API key set. Local no-auth ready.   ...setnot setz
  Current API key: z,Honcho API key (leave blank to keep current)T)r   z=
  No API key configured. Get yours at https://app.honcho.devz7  Run 'hermes honcho setup' again once you have a key.
r!   zYour name (user peer)USERuserr"   rJ   zAI peer namer#   zWorkspace IDobservationModedirectionalz
  Observation mode:zS    directional  -- all observations on, each AI peer builds its own view (default)zL    unified      -- shared pool, user observes self, AI observes others onlyzObservation mode)unifiedr   r   asyncz
  Write frequency:z=    async   -- background thread, no token cost (recommended)z*    turn    -- sync write after every turnz.    session -- batch write at session end onlyz+    N       -- write every N turns (e.g. 5)zWrite frequency)r   turnsessionr   hybridr   contexttoolsz
  Recall mode:zG    hybrid  -- auto-injected context + Honcho tools available (default)z>    context -- auto-injected context only, Honcho tools hiddenz:    tools   -- Honcho tools only, no auto-injected contextzRecall moder   uncappedzA
  Context injection per turn (hybrid/context recall modes only):z"    uncapped -- no limit (default)z0    N        -- token limit per turn (e.g. 1200)zContext tokens)r   r   zno limitr   dialecticCadence2z
  Dialectic cadence:zJ    How often Honcho rebuilds its user model (LLM call on Honcho backend).z7    1 = every turn, 2 = every other turn, 3+ = sparser.z    Recommended: 1-5.zDialectic cadencerQ   r   r   lowz
  Dialectic reasoning level:zL    Depth Honcho uses when synthesizing user context on auto-injected calls.z%    minimal  -- quick factual lookupsz3    low      -- straightforward questions (default)z&    medium   -- multi-aspect synthesisz+    high     -- complex behavioral patternsz-    max      -- thorough audit-level analysiszReasoning levelminimalr   mediumhighmaxr   per-sessionz
  Session strategy:zP    per-session   -- each run starts clean, Honcho injects context automaticallyzQ    per-directory -- reuses session per dir, prior context auto-injected each runz3    per-repo      -- one session per git repositoryz:    global        -- single session across all directorieszSession strategy)r   per-repoper-directoryglobalr$   r   z
  Config written to )load_configsave_configr   memoryproviderz0  Memory provider set to 'honcho' in config.yamlz(  Could not auto-enable in config.yaml: z/  Run: hermes config set memory.provider honchoz  Testing connection... endr   r;   r<   reset_honcho_clientr=   OKzFAILED
  Error: z
  Honcho is ready.z  Session:   z  Workspace: z  User:        AI peer:   z  Observe:   z  Frequency: z  Recall:    z  Sessions:  z"
  Honcho tools available in chat:zP    honcho_context   -- session context: summary, representation, card, messagesz4    honcho_search    -- semantic search over historyz,    honcho_profile   -- peer card, key factszA    honcho_reasoning -- ask Honcho a question, synthesized answerz5    honcho_conclude  -- persist a user fact to memoryz
  Other commands:z0    hermes honcho status     -- show full configz>    hermes honcho mode       -- change recall/observation modezB    hermes honcho tokens     -- tune context and dialectic budgetsz1    hermes honcho peer       -- update peer nameszE    hermes honcho map <name> -- map this directory to a session name
)'r%   rr   rW   rU   rx   r   r)   rT   r   r   r   popr&   lenr'   getenvr   ri   r   r   r   r*   hermes_cli.configr   r   rE   r?   r;   r<   r   r@   resolve_session_nameworkspace_idr3   rD   observation_modewrite_frequencyrecall_modesession_strategy)-rX   
write_path	read_pathr   hermes_hostcurrent_deploydeployis_localcurrent_urlnew_urlcurrent_keymaskednew_keycurrent_peernew_peer
current_ainew_aicurrent_workspacenew_workspacecurrent_obsnew_obs
current_wfnew_wf_raw_recallcurrent_recall
new_recallcurrent_ctx_tokenscurrent_displaynew_ctx_tokensr2   current_dialecticnew_dialecticcurrent_reasoningnew_reasoningcurrent_strat	new_stratr   r   hermes_configrd   r;   r<   r   rF   r,   s-                                               @r4   	cmd_setupr!  e  s   
..C#%%JI	
0111	
BCCC	
#z
#
#$$$J9#3#3#5#5@I@@@AAA	GGG "" NN7B''E""9;;33K 
/	
6777	
2333 # $ $ $ $2$ $ $ ! ! WW   &???F||~~/H GGJ ggi((.B*k.T=TUUU 	%$C	N
 ggh++ 	>OPPPEFFFF<==== 		4   ggh++-0-=-=-A-A){233')))Q\Hkbk.f..///HQUVVV 	$#CMwwx   	RSSSLMMMF ??:..I#''*b2I2IL.8a	RXZ`HaHabbbH +"*J**Icggh.I.IJ^Z888F ' &H#44VX8V8VN4EFFFM 1#0K  //"344a@QS`8a8aK	
!"""	
_```	
XYYY(+>>>G,,,)0%&&)6%& [__%566\#''BRT[:\:\]]J	
 !!!	
IJJJ	
6777	
:;;;	
7888&
;;;Ff(+F$%%	" f f f28<X2X2X^e$%%%f //,//R377<3R3RK!,4R!R!RXXXcN	
	
STTT	
JKKK	
FGGG???J333$.L! %99USWW_=U=U1CSc,---O	
NOOO	
.///	
<===-GGGN##%%)III....					2	%	%	n%%Caxx/2O,I& 	 	 	D	 KOO,>??e377K]C^C^ebeff	
"###	
VWWW	
CDDD	
!"""/9JKKKM,-  !88.1K*+	" , , ,*+&''',
 	122 	77,--	 
 

*+++	
XYYY	
1222	
?@@@	
2333	
7888	
9:::-7HIIIMCCC1>-..16-.  OO$566c#''BSUb:c:cM	
!"""	
\]]]	
]^^^	
?@@@	
FGGG*MBBBIJJJ)2%&!K	>4000#	
/:
/
/000A>>>>>>>>#=E  2..z:M"""@AAAA A A A<<<===?@@@@@@@@A
 

$"D9999kkkkkkkkkk!44)++4FF$d   %!%%&&& 

 !!!	
7$3355
7
7888	
-$+
-
-...	
*$.
*
*+++	
($,
(
()))	
1$/
1
1222	
0$.
0
0111	
,$*
,
,---	
1$/
1
1222	
/000	
\]]]	
@AAA	
8999	
MNNN	
ABBB	
   	
<===	
JKKK	
NOOO	
=>>>	
RSSSSSsh   >R R0/R0X+ +X?>X?	[$ $[=<[=Ac 
c=!c88c=Ae$ $
f.ffc                 b    t           rt           S 	 ddlm}   |             S # t          $ r Y dS w xY w)zKReturn the active Hermes profile name (respects --target-profile override).r   get_active_profile_namerP   )rl   ra   r$  rE   r#  s    r4   _active_profile_namer%  L  sX     !  ??????&&(((   yys     
..list[tuple[str, str, dict]]c            	        	 ddl m}   |             }n.# t          $ r! t                      t	                      i fgcY S w xY wt                      }|                    di           }g }|                    t          i           }|                    dt          |f           |D ]P}|j	        dk    rt           d|j	         }|                    |j	        ||                    |i           f           Q|S )zReturn (profile_name, host_key, host_block) for every known profile.

    Reads honcho.json once and maps each profile to its host block.
    r   r_   r   rP   r   )
ra   r`   rE   r%  rT   r%   r&   r
   appendrb   )r`   rc   r,   r   resultsr-   rg   r   s           r4   _all_profile_host_configsr*  W  s   
;555555 =?? ; ; ;%''b9::::; ..CGGGR  EG IIdB''MNNIt]3444 6 66Yaf599Q#3#345555Ns    (>>c                   t          | dd          }|rt                       dS 	 ddl}n # t          $ r t	          d           Y dS w xY wt                      }t                      }t                      }|s#t	          d|            t	          d           dS 	 ddlm	}m
} |                    t                      	          }n+# t          $ r}	t	          d
|	 d           Y d}	~	dS d}	~	ww xY w|j        pd}
t          |
          dk    rd|
dd          n|
rdnd}t!                      }|dk    rd|j         dnd}t	          d| ddz              |dk    rt	          d|            t	          d|j                    t	          d|j                    t	          d|            t	          d|j                    t)          j                    dz  dz  }t	          d|            ||k    rt	          d| d            ||k    rt	          d!           n'|                                rt	          d"| d#           t	          d$|j                    t	          d%|j        pd            t	          d&|                                            t	          d'|j                    t	          d(|j                    t	          d)|j        pd* d+           t          |d,d          pi }|                    d-          pd.}t	          d/| d0|d.k    rd1nd            |                    d2          p|j        }|j        rd3nd4}t	          d5|j          d6| d7|            t	          d8|j!         d9|j"         d:|j#         d9|j$         d;	           t	          d<|j%                    |j        rx|j        s|j&        rjt	          d=dd>?           	  ||          }tO          ||           t	          d@           dS # t          $ r}	t	          dA|	 dB           Y d}	~	dS d}	~	ww xY w|j        sdCndD}t	          dE| dB           dS )Fz1Show current Honcho config and connection status.allFNr   z7  honcho-ai is not installed. Run: hermes honcho setup
z  No Honcho config found at z*  Run 'hermes honcho setup' to configure.
r:   r=   z  Config error: rS   rM   r   r   r   r   r   rP   r   r   z
Honcho statusx   ────────────────────────────────────────z  Profile:        z  Host:           z  Enabled:        z  API key:        z  Workspace:      z.honchozconfig.jsonz  Config:         z  Write to:       z  (profile-local)u?     Fallback:       (none — using global ~/.honcho/config.json)z  Fallback:       z  (exists, cross-app interop)z  AI peer:        z  User peer:      z  Session key:    z  Session strat:  z  Recall mode:    z  Context budget: z
(uncapped) tokensrawr   rQ   z  Dialectic cad:  every z turnsreasoningLevelCaponoffz  Reasoning:      base=z, cap=z, heuristic=z  Observation:    user(me=z,others=z) ai(me=r   z  Write freq:     z
  Connection... Tr   r   zFAILED ()
disabledzno API key or base URLz
  Not connected ()(getattr_cmd_status_allr   r   rU   r%   rW   rr   r?   r;   r<   r@   rT   rE   rA   r   r%  r>   r$   r   r   homerx   rD   r3   r   r   r   context_tokensr&   reasoning_level_capreasoning_heuristicdialectic_reasoning_leveluser_observe_meuser_observe_othersai_observe_meai_observe_othersr   rB   _show_peer_cards)rX   show_allr   r,   active_pathr   r;   r<   rF   rd   rA   r  profileprofile_labelglobal_pathr/  dialectic_cadencereasoning_capheuristic_onrG   reasons                        r4   
cmd_statusrK  s  s   tUE**H    HIII ..C..K#%%J :[::;;;;<<<VVVVVVVV!44)++4FF   &&&&''' l bG%(\\A%5%5!7233<!!!W<[EER[F"$$G)0I)=)=%%%%%2M	
-M
-
-
-

:;;;),7,,---	
*ty
*
*+++	
-t|
-
-...	
'v
'
'(((	
2t0
2
2333 )++	)M9K	
,{
,
,---[  @:@@@AAAk!!PQQQQ					 OM;MMMNNN	
-t|
-
-...	
<t~:
<
<===	
<t88::
<
<===	
6t4
6
6777	
1t/
1
1222	
Kt2Bl
K
K
KLLL
$t
$
$
*C 2338q	
d%6
d
dDUYZDZDZSS`b
d
deeeGG/00LD4LM3>44L	
sD$B
s
s-
s
seq
s
sttt	  ]t';  ]  ]TE]  ]  ]gkgy  ]  ]  DH  DZ  ]  ]  ]  ^  ^  ^	
5t3
5
5666| 
1 
1 
1"$7777	%&&t,,FT6***$KKKKK 	% 	% 	%#Q###$$$$$$$$$	% $(<M5M/F///00000s?   * AA*C 
C-C((C-*P 
P0P++P0c                   	 ddl m}  |||           }|                                 }|                    |           |                    |          }|rut          dt          |           d           |dd         D ]}t          d|            t          |          dk    r#t          d	t          |          dz
   d
           |                    |          }|                    dd          }|rC|dd         t          |          dk    rdndz   }	t          d           t          d|	            |s|st          d           t                       dS # t          $ r}
t          d|
 d           Y d}
~
dS d}
~
ww xY w)zFetch and display peer cards for the active profile.

    Uses get_or_create to ensure the session exists with peers configured.
    This is idempotent -- if the session already exists on the server it's
    just retrieved, not duplicated.
    r   HonchoSessionManagerr   configz
  User peer card (z facts):N
   z    - z    ... and z morerepresentationrM      r   z
  AI peer representation:    z:
  No peer data yet (accumulates after first conversation)z
  Peer data unavailable: rS   )
plugins.memory.honcho.sessionrN  r   get_or_createget_peer_cardrU   r   get_ai_representationr&   rE   )rF   rG   rN  mgrsession_keycardfactai_repai_textdisplayrd   s              r4   rA  rA    s   3FFFFFF""&>>>//11+&&&   -- 	<<T<<<===SbS	 ' 'otoo&&&&4yy2~~:SYY^:::;;; **;77**-r22 	$dsdmGs0B0BuuKG0111"""### 	QG 	QOPPP 3 3 31A1112222222223s   EE 
F'F  Fc                 N   t                      } t                      }t                      }t          dt	          |            ddz              t          dddddd	dd
dddddd 
           t          dd dd dd dd dd 
           | D ]\  }}}|                    d|                    d                    }|Gt          |                    d          pt          j                            d                    }|r|nd}|rdnd}|                    d          p|                    dd          }	|                    d          p|                    dd          }
||k    rdnd}t          d||z   dd|d	d|dd|	dd|
 
           t          d           dS )z0Show Honcho config overview across all profiles.z
Honcho profiles (r4  u   ───────────────────────────────────────────────────────rN   Profile<14 Hostz<22Enabledz<9RecallWrite*   ──────────────uB   ──────────────────────u   ─────────r$   Nr   r   Fr   nor   r   r   r   z *rM   z
  * active profile
)	r*  r%   r%  rU   r   r&   r   r'   r(   )rowsr,   activerb   r>   rZ   r$   	has_credsenabled_strrecallr   markers               r4   r7  r7    s   $&&D
..C!##F	
.D		
.
.
.
;<<<	
Ry
R
R
Rv
R
R
RI
R
R
R8
R
R
R
R
RSSS	
Lz
L
LJ
L
L
L
LY
L
L
L
LMMM! X XdE))Iswwy'9'9::?SWWX..R"*..AQ2R2RSSI#(3iieG&0eeD<((KCGGL(,K,K		*++Qsww7G/Q/QRV4&=VVVtVVV+VVV6VVVuVVWWWW	
#$$$$$r6   c           	        t                      }t                      }t          dt          |           ddz              t          dddddd	dd
            t          dd dd dd            |D ]x\  }}}|                    d          p|                    d          pd}|                    d          p|                    d          p|}t          d|dd|d	d|            yt                       dS )z)Show peer identities across all profiles.z
Honcho peer identities (z profiles)
u   ──────────────────────────────────────────────────rN   ra  rb  rc  z	User peerz<16zAI peerrh  u0   ────────────────u6   ──────────────────r!   	(not set)r"   N)r*  r%   rU   r   r&   )rX   rj  r,   rb   r>   rZ   r   ais           r4   	cmd_peersrs    s0   $&&D
..C	
>s4yy
>
>
>
KLLL	
<y
<
<
<{
<
<
<
<
<===	
5z
5
5J
5
5
5
5666! / /dEyy$$J
(;(;J{YYx  =CGGH$5$5=-4---d-----....	GGGGGr6   c                   t                      }|                    di           }|s?t          d           t          d           t          dt                       d           dS t	          j                    }t          dt          |           dd	z              t          |                                          D ]'\  }}||k    rd
nd}t          d|dd| |            (t                       dS )u/   List known directory → session name mappings.sessionsz"  No session mappings configured.
z0  Add one with: hermes honcho map <session-name>z
  Or edit z directly.
Nz
Honcho session mappings (r4  r-  u    ←rM   rN   z<30rc  )	r%   r&   rU   rW   r'   getcwdr   sorteditems)rX   r,   ru  cwdr|   rb   ro  s          r4   cmd_sessionsrz    s   
..Cwwz2&&H 3444@AAA7<>>777888
)++C	
:H
:
:
:Z
GHHHX^^--.. . .
d3;;B,4,,,d,F,,----	GGGGGr6   c                   | j         st          |            dS t          j                    }| j                                         }|st          d           dS ddl}|                    dd|                              d          }||k    rt          d|            |}t                      }||	                    di           |<   t          |           t          d| d	| d
           dS )z/Map current directory to a Honcho session name.Nz   Session name cannot be empty.
r   z[^a-zA-Z0-9_-]-z  Session name sanitized to: ru  z	  Mapped u
   
     → rS   )session_namerz  r'   rv  r   rU   resubr%   r)   r*   )rX   ry  r}  r~  	sanitizedr,   s         r4   cmd_mapr  +  s    T
)++C$**,,L 1222III(#|<<BB3GGIL  9i99::: 
..C*6CNN:r""3'#	
6c
6
6l
6
6
677777r6   c                   t                      }d}t          | dd          }t          | dd          }t          | dd          }d}||||                    di           }|                    t                      i           }|                    d          p|                    d          pd	}	|                    d
          p"|                    d
          pt                      }
|                    d          p|                    d          pd}|                    d          p|                    d          pd}t	          d           t	          d|	            t	          d           t	          d|
            t	          d           t	          d           t	                       t	          d| dd                    |           d           t	          d| d           dS t                      }|dk    rd| dnd}|h|                                |                    di                               |i           d<   d}t	          d | d!|                                            |h|                                |                    di                               |i           d
<   d}t	          d | d"|                                            |r||vr*t	          d#| d$d                    |                      dS ||                    di                               |i           d<   d}t	          d | d%|            |r0t          |           t	          d&t                       d'           dS dS )(z8Show or update peer names and dialectic reasoning level.Fr   Nrr  	reasoningr   r   r!   rq  r"   r   r   r   X  u   
Honcho peers
────────────────────────────────────────z  User peer:   zF    Your identity in Honcho. Messages you send build this peer's card.z  AI peer:     zJ    Hermes' identity in Honcho. Seed with 'hermes honcho identity <file>'.zD    Dialectic calls ask this peer questions to warm session context.z  Dialectic reasoning:    (, r   z  Dialectic cap:        z chars
rJ   rK   rL   rM   TrN   zUser peer -> zAI peer   -> z  Invalid reasoning level ''. Options: zDialectic reasoning level -> rR   rS   )
r%   r6  r&   rT   rU   joinr   r)   r*   rW   )rX   r,   changed	user_nameai_namer  REASONING_LEVELSr   rJ   r   rr  lvl	max_charsr>   rY   s                  r4   cmd_peerr  D  s   
..CGfd++IdD$''Gk400IBW_1B$$9;;++zz*%%K)<)<KZZ!!ESWWX%6%6E)++jj233bsww?X7Y7Yb]bJJ233Zsww?R7S7SZWZ	-...&&&'''VWWW$$$%%%Z[[[TUUUOOO;K1L1LOOOPPP<<<<===;;D H,,LLLLL"EGPGXGXw##..tR88D:5::y'8'8::;;;EL]]__w##..tR88B8588w}}88999,,,d	ddtyyQaGbGbddeeeFV_w##..tR889RSB5BByBBCCC 0c.LNN.../////0 0r6   c           	        dddd}t                      }t          | dd          }||                    d          pi                     t                      i                               d          p|                    d          pd	}t	          d
           |                                D ]'\  }}||k    rdnd}t	          d|dd| |            (t	          d           dS ||vr+t	          d| dd                    |           d           dS t                      }|dk    rd| dnd}	||                    di                               |i           d<   t          |           t	          d|	 d| d||          d           dS )zShow or set the recall mode.z8auto-injected context + Honcho tools available (default)z/auto-injected context only, Honcho tools hiddenz+Honcho tools only, no auto-injected contextr   modeNr   r   r   u   
Honcho recall mode
──────────────────────────────────────── <-rM   rN   z<10z7
  Set with: hermes honcho mode [hybrid|context|tools]
z  Invalid mode 'r  r  rS   rJ   rK   rL   zRecall mode -> r  r4  	r%   r6  r&   rT   rU   rx  r  r)   r*   )
rX   MODESr,   mode_argcurrentmdescro  r>   rY   s
             r4   cmd_moder  |  s    MD> E
 ..CtVT**HWWW#((b99==lKK ww|$$ 	
 	3444{{}} 	0 	0GAt7llUUF.q....f..////JKKKuKKKtyy7G7GKKKLLL;;D H,,LLLLL"EEMCNN7B**444\B#	
Fu
F
FX
F
F%/
F
F
FGGGGGr6   c           	        ddddd}t                      }t          | dd          }||                    d          pi                     t                      i                               d	          p|                    d	          pd
}t	          d           |                                D ]'\  }}||k    rdnd}t	          d|dd| |            (t	          d           dS ||vr+t	          d| dd                    |           d           dS t                      }|dk    rd| dnd}	||                    di                               |i           d	<   t          |           t	          d|	 d| d||          d           dS )z!Show or set the session strategy.z;each run starts clean, Honcho injects context automaticallyz<reuses session per dir, prior context auto-injected each runzone session per git repositoryz%single session across all directoriesr   r   r   r   strategyNr   r   r   u   
Honcho session strategy
────────────────────────────────────────r  rM   rN   z<15zP
  Set with: hermes honcho strategy [per-session|per-directory|per-repo|global]
z  Invalid strategy 'r  r  rS   rJ   rK   rL   zSession strategy -> r  r4  r  )
rX   
STRATEGIESr,   	strat_argr  r0  r  ro  r>   rY   s
             r4   cmd_strategyr    s    UW49	 J ..Cj$//IWWW#((b99==>OPP ww()) 	
 	8999!'')) 	0 	0GAt7llUUF.q....f..////cddd
""UYUUDIIj<Q<QUUUVVV;;D H,,LLLLL"EJSCNN7B**4445FG#	
Ru
R
R)
R
R
98M
R
R
RSSSSSr6   c                    t                      }|                    di           }|                    t                      i           }t          | dd          }t          | dd          }|E|B|                    d          p|                    d          pd}|                    d          p|                    d          pd}|                    d	          p|                    d	          pd
}t	          d           t	                       t	          d| d           t	          d           t	          d           t	                       t	          d| d|            t	          d           t	          d           t	          d           t	          d           t	          d           dS t                      }	|	dk    rd|	 dnd}
d}|D||                    di                               |	i           d<   t	          d|
 d|            d}|E||                    di                               |	i           d<   t	          d|
 d| d            d}|r0t          |           t	          d!t                       d"           dS dS )#z"Show or set token budget settings.r   r   N	dialecticr   z(Honcho default)r   r  r   r   u   
Honcho budgets
────────────────────────────────────────z  Context     r.  zC    Raw memory retrieval. Honcho returns stored facts/history aboutzC    the user and session, injected directly into the system prompt.z  Dialectic   z chars, reasoning: z?    AI-to-AI inference. Hermes asks Honcho's AI peer a questionzC    (e.g. "what were we working on?") and Honcho runs its own modelzD    to synthesize an answer. Used for first-turn session continuity.zB    Level controls how much reasoning Honcho spends on the answer.z@
  Set with: hermes honcho tokens [--context N] [--dialectic N]
rJ   rK   rL   rM   FrN   zcontext tokens -> Tzdialectic cap  -> z charsrR   rS   )r%   r&   rT   r6  rU   r)   r*   rW   )rX   r,   r   rJ   r   r  
ctx_tokensd_charsd_levelr>   rY   r  s               r4   
cmd_tokensr    s   
..CGGGR  EYYy{{B''FdIt,,Gk400I9,ZZ00bCGGO4L4LbPb
**011XSWW=P5Q5QXUX**677f377C\;];]faf/0002z222333STTTSTTTDwDD7DDEEEOPPPUVVVTUUURSSSRSSS;;D H,,LLLLL"EGLSw##..tR88I5555G55666PYw##..tR889LM=5==I===>>> 0c.LNN.../////0 0r6   c                   t                      }t          |          st          d           dS t          | dd          }t          | dd          }	 ddlm}m} ddlm} |	                    t                      	          } ||          } |||
          }	|                                }
|	                    |
           n+# t          $ r}t          d| d           Y d}~dS d}~ww xY w|r|	                    |
          }t          d|j        pd ddz              |r|D ]}t          d|            nt          d           |	                    |
          }t          d|j         ddz              |                    d          rt          |d                    nI|                    d          rt          |d                    nt          d           t          d           t                       dS |smt          d           t          d|j        pd            t          d|j                    t                       t          d           t          d           dS ddlm}  ||                                          }|                                st          d| d           dS |                    d                                           }|st          d!| d           dS |j        }|	                    |
||"          }|r5t          d#|j         d$|
 d%           t          d&|j         d'           dS t          d(           dS ))z8Seed AI peer identity or show both peer representations.z:  No API key configured. Run 'hermes honcho setup' first.
NfileshowFr   r:   rM  r=   rO  z  Honcho connection failed: rS   z
User peer (r   r4  r-  rN   z:  No user peer card yet. Send a few messages to build one.z

AI peer (rR  r[  z  No representation built yet.z2  Run 'hermes honcho identity <file>' to seed one.u   
Honcho identity management
────────────────────────────────────────z  User peer: r   uK       hermes honcho identity --show        — show both peer representationsuW       hermes honcho identity <file>        — seed AI peer from SOUL.md or any .md/.txt
r   z  File not found: ru   rv   z  File is empty: sourcez  Seeded AI peer identity from z into session ''z$  Honcho will incorporate this into z's representation over time.
z3  Failed to seed identity. Check logs for details.
)r%   r   rU   r6  r?   r;   r<   rU  rN  r@   rT   r   rV  rE   rW  r3   rX  rD   r&   pathlibr   
expanduserrx   r{   r   rb   seed_ai_identity)rX   r,   	file_pathr  r;   r<   rN  rF   rG   rY  rZ  rd   	user_cardr\  r]  r   rg   contentr  oks                       r4   cmd_identityr    s   
..CC   KLLLfd++I4''D
VVVVVVVVFFFFFF!44)++4FF""4((""&>>>//11+&&&&   2Q222333  %%k22	>dn9	>>>KLLL 	P! # #k4kk""""# NOOO **;77-DL---
:;;;::&'' 	H&)*++++ZZ 	H&.!!!!2333FGGG ;<<<;dn9	;;<<<,dl,,---[\\\hiiiY""$$A88:: (1((()))kk7k++1133G '!'''(((VF			k76		B	BB	 FUUU{UUUVVVaT\aaabbbbbDEEEEEs   A1C 
C,C''C,c                R   ddl m}  |t          j                              } |j                    dz  }ddg}g d}g }g }|D ];}||fD ]4}	|	|z  }
|
                                r|
|vr|                    |
           5<|D ];}||fD ]4}	|	|z  }
|
                                r|
|vr|                    |
           5<t                      }t          t          |                    }t          d           t                       t          d           t          d	           t          d
           t          d           t          d           t                       t          d           t                       |rPt          |d                   dk    rd|d         dd          nd}t          d|            t          d           nt          d           t          d           t                       t          d           t          d           t          d           t                       t          dd          }|                                dv rAt          |            t                      }t          |                    dd                    }nt                       t          d            t                       t          d!           t                       |s|rs|r7t          d"t          |           d#           |D ]}t          d$|            |r7t          d%t          |           d&           |D ]}t          d$|            n-t          d'           t          d(           t          d)           t                       t          d*           t                       t          d+           t          d,           t          d-           t                       |rt          d.d/                    d0 |D                                   t                       t          d1           t          d2           t          d3           t                       t          d4           |D ]}t          d5           |r2t          d6d          }|                                dv r		 dd7lm}m}m} dd8lm}  |             |                                } ||          } |||9          }|                                }|                    |           t5          d: |D                       }d;}|D ]}	|                    ||	          rd<}|r&t          d=d/                    |                      nt          d>           nI# t8          $ r}t          d?|            Y d}~n(d}~ww xY wnt          d@           nt          dA           t                       t          dB           t                       t          dC           t          dD           t          dE           t                       t          dF           t          dG           t          dH           t          dI           t                       |rt          d.d/                    dJ |D                                   t                       |r/t          dKd          }|                                dv r	 dd7lm}m}m} dd8lm}  |             |                                } ||          } |||9          }|                                }|                    |           |D ]i}|                    dLM                                          }|r=|                    |||j         N          }|rdOndP}t          d$|j          dQ|            jno# t8          $ r}t          d?|            Y d}~nNd}~ww xY wnEt          dR           |D ]}t          dS|            nt          dT           t          dU           t                       t          dV           t                       t          dW           t          dX           t          dY           t          dZ           t                       t          d[           t          d\           t          d]           t          d^           t                       t          d_           t          d`           t          da           t          db           t                       t          dc           t          dd           t          de           t          df           t          dg           t          dh           t                       t          di           t          dj           t          dk           t          dl           t                       t          dm           t                       |st          dn           t          do           nZt          dp           t          dq           t          dr           t          ds           t          dt           t          du           t                       dS )vuI   Step-by-step migration guide: OpenClaw native memory → Hermes + Honcho.r   r   z	.openclawzUSER.mdz	MEMORY.md)zSOUL.mdzIDENTITY.mdz	AGENTS.mdzTOOLS.mdzBOOTSTRAP.mdu   
Honcho migration: OpenClaw native memory → Hermes
──────────────────────────────────────────────────zA  OpenClaw's native memory stores context in local markdown fileszE  (USER.md, MEMORY.md, SOUL.md, ...) and injects them via QMD search.zH  Honcho replaces that with a cloud-backed, LLM-observable memory layer:zF  context is retrieved semantically, injected automatically each turn,zD  and enriched by a dialectic reasoning layer that builds over time.zStep 1  Create a Honcho accountr   r   r   r   Nr   z%  Honcho API key already configured: z  Skip to Step 2.zF  Honcho is a cloud memory service that gives Hermes persistent memoryz1  across sessions. You need an API key to use it.z/  1. Get your API key at https://app.honcho.devz  2. Run:  hermes honcho setupz!     Paste the key when prompted.z   Run 'hermes honcho setup' now?r   rO   r   rM   zE  Run 'hermes honcho setup' when ready, then re-run this walkthrough.z&Step 2  Detected OpenClaw memory filesz  User memory (u*    file(s)) — will go to Honcho user peer:rT  z  Agent identity (u(    file(s)) — will go to Honcho AI peer:z?  No OpenClaw native memory files found in cwd or ~/.openclaw/.z@  If your files are elsewhere, copy them here before continuing,z?  or seed them manually:  hermes honcho identity <path/to/file>u6   Step 3  Migrate user memory files → Honcho user peerzE  USER.md and MEMORY.md contain facts about you that the agent shouldzH  remember across sessions. Honcho will store these under your user peerzD  and inject relevant excerpts into the system prompt automatically.z	  Found: r  c              3  $   K   | ]}|j         V  d S r   rb   r   fs     r4   r   zcmd_migrate.<locals>.<genexpr>  s$      #?#?qAF#?#?#?#?#?#?r6   zC  These are picked up automatically the first time you run 'hermes'z6  with Honcho configured and no prior session history.z>  (Hermes calls migrate_memory_files() on first session init.)z=  If you want to migrate them now without starting a session:uA       hermes honcho migrate  — this step handles it interactivelyz)  Upload user memory files to Honcho now?r   rM  rO  c              3  >   K   | ]}t          |j                  V  d S r   )r   r   r  s     r4   r   zcmd_migrate.<locals>.<genexpr>  s*      )L)LA#ah--)L)L)L)L)L)Lr6   FTz#  Uploaded user memory files from: z<  Nothing uploaded (files may already be migrated or empty).z
  Failed: z9  Run 'hermes honcho setup' first, then re-run this step.z9  No user memory files detected. Nothing to migrate here.u1   Step 4  Seed AI identity files → Honcho AI peerzD  SOUL.md, IDENTITY.md, AGENTS.md, TOOLS.md, BOOTSTRAP.md define thezD  agent's character, capabilities, and behavioral rules. In OpenClawz:  these are injected via file search at prompt-build time.zC  In Hermes, they are seeded once into Honcho's AI peer through thezD  observation pipeline. Honcho builds a representation from them andzF  from every subsequent assistant message (observe_me=True). Over timezD  the representation reflects actual behavior, not just declaration.c              3  $   K   | ]}|j         V  d S r   r  r  s     r4   r   zcmd_migrate.<locals>.<genexpr>  s$      #@#@qAF#@#@#@#@#@#@r6   z/  Seed AI identity from all detected files now?ru   rv   r  seededfailedr   z6  Run 'hermes honcho setup' first, then seed manually:z    hermes honcho identity z#  No agent identity files detected.z=  To seed manually:  hermes honcho identity <path/to/SOUL.md>z/Step 5  What changes vs. OpenClaw native memoryz	  StoragezL    OpenClaw: markdown files on disk, searched via QMD at prompt-build time.zI    Hermes:   cloud-backed Honcho peers. Files can stay on disk as sourcez=              of truth; Honcho holds the live representation.z  Context injectionzH    OpenClaw: file excerpts injected synchronously before each LLM call.zK    Hermes:   Honcho context fetched async at turn end, injected next turn.zL              First turn has no Honcho context; subsequent turns are loaded.z  Memory growthz7    OpenClaw: you edit files manually to update memory.zG    Hermes:   Honcho observes every message and updates representationszG              automatically. Files become the seed, not the live store.z;  Honcho tools (available to the agent during conversation)uQ       honcho_context   — session context: summary, representation, card, messagesu@       honcho_search        — semantic search over stored contextu4       honcho_profile       — fast peer card snapshotuF       honcho_reasoning     — ask Honcho a question, synthesized answeruC       honcho_conclude      — write a conclusion/fact back to memoryz  Session naminguA       OpenClaw: no persistent session concept — files are global.uF       Hermes:   per-session by default — each run gets its own sessionzB              Map a custom name:  hermes honcho map <session-name>zStep 6  Next stepsuF     1. hermes honcho setup              — configure API key (required)uA     2. hermes honcho migrate            — re-run this walkthroughuB     1. hermes honcho status             — verify Honcho connectionu9     2. hermes                           — start a sessionzF     (user memory files auto-uploaded on first turn if not done above)uG     3. hermes honcho identity --show    — verify AI peer representationuL     4. hermes honcho tokens             — tune context and dialectic budgetsuD     5. hermes honcho mode               — view or change memory mode)!r  r   r'   rv  r8  rx   r(  r%   r   r   rU   r   r   r   r!  r&   r  r?   r;   r<   r   rU  rN  r@   r   rV  r   migrate_memory_filesrE   r{   r   r  rb   )rX   r   ry  openclaw_homeuser_file_namesagent_file_names
user_filesagent_filesrb   drg   r,   r.   r  r   r  r;   r<   r   rN  rF   rG   rY  rZ  dirs_with_filesany_uploadedrd   r  r  statuss                                 r4   cmd_migrater  7  s     $ry{{

CDIKK+-M !+.OZZZJ K % %}% 	% 	%ADAxxzz %az11!!!$$$	% ! & &}% 	& 	&ADAxxzz &a{22""1%%%	&
 ..C#C(())G	
PQQQ	GGG	
MNNN	
QRRR	
TUUU	
RSSS	
PQQQ	GGG 

+,,,	GGG [/23x=/A/AA/E/E+s8}RSS)+++5>f>>???!""""VWWWABBB?@@@.///1222;SIII<<>>\))dOOO..C3778R0011GGGGGYZZZ 
GGG	
2333	GGG Q[ Q 	"_C
OO___``` " "jQjj!!!! 	"as;'7'7aaabbb  " "jQjj!!!!OPPPPQQQOPPP 
GGG	
BCCC	GGG	
QRRR	
TUUU	
PQQQ	GGG *KA$))#?#?J#?#?#???AABBBSTTTFGGGNOOOMNNN 	W 	WAUVVVV 	OHRUVVVF||~~--,         
 SRRRRR'')))-@@BBD..t44F..fTJJJC"&";";"="=K%%k222&))L)L)L)L)L&L&LO#(L, 0 033KCC 0+/L# ^`DIIoD^D^``aaaa\]]]  , , ,*q**++++++++,3 .8 MNNNNIJJJ 
GGG	
=>>>	GGG	
PQQQ	
PQQQ	
FGGG	GGG	
OPPP	
PQQQ	
RSSS	
PQQQ	GGG "OB$))#@#@K#@#@#@@@BBCCC 	9NX[\\\F||~~--,         
 SRRRRR'')))-@@BBD..t44F..fTJJJC"&";";"="=K%%k222( = ="#++w+"?"?"E"E"G"G" =!$!5!5k7STSY!5!Z!ZB13%AXXF!";";";6";";<<<= ! , , ,*q**++++++++,+ .0 JKKK  9 97A7788889 	3444MNNN 
GGG	
;<<<	GGG	+	
XYYY	
UVVV	
IJJJ	GGG	
   	
TUUU	
WXXX	
XYYY	GGG	
	
CDDD	
STTT	
STTT	GGG	
GHHH	
]^^^	
LMMM	
@AAA	
RSSS	
OPPP	GGG	
	
MNNN	
RSSS	
NOOO 
GGG	
	GGG 	VVWWWQRRRRRSSSIJJJVWWWWXXX\]]]TUUU	GGGGGs2   7CV 
V< V77V<;C_ 
_=!_88_=c                v   t          | dd          at          | dd          }|dk    r1t          d           t          d           ddlm}  |d	           dS |t          |            dS |d
k    rt          |            dS |dk    rt          |            dS |dk    rt          |            dS |dk    rt          |            dS |dk    rt          |            dS |dk    rt          |            dS |dk    rt          |            dS |dk    rt          |            dS |dk    rt          |            dS |dk    rt          |            dS |dk    rt          |            dS |dk    rt!          |            dS |dk    rt#          |            dS t          d|            t          d           dS )zRoute honcho subcommands.target_profileNhoncho_commandsetupz7
  Honcho is configured via the memory provider system.z#  Running 'hermes memory setup'...
r   )cmd_setup_providerr   r  peersru  maprC   r  r  tokensidentitymigrateenabledisablesyncz  Unknown honcho command: zk  Available: status, sessions, map, peer, mode, strategy, tokens, identity, migrate, enable, disable, sync
)r6  rl   rU   hermes_cli.memory_setupr  rK  rs  rz  r  r  r  r  r  r  r  r[   r]   rh   )rX   r  r  s      r4   r  r    s'     &6==
$($
/
/C
g~~HIII4555>>>>>>8$$$	4	4	$	
		T				
		T	4	
		T				D	4				D	0300111|}}}}}r6   c                T   |                      dddd           |                     d          }|                    dd	
           |                    dd
          }|                     ddd           |                    dd
           |                    dd
           |                    dd
          }|                     dddd           |                    dd
          }|                     ddd            |                     d!dd"            |                     d#d$d%d&'           |                    d(d)
          }|                     d(dd*d+d,-           |                    d.d/
          }|                     d.dd0d1d2-           |                    d3d4
          }|                     d5t          d6d78           |                     d9t          d6d:8           |                    d;d<
          }|                     d=ddd>           |                     d?dd@           |                    dAdB
           |                    dCdD
           |                    dEdF
           |                    dGdH
           |                     t
          I           dS )JzBuild the ``hermes honcho`` argparse subcommand tree.

    Called by the plugin CLI registration system during argparse setup.
    The *subparser* is the parser for ``hermes honcho``.
    z--target-profileNAMEr  z;Target a specific profile's Honcho config without switching)metavardesthelpr  )r  r  z7Initial Honcho setup (redirects to hermes memory setup))r  r  z0Show current Honcho config and connection statusz--all
store_truez(Show config overview across all profiles)actionr  r  z(Show peer identities across all profilesru  z"List known Honcho session mappingsr  zGMap current directory to a Honcho session name (no arg = list mappings)r}  ?NzMSession name to associate with this directory. Omit to list current mappings.)nargsrP   r  rC   z7Show or update peer names and dialectic reasoning levelz--userzSet user peer name)r  r  z--aizSet AI peer namez--reasoningLEVELr   zCSet default dialectic reasoning level (minimal/low/medium/high/max))r  choicesr  r  z.Show or set recall mode (hybrid/context/tools)MODEr   z@Recall mode to set (hybrid/context/tools). Omit to show current.)r  r  r  r  r  zHShow or set session strategy (per-session/per-directory/per-repo/global)STRATEGYr  z.Session strategy to set. Omit to show current.r  z2Show or set token budget for context and dialecticz	--contextNz9Max tokens Honcho returns from session.context() per turn)typer  r  z--dialecticz:Max chars of dialectic result to inject into system promptr  z9Seed or show the AI peer's Honcho identity representationr  z=Path to file to seed from (e.g. SOUL.md). Omit to show usage.z--showz/Show current AI peer representation from Honchor  zBStep-by-step migration guide from openclaw-honcho to Hermes Honchor  z$Enable Honcho for the active profiler  z%Disable Honcho for the active profiler  z+Sync Honcho config to all existing profiles)func)add_argumentadd_subparsers
add_parserri   set_defaultsr  )		subparsersubsstatus_parser
map_parserpeer_parsermode_parserstrategy_parsertokens_parseridentity_parsers	            r4   register_clir  J  s    F1AJ     ##)9#::DOOF    
 OOI $  M +U     	OOG"LOMMMOOJ%IOJJJ] !  J c4\    
 //N "  K Xv<PQQQVV:LMMMw;R     //E "  K c6.O     ooc &  O   #zF= !    OOK $  M #sH     CI    
 ooT &  O   c4L !      > !   
 	OOQ     	OOH#IOJJJOOI$KOLLLOOF!NOOOO/////r6   )r   r   r   r   r   )r7   r8   r   r   )r   rH   )r   ri   )r   r   )r   r   )r   rs   )r,   rs   r|   r}   r   rH   )r,   rs   r   r   )NF)rY   r   rP   r8   r   r   r   r   )r   r   )r   r&  )1__doc__
__future__r   ry   r'   r   r  r   hermes_constantsr   r?   r   r	   r
   r   r   r5   r+   r[   r]   rh   rk   rl   __annotations__rT   rW   rr   r%   r*   r   r   r   r!  r%  r*  rK  rA  r7  rs  rz  r  r  r  r  r  r  r  r  r  ro   r6   r4   <module>r     sh    
 # " " " " "  				 



       , , , , , , W W W W W W W W W W % % % % % %5 5 5 5p    *(, (, (, (,V, , , ,"+ + + +\   : !%  $ $ $ $! ! ! !! ! ! !
- - - -              F" " " " "    <dT dT dT dTN      8P1 P1 P1 P1f$3 $3 $3 $3N% % % %4   "   &8 8 8 8250 50 50 50pH H H HD T  T  T  TF)0 )0 )0 )0XGF GF GF GFTb b b bJ+~ +~ +~ +~\a0 a0 a0 a0 a0 a0r6   