tools

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BrowserLogDir string

BrowserLogDir can be set before first use to override the browser log directory. If empty, falls back to ~/.roger/logs/ (legacy).

Functions

func SSRFSafeTransport

func SSRFSafeTransport() *http.Transport

SSRFSafeTransport returns an http.Transport that validates resolved IPs against SSRF rules before connecting. This closes the TOCTOU gap between the checkSSRF pre-check and the actual TCP connection (DNS rebinding).

Types

type BrowserPool

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

BrowserPool manages per-session browser instances.

func NewBrowserPool

func NewBrowserPool(headless bool, chromePath string, noSandbox bool, width, height int) *BrowserPool

NewBrowserPool creates a pool with the given settings. If noSandbox is true, Chrome is launched with --no-sandbox (needed inside Docker containers that run as root). Prefer false when possible.

func (*BrowserPool) Close

func (p *BrowserPool) Close(sessionKey string)

Close removes and cancels the browser session for a key.

func (*BrowserPool) CloseAll

func (p *BrowserPool) CloseAll()

CloseAll closes all browser sessions and stops the idle reaper.

type BrowserTool

type BrowserTool struct {
	Pool *BrowserPool
}

BrowserTool provides browser automation actions.

func (*BrowserTool) CaptureScreenshot

func (t *BrowserTool) CaptureScreenshot(ctx context.Context, sessionKey string) ([]byte, string, error)

CaptureScreenshot captures a PNG screenshot for the given session key. Returns the raw PNG bytes and the current page URL. Used by the MCP server to return proper image content blocks.

func (*BrowserTool) Description

func (t *BrowserTool) Description() string

func (*BrowserTool) Name

func (t *BrowserTool) Name() string

func (*BrowserTool) Run

func (t *BrowserTool) Run(ctx context.Context, argsJSON string) string

func (*BrowserTool) Schema

func (t *BrowserTool) Schema() json.RawMessage

func (*BrowserTool) SetViewport

func (t *BrowserTool) SetViewport(sessionKey string, width, height int)

SetViewport overrides the browser viewport size for the given session.

type ChannelConfirmer

type ChannelConfirmer interface {
	// CanConfirm returns true if this channel can reach the given session key.
	CanConfirm(sessionKey string) bool
	// SendConfirmPrompt sends an inline-button confirmation prompt and blocks
	// until the user responds or ctx expires.
	SendConfirmPrompt(ctx context.Context, sessionKey, command, pattern string) (bool, error)
}

ChannelConfirmer can send a confirmation prompt on a specific channel bot.

type ConfirmFunc

type ConfirmFunc func(command string, timeout time.Duration) (bool, error)

ConfirmFunc is a callback that asks the user to confirm a dangerous command. It receives the command string and a timeout duration, and returns true if the user confirms execution. If nil, dangerous commands are hard-blocked.

type ConfirmManager

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

ConfirmManager routes confirmation requests to the appropriate channel bot. It satisfies the ExecConfirmer interface.

func NewConfirmManager

func NewConfirmManager() *ConfirmManager

NewConfirmManager creates a ConfirmManager.

func (*ConfirmManager) AddChannel

func (m *ConfirmManager) AddChannel(c ChannelConfirmer)

AddChannel registers a channel bot as a confirmation handler.

func (*ConfirmManager) RequestExecConfirm

func (m *ConfirmManager) RequestExecConfirm(ctx context.Context, sessionKey, command, pattern string) (bool, error)

RequestExecConfirm implements ExecConfirmer. It finds the first channel that can reach the session and sends a confirmation prompt.

type EideticAppendTool

type EideticAppendTool struct {
	Client     eidetic.Client
	Embeddings *embeddings.Client // optional: generates embedding vector on store
	AgentID    string             // default agent_id for writes
	OnAppend   func()             // called after successful append; optional
}

EideticAppendTool exposes semantic memory storage as an agent tool. It is registered only when the Eidetic integration is enabled.

func (*EideticAppendTool) Description

func (t *EideticAppendTool) Description() string

func (*EideticAppendTool) Name

func (t *EideticAppendTool) Name() string

func (*EideticAppendTool) Run

func (t *EideticAppendTool) Run(ctx context.Context, argsJSON string) string

func (*EideticAppendTool) Schema

func (t *EideticAppendTool) Schema() json.RawMessage

type EideticSearchTool

