Documentation
¶
Overview ¶
Package shell provides the built-in command tool shell: the model can run a command in the foreground and get its output, or run it in the background and receive the result as a notice in the session when it ends.
Where commands run is decided by an Executor: this package only provides Local, which runs on this machine; containers, remote sandboxes and so on are implemented by the business layer. Running commands hands the execution environment to the model, so production should run them in an isolated environment; use a WrapTool middleware when approval is needed.
Index ¶
Constants ¶
const ( // ToolName is the name of the command tool. ToolName = "shell" // TaskType is the tool.Task.Type of background commands. TaskType = "shell" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Executor is the execution environment of commands and is required.
Executor Executor
// Timeout is the default timeout of foreground commands, 2 minutes by default.
Timeout time.Duration
// MaxTimeout is the largest timeout the model may set for a foreground command, 10 minutes by default. Background commands have no timeout.
MaxTimeout time.Duration
}
Config configures the command tool.
type Details ¶
type Details struct {
Command string `json:"command"`
ExitCode int `json:"exit_code"`
TimedOut bool `json:"timed_out,omitempty"`
Duration time.Duration `json:"duration"`
}
Details are the Details of a command result: in the tool result for foreground commands, in the task snapshot for background ones.
type Executor ¶
type Executor interface {
// Run runs a command, writes stdout and stderr together to out, and returns the exit code.
// When ctx is canceled it must end the command and every child process it started, and return the ctx error.
Run(ctx context.Context, command string, out io.Writer) (exitCode int, err error)
}
Executor decides where commands run.
type Local ¶
type Local struct {
// Dir is the working directory every command starts in; empty means the working directory of the current process.
Dir string
// Env is appended to the environment of the current process, in KEY=VALUE form.
Env []string
// Shell is the shell that runs commands, passed with -c; bash by default.
Shell string
}
Local runs commands on this machine. It is only suited to development or trusted environments: commands have all the permissions of the current process. Each command runs in its own process group, so canceling or timing out also ends the child processes it started.