session

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AgentConfigs = map[AgentType]AgentConfig{
	AgentClaude: {
		Command:         "claude",
		SupportsResume:  true,
		SupportsAutoYes: true,
		AutoYesFlag:     "--dangerously-skip-permissions",
		ResumeFlag:      "--resume",
	},
	AgentGemini: {
		Command:         "gemini",
		SupportsResume:  true,
		SupportsAutoYes: false,
		ResumeFlag:      "--resume",
	},
	AgentAider: {
		Command:         "aider",
		SupportsResume:  false,
		SupportsAutoYes: true,
		AutoYesFlag:     "--yes",
	},
	AgentCodex: {
		Command:            "codex",
		SupportsResume:     true,
		SupportsAutoYes:    true,
		AutoYesFlag:        "--full-auto",
		ResumeFlag:         "resume",
		ResumeIsSubcommand: true,
	},
	AgentAmazonQ: {
		Command:            "q",
		SupportsResume:     true,
		SupportsAutoYes:    true,
		AutoYesFlag:        "--trust-all-tools",
		ResumeFlag:         "chat --resume",
		ResumeIsSubcommand: true,
	},
	AgentOpenCode: {
		Command:         "opencode",
		SupportsResume:  true,
		SupportsAutoYes: false,
		ResumeFlag:      "--session",
	},
	AgentCursor: {
		Command:         "cursor",
		SupportsResume:  false,
		SupportsAutoYes: false,
	},
	AgentCustom: {
		Command:         "",
		SupportsResume:  false,
		SupportsAutoYes: false,
	},
}

AgentConfigs maps agent types to their configurations

Functions

func CheckAgentCommand

func CheckAgentCommand(inst *Instance) error

CheckAgentCommand verifies that the agent command exists in PATH

func GetClaudeProjectDir

func GetClaudeProjectDir(projectPath string) string

func GetClaudeStatusLine added in v0.4.0

func GetClaudeStatusLine(lines []string, stripANSIFunc func(string) string) string

GetClaudeStatusLine handles Claude Code's special UI with horizontal separator lines. If the input area (between two horizontal lines) has only 1 line (the prompt), it returns the content above the top separator instead of the prompt line.

Types

type AgentConfig

type AgentConfig struct {
	Command            string // Base command to run
	SupportsResume     bool   // Whether agent supports session resume
	SupportsAutoYes    bool   // Whether agent has auto-approve flag
	AutoYesFlag        string // The flag for auto-approve (e.g., "--dangerously-skip-permissions")
	ResumeFlag         string // The flag for resume (e.g., "--resume")
	ResumeIsSubcommand bool   // If true, resume is a subcommand (e.g., "codex resume") not a flag
}

AgentConfig contains configuration for each agent type

type AgentPatterns added in v0.6.0

type AgentPatterns struct {
	WaitingPatterns []string // Patterns that indicate waiting for user input
	BusyPatterns    []string // Patterns that indicate agent is working
	Spinners        []string // Spinner characters
}

AgentPatterns holds detection patterns for a specific agent

type AgentSession added in v0.3.5

