executor

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 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 defines the worker abstraction (§48–§50). The deterministic `internal` executor is the first implementation; OMP is validated behind this same interface as `local_external`.

Package executor defines the worker abstraction (§48–§50). The deterministic `internal` executor is the first implementation; OMP is validated behind this same interface as `local_external`.

Package executor defines the worker abstraction (§48–§50). The deterministic `internal` executor is the first implementation; OMP is validated behind this same interface as `local_external`.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownAttempt = errors.New("executor: unknown attempt")

ErrUnknownAttempt is returned for an attempt this executor does not track -- including one already removed, which is how a caller knows its container is gone.

Functions

func DefaultAgentImage

func DefaultAgentImage(kind string) string

DefaultAgentImage returns the pinned default container image for a coding agent, or "" when no canonical image exists (the caller should then require an explicit --image). Hermes has an official image; OMP does not.

func PullImage

func PullImage(ctx context.Context, image string) (string, error)

PullImage ensures image is present locally (docker pull only if absent) and returns its image ID so the caller can surface exactly what was downloaded.

func SmokeAgent

func SmokeAgent(ctx context.Context, kind, image, model string, provider AgentProvider, lookupKey func(string) string, workDir string) error

SmokeAgent runs a trivial coding task through the agent in an isolated container and asserts it produced at least one file in the work root. It verifies the full CLI contract end-to-end (the exact agent invocation), not just that the binary exists. It requires the provider API key for model to be present in the environment (the agent needs it to call its model).

provider is resolved by the caller from the project's provider view, so the smoke calls the endpoint the real executor will -- including a custom provider or an Ollama moved to another port -- rather than a preset's.

lookupKey reads the provider key; the CLI passes one that falls back to the project's .env, as the daemon does, so a key `idea execute` would accept is not refused here.

workDir is where the smoke's work root is made. The daemon passes a directory under its state root: the system temp directory is not visible to Docker under snap-installed Docker or Colima, and a smoke there reported "produced no files" for a setup that worked. "" uses the temp directory, which is right for the CLI.

func SweepAgentLeftovers added in v0.5.0

func SweepAgentLeftovers(ctx context.Context, stateRoot string)

SweepAgentLeftovers removes the agent containers and agent homes that a previous daemon left behind anywhere under stateRoot. Collect and Cancel remove them in the normal course, and a daemon that is stopped cancels its runs first; this covers one that was killed or crashed mid-run, which used to leave the container, and the provider key in its config, on disk with nothing that would ever find it.

Call it before this daemon starts any operation, so no attempt of its own can be running. It finds leftovers by their agent-home directories, and then by container label as a backstop for one whose directory is gone.

func TrustAllows

func TrustAllows(trust domain.ExecutorTrust, action string) bool

TrustAllows reports whether an action is permitted for an executor's engine-assigned trust tier. It is the policy gate used before any execution, independent of the executor's self-declared capability list.

func TrustTierFor

func TrustTierFor(name string) domain.ExecutorTrust

TrustTierFor maps an executor's Name() (== the selected executor kind) to its engine-assigned trust tier. It is the single source of truth, never the executor's self-declared Capabilities().Trust, and it fails closed for any unknown kind (review: system-deny / engine-assigned trust).

func VerifyAgentCLI

func VerifyAgentCLI(ctx context.Context, image, cli string) error

VerifyAgentCLI checks that an agent CLI is present in a container image, WITHOUT pulling and with the same hardened flags the sandbox uses at runtime (no network, read-only root, dropped capabilities, non-root, bounded memory/ pids). It is a UX presence check only — trust must come from the image source, not this probe (review: v1 agent setup). The image must already be present locally; a missing image is a distinct error, not a CLI-missing result.

Types

type AgentProvider added in v0.5.0

type AgentProvider struct {
	Name    string              // provider key, e.g. "openai"
	Type    config.ProviderType // the API it speaks natively
	KeyEnv  string              // env var holding its API key; "" for a keyless provider
	BaseURL string              // its API root
}

AgentProvider is the model endpoint a coding agent is pinned to.

