agentrunner

package
v0.161.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package agentrunner centralizes spawning `infer agent` as a subprocess and streaming its stdout. It is the single implementation shared by the channel manager, scheduler, heartbeat, and the Agent tool (local subagents), so the spawn/scan/approval-IPC loop lives in exactly one place.

It is a leaf package (imports only domain + stdlib) so callers in the services, services/scheduler, and services/heartbeat packages can all depend on it without an import cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecFunc

type ExecFunc = func(ctx context.Context, name string, args ...string) *exec.Cmd

ExecFunc matches exec.CommandContext. It is a type alias (not a defined type) so callers' own named exec-override types stay assignable without conversion.

type Options

type Options struct {
	// BinaryPath is the infer binary to spawn; defaults to os.Args[0] when empty.
	BinaryPath string
	// Exec overrides command construction (tests); defaults to exec.CommandContext.
	Exec ExecFunc

	SessionID string
	Prompt    string
	Model     string
	Files     []string

	RequireApproval bool
	Remote          bool
	Heartbeat       bool
	// ResultFile, when set, passes --result-file so the agent writes its final
	// assistant message to a JSON file on exit (used by detached/tmux runs).
	ResultFile string
	// ExtraEnv is appended to os.Environ() for the subprocess (e.g. depth guard).
	ExtraEnv []string

	// OnLine is called for each non-empty raw stdout line. Approval-request
	// lines handled internally (see Approval) are not passed to OnLine.
	OnLine func(line []byte)
	// Approval, when set and RequireApproval is true, resolves a tool approval
	// request into a response that is written back to the agent's stdin. It
	// blocks until the decision is made.
	Approval func(domain.ApprovalRequest) domain.ApprovalResponse
}

Options configures a single `infer agent` subprocess run.

type Result

type Result struct {
	// FinalAssistant is the last non-empty assistant message content seen on
	// stdout - the harvested "answer" of the run.
	FinalAssistant string
	// Stderr is the full captured standard error (also mirrored live to os.Stderr).
	Stderr string
}

Result is the outcome of a subprocess run.

func Run

func Run(ctx context.Context, opts Options) (Result, error)

Run spawns `infer agent ...`, streams stdout line-by-line, optionally brokers tool approval over stdin, and returns the harvested final assistant message plus captured stderr. The returned error is the subprocess setup/exit error; callers format their own user-facing messages from it.

Jump to

Keyboard shortcuts

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