cwtypes

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: 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.

Functions

This section is empty.

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 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
}

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