Documentation
¶
Overview ¶
Package std provides TaskSmith's Standard Operations Library for executing filesystem, process, and network operations strictly within an isolated sandbox.Sandbox.
Architecture ¶
Every operation exposed by Std delegates underlying system access to the injected sandbox capabilities:
- Filesystem operations (Std.View, Std.List, Std.Glob, Std.Grep, Std.Write, Std.Edit, Std.Remove, Std.SyncExternalChanges) execute exclusively through sandbox.Sandbox.FS.
- Process execution (Std.Bash and Std.Exec) runs exclusively through sandbox.Sandbox.Proc and automatically synchronizes any external file mutations made by the command upon completion.
- Network operations (Std.Fetch, Std.Download) execute exclusively through the policy-enforced HTTP client from sandbox.Sandbox.Net.
Read-Before-Overwrite & Compare-And-Swap (CAS) ¶
Mutating operations on existing files (Std.Write, Std.Edit, Std.Remove, and Std.Download when overwriting) enforce two safety invariants through the injected FileTracker unless explicitly bypassed via Force:
- Read-Before-Overwrite (ErrFileNotRead): An existing file must have a tracked content hash in the FileTracker before it can be modified or removed.
- Compare-And-Swap (ErrFileModified): The file's current on-disk SHA-256 digest must match the last tracked hash in the FileTracker. If the file was altered outside the agent's last known state, the mutation is aborted.
Provenance Tracking (Agent vs. External) ¶
All file mutations are attributed with a github.com/masterkeysrd/tasksmith/api.ChangeSource:
- github.com/masterkeysrd/tasksmith/api.SourceAgent: Mutations performed directly via Std.Write, Std.Edit, Std.Remove, or Std.Download.
- github.com/masterkeysrd/tasksmith/api.SourceExternal: Mutations detected on disk when re-reading a tracked file in Std.View or scanning tracked paths in Std.SyncExternalChanges (including after Std.Bash or Std.Exec command execution).
Index ¶
- Constants
- Variables
- type BashRequest
- type BashResult
- type Config
- type DownloadRequest
- type DownloadResult
- type EditRequest
- type EditResult
- type ExecRequest
- type ExecResult
- type FetchRequest
- type FetchResult
- type FileChange
- type FileIndex
- type FileIndexOptions
- type FileTracker
- type GlobRequest
- type GlobResult
- type GrepMatch
- type GrepRequest
- type GrepResult
- type ListEntry
- type ListRequest
- type ListResult
- type MemoryTracker
- func (t *MemoryTracker) Changes() []FileChange
- func (t *MemoryTracker) ChangesForPath(path string) []FileChange
- func (t *MemoryTracker) LastContent(path string) ([]byte, bool)
- func (t *MemoryTracker) LastHash(path string) (string, bool)
- func (t *MemoryTracker) RecentPaths() []string
- func (t *MemoryTracker) RecordChange(ctx context.Context, change *FileChange) error
- func (t *MemoryTracker) RecordRead(ctx context.Context, path, hash string) error
- func (t *MemoryTracker) TrackedPaths() []string
- type RemoveRequest
- type RemoveResult
- type SearchHit
- type SearchOptions
- type SearchRequest
- type SearchResult
- type Std
- func (s *Std) Bash(ctx context.Context, req BashRequest) (*BashResult, error)
- func (s *Std) Download(ctx context.Context, req DownloadRequest) (*DownloadResult, error)
- func (s *Std) Edit(ctx context.Context, req EditRequest) (*EditResult, error)
- func (s *Std) Exec(ctx context.Context, req ExecRequest) (*ExecResult, error)
- func (s *Std) Fetch(ctx context.Context, req FetchRequest) (*FetchResult, error)
- func (s *Std) Glob(ctx context.Context, req GlobRequest) (*GlobResult, error)
- func (s *Std) Grep(ctx context.Context, req GrepRequest) (*GrepResult, error)
- func (s *Std) List(ctx context.Context, req ListRequest) (*ListResult, error)
- func (s *Std) Remove(ctx context.Context, req RemoveRequest) (*RemoveResult, error)
- func (s *Std) Sandbox() sandbox.Sandbox
- func (s *Std) Search(ctx context.Context, req SearchRequest) (*SearchResult, error)
- func (s *Std) SyncExternalChanges(ctx context.Context) ([]FileChange, error)
- func (s *Std) Tracker() FileTracker
- func (s *Std) View(ctx context.Context, req ViewRequest) (*ViewResult, error)
- func (s *Std) Watch(ctx context.Context, req WatchRequest) (sandbox.Watcher, error)
- func (s *Std) Write(ctx context.Context, req WriteRequest) (*WriteResult, error)
- type ViewMedia
- type ViewRequest
- type ViewResult
- type WatchRequest
- type WriteRequest
- type WriteResult
Constants ¶
const ( // DefaultSearchLimit is the default number of results returned by Search. DefaultSearchLimit = 10 // MaxSearchLimit is the maximum number of results Search can return. MaxSearchLimit = 20 // MaxSearchResponseBytes caps a search results page body (1 MiB); HTML // result pages are small, so anything larger is not a results page. MaxSearchResponseBytes int64 = 1024 * 1024 // MaxSearchSnippetBytes is the maximum byte length of one result snippet. MaxSearchSnippetBytes = web.MaxSnippetBytes // DefaultSearchTimeout bounds one host-side web search request. DefaultSearchTimeout = 15 * time.Second )
const ( // DefaultViewLimit is the default maximum number of lines returned by View. DefaultViewLimit = 500 // MaxViewLimit is the maximum number of lines that View can return in a single call. MaxViewLimit = 2000 // MaxViewBytes is the maximum total byte size of content returned by View (32 KiB). MaxViewBytes = 32 * 1024 // MaxViewLineBytes is the maximum byte length of a single line in View before line truncation. MaxViewLineBytes = 2048 // DefaultListLimit is the default maximum number of entries returned by List. DefaultListLimit = 200 // MaxListLimit is the maximum number of entries that List can return in a single call. MaxListLimit = 500 // MaxListBytes is the maximum total byte budget for List entries (32 KiB). MaxListBytes = 32 * 1024 // DefaultGlobLimit is the default maximum number of matches returned by Glob. DefaultGlobLimit = 200 // MaxGlobLimit is the maximum number of matches that Glob can return in a single call. MaxGlobLimit = 500 // MaxGlobBytes is the maximum total byte budget for Glob match paths (32 KiB). MaxGlobBytes = 32 * 1024 // DefaultGrepLimit is the default maximum number of matches returned by Grep. DefaultGrepLimit = 100 // MaxGrepLimit is the maximum number of matches that Grep can return in a single call. MaxGrepLimit = 500 // MaxGrepLineBytes is the maximum byte length of a matched or context line in Grep. MaxGrepLineBytes = 500 // MaxGrepBytes is the maximum total byte budget for Grep matches (32 KiB). MaxGrepBytes = 32 * 1024 // DefaultMaxFetchBytes is the default response body cap for Fetch (10 MiB). DefaultMaxFetchBytes int64 = 10 * 1024 * 1024 // DefaultMaxDownloadBytes is the default response body cap for Download (100 MiB). DefaultMaxDownloadBytes int64 = 100 * 1024 * 1024 )
const DefaultSearchEndpoint = "https://html.duckduckgo.com/html/"
DefaultSearchEndpoint is the HTML search endpoint Std.Search queries when a request does not override it. DuckDuckGo's lightweight HTML surface needs no API key and returns parseable static markup.
Variables ¶
var ( ErrInvalidConfig = errors.New("std: invalid configuration") ErrFileNotRead = errors.New("std: file must be read before modification") ErrFileModified = errors.New("std: file was modified since last read") ErrTargetNotFound = errors.New("std: edit target not found in file") ErrAmbiguousEdit = errors.New("std: edit target matches multiple locations") ErrBinaryFile = errors.New("std: binary file not supported for text operation") ErrInvalidArgument = errors.New("std: invalid argument") )
Sentinel errors returned by the std package.
var DefaultWatchIgnoreDirs = []string{
".git", ".bare", "node_modules", "vendor", "dist", "target", ".venv", "__pycache__", ".next", ".cache",
}
DefaultWatchIgnoreDirs lists standard ignore directories for filesystem watching.
var ErrSearchResponseTooLarge = errors.New("std: search response exceeds size limit")
ErrSearchResponseTooLarge is returned when a search endpoint's body exceeds MaxSearchResponseBytes.
Functions ¶
This section is empty.
Types ¶
type BashRequest ¶
type BashRequest struct {
// Command is the shell command string passed to "sh -c".
Command string `json:"command"`
// Dir is the optional working directory relative to the sandbox root.
Dir string `json:"dir,omitempty"`
// Env specifies optional per-command environment variable overrides.
Env map[string]string `json:"env,omitempty"`
// Stdin provides optional standard input to the command.
Stdin string `json:"stdin,omitempty"`
// StdinReader provides optional streaming standard input to the command.
// When non-nil, StdinReader takes precedence over Stdin.
StdinReader io.Reader `json:"-"`
// Output optionally receives combined stdout and stderr from the command.
Output io.Writer `json:"-"`
// Timeout overrides the sandbox's default execution timeout.
Timeout time.Duration `json:"timeout,omitempty"`
// ReadOnly requests a read-only kernel profile for this command even when
// the sandbox itself is writable. It is enforced only by native OS
// sandboxes; local sandboxes ignore it.
ReadOnly bool `json:"read_only,omitempty"`
// Unsandboxed runs this command directly on the host without the kernel
// sandbox wrapper, for commands that genuinely need host credentials or
// sockets (GPG signing, SSH push, a Docker daemon socket). Process-group
// tracking, teardown, and environment scrubbing still apply. The sandbox
// rejects it while read-only, and it is only ever set after the
// permission engine approved an unsandboxed plan.
Unsandboxed bool `json:"unsandboxed,omitempty"`
}
BashRequest configures a shell command execution via Std.Bash.
type BashResult ¶
type BashResult struct {
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
ExitCode int `json:"exit_code"`
Duration time.Duration `json:"duration"`
ExternalChanges []FileChange `json:"external_changes,omitempty"`
}
BashResult contains the process output, exit status, and any external file changes detected after Std.Bash finishes.
type Config ¶
type Config struct {
Sandbox sandbox.Sandbox
Tracker FileTracker
Logger log.Interface
// SearchEndpoint optionally overrides the default web search endpoint from
// [DefaultSearchEndpoint], e.g. for a self-hosted search mirror. Empty uses
// the default.
SearchEndpoint string
}
Config holds the required dependencies for constructing a Std instance.
type DownloadRequest ¶
type DownloadRequest struct {
// URL is the source HTTP or HTTPS URL.
URL string `json:"url"`
// Path is the destination file path within the sandbox.
Path string `json:"path"`
// Headers contains optional HTTP request headers.
Headers map[string]string `json:"headers,omitempty"`
// Mode sets the destination file permission bits. Defaults to 0644.
Mode fs.FileMode `json:"mode,omitempty"`
// ExpectedHash optionally specifies the expected on-disk SHA-256 hex digest
// for Compare-And-Swap verification when overwriting an existing file.
ExpectedHash string `json:"expected_hash,omitempty"`
// Force bypasses Read-Before-Overwrite and Compare-And-Swap checks when the
// destination file already exists.
Force bool `json:"force,omitempty"`
// Timeout specifies an optional timeout for the download request.
Timeout time.Duration `json:"timeout,omitempty"`
// MaxBytes caps the maximum allowed download size in bytes.
// Defaults to DefaultMaxDownloadBytes (100 MiB).
MaxBytes int64 `json:"max_bytes,omitempty"`
// DryRun validates URL and destination path and enforces Read-Before-Overwrite
// and Compare-And-Swap checks without performing the network request or
// writing to disk.
DryRun bool `json:"dry_run,omitempty"`
}
DownloadRequest configures an HTTP file download into the sandbox via Std.Download.
type DownloadResult ¶
type DownloadResult struct {
URL string `json:"url"`
Path string `json:"path"`
StatusCode int `json:"status_code"`
ContentType string `json:"content_type,omitempty"`
BytesWritten int `json:"bytes_written"`
Created bool `json:"created"`
BeforeHash string `json:"before_hash,omitempty"`
AfterHash string `json:"after_hash"`
IsBinary bool `json:"is_binary,omitempty"`
Duration time.Duration `json:"duration"`
DryRun bool `json:"dry_run,omitempty"`
}
DownloadResult contains metadata for a completed Std.Download operation.
type EditRequest ¶
type EditRequest struct {
// Path is the target file path within the sandbox.
Path string `json:"path"`
// OldText is the exact literal substring to search for and replace.
OldText string `json:"old_text"`
// NewText is the replacement string.
NewText string `json:"new_text"`
// ReplaceAll replaces every occurrence of OldText when true. When false,
// Edit requires OldText to match exactly once.
ReplaceAll bool `json:"replace_all,omitempty"`
// ExpectedHash optionally specifies the expected on-disk SHA-256 hex digest
// for Compare-And-Swap verification. When empty, the FileTracker's last
// recorded hash is used.
ExpectedHash string `json:"expected_hash,omitempty"`
// Force bypasses Read-Before-Overwrite and Compare-And-Swap checks.
Force bool `json:"force,omitempty"`
// DryRun computes the unified diff and line statistics without writing to
// disk or updating the FileTracker.
DryRun bool `json:"dry_run,omitempty"`
}
EditRequest configures a targeted string replacement within a file via Std.Edit.
type EditResult ¶
type EditResult struct {
Path string `json:"path"`
Replacements int `json:"replacements"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Diff string `json:"diff,omitempty"`
BeforeHash string `json:"before_hash"`
AfterHash string `json:"after_hash"`
DryRun bool `json:"dry_run,omitempty"`
}
EditResult contains the diff, replacement count, and hashes produced by Std.Edit.
type ExecRequest ¶
type ExecRequest struct {
// Name is the executable to run, resolved through the sandbox PATH.
Name string `json:"name"`
// Args holds the program arguments, delivered without shell parsing.
Args []string `json:"args,omitempty"`
// Dir is the optional working directory relative to the sandbox root.
Dir string `json:"dir,omitempty"`
// Env specifies optional per-command environment variable overrides.
Env map[string]string `json:"env,omitempty"`
// Stdin provides optional standard input to the program.
Stdin io.Reader `json:"-"`
// Output optionally receives combined stdout and stderr from the program.
Output io.Writer `json:"-"`
// Timeout overrides the sandbox's default execution timeout.
Timeout time.Duration `json:"timeout,omitempty"`
// ReadOnly requests a read-only kernel profile for this program even when
// the sandbox itself is writable. It is enforced only by native OS
// sandboxes; local sandboxes ignore it.
ReadOnly bool `json:"read_only,omitempty"`
}
ExecRequest configures a direct program execution via Std.Exec. Unlike BashRequest, the program runs without shell interpretation, so argument values are delivered to the process verbatim.
type ExecResult ¶
type ExecResult struct {
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
ExitCode int `json:"exit_code"`
Duration time.Duration `json:"duration"`
ExternalChanges []FileChange `json:"external_changes,omitempty"`
}
ExecResult contains the program output, exit status, and any external file changes detected after Std.Exec finishes.
type FetchRequest ¶
type FetchRequest struct {
// URL is the target HTTP or HTTPS URL.
URL string `json:"url"`
// Method is the HTTP verb (defaults to "GET").
Method string `json:"method,omitempty"`
// Headers contains optional HTTP request headers.
Headers map[string]string `json:"headers,omitempty"`
// Body is the optional raw request payload.
Body []byte `json:"body,omitempty"`
// Format controls how fetched content is rendered in FetchResult.Text
// ("markdown" default, "text", or "html").
Format string `json:"format,omitempty"`
// Timeout specifies an optional per-request timeout.
Timeout time.Duration `json:"timeout,omitempty"`
// MaxBytes caps the maximum number of response body bytes read.
// Defaults to DefaultMaxFetchBytes (10 MiB).
MaxBytes int64 `json:"max_bytes,omitempty"`
// DryRun validates URL and network policy without executing the HTTP request.
DryRun bool `json:"dry_run,omitempty"`
}
FetchRequest configures an outbound HTTP request via Std.Fetch.
type FetchResult ¶
type FetchResult struct {
URL string `json:"url"`
StatusCode int `json:"status_code"`
Status string `json:"status"`
Headers map[string]string `json:"headers,omitempty"`
ContentType string `json:"content_type,omitempty"`
Body []byte `json:"body,omitempty"`
Text string `json:"text,omitempty"`
Truncated bool `json:"truncated,omitempty"`
Duration time.Duration `json:"duration"`
DryRun bool `json:"dry_run,omitempty"`
}
FetchResult contains the HTTP response status, headers, and body from Std.Fetch.
type FileChange ¶
type FileChange struct {
api.FileChange
BeforeContent []byte `json:"-"`
AfterContent []byte `json:"-"`
IsBinary bool `json:"is_binary,omitempty"`
}
FileChange captures metadata and content snapshots for a single file mutation.
type FileIndex ¶
type FileIndex struct {
// contains filtered or unexported fields
}
FileIndex maintains an in-memory, thread-safe, watcher-backed file and directory index for fuzzy '@' context mentions in the workspace.
func NewFileIndex ¶
func NewFileIndex(opts FileIndexOptions) (*FileIndex, error)
NewFileIndex constructs and initializes a new thread-safe FileIndex.
func (*FileIndex) Invalidate ¶
func (idx *FileIndex) Invalidate()
Invalidate triggers an asynchronous refresh of the in-memory index.
func (*FileIndex) Refresh ¶
Refresh re-scans the workspace filesystem and updates in-memory entries.
func (*FileIndex) Search ¶
func (idx *FileIndex) Search(ctx context.Context, opts SearchOptions) ([]api.WorkspaceFile, error)
Search queries the file index using fuzzy matching and MRU ranking.
func (*FileIndex) SetAllowExec ¶
SetAllowExec updates whether external discovery binaries (git, rg) may be spawned.
type FileIndexOptions ¶
FileIndexOptions configures a workspace FileIndex.
type FileTracker ¶
type FileTracker interface {
LastHash(path string) (hash string, ok bool)
LastContent(path string) (content []byte, ok bool)
TrackedPaths() []string
RecentPaths() []string
RecordRead(ctx context.Context, path, hash string) error
RecordChange(ctx context.Context, change *FileChange) error
}
FileTracker tracks read state for Compare-And-Swap (CAS) conflict detection and records structured file changes across a session.
type GlobRequest ¶
type GlobRequest struct {
// Pattern is the glob expression to match (supports *, ?, [...], and **).
Pattern string `json:"pattern"`
// Path is the root directory from which to walk. Defaults to ".".
Path string `json:"path,omitempty"`
// IncludeHidden includes dot-prefixed files and directories (except .git and .bare).
IncludeHidden bool `json:"include_hidden,omitempty"`
// Ignore specifies additional glob patterns to skip.
Ignore []string `json:"ignore,omitempty"`
// Limit caps the maximum number of matched paths returned.
Limit int `json:"limit,omitempty"`
}
GlobRequest configures a wildcard path search via Std.Glob.
type GlobResult ¶
type GlobResult struct {
Pattern string `json:"pattern"`
Path string `json:"path"`
Matches []string `json:"matches"`
Truncated bool `json:"truncated,omitempty"`
}
GlobResult contains the matched file paths returned by Std.Glob.
type GrepMatch ¶
type GrepMatch struct {
Path string `json:"path"`
Line int `json:"line"`
Column int `json:"column"`
Text string `json:"text"`
Before []string `json:"before,omitempty"`
After []string `json:"after,omitempty"`
}
GrepMatch represents a single regular expression match within a text file.
type GrepRequest ¶
type GrepRequest struct {
// Pattern is the regular expression to search for.
Pattern string `json:"pattern"`
// Path is the file or directory path under which to search. Defaults to ".".
Path string `json:"path,omitempty"`
// Include is an optional glob pattern filtering which file paths are searched.
Include string `json:"include,omitempty"`
// CaseInsensitive enables case-insensitive regex matching.
CaseInsensitive bool `json:"case_insensitive,omitempty"`
// ContextLines specifies the number of surrounding lines to capture before
// and after each matching line.
ContextLines int `json:"context_lines,omitempty"`
// IncludeHidden searches dot-prefixed files and directories (except .git and .bare).
IncludeHidden bool `json:"include_hidden,omitempty"`
// Limit caps the maximum number of matches returned.
Limit int `json:"limit,omitempty"`
}
GrepRequest configures a regular expression search across text files via Std.Grep.
type GrepResult ¶
type GrepResult struct {
Pattern string `json:"pattern"`
Matches []GrepMatch `json:"matches"`
Truncated bool `json:"truncated,omitempty"`
}
GrepResult contains the matches returned by Std.Grep.
type ListEntry ¶
type ListEntry struct {
Path string `json:"path"`
Name string `json:"name"`
IsDir bool `json:"is_dir"`
Size int64 `json:"size"`
Mode fs.FileMode `json:"mode"`
ModTime time.Time `json:"mod_time"`
}
ListEntry describes a single filesystem entry returned by Std.List.
type ListRequest ¶
type ListRequest struct {
// Path is the directory path relative to the sandbox root. Defaults to ".".
Path string `json:"path,omitempty"`
// Recursive traverses subdirectories when true.
Recursive bool `json:"recursive,omitempty"`
// MaxDepth bounds recursion depth when Recursive is true (1 = direct children).
// When zero or negative, recursion depth is unbounded.
MaxDepth int `json:"max_depth,omitempty"`
// IncludeHidden includes entries whose names begin with a dot (".").
IncludeHidden bool `json:"include_hidden,omitempty"`
// Ignore specifies glob patterns to exclude from the listing.
Ignore []string `json:"ignore,omitempty"`
// Limit caps the maximum number of entries returned.
Limit int `json:"limit,omitempty"`
}
ListRequest configures a directory listing operation via Std.List.
type ListResult ¶
type ListResult struct {
Path string `json:"path"`
Entries []ListEntry `json:"entries"`
Truncated bool `json:"truncated,omitempty"`
}
ListResult contains the directory entries returned by Std.List.
type MemoryTracker ¶
type MemoryTracker struct {
// contains filtered or unexported fields
}
MemoryTracker is a thread-safe, in-memory implementation of FileTracker suitable for unit tests and stateless callers that do not persist change journals to disk.
func NewMemoryTracker ¶
func NewMemoryTracker() *MemoryTracker
NewMemoryTracker creates a new initialized MemoryTracker.
func (*MemoryTracker) Changes ¶
func (t *MemoryTracker) Changes() []FileChange
Changes returns a chronological copy of all recorded FileChange entries.
func (*MemoryTracker) ChangesForPath ¶
func (t *MemoryTracker) ChangesForPath(path string) []FileChange
ChangesForPath returns a chronological copy of all recorded FileChange entries for the given path.
func (*MemoryTracker) LastContent ¶
func (t *MemoryTracker) LastContent(path string) ([]byte, bool)
LastContent returns a defensive copy of the most recently recorded content snapshot for path from RecordChange. It returns (nil, false) if path has not had a recorded change or if its most recent recorded change was a deletion.
func (*MemoryTracker) LastHash ¶
func (t *MemoryTracker) LastHash(path string) (string, bool)
LastHash returns the most recently recorded SHA-256 content hash for path (from either RecordRead or RecordChange). It returns ("", false) if path has not been read/changed or if its most recent recorded change was a deletion.
func (*MemoryTracker) RecentPaths ¶
func (t *MemoryTracker) RecentPaths() []string
RecentPaths returns the most recently read or modified file paths in MRU order.
func (*MemoryTracker) RecordChange ¶
func (t *MemoryTracker) RecordChange(ctx context.Context, change *FileChange) error
RecordChange assigns a UUIDv7 identifier to change (when empty), appends a defensive copy of change to the in-memory change history, and updates the tracked state for change.Path.
func (*MemoryTracker) RecordRead ¶
func (t *MemoryTracker) RecordRead(ctx context.Context, path, hash string) error
RecordRead records the latest observed SHA-256 hash for path without storing file content snapshots.
func (*MemoryTracker) TrackedPaths ¶
func (t *MemoryTracker) TrackedPaths() []string
TrackedPaths returns a sorted slice of all file paths that have had at least one change recorded via RecordChange.
type RemoveRequest ¶
type RemoveRequest struct {
// Path is the target file path within the sandbox.
Path string `json:"path"`
// ExpectedHash optionally specifies the expected on-disk SHA-256 hex digest
// for Compare-And-Swap verification. When empty, the FileTracker's last
// recorded hash is used.
ExpectedHash string `json:"expected_hash,omitempty"`
// Force bypasses Read-Before-Overwrite and Compare-And-Swap checks.
Force bool `json:"force,omitempty"`
// DryRun computes the deletion diff and line statistics without removing the
// file or updating the FileTracker.
DryRun bool `json:"dry_run,omitempty"`
}
RemoveRequest configures a file deletion operation via Std.Remove.
type RemoveResult ¶
type RemoveResult struct {
Path string `json:"path"`
Deletions int `json:"deletions"`
Diff string `json:"diff,omitempty"`
BeforeHash string `json:"before_hash"`
DryRun bool `json:"dry_run,omitempty"`
}
RemoveResult contains the deletion diff and metadata produced by Std.Remove.
type SearchOptions ¶
type SearchOptions struct {
Query string
Limit int
RecentPaths []string
IncludeHidden *bool // Defaults to true (excluding .git and .env secrets)
}
SearchOptions specifies parameters for fuzzy file searching and ranking.
type SearchRequest ¶
type SearchRequest struct {
// Query is the search string. It is required.
Query string `json:"query"`
// AllowedDomains, when non-empty, keeps only results whose host matches one
// of these domains (a bare domain also matches its subdomains).
AllowedDomains []string `json:"allowed_domains,omitempty"`
// BlockedDomains drops results whose host matches one of these domains. It
// takes precedence over AllowedDomains.
BlockedDomains []string `json:"blocked_domains,omitempty"`
// Limit caps the number of returned results. Zero uses DefaultSearchLimit;
// values above MaxSearchLimit are clamped.
Limit int `json:"limit,omitempty"`
// Endpoint overrides [DefaultSearchEndpoint]. It exists for self-hosted
// search mirrors and for tests; ordinary callers leave it empty.
Endpoint string `json:"endpoint,omitempty"`
// DryRun builds and validates the request without executing it.
DryRun bool `json:"dry_run,omitempty"`
}
SearchRequest configures an outbound web search via Std.Search.
type SearchResult ¶
type SearchResult struct {
Query string `json:"query"`
Endpoint string `json:"endpoint"`
Hits []SearchHit `json:"hits"`
Truncated bool `json:"truncated,omitempty"`
Duration time.Duration `json:"duration"`
DryRun bool `json:"dry_run,omitempty"`
}
SearchResult is the outcome of a Std.Search invocation.
type Std ¶
type Std struct {
// contains filtered or unexported fields
}
Std implements TaskSmith's Standard Operations Library over an isolated sandbox.Sandbox and a FileTracker.
func (*Std) Bash ¶
func (s *Std) Bash(ctx context.Context, req BashRequest) (*BashResult, error)
Bash executes a shell command via "sh -c" inside the sandbox's process capability and immediately calls Std.SyncExternalChanges so any tracked files modified or deleted by the command are recorded with [SourceExternal].
func (*Std) Download ¶
func (s *Std) Download(ctx context.Context, req DownloadRequest) (*DownloadResult, error)
Download fetches a remote resource over HTTP using the sandbox's policy-enforced network client, writes it to req.Path in the sandbox filesystem, and records the mutation in the FileTracker with SourceAgent and tool "download".
func (*Std) Edit ¶
func (s *Std) Edit(ctx context.Context, req EditRequest) (*EditResult, error)
Edit replaces text in an existing file in the sandbox, enforcing Read-Before-Overwrite and Compare-And-Swap unless req.Force is true.
func (*Std) Exec ¶
func (s *Std) Exec(ctx context.Context, req ExecRequest) (*ExecResult, error)
Exec runs a program directly inside the sandbox's process capability without shell interpretation, so argument values reach the process verbatim. It is the execution path for command-backed custom tools, whose argv comes from a vetted manifest rather than a shell string. Like Std.Bash, it immediately calls Std.SyncExternalChanges so any tracked files modified or deleted by the program are recorded with [SourceExternal].
func (*Std) Fetch ¶
func (s *Std) Fetch(ctx context.Context, req FetchRequest) (*FetchResult, error)
Fetch executes an outbound HTTP request through the sandbox's policy-enforced network client.
func (*Std) Glob ¶
func (s *Std) Glob(ctx context.Context, req GlobRequest) (*GlobResult, error)
Glob walks the sandbox filesystem starting from req.Path and returns all file paths matching req.Pattern (including ** multi-directory wildcards). It skips .git and .bare directories by default.
func (*Std) Grep ¶
func (s *Std) Grep(ctx context.Context, req GrepRequest) (*GrepResult, error)
Grep searches text files under req.Path for lines matching req.Pattern.
func (*Std) List ¶
func (s *Std) List(ctx context.Context, req ListRequest) (*ListResult, error)
List enumerates directory entries within the sandbox filesystem.
func (*Std) Remove ¶
func (s *Std) Remove(ctx context.Context, req RemoveRequest) (*RemoveResult, error)
Remove deletes an existing file from the sandbox filesystem, enforcing Read-Before-Overwrite and Compare-And-Swap unless req.Force is true.
func (*Std) Sandbox ¶
Sandbox returns the underlying sandbox.Sandbox bound to s.
func (*Std) Search ¶
func (s *Std) Search(ctx context.Context, req SearchRequest) (*SearchResult, error)
Search executes a web search from the daemon host using a dedicated HTTP client with its own timeout budget. Unlike Std.Fetch, it deliberately does not route through the sandbox network client: search is a daemon-side capability the harness mediates through the permission pipeline, while the session's sandbox.NetworkPolicy keeps confining child processes unchanged.
func (*Std) SyncExternalChanges ¶
func (s *Std) SyncExternalChanges(ctx context.Context) ([]FileChange, error)
SyncExternalChanges inspects all paths currently tracked in the FileTracker against the sandbox filesystem. Any tracked file whose on-disk SHA-256 hash differs from its last recorded hash—or that has been deleted on disk—is recorded as a SourceExternal change.
func (*Std) Tracker ¶
func (s *Std) Tracker() FileTracker
Tracker returns the FileTracker bound to s.
func (*Std) View ¶
func (s *Std) View(ctx context.Context, req ViewRequest) (*ViewResult, error)
View reads a text file from the sandbox filesystem, records its SHA-256 content hash in the FileTracker (emitting a SourceExternal change if a previously tracked file was modified outside the agent), and returns the requested line range with 1-based line numbers.
func (*Std) Write ¶
func (s *Std) Write(ctx context.Context, req WriteRequest) (*WriteResult, error)
Write creates a new file or overwrites an existing file within the sandbox. When overwriting an existing file and !req.Force, Write enforces Read-Before-Overwrite (ErrFileNotRead) and Compare-And-Swap (ErrFileModified).
type ViewMedia ¶
type ViewMedia struct {
Modality media.Modality `json:"modality"`
MIMEType string `json:"mime_type"`
ByteSize int64 `json:"byte_size"`
Pages string `json:"pages,omitempty"`
Data []byte `json:"-"`
}
ViewMedia holds metadata and raw bytes for a supported multimodal file read via Std.View.
type ViewRequest ¶
type ViewRequest struct {
// Path is the file path relative to the sandbox root (or an absolute path
// within the sandbox root).
Path string `json:"path"`
// Offset is the 1-based line number from which to start reading. Defaults to 1.
// Ignored for images, PDFs, and audio.
Offset int `json:"offset,omitempty"`
// Limit is the maximum number of lines to return. Defaults to DefaultViewLimit (2000).
// Ignored for images, PDFs, and audio.
Limit int `json:"limit,omitempty"`
// Pages specifies an optional page range for PDF files (e.g. "1-10" or "3").
// Ignored for text, image, and audio files.
Pages string `json:"pages,omitempty"`
}
ViewRequest configures a file read operation via Std.View.
type ViewResult ¶
type ViewResult struct {
Path string `json:"path"`
Content string `json:"content"`
Numbered string `json:"numbered"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
TotalLines int `json:"total_lines"`
Truncated bool `json:"truncated"`
Hash string `json:"hash"`
Media *ViewMedia `json:"media,omitempty"`
}
ViewResult contains the sliced file content and metadata returned by Std.View.
type WatchRequest ¶
type WatchRequest struct {
// Path is the directory path relative to the sandbox root.
Path string `json:"path"`
// Recursive monitors subdirectories recursively when true.
Recursive bool `json:"recursive,omitempty"`
// Ignore specifies additional directory names or patterns to ignore.
Ignore []string `json:"ignore,omitempty"`
// MaxDirs is the maximum number of directories to watch.
MaxDirs int `json:"max_dirs,omitempty"`
}
WatchRequest configures a filesystem watcher via Std.Watch.
type WriteRequest ¶
type WriteRequest struct {
// Path is the target file path within the sandbox.
Path string `json:"path"`
// Content is the full text content to write to the file.
Content string `json:"content"`
// Mode sets the file permission bits. Defaults to the existing file's mode
// or 0644 for newly created files.
Mode fs.FileMode `json:"mode,omitempty"`
// ExpectedHash optionally specifies the expected on-disk SHA-256 hex digest
// for Compare-And-Swap verification. When empty, the FileTracker's last
// recorded hash is used.
ExpectedHash string `json:"expected_hash,omitempty"`
// Force bypasses Read-Before-Overwrite and Compare-And-Swap checks when
// overwriting an existing file.
Force bool `json:"force,omitempty"`
// DryRun computes the unified diff and line statistics without writing to
// disk or updating the FileTracker.
DryRun bool `json:"dry_run,omitempty"`
}
WriteRequest configures a file creation or overwrite operation via Std.Write.
type WriteResult ¶
type WriteResult struct {
Path string `json:"path"`
Created bool `json:"created"`
BytesWritten int `json:"bytes_written"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Diff string `json:"diff,omitempty"`
BeforeHash string `json:"before_hash,omitempty"`
AfterHash string `json:"after_hash"`
DryRun bool `json:"dry_run,omitempty"`
}
WriteResult contains the diff, statistics, and hashes produced by Std.Write.