workspace

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package workspace provides workspace configuration management.

Package workspace provides workspace configuration management.

Package workspace provides workspace management including git tracking.

Package workspace provides workspace configuration management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigManager

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

ConfigManager handles workspace configuration CRUD operations. This is the simplified version that only manages configs, not processes.

func NewConfigManager

func NewConfigManager(cfg *config.WorkspacesConfig, configPath string, appCfg ...*config.Config) *ConfigManager

NewConfigManager creates a new workspace config manager. appCfg is optional — when non-nil, discovery settings from config.yaml are applied.

func (*ConfigManager) AddWorkspace

func (m *ConfigManager) AddWorkspace(name, path string, autoStart bool) (*Workspace, error)

AddWorkspace adds a new workspace configuration. This is a convenience wrapper around AddWorkspaceWithOptions with createIfMissing=false.

func (*ConfigManager) AddWorkspaceWithOptions

func (m *ConfigManager) AddWorkspaceWithOptions(name, path string, autoStart bool, createIfMissing bool) (*Workspace, error)

AddWorkspaceWithOptions adds a new workspace configuration with additional options. If createIfMissing is true and the path doesn't exist, it will be created. This supports the iOS app flow where users can create new project folders.

func (*ConfigManager) DiscoverRepositories

func (m *ConfigManager) DiscoverRepositories(searchPaths []string) ([]DiscoveredRepo, error)

DiscoverRepositories scans directories for git repositories using the enterprise discovery engine. Returns cached results immediately if available, with background refresh for stale cache.

func (*ConfigManager) DiscoverRepositoriesFresh

func (m *ConfigManager) DiscoverRepositoriesFresh(searchPaths []string) (*DiscoveryResult, error)

DiscoverRepositoriesFresh forces a fresh scan, ignoring cache.

func (*ConfigManager) DiscoverRepositoriesWithResult

func (m *ConfigManager) DiscoverRepositoriesWithResult(searchPaths []string) (*DiscoveryResult, error)

DiscoverRepositoriesWithResult returns the full discovery result including cache metadata.

func (*ConfigManager) GetAllWorkspaceIDs

func (m *ConfigManager) GetAllWorkspaceIDs() []string

GetAllWorkspaceIDs returns all workspace IDs.

func (*ConfigManager) GetGitTrackerManager

func (m *ConfigManager) GetGitTrackerManager() *GitTrackerManager

GetGitTrackerManager returns the git tracker manager.

func (*ConfigManager) GetWorkspace

func (m *ConfigManager) GetWorkspace(id string) (*Workspace, error)

GetWorkspace returns a workspace by ID.

func (*ConfigManager) InvalidateDiscoveryCache

func (m *ConfigManager) InvalidateDiscoveryCache() error

InvalidateDiscoveryCache clears the discovery cache.

func (*ConfigManager) ListWorkspaces

func (m *ConfigManager) ListWorkspaces() []*Workspace

ListWorkspaces returns all configured workspaces.

func (*ConfigManager) RemoveWorkspace

func (m *ConfigManager) RemoveWorkspace(id string) error

RemoveWorkspace removes a workspace configuration.

func (*ConfigManager) SetGitTrackerManager

func (m *ConfigManager) SetGitTrackerManager(gtm *GitTrackerManager)

SetGitTrackerManager sets the git tracker manager and registers all existing workspaces.

func (*ConfigManager) UpdateWorkspace

func (m *ConfigManager) UpdateWorkspace(ws *Workspace) error

UpdateWorkspace updates a workspace configuration.

type DiscoveredRepo

type DiscoveredRepo struct {
	Path         string    `json:"path"`
	Name         string    `json:"name"`
	RemoteURL    string    `json:"remote_url,omitempty"`
	LastModified time.Time `json:"last_modified"`
	IsConfigured bool      `json:"is_configured"` // Already added as workspace
}

DiscoveredRepo represents a discovered Git repository

func GetRepoInfo

func GetRepoInfo(repoPath string) DiscoveredRepo

GetRepoInfo is the exported version for external use

type DiscoveryCache

type DiscoveryCache struct {
	Repositories []DiscoveredRepo `json:"repositories"`
	SearchPaths  []string         `json:"search_paths"`
	Timestamp    time.Time        `json:"timestamp"`
	Version      int              `json:"version"`
}

DiscoveryCache represents the cached discovery results.

type DiscoveryConfig

type DiscoveryConfig struct {
	// MaxDepth limits how deep to scan (0 = unlimited, recommended: 4)
	MaxDepth int
	// Timeout for the entire discovery operation
	Timeout time.Duration
	// Workers is the number of parallel workers (0 = NumCPU)
	Workers int
	// CacheTTL is how long cached results are valid
	CacheTTL time.Duration
	// CachePath is where to store the cache file
	CachePath string
	// UserSearchPaths are additional paths from config.yaml (scanned before defaults)
	UserSearchPaths []string
}

