runner

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 13 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 runner owns agent CLI subprocess lifecycle: spawning, streaming stdout line by line, capturing a bounded stderr tail, enforcing idle and absolute deadlines, and making sure nothing outlives the request.

Adapters do not touch os/exec directly; they only build argv and parse lines.

Index

Constants

View Source
const (
	DefaultMaxLineBytes    = 16 << 20 // 16 MiB
	DefaultStderrTailBytes = 8 << 10  // 8 KiB
)

Defaults for the size limits. They are generous on purpose: a single stream-json line can carry a whole assistant message.

Variables

This section is empty.

Functions

func Environ

func Environ(allowPrefixes []string, extra map[string]string) []string

Environ builds the child environment: the base allowlist, plus any variable matching one of allowPrefixes (adapters use this to let their own vendor variables through, e.g. "ANTHROPIC_"), plus explicit overrides from extra.

The result is sorted, so argv/env is reproducible across runs.

func ExpandPath

func ExpandPath(p string) string

ExpandPath resolves a leading "~" against the user's home directory.

func ScratchDir

func ScratchDir(root, prefix string) (dir string, cleanup func(), err error)

ScratchDir creates an empty per-request working directory under root (or the OS temp directory when root is empty) and returns it with a cleanup func.

Running the CLI here is defense in depth: even if a tool-disable flag is renamed or ignored by a future CLI version, the process starts somewhere with nothing in it rather than in the gateway's own directory.

Types

type Result

type Result struct {
	ExitCode int
	// Stderr holds the last StderrTailBytes bytes the child wrote to stderr.
	Stderr string
}

Result reports how the child ended. It is filled in even when Run returns an error, so callers can inspect the CLI's own complaint.

func Run

func Run(ctx context.Context, spec Spec, onLine func([]byte) error) (Result, error)

Run starts the process and calls onLine for every line the child writes to stdout, in order, from a single goroutine. Run returns once the child has exited and all output has been consumed.

If onLine returns an error, the child is killed and that error is returned. Infrastructure failures (missing binary, timeout, non-zero exit) come back as *ir.Error so frontends can map them to a status without re-classifying.

type Spec

type Spec struct {
	// Binary is a command name resolved through PATH, or an absolute path.
	Binary string
	Args   []string
	// Adapter is the adapter id this run belongs to, used to name the config
	// keys in a timeout message. Empty is fine for calls that are not a
	// request, like probing an install.
	Adapter string
	// Dir is the working directory. Callers should point this at an empty
	// scratch directory so the CLI has nothing real within reach.
	Dir string
	// Env is the complete environment for the child; nothing is inherited
	// implicitly. Build it with [Environ].
	Env []string
	// Stdin is written to the child's stdin, which is then closed. Passing the
	// prompt this way avoids OS argv length limits on long conversations.
	Stdin string

	// RequestTimeout is the absolute cap on the run. Zero means no cap.
	RequestTimeout time.Duration
	// IdleTimeout kills the child when it has produced no output line for this
	// long. Zero disables the watchdog.
	IdleTimeout time.Duration

	MaxLineBytes    int
	StderrTailBytes int
}

Spec describes one subprocess run.

Jump to

Keyboard shortcuts

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