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 ¶
- Variables
- func DefaultAgentImage(kind string) string
- func PullImage(ctx context.Context, image string) (string, error)
- func SmokeAgent(ctx context.Context, kind, image, model string, provider AgentProvider, ...) error
- func SweepAgentLeftovers(ctx context.Context, stateRoot string)
- func TestOnlySetKnownIncompatible(kind, spec, reason string) (restore func())
- func TrustAllows(trust domain.ExecutorTrust, action string) bool
- func TrustTierFor(name string) domain.ExecutorTrust
- func VerifyAgentCLI(ctx context.Context, image, cli string) error
- type AgentProvider
- type Attempt
- type Capabilities
- type CapabilityBroker
- type ContainerExecutor
- func (e *ContainerExecutor) Cancel(ctx context.Context, id string) error
- func (e *ContainerExecutor) Capabilities(ctx context.Context) Capabilities
- func (e *ContainerExecutor) Collect(ctx context.Context, id string) (Result, error)
- func (e *ContainerExecutor) Name() string
- func (e *ContainerExecutor) Start(ctx context.Context, req Request) (Attempt, error)
- func (e *ContainerExecutor) Status(ctx context.Context, id string) (Status, error)
- type ContainerSandbox
- type Executor
- type InternalExecutor
- func (e *InternalExecutor) Cancel(ctx context.Context, id string) error
- func (e *InternalExecutor) Capabilities(ctx context.Context) Capabilities
- func (e *InternalExecutor) Collect(ctx context.Context, id string) (Result, error)
- func (e *InternalExecutor) Name() string
- func (e *InternalExecutor) Start(ctx context.Context, req Request) (Attempt, error)
- func (e *InternalExecutor) Status(ctx context.Context, id string) (Status, error)
- type ModelCompat
- type OutputTailer
- type Request
- type Result
- type RunOptions
- type SandboxedAgentExecutor
- func (e *SandboxedAgentExecutor) Cancel(ctx context.Context, id string) error
- func (e *SandboxedAgentExecutor) Capabilities(ctx context.Context) Capabilities
- func (e *SandboxedAgentExecutor) Collect(ctx context.Context, id string) (Result, error)
- func (e *SandboxedAgentExecutor) Name() string
- func (e *SandboxedAgentExecutor) OutputTail(ctx context.Context, id string, lines int) string
- func (e *SandboxedAgentExecutor) SetKeyLookup(lookup func(name string) string)
- func (e *SandboxedAgentExecutor) Start(ctx context.Context, req Request) (Attempt, error)
- func (e *SandboxedAgentExecutor) Status(ctx context.Context, id string) (Status, error)
- type Status
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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
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 TestOnlySetKnownIncompatible ¶ added in v0.6.0
func TestOnlySetKnownIncompatible(kind, spec, reason string) (restore func())
TestOnlySetKnownIncompatible appends a fixture row to the known-incompatible table and returns a func that restores it -- for a test outside this package (internal/cli's, internal/daemon's and internal/workflow's own executor-setup tests) that needs to prove the refusal mechanism still works, without the test depending on knownIncompatible actually holding a real row (it does not, as of the fix that made gpt-4.1-mini's context window explicit instead of refusing it -- see knownIncompatible's own doc comment).
This mutates package-level state with no synchronization, so calling it from anything other than a test would be a real, exploitable defect: any importer of this package could silently poison every other caller's CheckModelCompat result. It cannot simply move into a `_test.go` file the way an internal-only test seam normally would (LOW, release-gate report, "move it behind a test-only file") -- Go never links one package's `_test.go` files into another package's build, and the three callers named above are in different packages, so a `_test.go` version of this function would compile clean for `go test ./internal/executor` and then fail to resolve for every other package that needs it. testing.Testing() (stable since Go 1.21, and this module already requires 1.25) is the enforcement a file rename can't provide here: it reports whether the CURRENT BINARY was built by `go test`, not merely whether this call happens to be reachable from test code, so a production `idea`/`idea-harness` build panics instead of quietly accepting the mutation.
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 ¶
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 ¶
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.
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).
The /tmp tmpfs mounts are explicitly `exec` (Docker's tmpfs default is `noexec`). A compiled toolchain -- `go test`, jest's native transforms, cargo build scripts, pytest's compiled extensions -- stages its binary under $TMPDIR/os.TempDir() before it fork/execs it; under a noexec /tmp that exec fails with "permission denied" even though the compile itself succeeded (review defect #1). TMPDIR is set explicitly so every toolchain -- not just Go, which already defaults to os.TempDir() -- resolves its scratch directory to this same exec-capable tmpfs rather than whatever its own default happens to be.
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 ¶
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.
type ModelCompat ¶ added in v0.6.0
type ModelCompat struct {
// Blocked means the combination is known to fail every time -- a real
// call, not a flaky one -- and the caller should refuse rather than spend
// an image pull or a paid call on it.
Blocked bool
// Message explains why, and how to change it. Empty when the combination
// is verified and nothing needs to be said.
Message string
}
ModelCompat is a verdict on one executor-kind/model combination: whether it is known to fail deterministically, or simply untested (§ docs/agents.md "Known executor/model compatibility").
func CheckModelCompat ¶ added in v0.6.0
func CheckModelCompat(kind, modelSpec string) ModelCompat
CheckModelCompat reports whether kind (hermes|omp) paired with modelSpec ("provider/model") is known to fail, or merely untested. modelSpec with no provider prefix (a bare model, or "" when nothing is configured yet) is always treated as untested -- there is nothing to match in either table.
type OutputTailer ¶ added in v0.5.0
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 ¶
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
OutputTail implements OutputTailer. See tailLogs and tailRawMultiplier for how this actually delivers the requested line count (review defect F).
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).