func ResolveAgentProvider added in v0.5.0

func ResolveAgentProvider(model, defaultModel string, providers map[string]config.ProviderConfig) (AgentProvider, error)

ResolveAgentProvider resolves the provider a coding-agent model spec names, the same way the model registry does: a `providers:` entry in harness.yaml first (which falls back to the preset for its missing fields), then the built-in preset.

The entry is consulted BEFORE the preset. Checking the preset first handed the agent the preset's own endpoint and key variable, so an Ollama moved to another port, or an OpenAI key under a project-specific variable, reached every model call except the coding agent's.

A bare model id (no `/`) takes the provider of defaultModel, which the operator chose explicitly. A spec WITH a provider prefix never falls back: `opneai/gpt-x` is a typo, and resolving it to the default provider would send a model id nobody chose to an endpoint the typo did not name.

func (AgentProvider) Validate added in v0.5.0

func (p AgentProvider) Validate() error

Validate reports what would stop the agent from using this provider, so it is caught before a multi-gigabyte image pull rather than at Start.

type Attempt

type Attempt struct {
	ID       string `json:"id"`
	Executor string `json:"executor"`
	Status   string `json:"status"` // running|succeeded|failed|cancelled
	Phase    string `json:"phase"`  // Planning|Editing|Testing|Waiting|Reviewing|Finished
}

Attempt is the durable handle returned by Start.

type Capabilities

type Capabilities struct {
	Trust        domain.ExecutorTrust `json:"trust"`
	SandboxMode  domain.SandboxMode   `json:"sandbox_mode"`
	Network      bool                 `json:"network"`
	Capabilities []string             `json:"capabilities"`
}

Capabilities declares the executor's trust, sandbox mode, and (deterministic, not model-granted) capabilities.

type CapabilityBroker

type CapabilityBroker struct{}

CapabilityBroker authorizes tool actions against an executor's declared capability set. It is a pure gate: it can only deny, never grant.

func (CapabilityBroker) Authorize

func (CapabilityBroker) Authorize(caps []string, action string) error

Authorize returns nil if every declared capability required by action is present in caps, and an error otherwise. An unknown action is always denied.

func (CapabilityBroker) GrantSuggested

func (CapabilityBroker) GrantSuggested(suggested []string) []string

GrantSuggested returns an empty set: models cannot grant capabilities. The suggested list is deliberately ignored so a model can never widen its own executor's declared capability set (§50).

type ContainerExecutor

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

ContainerExecutor runs a task inside a Docker container with no network and a read-only-by-convention workspace mount, collecting the produced patch from a mounted hand-off file (§52 SandboxContainer).

func NewContainerExecutor

func NewContainerExecutor(store *blob.Store, image string) *ContainerExecutor

NewContainerExecutor returns a ContainerExecutor that persists produced patch content to the given blob store. image defaults to a minimal Alpine image when empty; dockerPath is the Docker CLI (override for tests).

func (*ContainerExecutor) Cancel

func (e *ContainerExecutor) Cancel(ctx context.Context, id string) error

Cancel removes the container, terminating the attempt.

func (*ContainerExecutor) Capabilities

func (e *ContainerExecutor) Capabilities(ctx context.Context) Capabilities

Capabilities declares the container executor's deterministic capabilities.

func (*ContainerExecutor) Collect

func (e *ContainerExecutor) Collect(ctx context.Context, id string) (Result, error)

Collect reads the produced patch from the mounted hand-off file, cleans up the container, and persists the content to the blob store.

func (*ContainerExecutor) Name

func (e *ContainerExecutor) Name() string

Name reports the executor's registered name.

func (*ContainerExecutor) Start

func (e *ContainerExecutor) Start(ctx context.Context, req Request) (Attempt, error)

Start launches the task in a detached container and records its container id.

func (*ContainerExecutor) Status

func (e *ContainerExecutor) Status(ctx context.Context, id string) (Status, error)

Status reports the container's run state by inspecting the Docker daemon.

type ContainerSandbox

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

