Documentation
¶
Overview ¶
Package filesystem provides portable filesystem tool coordination.
Index ¶
- Constants
- func ApplyPatchDefinition() toolcontract.Definition
- func ApplyUpdateChunk(content string, chunk PatchChunk) (string, error)
- func EditDefinition() toolcontract.Definition
- func EditText(content, oldText, newText string, replaceAll bool, maxOutputChars int) (string, int, error)
- func IsLikelyBinary(blob []byte) bool
- func NewApplyPatchHandler(opts Options) toolcontract.Handler
- func NewEditHandler(opts Options) toolcontract.Handler
- func NewReadHandler(opts Options) toolcontract.Handler
- func NewWriteHandler(opts Options) toolcontract.Handler
- func ReadDefinition() toolcontract.Definition
- func Register(reg toolcontract.Registrar, opts Options)
- func SelectText(source io.Reader, startLine, maxLines, maxChars int) (selected string, selectedStart, selectedLines int, truncated bool, err error)
- func WriteDefinition() toolcontract.Definition
- type ApplyPatchRequest
- type EditRequest
- type EditResult
- type Options
- type PatchChunk
- type PatchHunk
- type PatchKind
- type PatchSummary
- type ReadRequest
- type ReadResult
- type Workspace
- type WorkspaceFuncs
- func (w WorkspaceFuncs) ApplyPatch(ctx context.Context, request ApplyPatchRequest) (PatchSummary, error)
- func (w WorkspaceFuncs) Edit(ctx context.Context, request EditRequest) (EditResult, error)
- func (w WorkspaceFuncs) Read(ctx context.Context, request ReadRequest) (ReadResult, error)
- func (w WorkspaceFuncs) Write(ctx context.Context, request WriteRequest) (WriteResult, error)
- type WriteRequest
- type WriteResult
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
ParsePatch parses the AgentX custom *** Begin Patch grammar.
type PatchSummary ¶
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 ¶
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 ¶
type Workspace interface {
Read(context.Context, ReadRequest) (ReadResult, error)
Write(context.Context, WriteRequest) (WriteResult, error)
Edit(context.Context, EditRequest) (EditResult, error)
ApplyPatch(context.Context, ApplyPatchRequest) (PatchSummary, error)
}
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 ¶
WriteRequest is a normalized mutation request.