tmux

package
v0.3.4 Latest Latest
Warning

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

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

Documentation

Overview

Package tmux scrapes tmux sessions to detect running AI agent processes and their usage.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTmuxNotFound indicates tmux is not installed.
	ErrTmuxNotFound = errors.New("tmux not found")
)

Functions

func StripANSI

func StripANSI(input string) string

StripANSI removes ANSI escape codes from text.

Types

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, name string, args ...string) ([]byte, error)
}

CommandRunner executes commands for tmux interactions.

type ExecRunner

type ExecRunner struct{}

ExecRunner executes commands using os/exec.

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, name string, args ...string) ([]byte, error)

Run runs the command and returns combined output.

type Session

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

Session wraps a tmux session.

func NewSession

func NewSession(name string, opts ...SessionOption) *Session

NewSession constructs a tmux session wrapper.

func (*Session) CapturePane

func (s *Session) CapturePane(ctx context.Context, captureArgs ...string) (string, error)

CapturePane captures the current pane contents.

func (*Session) Kill

func (s *Session) Kill(ctx context.Context) error

Kill terminates the session.

func (*Session) Resize

func (s *Session) Resize(ctx context.Context, width, height int) error

Resize sets the pane size.

func (*Session) SendKeys

func (s *Session) SendKeys(ctx context.Context, keys ...string) error

SendKeys sends keys to the session.

func (*Session) Start

func (s *Session) Start(ctx context.Context) error

Start creates the tmux session.

func (*Session) WaitForPattern

func (s *Session) WaitForPattern(ctx context.Context, pattern *regexp.Regexp, timeout, pollInterval time.Duration, captureArgs ...string) (string, error)

WaitForPattern polls capture-pane until regex match or timeout.

type SessionOption

type SessionOption func(*Session)

SessionOption configures a tmux Session.

func WithRunner

func WithRunner(runner CommandRunner) SessionOption

WithRunner sets the command runner.

func WithSize

func WithSize(width, height int) SessionOption

WithSize sets the session pane size.

func WithWorkDir

func WithWorkDir(dir string) SessionOption

WithWorkDir sets the session working directory.

type UsageResult

type UsageResult struct {
	Provider         string
	WeeklyPct        float64
	SessionResetTime string // e.g. "9pm (America/Los_Angeles)" or "01:18 on 5 Feb"
	WeeklyResetTime  string // e.g. "Feb 8 at 10am (America/Los_Angeles)" or "20:08 on 9 Feb"
	ScrapedAt        time.Time
	RawOutput        string
}

UsageResult captures scraped usage metadata.

func ScrapeClaudeUsage

func ScrapeClaudeUsage(ctx context.Context) (UsageResult, error)

ScrapeClaudeUsage starts Claude in tmux, runs /usage, and parses weekly usage percent.

func ScrapeCodexUsage

func ScrapeCodexUsage(ctx context.Context) (UsageResult, error)

ScrapeCodexUsage starts Codex in tmux, runs /status, and parses weekly usage percent.

Jump to

Keyboard shortcuts

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