type AgentSession struct {
	SessionID    string    `json:"session_id"`
	FirstPrompt  string    `json:"first_prompt"`
	LastPrompt   string    `json:"last_prompt"`
	MessageCount int       `json:"message_count"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	AgentType    AgentType `json:"agent_type"`
}

AgentSession is a generic session structure for any agent type

func ListAgentSessions added in v0.3.5

func ListAgentSessions(projectPath string) ([]AgentSession, error)

func ListAmazonQSessions added in v0.3.5

func ListAmazonQSessions(projectPath string) ([]AgentSession, error)

ListAmazonQSessions lists all Amazon Q sessions for the given project path Note: Amazon Q automatically saves conversations by working directory and resumes with "q chat --resume" without needing session IDs

func ListCodexSessions added in v0.3.5

func ListCodexSessions(projectPath string) ([]AgentSession, error)

ListCodexSessions lists all Codex sessions for the given project path

func ListGeminiSessions added in v0.3.5

func ListGeminiSessions(projectPath string) ([]AgentSession, error)

ListGeminiSessions lists all Gemini sessions for the given project path

func ListOpenCodeSessions added in v0.3.5

func ListOpenCodeSessions(projectPath string) ([]AgentSession, error)

ListOpenCodeSessions lists all OpenCode sessions for the given project path

type AgentType

type AgentType string

AgentType represents the type of AI agent

const (
	AgentClaude   AgentType = "claude"
	AgentGemini   AgentType = "gemini"
	AgentAider    AgentType = "aider"
	AgentCodex    AgentType = "codex"
	AgentAmazonQ  AgentType = "amazonq"
	AgentOpenCode AgentType = "opencode"
	AgentCursor   AgentType = "cursor"
	AgentCustom   AgentType = "custom"
	AgentTerminal AgentType = "terminal" // Plain shell/terminal window
)

type ConversationMessage added in v0.7.5

type ConversationMessage struct {
	Role      string    // "user" or "assistant"
	Content   string    // Message content
	Timestamp time.Time // Message timestamp
}

ConversationMessage represents a single message in a conversation

type DiffStats added in v0.6.5

type DiffStats struct {
	Added   int    // Number of added lines
	Removed int    // Number of removed lines
	Content string // Raw diff content
	Error   error  // Error if diff failed
}

DiffStats contains git diff statistics and content

func (*DiffStats) IsEmpty added in v0.6.5

func (d *DiffStats) IsEmpty() bool

IsEmpty returns true if there are no changes

type FollowedWindow added in v0.6.0

type FollowedWindow struct {
	Index           int       `json:"index"`
	Agent           AgentType `json:"agent"`
	Name            string    `json:"name"`              // Tab name for display
	CustomCommand   string    `json:"custom_command"`    // For custom agents
	AutoYes         bool      `json:"auto_yes"`          // YOLO mode for this tab
	ResumeSessionID string    `json:"resume_session_id"` // Resume session ID for this tab
	Notes           string    `json:"notes,omitempty"`   // User notes for this tab
}

FollowedWindow represents a tmux window tracked as an agent

type Group

type Group struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	Collapsed    bool   `json:"collapsed"`
	Color        string `json:"color,omitempty"`          // Group name color
	BgColor      string `json:"bg_color,omitempty"`       // Background color
	FullRowColor bool   `json:"full_row_color,omitempty"` // Extend background to full row
}

Group represents a session group for organizing sessions

type HistoryEntry added in v0.7.5

type HistoryEntry struct {
	ID          string
	Agent       AgentType
	Content     string // Full conversation or command (for search)
	Snippet     string // Highlighted excerpt for display
	Path        string // Project path (if applicable)
	Timestamp   time.Time
	Score       int    // Relevance score for sorting
	SessionFile string // Full path to session file (for Claude - to load conversation)
	SessionID   string // Claude session ID (for resume)
}

HistoryEntry represents a single searchable history item from any agent

func (*HistoryEntry) LoadConversation added in v0.7.5

func (e *HistoryEntry) LoadConversation() ([]ConversationMessage, error)

LoadConversation loads the full conversation from a session file

type HistoryIndex added in v0.7.5

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

HistoryIndex manages the searchable history across all agents

func NewHistoryIndex added in v0.7.5

func NewHistoryIndex() *HistoryIndex

NewHistoryIndex creates a new history index

func (*HistoryIndex) FuzzySearch added in v0.7.5

func (h *HistoryIndex) FuzzySearch(query string) []HistoryEntry

FuzzySearch performs fuzzy matching with typo tolerance

func (*HistoryIndex) IsLoaded added in v0.7.5

func (h *HistoryIndex) IsLoaded() bool

IsLoaded returns true if history has been loaded

func (*HistoryIndex) Load added in v0.7.5

func (h *HistoryIndex) Load() error

Load loads history from all available sources

func (*HistoryIndex) Search added in v0.7.5

func (h *HistoryIndex) Search(query string) []HistoryEntry

Search searches the history index for matching entries Falls back to fuzzy search if no exact matches found

func (*HistoryIndex) SetInstances added in v0.7.5

func (h *HistoryIndex) SetInstances(instances []*Instance)

SetInstances sets the live instances for terminal search

type Instance

type Instance struct {
	ID              string           `json:"id"`
	Name            string           `json:"name"`
	Path            string           `json:"path"`
	Status          Status           `json:"status"`
	CreatedAt       time.Time        `json:"created_at"`
	UpdatedAt       time.Time        `json:"updated_at"`
	AutoYes         bool             `json:"auto_yes"`
	ResumeSessionID string           `json:"resume_session_id,omitempty"` // Claude session ID to resume
	Color           string           `json:"color,omitempty"`             // Foreground color
	BgColor         string           `json:"bg_color,omitempty"`          // Background color
	FullRowColor    bool             `json:"full_row_color,omitempty"`    // Extend background to full row
	GroupID         string           `json:"group_id,omitempty"`          // Session group ID
	Agent           AgentType        `json:"agent,omitempty"`             // Agent type (claude, gemini, aider, custom)
	CustomCommand   string           `json:"custom_command,omitempty"`    // Custom command for AgentCustom
	Notes           string           `json:"notes,omitempty"`             // User notes/comments for this session
	FollowedWindows []FollowedWindow `json:"followed_windows,omitempty"`  // Windows tracked as agents (window 0 is main agent)
	BaseCommitSHA   string           `json:"base_commit_sha,omitempty"`   // Git HEAD commit at session start (for diff)
	Favorite        bool             `json:"favorite,omitempty"`          // Whether session is marked as favorite
}

func NewInstance

func NewInstance(name, path string, autoYes bool, agent AgentType) (*Instance, error)

func (*Instance) Attach

func (i *Instance) Attach() error

func (*Instance) CloseWindow added in v0.6.0

func (i *Instance) CloseWindow(windowIdx int) error

CloseWindow closes a tmux window by index and removes it from FollowedWindows

func (*Instance) DetectActivity added in v0.4.0

func (i *Instance) DetectActivity() SessionActivity

DetectActivity analyzes tmux pane content to determine session activity This always checks window 0 (the main agent window)

func (*Instance) DetectActivityForWindow added in v0.6.0

func (i *Instance) DetectActivityForWindow(windowIdx int) SessionActivity

DetectActivityForWindow analyzes a specific tmux window to determine activity

func (*Instance) DetectAggregatedActivity added in v0.6.0

func (i *Instance) DetectAggregatedActivity() SessionActivity

DetectAggregatedActivity checks all followed windows and returns highest priority activity Priority: Waiting > Busy > Idle

func (*Instance) ForkSession added in v0.7.5

func (i *Instance) ForkSession() (string, error)

ForkSession creates a fork of the current Claude session using --fork-session Returns the new session ID

func (*Instance) GetAgentConfig

func (i *Instance) GetAgentConfig() AgentConfig

GetAgentConfig returns the agent configuration for this instance

func (*Instance) GetAllFollowedAgents added in v0.6.0

func (i *Instance) GetAllFollowedAgents() []FollowedWindow

GetAllFollowedAgents returns info about all followed agents (including main window 0)

func (*Instance) GetCurrentWindowIndex added in v0.6.0

func (i *Instance) GetCurrentWindowIndex() int

GetCurrentWindowIndex returns the current (active) window index (0-based)

func (*Instance) GetFollowedWindow added in v0.6.0

func (i *Instance) GetFollowedWindow(index int) *FollowedWindow

GetFollowedWindow returns the FollowedWindow for a given index, or nil if not followed

func (*Instance) GetFullDiff added in v0.6.5

func (i *Instance) GetFullDiff() *DiffStats

GetFullDiff returns all uncommitted changes (staged + unstaged)

func (*Instance) GetLastLine

func (i *Instance) GetLastLine() string

GetLastLine returns the last non-empty line of output (for status display)

func (*Instance) GetLastLineForWindow added in v0.6.0

func (i *Instance) GetLastLineForWindow(windowIdx int, agent AgentType) string

GetLastLineForWindow returns the last meaningful line from a specific window

func (*Instance) GetPreview

func (i *Instance) GetPreview(lines int) (string, error)

func (*Instance) GetSessionDiff added in v0.6.5

func (i *Instance) GetSessionDiff() *DiffStats

GetSessionDiff returns diff since session start (BaseCommitSHA)

func (*Instance) GetSuggestion added in v0.4.0

func (i *Instance) GetSuggestion() string

GetSuggestion extracts the autocomplete suggestion from the agent's prompt area

func (*Instance) GetWindowCount added in v0.6.0

func (i *Instance) GetWindowCount() int

GetWindowCount returns the number of tmux windows in the session

func (*Instance) GetWindowList added in v0.6.0

func (i *Instance) GetWindowList() []WindowInfo

GetWindowList returns information about all windows in the session

func (*Instance) IsAlive

func (i *Instance) IsAlive() bool

func (*Instance) IsWindowFollowed added in v0.6.0

func (i *Instance) IsWindowFollowed(index int) bool

IsWindowFollowed checks if a window index is being tracked as an agent

func (*Instance) NewAgentWindow added in v0.6.0

func (i *Instance) NewAgentWindow(name string, agent AgentType, customCmd string) (int, error)

NewAgentWindow creates a new tmux window running the specified agent

func (*Instance) NewForkedTab added in v0.7.5

func (i *Instance) NewForkedTab(name string, sessionID string) error

NewForkedTab creates a new tab with a forked Claude session

func (*Instance) NewWindow added in v0.6.0

func (i *Instance) NewWindow() error

NewWindow creates a new tmux window in the session's directory

func (*Instance) NewWindowWithName added in v0.6.0

func (i *Instance) NewWindowWithName(name string) error

NewWindowWithName creates a new tmux window with a specific name

func (*Instance) NextWindow added in v0.6.0

func (i *Instance) NextWindow() error

NextWindow switches to the next tmux window

func (*Instance) PrevWindow added in v0.6.0

func (i *Instance) PrevWindow() error

PrevWindow switches to the previous tmux window

func (*Instance) RenameCurrentWindow added in v0.6.0

func (i *Instance) RenameCurrentWindow(name string) error

RenameCurrentWindow renames the current tmux window

func (*Instance) ResetBaseCommit added in v0.6.5

func (i *Instance) ResetBaseCommit()

ResetBaseCommit clears the base commit SHA (useful for "reset diff" feature)

func (*Instance) ResizePane

func (i *Instance) ResizePane(width, height int) error

ResizePane resizes the tmux pane to the specified dimensions

func (*Instance) RespawnWindow added in v0.6.0

func (i *Instance) RespawnWindow(windowIdx int) error

RespawnWindow restarts a dead window's process

func (*Instance) RespawnWindowWithResume added in v0.6.5

func (i *Instance) RespawnWindowWithResume(windowIdx int, resumeID string) error

RespawnWindowWithResume restarts a window's process with a specific resume session ID

func (*Instance) SelectWindow added in v0.6.0

func (i *Instance) SelectWindow(index int) error

SelectWindow switches to the specified window index

func (*Instance) SendKeys

func (i *Instance) SendKeys(keys string) error

func (*Instance) SendPrompt added in v0.3.5

func (i *Instance) SendPrompt(text string) error

SendPrompt sends a prompt text followed by Enter key

func (*Instance) SendText added in v0.3.5

func (i *Instance) SendText(text string) error

SendText sends text literally (not interpreted as key names)

func (*Instance) Start

func (i *Instance) Start() error

func (*Instance) StartWithResume

func (i *Instance) StartWithResume(resumeID string) error

func (*Instance) Stop

func (i *Instance) Stop() error

func (*Instance) StopWindow added in v0.6.0

func (i *Instance) StopWindow(windowIdx int) error

StopWindow kills the process in a tmux window (keeps window due to remain-on-exit)

func (*Instance) TmuxSessionName

func (i *Instance) TmuxSessionName() string

func (*Instance) ToggleWindowFollow added in v0.6.0

func (i *Instance) ToggleWindowFollow(index int) bool

ToggleWindowFollow toggles the follow status of a window

func (*Instance) UpdateDetachBinding

func (i *Instance) UpdateDetachBinding(previewWidth, previewHeight int)

UpdateDetachBinding updates Ctrl+Q to resize to preview size before detaching

func (*Instance) UpdateStatus

func (i *Instance) UpdateStatus()

func (*Instance) WindowName added in v0.6.5

func (i *Instance) WindowName() string

WindowName returns the display name for the main tmux window (agent type)

type Project added in v0.3.0

type Project struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Path      string    `json:"path,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	Color     string    `json:"color,omitempty"`
}

