{"modulePath":"github.com/outplane/cli","version":"v0.2.17","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package execctx\n\nPackage execctx answers one question: who is running this command, and what can they see?\n\nEvery 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.\n\nThe 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.\n\n## Variables\n\n```go\nvar Formats = []Format{FormatAuto, FormatText, FormatJSON, FormatNDJSON}\n```\nFormats is every value --output accepts, in the order the help lists them.\n\n## Types\n\n```go\ntype Context struct {\n\t// RequestedFormat is what --output asked for, or FormatAuto if the flag\n\t// was not given. Resolve it with Format().\n\tRequestedFormat Format\n\n\t// StdoutTTY and StdinTTY report whether each stream is attached to a\n\t// terminal. StdinTTY matters on its own: it is the difference between a\n\t// human who can answer a prompt and a process that cannot.\n\tStdoutTTY bool\n\tStdinTTY  bool\n\n\t// CI reports a continuous integration environment.\n\tCI bool\n\n\t// AgentHarness names the AI coding agent driving this invocation, or is\n\t// empty. Detection is by environment variable presence, never by value,\n\t// and additionally requires stdin not to be a terminal, so that a stale\n\t// export in someone's shell profile cannot misclassify a human sitting at\n\t// a keyboard.\n\tAgentHarness string\n\n\t// NoColour is set by --no-color, NO_COLOR, or TERM=dumb.\n\tNoColour bool\n\n\t// Quiet suppresses everything except errors.\n\tQuiet bool\n\n\t// AssumeYes is --yes. It acknowledges a reversible mutation. It is\n\t// deliberately not sufficient for a destructive one; see CanAutoApprove.\n\tAssumeYes bool\n}\n```\nContext describes the environment a single invocation runs in.\n\nIt is a plain value. Copy it freely; nothing here is a handle to anything.\n\n```go\nfunc Detect() Context\n```\nDetect builds a Context from the process environment. It is called exactly once, from main, before any command runs.\n\n```go\nfunc (c Context) CanAutoApprove(destructive bool) bool\n```\nCanAutoApprove reports whether a mutation may proceed without a human confirming it in this moment.\n\nReversible writes are allowed through with --yes, and are allowed through unattended, because refusing them would make the CLI useless in CI.\n\nDestructive 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.\n\n```go\nfunc (c Context) CanOpenBrowser() bool\n```\nCanOpenBrowser reports whether a browser-based login can be attempted.\n\nDeliberately not Interactive(). That answers a different question, which is whether the CLI may print a prompt and wait for a keypress, and it excludes agent harnesses because they hand out a pseudo-terminal with no keyboard behind it. Nothing here is typed: the console mints the token when somebody presses Approve and posts it straight to a loopback listener. Borrowing the keyboard rule cost an agent the one step of a first deployment it could otherwise have finished, and sent the person off to another window.\n\nWhat still has to hold is that a browser opened on this machine can reach that listener, which is what the rest of these checks are about. An agent in a container is refused for the same reason an SSH session is, and the reason is not that it is an agent.\n\n```go\nfunc (c Context) Format() Format\n```\nFormat resolves the effective output format.\n\nAn 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.\n\n```go\nfunc (c Context) Interactive() bool\n```\nInteractive 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.\n\nCI and agent harnesses are excluded even when a pseudo-terminal is present, because in both cases nobody is watching.\n\n```go\nfunc (c Context) Machine() bool\n```\nMachine reports whether output is structured rather than prose.\n\nIt 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.\n\nColour and spinners are governed by NoColour, not by this, because those depend on the terminal even when the format is text.\n\n```go\ntype Format string\n```\nFormat is how results are encoded.\n\n```go\nconst (\n\t// FormatAuto resolves to Text on a terminal and JSON when piped. It is the\n\t// default so that a human gets a table and a script gets parseable output\n\t// without either having to ask.\n\tFormatAuto Format = \"auto\"\n\n\tFormatText   Format = \"text\"\n\tFormatJSON   Format = \"json\"\n\tFormatNDJSON Format = \"ndjson\"\n)\n```\n\n```go\nfunc ParseFormat(s string) (Format, bool)\n```\nParseFormat validates what --output was given.\n\nAn 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.\n\n","path":"github.com/outplane/cli/internal/execctx","name":"execctx","synopsis":"Package execctx answers one question: who is running this command, and what can they see?","isRedistributable":true}