ContainerSandbox runs a command inside an isolated Docker container: no network, read-only root filesystem, dropped capabilities, bounded memory/pids, and the daemon's own UID/GID -- which is not the same as non-root. If the daemon runs as root the container does too, and nothing refuses to start or warns (docs/security-model.md records this under what the gateway does not protect against). Only the work root (mounted at /work) and a /tmp tmpfs are writable; an optional project root is mounted read-only at /repo. This is the OS-isolation boundary for external coding agents and deterministic checks (§52, review B2/H3).

func NewContainerSandbox

func NewContainerSandbox(image string) *ContainerSandbox

NewContainerSandbox returns a sandbox using image (defaulting to a minimal Alpine image). dockerPath is the Docker CLI (override for tests).

func (*ContainerSandbox) Run

func (s *ContainerSandbox) Run(ctx context.Context, opts RunOptions) (stdout, stderr string, exitCode int, err error)

Run executes cmd in the sandbox and returns stdout, stderr, and the exit code. The container is started detached so a context timeout/cancellation can be enforced by `docker rm -f` (a hung build/test is genuinely killed, not left orphaned). A non-zero exit code is not a Go error; only a failure to launch Docker is.

type Executor

type Executor interface {
	Name() string
	Capabilities(ctx context.Context) Capabilities
	Start(ctx context.Context, req Request) (Attempt, error)
	Status(ctx context.Context, id string) (Status, error)
	Cancel(ctx context.Context, id string) error
	Collect(ctx context.Context, id string) (Result, error)
}

Executor runs a Task in an isolated worker and returns a patch.

type InternalExecutor

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

InternalExecutor runs tasks deterministically in-process. It is hermetic: it performs no network I/O and depends on no external services.

func NewInternalExecutor

func NewInternalExecutor(store *blob.Store) *InternalExecutor

NewInternalExecutor returns a ready-to-use InternalExecutor that persists produced patch content to the given content-addressed blob store.

func (*InternalExecutor) Cancel

func (e *InternalExecutor) Cancel(ctx context.Context, id string) error

Cancel marks an attempt cancelled. It is a no-op after the attempt has already succeeded or been cancelled.

func (*InternalExecutor) Capabilities

func (e *InternalExecutor) Capabilities(ctx context.Context) Capabilities

Capabilities declares the executor's deterministic capabilities. Trust and sandbox mode are fixed by construction; the capability set is never model-granted (§49, §50).

func (*InternalExecutor) Collect

func (e *InternalExecutor) Collect(ctx context.Context, id string) (Result, error)

Collect writes the deterministic implementation file into the isolated work root and returns an empty Result. The engine (orchestrator) snapshots the work root before/after and computes the real diff (§36); the executor's job is only to produce file changes, never to self-declare the diff.

func (*InternalExecutor) Name

func (e *InternalExecutor) Name() string

Name reports the executor's registered name.

func (*InternalExecutor) Start

func (e *InternalExecutor) Start(ctx context.Context, req Request) (Attempt, error)

Start records a new attempt and returns its durable handle. The isolated work root is created so the engine can snapshot it before/after and compute the diff.

func (*InternalExecutor) Status

func (e *InternalExecutor) Status(ctx context.Context, id string) (Status, error)

Status reports the next step of the deterministic progression. It is idempotent at the terminal phase and never exposes chain-of-thought.

type OutputTailer added in v0.5.0

type OutputTailer interface {
	OutputTail(ctx context.Context, id string, lines int) string
}

OutputTailer is implemented by executors that run an external agent and can report the end of its own output. The engine uses it to say WHY an attempt failed or changed nothing -- a 401, a retired model id -- which the attempt status alone does not carry. It must be read before Collect or Cancel, which discard the output.

type Request

type Request struct {
	InitiativeID  string `json:"initiative_id"`
	TaskID        string `json:"task_id"`
	TaskTitle     string `json:"task_title"`
	TaskStatement string `json:"task_statement"`
	Brief         string `json:"brief,omitempty"`
	WorkRoot      string `json:"work_root"`
}

