workspace

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SharePurpose is the volume purpose label for the shared volume.
	SharePurpose = "share"
	// ShareStagingPath is the container mount point for the shared volume.
	ShareStagingPath = "/home/claude/.clawker-share"
)
View Source
const HostGitConfigStagingPath = "/tmp/host-gitconfig"

HostGitConfigStagingPath is where the host's gitconfig is mounted for processing by entrypoint

Variables

This section is empty.

Functions

func GetConfigVolumeMounts

func GetConfigVolumeMounts(projectName, agentName string) ([]mount.Mount, error)

GetConfigVolumeMounts returns mounts for persistent config volumes. These are used for both bind and snapshot modes to preserve Claude config.

func GetDockerSocketMount

func GetDockerSocketMount() mount.Mount

GetDockerSocketMount returns the Docker socket mount if enabled

func GetGitConfigMount

func GetGitConfigMount(log *logger.Logger) []mount.Mount

GetGitConfigMount returns a mount configuration for the host's ~/.gitconfig file. The file is mounted read-only to a staging location where the entrypoint script can process it (filtering credential.helper lines) before copying to ~/.gitconfig.

Returns nil if ~/.gitconfig doesn't exist on the host.

func GetShareVolumeMount

func GetShareVolumeMount(hostPath string) mount.Mount

GetShareVolumeMount returns the mount for the global shared volume (read-only).

func GitConfigExists

func GitConfigExists() bool

GitConfigExists checks if the host has a ~/.gitconfig file

Types

type BindStrategy

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

BindStrategy implements Strategy for direct host mount (live sync)

func NewBindStrategy

func NewBindStrategy(cfg Config, log *logger.Logger) *BindStrategy

NewBindStrategy creates a new bind mount strategy

func (*BindStrategy) Cleanup

func (s *BindStrategy) Cleanup(ctx context.Context, cli *docker.Client) error

Cleanup removes resources (no-op for bind mode)

func (*BindStrategy) GetMounts

func (s *BindStrategy) GetMounts() ([]mount.Mount, error)

GetMounts returns the Docker mount configuration. In addition to the primary bind mount, generates tmpfs overlay mounts for directories matching .clawkerignore patterns. File-level patterns (*.env, *.pem) cannot be enforced in bind mode — only directory-level masking.

func (*BindStrategy) Mode

func (s *BindStrategy) Mode() config.Mode

Mode returns the config mode

func (*BindStrategy) Name

func (s *BindStrategy) Name() string

Name returns the strategy name

func (*BindStrategy) Prepare

func (s *BindStrategy) Prepare(ctx context.Context, cli *docker.Client) error

Prepare sets up resources for bind mount (no-op for bind mode)

func (*BindStrategy) ShouldPreserve

func (s *BindStrategy) ShouldPreserve() bool

ShouldPreserve returns true - bind mounts are the source of truth

type Config

type Config struct {
	// HostPath is the path on the host to mount/copy
	HostPath string

	// RemotePath is the path inside the container
	RemotePath string

	// ProjectName is used for naming volumes
	ProjectName string

	// AgentName is used for naming agent-specific volumes
	AgentName string

	IgnorePatterns []string // Patterns to exclude (snapshot: tar filtering, bind: tmpfs overlays)
}

Config holds common configuration for workspace strategies

type ConfigVolumeResult

type ConfigVolumeResult struct {
	ConfigCreated  bool
	HistoryCreated bool
}

ConfigVolumeResult tracks which config volumes were newly created vs pre-existing.

func EnsureConfigVolumes

func EnsureConfigVolumes(ctx context.Context, cli *docker.Client, projectName, agentName string) (ConfigVolumeResult, error)

EnsureConfigVolumes creates config and history volumes with proper labels. Should be called before container creation to ensure volumes have clawker labels. This enables proper cleanup via label-based filtering in RemoveContainerWithVolumes.

type GitCredentialSetupResult

type GitCredentialSetupResult struct {
	Mounts []mount.Mount
	Env    []string
}

GitCredentialSetupResult holds the mounts and environment variables needed for git credential forwarding.

func SetupGitCredentials

func SetupGitCredentials(cfg *config.GitCredentialsConfig, hostProxyRunning bool, log *logger.Logger) GitCredentialSetupResult

SetupGitCredentials configures mounts and environment variables for git credential forwarding. It returns the mounts to add and environment variables to set based on the config and whether the host proxy is running.

SSH and GPG agent forwarding are handled by the socketbridge package (via docker exec), not by host proxy or socket mounts. Only HTTPS credentials and git config are handled here.

type SetupMountsConfig

