out

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 16 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; CONNECTION_LOST: broke mid-command
	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.

View Source
const (
	PersonalEmail  = "email"
	PersonalPhone  = "phone"
	PersonalCard   = "card"
	PersonalIBAN   = "iban"
	PersonalColumn = "column"
)

Personal kinds, as they appear in [hidden: KIND].

View Source
const Contract = 1

Contract is the version of komando's output contract: the envelope, field names, error codes and exit codes. Within one contract, fields and codes are only added, never renamed or removed; a breaking change raises it (docs/design/ux.md, section 13).

View Source
const Hidden = "[hidden]"

Hidden is what a password, key or token looks like in masked output. Writing text that still holds it is refused (HasHidden), so a masked file read by an agent can never be written back over the real one.

View Source
const UsageHint = "run with --help or `komando schema` for the full command reference"

UsageHint is the hint a usage error gets when its command gives none. The error handler swaps it for the failing command's own --help and example, which says more than a hint shared by every command.

Variables

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

Functions

func DefaultHint added in v0.9.0

func DefaultHint(exit int) string

DefaultHint is the next step for an error whose code gives no hint of its own, by its exit code.

func HasHidden added in v0.2.0

func HasHidden(s string) bool

HasHidden reports whether text holds a value komando hid from an agent ([hidden], [hidden: KIND] or [secret:NAME]). Such text must not be written to a file or a database: it would destroy the real value.

func MaskPersonal added in v0.7.0

func MaskPersonal(s string) string

MaskPersonal hides email addresses, phone numbers, payment card numbers and IBANs in text.

func MaskSecrets added in v0.2.0

func MaskSecrets(s string) string

MaskSecrets hides secret-looking values in plain text.

func PersonalLabel added in v0.7.0

func PersonalLabel(kind string) string

PersonalLabel is how a hidden value of kind looks.

func SafeText added in v0.2.0

func SafeText(s string) string

