feat: Register() factories + consume new core.New() API

Each package exposes Register(c *Core) Result for core.WithService():
- agentic.Register: creates PrepSubsystem, wires IPC handlers, lifecycle
- monitor.Register: creates Subsystem, wires IPC handler, lifecycle
- brain.Register: creates Direct, registers service

main.go updated for core.New() returning Result.
Ready for core.New(WithService(agentic.Register)) pattern.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-24 16:23:44 +00:00
parent cdb29a2f75
commit 9f8a63ae21
5 changed files with 111 additions and 8 deletions

View file

@ -18,9 +18,15 @@ import (
)
func main() {
c := core.New(core.Options{
{Key: "name", Value: "core-agent"},
})
r := core.New(
core.WithOptions(core.Options{{Key: "name", Value: "core-agent"}}),
)
if !r.OK {
core.Error("failed to create core", "err", r.Value)
os.Exit(1)
}
c := r.Value.(*core.Core)
// Version set at build time: go build -ldflags "-X main.version=0.15.0"
if version != "" {
c.App().Version = version
@ -312,7 +318,8 @@ func main() {
prep.SetCore(c)
mon.SetCore(c)
// IPC handlers registered automatically in SetCore()
// Register post-completion pipeline as IPC handlers
agentic.RegisterHandlers(c, prep)
// Register as Core services with lifecycle hooks
c.Service("agentic", core.Service{
@ -509,9 +516,9 @@ func main() {
})
// Run CLI — resolves os.Args to command path
r := c.Cli().Run()
if !r.OK {
if err, ok := r.Value.(error); ok {
result := c.Cli().Run()
if !result.OK {
if err, ok := result.Value.(error); ok {
core.Error(err.Error())
}
os.Exit(1)

View file

@ -190,7 +190,7 @@ func TestSetCore_Good(t *testing.T) {
s := &PrepSubsystem{}
assert.Nil(t, s.core)
c := core.New(core.Options{{Key: "name", Value: "test"}})
c := core.New(core.WithOptions(core.Options{{Key: "name", Value: "test"}})).Value.(*core.Core)
s.SetCore(c)
assert.NotNil(t, s.core)
}

34
pkg/agentic/register.go Normal file
View file

@ -0,0 +1,34 @@
// SPDX-License-Identifier: EUPL-1.2
package agentic
import (
core "dappco.re/go/core"
)
// Register is the service factory for core.WithService.
// It creates the PrepSubsystem, wires Core, registers lifecycle hooks,
// and registers IPC handlers — all during Core construction.
//
// core.New(
// core.WithService(agentic.Register),
// )
func Register(c *core.Core) core.Result {
prep := NewPrep()
prep.core = c
c.Service("agentic", core.Service{
OnStart: func() core.Result {
prep.StartRunner()
return core.Result{OK: true}
},
OnStop: func() core.Result {
prep.frozen = true
return core.Result{OK: true}
},
})
RegisterHandlers(c, prep)
return core.Result{OK: true}
}

22
pkg/brain/register.go Normal file
View file

@ -0,0 +1,22 @@
// SPDX-License-Identifier: EUPL-1.2
package brain
import (
core "dappco.re/go/core"
)
// Register is the service factory for core.WithService.
// Brain has no lifecycle hooks — it's a stateless API proxy.
//
// core.New(
// core.WithService(brain.Register),
// )
func Register(c *core.Core) core.Result {
brn := NewDirect()
c.Service("brain", core.Service{})
_ = brn // brain instance available for MCP tool registration
return core.Result{OK: true}
}

40
pkg/monitor/register.go Normal file
View file

@ -0,0 +1,40 @@
// SPDX-License-Identifier: EUPL-1.2
package monitor
import (
"dappco.re/go/agent/pkg/messages"
core "dappco.re/go/core"
)
// Register is the service factory for core.WithService.
// It creates the monitor subsystem, wires Core for IPC,
// and registers lifecycle hooks.
//
// core.New(
// core.WithService(monitor.Register),
// )
func Register(c *core.Core) core.Result {
mon := New()
mon.core = c
c.Service("monitor", core.Service{
OnStart: func() core.Result {
mon.Start(c.Context())
return core.Result{OK: true}
},
})
// Register IPC handler for agent lifecycle events
c.RegisterAction(func(c *core.Core, msg core.Message) core.Result {
switch ev := msg.(type) {
case messages.AgentCompleted:
mon.handleAgentCompleted(ev)
case messages.AgentStarted:
mon.handleAgentStarted(ev)
}
return core.Result{OK: true}
})
return core.Result{OK: true}
}