texttool

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyUnifiedDiffArgs added in v0.21.0

type ApplyUnifiedDiffArgs struct {
	DiffText string `json:"diffText"`

	// Default false. If true, only checks and returns reusable FileTargets.
	DryRun bool `json:"dryRun,omitempty"`

	// Default false. If true, disables fuzzy matching.
	Strict bool `json:"strict,omitempty"`

	// Optional explicit path mappings.
	FileTargets []ApplyUnifiedDiffFileTarget `json:"fileTargets,omitempty"`

	// Optional local paths to consider when diff paths do not resolve.
	CandidatePaths []string `json:"candidatePaths,omitempty"`
}

type ApplyUnifiedDiffFileOut added in v0.21.0

type ApplyUnifiedDiffFileOut struct {
	OK bool `json:"ok"`

	FileKey      string                 `json:"fileKey"`
	OldPath      string                 `json:"oldPath,omitempty"`
	NewPath      string                 `json:"newPath,omitempty"`
	TargetPath   string                 `json:"targetPath,omitempty"`
	ResolvedPath string                 `json:"resolvedPath,omitempty"`
	Status       ApplyUnifiedDiffStatus `json:"status"`
	Message      string                 `json:"message,omitempty"`

	CandidatePaths []string `json:"candidatePaths,omitempty"`
	Diagnostics    []string `json:"diagnostics,omitempty"`

	Hunks               int `json:"hunks"`
	AppliedHunks        int `json:"appliedHunks"`
	AlreadyAppliedHunks int `json:"alreadyAppliedHunks"`
	AddedLines          int `json:"addedLines"`
	DeletedLines        int `json:"deletedLines"`
}

type ApplyUnifiedDiffFileTarget added in v0.21.0

type ApplyUnifiedDiffFileTarget struct {
	FileKey    string `json:"fileKey,omitempty"`
	OldPath    string `json:"oldPath,omitempty"`
	NewPath    string `json:"newPath,omitempty"`
	TargetPath string `json:"targetPath"`
}

type ApplyUnifiedDiffOut added in v0.21.0

type ApplyUnifiedDiffOut struct {
	OK     bool                   `json:"ok"`
	DryRun bool                   `json:"dryRun"`
	Status ApplyUnifiedDiffStatus `json:"status"`

	Message     string   `json:"message,omitempty"`
	Diagnostics []string `json:"diagnostics,omitempty"`

	Summary ApplyUnifiedDiffSummary `json:"summary"`

	// Reusable as ApplyUnifiedDiffArgs.FileTargets.
	FileTargets []ApplyUnifiedDiffFileTarget `json:"fileTargets,omitempty"`

	Files []ApplyUnifiedDiffFileOut `json:"files,omitempty"`
}

type ApplyUnifiedDiffStatus added in v0.21.0

type ApplyUnifiedDiffStatus string
const (
	ApplyUnifiedDiffStatusApplicable     ApplyUnifiedDiffStatus = "applicable"
	ApplyUnifiedDiffStatusApplied        ApplyUnifiedDiffStatus = "applied"
	ApplyUnifiedDiffStatusAlreadyApplied ApplyUnifiedDiffStatus = "already_applied"
	ApplyUnifiedDiffStatusNeedsInfo      ApplyUnifiedDiffStatus = "needs_info"
	ApplyUnifiedDiffStatusConflict       ApplyUnifiedDiffStatus = "conflict"
	ApplyUnifiedDiffStatusError          ApplyUnifiedDiffStatus = "error"
)

type ApplyUnifiedDiffSummary added in v0.21.0

type ApplyUnifiedDiffSummary struct {
	Files               int `json:"files"`
	Hunks               int `json:"hunks"`
	AppliedHunks        int `json:"appliedHunks"`
	AlreadyAppliedHunks int `json:"alreadyAppliedHunks"`
	AddedLines          int `json:"addedLines"`
	DeletedLines        int `json:"deletedLines"`
}

type DeleteTextArgs added in v0.17.0

