builtin

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 47 Imported by: 0

Documentation

Overview

Package builtin provides general-purpose tools modeled on those of coding agents such as Claude Code and Codex: file reading, writing and editing, patches, glob and grep search, shell commands, web fetching and a todo list.

File tools are confined to Config.Dir with os.Root, so paths cannot escape it through ".." or symbolic links. The bash tool is not confined unless Config.Sandbox is set: commands start in Config.Dir but can access anything the process can. write_file, edit_file, apply_patch and bash therefore require approval unless Config.NoApproval is set. With a sandbox, which NewSandbox builds from the operating system's Seatbelt or bubblewrap, bash commands run confined to the writable roots and allowed hosts without approval, and only commands that leave the sandbox need it.

The file-changing tools stage regular files in the same directory and replace them with os.Rename; per-file atomicity depends on the platform. Symbolic links are written through in place. Multi-file changes attempt rollback on failure but do not isolate changes from concurrent readers or writers. The tools return a unified diff of the change. With Config.History they first save the state of the files they change, so tracked files can be restored to a checkpoint; see History.

bash can run commands in the background; bash_output reads their output and kill_shell stops them. Close the tools when the agent is done.

web_fetch is read-only and does not require approval. By default it refuses loopback, private, link-local and shared addresses, including after redirects and, for direct connections, DNS changes; set Config.AllowPrivateNetwork to lift the restriction. Through a proxy from the environment, destinations are checked by name before each request only, since the proxy resolves them again. A Config.HTTPClient replaces these checks entirely.

Index

Constants

View Source
const (
	BackendSeatbelt   = "seatbelt"
	BackendBubblewrap = "bubblewrap"
)

Sandbox backends of NewSandbox.

View Source
const (
	TodoPending    = "pending"
	TodoInProgress = "in_progress"
	TodoCompleted  = "completed"
)

Todo statuses.

Variables

View Source
var ErrCheckpointNotFound = fmt.Errorf("file history: %w", loop.ErrCheckpointNotFound)

ErrCheckpointNotFound is returned for a file history checkpoint that does not exist or is no longer kept. It wraps loop.ErrCheckpointNotFound, so errors.Is matches either: check this error for file history only, or loop's for any checkpoint.

View Source
var ErrSandboxUnavailable = errors.New("sandbox unavailable")

ErrSandboxUnavailable reports that a sandbox cannot run commands on this system.

Functions

func ApplyPatch

func ApplyPatch(cfg Config) tool.Tool

ApplyPatch returns the apply_patch tool, which applies patches in the format of OpenAI's Codex, the format GPT models are trained to write. To providers that support freeform tools, such as the OpenAI Responses API, the tool is freeform, constrained by Codex's Lark grammar; others send the patch as the JSON argument "input".

Like Codex, the tool locates changes by their lines with decreasing strictness: exactly, ignoring trailing whitespace, ignoring surrounding whitespace, and treating typographic punctuation as ASCII. Unlike Codex it checks every operation, including Config.Files for files it updates, replaces or deletes, before it changes anything, and then commits all files together; if a step fails, the files it already changed are restored. The result lists the changed files and shows the diff of each file whose old content was changed.

func Bash

func Bash(cfg Config) tool.Tool

Bash returns the bash tool. Commands run with "bash -c" when bash is on PATH and with "sh -c" otherwise ("cmd /d /s /c" on Windows), starting in the working directory.

The command runs in its own process tree: a process group on Unix, a Job Object on Windows. When the shell exits or the timeout expires, the whole tree is killed, so processes it left in the background do not outlive the call. With Config.Shells set, the model can instead start a command with run_in_background, which returns a shell ID at once; BashOutput and KillShell, given the same Shells, read and stop it.

As in Claude Code, a cd carries over to later calls while it stays inside the working directory, symbolic links resolved; a command that ends elsewhere, or a directory that disappeared, resets the next command to the working directory and the result says "Shell cwd was reset to <dir>". The shell reports its final directory through descriptor 3 from an EXIT trap, so a command that replaces that trap, closes descriptor 3 or replaces the shell with exec leaves the directory unchanged. Changes made by background commands never carry over. Config.ResetDir starts every command in the working directory. On Windows, where cmd.exe has no exit trap, every command starts in the working directory.

