agent

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package agent contains the logic that runs inside the cliwrap-agent subprocess. It owns the child CLI process and the IPC connection back to the host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, cfg Config) error

Run is the main entry point invoked from cmd/cliwrap-agent/main.go. It blocks until the IPC connection closes or ctx is canceled.

Types

type Config

type Config struct {
	IPCFD          int
	AgentID        string
	RuntimeDir     string
	OutboxCapacity int
	WALBytes       int64
	MaxRecvPayload uint32
}

Config is the runtime configuration passed from the host via env vars and argv. For v1, the fd index is fixed at 3.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults, reading host-supplied env vars CLIWRAP_AGENT_ID and CLIWRAP_AGENT_RUNTIME when present.

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher routes inbound IPC messages and coordinates child lifecycles.

func NewDispatcher

func NewDispatcher(conn *ipc.Conn) *Dispatcher

NewDispatcher constructs a Dispatcher bound to conn.

func (*Dispatcher) Handle

func (d *Dispatcher) Handle(msg ipc.OutboxMessage)

Handle processes an inbound message from the host.

func (*Dispatcher) SendControl

func (d *Dispatcher) SendControl(t ipc.MsgType, payload any, ackRequired bool) error

SendControl serializes payload and enqueues it as an outbound frame.

type RunResult

type RunResult struct {
	PID      int
	ExitCode int
	Signal   int
	ExitedAt time.Time
	Reason   string
}

RunResult summarizes the child's exit.

type RunSpec

type RunSpec struct {
	Command     string
	Args        []string
	Env         map[string]string
	WorkDir     string
	StopTimeout time.Duration
	OnStarted   func(pid int) // called after cmd.Start() succeeds, before Wait()
}

RunSpec describes the child process to fork/exec.

type Runner

type Runner struct {
	// StdoutSink, if non-nil, is used to tee the child's stdout bytes.
	StdoutSink io.Writer
	// StderrSink, if non-nil, is used to tee the child's stderr bytes.
	StderrSink io.Writer
}

Runner starts a single child process and blocks until it exits.

func NewRunner

func NewRunner() *Runner

NewRunner returns a Runner with default sinks set to io.Discard.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, spec RunSpec) (RunResult, error)

Run forks/execs the child and blocks until it exits or ctx is canceled. On ctx cancel it sends SIGTERM, waits StopTimeout, then SIGKILL.

Jump to

Keyboard shortcuts

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