output

package
v1.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package output defines the shared CLI response contract for agent-friendly output modes.

Index

Constants

View Source
const (
	CodeError                 = "error"
	CodeUsage                 = "usage_error"
	CodeOutputMode            = "invalid_output_mode"
	CodeProjectNotFound       = "project_not_found"
	CodeMissingTool           = "missing_tool"
	CodeInvalidExtension      = "invalid_extension"
	CodeInvalidInertiaAdapter = "invalid_inertia_adapter"
	CodeUnsafeAction          = "unsafe_action_requires_confirmation"
	CodeGenerationFailed      = "generation_failed"
	CodeExternalCommandFailed = "external_command_failed"
	CodeConfigError           = "config_error"
	CodeAmbiguousInput        = "ambiguous_input"
	ExitUsage                 = 1
	ExitProject               = 2
	ExitDependency            = 3
	ExitUnsafe                = 4
	ExitGeneration            = 5
	ExitExternal              = 6
	ExitConfig                = 7
	ExitAmbiguous             = 8
)

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode returns the process exit code for an error.

func OK

func OK(cmd *cobra.Command, data any, summary string, breadcrumbs ...Breadcrumb) error

OK renders a successful response using the selected output mode.

func RegisterPersistentFlags

func RegisterPersistentFlags(cmd *cobra.Command)

RegisterPersistentFlags adds the shared agent-friendly output flags.

func RenderError

func RenderError(cmd *cobra.Command, err error) error

RenderError renders a failed response using the selected output mode.

func SuppressesHumanOutput

func SuppressesHumanOutput(opts Options) bool

SuppressesHumanOutput reports whether command progress from lower-level routines should be hidden before rendering the final response.

func UsesStructuredOutput

func UsesStructuredOutput(opts Options) bool

UsesStructuredOutput reports whether a command should render through the shared output contract instead of human prose.

Types

type Breadcrumb struct {
	Command     string `json:"cmd"`
	Description string `json:"description,omitempty"`
}

Breadcrumb is a follow-up action an agent or human can take.

type CLIError

type CLIError struct {
	Code     string
	Message  string
	Hint     string
	ExitCode int
	Cause    error
}

CLIError is a typed command error with a stable machine-readable code.

func NewError

func NewError(code, message string, exitCode int, hint string) *CLIError

NewError creates a typed CLI error.

func WrapError

func WrapError(code string, cause error, exitCode int, hint string) *CLIError

WrapError creates a typed CLI error while preserving the wrapped cause.

func (*CLIError) Error

func (e *CLIError) Error() string

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

type Envelope

type Envelope struct {
	OK          bool         `json:"ok"`
	Data        any          `json:"data,omitempty"`
	Summary     string       `json:"summary,omitempty"`
	Breadcrumbs []Breadcrumb `json:"breadcrumbs,omitempty"`
}

Envelope wraps successful structured command output.

type ErrorEnvelope

type ErrorEnvelope struct {
	OK       bool   `json:"ok"`
	Code     string `json:"code"`
	Error    string `json:"error"`
	Hint     string `json:"hint,omitempty"`
	ExitCode int    `json:"exit_code,omitempty"`
}

ErrorEnvelope wraps failed structured command output.

func Fail

func Fail(err error) ErrorEnvelope

Fail converts any error into a structured error envelope.

type Mode

type Mode string

Mode is the selected output format for a command invocation.

const (
	ModeHuman    Mode = "human"
	ModeJSON     Mode = "json"
	ModeAgent    Mode = "agent"
	ModeMarkdown Mode = "markdown"
)

type Options

type Options struct {
	Mode    Mode
	Quiet   bool
	JQ      string
	IDsOnly bool
	Count   bool
	Verbose bool
}

Options are parsed from the root persistent output flags.

func ParseOptions

func ParseOptions(cmd *cobra.Command) (Options, error)

ParseOptions returns output options from command flags.

Jump to

Keyboard shortcuts

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