From c077819c0dafce99ba0af601d00d35070a325408 Mon Sep 17 00:00:00 2001 From: Virgil Date: Mon, 30 Mar 2026 20:32:17 +0000 Subject: [PATCH] fix(ax): unify home-path resolution Co-Authored-By: Virgil --- pkg/agentic/ingest.go | 6 +----- pkg/brain/direct.go | 9 +-------- pkg/brain/direct_test.go | 16 ++++++++++++++++ pkg/monitor/monitor.go | 12 +----------- pkg/monitor/sync.go | 2 +- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/pkg/agentic/ingest.go b/pkg/agentic/ingest.go index 1d03785..2c12dba 100644 --- a/pkg/agentic/ingest.go +++ b/pkg/agentic/ingest.go @@ -8,10 +8,6 @@ import ( core "dappco.re/go/core" ) -func agentHomeDir() string { - return HomeDir() -} - // ingestFindings reads the agent output log and creates issues via the API // for scan/audit results. Only runs for conventions and security templates. func (s *PrepSubsystem) ingestFindings(wsDir string) { @@ -93,7 +89,7 @@ func (s *PrepSubsystem) createIssueViaAPI(repo, title, description, issueType, p } // Read the agent API key from file - r := fs.Read(core.JoinPath(agentHomeDir(), ".claude", "agent-api.key")) + r := fs.Read(core.JoinPath(HomeDir(), ".claude", "agent-api.key")) if !r.OK { return } diff --git a/pkg/brain/direct.go b/pkg/brain/direct.go index 512d678..31635ce 100644 --- a/pkg/brain/direct.go +++ b/pkg/brain/direct.go @@ -36,7 +36,7 @@ func NewDirect() *DirectSubsystem { apiKey := core.Env("CORE_BRAIN_KEY") keyPath := "" if apiKey == "" { - keyPath = brainKeyPath(brainHomeDir()) + keyPath = brainKeyPath(agentic.HomeDir()) if keyPath != "" { if r := fs.Read(keyPath); r.OK { apiKey = core.Trim(r.Value.(string)) @@ -97,13 +97,6 @@ func brainKeyPath(home string) string { return core.JoinPath(core.TrimSuffix(home, "/"), ".claude", "brain.key") } -func brainHomeDir() string { - if home := core.Env("CORE_HOME"); home != "" { - return home - } - return core.Env("DIR_HOME") -} - func (s *DirectSubsystem) apiCall(ctx context.Context, method, path string, body any) core.Result { if s.apiKey == "" { return core.Result{ diff --git a/pkg/brain/direct_test.go b/pkg/brain/direct_test.go index 6eaa025..1a9c926 100644 --- a/pkg/brain/direct_test.go +++ b/pkg/brain/direct_test.go @@ -68,6 +68,22 @@ func TestDirect_NewDirect_Good_KeyFromFile(t *testing.T) { assert.Equal(t, "file-key-456", sub.apiKey) } +func TestDirect_NewDirect_Good_HomeFallback(t *testing.T) { + t.Setenv("CORE_BRAIN_URL", "") + t.Setenv("CORE_BRAIN_KEY", "") + t.Setenv("CORE_HOME", "") + t.Setenv("DIR_HOME", "") + + tmpHome := t.TempDir() + t.Setenv("HOME", tmpHome) + keyDir := core.JoinPath(tmpHome, ".claude") + require.True(t, fs.EnsureDir(keyDir).OK) + require.True(t, fs.Write(core.JoinPath(keyDir, "brain.key"), " home-key-789 \n").OK) + + sub := NewDirect() + assert.Equal(t, "home-key-789", sub.apiKey) +} + func TestDirect_Subsystem_Good_Name(t *testing.T) { sub := &DirectSubsystem{} assert.Equal(t, "brain", sub.Name()) diff --git a/pkg/monitor/monitor.go b/pkg/monitor/monitor.go index 80c5a5d..7e2c6ac 100644 --- a/pkg/monitor/monitor.go +++ b/pkg/monitor/monitor.go @@ -33,16 +33,6 @@ func brainKeyPath(home string) string { return core.JoinPath(home, ".claude", "brain.key") } -func monitorHomeDir() string { - if d := core.Env("CORE_HOME"); d != "" { - return d - } - if d := core.Env("HOME"); d != "" { - return d - } - return core.Env("DIR_HOME") -} - func monitorAPIURL() string { if u := core.Env("CORE_API_URL"); u != "" { return u @@ -54,7 +44,7 @@ func monitorBrainKey() string { if k := core.Env("CORE_BRAIN_KEY"); k != "" { return k } - if r := fs.Read(brainKeyPath(monitorHomeDir())); r.OK { + if r := fs.Read(brainKeyPath(agentic.HomeDir())); r.OK { if value, ok := resultString(r); ok { return core.Trim(value) } diff --git a/pkg/monitor/sync.go b/pkg/monitor/sync.go index 5fc2dc4..57bdfc1 100644 --- a/pkg/monitor/sync.go +++ b/pkg/monitor/sync.go @@ -57,7 +57,7 @@ func (m *Subsystem) syncRepos() string { // Pull changed repos basePath := core.Env("CODE_PATH") if basePath == "" { - basePath = core.JoinPath(monitorHomeDir(), "Code", "core") + basePath = core.JoinPath(agentic.HomeDir(), "Code", "core") } var pulled []string