notifydelivery

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 25 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 notifydelivery owns coordination contracts for external notification providers. M0 supplies only the policy-adjacent ledger; no provider can run.

Index

Constants

View Source
const (
	ChannelNative = "native"
	ChannelSound  = "sound"
	DefaultLease  = 30 * time.Second
	// RemoteUnavailableReason is stable status text for the deliberately local
	// delivery boundary. Sidecar never substitutes delivery on an SSH host for
	// delivery by a future local client.
	RemoteUnavailableReason = "remote SSH session; external delivery requires a local Sidecar process"
)
View Source
const (
	ClaimWon            = "claimed"
	ClaimAlreadyClaimed = "already_claimed"
	ClaimCancelled      = "cancelled"
	ReceiptRetention    = 24 * time.Hour
)
View Source
const LedgerFileName = "notification-delivery.jsonl"
View Source
const (
	SoundLedgerFileName = "notification-sound-batches.jsonl"
)

Variables

View Source
var (
	ErrNoClaim      = errors.New("notifydelivery: no active claim")
	ErrClaimOwner   = errors.New("notifydelivery: receipt owner does not own claim")
	ErrInvalidClaim = errors.New("notifydelivery: invalid claim")
)
View Source
var ErrUnsupported = errors.New("notifydelivery: operation unsupported")

Functions

func GroupFor

func GroupFor(n notify.Notification) string

func HostingTerminalBundle

func HostingTerminalBundle(getenv func(string) string) string

HostingTerminalBundle recognizes only fixed environment evidence. The fallbacks remain useful when tmux overwrites TERM_PROGRAM with "tmux".

func StderrTerminalWriter

func StderrTerminalWriter(p []byte) (int, error)

StderrTerminalWriter is the default writer: standard error, and only when standard error is a terminal.

Standard error rather than standard output, because `sidecar notify ... --json` puts machine-readable output on stdout and protocol bytes must never be mixed into it. Refusing a non-terminal stderr keeps the transport honest under a redirect or a pipe, where the sequence would be noise in a log file instead of a notification.

Types

type AssetCache

type AssetCache interface {
	Materialize(Cue) (string, error)
}

type AttentionResolver

type AttentionResolver interface {
	Foreground(notify.Origin) (bool, error)
}

type AudioArbiter

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

AudioArbiter collapses a burst to one highest-priority cue and never overlaps an in-flight player. While one cue plays, every arrival becomes at most one next batch, so a noisy transition burst cannot grow into a long queue.

func NewAudioArbiter

func NewAudioArbiter(player SoundPlayer, window time.Duration, clock Clock) *AudioArbiter

func (*AudioArbiter) Play

func (a *AudioArbiter) Play(ctx context.Context, cue Cue) (ProviderReceipt, error)

func (*AudioArbiter) Probe

func (a *AudioArbiter) Probe(ctx context.Context) Capability

type Capability

type Capability struct {
	Available bool   `json:"available"`
	Provider  string `json:"provider,omitempty"`
	Reason    string `json:"reason,omitempty"`
}

Capability describes an adapter without exposing its platform command.

type ChannelResult

type ChannelResult struct {
	Attempted bool          `json:"attempted"`
	Provider  string        `json:"provider"`
	Delivered bool          `json:"delivered"`
	Reason    notify.Reason `json:"reason,omitempty"`
	Error     string        `json:"error"`
}

type Clock

type Clock interface {
	Now() time.Time
	AfterFunc(time.Duration, func()) Timer
}

type ConfiguredAssetCache

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

ConfiguredAssetCache selects a live custom file when configured and falls back to Sidecar's embedded cue if a hand-edited path becomes invalid. Saved paths are validated earlier by config; this second check protects runtime edits, symlink changes, and file removal between saves.

func NewConfiguredAssetCache

func NewConfiguredAssetCache(fallback AssetCache, source SoundPathSource) *ConfiguredAssetCache

func (*ConfiguredAssetCache) Fallback

func (c *ConfiguredAssetCache) Fallback(cue Cue, attempted string, _ error) (string, bool, error)

func (*ConfiguredAssetCache) Materialize

func (c *ConfiguredAssetCache) Materialize(cue Cue) (string, error)

func (*ConfiguredAssetCache) Selections

func (c *ConfiguredAssetCache) Selections() []assetSelection

type Coordinator

type Coordinator interface {
	Deliver(context.Context, Request) Result
	Remove(context.Context, notify.Notification) error
}

