fix(paths): prefer LOCALAPPDATA over HOME for state_dir on Windows - #130
ziyaad-mallick wants to merge 2 commits into
Conversation
state_dir() tested HOME before its own _WIN32 block, so on any Windows machine where HOME is set -- MSYS2, Git Bash, and anything launched from them -- state resolved to %USERPROFILE%/.local/state/runanywhere and the LOCALAPPDATA branch was unreachable. Native cmd.exe and PowerShell do not set HOME, so the intended path only ever applied there. The existing separator case in test_state_dir unsets HOME to reach the Windows branch, which is why this never showed up in CI. Moving the Windows block ahead of HOME makes the platform branch win on the platform it is for. XDG_STATE_HOME stays first as an explicit override on every platform, and non-Windows builds are unchanged. For an existing MSYS2 / Git Bash user this moves everything kept under state_dir() -- REPL history, shim.log and the seeded Claude Code config dir -- to %LOCALAPPDATA%/RunAnywhere/state. Nothing is migrated; the config dir re-seeds from ~/.claude on the next launch. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
docs/EDITORS.md sends people to ~/.local/state/runanywhere/ for shim.log, and the state_dir() contract in cli_paths.h says the same. With the previous commit that is never the answer on Windows unless XDG_STATE_HOME is set: state lands under %LOCALAPPDATA%\RunAnywhere\state even from Git Bash, where HOME is set. Say so in both places. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughWindows state directory resolution now prioritizes ChangesWindows state directory resolution
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to Windows environments with HOME set now use LOCALAPPDATA for state and related logs, matching the documented behavior; no merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
state_dir()insrc/config/cli_paths.cppchecksHOMEbefore its own#if defined(_WIN32)block:So whether the Windows branch runs at all depends on whether
HOMEhappens tobe set. On a Windows 11 Pro x64 machine:
HOMEstate_dir()resolves to%LOCALAPPDATA%/RunAnywhere/state(intended)/c/Users/<user>$HOME/.local/state/runanywhere(POSIX layout on Windows)Anyone running
wallyfrom Git Bash, MSYS2, or a tool launched from one gets aPOSIX-shaped state directory under the user profile, and the
LOCALAPPDATA/USERPROFILEbranches are unreachable for them.Change
Move the
_WIN32block ahead of theHOMEcheck.XDG_STATE_HOMEstays firstas an explicit override on every platform. Non-Windows builds are unchanged:
the moved block is compiled out there, so the order is still
XDG_STATE_HOME->HOME.A second commit updates the two places that describe the location:
docs/EDITORS.md(where to findshim.log) and thestate_dir()comment insrc/config/cli_paths.h. Both named only~/.local/state/runanywhere, which isno longer the answer on Windows unless
XDG_STATE_HOMEis set.Why CI did not catch this
The Windows case already in
test_state_dir()(the backslashedLOCALAPPDATAcase from #58) explicitly unsets
HOMEbefore callingstate_dir(), so itreaches the Windows branch regardless of the ordering. This PR adds a second
_WIN32case withHOMEset alongsideLOCALAPPDATAand assertsLOCALAPPDATAwins. It runs on the existingwindows-2022andwindows-11-armctest jobs.Behaviour change for existing users
For a user who has been running from Git Bash / MSYS2, everything kept under
state_dir()moves from~/.local/state/runanywhereto%LOCALAPPDATA%/RunAnywhere/state: REPL history (cmd_run),shim.log(
anthropic/messages.cpp), and the seeded Claude Code config dir(
cmd_editors.cpp,state_dir() + "/claude"). Nothing is migrated. The configdir re-seeds from
~/.claudeon the next launch (itsfirst_runpath); the oldhistory and log are simply left behind. If you would rather keep existing
MSYS2 users where they are, say so and I will add a fallback that prefers an
already-existing
$HOME/.local/state/runanywhere, but that seemed like morecode than the problem deserves.
Tested
Windows 11 Pro x64, MinGW-w64 g++ 15.2.0 (MSYS2 Rev10). Full
ctestwasnot run: building the test binary needs the pinned SDK kit (protobuf +
rac/*headers), which is not on this machine. Instead I compiled the realsrc/config/cli_paths.cppagainst a one-line stub for its SDK include(
rac_desktop_default_base_dir, used only byresolve_home, not bystate_dir), and extracted theEnvVarhelper andtest_state_dir()verbatim from
tests/test_wally_unit.cppwithsedinto a throwawayharness (
main()just runstest_state_dir()and prints the result).Build (same for each variant,
-Wall, no warnings):main'scli_paths.cpp+ this PR'stest_state_dir()(red):This PR's
cli_paths.cpp+ this PR'stest_state_dir()(green):Same result with
HOMEunset in the calling shell (env -u HOME): red onmain, green on the branch.main's own unmodifiedtest_state_dir()alsopasses against
main's source ([PASS] state_dir, exit 0), confirming theexisting case does not exercise this ordering.
UNVERIFIED:
wally infooutput end to end from Git Bash (no full build here).🤖 Generated with Claude Code
Summary by cubic
Fixes Windows state directory resolution so
LOCALAPPDATAis preferred overHOMEwhen both are set (as in MSYS2/Git Bash), and updates the docs andstate_dir()comment to name the Windows path.Bug Fixes
_WIN32, checkLOCALAPPDATA/USERPROFILEbeforeHOMEso Windows builds no longer fall back to a POSIX-shaped path (~/.local/state/runanywhere);XDG_STATE_HOMEstill wins first on all platforms.HOMEset alongsideLOCALAPPDATAto guard this ordering.Migration
state_dir()(REPL history,shim.log, seeded Claude config dir) moves to%LOCALAPPDATA%\RunAnywhere\state; nothing is migrated, and the config dir re-seeds from~/.claudeon next launch.Written for commit 66ab335. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
%LOCALAPPDATA%\RunAnywhere\state, including whenHOMEis set through environments such as MSYS2 or Git Bash.XDG_STATE_HOMEsettings and non-Windows platforms.Documentation