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 ¶
- func ExtraArgValues(extra []string) []string
- func FirstLine(s string) string
- func ParseFlagNames(help string) map[string]bool
- func RedactArgs(cliArgs []string, secretFlags []string, literals ...string) []string
- func Stream(ctx context.Context, log *slog.Logger, r Run, ...) <-chan ir.Event
- type Caps
- type Parser
- type Probe
- type Run
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtraArgValues ¶
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 ParseFlagNames ¶
ParseFlagNames extracts every "--flag" token from a --help dump, which is how agent2api tells what an installed version supports.
func RedactArgs ¶
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 ¶
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.
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.
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.