out

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 8 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 out renders every command result as a stable, machine-readable envelope. AI agents parse stdout; humans can ask for -o text.

Index

Constants

View Source
const (
	ExitOK       = 0
	ExitError    = 1 // generic / internal error
	ExitUsage    = 2 // bad flags or arguments
	ExitNotFound = 3 // host, key, secret, job ... not found
	ExitConnect  = 4 // ssh connection / auth / host-key failure
	ExitRemote   = 5 // remote command ran but exited non-zero
	ExitPolicy   = 6 // blocked by safety policy (needs --yes / --allow-dangerous)
	ExitTimeout  = 7 // command or connection timed out
	ExitConflict = 8 // precondition failed (e.g. replace text not found / ambiguous)
)

Exit codes are part of the public contract. Agents may branch on them.

Variables

View Source
var P = &Printer{Format: "json", W: os.Stdout, Start: time.Now()}

Functions

This section is empty.

Types

type Envelope

type Envelope struct {
	OK      bool   `json:"ok"`
	Command string `json:"command"`
	Data    any    `json:"data,omitempty"`
	Error   *Error `json:"error,omitempty"`
	Meta    Meta   `json:"meta"`
}

Envelope is the single JSON object printed on stdout for every command.

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Hint    string `json:"hint,omitempty"`
	Exit    int    `json:"-"`
}

Error is a typed error carrying a stable code, an exit code and a hint that tells the agent how to recover.

func Errf

func Errf(exit int, code, hint, format string, a ...any) *Error

func NotFound

func NotFound(kind, name string) *Error

func Usage

func Usage(format string, a ...any) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) WithHint

func (e *Error) WithHint(h string) *Error

type Meta

type Meta struct {
	Version    string `json:"version"`
	DurationMS int64  `json:"duration_ms"`
	DryRun     bool   `json:"dry_run,omitempty"`
}

type Printer

type Printer struct {
	Format  string // json | text | yaml-ish not supported, keep it simple
	Pretty  bool
	Version string
	Start   time.Time
	DryRun  bool
	W       io.Writer
}

Printer is configured once by the root command.

func (*Printer) Event

func (p *Printer) Event(v any)

NDJSON emits one streaming event line (used by --stream / follow modes).

func (*Printer) Fail

func (p *Printer) Fail(command string, err error) int

func (*Printer) Print

func (p *Printer) Print(command string, data any, softErr *Error)

Success prints data. A non-nil softErr marks the envelope not-ok but still carries data (e.g. multi-host exec with partial failures).

type Texter

type Texter interface{ Text() string }

Texter lets a result type provide a human rendering for -o text.

Jump to

Keyboard shortcuts

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