Documentation
¶
Index ¶
- Variables
- type CommandResult
- type CommandSpec
- type DirEntry
- type EvictionSink
- type ExaClient
- type ExaSearchResult
- type FileInfo
- type NativePatchOperation
- type PatchChange
- type PatchChunk
- type PatchOperation
- type PatchOperationType
- type Workspace
- func (w *Workspace) AddReadRoots(dirs ...string) error
- func (w *Workspace) ApplyPatch(ctx context.Context, operations []PatchOperation) ([]PatchChange, error)
- func (w *Workspace) EditFile(ctx context.Context, relPath string, oldText string, newText string) error
- func (w *Workspace) GrantWorkingDirectory(dir string) error
- func (w *Workspace) GrantWorkspaceDirectory(dir string) error
- func (w *Workspace) InspectFile(ctx context.Context, relPath string) (FileInfo, error)
- func (w *Workspace) ListDir(ctx context.Context, relPath string) ([]DirEntry, error)
- func (w *Workspace) ReadBytes(ctx context.Context, relPath string, maxBytes int64) ([]byte, error)
- func (w *Workspace) ReadFile(ctx context.Context, relPath string, maxBytes int64) (string, error)
- func (w *Workspace) Root() string
- func (w *Workspace) RunCommand(ctx context.Context, spec CommandSpec) (CommandResult, error)
- func (w *Workspace) RunPython(ctx context.Context, pythonPath string, code string, spec CommandSpec) (CommandResult, error)
- func (w *Workspace) WriteFile(ctx context.Context, relPath string, content string) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidRoot = errors.New("localtools: invalid workspace root") ErrPathOutsideRoot = errors.New("localtools: path outside workspace root") ErrOldTextNotFound = errors.New("localtools: old text not found") ErrOldTextNotUnique = errors.New("localtools: old text occurs more than once") ErrInvalidPatch = errors.New("localtools: invalid patch") ErrPatchUnsupported = errors.New("localtools: patch delegation is not supported") ErrCommandFailed = errors.New("localtools: command failed") ErrExternalAPIKey = errors.New("localtools: real external api key is not allowed") ErrInvalidFile = errors.New("localtools: invalid file") )
Functions ¶
This section is empty.
Types ¶
type CommandResult ¶
type CommandResult struct {
ExitCode int
Output string
OutputBytes int
OutputTruncated bool
PID int
// Archive is the retained output for the recovery archive: up to
// ArchiveLimit bytes as head+tail windows separated by a gap marker. Empty
// when nothing was truncated or ArchiveLimit was <=0. It is a superset of
// Output, not a replacement — callers write it to durable storage and hand
// the model a read-back reference.
Archive string
}
type CommandSpec ¶
type CommandSpec struct {
Name string
Args []string
CWD string
Env []string
Timeout time.Duration
MaxOutput int
// ArchiveLimit bounds the bytes retained BEYOND MaxOutput for the recovery
// archive, so output the model never sees can still be written somewhere it
// can read back. <=0 retains nothing (Archive stays empty). When the command
// produces more than this, the retained text keeps a head and a tail window
// with an explicit middle-gap marker — a build's error is usually at the end,
// so a head-only archive would drop the one part worth keeping.
ArchiveLimit int
}
type EvictionSink ¶
type EvictionSink struct {
// contains filtered or unexported fields
}
EvictionSink adapts a Workspace to compaction.EvictionSink: it writes evicted tool-result/text content under a workspace subdir and returns the workspace-relative path the model reads back via read_file. It structurally satisfies compaction.EvictionSink (a Put method), so localtools needn't import compaction.
func NewEvictionSink ¶
func NewEvictionSink(ws *Workspace, dir string) *EvictionSink
NewEvictionSink returns a Workspace-backed eviction sink writing under dir (workspace-relative; "" -> defaultEvictionDir).
type ExaClient ¶
type ExaClient struct {
// contains filtered or unexported fields
}
func NewExaClient ¶
func NewExaClient(endpoint string, auth string, allowDirect bool, client *http.Client) (*ExaClient, error)
NewExaClient builds the Exa web_search client. By default the auth value must be a sidecar placeholder (the sidecar rewrites it with the real key); allowDirect permits a real EXA_API_KEY for sidecar-less testing, in which case requests hit Exa directly.
type ExaSearchResult ¶
type ExaSearchResult struct {
Body string
}
type NativePatchOperation ¶ added in v0.0.2
type PatchChange ¶ added in v0.0.2
type PatchChunk ¶ added in v0.0.2
type PatchOperation ¶ added in v0.0.2
type PatchOperation struct {
Type PatchOperationType
Path string
MovePath string
Content string
Chunks []PatchChunk
}
func ParseNativePatchOperation ¶ added in v0.0.2
func ParseNativePatchOperation(op NativePatchOperation) ([]PatchOperation, error)
ParseNativePatchOperation converts the Responses API apply_patch operation object into the same V4A operation representation used by custom tool calls.
func ParsePatch ¶ added in v0.0.2
func ParsePatch(patch string) ([]PatchOperation, error)
ParsePatch parses the V4A patch format used by Codex custom apply_patch calls. It intentionally accepts only explicit file markers and line prefixes; path authorization happens later, before any filesystem mutation.
type PatchOperationType ¶ added in v0.0.2
type PatchOperationType string
const ( PatchCreate PatchOperationType = "create_file" PatchUpdate PatchOperationType = "update_file" PatchDelete PatchOperationType = "delete_file" )
type Workspace ¶
type Workspace struct {
// contains filtered or unexported fields
}
func NewWorkspace ¶
func (*Workspace) AddReadRoots ¶
AddReadRoots registers additional read-only roots (absolute paths) that read-only file ops may read from. Each is resolved to an absolute, symlink-evaluated path; an entry that doesn't exist is skipped (so a deployment with no baked assets is a no-op rather than a startup error). Writes never use these roots.
func (*Workspace) ApplyPatch ¶ added in v0.0.2
func (w *Workspace) ApplyPatch(ctx context.Context, operations []PatchOperation) ([]PatchChange, error)
ApplyPatch validates every operation and computes every resulting file in memory before committing. If a filesystem error occurs during commit, the touched files are restored to their original state.
func (*Workspace) GrantWorkingDirectory ¶
GrantWorkingDirectory registers a user-selected directory for read-only file tools and as an allowed cwd for command execution. The structured write/edit APIs remain confined to Root().
func (*Workspace) GrantWorkspaceDirectory ¶ added in v0.0.2
GrantWorkspaceDirectory grants a user-selected project to both read and write tools. Callers must expose this only through an explicit workspace selection action such as project-mode /cd.
func (*Workspace) InspectFile ¶
func (*Workspace) ReadBytes ¶
ReadBytes returns the raw bytes of relPath without coercing to a string, so it is safe for binary artifacts the agent presents (images, PDFs). Unlike ReadFile it errors rather than truncating when the file exceeds maxBytes (<=0 → no cap) — a truncated binary is corrupt.
func (*Workspace) RunCommand ¶
func (w *Workspace) RunCommand(ctx context.Context, spec CommandSpec) (CommandResult, error)
func (*Workspace) RunPython ¶
func (w *Workspace) RunPython(ctx context.Context, pythonPath string, code string, spec CommandSpec) (CommandResult, error)