Documentation
¶
Overview ¶
Package tools holds the tools Scribe's agent can call. Each tool is a value implementing Tool; the agent loop looks them up in a Registry.
Index ¶
- func Arr(desc string, items map[string]any) map[string]any
- func Bool(desc string) map[string]any
- func Decode(args json.RawMessage, v any) error
- func DeniedWithReason(reason string) string
- func Enum(desc string, vals ...string) map[string]any
- func Int(desc string) map[string]any
- func IsReadOnlyCall(t Tool, args json.RawMessage) bool
- func NoteApproval(ctx context.Context, reason string)
- func Schema(props map[string]any, required ...string) json.RawMessage
- func Service[T any](e *Env, key string) (T, bool)
- func SetApprovalReason(ctx context.Context, reason string)
- func Str(desc string) map[string]any
- func WithCallNotes(ctx context.Context) (context.Context, func() string)
- func WithReasonSlot(ctx context.Context) (context.Context, func() string)
- type Approval
- type CallReadOnly
- type ClaimSource
- type Decision
- type Env
- type FileTracker
- type Host
- type Question
- type Registry
- type Result
- type Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode(args json.RawMessage, v any) error
Decode unmarshals args into v, tolerating an empty payload.
func DeniedWithReason ¶
DeniedWithReason is the tail a caller appends to a denial message: the reason the Host gave (the person's words, or why the phone side failed), otherwise nothing.
func IsReadOnlyCall ¶
func IsReadOnlyCall(t Tool, args json.RawMessage) bool
IsReadOnlyCall reports whether this particular call of t only reads.
func NoteApproval ¶
NoteApproval records that the user approved a call and gave a note. It is a no-op for an empty reason or a context without a slot. Call it after an approval that was not a denial, with the reason the Host gave.
func Schema ¶
func Schema(props map[string]any, required ...string) json.RawMessage
Schema is a helper to build a JSON Schema object for tool specs:
Schema(map[string]any{"path": Str("file path")}, "path")
func SetApprovalReason ¶
SetApprovalReason records the reason a Host gives for its answer. It is a no-op when the context has no slot. Long text is cut to 500 bytes.
func WithCallNotes ¶
WithCallNotes returns a context that collects approval notes for one tool call, and a function that returns them joined by newlines ("" when none).
Types ¶
type Approval ¶
type Approval struct {
Tool string // tool name
Kind string // "shell", "write_outside", "destructive", "web", "mcp"
Title string // short line, e.g. "Run shell command"
Detail string // the command / path / URL
Danger bool // destructive: render red, default to Deny
}
Approval is a question to the user before a risky action.
type CallReadOnly ¶
type CallReadOnly interface {
ReadOnlyCall(args json.RawMessage) bool
}
CallReadOnly is implemented by tools whose read-only-ness depends on the arguments (git status vs git commit). The agent's mode gate and its parallel scheduler prefer it over Tool.ReadOnly.
type ClaimSource ¶
type ClaimSource interface {
// OtherClaims maps each file another tab claimed to that tab's label.
OtherClaims() map[string]string
}
ClaimSource lists live file claims held by other tabs. Paths are absolute.
type Env ¶
type Env struct {
Workdir string // absolute project root
CallID string // the tool call id
Host Host
Files FileTracker
// Services is a bag of optional subsystems keyed by name ("repomap",
// "lsp", "memory", "skills", "plan", "tasks", "dispatch", "mcp"). Each
// package that provides one documents its key and type.
Services map[string]any
// Mode is the agent mode ("default", "plan", "auto", ...). Tools that
// self-approve in auto mode read it.
Mode string
// Scope identifies the conversation context the call belongs to: one
// agent's history, renewed whenever that history is compacted, reset or
// replaced. Tools that remember what the model has already seen (the read
// tool's "unchanged" notices) key that memory by Scope.
Scope string
// Claims reports the files other tabs in this process have claimed. Nil
// when the tab has no cross-tab registry (tests, headless runs).
Claims ClaimSource
}
Env is the per-call environment. Optional services are nil when not available; tools must check.
type FileTracker ¶
type FileTracker interface {
// BeforeWrite snapshots abs before it is modified (or notes that it
// did not exist). Idempotent within a checkpoint.
BeforeWrite(abs string)
// MarkRead records that the model has seen abs at its current mtime.
MarkRead(abs string)
// StaleSinceRead reports whether abs changed on disk since MarkRead
// (false when it was never read).
StaleSinceRead(abs string) bool
// WasRead reports whether the model has read abs this session.
WasRead(abs string) bool
}
FileTracker records file contents before the agent changes them, so a turn can be undone (checkpoints) and edits can be refused on files the model has not read or that changed since it read them.
type Host ¶
type Host interface {
Approve(ctx context.Context, a Approval) Decision
Ask(ctx context.Context, q Question) (string, error)
// Progress streams partial output of a long-running call (shell
// output lines, subagent steps) to the UI. May be a no-op.
Progress(callID, text string)
}
Host is what the agent's surroundings (TUI, headless runner, Lectern session) provide to tools. Every method must be safe to call from any goroutine. Implementations for headless use may answer without a user.
type Question ¶
type Question struct {
Question string `json:"question"`
Options []string `json:"options,omitempty"`
// AllowFreeText lets the user type an answer instead of picking.
AllowFreeText bool `json:"allow_free_text,omitempty"`
// Kind is "" for a plain question or "plan_review" when the agent is
// asking the user to approve a plan (the UI shows the plan view).
Kind string `json:"kind,omitempty"`
// Body is extra content to show with the question (the plan markdown).
Body string `json:"body,omitempty"`
// NoSkip means the question must be answered: Esc does not skip it.
NoSkip bool `json:"no_skip,omitempty"`
}
Question is an ask_user prompt.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a name-indexed set of tools.
func (*Registry) SortedNames ¶
SortedNames is Names sorted alphabetically.
func (*Registry) Specs ¶
Specs returns specs in registration order, restricted to names when names is non-nil.
func (*Registry) Unregister ¶
Unregister removes the tool called name. It reports whether one was registered. Specs and Names no longer include it, so the next model request does not offer it.
type Result ¶
type Result struct {
Output string `json:"output"`
IsError bool `json:"is_error,omitempty"`
// Tag is a short machine code for an error, so the UI and hooks can
// branch without parsing Output. Empty when there is nothing to branch
// on. Known values: "forbidden", "not found", "concurrent modification",
// "stale_undo", "contested".
Tag string `json:"tag,omitempty"`
// Summary is a one-line human summary for tool rows, e.g. "42 lines",
// "3 matches in 2 files", "+5 -2". Optional.
Summary string `json:"summary,omitempty"`
// Diff is a unified diff for edit/write tools, rendered by the UI.
Diff string `json:"diff,omitempty"`
// Files lists paths (relative to the workdir) the call created,
// changed or deleted. Used for checkpoints, "files edited" and the
// changed-files bar.
Files []string `json:"files,omitempty"`
// Meta is free-form structured data for the UI.
Meta map[string]any `json:"meta,omitempty"`
// Image is an image the model should see with the result (a screenshot).
// ImageType is its media type. Adapters that cannot send images drop it.
Image []byte `json:"-"`
ImageType string `json:"-"`
}
Result is what a tool returns to the model (Output) and to the UI (Display and Meta). Output is always plain text the model reads.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package exec holds Scribe's execution tools: shell (foreground and background), project (detected test, lint, build and run commands) and git.
|
Package exec holds Scribe's execution tools: shell (foreground and background), project (detected test, lint, build and run commands) and git. |
|
Package fs holds Scribe's file tools: read, write_file, edit_file, multi_edit, undo_edit, list_dir, glob and grep.
|
Package fs holds Scribe's file tools: read, write_file, edit_file, multi_edit, undo_edit, list_dir, glob and grep. |
|
Package web holds Scribe's web tools: web_search (SearXNG or DuckDuckGo HTML) and fetch_page (a readable-text fetch with an SSRF guard).
|
Package web holds Scribe's web tools: web_search (SearXNG or DuckDuckGo HTML) and fetch_page (a readable-text fetch with an SSRF guard). |