bashrun

package
v0.107.38 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyEnter = "\r"
	KeyEsc   = "\x1b"
	KeyTab   = "\t"
	KeyBS    = "\x7f"
	KeyUp    = "\x1b[A"
	KeyDown  = "\x1b[B"
	KeyRight = "\x1b[C"
	KeyLeft  = "\x1b[D"
)

Variables

View Source
var ChildMarkers = []string{"K_BRAIN=1", "K_BRAIN=1"}
View Source
var SecretEnvVars = []string{"K_BRAIN_BACKEND_TOKEN", "K_BRAIN_COMPUTER_TOKEN"}

SecretEnvVars are credentials handed to K-brain processes by their parent. They authenticate callers of the backend API (or of the computer helper) and must never reach commands the agent runs.

Functions

func Command added in v0.107.6

func Command(ctx context.Context, shell, command string) (*exec.Cmd, error)

Command shares quoting, encoding and exit status handling across process tools.

func DefaultShell

func DefaultShell() string

func KeyBytes

func KeyBytes(name string) string

func KillAll

func KillAll()

func ResolveShell added in v0.107.6

func ResolveShell(ctx context.Context, shell string) string

ResolveShell keeps explicit per-tool selection ahead of the session and platform default.

func ScrubEnv added in v0.107.13

func ScrubEnv(env []string) []string

ScrubEnv returns env without SecretEnvVars entries.

func SetMarkers

func SetMarkers(sessionID, model string)

func ShellName added in v0.107.6

func ShellName(shell string) string

func Spill

func Spill(output string) string

func UnsetSecretEnv added in v0.107.13

func UnsetSecretEnv()

UnsetSecretEnv removes SecretEnvVars from this process's environment, so every child started afterwards inherits an environment without them. Call it once the values have been read.

func WithShell

func WithShell(ctx context.Context, shell string) context.Context

func WithWorkingDir added in v0.103.0

func WithWorkingDir(ctx context.Context, dir string) context.Context

func WorkingDir added in v0.103.0

func WorkingDir(ctx context.Context) string

Types

type Detached added in v0.107.28

type Detached struct {
	Cmd     *exec.Cmd
	PID     int
	Started time.Time
	// contains filtered or unexported fields
}

Detached is a command Run handed over while it was still running. Its output keeps being drained; the new owner takes it over with Stream and reaps the command with Wait. Until Wait returns it stays tracked, so KillAll still stops it.

func (*Detached) Kill added in v0.107.28

func (d *Detached) Kill()

Kill stops the command and its process group.

func (*Detached) Output added in v0.107.28

func (d *Detached) Output() (string, int64)

Output is the bounded tail of what the command printed before Stream, and the total number of bytes it printed so far.

func (*Detached) Stream added in v0.107.28

func (d *Detached) Stream(w io.Writer) error

Stream writes everything the command printed so far to w, then sends its further output there as it arrives. Output that could not be kept (more than the in-memory tail when no spill file was available) is marked as missing.

func (*Detached) Wait added in v0.107.28

func (d *Detached) Wait() error

Wait waits for the command to exit and its output to be drained, and returns what exec.Cmd.Wait returned. It is safe to call more than once.

type Options

type Options struct {
	Command string

	Dir string

	Shell string

	Timeout time.Duration

	Interactive bool

	InactivityTimeout time.Duration

	OnOutput func(chunk string)

	// OnUpdate receives a bounded tail snapshot when output changes.
	OnUpdate func(outputTail string)

	OnAwaitInput func(secLeft int)

	Keys <-chan []byte

	Env []string

	Sandbox *sandbox.Policy

	// Detach, once it fires, makes Run return the running command as
	// Result.Detached instead of waiting for it. The command keeps its process
	// group and sandbox and no longer ends with ctx or Timeout. Interactive
	// commands ignore it.
	Detach <-chan struct{}
}

type Result

type Result struct {
	Output      string
	OutputFile  string
	OutputBytes int64

	Exit string

	// ExitCode is the status the command exited with, 0 included; nil when it
	// did not start, timed out, was cancelled or was killed by a signal.
	ExitCode *int

	TimedOut bool

	Killed bool

	Interactive bool

	// Detached is the still-running command Run handed over when Options.Detach
	// fired; the other fields then describe only what it printed so far.
	Detached *Detached
}

func Run

func Run(ctx context.Context, opts Options) Result

Jump to

Keyboard shortcuts

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