builtin

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Overview

Package builtin provides the built-in tools for the OK agent.

bash_security.go — command classification and whitelist for bash.Execute

System prompt component sizes (measured): - DefaultSystemPrompt: ~1900 bytes (~475 tokens) - LanguagePolicy: ~290 bytes (~72 tokens) - Memory/skills/env: ~1500 bytes (~375 tokens) - Tool schemas (36): ~14723 bytes (~3680 tokens) -------------------------------------------------- TOTAL per-turn prefix: ~18413 bytes (~4602 tokens)

Optimization targets: 1. Minify schemas (-30% = -4400 bytes / -1100 tokens) ← BIGGEST WIN 2. Shorten descriptions (-50% = -2400 bytes / -600 tokens) 3. Remove redundant tools from prompt during simple tasks

Every turn saved = ~1800 fewer tokens in prefix. 20-turn session = 36,000 fewer tokens = ~$3.60 savings (DeepSeek Flash).

Package builtin — gosyntax.go replaced by precheck.go. precheckGoFile in precheck.go handles all Go file validation (syntax + go vet).

Package builtin — dead code removed; model-router tool was never wired.

Package builtin provides OK's compile-time built-in tools. Each tool self-registers via init(); main blank-imports this package to wire them in.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCommand

func CheckCommand(cmd string) error

CheckCommand runs before bash execution. Returns nil to allow, error to deny.

func ConfineBash

func ConfineBash(spec sandbox.Spec) tool.Tool

ConfineBash returns the bash built-in bound to an OS-sandbox spec, overriding the unconfined instance registered at init. When the spec enforces, bash runs each command through the sandbox (see package sandbox).

func ConfineReaders

func ConfineReaders(roots []string) []tool.Tool

ConfineReaders returns the file-reading built-ins (read_file, ls, glob, grep) bound to roots — the only directories they may access. Follows the same pattern as ConfineWriters: an empty roots slice yields unconfined readers.

func ConfineWriters

func ConfineWriters(roots []string) []tool.Tool

ConfineWriters returns the file-writing built-ins (write_file, edit_file, multi_edit) bound to roots — the only directories they may modify. The composition root adds these to the per-run registry to override the unconfined instances registered at init time, so writes stay inside the workspace by default. roots may be relative; they are resolved to absolute, symlink-free paths once here. An empty roots slice yields unconfined writers.

func NewComputerUseTool

func NewComputerUseTool(baseURL, apiKey, model string) tool.Tool

NewComputerUseTool creates a Tool that runs the screenshot→analyze→act→verify loop.

func NewOCRTool

func NewOCRTool(baseURL, apiKey, model string) tool.Tool

NewOCRTool creates a Tool that extracts text from images via LLM vision API.

func NewToolGroupsTool

func NewToolGroupsTool(reg tool.RegistrySetGroups) tool.Tool

NewToolGroupsTool creates a tool-groups tool bound to a registry.

func NewTranslateTool

func NewTranslateTool(baseURL, apiKey, model string) tool.Tool

NewTranslateTool creates a Tool that translates text using the configured LLM.

func SetSemanticEngine

func SetSemanticEngine(eng *semantic.Engine)

SetSemanticEngine installs a semantic engine for the semantic-search tool. Called during boot. If nil, the tool reports "not configured".

func ToolGroup

func ToolGroup(name string) string

ToolGroup returns the group for a tool name, defaulting to "core".

Types

type EditStep

type EditStep struct {
	OldString  string `json:"old_string"`
	NewString  string `json:"new_string"`
	ReplaceAll bool   `json:"replace_all,omitempty"`
}

editStep is one edit in a multi_edit operation. Exported so preview.go can reuse the same apply logic.

type Workspace

type Workspace struct {
	Dir        string
	WriteRoots []string
	Bash       sandbox.Spec
}

Workspace binds all file tools to a project directory. When Dir is non-empty, relative paths are resolved within it and writes outside it are confined. AllowWrite lists additional directories file-writer tools may modify (e.g. /tmp for temporary output).

func (Workspace) Tools

func (ws Workspace) Tools(enabled ...string) []tool.Tool

Tools returns workspace-scoped built-in tools: writers confined to WriteRoots (falling back to Dir), readers open, and bash bound to the sandbox spec. When enabled is non-empty, only those named tools are returned; nil/empty means all.

Jump to

Keyboard shortcuts

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