Documentation
¶
Overview ¶
Package workspace provides opt-in, bounded text-file operations in a caller-selected directory. It is not an operating-system sandbox.
Index ¶
- Variables
- type Config
- type DiscoveryStats
- type Entry
- type ListOptions
- type ListResult
- type Mutation
- type SearchMatch
- type SearchOptions
- type SearchResult
- type Snapshot
- type Workspace
- func (w *Workspace) Close() error
- func (w *Workspace) Create(ctx context.Context, name, content string) (Mutation, error)
- func (w *Workspace) Edit(ctx context.Context, name, revision, oldText, newText string) (Mutation, error)
- func (w *Workspace) List(ctx context.Context, opts ListOptions) (ListResult, error)
- func (w *Workspace) Read(ctx context.Context, name string) (Snapshot, error)
- func (w *Workspace) Replace(ctx context.Context, name, revision, content string) (Mutation, error)
- func (w *Workspace) Search(ctx context.Context, opts SearchOptions) (SearchResult, error)
- func (w *Workspace) Tools() ([]agent.Tool, error)
Constants ¶
This section is empty.
Variables ¶
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") )
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 ¶
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 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 (*Workspace) Create ¶
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 ¶
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 ¶
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.
Source Files
¶
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. |