From ee96aeea56b10f8b372a76d683bb93d2fdd74efd Mon Sep 17 00:00:00 2001 From: Willie Date: Tue, 27 Oct 2026 21:35:14 +0800 Subject: [PATCH] fix(config): keep env-derived default skills paths on save (#662) A pathless deepseek-harness or gitlab-duo target resolves its skills path from DSH_HOME, GLAB_CONFIG_DIR, or XDG_CONFIG_HOME, and the docs promise it keeps following those overrides. decodeConfig filled the omitted path in, though, and the next save (editing filters, changing mode) wrote it back as an explicit path, so later environment changes were ignored. Mark a default that came from targetConfigHome as derived, reusing the mechanism that already keeps config_dir paths out of the saved file. Closes #661 Release-As: 0.27.1 --- internal/config/agent_config_dir.go | 4 ++-- internal/config/config.go | 6 +++++- internal/config/targets_new_tools_test.go | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/internal/config/agent_config_dir.go b/internal/config/agent_config_dir.go index 00bcfd71e..07d63a012 100644 --- a/internal/config/agent_config_dir.go +++ b/internal/config/agent_config_dir.go @@ -185,8 +185,8 @@ func (c *Config) AddAgentConfigDirTarget(name, agent, dir, cli string) (string, return target.SkillsConfig().Path, nil } -// withoutDerivedPaths drops the paths expandAgentConfigDirs filled in, so they keep -// following config_dir instead of being saved as written ones. +// withoutDerivedPaths drops the paths filled in from config_dir or the environment, so +// they keep following it instead of being saved as written ones. func (tc TargetConfig) withoutDerivedPaths() TargetConfig { strip := func(rc *ResourceTargetConfig, derived string) *ResourceTargetConfig { if rc == nil || derived == "" || rc.Path != derived { diff --git a/internal/config/config.go b/internal/config/config.go index cb29450fe..55805d1d6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -168,7 +168,7 @@ type TargetConfig struct { Files []string `yaml:"files,omitempty"` defaultTargetNaming string `yaml:"-"` - // derivedSkills and derivedAgents are the paths expandAgentConfigDirs filled in. + // derivedSkills and derivedAgents are the paths filled in from config_dir or the environment. derivedSkills, derivedAgents string `yaml:"-"` // projectRoot marks a target expanded from projects; see expandProjects. projectRoot string `yaml:"-"` @@ -838,6 +838,10 @@ func decodeConfig(path string, data []byte, persist bool) (*Config, error) { if target.SkillsConfig().Path == "" { if def, ok := defaults[name]; ok { target.EnsureSkills().Path = expandPath(def.Path) + // A default from the environment keeps following it instead of being saved. + if targetConfigHome(name, runtime.GOOS) != "" { + target.derivedSkills = target.SkillsConfig().Path + } } } cfg.Targets[name] = target diff --git a/internal/config/targets_new_tools_test.go b/internal/config/targets_new_tools_test.go index 562bae1b8..dbc987ba9 100644 --- a/internal/config/targets_new_tools_test.go +++ b/internal/config/targets_new_tools_test.go @@ -100,6 +100,23 @@ func TestTargets_ConfigHomeOverrides(t *testing.T) { if got := filepath.Clean(target.SkillsConfig().Path); got != filepath.Join(root, "pinned", "skills") { t.Errorf("explicit path = %q, want pinned path", got) } + + // A pathless entry keeps following the override after a save. + cfg, _, err = loadWithTargets(t, " "+tt.name+": {}\n") + if err != nil { + t.Fatal(err) + } + if err := cfg.Save(); err != nil { + t.Fatal(err) + } + t.Setenv(tt.env, filepath.Join(base, "moved")) + if cfg, err = Load(); err != nil { + t.Fatal(err) + } + target = cfg.Targets[tt.name] + if got := target.SkillsConfig().Path; got != DefaultTargets()[tt.name].Path { + t.Errorf("path after save = %q, want %q", got, DefaultTargets()[tt.name].Path) + } }) } }