fileops

package
v1.10.6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFile

func CreateFile(root, path, content string) error

CreateFile creates a new file with the given content. Parent directories are created if they don't exist. Returns an error if the file already exists.

func FindFiles

func FindFiles(root, pattern string) ([]string, error)

FindFiles finds files matching a glob pattern relative to root. Supports standard glob patterns (* and ?). For ** patterns, it matches any number of path components. Returns paths relative to root.

func FuzzyEdit

func FuzzyEdit(root, path, search, replacement string, allowEllipsis bool) (*fuzzy.Result, error)

FuzzyEdit reads a file, runs fuzzy.Match against its content, and writes the result via atomic OverwriteFile. Returns the fuzzy.Result on success.

func OverwriteFile

func OverwriteFile(root, path, content string) error

OverwriteFile writes content to a file using atomic write (temp file + rename). Creates parent directories if needed.

func ReadFile

func ReadFile(root, path string) (string, error)

ReadFile reads the entire file at the given path and returns its content as a string. Returns an error if the file does not exist or exceeds 10 MB.

func ReadFileRange

func ReadFileRange(root, path string, startLine, endLine int) (string, error)

ReadFileRange reads lines from startLine to endLine (1-indexed, inclusive). If endLine is 0 or beyond EOF, reads to end of file. Returns lines with line numbers prefixed (e.g., " 1: content").

func RegisterTools

func RegisterTools(server *mcp.SerenaMCPServer, workspaceRoot func() string, tracer trace.Tracer)

RegisterTools registers all file operation tools with the MCP tool registry. The workspaceRoot function provides the active workspace root path. Each handler is wrapped with kernel.WrapToolSpan to produce kernel.tool.{name} sub-spans under the TelemetryMiddleware span (Phase 12, TRACE-03).

func ReplaceInFile

func ReplaceInFile(root, path, pattern, replacement string, isRegex bool) (int, error)

ReplaceInFile replaces all occurrences of a pattern in a file. If isRegex is true, pattern is compiled as a regex; otherwise it's a literal string match. Uses atomic write to prevent partial writes on crash. Returns the number of replacements made.

func ValidatePath

func ValidatePath(root, path string) (string, error)

ValidatePath resolves symlinks and ensures the path is within the workspace root. Returns the cleaned absolute path or an error if the path escapes the root.

Types

type CreateFileArgs

type CreateFileArgs struct {
	Path    string `json:"path" jsonschema:"File path to create (relative to workspace root)"`
	Content string `json:"content" jsonschema:"File content to write"`
}

CreateFileArgs is the input schema for the create_file tool.

type DirEntry

type DirEntry struct {
	Name    string
	IsDir   bool
	Size    int64
	ModTime time.Time
}

DirEntry represents a single directory entry.

func ListDirectory

func ListDirectory(root, path string) ([]DirEntry, error)

ListDirectory returns directory entries sorted alphabetically with directories first.

type FileOpsSkill

type FileOpsSkill struct{}

FileOpsSkill is a ToolProvider adapter that exposes the 7 file operation tools through the skill interface for daemon discovery.

func (*FileOpsSkill) Description

func (s *FileOpsSkill) Description() string

Description returns a human-readable description of this skill.

func (*FileOpsSkill) Init

func (s *FileOpsSkill) Init(deps skill.SkillDeps) error

Init is a no-op; kernel tools get their dependencies from the daemon, not SkillDeps.

func (*FileOpsSkill) Name

func (s *FileOpsSkill) Name() string

Name returns the unique skill identifier.

func (*FileOpsSkill) Tools

func (s *FileOpsSkill) Tools() []*mcp.ToolDef

Tools returns the 7 ToolDefs for file operations. RegisterFn is nil because the daemon owns MCP registration (D-01).

type FindFilesArgs

type FindFilesArgs struct {
	Pattern string `json:"pattern" jsonschema:"Glob pattern to match files (supports ** for recursive)"`
}

FindFilesArgs is the input schema for the find_files tool.

type FuzzyEditArgs

type FuzzyEditArgs struct {
	Path            string `json:"path" jsonschema:"File path (relative to workspace root)"`
	Search          string `` /* 137-byte string literal not displayed */
	Replacement     string `json:"replacement" jsonschema:"Replacement text"`
	DisableEllipsis bool   `json:"disable_ellipsis,omitempty" jsonschema:"Disable ... ellipsis segmentation (default false, meaning ellipsis is enabled)"`
}

FuzzyEditArgs is the input schema for the fuzzy_edit tool.

type ListDirectoryArgs

type ListDirectoryArgs struct {
	Path string `json:"path" jsonschema:"Directory path (relative to workspace root)"`
}

ListDirectoryArgs is the input schema for the list_directory tool.

type ReadFileArgs

type ReadFileArgs struct {
	Path      string `json:"path" jsonschema:"File path to read (relative to workspace root)"`
	StartLine int    `json:"start_line,omitempty" jsonschema:"Start line (1-indexed, optional)"`
	EndLine   int    `json:"end_line,omitempty" jsonschema:"End line (1-indexed, inclusive, optional)"`
}

ReadFileArgs is the input schema for the read_file tool.

type ReplaceInFileArgs

type ReplaceInFileArgs struct {
	Path        string `json:"path" jsonschema:"File path (relative to workspace root)"`
	Pattern     string `json:"pattern" jsonschema:"Pattern to search for (literal or regex)"`
	Replacement string `json:"replacement" jsonschema:"Replacement string"`
	IsRegex     bool   `json:"is_regex,omitempty" jsonschema:"Treat pattern as regex (default false)"`
}

ReplaceInFileArgs is the input schema for the replace_in_file tool.

type SearchInFilesArgs

type SearchInFilesArgs struct {
	Pattern      string `json:"pattern" jsonschema:"Regex pattern to search for"`
	IncludeGlob  string `json:"include_glob,omitempty" jsonschema:"Only search files matching this glob (optional)"`
	ExcludeGlob  string `json:"exclude_glob,omitempty" jsonschema:"Skip files matching this glob (optional)"`
	ContextLines int    `json:"context_lines,omitempty" jsonschema:"Number of context lines before/after match (optional)"`
	MaxResults   int    `json:"max_results,omitempty" jsonschema:"Maximum number of results (default 100, optional)"`
}

SearchInFilesArgs is the input schema for the search_in_files tool.

type SearchMatch

type SearchMatch struct {
	Path          string
	Line          int
	Text          string
	ContextBefore []string
	ContextAfter  []string
}

SearchMatch represents a single search match.

func SearchPattern

func SearchPattern(root, pattern string, opts SearchOpts) ([]SearchMatch, error)

SearchPattern searches files under root for a regex pattern. Skips binary files and excluded directories.

type SearchOpts

type SearchOpts struct {
	MaxResults   int
	ContextLines int
	IncludeGlob  string
	ExcludeGlob  string
}

SearchOpts configures search behavior.

Jump to

Keyboard shortcuts

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