Documentation
¶
Overview ¶
Package notifydelivery owns coordination contracts for external notification providers. M0 supplies only the policy-adjacent ledger; no provider can run.
Index ¶
- Constants
- Variables
- func GroupFor(n notify.Notification) string
- func HostingTerminalBundle(getenv func(string) string) string
- func StderrTerminalWriter(p []byte) (int, error)
- type AssetCache
- type AttentionResolver
- type AudioArbiter
- type Capability
- type ChannelResult
- type Clock
- type ConfiguredAssetCache
- type Coordinator
- type Cue
- type EmbeddedAssetCache
- type Entry
- type ExecRunner
- type HostSound
- type JSONLLedger
- func (l *JSONLLedger) Cancel(notificationID, group, owner string, now time.Time, remove func() error) NativeCancelResult
- func (l *JSONLLedger) Cancelled(notificationID string) (bool, error)
- func (l *JSONLLedger) Claim(notificationID, channel, owner string, now time.Time, lease time.Duration) (bool, string, error)
- func (l *JSONLLedger) Close() error
- func (l *JSONLLedger) Complete(notificationID, channel string, receipt Receipt) error
- func (l *JSONLLedger) DeliverNative(notificationID, group, owner string, now time.Time, lease time.Duration, ...) NativeOperationResult
- func (l *JSONLLedger) List(notificationID string) ([]Entry, error)
- func (l *JSONLLedger) ReleaseExpired(now time.Time) (int, error)
- type Ledger
- type MemoryLedger
- func (l *MemoryLedger) Cancel(notificationID, group, owner string, now time.Time, remove func() error) NativeCancelResult
- func (l *MemoryLedger) Cancelled(notificationID string) (bool, error)
- func (l *MemoryLedger) Claim(notificationID, channel, owner string, now time.Time, lease time.Duration) (bool, string, error)
- func (l *MemoryLedger) Close() error
- func (l *MemoryLedger) Complete(notificationID, channel string, receipt Receipt) error
- func (l *MemoryLedger) DeliverNative(notificationID, group, owner string, now time.Time, lease time.Duration, ...) NativeOperationResult
- func (l *MemoryLedger) List(notificationID string) ([]Entry, error)
- func (l *MemoryLedger) ReleaseExpired(now time.Time) (int, error)
- type Message
- type NativeCancelResult
- type NativeGroupState
- type NativeNotifier
- type NativeOperationResult
- type ProviderReceipt
- type RealClock
- type Receipt
- type Request
- type Result
- type Runner
- type Service
- type ServiceOptions
- type SoundCoordinator
- type SoundPathSource
- type SoundPaths
- type SoundPlayer
- type Status
- type StatusProvider
- type TerminalOptions
- type TestEvent
- type Timer
Constants ¶
const ( ChannelNative = "native" ChannelSound = "sound" DefaultLease = 30 * time.Second // 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" )
const ( ClaimWon = "claimed" ClaimAlreadyClaimed = "already_claimed" ClaimCancelled = "cancelled" ReceiptRetention = 24 * time.Hour )
const LedgerFileName = "notification-delivery.jsonl"
const (
SoundLedgerFileName = "notification-sound-batches.jsonl"
)
Variables ¶
var ( ErrNoClaim = errors.New("notifydelivery: no active claim") ErrClaimOwner = errors.New("notifydelivery: receipt owner does not own claim") ErrInvalidClaim = errors.New("notifydelivery: invalid claim") )
var ErrUnsupported = errors.New("notifydelivery: operation unsupported")
Functions ¶
func GroupFor ¶
func GroupFor(n notify.Notification) string
func HostingTerminalBundle ¶
HostingTerminalBundle recognizes only fixed environment evidence. The fallbacks remain useful when tmux overwrites TERM_PROGRAM with "tmux".
func StderrTerminalWriter ¶
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 AttentionResolver ¶
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 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) 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 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{}
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 (*HostSound) PlayNotification ¶
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) 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) 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) 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) 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 NativeGroupState ¶
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 ¶
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 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 ¶
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 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
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 SoundPathSource ¶
type SoundPathSource func() (SoundPaths, error)
type SoundPaths ¶
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 ¶
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.