This commit is contained in:
Dylan Hurd
2025-11-03 20:54:39 -08:00
parent 86d636cf33
commit c9c5d694c9
2 changed files with 10 additions and 6 deletions

View File

@@ -256,9 +256,14 @@ fn operating_system_info_impl() -> Option<OperatingSystemInfo> {
#[cfg(not(target_os = "macos"))]
fn has_wsl_env_markers() -> bool {
std::env::var_os("WSL_INTEROP").is_some()
|| std::env::var_os("WSLENV").is_some()
|| std::env::var_os("WSL_DISTRO_NAME").is_some()
// Cache detection result since env vars are stable across process lifetime
// and this function may be called multiple times.
static CACHE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*CACHE.get_or_init(|| {
std::env::var_os("WSL_INTEROP").is_some()
|| std::env::var_os("WSLENV").is_some()
|| std::env::var_os("WSL_DISTRO_NAME").is_some()
})
}
#[cfg(test)]

View File

@@ -77,12 +77,11 @@ fn default_env_context_str(cwd: &str, shell: &Shell) -> String {
let os_block = operating_system_context_block();
format!(
r#"<environment_context>
<cwd>{}</cwd>
<cwd>{cwd}</cwd>
<approval_policy>on-request</approval_policy>
<sandbox_mode>read-only</sandbox_mode>
<network_access>restricted</network_access>
{}{}</environment_context>"#,
cwd, shell_line, os_block
{shell_line}{os_block}</environment_context>"#
)
}