attention

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package attention implements the v0.1 attention engine: the seven locked triggers (A–G) from docs/superpowers/specs/2026-04-20-ctm-serve- ui-v0.1-design.md §4 "Attention engine". The engine subscribes to the hub's global stream, maintains per-session state, and publishes `attention_raised` / `attention_cleared` events on state transitions.

Index

Constants

View Source
const (
	StateClear           = ""
	StateLastErrorCall   = "last_error_call"
	StateErrorBurst      = "error_burst"
	StateStuck           = "stuck"
	StateTmuxDead        = "tmux_dead"
	StateQuotaHigh       = "quota_high"
	StateContextImminent = "context_imminent"
	StateYoloUnchecked   = "yolo_unchecked"
)

State values are the canonical alert identifiers consumed by the UI (see spec §6 Session.attention.state). Empty string means "clear".

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine is the attention evaluator. A single instance runs per serve process, subscribed to the hub's global stream.

func NewEngine

func NewEngine(hub *events.Hub, quota QuotaSource, sessions SessionSource, thr Thresholds, clock func() time.Time) *Engine

NewEngine constructs an Engine. clock == nil uses time.Now.

func (*Engine) LastToolCallAt

func (e *Engine) LastToolCallAt(name string) (time.Time, bool)

LastToolCallAt returns the timestamp of the most recent tool_call event observed for this session (from live stream or hub replay). Exposed so the sessions API can surface real activity instead of just last_attached_at — used as the primary list sort key.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) error

Run blocks until ctx is cancelled. It drives the engine from two sources: hub events (reactive) and a 30-second tick (idle/yolo).

func (*Engine) Snapshot

func (e *Engine) Snapshot(name string) (Snapshot, bool)

Snapshot returns the current per-session snapshot. Returns ok=false when no alert is active (StateClear).

type QuotaSource

type QuotaSource interface {
	WeeklyPct() (float64, bool)
	FiveHourPct() (float64, bool)
	ContextPct(session string) (int, bool)
}

QuotaSource is the read side of ingest.QuotaIngester the engine needs. Percentages are float64 to match the underlying accessor; the engine compares against the configured int threshold after a plain cast.

type SessionSource

type SessionSource interface {
	Names() []string
	Mode(name string) string
	TmuxAlive(name string) bool
	LastCheckpointAt(name string) (time.Time, bool)
}

SessionSource supplies per-session metadata for triggers C/D/G.

type Snapshot

type Snapshot struct {
	State   string
	Since   time.Time
	Details string
}

Snapshot is the point-in-time per-session view surfaced via the SessionEnricher into /api/sessions. An empty State means "no alert".

type Thresholds

type Thresholds struct {
	ErrorRatePct         int
	ErrorRateWindow      int
	IdleMinutes          int
	QuotaPct             int
	ContextPct           int
	YoloUncheckedMinutes int
}

Thresholds wires the seven spec-mandated defaults through to the engine. Server-side config maps onto these fields.

func Defaults

func Defaults() Thresholds

Defaults returns the thresholds documented in spec §1 "Attention triggers". Any field left zero by a caller is NOT backfilled here — callers pass `Defaults()` and then override as needed.

Jump to

Keyboard shortcuts

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