refactor(brain): consolidate newFs and agentName wrappers
Remove duplicated newFs() from brain package — use agentic.LocalFs() instead. Inline agentName() wrapper — call agentic.AgentName() directly. Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
b266db5069
commit
6db0110b6f
3 changed files with 7 additions and 23 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue