Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMaxRestartsExhausted = errors.New("supervise: max restarts exhausted")
ErrMaxRestartsExhausted is returned when Run gives up.
Functions ¶
func BuildAgentForTest ¶
BuildAgentForTest compiles the cliwrap-agent binary once per test process and returns its path.
Types ¶
type AgentHandle ¶
type AgentHandle struct {
Socket *net.UnixConn
Process *os.Process
PID int
// contains filtered or unexported fields
}
AgentHandle is the result of spawning an agent: one half of a connected socket pair plus the OS process handle.
func (*AgentHandle) Close ¶
func (h *AgentHandle) Close() error
Close shuts the host side of the socket, sends SIGTERM to the agent, waits briefly, then SIGKILL if still alive. It is idempotent.
type BackoffStrategy ¶
BackoffStrategy computes the delay before the Nth restart attempt.
type ExponentialBackoff ¶
type ExponentialBackoff struct {
Initial time.Duration
Max time.Duration
Multiplier float64
Jitter float64 // 0..1, relative jitter range
// contains filtered or unexported fields
}
ExponentialBackoff is an exponential backoff with optional jitter.
type RestartLoop ¶
type RestartLoop struct {
// contains filtered or unexported fields
}
RestartLoop runs Starter.Start in a loop, honoring the configured policy.
func NewRestartLoop ¶
func NewRestartLoop(opts RestartLoopOptions) *RestartLoop
NewRestartLoop returns a loop.
type RestartLoopOptions ¶
type RestartLoopOptions struct {
Starter Starter
Policy RestartLoopPolicy
MaxRestarts int // 0 = unlimited
Backoff BackoffStrategy
}
RestartLoopOptions configures a RestartLoop.
type RestartLoopPolicy ¶
type RestartLoopPolicy int
RestartLoopPolicy controls whether Run retries on failure.
const ( RestartLoopNever RestartLoopPolicy = iota RestartLoopOnFailure RestartLoopAlways )
type SpawnOpts ¶ added in v0.3.0
type SpawnOpts struct {
// Persistent enables CW-G4 daemonization for this agent.
Persistent bool
// SessionDir is the per-session metadata directory (sock, pid,
// meta.json, agent.log live here). Required when Persistent=true.
// Created with mode 0700 if it does not exist.
SessionDir string
}
SpawnOpts is per-spawn customization passed to Spawner.Spawn.
Default zero value spawns a non-persistent agent (identical to historical behavior; agent is in host's process group, dies with host on terminal close). When Persistent=true, the agent is daemonized with Setsid and stdio redirected to <SessionDir>/agent.log.
type Spawner ¶
type Spawner struct {
// contains filtered or unexported fields
}
Spawner starts agent subprocesses.
func (*Spawner) Options ¶ added in v0.4.6
func (s *Spawner) Options() SpawnerOptions
Options returns the SpawnerOptions this Spawner was constructed with. Exposed so cross-package tests can verify env-var propagation set up at Manager construction time (e.g., CLIWRAP_AGENT_OUTBOX_CAPACITY) without spawning a real child process.
func (*Spawner) Spawn ¶
Spawn creates a socket pair, execs the agent with one fd, and returns the host side of the socket wrapped in a net.UnixConn.
When opts.Persistent is true, the spawned agent is daemonized: Setsid=true (new POSIX session, no controlling terminal), stdio redirected to <opts.SessionDir>/agent.log, cwd set to "/", and --persistent argv flag + CLIWRAP_PERSISTENT=1 + CLIWRAP_SESSION_DIR=<dir> env vars passed. See spec/2026-05-07-CW-G4-persistent-reattach-design.md.
type SpawnerOptions ¶
type SpawnerOptions struct {
// AgentPath is the path to the cliwrap-agent binary. Required.
AgentPath string
// RuntimeDir is the parent directory for per-agent state.
RuntimeDir string
// ExtraEnv entries are appended to the agent's environment.
ExtraEnv []string
}
SpawnerOptions configures a Spawner.
type WatchResult ¶
WatchResult is the OS-level summary of a child's exit.