Request is one execution request. The canonical workspace is never passed as a writable root — the executor receives an isolated WorkRoot (§37). Brief is the planner-produced implementation brief (rendered text) the implementer should follow; when empty the executor falls back to TaskStatement.

type Result

type Result struct {
	PatchDigest string          `json:"patch_digest"`
	LogDigest   string          `json:"log_digest,omitempty"`
	Usage       domain.RunUsage `json:"usage,omitempty"`
}

Result is the collected execution output (content-addressed digests + usage).

type RunOptions

type RunOptions struct {
	WorkRoot string   // writable, mounted at /work
	RepoRoot string   // optional, mounted read-only at /repo (the canonical workspace)
	Cmd      []string // command + args (run with work dir /work)
}

RunOptions configures a sandbox execution.

type SandboxedAgentExecutor

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

SandboxedAgentExecutor runs a coding-agent CLI inside an isolated container (review B2, amended). The container gives FILESYSTEM/PROCESS isolation — read-only root, only the mounted /work and a /tmp tmpfs are writable — but NOT network isolation: the agent needs egress to reach its model API, so the provider keys are forwarded in and `--network none` is deliberately omitted. OMP and Hermes are the two agents; neither runs as a host subprocess. The agent writes files under /work (== req.WorkRoot); the engine snapshots that directory before/after and computes the diff (B3).

func NewHermesExecutor

func NewHermesExecutor(store *blob.Store, model, image string, provider AgentProvider) *SandboxedAgentExecutor

NewHermesExecutor returns a sandboxed Hermes (Nous Research) executor.

func NewOMPExecutor

func NewOMPExecutor(store *blob.Store, model, image string, provider AgentProvider) *SandboxedAgentExecutor

NewOMPExecutor returns a sandboxed OMP executor pinned to provider, which the engine resolves with ResolveAgentProvider.

func (*SandboxedAgentExecutor) Cancel

func (e *SandboxedAgentExecutor) Cancel(ctx context.Context, id string) error

Cancel removes the container, terminating the agent.

func (*SandboxedAgentExecutor) Capabilities

func (e *SandboxedAgentExecutor) Capabilities(ctx context.Context) Capabilities

Capabilities declares the agent's capabilities. The sandbox mode is REAL filesystem/process isolation (container, read-only root); Network is true because the agent needs egress to reach its model API.

func (*SandboxedAgentExecutor) Collect

func (e *SandboxedAgentExecutor) Collect(ctx context.Context, id string) (Result, error)

Collect cleans up the container and returns an empty Result. The engine computes the diff from the work root (B3); the executor's job is only to run the agent in isolation.

func (*SandboxedAgentExecutor) Name

func (e *SandboxedAgentExecutor) Name() string

Name reports the executor's registered name.

func (*SandboxedAgentExecutor) OutputTail added in v0.5.0

func (e *SandboxedAgentExecutor) OutputTail(ctx context.Context, id string, lines int) string

OutputTail implements OutputTailer.

func (*SandboxedAgentExecutor) SetKeyLookup added in v0.5.0

func (e *SandboxedAgentExecutor) SetKeyLookup(lookup func(name string) string)

SetKeyLookup sets where the provider key's value is read from. The daemon passes one that falls back to the project's .env, as its model registry does; reading only the process environment gave the agent no key while every other model call had one.

func (*SandboxedAgentExecutor) Start

Start launches the agent inside the isolated container (detached) and records the container id. The provider keys are forwarded so the agent can reach its model; `--network none` is intentionally omitted (the agent must egress to the model API — this is a filesystem/process sandbox, not a network sandbox).

func (*SandboxedAgentExecutor) Status

func (e *SandboxedAgentExecutor) Status(ctx context.Context, id string) (Status, error)

Status reports the container's run state by inspecting the Docker daemon.

type Status

type Status struct {
	Status string `json:"status"`
	Phase  string `json:"phase"`
	Action string `json:"action"`
}

Status is a progress snapshot (§50). Never exposes chain-of-thought.

Jump to

Keyboard shortcuts

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