core

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxSize = 70000

DefaultMaxSize is the default maximum JSON output size in characters (70K) This accounts for Claude's ~75K character limit on tool responses

Variables

This section is empty.

Functions

func CreateBackupPath

func CreateBackupPath(path string) string

CreateBackupPath generates a backup path

func EnsureDir

func EnsureDir(path string) error

EnsureDir creates directory and parents if needed

func EstimateJSONStringSize added in v1.3.0

func EstimateJSONStringSize(s string) int

EstimateJSONStringSize estimates the size of a string after JSON encoding JSON escapes: \n, \t, \r, ", \, and control characters

func GetFileTimestamps

func GetFileTimestamps(info os.FileInfo) (created, accessed, modified time.Time)

GetFileTimestamps returns the created, accessed, and modified timestamps for a file On Linux, creation time (birth time) is not always available, so we use ctime as fallback

func IsPathAllowed

func IsPathAllowed(path string, allowedDirs []string) bool

IsPathAllowed checks if a path is within any of the allowed directories

func NormalizePath

func NormalizePath(path string) (string, error)

NormalizePath cleans and normalizes a file path

func ResolveSymlink(path string) (string, error)

ResolveSymlink resolves a symlink to its target path

func ValidatePath

func ValidatePath(path string, allowedDirs []string) error

ValidatePath checks if a path is allowed based on the allowed directories list

Types

type BatchFileOperationsOptions

type BatchFileOperationsOptions struct {
	Operations  []BatchOperation
	AllowedDirs []string
}

BatchFileOperationsOptions contains input parameters for BatchFileOperations

type BatchOpResult

type BatchOpResult struct {
	Success    int            `json:"success"`
	Failed     int            `json:"failed"`
	Operations []FileOpResult `json:"operations"`
}

BatchOpResult represents the result of batch operations

func BatchFileOperations

func BatchFileOperations(opts BatchFileOperationsOptions) (*BatchOpResult, error)

BatchFileOperations performs multiple file operations

type BatchOperation

type BatchOperation struct {
	Operation   string `json:"operation"`
	Source      string `json:"source"`
	Destination string `json:"destination,omitempty"`
	Recursive   bool   `json:"recursive,omitempty"`
}

BatchOperation represents a single batch operation

type CodeMatch

type CodeMatch struct {
	File    string   `json:"file"`
	Line    int      `json:"line"`
	Content string   `json:"content"`
	Context []string `json:"context,omitempty"`
}

CodeMatch represents a single code match

type CompressFilesOptions

type CompressFilesOptions struct {
	Paths       []string
	Output      string
	Format      string
	AllowedDirs []string
}

CompressFilesOptions contains input parameters for CompressFiles

type CompressResult

type CompressResult struct {
	Output     string `json:"output"`
	Format     string `json:"format"`
	Size       int64  `json:"size"`
	FilesAdded int    `json:"files_added"`
	Success    bool   `json:"success"`
}

CompressResult represents compression result

func CompressFiles

func CompressFiles(opts CompressFilesOptions) (*CompressResult, error)

CompressFiles compresses files into an archive

type CopyFileOptions

type CopyFileOptions struct {
	Source      string
	Destination string
	AllowedDirs []string
}

CopyFileOptions contains input parameters for CopyFile

type CreateDirectoriesOptions added in v1.3.0

type CreateDirectoriesOptions struct {
	Paths       []string
	Recursive   bool
	AllowedDirs []string
}

CreateDirectoriesOptions contains input parameters for CreateDirectories

type CreateDirectoriesResult added in v1.3.0

type CreateDirectoriesResult struct {
	Directories []CreateDirectoryResult `json:"directories"`
	Success     int                     `json:"success"`
	Failed      int                     `json:"failed"`
	Message     string                  `json:"message"`
}

CreateDirectoriesResult represents the result of creating multiple directories

func CreateDirectories added in v1.3.0

func CreateDirectories(opts CreateDirectoriesOptions) (*CreateDirectoriesResult, error)

CreateDirectories creates multiple directories concurrently

type CreateDirectoryOptions

type CreateDirectoryOptions struct {
	Path        string
	Recursive   bool
	AllowedDirs []string
}

CreateDirectoryOptions contains input parameters for CreateDirectory

type CreateDirectoryResult

type CreateDirectoryResult struct {
	Path    string `json:"path"`
	Created bool   `json:"created"`
	Message string `json:"message"`
}

CreateDirectoryResult represents the result of creating a directory

func CreateDirectory

func CreateDirectory(opts CreateDirectoryOptions) (*CreateDirectoryResult, error)

CreateDirectory creates a directory

type DeleteFileOptions

type DeleteFileOptions struct {
	Path        string
	Recursive   bool
	AllowedDirs []string
}

DeleteFileOptions contains input parameters for DeleteFile

type DirectoryEntry

type DirectoryEntry struct {
	Name         string `json:"name"`
	Path         string `json:"path"`
	Type         string `json:"type"` // "file" or "directory"
	IsDir        bool   `json:"is_dir"`
	Size         int64  `json:"size"`
	SizeReadable string `json:"size_readable"`
	Mode         string `json:"mode"`
	Permissions  uint32 `json:"permissions"`
	Modified     string `json:"modified"`
	Created      string `json:"created,omitempty"`
	Accessed     string `json:"accessed,omitempty"`
	Extension    string `json:"extension,omitempty"`
	MimeType     string `json:"mime_type,omitempty"`
	IsReadable   bool   `json:"is_readable"`
	IsWritable   bool   `json:"is_writable"`
}

DirectoryEntry represents a file or directory entry

type DiskUsageOptions

type DiskUsageOptions struct {
	Path        string
	AllowedDirs []string
}

DiskUsageOptions contains input parameters for GetDiskUsage

type DiskUsageResult

type DiskUsageResult struct {
	Path       string `json:"path"`
	TotalSize  int64  `json:"total_size"`
	TotalFiles int    `json:"total_files"`
	TotalDirs  int    `json:"total_dirs"`
}

DiskUsageResult represents disk usage information

func GetDiskUsage

func GetDiskUsage(opts DiskUsageOptions) (*DiskUsageResult, error)

GetDiskUsage calculates disk usage for a path

type EditBlockOptions

type EditBlockOptions struct {
	Path        string
	OldString   string
	NewString   string
	AllowedDirs []string
}

EditBlockOptions contains input parameters for EditBlock

type EditBlocksOptions

type EditBlocksOptions struct {
	Path        string
	Edits       []EditPair
	AllowedDirs []string
}

EditBlocksOptions contains input parameters for EditBlocks

type EditFileOptions

type EditFileOptions struct {
	Path        string
	Operation   string
	Line        int
	Content     string
	AllowedDirs []string
}

EditFileOptions contains input parameters for EditFile

type EditMultipleBlocksOptions

type EditMultipleBlocksOptions struct {
	Path        string
	Edits       []MultiEditOperation
	Backup      bool
	AllowedDirs []string
}

EditMultipleBlocksOptions contains input parameters for EditMultipleBlocks

type EditOpResult

type EditOpResult struct {
	EditIndex    int    `json:"edit_index"`
	Mode         string `json:"mode"`
	Status       string `json:"status"`
	LineNumber   int    `json:"line_number,omitempty"`
	OldText      string `json:"old_text_preview,omitempty"`
	NewText      string `json:"new_text_preview,omitempty"`
	InsertedLine string `json:"inserted_line,omitempty"`
	DeletedLine  string `json:"deleted_line,omitempty"`
	ChangesMade  int    `json:"changes_made"`
}

EditOpResult represents the result of a single edit operation

type EditPair

type EditPair struct {
	OldString string `json:"old_string"`
	NewString string `json:"new_string"`
}

EditPair represents an old/new string pair for editing

type EditResult

type EditResult struct {
	Path       string `json:"path"`
	Success    bool   `json:"success"`
	Changes    int    `json:"changes"`
	Backup     string `json:"backup,omitempty"`
	Message    string `json:"message"`
	OldContent string `json:"old_content,omitempty"`
	NewContent string `json:"new_content,omitempty"`
}

