notify

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 23 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 notify owns the notification model, its source registry, and the state-free rules every surface applies to a set of notifications.

Nothing in here draws anything or knows about Bubble Tea: the TUI, the CLI, and any future headless caller all read the same model through the same resolution helpers, so "what is unread", "what may toast", and "who may dismiss this" cannot drift between surfaces.

Index

Constants

View Source
const DefaultLaneDebounce = 3 * time.Second

DefaultLaneDebounce is the window a lane must hold before it posts. Long enough to swallow the flicker as an agent's prompt renders, short enough that "your agent is waiting" still arrives while the user is looking.

View Source
const DefaultSlots = 3

DefaultSlots is how many toast blocks may be on screen at once (1b).

View Source
const FileName = "notifications.jsonl"

FileName is the notification log inside the sidecar state dir.

View Source
const LiveEventGrace = 15 * time.Second

LiveEventGrace is the age window in which a notification discovered through a cross-process sweep is still live rather than startup backlog.

View Source
const Retention = 24 * time.Hour

Retention is how long a dismissed notification stays in the store before it is compacted away. The centre's footer note ("Dismissed items clear after 24h") is a description of this constant, not a separate rule.

Variables

View Source
var ErrNotFound = errors.New("notification not found")

ErrNotFound is returned for an id the store has never seen.

Functions

func ApplyConfig

func ApplyConfig(cfg config.NotificationsConfig)

ApplyConfig atomically replaces the complete resolved policy. Normalize, delivery resolution, the TUI, and CLI callers therefore observe one version.

func CTABody

func CTABody(n Notification) string

CTABody is the body text the centre renders and the scan reads, whitespace collapsed exactly as the centre collapses it.

func CTATitle

func CTATitle(n Notification) string

CTATitle is the title text the centre renders and the scan reads — the same string for both, so a span's columns are the columns on screen. Untrusted text is stripped of source OSC sequences here, once, per the safety rule in internal/targetactivation's package doc.

func ChromeColor

func ChromeColor(source SourceID, severity Severity) color.Color

ChromeColor is the colour a notification's chrome takes: its source's hue, overridden by error severity. An error is loud whatever posted it — that override lived in the toast renderer alone, which is how an error could look like an error in one surface and not in another.

func Expired

func Expired(n Notification, now time.Time) bool

Expired reports whether a dismissed notification is past the retention window and may be compacted away. Undismissed notifications never expire out of the store, however old they are.

func ExpiryFor

func ExpiryFor(id SourceID) time.Duration

ExpiryFor retains the established notification completion contract while reading from the same snapshot external delivery uses.

func Glyph

func Glyph(source SourceID) string

Glyph is the bare glyph for a source, with no styling.

func MayDismiss

func MayDismiss(n Notification, caller Origin) bool

MayDismiss reports whether caller is allowed to dismiss n from outside the TUI. Inside the TUI the user dismisses anything; over the CLI a caller may only dismiss what it posted.

func MayToast

func MayToast(n Notification, now time.Time) bool

MayToast reports whether a notification should currently be on screen as a toast: never seen, never dismissed, and not past its expiry. A sticky notification has no expiry and toasts until it is read or dismissed.

func NewID

func NewID() string

NewID generates a sortable unique notification id, in the same shape as a uirequest id so both are recognisable at a glance in the state tree.

func Path

func Path(stateDir string) string

Path returns the notification log path under stateDir.

func RemoteID added in v1.11.0

func RemoteID(hostID, eventKey string) string

RemoteID is the local record ID for one forwarded remote transition.

It is derived rather than generated, and that is the whole of same-machine duplicate prevention for remote work: two Sidecar processes here, each with its own connection to the same host, compute the same ID for one remote event, so the store files one record and the delivery ledger has one thing to claim. Two Sidecars on two different computers derive the same ID too and deliver independently, which is intended — the dedupe boundary is one destination host, because each user needs their own attention.

func RenderGlyph

func RenderGlyph(source SourceID, severity Severity) string

RenderGlyph is the source's glyph in its chrome colour.

func ResolveHue

func ResolveHue(h Hue) color.Color

