localtools

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 39 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

View Source
const DenyMessage = "User denied the operation. Please ask for clarification or try a different, less destructive approach."
View Source
const LocalFSToolsName = "local_fs"
View Source
const WebToolsName = "webtools"

Variables

View Source
var (
	ErrMCPSessionUnavailable    = errors.New("mcp session unavailable")
	ErrMCPToolCallFailed        = errors.New("mcp tool call failed")
	ErrMCPListToolsFailed       = errors.New("mcp list-tools failed")
	ErrMCPOAuthNotAuthenticated = errors.New("mcp oauth not authenticated")
	ErrOAuthNotAuthenticated    = ErrMCPOAuthNotAuthenticated
)
View Source
var ErrOutputBudgetExceeded = errors.New("local_shell: command output exceeded the remaining context budget")

Functions

func IsApprovalPending

func IsApprovalPending() bool

func NewEchoTools

func NewEchoTools() taskengine.ToolsRepo

func NewLocalExecTools

func NewLocalExecTools(opts ...LocalExecOption) taskengine.ToolsRepo

func NewLocalExecToolsWith

func NewLocalExecToolsWith(runner CommandRunner, opts ...LocalExecOption) taskengine.ToolsRepo

func NewLocalFSTools

func NewLocalFSTools(allowedDir string, db libdb.DBManager) taskengine.ToolsRepo

func NewLocalFSToolsWith

func NewLocalFSToolsWith(allowedDir string, db libdb.DBManager, io FileIO, name string, cwdResolver func(context.Context) string, opts ...FSOption) taskengine.ToolsRepo

func NewSSHTools

func NewSSHTools(options ...SSHOption) (taskengine.ToolsRepo, error)

func NewWebCaller

func NewWebCaller(tracker libtracker.ActivityTracker, options ...WebtoolsOption) taskengine.ToolsRepo

func PruneLocalFSReads

func PruneLocalFSReads(ctx context.Context, exec interface {
	ExecContext(context.Context, string, ...any) (sql.Result, error)
}, dialect SQLDialect, olderThan time.Duration) error

func RunOAuthFlow

func RunOAuthFlow(ctx context.Context, o2cfg *oauth2.Config, oauthCfg *MCPOAuthConfig, meta *mcpoauth.ServerMetadata) (*oauth2.Token, error)

Types

type AskApproval

type AskApproval func(ctx context.Context, req hitlservice.ApprovalRequest) (bool, error)

type AtomicFileIO

type AtomicFileIO interface {
	WriteFileAtomic(ctx context.Context, path string, data []byte) error
}

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, spec CommandSpec, stdout, stderr io.Writer) (exitCode int, err error)
}

func NewOSCommandRunner

func NewOSCommandRunner() CommandRunner

func NewOSCommandRunnerWithShell added in v0.28.4

func NewOSCommandRunnerWithShell(shell PlatformShell) CommandRunner

func NewOSCommandRunnerWithShellAndScrub

func NewOSCommandRunnerWithShellAndScrub(shell PlatformShell, scrub func([]string) []string) CommandRunner

type CommandSpec

type CommandSpec struct {
	Command  string
	Args     []string
	Cwd      string
	Timeout  time.Duration
	UseShell bool
	Shell    PlatformShell
	Stdin    string
}

type EchoTools

type EchoTools struct{}

func (*EchoTools) Exec

func (e *EchoTools) Exec(ctx context.Context, startTime time.Time, input any, debug bool, toolsCall *taskengine.ToolsCall) (any, taskengine.DataType, error)

func (*EchoTools) GetSchemasForSupportedTools

func (e *EchoTools) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

func (*EchoTools) GetToolsForToolsByName

func (e *EchoTools) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

func (*EchoTools) Supports

func (e *EchoTools) Supports(ctx context.Context) ([]string, error)

type FSOption

type FSOption func(*LocalFSTools)

func WithSQLDialect

func WithSQLDialect(d SQLDialect) FSOption

type FileIO

type FileIO interface {
	ReadFile(ctx context.Context, path string) ([]byte, error)
	WriteFile(ctx context.Context, path string, data []byte) error
}

func NewOSFileIO

func NewOSFileIO() FileIO

type FsSedResult added in v0.29.0

type FsSedResult struct {
	Path         string `json:"path"`
	Written      bool   `json:"written"`
	Changed      bool   `json:"changed"`
	Replacements int    `json:"replacements"`
	OldBytes     int    `json:"old_bytes"`
	NewBytes     int    `json:"new_bytes"`
	OldSHA256    string `json:"old_sha256"`
	NewSHA256    string `json:"new_sha256"`
	OldText      string `json:"-"`
	NewText      string `json:"-"`
}

func (FsSedResult) ToolDiff added in v0.29.0

