Files
pipelines/internal/protocol/notification_settings.go
T
alan fc7dbb0ac0 Remove ntfy: notifications go only through the app notification stream
Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat
tool notify, auto-switch and schedule notices), the chat push outbox (its
table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*.
The app_notifications stream, subscribe/clear and kinds are unchanged.
Notification settings keep run_finished/chat_needs_you/chat_reply_finished;
ntfy_enabled is accepted and ignored and its stored row is never read.

Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to
the Pipelines apps — use the stage notify hook". The notify hook remains.

Installer: no ntfy build, accounts, config or supervisor child; manifest
gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an
old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log,
with a note in logs/install.log); uninstall cleans leftovers.

App: ntfy settings section replaced by "Notification events"; texts updated.
Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli,
author skill references updated; security review M1 marked resolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:24:24 +00:00

105 lines
3.7 KiB
Go

package protocol
import (
"fmt"
"sort"
)
// Notification settings are the operator's global choices about which events
// are recorded on the app notification stream (subscribe_notifications), and
// so reach every signed-in Pipelines app. A client reads them with
// {"type":"notification_settings"} and changes them with
// {"type":"set_notification_settings","notification_settings":{"<key>":bool}};
// a set may name any subset of keys, and unknown keys or non-boolean values
// are refused (the removed ntfy_enabled key is accepted and ignored, so an
// older client's switch does not fail). Both replies have type
// "notification_settings" and carry every key with its stored value.
const (
GetNotificationSettings = "notification_settings"
SetNotificationSettings = "set_notification_settings"
NotificationSettingsReply = "notification_settings"
)
// Notification setting keys, as carried on the wire.
const (
NotifyRunFinished = "run_finished"
NotifyChatNeedsYou = "chat_needs_you"
NotifyChatReplyFinished = "chat_reply_finished"
// LegacyNotifyNtfyEnabled is the removed "also send to ntfy" switch. A set
// that names it is accepted and the key ignored; a stored value is never
// read.
LegacyNotifyNtfyEnabled = "ntfy_enabled"
)
// NotificationSettings is the typed form of the global notification choices.
type NotificationSettings struct {
// RunFinished makes every run end (success or failure) notify, not only
// runs started with notify mode "on". Off by default: an "auto" run then
// notifies only when it waits for a human decision, and "off" never does.
RunFinished bool
// ChatNeedsYou notifies when a chat asks a question or requests approval.
ChatNeedsYou bool
// ChatReplyFinished notifies when an assistant turn in a chat ends.
ChatReplyFinished bool
}
// NotificationSettingKeys lists every setting key in a stable order.
var NotificationSettingKeys = []string{NotifyRunFinished, NotifyChatNeedsYou, NotifyChatReplyFinished}
// DefaultNotificationSettings are the values before the operator changes any.
func DefaultNotificationSettings() NotificationSettings {
return NotificationSettings{RunFinished: false, ChatNeedsYou: true, ChatReplyFinished: false}
}
// Map returns the wire form with every key present.
func (s NotificationSettings) Map() map[string]any {
return map[string]any{
NotifyRunFinished: s.RunFinished,
NotifyChatNeedsYou: s.ChatNeedsYou,
NotifyChatReplyFinished: s.ChatReplyFinished,
}
}
// Field returns a pointer to the setting named key, or nil for an unknown key.
func (s *NotificationSettings) Field(key string) *bool {
switch key {
case NotifyRunFinished:
return &s.RunFinished
case NotifyChatNeedsYou:
return &s.ChatNeedsYou
case NotifyChatReplyFinished:
return &s.ChatReplyFinished
}
return nil
}
// ValidateNotificationSettingsUpdate checks a partial update: at least one key,
// every key known and every value a boolean. The legacy ntfy_enabled key is
// dropped from the result, so an update naming only it changes nothing.
func ValidateNotificationSettingsUpdate(update map[string]any) (map[string]bool, error) {
if len(update) == 0 {
return nil, fmt.Errorf("notification_settings must name at least one setting")
}
keys := make([]string, 0, len(update))
for key := range update {
keys = append(keys, key)
}
sort.Strings(keys)
result := make(map[string]bool, len(update))
var probe NotificationSettings
for _, key := range keys {
if key == LegacyNotifyNtfyEnabled {
continue
}
if probe.Field(key) == nil {
return nil, fmt.Errorf("unknown notification setting %q", key)
}
value, ok := update[key].(bool)
if !ok {
return nil, fmt.Errorf("notification setting %q must be true or false", key)
}
result[key] = value
}
return result, nil
}