Skip to content

Fix: home/repoRoot/allAgentDescriptors ignored HOME overrides - #3

Merged
molayab merged 1 commit into
feature/library-target-and-unified-modelfrom
fix/home-env-override
Aug 8, 2026
Merged

Fix: home/repoRoot/allAgentDescriptors ignored HOME overrides#3
molayab merged 1 commit into
feature/library-target-and-unified-modelfrom
fix/home-env-override

Conversation

@molayab

@molayab molayab commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Why

Stacked on #2 β€” this only exists because that PR introduces CLIManagerKit.

While manually smoke-testing #2, I tried to run skill activate/command activate against a
scratch repo with HOME overridden to a fake directory, expecting the tool to stay fully
sandboxed. It didn't: home was NSHomeDirectory(), which resolves the account's real home
directory and ignores a HOME environment override. The commands quietly created a real
symlink under my actual ~/.claude/skills and a real file under ~/.gemini/commands β€” outside
the 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_REPO for
exactly this reason on the repo side; HOME just wasn't wired up the same way.

Fix

  • home now checks the HOME environment variable first, falling back to NSHomeDirectory().
    expandingTilde follows it instead of calling NSHomeDirectory() directly.
  • home, repoRoot/skillsDir/commandsDir/dotfilesDir, and allAgentDescriptors all
    switch from let (cached at first access) to computed var (re-resolved every access) β€” the
    paths baked into allAgentDescriptors in particular were stale-until-restart even for
    CLI_MANAGER_REPO-style overrides, since they were computed once from home at 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-directory HOME, restored in deinit, .serialized since it
mutates process-wide environment state) covering:

  • home reflects the override
  • expandingTilde expands against the override
  • allAgentDescriptors paths are derived from the override
  • AgentDescriptor.detected(for:) only reports agents that exist under the override

swift build / swift test (39/39 passing) / swiftlint lint all clean except the same two
pre-existing warnings already present on main in unrelated, untouched lines. Also re-ran the
original 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 the
real ~ this time.

…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.
@molayab
molayab merged commit 2fcd311 into feature/library-target-and-unified-model Aug 8, 2026
@molayab
molayab deleted the fix/home-env-override branch August 8, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant