terminal

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package terminal provides interfaces for terminal multiplexer integrations.

Index

Constants

View Source
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.

View Source
const SpikeWindow = 1 * time.Second

SpikeWindow is how long we wait to confirm sustained activity.

Variables

This section is empty.

Functions

func DetectTool

func DetectTool(content string) string

DetectTool attempts to identify the AI tool from terminal content.

func HashContent

func HashContent(content string) string

HashContent generates SHA256 hash of content.

func NormalizeContent

func NormalizeContent(content string) string

NormalizeContent prepares content for hashing by removing dynamic elements. This prevents false hash changes from animations and counters.

func StripANSI

func StripANSI(content string) string

StripANSI removes ANSI escape codes from content.

Types

type Detector

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

Detector detects AI tool status from terminal content.

func NewDetector

func NewDetector(tool string) *Detector

NewDetector creates a detector for the specified tool.

func (*Detector) DetectStatus

func (d *Detector) DetectStatus(content string) Status

DetectStatus returns the detected status based on terminal content alone. For more accurate detection with spike filtering, use StateTracker.Update().

func (*Detector) IsBusy

func (d *Detector) IsBusy(content string) bool

IsBusy returns true if the terminal content indicates the agent is actively working.

func (*Detector) IsReady

func (d *Detector) IsReady(content string) bool

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

func (d *Detector) NeedsApproval(content string) bool

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

func NewManager(enabled []string) *Manager

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

func (m *Manager) HasEnabledIntegrations() bool

HasEnabledIntegrations returns true if any integrations are enabled and available.

func (*Manager) IsEnabled

func (m *Manager) IsEnabled(name string) bool

IsEnabled returns true if the named integration is in the enabled list.

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
)

Directories

Path Synopsis
Package tmux implements terminal integration for tmux.
Package tmux implements terminal integration for tmux.

Jump to

Keyboard shortcuts

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