exec

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 11 Imported by: ? 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 exec runs the user's "!<command>" shell escape.

It is deliberately small and terminal-free: parsing, authority gating, and process execution are pure enough to unit-test without a TUI. The interactive layer owns presentation; this package owns the contract of what an escape is and how it runs. It is the process-execution seam the TUI is wired to, so a test can substitute a stub for the shell.

Index

Constants

View Source
const EscapePrefix = '!'

EscapePrefix is the character that opens a shell escape.

View Source
const MaxOutput = 256 * 1024

MaxOutput is the default byte cap on captured output. A command that emits more is truncated at a rune boundary and flagged, so a runaway stream can never grow the transcript without bound.

Variables

This section is empty.

Functions

func ParseEscape

func ParseEscape(line string) (command string, ok bool)

ParseEscape reports whether line is a shell escape and returns the command that follows the leading "!".

Leading spaces and tabs before the "!" are tolerated so a stray indent does not silently turn an escape back into a model prompt; a line whose first non-space rune is anything else is not an escape. A line that is exactly "!" parses as an escape with an empty command, which the caller reports as a syntax hint rather than feeding an empty string to the shell.

Types

type Action

type Action int

Action is how an escape command may proceed under the active authority.

const (
	// Run executes the command immediately.
	Run Action = iota
	// Confirm asks the user before executing.
	Confirm
)

func Decide

func Decide(mode string, mutating bool) Action

Decide classifies an escape command under an authority mode.

BUILD and FUZZ are execution authorities, so the fallback path does not ask for a confirmation. That is not a mutation licence: the caller still applies the authority-derived read-only boundary when it runs the command. This helper exists for a host with no security gate installed (tests), and only decides whether a prompt is needed.

type EscapeResult

type EscapeResult struct {
	// Command is the raw command as typed, without the leading "!".
	Command string
	// Output is the combined stdout and stderr, in arrival order.
	Output string
	// ExitCode is the process exit status, or -1 when it is unknown.
	ExitCode int
	// Duration is the measured wall-clock execution time.
	Duration time.Duration
	// Truncated reports that Output was capped at the runner's limit.
	Truncated bool
}

EscapeResult is the outcome of one executed escape command.

type ShellRunner

type ShellRunner struct {
	// Dir is the working directory for every command. Empty uses the
	// process's own working directory.
	Dir string
	// Shell overrides the shell program. Empty auto-detects: "/bin/sh" when
	// present, else "sh" (cmd on Windows).
	Shell string
	// MaxOutput caps captured bytes. Zero means MaxOutput.
	MaxOutput int
	// ReadOnly runs the command behind the platform's read-only workspace
	// boundary. It is set from the authority decision, never from the command
	// text: a human escape in ASK or FUZZ may read the repository but cannot
	// change it, whatever program the command names.
	ReadOnly bool
}

ShellRunner executes escape commands in a working directory.

The zero value is usable: it runs in the process's own directory through the platform's default shell with the default output cap.

func (ShellRunner) Run

func (r ShellRunner) Run(ctx context.Context, command string, onChunk func(string)) (EscapeResult, error)

Run executes command, invoking onChunk for each chunk of output as it arrives; onChunk may be nil.

A non-zero exit is reported in the result, not as an error: a command that fails is a result to render, not a failure to report. An error is returned only when the process could not start or was killed by cancellation or timeout, in which case the caller should treat the attempt as aborted.

onChunk is called synchronously from the writer goroutines, so it must be quick and must not call back into the runner. Chunks arrive in the same order they are appended to Output.

Jump to

Keyboard shortcuts

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