func (r FsSedResult) ToolDiff() (string, string, string, bool)

type FsWriteResult

type FsWriteResult struct {
	Path      string `json:"path"`
	Written   bool   `json:"written"`
	OldBytes  int    `json:"old_bytes"`
	NewBytes  int    `json:"new_bytes"`
	OldSHA256 string `json:"old_sha256"`
	NewSHA256 string `json:"new_sha256"`
	OldText   string `json:"-"`
	NewText   string `json:"-"`
}

func (FsWriteResult) ToolDiff added in v0.29.0

func (r FsWriteResult) ToolDiff() (string, string, string, bool)

type HITLWrapper

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

func (*HITLWrapper) Exec

func (h *HITLWrapper) Exec(
	ctx context.Context,
	startTime time.Time,
	input any,
	debug bool,
	tools *taskengine.ToolsCall,
) (any, taskengine.DataType, error)

func (*HITLWrapper) GetSchemasForSupportedTools

func (h *HITLWrapper) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

func (*HITLWrapper) GetToolsForToolsByName

func (h *HITLWrapper) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

func (*HITLWrapper) Supports

func (h *HITLWrapper) Supports(ctx context.Context) ([]string, error)

type HostKeyVerifier

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

func NewHostKeyVerifier

func NewHostKeyVerifier(knownHostsFile string, strict bool) (*HostKeyVerifier, error)

func (*HostKeyVerifier) AddKnownHost

func (v *HostKeyVerifier) AddKnownHost(host, key string)

func (*HostKeyVerifier) VerifyHostKey

func (v *HostKeyVerifier) VerifyHostKey(hostname string, remote net.Addr, key ssh.PublicKey) error

type LocalExecOption

type LocalExecOption func(*LocalExecTools)

func WithLocalExecAllowedCommands

func WithLocalExecAllowedCommands(commands []string) LocalExecOption

func WithLocalExecAllowedDir

func WithLocalExecAllowedDir(dir string) LocalExecOption

func WithLocalExecDeniedCommands

func WithLocalExecDeniedCommands(commands []string) LocalExecOption

func WithLocalExecScrubEnv

func WithLocalExecScrubEnv(scrub func([]string) []string) LocalExecOption

func WithLocalExecShell added in v0.28.4

func WithLocalExecShell(shell PlatformShell) LocalExecOption

func WithLocalExecTimeout

func WithLocalExecTimeout(d time.Duration) LocalExecOption

type LocalExecResult

type LocalExecResult struct {
	ExitCode        int     `json:"exit_code"`
	Stdout          string  `json:"stdout"`
	Stderr          string  `json:"stderr"`
	Success         bool    `json:"success"`
	Error           string  `json:"error,omitempty"`
	DurationSeconds float64 `json:"duration_seconds"`
	Command         string  `json:"command,omitempty"`
	Shell           string  `json:"shell,omitempty"`
	OS              string  `json:"os,omitempty"`
}

type LocalExecTools

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

func (*LocalExecTools) Exec

func (h *LocalExecTools) Exec(ctx context.Context, startTime time.Time, input any, debug bool, tools *taskengine.ToolsCall) (any, taskengine.DataType, error)

func (*LocalExecTools) GetSchemasForSupportedTools

func (h *LocalExecTools) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

func (*LocalExecTools) GetToolsForToolsByName

func (h *LocalExecTools) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

func (*LocalExecTools) Supports

func (h *LocalExecTools) Supports(ctx context.Context) ([]string, error)

type LocalFSTools

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

func (*LocalFSTools) Exec

func (h *LocalFSTools) Exec(ctx context.Context, startTime time.Time, input any, debug bool, toolsCall *taskengine.ToolsCall) (any, taskengine.DataType, error)

func (*LocalFSTools) GetSchemasForSupportedTools

func (h *LocalFSTools) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

func (*LocalFSTools) GetToolsForToolsByName

func (h *LocalFSTools) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

func (*LocalFSTools) InvalidateSessionReads

func (h *LocalFSTools) InvalidateSessionReads(ctx context.Context, sessionID string) error

func (*LocalFSTools) Supports

func (h *LocalFSTools) Supports(ctx context.Context) ([]string, error)

type MCPAuthConfig

type MCPAuthConfig struct {
	Type MCPAuthType

	Token string

	APIKeyFromEnv string
}

func (*MCPAuthConfig) ResolveToken

func (a *MCPAuthConfig) ResolveToken() string

type MCPAuthType

type MCPAuthType string
const (
	MCPAuthNone   MCPAuthType = ""
	MCPAuthBearer MCPAuthType = "bearer"
	MCPAuthOAuth  MCPAuthType = "oauth"
)

type MCPOAuthConfig

