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
- Variables
- func ApplyConfig(cfg config.NotificationsConfig)
- func CTABody(n Notification) string
- func CTATitle(n Notification) string
- func ChromeColor(source SourceID, severity Severity) color.Color
- func Expired(n Notification, now time.Time) bool
- func ExpiryFor(id SourceID) time.Duration
- func Glyph(source SourceID) string
- func MayDismiss(n Notification, caller Origin) bool
- func MayToast(n Notification, now time.Time) bool
- func NewID() string
- func Path(stateDir string) string
- func RenderGlyph(source SourceID, severity Severity) string
- func ResolveHue(h Hue) color.Color
- func SetSourceExpiries(overrides map[SourceID]time.Duration)
- func SortNewestFirst(ns []Notification)
- func SourceColor(id SourceID) color.Color
- func SourceIDs() []string
- func TargetKindNames() []string
- func ToastExpired(n Notification, now time.Time) bool
- func UnreadCount(all []Notification) int
- func ValidSource(id SourceID) bool
- func ValidTargetKind(kind TargetKind) bool
- type CTAField
- type CallToAction
- type DismissMsg
- type Group
- type Hue
- type JSONLStore
- func (s *JSONLStore) Close() error
- func (s *JSONLStore) Dismiss(id string) error
- func (s *JSONLStore) Get(id string) (Notification, bool)
- func (s *JSONLStore) List() ([]Notification, error)
- func (s *JSONLStore) MarkRead(id string) error
- func (s *JSONLStore) Path() string
- func (s *JSONLStore) Post(n Notification) (Notification, error)
- func (s *JSONLStore) Sweep(now time.Time) (int, error)
- type LaneEvents
- type LaneObservation
- type LaneTracker
- type Layout
- type MemStore
- type Notification
- func Active(all []Notification) []Notification
- func Loudest(all []Notification) (Notification, bool)
- func Normalize(n Notification, now time.Time) Notification
- func ReadAll(path string) ([]Notification, error)
- func Toastable(all []Notification, now time.Time) []Notification
- func Unread(all []Notification) []Notification
- type Origin
- type PostMsg
- type PostedMsg
- type ReadMsg
- type Severity
- type Source
- type SourceID
- type Stack
- type StackKey
- type Store
- type Target
- type TargetKind
Constants ¶
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.
const DefaultSlots = 3
DefaultSlots is how many toast blocks may be on screen at once (1b).
const FileName = "notifications.jsonl"
FileName is the notification log inside the sidecar state dir.
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 ¶
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 binds the `notifications` config section to this package. It is the seam between configuration and the model: nothing else in internal/notify reads config, and nothing outside it has to know how an expiry is stored.
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 ¶
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 ¶
ExpiryFor is how long a toast from this source stays on screen: the configured override if there is one, otherwise the registry default. Zero means the source is sticky.
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 RenderGlyph ¶
RenderGlyph is the source's glyph in its chrome colour.
func ResolveHue ¶
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 ¶
SetSourceExpiries replaces the per-source expiry overrides. A source absent from the map keeps its registry default; a zero duration means sticky.
It is package state deliberately: Normalize is called from the store, from the CLI, and from the app, and threading a config through all three to answer one duration would put configuration in the model. Callers set it once after loading config (see ApplyConfig).
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 ¶
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 UnreadCount ¶
func UnreadCount(all []Notification) int
UnreadCount is what the header indicator counts.
func ValidSource ¶
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.
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 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.
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.
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) (Notification, 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.
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
}
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) 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.
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 (*MemStore) Post ¶
func (s *MemStore) Post(n Notification) (Notification, error)
Post 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"`
}
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"`
}
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.
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 ¶
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 PostedMsg ¶
type PostedMsg struct {
Notification Notification
}
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 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.
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) 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
// stored record. Posting an id that already exists is a no-op that returns
// the existing record, so a CLI fallback path can never double-file.
Post(n Notification) (Notification, 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 ¶
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 ¶
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.