2026-03-16 11:10:33 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package brain
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-03-21 11:10:31 +00:00
|
|
|
"dappco.re/go/agent/pkg/agentic"
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
core "dappco.re/go/core"
|
2026-03-29 20:15:58 +00:00
|
|
|
coremcp "forge.lthn.ai/core/mcp/pkg/mcp"
|
2026-03-16 11:10:33 +00:00
|
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-29 23:30:08 +00:00
|
|
|
// DirectSubsystem talks to OpenBrain over HTTP without the IDE bridge.
|
2026-03-22 03:41:07 +00:00
|
|
|
//
|
|
|
|
|
// sub := brain.NewDirect()
|
2026-03-29 23:45:48 +00:00
|
|
|
// core.Println(sub.Name()) // "brain"
|
2026-03-16 11:10:33 +00:00
|
|
|
type DirectSubsystem struct {
|
|
|
|
|
apiURL string
|
|
|
|
|
apiKey string
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-22 06:42:42 +00:00
|
|
|
var _ coremcp.Subsystem = (*DirectSubsystem)(nil)
|
|
|
|
|
|
2026-03-29 23:30:08 +00:00
|
|
|
// NewDirect builds the HTTP-backed OpenBrain subsystem.
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
//
|
|
|
|
|
// sub := brain.NewDirect()
|
2026-03-29 23:45:48 +00:00
|
|
|
// core.Println(sub.Name())
|
2026-03-16 11:10:33 +00:00
|
|
|
func NewDirect() *DirectSubsystem {
|
2026-03-22 13:02:37 +00:00
|
|
|
apiURL := core.Env("CORE_BRAIN_URL")
|
2026-03-16 11:10:33 +00:00
|
|
|
if apiURL == "" {
|
|
|
|
|
apiURL = "https://api.lthn.sh"
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-22 13:02:37 +00:00
|
|
|
apiKey := core.Env("CORE_BRAIN_KEY")
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
keyPath := ""
|
2026-03-16 11:10:33 +00:00
|
|
|
if apiKey == "" {
|
2026-03-22 13:02:37 +00:00
|
|
|
keyPath = brainKeyPath(brainHomeDir())
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
if keyPath != "" {
|
|
|
|
|
if r := fs.Read(keyPath); r.OK {
|
|
|
|
|
apiKey = core.Trim(r.Value.(string))
|
|
|
|
|
if apiKey != "" {
|
|
|
|
|
core.Info("brain direct subsystem loaded API key from file", "path", keyPath)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
if apiKey == "" {
|
|
|
|
|
core.Warn("brain direct subsystem has no API key configured", "path", keyPath)
|
|
|
|
|
}
|
2026-03-16 11:10:33 +00:00
|
|
|
|
|
|
|
|
return &DirectSubsystem{
|
|
|
|
|
apiURL: apiURL,
|
|
|
|
|
apiKey: apiKey,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 23:30:08 +00:00
|
|
|
// Name keeps the direct subsystem address stable for core.WithService and MCP.
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
//
|
|
|
|
|
// name := sub.Name() // "brain"
|
2026-03-16 11:10:33 +00:00
|
|
|
func (s *DirectSubsystem) Name() string { return "brain" }
|
|
|
|
|
|
2026-03-29 23:45:48 +00:00
|
|
|
// RegisterTools publishes the direct `brain_*` and `agent_*` tools on an MCP server.
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
//
|
|
|
|
|
// sub := brain.NewDirect()
|
|
|
|
|
// sub.RegisterTools(server)
|
2026-03-16 11:10:33 +00:00
|
|
|
func (s *DirectSubsystem) RegisterTools(server *mcp.Server) {
|
|
|
|
|
mcp.AddTool(server, &mcp.Tool{
|
|
|
|
|
Name: "brain_remember",
|
|
|
|
|
Description: "Store a memory in OpenBrain. Types: fact, decision, observation, plan, convention, architecture, research, documentation, service, bug, pattern, context, procedure.",
|
|
|
|
|
}, s.remember)
|
|
|
|
|
|
|
|
|
|
mcp.AddTool(server, &mcp.Tool{
|
|
|
|
|
Name: "brain_recall",
|
|
|
|
|
Description: "Semantic search across OpenBrain memories. Returns memories ranked by similarity. Use agent_id 'cladius' for Cladius's memories.",
|
|
|
|
|
}, s.recall)
|
|
|
|
|
|
|
|
|
|
mcp.AddTool(server, &mcp.Tool{
|
|
|
|
|
Name: "brain_forget",
|
|
|
|
|
Description: "Remove a memory from OpenBrain by ID.",
|
|
|
|
|
}, s.forget)
|
2026-03-16 14:03:36 +00:00
|
|
|
|
|
|
|
|
// Agent messaging — direct, chronological, not semantic
|
|
|
|
|
s.RegisterMessagingTools(server)
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 23:30:08 +00:00
|
|
|
// Shutdown satisfies the MCP subsystem lifecycle without extra cleanup.
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
//
|
|
|
|
|
// _ = sub.Shutdown(context.Background())
|
2026-03-16 11:10:33 +00:00
|
|
|
func (s *DirectSubsystem) Shutdown(_ context.Context) error { return nil }
|
|
|
|
|
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
func brainKeyPath(home string) string {
|
|
|
|
|
if home == "" {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return core.JoinPath(core.TrimSuffix(home, "/"), ".claude", "brain.key")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-22 13:02:37 +00:00
|
|
|
func brainHomeDir() string {
|
|
|
|
|
if home := core.Env("CORE_HOME"); home != "" {
|
|
|
|
|
return home
|
|
|
|
|
}
|
|
|
|
|
return core.Env("DIR_HOME")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 23:45:48 +00:00
|
|
|
func (s *DirectSubsystem) apiCall(ctx context.Context, method, path string, body any) core.Result {
|
2026-03-16 11:10:33 +00:00
|
|
|
if s.apiKey == "" {
|
2026-03-29 23:45:48 +00:00
|
|
|
return core.Result{
|
|
|
|
|
Value: core.E("brain.apiCall", "no API key (set CORE_BRAIN_KEY or create ~/.claude/brain.key)", nil),
|
|
|
|
|
}
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
requestURL := core.Concat(s.apiURL, path)
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
var bodyStr string
|
|
|
|
|
if body != nil {
|
|
|
|
|
bodyStr = core.JSONMarshalString(body)
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
r := agentic.HTTPDo(ctx, method, requestURL, bodyStr, s.apiKey, "Bearer")
|
|
|
|
|
if !r.OK {
|
|
|
|
|
core.Error("brain API call failed", "method", method, "path", path)
|
2026-03-29 23:45:48 +00:00
|
|
|
return core.Result{Value: core.E("brain.apiCall", "API call failed", nil)}
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result map[string]any
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
if ur := core.JSONUnmarshalString(r.Value.(string), &result); !ur.OK {
|
|
|
|
|
core.Error("brain API response parse failed", "method", method, "path", path)
|
2026-03-29 23:45:48 +00:00
|
|
|
return core.Result{Value: core.E("brain.apiCall", "parse response", nil)}
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 23:45:48 +00:00
|
|
|
return core.Result{Value: result, OK: true}
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *DirectSubsystem) remember(ctx context.Context, _ *mcp.CallToolRequest, input RememberInput) (*mcp.CallToolResult, RememberOutput, error) {
|
2026-03-29 23:45:48 +00:00
|
|
|
result := s.apiCall(ctx, "POST", "/v1/brain/remember", map[string]any{
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
"content": input.Content,
|
|
|
|
|
"type": input.Type,
|
|
|
|
|
"tags": input.Tags,
|
|
|
|
|
"project": input.Project,
|
|
|
|
|
"confidence": input.Confidence,
|
|
|
|
|
"supersedes": input.Supersedes,
|
|
|
|
|
"expires_in": input.ExpiresIn,
|
|
|
|
|
"agent_id": agentic.AgentName(),
|
2026-03-16 11:10:33 +00:00
|
|
|
})
|
2026-03-29 23:45:48 +00:00
|
|
|
if !result.OK {
|
|
|
|
|
err, _ := result.Value.(error)
|
2026-03-16 11:10:33 +00:00
|
|
|
return nil, RememberOutput{}, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 23:45:48 +00:00
|
|
|
payload, _ := result.Value.(map[string]any)
|
|
|
|
|
id, _ := payload["id"].(string)
|
2026-03-16 11:10:33 +00:00
|
|
|
return nil, RememberOutput{
|
|
|
|
|
Success: true,
|
|
|
|
|
MemoryID: id,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *DirectSubsystem) recall(ctx context.Context, _ *mcp.CallToolRequest, input RecallInput) (*mcp.CallToolResult, RecallOutput, error) {
|
|
|
|
|
body := map[string]any{
|
2026-03-16 11:50:20 +00:00
|
|
|
"query": input.Query,
|
|
|
|
|
"top_k": input.TopK,
|
|
|
|
|
}
|
|
|
|
|
// Only filter by agent_id if explicitly provided — shared brain by default
|
|
|
|
|
if input.Filter.AgentID != "" {
|
|
|
|
|
body["agent_id"] = input.Filter.AgentID
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
if input.Filter.Project != "" {
|
|
|
|
|
body["project"] = input.Filter.Project
|
|
|
|
|
}
|
|
|
|
|
if input.Filter.Type != nil {
|
|
|
|
|
body["type"] = input.Filter.Type
|
|
|
|
|
}
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
if input.Filter.MinConfidence != 0 {
|
|
|
|
|
body["min_confidence"] = input.Filter.MinConfidence
|
|
|
|
|
}
|
2026-03-16 11:10:33 +00:00
|
|
|
if input.TopK == 0 {
|
|
|
|
|
body["top_k"] = 10
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 23:45:48 +00:00
|
|
|
result := s.apiCall(ctx, "POST", "/v1/brain/recall", body)
|
|
|
|
|
if !result.OK {
|
|
|
|
|
err, _ := result.Value.(error)
|
2026-03-16 11:10:33 +00:00
|
|
|
return nil, RecallOutput{}, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var memories []Memory
|
2026-03-29 23:45:48 +00:00
|
|
|
payload, _ := result.Value.(map[string]any)
|
|
|
|
|
if mems, ok := payload["memories"].([]any); ok {
|
2026-03-16 11:10:33 +00:00
|
|
|
for _, m := range mems {
|
|
|
|
|
if mm, ok := m.(map[string]any); ok {
|
|
|
|
|
mem := Memory{
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
Content: fieldString(mm, "content"),
|
|
|
|
|
Type: fieldString(mm, "type"),
|
|
|
|
|
Project: fieldString(mm, "project"),
|
|
|
|
|
AgentID: fieldString(mm, "agent_id"),
|
|
|
|
|
CreatedAt: fieldString(mm, "created_at"),
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
if id, ok := mm["id"].(string); ok {
|
|
|
|
|
mem.ID = id
|
|
|
|
|
}
|
|
|
|
|
if score, ok := mm["score"].(float64); ok {
|
|
|
|
|
mem.Confidence = score
|
|
|
|
|
}
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
if tags, ok := mm["tags"].([]any); ok {
|
|
|
|
|
for _, tag := range tags {
|
|
|
|
|
mem.Tags = append(mem.Tags, core.Sprint(tag))
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-16 11:10:33 +00:00
|
|
|
if source, ok := mm["source"].(string); ok {
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
mem.Tags = append(mem.Tags, core.Concat("source:", source))
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
memories = append(memories, mem)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, RecallOutput{
|
|
|
|
|
Success: true,
|
|
|
|
|
Count: len(memories),
|
|
|
|
|
Memories: memories,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *DirectSubsystem) forget(ctx context.Context, _ *mcp.CallToolRequest, input ForgetInput) (*mcp.CallToolResult, ForgetOutput, error) {
|
2026-03-29 23:45:48 +00:00
|
|
|
result := s.apiCall(ctx, "DELETE", core.Concat("/v1/brain/forget/", input.ID), nil)
|
|
|
|
|
if !result.OK {
|
|
|
|
|
err, _ := result.Value.(error)
|
2026-03-16 11:10:33 +00:00
|
|
|
return nil, ForgetOutput{}, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, ForgetOutput{
|
|
|
|
|
Success: true,
|
|
|
|
|
Forgotten: input.ID,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|