cwtypes

package
v0.4.6 Latest Latest
Warning

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

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

Documentation

Overview

Package cwtypes contains the shared type definitions used by both pkg/cliwrap (the public API) and internal/controller. Placing them in a leaf package avoids an import cycle.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSpec = errors.New("cliwrap: invalid spec")

ErrInvalidSpec is the sentinel that SpecValidationError.Is maps to.

View Source
var ErrPTYUnsupportedByAgent = errors.New("cliwrap: agent does not support PTY mode")

ErrPTYUnsupportedByAgent is returned by Controller.Start when the agent's capability reply does not include the "pty" feature and Spec.PTY is set. Defined here (leaf package) so internal/controller can return it without importing pkg/cliwrap and creating an import cycle.

Functions

func ApplyPTYDefaults added in v0.3.0

func ApplyPTYDefaults(c *PTYConfig) error

ApplyPTYDefaults fills in zero-valued fields of c with sensible defaults. It is a no-op when c is nil.

Types

type ExceedAction

type ExceedAction int

ExceedAction is the action taken when a resource limit is breached.

const (
	ExceedWarn ExceedAction = iota
	ExceedThrottle
	ExceedKill
)

type FileRotationOptions

type FileRotationOptions = LogOptions

FileRotationOptions is an alias kept for backward compatibility.

type LogChunk added in v0.2.0

type LogChunk struct {
	ProcessID string
	Stream    uint8 // 0=stdout, 1=stderr
	Data      []byte
}

LogChunk is one chunk of streamed log data delivered to a follow-mode watcher.

Data is a SHARED byte slice — the producer copies it once and fans the same slice out to every matching subscriber. Receivers MUST NOT mutate Data (no in-place sort, no append that grows in place, no lowercase conversion, etc.), because any mutation would corrupt the slice for other concurrent subscribers. A receiver that needs to modify the bytes must make its own copy first.

This type lives in cwtypes (rather than pkg/cliwrap) so internal/mgmt can refer to it without creating an import cycle with pkg/cliwrap. pkg/cliwrap re-exports it as a type alias.

type LogOptions

type LogOptions struct {
	RingBufferBytes       int
	RotationDir           string
	RotationMaxSize       int64
	RotationMaxFiles      int
	PreserveWALOnShutdown bool
}

LogOptions controls per-process log storage.

type PTYConfig added in v0.3.0

type PTYConfig struct {
	InitialCols uint16 `yaml:"initial_cols"`
	InitialRows uint16 `yaml:"initial_rows"`
	Echo        bool   `yaml:"echo"`
}

PTYConfig holds pseudo-terminal configuration for a managed process.

type ResourceLimits

type ResourceLimits struct {
	MaxRSS        uint64  // bytes
	MaxCPUPercent float64 // 0-100
	OnExceed      ExceedAction
}

ResourceLimits express per-process resource caps.

type RestartPolicy

type RestartPolicy int

RestartPolicy decides what happens after a child exits.

const (
	RestartNever RestartPolicy = iota
	RestartOnFailure
	RestartAlways
)

type SandboxSpec

type SandboxSpec struct {
	Provider string
	Config   map[string]any
}

SandboxSpec selects a sandbox provider and its configuration.

type Spec

type Spec struct {
	ID             string
	Name           string
	Command        string
	Args           []string
	Env            map[string]string
	WorkDir        string
	Restart        RestartPolicy
	MaxRestarts    int
	RestartBackoff time.Duration
	StopTimeout    time.Duration
	Stdin          StdinMode
	Sandbox        *SandboxSpec
	Resources      ResourceLimits
	LogOptions     LogOptions
	PTY            *PTYConfig `yaml:"pty,omitempty"`

	// Persistent makes the agent + child outlive the host process. When true,
	// the agent self-daemonizes at spawn time and accepts reattach via a
	// UNIX socket at WithPersistentDir/<ID>/sock.
	//
	// Default false: foreground-mode session, identical to historical behavior.
	Persistent bool `yaml:"persistent,omitempty"`

	// RingBufferSize is the in-memory PTY output buffer size in bytes,
	// used to redraw the current screen state on reattach. Only meaningful
	// when Persistent=true. Zero means "use default 256 KiB at agent startup".
	RingBufferSize int `yaml:"ring_buffer_size,omitempty"`
}

Spec is the immutable description of a managed process.

func (*Spec) Validate

func (s *Spec) Validate() error

Validate returns an error if s is missing required fields or has bad values.

type SpecValidationError

type SpecValidationError struct {
	Field  string
	Value  any
	Reason string
}

SpecValidationError describes a field-level validation failure.

func (*SpecValidationError) Error

func (e *SpecValidationError) Error() string

func (*SpecValidationError) Is

func (e *SpecValidationError) Is(target error) bool

type State

type State int

State is the runtime state of a managed process.

const (
	StatePending State = iota
	StateStarting
	StateRunning
	StateStopping
	StateStopped
	StateCrashed
	StateRestarting
	StateFailed
)

func (State) String

func (s State) String() string

String returns the lowercase name of a State.

type Status

type Status struct {
	State         State
	AgentPID      int
	ChildPID      int
	StartedAt     time.Time
	LastExitAt    time.Time
	LastExitCode  int
	RestartCount  int
	LastError     string
	PendingReason string
	RSS           uint64
	CPUPercent    float64
}

Status is a snapshot of the runtime state.

type StdinMode

type StdinMode int

StdinMode controls how the agent connects the child's stdin.

const (
	StdinNone    StdinMode = iota
	StdinPipe              // host may call ProcessHandle.SendStdin
	StdinInherit           // inherit agent's stdin (rarely useful)
)

Jump to

Keyboard shortcuts

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