tool

package
v0.10.15 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package tool provides the built-in agent tools: read, write, edit, and bash.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinToolsForPreset

func BuiltinToolsForPreset(workDir, preset string, bashFilter BashOutputFilterConfig) []agent.Tool

BuiltinToolsForPreset returns the built-in tool set used by the native agent harness for a prompt preset.

func TruncateHead

func TruncateHead(s string, maxLines int, maxBytes int) string

TruncateHead keeps the first maxLines lines or maxBytes bytes, whichever hits first. If the content was cut, a truncation marker is appended.

func TruncateTail

func TruncateTail(s string, maxLines int, maxBytes int) string

TruncateTail keeps the last maxLines lines or maxBytes bytes, whichever hits first. If the content was cut, a truncation marker is prepended.

Types

type AnchorEditParams added in v0.10.5

type AnchorEditParams struct {
	Path        string `json:"path"`
	StartAnchor string `json:"start_anchor"`
	EndAnchor   string `json:"end_anchor"`
	NewText     string `json:"new_text"`
	OffsetHint  *int   `json:"offset_hint,omitempty"`
}

AnchorEditParams are the parameters for the anchor_edit tool.

type AnchorEditTool added in v0.10.5

type AnchorEditTool struct {
	WorkDir     string
	AnchorStore *anchorstore.AnchorStore
}

AnchorEditTool performs line-range edits using anchors assigned by ReadTool.

func (*AnchorEditTool) Description added in v0.10.5

func (t *AnchorEditTool) Description() string

func (*AnchorEditTool) Execute added in v0.10.5

func (t *AnchorEditTool) Execute(_ context.Context, params json.RawMessage) (string, error)

func (*AnchorEditTool) Name added in v0.10.5

func (t *AnchorEditTool) Name() string

func (*AnchorEditTool) Parallel added in v0.10.5

func (t *AnchorEditTool) Parallel() bool

func (*AnchorEditTool) Schema added in v0.10.5

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

type BashOutputFilterConfig

type BashOutputFilterConfig struct {
	Mode         string
	RTKBinary    string
	MaxBytes     int
	RawOutputDir string
}

type BashParams

type BashParams struct {
	Command   string `json:"command"`
	TimeoutMs int    `json:"timeout_ms,omitempty"`
}

BashParams are the parameters for the bash tool.

type BashTool

type BashTool struct {
	WorkDir      string
	OutputFilter BashOutputFilterConfig
}

BashTool executes shell commands.

func (*BashTool) Description

func (t *BashTool) Description() string

func (*BashTool) Execute

func (t *BashTool) Execute(ctx context.Context, params json.RawMessage) (string, error)

func (*BashTool) Name

func (t *BashTool) Name() string

func (*BashTool) Parallel

func (t *BashTool) Parallel() bool

func (*BashTool) Schema

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

type EditEntry

type EditEntry struct {
	OldText string `json:"oldText"`
	NewText string `json:"newText"`
}

EditEntry is a single oldText→newText replacement.

type EditParams

type EditParams struct {
	Path string `json:"path"`

	// Multi-edit form
	Edits []EditEntry `json:"edits,omitempty"`

	// Single-edit form (backward compat)
	OldString string `json:"old_string,omitempty"`
	NewString string `json:"new_string,omitempty"`
}

EditParams are the parameters for the edit tool. Supports two forms:

  • Multi-edit (pi-style): path + edits[] array
  • Single-edit (legacy): path + old_string + new_string

type EditTool

type EditTool struct {
	WorkDir string
}

EditTool performs find-replace edits on files.

func (*EditTool) Description

func (t *EditTool) Description() string

func (*EditTool) Execute

func (t *EditTool) Execute(ctx context.Context, params json.RawMessage) (string, error)

func (*EditTool) Name

func (t *EditTool) Name() string

func (*EditTool) Parallel

func (t *EditTool) Parallel() bool

func (*EditTool) Schema

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

type FindParams

type FindParams struct {
	Pattern     string    `json:"pattern"`
	Dir         string    `json:"dir,omitempty"`          // base dir; defaults to WorkDir
	ExcludeDirs *[]string `json:"exclude_dirs,omitempty"` // override default skip dirs; nil uses defaults, empty slice means no skips
}

FindParams are the parameters for the find tool.

type FindTool

type FindTool struct {
	WorkDir     string
	ExcludeDirs []string // optional override for skipDirs; if empty, uses default skipDirs
}

FindTool finds files matching a path pattern.

func (*FindTool) Description

func (t *FindTool) Description() string

func (*FindTool) Execute

func (t *FindTool) Execute(_ context.Context, params json.RawMessage) (string, error)

func (*FindTool) Name

func (t *FindTool) Name() string

func (*FindTool) Parallel

func (t *FindTool) Parallel() bool

func (*FindTool) Schema

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

type GrepParams

type GrepParams struct {
	Pattern         string    `json:"pattern"`
	Dir             string    `json:"dir,omitempty"`
	Glob            string    `json:"glob,omitempty"`
	CaseInsensitive bool      `json:"case_insensitive,omitempty"`
	ExcludeDirs     *[]string `json:"exclude_dirs,omitempty"` // override default skip dirs; nil uses defaults, empty slice means no skips
}

GrepParams are the parameters for the grep tool.

type GrepTool

type GrepTool struct {
	WorkDir     string
	ExcludeDirs []string // optional override for skipDirs; if empty, uses default skipDirs
}

GrepTool searches file contents for a regex pattern.

func (*GrepTool) Description

func (t *GrepTool) Description() string

func (*GrepTool) Execute

func (t *GrepTool) Execute(_ context.Context, params json.RawMessage) (string, error)

func (*GrepTool) Name

