container

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInteractiveClaudeCmd added in v0.1.68

func BuildInteractiveClaudeCmd(cfg *config.Config, channelID, workDir, sessionID string, forkSession bool) string

BuildInteractiveClaudeCmd assembles the Claude CLI shell command for interactive terminal sessions (no --print, --verbose, --output-format flags).

Types

type ChannelContainerEnsurer added in v0.1.68

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

ChannelContainerEnsurer finds running containers by channel ID label, creating a new shell container if none exists.

func NewChannelContainerEnsurer added in v0.1.68

func NewChannelContainerEnsurer(client containerLister, creator shellContainerCreator) *ChannelContainerEnsurer

NewChannelContainerEnsurer creates a new ensurer.

func (*ChannelContainerEnsurer) FindContainerByChannel added in v0.1.68

func (e *ChannelContainerEnsurer) FindContainerByChannel(ctx context.Context, channelID, dirPath string) (string, error)

FindContainerByChannel returns the ID of a running container for the channel. If no container exists, a new shell container is created automatically. dirPath is the channel's work directory from the DB (may be empty).

type ClaudeCmdBuilder added in v0.1.68

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

ClaudeCmdBuilder builds the interactive Claude command for terminal sessions. It implements api.InteractiveCmdBuilder.

func NewClaudeCmdBuilder added in v0.1.68

func NewClaudeCmdBuilder(cfg *config.Config) *ClaudeCmdBuilder

NewClaudeCmdBuilder creates a builder that uses the given config.

func (*ClaudeCmdBuilder) BuildInteractiveCmd added in v0.1.68

func (b *ClaudeCmdBuilder) BuildInteractiveCmd(channelID, dirPath, sessionID string, forkSession bool) string

BuildInteractiveCmd returns the interactive Claude shell command for the given channel. It loads the project-specific config (if any) to apply per-project overrides such as claude_model before building the command.

type Client

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

Client implements DockerClient by delegating to the Docker SDK. It wraps container lifecycle operations (create/start/stop/rm/list). For exec-ing into running containers (interactive PTY sessions), see terminal.DockerExecClient instead.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new Client backed by the Docker SDK.

func (*Client) Close

func (c *Client) Close() error

Close releases the underlying Docker client resources.

func (*Client) ContainerCreate

func (c *Client) ContainerCreate(ctx context.Context, cfg *ContainerConfig, name string) (string, error)

ContainerCreate creates a new Docker container from the given config.

func (*Client) ContainerList

func (c *Client) ContainerList(ctx context.Context, labelKey, labelValue string) ([]string, error)

ContainerList returns the IDs of running containers matching the given label.

func (*Client) ContainerLogs

func (c *Client) ContainerLogs(ctx context.Context, containerID string) (io.Reader, error)

ContainerLogs retrieves the container's stdout/stderr logs after it exits. It demultiplexes the Docker stream so the caller receives clean output bytes.

func (*Client) ContainerLogsFollow added in v0.1.28

func (c *Client) ContainerLogsFollow(ctx context.Context, containerID string) (io.ReadCloser, error)

ContainerLogsFollow follows the container's stdout/stderr logs in real-time. The returned ReadCloser streams log output as it is produced. The caller must close the reader when done.

func (*Client) ContainerRemove

func (c *Client) ContainerRemove(ctx context.Context, containerID string) error

ContainerRemove forcefully removes the specified container.

func (*Client) ContainerStart

func (c *Client) ContainerStart(ctx context.Context, containerID string) error

ContainerStart starts the specified container.

func (*Client) ContainerWait

func (c *Client) ContainerWait(ctx context.Context, containerID string) (<-chan WaitResponse, <-chan error)

ContainerWait waits for the container to reach a "not-running" state and converts the Docker SDK response into our WaitResponse type.

func (*Client) CopyToContainer added in v0.1.56

func (c *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader) error

CopyToContainer copies a tar archive into the container at the given path.

func (*Client) ImageBuild

func (c *Client) ImageBuild(ctx context.Context, contextDir, tag string) error

ImageBuild builds a Docker image from the given context directory.

func (*Client) ImageList

func (c *Client) ImageList(ctx context.Context, imageName string) ([]string, error)

ImageList returns the IDs of images matching the given reference.

func (*Client) ImagePull

func (c *Client) ImagePull(ctx context.Context, imageName string) error

ImagePull pulls the specified image and drains the response.

func (*Client) RunningChannelIDs added in v0.1.68

func (c *Client) RunningChannelIDs(ctx context.Context) (map[string]struct{}, error)

RunningChannelIDs returns the set of channel IDs that have at least one running Docker container (containers labeled with the loop-channel key).

type ContainerConfig

type ContainerConfig struct {
	Image      string
	MemoryMB   int64
	CPUs       float64
	Env        []string
	Cmd        []string
	Binds      []string
	WorkingDir string
	GroupAdd   []string
	Labels     map[string]string
}

ContainerConfig holds settings for creating a container.

type DockerClient

type DockerClient interface {
	ContainerCreate(ctx context.Context, cfg *ContainerConfig, name string) (string, error)
	ContainerStart(ctx context.Context, containerID string) error
	ContainerLogs(ctx context.Context, containerID string) (io.Reader, error)
	ContainerLogsFollow(ctx context.Context, containerID string) (io.ReadCloser, error)
	ContainerWait(ctx context.Context, containerID string) (<-chan WaitResponse, <-chan error)
	ContainerRemove(ctx context.Context, containerID string) error
	ImageList(ctx context.Context, image string) ([]string, error)
	ImagePull(ctx context.Context, image string) error
	ImageBuild(ctx context.Context, contextDir, tag string) error
	ContainerList(ctx context.Context, labelKey, labelValue string) ([]string, error)
	CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader) error
	RunningChannelIDs(ctx context.Context) (map[string]struct{}, error)
}

DockerClient abstracts the Docker SDK container lifecycle methods used by DockerRunner. It handles creating, starting, stopping, and removing containers.

This is distinct from terminal.ExecClient, which handles exec-ing into already-running containers for interactive PTY sessions (docker exec).

type DockerRunner

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

DockerRunner implements Runner using Docker containers.

func NewDockerRunner

func NewDockerRunner(client DockerClient, cfg *config.Config) *DockerRunner

NewDockerRunner creates a new DockerRunner with the given Docker client and config.

func (*DockerRunner) Cleanup

func (r *DockerRunner) Cleanup(ctx context.Context) error

Cleanup removes any lingering containers with the loop-agent label.

func (*DockerRunner) CreateShellContainer added in v0.1.68

func (r *DockerRunner) CreateShellContainer(ctx context.Context, channelID, dirPath string) (string, error)

CreateShellContainer creates a long-lived shell container for terminal access. Unlike Run, the container runs "sleep infinity" instead of Claude CLI and is not auto-removed — it persists until explicitly stopped.

func (*DockerRunner) Run

Run executes an agent request in a Docker container. If a session ID is set and the run fails, it retries with --resume using only the original prompt (no full message history rebuild).

type Runner

type Runner interface {
	Run(ctx context.Context, req *agent.AgentRequest) (*agent.AgentResponse, error)
	Cleanup(ctx context.Context) error
}

Runner executes agent requests inside containers.

type ToolUse added in v0.2.0

type ToolUse struct {
	Name  string
	Input string // short summary of the input
}

ToolUse represents a tool invocation extracted from an assistant message.

type WaitResponse

type WaitResponse struct {
	StatusCode int64
	Error      error
}

WaitResponse represents the result of waiting for a container to finish.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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