Documentation
¶
Overview ¶
Package workspace resolves the active CogOS workspace root.
Resolution precedence:
- COG_ROOT environment variable (explicit)
- COG_WORKSPACE env var (lookup in global config)
- Local git repo detection (if inside a workspace)
- 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 ¶
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 ¶
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 ¶
ResolveWorkspace determines the workspace root based on precedence:
- COG_ROOT environment variable (explicit)
- COG_WORKSPACE env var (lookup in global config)
- Local git repo detection (if inside a workspace)
- 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.