Without Config.Sandbox, commands are not confined: they can access anything the process can, and every call needs approval unless Config.NoApproval is set. With a sandbox, commands, including background ones, run inside it and need no approval unless Config.AskSandboxed is set, like Claude Code's auto-allow sandbox mode. A command that fails because of the sandbox can be retried with the dangerously_disable_sandbox argument, which runs it outside the sandbox and always needs approval; Config.NoSandboxEscape removes that escape. Permission rules still apply on top: the argument can be matched as "Bash(dangerously_disable_sandbox:true)". When the sandbox is not available, Config.SandboxFallback either fails each command or runs it unsandboxed after approval. Info().RequiresApproval reports whether any call may need approval; bash implements tool.CallApprover for the decision of each call.

The tool implements io.Closer: Close stops the background commands of Config.Shells.

func BashOutput

func BashOutput(cfg Config) tool.Tool

BashOutput returns the bash_output tool, which reads the output a background command of Config.Shells wrote since the previous read, optionally only the lines matching a regular expression, and reports whether the command is running or how it ended. It needs no approval and may run concurrently with other calls, but it is not read-only: a read consumes the output it returns.

func Close

func Close(tools []tool.Tool) error

Close closes the tools that hold resources, such as bash, which stops its background commands. It returns the first error.

func DefaultProtectedNames

func DefaultProtectedNames() []string

DefaultProtectedNames returns the entries that stay read-only at the top of each writable root by default: those Codex protects (.git, .agents, .codex and .aws, whose profiles can name credential helpers) and Claude Code's .claude configuration directory.

func EditFile

func EditFile(cfg Config) tool.Tool

EditFile returns the edit_file tool. It makes one exact-text replacement, or several in order with the edits argument, and returns the diff. See the package documentation for replacement semantics.

func Glob

func Glob(cfg Config) tool.Tool

Glob returns the glob tool.

func Grep

func Grep(cfg Config) tool.Tool

Grep returns the grep tool.

func KillShell

func KillShell(cfg Config) tool.Tool

KillShell returns the kill_shell tool, which kills a background command of Config.Shells together with every process it started. It needs no approval: it can only stop commands the agent started.

func ReadFile

func ReadFile(cfg Config) tool.Tool

ReadFile returns the read_file tool.

func ReadOnlyTools

func ReadOnlyTools(cfg Config) []tool.Tool

ReadOnlyTools returns the tools without side effects: read_file, glob, grep and web_fetch. They suit research sub-agents. Pass the parent's Config.Files to let the parent edit files a sub-agent has read.

func TodoWrite

func TodoWrite(list *TodoList) tool.Tool

TodoWrite returns the todo_write tool, which replaces the items of list.

func Tools

func Tools(cfg Config) []tool.Tool

Tools returns all built-in tools: read_file, write_file, edit_file, apply_patch, glob, grep, bash, bash_output, kill_shell, web_fetch and todo_write. Config.Edit can leave out edit_file or apply_patch. Call Close with the tools when the agent is done, to stop the commands bash left running in the background.

func WebFetch

func WebFetch(cfg Config) tool.Tool

WebFetch returns the web_fetch tool. HTML is converted to plain text.

Without Config.HTTPClient, it refuses loopback, private, link-local and shared (CGNAT) addresses unless Config.AllowPrivateNetwork is set, and gives up on a fetch after 60 seconds. When the environment configures a proxy, destinations are checked by name before the request only; see publicClient.

func WriteFile

func WriteFile(cfg Config) tool.Tool

WriteFile returns the write_file tool. It replaces the file, keeping the permissions of an existing file, and returns the diff of an existing file's change. See the package documentation for replacement semantics.

Types

type ChangeKind

type ChangeKind string

ChangeKind is the kind of a file change.

const (
	// FileCreated is the creation of a file that did not exist.
	FileCreated ChangeKind = "created"
	// FileModified is a change to the content of a file.
	FileModified ChangeKind = "modified"
	// FileDeleted is the deletion of a file.
	FileDeleted ChangeKind = "deleted"
)

