builtins

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package builtins provides built-in tools available to all agents.

Index

Constants

View Source
const (
	// MaxOutputLines is the maximum number of lines returned by tool output.
	MaxOutputLines = 2000
	// MaxOutputBytes is the maximum size of tool output in bytes.
	MaxOutputBytes = 50 * 1024

	// Relaxed limits apply when the context carries tools.WithRelaxedLimits
	// (compression enabled): a destructive tool-side cut would otherwise
	// destroy data before the compression hook can shrink it losslessly.
	// 16x mirrors the agent loop's pre-hook safety ceiling multiplier; the
	// loop still bounds everything downstream.
	RelaxedMaxOutputLines = MaxOutputLines * 16
	RelaxedMaxOutputBytes = MaxOutputBytes * 16
)

Variables

This section is empty.

Functions

func All

func All(opts ...Options) []tools.Tool

All returns all built-in tools. Accepts zero or one Options value; extra Options are ignored (variadic for backward-compat only — callers should pass at most one).

func CodeAgentReadTools

func CodeAgentReadTools(workDir string) []tools.Tool

CodeAgentReadTools returns read-only coding tools (file_read + search).

func CodeAgentSearchTools

func CodeAgentSearchTools(workDir string) []tools.Tool

CodeAgentSearchTools returns search/exploration tools (grep, glob, tree). These are safe read-only tools for exploring codebases.

func CodeAgentTools

func CodeAgentTools(workDir string) []tools.Tool

CodeAgentTools returns all coding agent tools (read + write).

func CodeAgentWriteTools

func CodeAgentWriteTools(workDir string) []tools.Tool

CodeAgentWriteTools returns write/execute tools.

func FileTools added in v0.17.1

func FileTools(workDir string) []tools.Tool