ResolveHue maps a source's hue name onto the active theme's palette. It is the only place in this package that knows a colour exists: the model, the store, and the resolution rules stay renderable by anything.

The values are the existing theme keys, re-read on every call so a theme switch reaches notifications the same way it reaches every other surface.

func SetSourceExpiries

func SetSourceExpiries(overrides map[SourceID]time.Duration)

SetSourceExpiries is retained for focused tests and older internal callers. It still swaps a whole immutable snapshot rather than separate mutable state.

func SortNewestFirst

func SortNewestFirst(ns []Notification)

SortNewestFirst orders in place by creation time, newest first, with the id as a stable tiebreak so two notifications posted in the same instant do not swap places between frames.

func SourceColor

func SourceColor(id SourceID) color.Color

SourceColor is the colour of a notification's source chrome: its border, its glyph, and its section rule in the centre. It is ChromeColor without a severity — the shorthand for the places that mark a source rather than a particular notification.

func SourceIDs

func SourceIDs() []string

SourceIDs lists the registered ids in registry order, for help text.

func TargetKindNames

func TargetKindNames() []string

TargetKindNames is TargetKinds as strings, for help text and error messages.

func ToastExpired

func ToastExpired(n Notification, now time.Time) bool

ToastExpired reports whether a toast's countdown has run out.

func TransitionOwnedByProject added in v1.11.0

func TransitionOwnedByProject(n Notification, projectRoot string) bool

TransitionOwnedByProject is the deterministic ownership gate for restart seeding and post reconciliation. New structured records compare their producer-captured root directly. Legacy records without that field are accepted only when Origin.WorkDir is lexically inside the current root; basename-only ProjectKey records are ambiguous and remain retained without giving this project authority to dismiss them.

func UnreadCount

func UnreadCount(all []Notification) int

UnreadCount is what the header indicator counts.

func ValidSource

func ValidSource(id SourceID) bool

ValidSource reports whether id names a registered source. The CLI uses it to refuse a typo rather than silently filing under system.

func ValidTargetKind

func ValidTargetKind(kind TargetKind) bool

ValidTargetKind reports whether kind is one a spec may name.

Types

type CTAField

type CTAField string

CTAField names the field a call to action was found in. A stored target that appears nowhere in the text has CTAFieldNone and no columns: it is real, it is numbered, and it simply has nothing to underline.

const (
	CTAFieldNone  CTAField = ""
	CTAFieldTitle CTAField = "title"
	CTAFieldBody  CTAField = "body"
)

type CallToAction

type CallToAction struct {
	// Number is the 1-based digit that jumps to this target.
	Number int
	// Target is the activation vocabulary every surface shares.
	Target uirequest.Target
	// Project qualifies a target in another checkout; empty means "here".
	Project string
	// Label is how the target reads in a list — the text as written when the
	// scan found it, the stored value otherwise.
	Label string
	// Field, StartCol and EndCol locate the target in CTAText's output, in
	// visual columns, EndCol inclusive. StartCol is -1 when Field is
	// CTAFieldNone.
	Field    CTAField
	StartCol int
	EndCol   int
}

CallToAction is one numbered, activatable reference of a notification.

func CallToActionAt

func CallToActionAt(list []CallToAction, number int) (CallToAction, bool)

CallToActionAt returns the call to action a digit key names.

func CallsToAction

func CallsToAction(n Notification, opts terminallink.Options) []CallToAction

CallsToAction reconciles a notification's stored targets with what a scan of its title and body finds, and numbers the result 1..N.

opts is passed straight to terminallink.ScanWith, so the caller decides how much verification it can afford: a nil Resolve leaves bare filenames as ordinary text (the I/O-free choice), and a Resolve that stats against the project root earns those spans an underline.

func (CallToAction) Display

func (c CallToAction) Display() string

Display is how a call to action reads in the numbered list. A target in another project carries that project's name — design 1e's "repo/td-xxxxxx" — so a jump that will change projects says so before it is taken.

type CapabilitySet added in v1.11.0

type CapabilitySet struct {
	Native bool
	Sound  bool
}

type Channel added in v1.11.0

type Channel string
const (
	ChannelNative Channel = "native"
	ChannelSound  Channel = "sound"
)

