shell

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 12 Imported by: 0 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 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

View Source
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

func Tool

func Tool(cfg Config) tool.Tool

Tool returns the command tool. A nil Executor is a programming error and panics.

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.

func (Local) Run

func (l Local) Run(ctx context.Context, command string, out io.Writer) (int, error)

Run implements Executor.

Jump to

Keyboard shortcuts

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