workspace

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: AGPL-3.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package workspace provisions one agent's working copy: the git worktree, the ports it may bind, and the variable set every later materialisation stage interpolates against. It is relay-side (D2) — the browser cannot touch a filesystem on another box, and the relay already can.

Index

Constants

View Source
const (
	StateProvisioning  = "provisioning"
	StateMaterialising = "materialising"
	StateReady         = "ready"
	StateUnhealthy     = "unhealthy"
	StateStopped       = "stopped"
	StateDestroying    = "destroying"
)

States a workspace can be in. `unhealthy` is deliberately distinct from `ready`: a workspace whose probes failed must never read as usable.

Variables

This section is empty.

Functions

func ValidName

func ValidName(name string) error

ValidName reports whether a workspace name is safe to use as a path segment and a branch name.

Types

type Provisioner

type Provisioner struct {
	// Home is the relay's own state directory, typically ~/.menagerie.
	Home string
	// Root is where worktrees are created, typically <Home>/workspaces.
	Root string
}

Provisioner owns one relay home (where the record and the port lock live).

func New

func New(home string) *Provisioner

New returns a Provisioner rooted at the relay's home directory.

func (*Provisioner) ArmManaged

func (p *Provisioner) ArmManaged(name, hash string) error

func (*Provisioner) BeginDestroy

func (p *Provisioner) BeginDestroy(name string) error

func (*Provisioner) BeginLifecycle

func (p *Provisioner) BeginLifecycle(name, step string, retryUncertain bool) error

func (*Provisioner) CompleteDestroyHook

func (p *Provisioner) CompleteDestroyHook(name, step string) error

func (*Provisioner) CompleteLifecycle

func (p *Provisioner) CompleteLifecycle(name, step string) error

func (*Provisioner) CompleteTeardownCommand

func (p *Provisioner) CompleteTeardownCommand(name, step string, index int) error

func (*Provisioner) ConfigureManaged

func (p *Provisioner) ConfigureManaged(name, specPath, hash string) error

func (*Provisioner) DisarmManaged

func (p *Provisioner) DisarmManaged(name, reason string) error

func (*Provisioner) Load

func (p *Provisioner) Load(name string) (*Record, error)

Load returns the recorded workspace, or nil when it was never provisioned.

func (*Provisioner) Managed

func (p *Provisioner) Managed() ([]Record, error)

func (*Provisioner) MarkStarted

func (p *Provisioner) MarkStarted(name string) error

MarkStarted stamps the moment hooks.on_start first ran successfully, so it is never run twice for one workspace and never skipped for one that has not actually started.

func (*Provisioner) MarkStopped

func (p *Provisioner) MarkStopped(name string) error

func (*Provisioner) Provision

func (p *Provisioner) Provision(spec *fleet.Spec, repoRoot, name string) (*Record, error)

Provision creates (or re-adopts) the workspace called name for spec, against the repository at repoRoot. It is safe to call twice: an existing record is reused rather than duplicated, which is what makes recovery cheap (D3).

func (*Provisioner) ProvisionManaged

func (p *Provisioner) ProvisionManaged(spec *fleet.Spec, repoRoot, name, specPath, hash string) (*Record, error)

ProvisionManaged binds the reviewed spec identity in the same locked record update as ports and variables. A rejected new hash cannot partially replace the live inputs of an older managed workspace.

func (*Provisioner) RemoveVerified

func (p *Provisioner) RemoveVerified(name string, keepBranch bool) error

RemoveVerified only removes this provisioner's clean, identity-checked git worktree. A failed removal keeps the record for explicit reconciliation.

func (*Provisioner) SetRestart

func (p *Provisioner) SetRestart(name, service string, count int, next time.Time) error

func (*Provisioner) SetState

func (p *Provisioner) SetState(name, state string) error

SetState records a workspace's lifecycle state. A failed health probe leaves a workspace `unhealthy`, never `ready`.

func (*Provisioner) SetStateReason

func (p *Provisioner) SetStateReason(name, state, reason string) error

SetStateReason records a state together with why. The reason is what lets a later signal tell an unhealthy it is entitled to clear (its own supervised service came back) from one it is not (a health probe failed).

func (*Provisioner) SuspendManaged

func (p *Provisioner) SuspendManaged() error

SuspendManaged is called whenever the owning daemon starts. No uncertain service command is automatically repeated across an unclean daemon epoch.

type Record

type Record struct {
	Name   string            `json:"name"`
	Repo   string            `json:"repo"`
	Branch string            `json:"branch"`
	Path   string            `json:"path"`
	Ports  map[string]int    `json:"ports"`
	Vars   map[string]string `json:"vars"`
	State  string            `json:"state"`
	// Reason says why the workspace is in State, when State is unhealthy. It is
	// what lets supervision clear an unhealthy it caused without clearing one a
	// failed health probe caused.
	Reason string `json:"reason,omitempty"`
	// StartedAt is stamped the first time hooks.on_start ran successfully. The
	// hook is gated on this rather than on the workspace's state, because
	// supervision can promote a workspace to ready without ever starting it —
	// gating on state meant a recovered workspace skipped on_start forever.
	StartedAt       string            `json:"started_at,omitempty"`
	StoppedAt       string            `json:"stopped_at,omitempty"`
	ManagedSpec     string            `json:"managed_spec,omitempty"`
	ManagedHash     string            `json:"managed_hash,omitempty"`
	ManagedArmed    bool              `json:"managed_armed,omitempty"`
	RestartCount    map[string]int    `json:"restart_count,omitempty"`
	NextRestart     map[string]string `json:"next_restart,omitempty"`
	LifecycleIntent string            `json:"lifecycle_intent,omitempty"`
	TeardownIndex   int               `json:"teardown_index,omitempty"`
	DestroyHookDone bool              `json:"destroy_hook_done,omitempty"`
	CreatedAt       string            `json:"created_at"`
	UpdatedAt       string            `json:"updated_at"`
}

Record is one provisioned workspace.

Jump to

Keyboard shortcuts

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