type ChannelDecision added in v1.11.0

type ChannelDecision struct {
	Deliver bool   `json:"deliver"`
	Reason  Reason `json:"reason,omitempty"`
}

type Cue added in v1.11.0

type Cue string
const (
	CueNone      Cue = "none"
	CueAttention Cue = "attention"
	CueDone      Cue = "done"
	CueFailure   Cue = "failure"
)

type DeliveryDecision added in v1.11.0

type DeliveryDecision struct {
	Native ChannelDecision `json:"native"`
	Sound  ChannelDecision `json:"sound"`
	Cue    Cue             `json:"cue"`
}

func ResolveDelivery added in v1.11.0

func ResolveDelivery(n Notification, cfg ResolvedConfig, runtime RuntimeContext) DeliveryDecision

ResolveDelivery applies the complete state-free delivery policy.

type DismissMsg

type DismissMsg struct {
	ID string
}

DismissMsg dismisses one notification.

type DismissTransitionMsg added in v1.11.0

type DismissTransitionMsg struct {
	DedupeKey string
}

DismissTransitionMsg dismisses whatever record currently represents one logical transition, named by its dedupe key rather than by record ID.

A forwarded remote wait can outlive the process that announced it: the serve process that reconnects or restarts never saw the original event and cannot name its ID, but both sides can always derive the dedupe key from the origin and the class. Dismissing by identity rather than by ID is what lets the answer reach the record anyway.

type Group

type Group struct {
	Source Source
	Items  []Notification
}

Group is one section of the notification centre.

func GroupBySource

func GroupBySource(all []Notification) []Group

GroupBySource splits a set into per-source groups in registry order, for the centre's section grammar. Groups with nothing in them are omitted.

func (Group) Unread

func (g Group) Unread() int

Unread counts the unread items in the group.

type Hue

type Hue string

Hue is the name of a palette entry, not a colour. The model stays free of lipgloss so a headless caller can read it; ResolveHue in hue.go is the one place that turns a hue into the theme's actual colour.

const (
	HuePrimary   Hue = "primary"
	HueSecondary Hue = "secondary"
	HueAccent    Hue = "accent"
	HueSuccess   Hue = "success"
	HueWarning   Hue = "warning"
	HueError     Hue = "error"
	HueInfo      Hue = "info"
	HueMuted     Hue = "muted"
)

func LoudestHue

func LoudestHue(all []Notification) (Hue, bool)

LoudestHue is the colour the header indicator takes. It returns HueMuted and false when nothing is unread, which is the `·` empty state.

type JSONLStore

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

JSONLStore is the default store: one append-only JSONL file under the state dir, folded and compacted on open.

func Open

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

Open loads (and compacts) the notification log under stateDir. A missing file is an empty store, not an error.

func OpenPath

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

OpenPath is Open against an explicit file path. Tests and any future caller that owns its own directory use it; ordinary code uses Open.

func (*JSONLStore) Close

func (s *JSONLStore) Close() error

Close implements Store. The log is written through on every call, so there is nothing buffered to flush; Close exists so the interface can front a store that does hold a handle.

func (*JSONLStore) Dismiss

func (s *JSONLStore) Dismiss(id string) error

Dismiss implements Store.

func (*JSONLStore) Get

func (s *JSONLStore) Get(id string) (Notification, bool)

Get returns one record.

func (*JSONLStore) List

func (s *JSONLStore) List() ([]Notification, error)

List implements Store.

func (*JSONLStore) MarkRead

func (s *JSONLStore) MarkRead(id string) error

MarkRead implements Store.

func (*JSONLStore) Path

func (s *JSONLStore) Path() string

Path returns the file this store writes.

func (*JSONLStore) Post

func (s *JSONLStore) Post(n Notification) (PostResult, error)

Post implements Store.

func (*JSONLStore) Sweep

func (s *JSONLStore) Sweep(now time.Time) (int, error)

Sweep implements Store. It is also this store's cross-process read point: it re-folds the file first, so records another process appended since the last sweep become visible here instead of being overwritten by the rewrite.

type LaneEvents

