fix(core): use os.homedir() instead of trusting HOME env var - #434
Merged
Conversation
getHomeDir() prioritized process.env.HOME, which Git Bash/MSYS shells can mistranslate into a bare drive root (e.g. "C:\") if HOME is misconfigured — causing user-scope sync to treat the whole drive as home and walk into permission-restricted system folders. os.homedir() ignores HOME on Windows entirely, so it's immune to this failure mode. Also updates the ~16 tests that stub HOME to sandbox user-scope behavior in a temp dir, since os.homedir() no longer reads it on Windows; added tests/helpers/env.ts to centralize the stub/restore logic across them. Closes #433
Deploying allagents with
|
| Latest commit: |
6261ebf
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e9c967d8.allagents.pages.dev |
| Branch Preview URL: | https://fix-433-home-dir-resolution.allagents.pages.dev |
This was referenced Jul 13, 2026
christso
added a commit
that referenced
this pull request
Jul 15, 2026
…-root plugin sources (#440) A user hit `EPERM: operation not permitted, scandir 'C:\$WinREAgent\...'` right after a successful `plugin uninstall`, on v1.13.2 (already past the #434 getHomeDir() fix). Root cause: their workspace.yaml had a corrupted plugin entry that was a bare `\`, which resolves to the drive root on Windows — walkForSkillMd (skills.ts) recursed into it unguarded (no try/catch, no symlink guard) and crashed the whole post-uninstall sync, even though uninstall itself had already succeeded. - walkForSkillMd now catches readdir errors and records a warning with remediation steps instead of throwing; also skips symlinks/junctions to avoid unbounded recursion through loops. Warnings thread through collectPluginSkills -> collectAllSkills/collectAvailableSkillNames -> SyncResult.warnings, deduplicated since the same bad plugin is scanned twice internally. - addPlugin/addUserPlugin now reject a local-path source that resolves to a filesystem root (new isFilesystemRoot helper), closing the entry point that let the bare `\` get written in the first place. - runUserSyncAndPrint (plugin.ts) was silently never printing the Warnings: section at all (unlike its project-scope sibling) - user-scope syncs were swallowing every warning, not just the new ones. Fixed to match runSyncAndPrint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getHomeDir()(src/constants.ts) prioritizedprocess.env.HOMEoverUSERPROFILE. Git Bash/MSYS shells setHOME, and MSYS mistranslates a misconfiguredHOME=/cinto the literal Windows pathC:\when spawningnode.exe. SincegetHomeDir()is the workspace root for every--scope useroperation, this madeallagentstreat the entireC:drive as "home" — a user hit this exactly, crashing withEPERM: operation not permitted, scandir 'C:\$WinREAgent\Scratch\Mount\Windows\System32\LogFiles\WMI\RtBackup'(a SYSTEM-only folder at the drive root).os.homedir(), which ignoresHOMEon Windows entirely (usesUSERPROFILE/native API), so it's immune to this failure mode.process.env.HOMEto a temp dir — a pattern that no longer takes effect on Windows onceHOMEis ignored. Addedtests/helpers/env.ts(stubHomeDir) to stub bothHOME/USERPROFILEcorrectly (and restore — deleting, not stringifyingundefinedinto — whichever wasn't originally set), and migrated all affected test files to use it.tests/unit/utils/plugin-path.test.tspreviously re-derived the oldHOME || USERPROFILEformula to compute an expected value; changed it to call the realgetHomeDir()so the test can't silently encode the same bug as production code.Closes #433
Root cause / investigation
Full writeup in #433, reproduced directly:
Test plan
tests/unit/constants.test.tsreproducing the bug against the old implementation (failed as expected)os.homedir()bun test— 1232 pass, 2 pre-existing failures unrelated to this change (Windows path-separator assertions intests/unit/core/repo-skills.test.ts, present onmaintoo)bun run typecheck— cleansuperpowers:code-reviewer— 3 findings, all addressed (platform-gated the new test since POSIXos.homedir()behaves differently, clarified an intentionally-discarded restore-fn return, minor comment cleanup)