func (t *GrepTool) Name() string

func (*GrepTool) Parallel

func (t *GrepTool) Parallel() bool

func (*GrepTool) Schema

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

type LsParams

type LsParams struct {
	Path string `json:"path,omitempty"` // defaults to WorkDir
}

LsParams are the parameters for the ls tool.

type LsTool

type LsTool struct {
	WorkDir string
}

LsTool lists directory contents.

func (*LsTool) Description

func (t *LsTool) Description() string

func (*LsTool) Execute

func (t *LsTool) Execute(_ context.Context, params json.RawMessage) (string, error)

func (*LsTool) Name

func (t *LsTool) Name() string

func (*LsTool) Parallel

func (t *LsTool) Parallel() bool

func (*LsTool) Schema

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

type PatchParams

type PatchParams struct {
	Path      string `json:"path"`
	Search    string `json:"search,omitempty"`    // unique text to locate; must appear exactly once
	Content   string `json:"content"`             // replacement text, or text to prepend/append
	Operation string `json:"operation,omitempty"` // "replace" (default), "replace_all", "prepend", "append"
}

PatchParams are the parameters for the patch tool. The model provides search (context from the file) and content (the replacement). When search is omitted or empty, the operation is a full-file replace, prepend, or append depending on the operation field.

type PatchTool

type PatchTool struct {
	WorkDir string
}

PatchTool performs search-and-replace edits on files with robust line-ending handling and clear error messages. Inspired by ForgeCode's fs_patch design.

func (*PatchTool) Description

func (t *PatchTool) Description() string

func (*PatchTool) Execute

func (t *PatchTool) Execute(_ context.Context, params json.RawMessage) (string, error)

func (*PatchTool) Name

func (t *PatchTool) Name() string

func (*PatchTool) Parallel

func (t *PatchTool) Parallel() bool

func (*PatchTool) Schema

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

type ReadParams

type ReadParams struct {
	Path   string `json:"path"`
	Offset int    `json:"offset,omitempty"` // 0-based line offset
	Limit  int    `json:"limit,omitempty"`  // max lines to return
}

ReadParams are the parameters for the read tool.

type ReadTool

type ReadTool struct {
	WorkDir     string
	AnchorStore *anchorstore.AnchorStore
}

ReadTool reads file contents relative to a working directory.

func (*ReadTool) Description

func (t *ReadTool) Description() string

func (*ReadTool) Execute

func (t *ReadTool) Execute(ctx context.Context, params json.RawMessage) (string, error)

func (*ReadTool) Name

func (t *ReadTool) Name() string

func (*ReadTool) Parallel

func (t *ReadTool) Parallel() bool

func (*ReadTool) Schema

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

type Task

type Task struct {
	ID          string     `json:"id"`
	Title       string     `json:"title"`
	Description string     `json:"description,omitempty"`
	Status      TaskStatus `json:"status"`
	Order       int        `json:"order"` // for ordering tasks in a plan
}

Task represents a tracked subtask within an agent run.

type TaskParams

type TaskParams struct {
	Operation   string `json:"operation"` // create, update, list, get
	ID          string `json:"id,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Status      string `json:"status,omitempty"`
}

TaskParams are the parameters for task tool operations.

type TaskStatus

type TaskStatus string

TaskStatus represents the status of a tracked task.

const (
	TaskStatusPending    TaskStatus = "pending"
	TaskStatusInProgress TaskStatus = "in_progress"
	TaskStatusCompleted  TaskStatus = "completed"
)

type TaskStore

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

TaskStore persists task state within a single agent run.

func NewTaskStore

func NewTaskStore() *TaskStore

NewTaskStore creates a new empty task store.

func (*TaskStore) Create

func (s *TaskStore) Create(title string, description string) string

Create adds a new pending task and returns its ID.

func (*TaskStore) Get

func (s *TaskStore) Get(id string) (*Task, error)

Get retrieves a task by ID.

func (*TaskStore) List

func (s *TaskStore) List() []*Task

List returns all tasks sorted by their Order field.

func (*TaskStore) Update

func (s *TaskStore) Update(id string, status TaskStatus) error

Update changes the status of an existing task.

type TaskTool

type TaskTool struct {
	Store *TaskStore
}

TaskTool provides task tracking capabilities for multi-step planning.

func (*TaskTool) Description

func (t *TaskTool) Description() string

func (*TaskTool) Execute

func (t *TaskTool) Execute(_ context.Context, params json.RawMessage) (string, error)

func (*TaskTool) Name

func (t *TaskTool) Name() string

func (*TaskTool) Parallel

func (t *TaskTool) Parallel() bool

func (*TaskTool) Schema

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

type WriteParams

type WriteParams struct {
	Path    string `json:"path"`
	Content string `json:"content"`
}

WriteParams are the parameters for the write tool.

type WriteTool

type WriteTool struct {
	WorkDir string
}

WriteTool creates or overwrites a file.

func (*WriteTool) Description

func (t *WriteTool) Description() string

func (*WriteTool) Execute

func (t *WriteTool) Execute(ctx context.Context, params json.RawMessage) (string, error)

func (*WriteTool) Name

func (t *WriteTool) Name() string

func (*WriteTool) Parallel

func (t *WriteTool) Parallel() bool

func (*WriteTool) Schema

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

Directories

Path Synopsis
Package anchorstore tracks per-session line anchors for file reads.
Package anchorstore tracks per-session line anchors for file reads.
Package anchorwords provides the static 1024-word anchor vocabulary used by the ReadTool's anchor mode and the anchor_edit tool.
Package anchorwords provides the static 1024-word anchor vocabulary used by the ReadTool's anchor mode and the anchor_edit tool.

Jump to

Keyboard shortcuts

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