shell

package
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 15 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

Index

Constants

View Source
const (
	ShellName  = "Shell"
	OutputName = "ShellOutput"
	KillName   = "KillShell"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type JobEvent

type JobEvent struct {
	Kind JobEventKind
	Job  JobInfo
	// Output chunk on output events
	Data []byte
}

What changed about a background job

type JobEventKind

type JobEventKind string
const (
	JobStarted  JobEventKind = "started"
	JobOutput   JobEventKind = "output"
	JobFinished JobEventKind = "finished"
)

type JobInfo

type JobInfo struct {
	ID          string
	CallID      string
	Line        string
	Description string
	Dir         string
	Started     time.Time
	Finished    time.Time
	Running     bool
	ExitCode    int
	TimedOut    bool
	// Bytes of output produced so far
	Bytes int64
}

Snapshot of one background job

type Jobs

type Jobs struct {
	// contains filtered or unexported fields
}

Table of background jobs keyed by id

type Options

type Options struct {
	// Starting directory, the process working directory when empty
	Dir string
	// KEY=VALUE pairs layered over the environment the shell starts with
	Env []string
	// Run allowed a command the model names no timeout for, unlimited when zero
	Timeout time.Duration
	// Largest timeout the model may ask for, any when zero
	MaxTimeout time.Duration
	// Receives every background job start, output chunk and finish
	OnJob func(JobEvent)
}

Settings shared by the shell tools

type Output

type Output struct {
	ExitCode int
	// Exit code of every stage of the last pipeline the command ran, empty when it ran none
	Pipeline []int
	// Command name of every stage of that pipeline
	Commands []string
	Dir      string
	TimedOut bool
	// The command ended the shell with exit
	Exited   bool
	Duration time.Duration
}

How a command ended, with the working directory it left behind

type Run

type Run struct {
	Command     string
	Description string
	Dir         string
	ExitCode    int
	Pipeline    []int
	TimedOut    bool
	// The command ended the shell with exit and the next call starts a fresh one
	Exited   bool
	Duration time.Duration
	Stdout   string
	Stderr   string
}

Structured outcome of a foreground Shell call

type Shell

type Shell struct {
	// contains filtered or unexported fields
}

Shell state shared by Shell, ShellOutput and KillShell

func New

func New(o Options) (*Shell, error)

Starts the shell in the configured directory

func (*Shell) Close

func (s *Shell) Close()

Stops every background job, then the shell with everything it started

func (*Shell) Command

func (s *Shell) Command() tool.Tool

Tool that runs a command line in the shell, foreground or as a background job

func (*Shell) Dir

func (s *Shell) Dir() string

Working directory the next command starts in

func (*Shell) Fork

func (s *Shell) Fork(ctx context.Context, line string, stdout, stderr io.Writer, timeout time.Duration) Output

Fork runs a command line beside the agent's shell, on a copy of it as it stands with the same directory and environment, so a long scan never queues behind the agent's own Shell calls and the agent never waits behind it

func (*Shell) Job

func (s *Shell) Job(id string) (JobInfo, bool)

Snapshot of one background job

func (*Shell) Jobs

func (s *Shell) Jobs() []JobInfo

Background jobs started so far, oldest first

func (*Shell) Kill

func (s *Shell) Kill() tool.Tool

Tool that stops a running background job

func (*Shell) KillJob

func (s *Shell) KillJob(ctx context.Context, id string) error

Stops a running job and waits for it to end

func (*Shell) Output

func (s *Shell) Output() tool.Tool

Tool that returns the output a background job produced since the previous call

func (*Shell) RunWith

func (s *Shell) RunWith(ctx context.Context, line string, stdout, stderr io.Writer, timeout time.Duration) Output

RunWith runs a command line with explicit writers and timeout on the shell itself, so it waits behind whatever the agent has running. Extensions that must not queue behind the agent use Fork instead

func (*Shell) StartJob

func (s *Shell) StartJob(callID, description, line string, timeout time.Duration) (string, error)

StartJob runs line as a background job on a copy of the shell as it stands, the way the Shell tool does, and reports its id so ShellOutput, KillShell and Wait take it

func (*Shell) Tail

func (s *Shell) Tail(id string, from int64) (data []byte, next int64, dropped int64, ok bool)

Output of a job from an absolute offset without moving the cursor the model reads with

func (*Shell) Tools

func (s *Shell) Tools() []tool.Tool

Every shell tool sharing this state

func (*Shell) Wait

func (s *Shell) Wait(id string) (<-chan struct{}, bool)

Channel closed when the job finishes

Jump to

Keyboard shortcuts

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