SafeText makes text from servers and databases safe to print on a terminal: escape sequences other than colours (window titles, clipboard writes, cursor moves that fake output) and control characters are shown as \e and \xNN instead of being run by the terminal. Tabs, newlines and carriage returns stay.

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:"-"`
	// Final: no flag lifts this stop (no --yes, --allow-dangerous or
	// --reveal), so an AI agent is not told that adding one asks the user
	Final bool `json:"-"`
	// contains filtered or unexported fields
}

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) Cancel added in v0.11.0

func (e *Error) Cancel(msg string) *Error

Cancel marks a stop the person chose at the terminal: text mode prints msg alone, without "Stopped:", a hint or the code.

func (*Error) Error

func (e *Error) Error() string

func (Error) MarshalJSON added in v0.9.0

func (e Error) MarshalJSON() ([]byte, error)

MarshalJSON writes the error with a hint even when the code that made it gave none: error.hint always says what to try next.

func (*Error) NoFlag added in v0.8.0

func (e *Error) NoFlag() *Error

NoFlag marks a stop that no flag lifts (see Final).

func (*Error) Say added in v0.11.0

func (e *Error) Say(msg, hint string) *Error

Say sets the words a person reads in text mode. JSON is unchanged, so agents and scripts keep the stable Message and Hint. An empty hint keeps the usual one.

func (*Error) TextHint added in v0.11.0

func (e *Error) TextHint() string

func (*Error) TextMessage added in v0.11.0

func (e *Error) TextMessage() string

TextMessage and TextHint are what text mode prints.

func (*Error) WithHint

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

type HostKey added in v0.8.0

type HostKey struct {
	Host        string `json:"host"`
	Address     string `json:"address"`
	Type        string `json:"key_type"`
	Fingerprint string `json:"fingerprint"` // SHA256:...
}

HostKey is a server's host key, as komando pinned it.

type Meta

type Meta struct {
	Contract   int    `json:"contract"`
	Version    string `json:"version"`
	DurationMS int64  `json:"duration_ms"`
	DryRun     bool   `json:"dry_run,omitempty"`
	// Skipped lists targets a selector picked that this command cannot work
	// with (a database picked by `exec @prod`, a server by `db query @prod`).
	Skipped []Skipped `json:"skipped,omitempty"`
	// WouldBeBlocked: under --dry-run, the safety stop the real run would hit
	WouldBeBlocked *Error `json:"would_be_blocked,omitempty"`
	// HostKeysPinned lists the servers whose host key this command trusted
	// for the first time (host_key_policy accept-new). Nothing proved the
	// key is the server's: compare the fingerprint with the server's own.
	HostKeysPinned []HostKey `json:"host_keys_pinned,omitempty"`
}

type Printer

type Printer struct {
	Format  string // json | text
	Pretty  bool
	Version string
	Start   time.Time
	DryRun  bool
	W       io.Writer

	// Secrets returns the secret values (by name) that must never appear in
	// output: remote files, logs and command output that happen to contain
	// one show [secret:NAME] instead. It is called once, on first use.
	Secrets  func() map[string]string
	NoRedact bool // `secret get --reveal`: a person asked for the value
	// Mask also hides values that look like passwords, keys and tokens
	// (mask.go). It is on for AI agents.
	Mask bool
	// Personal, with Mask, also hides personal data: email addresses,
	// phone numbers, card numbers and IBANs (personal.go). A command that
	// reads data from a target turns it on when the mask_personal setting
	// covers that target.
	Personal bool
	// contains filtered or unexported fields
}

Printer is configured once by the root command.

func (*Printer) Blocked added in v0.2.0

func (p *Printer) Blocked() *Error

Blocked is the stop WouldBlock recorded, or nil.

func (*Printer) Event

func (p *Printer) Event(v any)

Event emits one NDJSON line (--stream and follow modes).

func (*Printer) Fail

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

func (*Printer) HostKeyPinned added in v0.8.0

func (p *Printer) HostKeyPinned(k HostKey)

HostKeyPinned records a host key trusted on first use, for meta.host_keys_pinned (a person reads it on stderr).

func (*Printer) Print

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

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

func (*Printer) Redact added in v0.2.0

func (p *Printer) Redact(s string) string

Redact hides secret values in plain text.

func (*Printer) Reset added in v0.2.0

func (p *Printer) Reset()

Reset forgets what one command recorded (tests run many in one process).

func (*Printer) Skip added in v0.2.0

func (p *Printer) Skip(s Skipped)

Skip records a target the command leaves out. It is reported in meta.skipped, and on stderr in text mode. A command may resolve its target more than once (exec checks the OS mix first): the same target is listed once.

func (*Printer) View added in v0.3.0

func (p *Printer) View(s string) View

View hides in s what Redact hides, keeping track of where each value was.

func (*Printer) WouldBlock added in v0.2.0

func (p *Printer) WouldBlock(e *Error)

WouldBlock records, under --dry-run, the first safety stop the real run would hit (meta.would_be_blocked).

type Skipped added in v0.2.0

type Skipped struct {
	Name   string `json:"name"`
	Kind   string `json:"kind"` // host, or the conn kind (postgres, redis, ...)
	Reason string `json:"reason"`
}

type Texter

type Texter interface{ Text() string }

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

type View added in v0.3.0

type View struct {
	Text string
	// contains filtered or unexported fields
}

View is a text as output for an AI agent shows it (Printer.Redact), with the place of every hidden value in the original text. A command that edits what the agent saw (fs replace) works on Text and maps its edits back with Source, so neither its result nor its errors depend on a value the agent never saw.

func (View) Hidden added in v0.3.0

func (v View) Hidden(orig string) []string

Hidden returns the values of orig (the text v was made from) that v shows as labels, in order.

func (View) Masked added in v0.3.0

func (v View) Masked() bool

Masked reports whether v hides a value the agent does not know by name: a label other than a vault value's [secret:NAME].

func (View) Source added in v0.3.0

func (v View) Source(a, b int) (start, end int, ok bool)

Source maps Text[a:b] to the stretch of the original it shows. ok is false when a or b falls inside a label: the edit would cut a hidden value.

Jump to

Keyboard shortcuts

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