session

package
v0.0.0-...-6b1cd05 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentCommand

func AgentCommand(agentType AgentType, agentSessionID string) (string, []string)

AgentCommand returns the command and arguments for the agent type. If agentSessionID is non-empty, it is passed to the CLI for session tracking.

func AgentContinueCommand

func AgentContinueCommand(agentType AgentType, agentSessionID string) (string, []string)

AgentContinueCommand returns the command and arguments to resume/continue a session. If agentSessionID is non-empty, it is used for precise session resume.

func SaveState

func SaveState(filePath string, sessions []*Session) error

SaveState saves session state to a file. Uses atomic write.

Types

type AgentType

type AgentType string

AgentType identifies the AI agent being run.

const (
	AgentClaude  AgentType = "claude"
	AgentGemini  AgentType = "gemini"
	AgentCopilot AgentType = "copilot"
)

func AvailableAgents

func AvailableAgents() []AgentType

AvailableAgents returns the agent types whose CLI binary is found in PATH.

type Manager

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

Manager handles the lifecycle of agent sessions.

func NewManager

func NewManager(tmuxServer *tmux.Server) *Manager

NewManager creates a new session manager.

func (*Manager) Add

func (m *Manager) Add(s *Session)

Add inserts a session into the manager without launching a tmux window.

func (*Manager) CloseTerminal

func (m *Manager) CloseTerminal(s *Session) tea.Cmd

CloseTerminal closes the terminal split pane for a session.

func (*Manager) Count

func (m *Manager) Count() int

Count returns the total number of sessions.

func (*Manager) Get

func (m *Manager) Get(id string) *Session

Get returns a session by ID.

func (*Manager) List

func (m *Manager) List() []*Session

List returns all sessions sorted by creation time (oldest first).

func (*Manager) OpenTerminal

func (m *Manager) OpenTerminal(s *Session) tea.Cmd

OpenTerminal opens a terminal split pane in the session's tmux window.

func (*Manager) Remove

func (m *Manager) Remove(id string)

Remove removes a session from the manager.

func (*Manager) RestartSession

func (m *Manager) RestartSession(s *Session) tea.Cmd

RestartSession restarts a stopped session in a new tmux window. For Claude it uses --continue to resume the conversation; for others it starts fresh.

func (*Manager) Running

func (m *Manager) Running() []*Session

Running returns all currently running sessions.

func (*Manager) RunningCount

func (m *Manager) RunningCount() int

RunningCount returns the number of running sessions.

func (*Manager) StartSession

func (m *Manager) StartSession(s *Session) tea.Cmd

StartSession creates and starts a new agent session in a tmux window.

func (*Manager) StopSession

func (m *Manager) StopSession(sessionID string) tea.Cmd

StopSession stops a running session by sending Ctrl-C and killing the window.

type PersistedSession

type PersistedSession struct {
	ID             string    `json:"id"`
	AgentType      AgentType `json:"agent_type"`
	AgentSessionID string    `json:"agent_session_id,omitempty"`
	ProjectID      string    `json:"project_id"`
	FeatureID      string    `json:"feature_id"`
	WorkDir        string    `json:"work_dir"`
	State          string    `json:"state"`
	TmuxTarget     string    `json:"tmux_target,omitempty"`
}

PersistedSession holds the serializable parts of a session.

func ToPersistedSession

func ToPersistedSession(s *Session) PersistedSession

ToPersistedSession converts a session to its persisted form.

type PersistedState

type PersistedState struct {
	Version  int                `json:"version"`
	Sessions []PersistedSession `json:"sessions"`
}

PersistedState holds all session state for persistence.

func LoadState

func LoadState(filePath string) (*PersistedState, error)

LoadState loads session state from a file.

type Session

type Session struct {
	ID             string     `json:"id"`
	AgentType      AgentType  `json:"agent_type"`
	AgentSessionID string     `json:"agent_session_id,omitempty"`
	ProjectID      string     `json:"project_id"`
	FeatureID      string     `json:"feature_id"`
	WorkDir        string     `json:"work_dir"`
	CreatedAt      time.Time  `json:"created_at"`
	StoppedAt      *time.Time `json:"stopped_at,omitempty"`
	// contains filtered or unexported fields
}

Session represents a running agent session backed by a tmux window.

func NewSession

func NewSession(id string, agentType AgentType, projectID, featureID, workDir string) *Session

NewSession creates a new session in the starting state.

func (*Session) ExitCode

func (s *Session) ExitCode() int

ExitCode returns the exit code of the stopped session.

func (*Session) HasTerminal

func (s *Session) HasTerminal() bool

HasTerminal returns true if a terminal split pane is open.

func (*Session) IsRunning

func (s *Session) IsRunning() bool

IsRunning returns true if the session is in a running state.

func (*Session) LastRestart

func (s *Session) LastRestart() time.Time

LastRestart returns the timestamp of the last restart attempt.

func (*Session) SetExitCode

func (s *Session) SetExitCode(code int)

SetExitCode records the process exit code.

func (*Session) SetLastRestart

func (s *Session) SetLastRestart(t time.Time)

SetLastRestart records the timestamp of a restart attempt.

func (*Session) SetState

func (s *Session) SetState(state State)

SetState sets the session state.

func (*Session) SetTerminalPane

func (s *Session) SetTerminalPane(target string)

SetTerminalPane sets the tmux pane target for the terminal split.

func (*Session) SetTmuxTarget

func (s *Session) SetTmuxTarget(target string)

SetTmuxTarget sets the tmux target for this session.

func (*Session) State

func (s *Session) State() State

State returns the current session state.

func (*Session) TerminalPane

func (s *Session) TerminalPane() string

TerminalPane returns the tmux pane target for the terminal split.

func (*Session) TmuxTarget

func (s *Session) TmuxTarget() string

TmuxTarget returns the tmux target (session:window) for this session.

type SessionLostMsg

type SessionLostMsg struct {
	SessionID string
}

SessionLostMsg is sent when a running session's tmux window disappears (e.g. after app restart). The app should attempt to restart the session.

type SessionStartedMsg

type SessionStartedMsg struct {
	SessionID string
}

SessionStartedMsg is sent when a session successfully starts.

type SessionStoppedMsg

type SessionStoppedMsg struct {
	SessionID string
	Err       error
}

SessionStoppedMsg is sent when a session stops (normally or due to error).

type State

type State int

State represents the lifecycle state of a session.

const (
	StateStarting State = iota
	StateRunning
	StateStopped
)

func (State) String

func (s State) String() string

type TerminalClosedMsg

type TerminalClosedMsg struct {
	SessionID string
}

TerminalClosedMsg is sent when a terminal split pane is closed.

type TerminalOpenedMsg

type TerminalOpenedMsg struct {
	SessionID  string
	PaneTarget string
}

TerminalOpenedMsg is sent when a terminal split pane is successfully opened.

Jump to

Keyboard shortcuts

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