EditResult represents the result of an edit operation

func EditBlock

func EditBlock(opts EditBlockOptions) (*EditResult, error)

EditBlock replaces a single block of text in a file

func EditBlocks

func EditBlocks(opts EditBlocksOptions) (*EditResult, error)

EditBlocks applies multiple edits to a single file

func EditFile

func EditFile(opts EditFileOptions) (*EditResult, error)

EditFile performs line-based file editing

func SafeEdit

func SafeEdit(opts SafeEditOptions) (*EditResult, error)

SafeEdit performs a safe edit with backup and dry-run support

type ExtractArchiveOptions

type ExtractArchiveOptions struct {
	Archive     string
	Destination string
	AllowedDirs []string
}

ExtractArchiveOptions contains input parameters for ExtractArchive

type ExtractLinesOptions

type ExtractLinesOptions struct {
	Path         string
	LineNumbers  []int
	StartLine    int
	EndLine      int
	Pattern      string
	ContextLines int
	AllowedDirs  []string
}

ExtractLinesOptions contains input parameters for ExtractLines

type ExtractLinesResult

type ExtractLinesResult struct {
	Path    string `json:"path"`
	Content string `json:"content"`
	Lines   int    `json:"lines"`
}

ExtractLinesResult represents the result of extracting lines

func ExtractLines

func ExtractLines(opts ExtractLinesOptions) (*ExtractLinesResult, error)

ExtractLines extracts specific lines from a file

type ExtractResult

type ExtractResult struct {
	Archive        string `json:"archive"`
	Destination    string `json:"destination"`
	FilesExtracted int    `json:"files_extracted"`
	Success        bool   `json:"success"`
}

ExtractResult represents extraction result

func ExtractArchive

func ExtractArchive(opts ExtractArchiveOptions) (*ExtractResult, error)

ExtractArchive extracts an archive to a destination

type FileOpResult

type FileOpResult struct {
	Path        string `json:"path"`
	Source      string `json:"source,omitempty"`
	Destination string `json:"destination,omitempty"`
	Success     bool   `json:"success"`
	Operation   string `json:"operation"`
	Message     string `json:"message"`
}

FileOpResult represents the result of a file operation

func CopyFile

func CopyFile(opts CopyFileOptions) (*FileOpResult, error)

CopyFile copies a file or directory

func DeleteFile

func DeleteFile(opts DeleteFileOptions) (*FileOpResult, error)

DeleteFile deletes a file or directory

func MoveFile

func MoveFile(opts MoveFileOptions) (*FileOpResult, error)

MoveFile moves or renames a file or directory

type FileSearchResult

type FileSearchResult struct {
	Path    string `json:"path"`
	Name    string `json:"name"`
	Size    int64  `json:"size"`
	IsDir   bool   `json:"is_dir"`
	ModTime string `json:"mod_time"`
}

FileSearchResult represents a found file

type FileSizeEntry added in v1.3.0

type FileSizeEntry struct {
	Path string `json:"path"`
	Size int64  `json:"size"`
}

FileSizeEntry represents a file and its size

type FindLargeFilesOptions

type FindLargeFilesOptions struct {
	Path        string
	MinSize     int64
	Limit       int
	AllowedDirs []string
}

FindLargeFilesOptions contains input parameters for FindLargeFiles

type FindLargeFilesResult

type FindLargeFilesResult struct {
	Path    string          `json:"path"`
	MinSize int64           `json:"min_size"`
	Files   []LargeFileInfo `json:"files"`
	Total   int             `json:"total"`
}

FindLargeFilesResult represents find large files result

func FindLargeFiles

func FindLargeFiles(opts FindLargeFilesOptions) (*FindLargeFilesResult, error)

FindLargeFiles finds files larger than a minimum size

type GetDirectoryTreeOptions

type GetDirectoryTreeOptions struct {
	Path         string
	MaxDepth     int
	ShowHidden   bool
	IncludeFiles bool
	Pattern      string
	AllowedDirs  []string
}

GetDirectoryTreeOptions contains input parameters for GetDirectoryTree

