Documentation
¶
Overview ¶
Package workdir finds projects from paths and keeps workdirs: the main checkout of a repository, git worktrees, and plain folders.
Index ¶
- Constants
- Variables
- type Docs
- type Filter
- type Kind
- type Manager
- func (m *Manager) Archive(ctx context.Context, id string) (Workdir, error)
- func (m *Manager) Ensure(ctx context.Context, s Spec) (Workdir, error)
- func (m *Manager) ForPath(ctx context.Context, dir string) (Workdir, error)
- func (m *Manager) ForgetProject(ctx context.Context, id string) error
- func (m *Manager) Project(ctx context.Context, id string) (Project, error)
- func (m *Manager) Projects(ctx context.Context) ([]Project, error)
- func (m *Manager) Remove(ctx context.Context, id string, force bool) error
- func (m *Manager) Restore(ctx context.Context, id string) (Workdir, error)
- func (m *Manager) Workdir(ctx context.Context, id string) (Workdir, error)
- func (m *Manager) Workdirs(ctx context.Context, f Filter) ([]Workdir, error)
- type Project
- type Script
- type Spec
- type State
- type Workdir
Constants ¶
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 ¶
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 Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the project and workdir rows and the worktree folders.
func New ¶
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) Ensure ¶
Ensure gives the workdir for s. With a key, it makes the workdir once and then returns the same row.
func (*Manager) ForPath ¶
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 ¶
ForgetProject removes a project with no workdirs.
func (*Manager) Projects ¶
Projects lists the projects. It forgets a project whose folder is gone and that has no workdirs.
func (*Manager) Remove ¶
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.
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 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.