Project represents a workspace containing sessions and groups

func NewProject added in v0.3.0

func NewProject(name string) *Project

NewProject creates a new project with the given name

type ProjectsData added in v0.3.0

type ProjectsData struct {
	Projects    []*Project `json:"projects"`
	LastProject string     `json:"last_project,omitempty"`
}

ProjectsData contains the list of projects and metadata

type SessionActivity added in v0.4.0

type SessionActivity int

SessionActivity represents the activity state of a session

const (
	ActivityIdle    SessionActivity = iota // No activity, no prompt
	ActivityBusy                           // Agent is working
	ActivityWaiting                        // Agent needs user input/permission
)

type Settings

type Settings struct {
	CompactList     bool   `json:"compact_list"`
	HideStatusLines bool   `json:"hide_status_lines"`
	ShowAgentIcons  bool   `json:"show_agent_icons,omitempty"`
	SplitView       bool   `json:"split_view,omitempty"`
	MarkedSessionID string `json:"marked_session_id,omitempty"`
	Cursor          int    `json:"cursor,omitempty"`
	SplitFocus      int    `json:"split_focus,omitempty"`
}

Settings stores UI preferences

type Status

type Status string
const (
	StatusRunning Status = "running"
	StatusPaused  Status = "paused"
	StatusStopped Status = "stopped"
)