type Config

type Config struct {
	// Dir is the working directory. File tools are confined to it. The
	// default is the current directory.
	Dir string
	// HTTPClient is used by web_fetch instead of the default client, which
	// refuses non-public addresses. The caller is then responsible for
	// restricting the addresses it can reach.
	HTTPClient *http.Client
	// AllowPrivateNetwork lets the default web_fetch client reach loopback,
	// private, link-local and shared (CGNAT, 100.64.0.0/10) addresses.
	AllowPrivateNetwork bool
	// MaxOutput caps the bytes of a tool result. The default is 30000.
	MaxOutput int
	// CommandTimeout is the default bash timeout. The default is two
	// minutes; the model may request up to ten.
	CommandTimeout time.Duration
	// Env is added to the environment of bash commands.
	Env []string
	// Todos is the list updated by todo_write. If nil, Tools creates one.
	Todos *TodoList
	// Files tracks the files read_file has read. When set, write_file,
	// edit_file and apply_patch only change or delete an existing file
	// after it was read and while it is unchanged since. If nil, Tools
	// creates one; tools constructed individually without it do not check.
	Files *FileTracker
	// NoApproval lets write_file, edit_file, apply_patch and bash run
	// without approval.
	NoApproval bool
	// CheckRedirect, if set, is called before web_fetch follows a
	// redirect, after the client's own checks, with the arguments of
	// http.Client.CheckRedirect; an error stops the fetch and is reported
	// to the model. permission.Policy.CheckRedirect applies WebFetch
	// permission rules to redirects this way.
	CheckRedirect func(req *http.Request, via []*http.Request) error
	// Edit selects the editing tools Tools returns besides write_file.
	Edit EditStyle
	// History, if set, saves the state of files before write_file,
	// edit_file and apply_patch change them, so the files of a session can
	// be restored to a checkpoint with agent.Runner.Rewind. If a save
	// fails, the tool changes nothing. Changes made by bash are not
	// tracked. A FileHistory forgets the files it restores in Files.
	History History
	// Sandbox, if set, runs every bash command, foreground and
	// background, inside it; see NewSandbox. Sandboxed commands need no
	// approval unless AskSandboxed is set; commands that run outside it
	// always do. See Bash.
	Sandbox Sandbox
	// SandboxFallback decides what bash does when Sandbox is set but not
	// available: SandboxRequired, the default, fails the command, and
	// SandboxBestEffort runs it unsandboxed after approval.
	SandboxFallback SandboxFallback
	// AskSandboxed keeps approval for sandboxed bash commands unless
	// NoApproval is set, like Claude Code's regular-permissions sandbox
	// mode.
	AskSandboxed bool
	// NoSandboxEscape removes bash's dangerously_disable_sandbox argument,
	// like Claude Code's allowUnsandboxedCommands set to false, so
	// commands always run in the sandbox.
	NoSandboxEscape bool
	// Shells holds the commands bash runs in the background, which
	// bash_output reads and kill_shell stops. If nil, Tools creates one;
	// bash constructed individually without it offers no background
	// commands. Close it, or call Close with the tools, when the agent is
	// done.
	Shells *Shells
	// ResetDir starts every bash command in Dir. By default a cd carries
	// over to later commands while it stays inside Dir.
	ResetDir bool
}

Config configures the built-in tools.

type EditStyle

type EditStyle int

EditStyle selects the file-editing tools of Tools.

const (
	// EditAll returns edit_file and apply_patch, so each model can use the
	// format it was trained on: Claude models exact-text replacement, GPT
	// models Codex patches.
	EditAll EditStyle = iota
	// EditReplace returns only edit_file.
	EditReplace
	// EditPatch returns only apply_patch.
	EditPatch
)

type FileChange