type DeleteTextArgs struct {
	Path string `json:"path"`

	// Required. Nil means omitted. Must not be the empty string.
	OldText *string `json:"oldText"`

	// Optional. Must not be the empty string if provided.
	TextAbove *string `json:"textAbove,omitempty"`

	// Optional. Must not be the empty string if provided.
	TextBelow *string `json:"textBelow,omitempty"`

	// Optional 1-based hint for the start line of oldText.
	// May only be used when ExpectedCount is omitted or 1.
	LineHint *int `json:"lineHint,omitempty"`

	// Default 1.
	ExpectedCount *int `json:"expectedCount,omitempty"`
}

type DeleteTextOut added in v0.17.0

type DeleteTextOut struct {
	DeletionsMade  int   `json:"deletionsMade"`
	DeletedAtLines []int `json:"deletedAtLines"` // 1-based start lines of deleted blocks
}

type FindTextArgs

type FindTextArgs struct {
	Path string `json:"path"`

	QueryType string `json:"queryType,omitempty"` // substring (default) | regex
	Query     string `json:"query"`               // required, may contain newlines

	ContextLines int `json:"contextLines,omitempty"` // default 1, effective min 1
	MaxMatches   int `json:"maxMatches,omitempty"`   // default 10
}

type FindTextLine

type FindTextLine struct {
	LineNumber int    `json:"lineNumber"` // 1-based
	Text       string `json:"text"`       // original line, without trailing newline
}

type FindTextMatch

type FindTextMatch struct {
	MatchStartLine   int `json:"matchStartLine"`   // 1-based
	MatchStartColumn int `json:"matchStartColumn"` // 1-based UTF-8 rune column, inclusive

	MatchEndLine   int `json:"matchEndLine"`   // 1-based
	MatchEndColumn int `json:"matchEndColumn"` // 1-based UTF-8 rune column, exclusive

	Context []FindTextLine `json:"context,omitempty"` // includes matched lines as well
}

type FindTextOut

type FindTextOut struct {
	ReachedMaxMatches        bool            `json:"reachedMaxMatches"`
	AdditionalMatchesOmitted int             `json:"additionalMatchesOmitted,omitempty"`
	MatchesReturned          int             `json:"matchesReturned"`
	Matches                  []FindTextMatch `json:"matches"`
}

type InsertTextArgs added in v0.17.0

type InsertTextArgs struct {
	Path      string  `json:"path"`
	Text      *string `json:"text"`
	Position  string  `json:"position"`
	TextAbove *string `json:"textAbove,omitempty"`
	TextBelow *string `json:"textBelow,omitempty"`
	LineHint  *int    `json:"lineHint,omitempty"`
}

type InsertTextOut added in v0.17.0

type InsertTextOut struct {
	InsertedAtLine         int  `json:"insertedAtLine"` // 1-based, where insertion begins
	InsertedLineCount      int  `json:"insertedLineCount"`
	TextAboveMatchedAtLine *int `json:"textAboveMatchedAtLine,omitempty"` // 1-based start line of the matched textAbove boundary block used in the original file
	TextBelowMatchedAtLine *int `json:"textBelowMatchedAtLine,omitempty"` // 1-based start line of the matched textBelow boundary block used in the original file
}

type ReadTextRangeArgs

type ReadTextRangeArgs struct {
	Path string `json:"path"`

	// Optional 1-based start line. Defaults to 1.
	StartLine *int `json:"startLine,omitempty"`

	// Optional number of lines to return. Defaults to defaultReadTextRangeLineCount.
	LineCount *int `json:"lineCount,omitempty"`
}

type ReadTextRangeLine

type ReadTextRangeLine struct {
	LineNumber int    `json:"lineNumber"` // 1-based
	Text       string `json:"text"`       // original file line (not trimmed)
}

type ReadTextRangeOut

type ReadTextRangeOut struct {
	StartLine     int                 `json:"startLine,omitempty"` // 1-based; zero for empty output
	EndLine       int                 `json:"endLine,omitempty"`   // 1-based; zero for empty output
	LinesReturned int                 `json:"linesReturned"`
	Lines         []ReadTextRangeLine `json:"lines"`
	EOFReached    bool                `json:"eofReached"` // true if returned range reaches EOF
}