type LaneEvents struct {
	// Post are complete notifications, ids already assigned. The ids are
	// assigned here rather than by the store because the tracker has to be able
	// to name a waiting notification later in order to withdraw it.
	Post []Notification
	// Dismiss are ids of previously posted waiting notifications whose agent has
	// stopped waiting. A "needs input" toast that outlives the wait is worse
	// than no toast at all, so the tracker withdraws its own.
	Dismiss []string
}

LaneEvents is what one Observe call produced: notifications to post, and the ids of notifications the tracker itself posted earlier and now considers answered.

func (LaneEvents) Empty

func (e LaneEvents) Empty() bool

Empty reports whether nothing happened.

type LaneObservation

type LaneObservation struct {
	// Key is the stable identity of the workspace — a tmux session name or a
	// worktree identity key. It is what the tracker remembers state under, so
	// it must not change while the workspace lives.
	Key string
	// Label names the shell or worktree for a human ("Shell 2", "auth-flow").
	Label string
	// Context is the surrounding place: the project, the branch, the repo. It
	// becomes the notification body so a toast identifies which of five agents
	// is talking.
	Context string
	// Provider is the agent kind ("claude", "codex"), if known.
	Provider string
	// Presentation is the already-resolved agent status for this workspace.
	Presentation agentstatus.Presentation
	// Origin records who this notification belongs to, so an agent that posted
	// through the CLI and a lane trigger about the same shell agree on identity
	// and the origin-checked dismiss path keeps working.
	Origin Origin
	// ProjectRoot is the stable owning project identity already resolved by the
	// producer. It may differ from Origin.WorkDir for an external worktree.
	ProjectRoot string
}

LaneObservation is one workspace's resolved agent state at a moment in time. The caller supplies the identity and the presentation; the tracker never re-resolves anything.

type LaneTracker

type LaneTracker struct {
	// Debounce is how long a new lane must hold before it counts as a real
	// transition. Zero uses DefaultLaneDebounce.
	Debounce time.Duration
	// contains filtered or unexported fields
}

LaneTracker turns a stream of per-workspace agent states into notifications about the *transitions* between them.

It is deliberately state-free with respect to the rest of sidecar: it knows nothing about tmux, plugins, or Bubble Tea. A caller — the workspace plugin today, a headless watcher tomorrow — resolves whatever it already has into []LaneObservation and hands the whole set to Observe on whatever cadence it polls at. Everything else (which lanes are worth a notification, how long a state must hold before it counts, what self-dismisses) lives here so both callers cannot drift.

Two rules do all the work:

  • Only a *settled* lane change posts. A lane must hold for Debounce before it is committed, so an agent flickering working→blocked→working while a prompt renders produces nothing at all.
  • A committed lane is the tracker's new truth, so the same logical event can never post twice: the next post needs a different settled lane first.

func (*LaneTracker) Knows added in v1.11.0

func (t *LaneTracker) Knows(key string) bool

Knows reports whether the tracker already holds state for a workspace.

It exists for a caller that has to tell a first sighting from a subsequent one, because the two mean different things: the first is a baseline the tracker will never announce, so anything already in progress at that moment belongs to whoever was watching before.

func (*LaneTracker) Observe

func (t *LaneTracker) Observe(obs []LaneObservation, now time.Time) LaneEvents

Observe folds one complete round of observations into the tracker and returns whatever transitions settled. Passing the *whole* set matters: a workspace missing from obs is treated as gone, which is how a closed shell withdraws its waiting notification.

func (*LaneTracker) ReconcilePosted added in v1.11.0

func (t *LaneTracker) ReconcilePosted(n Notification)

ReconcilePosted adopts the store's authoritative id after Post. This matters when another process won logical-event dedupe: the local tracker generated a different id and must dismiss the retained winner when the lane leaves.

func (*LaneTracker) Seed added in v1.11.0

func (t *LaneTracker) Seed(all []Notification)

Seed restores the latest retained transition for each lane. A retained waiting record makes the blocked episode resumable across restart. A user-dismissed wait seeds the lane without restoring waitingID, so it stays dismissed until the lane leaves and later blocks again.

type Layout

