tools

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDoneTool

func NewDoneTool(signal *DoneSignal) tool.ToolDef

NewDoneTool returns a ToolDef for the done tool bound to signal. When Execute is called the summary is stored on signal and Done is set to true.

Types

type CmdHook

type CmdHook struct {
	Name  string
	Match func(subcommand string, exitCode int) bool
	Run   func(projectDir string) string
}

CmdHook runs after go_cmd produces a non-zero exit code. Name is the key used in CmdResult.Hooks. Match decides whether this hook applies. Run returns output to add to the hooks map.

type CmdResult

type CmdResult struct {
	Stdout   string            `json:"stdout"`
	Stderr   string            `json:"stderr"`
	ExitCode int               `json:"exit_code"`
	Hooks    map[string]string `json:"hooks,omitempty"`
}

CmdResult is a JSON-serializable command execution result used by go_cmd and git_cmd.

type Config

type Config struct {
	// BashTimeout is the default execution timeout for the bash tool.
	// If zero, a 30-second default is applied.
	BashTimeout time.Duration
}

Config carries tool-level configuration for the registry builder.

type DomainTools

type DomainTools struct {
	InspectProjectTool tool.ToolDef
}

DomainTools holds project-level domain tools.

func NewDomainTools

func NewDomainTools(projectDir string) DomainTools

NewDomainTools constructs domain tools bound to projectDir.

type DoneSignal

type DoneSignal struct {
	Done    bool
	Summary string
	Files   []string // paths modified during this session (relative to project dir)
}

DoneSignal is populated by the done tool when the agent signals completion. The caller inspects Done, Summary, and Files after the loop exits.

func Build

func Build(projectDir string, cfg Config) ([]tool.ToolDef, *DoneSignal, error)

Build instantiates all tools bound to projectDir and returns them as a slice alongside a DoneSignal that the caller can inspect after the loop exits.

The standard tool set is AST-first: ast and rewrite for Go source files, read_file for non-Go files (config, markdown, YAML), write_file for creating or overwriting files. All Go toolchain and git operations go through go_cmd and git_cmd respectively.

Tools that modify files (write_file, edit_file, rewrite) track their changes in a manifest. After the loop exits, DoneSignal.Files contains the list of modified paths.

type FSTools

type FSTools struct {
	ReadTool  tool.ToolDef
	WriteTool tool.ToolDef
	EditTool  tool.ToolDef
	ListTool  tool.ToolDef
}

FSTools holds the file-system ToolDefs bound to a project directory.

func NewFSTools

func NewFSTools(projectDir string, manifest *Manifest, hooks *HookRegistry) FSTools

NewFSTools constructs FSTools bound to projectDir. Every path argument is resolved through sandbox.Resolve before any OS call. The manifest tracks files modified by write_file and edit_file. Hooks run after successful writes/edits (nil hooks is safe).

type FileHook

type FileHook struct {
	Pattern string
	Run     func(absPath, projectDir string) string
}

FileHook runs after a file is successfully written or edited. Pattern is a glob matched against filepath.Base(relPath). Run receives the absolute path and project directory. Returns output to append to the tool result ("" = silent).

type GitCmdTools

type GitCmdTools struct {
	GitCmdTool tool.ToolDef
}

GitCmdTools holds the git_cmd ToolDef bound to a project directory.

func NewGitCmdTool

func NewGitCmdTool(projectDir string, defaultTimeout time.Duration) GitCmdTools

NewGitCmdTool constructs GitCmdTools bound to projectDir.

type GoASTTools

type GoASTTools struct {
	InspectTool tool.ToolDef
	RewriteTool tool.ToolDef
}

GoASTTools holds the AST-aware ToolDefs bound to a project directory.

func NewGoASTTools

func NewGoASTTools(projectDir string, manifest *Manifest) GoASTTools

NewGoASTTools constructs GoASTTools bound to projectDir. The manifest tracks files modified by the rewrite tool.

type GoCmdTools

type GoCmdTools struct {
	GoCmdTool tool.ToolDef
}

GoCmdTools holds the go_cmd ToolDef bound to a project directory.

func NewGoCmdTool

func NewGoCmdTool(projectDir string, defaultTimeout time.Duration, hooks *HookRegistry) GoCmdTools

NewGoCmdTool constructs GoCmdTools bound to projectDir. Hooks run after failed commands (nil hooks is safe).

type HookRegistry

type HookRegistry struct {
	FileHooks []FileHook
	CmdHooks  []CmdHook
}

HookRegistry holds file and command hooks.

func NewDefaultHookRegistry

func NewDefaultHookRegistry(projectDir string) *HookRegistry

NewDefaultHookRegistry creates a HookRegistry with the standard hooks: - *.go files: gofmt -w (silent on success, reports syntax errors) - go.mod: go mod tidy (silent on success, reports errors) - build/test/vet failure: gopls check ./... (if gopls on PATH)

func (*HookRegistry) RunCmdHooks

func (hr *HookRegistry) RunCmdHooks(subcommand string, exitCode int, projectDir string) map[string]string

RunCmdHooks runs all matching command hooks and returns a map of name->output. Nil-safe: returns nil if hr is nil or no hooks matched.

func (*HookRegistry) RunFileHooks

func (hr *HookRegistry) RunFileHooks(relPath, absPath, projectDir string) string

RunFileHooks runs all file hooks matching relPath and returns aggregated output. Nil-safe: returns "" if hr is nil.

type LSPTools

type LSPTools struct {
	DiagnosticsTool tool.ToolDef
	DefinitionTool  tool.ToolDef
}

LSPTools holds gopls-based ToolDefs bound to a project directory.

func NewLSPTools

func NewLSPTools(projectDir string, timeout time.Duration) LSPTools

NewLSPTools constructs LSPTools bound to projectDir.

type Manifest

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

Manifest tracks files modified by tool execution. It is shared across write_file, edit_file, and rewrite tools.

func NewManifest

func NewManifest() *Manifest

NewManifest creates an empty file manifest.

func (*Manifest) Files

func (m *Manifest) Files() []string

Files returns the deduplicated list of modified file paths.

func (*Manifest) Track

func (m *Manifest) Track(path string)

Track records a file path as modified.

type SearchTools

type SearchTools struct {
	GrepTool tool.ToolDef
	GlobTool tool.ToolDef
}

SearchTools holds the grep and glob ToolDefs bound to a project directory.

func NewSearchTools

func NewSearchTools(projectDir string) SearchTools

NewSearchTools constructs SearchTools bound to projectDir. Every path argument is resolved through sandbox.Resolve before any OS call.

Jump to

Keyboard shortcuts

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