type Storage

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

func NewStorage

func NewStorage() (*Storage, error)

func (*Storage) AddGroup

func (s *Storage) AddGroup(name string) (*Group, error)

AddGroup adds a new group

func (*Storage) AddInstance

func (s *Storage) AddInstance(instance *Instance) error

func (*Storage) AddProject added in v0.3.0

func (s *Storage) AddProject(name string) (*Project, error)

AddProject creates a new project

func (*Storage) GetActiveProjectID added in v0.3.0

func (s *Storage) GetActiveProjectID() string

GetActiveProjectID returns the currently active project ID

func (*Storage) GetGroups

func (s *Storage) GetGroups() ([]*Group, error)

GetGroups returns all groups

func (*Storage) GetInstance

func (s *Storage) GetInstance(id string) (*Instance, error)

func (*Storage) GetInstanceByName

func (s *Storage) GetInstanceByName(name string) (*Instance, error)

func (*Storage) GetProject added in v0.3.0

func (s *Storage) GetProject(id string) (*Project, error)

GetProject returns a project by ID

func (*Storage) GetProjectSessionCount added in v0.3.0

func (s *Storage) GetProjectSessionCount(projectID string) int

GetSessionCount returns the number of sessions in a project This requires loading the project's sessions file

func (*Storage) ImportDefaultSessions added in v0.3.0

