Documentation
¶
Overview ¶
Package filesystem provides file system operations.
Index ¶
- type Backend
- type EditRequest
- type ExecuteRequest
- type ExecuteResponse
- type FileContent
- type FileInfo
- type GlobInfoRequest
- type GrepMatch
- type GrepRequest
- type InMemoryBackend
- func (b *InMemoryBackend) Edit(ctx context.Context, req *EditRequest) error
- func (b *InMemoryBackend) GlobInfo(ctx context.Context, req *GlobInfoRequest) ([]FileInfo, error)
- func (b *InMemoryBackend) GrepRaw(ctx context.Context, req *GrepRequest) ([]GrepMatch, error)
- func (b *InMemoryBackend) LsInfo(ctx context.Context, req *LsInfoRequest) ([]FileInfo, error)
- func (b *InMemoryBackend) Read(ctx context.Context, req *ReadRequest) (*FileContent, error)
- func (b *InMemoryBackend) Write(ctx context.Context, req *WriteRequest) error
- type LsInfoRequest
- type ReadRequest
- type Shell
- type StreamingShell
- type WriteRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// LsInfo lists file information under the given path.
//
// Returns:
// - []FileInfo: List of matching file information
// - error: Error if the operation fails
LsInfo(ctx context.Context, req *LsInfoRequest) ([]FileInfo, error)
// Read reads file content with support for line-based offset and limit.
//
// Returns:
// - string: The file content read
// - error: Error if file does not exist or read fails
Read(ctx context.Context, req *ReadRequest) (*FileContent, error)
// GrepRaw searches for content matching the specified pattern in files.
//
// Returns:
// - []GrepMatch: List of all matching results
// - error: Error if the search fails
GrepRaw(ctx context.Context, req *GrepRequest) ([]GrepMatch, error)
// GlobInfo returns file information matching the glob pattern.
//
// Returns:
// - []FileInfo: List of matching file information
// - error: Error if the pattern is invalid or operation fails
GlobInfo(ctx context.Context, req *GlobInfoRequest) ([]FileInfo, error)
// Write creates or updates file content.
//
// Returns:
// - error: Error if the write operation fails
Write(ctx context.Context, req *WriteRequest) error
// Edit replaces string occurrences in a file.
//
// Returns:
// - error: Error if file does not exist, OldString is empty, or OldString is not found
Edit(ctx context.Context, req *EditRequest) error
}
Backend is a pluggable, unified file backend protocol interface.
All methods use struct-based parameters to allow future extensibility without breaking backward compatibility.
type EditRequest ¶
type EditRequest struct {
// FilePath is the path of the file to edit.
FilePath string
// OldString is the exact string to be replaced. It must be non-empty and will be matched literally, including whitespace.
OldString string
// NewString is the string that will replace OldString.
// It must be different from OldString.
// An empty string can be used to effectively delete OldString.
NewString string
// ReplaceAll controls the replacement behavior.
// If true, all occurrences of OldString are replaced.
// If false, the operation fails unless OldString appears exactly once in the file.
ReplaceAll bool
}
EditRequest contains parameters for editing file content.
type ExecuteRequest ¶
ExecuteRequest contains parameters for executing a command.
type ExecuteResponse ¶
type ExecuteResponse struct {
Output string // Command output content
ExitCode *int // Command exit code
Truncated bool // Whether the output was truncated
}
ExecuteResponse contains the response result of command execution.
type FileContent ¶ added in v0.8.0
type FileContent struct {
Content string
}
type FileInfo ¶
type FileInfo struct {
// Path is the path of the file or directory, which can be a filename, relative path, or absolute path.
Path string
// IsDir indicates whether the entry is a directory.
// true for directories, false for regular files.
IsDir bool
// Size is the file size in bytes.
// For directories, this value may be 0 or platform-dependent.
Size int64
// ModifiedAt is the last modification time in ISO 8601 format.
// Example: "2025-01-15T10:30:00Z"
ModifiedAt string
}
FileInfo represents basic file metadata information.
type GlobInfoRequest ¶
type GlobInfoRequest struct {
// Pattern is the glob expression used to match file paths.
// It supports standard glob syntax:
// - `*` matches any characters except path separators.
// - `**` matches any directories recursively.
// - `?` matches a single character.
// - `[abc]` matches one character from the set.
Pattern string
// Path is the base directory from which to start the search.
Path string
}
GlobInfoRequest contains parameters for glob pattern matching.
type GrepMatch ¶
type GrepMatch struct {
Content string
// Path is the file path where the match was found.
Path string
// Line is the 1-based line number of the match.
Line int
}
GrepMatch represents a single pattern match result.
type GrepRequest ¶
type GrepRequest struct {
// Pattern is the search pattern, supports full regular expression syntax.
// Uses ripgrep syntax (not grep). Examples:
// - "log.*Error" matches lines with "log" followed by "Error"
// - "function\\s+\\w+" matches "function" followed by whitespace and word characters
// - Literal braces need escaping: "interface\\{\\}" matches "interface{}"
Pattern string
// Path is an optional directory path to limit the search scope.
Path string
// Glob is an optional pattern to filter the files to be searched.
// It filters by file path, not content. If empty, no files are filtered.
// Supports standard glob wildcards:
// - `*` matches any characters except path separators.
// - `**` matches any directories recursively.
// - `?` matches a single character.
// - `[abc]` matches one character from the set.
Glob string
// FileType is the file type filter, e.g., "js", "py", "rust".
// More efficient than Glob for standard file types.
FileType string
// CaseInsensitive enables case insensitive search.
CaseInsensitive bool
// EnableMultiline enables multiline mode where patterns can span lines.
// Default: false (patterns match within single lines only).
EnableMultiline bool
// AfterLines shows N lines after each match.
// Only applicable when OutputMode is "content".
// Values <= 0 are treated as unset.
AfterLines int
// BeforeLines shows N lines before each match.
// Only applicable when OutputMode is "content".
// Values <= 0 are treated as unset.
BeforeLines int
}
GrepRequest contains parameters for searching file content.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend is an in-memory implementation of the Backend interface. It stores files in a map and is safe for concurrent use.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates a new in-memory backend.
func (*InMemoryBackend) Edit ¶
func (b *InMemoryBackend) Edit(ctx context.Context, req *EditRequest) error
Edit replaces string occurrences in a file.
func (*InMemoryBackend) GlobInfo ¶
func (b *InMemoryBackend) GlobInfo(ctx context.Context, req *GlobInfoRequest) ([]FileInfo, error)
GlobInfo returns file info entries matching the glob pattern.
func (*InMemoryBackend) GrepRaw ¶
func (b *InMemoryBackend) GrepRaw(ctx context.Context, req *GrepRequest) ([]GrepMatch, error)
GrepRaw returns matches for the given pattern.
func (*InMemoryBackend) LsInfo ¶
func (b *InMemoryBackend) LsInfo(ctx context.Context, req *LsInfoRequest) ([]FileInfo, error)
LsInfo lists file information under the given path.
func (*InMemoryBackend) Read ¶
func (b *InMemoryBackend) Read(ctx context.Context, req *ReadRequest) (*FileContent, error)
Read reads file content with offset and limit.
func (*InMemoryBackend) Write ¶
func (b *InMemoryBackend) Write(ctx context.Context, req *WriteRequest) error
Write creates or overwrites file content.
type LsInfoRequest ¶
type LsInfoRequest struct {
// Path specifies the directory path to list.
Path string
}
LsInfoRequest contains parameters for listing file information.
type ReadRequest ¶
type ReadRequest struct {
// FilePath is the path to the file to be read.
FilePath string
// Offset specifies the starting line number (1-based) for reading.
// Line 1 is the first line of the file.
// Use this when the file is too large to read at once.
// Defaults to 1 (start from the first line).
// Values < 1 will be treated as 1.
Offset int
// Limit specifies the maximum number of lines to read.
// Use this when the file is too large to read at once.
// Defaults to 2000 if not provided or non-positive (<= 0).
Limit int
}
ReadRequest contains parameters for reading file content.
type Shell ¶ added in v0.8.0
type Shell interface {
Execute(ctx context.Context, input *ExecuteRequest) (result *ExecuteResponse, err error)
}
type StreamingShell ¶ added in v0.8.0
type StreamingShell interface {
ExecuteStreaming(ctx context.Context, input *ExecuteRequest) (result *schema.StreamReader[*ExecuteResponse], err error)
}
type WriteRequest ¶
type WriteRequest struct {
// FilePath is the path of the file to write.
FilePath string
// Content is the data to be written to the file.
Content string
}
WriteRequest contains parameters for writing file content.