Documentation
¶
Overview ¶
Package execctx answers one question: who is running this command, and what can they see?
Every decision about interactivity, colour, output format and login transport derives from a single Context value that is detected once, at startup, and then never re-derived. The alternative, which is to ask "is this a TTY?" and "is this CI?" separately at each call site, is how inconsistencies creep in: one command prompts in CI, another emits colour into a pipe, a third opens a browser inside a container.
The rules below are therefore pure functions of Context. They take no arguments beyond the context, do no I/O, and are exhaustively unit-tested as a truth table. If a new behaviour depends on the environment, it becomes a method here rather than an `if` somewhere else.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Formats = []Format{FormatAuto, FormatText, FormatJSON, FormatNDJSON}
Formats is every value --output accepts, in the order the help lists them.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// RequestedFormat is what --output asked for, or FormatAuto if the flag
// was not given. Resolve it with Format().
RequestedFormat Format
// StdoutTTY and StdinTTY report whether each stream is attached to a
// terminal. StdinTTY matters on its own: it is the difference between a
// human who can answer a prompt and a process that cannot.
StdoutTTY bool
StdinTTY bool
// CI reports a continuous integration environment.
CI bool
// AgentHarness names the AI coding agent driving this invocation, or is
// empty. Detection is by environment variable presence, never by value,
// and additionally requires stdin not to be a terminal, so that a stale
// export in someone's shell profile cannot misclassify a human sitting at
// a keyboard.
AgentHarness string
// NoColour is set by --no-color, NO_COLOR, or TERM=dumb.
NoColour bool
// Quiet suppresses everything except errors.
Quiet bool
// AssumeYes is --yes. It acknowledges a reversible mutation. It is
// deliberately not sufficient for a destructive one; see CanAutoApprove.
AssumeYes bool
}
Context describes the environment a single invocation runs in.
It is a plain value. Copy it freely; nothing here is a handle to anything.
func Detect ¶
func Detect() Context
Detect builds a Context from the process environment. It is called exactly once, from main, before any command runs.
func (Context) CanAutoApprove ¶
CanAutoApprove reports whether a mutation may proceed without a human confirming it in this moment.
Reversible writes are allowed through with --yes, and are allowed through unattended, because refusing them would make the CLI useless in CI.
Destructive operations are never auto-approved, by anyone, ever. They exit 4 with a replayable command instead, which pushes the decision to whoever is actually accountable: a human at a terminal, a CI approval gate, or an agent harness's permission prompt. A client-side flag is not a safety boundary, because an agent that read our documentation can emit any flag we define.
func (Context) CanOpenBrowser ¶
CanOpenBrowser reports whether a browser-based login can be attempted.
The failure mode this guards against is specific and bad: the browser flow creates a real, full-power token before delivering it, so an attempt that cannot complete leaves a live credential belonging to nobody. When in doubt, we print paste instructions instead.
func (Context) Format ¶
Format resolves the effective output format.
An explicit --output always wins. Otherwise a terminal gets text and anything else gets JSON, so that `outplane app list | jq` works without the caller remembering a flag.
func (Context) Interactive ¶
Interactive reports whether the CLI may ask a question and wait for an answer. It requires a terminal on both ends: a prompt written to a pipe is invisible, and a prompt with no keyboard behind it is a hang.
CI and agent harnesses are excluded even when a pseudo-terminal is present, because in both cases nobody is watching.
func (Context) Machine ¶
Machine reports whether output is structured rather than prose.
It is derived from the resolved format alone, deliberately. An earlier version also returned true whenever stdout was not a terminal, which made `outplane app list -o text | less` produce JSON: an explicit request was silently overruled by an inference. Format() already handles the inference, so consulting the terminal a second time can only ever contradict it.
Colour and spinners are governed by NoColour, not by this, because those depend on the terminal even when the format is text.
type Format ¶
type Format string
Format is how results are encoded.
const ( // FormatAuto resolves to Text on a terminal and JSON when piped. It is the // default so that a human gets a table and a script gets parseable output // without either having to ask. FormatAuto Format = "auto" FormatText Format = "text" FormatJSON Format = "json" FormatNDJSON Format = "ndjson" )
func ParseFormat ¶
ParseFormat validates what --output was given.
An unrecognised value is an error rather than a fallback to text. A fallback is the worst of both: `--output jsonl` would print a table and exit 0, so a consumer parsing stdout as JSON fails on data that looks like a result, and a person reading the exit code concludes the command worked.