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
- Variables
- func DefaultHint(exit int) string
- func HasHidden(s string) bool
- func MaskPersonal(s string) string
- func MaskSecrets(s string) string
- func PersonalLabel(kind string) string
- func SafeText(s string) string
- type Envelope
- type Error
- func (e *Error) Cancel(msg string) *Error
- func (e *Error) Error() string
- func (e Error) MarshalJSON() ([]byte, error)
- func (e *Error) NoFlag() *Error
- func (e *Error) Say(msg, hint string) *Error
- func (e *Error) TextHint() string
- func (e *Error) TextMessage() string
- func (e *Error) WithHint(h string) *Error
- type HostKey
- type Meta
- type Printer
- func (p *Printer) Blocked() *Error
- func (p *Printer) Event(v any)
- func (p *Printer) Fail(command string, err error) int
- func (p *Printer) HostKeyPinned(k HostKey)
- func (p *Printer) Print(command string, data any, softErr *Error)
- func (p *Printer) Redact(s string) string
- func (p *Printer) Reset()
- func (p *Printer) Skip(s Skipped)
- func (p *Printer) View(s string) View
- func (p *Printer) WouldBlock(e *Error)
- type Skipped
- type Texter
- type View
Constants ¶
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.
const ( PersonalEmail = "email" PersonalPhone = "phone" PersonalCard = "card" PersonalIBAN = "iban" PersonalColumn = "column" )
Personal kinds, as they appear in [hidden: KIND].
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).
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.
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 ¶
Functions ¶
func DefaultHint ¶ added in v0.9.0
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
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
MaskPersonal hides email addresses, phone numbers, payment card numbers and IBANs in text.
func MaskSecrets ¶ added in v0.2.0
MaskSecrets hides secret-looking values in plain text.
func PersonalLabel ¶ added in v0.7.0
PersonalLabel is how a hidden value of kind looks.
func SafeText ¶ added in v0.2.0
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 (*Error) Cancel ¶ added in v0.11.0
Cancel marks a stop the person chose at the terminal: text mode prints msg alone, without "Stopped:", a hint or the code.
func (Error) MarshalJSON ¶ added in v0.9.0
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) Say ¶ added in v0.11.0
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) TextMessage ¶ added in v0.11.0
TextMessage and TextHint are what text mode prints.
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) HostKeyPinned ¶ added in v0.8.0
HostKeyPinned records a host key trusted on first use, for meta.host_keys_pinned (a person reads it on stderr).
func (*Printer) Print ¶
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) 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
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
View hides in s what Redact hides, keeping track of where each value was.
func (*Printer) WouldBlock ¶ added in v0.2.0
WouldBlock records, under --dry-run, the first safety stop the real run would hit (meta.would_be_blocked).
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
Hidden returns the values of orig (the text v was made from) that v shows as labels, in order.