Coordinator is the shared app/CLI boundary. TUI callers invoke it only from a tea.Cmd; CLI fallback calls it after its own fresh store append.

func NewDefault

func NewDefault(stateDir string) Coordinator

NewDefault constructs the production adapters without touching the cache, state tree, PATH, or subprocesses. Those are all lazy first-delivery work.

The terminal transport writes to standard error. That is right for a CLI process but wrong inside the TUI, where the renderer owns the screen and an escape written from a delivery goroutine can land mid-frame; the TUI passes its own writer to NewDefaultWithTerminalWriter instead.

func NewDefaultWithTerminalWriter

func NewDefaultWithTerminalWriter(stateDir string, write func([]byte) (int, error)) Coordinator

NewDefaultWithTerminalWriter is NewDefault with the direct-terminal transport's writer supplied by the caller, so a host that already owns the terminal can sequence the sequence with its own output.

type Cue

type Cue string

Cue is the provider-neutral sound selected by the notification policy.

const (
	CueAttention Cue = "attention"
	CueDone      Cue = "done"
	CueFailure   Cue = "failure"
)

type EmbeddedAssetCache

type EmbeddedAssetCache struct {
	Root string
	// contains filtered or unexported fields
}

EmbeddedAssetCache lazily materializes immutable embedded WAVs. Versioned filenames make an upgrade additive; atomic rename keeps concurrent Sidecar processes from observing a partial player input.

func NewEmbeddedAssetCache

func NewEmbeddedAssetCache(root string) *EmbeddedAssetCache

func (*EmbeddedAssetCache) Materialize

func (c *EmbeddedAssetCache) Materialize(cue Cue) (string, error)

type Entry

type Entry struct {
	NotificationID string     `json:"notificationId"`
	Channel        string     `json:"channel"`
	Owner          string     `json:"owner"`
	ClaimedAt      time.Time  `json:"claimedAt"`
	LeaseUntil     time.Time  `json:"leaseUntil"`
	Group          string     `json:"group,omitempty"`
	Receipt        *Receipt   `json:"receipt,omitempty"`
	CancelledAt    *time.Time `json:"cancelledAt,omitempty"`
}

type ExecRunner

type ExecRunner struct{}

func (ExecRunner) LookPath

func (ExecRunner) LookPath(name string) (string, error)

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, name string, args ...string) error

type HostSound

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

HostSound coordinates the burst window and playback lease through a small locked JSONL file. Independent Sidecar processes therefore share one batch winner and one playback slot while the underlying player remains replaceable. Construction is I/O-free; enqueue is called only from app commands or CLI.

func NewHostSound

func NewHostSound(stateDir string, player SoundPlayer, window, lease time.Duration, clock Clock) *HostSound

func (*HostSound) Cancel

func (h *HostSound) Cancel(_ context.Context, notificationID string) error

func (*HostSound) PlayNotification

func (h *HostSound) PlayNotification(ctx context.Context, notificationID string, cue Cue) (ProviderReceipt, error)

func (*HostSound) Probe

func (h *HostSound) Probe(ctx context.Context) Capability

type JSONLLedger

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

func Open

func Open(stateDir string) (*JSONLLedger, error)

func OpenPath

func OpenPath(path string) (*JSONLLedger, error)

func (*JSONLLedger) Cancel

func (l *JSONLLedger) Cancel(notificationID, group, owner string, now time.Time, remove func() error) NativeCancelResult

func (*JSONLLedger) Cancelled

func (l *JSONLLedger) Cancelled(notificationID string) (bool, error)

func (*JSONLLedger) Claim

func (l *JSONLLedger) Claim(notificationID, channel, owner string, now time.Time, lease time.Duration) (bool, string, error)

func (*JSONLLedger) Close

func (l *JSONLLedger) Close() error

func (*JSONLLedger) Complete

func (l *JSONLLedger) Complete(notificationID, channel string, receipt Receipt) error

func (*JSONLLedger) DeliverNative

func (l *JSONLLedger) DeliverNative(notificationID, group, owner string, now time.Time, lease time.Duration, invoke func() (ProviderReceipt, error)) NativeOperationResult

func (*JSONLLedger) List

func (l *JSONLLedger) List(notificationID string) ([]Entry, error)

func (*JSONLLedger) ReleaseExpired

func (l *JSONLLedger) ReleaseExpired(now time.Time) (int, error)

type Ledger