type FileChange struct {
	// Checkpoint is the ID of the checkpoint the change belongs to.
	Checkpoint string `json:"checkpoint"`
	// Run and Turn identify the run, and its turn, that made the change;
	// for a sub-agent, the outermost run with a session.
	Run  string `json:"run,omitempty"`
	Turn int    `json:"turn,omitempty"`
	// Tool is the name of the tool that made the change. Restore records
	// the files' state before it as changes of the tool "rewind".
	Tool string `json:"tool,omitempty"`
	// Dir is the absolute working directory of the tool, and Path the
	// slash-separated path of the file relative to it.
	Dir  string     `json:"dir"`
	Path string     `json:"path"`
	Kind ChangeKind `json:"kind"`
	// From and To are those of the FileEdit.
	From string `json:"from,omitempty"`
	To   string `json:"to,omitempty"`

	// Existed reports whether the file existed before the change. Mode,
	// Size and Hash, the hex SHA-256 of the content, describe the file
	// then; Link is the target of a symbolic link.
	Existed bool        `json:"existed"`
	Mode    fs.FileMode `json:"mode,omitempty"`
	Size    int64       `json:"size,omitempty"`
	Hash    string      `json:"hash,omitempty"`
	Link    string      `json:"link,omitempty"`
	// Skipped, if set, says why the content was not saved, or, in a
	// Restoration, why the file was not restored.
	Skipped string `json:"skipped,omitempty"`

	Time time.Time `json:"time"`
	// Seq orders the changes of a session.
	Seq int64 `json:"seq"`
}

FileChange is a change a tool made to a file, with the state the file had before it.

type FileEdit

type FileEdit struct {
	// Path is the path of the file, relative to the tool's working
	// directory.
	Path string
	Kind ChangeKind
	// From and To are set for a file apply_patch moves: From on the file
	// it creates or replaces, To on the file it deletes.
	From, To string
}

FileEdit is a change a tool is about to make to a file.

type FileHistory

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

FileHistory is a History in a directory. File contents are stored once by their SHA-256, shared by all sessions, so a fork copies only the session's index:

<Dir>/objects/<2 hex digits>/<62 hex digits>   file contents
<Dir>/sessions/<session ID>.json              checkpoints and changes

Contents are checked against their hash before a restore. Files are written with mode 0600 in directories with mode 0700. A FileHistory assumes it is the only user of its directory. Its lock protects calls on this instance, not concurrent changes to the workspace files it tracks.

Restore forgets the restored files in the FileTracker of the tools built with the history, so the model must read them again before changing them.

func NewFileHistory

func NewFileHistory(cfg FileHistoryConfig) (*FileHistory, error)

NewFileHistory returns a history in cfg.Dir, creating it if needed.

func (*FileHistory) Checkpoint

func (h *FileHistory) Checkpoint(ctx context.Context, sessionID, id string) error

Checkpoint implements History. It also removes the oldest checkpoints beyond MaxCheckpoints and, at most once an hour, the histories of sessions beyond MaxAge, as Prune does.

func (*FileHistory) Checkpoints

func (h *FileHistory) Checkpoints(ctx context.Context, sessionID string) ([]HistoryCheckpoint, error)

Checkpoints implements History.

func (*FileHistory) Delete

func (h *FileHistory) Delete(ctx context.Context, sessionID string) error

Delete implements History. Contents no other session references are removed.

func (*FileHistory) Fork

func (h *FileHistory) Fork(ctx context.Context, from, to string) error

Fork implements History. The copy shares the stored contents.

func (*FileHistory) Prune

func (h *FileHistory) Prune(ctx context.Context) error

Prune removes the histories of sessions without changes for MaxAge, like Claude Code's retention sweep, and the contents no session references. Checkpoint runs it at most once an hour.

func (*FileHistory) Restore

func (h *FileHistory) Restore(ctx context.Context, sessionID, id string) (*Restoration, error)

Restore implements History. Files are restored like apply_patch commits a patch: staging regular files and, if a step fails, attempting to restore files already changed. Rollback errors are joined with the original error. A file is skipped, and reported in Restoration.Skipped, if its content was not saved or a symbolic link would have to be created or replaced; a symbolic link that still points to the same file is written through. Directories created since the checkpoint are left in place.

func (*FileHistory) Save

