alerts

package
v2.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 8 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 pushes a phone notification when an interactive session needs its operator — docs/agent-events.md section 3. It is wired as agentevents.Ingester.OnHookEvent (see internal/app), so it only observes hook-driven sessions. That covers the overwhelming majority in practice: every builtin claude/codex session installs its hooks at launch unless the install itself fails (section 2), and a hooked session's state is hook-preferred for 10 minutes of silence before the screen-scrape fallback is even allowed to touch it (internal/sessions/poll.go). A session that never gets hooks at all, or one that has been silent past that window, is not separately alerted by this package — see the section 3 worker's final report for that scope call. PreCompact and Stop's last_assistant_message never reach the bus as structured session fields, which is why this listens on the raw hook event rather than a generic "session changed" bus subscription: the fields it needs are only ever on the wire, once, right here.

Index

Constants

View Source
const (
	KeyWaitingPermission = "alert_waiting_permission"
	KeyWaitingInput      = "alert_waiting_input"
	KeyIdle              = "alert_idle"
	KeyError             = "alert_error"
	KeyCompacting        = "alert_compacting"
)

Settings keys, appended to sinks.Keys so the existing PUT/GET /api/settings endpoint and Notifications UI can read and write them without a second settings registry. Every one defaults ON: a fresh install should not silently swallow the first alert while an operator is still discovering the toggle exists.

View Source
const DefaultCooldown = 60 * time.Second

DefaultCooldown is the minimum spacing between two alerts for the SAME session, regardless of what changed — a flapping pane must not become a notification storm. Never repeating for the same target state is a separate, always-on rule that falls out of only ever firing on an actual IngestEvent state transition (see HandleHookEvent) — no bookkeeping is needed for that half, only for this one.

View Source
const SuppressWindow = 30 * time.Second

SuppressWindow: a browser that sent real terminal input for a session in the last 30s means a person is plainly already looking at it.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

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

Activity records the last time a browser sent input into a session's terminal, for the "suppressed if a browser typed into that session within the last 30s" rule.

Populated from POST /api/term/{kind}/{id}/activity, an explicit heartbeat the terminal page sends whenever it actually sends bytes to the pty (frontend/src/terminal/engine.ts's input(), throttled client-side) — documented deviation from hooking the ttyd reverse proxy itself: the proxy (internal/api/termproxy.go's termProxy) hands an Upgrade request straight to net/http/httputil.ReverseProxy, which hijacks the connection and pipes it byte-for-byte in both directions with no per-message callback. Adding one would mean replacing that proxy with a hand-rolled hijacking implementation across every terminal attachment kind (session/attempt/project/companion shells) — a lot of surface and regression risk to take on for what an explicit page-level heartbeat already gets, with far less code and no risk to the existing terminal e2e suite.

func NewActivity

func NewActivity() *Activity

NewActivity builds an empty tracker.

func (*Activity) Recent

func (a *Activity) Recent(sessionID int64, window time.Duration) bool

Recent reports whether sessionID had input within window.

func (*Activity) Touch

func (a *Activity) Touch(sessionID int64)

Touch records that a browser just sent real input to sessionID.

type Watcher

type Watcher struct {
	DB       *store.DB
	Notifier *sinks.Notifier
	// Activity suppresses an alert when set and the session was just typed
	// into; nil disables suppression entirely (still safe, just less quiet).
	Activity *Activity
	// Cooldown overrides DefaultCooldown; zero means DefaultCooldown.
	Cooldown time.Duration
	// Clock overrides time.Now for tests. nil means time.Now.
	Clock func() time.Time
	// contains filtered or unexported fields
}

Watcher turns hook events into pushes through the existing sinks.Notifier. Wire HandleHookEvent as agentevents.Ingester.OnHookEvent.

func (*Watcher) HandleHookEvent

func (w *Watcher) HandleHookEvent(sess *store.Session, event string, body []byte, state string, changed bool)

HandleHookEvent is agentevents.Ingester.OnHookEvent. It runs synchronously inside the hook HTTP handler's call to IngestEvent, so every code path here must stay cheap — Notifier.Notify itself already fans out asynchronously (see internal/sinks), which is what keeps this fast.

Jump to

Keyboard shortcuts

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