Documentation
¶
Overview ¶
Package terminal provides interfaces for terminal multiplexer integrations.
Index ¶
- Constants
- func DetectTool(content string) string
- func HashContent(content string) string
- func NormalizeContent(content string) string
- func StripANSI(content string) string
- type Detector
- type Integration
- type Manager
- func (m *Manager) DiscoverSession(ctx context.Context, slug string, metadata map[string]string) (*SessionInfo, Integration, error)
- func (m *Manager) EnabledIntegrations() []Integration
- func (m *Manager) Get(name string) Integration
- func (m *Manager) HasEnabledIntegrations() bool
- func (m *Manager) IsEnabled(name string) bool
- func (m *Manager) RefreshAll()
- func (m *Manager) Register(i Integration)
- type RateLimiter
- type SessionInfo
- type StateTracker
- type Status
Constants ¶
const HysteresisWindow = 500 * time.Millisecond
HysteresisWindow is the minimum time to hold a status before changing. This prevents rapid flickering between states from status bar updates.
const SpikeWindow = 1 * time.Second
SpikeWindow is how long we wait to confirm sustained activity.
Variables ¶
This section is empty.
Functions ¶
func DetectTool ¶
DetectTool attempts to identify the AI tool from terminal content.
func HashContent ¶
HashContent generates SHA256 hash of content.
func NormalizeContent ¶
NormalizeContent prepares content for hashing by removing dynamic elements. This prevents false hash changes from animations and counters.
Types ¶
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector detects AI tool status from terminal content.
func NewDetector ¶
NewDetector creates a detector for the specified tool.
func (*Detector) DetectStatus ¶
DetectStatus returns the detected status based on terminal content alone. For more accurate detection with spike filtering, use StateTracker.Update().
func (*Detector) IsBusy ¶
IsBusy returns true if the terminal content indicates the agent is actively working.
func (*Detector) IsReady ¶
IsReady returns true if the terminal shows an input prompt (Claude finished, waiting for next task). This is LOW URGENCY - just ready for more work.
func (*Detector) NeedsApproval ¶
NeedsApproval returns true if the terminal shows a permission/approval dialog. This is HIGH URGENCY - Claude is blocked waiting for user decision.
type Integration ¶
type Integration interface {
// Name returns the integration name (e.g., "tmux").
Name() string
// Available returns true if this integration is usable (e.g., tmux is installed).
Available() bool
// RefreshCache updates cached session data. Call once per poll cycle
// to batch tmux queries efficiently.
RefreshCache()
// DiscoverSession finds a terminal session for the given slug and metadata.
// Returns nil if no matching session is found.
DiscoverSession(ctx context.Context, slug string, metadata map[string]string) (*SessionInfo, error)
// GetStatus returns the current status of a previously discovered session.
GetStatus(ctx context.Context, info *SessionInfo) (Status, error)
}
Integration defines the interface for terminal multiplexer integrations.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages terminal integrations.
func NewManager ¶
NewManager creates a new integration manager with the given enabled integrations.
func (*Manager) DiscoverSession ¶
func (m *Manager) DiscoverSession(ctx context.Context, slug string, metadata map[string]string) (*SessionInfo, Integration, error)
DiscoverSession tries all enabled integrations to find a session.
func (*Manager) EnabledIntegrations ¶
func (m *Manager) EnabledIntegrations() []Integration
EnabledIntegrations returns all enabled and available integrations.
func (*Manager) Get ¶
func (m *Manager) Get(name string) Integration
Get returns an integration by name, or nil if not found.
func (*Manager) HasEnabledIntegrations ¶
HasEnabledIntegrations returns true if any integrations are enabled and available.
func (*Manager) RefreshAll ¶
func (m *Manager) RefreshAll()
RefreshAll calls RefreshCache on all enabled integrations.
func (*Manager) Register ¶
func (m *Manager) Register(i Integration)
Register adds an integration to the manager.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides simple thread-safe rate limiting for events. It ensures that events are processed at most once per minimum interval.
func NewRateLimiter ¶
func NewRateLimiter(eventsPerSecond int) *RateLimiter
NewRateLimiter creates a new rate limiter with the specified events per second.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow() bool
Allow returns true if the event should be allowed based on the rate limit.
func (*RateLimiter) Coalesce ¶
func (rl *RateLimiter) Coalesce(callback func())
Coalesce executes the provided callback only if the rate limit allows.
type SessionInfo ¶
type SessionInfo struct {
Name string // terminal session name (e.g., tmux session name)
Pane string // pane identifier if applicable (window index for tmux)
WindowName string // window name (for display and template data)
Status Status // current detected status
DetectedTool string // detected AI tool (claude, gemini, etc.)
PaneContent string // captured pane content for preview
}
SessionInfo holds information about a discovered terminal session.
type StateTracker ¶
type StateTracker struct {
// contains filtered or unexported fields
}
StateTracker tracks terminal activity state across poll cycles. Implements spike detection to filter cursor blinks and terminal redraws.
Three-state model:
- GREEN (active) = Explicit busy indicator found (spinner, "ctrl+c to interrupt")
- YELLOW (approval) = Permission dialog detected, needs user decision
- CYAN (ready) = Input prompt detected, ready for next task
func NewStateTracker ¶
func NewStateTracker() *StateTracker
NewStateTracker creates a new state tracker.
func (*StateTracker) Update ¶
func (st *StateTracker) Update(content string, activityTS int64, detector *Detector) Status
Update processes new activity data and returns the detected status. content is the terminal content (for busy/prompt detection). activityTS is the tmux window_activity timestamp. detector is used to check busy/approval/ready patterns.
func (*StateTracker) UpdateHash ¶
func (st *StateTracker) UpdateHash(content string) bool
UpdateHash updates the content hash and returns true if content changed.
type Status ¶
type Status string
Status represents the detected state of a terminal session.
const ( StatusActive Status = "active" // agent is actively working (spinner/busy indicator) StatusApproval Status = "approval" // agent needs permission (Yes/No dialog) StatusReady Status = "ready" // agent finished, waiting for next input (❯ prompt) StatusMissing Status = "missing" // terminal session not found )