type MCPOAuthConfig struct {
	ClientName string

	ClientID string

	ClientSecret string

	Scopes []string

	CallbackPort int

	TokenStore mcpoauth.TokenStore

	OpenBrowser func(url string) error
}

func (*MCPOAuthConfig) ResolveCallbackPort

func (c *MCPOAuthConfig) ResolveCallbackPort() int

func (*MCPOAuthConfig) ResolveClientName

func (c *MCPOAuthConfig) ResolveClientName() string

type MCPServerConfig

type MCPServerConfig struct {
	Name string

	Transport MCPTransport

	Command string
	Args    []string

	URL string

	Auth *MCPAuthConfig

	OAuth *MCPOAuthConfig

	ConnectTimeout time.Duration

	MCPSessionID string

	OnSessionID func(string)

	Tracker libtracker.ActivityTracker
}

type MCPSessionPool

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

func NewMCPSessionPool

func NewMCPSessionPool(cfg MCPServerConfig) *MCPSessionPool

func (*MCPSessionPool) CallTool

func (p *MCPSessionPool) CallTool(ctx context.Context, toolName string, args map[string]any) (any, error)

func (*MCPSessionPool) Close

func (p *MCPSessionPool) Close() error

func (*MCPSessionPool) Connect

func (p *MCPSessionPool) Connect(ctx context.Context) error

func (*MCPSessionPool) ListTools

func (p *MCPSessionPool) ListTools(ctx context.Context) ([]*mcp.Tool, error)

func (*MCPSessionPool) Reconnect

func (p *MCPSessionPool) Reconnect(ctx context.Context) error

func (*MCPSessionPool) Session

func (p *MCPSessionPool) Session(ctx context.Context) (*mcp.ClientSession, error)

type MCPTransport

type MCPTransport string
const (
	MCPTransportStdio MCPTransport = "stdio"
	MCPTransportSSE   MCPTransport = "sse"
	MCPTransportHTTP  MCPTransport = "http"
)

type MockToolsRepo

type MockToolsRepo struct {
	Calls           []ToolsCallRecord
	ResponseMap     map[string]ToolsResponse
	DefaultResponse ToolsResponse
	ErrorSequence   []error
	// contains filtered or unexported fields
}

func NewMockToolsRegistry

func NewMockToolsRegistry() *MockToolsRepo

func (*MockToolsRepo) CallCount

func (m *MockToolsRepo) CallCount() int

func (*MockToolsRepo) Exec

func (m *MockToolsRepo) Exec(
	ctx context.Context,
	startingTime time.Time,
	input any,
	inputType taskengine.DataType,
	transition string,
	args *taskengine.ToolsCall,
) (int, any, taskengine.DataType, string, error)

func (*MockToolsRepo) LastCall

func (m *MockToolsRepo) LastCall() *ToolsCallRecord

func (*MockToolsRepo) Reset

func (m *MockToolsRepo) Reset()

func (*MockToolsRepo) Supports

func (m *MockToolsRepo) Supports(ctx context.Context) ([]string, error)

func (*MockToolsRepo) WithErrorSequence

func (m *MockToolsRepo) WithErrorSequence(errors ...error) *MockToolsRepo

func (*MockToolsRepo) WithResponse

func (m *MockToolsRepo) WithResponse(toolsType string, response ToolsResponse) *MockToolsRepo

type PlatformShell added in v0.28.4

type PlatformShell struct {
	OS          string
	Kind        ShellKind
	Command     string
	ArgsPrefix  []string
	DisplayName string
	SyntaxHint  string
}

func DetectPlatformShell added in v0.28.4

func DetectPlatformShell() PlatformShell

func DetectPlatformShellFor added in v0.28.4

func DetectPlatformShellFor(goos string, getenv func(string) string, lookPath func(string) (string, error)) PlatformShell

func NewCmdShell added in v0.28.4

func NewCmdShell(command string) PlatformShell

func NewPowerShellShell added in v0.28.4

func NewPowerShellShell(command string) PlatformShell

func NewShShell added in v0.28.4

func NewShShell(command string) PlatformShell

func (PlatformShell) IsSet added in v0.28.4

func (s PlatformShell) IsSet() bool

func (PlatformShell) ShellModeDescription added in v0.28.4

func (s PlatformShell) ShellModeDescription() string

func (PlatformShell) Summary added in v0.28.4

func (s PlatformShell) Summary() string

func (PlatformShell) WithDefaults added in v0.28.4

func (s PlatformShell) WithDefaults() PlatformShell

func (PlatformShell) WrapCommand added in v0.28.4

func (s PlatformShell) WrapCommand(command string, args []string) (program string, wrappedArgs []string, script string)

type Print

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

func (*Print) Exec

