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 -- ask the person at the terminal first, through an Asker that also raises 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 is a path that leads out of the pane's working directory. ErrOutsideRoot = errors.New("path is outside the pane's working directory") // ErrDenied is the user answering no. ErrDenied = errors.New("the user declined") )
Errors a tool returns for a call that will not be attempted. They are exported so the chat loop can tell a refusal, which is Flockdeck's own decision and worth showing plainly, from a failure of the underlying operation.
Functions ¶
Types ¶
type Allowlist ¶
type Allowlist struct {
// contains filtered or unexported fields
}
Allowlist is the run_command prefixes the user has approved for the rest of the session.
Approval is per call everywhere else, deliberately: an approved write is one file and the next one is a different decision. A command prefix is the one place where standing permission is worth offering, because a session spends its time running the same handful of commands -- `go test`, `git status` -- and asking every time trains the user to stop reading the question.
func NewAllowlist ¶
func NewAllowlist() *Allowlist
type Answer ¶
type Answer int
Answer is what the user said to one question.
const ( // AnswerNo declines this call. It is the zero value because it is what // every way of not answering -- a closed input, an unreadable terminal, a // reply nobody recognises -- has to mean. AnswerNo Answer = iota // AnswerYes permits this call and nothing else. AnswerYes // AnswerAlways permits this call and everything sharing its prefix for the // rest of the session. Offered for run_command only. AnswerAlways )
type Asker ¶
Asker puts an approval to the person at the terminal.
It is an interface because the chat loop, not this package, owns the pane's terminal: it knows what is on the screen, whether a turn is streaming, and how the input is being read. The tools know only what needs asking.
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 PrefixApprover ¶
type PrefixApprover interface {
Prefix(args json.RawMessage) string
Allow(prefix string)
}
PrefixApprover is a tool that can offer standing permission for a class of calls. run_command is the only one, and the reasoning is on Allowlist.
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 Question ¶
type Question struct {
// Tool is the name of the tool asking, so the notification can say what
// the pane wants without repeating the whole question.
Tool string
// Text is what Approval returned: a sentence ending in a question mark,
// occasionally with a line or two of detail under it.
Text string
// Prefix is the standing permission on offer, or "" when there is none.
Prefix string
}
Question is one approval put to the user.
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, together with the state they share: the directory they are confined to and the command prefixes the user has allowed for the rest of the session.
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.
type TerminalAsker ¶
type TerminalAsker struct {
// In and Out are the pane's terminal.
In io.Reader
Out io.Writer
// Notify is called with a one-line summary the moment the question goes
// up, before anything is read back.
//
// This is the point of asking in Flockdeck rather than in a terminal on its
// own: the chat client wires it to a Notification hook event, so the pane
// turns amber in the window and whoever is looking at eleven other panes
// is told which one is waiting for them. A nil Notify simply asks
// quietly, which is what a test wants.
Notify func(message string)
// contains filtered or unexported fields
}
TerminalAsker asks in the pane, on the terminal the agent is running in.
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.