alerts

package
v0.72.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package alerts decides when the owner's phone hears about a session: at once when it shows a permission dialog, and a minute after it finishes a turn with nothing following. Pure rules over the event stream, with no clock or network of its own; the daemon feeds it and sends what it returns (ADR-036).

Index

Constants

View Source
const (
	// FinishedAfter is how long a Stop must stand before it is "finished": an
	// agent pausing between turns, or an owner replying at once, pages nobody.
	FinishedAfter = time.Minute
	// Cooldown is the quietest a session may be between two alerts of one kind.
	// A run of permission dialogs a few seconds apart is one interruption, and
	// whoever answered the first is already looking.
	Cooldown = 3 * time.Minute
	// HourlyCap bounds every alert together, whatever the sessions do.
	HourlyCap = 20
)

Defaults, chosen so that someone at the keyboard is never paged and someone away from it hears once.

Variables

This section is empty.

Functions

func CheckMessage

func CheckMessage(link string) string

CheckMessage is what "Send a test alert" sends: the same shape as a real one, saying it is a test, so the person setting it up sees exactly what will arrive.

func Message

func Message(a Alert, project, agent, link string) string

Message renders an alert as the text of one Telegram message.

What it may carry is the whole privacy argument for sending it (ADR-036): the project's folder name, what happened, which agent, and a link back to the dashboard. Never a prompt, a reply, a tool, a command or a path — Telegram reads every word of it. link is empty when the dashboard cannot be reached from a phone, and then the line is left out rather than offering a loopback address that opens nothing.

Types

type Alert

type Alert struct {
	Kind      Kind
	SessionID string
	// Question says the dialog is AskUserQuestion's: waiting for an answer
	// rather than an approval.
	Question bool
	// LastThisHour says this alert used the hour's final slot, so the message
	// can say the rest are held back rather than leaving a silence to explain.
	LastThisHour bool
}

Alert is one message to send.

type Kind

type Kind string

Kind is what an alert says about a session.

const (
	// KindApproval: the session is showing a permission dialog.
	KindApproval Kind = "approval"
	// KindFinished: the session ended a turn and nothing followed for a minute.
	KindFinished Kind = "finished"
)

type Rules

type Rules struct {
	// Enabled says whether a kind is switched on right now. A switched-off
	// kind is still tracked, so turning it on later starts from the truth.
	Enabled func(Kind) bool
	// contains filtered or unexported fields
}

Rules holds what the alerts depend on: which sessions are waiting or stopped, and what was sent when. Not safe for concurrent use.

func New

func New(enabled func(Kind) bool) *Rules

New returns rules with nothing pending.

func (*Rules) Due

func (r *Rules) Due(now time.Time) []Alert

Due returns the finished alerts whose minute has passed, and forgets sessions with nothing left to decide.

func (*Rules) Observe

func (r *Rules) Observe(ev event.Event, now time.Time) []Alert

Observe takes one stored event and returns the alerts it causes now: an approval alert for a permission dialog, at most one per dialog.

Jump to

Keyboard shortcuts

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