From 574122884a616f5347e2208c1b7632198fdb91de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 27 Aug 2026 11:34:45 -0400 Subject: [PATCH] fix(windows): resolve the home directory via the standard lookup Port of upstream grok-build 1.0.4/1.0.5. Two paths read $HOME only, which is usually unset on Windows outside Git Bash: - the global-gitignore fallback (prompt/ignore.rs) now uses std::env::home_dir(), the crate-wide idiom; - fast-worktree's resolve_kigi_home falls back to std::env::home_dir() with the same dunce canonicalization, eliminating the documented divergence from kigi_config::default_kigi_home. On Unix home_dir() reads $HOME first, so behavior is unchanged where HOME is set. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01KSy9S31pZNWXtRZNVJ1sDf --- crates/codegen/kigi-agent/src/prompt/ignore.rs | 2 +- crates/codegen/kigi-fast-worktree/src/db/mod.rs | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/codegen/kigi-agent/src/prompt/ignore.rs b/crates/codegen/kigi-agent/src/prompt/ignore.rs index 7ac0b9f..a1e90ef 100644 --- a/crates/codegen/kigi-agent/src/prompt/ignore.rs +++ b/crates/codegen/kigi-agent/src/prompt/ignore.rs @@ -32,5 +32,5 @@ fn get_global_gitignore_path() -> Option { git2::Config::open_default() .ok() .and_then(|cfg| cfg.get_path("core.excludesFile").ok()) - .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".gitignore"))) + .or_else(|| std::env::home_dir().map(|h| h.join(".gitignore"))) } diff --git a/crates/codegen/kigi-fast-worktree/src/db/mod.rs b/crates/codegen/kigi-fast-worktree/src/db/mod.rs index c374a16..de57447 100644 --- a/crates/codegen/kigi-fast-worktree/src/db/mod.rs +++ b/crates/codegen/kigi-fast-worktree/src/db/mod.rs @@ -341,12 +341,14 @@ pub fn resolve_kigi_home() -> Result { if let Ok(v) = std::env::var("KIGI_SHARE_DIR") { return Ok(PathBuf::from(v)); } - let home = - PathBuf::from(std::env::var("HOME").context("neither $KIGI_SHARE_DIR nor $HOME is set")?); - // Canonicalize the home dir so worktree paths share the same physical .kigi - // tree as trust/hooks even when it is symlinked. The dunce canonicalization - // must stay in sync with kigi_config::default_kigi_home(); - // home resolution deliberately differs ($HOME here vs std::env::home_dir()). + // Standard home-dir lookup (`USERPROFILE`/Known Folders on Windows, where + // `HOME` is usually unset outside Git Bash) — the same resolution as + // kigi_config::default_kigi_home(), so worktree paths land in the same + // physical .kigi tree as trust/hooks. + let home = std::env::home_dir() + .context("neither $KIGI_SHARE_DIR nor a home directory could be resolved")?; + // Canonicalize so a symlinked home still maps to one physical tree; the + // dunce canonicalization must stay in sync with default_kigi_home(). Ok(dunce::canonicalize(&home).unwrap_or(home).join(".kigi")) }