func (h *Print) Exec(ctx context.Context, startTime time.Time, input any, debug bool, toolsCall *taskengine.ToolsCall) (any, taskengine.DataType, error)

func (*Print) GetSchemasForSupportedTools

func (h *Print) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

func (*Print) GetToolsForToolsByName

func (h *Print) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

func (*Print) Supports

func (h *Print) Supports(ctx context.Context) ([]string, error)

type SQLDialect

type SQLDialect int
const (
	DialectSQLite SQLDialect = iota
	DialectPostgres
)

type SSHClientCache

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

func NewSSHClientCache

func NewSSHClientCache() *SSHClientCache

func (*SSHClientCache) Clear

func (c *SSHClientCache) Clear()

func (*SSHClientCache) Get

func (c *SSHClientCache) Get(key string) (*ssh.Client, bool)

func (*SSHClientCache) IsAlive

func (c *SSHClientCache) IsAlive(key string) bool

func (*SSHClientCache) Put

func (c *SSHClientCache) Put(key string, client *ssh.Client, config *ssh.ClientConfig)

func (*SSHClientCache) Remove

func (c *SSHClientCache) Remove(key string)

type SSHConfig

type SSHConfig struct {
	Host           string
	Port           int
	User           string
	Password       string
	PrivateKey     string
	PrivateKeyFile string
	Timeout        time.Duration
	HostKey        string
	StrictHostKey  bool
}

type SSHOption

type SSHOption func(*SSHTools) error

func WithClientCache

func WithClientCache() SSHOption

func WithCustomHostKeyCallback

func WithCustomHostKeyCallback(callback ssh.HostKeyCallback) SSHOption

func WithDefaultPort

func WithDefaultPort(port int) SSHOption

func WithDefaultTimeout

func WithDefaultTimeout(timeout time.Duration) SSHOption

func WithKnownHostsFile

func WithKnownHostsFile(path string) SSHOption

func WithStrictHostKey

func WithStrictHostKey() SSHOption

type SSHResult

type SSHResult struct {
	ExitCode int     `json:"exit_code"`
	Stdout   string  `json:"stdout"`
	Stderr   string  `json:"stderr"`
	Duration float64 `json:"duration_seconds"`
	Command  string  `json:"command"`
	Host     string  `json:"host"`
	Success  bool    `json:"success"`
	Error    string  `json:"error,omitempty"`
	HostKey  string  `json:"host_key,omitempty"`
}

type SSHTools

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

func (*SSHTools) Close

func (h *SSHTools) Close() error

func (*SSHTools) Exec

func (h *SSHTools) Exec(ctx context.Context, startTime time.Time, input any, debug bool, tools *taskengine.ToolsCall) (any, taskengine.DataType, error)

func (*SSHTools) GetSchemasForSupportedTools

func (h *SSHTools) GetSchemasForSupportedTools(ctx context.Context) (map[string]*openapi3.T, error)

func (*SSHTools) GetToolsForToolsByName

func (h *SSHTools) GetToolsForToolsByName(ctx context.Context, name string) ([]taskengine.Tool, error)

func (*SSHTools) Supports

func (h *SSHTools) Supports(ctx context.Context) ([]string, error)

type ShellKind added in v0.28.4

type ShellKind string
const (
	ShellKindSh         ShellKind = "sh"
	ShellKindPowerShell ShellKind = "powershell"
	ShellKindCmd        ShellKind = "cmd"
)

type StatFileIO

type StatFileIO interface {
	Stat(ctx context.Context, path string) (os.FileInfo, error)
}

type ToolsCallRecord

type ToolsCallRecord struct {
	Args       taskengine.ToolsCall
	Input      any
	InputType  taskengine.DataType
	Transition string
}

type ToolsResponse

type ToolsResponse struct {
	Status     int
	Output     any
	OutputType taskengine.DataType
	Transition string
}

type WebCaller

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

func (*WebCaller) Exec

func (h *WebCaller) Exec(ctx context.Context, _ time.Time, input any, _ bool, toolsCall *taskengine.ToolsCall) (any, taskengine.DataType, error)

func (*WebCaller) GetSchemasForSupportedTools

func (h *WebCaller) GetSchemasForSupportedTools(_ context.Context) (map[string]*openapi3.T, error)

func (*WebCaller) GetToolsForToolsByName

func (h *WebCaller) GetToolsForToolsByName(_ context.Context, name string) ([]taskengine.Tool, error)

func (*WebCaller) Supports

func (h *WebCaller) Supports(_ context.Context) ([]string, error)

type WebtoolsOption

type WebtoolsOption func(*WebCaller)

func WithDefaultHeader

func WithDefaultHeader(key, value string) WebtoolsOption

func WithHTTPClient

func WithHTTPClient(client *http.Client) WebtoolsOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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