Repository navigation
fix(home): resolve user home via getUserHome everywhere for Windows - #309
Merged
Merged
Conversation
5 of 9 tasks
PR #301 introduced getUserHome() (HOME → USERPROFILE → os.homedir) but only wired it into types.ts. The rest of the codebase still read a bare `process.env.HOME`, so on a normal Windows session (where only USERPROFILE is set) `teamai init` printed "Local config saved to undefined/..." and then crashed with ERR_INVALID_ARG_TYPE — the exact failure reported on #301. Route every remaining home lookup through getUserHome(). Because it now always returns a non-empty path, drop the dead `if (!home)` guards it made unreachable (including one in uninstall.ts that used to abort the whole command when HOME was unset — i.e. uninstall was fully broken on Windows). Fix getVotesLocalDir(), the import/recall/search-index paths and the debug-log path to build with path.join instead of a hardcoded "/" separator. Harden getUserHome() with a final os.tmpdir() fallback: os.homedir() is documented to return '' when the home can't be resolved, which would make every derived path cwd-relative; the guarantee of a non-empty absolute path is what lets the callers above drop their guards safely. Add a guard test that fails if any source file outside utils/home.ts reads process.env.HOME directly, plus USERPROFILE- and tmpdir-fallback regression tests. Co-Authored-By: Claude Fable 5 <[email protected]>
jeff-r2026
force-pushed
the
worktree-fix-windows-home
branch
from
August 24, 2026 07:11
0f793d3 to
d8ad12d
Compare
Collaborator
Author
|
Ran an adversarial self-review across all 30 changed files (semantic-equivalence + mechanical-correctness passes). Both came back clean — every site is either behavior-preserving or a genuine bug fix. Pushed one hardening change on top:
Verification: |
4 tasks done
jeff-r2026
added a commit
that referenced
this pull request
Aug 24, 2026
…ome (#310) Follow-up to #309. That PR ended getUserHome()'s fallback chain with `|| os.tmpdir()` to guarantee a non-empty path. But callers join the result onto `.teamai/...` to write credentials (api-key.ts) and to resolve and execute a node binary (builtin-hooks.ts resolveCodebuddyNode/resolveWorkbuddyNode), so falling back to a world-writable shared directory is a code-execution and credential-exposure vector: an attacker who can write /tmp/.codebuddy-server/.../node would get their binary run. Throw when none of HOME, USERPROFILE, or os.homedir() resolves instead. The empty-string case os.tmpdir() was guarding against (cwd-relative paths) is also covered by throwing. On any real machine at least one of the three is set, so this path is only reached in pathological contexts (passwd-less uid, `env -i`) where refusing to run is the correct, safe behavior. Update the regression test to assert the throw. Co-authored-by: Claude Fable 5 <[email protected]>
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
…encent#309) PR Tencent#301 introduced getUserHome() (HOME → USERPROFILE → os.homedir) but only wired it into types.ts. The rest of the codebase still read a bare `process.env.HOME`, so on a normal Windows session (where only USERPROFILE is set) `teamai init` printed "Local config saved to undefined/..." and then crashed with ERR_INVALID_ARG_TYPE — the exact failure reported on Tencent#301. Route every remaining home lookup through getUserHome(). Because it now always returns a non-empty path, drop the dead `if (!home)` guards it made unreachable (including one in uninstall.ts that used to abort the whole command when HOME was unset — i.e. uninstall was fully broken on Windows). Fix getVotesLocalDir(), the import/recall/search-index paths and the debug-log path to build with path.join instead of a hardcoded "/" separator. Harden getUserHome() with a final os.tmpdir() fallback: os.homedir() is documented to return '' when the home can't be resolved, which would make every derived path cwd-relative; the guarantee of a non-empty absolute path is what lets the callers above drop their guards safely. Add a guard test that fails if any source file outside utils/home.ts reads process.env.HOME directly, plus USERPROFILE- and tmpdir-fallback regression tests. Co-authored-by: Claude Fable 5 <[email protected]>
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
…ome (Tencent#310) Follow-up to Tencent#309. That PR ended getUserHome()'s fallback chain with `|| os.tmpdir()` to guarantee a non-empty path. But callers join the result onto `.teamai/...` to write credentials (api-key.ts) and to resolve and execute a node binary (builtin-hooks.ts resolveCodebuddyNode/resolveWorkbuddyNode), so falling back to a world-writable shared directory is a code-execution and credential-exposure vector: an attacker who can write /tmp/.codebuddy-server/.../node would get their binary run. Throw when none of HOME, USERPROFILE, or os.homedir() resolves instead. The empty-string case os.tmpdir() was guarding against (cwd-relative paths) is also covered by throwing. On any real machine at least one of the three is set, so this path is only reached in pathological contexts (passwd-less uid, `env -i`) where refusing to run is the correct, safe behavior. Update the regression test to assert the throw. Co-authored-by: Claude Fable 5 <[email protected]>
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.
Problem
Reported by @MyNameisPI on #301: on a normal Windows PowerShell session,
teamai init git@…fails withWindows commonly exposes only
USERPROFILE, notHOME. #301 addedgetUserHome()(HOME→USERPROFILE→os.homedir()) but only wired it intotypes.ts. Every other module still read a bareprocess.env.HOME, which on Windows isundefined—?? ''silently degrades to a relative path, and a non-null assertion crashes.Fix
getUserHome()(30 source files).getUserHome()now always returns a non-empty path, so drop the deadif (!home)guards it made unreachable, and remove a stale Chinese error string inuninstall.ts(violated the English-output rule).getVotesLocalDir()to build its path withpath.joininstead of a hardcoded/separator (also Windows-incorrect).utils/home.tsreadsprocess.env.HOMEdirectly, preventing regressions.USERPROFILE-fallback regression test.Test Plan
npx tsc --noEmit— cleannpx vitest run— 2140 passed (159 files)npm run build— successprocess.env.HOMEremains in production codeHOMEunset and onlyUSERPROFILEset —teamai doctorruns and resolves~/.teamai/...correctly instead of crashing🤖 Generated with Claude Code