| package | github.com/genai-io/san/internal/tool |
|---|---|
| layer | feature |
Registry of built-in tools the agent can call, with their JSON schemas, permission gate, side-effect plumbing, and per-call dispatch.
Every built-in tool (Bash, Read, Edit, Write, WebFetch, …)
registers into this package's singleton at init time. The agent loop calls
Execute(name, params, cwd) to dispatch; the registry resolves the tool,
runs the permission check (internal/setting), invokes the tool, and
returns a toolresult.ToolResult with stdout, error, side-effect handle,
and audit metadata.
Built-in tool registry: tools register at init time; consumers fetch by name and dispatch through the permission gate. The package exposes *Registry directly — no Service interface.
package tool
// Registry is the opaque handle. Type exported; fields unexported.
type Registry struct { /* internal fields */ }
func (r *Registry) Register(t Tool)
func (r *Registry) RegisterAlias(alias string, t Tool)
func (r *Registry) Get(name string) (Tool, bool)
func (r *Registry) List() []string
func (r *Registry) Execute(ctx context.Context, name string, params map[string]any, cwd string) toolresult.ToolResult
func (r *Registry) PopSideEffect(toolCallID string) any
// Package-level access
func Initialize(opts Options)
func Default() *Registry
func SetDefaultRegistry(r *Registry) // test-only
func ResetDefaultRegistry() // test-onlyRegistry(registry.go) — name →Toolmap plus alias map. The package-leveldefaultRegistryis the singleton; subpackages calltool.Register(...)frominit().- Schemas (
schema_base.go,schema_agent.go,schema_task.go) — JSON schema fragments shared by the built-in tools. - Permission gate (
perm/) — wraps tool execution withsetting.HasPermissionToUseTool. Returns deny / ask / allow. - Side-effect store —
Executemay return a token; the consumer callsPopSideEffect(token)to retrieve a queued action (e.g. a pending file write). - Subpackages own their tools:
fs/for filesystem,web/for fetch,agent/for the Agent tool,task/for task tools,skill/for skill invocation, etc.
- Registration: tools register from
init()in their subpackages. Initialize(Options{})flips the singleton todefaultRegistry— before that,Default()already returnsdefaultRegistry, soinit()-time registrations are not lost.- Per-call:
Executeis goroutine-safe; the registry uses an RWMutex.
internal/tool/execute_test.go — dispatch and not-found behavior.
internal/tool/schema_agent_test.go — schema generation for the Agent tool.
- Code:
internal/tool/ - Primitive:
packages/core.md(ToolandToolsinterfaces) - Permission gate:
packages/setting.md,concepts/permission-model.md - MCP-registered tools:
packages/mcp.md - Layer:
feature