driver

package
v0.1.54 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 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 driver is how the daemon DRIVES an agent for a turn — the control channel between the daemon and the agent, orthogonal to the agent's output format. An adapter's RunStream composes the driver matching its declared Protocol (agent.Capabilities.Protocol):

  • CLI (here) — spawn the agent's command line per turn and stream its stdout. The UNIVERSAL FALLBACK: any agent that ships only a CLI uses it (Claude: `claude -p`).
  • HTTP — an agent with a native REST/SSE API implements Driver directly, calling its API.
  • Persistent — a long-lived process spoken to over a protocol implements Driver directly.

The daemon core never dispatches on Protocol; it only ever sees unified agent.Events via `emit`. The adapter picks the driver. Adding a protocol-native agent = a new Driver impl, no core change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLI

type CLI struct {
	Command string            // the shell command to run (already assembled from the turn)
	Env     map[string]string // extra env exported to the process (auth tokens, etc.)
	// Parse consumes the command's stdout, emits unified events, and returns the final result plus
	// whether a terminal result was seen. got=false ⇒ CLI surfaces stderr/exit as the error.
	Parse func(stdout io.Reader, emit agent.Emit) (agent.TurnResult, bool)
}

CLI drives an agent by running a shell command (via `bash -lc`) and handing its stdout to a per-agent Parse function that emits unified events. It owns the generic plumbing — process spawn, env, stderr capture, and the "no terminal result" error fallback — so a CLI-based adapter only supplies the command + the stream parser.

func (CLI) Run

func (c CLI) Run(ctx context.Context, _ agent.TurnInput, emit agent.Emit) (agent.TurnResult, error)

type Driver

type Driver interface {
	Run(ctx context.Context, in agent.TurnInput, emit agent.Emit) (agent.TurnResult, error)
}

Driver runs one turn to unified events, however the agent is best driven.

type Persistent

type Persistent struct {
	Command string            // the shell command to run (assembled without the message; it goes in Preamble)
	Env     map[string]string // extra env exported to the process (auth tokens, etc.)
	// Parse consumes the command's stdout, emits unified events, and returns the final result plus
	// whether a terminal result was seen — the SAME parser CLI uses (reused, not reimplemented).
	Parse func(stdout io.Reader, emit agent.Emit) (agent.TurnResult, bool)
	// Encode maps one Inbound to a single NDJSON line for stdin. ok=false ⇒ the message is skipped
	// (nothing to send). The adapter owns the native wire shape; the driver only frames + flushes it.
	Encode func(agent.Inbound) ([]byte, bool)
	// Preamble is written to stdin verbatim (one line each) before the pump starts — the initialize
	// handshake that arms bidirectional control routing, then the first user message.
	Preamble [][]byte
	// Inbound is the user's mid-turn ingress for this turn; the writer selects on it until the turn's
	// result is seen (stdin closed) or the context is cancelled.
	Inbound <-chan agent.Inbound
}

Persistent drives an agent over a long-lived process with an OPEN stdin, for a turn that pauses for the user mid-flight (permission approvals, a follow-up message, an interrupt). It owns the same generic plumbing as CLI — spawn, env, the reused stdout Parse, stderr fallback — plus the wiring CLI lacks: a StdinPipe and a single writer goroutine that first emits the Preamble (the control-protocol handshake + first user message) and then pumps each Inbound to stdin as one NDJSON line via Encode.

Lifecycle is still ONE turn per process (no cross-turn reuse): with a stream-json input the CLI keeps stdin open waiting for more, so the driver closes stdin as soon as the parser emits the turn's terminal result — the process then exits and Parse returns on stdout EOF, exactly like CLI.

func (Persistent) Run

Jump to

Keyboard shortcuts

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