tool

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 21 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

Overview

Package tool is the set of tools the native API agent runs.

`flockdeck chat` talks to a model API directly, so nothing else supplies the model with a way to read or change the project: these are it. Each one is confined to the pane's working directory, and the three that change something -- write_file, edit_file and run_command -- have a question for the person at the terminal, which the chat loop puts to them before the call runs, raising a Notification so the pane turns amber and whoever is watching the window learns which pane wants them.

The tools sit behind the Tool interface so the chat loop and the tools can be built and tested apart: the loop knows how to describe a tool to a wire format, when to ask, and what to do with the answer, and knows nothing about what any particular tool does.

Index

Constants

This section is empty.

Variables

View Source
var ErrOutsideRoot = errors.New("path is outside the pane's working directory")

ErrOutsideRoot is a path that leads out of the pane's working directory: a call that will not be attempted, which is Flockdeck's own decision rather than a failure of the underlying operation.

Functions

This section is empty.

Types

type Params

type Params struct {
	Type       string              `json:"type"`
	Properties map[string]Property `json:"properties"`
	Required   []string            `json:"required,omitempty"`
}

Params is a JSON Schema object describing a tool's arguments.

type Property

type Property struct {
	Type        string    `json:"type"`
	Description string    `json:"description,omitempty"`
	Items       *Property `json:"items,omitempty"`
	Enum        []string  `json:"enum,omitempty"`
}

Property is one argument.

type Root

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

Root is the pane's working directory and the boundary of everything the tools can reach.

The confinement is deliberately not a permission question. A model that asks to read C:\Users\someone\.ssh\id_rsa, or to write outside the worktree it was given, is refused outright: offering that for approval would put the decision in front of somebody who is approving a dozen calls a minute, and the one time it matters is the time it slips through.

func NewRoot

func NewRoot(dir string) (*Root, error)

NewRoot resolves dir into a root, following symbolic links so that later comparisons are between real paths.

func (*Root) Dir

func (r *Root) Dir() string

Dir is the root itself.

func (*Root) Rel

func (r *Root) Rel(abs string) string

Rel is a path as it should be shown: relative to the root, with forward slashes, so that a message reads the same whichever platform produced it.

func (*Root) Resolve

func (r *Root) Resolve(p string) (string, error)

Resolve turns a path from the model into an absolute path inside the root, or refuses it. A relative path is taken from the root; an absolute one is accepted only if it is already inside it; "" means the root.

func (*Root) ResolveFile

func (r *Root) ResolveFile(p string) (string, error)

ResolveFile is Resolve for the tools that name one file. An empty path is refused rather than quietly meaning the working directory, because a call that forgot to say which file is a mistake, and a mistake should be sent back to the model rather than put in front of the user as a question about creating a file called nothing.

type Schema

type Schema struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Params      Params `json:"parameters"`
}

Schema is one tool as the model is told about it. Every wire format Flockdeck speaks -- Anthropic's `input_schema`, OpenAI's `function`, Gemini's `functionDeclarations` -- carries the same three things in a different envelope, so this is the shape they are all translated from.

type Set

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

Set is the tools one chat session offers, all confined to one directory.

func New

func New(cwd string) (*Set, error)

New builds the v1 tools for a pane working in cwd.

The directory is resolved through any symbolic links once, here, so that every later containment check compares like with like: on macOS a temporary directory reached through /tmp is really under /private/tmp, and a pane whose root was recorded by the shorter name would refuse every path in it.

func (*Set) HideEnv added in v0.2.3

func (s *Set) HideEnv(names ...string)

HideEnv keeps the named variables out of the environment of every command run_command runs. It is for the key Flockdeck handed the pane: that is in the chat's own environment for the chat to use, and a model that runs `env` has no business printing it into the conversation.

func (*Set) Lookup

func (s *Set) Lookup(name string) (Tool, bool)

Lookup finds a tool by the name the model called.

func (*Set) Tools

func (s *Set) Tools() []Tool

Tools returns the set in a stable order, which is the order the model is told about them in and so worth keeping the same from one turn to the next.

type Tool

type Tool interface {
	Name() string
	// Describe is the tool as the model is told about it, in the small corner
	// of JSON Schema every wire format understands.
	Describe() Schema
	// Approval is the question to put to the user before the call runs, or ""
	// when the call needs no permission. A call that will be refused outright
	// -- a path leading out of the pane's directory, arguments that do not
	// parse -- answers "" as well, because refusing is not the user's decision
	// to make and asking about it would only teach them to say yes.
	Approval(args json.RawMessage) string
	// Run performs the call and returns what the model should be told. An
	// error is a result too: it is handed back as the tool's output so the
	// model can correct itself rather than being left to guess.
	Run(ctx context.Context, args json.RawMessage) (string, error)
}

Tool is one thing the model can do. It is the contract in section 8 of design/multi-agent.md, and the only thing the chat loop sees.

Jump to

Keyboard shortcuts

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