type Ledger interface {
	Claim(notificationID, channel, owner string, now time.Time, lease time.Duration) (won bool, reason string, err error)
	Complete(notificationID, channel string, receipt Receipt) error
	ReleaseExpired(now time.Time) (int, error)
	List(notificationID string) ([]Entry, error)
	Cancelled(notificationID string) (bool, error)
	DeliverNative(notificationID, group, owner string, now time.Time, lease time.Duration, invoke func() (ProviderReceipt, error)) NativeOperationResult
	Cancel(notificationID, group, owner string, now time.Time, remove func() error) NativeCancelResult
	Close() error
}

type MemoryLedger

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

MemoryLedger is the deterministic test and fallback implementation.

func NewMemoryLedger

func NewMemoryLedger() *MemoryLedger

func (*MemoryLedger) Cancel

func (l *MemoryLedger) Cancel(notificationID, group, owner string, now time.Time, remove func() error) NativeCancelResult

func (*MemoryLedger) Cancelled

func (l *MemoryLedger) Cancelled(notificationID string) (bool, error)

func (*MemoryLedger) Claim

func (l *MemoryLedger) Claim(notificationID, channel, owner string, now time.Time, lease time.Duration) (bool, string, error)

func (*MemoryLedger) Close

func (l *MemoryLedger) Close() error

func (*MemoryLedger) Complete

func (l *MemoryLedger) Complete(notificationID, channel string, receipt Receipt) error

func (*MemoryLedger) DeliverNative

func (l *MemoryLedger) DeliverNative(notificationID, group, owner string, now time.Time, lease time.Duration, invoke func() (ProviderReceipt, error)) NativeOperationResult

func (*MemoryLedger) List

func (l *MemoryLedger) List(notificationID string) ([]Entry, error)

func (*MemoryLedger) ReleaseExpired

func (l *MemoryLedger) ReleaseExpired(now time.Time) (int, error)

type Message

type Message struct {
	NotificationID     string
	Title              string
	Body               string
	Severity           notify.Severity
	Sticky             bool
	Group              string
	ActivationBundleID string
}

Message is the bounded, sanitized input to a native-notification adapter. Group and ActivationBundleID are derived by Sidecar, never supplied by a notification body or target.

func NativeMessage

func NativeMessage(n notify.Notification) Message

NativeMessage applies one sanitization/bounds contract before any provider sees OS-retained text.

type NativeCancelResult

type NativeCancelResult struct {
	Removed bool
	Reason  string
	Err     error
}

type NativeGroupState

type NativeGroupState struct {
	Group          string    `json:"group"`
	NotificationID string    `json:"notificationId"`
	Phase          string    `json:"phase"`
	UpdatedAt      time.Time `json:"updatedAt"`
}

type NativeNotifier

type NativeNotifier interface {
	Probe(context.Context) Capability
	Deliver(context.Context, Message) (ProviderReceipt, error)
	Remove(context.Context, string) error
}

func NewNativeWithTerminal

func NewNativeWithTerminal(local, terminal NativeNotifier, getenv func(string) string) NativeNotifier

NewNativeWithTerminal routes native delivery by locality.

A local process uses the platform desktop provider. A process inside SSH uses the direct-terminal transport, which is the only native provider that can do anything useful from there — the desktop providers stay fail-closed remote, and sound never crosses the boundary at all.

func NewPlatformNative

func NewPlatformNative(runner Runner) NativeNotifier

func NewTerminalNative

func NewTerminalNative(opts TerminalOptions) NativeNotifier

NewTerminalNative builds the opt-in direct-terminal transport. Construction performs no I/O and reads no configuration.

type NativeOperationResult

type NativeOperationResult struct {
	Attempted bool
	Receipt   ProviderReceipt
	Reason    string
	Err       error
}

type ProviderReceipt

type ProviderReceipt struct {
	Provider  string
	Delivered bool
	Reason    string
	At        time.Time
}

ProviderReceipt is one adapter attempt. Delivered=false with a reason is a deliberate provider-level suppression, such as an audio burst losing to a higher-priority cue, rather than an invocation error.

type RealClock

type RealClock struct{}

func (RealClock) AfterFunc

func (RealClock) AfterFunc(d time.Duration, fn func()) Timer

func (RealClock) Now

func (RealClock) Now() time.Time

type Receipt

