tools

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidatePath added in v0.4.0

func ValidatePath(workspaceRoot, requestedPath string) (string, error)

ValidatePath ensures that the requested path resolves to a location within the workspace root. It converts relative paths to absolute, cleans them, evaluates symlinks, and rejects any path that escapes the workspace boundary.

Returns the cleaned absolute path if valid.

Types

type ApprovalGate

type ApprovalGate struct {
	OnPresent func(toolName string, args json.RawMessage, preview string) (bool, error)
	// contains filtered or unexported fields
}

func NewApprovalGate

func NewApprovalGate() *ApprovalGate

func NewApprovalGateWithPermissions added in v0.2.0

func NewApprovalGateWithPermissions(autoApprove, deny []string) *ApprovalGate

func (*ApprovalGate) IsAutoApproved added in v0.2.0

func (g *ApprovalGate) IsAutoApproved(toolName string) bool

func (*ApprovalGate) IsDenied added in v0.2.0

func (g *ApprovalGate) IsDenied(toolName string) bool

func (*ApprovalGate) RequestApproval

func (g *ApprovalGate) RequestApproval(toolName string, args json.RawMessage, preview string) (bool, error)

func (*ApprovalGate) SetPermissions added in v0.2.0

func (g *ApprovalGate) SetPermissions(autoApprove, deny []string)

func (*ApprovalGate) WrapExecution

func (g *ApprovalGate) WrapExecution(ctx context.Context, tool Tool, args json.RawMessage) (Result, error)

WrapExecution handles the full preview → approval → execute flow. If the tool implements Previewer, a preview is generated first and shown to the user before execution. Denied operations never call Execute.

type CodeSearchTool added in v0.4.0

type CodeSearchTool struct {
	IgnoreMatcher    ignore.Matcher
	SensitiveMatcher *ignore.SensitiveMatcher
	WorkspaceRoot    string
}

CodeSearchTool searches for patterns across workspace files.

func (*CodeSearchTool) Execute added in v0.4.0

func (c *CodeSearchTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)

func (*CodeSearchTool) RequiresApproval added in v0.4.0

func (c *CodeSearchTool) RequiresApproval() bool

func (*CodeSearchTool) Spec added in v0.4.0

func (c *CodeSearchTool) Spec() ToolSpec

type FilePatchTool

type FilePatchTool struct {
	IgnoreMatcher    ignore.Matcher
	SensitiveMatcher *ignore.SensitiveMatcher
	WorkspaceRoot    string
	OnModified       func(path string)
}

func (*FilePatchTool) Execute

func (f *FilePatchTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)

Execute applies the patch. This is called ONLY after approval.

func (*FilePatchTool) Preview added in v0.4.0

func (f *FilePatchTool) Preview(ctx context.Context, args json.RawMessage) (Preview, error)

Preview generates a diff preview of the proposed patch WITHOUT modifying any files. This is called before approval.

func (*FilePatchTool) RequiresApproval

func (f *FilePatchTool) RequiresApproval() bool

func (*FilePatchTool) Spec

func (f *FilePatchTool) Spec() ToolSpec

type FileReadTool

type FileReadTool struct {
	IgnoreMatcher    ignore.Matcher
	SensitiveMatcher *ignore.SensitiveMatcher
	WorkspaceRoot    string
}

func (*FileReadTool) Execute

func (f *FileReadTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)

func (*FileReadTool) RequiresApproval

func (f *FileReadTool) RequiresApproval() bool

func (*FileReadTool) Spec

func (f *FileReadTool) Spec() ToolSpec

type FileWriteTool

type FileWriteTool struct {
	IgnoreMatcher    ignore.Matcher
	SensitiveMatcher *ignore.SensitiveMatcher
	WorkspaceRoot    string
	OnModified       func(path string)
}

func (*FileWriteTool) Execute

func (f *FileWriteTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)

Execute writes the file. This is called ONLY after approval.

func (*FileWriteTool) Preview added in v0.4.0

func (f *FileWriteTool) Preview(ctx context.Context, args json.RawMessage) (Preview, error)

Preview generates a diff preview of the proposed change WITHOUT modifying any files. This is called before approval.

func (*FileWriteTool) RequiresApproval

func (f *FileWriteTool) RequiresApproval() bool

func (*FileWriteTool) Spec

func (f *FileWriteTool) Spec() ToolSpec

type Preview added in v0.4.0

type Preview struct {
	Description string `json:"description,omitempty"`
	Diff        string `json:"diff,omitempty"`
	Command     string `json:"command,omitempty"`
	WorkDir     string `json:"work_dir,omitempty"`
}

Preview contains the information shown to the user before approval.

func (Preview) String added in v0.4.0

func (p Preview) String() string

type Previewer added in v0.4.0

type Previewer interface {
	Preview(ctx context.Context, args json.RawMessage) (Preview, error)
}

Previewer is an optional interface that tools can implement to provide a preview of the proposed change before execution. This enables the approval-before-execution flow where the user sees a diff/command preview and approves before any filesystem changes are made.

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Get

func (r *Registry) Get(name string) Tool

func (*Registry) List

func (r *Registry) List() []string

func (*Registry) Register

func (r *Registry) Register(t Tool)

func (*Registry) Specs

func (r *Registry) Specs() []ToolSpec

type Result

type Result struct {
	Output string `json:"output,omitempty"`
	Error  string `json:"error,omitempty"`
	Diff   string `json:"diff,omitempty"`
}

func (Result) String

func (r Result) String() string

type ShellExecTool

type ShellExecTool struct {
	Timeout        time.Duration
	WorkspaceRoot  string
	MaxOutputBytes int
}

func (*ShellExecTool) Execute

func (s *ShellExecTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)

func (*ShellExecTool) Preview added in v0.4.0

func (s *ShellExecTool) Preview(ctx context.Context, args json.RawMessage) (Preview, error)

Preview returns command execution metadata without running the command.

func (*ShellExecTool) RequiresApproval

func (s *ShellExecTool) RequiresApproval() bool

func (*ShellExecTool) Spec

func (s *ShellExecTool) Spec() ToolSpec

type Tool

type Tool interface {
	Spec() ToolSpec
	Execute(ctx context.Context, args json.RawMessage) (Result, error)
	RequiresApproval() bool
}

type ToolSpec

type ToolSpec struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters"`
}

Jump to

Keyboard shortcuts

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