fstool

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeleteFileArgs added in v0.6.0

type DeleteFileArgs struct {
	Path     string `json:"path"`
	TrashDir string `json:"trashDir,omitempty"` // "auto" default
}

type DeleteFileMethod added in v0.6.0

type DeleteFileMethod string
const (
	DeleteFileMethodRename        DeleteFileMethod = "rename"
	DeleteFileMethodCopyAndRemove DeleteFileMethod = "copyAndRemove"
	DeleteFileMethodSymlinkRehome DeleteFileMethod = "symlinkRehome"
)

type DeleteFileOut added in v0.6.0

type DeleteFileOut struct {
	OriginalPath string           `json:"originalPath"`
	TrashedPath  string           `json:"trashedPath"`
	Method       DeleteFileMethod `json:"method"`
}

type FSTool added in v0.7.0

type FSTool struct {
	// contains filtered or unexported fields
}

FSTool is an instance-owned filesystem tool runner. It centralizes path resolution and sandbox policy:

  • workBaseDir: base for resolving relative paths
  • allowedRoots: optional restriction; if empty, allow all
  • blockSymlinks: blocks symlink traversal (enforced downstream).

func NewFSTool added in v0.7.0

func NewFSTool(opts ...FSToolOption) (*FSTool, error)

func (*FSTool) DeleteFile added in v0.7.0

func (ft *FSTool) DeleteFile(ctx context.Context, args DeleteFileArgs) (*DeleteFileOut, error)

func (*FSTool) DeleteFileTool added in v0.7.0

func (ft *FSTool) DeleteFileTool() spec.Tool

func (*FSTool) ListDirectory added in v0.7.0

func (ft *FSTool) ListDirectory(ctx context.Context, args ListDirectoryArgs) (*ListDirectoryOut, error)

func (*FSTool) ListDirectoryTool added in v0.7.0

func (ft *FSTool) ListDirectoryTool() spec.Tool

func (*FSTool) MIMEForExtension added in v0.7.0

func (ft *FSTool) MIMEForExtension(ctx context.Context, args MIMEForExtensionArgs) (*MIMEForExtensionOut, error)

func (*FSTool) MIMEForExtensionTool added in v0.7.0

func (ft *FSTool) MIMEForExtensionTool() spec.Tool

func (*FSTool) MIMEForPath added in v0.7.0

func (ft *FSTool) MIMEForPath(ctx context.Context, args MIMEForPathArgs) (*MIMEForPathOut, error)

func (*FSTool) MIMEForPathTool added in v0.7.0

func (ft *FSTool) MIMEForPathTool() spec.Tool

func (*FSTool) ReadFile added in v0.7.0

func (ft *FSTool) ReadFile(
	ctx context.Context,
	args ReadFileArgs,
) ([]spec.ToolOutputUnion, error)

func (*FSTool) ReadFileTool added in v0.7.0

func (ft *FSTool) ReadFileTool() spec.Tool

func (*FSTool) SearchFiles added in v0.7.0

func (ft *FSTool) SearchFiles(ctx context.Context, args SearchFilesArgs) (*SearchFilesOut, error)

func (*FSTool) SearchFilesTool added in v0.7.0

func (ft *FSTool) SearchFilesTool() spec.Tool

func (*FSTool) StatPath added in v0.7.0

func (ft *FSTool) StatPath(ctx context.Context, args StatPathArgs) (*StatPathOut, error)

func (*FSTool) StatPathTool added in v0.7.0

func (ft *FSTool) StatPathTool() spec.Tool

func (*FSTool) WriteFile added in v0.7.0

func (ft *FSTool) WriteFile(ctx context.Context, args WriteFileArgs) (*WriteFileOut, error)

func (*FSTool) WriteFileTool added in v0.7.0

func (ft *FSTool) WriteFileTool() spec.Tool

type FSToolOption added in v0.7.0

type FSToolOption func(*FSTool) error

func WithAllowedRoots added in v0.7.0

func WithAllowedRoots(roots []string) FSToolOption

WithAllowedRoots restricts all filesystem paths to be within one of the provided roots. Roots are canonicalized (clean+abs+best-effort symlink eval) and must exist as directories.

func WithBlockSymlinks(block bool) FSToolOption

WithBlockSymlinks configures whether symlink traversal should be blocked (if supported downstream).

func WithWorkBaseDir added in v0.7.0

func WithWorkBaseDir(base string) FSToolOption

WithWorkBaseDir sets the base directory used to resolve relative input paths. If empty/whitespace, NewFSTool will pick an effective default (via InitPathPolicy).

type ListDirectoryArgs

type ListDirectoryArgs struct {
	Path              string                 `json:"path,omitempty"`
	NameGlob          string                 `json:"nameGlob,omitempty"`
	IncludeDotEntries bool                   `json:"includeDotEntries,omitempty"`
	Kind              ListDirectoryEntryKind `json:"kind,omitempty"`
	MaxEntries        int                    `json:"maxEntries,omitempty"`
}

type ListDirectoryEntry added in v0.13.0

type ListDirectoryEntry struct {
	Name string                 `json:"name"`
	Kind ListDirectoryEntryKind `json:"kind"`
}

type ListDirectoryEntryKind added in v0.13.0

type ListDirectoryEntryKind string
const (
	ListDirectoryEntryKindAll       ListDirectoryEntryKind = "all"
	ListDirectoryEntryKindFile      ListDirectoryEntryKind = "file"
	ListDirectoryEntryKindDirectory ListDirectoryEntryKind = "directory"
	ListDirectoryEntryKindOther     ListDirectoryEntryKind = "other"
)

type ListDirectoryOut

type ListDirectoryOut struct {
	Path              string               `json:"path"`
	ReachedMaxEntries bool                 `json:"reachedMaxEntries"`
	Items             []ListDirectoryEntry `json:"items,omitempty"`
}

type MIMEDetectMethod added in v0.4.0

type MIMEDetectMethod string
const (
	MIMEDetectMethodExtension MIMEDetectMethod = "extension"
	MIMEDetectMethodSniff     MIMEDetectMethod = "sniff"
)

type MIMEForExtensionArgs added in v0.4.0

type MIMEForExtensionArgs struct {
	Extension string `json:"extension"`
}

type MIMEForExtensionOut added in v0.4.0

type MIMEForExtensionOut struct {
	Extension           string   `json:"extension"`
	NormalizedExtension string   `json:"normalizedExtension"`
	MIMEType            string   `json:"mimeType"`
	BaseMIMEType        string   `json:"baseMIMEType"`
	Mode                MIMEMode `json:"mode"`
	Known               bool     `json:"known"`
}

type MIMEForPathArgs added in v0.4.0

type MIMEForPathArgs struct {
	Path string `json:"path"`
}

type MIMEForPathOut added in v0.4.0

type MIMEForPathOut struct {
	Path                string           `json:"path"`
	Extension           string           `json:"extension,omitempty"`
	NormalizedExtension string           `json:"normalizedExtension,omitempty"`
	MIMEType            string           `json:"mimeType"`
	BaseMIMEType        string           `json:"baseMIMEType"`
	Mode                MIMEMode         `json:"mode"`
	Method              MIMEDetectMethod `json:"method"`
}

type MIMEMode added in v0.4.0

type MIMEMode string
const (
	MIMEModeText     MIMEMode = "text"
	MIMEModeImage    MIMEMode = "image"
	MIMEModeDocument MIMEMode = "document"
	MIMEModeDefault  MIMEMode = "default"
)

type ReadFileArgs

type ReadFileArgs struct {
	Path     string `json:"path"`               // required
	Encoding string `json:"encoding,omitempty"` // "text" (default) | "binary"
}

type SearchFilesArgs

type SearchFilesArgs struct {
	Root              string              `json:"root,omitempty"`
	Query             string              `json:"query,omitempty"`
	Regexp            bool                `json:"regexp,omitempty"`
	SearchIn          SearchFilesSearchIn `json:"searchIn,omitempty"`
	NameGlob          string              `json:"nameGlob,omitempty"`
	CaseSensitive     *bool               `json:"caseSensitive,omitempty"`
	IncludeDotEntries bool                `json:"includeDotEntries,omitempty"`
	MaxResults        int                 `json:"maxResults,omitempty"`
}

type SearchFilesMatch added in v0.13.0

type SearchFilesMatch struct {
	Path      string               `json:"path"`
	MatchKind SearchFilesMatchKind `json:"matchKind"`
}

type SearchFilesMatchKind added in v0.13.0

type SearchFilesMatchKind string
const (
	SearchFilesMatchKindPath           SearchFilesMatchKind = "path"
	SearchFilesMatchKindContent        SearchFilesMatchKind = "content"
	SearchFilesMatchKindPathAndContent SearchFilesMatchKind = "pathAndContent"
)

type SearchFilesOut

type SearchFilesOut struct {
	Root              string             `json:"root"`
	Items             []SearchFilesMatch `json:"items,omitempty"`
	MatchCount        int                `json:"matchCount"`
	ReachedMaxResults bool               `json:"reachedMaxResults"`
}

type SearchFilesSearchIn added in v0.13.0

type SearchFilesSearchIn string
const (
	SearchFilesSearchInPath          SearchFilesSearchIn = "path"
	SearchFilesSearchInContent       SearchFilesSearchIn = "content"
	SearchFilesSearchInPathOrContent SearchFilesSearchIn = "pathOrContent"
)

type StatPathArgs

type StatPathArgs struct {
	Path string `json:"path"`
}

type StatPathOut

type StatPathOut struct {
	Path      string     `json:"path"`
	Name      string     `json:"name"`
	Exists    bool       `json:"exists"`
	IsDir     bool       `json:"isDir"`
	SizeBytes int64      `json:"sizeBytes,omitempty"`
	ModTime   *time.Time `json:"modTime,omitempty"`
}

type WriteFileAction added in v0.13.0

type WriteFileAction string
const (
	WriteFileActionCreated     WriteFileAction = "created"
	WriteFileActionOverwritten WriteFileAction = "overwritten"
)

type WriteFileArgs added in v0.6.0

type WriteFileArgs struct {
	Path          string `json:"path"`
	Encoding      string `json:"encoding,omitempty"` // "text"(default) | "binary"
	Content       string `json:"content"`
	Overwrite     bool   `json:"overwrite,omitempty"`
	CreateParents bool   `json:"createParents,omitempty"`
}

type WriteFileOut added in v0.6.0

type WriteFileOut struct {
	Path         string          `json:"path"`
	BytesWritten int64           `json:"bytesWritten"`
	Action       WriteFileAction `json:"action"`
}

Jump to

Keyboard shortcuts

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