Documentation
¶
Overview ¶
Package toolbase provides domain-neutral helpers shared by tool packages.
Package toolbase contains domain-neutral helpers shared by tool packages.
Package toolbase provides the small set of schema "semantic" wrappers used by FileEditTool, FileReadTool, etc. They mirror the TS zod helper style (semanticBoolean, semanticNumber) so the JSON schema published to the model carries human-readable descriptions and safe defaults.
Index ¶
- Constants
- func CanonicalPath(path string) string
- func DisplayPath(path string) string
- func MatchGlob(pattern string, path string) (bool, error)
- func MatchGlobRelativeTo(pattern string, path string, root string) (bool, error)
- func NewBase64ImageBlock(data, mediaType string) types.ContentBlock
- func ParseInput[T any](input map[string]any) (T, error)
- func ParseInputOrError[T any](input map[string]any) (T, *types.ToolResult)
- func ParseStrictInput[T any](input map[string]any) (T, error)
- func ParseStrictInputOrError[T any](input map[string]any) (T, *types.ToolResult)
- func PathContains(root, candidate string) bool
- func PathWithinAllowedDirs(candidate string, allowedDirs []string) bool
- func ResizeImageBytes(raw []byte, mediaType string, targetBytes int) ([]byte, string, error)
- func ResizeImageToolResult(res types.ToolResult) types.ToolResult
- func SemanticBoolean(description string, defaultValue bool) map[string]any
- func SemanticNumber(description string, minimum int, integer bool) map[string]any
- func SuggestNearbyPath(filePath, cwd string) string
Constants ¶
const ModelImageMaxBytes = 5 * 1024 * 1024
ModelImageMaxBytes is the maximum decoded size accepted for one tool image.
Variables ¶
This section is empty.
Functions ¶
func CanonicalPath ¶
CanonicalPath normalizes a filesystem path for containment comparisons. On Darwin it also removes the kernel's /private alias for public system directories so the same path has one comparison form.
func DisplayPath ¶
DisplayPath returns the stable user-facing representation of a path.
func MatchGlobRelativeTo ¶
MatchGlobRelativeTo behaves like MatchGlob but resolves path against root when path is absolute, so patterns like "src/**/*.go" continue to match "<root>/src/foo/bar.go". Patterns without a path separator match against the basename only.
func NewBase64ImageBlock ¶
func NewBase64ImageBlock(data, mediaType string) types.ContentBlock
NewBase64ImageBlock builds an image content block from already encoded data.
func ParseInput ¶
ParseInput unmarshals a map input into T using the standard JSON contract.
func ParseInputOrError ¶
func ParseInputOrError[T any](input map[string]any) (T, *types.ToolResult)
ParseInputOrError parses input and projects decoding failures as a failed tool result suitable for returning from Execute.
func ParseStrictInput ¶
ParseStrictInput decodes T and rejects fields not declared by its JSON contract.
func ParseStrictInputOrError ¶
func ParseStrictInputOrError[T any](input map[string]any) (T, *types.ToolResult)
ParseStrictInputOrError parses strict input and projects decoding failures as a failed tool result suitable for returning from Execute.
func PathContains ¶
PathContains reports whether candidate is root itself or a descendant.
func PathWithinAllowedDirs ¶
PathWithinAllowedDirs checks containment against canonical absolute roots. Symlinks in the longest existing prefix are resolved for both candidate and roots; a not-yet-created suffix is then reattached to the resolved prefix.
func ResizeImageBytes ¶
ResizeImageBytes downsamples an encoded image (PNG/JPEG) until its byte size drops below `targetBytes`. We approximate matplotlib DPI=300 → DPI=96 by halving width/height repeatedly; the JPEG quality ladder (90 → 75 → 60) handles the long tail. Returns the encoded bytes and the media type (which switches to image/jpeg when JPEG is the smaller form).
func ResizeImageToolResult ¶
func ResizeImageToolResult(res types.ToolResult) types.ToolResult
ResizeImageToolResult mutates res in-place to apply the disk- fallback + DPI downsampling pipeline TS uses to fit Anthropic's 5MB image cap. When the image already fits, it is returned unchanged.
The caller is expected to have populated res.ContentBlocks with an ImageBlock built from the stdout data URI; this routine is a no-op for non-image results.
func SemanticBoolean ¶
SemanticBoolean returns a JSON Schema object describing a boolean property with a human-friendly description and a default value. The `_semantic` marker distinguishes schemas built via this helper from raw boolean schemas, letting downstream introspection tell the two apart.
func SemanticNumber ¶
SemanticNumber returns a JSON Schema object describing a numeric property with bounds and a description. `minimum`/`maximum` are emitted only when non-zero (use math.Inf-style sentinels by passing 0 to skip). `integer` is set when the value must be a whole number.
func SuggestNearbyPath ¶
SuggestNearbyPath returns the closest sibling path for a misspelled input.
Types ¶
This section is empty.