type ReplaceTextArgs added in v0.17.0

type ReplaceTextArgs struct {
	Path string `json:"path"`

	// Required. Nil means omitted. Must not be the empty string.
	OldText *string `json:"oldText"`

	// Required. Nil means omitted. Must not be the empty string.
	NewText *string `json:"newText"`

	// Optional. Must not be the empty string if provided.
	TextAbove *string `json:"textAbove,omitempty"`

	// Optional. Must not be the empty string if provided.
	TextBelow *string `json:"textBelow,omitempty"`

	// Optional 1-based hint for the start line of oldText.
	// May only be used when ExpectedCount is omitted or 1.
	LineHint *int `json:"lineHint,omitempty"`

	// Default 1.
	ExpectedCount *int `json:"expectedCount,omitempty"`
}

type ReplaceTextOut added in v0.17.0

type ReplaceTextOut struct {
	ReplacementsMade int   `json:"replacementsMade"`
	ReplacedAtLines  []int `json:"replacedAtLines"` // 1-based start lines of replaced blocks
}

type TextTool added in v0.7.0

type TextTool struct {
	// contains filtered or unexported fields
}

TextTool is an instance-owned text tool runner. It centralizes path resolution and sandbox policy:

  • workBaseDir: base for resolving relative paths
  • allowedRoots: optional restriction; if empty/nil, allow all
  • blockSymlinks: blocks symlink traversal (if enforced downstream).

func NewTextTool added in v0.7.0

func NewTextTool(opts ...TextToolOption) (*TextTool, error)

func (*TextTool) ApplyUnifiedDiff added in v0.21.0

func (tt *TextTool) ApplyUnifiedDiff(ctx context.Context, args ApplyUnifiedDiffArgs) (*ApplyUnifiedDiffOut, error)

func (*TextTool) ApplyUnifiedDiffTool added in v0.21.0

func (tt *TextTool) ApplyUnifiedDiffTool() spec.Tool

func (*TextTool) DeleteText added in v0.17.0

func (tt *TextTool) DeleteText(ctx context.Context, args DeleteTextArgs) (*DeleteTextOut, error)

func (*TextTool) DeleteTextTool added in v0.17.0

func (tt *TextTool) DeleteTextTool() spec.Tool

func (*TextTool) FindText added in v0.7.0

func (tt *TextTool) FindText(ctx context.Context, args FindTextArgs) (*FindTextOut, error)

func (*TextTool) FindTextTool added in v0.7.0

func (tt *TextTool) FindTextTool() spec.Tool

func (*TextTool) InsertText added in v0.17.0

func (tt *TextTool) InsertText(ctx context.Context, args InsertTextArgs) (*InsertTextOut, error)

func (*TextTool) InsertTextTool added in v0.17.0

func (tt *TextTool) InsertTextTool() spec.Tool

func (*TextTool) ReadTextRange added in v0.7.0

func (tt *TextTool) ReadTextRange(ctx context.Context, args ReadTextRangeArgs) (*ReadTextRangeOut, error)

func (*TextTool) ReadTextRangeTool added in v0.7.0

func (tt *TextTool) ReadTextRangeTool() spec.Tool

func (*TextTool) ReplaceText added in v0.17.0

func (tt *TextTool) ReplaceText(ctx context.Context, args ReplaceTextArgs) (*ReplaceTextOut, error)

func (*TextTool) ReplaceTextTool added in v0.17.0

func (tt *TextTool) ReplaceTextTool() spec.Tool

type TextToolOption added in v0.7.0

type TextToolOption func(*TextTool) error

func WithAllowedRoots added in v0.7.0

func WithAllowedRoots(roots []string) TextToolOption
func WithBlockSymlinks(block bool) TextToolOption

WithBlockSymlinks configures whether symlink traversal should be blocked (if supported downstream).

func WithWorkBaseDir added in v0.7.0

func WithWorkBaseDir(base string) TextToolOption

Jump to

Keyboard shortcuts

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