Skip to content

Commit 9c73601

Browse files
fix(config): normalize provider env category resolution (#48)
Align category and provider env handling with the updated provider map and tighten related tests. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent abeb727 commit 9c73601

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

config/category.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func DefaultCategories() map[ModelCategory]CategoryConfig {
9999
}
100100

101101
// GetCategoryRegistry returns the global category registry.
102-
// It loads overrides from ~/.hawk/categories.json if present.
102+
// It loads overrides from Hawk user config if present.
103103
func GetCategoryRegistry() *CategoryRegistry {
104104
registryOnce.Do(func() {
105105
globalRegistry = &CategoryRegistry{
@@ -117,11 +117,15 @@ func ResetCategoryRegistry() {
117117
}
118118

119119
func (r *CategoryRegistry) loadOverrides() {
120-
home, err := os.UserHomeDir()
121-
if err != nil {
122-
return
120+
configDir := os.Getenv("HAWK_CONFIG_DIR")
121+
if configDir == "" {
122+
dir, err := os.UserConfigDir()
123+
if err != nil || dir == "" {
124+
return
125+
}
126+
configDir = filepath.Join(dir, "hawk")
123127
}
124-
path := filepath.Join(home, ".hawk", "categories.json")
128+
path := filepath.Join(configDir, "categories.json")
125129
data, err := os.ReadFile(path)
126130
if err != nil {
127131
return // file not found is fine

config/provider_env.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/GrayCodeAI/eyrie/catalog"
1212
)
1313

14-
// ProviderConfig mirrors ~/.hawk/provider.json.
14+
// ProviderConfig mirrors the Hawk provider.json file.
1515
type ProviderConfig struct {
1616
ConfigVersion int `json:"config_version,omitempty"`
1717
Version string `json:"_version,omitempty"`
@@ -314,8 +314,10 @@ func GetProviderConfigDir() string {
314314
if d := os.Getenv("HAWK_CONFIG_DIR"); d != "" {
315315
return d
316316
}
317-
home, _ := os.UserHomeDir()
318-
return filepath.Join(home, ".hawk")
317+
if d, err := os.UserConfigDir(); err == nil && d != "" {
318+
return filepath.Join(d, "hawk")
319+
}
320+
panic("hawk provider config: user config directory unavailable")
319321
}
320322

321323
// GetProviderConfigPath returns the full path to provider.json.

config/provider_env_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ func TestGetProviderConfigDir(t *testing.T) {
119119
t.Errorf("expected %q, got %q", dir, got)
120120
}
121121

122-
// Test without env var (falls back to ~/.hawk)
122+
// Test without env var (uses OS config dir when available)
123123
os.Unsetenv("HAWK_CONFIG_DIR")
124124
got = GetProviderConfigDir()
125-
if !strings.HasSuffix(got, ".hawk") {
126-
t.Errorf("expected path ending in .hawk, got %q", got)
125+
if !strings.HasSuffix(got, filepath.Join("hawk")) {
126+
t.Errorf("expected path ending in hawk, got %q", got)
127127
}
128128
}
129129

0 commit comments

Comments
 (0)