sinks

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: 10 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 sinks fans notifications out to web-push, a Discord webhook and ntfy, best-effort and never blocking the caller.

ntfy approval notifications carry real approve/deny HTTP action buttons, so a phone can decide without opening the app (and without VAPID setup).

Index

Constants

This section is empty.

Variables

View Source
var Keys = []string{
	"discord_webhook", "ntfy_server", "ntfy_topic", "summary_agent", "summary_model",
	"alert_waiting_permission", "alert_waiting_input", "alert_idle", "alert_error", "alert_compacting",
	"session_permission_mode",
	"judge_agent", "judge_model", "eval_concurrency",

	"awareness_briefing", "awareness_edit_warning",

	"claims_briefing", "claims_edit_warning", "claims_auto_paths",

	"claude_terminal_mouse",
}

Keys are the settings rows this package owns. Anything else is rejected by the settings endpoint so a typo cannot silently disable notifications.

The alert_* keys and session_permission_mode belong conceptually to internal/alerts and internal/sessions respectively (docs/agent-events.md section 3), but PUT/GET /api/settings only validates against this one list (internal/api/misc.go), so they are appended here rather than standing up a second settings registry for two features. Values are "0"/"1" strings for the toggles (missing or anything but "0" means ON — see internal/alerts.Enabled) and "bypass"/"ask" for the permission mode default (missing or anything but "ask" means "bypass").

Functions

func ApprovalTag added in v2.6.0

func ApprovalTag(id int64) string

ApprovalTag is the tag every device groups an approval's notification under (sw-actions.ts groupTag, the Android app's Notifications.tagOf).

func Subscribe

func Subscribe(db *store.DB, sub push.Subscription) error

Subscribe records (or refreshes) a browser push subscription.

func Unsubscribe added in v2.4.0

func Unsubscribe(db *store.DB, endpoint string) error

Unsubscribe removes one browser's push subscription by endpoint — the same identity a 404/410 delivery failure prunes automatically (sendPush above). It never errors on an endpoint that is already gone: asking to unsubscribe a device that was never (or is no longer) subscribed is not a failure.

Types

type Extra

type Extra struct {
	Kind       string
	ApprovalID int64
	// SessionID, when set, is included in the web-push payload as
	// session_id so the service worker (and anything else reading a push
	// message) can act on the session directly rather than parsing it back
	// out of the deep-link URL.
	SessionID int64
	// LimitID, when set, is the usage-limit hold (internal/limits) the push
	// is about; the service worker's one-tap choices post to it.
	LimitID int64
}

Extra carries the notification's context — which is what turns an ntfy message into one with decision buttons, and what a web-push payload's kind/session_id fields (docs/agent-events.md section 3) come from.

type Notifier

type Notifier struct {
	DB      *store.DB
	BaseURL string
	Push    *push.Sender
	Log     *slog.Logger
	Client  *http.Client

	// Hook, when set, replaces real delivery. Tests assert on the built payloads
	// without any network at all — the same seam the Python suite used.
	Hook func([]Payload)
	// PushHook, when set, receives each web-push message instead of the push
	// service, whether or not VAPID keys are configured. Tests only.
	PushHook func(raw []byte)
	// contains filtered or unexported fields
}

Notifier owns the sink fan-out.

func (*Notifier) Dismiss added in v2.6.0

func (n *Notifier) Dismiss(tag, title, body string)

Dismiss tells every subscribed device that a notification no longer needs anyone, so an approval decided on one phone leaves the others' trays. Web push only: an ntfy or Discord message cannot be withdrawn.

func (*Notifier) Notify

func (n *Notifier) Notify(title, body, urlPath string, extra *Extra)

Notify sends to every configured sink. Delivery happens on a goroutine: a sink outage must never slow a dispatch down, let alone fail one.

func (*Notifier) Settings

func (n *Notifier) Settings() map[string]string

Settings reads the configured sinks.

func (*Notifier) Wait

func (n *Notifier) Wait()

Wait blocks until in-flight deliveries finish — used at shutdown.

type Payload

type Payload struct {
	Kind string         `json:"kind"`
	URL  string         `json:"url"`
	Body map[string]any `json:"body"`
}

Payload is one outbound notification, already addressed and rendered.

func BuildPayloads

func BuildPayloads(cfg map[string]string, baseURL, title, body, urlPath string, extra *Extra) []Payload

BuildPayloads is the pure builder: one payload per configured sink.

type SubscriptionInfo added in v2.4.0

type SubscriptionInfo struct {
	ID        int64   `json:"id"`
	Endpoint  string  `json:"endpoint"`
	CreatedAt float64 `json:"created_at"`
}

SubscriptionInfo is one subscribed device, as listed for the settings UI. The endpoint is included so the UI can point out "this device" (it matches the endpoint the browser's own pushManager.getSubscription() returns) — it is not secret, unlike the p256dh/auth keys, which this never exposes.

func Subscriptions added in v2.4.0

func Subscriptions(db *store.DB) ([]SubscriptionInfo, error)

Subscriptions lists every subscribed device, newest first.

Jump to

Keyboard shortcuts

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