execx

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 8 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 execx defines the injectable external-command runner the orchestration core uses for git, gh, and host CLIs. Commands are always argument vectors — never shell strings. Before the OpenCode native binding repair this comment claimed that alone prevented shell interpretation; launchers (notably Windows batch files) can interpret forwarded arguments. Run does not make arbitrary launchers safe; OpenCode verifies its own native command before passing host-derived arguments. A non-zero exit is data in Result, not an error: callers that need exit codes as information (PRD §16 reproduce-on-base) read them directly, and callers for whom non-zero means failure convert it themselves.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	// Name is an executable name or path; the runner uses LookPath.
	Name string
	// Args is passed as an argument vector, not a shell string. A selected
	// launcher can still interpret it; callers must enforce any native-only rule.
	Args []string
	// Dir is the working directory. It is required: an implicit
	// inherited cwd would make command behavior depend on ambient
	// process state, so an empty Dir is an error (fail closed).
	Dir string
	// Env holds KEY=VALUE pairs appended to os.Environ(). Later
	// entries win, so callers can override inherited variables.
	// nil adds nothing.
	Env []string
	// Stdin is the process input; nil means no input.
	Stdin io.Reader
}

Cmd describes one external command invocation.

type Local

type Local struct {
	// LookPath resolves an executable name; defaults to exec.LookPath.
	LookPath func(string) (string, error)
}

Local is the production Runner backed by os/exec.

func (Local) ResolvePath added in v0.17.0

func (l Local) ResolvePath(name string) (string, error)

ResolvePath exposes the same injected lookup used by Run, so a caller can qualify and retain a particular executable without changing Runner's contract.

func (Local) Run

func (l Local) Run(ctx context.Context, c Cmd) (Result, error)

Run executes c and captures its output. The executable is resolved first so a missing binary yields an actionable error instead of a spawn failure.

type Result

type Result struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

Result carries everything a caller needs to interpret an invocation that ran to completion.

type Runner

type Runner interface {
	Run(ctx context.Context, cmd Cmd) (Result, error)
}

Runner runs external commands. Run returns a non-nil error only when the command could not be executed at all (executable missing, context canceled, spawn failure); a command that ran and exited non-zero returns a nil error with the exit code in Result.

Directories

Path Synopsis
Package execxtest provides a scripted fake execx.Runner for transcript tests: each expected call is asserted in order and answered with a recorded result, so tests pin the exact argument vectors the core sends to git and gh without running either.
Package execxtest provides a scripted fake execx.Runner for transcript tests: each expected call is asserted in order and answered with a recorded result, so tests pin the exact argument vectors the core sends to git and gh without running either.

Jump to

Keyboard shortcuts

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