workspaceops

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package workspaceops provides bounded filesystem operations for a workspace.

Package workspaceops provides bounded workspace file, search, and edit operations used by CLI and protocol surfaces.

Index

Constants

View Source
const MaxFileBytes int64 = 2_000_000

MaxFileBytes is the maximum byte size accepted for whole-file edits and diffs.

Variables

This section is empty.

Functions

func BoundedLimit

func BoundedLimit(value, defaultValue, maxValue int) int

BoundedLimit applies a default and maximum to a caller-provided limit.

func PatternMatch

func PatternMatch(pattern string, rel string, base string) (bool, error)

PatternMatch matches either a base name or slash-separated relative path.

func UnifiedDiff

func UnifiedDiff(path string, original string, updated string) string

UnifiedDiff returns a simple unified diff for a single workspace path.

Types

type DiffOptions

type DiffOptions struct {
	Path      string `json:"path"`
	Original  string `json:"original"`
	Updated   string `json:"updated"`
	OldString string `json:"old_string"`
	NewString string `json:"new_string"`
}

DiffOptions describes either a complete content diff or a string-replacement diff.

type DiffResult

type DiffResult struct {
	Path string `json:"path"`
	Diff string `json:"diff"`
}

DiffResult contains a unified diff for a workspace path.

type EditOptions

type EditOptions struct {
	Path       string `json:"path"`
	OldString  string `json:"old_string"`
	NewString  string `json:"new_string"`
	ReplaceAll bool   `json:"replace_all"`
}

EditOptions describes a string replacement edit.

type EditResult

type EditResult struct {
	Path         string `json:"path"`
	Replacements int    `json:"replacements"`
}

EditResult reports how many replacements were written.

type FileEntry

type FileEntry struct {
	Path    string    `json:"path"`
	IsDir   bool      `json:"is_dir"`
	Size    int64     `json:"size,omitempty"`
	ModTime time.Time `json:"mod_time,omitempty"`
}

FileEntry describes one file or directory returned by Files.

type FilesOptions

type FilesOptions struct {
	Path          string `json:"path"`
	Pattern       string `json:"pattern"`
	Limit         int    `json:"limit"`
	IncludeHidden bool   `json:"include_hidden"`
}

FilesOptions controls a workspace file listing.

type FilesResult

type FilesResult struct {
	Root      string      `json:"root"`
	Files     []FileEntry `json:"files"`
	Truncated bool        `json:"truncated"`
}

FilesResult contains files matched under a workspace root.

type InfoResult

type InfoResult struct {
	Path string `json:"path"`
	Name string `json:"name"`
}

InfoResult describes the workspace root.

type ReadOptions

type ReadOptions struct {
	Path   string `json:"path"`
	Offset int    `json:"offset"`
	Limit  int    `json:"limit"`
}

ReadOptions controls a bounded file read.

type ReadResult

type ReadResult struct {
	Path      string `json:"path"`
	Content   string `json:"content"`
	Bytes     int    `json:"bytes"`
	Truncated bool   `json:"truncated"`
}

ReadResult contains the content window read from a workspace file.

type SearchMatch

type SearchMatch struct {
	Path   string `json:"path"`
	Line   int    `json:"line"`
	Text   string `json:"text"`
	Column int    `json:"column,omitempty"`
}

SearchMatch identifies one matching line in a workspace file.

type SearchOptions

type SearchOptions struct {
	Query         string `json:"query"`
	Path          string `json:"path"`
	Glob          string `json:"glob"`
	Regex         bool   `json:"regex"`
	Limit         int    `json:"limit"`
	IncludeHidden bool   `json:"include_hidden"`
}

SearchOptions controls a literal or regular-expression workspace search.

type SearchResult

type SearchResult struct {
	Matches   []SearchMatch `json:"matches"`
	Truncated bool          `json:"truncated"`
}

SearchResult contains workspace search matches.

type Service

type Service struct {
	Workspace string
}

Service resolves and operates on paths relative to a workspace root.

func (Service) Diff

func (s Service) Diff(options DiffOptions) (DiffResult, error)

Diff builds a unified diff for a workspace file without writing changes.

func (Service) Edit

func (s Service) Edit(options EditOptions) (EditResult, error)

Edit applies a string replacement to a workspace file.

func (Service) Files

func (s Service) Files(options FilesOptions) (FilesResult, error)

Files lists files under the workspace using a bounded glob filter.

func (Service) Info

func (s Service) Info() (InfoResult, error)

Info returns the absolute workspace path and its base name.

func (Service) Read

func (s Service) Read(options ReadOptions) (ReadResult, error)

Read returns a bounded byte window from a workspace file.

func (Service) Rel

func (s Service) Rel(path string) (string, error)

Rel returns a slash-separated path relative to the workspace root.

func (Service) Resolve

func (s Service) Resolve(requested string, allowMissing bool) (string, string, error)

Resolve returns an absolute path and slash-separated relative path inside the workspace.

func (Service) ResolveWorkspacePath

func (s Service) ResolveWorkspacePath(requested string) (string, string, error)

ResolveWorkspacePath resolves a directory-like workspace path, defaulting to the root.

func (Service) Search

func (s Service) Search(options SearchOptions) (SearchResult, error)

Search scans text files under the workspace for literal or regex matches.

func (Service) WorkspacePath

func (s Service) WorkspacePath() (string, error)

WorkspacePath returns the absolute workspace root or the current directory.

func (Service) Write

func (s Service) Write(options WriteOptions) (WriteResult, error)

Write writes complete file content under the workspace.

type WriteOptions

type WriteOptions struct {
	Path    string `json:"path"`
	Content string `json:"content"`
}

WriteOptions describes a complete file write.

type WriteResult

type WriteResult struct {
	Path  string `json:"path"`
	Bytes int    `json:"bytes"`
}

WriteResult reports the file written by Write.

Jump to

Keyboard shortcuts

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