DiscoveryConfig holds configuration for repository discovery.

func DefaultDiscoveryConfig

func DefaultDiscoveryConfig() DiscoveryConfig

DefaultDiscoveryConfig returns sensible defaults.

type DiscoveryResult

type DiscoveryResult struct {
	Repositories      []DiscoveredRepo `json:"repositories"`
	Count             int              `json:"count"`
	Cached            bool             `json:"cached"`
	CacheAgeSeconds   int64            `json:"cache_age_seconds,omitempty"`
	RefreshInProgress bool             `json:"refresh_in_progress,omitempty"`
	ElapsedMs         int64            `json:"elapsed_ms"`
	ScannedPaths      int              `json:"scanned_paths"`
	SkippedPaths      int              `json:"skipped_paths"`
}

DiscoveryResult contains the results of a discovery operation.

type GitTrackerManager

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

GitTrackerManager manages git trackers for all workspaces. It provides: - Lazy initialization of trackers (on first use) - Caching of trackers by workspace ID - Thread-safe access with RWMutex - Health monitoring and auto-recovery - Graceful degradation for non-git repos

func NewGitTrackerManager

func NewGitTrackerManager(cfg GitTrackerManagerConfig) *GitTrackerManager

NewGitTrackerManager creates a new git tracker manager.

func (*GitTrackerManager) GetAllTrackerInfo

func (m *GitTrackerManager) GetAllTrackerInfo() []TrackerInfo

GetAllTrackerInfo returns information about all registered trackers.

func (*GitTrackerManager) GetTracker

func (m *GitTrackerManager) GetTracker(workspaceID string) (*git.Tracker, error)

GetTracker returns a git tracker for a workspace. Initializes the tracker lazily on first call. Returns nil tracker and no error for non-git repos (graceful degradation).

func (*GitTrackerManager) GetTrackerInfo

func (m *GitTrackerManager) GetTrackerInfo(workspaceID string) (*TrackerInfo, error)

GetTrackerInfo returns information about a workspace's git tracker.

func (*GitTrackerManager) RefreshTracker

func (m *GitTrackerManager) RefreshTracker(workspaceID string) error

RefreshTracker re-initializes a tracker, useful after repo changes.

func (*GitTrackerManager) RegisterWorkspace

func (m *GitTrackerManager) RegisterWorkspace(ws *config.WorkspaceDefinition) error

RegisterWorkspace registers a workspace for git tracking. This validates the path and prepares for lazy tracker initialization. Returns error if path is invalid, but allows non-git repos.

func (*GitTrackerManager) Stats

func (m *GitTrackerManager) Stats() map[string]interface{}

Stats returns statistics about the tracker manager.

func (*GitTrackerManager) Stop

func (m *GitTrackerManager) Stop()

Stop stops the git tracker manager and cleans up resources.

func (*GitTrackerManager) UnregisterWorkspace

func (m *GitTrackerManager) UnregisterWorkspace(workspaceID string)

UnregisterWorkspace removes a workspace from git tracking.

type GitTrackerManagerConfig

type GitTrackerManagerConfig struct {
	GitCommand          string
	HealthCheckInterval time.Duration
	OperationTimeout    time.Duration
	Logger              *slog.Logger
}

GitTrackerManagerConfig holds configuration for GitTrackerManager.

func DefaultGitTrackerManagerConfig

func DefaultGitTrackerManagerConfig() GitTrackerManagerConfig

DefaultGitTrackerManagerConfig returns default configuration.

type ImageStoragePathResolver

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

ImageStoragePathResolver adapts ConfigManager to implement imagestorage.WorkspacePathResolver.

func NewImageStoragePathResolver

func NewImageStoragePathResolver(cm *ConfigManager) *ImageStoragePathResolver

NewImageStoragePathResolver creates a new resolver that uses the ConfigManager.

func (*ImageStoragePathResolver) GetWorkspacePath

func (r *ImageStoragePathResolver) GetWorkspacePath(workspaceID string) (string, error)

GetWorkspacePath returns the absolute path for a workspace ID.

type RepoDiscovery

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

RepoDiscovery handles repository discovery with caching and parallel scanning.

func NewRepoDiscovery

func NewRepoDiscovery(cfg DiscoveryConfig) *RepoDiscovery

NewRepoDiscovery creates a new repository discovery engine.

func (*RepoDiscovery) Discover

func (d *RepoDiscovery) Discover(ctx context.Context, searchPaths []string) (*DiscoveryResult, error)

Discover finds git repositories using cache-first strategy. Returns cached results immediately if available, triggers background refresh if stale.

func (*RepoDiscovery) DiscoverFresh

func (d *RepoDiscovery) DiscoverFresh(ctx context.Context, searchPaths []string) (*DiscoveryResult, error)

DiscoverFresh forces a fresh scan, ignoring cache.

