coding

package
v0.97.8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package coding provides agent tools for terminal control, filesystem navigation, search, patching, web access, and code execution.

Index

Constants

View Source
const (
	// DefaultMaxOutput truncates tool result text beyond this byte count.
	DefaultMaxOutput = 8192
	// DefaultShellTimeout limits run_terminal and run_code execution.
	DefaultShellTimeout = 60 * time.Second
	// DefaultHTTPTimeout limits web_search and web_fetch HTTP calls.
	DefaultHTTPTimeout = 15 * time.Second

	// MaxReadFileBytes rejects read_file when the whole file exceeds this size.
	MaxReadFileBytes = 1 << 20
	// MaxWriteFileBytes rejects write_file content above this size.
	MaxWriteFileBytes = 1 << 20
	// MaxRunCodeBytes rejects run_code source above this size.
	MaxRunCodeBytes = 256 << 10
	// MaxWebSearchQueryBytes rejects web_search queries above this length.
	MaxWebSearchQueryBytes = 512
	// MaxWebSearchResults caps organic results returned by web_search.
	MaxWebSearchResults = 8

	// MaxListDirEntries caps list_dir result entries.
	MaxListDirEntries = 500
	// DefaultGlobMaxMatches is the default glob_files match cap.
	DefaultGlobMaxMatches = 200
	// HardGlobMaxMatches is the maximum allowed glob_files max_matches argument.
	HardGlobMaxMatches = 1000
	// DefaultGrepMaxMatches is the default grep_files hit cap.
	DefaultGrepMaxMatches = 100
	// HardGrepMaxMatches is the maximum allowed grep_files max_matches argument.
	HardGrepMaxMatches = 500
	// MaxGrepFileBytes skips grep_files files larger than this size.
	MaxGrepFileBytes = 1 << 20
	// MaxGrepFilesScanned caps how many files grep_files opens.
	MaxGrepFilesScanned = 2000
	// MaxPatchBytes rejects apply_patch payloads above this size.
	MaxPatchBytes = 1 << 20
	// MaxPatchFiles caps files touched by one apply_patch call.
	MaxPatchFiles = 20
	// MaxFetchBytes caps web_fetch response body bytes read.
	MaxFetchBytes = 1 << 20
)

Variables

View Source
var SkipDirNames = map[string]struct{}{
	".git":         {},
	"node_modules": {},
}

SkipDirNames are directory basenames skipped by recursive listing, glob, and grep.

Functions

func ActiveToolNames

func ActiveToolNames() []string

ActiveToolNames returns the default active coding tool names.

func ClampMaxMatches added in v0.97.8

func ClampMaxMatches(arg, defaultMax, hardMax int) int

ClampMaxMatches returns a positive match limit capped by hardMax, using defaultMax when arg is unset.

func MatchPath added in v0.97.8

func MatchPath(pattern, relativePath string) (bool, error)

MatchPath reports whether relativePath matches pattern. Patterns use forward slashes; ** matches any number of path segments.

func PatchFilePaths added in v0.97.8

func PatchFilePaths(patch string) []string

PatchFilePaths extracts relative file paths from a Codex-style patch for sensors and permissions.

func RedirectChecker added in v0.97.8

func RedirectChecker(allowLoopback bool, prev func(*http.Request, []*http.Request) error) func(*http.Request, []*http.Request) error

RedirectChecker returns an http.Client CheckRedirect that re-validates each redirect target.

func RegisterAll

func RegisterAll(registry *tool.Registry, ws Workspace, executionEnv env.ExecutionEnv) error

RegisterAll registers chat assistant tools on the registry.

func ShouldSkipDir added in v0.97.8

func ShouldSkipDir(name string) bool

ShouldSkipDir reports whether a directory basename should be skipped during walks.

Types

type ApplyPatchTool added in v0.97.8

type ApplyPatchTool struct {
	Workspace Workspace
	Env       env.ExecutionEnv
}

