workspace

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package workspace resolves the active CogOS workspace root.

Resolution precedence:

  1. COG_ROOT environment variable (explicit)
  2. COG_WORKSPACE env var (lookup in global config)
  3. Local git repo detection (if inside a workspace)
  4. current-workspace from ~/.cog/config

This package is dependency-injected: the main package wires global-config loading and git-root detection at init time. This avoids pulling the full config/git machinery into this package while still allowing providers to import it cleanly.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LoadConfig loads the global config (~/.cog/config).
	LoadConfig func() (ConfigProvider, error)
	// GitRoot returns the path of the enclosing git repository.
	GitRoot func() (string, error)
)

Dependency injection points. The main package must set these in an init() hook before ResolveWorkspace is called. If either is nil, the corresponding resolution tier is skipped gracefully.

Functions

func IsRealWorkspace

func IsRealWorkspace(dir string) bool

IsRealWorkspace checks if dir has a .cog/ directory that looks like a real CogOS workspace (has config/ or mem/), not just a bare .cog/ with .state/ only (which submodules sometimes have).

func ResolveWorkspace

func ResolveWorkspace() (string, string, error)

ResolveWorkspace determines the workspace root based on precedence:

  1. COG_ROOT environment variable (explicit)
  2. COG_WORKSPACE env var (lookup in global config)
  3. Local git repo detection (if inside a workspace)
  4. current-workspace from ~/.cog/config

Returns (workspaceRoot, source, error) where source describes how it was resolved.

Results are cached for the lifetime of the process since resolution is deterministic within a single invocation.

Types

type ConfigProvider

type ConfigProvider interface {
	// CurrentWorkspace returns the name of the globally-selected workspace,
	// or "" if none is set.
	CurrentWorkspace() string
	// WorkspacePath returns the filesystem path for the workspace with the
	// given name, and a bool indicating whether it exists in the config.
	WorkspacePath(name string) (string, bool)
}

ConfigProvider is the minimal view of the global config that ResolveWorkspace needs. The main package adapts its *GlobalConfig to this interface in an init() hook.

Jump to

Keyboard shortcuts

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