func (h *FileHistory) Save(ctx context.Context, tool, dir string, edits []FileEdit) error

Save implements History.

type FileHistoryConfig

type FileHistoryConfig struct {
	// Dir holds the history. The default is .agentx/history in the
	// current directory. Keep it out of the reach of the file tools, or
	// at least out of their working directory's version control.
	Dir string
	// MaxCheckpoints is the number of the most recent checkpoints kept
	// for each session; the default is 100, as in Claude Code. Older
	// checkpoints and their changes are removed.
	MaxCheckpoints int
	// MaxBytes bounds the total size of the file contents kept for each
	// session; the default is 1 GiB. The oldest checkpoints are removed
	// beyond it, except the latest.
	MaxBytes int64
	// MaxFileSize is the largest file whose content is saved; the default
	// is 16 MiB. Larger files are recorded but not restored.
	MaxFileSize int64
	// MaxAge is how long the history of a session is kept after its last
	// change; the default is 30 days, as in Claude Code.
	MaxAge time.Duration
}

FileHistoryConfig configures a FileHistory. Zero limits take their defaults; negative ones are unlimited.

type FileTracker

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

FileTracker remembers the files read_file has shown to the model, so write_file, edit_file and apply_patch can refuse to change or delete an existing file the model has not read, or one that changed after it was read. The zero value is ready to use, and a FileTracker is safe for concurrent use.

The check guards against changing a file from a stale view of it, not against concurrent writers: a file can still change between the check and the write.

type History

type History interface {
	// Save records the current state of files, named relative to dir,
	// which a call of the named tool is about to change. The session, run
	// and turn are those of the run executing the call, found with
	// loop.CallingRun; for the call of a nested run, such as a
	// sub-agent's, they are those of the outermost run with a session,
	// found with loop.Run.Caller. Outside a run with a session nothing
	// is saved. If no checkpoint of the session is named after the run,
	// Save starts one.
	Save(ctx context.Context, tool, dir string, edits []FileEdit) error
	// Checkpoint starts a checkpoint of a session, unless the latest one
	// has the same ID.
	Checkpoint(ctx context.Context, sessionID, id string) error
	// Checkpoints returns the checkpoints of a session that are kept,
	// oldest first, each with the changes saved after it and before the
	// next.
	Checkpoints(ctx context.Context, sessionID string) ([]HistoryCheckpoint, error)
	// Restore returns tracked files to their state at the checkpoint and
	// reports files it cannot restore in Restoration.Skipped. On failure it
	// attempts to undo changes already applied; rollback can also fail.
	// It returns ErrCheckpointNotFound for a checkpoint that is not kept.
	Restore(ctx context.Context, sessionID, id string) (*Restoration, error)
	// Fork copies the history of a session to a new session, so changes
	// saved for either later do not affect the other's.
	Fork(ctx context.Context, from, to string) error
	// Delete removes the history of a session.
	Delete(ctx context.Context, sessionID string) error
}

History keeps the state files had before the file tools changed them, so the files of a session can be restored to a checkpoint, like Claude Code's checkpointing (https://code.claude.com/docs/en/checkpointing). write_file, edit_file and apply_patch save to Config.History before each change. Changes made by bash, by other tools or outside the agent are not tracked.

A checkpoint marks a point in a session's history: agent.Runner starts one, named after the run's ID, before each run. Restoring a checkpoint returns every file changed since then to its state before the first change after the checkpoint.

Implementations must be safe for concurrent use.

type HistoryCheckpoint

type HistoryCheckpoint struct {
	ID   string
	Time time.Time
	// Changes are the changes saved after the checkpoint and before the
	// next one, oldest first.
	Changes []FileChange
}

HistoryCheckpoint is a checkpoint of a History.

type Restoration

type Restoration struct {
	// Files are the restored files, each in the state it was restored to.
	Files []FileChange
	// Skipped are files that were changed since the checkpoint but not
	// restored, with the reason in FileChange.Skipped.
	Skipped []FileChange
	// Undo is the ID of a checkpoint holding the state of the restored
	// files before the restore; restoring it undoes the restore. It is
	// empty if no file changed.
	Undo string
}

