filesystem

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package filesystem provides portable filesystem tool coordination.

Index

Constants

View Source
const (
	// ReadName is the catalog name of the read tool.
	ReadName = "read"
	// WriteName is the catalog name of the write tool.
	WriteName = "write"
	// EditName is the catalog name of the edit tool.
	EditName = "edit"
	// ApplyPatchName is the catalog name of the apply-patch tool.
	ApplyPatchName = "apply_patch"
)

Variables

This section is empty.

Functions

func ApplyPatchDefinition

func ApplyPatchDefinition() toolcontract.Definition

ApplyPatchDefinition returns the stable custom-patch schema.

func ApplyUpdateChunk

func ApplyUpdateChunk(content string, chunk PatchChunk) (string, error)

ApplyUpdateChunk applies one exact and unambiguous text chunk.

func EditDefinition

func EditDefinition() toolcontract.Definition

EditDefinition returns the stable exact-text edit schema.

func EditText

func EditText(content, oldText, newText string, replaceAll bool, maxOutputChars int) (string, int, error)

EditText applies the exact replacement contract without performing IO.

func IsLikelyBinary

func IsLikelyBinary(blob []byte) bool

IsLikelyBinary detects NUL bytes in the same bounded prefix used by read.

func NewApplyPatchHandler

func NewApplyPatchHandler(opts Options) toolcontract.Handler

NewApplyPatchHandler constructs the custom-patch implementation.

func NewEditHandler

func NewEditHandler(opts Options) toolcontract.Handler

NewEditHandler constructs the exact-text edit implementation.

func NewReadHandler

func NewReadHandler(opts Options) toolcontract.Handler

NewReadHandler constructs the read tool implementation.

func NewWriteHandler

func NewWriteHandler(opts Options) toolcontract.Handler

NewWriteHandler constructs the write tool implementation.

func ReadDefinition

func ReadDefinition() toolcontract.Definition

ReadDefinition returns the stable read tool schema.

func Register

func Register(reg toolcontract.Registrar, opts Options)

Register adds all four filesystem tools when a Workspace is available.

func SelectText

func SelectText(source io.Reader, startLine, maxLines, maxChars int) (selected string, selectedStart, selectedLines int, truncated bool, err error)

SelectText applies the stable line/rune selection and binary rejection used by the read tool. Hosts can stream any root-bound or immutable asset source.

func WriteDefinition

func WriteDefinition() toolcontract.Definition

WriteDefinition returns the stable write tool schema.

Types

type ApplyPatchRequest

type ApplyPatchRequest struct {
	Hunks         []PatchHunk
	MaxInputBytes int64
}

ApplyPatchRequest carries a canonical parsed patch to the Host transaction.

type EditRequest

type EditRequest struct {
	Path           string
	OldText        string
	NewText        string
	ReplaceAll     bool
	MaxInputBytes  int64
	MaxOutputChars int
}

EditRequest is a normalized exact-text mutation request.

type EditResult

type EditResult struct {
	Path         string   `json:"path"`
	Replacements int      `json:"replacements"`
	FilesTouched []string `json:"files_touched,omitempty"`
}

EditResult describes a committed edit.

type Options

type Options struct {
	Workspace            Workspace
	MaxReadChars         int
	MaxWriteChars        int
	MaxPatchChars        int
	MaxReadFileBytes     int64
	MaxMutationFileBytes int64
}

Options configures portable filesystem coordination. Workspace owns every side effect and all Host policy; this package owns model-facing semantics.

type PatchChunk

type PatchChunk struct {
	OldLines []string
	NewLines []string
}

PatchChunk contains the exact old/new line context for one update.

type PatchHunk

type PatchHunk struct {
	Kind    PatchKind
	Path    string
	MoveTo  string
	AddBody []string
	Chunks  []PatchChunk
}

PatchHunk is one parsed custom patch operation.

func ParsePatch

func ParsePatch(input string) ([]PatchHunk, error)

ParsePatch parses the AgentX custom *** Begin Patch grammar.

type PatchKind

type PatchKind string

PatchKind identifies a custom patch hunk operation.

const (
	// PatchAdd adds a new file.
	PatchAdd PatchKind = "add"
	// PatchDelete removes an existing file.
	PatchDelete PatchKind = "delete"
	// PatchUpdate edits or moves an existing file.
	PatchUpdate PatchKind = "update"
)

type PatchSummary

type PatchSummary struct {
	Added    []string
	Modified []string
	Deleted  []string
	Touched  []string
}

PatchSummary records successfully committed files.

func (PatchSummary) FilesTouched

func (s PatchSummary) FilesTouched() []string

FilesTouched returns a stable first-seen union of changed paths.

func (PatchSummary) Text

func (s PatchSummary) Text() string

Text returns the historical human-readable apply-patch summary.

type ReadRequest

type ReadRequest struct {
	Path         string
	StartLine    int
	MaxLines     int
	MaxChars     int
	MaxFileBytes int64
}

ReadRequest is a normalized text selection request.

type ReadResult

type ReadResult struct {
	Path      string `json:"path"`
	StartLine int    `json:"start_line"`
	LineCount int    `json:"line_count"`
	Content   string `json:"content"`
	Truncated bool   `json:"truncated"`
}

ReadResult is the Host-resolved text selection returned to the model.

type Workspace

Workspace is the narrow Host port for protected, root-bound filesystem IO. Implementations own workspace selection, authorization, symlink policy and atomic/durable mutation. They must not reinterpret model-facing arguments.

type WorkspaceFuncs

type WorkspaceFuncs struct {
	ReadFunc       func(context.Context, ReadRequest) (ReadResult, error)
	WriteFunc      func(context.Context, WriteRequest) (WriteResult, error)
	EditFunc       func(context.Context, EditRequest) (EditResult, error)
	ApplyPatchFunc func(context.Context, ApplyPatchRequest) (PatchSummary, error)
}

WorkspaceFuncs adapts four Host functions to Workspace. It keeps Host integration narrow without requiring a public adapter type in the Host.

func (WorkspaceFuncs) ApplyPatch

func (w WorkspaceFuncs) ApplyPatch(ctx context.Context, request ApplyPatchRequest) (PatchSummary, error)

ApplyPatch delegates to ApplyPatchFunc and fails closed when unavailable.

func (WorkspaceFuncs) Edit

func (w WorkspaceFuncs) Edit(ctx context.Context, request EditRequest) (EditResult, error)

Edit delegates to EditFunc and fails closed when it is unavailable.

func (WorkspaceFuncs) Read

func (w WorkspaceFuncs) Read(ctx context.Context, request ReadRequest) (ReadResult, error)

Read delegates to ReadFunc and fails closed when it is unavailable.

func (WorkspaceFuncs) Write

func (w WorkspaceFuncs) Write(ctx context.Context, request WriteRequest) (WriteResult, error)

Write delegates to WriteFunc and fails closed when it is unavailable.

type WriteRequest

type WriteRequest struct {
	Path       string
	Content    string
	Append     bool
	CreateDirs bool
}

WriteRequest is a normalized mutation request.

type WriteResult

type WriteResult struct {
	Path         string   `json:"path"`
	BytesWritten int      `json:"bytes_written"`
	Mode         string   `json:"mode"`
	FilesTouched []string `json:"files_touched,omitempty"`
}

WriteResult describes a committed write.

Jump to

Keyboard shortcuts

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