type GetDirectoryTreeResult

type GetDirectoryTreeResult struct {
	Tree       *TreeNode `json:"tree"`
	TotalDirs  int       `json:"total_dirs"`
	TotalFiles int       `json:"total_files"`
	TotalSize  int64     `json:"total_size"`
}

GetDirectoryTreeResult represents the result of a directory tree operation

func GetDirectoryTree

func GetDirectoryTree(opts GetDirectoryTreeOptions) (*GetDirectoryTreeResult, error)

GetDirectoryTree gets the directory tree structure

type GetFileInfoOptions

type GetFileInfoOptions struct {
	Path        string
	AllowedDirs []string
}

GetFileInfoOptions contains input parameters for GetFileInfo

type GetFileInfoResult

type GetFileInfoResult struct {
	Path     string `json:"path"`
	Name     string `json:"name"`
	Size     int64  `json:"size"`
	IsDir    bool   `json:"is_dir"`
	Mode     string `json:"mode"`
	Modified string `json:"modified"`
}

GetFileInfoResult represents file information

func GetFileInfo

func GetFileInfo(opts GetFileInfoOptions) (*GetFileInfoResult, error)

GetFileInfo gets detailed information about a file or directory

type LargeFileInfo

type LargeFileInfo struct {
	Path    string `json:"path"`
	Size    int64  `json:"size"`
	ModTime string `json:"mod_time"`
}

LargeFileInfo represents a large file found

type LargeWriteFileOptions

type LargeWriteFileOptions struct {
	Path        string
	Content     string
	CreateDirs  bool
	Append      bool
	Backup      bool
	VerifyWrite bool
	AllowedDirs []string
}

LargeWriteFileOptions contains input parameters for LargeWriteFile

type ListAllowedDirectoriesResult

type ListAllowedDirectoriesResult struct {
	AllowedDirectories []string `json:"allowed_directories"`
}

ListAllowedDirectoriesResult represents the allowed directories

func ListAllowedDirectories

func ListAllowedDirectories(allowedDirs []string) *ListAllowedDirectoriesResult

ListAllowedDirectories returns the list of allowed directories

type ListDirectoryOptions

type ListDirectoryOptions struct {
	Path        string
	ShowHidden  bool
	Pattern     string
	SortBy      string
	Reverse     bool
	Page        int
	PageSize    int
	AllowedDirs []string
}

ListDirectoryOptions contains input parameters for ListDirectory

type ListDirectoryResult

type ListDirectoryResult struct {
	Path       string           `json:"path"`
	Items      []DirectoryEntry `json:"items"`
	Total      int              `json:"total"`
	Page       int              `json:"page,omitempty"`
	PageSize   int              `json:"page_size,omitempty"`
	TotalPages int              `json:"total_pages,omitempty"`
}

ListDirectoryResult represents the result of a directory listing

func ListDirectory

func ListDirectory(opts ListDirectoryOptions) (*ListDirectoryResult, error)

ListDirectory lists directory contents

type MoveFileOptions

type MoveFileOptions struct {
	Source      string
	Destination string
	AllowedDirs []string
}

MoveFileOptions contains input parameters for MoveFile

type MultiEditOperation

type MultiEditOperation struct {
	OldText    string `json:"old_text,omitempty"`
	NewText    string `json:"new_text,omitempty"`
	LineNumber int    `json:"line_number,omitempty"`
	Mode       string `json:"mode,omitempty"` // "replace", "insert_before", "insert_after", "delete_line"
}

MultiEditOperation represents a single edit operation in EditMultipleBlocks

type MultiEditResult

type MultiEditResult struct {
	Message         string         `json:"message"`
	Path            string         `json:"path"`
	TotalEdits      int            `json:"total_edits"`
	SuccessfulEdits int            `json:"successful_edits"`
	TotalChanges    int            `json:"total_changes"`
	OriginalLines   int            `json:"original_lines"`
	NewLines        int            `json:"new_lines"`
	EditResults     []EditOpResult `json:"edit_results"`
	BackupCreated   *string        `json:"backup_created"`
	BackupEnabled   bool           `json:"backup_enabled"`
	Size            int64          `json:"size"`
	SizeReadable    string         `json:"size_readable"`
	Timestamp       string         `json:"timestamp"`
}

