CreateBuiltinTools
Go · module github.com/muthuishere/toolnexus/golang · SPEC §4A · golang/builtin.go
func CreateBuiltinTools() []ToolConstructs all ten built-in tools — the opencode-ported file/shell/web toolset toolnexus ships by
default — with no toolkit and no filtering. The order is fixed for parity across ports: bash,
read, write, edit, grep, glob, webfetch, question, apply_patch, todowrite.
When to use it
Section titled “When to use it”Reach for CreateBuiltinTools when you want the file/shell/web tools without going through
Options.Builtins on a toolkit — inspecting the full set, wiring your own selection logic on top,
or hand-assembling a []Tool for a use case that doesn’t fit CreateToolkit.
Why this and not the alternative
Section titled “Why this and not the alternative”Examples
Section titled “Examples”1. The full set, in the fixed order
Section titled “1. The full set, in the fixed order”package main
import ( "fmt" "log"
toolnexus "github.com/muthuishere/toolnexus/golang")
func main() { tools := toolnexus.CreateBuiltinTools() if len(tools) != 10 { log.Fatalf("expected 10 built-ins, got %d", len(tools)) }
wantOrder := []string{ "bash", "read", "write", "edit", "grep", "glob", "webfetch", "question", "apply_patch", "todowrite", } for i, name := range wantOrder { if tools[i].Name != name { log.Fatalf("position %d: expected %q, got %q", i, name, tools[i].Name) } if tools[i].Source != toolnexus.SourceBuiltin { log.Fatalf("expected Source builtin for %q, got %v", name, tools[i].Source) } }
fmt.Println("ok:", len(tools), "built-ins in fixed order")}2. Calling one directly, no toolkit involved
Section titled “2. Calling one directly, no toolkit involved”package main
import ( "fmt" "log" "os" "path/filepath"
toolnexus "github.com/muthuishere/toolnexus/golang")
func main() { tools := toolnexus.CreateBuiltinTools()
var write, read *toolnexus.Tool for i := range tools { switch tools[i].Name { case "write": write = &tools[i] case "read": read = &tools[i] } } if write == nil || read == nil { log.Fatal("expected write and read among the built-ins") }
path := filepath.Join(os.TempDir(), "toolnexus-docs-createbuiltintools.txt") defer os.Remove(path)
wRes, err := write.Execute(map[string]any{"path": path, "content": "hello"}, nil) if err != nil || wRes.IsError { log.Fatalf("unexpected write result: %+v %v", wRes, err) }
rRes, err := read.Execute(map[string]any{"path": path}, nil) if err != nil || rRes.IsError || rRes.Output != "hello" { log.Fatalf("unexpected read result: %+v %v", rRes, err) }
fmt.Println("ok:", rRes.Output)}3. Hand-assembling a custom set on top of the full list
Section titled “3. Hand-assembling a custom set on top of the full list”CreateBuiltinTools always returns all ten — filtering to a custom subset is your own slice logic,
which is exactly what SelectBuiltins does for you when the source is a
BuiltinsConfig.
package main
import ( "context" "fmt" "log"
toolnexus "github.com/muthuishere/toolnexus/golang")
func main() { only := map[string]bool{"read": true, "grep": true, "glob": true}
var readOnly []toolnexus.Tool for _, t := range toolnexus.CreateBuiltinTools() { if only[t.Name] { readOnly = append(readOnly, t) } }
if len(readOnly) != 3 { log.Fatalf("expected 3 tools, got %d", len(readOnly)) } for _, t := range readOnly { if !only[t.Name] { log.Fatalf("unexpected tool in custom set: %s", t.Name) } }
// Builtins:false turns the default ten OFF; only our hand-picked three go in // via ExtraTools — CreateBuiltinTools never wires itself into a toolkit on its own. tk, err := toolnexus.CreateToolkit(context.Background(), toolnexus.Options{ ExtraTools: readOnly, Builtins: false, }) if err != nil { log.Fatal(err) } defer tk.Close() if len(tk.Tools()) != 3 { log.Fatalf("expected exactly the 3 hand-picked tools, got %d", len(tk.Tools())) }
fmt.Println("ok:", len(readOnly), "hand-picked read-only tools")}Return value
Section titled “Return value”[]Tool — always length 10, always the same order, each with Source: SourceBuiltin.
See also
Section titled “See also”SelectBuiltins— pick which built-in file/shell/web tools are in play, by name or by source toggle.CreateToolkit— the aggregator; itsBuiltinsoption callsSelectBuiltinsinternally.