agent

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMultiplexerNotAvailable = errors.New("no terminal multiplexer available (install tmux)")

ErrMultiplexerNotAvailable is returned when no multiplexer is installed

View Source
var ErrTmuxNotAvailable = errors.New("tmux is not available in PATH")

ErrTmuxNotAvailable is returned when tmux is not installed

Functions

func CapturePane

func CapturePane(session string, lines int) (string, error)

CapturePane captures tmux pane output (backward compat)

func EnsureConfig

func EnsureConfig(m Multiplexer) (string, error)

EnsureConfig creates the multiplexer config file if it doesn't exist Returns the config path (empty string if config management is disabled)

func HasSession

func HasSession(session string) (bool, error)

HasSession checks if a tmux session exists (backward compat)

func KillSession

func KillSession(name string) error

KillSession kills a tmux session by name (backward compat)

func ListAvailable

func ListAvailable() []string

ListAvailable returns a list of available multiplexer names

func ListSessions

func ListSessions() ([]string, error)

ListSessions returns all tmux session names (backward compat)

func RequireTmux

func RequireTmux() error

RequireTmux returns an error if tmux is not available (backward compat)

func ResolveSession

func ResolveSession(workspaceOverride string, slot int, wsInfo *WorkspaceInfo) (string, error)

ResolveSession resolves the tmux session name for a given workspace and slot. If workspaceOverride is provided, it uses that workspace name directly. Otherwise, it uses the provided workspace info (typically from the current desktop).

func SendKeys

func SendKeys(session, text string) error

SendKeys sends text to a tmux session (backward compat)

func SessionName

func SessionName(workspaceName string, slot int) string

SessionName returns the tmux session name for a workspace and slot.

func TargetForSession

func TargetForSession(session string) string

TargetForSession returns the tmux target for a session (session:window.pane).

func TmuxAvailable

func TmuxAvailable() bool

TmuxAvailable returns true if tmux is installed (backward compat)

func Truncate

func Truncate(s string, maxLen int) string

Truncate returns a preview of a string, truncating if necessary.

func WaitFor

func WaitFor(session, pattern string, timeout time.Duration, lines int) (string, error)

WaitFor waits for pattern in tmux output (backward compat)

Types

type ActionType

type ActionType string

ActionType represents the type of agent action being logged.

const (
	ActionSend           ActionType = "SEND"
	ActionRead           ActionType = "READ"
	ActionAddTerminal    ActionType = "ADD-TERMINAL"
	ActionRemoveTerminal ActionType = "REMOVE-TERMINAL"
	ActionWorkspaceNew   ActionType = "WORKSPACE-NEW"
	ActionWorkspaceClose ActionType = "WORKSPACE-CLOSE"
	ActionSpawnAgent     ActionType = "SPAWN-AGENT"
	ActionKillAgent      ActionType = "KILL-AGENT"
	ActionWaitIdle       ActionType = "WAIT-IDLE"
	ActionListAgents     ActionType = "LIST-AGENTS"
	ActionMoveTerminal   ActionType = "MOVE-TERMINAL"
)

type ConfigManager

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

ConfigManager handles multiplexer configuration and initialization

func NewConfigManager

func NewConfigManager(cfg *config.Config) (*ConfigManager, error)

NewConfigManager creates a new ConfigManager from the application config

func (*ConfigManager) Available

func (cm *ConfigManager) Available() bool

Available returns true if the configured multiplexer is available

func (*ConfigManager) EnsureConfigIfEnabled

func (cm *ConfigManager) EnsureConfigIfEnabled() (string, error)

EnsureConfigIfEnabled creates the multiplexer config file if: 1. manage_multiplexer_config is enabled (default: true) 2. The config file doesn't already exist Returns the config path, or empty string if config management is disabled

func (*ConfigManager) GetConfigPath

func (cm *ConfigManager) GetConfigPath() string

GetConfigPath returns the path where the multiplexer config is stored

func (*ConfigManager) Initialize

func (cm *ConfigManager) Initialize() error

Initialize sets up the multiplexer environment Call this before creating agent mode sessions

func (*ConfigManager) Multiplexer

func (cm *ConfigManager) Multiplexer() Multiplexer

Multiplexer returns the configured multiplexer

func (*ConfigManager) Name

func (cm *ConfigManager) Name() string

Name returns the name of the configured multiplexer

func (*ConfigManager) SessionCommand

func (cm *ConfigManager) SessionCommand(session string) string

SessionCommand returns the command to create/attach to a session This will include the -f flag for the config file if it exists

type LogConfig

type LogConfig struct {
	Enabled        bool
	Level          LogLevel
	FilePath       string
	MaxSizeMB      int
	MaxFiles       int
	IncludeContent bool
	PreviewLength  int
}

LogConfig holds configuration for the agent logger.

type LogLevel

type LogLevel int

LogLevel defines the logging verbosity.

const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarn
	LevelError
)

func ParseLogLevel

func ParseLogLevel(s string) LogLevel

ParseLogLevel converts a string to LogLevel.

type Logger

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

Logger handles agent action logging with file rotation.

func NewLogger

func NewLogger(cfg LogConfig) (*Logger, error)

NewLogger creates a new logger with the given configuration.

func (*Logger) Close

func (l *Logger) Close() error

Close closes the logger and releases resources.

func (*Logger) Log

func (l *Logger) Log(action ActionType, workspace string, slot int, details map[string]interface{})

Log records an agent action to the log file.

type Multiplexer

