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 HasHidden(s string) bool
- func MaskSecrets(s string) string
- func SafeText(s string) string
- type Envelope
- type Error
- 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) 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) WouldBlock(e *Error)
- type Skipped
- type Texter
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 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 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.
Variables ¶
Functions ¶
func HasHidden ¶ added in v0.2.0
HasHidden reports whether text holds a value komando hid from an agent ([hidden] or [secret:NAME]). Such text must not be written to a file.
func MaskSecrets ¶ added in v0.2.0
MaskSecrets hides secret-looking values in plain text.
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:"-"`
}
Error is a typed error carrying a stable code, an exit code and a hint that tells the agent how to recover.
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"`
}
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
// 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
// contains filtered or unexported fields
}
Printer is configured once by the root command.
func (*Printer) Print ¶
Success 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.
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).