Repository navigation
fix(cli): resolve agent discovery against user home, not config dir - #7
Merged
Merged
Conversation
`init` and `config` injected the user config directory (`os.UserConfigDir`, `~/.config` on Linux) into the discovery home seam, so every global agent directory was resolved as `~/.config/.pi/agent`, `~/.config/.claude`, etc. None of those exist, so no global agent was ever discovered. Pi was fully invisible because its `AgentConfig.LocalDir` is `""`: it has only a global path. The TUI was unaffected — it calls `discovery.New()` without overriding the seam. Split the overloaded seam: `getUserConfig` keeps locating `skill-sync.yaml`, and a new `getUserHome` (`os.UserHomeDir`) resolves agent directories. The pre-existing `init`/`config` tests were passing only because the broken seam pointed them at a directory that never existed; they now pin `getUserHome` to an empty temporary directory so they cannot read the developer's real home.
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
initandconfigresolved every global agent directory against the user config directory instead of the user home, so no global agent was ever discovered.initemitted an emptytargets:list on a machine with several agents installed.AgentConfig.LocalDiris"", so it has only a global path and was completely invisible.Root cause
Both commands injected the config-directory lookup into the discovery home seam:
getUserConfigisos.UserConfigDir→~/.configon Linux. Global paths therefore resolved to~/.config/.pi/agent,~/.config/.claude,~/.config/.gemini, none of which exist.One package-level variable was serving two distinct responsibilities: locating
skill-sync.yamland locating the user home for agent discovery.The TUI was unaffected —
internal/tui/program.go:71,86calldiscovery.New()without overriding the seam. CLI and TUI had silently diverged.Fix
getUserConfigkeeps locatingskill-sync.yaml; a newgetUserHome(os.UserHomeDir) resolves agent directories.A second defect this surfaced
After wiring the real home seam, the pre-existing case
TestInitCmd/no_agents_found_prints_'no skills configured'started failing because it discovered the developer's actual~/.claude,~/.geminiand~/.pi/agent.Those tests had been passing only because the broken seam pointed them at a directory that never existed — the bug was acting as the test's isolation mechanism, which is why CI never caught it. Both suites now pin
getUserHometo an emptyt.TempDir().Changes
internal/cli/init.gogetUserHomeseam; use it for discoveryinternal/cli/config.gogetUserHomefor discoveryinternal/cli/init_test.goTestInitDiscoversGlobalAgents(Pi, Claude Code, OpenCode); pingetUserHomeinTestInitCmdinternal/cli/config_test.goTestConfigDiscoversGlobalAgents(Pi, Gemini CLI); pingetUserHomeinTestConfigCmdodd/tasks/fix-global-agent-discovery.mdIn the new tests the config directory is a sibling of home, never its parent, so a future collapse of the two seams cannot pass by accident.
Test plan
Built test-first; RED observed as a behavioral failure, not a compile error (the
getUserHomevariable was declared before being wired).go test ./internal/cli/ -run TestInitDiscoversGlobalAgents→ all three cases emitted an emptytargets:go test ./internal/cli/ -run TestConfigDiscoversGlobalAgents→ both cases emittedtargets: []go test -race ./...→ all 14 packages passgo vet ./...→ cleangofmt -l .→ emptyManual run against a real home directory:
Before this change the same command produced an empty
targets:list.Notes
~/.pi/agent/skillsneed not pre-exist:Discovery.Scanmatches the agent root andinternal/sync/engine.go:43-56creates missing target directories, so the firstsyncmaterializes it.LocalDirfor Pi remains""; whether Pi should gain a per-project directory is a separate decision.