type EideticSearchTool struct {
	Client     eidetic.Client
	Embeddings *embeddings.Client // optional: enables hybrid search
	Limit      int                // default search limit
	Threshold  float64            // default cosine similarity threshold
}

EideticSearchTool exposes semantic memory search as an agent tool. It is registered only when the Eidetic integration is enabled.

func (*EideticSearchTool) Description

func (t *EideticSearchTool) Description() string

func (*EideticSearchTool) Name

func (t *EideticSearchTool) Name() string

func (*EideticSearchTool) Run

func (t *EideticSearchTool) Run(ctx context.Context, argsJSON string) string

func (*EideticSearchTool) Schema

func (t *EideticSearchTool) Schema() json.RawMessage

type ExecConfirmer

type ExecConfirmer interface {
	// RequestExecConfirm sends a confirmation prompt to the user for a dangerous
	// command. sessionKey identifies which user/chat to prompt. Returns true if
	// the user confirms, false otherwise.
	RequestExecConfirm(ctx context.Context, sessionKey, command, pattern string) (bool, error)
}

ExecConfirmer presents a confirmation prompt via channel bots.

type ExecInput

type ExecInput struct {
	Command string `json:"command"`
	Timeout int    `json:"timeout,omitempty"` // seconds, 0 = use default
}

ExecInput is the argument schema for the exec tool.

type ExecTool

type ExecTool struct {
	DefaultTimeout      time.Duration
	BackgroundWait      time.Duration     // if >0: return partial output after this delay if cmd still running
	BackgroundHardLimit time.Duration     // hard kill deadline for bg processes (default 30m)
	MaxOutputChars      int               // output truncation limit (default 100000)
	Env                 map[string]string // extra env vars
	DenyCommands        []string          // deny patterns (empty = no restriction)
	DangerousPatterns   []string          // extra patterns that trigger confirmation (merged with builtins)
	Sandbox             *SandboxConfig    // nil = run on host
	ConfirmTimeout      time.Duration     // timeout for destructive command confirmation (default 60s)
	Confirm             ConfirmFunc       // nil = hard-block dangerous commands
	Confirmer           ExecConfirmer     // session-aware confirmer (REQ-061); takes priority over Confirm
	// contains filtered or unexported fields
}

ExecTool executes a shell command and returns combined output.

func (*ExecTool) Cleanup

func (t *ExecTool) Cleanup()

Cleanup stops and removes the sandbox container.

func (*ExecTool) Description

func (t *ExecTool) Description() string

func (*ExecTool) Name

func (t *ExecTool) Name() string

func (*ExecTool) Run

func (t *ExecTool) Run(ctx context.Context, argsJSON string) string

func (*ExecTool) Schema

func (t *ExecTool) Schema() json.RawMessage

type ListDirTool

type ListDirTool struct {
	AllowPaths []string // empty = no restriction
}

ListDirTool lists a directory's contents.

func (*ListDirTool) Description

func (t *ListDirTool) Description() string

func (*ListDirTool) Name

func (t *ListDirTool) Name() string

func (*ListDirTool) Run

func (t *ListDirTool) Run(_ context.Context, argsJSON string) string

func (*ListDirTool) Schema

func (t *ListDirTool) Schema() json.RawMessage

type MemoryAppendTool

type MemoryAppendTool struct {
	Workspace string
}

MemoryAppendTool appends content to the agent's memory files.

func (*MemoryAppendTool) Description

func (t *MemoryAppendTool) Description() string

func (*MemoryAppendTool) Name

func (t *MemoryAppendTool) Name() string

func (*MemoryAppendTool) Run

func (t *MemoryAppendTool) Run(_ context.Context, argsJSON string) string

func (*MemoryAppendTool) Schema

func (t *MemoryAppendTool) Schema() json.RawMessage

type MemoryGetTool

type MemoryGetTool struct {
	Workspace string
}

MemoryGetTool reads content from the agent's memory files.

func (*MemoryGetTool) Description

func (t *MemoryGetTool) Description() string

func (*MemoryGetTool) Name

func (t *MemoryGetTool) Name() string

func (*MemoryGetTool) Run

func (t *MemoryGetTool) Run(_ context.Context, argsJSON string) string

func (*MemoryGetTool) Schema

func (t *MemoryGetTool) Schema() json.RawMessage

type NotifyUserTool

type NotifyUserTool struct {
	Announcers []agentapi.Announcer
}