MultiEditResult represents the detailed result of EditMultipleBlocks (fast-filesystem parity)

func EditMultipleBlocks

func EditMultipleBlocks(opts EditMultipleBlocksOptions) (*MultiEditResult, error)

EditMultipleBlocks applies multiple edits to a file with support for different modes Modes: replace (text matching), insert_before (line-based), insert_after (line-based), delete_line (line-based)

type ReadFileOptions

type ReadFileOptions struct {
	Path             string
	StartOffset      int
	MaxSize          int
	LineStart        int
	LineCount        int
	AllowedDirs      []string
	SizeCheckMaxSize int64 // Maximum allowed JSON output size (0 = use default, -1 = no limit, >0 = custom)
}

ReadFileOptions contains input parameters for ReadFile

type ReadFileResult

type ReadFileResult struct {
	Path      string `json:"path"`
	Content   string `json:"content"`
	Size      int64  `json:"size"`
	Lines     int    `json:"lines,omitempty"`
	Truncated bool   `json:"truncated,omitempty"`
	Error     string `json:"error,omitempty"`
}

ReadFileResult represents the result of a file read operation

func ReadFile

func ReadFile(opts ReadFileOptions) (*ReadFileResult, error)

ReadFile reads a file with optional line range or byte offset

type ReadMultipleFilesOptions

type ReadMultipleFilesOptions struct {
	Paths                 []string
	AllowedDirs           []string
	SizeCheckMaxTotalSize int64 // Maximum allowed total JSON output size (0 = use default, -1 = no limit, >0 = custom)
}

ReadMultipleFilesOptions contains input parameters for ReadMultipleFiles

type ReadMultipleFilesResult

type ReadMultipleFilesResult struct {
	Files   []ReadFileResult `json:"files"`
	Success int              `json:"success"`
	Failed  int              `json:"failed"`
}

ReadMultipleFilesResult represents results from reading multiple files

func ReadMultipleFiles

func ReadMultipleFiles(opts ReadMultipleFilesOptions) (*ReadMultipleFilesResult, error)

ReadMultipleFiles reads multiple files concurrently

type SafeEditOptions

type SafeEditOptions struct {
	Path        string
	OldString   string
	NewString   string
	Backup      bool
	DryRun      bool
	AllowedDirs []string
}

SafeEditOptions contains input parameters for SafeEdit

type SearchCodeOptions

type SearchCodeOptions struct {
	Path            string
	Pattern         string
	CaseInsensitive bool
	Regex           bool
	ContextLines    int
	FileTypes       []string
	MaxResults      int
	ShowHidden      bool
	AllowedDirs     []string
}

SearchCodeOptions contains input parameters for SearchCode

type SearchCodeResult

type SearchCodeResult struct {
	Pattern      string      `json:"pattern"`
	Path         string      `json:"path"`
	Matches      []CodeMatch `json:"matches"`
	TotalFiles   int         `json:"total_files"`
	TotalMatches int         `json:"total_matches"`
}

SearchCodeResult represents the result of a code search

func SearchCode

func SearchCode(opts SearchCodeOptions) (*SearchCodeResult, error)

SearchCode searches for patterns in file contents

type SearchFilesOptions

type SearchFilesOptions struct {
	Path        string
	Pattern     string
	Recursive   bool
	ShowHidden  bool
	MaxResults  int
	AllowedDirs []string
}

SearchFilesOptions contains input parameters for SearchFiles

type SearchFilesResult

type SearchFilesResult struct {
	Pattern string             `json:"pattern"`
	Path    string             `json:"path"`
	Matches []FileSearchResult `json:"matches"`
	Total   int                `json:"total"`
}

SearchFilesResult represents the result of a file search

func SearchFiles

func SearchFiles(opts SearchFilesOptions) (*SearchFilesResult, error)

SearchFiles searches for files by name pattern

type SearchReplaceOptions