ApplyPatchTool applies an OpenAI/Codex-style patch inside the workspace.

func (ApplyPatchTool) Description added in v0.97.8

func (ApplyPatchTool) Description() string

Description explains the tool to the model.

func (ApplyPatchTool) Execute added in v0.97.8

Execute applies the patch with all-or-nothing semantics.

func (ApplyPatchTool) Name added in v0.97.8

func (ApplyPatchTool) Name() string

Name returns the tool identifier.

func (ApplyPatchTool) Parameters added in v0.97.8

func (ApplyPatchTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

type GlobFilesTool added in v0.97.8

type GlobFilesTool struct {
	Workspace Workspace
	Env       env.ExecutionEnv
}

GlobFilesTool finds files by path pattern inside the workspace.

func (GlobFilesTool) Description added in v0.97.8

func (GlobFilesTool) Description() string

Description explains the tool to the model.

func (GlobFilesTool) Execute added in v0.97.8

Execute runs the glob search.

func (GlobFilesTool) Name added in v0.97.8

func (GlobFilesTool) Name() string

Name returns the tool identifier.

func (GlobFilesTool) Parameters added in v0.97.8

func (GlobFilesTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

type GrepFilesTool added in v0.97.8

type GrepFilesTool struct {
	Workspace Workspace
	Env       env.ExecutionEnv
}

GrepFilesTool searches file contents with a regular expression.

func (GrepFilesTool) Description added in v0.97.8

func (GrepFilesTool) Description() string

Description explains the tool to the model.

func (GrepFilesTool) Execute added in v0.97.8

Execute runs the content search.

func (GrepFilesTool) Name added in v0.97.8

func (GrepFilesTool) Name() string

Name returns the tool identifier.

func (GrepFilesTool) Parameters added in v0.97.8

func (GrepFilesTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

type ListDirTool added in v0.97.8

type ListDirTool struct {
	Workspace Workspace
	Env       env.ExecutionEnv
}

ListDirTool lists directory entries inside the workspace.

func (ListDirTool) Description added in v0.97.8

func (ListDirTool) Description() string

Description explains the tool to the model.

func (ListDirTool) Execute added in v0.97.8

Execute lists directory contents.

func (ListDirTool) Name added in v0.97.8

func (ListDirTool) Name() string

Name returns the tool identifier.

func (ListDirTool) Parameters added in v0.97.8

func (ListDirTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

type ReadFileTool

type ReadFileTool struct {
	Workspace Workspace
	Env       env.ExecutionEnv
}

ReadFileTool reads file contents from the workspace.

func (ReadFileTool) Description

func (ReadFileTool) Description() string

Description explains the tool to the model.

func (ReadFileTool) Execute

Execute reads the requested file.

func (ReadFileTool) Name

func (ReadFileTool) Name() string

Name returns the tool identifier.

func (ReadFileTool) Parameters

func (ReadFileTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

type RunCodeTool

type RunCodeTool struct {
	Workspace Workspace
	Env       env.ExecutionEnv
}

RunCodeTool executes source code by writing a temporary file and invoking an interpreter.

func (RunCodeTool) Description

func (RunCodeTool) Description() string

Description explains the tool to the model.

func (RunCodeTool) Execute

func (t RunCodeTool) Execute(ctx context.Context, id string, args map[string]any, onUpdate tool.UpdateHandler) (msg.ToolResultMessage, error)

Execute runs the provided code snippet.

func (RunCodeTool) Name

func (RunCodeTool) Name() string

Name returns the tool identifier.

func (RunCodeTool) Parameters

func (RunCodeTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

type RunTerminalTool

type RunTerminalTool struct {
	Workspace Workspace
	Env       env.ExecutionEnv
}

RunTerminalTool executes shell commands inside the workspace.

func (RunTerminalTool) Description

func (RunTerminalTool) Description() string

Description explains the tool to the model.

func (RunTerminalTool) Execute

func (t RunTerminalTool) Execute(ctx context.Context, id string, args map[string]any, onUpdate tool.UpdateHandler) (msg.ToolResultMessage, error)

Execute runs the requested command.

func (RunTerminalTool) Name

func (RunTerminalTool) Name() string

Name returns the tool identifier.

func (RunTerminalTool) Parameters

func (RunTerminalTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

type WebFetchTool added in v0.97.8

type WebFetchTool struct {
	HTTPClient *http.Client
	MaxOutput  int
	// AllowLoopback permits localhost/loopback hosts (intended for tests).
	AllowLoopback bool
}

WebFetchTool downloads text content from an http(s) URL.

func (WebFetchTool) Description added in v0.97.8

func (WebFetchTool) Description() string

Description explains the tool to the model.

func (WebFetchTool) Execute added in v0.97.8

func (t WebFetchTool) Execute(ctx context.Context, id string, args map[string]any, onUpdate tool.UpdateHandler) (msg.ToolResultMessage, error)

Execute fetches the URL body.

func (WebFetchTool) Name added in v0.97.8

func (WebFetchTool) Name() string

Name returns the tool identifier.

func (WebFetchTool) Parameters added in v0.97.8

func (WebFetchTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

type WebSearchTool

type WebSearchTool struct {
	HTTPClient *http.Client
	MaxOutput  int
	// BaseURL overrides the DuckDuckGo HTML endpoint for tests.
	BaseURL string
	// InstantBaseURL overrides the DuckDuckGo Instant Answer endpoint for tests.
	InstantBaseURL string
	// SearxURL is a SearXNG-compatible JSON search endpoint (e.g. http://127.0.0.1:8080/search).
	SearxURL string
	// BraveAPIKey enables the Brave Search API when non-empty.
	BraveAPIKey string
	// BraveBaseURL overrides the Brave Search endpoint for tests.
	BraveBaseURL string
}

WebSearchTool searches the web via SearXNG, Brave, or DuckDuckGo HTML results.

func (WebSearchTool) Description

func (WebSearchTool) Description() string

Description explains the tool to the model.

func (WebSearchTool) Execute

func (t WebSearchTool) Execute(ctx context.Context, id string, args map[string]any, onUpdate tool.UpdateHandler) (msg.ToolResultMessage, error)

Execute performs the web search.

func (WebSearchTool) Name

func (WebSearchTool) Name() string

Name returns the tool identifier.

func (WebSearchTool) Parameters

func (WebSearchTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

type Workspace

type Workspace struct {
	// Root is the absolute workspace path.
	Root string
	// Timeout limits shell and code execution duration.
	Timeout time.Duration
	// MaxOutput truncates tool stdout/stderr beyond this byte count.
	MaxOutput int
	// WebSearchSearxURL is an optional SearXNG-compatible JSON search endpoint.
	WebSearchSearxURL string
	// WebSearchBraveAPIKey enables Brave Search when non-empty.
	WebSearchBraveAPIKey string
}

Workspace bounds file and shell operations to a single root directory.

func (Workspace) ResolvePath

func (w Workspace) ResolvePath(path string) result.Result[string, result.FileError]

ResolvePath maps a relative or absolute path into the workspace root.

func (Workspace) TruncateOutput

func (w Workspace) TruncateOutput(text string) string

TruncateOutput limits output size for model context safety.

type WriteFileTool

type WriteFileTool struct {
	Workspace Workspace
	Env       env.ExecutionEnv
}

WriteFileTool writes or overwrites a file in the workspace.

func (WriteFileTool) Description

func (WriteFileTool) Description() string

Description explains the tool to the model.

func (WriteFileTool) Execute

Execute writes the requested file.

func (WriteFileTool) Name

func (WriteFileTool) Name() string

Name returns the tool identifier.

func (WriteFileTool) Parameters

func (WriteFileTool) Parameters() map[string]any

Parameters returns the JSON schema for tool arguments.

Jump to

Keyboard shortcuts

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