agentcli

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 10 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 agentcli holds the plumbing every CLI-backed adapter needs: resolving the binary, learning which flags the installed version actually supports, and turning one subprocess run into a stream of IR events.

What stays in each adapter is only what is specific to its CLI: the argv to build, and how to read the CLI's output. Subprocess lifecycle itself belongs to internal/runner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtraArgValues

func ExtraArgValues(extra []string) []string

ExtraArgValues picks out the tokens in a user-supplied argv fragment that could be values rather than flag names, for RedactArgs to keep out of the log: extra_args may carry a credential, a flag name never does.

A token appearing elsewhere in argv is redacted there too. Losing a line of log detail is the right side to err on.

func FirstLine

func FirstLine(s string) string

FirstLine is the first non-empty line of s, trimmed.

func ParseFlagNames

func ParseFlagNames(help string) map[string]bool

ParseFlagNames extracts every "--flag" token from a --help dump, which is how agent2api tells what an installed version supports.

func RedactArgs

func RedactArgs(cliArgs []string, secretFlags []string, literals ...string) []string

RedactArgs makes argv safe to log by replacing the value that follows any of secretFlags, and any argument listed in literals. Caller content never reaches the log, at any level.

A hidden "--flag=value" token keeps its flag name: knowing which setting was passed is the useful half, and it is not the secret half.

func Stream

func Stream(ctx context.Context, log *slog.Logger, r Run, newParser func(emit func(ir.Event) bool) Parser) <-chan ir.Event

Stream spawns the process and returns the events it produces. The channel is closed after the terminal event, and every exit path runs Cleanup.

This is the whole run loop an adapter needs: it emits the start event, feeds stdout to the parser, and lets the parser have the last word on how the run ended.

Types

type Caps

type Caps struct {
	// Path is the resolved absolute path of the binary.
	Path string
	// Version is the first line of the CLI's --version output.
	Version string
	// contains filtered or unexported fields
}

Caps records what the installed CLI supports, so argv can adapt instead of breaking when flags drift between releases.

func NewCaps

func NewCaps(path, version string, flags map[string]bool) *Caps

NewCaps records what one install supports. Probe.Caps builds the real thing from a --help dump; passing the flag set directly also lets a caller state the capabilities it wants to reason about without spawning anything.

func (*Caps) Has

func (c *Caps) Has(flag string) bool

Has reports whether the installed CLI documents the given flag.

type Parser

type Parser interface {
	// Line consumes one line of stdout. Returning an error kills the process,
	// so unrecognized output should be ignored rather than rejected: CLIs add
	// events between releases.
	Line(b []byte) error
	// Finish emits the run's terminal event. runErr is whatever the runner
	// reported, nil on a clean exit.
	Finish(runErr error)
}

Parser turns one CLI's stdout into IR events. One parser handles one run.

type Probe

type Probe struct {
	// Binary is the configured command name or absolute path.
	Binary string
	// Env is the complete, allowlisted environment for probe calls.
	Env []string
	// HelpArgs and VersionArgs default to --help and --version. A CLI whose
	// flags live under a subcommand passes that subcommand here.
	HelpArgs    []string
	VersionArgs []string
	// Required lists flags the adapter cannot work without.
	Required []string
	// NotFound is the message for a missing binary; it should say where to get
	// the CLI. Missing renders the message for an install that lacks required
	// flags.
	NotFound string
	Missing  func(missing []string) string
	Log      *slog.Logger
	// contains filtered or unexported fields
}

Probe resolves one CLI and inspects it once, caching the result. A failure is never cached, so a CLI installed after startup is picked up on the next request.

func (*Probe) Caps

func (p *Probe) Caps(ctx context.Context) (*Caps, error)

Caps resolves the binary and its supported flags.

func (*Probe) Capture

func (p *Probe) Capture(ctx context.Context, timeout time.Duration, cliArgs ...string) (string, error)

Capture runs the CLI with the given arguments and returns its stdout. It is how adapters ask a CLI about itself, e.g. for login state.

type Run

type Run struct {
	Spec runner.Spec
	// Model is the namespaced model name, reported on the start event.
	Model string
	// LogArgs is argv with caller content already redacted; it is what gets
	// logged. Empty means log nothing.
	LogArgs []string
	// Cleanup releases per-request resources, e.g. the scratch directory. It
	// runs after the last event.
	Cleanup func()
}

Run describes one CLI invocation to stream.

Jump to

Keyboard shortcuts

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