executor

package
v0.182.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: BSD-2-Clause Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package executor runs prompt files inside Docker containers.

Index

Constants

This section is empty.

Variables

This section is empty.

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 struct {
	// ContainerName is the value passed to `--name`.
	ContainerName string
	// ContainerImage is the image reference (positional, last before Command).
	ContainerImage string
	// ProjectName is the value of the `dark-factory.project=` label.
	ProjectName string
	// ProjectRoot is the host path mounted at /workspace and the base used by
	// HideGit + ExtraMounts path resolution.
	ProjectRoot string
	// ClaudeDir is the host path mounted at /home/node/.claude (auth credentials).
	ClaudeDir string
	// Home is the host's HOME, used for ~/ expansion in NetrcFile/GitconfigFile/ExtraMounts.
	Home string
	// Env is appended as -e KEY=VALUE flags, sorted by key for stable argv shape.
	Env map[string]string
	// ExtraMounts is appended as -v <src>:<dst>[:ro] flags; missing src is skipped + logged.
	ExtraMounts []config.ExtraMount
	// NetrcFile, when non-empty, is mounted at /home/node/.netrc:ro.
	NetrcFile string
	// GitconfigFile, when non-empty, is mounted at /home/node/.gitconfig-extra:ro.
	GitconfigFile string
	// HideGit, when true, masks ProjectRoot/.git inside the container.
	HideGit bool
	// ExtraLabels is appended as additional --label KEY=VALUE flags after the project label.
	ExtraLabels map[string]string
	// CapAdd is appended as --cap-add=<value> flags.
	CapAdd []string
	// Entrypoint, when non-empty, is passed as --entrypoint <value>.
	Entrypoint string
	// Command is appended after the image (positional args to the container).
	Command []string
}

ContainerLaunchOpts carries the inputs needed to assemble a `docker run --rm ...` argv for any dark-factory container — prompt execution, spec generation, or healthcheck probes. Centralising the argv build here keeps the production launch path and the healthcheck probes on the same mount/env/hideGit/extraMounts wiring; if production stops launching containers correctly, the healthcheck probes notice immediately.

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(ctx context.Context, containerName string)
}

Executor executes a prompt.

func NewDockerExecutor added in v0.2.0

func NewDockerExecutor(
	containerImage string,
	projectName string,
	model string,
	netrcFile string,
	gitconfigFile string,
	env map[string]string,
	extraMounts []config.ExtraMount,
	claudeDir string,
	maxPromptDuration time.Duration,
	currentDateTimeGetter libtime.CurrentDateTimeGetter,
	fmtr formatter.Formatter,
	hideGit bool,
) Executor

NewDockerExecutor creates a new Executor using Docker with the specified container image.

Jump to

Keyboard shortcuts

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