type Layout struct {
	// Stacks are the blocks on screen, newest lead first — the top of the
	// column is the thing that just happened (1b).
	Stacks []Stack
	// Queued are the stacks waiting for a slot, oldest first: the next one to
	// surface is Queued[0]. They are not painted, and a host must not mark
	// their notifications seen.
	Queued []Stack
}

Layout is what a toast host draws this frame.

func StackToasts

func StackToasts(all []Notification, now time.Time, slots int) Layout

StackToasts resolves the whole toast column. slots <= 0 means DefaultSlots.

type MemStore

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

MemStore is a Store that keeps nothing. It is what the app falls back to when the state dir cannot be opened, so a read-only or misconfigured state tree costs the user persistence, not notifications.

func NewMemStore

func NewMemStore() *MemStore

NewMemStore returns an empty in-memory store.

func (*MemStore) Close

func (s *MemStore) Close() error

Close implements Store.

func (*MemStore) Dismiss

func (s *MemStore) Dismiss(id string) error

Dismiss implements Store.

func (*MemStore) List

func (s *MemStore) List() ([]Notification, error)

List implements Store.

func (*MemStore) MarkRead

func (s *MemStore) MarkRead(id string) error

MarkRead implements Store.

func (*MemStore) Post

func (s *MemStore) Post(n Notification) (PostResult, error)

Post implements Store.

func (*MemStore) Sweep

func (s *MemStore) Sweep(now time.Time) (int, error)

Sweep implements Store.

type Notification

type Notification struct {
	ID          string     `json:"id"`
	Source      SourceID   `json:"source"`
	Severity    Severity   `json:"severity,omitempty"`
	Title       string     `json:"title"`
	Body        string     `json:"body,omitempty"`
	Targets     []Target   `json:"targets,omitempty"`
	CreatedAt   time.Time  `json:"createdAt"`
	ReadAt      *time.Time `json:"readAt,omitempty"`
	DismissedAt *time.Time `json:"dismissedAt,omitempty"`
	// ExpiresAt is when the *toast* stops showing. It never removes the
	// notification from the centre — suppressed is not dropped.
	ExpiresAt *time.Time `json:"expiresAt,omitempty"`
	Origin    Origin     `json:"origin,omitempty"`
	// Sticky means the toast has no countdown and waits for the user.
	Sticky bool `json:"sticky,omitempty"`
	// Transition is present only for structured agent-lane events. Titles and
	// bodies remain presentation; policy and reconciliation never parse them.
	Transition *TransitionMetadata `json:"transition,omitempty"`
}

Notification is one alert. Times are UTC; a zero time means "not yet".

func Active

func Active(all []Notification) []Notification

Active returns the notifications that still belong in the centre: everything not dismissed, newest first.

func Loudest

func Loudest(all []Notification) (Notification, bool)

Loudest returns the unread notification that decides the indicator's colour: highest severity first, then the source's registry priority, then the newest. It reports false when there is nothing unread.

func Normalize

func Normalize(n Notification, now time.Time) Notification

Normalize fills in the defaults a poster may leave out: id, creation time, severity, and the source's default expiry. It is called by the store, so every surface gets the same completion whatever path posted the record.

func ReadAll

func ReadAll(path string) ([]Notification, error)

ReadAll folds the log at path without opening a store: no compaction, no writes, no locks. `sidecar notify list` uses it so listing works with no TUI running and never rewrites a file another process is appending to.

func Toastable

func Toastable(all []Notification, now time.Time) []Notification

Toastable filters a set to what may be on screen right now, newest first.

func Unread

func Unread(all []Notification) []Notification

Unread returns the undismissed, unread notifications, newest first.

func (Notification) Dismissed

func (n Notification) Dismissed() bool

Dismissed reports whether the notification has been dismissed.

func (Notification) Read

func (n Notification) Read() bool

Read reports whether the notification has been seen.

func (Notification) SourceInfo

func (n Notification) SourceInfo() Source

SourceInfo returns the registered source backing this notification.

type Origin

