tool

package
v0.0.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package tool defines the Tool port (ADR-0001 loop design). Every builtin (read, write, edit, bash, glob, grep) and every MCP-exposed capability implements this same interface; the agent loop never calls anything else.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bash

type Bash struct{}

Bash runs a shell command (sh -c) with merged stdout/stderr, streaming into the returned output. Cancellation (ctx) and a per-call timeout both kill the process. A non-zero exit is reported in the output (not as an error) so the model can react to it; only mechanism failures and cancellation error.

func (Bash) Description

func (Bash) Description() string

func (Bash) Execute

func (Bash) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (Bash) Name

func (Bash) Name() string

func (Bash) Schema

func (Bash) Schema() json.RawMessage

type Echo

type Echo struct{}

Echo is a trivial builtin used to prove the loop end-to-end without touching the filesystem or a shell. Real builtins (read/write/edit/bash/ glob/grep) follow this same shape — see T-020/T-021 in the backlog.

func (Echo) Description

func (Echo) Description() string

func (Echo) Execute

func (Echo) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (Echo) Name

func (Echo) Name() string

func (Echo) Schema

func (Echo) Schema() json.RawMessage

type Edit

type Edit struct{}

Edit performs an exact string replacement in a file. old_string must occur exactly once — this guards against ambiguous edits. Returns the region around the replacement so the model can verify.

func (Edit) Description

func (Edit) Description() string

func (Edit) Execute

func (Edit) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (Edit) Name

func (Edit) Name() string

func (Edit) Schema

func (Edit) Schema() json.RawMessage

type Glob

type Glob struct {
	Root string
}

Glob finds files under Root matching a pattern that supports *, ?, and ** (recursive across path segments). Returns one path per line. Root defaults to "." when empty.

func (Glob) Description

func (g Glob) Description() string

func (Glob) Execute

func (g Glob) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (Glob) Name

func (g Glob) Name() string

func (Glob) Schema

func (g Glob) Schema() json.RawMessage

type Grep

type Grep struct {
	Root string
}

Grep searches file contents under Root for a regex pattern. Returns matches as "path:line: text", one per line. Optional glob filters file names; ignore_case makes the pattern case-insensitive. Root defaults to ".".

func (Grep) Description

func (g Grep) Description() string

func (Grep) Execute

func (g Grep) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (Grep) Name

func (g Grep) Name() string

func (Grep) Schema

func (g Grep) Schema() json.RawMessage

type LSPDefinition

type LSPDefinition struct{ LS ports.LanguageService }

LSPDefinition locates where a symbol is defined.

func (LSPDefinition) Description

func (t LSPDefinition) Description() string

func (LSPDefinition) Execute

func (t LSPDefinition) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (LSPDefinition) Name

func (t LSPDefinition) Name() string

func (LSPDefinition) Schema

func (t LSPDefinition) Schema() json.RawMessage

type LSPDiagnostics

type LSPDiagnostics struct{ LS ports.LanguageService }

LSPDiagnostics reports the problems a language server sees in a file.

func (LSPDiagnostics) Description

func (t LSPDiagnostics) Description() string

func (LSPDiagnostics) Execute

func (t LSPDiagnostics) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (LSPDiagnostics) Name

func (t LSPDiagnostics) Name() string

func (LSPDiagnostics) Schema

func (t LSPDiagnostics) Schema() json.RawMessage

type LSPHover

type LSPHover struct{ LS ports.LanguageService }

LSPHover describes the symbol at a position.

func (LSPHover) Description

func (t LSPHover) Description() string

func (LSPHover) Execute

func (t LSPHover) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (LSPHover) Name

func (t LSPHover) Name() string

func (LSPHover) Schema

func (t LSPHover) Schema() json.RawMessage

type LSPReferences

type LSPReferences struct{ LS ports.LanguageService }

LSPReferences finds the uses of a symbol.

func (LSPReferences) Description

func (t LSPReferences) Description() string

func (LSPReferences) Execute

func (t LSPReferences) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (LSPReferences) Name

func (t LSPReferences) Name() string

func (LSPReferences) Schema

func (t LSPReferences) Schema() json.RawMessage

type LSPSymbols

type LSPSymbols struct{ LS ports.LanguageService }

LSPSymbols lists the declarations in a file.

func (LSPSymbols) Description

func (t LSPSymbols) Description() string

func (LSPSymbols) Execute

func (t LSPSymbols) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (LSPSymbols) Name

func (t LSPSymbols) Name() string

func (LSPSymbols) Schema

func (t LSPSymbols) Schema() json.RawMessage

type Read

type Read struct{}

Read returns a file's contents with cat -n style line numbering. offset is a 1-based starting line (default 1); limit caps the number of lines returned.

func (Read) Description

func (Read) Description() string

func (Read) Execute

func (Read) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (Read) Name

func (Read) Name() string

func (Read) Schema

func (Read) Schema() json.RawMessage

type Registry

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

Registry resolves tool calls by name.

func NewRegistry

func NewRegistry(tools ...Tool) *Registry

func (*Registry) All

func (r *Registry) All() []Tool

func (*Registry) Get

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

type Tool

type Tool interface {
	Name() string
	Description() string
	Schema() json.RawMessage // JSON Schema for the tool's input
	Execute(ctx context.Context, input json.RawMessage) (string, error)
}

Tool is one callable capability exposed to the model.

func LSPTools

func LSPTools(ls ports.LanguageService) []Tool

LSPTools returns every language-service tool bound to ls. Registration is the caller's decision — the runtime only registers these when LSP is configured.

type Write

type Write struct{}

Write creates or overwrites a file, creating parent directories as needed.

func (Write) Description

func (Write) Description() string

func (Write) Execute

func (Write) Execute(ctx context.Context, input json.RawMessage) (string, error)

func (Write) Name

func (Write) Name() string

func (Write) Schema

func (Write) Schema() json.RawMessage

Jump to

Keyboard shortcuts

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