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 ¶
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.
const ParseMode = "HTML"
ParseMode is the Telegram parse mode Message and CheckMessage are written for. Everything that comes from a session is escaped by html.
Variables ¶
This section is empty.
Functions ¶
func CheckMessage ¶
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 what will arrive.
func Message ¶
Message renders an alert as one Telegram message in HTML.
The first line is what a lock screen shows, so it carries what happened and which session: "✅ Finished · <title>". Then the folder and branch, and for a finished run what it took and changed and the first line of its reply; for a dialog, the tool and the command or file it asks about. What this sends to Telegram is set out in ADR-036.
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
// Trigger is the event the alert is about: the permission.prompt, or the
// Stop (or StopFailure, recorded as throttle) that ended the turn. The
// message reads what it asks about or how the turn ended from it.
Trigger event.Event
}
Alert is one message to send.
type Details ¶ added in v0.74.0
type Details struct {
// Title is the session's name as Now shows it: the agent's own title, or
// the first prompt that says something.
Title string
// Cwd is the session's directory; Home is the owner's home directory, so
// the folder reads ~/dev/caprock rather than one of several "caprock"s.
Cwd, Home string
Branch string
// Agent is the agent's display name. Claude Code, the usual one, is not
// repeated on every message.
Agent string
// Link is the session's page at an address the phone can open; empty
// when phone access is off, and then the line is left out rather than
// offering a loopback address that opens nothing.
Link string
// The run a finished alert reports: since the owner's last prompt.
Run time.Duration
CostUSD float64
Tools int
// Files are the paths the run changed, first changed first.
Files []string
// Reply is the agent's final reply; empty when the owner switched the
// line off or there is none.
Reply string
}
Details is what the daemon knows about the session an alert is about. Any field may be empty; the message leaves out what it does not know.
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.