fix: XDG default fallback in prompt resolver; deduplicate tool headers

- envLookup: provide XDG spec defaults (XDG_CONFIG_HOME, XDG_DATA_HOME,
  XDG_CACHE_HOME) when env vars are unset, so agent profile prompts
  resolve correctly on systems without explicit XDG vars.
- renderTools: skip generated '## name' header when the tool's prompt
  text already starts with a markdown header, eliminating duplicates.
This commit is contained in:
Levi Neely 2026-08-13 15:45:35 +02:00
parent 0b932a60ca
commit 5459e7fa2a
2 changed files with 24 additions and 4 deletions

View File

@ -49,6 +49,7 @@ func resolvePrompt(p Prompt, cwd string, env []string) (string, error) {
}
// envLookup returns a lookup function that checks env slice first, then os env.
// Provides XDG spec defaults when variables are unset.
func envLookup(env []string) func(string) string {
m := make(map[string]string, len(env))
for _, e := range env {
@ -56,11 +57,24 @@ func envLookup(env []string) func(string) string {
m[k] = v
}
}
home, _ := os.UserHomeDir()
return func(key string) string {
if v, ok := m[key]; ok {
return v
}
return os.Getenv(key)
if v := os.Getenv(key); v != "" {
return v
}
// XDG spec defaults
switch key {
case "XDG_CONFIG_HOME":
return home + "/.config"
case "XDG_DATA_HOME":
return home + "/.local/share"
case "XDG_CACHE_HOME":
return home + "/.cache"
}
return ""
}
}

View File

@ -100,12 +100,18 @@ func renderTools(infos []toolsrv.ToolInfo) string {
if ti.Description == "" {
continue
}
sb.WriteString("## ")
sb.WriteString(ti.Name)
sb.WriteString("\n\n")
if ti.Prompt != "" {
// If prompt already starts with a markdown header, skip the generated one.
if !strings.HasPrefix(ti.Prompt, "#") {
sb.WriteString("## ")
sb.WriteString(ti.Name)
sb.WriteString("\n\n")
}
sb.WriteString(ti.Prompt)
} else {
sb.WriteString("## ")
sb.WriteString(ti.Name)
sb.WriteString("\n\n")
sb.WriteString(ti.Description)
}
sb.WriteString("\n\n")