type SearchReplaceOptions struct {
	Path        string
	Pattern     string
	Replacement string
	Regex       bool
	DryRun      bool
	FileTypes   []string
	AllowedDirs []string
}

SearchReplaceOptions contains input parameters for SearchAndReplace

type SearchReplaceResult

type SearchReplaceResult struct {
	Path          string       `json:"path"`
	FilesModified int          `json:"files_modified"`
	TotalChanges  int          `json:"total_changes"`
	Results       []EditResult `json:"results"`
}

SearchReplaceResult represents results from search and replace

func SearchAndReplace

func SearchAndReplace(opts SearchReplaceOptions) (*SearchReplaceResult, error)

SearchAndReplace performs search and replace across files

type SizeExceededError added in v1.3.0

type SizeExceededError struct {
	Message           string `json:"message"`
	Path              string `json:"path"`
	Size              int64  `json:"size"`                // Raw file size in bytes
	EstimatedJSONSize int64  `json:"estimated_json_size"` // Estimated size after JSON encoding
	MaxSize           int64  `json:"max_size"`            // Maximum allowed JSON size
}

SizeExceededError represents an error when estimated JSON output size exceeds the limit

func (*SizeExceededError) Error added in v1.3.0

func (e *SizeExceededError) Error() string

func (*SizeExceededError) ToJSON added in v1.3.0

func (e *SizeExceededError) ToJSON() string

ToJSON returns the error as a JSON object with error: true

type SyncDirectoriesOptions

type SyncDirectoriesOptions struct {
	Source      string
	Destination string
	AllowedDirs []string
}

SyncDirectoriesOptions contains input parameters for SyncDirectories

type SyncResult

type SyncResult struct {
	Source      string `json:"source"`
	Destination string `json:"destination"`
	FilesCopied int    `json:"files_copied"`
	DirsCreated int    `json:"dirs_created"`
	Success     bool   `json:"success"`
}

SyncResult represents sync result

func SyncDirectories

func SyncDirectories(opts SyncDirectoriesOptions) (*SyncResult, error)

SyncDirectories synchronizes two directories

type TotalSizeExceededError added in v1.3.0

type TotalSizeExceededError struct {
	Message           string          `json:"message"`
	TotalSize         int64           `json:"total_size"`          // Raw total size in bytes
	EstimatedJSONSize int64           `json:"estimated_json_size"` // Estimated size after JSON encoding
	MaxTotalSize      int64           `json:"max_total_size"`      // Maximum allowed JSON size
	Files             []FileSizeEntry `json:"files"`
}

TotalSizeExceededError represents an error when combined estimated JSON size exceeds the limit

func (*TotalSizeExceededError) Error added in v1.3.0

func (e *TotalSizeExceededError) Error() string

func (*TotalSizeExceededError) ToJSON added in v1.3.0

func (e *TotalSizeExceededError) ToJSON() string

ToJSON returns the error as a JSON object with error: true

type TreeNode

type TreeNode struct {
	Name     string      `json:"name"`
	Path     string      `json:"path"`
	IsDir    bool        `json:"is_dir"`
	Size     int64       `json:"size,omitempty"`
	Children []*TreeNode `json:"children,omitempty"`
}

TreeNode represents a node in the directory tree

type WriteFileOptions

type WriteFileOptions struct {
	Path        string
	Content     string
	CreateDirs  bool
	Append      bool
	AllowedDirs []string
}

WriteFileOptions contains input parameters for WriteFile

type WriteFileResult

type WriteFileResult struct {
	Path    string `json:"path"`
	Size    int64  `json:"size"`
	Created bool   `json:"created"`
	Backup  string `json:"backup,omitempty"`
	Message string `json:"message"`
}

WriteFileResult represents the result of a write operation

func LargeWriteFile

func LargeWriteFile(opts LargeWriteFileOptions) (*WriteFileResult, error)

LargeWriteFile writes large files with backup and verification

func WriteFile

func WriteFile(opts WriteFileOptions) (*WriteFileResult, error)

WriteFile writes content to a file

Jump to

Keyboard shortcuts

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