Restoration is the result of History.Restore.

type Sandbox

type Sandbox interface {
	// Available returns nil if the sandbox can run commands on this
	// system, or an error saying why it cannot. bash asks before every
	// command, to decide whether the command needs approval and whether to
	// apply Config.SandboxFallback, so it should be cheap.
	Available() error
	// Wrap rewrites cmd, which has not been started, to run inside the
	// sandbox. dir is the working directory of the tools, Config.Dir,
	// which the sandbox should let the command write to; cmd.Dir is where
	// the command starts. Wrap may change cmd.Path, cmd.Args, cmd.Env and
	// cmd.SysProcAttr, but must keep cmd's descriptors, including
	// cmd.ExtraFiles, and run its program with its arguments. It returns
	// an error wrapping ErrSandboxUnavailable if the sandbox cannot run
	// commands.
	Wrap(cmd *exec.Cmd, dir string) error
}

Sandbox confines the commands of the bash tool, foreground and background, at the operating-system level, so that what a command can write and reach no longer depends on what the model chose to run. See NewSandbox for the sandbox of the operating system; other implementations may run commands in a container or a virtual machine.

type SandboxFallback

type SandboxFallback int

SandboxFallback selects what bash does when Config.Sandbox is set but not available.

const (
	// SandboxRequired, the default, fails every command with an error
	// result naming the reason, so that a missing sandbox never widens
	// what commands can do. It matches Claude Code's failIfUnavailable
	// setting, applied per command.
	SandboxRequired SandboxFallback = iota
	// SandboxBestEffort runs commands without the sandbox, but only after
	// approval, even with Config.NoApproval.
	SandboxBestEffort
)

type SandboxPolicy

type SandboxPolicy struct {
	// WritableRoots are directories commands may write to besides the
	// working directory and the temporary directories. A root whose path
	// passes through a symbolic link inside a writable root is refused,
	// since a command could retarget the link and widen the next
	// command's access.
	WritableRoots []string
	// ReadableRoots, if set, restricts reading to them, the writable
	// roots and the system directories programs need to run. If empty,
	// commands may read everything except DenyRead.
	ReadableRoots []string
	// DenyRead are files and directories commands may neither read nor
	// write, such as "~/.ssh" or "~/.aws/credentials". On Linux only
	// paths that exist when the command starts are hidden.
	DenyRead []string
	// ProtectedNames are entries at the top of each writable root that
	// stay read-only, so commands cannot change version control state or
	// agent configuration. On macOS they are protected even when missing,
	// so commands cannot create them either; on Linux only existing ones
	// are. A ".git" file pointing to a git directory protects that
	// directory too. Nil means DefaultProtectedNames; an empty non-nil
	// slice protects nothing.
	ProtectedNames []string
	// NoTempDirs keeps the temporary directories, $TMPDIR and /tmp,
	// read-only.
	NoTempDirs bool
	// AllowNetwork gives commands full network access.
	AllowNetwork bool
	// AllowedDomains are hosts commands may reach, unless AllowNetwork is
	// set, through an HTTP proxy that the sandbox starts on the loopback
	// interface and announces in HTTP_PROXY, HTTPS_PROXY and ALL_PROXY.
	// The proxy forwards plain HTTP requests and HTTPS CONNECT tunnels to
	// allowed hosts and refuses the rest. An entry is a host name, "*."
	// and a domain for its subdomains, "*" for every host, or an IP
	// address, IPv6 in brackets, each optionally followed by ":port". A
	// host name that resolves only to loopback or link-local addresses,
	// or to an address of this machine, is refused unless it is
	// "localhost" or ends in ".localhost". Programs that ignore the proxy
	// variables, and traffic other than TCP, cannot reach the network. On
	// Linux the proxy is bridged into the sandbox with socat, which must
	// be on PATH.
	AllowedDomains []string
	// AllowLocalBinding lets commands on macOS listen on ports and talk to
	// servers on the loopback interface. On Linux commands always have a
	// loopback interface of their own, isolated from the host's, unless
	// AllowNetwork is set.
	AllowLocalBinding bool
}

