refactor(heartbeat): simplify service with single handler and direct bus usage

- Remove redundant ChannelSender interface, use *bus.MessageBus directly
- Consolidate two handlers (onHeartbeat, onHeartbeatWithTools) into one
- Move HEARTBEAT.md and heartbeat.log to workspace root
- Simplify NewHeartbeatService signature (remove handler param)
- Add SetBus and SetHandler methods for dependency injection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yinwm
2026-02-13 09:51:51 +08:00
parent b59464230a
commit 8fbbb67f70
3 changed files with 127 additions and 198 deletions

View File

@@ -654,10 +654,20 @@ func gatewayCmd() {
heartbeatService := heartbeat.NewHeartbeatService(
cfg.WorkspacePath(),
nil,
30*60,
30,
cfg.Heartbeat.Enabled,
)
heartbeatService.SetBus(msgBus)
heartbeatService.SetHandler(func(prompt string) *tools.ToolResult {
response, err := agentLoop.ProcessDirect(context.Background(), prompt, "heartbeat")
if err != nil {
return tools.ErrorResult(fmt.Sprintf("Heartbeat error: %v", err))
}
if response == "HEARTBEAT_OK" {
return tools.SilentResult("Heartbeat OK")
}
return tools.UserResult(response)
})
channelManager, err := channels.NewManager(cfg, msgBus)
if err != nil {