workspace

package
v1.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package workspace provides the core business logic for managing workspaces.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWorkspaceNotFound = errors.New("workspace not found")
	ErrWorkspaceExists   = errors.New("workspace already exists")
	ErrAmbiguousName     = errors.New("ambiguous workspace name")
)

Sentinel errors for workspace operations.

Functions

func GenerateID

func GenerateID() string

GenerateID returns a random adjective-noun workspace ID.

func GenerateUniqueID

func GenerateUniqueID(existingIDs []string) string

GenerateUniqueID returns a unique ID that doesn't collide with any existing IDs. After 10 attempts, it appends a random numeric suffix.

Types

type AmbiguousNameError

type AmbiguousNameError struct {
	Name    string
	Matches []Info
}

AmbiguousNameError is returned when a name matches multiple workspaces.

func (*AmbiguousNameError) Error

func (e *AmbiguousNameError) Error() string

func (*AmbiguousNameError) Unwrap

func (e *AmbiguousNameError) Unwrap() error

type Info

type Info struct {
	ID          string // directory name (unique identifier)
	Name        string // metadata.name (may be empty or duplicated)
	Description string
	RepoCount   int
	Created     time.Time
}

Info holds summary data for listing workspaces.

type Service

type Service struct {
	Config *config.Config
	Git    git.Runner
	Log    *slog.Logger
}

Service orchestrates workspace operations.

func (*Service) Create

func (s *Service) Create(id string, st *state.State) error

Create initializes a new workspace directory and writes the state file. id is used as the directory name; st.Metadata.Name may differ from id or be empty.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id string) error

Delete removes all worktrees and the workspace directory.

func (*Service) Find

func (s *Service) Find(id string) (*state.State, error)

Find loads a workspace state by ID (directory name).

func (*Service) List

func (s *Service) List() ([]Info, error)

List returns info for all workspaces.

func (*Service) Render

func (s *Service) Render(ctx context.Context, id string, progress func(msg string)) error

Render materializes a workspace: ensures bare clones and creates worktrees. progress is called with status messages for each repo.

func (*Service) Resolve

func (s *Service) Resolve(idOrName string) ([]Info, error)

Resolve looks up workspaces by ID or name. It first tries an exact ID match, then falls back to scanning names. Returns 0 matches as ErrWorkspaceNotFound, N>1 matches as *AmbiguousNameError.

Jump to

Keyboard shortcuts

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