type Receipt struct {
	Owner       string    `json:"owner"`
	Provider    string    `json:"provider,omitempty"`
	Succeeded   bool      `json:"succeeded"`
	Error       string    `json:"error,omitempty"`
	CompletedAt time.Time `json:"completedAt"`
}

Receipt is the durable terminal outcome of a delivery attempt. Success and failure are both receipts: neither should replay indefinitely.

type Request

type Request struct {
	Notification notify.Notification
	Discovered   bool
	ExplicitTest bool
	// Channel narrows an explicit test to native or sound. Empty means both.
	Channel string
}

func ExplicitTestRequest

func ExplicitTestRequest(event TestEvent) (Request, error)

ExplicitTestRequest builds the one provider test notification used by the TUI and CLI. It is never posted to notify.Store, so testing cannot create an unread centre record.

type Result

type Result struct {
	Native ChannelResult `json:"native"`
	Sound  ChannelResult `json:"sound"`
}

type Runner

type Runner interface {
	LookPath(string) (string, error)
	Run(context.Context, string, ...string) error
}

type Service

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

Service resolves policy, claims independently, and invokes the two provider channels independently. Construction performs no I/O or capability probes.

func NewService

func NewService(opts ServiceOptions) *Service

func (*Service) Deliver

func (s *Service) Deliver(ctx context.Context, req Request) Result

func (*Service) Remove

func (s *Service) Remove(ctx context.Context, n notify.Notification) error

func (*Service) Status

func (s *Service) Status(ctx context.Context) Status

Status probes both adapters without touching the ledger or delivering anything. Callers must invoke it asynchronously; construction and rendering remain I/O-free.

type ServiceOptions

type ServiceOptions struct {
	Native           NativeNotifier
	Sound            SoundPlayer
	SoundCoordinator SoundCoordinator
	Ledger           func() (Ledger, error)
	Attention        AttentionResolver
	Config           func() notify.ResolvedConfig
	Clock            Clock
	Getenv           func(string) string
	Owner            string
	Lease            time.Duration
}

type SoundCoordinator

type SoundCoordinator interface {
	Probe(context.Context) Capability
	PlayNotification(context.Context, string, Cue) (ProviderReceipt, error)
	Cancel(context.Context, string) error
}

type SoundPathSource

type SoundPathSource func() (SoundPaths, error)

type SoundPaths

type SoundPaths struct {
	ConfigPath string
	Attention  string
	Done       string
	Failure    string
}

SoundPaths is the persisted custom-path portion of notification config. It stays transport-neutral so adapters do not need to know how config is stored.

type SoundPlayer

type SoundPlayer interface {
	Probe(context.Context) Capability
	Play(context.Context, Cue) (ProviderReceipt, error)
}

func NewPlatformSound

func NewPlatformSound(runner Runner, cache AssetCache) SoundPlayer

type Status

type Status struct {
	Native Capability `json:"native"`
	Sound  Capability `json:"sound"`
	Remote bool       `json:"remote"`
}

Status is the provider state reported by Configuration and the CLI. Remote explains why both deliberately local external channels are unavailable.

type StatusProvider

type StatusProvider interface {
	Status(context.Context) Status
}

StatusProvider is the read-only capability side of a Coordinator. It is a separate interface so small delivery fakes and alternate hosts do not need to claim they can probe providers. Production Service implements both.

type TerminalOptions

type TerminalOptions struct {
	// Getenv supplies the environment the terminal is detected from.
	Getenv func(string) string
	// Selected reads the configured terminal. It is called per probe and per
	// delivery, so a Configuration change applies without a restart.
	Selected func() config.TerminalNotifier
	// Write emits one complete sequence.
	Write func([]byte) (int, error)
	// Flush is called after a successful write. A nil Flush means the writer
	// buffers nothing, which is true of the unbuffered default below.
	Flush func() error
}

TerminalOptions binds the pure encoders in internal/termnotify to the native notifier seam.

Write and Flush are injected rather than resolved here because the human TUI and these protocol bytes share one process and one file descriptor. Only an app-owned writer knows when it is safe to emit them, and a package that picked its own output stream would eventually mix an escape sequence into structured CLI output.

type TestEvent

type TestEvent string

TestEvent is the stable event vocabulary accepted by every explicit-test surface.

const (
	TestWaiting TestEvent = "waiting"
	TestDone    TestEvent = "done"
	TestFailure TestEvent = "failure"
)

type Timer

type Timer interface{ Stop() bool }

Directories

Path Synopsis
assets
gen command

Jump to

Keyboard shortcuts

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