FileTools returns the general file read/write/edit/patch builtins, path-confined to workDir via a PathValidator (the same #235 confinement the search tools use). These are the general-agent counterpart to the code-agent skill's project-scoped code_agent_* tools (#268): the runtime registers them for a general agent so it has a real file read-back / edit / overwrite surface, not just search + file_create.

func GetByName

func GetByName(name string) tools.Tool

GetByName returns a built-in tool by name, or nil if not found.

func MimeFromExtension

func MimeFromExtension(ext string) string

MimeFromExtension returns the MIME type for a given file extension. Returns empty string if the extension is not in the allowlist.

func NewMemoryGetTool

func NewMemoryGetTool(mgr *memory.Manager) tools.Tool

NewMemoryGetTool creates a memory_get tool backed by a Manager. This tool is registered conditionally (not via All()) since it needs a Manager instance.

func NewMemorySearchTool

func NewMemorySearchTool(mgr *memory.Manager) tools.Tool

NewMemorySearchTool creates a memory_search tool backed by a Manager. This tool is registered conditionally (not via All()) since it needs a Manager instance.

func NewScheduleDeleteTool

func NewScheduleDeleteTool(store scheduler.ScheduleStore, reloader ScheduleReloader) tools.Tool

NewScheduleDeleteTool creates a schedule_delete tool for removing schedules.

func NewScheduleHistoryTool

func NewScheduleHistoryTool(store scheduler.ScheduleStore) tools.Tool

NewScheduleHistoryTool creates a schedule_history tool for viewing execution history.

func NewScheduleListTool

func NewScheduleListTool(store scheduler.ScheduleStore) tools.Tool

NewScheduleListTool creates a schedule_list tool for listing schedules.

func NewScheduleSetTool

func NewScheduleSetTool(store scheduler.ScheduleStore, reloader ScheduleReloader) tools.Tool

NewScheduleSetTool creates a schedule_set tool for creating/updating schedules.

func RegisterAll

func RegisterAll(reg *tools.Registry, opts ...Options) error

RegisterAll registers all built-in tools with the given registry. Same variadic-Options convention as All(); pass at most one.

func RegisterCodeAgentReadTools

func RegisterCodeAgentReadTools(reg *tools.Registry, workDir string) error

RegisterCodeAgentReadTools registers only the read-only coding tools.

func RegisterCodeAgentSearchTools

func RegisterCodeAgentSearchTools(reg *tools.Registry, workDir string) error

RegisterCodeAgentSearchTools registers search/exploration tools.

func RegisterCodeAgentTools

func RegisterCodeAgentTools(reg *tools.Registry, workDir string) error

RegisterCodeAgentTools registers all coding agent tools with the given registry.

func RegisterCodeAgentWriteTools

func RegisterCodeAgentWriteTools(reg *tools.Registry, workDir string) error

RegisterCodeAgentWriteTools registers the write/execute coding tools.

func RegisterFileTools added in v0.17.1

func RegisterFileTools(reg *tools.Registry, workDir string) error

RegisterFileTools registers the general file read/write/edit/patch builtins (#268), confined to workDir.

func SafeSkillJoin added in v0.17.0

func SafeSkillJoin(skillDir, rel string) (string, error)

SafeSkillJoin joins a skill-relative path onto the skill directory and confines the result to that directory — rejecting absolute paths, `..` traversal, AND symlinks that resolve outside the skill. The symlink check matters because a skill package ships whatever the author writes (COPY . .): a bundled symlink like `skills/owl/leak -> /etc/shadow` passes a purely-textual guard (no `..`, not absolute) but `os.ReadFile` / the script interpreter would follow it out of the skill dir. Same confinement posture as read_skill's traversal guard and cli_execute's workdir confinement.

func SkillDir added in v0.17.0

func SkillDir(workDir, name string) (string, bool)

SkillDir resolves a skill's loadable name to its on-disk directory (`<workDir>/skills/<dir>`), matching read_skill's resolution: the directory name (and its underscore->hyphen variant) first, then the frontmatter `name` of any subdirectory skill (normalized for case and separator drift). Returns ("", false) for an unknown name or a flat single-file skill (which has no companion directory). Shared with the run_skill_script tool so skill-relative reads and executions resolve the same skill dir.

func TruncateOutput

func TruncateOutput(s string) string

TruncateOutput truncates a string to MaxOutputLines and MaxOutputBytes, appending a truncation notice if the output was trimmed.

func TruncateOutputCtx added in v0.17.0

func TruncateOutputCtx(ctx context.Context, s string) string

TruncateOutputCtx is TruncateOutput with context-aware limits: relaxed (16x) when compression is enabled, standard otherwise.

Types

type Options added in v0.17.0

type Options struct {
	// HTTPCredentialInjector, when non-nil, is wired into the
	// http_request tool so per-call JIT credentials become request
	// headers. Zero value → no JIT injection.
	HTTPCredentialInjector *credentials.Injector
}

Options configures which optional per-tool integrations are wired when constructing the builtin tools. Governance R9 uses this to attach the JIT credential injector to http_request; future options (per-tool tracing, per-tool rate limits) belong here too so the public All() / RegisterAll() surface stays a small set of variadic entry points.

type PathValidator

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

PathValidator provides path confinement to a working directory. All resolved paths are guaranteed to be within workDir.

func NewPathValidator

func NewPathValidator(workDir string) *PathValidator

NewPathValidator creates a PathValidator for the given working directory.

func (*PathValidator) Resolve

func (v *PathValidator) Resolve(path string) (string, error)

Resolve converts a relative or absolute path to an absolute path within workDir. It returns an error if the resolved path escapes the working directory.

func (*PathValidator) WorkDir

func (v *PathValidator) WorkDir() string

WorkDir returns the absolute working directory.

type ReadSkillTool

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

ReadSkillTool reads a skill's SKILL.md file on demand. This enables lazy-loading: the LLM only loads full skill instructions when it decides a skill is relevant.

func NewReadSkillTool

func NewReadSkillTool(workDir string) *ReadSkillTool

NewReadSkillTool creates a read_skill tool rooted at the given working directory.

func (*ReadSkillTool) Category

func (t *ReadSkillTool) Category() tools.Category

func (*ReadSkillTool) Description

func (t *ReadSkillTool) Description() string

func (*ReadSkillTool) Execute

func (t *ReadSkillTool) Execute(_ context.Context, args json.RawMessage) (string, error)

func (*ReadSkillTool) InputSchema

func (t *ReadSkillTool) InputSchema() json.RawMessage

func (*ReadSkillTool) Name

func (t *ReadSkillTool) Name() string

type ScheduleReloader

type ScheduleReloader interface {
	Reload(ctx context.Context)
}

ScheduleReloader is the interface for reloading the scheduler after changes.

Jump to

Keyboard shortcuts

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