
    jh j                         U d Z ddlZddlmZmZ ddlmZ ddlmZ  e	            Z
eed<    ede
          Zeed	<   d
edz  defdZddZdefdZdefdZdedz  fdZdS )a>  Single source of truth for the agent working directory.

`TERMINAL_CWD` is the runtime carrier for the configured working directory
(design #19214/#19242: `terminal.cwd` is bridged once to `TERMINAL_CWD` at
gateway/cron startup). The local-CLI backend deliberately leaves it unset and
relies on the launch dir. Reading it in one place keeps the system prompt, the
tool surfaces, and context-file discovery agreeing on where the agent lives.

Multi-session gateways can pin a logical cwd via the `_SESSION_CWD`
contextvar; CLI/cron fall through to `TERMINAL_CWD`/launch cwd.
    N)
ContextVarToken)Path)Any_UNSETHERMES_SESSION_CWD)default_SESSION_CWDcwdreturnc                 ^    t                               | pd                                          S )z,Pin the logical cwd for the current context. )r
   setstrip)r   s    6/home/ubuntu/.hermes/hermes-agent/agent/runtime_cwd.pyset_session_cwdr      s&    SYB--//000    c                  :    t                               d           d S Nr   )r
   r    r   r   clear_session_cwdr      s    Rr   c                      t                                           } | t          u rdS t          |                                           S r   )r
   getr   strr   )values    r   _session_cwd_overrider       s9    Eru::r   c                     t                      } | r7t          |                                           }|                                r|S t          j                            dd                                          }|r7t          |                                          }|                                r|S t          t	          j                              S NTERMINAL_CWDr   )	r   r   
expanduseris_dirosenvironr   r   getcwd)overridepraws      r   resolve_agent_cwdr(   '   s    $&&H NN%%''88:: 	H
*..
,
,
2
2
4
4C
 II  ""88:: 	H	r   c                     t                      } | r!t          |                                           S t          j                            dd                                          }|r!t          |                                          nd S r   )r   r   r    r"   r#   r   r   )r%   r'   s     r   resolve_context_cwdr*   5   sr    
 %&&H +H~~((***
*..
,
,
2
2
4
4C%(2499!!!d2r   )r   N)__doc__r"   contextvarsr   r   pathlibr   typingr   objectr   __annotations__r
   r   r   r   r   r(   r*   r   r   r   <module>r1      s*  
 
 
 
			 ) ) ) ) ) ) ) )            fhh   %:&:FKKKj K K K1t 1 1 1 1 1
   s    4    	3TD[ 	3 	3 	3 	3 	3 	3r   