type Origin struct {
	TmuxSession string `json:"tmuxSession,omitempty"`
	ProjectKey  string `json:"projectKey,omitempty"`
	WorkDir     string `json:"workDir,omitempty"`
	PID         int    `json:"pid,omitempty"`
	// HostID names the registered remote host this work runs on. Empty means
	// this machine, which is every locally produced notification.
	//
	// It is part of identity rather than presentation because two machines
	// legitimately have a tmux session called `sidecar-agent-1` and a checkout
	// at the same path. Without it, a viewer showing a local workspace would
	// count as visibly showing the remote one, and the remote agent's alert
	// would be suppressed as foreground while nobody was looking at it.
	HostID string `json:"hostId,omitempty"`
}

Origin identifies who posted a notification, so a CLI caller can dismiss its own and nothing else. A notification posted inside the TUI has a zero Origin and is therefore not dismissible from outside.

func (Origin) Matches

func (o Origin) Matches(caller Origin) bool

Matches reports whether caller is the same poster as o. PID is deliberately not part of the test: an agent posts from one short-lived CLI process and dismisses from another, so identity is the shell it lives in — its tmux session, or failing that its working directory.

func (Origin) StableKey added in v1.11.0

func (o Origin) StableKey() string

StableKey is the identity used for logical transition dedupe and native replacement grouping. It hashes paths rather than repeating them in coordination records.

A remote origin's host ID joins the hash only when there is one, so local keys are byte-identical to what earlier builds produced and an upgrade does not reshuffle every retained replacement group.

func (Origin) Zero

func (o Origin) Zero() bool

Zero reports whether the origin identifies nobody.

type PostMsg

type PostMsg struct {
	Notification Notification
}

PostMsg asks the app to file a notification. It is the in-process posting API — the same road the CLI's request takes once it reaches the TUI.

func Alert

func Alert(source SourceID, severity Severity, title string) PostMsg

Alert builds a PostMsg for a source-specific notification. It exists so a producer that needs more than the generic `system` toast — a blocked action, a merge that unwound itself, an agent that fell back — can say which source it is speaking as without assembling a Notification by hand. Expiry is left to the store, which asks ExpiryFor for the source's configured lease.

type PostReason added in v1.11.0

type PostReason string
const (
	PostCreated         PostReason = "created"
	PostExistingID      PostReason = "existing_id"
	PostExistingLogical PostReason = "existing_logical_event"
	LogicalDedupeWindow            = 15 * time.Second
)

type PostResult added in v1.11.0

type PostResult struct {
	Notification `json:"notification"`
	Created      bool       `json:"created"`
	Reason       PostReason `json:"reason"`
}

type PostedMsg

type PostedMsg struct {
	Notification Notification
	Created      bool
	Reason       PostReason
}

PostedMsg is broadcast after a notification has been stored, carrying the completed record so a toast host can start its countdown from the same timestamps the store holds.

type ReadMsg

type ReadMsg struct {
	ID string
}

ReadMsg marks one notification read.

type Reason added in v1.11.0

type Reason string

Reason is a stable machine-readable delivery outcome.

const (
	ReasonChannelOff     Reason = "channel_off"
	ReasonSourceOff      Reason = "source_off"
	ReasonForeground     Reason = "foreground"
	ReasonQuietHours     Reason = "quiet_hours"
	ReasonStale          Reason = "stale"
	ReasonUnavailable    Reason = "unavailable"
	ReasonAlreadyClaimed Reason = "already_claimed"
	ReasonCancelled      Reason = "cancelled"
	ReasonRateLimited    Reason = "rate_limited"
	ReasonNotRequested   Reason = "not_requested"
	ReasonCoordination   Reason = "coordination_failed"
)

type ResolvedConfig added in v1.11.0

type ResolvedConfig struct {
	NativeMode config.DeliveryMode
	SoundMode  config.DeliveryMode
	QuietHours ResolvedQuietHours
	// contains filtered or unexported fields
}

ResolvedConfig is an immutable notification-policy snapshot. Its source map is private; callers can inspect copies but cannot mutate the live policy.

func CurrentConfig added in v1.11.0

func CurrentConfig() ResolvedConfig

CurrentConfig returns the current immutable snapshot by value.

func ResolveConfig added in v1.11.0

func ResolveConfig(cfg config.NotificationsConfig) ResolvedConfig

ResolveConfig returns the immutable policy a configuration means without changing the process-wide snapshot. Read-only surfaces use it to report defaults and resolved source rules deterministically.

