Documentation
¶
Index ¶
- Constants
- func AllocatePortsLegacy() (fePort, apiPort int, err error)
- func AttachEditorToSession(sessionName, path string) error
- func AttachTmuxSession(sessionName string) error
- func BranchExists(repoPath, branchName string) (bool, error)
- func ClearAttentionFlag(sessionName string) error
- func ClearRegistry() error
- func CopyBootstrapFiles(projectRoot, worktreePath string) error
- func CreateWorktree(repoPath, name string, detach bool) error
- func FetchOrigin(repoPath string) error
- func GenerateEnvrc(worktreePath string, data EnvrcData) error
- func GenerateTmuxpConfig(worktreePath string, data TmuxpData, projectPath string) error
- func GetCurrentSessionName() string
- func GetEditorCommand() string
- func GetProjectRoot() (string, error)
- func IsEditorAvailable() bool
- func IsProcessRunning(pid int) bool
- func IsTmuxRunning() bool
- func IsValidSessionName(name string) bool
- func IsWorktreeCheckedOut(repoPath, branchName string) (bool, string, error)
- func LaunchEditor(path string) (int, error)
- func LaunchEditorForSession(sessionName, path string) error
- func LaunchTmuxSession(worktreePath, sessionName string) error
- func PruneWorktrees(repoPath string) error
- func PullFromOrigin(repoPath, branch string) error
- func RemoteBranchExists(repoPath, branchName string) (bool, error)
- func RemoveSession(name string, sess *Session) error
- func RunCleanupCommand(sess *Session) error
- func RunCleanupCommandForShell(sess *Session) error
- func SetAttentionFlag(sessionName, reason string) error
- func TerminateEditor(sessionName string) error
- func ValidatePort(port int) error
- func WorktreeExists(repoPath, worktreePath string) (bool, error)
- type EnvrcData
- type PortAllocation
- type Session
- type SessionStore
- func (s *SessionStore) AddSession(name, branch, path string, ports map[string]int) error
- func (s *SessionStore) AddSessionWithProject(name, branch, path string, ports map[string]int, ...) error
- func (s *SessionStore) AssignSlot(name string) (int, error)
- func (s *SessionStore) GetSession(name string) (*Session, bool)
- func (s *SessionStore) GetSessionForSlot(slot int) string
- func (s *SessionStore) GetSlotForSession(name string) int
- func (s *SessionStore) ReconcileSlots()
- func (s *SessionStore) RecordAttach(name string) error
- func (s *SessionStore) RemoveSession(name string) error
- func (s *SessionStore) Save() error
- func (s *SessionStore) UpdateSession(name string, updateFn func(*Session)) error
- type TmuxpData
- type WorktreeInfo
Constants ¶
const MaxSessionNameLen = 100
MaxSessionNameLen is the maximum allowed length for a session name. The TUI input and the validation regex both enforce this limit.
Variables ¶
This section is empty.
Functions ¶
func AllocatePortsLegacy ¶
AllocatePortsLegacy allocates two unique ports for frontend and API (backwards compatibility)
func AttachEditorToSession ¶
AttachEditorToSession handles editor attachment logic for session attach
func AttachTmuxSession ¶
AttachTmuxSession attaches to an existing tmux session
func BranchExists ¶
BranchExists checks if a branch exists in the repository
func ClearAttentionFlag ¶
ClearAttentionFlag clears the attention flag for a session
func ClearRegistry ¶
func ClearRegistry() error
ClearRegistry removes all sessions and clears the sessions file
func CopyBootstrapFiles ¶
CopyBootstrapFiles copies configured bootstrap files from project root to the worktree
func CreateWorktree ¶
CreateWorktree creates a new git worktree
func FetchOrigin ¶ added in v0.3.0
FetchOrigin fetches remote refs from origin, pruning deleted branches. Failure is non-fatal (caller warns and continues).
func GenerateEnvrc ¶
GenerateEnvrc creates an .envrc file in the worktree directory
func GenerateTmuxpConfig ¶
GenerateTmuxpConfig creates a .tmuxp.yaml file in the worktree directory. projectPath is the root of the project (containing .devx/) and is used to find the project-level template. It must be passed explicitly so that config lookup is project-path-based rather than relying on os.Getwd(), which is unreliable when creating sessions via --project flag or the web UI.
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 ¶
GetProjectRoot finds the git repository root directory
func IsEditorAvailable ¶
func IsEditorAvailable() bool
IsEditorAvailable checks if the configured editor command is available
func IsProcessRunning ¶
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 IsValidSessionName ¶ added in v0.3.0
IsValidSessionName returns true if name passes both the character-class regex and path-traversal guards. Names are used as git branch names, tmux targets, and path components under .worktrees/, so "." and ".." segments must be rejected.
Validation is two-stage: (1) the regex enforces the allowed character set and maximum length; (2) the segment loop enforces structural constraints (path traversal, git-rejected patterns) that regex alone cannot cleanly express.
func IsWorktreeCheckedOut ¶
IsWorktreeCheckedOut checks if a branch is already checked out in a worktree
func LaunchEditor ¶
LaunchEditor launches the configured editor with the given path It runs asynchronously and returns the process PID
func LaunchEditorForSession ¶
LaunchEditorForSession launches the editor for a session and updates the session metadata
func LaunchTmuxSession ¶
LaunchTmuxSession launches a tmux session using tmuxp
func PruneWorktrees ¶
PruneWorktrees removes stale worktree references. --expire now bypasses git's default 3-month grace period so recently-deleted worktrees are pruned immediately rather than showing as "missing but registered".
func PullFromOrigin ¶
PullFromOrigin pulls the latest changes from origin for the specified branch
func RemoteBranchExists ¶ added in v0.3.0
RemoteBranchExists checks if a branch exists on origin.
func RemoveSession ¶
RemoveSession removes a single session completely (helper for commands)
func RunCleanupCommand ¶
RunCleanupCommand executes the configured cleanup command with session environment variables
func RunCleanupCommandForShell ¶
RunCleanupCommandForShell executes cleanup command through shell for complex commands
func SetAttentionFlag ¶
SetAttentionFlag sets the attention flag for a session
func TerminateEditor ¶
TerminateEditor terminates the editor process for a session
func WorktreeExists ¶
WorktreeExists checks if a worktree exists at the specified path
Types ¶
type PortAllocation ¶
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 -> hostname 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"`
LastAttached time.Time `json:"last_attached,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type SessionStore ¶
type SessionStore struct {
Sessions map[string]*Session `json:"sessions"`
NumberedSlots map[int]string `json:"numbered_slots,omitempty"`
}
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) AssignSlot ¶ added in v0.2.0
func (s *SessionStore) AssignSlot(name string) (int, error)
AssignSlot assigns a numbered slot (1-9) to a session. If the session already has a slot, returns the existing slot (stable). If a free slot exists, assigns the lowest available. If all 9 are full, evicts the session with the oldest LastAttached.
func (*SessionStore) GetSession ¶
func (s *SessionStore) GetSession(name string) (*Session, bool)
GetSession retrieves a session by name
func (*SessionStore) GetSessionForSlot ¶ added in v0.2.0
func (s *SessionStore) GetSessionForSlot(slot int) string
GetSessionForSlot returns the session name assigned to a slot, or "" if empty.
func (*SessionStore) GetSlotForSession ¶ added in v0.2.0
func (s *SessionStore) GetSlotForSession(name string) int
GetSlotForSession returns the slot number for a session, or 0 if unassigned.
func (*SessionStore) ReconcileSlots ¶ added in v0.2.0
func (s *SessionStore) ReconcileSlots()
ReconcileSlots removes slot assignments for sessions that no longer exist.
func (*SessionStore) RecordAttach ¶ added in v0.2.0
func (s *SessionStore) RecordAttach(name string) error
RecordAttach updates the LastAttached timestamp for a session
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 WorktreeInfo ¶
func ListWorktrees ¶
func ListWorktrees(repoPath string) ([]WorktreeInfo, error)
ListWorktrees returns all git worktrees in the repository