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
- func BoundedLimit(value, defaultValue, maxValue int) int
- func PatternMatch(pattern string, rel string, base string) (bool, error)
- func UnifiedDiff(path string, original string, updated string) string
- type DiffOptions
- type DiffResult
- type EditOptions
- type EditResult
- type FileEntry
- type FilesOptions
- type FilesResult
- type InfoResult
- type ReadOptions
- type ReadResult
- type SearchMatch
- type SearchOptions
- type SearchResult
- type Service
- func (s Service) Diff(options DiffOptions) (DiffResult, error)
- func (s Service) Edit(options EditOptions) (EditResult, error)
- func (s Service) Files(options FilesOptions) (FilesResult, error)
- func (s Service) Info() (InfoResult, error)
- func (s Service) Read(options ReadOptions) (ReadResult, error)
- func (s Service) Rel(path string) (string, error)
- func (s Service) Resolve(requested string, allowMissing bool) (string, string, error)
- func (s Service) ResolveWorkspacePath(requested string) (string, string, error)
- func (s Service) Search(options SearchOptions) (SearchResult, error)
- func (s Service) WorkspacePath() (string, error)
- func (s Service) Write(options WriteOptions) (WriteResult, error)
- type WriteOptions
- type WriteResult
Constants ¶
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 ¶
BoundedLimit applies a default and maximum to a caller-provided limit.
func PatternMatch ¶
PatternMatch matches either a base name or slash-separated relative 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 ¶
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 ¶
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 ¶
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) Resolve ¶
Resolve returns an absolute path and slash-separated relative path inside the workspace.
func (Service) ResolveWorkspacePath ¶
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 ¶
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 ¶
WriteOptions describes a complete file write.
type WriteResult ¶
WriteResult reports the file written by Write.