func (ResolvedConfig) SourceRule added in v1.11.0

func (c ResolvedConfig) SourceRule(id SourceID) ResolvedSourceRule

SourceRule returns the resolved rule for a registered source. Unknown future sources remain centre-only until this build knows their semantics.

func (ResolvedConfig) SourceRules added in v1.11.0

func (c ResolvedConfig) SourceRules() map[SourceID]ResolvedSourceRule

SourceRules returns a defensive copy for configuration summaries and future structured CLI output.

type ResolvedQuietHours added in v1.11.0

type ResolvedQuietHours struct {
	Enabled     bool
	StartMinute int
	EndMinute   int
}

type ResolvedSourceRule added in v1.11.0

type ResolvedSourceRule struct {
	Toast  bool
	Native bool
	Sound  config.SoundCue
	Expiry time.Duration
}

type RuntimeContext added in v1.11.0

type RuntimeContext struct {
	Now          time.Time
	Foreground   bool
	Discovered   bool
	ExplicitTest bool
	Capabilities CapabilitySet
}

RuntimeContext contains only already-resolved facts. ResolveDelivery does no I/O and is shared unchanged by TUI, CLI, tests, and future headless callers.

type SeedLaneTrackersMsg added in v1.11.0

type SeedLaneTrackersMsg struct {
	Notifications []Notification
}

SeedLaneTrackersMsg restores structured transition state after the store has loaded. It carries in-memory records only; plugins perform no startup I/O.

type Severity

type Severity string

Severity ranks a notification within its source.

const (
	SeverityInfo    Severity = "info"
	SeverityWarning Severity = "warning"
	SeverityError   Severity = "error"
)

func (Severity) Rank

func (s Severity) Rank() int

Rank orders severities for the loudest-first rules. Unknown values rank lowest so a record written by a newer build can never outrank a real error.

type Source

type Source struct {
	ID    SourceID
	Label string
	Glyph string
	Hue   Hue
	// Priority breaks ties between equally severe notifications. Higher is
	// louder: a waiting agent outranks a finished session outranks a task.
	Priority int
	// DefaultExpiry is how long a toast from this source stays on screen when
	// the poster names no expiry. Zero means the source is sticky by default.
	// It is the built-in value: ExpiryFor applies the user's configuration on
	// top of it, and everything that completes a notification asks ExpiryFor.
	DefaultExpiry time.Duration
}

Source is a registered origin of notifications: its label and glyph in the centre's section rules (design frame 1c) and the hue its toast border and the header indicator take when it is the loudest unread source.

func Lookup

func Lookup(id SourceID) (Source, bool)

Lookup returns the registered source for id.

func SourceOf

func SourceOf(id SourceID) Source

SourceOf returns the source for id, falling back to system for an id no build knows about. A notification is never dropped for naming a source that has since been removed.

func Sources

func Sources() []Source

Sources returns the registered sources, loudest first.

type SourceID

type SourceID string

SourceID names a registered notification source.

const (
	SourceAgent   SourceID = "agent"
	SourceWaiting SourceID = "waiting"
	SourceSession SourceID = "session"
	SourceTasks   SourceID = "tasks"
	SourceTD      SourceID = "td"
	SourceSystem  SourceID = "system"
)

The hardcoded source set. External registration is a later phase; the ids are stable because they are written into the JSONL store.

type Stack

type Stack struct {
	// Key is the stack's identity: the collapse key, the reveal key and the
	// pointer target. A block does not restart its animation because another
	// copy of the same message joined it.
	Key StackKey
	// Source is what the block looks like — hue, glyph, section — not what it
	// is. Two blocks can share a source.
	Source SourceID
	// Members are the stack's notifications, newest first. Never empty.
	Members []Notification
	// First is the arrival time of the oldest member: the stack's place in the
	// queue. A source already on screen keeps its slot when it gains a member.
	First time.Time
}

Stack is one toast block: the notification actually drawn, plus every other undismissed toastable notification from the same source hiding behind it.

func (Stack) Count

func (s Stack) Count() int

Count is the ×N on the block.

func (Stack) Hidden

func (s Stack) Hidden() int

