heartbeat

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package heartbeat implements periodic agent turns that check a HEARTBEAT.md checklist and optionally deliver results to channel bots.

The runner triggers an agent turn at a configurable interval, using a light system prompt (identity + HEARTBEAT.md only). If the agent replies with HEARTBEAT_OK (optionally followed by ≤ackMaxChars of text), the response is suppressed. Otherwise the response is delivered to the configured target.

Index

Constants

View Source
const HeartbeatOK = "HEARTBEAT_OK"

HeartbeatOK is the token that agents emit to indicate nothing needs attention.

Variables

This section is empty.

Functions

func IsWithinActiveHours

func IsWithinActiveHours(start, end, timezone string, now time.Time) bool

IsWithinActiveHours checks if the given time falls within the [start, end) window. Times are in HH:MM format (24h). "24:00" is allowed for end. If start == end, returns false (zero-width window). If end < start, the window wraps across midnight.

func StripHeartbeatToken

func StripHeartbeatToken(raw string, maxAckChars int) (string, bool)

StripHeartbeatToken checks if the response starts with HEARTBEAT_OK. Returns the cleaned text and whether it should be delivered.

Types

type Chatter

type Chatter interface {
	Chat(ctx context.Context, sessionKey, message string) (agentapi.Response, error)
	ChatLight(ctx context.Context, sessionKey, message string) (agentapi.Response, error)
	SetSessionModel(key, model string)
	ClearSessionModel(key string)
}

Chatter is the minimal agent interface needed by the heartbeat runner.

type Deliverer

type Deliverer interface {
	SendToAllPaired(text string)
}

Deliverer can broadcast a message to all paired users on a channel.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner manages the periodic heartbeat loop.

func NewRunner

func NewRunner(opts RunnerOpts) *Runner

NewRunner creates a heartbeat runner.

func (*Runner) Start

func (r *Runner) Start(ctx context.Context) error

Start runs the heartbeat loop until ctx is cancelled. It respects config changes (interval, active hours) on each tick.

type RunnerOpts

type RunnerOpts struct {
	Logger       *zap.SugaredLogger
	Agent        Chatter
	CfgFn        func() config.HeartbeatConfig // dynamic config getter
	UserTZFn     func() string                 // dynamic timezone getter
	ResolveAlias func(string) string           // model alias resolver
	Workspace    string
	Deliverers   []Deliverer
	SessionKey   string // session key for heartbeat turns (default "heartbeat:main")
}

RunnerOpts configures a new Runner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL