Go-native and cross-platform "tool" implementations for common local tasks, plus a small registry that makes them easy to expose to LLM tool-calling systems.
- Features at a glance
- Package overview
- Registry
- Tool outputs
- Sandboxing and path policy
- Examples
- Exec tool notes
- Development
- License
- Sandboxed execution for all tools under a enforced allowed roots and work directory.
- Symlinks are rejected throughout for safety.
- All implementations are cross-platform supporting lin/win/mac systems.
- Normalized tool spec to support text/image/binary output formats.
- Fully modular code for any customizations needed.
-
Grouped under:
fstool. -
readfile:encoding=text: reads UTF-8 text only (rejects non-text), with PDF text extraction support when the file is a PDF.encoding=binary: returns base64, emittingimageoutputs forimage/*MIME types andfileoutputs otherwise.- Safety: size caps and symlink-traversal hardening.
-
writefile:encoding=text: write UTF-8 contentencoding=binary: write base64-decoded bytes- Options:
overwrite,createParents(bounded), atomic writes, size caps, symlink hardening.
-
deletefile:- “Safe delete” by moving to trash.
trashDir=autotries system trash when possible; falls back to a local.trashdirectory.- Uses unique naming, best-effort cross-device handling, and avoids destructive removal when possible.
-
searchfiles: Recursively search file paths and UTF-8 text content using RE2 regex. -
listdirectory: List entries under a directory, optionally filtered by glob. -
statpath: Inspect a path (exists, size, timestamps, directory flag). -
mimeforpath: Best-effort MIME type detection (extension + sniffing). -
mimeforextension: MIME lookup for an extension.
-
Grouped under:
exectool -
shellcommand:- Execute one or more commands via a selected shell (
auto,sh,bash,pwsh,powershell,cmd, etc). - Enforces timeouts/output caps/command caps.
- Supports session-like persistence for workdir and environment across calls (note: not a persistent shell process).
- Execute one or more commands via a selected shell (
-
runscript:- Run an existing script from disk with arguments and environment overrides.
- Extension-based interpreter selection via
RunScriptPolicy(host-configurable).
-
Grouped under:
texttool -
readtextrange: Read lines, optionally constrained by unique start/end marker blocks. -
findtext: Find matches with context (modes: substring, regex (RE2/Go), exact line-block). -
inserttextlines: Insert lines at start/end or relative to a uniquely matched anchor block. -
replacetextlines: Replace exact line blocks; can disambiguate with immediate adjacentbeforeLines/afterLines. -
deletetextlines: Delete exact line blocks; can disambiguate with immediate adjacentbeforeLines/afterLines.
-
Grouped under:
imagetool -
readimage: Read intrinsic metadata (width/height/format/MIME), optionally include base64 content.
llmtools: Registry + tool registration helpers.spec: Tool manifests + output union types.fstool: Filesystem tools.exectool: Shell command execution and script execution.texttool: Safe, deterministic line-based text editing tools.imagetool: Image tools.
The registry provides:
- tool registration + lookup by
spec.FuncID - stable manifest ordering (
Tools()sorted by slug + funcID) - per-registry default call timeout via
WithDefaultCallTimeout - per-call timeout override via
llmtools.WithCallTimeout(...) - panic-to-error recovery around tool execution
-
Registry.Callreturns[]spec.ToolOutputUnion. -
The call wrapper can modify the union to support two common patterns:
-
Structured JSON-as-text (most tools)
- Most tools are registered via
RegisterTypedAsTextTool, which wraps the tool’s Go output as JSON and returns it as a singletextoutput item.
- Most tools are registered via
-
Typed content outputs
textoutput for UTF-8 text / extracted PDF textimageoutput for images whenencoding=binaryfileoutput for all other binaries whenencoding=binary- E.g.:
readfile: This output makesreadfilesuitable for LLM systems that support multi-modal/file outputs.
-
All Tools are are instance-owned tools. Hosts can configure:
workBaseDir: base directory for resolving relative pathsallowedRoots: optional allowlist roots; when set, all resolved paths must stay within these roots
This is the recommended way to run the tools safely inside a sandbox (for example, inside a temp workspace or per-user directory).
All examples are provided as end-to-end integration tests that:
- start from a registry
- register tools (sandboxed to a temp directory)
- execute realistic sequences: read/modify loops, text edits, shell sessions, script execution, binary/image workflows
Examples:
- Text read/modify loop (find/replace/insert/delete + verification):
text test - Filesystem + MIME + safe delete (trash) + binary/image flows:
fs + image test - Shell sessions + environment persistence + runscript:
exec test
-
OS support
- Cross-platform shell selection:
autochooses a safe default per OS. - Windows prefers
pwsh, then Windows PowerShell, thencmd.
- Cross-platform shell selection:
-
Timeouts
- The registry may enforce a call timeout (
WithDefaultCallTimeout). shellcommandandrunscriptalso enforce execution policy timeouts.- Ensure the registry timeout is >= tool execution timeout (or set registry timeout to 0) to avoid premature cancellation.
- The registry may enforce a call timeout (
-
Safety knobs
ExecutionPolicycaps total commands, command length, output bytes, and timeout.- “Hard blocked” commands are always blocked.
- Heuristic checks (fork-bomb/backgrounding patterns) can be toggled via
AllowDangerous.
-
RunScriptPolicy
- Interpreter selection is extension-based and host-configurable.
- Hosts can tighten allowed extensions and interpreter mappings.
- Formatting follows
gofumptandgolinesviagolangci-lint. Rules are in .golangci.yml. - Useful scripts are defined in
taskfile.yml; requires Task. - Bug reports and PRs are welcome:
- Keep the public API (
package llmtoolsandspec) small and intentional. - Avoid leaking provider‑specific types through the public surface; put them under
internal/. - Please run tests and linters before sending a PR.
- Keep the public API (
Copyright (c) 2026 - Present - Pankaj Pipada
All source code in this repository, unless otherwise noted, is licensed under the MIT License. See LICENSE for details.