Global npm install on macOS/Linux causes incorrect repo root resolution (/opt/homebrew instead of actual workspace)
Problem
When @evomap/evolver is installed globally via npm (e.g. npm install -g @evomap/evolver), the getRepoRoot() function walks upward from the package directory inside node_modules and stops at the first .git directory it finds. On macOS with Homebrew, this causes it to resolve to /opt/homebrew (Homebrew's own git repo) instead of the user's actual project workspace.
Impact
repoRoot→/opt/homebrewworkspaceRoot→/opt/homebrewmemoryDir→/opt/homebrew/memory(does not exist)evolutionDir→/opt/homebrew/memory/evolution(does not exist)
The evolver scans wrong session logs and produces evolution proposals for the wrong codebase.
Workaround
Set EVOLVER_REPO_ROOT env var explicitly:
<<key>EVOLVER_REPO_ROOT</key>
<string>/Users/allenrong/.openclaw/workspace</string>
Suggested Fix
When the evolver binary is installed inside a node_modules directory (global or local), detect this condition and either:
- Skip the
.gitauto-discovery entirely and require explicitEVOLVER_REPO_ROOT - Add a
node_modulesboundary in the upward walk so it never escapes the user's project - Prefer
process.env.HOMEorprocess.cwd()over git root when inside package manager directories
Environment
- OS: macOS 15.5 (arm64)
- Node: v26.0.0
- Evolver: v1.85.2
- Install method:
npm install -g @evomap/evolver
Verification
cd /opt/homebrew/lib/node_modules/@evomap/evolver && node -e "
const {getRepoRoot} = require('./src/gep/paths');
console.log(getRepoRoot()); // → /opt/homebrew ← wrong
"
@rongtianhua Thanks for the clean writeup — the impact section and the suggested fix matrix made triage essentially instant.
Confirmed root cause matches your analysis:
getRepoRoot() has two upward walks — one from process.cwd() and one from the package's own install directory — and both were unbounded. On macOS with Homebrew, the install lives at /opt/homebrew/lib/node_modules/@evomap/evolver and /opt/homebrew/.git exists (Homebrew is itself a git repo), so either walk can escape the package's own node_modules and resolve repoRoot to /opt/homebrew. Downstream workspaceRoot / memoryDir / evolutionDir all follow. No crash, just silent corruption — the review pipeline scans the wrong logs and produces evolution proposals for the wrong codebase.
The bug shows up in two distinct user paths, and ultimately the fix needed to cover both:
- Passive case — user runs
evolverfrom anywhere with no.gitin any ancestor (a fresh project beforegit init, a generic~/, an OpenClaw workspace). The cwd walk returns nothing, the ownDir walk escapes to/opt/homebrew. This is the case that actually bites real users in the wild. - Reporter-style active case — the exact snippet in the issue (
cd /opt/homebrew/lib/node_modules/@evomap/evolver && evolver). Here the cwd walk picks/opt/homebrew/.gitdirectly, before the ownDir walk even runs.
Your suggested fix #2 (node_modules boundary on the upward walk) is what landed. Both walks now stop at the parent of the nearest node_modules ancestor (inclusive — a .git at that boundary IS still picked up, so a local <project>/node_modules/@evomap/evolver install still resolves to <project> correctly). Dev clones (not inside any node_modules) keep the original unbounded behavior. EVOLVER_REPO_ROOT remains the explicit override.
Verified empirically against four layouts before merging:
| Case | Layout | Result |
|---|---|---|
| A | Passive (global install, cwd has no .git) |
install dir, no escape ✓ |
| B | Your verify snippet (cwd == install dir) | install dir, no escape ✓ |
| C | Local install, cwd has no .git |
resolves to user project root ✓ |
| D | User cdd into <project>/node_modules/<other-pkg> |
resolves to user project root ✓ |
Regression tests cover all four. The fix is targeted for v1.85.3, going out alongside the Codex session-end hotfix from #542.
Workaround until v1.85.3 ships: keep using EVOLVER_REPO_ROOT explicitly as you already are — that path is unaffected by either walk and has always been the canonical way to pin the workspace, so it'll remain stable across the upgrade too.
A small note on your "Verification" snippet, for posterity rather than as a correction: the cd /opt/homebrew/lib/node_modules/@evomap/evolver step makes the cwd walk pick /opt/homebrew/.git first, which is a slightly different code path than the passive case most users actually hit. The fix bounds both code paths, so your repro and the in-the-wild case both stop reproducing on v1.85.3 — but I wanted to flag the distinction so it doesn't confuse anyone diffing this issue against the patch.
I'll come back here to confirm once v1.85.3 is on npm.
Fixed in v1.87.2 (you were on 1.85.2). getRepoRoot() now bounds both upward .git walks at the parent of the nearest node_modules ancestor (_nodeModulesBoundary), so a Homebrew global install at /opt/homebrew/lib/node_modules/@evomap/evolver can no longer escape to /opt/homebrew/.git. A local install still resolves correctly (the boundary includes <project>, so <project>/.git is picked up), and a dev clone keeps the unbounded walk as before. I verified the published 1.87.2 paths.js contains the boundary.
EVOLVER_REPO_ROOT still works as an explicit override and always wins. Please upgrade and confirm repoRoot resolves to your actual workspace. Closing as resolved — reopen if it still escapes on 1.87.2.