NotifyUserTool allows the agent to push an asynchronous message to the user on whatever channel the conversation originated from. It uses the existing AnnounceToSession infrastructure.

func (*NotifyUserTool) Description

func (t *NotifyUserTool) Description() string

func (*NotifyUserTool) Name

func (t *NotifyUserTool) Name() string

func (*NotifyUserTool) Run

func (t *NotifyUserTool) Run(ctx context.Context, argsJSON string) string

func (*NotifyUserTool) Schema

func (t *NotifyUserTool) Schema() json.RawMessage

type ReadFileTool

type ReadFileTool struct {
	AllowPaths []string // empty = no restriction
}

ReadFileTool reads a file and returns its contents.

func (*ReadFileTool) Description

func (t *ReadFileTool) Description() string

func (*ReadFileTool) Name

func (t *ReadFileTool) Name() string

func (*ReadFileTool) Run

func (t *ReadFileTool) Run(_ context.Context, argsJSON string) string

func (*ReadFileTool) Schema

func (t *ReadFileTool) Schema() json.RawMessage

type SandboxConfig

type SandboxConfig struct {
	Enabled      bool
	Image        string
	Mounts       []string
	SetupCommand string
}

SandboxConfig holds Docker sandbox settings (mirrors config.SandboxConfig).

type SessionKeyContextKey

type SessionKeyContextKey = agentapi.SessionKeyContextKey

SessionKeyContextKey is an alias for agentapi.SessionKeyContextKey. Kept for backward compatibility with external references.

type SurfaceCreateTool

type SurfaceCreateTool struct {
	Store      *surfaces.Store
	Deliverers []agentapi.Deliverer
	Logger     *zap.SugaredLogger
}

SurfaceCreateTool allows the agent to create surfaces directly during any conversation turn. High-priority surfaces (1-2) are broadcast to channel bots.

func (*SurfaceCreateTool) Description

func (t *SurfaceCreateTool) Description() string

func (*SurfaceCreateTool) Name

func (t *SurfaceCreateTool) Name() string

func (*SurfaceCreateTool) Run

func (t *SurfaceCreateTool) Run(ctx context.Context, argsJSON string) string

func (*SurfaceCreateTool) Schema

func (t *SurfaceCreateTool) Schema() json.RawMessage

type Tool

type Tool = agentapi.Tool

Tool is an alias for agentapi.Tool.

type WebFetchTool

type WebFetchTool struct {
	MaxChars       int
	TimeoutSeconds int
	Transport      *http.Transport // shared SSRF-safe transport; nil = create per-call (wasteful)
	Client         *http.Client    // override for testing; nil = use Transport
	SkipSSRF       bool            // skip SSRF check (test only)
}

WebFetchTool fetches a URL and returns its text content.

func (*WebFetchTool) Description

func (t *WebFetchTool) Description() string

func (*WebFetchTool) Name

func (t *WebFetchTool) Name() string

func (*WebFetchTool) Run

func (t *WebFetchTool) Run(ctx context.Context, argsJSON string) string

func (*WebFetchTool) Schema

func (t *WebFetchTool) Schema() json.RawMessage

type WebSearchTool

type WebSearchTool struct {
	MaxResults     int
	TimeoutSeconds int
	BaseURL        string       // override for testing; defaults to DDG HTML search endpoint
	Client         *http.Client // override for testing; defaults to http.DefaultClient
}

WebSearchTool searches the web using DuckDuckGo.

func (*WebSearchTool) Description

func (t *WebSearchTool) Description() string

func (*WebSearchTool) Name

func (t *WebSearchTool) Name() string

func (*WebSearchTool) Run

func (t *WebSearchTool) Run(ctx context.Context, argsJSON string) string

func (*WebSearchTool) Schema

func (t *WebSearchTool) Schema() json.RawMessage

type WriteFileTool

type WriteFileTool struct {
	AllowPaths []string // empty = no restriction
}

WriteFileTool writes content to a file.

func (*WriteFileTool) Description

func (t *WriteFileTool) Description() string

func (*WriteFileTool) Name

func (t *WriteFileTool) Name() string

func (*WriteFileTool) Run

func (t *WriteFileTool) Run(_ context.Context, argsJSON string) string

func (*WriteFileTool) Schema

func (t *WriteFileTool) Schema() json.RawMessage

Jump to

Keyboard shortcuts

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