SandboxPolicy describes what the commands in a sandbox of NewSandbox may access. The zero value lets commands read everything, write to the working directory and the temporary directories except the DefaultProtectedNames entries in them, and use no network.

Paths may start with "~/" for the home directory; other relative paths are relative to the working directory passed to Wrap.

type Shells

type Shells struct {
	// MaxRunning caps the background commands running at once; the
	// default is 8.
	MaxRunning int
	// MaxOutput caps the bytes of output kept per command; the oldest
	// output is dropped beyond it. The default is 1 MiB.
	MaxOutput int
	// contains filtered or unexported fields
}

Shells holds the commands bash runs in the background, which bash_output reads and kill_shell stops. The zero value is ready to use. Each command runs in its own process tree, like a foreground command, with its output kept in a bounded buffer. Close stops them all; call it when the agent is done, as background commands otherwise run until they exit or time out. A Shells is safe for concurrent use.

func (*Shells) Close

func (r *Shells) Close() error

Close kills the background commands and refuses new ones.

func (*Shells) Running

func (r *Shells) Running() []string

Running returns the IDs of the commands that are still running, sorted.

type SystemSandbox

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

SystemSandbox is the sandbox of the operating system: Seatbelt through sandbox-exec on macOS and bubblewrap on Linux. Create it with NewSandbox and Close it when done, which stops its proxy. It is safe for concurrent use and may be shared by several tool sets.

func NewSandbox

func NewSandbox(p SandboxPolicy) *SystemSandbox

NewSandbox returns the sandbox of the operating system with policy p: Seatbelt on macOS, through /usr/bin/sandbox-exec with a profile modeled on Codex's, and bubblewrap on Linux when bwrap is on PATH, with the mounts Codex's Linux sandbox uses. Elsewhere, or when the backend is missing or cannot create its sandbox, for example inside another sandbox, Available reports why and Wrap fails.

Landlock and seccomp filters are not used on Linux: the sandbox relies on bubblewrap's mount, user, PID, IPC and network namespaces alone. A command can therefore still connect to Unix sockets it can reach in the filesystem; the sockets of Docker, containerd, Podman and CRI-O are hidden unless the network is allowed, but others, such as a desktop session bus, are not. Hide them with DenyRead where that matters.

func (*SystemSandbox) Available

func (s *SystemSandbox) Available() error

Available reports whether the backend exists and can create a sandbox. The first call runs a trivial command in a sandbox to find out.

func (*SystemSandbox) Backend

func (s *SystemSandbox) Backend() string

Backend returns BackendSeatbelt, BackendBubblewrap or "" if the system has no backend.

func (*SystemSandbox) Close

func (s *SystemSandbox) Close() error

Close stops the proxy. Later commands are refused.

func (*SystemSandbox) DeniedHosts

func (s *SystemSandbox) DeniedHosts(since time.Time) []string

DeniedHosts returns the hosts, with ports, that the proxy refused since the given time, so that a command's result can name what the sandbox blocked. Hosts refused to concurrent commands are included too.

func (*SystemSandbox) Wrap

func (s *SystemSandbox) Wrap(cmd *exec.Cmd, dir string) error

Wrap rewrites cmd to run in the sandbox; see Sandbox.

type Todo

type Todo struct {
	Content string `json:"content" jsonschema:"What needs to be done, in imperative form."`
	Status  string `json:"status" jsonschema:"enum=pending,enum=in_progress,enum=completed,description=Current status of the item."`
}

Todo is an item of a TodoList.

type TodoList

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

TodoList is the task list maintained by the todo_write tool. The zero value is an empty list. It is safe for concurrent use, so applications can display it while an agent runs.

func (*TodoList) Items

func (l *TodoList) Items() []Todo

Items returns a copy of the current items.

func (*TodoList) Set

func (l *TodoList) Set(items []Todo)

Set replaces the items.

func (*TodoList) String

func (l *TodoList) String() string

String renders the list with [ ], [~] and [x] markers.

Jump to

Keyboard shortcuts

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