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

workdir

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package workdir finds projects from paths and keeps workdirs: the main checkout of a repository, git worktrees, and plain folders.

Index

Constants

View Source
const (
	KindMain     Kind  = "main"
	KindWorktree Kind  = "worktree"
	KindFolder   Kind  = "folder"
	Active       State = "active"
	Archived     State = "archived"

	// RepoFile is the repository file with the setup and teardown scripts.
	RepoFile = ".agent-visor.json"
)

Workdir kinds and states.

Variables

View Source
var (
	ErrNotFound = errors.New("workdir: not found")
	ErrDirty    = errors.New("workdir: the worktree has changes")
	ErrHasWork  = errors.New("workdir: the project has workdirs")
)

Errors.

Functions

This section is empty.

Types

type Docs

type Docs interface {
	Put(ctx context.Context, kind, id string, data []byte) error
	Get(ctx context.Context, kind, id string) ([]byte, error)
	List(ctx context.Context, kind string) ([][]byte, error)
	Delete(ctx context.Context, kind, id string) error
}

Docs is the document store that the manager uses.

type Filter

type Filter struct {
	Project string
	Key     string
	State   State
}

Filter selects workdirs. The empty value selects all of them.

type Kind

type Kind string

Kind is the kind of a workdir.

type Manager

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

Manager owns the project and workdir rows and the worktree folders.

func New

func New(docs Docs, root string, log *slog.Logger, onScript func(Script)) *Manager

New makes a manager. root holds the worktrees that the manager makes. onScript receives the result of each script; it can be nil.

func (*Manager) Archive

func (m *Manager) Archive(ctx context.Context, id string) (Workdir, error)

Archive marks a workdir archived. It keeps the folder and the branch.

func (*Manager) Ensure

func (m *Manager) Ensure(ctx context.Context, s Spec) (Workdir, error)

Ensure gives the workdir for s. With a key, it makes the workdir once and then returns the same row.

func (*Manager) ForPath

func (m *Manager) ForPath(ctx context.Context, dir string) (Workdir, error)

ForPath gives the workdir that holds dir. It makes the project and a main or folder workdir the first time that it sees the place.

func (*Manager) ForgetProject

func (m *Manager) ForgetProject(ctx context.Context, id string) error

ForgetProject removes a project with no workdirs.

func (*Manager) Project

func (m *Manager) Project(ctx context.Context, id string) (Project, error)

Project reads one project.

func (*Manager) Projects

func (m *Manager) Projects(ctx context.Context) ([]Project, error)

Projects lists the projects. It forgets a project whose folder is gone and that has no workdirs.

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, id string, force bool) error

Remove runs the teardown script and removes the workdir. A worktree folder is deleted; force also deletes one with changes. A main or folder workdir keeps its folder.

func (*Manager) Restore

func (m *Manager) Restore(ctx context.Context, id string) (Workdir, error)

Restore makes an archived workdir active again.

func (*Manager) Workdir

func (m *Manager) Workdir(ctx context.Context, id string) (Workdir, error)

Workdir reads one workdir.

func (*Manager) Workdirs

func (m *Manager) Workdirs(ctx context.Context, f Filter) ([]Workdir, error)

Workdirs lists the workdirs that match f.

type Project

type Project struct {
	ID        string            `json:"id"`
	Name      string            `json:"name"`
	Path      string            `json:"path"`
	Git       bool              `json:"git"`
	Labels    map[string]string `json:"labels,omitempty"`
	CreatedAt time.Time         `json:"created_at"`
}

Project is a repository root or a plain folder.

type Script

type Script struct {
	Workdir string
	Name    string // setup or teardown
	Command string
	Output  []byte
	Err     error
}

Script is the result of one setup or teardown script.

type Spec

type Spec struct {
	// Path is a folder in the repository, or a plain folder.
	Path string `json:"path"`
	// Key is optional and unique in the project. A key gives the same
	// workdir on each call.
	Key    string `json:"key,omitempty"`
	Kind   Kind   `json:"kind,omitempty"`
	Branch string `json:"branch,omitempty"`
	Base   string `json:"base,omitempty"`
	// Setup and Teardown are shell commands. When both are empty, the
	// repository file .agent-visor.json gives them.
	Setup    []string          `json:"setup,omitempty"`
	Teardown []string          `json:"teardown,omitempty"`
	Labels   map[string]string `json:"labels,omitempty"`
}

Spec asks for a workdir. The empty Kind means main for a repository and folder for a plain folder.

type State

type State string

State is the state of a workdir.

type Workdir

type Workdir struct {
	ID        string            `json:"id"`
	Project   string            `json:"project"`
	Key       string            `json:"key,omitempty"`
	Kind      Kind              `json:"kind"`
	Path      string            `json:"path"`
	Branch    string            `json:"branch,omitempty"`
	Base      string            `json:"base,omitempty"`
	State     State             `json:"state"`
	PortBase  int               `json:"port_base"`
	Setup     []string          `json:"setup,omitempty"`
	Teardown  []string          `json:"teardown,omitempty"`
	Labels    map[string]string `json:"labels,omitempty"`
	CreatedAt time.Time         `json:"created_at"`
	UpdatedAt time.Time         `json:"updated_at"`
}

Workdir is one folder to work in, and for git one branch.

Jump to

Keyboard shortcuts

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