workspace

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 8 Imported by: 0 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 prepares the directory an agent works in: a git worktree on branch otag/<task> outside the repository (mode "worktree"), or the project itself ("same"). Nothing is written into the project's working tree; `git worktree add` only adds metadata under the repository's .git directory.

Index

Constants

View Source
const (
	Worktree = "worktree"
	Same     = "same"
)

Modes.

View Source
const (
	Removed = "removed"
	Gone    = "gone" // deleted before (pruned from git's list), or an empty directory left behind
	// Replaced: the path is now another linked worktree of the repository, on another
	// branch. It is not the task's any more and is left alone.
	Replaced = "replaced"
)

Outcomes of Remove.

Variables

This section is empty.

Functions

func BranchExists

func BranchExists(ctx context.Context, projectPath, branch string) bool

BranchExists reports whether the local branch exists in the repository at projectPath.

func BranchFor

func BranchFor(taskID string) string

BranchFor returns the branch of a task.

func Changes

func Changes(ctx context.Context, dir string) (string, error)

Changes returns the uncommitted changes of the work tree at dir (`git status --porcelain`; "" when clean).

func CommitsSince

func CommitsSince(ctx context.Context, dir, base string) (int, error)

CommitsSince counts commits on HEAD of dir that are not in base.

func DefaultBranch

func DefaultBranch(ctx context.Context, projectPath string) string

DefaultBranch returns the branch work is merged into: the local branch origin/HEAD names, else the branch the project checkout is on ("" when detached).

func DeleteBranch

func DeleteBranch(ctx context.Context, projectPath, branch, target string) (int, error)

DeleteBranch deletes branch if target contains all of its commits (the semantics of `git branch -d`, against target instead of the checkout's HEAD). It returns the number of unmerged commits; with any, nothing is deleted. Both commits are read once: the deletion is one ref transaction that verifies target and deletes branch only if both still point at them, so a branch or target that moved meanwhile keeps the branch. A symbolic branch ref (it would delete what it points at) and a branch checked out in a worktree (the main checkout included) are refused.

func Head(ctx context.Context, dir string) (sha string, dirty bool, err error)

Head returns the commit at HEAD of dir and whether the work tree has uncommitted changes.

func MergeBase

func MergeBase(ctx context.Context, projectPath, branch string) string

MergeBase returns the merge base of branch and the project's HEAD: the best guess of a task's base when none was recorded.

func Remove

func Remove(ctx context.Context, s RemoveSpec) (string, error)

Remove removes the worktree of a task (`git worktree remove`) and returns what it found: Removed, Gone or Replaced. Uncommitted changes are a *DirtyError unless Force, which discards them. A path that no longer exists is only pruned from git's list; an empty directory (what an interrupted removal leaves) is deleted first, as it has nothing to lose. A path outside Root, the main checkout, anything that is not a linked worktree of the repository, and a worktree with a detached HEAD are refused. The branch stays.

func Uncommitted

func Uncommitted(ctx context.Context, s RemoveSpec) (string, error)

Uncommitted returns the uncommitted changes of the task worktree s ("" when it is clean, gone or not the task's any more); errors are Remove's refusals.

func Unmerged

func Unmerged(ctx context.Context, projectPath, branch, target string) (int, error)

Unmerged counts the commits of branch that target does not contain (0 = merged).

Types

type DirtyError

type DirtyError struct {
	Path   string
	Status string // `git status --porcelain`
}

DirtyError means a worktree has uncommitted changes (tracked or untracked files).

func (*DirtyError) Error

func (e *DirtyError) Error() string

type RemoveSpec

type RemoveSpec struct {
	ProjectPath string
	Path        string // the recorded worktree path
	Branch      string // the task's branch: the worktree must still be on it
	// Root is otag's worktree root of the project (<data>/worktrees/<project>): Path,
	// with symlinks resolved, must be inside it.
	Root  string
	Force bool // discard uncommitted changes
}

RemoveSpec names the worktree of a task that is to be removed.

type Result

type Result struct {
	Mode    string `json:"mode"`
	Path    string `json:"path"`
	Branch  string `json:"branch,omitempty"`
	BaseRef string `json:"base_ref,omitempty"`
	BaseSHA string `json:"base_sha,omitempty"`
	Reused  bool   `json:"reused"` // an existing worktree of the task was reused
	// BranchExisted: the branch predates this call (reused worktree, or recreated from a
	// surviving branch); BaseSHA is then not the task's base and the caller keeps the
	// recorded one (or MergeBase).
	BranchExisted bool `json:"branch_existed"`
}

Result is a prepared workspace.

func Prepare

func Prepare(ctx context.Context, s Spec) (Result, error)

Prepare creates (or reuses) the workspace.

type Spec

type Spec struct {
	Mode        string
	ProjectPath string
	Path        string // worktree path (mode worktree)
	Branch      string // worktree branch (mode worktree)
}

Spec describes the workspace of a task.

Jump to

Keyboard shortcuts

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