workspace

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRegistered

func IsRegistered(name string) bool

IsRegistered checks if a preparer with the given name is registered.

func List

func List() []string

List returns all registered preparer names.

func MkdirTempOutsideWorkspace

func MkdirTempOutsideWorkspace(workspace, pattern string) (string, error)

MkdirTempOutsideWorkspace creates a temporary directory outside of the given path This is important to ensure the snapshot directory can be cleaned up independently

func Register

func Register(preparer Preparer) error

Register registers a preparer with a given name. If a preparer with the same name is already registered, it returns an error.

func Unregister

func Unregister(name string) error

Unregister removes a preparer from the registry.

func WriteManifest

func WriteManifest(dest string, result PrepareResult) error

WriteManifest writes a workspace.manifest.json file to the specified directory Note: This function is kept for backward compatibility and testing purposes. The runtime now writes the manifest to the output directory instead of the workspace.

Types

type ExistingPreparer

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

ExistingPreparer uses an existing directory as the workspace without modification This is useful when the user wants to use an existing checkout

func NewExistingPreparer

func NewExistingPreparer() *ExistingPreparer

NewExistingPreparer creates a new existing preparer

func (*ExistingPreparer) Cleanup

func (p *ExistingPreparer) Cleanup(dest string) error

Cleanup for existing strategy is a no-op (we don't own the directory)

func (*ExistingPreparer) Name

func (p *ExistingPreparer) Name() string

Name returns the strategy name

func (*ExistingPreparer) Prepare

Prepare uses an existing directory as the workspace. This validates that dest contains a usable git repository or directory tree, and typically does not modify content. If a Ref is explicitly requested, a git checkout will be performed which modifies the working directory content. The Source parameter is used for metadata and origin tracking. This strategy is useful for using already-prepared workspaces (e.g., GitHub Actions checkout). Note: The workspace manifest is written to the output directory by the runtime, not here.

func (*ExistingPreparer) Validate

func (p *ExistingPreparer) Validate(req PrepareRequest) error

Validate checks if the request is valid for this preparer

type GitClonePreparer

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

GitClonePreparer prepares a workspace using git clone This creates a self-contained git repository that works inside containers without host-path references or alternates

func NewGitClonePreparer

func NewGitClonePreparer() *GitClonePreparer

NewGitClonePreparer creates a new git-clone preparer

func (*GitClonePreparer) Cleanup

func (p *GitClonePreparer) Cleanup(dest string) error

Cleanup removes the workspace directory

func (*GitClonePreparer) Name

func (p *GitClonePreparer) Name() string

Name returns the strategy name

func (*GitClonePreparer) Prepare

Prepare creates a workspace using git clone

func (*GitClonePreparer) Validate

func (p *GitClonePreparer) Validate(req PrepareRequest) error

Validate checks if the request is valid for this preparer

type HistoryMode

type HistoryMode string

HistoryMode defines how much git history to include in the workspace

const (
	// HistoryFull includes complete git history
	HistoryFull HistoryMode = "full"
	// HistoryShallow creates a shallow clone with reduced history
	HistoryShallow HistoryMode = "shallow"
	// HistoryNone creates a workspace without git history (e.g., copy only)
	HistoryNone HistoryMode = "none"
)

type Manifest

type Manifest struct {
	// Strategy is the name of the strategy used
	Strategy string `json:"strategy"`

	// Source is the origin of the workspace content
	Source string `json:"source"`

	// Ref is the git reference that was checked out
	Ref string `json:"ref,omitempty"`

	// HeadSHA is the commit SHA of the workspace
	HeadSHA string `json:"head_sha,omitempty"`

	// CreatedAt is the timestamp when the workspace was prepared
	CreatedAt time.Time `json:"created_at"`

	// HasHistory indicates whether git history is available
	HasHistory bool `json:"has_history"`

	// IsShallow indicates whether the git repository is shallow
	IsShallow bool `json:"is_shallow"`

	// Notes contains any additional information
	Notes []string `json:"notes,omitempty"`
}

Manifest contains workspace metadata The manifest is written to the output directory (not the workspace) by the runtime

func ReadManifest

func ReadManifest(dest string) (*Manifest, error)

ReadManifest reads a workspace.manifest.json file from the specified directory

type PrepareRequest

type PrepareRequest struct {
	// Source is the origin of the workspace content
	// Examples: local path "/path/to/repo", remote URL "https://github.com/owner/repo.git"
	Source string

	// Ref is the git reference to checkout (branch, tag, or SHA)
	// Examples: "main", "v1.0.0", "abc123def", "" (HEAD)
	Ref string

	// Dest is the host directory where the workspace will be created
	// This directory will be mounted into the container at /holon/workspace
	Dest string

	// History specifies how much git history to include
	History HistoryMode

	// Submodules specifies how to handle git submodules
	Submodules SubmoduleMode

	// CleanDest indicates whether to clean the destination directory before preparation
	// If true, any existing content at Dest will be removed
	CleanDest bool
}

PrepareRequest contains the parameters for a workspace preparation operation

type PrepareResult

type PrepareResult struct {
	// Strategy is the name of the strategy that handled this request
	Strategy string `json:"strategy"`

	// Source is the origin that was used
	Source string `json:"source"`

	// Ref is the git reference that was checked out
	Ref string `json:"ref"`

	// HeadSHA is the commit SHA of the workspace after preparation
	HeadSHA string `json:"head_sha"`

	// CreatedAt is the timestamp when preparation completed
	CreatedAt time.Time `json:"created_at"`

	// HasHistory indicates whether git history is available
	HasHistory bool `json:"has_history"`

	// IsShallow indicates whether the git repository is shallow
	IsShallow bool `json:"is_shallow"`

	// Notes contains any additional information about the preparation
	Notes []string `json:"notes,omitempty"`
}

PrepareResult contains the outcome of a workspace preparation operation

func NewPrepareResult

func NewPrepareResult(strategy string) PrepareResult

NewPrepareResult creates a PrepareResult with the current timestamp

type Preparer

type Preparer interface {
	// Prepare creates a workspace directory at Dest with the requested content
	Prepare(ctx context.Context, req PrepareRequest) (PrepareResult, error)

	// Name returns the strategy name (e.g., "git-clone", "snapshot", "existing")
	Name() string

	// Validate checks if the request is valid for this preparer
	// Returns nil if valid, or an error describing what's invalid
	Validate(req PrepareRequest) error

	// Cleanup performs any necessary cleanup after workspace use
	// For most strategies, this is a simple directory removal
	// Returns an error if cleanup fails
	Cleanup(dest string) error
}

Preparer is the interface for preparing workspaces

func Get

func Get(name string) Preparer

Get retrieves a preparer by name. Returns nil if the preparer is not found.

type SnapshotPreparer

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

SnapshotPreparer prepares a workspace by copying files without git history This is useful for cases where history is not needed or when the source is not a git repo

func NewSnapshotPreparer

func NewSnapshotPreparer() *SnapshotPreparer

NewSnapshotPreparer creates a new snapshot preparer

func (*SnapshotPreparer) Cleanup

func (p *SnapshotPreparer) Cleanup(dest string) error

Cleanup removes the workspace directory

func (*SnapshotPreparer) Name

func (p *SnapshotPreparer) Name() string

Name returns the strategy name

func (*SnapshotPreparer) Prepare

Prepare creates a workspace by copying files

func (*SnapshotPreparer) Validate

func (p *SnapshotPreparer) Validate(req PrepareRequest) error

Validate checks if the request is valid for this preparer

type SubmoduleMode

type SubmoduleMode string

SubmoduleMode defines how to handle git submodules

const (
	// SubmodulesNone does not initialize any submodules
	SubmodulesNone SubmoduleMode = "none"
	// SubmodulesRecursive initializes submodules recursively
	SubmodulesRecursive SubmoduleMode = "recursive"
)

Jump to

Keyboard shortcuts

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