Hidden is how many members the peek line offers to expand.

func (Stack) Lead

func (s Stack) Lead() Notification

Lead is the notification the block is drawn for: the newest in the stack.

type StackKey

type StackKey string

StackKey is a block's identity: the collapse key, the reveal key, and the pointer target, one string.

It was the source id through Phase 3, which read correctly against the six registered sources but wrongly against real use: nearly everything an agent or the CLI posts is `agent`, so three unrelated notifications a second apart collapsed into one block and each new title *replaced* the last. Design 1b's collapse exists to stop a source repeating *itself* — "a refusal the user is leaning on a key for" — which is a repeat of the same message, not any two messages that share a source. So identity is source **and** title: repeats still dedupe to `×N`, and distinct notifications stack, queue and retract as separate blocks the way the spec describes.

func StackKeyFor

func StackKeyFor(n Notification) StackKey

StackKeyFor is the block identity a notification belongs to.

type Store

type Store interface {
	// Post records a notification, filling in its defaults, and returns the
	// result. Posting an id or short-lived logical event that already exists is
	// an explicit no-op, so delivery callers cannot mistake it for new work.
	Post(n Notification) (PostResult, error)
	MarkRead(id string) error
	Dismiss(id string) error
	// List returns every retained notification, newest first.
	List() ([]Notification, error)
	// Sweep drops dismissed notifications past the retention window and
	// returns how many it removed.
	Sweep(now time.Time) (int, error)
	Close() error
}

Store is the narrow persistence interface every surface talks to. It is deliberately small enough to reimplement over SQLite — or over nothing at all, as MemStore does in tests — without any caller changing.

type Target

type Target struct {
	Kind    TargetKind `json:"kind"`
	Value   string     `json:"value"`
	Line    int        `json:"line,omitempty"`
	Project string     `json:"project,omitempty"`
}

Target is one actionable reference carried by a notification.

func ParseTargetSpec

func ParseTargetSpec(spec string) (Target, error)

ParseTargetSpec parses one `kind:value[:line][@project]` spec.

The two ambiguities in that grammar are resolved by kind:

  • `:line` is read only for file targets. A commit sha, a session name and a URL can all end in digits, and none of them has a line.
  • `@project` is never read for a URL (a URL is not project-scoped, and `@` is legal throughout one), and elsewhere only when the text after the last `@` looks like a qualifier: an absolute path, or a name with no `/` and no `:`. (Project qualifiers are resolved by the running instance — a configured project name or a checkout path.)

func ParseTargetSpecs

func ParseTargetSpecs(specs []string) ([]Target, error)

ParseTargetSpecs parses a repeatable --target list, keeping poster order and dropping exact duplicates (the same kind, value, line and project twice is a typo, not two calls to action).

type TargetKind

type TargetKind string

TargetKind classifies a call to action inside a notification. Phase 1 stores targets but activates none of them; Phase 5 turns them into jumps.

const (
	TargetIssue   TargetKind = "issue"
	TargetTask    TargetKind = "task"
	TargetCommit  TargetKind = "commit"
	TargetFile    TargetKind = "file"
	TargetSession TargetKind = "session"
	TargetURL     TargetKind = "url"
)

func TargetKinds

func TargetKinds() []TargetKind

TargetKinds lists the kinds a spec may name, in the order they are documented.

type TransitionClass added in v1.11.0

type TransitionClass string
const (
	TransitionWaiting TransitionClass = "waiting"
	TransitionDone    TransitionClass = "done"
	TransitionFailure TransitionClass = "failure"
)

type TransitionMetadata added in v1.11.0

type TransitionMetadata struct {
	Class          TransitionClass `json:"class"`
	LaneKey        string          `json:"laneKey"`
	DedupeKey      string          `json:"dedupeKey"`
	ReplacementKey string          `json:"replacementKey,omitempty"`
	// ProjectRoot is the durable lexical identity of the project that produced
	// this transition. It lets restart reconciliation distinguish same-named
	// checkouts without consulting the filesystem or current inventory.
	ProjectRoot string `json:"projectRoot,omitempty"`
}

TransitionMetadata carries the stable machine meaning of one agent event.

Jump to

Keyboard shortcuts

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