agent/pkg/monitor/register.go
Snider 4e69daf2da feat: replace initServices() with core.New() service conclave
Services are now registered during Core construction:
  core.New(
      core.WithService(agentic.Register),
      core.WithService(monitor.Register),
      core.WithService(brain.Register),
  )

- Remove initServices() closure — services created once in conclave
- Commands use c.ServiceStartup()/c.ServiceShutdown() for lifecycle
- Service instances retrieved via c.Config() for MCP tool registration
- run/orchestrator reduced to ServiceStartup + block + ServiceShutdown
- run/task uses conclave's agentic instance

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-24 16:33:04 +00:00

43 lines
979 B
Go

// 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}
})
// Store instance for MCP tool registration
c.Config().Set("monitor.instance", mon)
return core.Result{OK: true}
}