contract

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 3 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 contract defines cchp's machine output: one JSON result object on stdout per run (or NDJSON lines for streams), stable error kinds and exit codes.

Index

Constants

View Source
const (
	ExitOK          = 0
	ExitInternal    = 1
	ExitUsage       = 2
	ExitAuth        = 3
	ExitPermission  = 4
	ExitNotFound    = 5
	ExitConflict    = 6
	ExitInvalid     = 7
	ExitBrowser     = 8
	ExitRateLimited = 9
	ExitServer      = 10
	ExitNotSent     = 11
	ExitUnknown     = 12
	ExitPolicy      = 13
	ExitNotSignedIn = 14
)

Exit codes. A run that fails always exits nonzero.

View Source
const (
	KindUsage          = "usage"
	KindInvalidInput   = "invalid_input"
	KindPolicy         = "policy"
	KindNotSignedIn    = "not_signed_in"
	KindUnauthorized   = "unauthorized"
	KindPermission     = "permission_denied"
	KindNotFound       = "not_found"
	KindConflict       = "conflict"
	KindValidation     = "validation"
	KindHumanCheck     = "human_verification_required"
	KindBrowserOnly    = "browser_session_required"
	KindRateLimited    = "rate_limited"
	KindServer         = "server_error"
	KindHTTP           = "http_error"
	KindNotSent        = "not_sent"
	KindUnknownOutcome = "unknown_outcome"
	KindInternal       = "internal"
)

Error kinds.

View Source
const (
	OutcomeApplied    = "applied"
	OutcomeNotApplied = "not_applied"
	OutcomeUnknown    = "unknown"
)

Outcomes of a mutation.

View Source
const SchemaVersion = 1

SchemaVersion changes only when an existing field changes meaning.

Variables

This section is empty.

Functions

func Write

func Write(w io.Writer, r *Result) error

Write prints one result object followed by a newline.

func WriteEvent

func WriteEvent(w io.Writer, e *Event) error

WriteEvent prints one NDJSON stream line.

Types

type DryRun

type DryRun struct {
	Method   string            `json:"method"`
	URL      string            `json:"url"`
	Headers  map[string]string `json:"headers"`
	Body     json.RawMessage   `json:"body,omitempty"`
	BodyText string            `json:"body_text,omitempty"`
	Policy   PolicyView        `json:"policy"`
}

DryRun is the request cchp would have sent.

type Error

type Error struct {
	Kind               string          `json:"kind"`
	Message            string          `json:"message"`
	Hint               string          `json:"hint,omitempty"`
	Code               int64           `json:"code,omitempty"`
	Detail             string          `json:"detail,omitempty"`
	RequiredPermission string          `json:"required_permission,omitempty"`
	ChallengeAction    string          `json:"challenge_action,omitempty"`
	Fields             []FieldError    `json:"fields,omitempty"`
	Retryable          bool            `json:"retryable"`
	Problem            json.RawMessage `json:"problem,omitempty"`
}

Error is the failure description.

type Event

type Event struct {
	Type      string          `json:"type"` // event
	Operation string          `json:"operation"`
	Seq       int             `json:"seq"`
	Event     string          `json:"event,omitempty"`
	ID        string          `json:"id,omitempty"`
	Data      json.RawMessage `json:"data"`
}

Event is one NDJSON stream line.

type Failure

type Failure struct {
	Err  Error
	Exit int
	// Status and RequestID are set when the server answered.
	Status    int
	RequestID string
	Outcome   string
}

Failure is an error that carries its contract kind and exit code.

func Fail

func Fail(kind string, exit int, format string, args ...any) *Failure

Fail builds a Failure.

func (*Failure) Error

func (f *Failure) Error() string

func (*Failure) WithHint

func (f *Failure) WithHint(format string, args ...any) *Failure

WithHint adds a hint.

type FieldError

type FieldError struct {
	Location string `json:"location"`
	Message  string `json:"message"`
}

FieldError points at one bad input value.

type FileOutput

type FileOutput struct {
	Path        string `json:"path"`
	Bytes       int64  `json:"bytes"`
	SHA256      string `json:"sha256"`
	ContentType string `json:"content_type,omitempty"`
}

FileOutput describes a downloaded file.

type Pagination

type Pagination struct {
	Pages      int    `json:"pages"`
	Items      int    `json:"items"`
	HasMore    bool   `json:"has_more"`
	NextCursor string `json:"next_cursor,omitempty"`
	NextPage   int    `json:"next_page,omitempty"`
	Total      *int64 `json:"total,omitempty"`
	Truncated  bool   `json:"truncated,omitempty"`
}

Pagination describes where a list stopped and how to continue.

type PolicyView

type PolicyView struct {
	Risk         string `json:"risk"`
	NeedsWrite   bool   `json:"needs_allow_write"`
	NeedsConfirm bool   `json:"needs_confirm"`
	NeedsSecret  bool   `json:"needs_secret_out"`
	Retry        bool   `json:"retry"`
	Classified   bool   `json:"classified"`
}

PolicyView explains what a real run would need.

type Result

type Result struct {
	SchemaVersion  int             `json:"schema_version"`
	OK             bool            `json:"ok"`
	Operation      string          `json:"operation,omitempty"`
	Status         int             `json:"status,omitempty"`
	RequestID      string          `json:"request_id,omitempty"`
	Data           json.RawMessage `json:"data,omitempty"`
	Pagination     *Pagination     `json:"pagination,omitempty"`
	Outcome        string          `json:"outcome,omitempty"`
	IdempotencyKey string          `json:"idempotency_key,omitempty"`
	Secret         *SecretOutput   `json:"secret,omitempty"`
	File           *FileOutput     `json:"file,omitempty"`
	Stream         *StreamSummary  `json:"stream,omitempty"`
	DryRun         *DryRun         `json:"dry_run,omitempty"`
	Error          *Error          `json:"error,omitempty"`
	Warnings       []string        `json:"warnings,omitempty"`
}

Result is the JSON object cchp prints on stdout.

type SecretOutput

type SecretOutput struct {
	Path   string   `json:"path"`
	Fields []string `json:"fields"`
}

SecretOutput says where one-time secrets went.

type StreamSummary

type StreamSummary struct {
	Events int    `json:"events"`
	Ended  string `json:"ended"` // max_events, deadline or server_closed
}

StreamSummary closes an NDJSON stream.

Jump to

Keyboard shortcuts

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