shared

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package shared provides domain logic shared between container run and create commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitContainerConfig

func InitContainerConfig(ctx context.Context, opts InitConfigOpts) error

InitContainerConfig handles one-time claude config initialization for new containers. Called after EnsureConfigVolumes when the config volume was freshly created.

Steps:

  1. If strategy=="copy": prepare host claude config, copy to volume
  2. If use_host_auth: prepare credentials, copy to volume

func InjectOnboardingFile

func InjectOnboardingFile(ctx context.Context, opts InjectOnboardingOpts) error

InjectOnboardingFile writes ~/.claude.json to a created (not started) container. Must be called after ContainerCreate and before ContainerStart. The file marks Claude Code onboarding as complete so the user is not prompted.

func InjectPostInitScript

func InjectPostInitScript(ctx context.Context, opts InjectPostInitOpts) error

InjectPostInitScript writes ~/.clawker/post-init.sh to a created (not started) container. Must be called after ContainerCreate and before ContainerStart. The entrypoint is responsible for running this script once on first start and creating a ~/.claude/post-initialized marker to prevent re-runs on restart.

func RebuildMissingDefaultImage

func RebuildMissingDefaultImage(ctx context.Context, opts RebuildMissingImageOpts) error

RebuildMissingDefaultImage prompts the user to rebuild a missing default image. In non-interactive mode, prints instructions and returns an error. In interactive mode, prompts for flavor selection and rebuilds with TUI progress.

Types

type ContainerInitializer

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

ContainerInitializer is the Factory noun for container initialization. Constructed from Factory, captures eager + lazy deps. Run() performs the progress-tracked initialization with runtime values.

func NewContainerInitializer

func NewContainerInitializer(f *cmdutil.Factory) *ContainerInitializer

NewContainerInitializer creates a ContainerInitializer from the Factory.

func (*ContainerInitializer) Run

Run performs container initialization with TUI progress display. It expects image resolution to have already been completed (pre-progress phase).

type CopyToContainerFn

type CopyToContainerFn func(ctx context.Context, containerID, destPath string, content io.Reader) error

CopyToContainerFn is the signature for copying a tar archive to a container. Wraps the lower-level Docker CopyToContainer API into a simpler interface.

func NewCopyToContainerFn

func NewCopyToContainerFn(client *docker.Client) CopyToContainerFn

TODO: This is implemented wrong. constructors need to be added to accept factory *cmdutil.Factory, we don't pass indivdual deps) NewCopyToContainerFn creates a CopyToContainerFn that delegates to the docker client. This is the standard production wiring — use directly instead of writing an inline closure.

type CopyToVolumeFn

type CopyToVolumeFn func(ctx context.Context, volumeName, srcDir, destPath string, ignorePatterns []string) error

CopyToVolumeFn is the signature for copying a directory to a Docker volume. Matches *docker.Client.CopyToVolume.

type InitConfigOpts

type InitConfigOpts struct {
	// ProjectName is the project name for volume naming.
	ProjectName string
	// AgentName is the agent name for volume naming.
	AgentName string
	// ContainerWorkDir is the workspace directory inside the container (e.g. "/workspace").
	// Used to rewrite projectPath values in installed_plugins.json.
	ContainerWorkDir string
	// ClaudeCode is the claude code configuration. Nil uses defaults (copy strategy + host auth).
	ClaudeCode *config.ClaudeCodeConfig
	// CopyToVolume copies a directory to a Docker volume.
	// In production, wire this to (*docker.Client).CopyToVolume.
	CopyToVolume CopyToVolumeFn
}

InitConfigOpts holds options for container init orchestration.

type InitParams

type InitParams struct {
	Client           *docker.Client
	Config           *config.Project
	ContainerOptions *copts.ContainerOptions
	Flags            *pflag.FlagSet
	Image            string // resolved image reference
	StartAfterCreate bool   // true for detached run (adds "Start container" step)
	AltScreen        bool   // use alternate screen for progress (clears display for clean TTY handoff)
}

InitParams holds runtime values resolved during the pre-progress phase.

type InitResult

type InitResult struct {
	ContainerID      string
	AgentName        string
	ContainerName    string
	HostProxyRunning bool
	Warnings         []string // deferred warnings (can't print during progress)
}

InitResult holds outputs needed by the post-progress phase.

type InjectOnboardingOpts

type InjectOnboardingOpts struct {
	// ContainerID is the Docker container ID to inject the file into.
	ContainerID string
	// CopyToContainer copies a tar archive to the container at the given destination path.
	// In production, wire this to a function that calls (*docker.Client).CopyToContainer.
	CopyToContainer CopyToContainerFn
}

InjectOnboardingOpts holds options for onboarding file injection.

type InjectPostInitOpts

type InjectPostInitOpts struct {
	// ContainerID is the Docker container ID to inject the script into.
	ContainerID string
	// Script is the user's post_init content from clawker.yaml.
	Script string
	// CopyToContainer copies a tar archive to the container at the given destination path.
	// In production, wire this to a function that calls (*docker.Client).CopyToContainer.
	CopyToContainer CopyToContainerFn
}

InjectPostInitOpts holds options for post-init script injection.

type RebuildMissingImageOpts

type RebuildMissingImageOpts struct {
	ImageRef       string
	IOStreams      *iostreams.IOStreams
	TUI            *tui.TUI
	Prompter       func() *prompter.Prompter
	SettingsLoader func() config.SettingsLoader
	BuildImage     docker.BuildDefaultImageFn
	CommandVerb    string // "run" or "create" for error messages
}

RebuildMissingImageOpts holds options for the rebuild prompt flow.

Jump to

Keyboard shortcuts

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