tools

package
v0.7.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: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSensitiveFile added in v0.7.0

func CheckSensitiveFile(m *ignore.SensitiveMatcher, path string, isDir bool) (bool, string, error)

CheckSensitiveFile rejects normalisation tricks, then applies ignore and case-folded sensitive checks.

func DescribeFlags added in v0.5.0

func DescribeFlags(flagged []string) string

DescribeFlags renders the advisory warnings shown in the approval preview.

func DescribeRedactions added in v0.5.0

func DescribeRedactions(hits []string) string

DescribeRedactions renders a note listing which secret patterns were masked.

func IsBlockedByIdentity added in v0.7.0

func IsBlockedByIdentity(set []os.FileInfo, info os.FileInfo) bool

IsBlockedByIdentity reports whether info is SameFile-equal to any entry in set.

func RedactToolOutput added in v0.7.0

func RedactToolOutput(output string) (string, []string)

RedactToolOutput masks credential-shaped values unconditionally. SECURITY: it is the transcript boundary.

func SensitiveIdentitySet added in v0.7.0

func SensitiveIdentitySet(root string, m *ignore.SensitiveMatcher) []os.FileInfo

SensitiveIdentitySet returns FileInfo of blocked files. SECURITY: hardlink aliases match by identity. Callers filter candidates by identity instead of by name.

func ValidatePath added in v0.4.0

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

ValidatePath ensures the requested path resolves inside the workspace root. Returns the absolute path.

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) SetInputReader added in v0.5.0

func (g *ApprovalGate) SetInputReader(r *bufio.Reader)

SetInputReader makes the gate read answers from r. Callers sharing the stream must pass their reader.

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 runs preview → approval → execute. 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. 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 shows a diff preview without modifying files.

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. 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 shows a diff preview without modifying files.

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 optionally provides a preview for approval before execution.

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) error

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
	// Guard redacts secrets and warns about sensitive paths in previews. May be nil.
	Guard *ShellGuard
}

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 ShellGuard added in v0.5.0

type ShellGuard struct {
	// SensitiveMatcher flags sensitive paths. May be nil; redaction still applies.
	SensitiveMatcher *ignore.SensitiveMatcher
	// RedactSecretOutput enables redaction of secret-shaped values in output.
	RedactSecretOutput bool
}

ShellGuard redacts secrets from shell output and warns about sensitive paths. It does not sandbox the shell. SECURITY: file tools stay confined via ValidatePath; the shell is advisory-only.

func (*ShellGuard) FlagSensitivePaths added in v0.5.0

func (g *ShellGuard) FlagSensitivePaths(command string) []string

FlagSensitivePaths returns sensitive paths referenced by a command for the approval preview. Advisory only.

func (*ShellGuard) RedactSecrets added in v0.5.0

func (g *ShellGuard) RedactSecrets(output string) (string, []string)

RedactSecrets masks secret-shaped values. With redaction disabled the text is unchanged.

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