session

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllocatePortsLegacy

func AllocatePortsLegacy() (fePort, apiPort int, err error)

AllocatePortsLegacy allocates two unique ports for frontend and API (backwards compatibility)

func AttachEditorToSession

func AttachEditorToSession(sessionName, path string) error

AttachEditorToSession handles editor attachment logic for session attach

func AttachTmuxSession

func AttachTmuxSession(sessionName string) error

AttachTmuxSession attaches to an existing tmux session

func BranchExists

func BranchExists(repoPath, branchName string) (bool, error)

BranchExists checks if a branch exists in the repository

func ClearAttentionFlag

func ClearAttentionFlag(sessionName string) error

ClearAttentionFlag clears the attention flag for a session

func ClearRegistry

func ClearRegistry() error

ClearRegistry removes all sessions and clears the sessions file

func CopyBootstrapFiles

func CopyBootstrapFiles(projectRoot, worktreePath string) error

CopyBootstrapFiles copies configured bootstrap files from project root to the worktree

func CreateWorktree

func CreateWorktree(repoPath, name string, detach bool) error

CreateWorktree creates a new git worktree

func GenerateEnvrc

func GenerateEnvrc(worktreePath string, data EnvrcData) error

GenerateEnvrc creates an .envrc file in the worktree directory

func GenerateTmuxpConfig

func GenerateTmuxpConfig(worktreePath string, data TmuxpData) error

GenerateTmuxpConfig creates a .tmuxp.yaml file in the worktree directory

func GetCurrentSessionName

func GetCurrentSessionName() string

GetCurrentSessionName attempts to determine the current session based on working directory

func GetEditorCommand

func GetEditorCommand() string

GetEditorCommand returns the editor command to use, checking in this order: 1. devx config "editor" setting 2. VISUAL environment variable 3. EDITOR environment variable 4. Empty string if none are set

func GetProjectRoot

func GetProjectRoot() (string, error)

GetProjectRoot finds the git repository root directory

func IsEditorAvailable

func IsEditorAvailable() bool

IsEditorAvailable checks if the configured editor command is available

func IsProcessRunning

func IsProcessRunning(pid int) bool

IsProcessRunning checks if a process with the given PID is still running

func IsTmuxRunning

func IsTmuxRunning() bool

IsTmuxRunning checks if we're already inside a tmux session

func IsWorktreeCheckedOut

func IsWorktreeCheckedOut(repoPath, branchName string) (bool, string, error)

IsWorktreeCheckedOut checks if a branch is already checked out in a worktree

func LaunchEditor

func LaunchEditor(path string) (int, error)

LaunchEditor launches the configured editor with the given path It runs asynchronously and returns the process PID

func LaunchEditorForSession

func LaunchEditorForSession(sessionName, path string) error

LaunchEditorForSession launches the editor for a session and updates the session metadata

func LaunchTmuxSession

func LaunchTmuxSession(worktreePath, sessionName string) error

LaunchTmuxSession launches a tmux session using tmuxp

func PruneWorktrees

func PruneWorktrees(repoPath string) error

PruneWorktrees removes stale worktree references

func PullFromOrigin

func PullFromOrigin(repoPath, branch string) error

PullFromOrigin pulls the latest changes from origin for the specified branch

func RemoveSession

func RemoveSession(name string, sess *Session) error

RemoveSession removes a single session completely (helper for commands)

func RunCleanupCommand

func RunCleanupCommand(sess *Session) error

RunCleanupCommand executes the configured cleanup command with session environment variables

func RunCleanupCommandForShell

func RunCleanupCommandForShell(sess *Session) error

RunCleanupCommandForShell executes cleanup command through shell for complex commands

func SetAttentionFlag

func SetAttentionFlag(sessionName, reason string) error

SetAttentionFlag sets the attention flag for a session

func TerminateEditor

func TerminateEditor(sessionName string) error

TerminateEditor terminates the editor process for a session

func ValidatePort

func ValidatePort(port int) error

ValidatePort checks if a port number is valid

func WorktreeExists

func WorktreeExists(repoPath, worktreePath string) (bool, error)

WorktreeExists checks if a worktree exists at the specified path

Types

type EnvrcData

type EnvrcData struct {
	Ports  map[string]int    // service name -> port number
	Routes map[string]string // service name -> hostname
	Name   string
}

type PortAllocation

type PortAllocation struct {
	Ports map[string]int // service name -> port number
}

PortAllocation represents allocated ports with their service names

func AllocatePorts

func AllocatePorts(serviceNames []string) (*PortAllocation, error)

AllocatePorts allocates unique ports for the given service names

type Session

type Session struct {
	Name            string            `json:"name"`
	ProjectAlias    string            `json:"project_alias,omitempty"` // Reference to project in registry
	ProjectPath     string            `json:"project_path,omitempty"`  // Resolved project path
	Branch          string            `json:"branch"`
	Path            string            `json:"path"`
	Ports           map[string]int    `json:"ports"`
	Routes          map[string]string `json:"routes,omitempty"`     // service -> route ID mapping
	EditorPID       int               `json:"editor_pid,omitempty"` // PID of the editor process
	AttentionFlag   bool              `json:"attention_flag,omitempty"`
	AttentionReason string            `json:"attention_reason,omitempty"` // "claude_done", "claude_stuck", "manual", etc.
	AttentionTime   time.Time         `json:"attention_time,omitempty"`
	CreatedAt       time.Time         `json:"created_at"`
	UpdatedAt       time.Time         `json:"updated_at"`
}

type SessionStore

type SessionStore struct {
	Sessions map[string]*Session `json:"sessions"`
}

func LoadRegistry

func LoadRegistry() (*SessionStore, error)

LoadRegistry is an alias for LoadSessions for compatibility

func LoadSessions

func LoadSessions() (*SessionStore, error)

LoadSessions loads the sessions from the metadata file

func (*SessionStore) AddSession

func (s *SessionStore) AddSession(name, branch, path string, ports map[string]int) error

AddSession adds a new session to the store

func (*SessionStore) AddSessionWithProject

func (s *SessionStore) AddSessionWithProject(name, branch, path string, ports map[string]int, projectAlias, projectPath string) error

AddSessionWithProject adds a new session to the store with project information

func (*SessionStore) GetSession

func (s *SessionStore) GetSession(name string) (*Session, bool)

GetSession retrieves a session by name

func (*SessionStore) RemoveSession

func (s *SessionStore) RemoveSession(name string) error

RemoveSession removes a session from the store

func (*SessionStore) Save

func (s *SessionStore) Save() error

SaveSessions saves the sessions to the metadata file

func (*SessionStore) UpdateSession

func (s *SessionStore) UpdateSession(name string, updateFn func(*Session)) error

UpdateSession updates an existing session

type TmuxpData

type TmuxpData struct {
	Name   string
	Path   string
	Ports  map[string]int    // service name -> port number
	Routes map[string]string // service name -> hostname
}

type WorktreeInfo

type WorktreeInfo struct {
	Path   string
	Branch string
	Head   string
}

func ListWorktrees

func ListWorktrees(repoPath string) ([]WorktreeInfo, error)

ListWorktrees returns all git worktrees in the repository

Jump to

Keyboard shortcuts

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