func (s *Storage) ImportDefaultSessions(projectID string) (int, error)

ImportDefaultSessions moves sessions from default storage to a project

func (*Storage) IsProjectLocked added in v0.3.0

func (s *Storage) IsProjectLocked(projectID string) (bool, int)

IsProjectLocked checks if a project is already running

func (*Storage) Load

func (s *Storage) Load() ([]*Instance, error)

func (*Storage) LoadAll

func (s *Storage) LoadAll() ([]*Instance, []*Group, error)

LoadAll loads instances, groups, and settings

func (*Storage) LoadAllWithSettings

func (s *Storage) LoadAllWithSettings() ([]*Instance, []*Group, *Settings, error)

LoadAllWithSettings loads instances, groups, and settings

func (*Storage) LoadProjects added in v0.3.0

func (s *Storage) LoadProjects() (*ProjectsData, error)

LoadProjects loads the list of projects

func (*Storage) LockProject added in v0.3.0

func (s *Storage) LockProject(projectID string) error

LockProject creates a lock file for the current project

func (*Storage) RemoveGroup

func (s *Storage) RemoveGroup(id string) error

RemoveGroup removes a group (sessions become ungrouped)

func (*Storage) RemoveInstance

func (s *Storage) RemoveInstance(id string) error

func (*Storage) RemoveProject added in v0.3.0

