From 6db0110b6f442830a09a574c92ffe82e74e837a4 Mon Sep 17 00:00:00 2001 From: Snider Date: Sun, 22 Mar 2026 03:47:08 +0000 Subject: [PATCH] refactor(brain): consolidate newFs and agentName wrappers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove duplicated newFs() from brain package — use agentic.LocalFs() instead. Inline agentName() wrapper — call agentic.AgentName() directly. Co-Authored-By: Virgil --- pkg/brain/brain.go | 15 --------------- pkg/brain/direct.go | 8 +++----- pkg/brain/messaging.go | 7 ++++--- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/pkg/brain/brain.go b/pkg/brain/brain.go index 0e5998c..5ef8608 100644 --- a/pkg/brain/brain.go +++ b/pkg/brain/brain.go @@ -6,27 +6,12 @@ package brain import ( "context" - "unsafe" core "dappco.re/go/core" "forge.lthn.ai/core/mcp/pkg/mcp/ide" "github.com/modelcontextprotocol/go-sdk/mcp" ) -// fs provides unrestricted filesystem access (root "/" = no sandbox). -// -// r := fs.Read(filepath.Join(home, ".claude", "brain.key")) -// if r.OK { apiKey = strings.TrimSpace(r.Value.(string)) } -var fs = newFs("/") - -// newFs creates a core.Fs with the given root directory. -func newFs(root string) *core.Fs { - type fsRoot struct{ root string } - f := &core.Fs{} - (*fsRoot)(unsafe.Pointer(f)).root = root - return f -} - // errBridgeNotAvailable is returned when a tool requires the Laravel bridge // but it has not been initialised (headless mode). var errBridgeNotAvailable = core.E("brain", "bridge not available", nil) diff --git a/pkg/brain/direct.go b/pkg/brain/direct.go index 7907d7a..54ac75e 100644 --- a/pkg/brain/direct.go +++ b/pkg/brain/direct.go @@ -19,10 +19,8 @@ import ( "github.com/modelcontextprotocol/go-sdk/mcp" ) -// agentName returns the identity of this agent. -func agentName() string { - return agentic.AgentName() -} +// fs provides unrestricted filesystem access for the brain package. +var fs = agentic.LocalFs() // DirectSubsystem implements mcp.Subsystem for OpenBrain via direct HTTP calls. // Unlike Subsystem (which uses the IDE WebSocket bridge), this calls the @@ -138,7 +136,7 @@ func (s *DirectSubsystem) remember(ctx context.Context, _ *mcp.CallToolRequest, "type": input.Type, "tags": input.Tags, "project": input.Project, - "agent_id": agentName(), + "agent_id": agentic.AgentName(), }) if err != nil { return nil, RememberOutput{}, err diff --git a/pkg/brain/messaging.go b/pkg/brain/messaging.go index eb5148e..db7323e 100644 --- a/pkg/brain/messaging.go +++ b/pkg/brain/messaging.go @@ -8,6 +8,7 @@ import ( "net/url" core "dappco.re/go/core" + "dappco.re/go/agent/pkg/agentic" "github.com/modelcontextprotocol/go-sdk/mcp" ) @@ -80,7 +81,7 @@ func (s *DirectSubsystem) sendMessage(ctx context.Context, _ *mcp.CallToolReques result, err := s.apiCall(ctx, "POST", "/v1/messages/send", map[string]any{ "to": input.To, - "from": agentName(), + "from": agentic.AgentName(), "content": input.Content, "subject": input.Subject, }) @@ -101,7 +102,7 @@ func (s *DirectSubsystem) sendMessage(ctx context.Context, _ *mcp.CallToolReques func (s *DirectSubsystem) inbox(ctx context.Context, _ *mcp.CallToolRequest, input InboxInput) (*mcp.CallToolResult, InboxOutput, error) { agent := input.Agent if agent == "" { - agent = agentName() + agent = agentic.AgentName() } result, err := s.apiCall(ctx, "GET", "/v1/messages/inbox?agent="+url.QueryEscape(agent), nil) if err != nil { @@ -119,7 +120,7 @@ func (s *DirectSubsystem) conversation(ctx context.Context, _ *mcp.CallToolReque return nil, ConversationOutput{}, core.E("brain.conversation", "agent is required", nil) } - result, err := s.apiCall(ctx, "GET", "/v1/messages/conversation/"+url.PathEscape(input.Agent)+"?me="+url.QueryEscape(agentName()), nil) + result, err := s.apiCall(ctx, "GET", "/v1/messages/conversation/"+url.PathEscape(input.Agent)+"?me="+url.QueryEscape(agentic.AgentName()), nil) if err != nil { return nil, ConversationOutput{}, err }