Documentation
¶
Index ¶
- Constants
- Variables
- func Command(ctx context.Context, shell, command string) (*exec.Cmd, error)
- func DefaultShell() string
- func KeyBytes(name string) string
- func KillAll()
- func ResolveShell(ctx context.Context, shell string) string
- func ScrubEnv(env []string) []string
- func SetMarkers(sessionID, model string)
- func ShellName(shell string) string
- func Spill(output string) string
- func UnsetSecretEnv()
- func WithShell(ctx context.Context, shell string) context.Context
- func WithWorkingDir(ctx context.Context, dir string) context.Context
- func WorkingDir(ctx context.Context) string
- type Detached
- type Options
- type Result
Constants ¶
const ( KeyEnter = "\r" KeyEsc = "\x1b" KeyTab = "\t" KeyBS = "\x7f" KeyUp = "\x1b[A" KeyDown = "\x1b[B" KeyRight = "\x1b[C" KeyLeft = "\x1b[D" )
Variables ¶
var ChildMarkers = []string{"K_BRAIN=1", "K_BRAIN=1"}
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
Command shares quoting, encoding and exit status handling across process tools.
func DefaultShell ¶
func DefaultShell() string
func ResolveShell ¶ added in v0.107.6
ResolveShell keeps explicit per-tool selection ahead of the session and platform default.
func SetMarkers ¶
func SetMarkers(sessionID, model 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 WithWorkingDir ¶ added in v0.103.0
func WorkingDir ¶ added in v0.103.0
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
Output is the bounded tail of what the command printed before Stream, and the total number of bytes it printed so far.
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
// Stdin, when set, is fed to a non-interactive command's standard input;
// otherwise the command reads from the null device. Interactive commands
// ignore it.
Stdin io.Reader
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
}