func (s *Storage) RemoveProject(id string) error

RemoveProject removes a project and its data

func (*Storage) RenameGroup

func (s *Storage) RenameGroup(id, name string) error

RenameGroup renames a group

func (*Storage) RenameProject added in v0.3.0

func (s *Storage) RenameProject(id, name string) error

RenameProject renames a project

func (*Storage) Save

func (s *Storage) Save(instances []*Instance) error

func (*Storage) SaveAll

func (s *Storage) SaveAll(instances []*Instance, groups []*Group, settings *Settings) error

SaveAll saves instances, groups, and settings

func (*Storage) SaveProjects added in v0.3.0

func (s *Storage) SaveProjects(projectsData *ProjectsData) error

SaveProjects saves the list of projects

func (*Storage) SaveSettings

func (s *Storage) SaveSettings(settings *Settings) error

SaveSettings saves only the settings (preserves instances and groups)

func (*Storage) SaveWithGroups

func (s *Storage) SaveWithGroups(instances []*Instance, groups []*Group) error

SaveWithGroups saves instances and groups (preserves settings)

func (*Storage) SetActiveProject added in v0.3.0

func (s *Storage) SetActiveProject(projectID string) error

SetActiveProject switches to a different project

func (*Storage) SetInstanceGroup

func (s *Storage) SetInstanceGroup(instanceID, groupID string) error

SetInstanceGroup assigns an instance to a group

func (*Storage) ToggleGroupCollapsed

func (s *Storage) ToggleGroupCollapsed(id string) error

ToggleGroupCollapsed toggles the collapsed state of a group

func (*Storage) UnlockProject added in v0.3.0

func (s *Storage) UnlockProject()

UnlockProject removes the lock file

func (*Storage) UpdateInstance

func (s *Storage) UpdateInstance(instance *Instance) error

type StorageData

type StorageData struct {
	Instances []*Instance `json:"instances"`
	Groups    []*Group    `json:"groups,omitempty"`
	Settings  *Settings   `json:"settings,omitempty"`
}

type WindowInfo added in v0.6.0

type WindowInfo struct {
	Index    int
	Name     string
	Active   bool
	Followed bool      // Whether this window is tracked as an agent
	Agent    AgentType // Agent type if followed
	Dead     bool      // Whether the window's pane has exited (command finished)
}

WindowInfo contains information about a tmux window

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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