Documentation
¶
Index ¶
- Constants
- func AgentIdlePayload(id string, idleSince time.Time) map[string]any
- func AgentPayload(id, agentType, principal string) map[string]any
- func AllEventNames() []string
- func HooksFilePath() string
- func MurmurPayload(id, agentID, principal, topic, importance, content string) map[string]any
- func SaveHook(hook HookConfig) error
- func SessionAvailablePayload(name, url, principal, agentID string) map[string]any
- func SessionPayload(name, agentID string) map[string]any
- func SessionStoppedPayload(name, agentID string, dur time.Duration) map[string]any
- func SessionUploadedPayload(name, url, agentID string, dur time.Duration) map[string]any
- func SyncFailedPayload(workspace, syncType, errMsg string) map[string]any
- func SyncPayload(workspace, syncType string, dur time.Duration) map[string]any
- func ValidEvent(name string) bool
- type Event
- type EventBus
- type HookConfig
- type HookRunner
Constants ¶
const ( EventDaemonStarted = "daemon.started" EventDaemonStopped = "daemon.stopped" EventSessionStarted = "session.started" EventSessionStopped = "session.stopped" EventSessionUploaded = "session.uploaded" EventSessionAvailable = "session.available" EventMurmurReceived = "murmur.received" EventMurmurCritical = "murmur.critical" EventSyncCompleted = "sync.completed" EventSyncFailed = "sync.failed" EventAgentRegistered = "agent.registered" EventAgentIdle = "agent.idle" )
Event name constants. Dot-separated: category.action.
Variables ¶
This section is empty.
Functions ¶
func AgentIdlePayload ¶
AgentIdlePayload builds the payload for agent.idle events.
func AgentPayload ¶
AgentPayload builds the payload for agent.registered events.
func AllEventNames ¶
func AllEventNames() []string
AllEventNames returns all valid event names sorted alphabetically.
func HooksFilePath ¶
func HooksFilePath() string
HooksFilePath returns the path to the hooks.yaml config file.
func MurmurPayload ¶
MurmurPayload builds the payload for murmur.received and murmur.critical events.
func SaveHook ¶
func SaveHook(hook HookConfig) error
SaveHook appends a hook to the hooks.yaml file. Creates the file if it doesn't exist. Uses atomic write-via-rename to prevent corruption from crashes or concurrent writers.
func SessionAvailablePayload ¶
SessionAvailablePayload builds the payload for session.available events.
func SessionPayload ¶
SessionPayload builds the payload for session.started events.
func SessionStoppedPayload ¶
SessionStoppedPayload builds the payload for session.stopped with duration.
func SessionUploadedPayload ¶
SessionUploadedPayload builds the payload for session.uploaded events.
func SyncFailedPayload ¶
SyncFailedPayload builds the payload for sync.failed events.
func SyncPayload ¶
SyncPayload builds the payload for sync.completed events.
func ValidEvent ¶
ValidEvent returns true if name is a known event name.
Types ¶
type Event ¶
type Event struct {
Name string `json:"event"`
Timestamp time.Time `json:"timestamp"`
Project string `json:"project_root"`
RepoID string `json:"repo_id"`
Payload map[string]any `json:"-"` // merged into top-level JSON, not nested
}
Event represents a daemon event that can trigger notifications and hooks.
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus dispatches daemon events to hook scripts. All dispatch is asynchronous — Emit() never blocks the caller.
type HookConfig ¶
type HookConfig struct {
Event string `yaml:"event" json:"event"`
Command string `yaml:"command" json:"command"`
}
HookConfig defines a user-registered hook script triggered by daemon events.
func LoadHooks ¶
func LoadHooks() ([]HookConfig, error)
LoadHooks reads and validates hook configurations from hooks.yaml. Returns an empty slice (not error) if the file doesn't exist.
func LoadHooksFrom ¶
func LoadHooksFrom(path string) ([]HookConfig, error)
LoadHooksFrom reads hooks from a specific file path. Exported for testing.
type HookRunner ¶
type HookRunner struct {
// contains filtered or unexported fields
}
HookRunner executes user-defined hook scripts for matching events. Scripts receive the event as JSON on stdin with a hard 500ms timeout.
func NewHookRunner ¶
func NewHookRunner(hooks []HookConfig, logger *slog.Logger) *HookRunner
NewHookRunner creates a HookRunner with the given hooks.
func (*HookRunner) Dispatch ¶
func (r *HookRunner) Dispatch(ctx context.Context, event Event)
Dispatch finds hooks matching the event and runs each in a background goroutine. Never blocks the caller.
func (*HookRunner) SetHooks ¶
func (r *HookRunner) SetHooks(hooks []HookConfig)
SetHooks replaces the current hook configuration.
func (*HookRunner) Wait ¶
func (r *HookRunner) Wait()
Wait blocks until all dispatched hooks have finished. Intended for tests; production callers should treat Dispatch as fire-and-forget.