workspace

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package workspace provides opt-in, bounded text-file operations in a caller-selected directory. It is not an operating-system sandbox.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPattern        = errors.New("workspace: invalid or excessive glob pattern")
	ErrDiscoveryLimit = errors.New("workspace: result limit must be between 1 and 200, or zero for default")
	ErrQuery          = errors.New("workspace: invalid or excessive search query")
)
View Source
var (
	ErrPath       = errors.New("workspace: invalid or excluded relative path")
	ErrReadOnly   = errors.New("workspace: writes are not enabled")
	ErrNotRegular = errors.New("workspace: expected a regular file or directory")
	ErrTooLarge   = errors.New("workspace: file exceeds configured byte limit")
	ErrText       = errors.New("workspace: expected UTF-8 text without NUL bytes")
	ErrRevision   = errors.New("workspace: invalid or stale content revision; read the file again")
	ErrExists     = errors.New("workspace: target already exists")
	ErrMissing    = errors.New("workspace: file or parent directory not found")
	ErrIO         = errors.New("workspace: filesystem operation failed")
	ErrClosed     = errors.New("workspace: handle is closed")
	ErrMatch      = errors.New("workspace: edit requires a unique exact match with correct indentation")
	ErrLineEnding = errors.New("workspace: edit would change the existing line-ending convention")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Writable     bool
	MaxFileBytes int
}

Config grants read access to one existing directory. Writes require opt-in. MaxFileBytes defaults to 48 KiB and may not exceed 1 MiB.

type DiscoveryStats

type DiscoveryStats struct {
	EntriesRead       int    `json:"entries_read"`
	FilesExamined     int    `json:"files_examined"`
	ReadBudgetBytes   int    `json:"read_budget_bytes"`
	SkippedExcluded   int    `json:"skipped_excluded"`
	SkippedSpecial    int    `json:"skipped_special"`
	SkippedUnreadable int    `json:"skipped_unreadable"`
	SkippedOversized  int    `json:"skipped_oversized"`
	SkippedNonText    int    `json:"skipped_non_text"`
	Truncated         bool   `json:"truncated"`
	StopReason        string `json:"stop_reason,omitempty"`
}

DiscoveryStats describes coverage, not a claim of a complete project index. EntriesRead includes excluded entries and at most one budget lookahead.

type Entry

type Entry struct {
	Path  string `json:"path"`
	Kind  string `json:"kind"`
	Bytes int64  `json:"bytes,omitempty"`
}

type ListOptions

type ListOptions struct {
	Path      string `json:"path,omitempty"`
	Glob      string `json:"glob,omitempty"`
	Recursive bool   `json:"recursive,omitempty"`
	Limit     int    `json:"limit,omitempty"`
}

ListOptions selects a directory and an optional slash-separated glob relative to that directory. Empty Path means the workspace root.

type ListResult

type ListResult struct {
	Entries []Entry        `json:"entries"`
	Stats   DiscoveryStats `json:"stats"`
}

type Mutation

type Mutation struct {
	Path           string `json:"path"`
	Revision       string `json:"revision"`
	Bytes          int    `json:"bytes"`
	CleanupPending bool   `json:"cleanup_pending,omitempty"`
}

Mutation describes the committed filesystem effect. CleanupPending means publication succeeded but removal of a temporary entry failed.

type SearchMatch

type SearchMatch struct {
	Path             string `json:"path"`
	Line             int    `json:"line"`
	ByteColumn       int    `json:"byte_column"`
	Excerpt          string `json:"excerpt"`
	ExcerptTruncated bool   `json:"excerpt_truncated,omitempty"`
}

SearchMatch reports the first match on a line. ByteColumn is one-based, not a visual/rune column. Excerpt may be clipped around the match.

type SearchOptions

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

SearchOptions searches complete bounded UTF-8 files under Path. Glob is relative to Path; result paths are always workspace-relative.

type SearchResult

type SearchResult struct {
	Matches []SearchMatch  `json:"matches"`
	Stats   DiscoveryStats `json:"stats"`
}

type Snapshot

type Snapshot struct {
	Path     string `json:"path"`
	Content  string `json:"content"`
	Revision string `json:"revision"`
}

Snapshot is a complete bounded read. Revision identifies the raw UTF-8 bytes.

type Workspace

type Workspace struct {
	// contains filtered or unexported fields
}

Workspace owns a rooted handle and serializes cooperating operations on it. Use a dedicated trusted directory. External writers, hard links and mounts are not isolated by this API.

func Open

func Open(directory string, cfg Config) (*Workspace, error)

Open opens an existing caller-selected directory without creating it.

func (*Workspace) Close

func (w *Workspace) Close() error

Close releases the handle. It is safe to call more than once.

func (*Workspace) Create

func (w *Workspace) Create(ctx context.Context, name, content string) (Mutation, error)

Create publishes new content without overwriting any existing entry. Its parent directory must already exist.

func (*Workspace) Edit

func (w *Workspace) Edit(ctx context.Context, name, revision, oldText, newText string) (Mutation, error)

Edit replaces one exact occurrence, refusing ambiguous or mid-indentation anchors. It never performs automatic whitespace normalization.

func (*Workspace) List

func (w *Workspace) List(ctx context.Context, opts ListOptions) (ListResult, error)

List lists authorized regular files and directories, in sorted depth-first order for a stable tree. It does not follow observed symbolic links.

func (*Workspace) Read

func (w *Workspace) Read(ctx context.Context, name string) (Snapshot, error)

Read returns the entire file or an error. It never issues a revision for partial, oversized, invalid UTF-8 or binary content.

func (*Workspace) Replace

func (w *Workspace) Replace(ctx context.Context, name, revision, content string) (Mutation, error)

Replace overwrites a complete file only if its current raw bytes match revision. This is not an atomic compare-and-swap against external writers.

func (*Workspace) Search

func (w *Workspace) Search(ctx context.Context, opts SearchOptions) (SearchResult, error)

Search recursively searches matching regular text files without launching a process. Skipped and truncated coverage is explicit in the result.

func (*Workspace) Tools

func (w *Workspace) Tools() ([]agent.Tool, error)

Tools returns read-only tools unless write access was explicitly granted when the workspace was opened. The caller still chooses which to register.

Directories

Path Synopsis
internal
pathpolicy
Package pathpolicy validates portable relative names and restricted glob syntax.
Package pathpolicy validates portable relative names and restricted glob syntax.
textedit
Package textedit implements the workspace's pure text and revision policy.
Package textedit implements the workspace's pure text and revision policy.

Jump to

Keyboard shortcuts

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