func (*RepoDiscovery) DiscoverStreaming

func (d *RepoDiscovery) DiscoverStreaming(ctx context.Context, searchPaths []string, results chan<- DiscoveredRepo) error

DiscoverStreaming discovers repositories and sends them to a channel as found. This is useful for progressive UI updates.

func (*RepoDiscovery) InvalidateCache

func (d *RepoDiscovery) InvalidateCache() error

InvalidateCache clears the discovery cache.

func (*RepoDiscovery) SetConfiguredPaths

func (d *RepoDiscovery) SetConfiguredPaths(paths map[string]bool)

SetConfiguredPaths updates the list of already-configured workspace paths.

type TrackerInfo

type TrackerInfo struct {
	WorkspaceID string       `json:"workspace_id"`
	Path        string       `json:"path"`
	State       TrackerState `json:"state"`
	IsGitRepo   bool         `json:"is_git_repo"`
	RepoName    string       `json:"repo_name,omitempty"`
	LastChecked time.Time    `json:"last_checked"`
	LastError   string       `json:"last_error,omitempty"`
}

TrackerInfo contains information about a cached git tracker.

type TrackerState

type TrackerState string

TrackerState represents the health state of a git tracker.

const (
	TrackerStateHealthy     TrackerState = "healthy"
	TrackerStateUnhealthy   TrackerState = "unhealthy"
	TrackerStateUnavailable TrackerState = "unavailable"
	TrackerStateNotGit      TrackerState = "not_git"
)

type Workspace

type Workspace struct {
	// Configuration from workspaces.yaml
	Definition config.WorkspaceDefinition

	// Runtime state
	Status       WorkspaceStatus
	PID          int
	ProcessCmd   *exec.Cmd
	LastActive   time.Time
	ErrorMessage string
	RestartCount int
	// contains filtered or unexported fields
}

Workspace represents a running or configured workspace instance

func NewWorkspace

func NewWorkspace(def config.WorkspaceDefinition) *Workspace

NewWorkspace creates a new workspace instance from a definition

func (*Workspace) GetIdleTime

func (w *Workspace) GetIdleTime() time.Duration

GetIdleTime returns how long the workspace has been idle

func (*Workspace) GetPID

func (w *Workspace) GetPID() int

GetPID returns the process ID

func (*Workspace) GetRestartCount

func (w *Workspace) GetRestartCount() int

GetRestartCount returns the current restart count

func (*Workspace) GetStatus

func (w *Workspace) GetStatus() WorkspaceStatus

GetStatus returns the current status

func (*Workspace) IncrementRestartCount

func (w *Workspace) IncrementRestartCount() int

IncrementRestartCount increments and returns the restart counter

func (*Workspace) IsRunning

func (w *Workspace) IsRunning() bool

IsRunning returns true if the workspace is currently running

func (*Workspace) IsStopped

func (w *Workspace) IsStopped() bool

IsStopped returns true if the workspace is stopped

func (*Workspace) ResetRestartCount

func (w *Workspace) ResetRestartCount()

ResetRestartCount resets the restart counter to 0

func (*Workspace) SetError

func (w *Workspace) SetError(message string)

SetError sets the workspace to error state with a message

func (*Workspace) SetPID

func (w *Workspace) SetPID(pid int)

SetPID sets the process ID

func (*Workspace) SetStatus

func (w *Workspace) SetStatus(status WorkspaceStatus)

SetStatus updates the workspace status

func (*Workspace) ToInfo

func (w *Workspace) ToInfo() WorkspaceInfo

ToInfo converts a Workspace to WorkspaceInfo for API responses

func (*Workspace) UpdateLastActive

func (w *Workspace) UpdateLastActive()

UpdateLastActive updates the last active timestamp

type WorkspaceInfo

type WorkspaceInfo struct {
	ID           string          `json:"id"`
	Name         string          `json:"name"`
	Path         string          `json:"path"`
	Port         int             `json:"port"`
	Status       WorkspaceStatus `json:"status"`
	AutoStart    bool            `json:"auto_start"`
	PID          int             `json:"pid,omitempty"`
	ErrorMessage string          `json:"error_message,omitempty"`
	RestartCount int             `json:"restart_count"`
	LastActive   time.Time       `json:"last_active"`
	CreatedAt    time.Time       `json:"created_at"`
	LastAccessed time.Time       `json:"last_accessed"`
}

WorkspaceInfo contains information about a workspace for API responses

type WorkspaceStatus

type WorkspaceStatus string

WorkspaceStatus represents the current state of a workspace

const (
	StatusStopped  WorkspaceStatus = "stopped"
	StatusStarting WorkspaceStatus = "starting"
	StatusRunning  WorkspaceStatus = "running"
	StatusStopping WorkspaceStatus = "stopping"
	StatusError    WorkspaceStatus = "error"
)

Jump to

Keyboard shortcuts

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