type Multiplexer interface {
	// Name returns the multiplexer name (e.g., "tmux", "screen")
	Name() string

	// Available returns true if this multiplexer is installed and usable
	Available() bool

	// HasSession checks if a session with the given name exists
	HasSession(session string) (bool, error)

	// CreateSession creates a new session with the given name
	// Returns the command string to spawn a terminal attached to this session
	CreateSession(session string) (string, error)

	// SendKeys sends text followed by Enter to the session
	SendKeys(session, text string) error

	// CapturePane captures the last N lines of output from the session
	// If lines is 0, captures the visible pane content
	CapturePane(session string, lines int) (string, error)

	// WaitFor polls the session output until pattern is found or timeout
	WaitFor(session, pattern string, timeout time.Duration, lines int) (string, error)

	// SessionCommand returns the command to attach to an existing session
	// or create it if it doesn't exist (e.g., "tmux new-session -A -s <name>")
	SessionCommand(session string) string

	// ConfigPath returns the path where this multiplexer's config should be stored
	// Returns empty string if config management is not supported
	ConfigPath() string

	// DefaultConfig returns the default config content for agent mode
	// This config optimizes for the agentic workflow (scroll UX, history, etc.)
	DefaultConfig() string
}

Multiplexer defines the interface for terminal multiplexer implementations. This abstraction allows termtile to work with tmux, screen, zellij, etc.

func AutoDetect

func AutoDetect(opts ...MultiplexerOption) (Multiplexer, error)

AutoDetect returns the best available multiplexer Detection order: tmux > screen Returns nil and ErrMultiplexerNotAvailable if none are installed

func GetMultiplexer

func GetMultiplexer(mtype MultiplexerType, opts ...MultiplexerOption) (Multiplexer, error)

GetMultiplexer returns a multiplexer by type Use MultiplexerAuto to auto-detect the best available option

type MultiplexerOption

type MultiplexerOption func(*multiplexerOptions)

MultiplexerOption configures multiplexer behavior

func WithConfigPath

func WithConfigPath(path string) MultiplexerOption

WithConfigPath overrides the default config file path

type MultiplexerType

type MultiplexerType string

MultiplexerType represents supported multiplexer types

const (
	MultiplexerAuto   MultiplexerType = "auto"
	MultiplexerTmux   MultiplexerType = "tmux"
	MultiplexerScreen MultiplexerType = "screen"
)

func ParseMultiplexerType

func ParseMultiplexerType(s string) (MultiplexerType, error)

ParseMultiplexerType parses a string into MultiplexerType

type SessionStatus

type SessionStatus struct {
	Exists         bool   `json:"exists"`
	CurrentCommand string `json:"current_command,omitempty"`
	IsIdle         bool   `json:"is_idle"`
	PanePID        int    `json:"pane_pid,omitempty"`
}

SessionStatus represents the current state of a tmux session

func GetSessionStatus

func GetSessionStatus(session string) (SessionStatus, error)

GetSessionStatus queries the status of a tmux session (backward compat)

type TmuxMultiplexer

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

TmuxMultiplexer implements the Multiplexer interface for tmux

func NewTmuxMultiplexer

func NewTmuxMultiplexer(opts ...MultiplexerOption) *TmuxMultiplexer

NewTmuxMultiplexer creates a new tmux multiplexer instance

func (*TmuxMultiplexer) Available

func (t *TmuxMultiplexer) Available() bool

Available returns true if tmux is installed

func (*TmuxMultiplexer) CapturePane

func (t *TmuxMultiplexer) CapturePane(session string, lines int) (string, error)

CapturePane captures output from a tmux pane

func (*TmuxMultiplexer) ConfigPath

func (t *TmuxMultiplexer) ConfigPath() string

ConfigPath returns the path for termtile's tmux config

func (*TmuxMultiplexer) CreateSession

func (t *TmuxMultiplexer) CreateSession(session string) (string, error)

CreateSession creates a new tmux session and returns the attach command

func (*TmuxMultiplexer) DefaultConfig

func (t *TmuxMultiplexer) DefaultConfig() string

DefaultConfig returns the default tmux config optimized for agent workflows The config is embedded from templates/tmux.conf

func (*TmuxMultiplexer) GetSessionStatus

func (t *TmuxMultiplexer) GetSessionStatus(session string) (SessionStatus, error)

GetSessionStatus queries the status of a tmux session

func (*TmuxMultiplexer) HasSession

func (t *TmuxMultiplexer) HasSession(session string) (bool, error)

HasSession checks if a tmux session exists

func (*TmuxMultiplexer) KillSession

func (t *TmuxMultiplexer) KillSession(name string) error

KillSession kills a tmux session by name.

func (*TmuxMultiplexer) ListSessions

func (t *TmuxMultiplexer) ListSessions() ([]string, error)

ListSessions returns all tmux session names.

func (*TmuxMultiplexer) Name

func (t *TmuxMultiplexer) Name() string

Name returns "tmux"

func (*TmuxMultiplexer) RenameSession

func (t *TmuxMultiplexer) RenameSession(oldName, newName string) error

RenameSession renames a tmux session.

func (*TmuxMultiplexer) SendKeys

func (t *TmuxMultiplexer) SendKeys(session, text string) error

SendKeys sends text followed by Enter to a tmux session

func (*TmuxMultiplexer) SessionCommand

func (t *TmuxMultiplexer) SessionCommand(session string) string

SessionCommand returns the tmux command to create-or-attach to a session Note: -f flag only applies when tmux server starts fresh. For existing servers, we also source the config to ensure settings are applied.

func (*TmuxMultiplexer) WaitFor

func (t *TmuxMultiplexer) WaitFor(session, pattern string, timeout time.Duration, lines int) (string, error)

WaitFor polls session output until pattern is found or timeout

type WorkspaceInfo

type WorkspaceInfo struct {
	Name       string
	AgentMode  bool
	AgentSlots []int
}

WorkspaceInfo contains the information needed to resolve an agent session. This is passed in from the workspace package to avoid import cycles.

Jump to

Keyboard shortcuts

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