Help us shape the future of Go! Take the 2026 Go Developer Survey

workspace

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDevContainer = errors.New("no devcontainer configuration found")

ErrNoDevContainer is returned when no devcontainer configuration is found walking up from the start directory.

View Source
var ErrWorkspaceNotFound = errors.New("workspace not found")

ErrWorkspaceNotFound is returned when a workspace does not exist in the store.

Functions

func Slugify

func Slugify(name string) string

Slugify converts a project directory name into a valid workspace ID. Rules: lowercase, replace non-alphanumeric with hyphens, trim hyphens, truncate to 48 chars with hash suffix if longer.

Types

type ResolveResult

type ResolveResult struct {
	// ProjectRoot is the absolute path to the project root directory.
	ProjectRoot string

	// ConfigPath is the absolute path to the devcontainer.json file.
	ConfigPath string

	// RelativeConfigPath is the config path relative to ProjectRoot.
	RelativeConfigPath string

	// WorkspaceID is the derived workspace identifier.
	WorkspaceID string
}

ResolveResult holds the outcome of workspace resolution.

func Resolve

func Resolve(startDir string) (*ResolveResult, error)

Resolve walks up from startDir looking for a .devcontainer/ directory or .devcontainer.json file. Returns the project root, config path, and derived workspace ID.

func ResolveConfigDir

func ResolveConfigDir(configDir string) (*ResolveResult, error)

ResolveConfigDir resolves workspace info when the devcontainer config directory is explicitly given (bypasses the walk-up). The config directory must contain a devcontainer.json directly. The project root is the parent of configDir.

type Result

type Result struct {
	// ContainerID is the Docker/Podman container ID.
	ContainerID string `json:"containerID"`

	// ImageName is the name of the built/pulled image.
	ImageName string `json:"imageName"`

	// MergedConfig is the devcontainer config after merging with image metadata.
	// Stored as raw JSON to avoid a dependency on the config package.
	MergedConfig json.RawMessage `json:"mergedConfig"`

	// WorkspaceFolder is the path inside the container where the project is mounted.
	WorkspaceFolder string `json:"workspaceFolder"`

	// RemoteEnv holds the resolved remoteEnv variables from devcontainer.json.
	// ${containerEnv:VAR} references are already substituted.
	// These should be injected via -e flags when running docker/podman exec.
	RemoteEnv map[string]string `json:"remoteEnv,omitempty"`

	// RemoteUser is the user to run commands as inside the container.
	// Passed as -u to docker/podman exec.
	RemoteUser string `json:"remoteUser,omitempty"`
}

Result stores the outcome of a successful `crib up` run.

type Store

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

Store manages workspace state on disk at a base directory.

func NewStore

func NewStore() (*Store, error)

NewStore creates a Store at the default location (~/.crib/workspaces). The CRIB_HOME env var overrides the base directory: $CRIB_HOME/workspaces.

func NewStoreAt

func NewStoreAt(baseDir string) *Store

NewStoreAt creates a Store with a custom base directory. Useful for testing.

func (*Store) ClearHookMarkers

func (s *Store) ClearHookMarkers(id string) error

ClearHookMarkers removes all lifecycle hook markers for a workspace, allowing hooks to run again (used on recreate).

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete removes a workspace directory from disk.

func (*Store) Exists

func (s *Store) Exists(id string) bool

Exists checks if a workspace exists on disk.

func (*Store) IsHookDone

func (s *Store) IsHookDone(id, hookName string) bool

IsHookDone checks whether a lifecycle hook has already been executed.

func (*Store) List

func (s *Store) List() ([]string, error)

List returns all known workspace IDs.

func (*Store) Load

func (s *Store) Load(id string) (*Workspace, error)

Load reads a workspace config from disk.

func (*Store) LoadResult

func (s *Store) LoadResult(id string) (*Result, error)

LoadResult reads a build result from disk. Returns nil, nil if not found.

func (*Store) MarkHookDone

func (s *Store) MarkHookDone(id, hookName string) error

MarkHookDone records that a lifecycle hook has been executed for a workspace.

func (*Store) Save

func (s *Store) Save(ws *Workspace) error

Save writes a workspace config to disk.

func (*Store) SaveResult

func (s *Store) SaveResult(id string, result *Result) error

SaveResult writes a build result to disk.

func (*Store) WorkspaceDir added in v0.4.0

func (s *Store) WorkspaceDir(id string) string

WorkspaceDir returns the on-disk directory for a workspace.

type Workspace

type Workspace struct {
	// ID is the workspace identifier, derived from the project directory name.
	ID string `json:"id"`

	// Source is the absolute path to the project root directory.
	Source string `json:"source"`

	// DevContainerPath is the relative path to the devcontainer config
	// from the project root (e.g., ".devcontainer/devcontainer.json").
	DevContainerPath string `json:"devContainerPath,omitempty"`

	// CreatedAt is when this workspace was first created.
	CreatedAt time.Time `json:"createdAt"`

	// LastUsedAt is when this workspace was last accessed.
	LastUsedAt time.Time `json:"lastUsedAt"`
}

Workspace represents a crib workspace, which maps a local project directory to a devcontainer.

Jump to

Keyboard shortcuts

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