Documentation
¶
Overview ¶
Package cli wires the command-line surface: Runefile resolution, the parse → analyze → run pipeline, task dispatch, and exit-code mapping.
Failure-hook capture for the MCP surface (spec 022 US1): hook stdout is collected in a dedicated masked buffer and delivered to agents as the fix-suggestion section of the tool result. Masking happens at the writer as bytes arrive, so it always precedes the size cap (FR-007).
Index ¶
- Constants
- func Analyze(opts Options, path string, jsonOut bool) error
- func BannerLine(th style.Theme, msg string) string
- func BannerMessage(err error) string
- func CodeFor(err error) int
- func LSP(opts Options, lspOpts LSPOptions) error
- func Log(opts Options, flags LogFlags) error
- func Run(opts Options, args []string) error
- func SandboxWorker(ctx context.Context) int
- func ServeMCP(opts Options, useHTTP bool, addr, tokenFile string) error
- func VersionCheck(opts Options, asJSON bool) error
- type CommandFailure
- type CompatibilityResult
- type Interrupted
- type LSPOptions
- type LogFlags
- type Options
- type TaskCandidate
- type TaskFailure
- type UsageError
- type ValidationError
Constants ¶
const ( ExitSuccess = 0 // all requested tasks succeeded ExitTaskFail = 1 // a task failed without a body exit code ExitUsage = 2 // usage error / no Runefile / unknown task / bad args ExitValidation = 3 // static parse/analyze error — nothing executed ExitInterrupt = 130 // interrupted (SIGINT) )
Exit codes (spec 001 contracts/cli.md FR-021; spec 028 contracts/exit-codes.md). A task body failure exits with the body's own code instead of a constant.
const ( // SandboxWorkerArg and SandboxProbeArg are the two internal ways to start // the binary. Neither can be a task name, which never starts with "-". SandboxWorkerArg = "--sandbox-worker" SandboxProbeArg = "--sandbox-probe" )
Variables ¶
This section is empty.
Functions ¶
func Analyze ¶ added in v0.3.0
Analyze statically analyzes the Runefile at path (or the discovered Runefile when path is empty) together with its transitive imports, printing diagnostics and running nothing (spec FR-023). It uses the shared analysis service, so its diagnostics are identical to what the language server publishes (FR-002).
Exit codes follow Rune's house scheme: 0 when there are no error-severity diagnostics, 3 (ValidationError) when there are, and 2 (UsageError) for a missing/unreadable Runefile or other discovery/IO failure.
func BannerLine ¶ added in v0.4.0
BannerLine formats one of Rune's "rune: <msg>" failure banners, emphasizing the prefix with the shared error role so failures are scannable by color in a long transcript (spec 014 C1). Only the prefix is styled: the message stays plain (and pre-masked where it embeds task output), so stripping ANSI recovers the exact plain bytes. It is the single definition of the banner shape, shared by the cycle/watch banners here and the top-level banner in cmd/rune.
func BannerMessage ¶ added in v0.4.0
BannerMessage returns the banner text for err, or "" when err must not produce a top-level banner: a ValidationError's diagnostics are already rendered by the pipeline, and a silent TaskFailure ([no-exit-message]) intentionally stays quiet. It is the single source of the suppression rule shared by the top-level (cmd/rune) and watch-loop banner paths.
func LSP ¶ added in v0.3.0
func LSP(opts Options, lspOpts LSPOptions) error
LSP starts the Rune language server over stdio (spec FR-011). stdout carries only JSON-RPC protocol messages; logs go to stderr or --log-file (FR-012). It executes nothing (FR-028).
func Log ¶ added in v0.10.0
Log prints the actions of the audit log of the Runefile found from the working directory, or of the one opts.File names.
func Run ¶
Run executes one CLI invocation. args is everything after the global flags: VAR=VALUE overrides interleaved with task names and their arguments.
The full pipeline (lex → parse → analyze → schedule → execute) is wired in run.go; this function resolves the Runefile and delegates.
func SandboxWorker ¶ added in v0.10.0
SandboxWorker is the binary's worker mode. It is started only by Rune, inside a sandbox, with the job and the result on two pipes.
func VersionCheck ¶ added in v0.3.0
VersionCheck implements `rune version --check [--json]`: it resolves the applicable Runefile, reads its minimum_version, and reports compatibility of the installed binary. It runs no task. When no Runefile or no requirement is present it reports "no requirement declared" (exit 0). An installed version that does not satisfy a valid requirement exits non-zero (ExitValidation).
Types ¶
type CommandFailure ¶ added in v0.8.0
type CommandFailure struct{ Err error }
CommandFailure marks a built-in command that could not do what was asked (exit 1). It is the non-task counterpart of TaskFailure: without it such an error would fall through to the usage exit code.
func (*CommandFailure) Error ¶ added in v0.8.0
func (e *CommandFailure) Error() string
func (*CommandFailure) Unwrap ¶ added in v0.8.0
func (e *CommandFailure) Unwrap() error
type CompatibilityResult ¶ added in v0.3.0
type CompatibilityResult struct {
Installed string `json:"installed"`
Required string `json:"required"` // empty when no requirement is declared
Compatible bool `json:"compatible"`
// Development is true when the installed version is not a recognized semantic
// version (a local "dev" build): the requirement is waved through rather than
// enforced, so a machine consumer can tell this apart from a genuine match.
Development bool `json:"development"`
Runefile string `json:"runefile"` // resolved path, empty when none found
}
CompatibilityResult is the machine-readable result of `rune version --check`.
type Interrupted ¶
type Interrupted struct{ Err error }
Interrupted marks a SIGINT (exit 130).
func (*Interrupted) Error ¶
func (e *Interrupted) Error() string
func (*Interrupted) Unwrap ¶
func (e *Interrupted) Unwrap() error
type LSPOptions ¶ added in v0.3.0
type LSPOptions struct {
LogFile string // path to write logs to; empty means stderr
LogLevel string // error|warn|info|debug (coarse for the MVP)
}
LSPOptions configures the language server started by LSP.
type LogFlags ¶ added in v0.10.0
type LogFlags struct {
Date string // --date
Since string // --since
Until string // --until
TZ string // --tz
// The list flags, each value possibly comma-separated.
Tasks []string // --task
Outcomes []string // --outcome
Clients []string // --client
Sessions []string // --session
All bool // --all
JSON bool // --json
Dir bool // --dir
// contains filtered or unexported fields
}
LogFlags are the flags of `rune log`, as the command line gave them.
type Options ¶
type Options struct {
File string // -f/--file
List bool // --list
DryRun bool // --dry-run
Summary bool // --summary
Dump bool // --dump
DumpFormat string // --format (with --dump)
Set []string
Watch bool
Choose bool
Yes bool
Quiet bool
Fmt bool
ClearCache bool
// IgnoreVersion bypasses the Runefile's minimum_version gate for this run
// (the CLI-only --ignore-version flag). It is never settable from a Runefile.
IgnoreVersion bool
// MCPAllowIgnoreVersion lets the MCP/agent server run despite an unmet
// minimum_version. It is an operator-only opt (a `rune serve` flag), disabled
// by default, and never settable from a Runefile.
MCPAllowIgnoreVersion bool
// MCPAllowDestructive holds the raw --allow-destructive values: the
// [confirm] tasks the operator lets agents run. It is an operator-only
// `rune serve` flag, never settable from a Runefile; ServeMCP splits and
// validates it (spec 031).
MCPAllowDestructive []string
// MCPAllow holds the raw --allow values: the tasks rune serve exposes
// as tools. Only ServeMCP reads it.
MCPAllow []string
// MCPDeny holds the raw --deny values: the tasks rune serve hides from
// agents. Only ServeMCP reads it.
MCPDeny []string
// MCPOutputLimit is the raw --output-limit value: the size that caps each
// of stdout and stderr in a tool result. Nil means the flag was not given,
// which an empty value is not. Only ServeMCP reads it (spec 042).
MCPOutputLimit *string
// AuditDir is RUNE_AUDIT_DIR: the directory the audit logs live under.
// Empty means the user's state directory. AuditRetention is the raw
// RUNE_AUDIT_RETENTION_DAYS. Servers and `rune log` read them (spec 052).
AuditDir string
AuditRetention string
// MCPSandbox is the raw --sandbox value: whether rune serve confines the
// tasks agents call. Nil means the flag was not given, and SandboxEnv
// decides. SandboxEnv is RUNE_SANDBOX, which the endpoint of an (agent)
// task reads as well. Neither is settable from a Runefile: a task could
// edit that (spec 053).
MCPSandbox *string
SandboxEnv string
// MCPNoReload is --no-reload: rune serve keeps the tasks it read at
// start and watches no file. Only ServeMCP reads it (spec 043).
MCPNoReload bool
// Resolved per-stream color decisions (see cmd/rune): ColorStdout gates
// --list and --help (which write to stdout); ColorStderr gates Rune's own
// messages — status/echo/cache lines and diagnostics — on stderr.
ColorStdout bool
ColorStderr bool
Version string
Cwd string
Ctx context.Context // cancelled on SIGINT (nil => Background)
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
// Commands are the reserved subcommand names (and aliases). They are used
// only to enrich the "unknown task" error with a did-you-mean suggestion.
Commands []string
}
Options carries the resolved global CLI flags and I/O streams for one invocation. main.go populates it from cobra and passes it to Run.
type TaskCandidate ¶
TaskCandidate is a completable task: its name plus the first line of its doc comment, used as the shell-completion description.
func TaskCandidates ¶
func TaskCandidates(opts Options) []TaskCandidate
TaskCandidates returns the non-private, OS-matching tasks of the resolved Runefile, each with its first doc line, for dynamic shell completion. It is deliberately tolerant: any failure (no Runefile, read error, parse/compose error) yields nil so completion degrades gracefully and never disrupts the shell session. The analyzer is intentionally skipped — task names should still complete when the Runefile has semantic (not syntactic) errors.
type TaskFailure ¶
TaskFailure marks a task failure. It exits with the wrapped body's exit code, or 1 when there is none. Silent suppresses the trailing error banner (the [no-exit-message] attribute) without changing the exit code.
func (*TaskFailure) Error ¶
func (e *TaskFailure) Error() string
func (*TaskFailure) Unwrap ¶
func (e *TaskFailure) Unwrap() error
type UsageError ¶
type UsageError struct{ Err error }
UsageError marks an error as a usage/discovery problem (exit 2).
func (*UsageError) Error ¶
func (e *UsageError) Error() string
func (*UsageError) Unwrap ¶
func (e *UsageError) Unwrap() error
type ValidationError ¶
type ValidationError struct{ Err error }
ValidationError marks a static parse/analyze failure (exit 3). The diagnostics have already been rendered to stderr by the caller; this type only carries the exit code intent.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error
Source Files
¶
- agentexec.go
- agentpolicy.go
- analyze.go
- args.go
- audit.go
- banner.go
- choose.go
- complete.go
- confirm.go
- contextprep.go
- dispatch.go
- dump.go
- exit.go
- failhook.go
- fmt.go
- log.go
- lsp.go
- masking.go
- mcp.go
- mcpreload.go
- planapply.go
- run.go
- sandbox.go
- sandboxexec.go
- sandboxexec_unix.go
- serve.go
- terminal.go
- version_check.go
- version_gate.go
- watch.go