classifier

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToolNamesFromPatterns

func ToolNamesFromPatterns(patterns []string) []string

TitlePatternsFromConfig compiles config regex strings into TitlePatterns. agentNames is the list of known tool names used to infer the tool label from each pattern string (e.g. a pattern containing "claude" maps to tool "claude"). Pass nil to fall back to the generic "agent" label for all patterns. The list should come from config so no source-code change is required when a new tool is added.

ToolNamesFromPatterns extracts clean binary names for process detection from the same pattern list. Use it alongside TitlePatternsFromConfig so that patterns containing regex metacharacters (e.g. "^pi$") map correctly to process names (e.g. "pi").

Types

type Cache

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

Cache stores classification results, invalidated on process fingerprint change.

func NewCache

func NewCache() *Cache

NewCache creates an empty classification cache.

func (*Cache) Get

func (c *Cache) Get(paneID string, currentFingerprint int64) (Result, bool)

Get returns a cached classification if the process fingerprint hasn't changed.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of cached entries.

func (*Cache) Prune

func (c *Cache) Prune(activePaneIDs map[string]bool)

Prune removes entries for pane IDs not in the provided set.

func (*Cache) Set

func (c *Cache) Set(paneID string, fingerprint int64, result Result)

Set stores a classification result for a pane.

type Classifier

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

Classifier classifies tmux panes as agent or non-agent.

func New

func New(titles []TitlePattern, reader process.ProcessReader, capture ContentCapture, scorer ContentScorer) *Classifier

New creates a Classifier with the given dependencies. titlePatterns drives both Tier 1 (pane title) and Tier 2 (process binary name) detection, so no separate tool-name list is required.

func (*Classifier) Classify

func (c *Classifier) Classify(ctx context.Context, input PaneInput) Result

Classify runs the 3-tier cascade on a single pane.

func (*Classifier) ClassifyStable

func (c *Classifier) ClassifyStable(input PaneInput) Result

ClassifyStable runs only Tier 1 (title) and Tier 2 (process) classification. It skips Tier 3 content capture, which spawns external subprocesses. Use this during periodic cache refresh when Tier 3 is gated by a rate limiter.

func (*Classifier) WithReader

func (c *Classifier) WithReader(r process.ProcessReader) *Classifier

WithReader returns a shallow copy of the Classifier that uses r for process identification instead of the original reader. Use this to inject a per-refresh-cycle SnapshotReader without mutating the shared Classifier.

type Confidence

type Confidence string

Confidence represents classification certainty.

const (
	// ConfidenceHigh indicates a strong classification signal.
	ConfidenceHigh Confidence = "high"
	// ConfidenceMedium indicates a moderate classification signal.
	ConfidenceMedium Confidence = "medium"
)

type ContentCapture

type ContentCapture interface {
	CapturePane(ctx context.Context, target string) (string, error)
}

ContentCapture abstracts pane content retrieval for Tier 3.

type ContentScorer

type ContentScorer interface {
	Score(content string) (score int, categories int, tool string)
}

ContentScorer scores terminal content for agent-like signals.

type PaneInput

type PaneInput struct {
	SessionName string
	PaneID      string
	PanePID     int64
	WindowIndex string
	WindowName  string
	PaneTitle   string
	WorkDir     string
	Activity    int64
	HiveSession string
}

PaneInput holds the raw data for one pane from tmux list-panes.

type Result

type Result struct {
	IsAgent      bool
	Tool         string
	Confidence   Confidence
	Tier         int
	ClassifiedAt time.Time
}

Result holds the classification output for a single pane.

func (Result) StableForProcessCache

func (r Result) StableForProcessCache() bool

StableForProcessCache reports whether this positive result can be reused while the pane foreground process fingerprint is unchanged.

type TitlePattern

type TitlePattern struct {
	Pattern *regexp.Regexp
	Tool    string
}

TitlePattern is a compiled regex for Tier 1 title matching.

func TitlePatternsFromConfig

func TitlePatternsFromConfig(patterns []string, agentNames []string) []TitlePattern

Jump to

Keyboard shortcuts

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