type SetupMountsConfig struct {
	// Log is the logger instance for diagnostic file logging.
	Log *logger.Logger
	// ModeOverride is the CLI flag value (empty means use config default)
	ModeOverride string
	// Cfg is the config.Config interface for reading paths and constants.
	Cfg config.Config
	// ProjectName is the resolved project name for volume naming.
	// Resolved from project.ProjectManager at the command level.
	// Empty string when no project is registered.
	ProjectName string
	// AgentName is the agent name for volume naming
	AgentName string
	// WorkDir is the host working directory for workspace mounts.
	// If empty, falls back to os.Getwd() for backward compatibility.
	WorkDir string
	// ProjectRootDir is the main repository root when using a worktree.
	// If set, the .git directory will be mounted at the same absolute path
	// in the container to allow git worktree references to resolve.
	ProjectRootDir string
	// ContainerPath is the container-side mount destination for the workspace.
	// Set to the host absolute path for Claude Code /resume compatibility.
	// Must be set by callers (CreateContainer passes the resolved working directory).
	ContainerPath string
}

SetupMountsConfig holds configuration for workspace mount setup

type SetupMountsResult

type SetupMountsResult struct {
	// Mounts is the list of mounts to add to the container's HostConfig.
	Mounts []mount.Mount
	// ConfigVolumeResult tracks which config volumes were newly created.
	// Used by container init orchestration to decide whether to copy host config.
	ConfigVolumeResult ConfigVolumeResult
	// WorkspaceVolumeName is the name of the workspace volume created during setup.
	// Non-empty only for snapshot mode. Used for cleanup on init failure.
	WorkspaceVolumeName string
	// ContainerPath is the resolved container-side workspace mount path.
	ContainerPath string
}

SetupMountsResult holds the results from setting up workspace mounts.

func SetupMounts

func SetupMounts(ctx context.Context, client *docker.Client, cfg SetupMountsConfig) (*SetupMountsResult, error)

SetupMounts prepares workspace mounts for container creation. It handles workspace mode resolution, strategy creation/preparation, .clawkerignore pattern loading, config volumes, and docker socket mounting.

Returns a result containing the mounts and config volume creation state.

type SnapshotStrategy

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

SnapshotStrategy implements Strategy for ephemeral volume copy (isolated)

func NewSnapshotStrategy

func NewSnapshotStrategy(cfg Config, log *logger.Logger) (*SnapshotStrategy, error)

NewSnapshotStrategy creates a new snapshot strategy. Returns an error if the project or agent name is invalid for Docker resource naming.

func (*SnapshotStrategy) Cleanup

func (s *SnapshotStrategy) Cleanup(ctx context.Context, cli *docker.Client) error

Cleanup removes the snapshot volume

func (*SnapshotStrategy) GetMounts

func (s *SnapshotStrategy) GetMounts() ([]mount.Mount, error)

GetMounts returns the volume mount. Never returns an error.

func (*SnapshotStrategy) Mode

func (s *SnapshotStrategy) Mode() config.Mode

Mode returns the config mode

func (*SnapshotStrategy) Name

func (s *SnapshotStrategy) Name() string

Name returns the strategy name

func (*SnapshotStrategy) Prepare

func (s *SnapshotStrategy) Prepare(ctx context.Context, cli *docker.Client) error

Prepare creates the volume and copies files

func (*SnapshotStrategy) ShouldPreserve

func (s *SnapshotStrategy) ShouldPreserve() bool

ShouldPreserve returns false - snapshot volumes are ephemeral

func (*SnapshotStrategy) VolumeName

func (s *SnapshotStrategy) VolumeName() string

VolumeName returns the name of the snapshot volume

func (*SnapshotStrategy) WasCreated

func (s *SnapshotStrategy) WasCreated() bool

WasCreated returns true if this prepare call created the volume

type Strategy

type Strategy interface {
	// Name returns the strategy name for logging/display
	Name() string

	// Mode returns the config mode this strategy implements
	Mode() config.Mode

	// Prepare sets up any required resources (volumes, etc.)
	Prepare(ctx context.Context, cli *docker.Client) error

	// GetMounts returns the Docker mount configuration for the workspace.
	// Returns an error if mount generation requires I/O that fails (e.g. scanning
	// for ignored directories in bind mode).
	GetMounts() ([]mount.Mount, error)

	// Cleanup removes any temporary resources
	Cleanup(ctx context.Context, cli *docker.Client) error

	// ShouldPreserve returns true if resources should be preserved on down
	ShouldPreserve() bool
}

Strategy defines the interface for workspace mounting strategies

func NewStrategy

func NewStrategy(mode config.Mode, cfg Config, log *logger.Logger) (Strategy, error)

NewStrategy creates a Strategy based on the mode

Jump to

Keyboard shortcuts

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