Fix: home/repoRoot/allAgentDescriptors ignored HOME overrides - #3
Merged
molayab merged 1 commit intoAug 8, 2026
Merged
Conversation
β¦access NSHomeDirectory() ignores a HOME environment override, so pointing this tool at a scratch directory for testing/sandboxing silently fell through to the real user home instead β any command that touches agent directories (activate, clean, ...) would act on the real machine regardless of HOME. - home now reads the HOME environment variable first, falling back to NSHomeDirectory(); expandingTilde follows it. - home, repoRoot, skillsDir/commandsDir/dotfilesDir, and allAgentDescriptors are computed on every access instead of cached at first use, so an override set partway through a process (as in tests) takes effect immediately rather than being stuck with whatever was resolved first. - Adds HomeOverrideTests covering the override itself, tilde expansion, agent descriptor paths, and detected(for:) β all exercised against a temp directory, restoring the original HOME afterward.
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.
Why
Stacked on #2 β this only exists because that PR introduces
CLIManagerKit.While manually smoke-testing #2, I tried to run
skill activate/command activateagainst ascratch repo with
HOMEoverridden to a fake directory, expecting the tool to stay fullysandboxed. It didn't:
homewasNSHomeDirectory(), which resolves the account's real homedirectory and ignores a
HOMEenvironment override. The commands quietly created a realsymlink under my actual
~/.claude/skillsand a real file under~/.gemini/commandsβ outsidethe sandbox I thought I'd set up. (Cleaned up by hand; nothing shipped or committed.)
This isn't just a testing inconvenience β it's the same class of hazard for anyone who wants to
run this tool against an isolated
HOME(containers, CI,env -i HOME=... cli-manager ...,Grove eventually sandboxing an embedded call). The tool already honors
CLI_MANAGER_REPOforexactly this reason on the repo side;
HOMEjust wasn't wired up the same way.Fix
homenow checks theHOMEenvironment variable first, falling back toNSHomeDirectory().expandingTildefollows it instead of callingNSHomeDirectory()directly.home,repoRoot/skillsDir/commandsDir/dotfilesDir, andallAgentDescriptorsallswitch from
let(cached at first access) to computedvar(re-resolved every access) β thepaths baked into
allAgentDescriptorsin particular were stale-until-restart even forCLI_MANAGER_REPO-style overrides, since they were computed once fromhomeat first touch.No public API shape changes β everything is still accessed as a plain property
(
home,repoRoot,allAgentDescriptors, ...); only how it's computed changed.Testing
Added
HomeOverrideTests(temp-directoryHOME, restored indeinit,.serializedsince itmutates process-wide environment state) covering:
homereflects the overrideexpandingTildeexpands against the overrideallAgentDescriptorspaths are derived from the overrideAgentDescriptor.detected(for:)only reports agents that exist under the overrideswift build/swift test(39/39 passing) /swiftlint lintall clean except the same twopre-existing warnings already present on
mainin unrelated, untouched lines. Also re-ran theoriginal repro by hand with
env -i HOME=<scratch> CLI_MANAGER_REPO=<scratch> cli-manager skill statusβ every agent path now resolves under the scratch home, confirmed nothing touches thereal
~this time.