executor

package
v0.185.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package executor runs prompt files inside Docker containers.

Index

Constants

This section is empty.

Variables

View Source
var ErrDockerDaemonUnavailable = stderrors.New("docker daemon unavailable")

ErrDockerDaemonUnavailable signals that the Docker daemon could not be reached (socket missing, daemon not running). Callers MUST NOT treat this as "container not running" — the container's actual state is unknown.

Functions

func BuildDockerRunArgs added in v0.180.0

func BuildDockerRunArgs(opts ContainerLaunchOpts) []string

BuildDockerRunArgs returns the argv for `docker run --rm` from opts. First argv element is "run"; caller invokes via `exec.CommandContext(ctx, "docker", args...)` or `subproc.Runner.RunWithWarnAndTimeout(ctx, op, "docker", args...)`.

The returned argv shape matches what dark-factory's executor produces for prompt containers, minus the prompt-file mount and the YOLO_PROMPT_FILE/YOLO_OUTPUT env vars (those are prompt-specific and not part of the shared launch surface).

Stable argv shape: env keys are sorted, mount order is deterministic. Callers can grep the argv in tests without flakiness.

Types

type ContainerChecker added in v0.65.0

type ContainerChecker interface {
	IsRunning(ctx context.Context, name string) (bool, error)
	// WaitUntilRunning blocks until the named container is in the running state,
	// the timeout elapses, or ctx is cancelled.
	WaitUntilRunning(ctx context.Context, name string, timeout time.Duration) error
}

ContainerChecker checks whether a Docker container is currently running.

func NewDockerContainerChecker added in v0.65.0

func NewDockerContainerChecker(
	currentDateTimeGetter libtime.CurrentDateTimeGetter,
) ContainerChecker

NewDockerContainerChecker creates a ContainerChecker backed by docker inspect.

type ContainerCounter added in v0.82.0

type ContainerCounter interface {
	CountRunning(ctx context.Context) (int, error)
}

ContainerCounter counts running dark-factory containers system-wide.

func NewDockerContainerCounter added in v0.82.0

func NewDockerContainerCounter(runner subproc.Runner) ContainerCounter

NewDockerContainerCounter creates a ContainerCounter that uses docker ps with label filtering.

type ContainerLaunchOpts added in v0.180.0

type ContainerLaunchOpts = launchpolicy.ContainerLaunchOpts

ContainerLaunchOpts is an alias for launchpolicy.ContainerLaunchOpts. The type definition lives in pkg/launchpolicy to avoid a circular import (executor imports launchpolicy; launchpolicy must not import executor). Callers continue using executor.ContainerLaunchOpts with no source change.

type ContainerStopper added in v0.107.0

type ContainerStopper interface {
	StopContainer(ctx context.Context, name string) error
}

ContainerStopper stops a running Docker container by name.

func NewDockerContainerStopper added in v0.107.0

func NewDockerContainerStopper() ContainerStopper

NewDockerContainerStopper creates a ContainerStopper backed by docker stop.

type Executor added in v0.2.0

type Executor interface {
	Execute(ctx context.Context, promptContent string, logFile string, containerName string) error
	// Reattach connects to a running container's output stream and waits for it to exit.
	// It does not create a new container. The log file is overwritten from the beginning
	// of the container's output (docker logs replays all output from container start).
	// maxPromptDuration is the remaining allowed run time; 0 disables the timeout.
	// Returns nil when the container exits successfully.
	Reattach(
		ctx context.Context,
		logFile string,
		containerName string,
		maxPromptDuration time.Duration,
	) error
	// StopAndRemoveContainer stops and forcibly removes the named container.
	// Best-effort: any errors are logged but not returned.
	StopAndRemoveContainer(ctx context.Context, containerName string)
}

Executor executes a prompt.

func NewDockerExecutor added in v0.2.0

func NewDockerExecutor(
	policy launchpolicy.Policy,
	model string,
	maxPromptDuration time.Duration,
	currentDateTimeGetter libtime.CurrentDateTimeGetter,
	fmtr formatter.Formatter,
) Executor

NewDockerExecutor creates a new Executor using Docker. The launch shape (image, project, mounts, base env, netrc/gitconfig, hide-git, capabilities) is sourced from the shared launchpolicy.Policy — see pkg/launchpolicy. Prompt-specific concerns (model, max duration, formatter) remain on the executor itself.

Jump to

Keyboard shortcuts

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