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 ¶
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 ¶
NewRoot resolves dir into a root, following symbolic links so that later comparisons are between real paths.
func (*Root) Rel ¶
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 ¶
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 ¶
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 ¶
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
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.
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.