texttool

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteTextLinesTool

func DeleteTextLinesTool() spec.Tool

func FindTextTool

func FindTextTool() spec.Tool

func InsertTextLinesTool

func InsertTextLinesTool() spec.Tool

func ReadTextRangeTool

func ReadTextRangeTool() spec.Tool

func ReplaceTextLinesTool

func ReplaceTextLinesTool() spec.Tool

Types

type DeleteTextLinesArgs

type DeleteTextLinesArgs struct {
	Path              string   `json:"path"`
	MatchLines        []string `json:"matchLines"`
	BeforeLines       []string `json:"beforeLines,omitempty"`
	AfterLines        []string `json:"afterLines,omitempty"`
	ExpectedDeletions int      `json:"expectedDeletions,omitempty"` // default 1
}

type DeleteTextLinesOut

type DeleteTextLinesOut struct {
	DeletionsMade  int   `json:"deletionsMade"`
	DeletedAtLines []int `json:"deletedAtLines"` // 1-based start line of each deleted block
}

func DeleteTextLines

func DeleteTextLines(ctx context.Context, args DeleteTextLinesArgs) (*DeleteTextLinesOut, error)

DeleteTextLines deletes occurrences of MatchLines from a UTF‑8 file. Behavior notes (entry point):

  • The file must exist, be a regular file, not a symlink, and be valid UTF‑8.
  • Matching is line-wise using strings.TrimSpace on each line.
  • If ExpectedDeletions is set, the tool fails unless exactly that many deletions would be made.
  • Writes are atomic (temp file + fsync + rename) and preserve newline style and final newline.

type FindTextArgs

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

	QueryType string `json:"queryType,omitempty"` // substring (default) | regex | lineBlock
	Query     string `json:"query,omitempty"`     // required for substring/regex

	MatchLines []string `json:"matchLines,omitempty"` // required for lineBlock

	ContextLines int `json:"contextLines,omitempty"` // default 5
	MaxMatches   int `json:"maxMatches,omitempty"`   // default 10
}

type FindTextLine

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

type FindTextMatch

type FindTextMatch struct {
	MatchStartLine          int            `json:"matchStartLine"`          // 1-based
	MatchEndLine            int            `json:"matchEndLine"`            // 1-based
	MatchedLinesWithContext []FindTextLine `json:"matchedLinesWithContext"` // includes matched lines as well (window around match)
}

type FindTextOut

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

func FindText

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

FindText finds occurrences and returns matches with context. Behavior notes (entry point):

  • File must exist, be regular, not a symlink, and valid UTF‑8.
  • Matching uses TrimSpace per line for both file and input blocks.
  • Returned lines are original file lines (not trimmed).
  • Deterministic: matches are returned in ascending file order up to maxMatches.
  • For queryType=lineBlock, overlapping matches are rejected.

type InsertTextLinesArgs

type InsertTextLinesArgs struct {
	Path             string   `json:"path"`
	Position         string   `json:"position,omitempty"` // default "end"
	LinesToInsert    []string `json:"linesToInsert"`
	AnchorMatchLines []string `json:"anchorMatchLines,omitempty"`
}

type InsertTextLinesOut

type InsertTextLinesOut struct {
	InsertedAtLine      int  `json:"insertedAtLine"` // 1-based, where insertion begins
	InsertedLineCount   int  `json:"insertedLineCount"`
	AnchorMatchedAtLine *int `json:"anchorMatchedAtLine,omitempty"` // 1-based start line of anchor block
}

func InsertTextLines

func InsertTextLines(ctx context.Context, args InsertTextLinesArgs) (*InsertTextLinesOut, error)

InsertTextLines inserts LinesToInsert into a UTF‑8 file. Behavior notes (entry point):

  • File must exist, be regular, not a symlink, and valid UTF‑8.
  • Matching is line-wise using strings.TrimSpace.
  • For beforeAnchor/afterAnchor: the anchor block must match exactly once; otherwise it fails.
  • Writes are atomic and preserve newline style and final newline presence.

type ReadTextRangeArgs

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

	StartMatchLines []string `json:"startMatchLines,omitempty"`
	EndMatchLines   []string `json:"endMatchLines,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
	EndLine       int                 `json:"endLine,omitempty"`   // 1-based
	LinesReturned int                 `json:"linesReturned"`
	Lines         []ReadTextRangeLine `json:"lines"`
}

func ReadTextRange

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

ReadTextRange reads a UTF‑8 file and returns a bounded range of lines.

Behavior notes (entry point):

  • File must exist, be regular, not a symlink, and valid UTF‑8.
  • Matching uses TrimSpace comparisons (for file + provided blocks).
  • Deterministic / no ambiguity:
  • startMatchLines (if provided) must match exactly once.
  • endMatchLines (if provided) must match exactly once.
  • if both are provided, end must occur after start block (non-overlapping).
  • If the selected range exceeds maxReadTextRangeOutputLines, the tool fails.

type ReplaceTextLinesArgs

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

	MatchLines []string `json:"matchLines"`

	// Required; must contain at least one line.
	// This tool does NOT support deletion (use deletetextlines).
	ReplaceWithLines []string `json:"replaceWithLines"`

	BeforeLines []string `json:"beforeLines,omitempty"`
	AfterLines  []string `json:"afterLines,omitempty"`

	// Pointer is used so we can distinguish "omitted" (default to 1) from "explicit 0" (error).
	ExpectedReplacements *int `json:"expectedReplacements,omitempty"` // default 1; minimum 1
}

type ReplaceTextLinesOut

type ReplaceTextLinesOut struct {
	ReplacementsMade int   `json:"replacementsMade"`
	ReplacedAtLines  []int `json:"replacedAtLines"` // 1-based start line of each replacement
}

func ReplaceTextLines

func ReplaceTextLines(ctx context.Context, args ReplaceTextLinesArgs) (*ReplaceTextLinesOut, error)

ReplaceTextLines replaces occurrences of MatchLines in a UTF‑8 file.

Behavior notes (entry point):

  • File must exist, be regular, not a symlink, and valid UTF‑8.
  • Matching is line-wise using TrimSpace comparisons (for both file + input blocks).
  • Returned/inserted lines are written exactly as provided (no trimming).
  • Deterministic / no ambiguity: fails unless match count == expectedReplacements (default 1, minimum 1).
  • Deletion is not supported here; use deletetextlines.
  • Writes are atomic and preserve newline style and final newline presence.

Jump to

Keyboard shortcuts

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