Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyLineEdit(content string, startLine, endLine int, newText string) (string, int, int, error)
- func ApplyPatchChunks(content string, chunks []PatchChunk) (string, int, int, error)
- func BuildEditPreviewResult(path, diff, newContent string, editStartLine, editEndLine int, isNewFile bool) map[string]any
- func BuildEditSuccessResult(path, diff, newContent string, editStartLine, editEndLine int, isNewFile bool) map[string]any
- func CalculateEditLineRange(newContent string, replaceStart int, replaceText string) (startLine, endLine int)
- func ClearPendingEditForPath(toolCtx *ToolContext, path string)
- func CommonEditCheck(ctx context.Context, args json.RawMessage, base *BaseEditTool) error
- func CountMatches(content, search string) int
- func CreateNewFileContent(newText string) string
- func FinalizeEdit(b *BaseEditTool, path, fullPath, oldContent, newContent, diff string, ...) (any, error)
- func FindMatchPosition(content, search string) (start, end int, found bool)
- func FindMatchWithSearch(ctx context.Context, cfg *config.Config, fullPath string, search string) (matchLine int, matchCount int, err error)
- func FindMostSimilarLine(content, search string) (lineNum int, line string, ratio float64)
- func FindSimilarChunk(content, search string, contextLines int) (startLine int, chunk string, ratio float64)
- func FormatError(err error) string
- func FormatToolError(err *ToolError) string
- func GeneratePostEditContext(newContent string, editStartLine, editEndLine int) string
- func GenerateStreamingDiff(fullPath, path string, startLine, endLine int, oldLines, newText string) (string, error)
- func GetContextAroundPosition(content string, position int, contextLines int) string
- func GetLineNumber(content string, byteOffset int) int
- func GetMaxIgnoreCount(cfg *config.Config) int
- func HandleMultipleMatches(content, search, path string, count int) map[string]any
- func HandleNoMatch(content, search, path string) map[string]any
- func IsBacktrackable(err error) bool
- func IsLargeFile(fullPath string) (bool, int64, error)
- func IsRipgrepAvailable() bool
- func LevenshteinDistance(s1, s2 string) int
- func LineEditDescription() string
- func LineEditJSONSchema() map[string]any
- func LineEditPromptSection(previewMode bool) string
- func MatchWithNormalization(content, search string, fuzzyThreshold float64) (start, end int, level int, found bool)
- func NormalizeAndValidatePath(workspaceRoot, inputPath string) (string, bool, error)
- func NormalizeToolCallArguments(tool Tool, args json.RawMessage) (json.RawMessage, error)
- func NormalizeToolCallTypes(msg *llm.Message)
- func NormalizeWhitespace(s string) string
- func NormalizeWhitespaceRstrip(s string) string
- func PatchEditDescription() string
- func PatchEditJSONSchema() map[string]any
- func PatchEditPromptSection(previewMode bool) string
- func ReadLineRange(fullPath string, startLine, endLine int) (content string, totalLines int, err error)
- func SearchReplaceEditDescription() string
- func SearchReplaceEditJSONSchema() map[string]any
- func SearchReplaceEditPromptSection(previewMode bool) string
- func SequenceMatcherRatio(s1, s2 string) float64
- func SimilarityRatio(s1, s2 string) float64
- func StorePendingEdit(toolCtx *ToolContext, path, fullPath, oldContent, newContent, diff string, ...)
- func StreamingSearchInRange(fullPath string, search string, startLine, endLine int) (matchStartLine, matchEndLine int, found bool, err error)
- type BaseEditTool
- func (b *BaseEditTool) CheckReadBeforeEdit(path string) error
- func (b *BaseEditTool) GetConfig() *config.Config
- func (b *BaseEditTool) ReadFileForEdit(fullPath string) (content string, isNewFile bool, err error)
- func (b *BaseEditTool) StreamingLineReplace(fullPath string, startLine, endLine int, newText string) error
- func (b *BaseEditTool) ValidateAndResolvePath(path string) (fullPath string, outside bool, err error)
- func (b *BaseEditTool) WriteFileAtomic(fullPath, content string, isNewFile bool) error
- type CancelEditTool
- func (t *CancelEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *CancelEditTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *CancelEditTool) Description() string
- func (t *CancelEditTool) JSONSchema() map[string]any
- func (t *CancelEditTool) Name() string
- func (t *CancelEditTool) PromptCategory() string
- func (t *CancelEditTool) PromptOrder() int
- func (t *CancelEditTool) PromptSection() string
- func (t *CancelEditTool) PromptTemplateName() string
- type CancelWriteTool
- func (t *CancelWriteTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *CancelWriteTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *CancelWriteTool) Description() string
- func (t *CancelWriteTool) JSONSchema() map[string]any
- func (t *CancelWriteTool) Name() string
- func (t *CancelWriteTool) PromptCategory() string
- func (t *CancelWriteTool) PromptOrder() int
- func (t *CancelWriteTool) PromptSection() string
- func (t *CancelWriteTool) PromptTemplateName() string
- type CheckpointDiffTool
- func (t *CheckpointDiffTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *CheckpointDiffTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *CheckpointDiffTool) Description() string
- func (t *CheckpointDiffTool) JSONSchema() map[string]any
- func (t *CheckpointDiffTool) Name() string
- func (t *CheckpointDiffTool) PromptCategory() string
- func (t *CheckpointDiffTool) PromptOrder() int
- func (t *CheckpointDiffTool) PromptSection() string
- func (t *CheckpointDiffTool) PromptTemplateName() string
- type CheckpointListTool
- func (t *CheckpointListTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *CheckpointListTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *CheckpointListTool) Description() string
- func (t *CheckpointListTool) JSONSchema() map[string]any
- func (t *CheckpointListTool) Name() string
- func (t *CheckpointListTool) PromptCategory() string
- func (t *CheckpointListTool) PromptOrder() int
- func (t *CheckpointListTool) PromptSection() string
- func (t *CheckpointListTool) PromptTemplateName() string
- type CheckpointRestoreTool
- func (t *CheckpointRestoreTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *CheckpointRestoreTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *CheckpointRestoreTool) Description() string
- func (t *CheckpointRestoreTool) JSONSchema() map[string]any
- func (t *CheckpointRestoreTool) Name() string
- func (t *CheckpointRestoreTool) PromptCategory() string
- func (t *CheckpointRestoreTool) PromptOrder() int
- func (t *CheckpointRestoreTool) PromptSection() string
- func (t *CheckpointRestoreTool) PromptTemplateName() string
- type CheckpointUndoTool
- func (t *CheckpointUndoTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *CheckpointUndoTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *CheckpointUndoTool) Description() string
- func (t *CheckpointUndoTool) JSONSchema() map[string]any
- func (t *CheckpointUndoTool) Name() string
- func (t *CheckpointUndoTool) PromptCategory() string
- func (t *CheckpointUndoTool) PromptOrder() int
- func (t *CheckpointUndoTool) PromptSection() string
- func (t *CheckpointUndoTool) PromptTemplateName() string
- type ConfirmEditTool
- func (t *ConfirmEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *ConfirmEditTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *ConfirmEditTool) Description() string
- func (t *ConfirmEditTool) JSONSchema() map[string]any
- func (t *ConfirmEditTool) Name() string
- func (t *ConfirmEditTool) PromptCategory() string
- func (t *ConfirmEditTool) PromptOrder() int
- func (t *ConfirmEditTool) PromptSection() string
- func (t *ConfirmEditTool) PromptTemplateName() string
- type ConfirmWriteTool
- func (t *ConfirmWriteTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *ConfirmWriteTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *ConfirmWriteTool) Description() string
- func (t *ConfirmWriteTool) JSONSchema() map[string]any
- func (t *ConfirmWriteTool) Name() string
- func (t *ConfirmWriteTool) PromptCategory() string
- func (t *ConfirmWriteTool) PromptOrder() int
- func (t *ConfirmWriteTool) PromptSection() string
- func (t *ConfirmWriteTool) PromptTemplateName() string
- type DebugLogger
- type EditPreviewResult
- type EditResult
- type EditTool
- type FilePatch
- type FileReadTracker
- type FuzzyMatcher
- type GrepTool
- type JSONError
- type OutputBuffer
- type PatchAction
- type PatchChunk
- type PatchEditTool
- func (t *PatchEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *PatchEditTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *PatchEditTool) Description() string
- func (t *PatchEditTool) JSONSchema() map[string]any
- func (t *PatchEditTool) Name() string
- func (t *PatchEditTool) PromptCategory() string
- func (t *PatchEditTool) PromptOrder() int
- func (t *PatchEditTool) PromptSection() string
- func (t *PatchEditTool) PromptTemplateName() string
- type PendingEditState
- type Plan
- type PlanAddStepTool
- func (t *PlanAddStepTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *PlanAddStepTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *PlanAddStepTool) Description() string
- func (t *PlanAddStepTool) JSONSchema() map[string]any
- func (t *PlanAddStepTool) Name() string
- func (t *PlanAddStepTool) PromptCategory() string
- func (t *PlanAddStepTool) PromptOrder() int
- func (t *PlanAddStepTool) PromptSection() string
- func (t *PlanAddStepTool) PromptTemplateName() string
- type PlanCompleteStepTool
- func (t *PlanCompleteStepTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *PlanCompleteStepTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *PlanCompleteStepTool) Description() string
- func (t *PlanCompleteStepTool) JSONSchema() map[string]any
- func (t *PlanCompleteStepTool) Name() string
- func (t *PlanCompleteStepTool) PromptCategory() string
- func (t *PlanCompleteStepTool) PromptOrder() int
- func (t *PlanCompleteStepTool) PromptSection() string
- func (t *PlanCompleteStepTool) PromptTemplateName() string
- type PlanCreateTool
- func (t *PlanCreateTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *PlanCreateTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *PlanCreateTool) Description() string
- func (t *PlanCreateTool) JSONSchema() map[string]any
- func (t *PlanCreateTool) Name() string
- func (t *PlanCreateTool) PromptCategory() string
- func (t *PlanCreateTool) PromptOrder() int
- func (t *PlanCreateTool) PromptSection() string
- func (t *PlanCreateTool) PromptTemplateName() string
- type PlanManager
- type PlanMoveStepTool
- func (t *PlanMoveStepTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *PlanMoveStepTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *PlanMoveStepTool) Description() string
- func (t *PlanMoveStepTool) JSONSchema() map[string]any
- func (t *PlanMoveStepTool) Name() string
- func (t *PlanMoveStepTool) PromptCategory() string
- func (t *PlanMoveStepTool) PromptOrder() int
- func (t *PlanMoveStepTool) PromptSection() string
- func (t *PlanMoveStepTool) PromptTemplateName() string
- type PlanRemoveStepTool
- func (t *PlanRemoveStepTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *PlanRemoveStepTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *PlanRemoveStepTool) Description() string
- func (t *PlanRemoveStepTool) JSONSchema() map[string]any
- func (t *PlanRemoveStepTool) Name() string
- func (t *PlanRemoveStepTool) PromptCategory() string
- func (t *PlanRemoveStepTool) PromptOrder() int
- func (t *PlanRemoveStepTool) PromptSection() string
- func (t *PlanRemoveStepTool) PromptTemplateName() string
- type ReadFileTool
- func (t *ReadFileTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *ReadFileTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *ReadFileTool) Description() string
- func (t *ReadFileTool) JSONSchema() map[string]any
- func (t *ReadFileTool) Name() string
- func (t *ReadFileTool) PromptCategory() string
- func (t *ReadFileTool) PromptOrder() int
- func (t *ReadFileTool) PromptSection() string
- func (t *ReadFileTool) PromptTemplateName() string
- type Registry
- func (r *Registry) All() []Tool
- func (r *Registry) Disable(name string)
- func (r *Registry) Enable(t Tool)
- func (r *Registry) EnabledCategories() []string
- func (r *Registry) ExtractToolCallsFromText(content string) []llm.ToolCall
- func (r *Registry) GenerateToolPrompt() string
- func (r *Registry) Get(name string) Tool
- func (r *Registry) IsEnabled(name string) bool
- func (r *Registry) ListTools() []string
- func (r *Registry) LooksLikeMalformedToolCall(content string) bool
- func (r *Registry) PromptSections() map[string][]toolDoc
- func (r *Registry) Specs() []llm.ToolSpec
- func (r *Registry) ToolsInCategory(category string) []Tool
- type RestoreFileTool
- func (t *RestoreFileTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *RestoreFileTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *RestoreFileTool) Description() string
- func (t *RestoreFileTool) JSONSchema() map[string]any
- func (t *RestoreFileTool) Name() string
- func (t *RestoreFileTool) PromptCategory() string
- func (t *RestoreFileTool) PromptOrder() int
- func (t *RestoreFileTool) PromptSection() string
- func (t *RestoreFileTool) PromptTemplateName() string
- type SearchReplaceEditTool
- func (t *SearchReplaceEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *SearchReplaceEditTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *SearchReplaceEditTool) Description() string
- func (t *SearchReplaceEditTool) JSONSchema() map[string]any
- func (t *SearchReplaceEditTool) Name() string
- func (t *SearchReplaceEditTool) PromptCategory() string
- func (t *SearchReplaceEditTool) PromptOrder() int
- func (t *SearchReplaceEditTool) PromptSection() string
- func (t *SearchReplaceEditTool) PromptTemplateName() string
- type SearchTool
- func (t *SearchTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *SearchTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *SearchTool) Description() string
- func (t *SearchTool) JSONSchema() map[string]any
- func (t *SearchTool) Name() string
- func (t *SearchTool) PromptCategory() string
- func (t *SearchTool) PromptOrder() int
- func (t *SearchTool) PromptSection() string
- func (t *SearchTool) PromptTemplateName() string
- type SetupConfig
- type ShellAdvancedTool
- func (t *ShellAdvancedTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *ShellAdvancedTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *ShellAdvancedTool) Description() string
- func (t *ShellAdvancedTool) JSONSchema() map[string]any
- func (t *ShellAdvancedTool) Name() string
- func (t *ShellAdvancedTool) PromptCategory() string
- func (t *ShellAdvancedTool) PromptOrder() int
- func (t *ShellAdvancedTool) PromptSection() string
- func (t *ShellAdvancedTool) PromptTemplateName() string
- type ShellTool
- func (t *ShellTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *ShellTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *ShellTool) Description() string
- func (t *ShellTool) JSONSchema() map[string]any
- func (t *ShellTool) Name() string
- func (t *ShellTool) PromptCategory() string
- func (t *ShellTool) PromptOrder() int
- func (t *ShellTool) PromptSection() string
- func (t *ShellTool) PromptTemplateName() string
- type Step
- type TasksAcceptDiffTool
- func (t *TasksAcceptDiffTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *TasksAcceptDiffTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *TasksAcceptDiffTool) Description() string
- func (t *TasksAcceptDiffTool) JSONSchema() map[string]any
- func (t *TasksAcceptDiffTool) Name() string
- func (t *TasksAcceptDiffTool) PromptCategory() string
- func (t *TasksAcceptDiffTool) PromptOrder() int
- func (t *TasksAcceptDiffTool) PromptSection() string
- func (t *TasksAcceptDiffTool) PromptTemplateName() string
- type TasksDeclineDiffTool
- func (t *TasksDeclineDiffTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *TasksDeclineDiffTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *TasksDeclineDiffTool) Description() string
- func (t *TasksDeclineDiffTool) JSONSchema() map[string]any
- func (t *TasksDeclineDiffTool) Name() string
- func (t *TasksDeclineDiffTool) PromptCategory() string
- func (t *TasksDeclineDiffTool) PromptOrder() int
- func (t *TasksDeclineDiffTool) PromptSection() string
- func (t *TasksDeclineDiffTool) PromptTemplateName() string
- type TasksFinishTool
- func (t *TasksFinishTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *TasksFinishTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *TasksFinishTool) Description() string
- func (t *TasksFinishTool) JSONSchema() map[string]any
- func (t *TasksFinishTool) Name() string
- func (t *TasksFinishTool) PromptCategory() string
- func (t *TasksFinishTool) PromptOrder() int
- func (t *TasksFinishTool) PromptSection() string
- func (t *TasksFinishTool) PromptTemplateName() string
- type TasksRevertFileTool
- func (t *TasksRevertFileTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *TasksRevertFileTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *TasksRevertFileTool) Description() string
- func (t *TasksRevertFileTool) JSONSchema() map[string]any
- func (t *TasksRevertFileTool) Name() string
- func (t *TasksRevertFileTool) PromptCategory() string
- func (t *TasksRevertFileTool) PromptOrder() int
- func (t *TasksRevertFileTool) PromptSection() string
- func (t *TasksRevertFileTool) PromptTemplateName() string
- type TasksRevertToTaskStartTool
- func (t *TasksRevertToTaskStartTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *TasksRevertToTaskStartTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *TasksRevertToTaskStartTool) Description() string
- func (t *TasksRevertToTaskStartTool) JSONSchema() map[string]any
- func (t *TasksRevertToTaskStartTool) Name() string
- func (t *TasksRevertToTaskStartTool) PromptCategory() string
- func (t *TasksRevertToTaskStartTool) PromptOrder() int
- func (t *TasksRevertToTaskStartTool) PromptSection() string
- func (t *TasksRevertToTaskStartTool) PromptTemplateName() string
- type TasksStartTool
- func (t *TasksStartTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *TasksStartTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *TasksStartTool) Description() string
- func (t *TasksStartTool) JSONSchema() map[string]any
- func (t *TasksStartTool) Name() string
- func (t *TasksStartTool) PromptCategory() string
- func (t *TasksStartTool) PromptOrder() int
- func (t *TasksStartTool) PromptSection() string
- func (t *TasksStartTool) PromptTemplateName() string
- type TempFileManager
- type Tool
- type ToolContext
- func (tc *ToolContext) ClearPendingEdit()
- func (tc *ToolContext) ClearPendingEditIfPath(path string)
- func (tc *ToolContext) GetAndClearPendingEdit() *pendingEdit
- func (tc *ToolContext) GetAndClearPendingWrite() *pendingWrite
- func (tc *ToolContext) GetPendingEdit() *pendingEdit
- func (tc *ToolContext) GetPendingEditDiff() string
- func (tc *ToolContext) GetPendingEditPath() string
- func (tc *ToolContext) GetPendingWritePath() string
- func (tc *ToolContext) HasPendingEdit() bool
- func (tc *ToolContext) SetPendingEdit(p *pendingEdit)
- func (tc *ToolContext) SetPendingWrite(p *pendingWrite)
- type ToolError
- func CheckPendingEditBlockWithConfig(toolName string, args json.RawMessage, blockCount int, cfg *config.Config, ...) *ToolError
- func CheckPendingEditBlockWithState(toolName string, state PendingEditState, cfg *config.Config, ...) *ToolError
- func RuntimeError(msg string) *ToolError
- func RuntimeErrorWithDetails(msg string, details map[string]any) *ToolError
- func RuntimeErrorf(format string, args ...any) *ToolError
- func SemanticError(msg string) *ToolError
- func SemanticErrorWithDetails(msg string, details map[string]any) *ToolError
- func SemanticErrorf(format string, args ...any) *ToolError
- func WrapAsRuntime(err error) *ToolError
- func WrapAsSemantic(err error) *ToolError
- type ToolErrorType
- type TruncationResult
- type UnifiedEditTool
- func (t *UnifiedEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *UnifiedEditTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *UnifiedEditTool) Description() string
- func (t *UnifiedEditTool) JSONSchema() map[string]any
- func (t *UnifiedEditTool) Name() string
- func (t *UnifiedEditTool) PromptCategory() string
- func (t *UnifiedEditTool) PromptOrder() int
- func (t *UnifiedEditTool) PromptSection() string
- func (t *UnifiedEditTool) PromptTemplateName() string
- type WriteFileTool
- func (t *WriteFileTool) Call(ctx context.Context, args json.RawMessage) (any, error)
- func (t *WriteFileTool) Check(ctx context.Context, args json.RawMessage) error
- func (t *WriteFileTool) Description() string
- func (t *WriteFileTool) JSONSchema() map[string]any
- func (t *WriteFileTool) Name() string
- func (t *WriteFileTool) PromptCategory() string
- func (t *WriteFileTool) PromptOrder() int
- func (t *WriteFileTool) PromptSection() string
- func (t *WriteFileTool) PromptTemplateName() string
Constants ¶
const ( DefaultMaxLines = 150 // No truncation threshold DefaultMaxBytes = 24 * 1024 // 24KB DefaultTruncatedLines = 75 // Lines per side when truncated DefaultTruncatedBytes = 12 * 1024 // 12KB total when truncated )
const EditPendingNextStep = "" /* 249-byte string literal not displayed */
EditPendingNextStep is the message shown when an edit is pending confirmation
const LargeFileThreshold = 1024 * 1024 // 1MB
LargeFileThreshold is the file size above which we require line hints for editing Files larger than this won't be loaded entirely into memory
const PendingEditAutoResolveThreshold = 5
PendingEditAutoResolveThreshold is the number of retries before auto-cancelling pending edit
const PendingEditEscalateThreshold = 3
PendingEditEscalateThreshold is the number of retries before escalating error message
const PendingEditMaxIgnoreCount = 5
PendingEditMaxIgnoreCount is the maximum number of ignored responses before auto-cancel
const PostEditContextLines = 3
PostEditContextLines is the number of surrounding lines to show in post-edit context
const StreamingEditBufferSize = 64 * 1024 // 64KB
StreamingEditBufferSize is the buffer size used for streaming file operations
Variables ¶
var CategoryHeaders = map[string]string{
"filesystem": "## File Tools Reference",
"shell": "## Shell Tool",
"plan": "## Plan Management Tools",
"checkpoint": "## Checkpoints and Undo",
}
CategoryHeaders defines the section headers for each category
Functions ¶
func ApplyLineEdit ¶
func ApplyLineEdit(content string, startLine, endLine int, newText string) (string, int, int, error)
ApplyLineEdit applies a line-based edit to content. If endLine is 0, inserts newText at startLine (existing content shifts down). Otherwise replaces lines [startLine, endLine] (1-based, inclusive) with newText. Returns new content, edit start line, edit end line, and error.
func ApplyPatchChunks ¶
ApplyPatchChunks applies patch chunks to file content. Returns new content, edit start line, edit end line, and error.
func BuildEditPreviewResult ¶
func BuildEditPreviewResult(path, diff, newContent string, editStartLine, editEndLine int, isNewFile bool) map[string]any
BuildEditPreviewResult builds the standard preview result for an edit operation. This is the single place where the edit preview response format is defined.
func BuildEditSuccessResult ¶
func BuildEditSuccessResult(path, diff, newContent string, editStartLine, editEndLine int, isNewFile bool) map[string]any
BuildEditSuccessResult builds the standard success result for an edit operation. This is the single place where the edit success response format is defined.
func CalculateEditLineRange ¶
func CalculateEditLineRange(newContent string, replaceStart int, replaceText string) (startLine, endLine int)
CalculateEditLineRange calculates the line range affected by an edit given the new content and the byte position where the replacement was inserted. Returns 1-based start and end line numbers in the new content.
func ClearPendingEditForPath ¶
func ClearPendingEditForPath(toolCtx *ToolContext, path string)
ClearPendingEditForPath clears any pending edit for a specific path using the provided ToolContext.
func CommonEditCheck ¶
func CommonEditCheck(ctx context.Context, args json.RawMessage, base *BaseEditTool) error
CommonEditCheck performs common validation for all edit tool modes
func CountMatches ¶
CountMatches counts how many times search appears in content
func CreateNewFileContent ¶
CreateNewFileContent creates content for a new file. For new files, ignores line numbers and just uses the newText as content.
func FinalizeEdit ¶
func FinalizeEdit(b *BaseEditTool, path, fullPath, oldContent, newContent, diff string, editStartLine, editEndLine int, isNewFile bool) (any, error)
FinalizeEdit handles preview mode or applies the edit with consistent result format. This is the single source of truth for the final edit handling logic.
func FindMatchPosition ¶
FindMatchPosition finds the position of search in content Returns start index, end index, and whether found
func FindMatchWithSearch ¶
func FindMatchWithSearch(ctx context.Context, cfg *config.Config, fullPath string, search string) (matchLine int, matchCount int, err error)
FindMatchWithSearch uses the Search tool (ripgrep/grep) to find matches in a file Returns: line number of first match, total match count, error This is robust and handles large files, long lines, binary files, etc.
func FindMostSimilarLine ¶
FindMostSimilarLine finds the most similar line in content to the search string Useful for error messages suggesting what the user might have meant
func FindSimilarChunk ¶
func FindSimilarChunk(content, search string, contextLines int) (startLine int, chunk string, ratio float64)
FindSimilarChunk finds a chunk of lines similar to the search text Returns the start line number, the chunk, and similarity ratio
func FormatError ¶
FormatError checks if an error implements JSONError and returns JSON, otherwise returns plain text
func FormatToolError ¶
FormatToolError returns a formatted string representation of a ToolError If the error has details, returns JSON; otherwise returns plain message
func GeneratePostEditContext ¶
GeneratePostEditContext generates a formatted view of the file content after edit showing the edited region with surrounding context lines. editStartLine and editEndLine are 1-based line numbers in the new content.
func GenerateStreamingDiff ¶
func GenerateStreamingDiff(fullPath, path string, startLine, endLine int, oldLines, newText string) (string, error)
GenerateStreamingDiff generates a diff by reading only the affected line range This avoids loading the entire file for diff generation
func GetContextAroundPosition ¶
GetContextAroundPosition returns a few lines of context around a byte position
func GetLineNumber ¶
GetLineNumber returns the 1-based line number for a byte offset in content
func GetMaxIgnoreCount ¶
GetMaxIgnoreCount returns the maximum ignore count from config or default
func HandleMultipleMatches ¶
HandleMultipleMatches returns an error result with context for disambiguation
func HandleNoMatch ¶
HandleNoMatch returns a helpful error result when search text is not found
func IsBacktrackable ¶
IsBacktrackable checks if an error should trigger backtracking Returns true only for semantic errors where the LLM should have known better
func IsLargeFile ¶
IsLargeFile checks if a file exceeds the large file threshold
func IsRipgrepAvailable ¶
func IsRipgrepAvailable() bool
IsRipgrepAvailable returns true if ripgrep (rg) is available on the system
func LevenshteinDistance ¶
LevenshteinDistance calculates the edit distance between two strings
func LineEditDescription ¶
func LineEditDescription() string
LineEditDescription returns the description for line edit mode
func LineEditJSONSchema ¶
LineEditJSONSchema returns the JSON schema for line edit mode
func LineEditPromptSection ¶
LineEditPromptSection returns the prompt section for line edit mode
func MatchWithNormalization ¶
func MatchWithNormalization(content, search string, fuzzyThreshold float64) (start, end int, level int, found bool)
MatchWithNormalization tries to match search text with progressive normalization levels Returns position and the normalization level that succeeded: 0 = exact, 1 = rstrip, 2 = full strip, 3 = fuzzy
func NormalizeAndValidatePath ¶
NormalizeAndValidatePath normalizes a path and checks if it's outside workspace Returns: (normalizedPath, isOutside, error)
func NormalizeToolCallArguments ¶
func NormalizeToolCallArguments(tool Tool, args json.RawMessage) (json.RawMessage, error)
NormalizeToolCallArguments is a middleware that normalizes tool arguments by converting string numbers to actual numbers when the schema expects numeric types
func NormalizeToolCallTypes ¶
NormalizeToolCallTypes ensures all tool calls have type: "function" This handles cases where LLMs return tool calls with empty or missing type fields, which causes validation errors when replaying messages to stricter APIs like Mistral.
func NormalizeWhitespace ¶
NormalizeWhitespace strips leading and trailing whitespace from each line
func NormalizeWhitespaceRstrip ¶
NormalizeWhitespaceRstrip strips only trailing whitespace from each line
func PatchEditDescription ¶
func PatchEditDescription() string
PatchEditDescription returns the description for patch edit mode
func PatchEditJSONSchema ¶
PatchEditJSONSchema returns the JSON schema for patch edit mode
func PatchEditPromptSection ¶
PatchEditPromptSection returns the prompt section for patch edit mode
func ReadLineRange ¶
func ReadLineRange(fullPath string, startLine, endLine int) (content string, totalLines int, err error)
ReadLineRange reads a specific range of lines from a file without loading the entire file Returns the content of lines [startLine, endLine] (1-based, inclusive) and total line count
func SearchReplaceEditDescription ¶
func SearchReplaceEditDescription() string
SearchReplaceEditDescription returns the description for search-replace edit mode
func SearchReplaceEditJSONSchema ¶
SearchReplaceEditJSONSchema returns the JSON schema for search-replace edit mode
func SearchReplaceEditPromptSection ¶
SearchReplaceEditPromptSection returns the prompt section for search-replace edit mode
func SequenceMatcherRatio ¶
SequenceMatcherRatio implements a ratio similar to Python's difflib.SequenceMatcher.ratio() Uses the Ratcliff/Obershelp algorithm: 2 * matching_chars / total_chars This is faster than Levenshtein for large strings and better suited for code comparison
func SimilarityRatio ¶
SimilarityRatio calculates the similarity ratio between two strings (0.0 to 1.0) Based on the formula: 1 - (distance / max(len(s1), len(s2)))
func StorePendingEdit ¶
func StorePendingEdit(toolCtx *ToolContext, path, fullPath, oldContent, newContent, diff string, isNewFile bool, editStartLine, editEndLine int)
StorePendingEdit stores a computed edit for preview mode using the provided ToolContext. editStartLine and editEndLine are 1-based line numbers in the new content.
func StreamingSearchInRange ¶
func StreamingSearchInRange(fullPath string, search string, startLine, endLine int) (matchStartLine, matchEndLine int, found bool, err error)
StreamingSearchInRange searches for text within a specific line range Returns the matched content's start/end line numbers within the range
Types ¶
type BaseEditTool ¶
type BaseEditTool struct {
Config *config.Config
WorkspaceRoot string
ToolCtx *ToolContext
}
BaseEditTool provides common functionality for all edit tool implementations
func (*BaseEditTool) CheckReadBeforeEdit ¶
func (b *BaseEditTool) CheckReadBeforeEdit(path string) error
CheckReadBeforeEdit validates that the file was read recently if configured
func (*BaseEditTool) GetConfig ¶
func (b *BaseEditTool) GetConfig() *config.Config
GetConfig returns the tool's config
func (*BaseEditTool) ReadFileForEdit ¶
func (b *BaseEditTool) ReadFileForEdit(fullPath string) (content string, isNewFile bool, err error)
ReadFileForEdit reads a file for editing, handling new file creation Returns content, isNewFile, and error
func (*BaseEditTool) StreamingLineReplace ¶
func (b *BaseEditTool) StreamingLineReplace(fullPath string, startLine, endLine int, newText string) error
StreamingLineReplace performs a streaming line-based replacement Replaces lines [startLine, endLine] with newText without loading entire file into memory
func (*BaseEditTool) ValidateAndResolvePath ¶
func (b *BaseEditTool) ValidateAndResolvePath(path string) (fullPath string, outside bool, err error)
ValidateAndResolvePath validates and resolves a path for editing Returns the full path, whether it's outside workspace, and any error
func (*BaseEditTool) WriteFileAtomic ¶
func (b *BaseEditTool) WriteFileAtomic(fullPath, content string, isNewFile bool) error
WriteFileAtomic writes content to a file atomically using temp file + rename
type CancelEditTool ¶
type CancelEditTool struct {
// contains filtered or unexported fields
}
CancelEditTool cancels the pending edit from edit (only used in preview mode)
func NewCancelEditTool ¶
func NewCancelEditTool(cfg *config.Config, toolCtx *ToolContext) *CancelEditTool
func (*CancelEditTool) Call ¶
func (t *CancelEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*CancelEditTool) Check ¶
func (t *CancelEditTool) Check(ctx context.Context, args json.RawMessage) error
func (*CancelEditTool) Description ¶
func (t *CancelEditTool) Description() string
func (*CancelEditTool) JSONSchema ¶
func (t *CancelEditTool) JSONSchema() map[string]any
func (*CancelEditTool) Name ¶
func (t *CancelEditTool) Name() string
func (*CancelEditTool) PromptCategory ¶
func (t *CancelEditTool) PromptCategory() string
func (*CancelEditTool) PromptOrder ¶
func (t *CancelEditTool) PromptOrder() int
func (*CancelEditTool) PromptSection ¶
func (t *CancelEditTool) PromptSection() string
func (*CancelEditTool) PromptTemplateName ¶
func (t *CancelEditTool) PromptTemplateName() string
type CancelWriteTool ¶
type CancelWriteTool struct {
// contains filtered or unexported fields
}
CancelWriteTool cancels a pending write operation
func NewCancelWriteTool ¶
func NewCancelWriteTool(cfg *config.Config, toolCtx *ToolContext) *CancelWriteTool
func (*CancelWriteTool) Call ¶
func (t *CancelWriteTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*CancelWriteTool) Check ¶
func (t *CancelWriteTool) Check(ctx context.Context, args json.RawMessage) error
func (*CancelWriteTool) Description ¶
func (t *CancelWriteTool) Description() string
func (*CancelWriteTool) JSONSchema ¶
func (t *CancelWriteTool) JSONSchema() map[string]any
func (*CancelWriteTool) Name ¶
func (t *CancelWriteTool) Name() string
func (*CancelWriteTool) PromptCategory ¶
func (t *CancelWriteTool) PromptCategory() string
func (*CancelWriteTool) PromptOrder ¶
func (t *CancelWriteTool) PromptOrder() int
func (*CancelWriteTool) PromptSection ¶
func (t *CancelWriteTool) PromptSection() string
func (*CancelWriteTool) PromptTemplateName ¶
func (t *CancelWriteTool) PromptTemplateName() string
type CheckpointDiffTool ¶
type CheckpointDiffTool struct {
// contains filtered or unexported fields
}
func NewCheckpointDiffTool ¶
func NewCheckpointDiffTool(manager *checkpoint.Manager) *CheckpointDiffTool
func (*CheckpointDiffTool) Call ¶
func (t *CheckpointDiffTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*CheckpointDiffTool) Check ¶
func (t *CheckpointDiffTool) Check(ctx context.Context, args json.RawMessage) error
func (*CheckpointDiffTool) Description ¶
func (t *CheckpointDiffTool) Description() string
func (*CheckpointDiffTool) JSONSchema ¶
func (t *CheckpointDiffTool) JSONSchema() map[string]any
func (*CheckpointDiffTool) Name ¶
func (t *CheckpointDiffTool) Name() string
func (*CheckpointDiffTool) PromptCategory ¶
func (t *CheckpointDiffTool) PromptCategory() string
func (*CheckpointDiffTool) PromptOrder ¶
func (t *CheckpointDiffTool) PromptOrder() int
func (*CheckpointDiffTool) PromptSection ¶
func (t *CheckpointDiffTool) PromptSection() string
func (*CheckpointDiffTool) PromptTemplateName ¶
func (t *CheckpointDiffTool) PromptTemplateName() string
type CheckpointListTool ¶
type CheckpointListTool struct {
// contains filtered or unexported fields
}
func NewCheckpointListTool ¶
func NewCheckpointListTool(manager *checkpoint.Manager) *CheckpointListTool
func (*CheckpointListTool) Call ¶
func (t *CheckpointListTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*CheckpointListTool) Check ¶
func (t *CheckpointListTool) Check(ctx context.Context, args json.RawMessage) error
func (*CheckpointListTool) Description ¶
func (t *CheckpointListTool) Description() string
func (*CheckpointListTool) JSONSchema ¶
func (t *CheckpointListTool) JSONSchema() map[string]any
func (*CheckpointListTool) Name ¶
func (t *CheckpointListTool) Name() string
func (*CheckpointListTool) PromptCategory ¶
func (t *CheckpointListTool) PromptCategory() string
func (*CheckpointListTool) PromptOrder ¶
func (t *CheckpointListTool) PromptOrder() int
func (*CheckpointListTool) PromptSection ¶
func (t *CheckpointListTool) PromptSection() string
func (*CheckpointListTool) PromptTemplateName ¶
func (t *CheckpointListTool) PromptTemplateName() string
type CheckpointRestoreTool ¶
type CheckpointRestoreTool struct {
// contains filtered or unexported fields
}
func NewCheckpointRestoreTool ¶
func NewCheckpointRestoreTool(manager *checkpoint.Manager) *CheckpointRestoreTool
func (*CheckpointRestoreTool) Call ¶
func (t *CheckpointRestoreTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*CheckpointRestoreTool) Check ¶
func (t *CheckpointRestoreTool) Check(ctx context.Context, args json.RawMessage) error
func (*CheckpointRestoreTool) Description ¶
func (t *CheckpointRestoreTool) Description() string
func (*CheckpointRestoreTool) JSONSchema ¶
func (t *CheckpointRestoreTool) JSONSchema() map[string]any
func (*CheckpointRestoreTool) Name ¶
func (t *CheckpointRestoreTool) Name() string
func (*CheckpointRestoreTool) PromptCategory ¶
func (t *CheckpointRestoreTool) PromptCategory() string
func (*CheckpointRestoreTool) PromptOrder ¶
func (t *CheckpointRestoreTool) PromptOrder() int
func (*CheckpointRestoreTool) PromptSection ¶
func (t *CheckpointRestoreTool) PromptSection() string
func (*CheckpointRestoreTool) PromptTemplateName ¶
func (t *CheckpointRestoreTool) PromptTemplateName() string
type CheckpointUndoTool ¶
type CheckpointUndoTool struct {
// contains filtered or unexported fields
}
func NewCheckpointUndoTool ¶
func NewCheckpointUndoTool(manager *checkpoint.Manager) *CheckpointUndoTool
func (*CheckpointUndoTool) Call ¶
func (t *CheckpointUndoTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*CheckpointUndoTool) Check ¶
func (t *CheckpointUndoTool) Check(ctx context.Context, args json.RawMessage) error
func (*CheckpointUndoTool) Description ¶
func (t *CheckpointUndoTool) Description() string
func (*CheckpointUndoTool) JSONSchema ¶
func (t *CheckpointUndoTool) JSONSchema() map[string]any
func (*CheckpointUndoTool) Name ¶
func (t *CheckpointUndoTool) Name() string
func (*CheckpointUndoTool) PromptCategory ¶
func (t *CheckpointUndoTool) PromptCategory() string
func (*CheckpointUndoTool) PromptOrder ¶
func (t *CheckpointUndoTool) PromptOrder() int
func (*CheckpointUndoTool) PromptSection ¶
func (t *CheckpointUndoTool) PromptSection() string
func (*CheckpointUndoTool) PromptTemplateName ¶
func (t *CheckpointUndoTool) PromptTemplateName() string
type ConfirmEditTool ¶
type ConfirmEditTool struct {
// contains filtered or unexported fields
}
ConfirmEditTool confirms and applies the last previewed edit from edit (only used in preview mode)
func NewConfirmEditTool ¶
func NewConfirmEditTool(cfg *config.Config, toolCtx *ToolContext) *ConfirmEditTool
func (*ConfirmEditTool) Call ¶
func (t *ConfirmEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*ConfirmEditTool) Check ¶
func (t *ConfirmEditTool) Check(ctx context.Context, args json.RawMessage) error
func (*ConfirmEditTool) Description ¶
func (t *ConfirmEditTool) Description() string
func (*ConfirmEditTool) JSONSchema ¶
func (t *ConfirmEditTool) JSONSchema() map[string]any
func (*ConfirmEditTool) Name ¶
func (t *ConfirmEditTool) Name() string
func (*ConfirmEditTool) PromptCategory ¶
func (t *ConfirmEditTool) PromptCategory() string
func (*ConfirmEditTool) PromptOrder ¶
func (t *ConfirmEditTool) PromptOrder() int
func (*ConfirmEditTool) PromptSection ¶
func (t *ConfirmEditTool) PromptSection() string
func (*ConfirmEditTool) PromptTemplateName ¶
func (t *ConfirmEditTool) PromptTemplateName() string
type ConfirmWriteTool ¶
type ConfirmWriteTool struct {
// contains filtered or unexported fields
}
ConfirmWriteTool confirms and applies a pending write operation
func NewConfirmWriteTool ¶
func NewConfirmWriteTool(cfg *config.Config, toolCtx *ToolContext) *ConfirmWriteTool
func (*ConfirmWriteTool) Call ¶
func (t *ConfirmWriteTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*ConfirmWriteTool) Check ¶
func (t *ConfirmWriteTool) Check(ctx context.Context, args json.RawMessage) error
func (*ConfirmWriteTool) Description ¶
func (t *ConfirmWriteTool) Description() string
func (*ConfirmWriteTool) JSONSchema ¶
func (t *ConfirmWriteTool) JSONSchema() map[string]any
func (*ConfirmWriteTool) Name ¶
func (t *ConfirmWriteTool) Name() string
func (*ConfirmWriteTool) PromptCategory ¶
func (t *ConfirmWriteTool) PromptCategory() string
func (*ConfirmWriteTool) PromptOrder ¶
func (t *ConfirmWriteTool) PromptOrder() int
func (*ConfirmWriteTool) PromptSection ¶
func (t *ConfirmWriteTool) PromptSection() string
func (*ConfirmWriteTool) PromptTemplateName ¶
func (t *ConfirmWriteTool) PromptTemplateName() string
type DebugLogger ¶
type DebugLogger interface {
Debug(msg string)
}
DebugLogger is an interface for debug logging to avoid import cycles
type EditPreviewResult ¶
type EditPreviewResult struct {
Status string `json:"status"` // "pending_confirmation"
NextStep string `json:"next_step"`
Diff string `json:"diff"`
AfterEdit string `json:"after_edit,omitempty"` // Shows how file looks after edit
Path string `json:"path"`
IsNewFile bool `json:"is_new_file,omitempty"`
Message string `json:"message,omitempty"`
}
EditPreviewResult is returned when preview mode is enabled
type EditResult ¶
type EditResult struct {
Success bool `json:"success"`
Path string `json:"path"`
Diff string `json:"diff,omitempty"`
Created bool `json:"created,omitempty"`
Message string `json:"message,omitempty"`
}
EditResult contains the result of an edit operation
type EditTool ¶
type EditTool interface {
Tool
// GetConfig returns the tool's config for shared functionality
GetConfig() *config.Config
}
EditTool is the interface that all edit tool implementations must satisfy
type FilePatch ¶
type FilePatch struct {
Action PatchAction
Path string
Chunks []PatchChunk
}
FilePatch represents a patch for a single file
func ParsePatch ¶
ParsePatch parses a V4A-format patch into structured FilePatch objects
type FileReadTracker ¶
type FileReadTracker struct {
// contains filtered or unexported fields
}
FileReadTracker tracks which files have been read recently for read-before-edit enforcement
func (*FileReadTracker) CurrentMessageID ¶
func (t *FileReadTracker) CurrentMessageID() int
CurrentMessageID returns the current message ID
func (*FileReadTracker) NextMessage ¶
func (t *FileReadTracker) NextMessage() int
NextMessage increments and returns the new message ID (call for each agent loop iteration)
func (*FileReadTracker) RecordRead ¶
func (t *FileReadTracker) RecordRead(path string, messageID int)
RecordRead records that a file was read
func (*FileReadTracker) WasReadRecently ¶
func (t *FileReadTracker) WasReadRecently(path string, currentMessageID, withinMessages int) bool
WasReadRecently checks if a file was read within the last N messages
type FuzzyMatcher ¶
type FuzzyMatcher struct {
Threshold float64 // Similarity threshold (0.0 to 1.0)
}
FuzzyMatcher provides fuzzy string matching capabilities
func NewFuzzyMatcher ¶
func NewFuzzyMatcher(threshold float64) *FuzzyMatcher
NewFuzzyMatcher creates a new FuzzyMatcher with the given threshold
func (*FuzzyMatcher) FindBestMatch ¶
func (fm *FuzzyMatcher) FindBestMatch(content, search string) (start, end int, ratio float64, matched string, found bool)
FindBestMatch finds the best matching substring in content for the search string Uses LINE-BASED matching like Aider for performance (O(lines²) instead of O(chars²)) Returns the start position, end position, similarity ratio, and the matched text
type GrepTool ¶
type GrepTool struct {
// contains filtered or unexported fields
}
func NewGrepTool ¶
func (*GrepTool) Description ¶
func (*GrepTool) JSONSchema ¶
type OutputBuffer ¶
type OutputBuffer struct {
// contains filtered or unexported fields
}
OutputBuffer manages shell command output with memory/file buffering and truncation
func NewOutputBuffer ¶
func NewOutputBuffer(tempFileMgr *TempFileManager) *OutputBuffer
NewOutputBuffer creates a new output buffer
func (*OutputBuffer) Close ¶
func (o *OutputBuffer) Close() error
Close cleans up resources (but doesn't delete temp file - that's session cleanup's job)
func (*OutputBuffer) FormatForLLM ¶
func (o *OutputBuffer) FormatForLLM() (string, error)
FormatForLLM returns the output formatted for LLM consumption - If output is small (< 150 lines and < 24KB), return all of it - Otherwise, save to temp file and return truncated output with file path Uses shared truncation utility for consistent behavior across all tools
type PatchAction ¶
type PatchAction string
PatchAction represents the type of file operation
const ( PatchAdd PatchAction = "Add" PatchUpdate PatchAction = "Update" PatchDelete PatchAction = "Delete" )
type PatchChunk ¶
type PatchChunk struct {
Scope string // Optional @@ scope marker
LineHint int // Optional line number hint for large files (from ":line N" in scope)
Context []string // Context lines (space prefix) - before the change
Deletions []string // Lines to remove (- prefix)
Additions []string // Lines to add (+ prefix)
PostContext []string // Context lines after the change
}
PatchChunk represents a single change within a file
type PatchEditTool ¶
type PatchEditTool struct {
BaseEditTool
}
PatchEditTool implements V4A-style patch editing
func NewPatchEditTool ¶
func NewPatchEditTool(cfg *config.Config, toolCtx *ToolContext) *PatchEditTool
NewPatchEditTool creates a new PatchEditTool
func (*PatchEditTool) Call ¶
func (t *PatchEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*PatchEditTool) Check ¶
func (t *PatchEditTool) Check(ctx context.Context, args json.RawMessage) error
func (*PatchEditTool) Description ¶
func (t *PatchEditTool) Description() string
func (*PatchEditTool) JSONSchema ¶
func (t *PatchEditTool) JSONSchema() map[string]any
func (*PatchEditTool) Name ¶
func (t *PatchEditTool) Name() string
func (*PatchEditTool) PromptCategory ¶
func (t *PatchEditTool) PromptCategory() string
func (*PatchEditTool) PromptOrder ¶
func (t *PatchEditTool) PromptOrder() int
func (*PatchEditTool) PromptSection ¶
func (t *PatchEditTool) PromptSection() string
func (*PatchEditTool) PromptTemplateName ¶
func (t *PatchEditTool) PromptTemplateName() string
type PendingEditState ¶
type PendingEditState struct {
HasPending bool // Whether there's an unresolved pending edit
PendingPath string // Path of the pending edit (empty if none)
LastPendingIdx int // Index of the last pending_confirmation message
BlockCountSincePending int // Number of BLOCKED messages since last pending_confirmation
}
PendingEditState represents the state of pending edits derived from message history
func AnalyzePendingEditState ¶
func AnalyzePendingEditState(messageRoles []string, messageContents []string, toolNames []string) PendingEditState
AnalyzePendingEditState scans message history to determine pending edit state. This is the source of truth - RAM state may be out of sync after history manipulation. messageRoles, messageContents, and toolNames should be parallel arrays from the message history. toolNames contains the tool name for tool messages (empty for non-tool messages).
type Plan ¶
type Plan struct {
TaskName string `json:"task"`
Status string `json:"status,omitempty"` // "in_progress" | "complete"
Steps []Step `json:"steps"`
}
Plan represents the active execution plan
type PlanAddStepTool ¶
type PlanAddStepTool struct {
// contains filtered or unexported fields
}
func NewPlanAddStepTool ¶
func NewPlanAddStepTool(manager *PlanManager) *PlanAddStepTool
func (*PlanAddStepTool) Call ¶
func (t *PlanAddStepTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*PlanAddStepTool) Check ¶
func (t *PlanAddStepTool) Check(ctx context.Context, args json.RawMessage) error
func (*PlanAddStepTool) Description ¶
func (t *PlanAddStepTool) Description() string
func (*PlanAddStepTool) JSONSchema ¶
func (t *PlanAddStepTool) JSONSchema() map[string]any
func (*PlanAddStepTool) Name ¶
func (t *PlanAddStepTool) Name() string
func (*PlanAddStepTool) PromptCategory ¶
func (t *PlanAddStepTool) PromptCategory() string
func (*PlanAddStepTool) PromptOrder ¶
func (t *PlanAddStepTool) PromptOrder() int
func (*PlanAddStepTool) PromptSection ¶
func (t *PlanAddStepTool) PromptSection() string
func (*PlanAddStepTool) PromptTemplateName ¶
func (t *PlanAddStepTool) PromptTemplateName() string
type PlanCompleteStepTool ¶
type PlanCompleteStepTool struct {
// contains filtered or unexported fields
}
func NewPlanCompleteStepTool ¶
func NewPlanCompleteStepTool(manager *PlanManager) *PlanCompleteStepTool
func (*PlanCompleteStepTool) Call ¶
func (t *PlanCompleteStepTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*PlanCompleteStepTool) Check ¶
func (t *PlanCompleteStepTool) Check(ctx context.Context, args json.RawMessage) error
func (*PlanCompleteStepTool) Description ¶
func (t *PlanCompleteStepTool) Description() string
func (*PlanCompleteStepTool) JSONSchema ¶
func (t *PlanCompleteStepTool) JSONSchema() map[string]any
func (*PlanCompleteStepTool) Name ¶
func (t *PlanCompleteStepTool) Name() string
func (*PlanCompleteStepTool) PromptCategory ¶
func (t *PlanCompleteStepTool) PromptCategory() string
func (*PlanCompleteStepTool) PromptOrder ¶
func (t *PlanCompleteStepTool) PromptOrder() int
func (*PlanCompleteStepTool) PromptSection ¶
func (t *PlanCompleteStepTool) PromptSection() string
func (*PlanCompleteStepTool) PromptTemplateName ¶
func (t *PlanCompleteStepTool) PromptTemplateName() string
type PlanCreateTool ¶
type PlanCreateTool struct {
// contains filtered or unexported fields
}
func NewPlanCreateTool ¶
func NewPlanCreateTool(manager *PlanManager) *PlanCreateTool
func (*PlanCreateTool) Call ¶
func (t *PlanCreateTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*PlanCreateTool) Check ¶
func (t *PlanCreateTool) Check(ctx context.Context, args json.RawMessage) error
func (*PlanCreateTool) Description ¶
func (t *PlanCreateTool) Description() string
func (*PlanCreateTool) JSONSchema ¶
func (t *PlanCreateTool) JSONSchema() map[string]any
func (*PlanCreateTool) Name ¶
func (t *PlanCreateTool) Name() string
func (*PlanCreateTool) PromptCategory ¶
func (t *PlanCreateTool) PromptCategory() string
func (*PlanCreateTool) PromptOrder ¶
func (t *PlanCreateTool) PromptOrder() int
func (*PlanCreateTool) PromptSection ¶
func (t *PlanCreateTool) PromptSection() string
func (*PlanCreateTool) PromptTemplateName ¶
func (t *PlanCreateTool) PromptTemplateName() string
type PlanManager ¶
type PlanManager struct {
// contains filtered or unexported fields
}
PlanManager manages the active plan
func (*PlanManager) ClearPlan ¶
func (pm *PlanManager) ClearPlan()
ClearPlan removes the active plan
func (*PlanManager) FormatActivePlan ¶
func (pm *PlanManager) FormatActivePlan() string
FormatActivePlan formats the plan in <active_plan> XML format
func (*PlanManager) GetActivePlan ¶
func (pm *PlanManager) GetActivePlan() *Plan
GetActivePlan returns the currently active plan (if any)
func (*PlanManager) GetActiveStepDescription ¶
func (pm *PlanManager) GetActiveStepDescription() string
GetActiveStepDescription returns the description of the active step
func (*PlanManager) IsComplete ¶
func (pm *PlanManager) IsComplete() bool
IsComplete returns true if the plan is complete
func (*PlanManager) SetPlan ¶
func (pm *PlanManager) SetPlan(plan *Plan)
SetPlan sets the active plan
type PlanMoveStepTool ¶
type PlanMoveStepTool struct {
// contains filtered or unexported fields
}
func NewPlanMoveStepTool ¶
func NewPlanMoveStepTool(manager *PlanManager) *PlanMoveStepTool
func (*PlanMoveStepTool) Call ¶
func (t *PlanMoveStepTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*PlanMoveStepTool) Check ¶
func (t *PlanMoveStepTool) Check(ctx context.Context, args json.RawMessage) error
func (*PlanMoveStepTool) Description ¶
func (t *PlanMoveStepTool) Description() string
func (*PlanMoveStepTool) JSONSchema ¶
func (t *PlanMoveStepTool) JSONSchema() map[string]any
func (*PlanMoveStepTool) Name ¶
func (t *PlanMoveStepTool) Name() string
func (*PlanMoveStepTool) PromptCategory ¶
func (t *PlanMoveStepTool) PromptCategory() string
func (*PlanMoveStepTool) PromptOrder ¶
func (t *PlanMoveStepTool) PromptOrder() int
func (*PlanMoveStepTool) PromptSection ¶
func (t *PlanMoveStepTool) PromptSection() string
func (*PlanMoveStepTool) PromptTemplateName ¶
func (t *PlanMoveStepTool) PromptTemplateName() string
type PlanRemoveStepTool ¶
type PlanRemoveStepTool struct {
// contains filtered or unexported fields
}
func NewPlanRemoveStepTool ¶
func NewPlanRemoveStepTool(manager *PlanManager) *PlanRemoveStepTool
func (*PlanRemoveStepTool) Call ¶
func (t *PlanRemoveStepTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*PlanRemoveStepTool) Check ¶
func (t *PlanRemoveStepTool) Check(ctx context.Context, args json.RawMessage) error
func (*PlanRemoveStepTool) Description ¶
func (t *PlanRemoveStepTool) Description() string
func (*PlanRemoveStepTool) JSONSchema ¶
func (t *PlanRemoveStepTool) JSONSchema() map[string]any
func (*PlanRemoveStepTool) Name ¶
func (t *PlanRemoveStepTool) Name() string
func (*PlanRemoveStepTool) PromptCategory ¶
func (t *PlanRemoveStepTool) PromptCategory() string
func (*PlanRemoveStepTool) PromptOrder ¶
func (t *PlanRemoveStepTool) PromptOrder() int
func (*PlanRemoveStepTool) PromptSection ¶
func (t *PlanRemoveStepTool) PromptSection() string
func (*PlanRemoveStepTool) PromptTemplateName ¶
func (t *PlanRemoveStepTool) PromptTemplateName() string
type ReadFileTool ¶
type ReadFileTool struct {
// contains filtered or unexported fields
}
ReadFileTool reads file contents with enhanced capabilities
func NewReadFileTool ¶
func NewReadFileTool(cfg *config.Config, toolCtx *ToolContext) *ReadFileTool
func (*ReadFileTool) Call ¶
func (t *ReadFileTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*ReadFileTool) Check ¶
func (t *ReadFileTool) Check(ctx context.Context, args json.RawMessage) error
func (*ReadFileTool) Description ¶
func (t *ReadFileTool) Description() string
func (*ReadFileTool) JSONSchema ¶
func (t *ReadFileTool) JSONSchema() map[string]any
func (*ReadFileTool) Name ¶
func (t *ReadFileTool) Name() string
func (*ReadFileTool) PromptCategory ¶
func (t *ReadFileTool) PromptCategory() string
func (*ReadFileTool) PromptOrder ¶
func (t *ReadFileTool) PromptOrder() int
func (*ReadFileTool) PromptSection ¶
func (t *ReadFileTool) PromptSection() string
func (*ReadFileTool) PromptTemplateName ¶
func (t *ReadFileTool) PromptTemplateName() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages enabled tools
func NewRegistry ¶
func NewRegistry() *Registry
func SetupRegistry ¶
func SetupRegistry(sc SetupConfig) *Registry
SetupRegistry creates and configures the tool registry based on config. It enables all tools according to the configuration and returns the populated registry.
func (*Registry) EnabledCategories ¶
EnabledCategories returns the list of categories that have enabled tools
func (*Registry) ExtractToolCallsFromText ¶
ExtractToolCallsFromText attempts to parse tool calls from text content This handles cases where LLM describes tool calls in XML-like format or JSON format
func (*Registry) GenerateToolPrompt ¶
GenerateToolPrompt returns complete tool documentation for system prompt
func (*Registry) LooksLikeMalformedToolCall ¶
LooksLikeMalformedToolCall checks if content appears to be a malformed tool call (e.g., when LLM outputs "read{\"path\": \"...\"}" as text instead of a proper tool call)
func (*Registry) PromptSections ¶
PromptSections returns documentation for all registered tools, grouped by category
func (*Registry) ToolsInCategory ¶
ToolsInCategory returns tools in a given category, sorted by PromptOrder
type RestoreFileTool ¶
type RestoreFileTool struct {
// contains filtered or unexported fields
}
RestoreFileTool restores a file to its original state at session start
func NewRestoreFileTool ¶
func NewRestoreFileTool(cfg *config.Config, mgr *checkpoint.Manager, toolCtx *ToolContext) *RestoreFileTool
func (*RestoreFileTool) Call ¶
func (t *RestoreFileTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*RestoreFileTool) Check ¶
func (t *RestoreFileTool) Check(ctx context.Context, args json.RawMessage) error
func (*RestoreFileTool) Description ¶
func (t *RestoreFileTool) Description() string
func (*RestoreFileTool) JSONSchema ¶
func (t *RestoreFileTool) JSONSchema() map[string]any
func (*RestoreFileTool) Name ¶
func (t *RestoreFileTool) Name() string
func (*RestoreFileTool) PromptCategory ¶
func (t *RestoreFileTool) PromptCategory() string
func (*RestoreFileTool) PromptOrder ¶
func (t *RestoreFileTool) PromptOrder() int
func (*RestoreFileTool) PromptSection ¶
func (t *RestoreFileTool) PromptSection() string
func (*RestoreFileTool) PromptTemplateName ¶
func (t *RestoreFileTool) PromptTemplateName() string
type SearchReplaceEditTool ¶
type SearchReplaceEditTool struct {
BaseEditTool
}
SearchReplaceEditTool implements content-based search and replace editing
func NewSearchReplaceEditTool ¶
func NewSearchReplaceEditTool(cfg *config.Config, toolCtx *ToolContext) *SearchReplaceEditTool
NewSearchReplaceEditTool creates a new SearchReplaceEditTool
func (*SearchReplaceEditTool) Call ¶
func (t *SearchReplaceEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*SearchReplaceEditTool) Check ¶
func (t *SearchReplaceEditTool) Check(ctx context.Context, args json.RawMessage) error
func (*SearchReplaceEditTool) Description ¶
func (t *SearchReplaceEditTool) Description() string
func (*SearchReplaceEditTool) JSONSchema ¶
func (t *SearchReplaceEditTool) JSONSchema() map[string]any
func (*SearchReplaceEditTool) Name ¶
func (t *SearchReplaceEditTool) Name() string
func (*SearchReplaceEditTool) PromptCategory ¶
func (t *SearchReplaceEditTool) PromptCategory() string
func (*SearchReplaceEditTool) PromptOrder ¶
func (t *SearchReplaceEditTool) PromptOrder() int
func (*SearchReplaceEditTool) PromptSection ¶
func (t *SearchReplaceEditTool) PromptSection() string
func (*SearchReplaceEditTool) PromptTemplateName ¶
func (t *SearchReplaceEditTool) PromptTemplateName() string
type SearchTool ¶
type SearchTool struct {
// contains filtered or unexported fields
}
SearchTool searches for code patterns and returns snippets with line numbers
func NewSearchTool ¶
func NewSearchTool(cfg *config.Config, tempFileMgr *TempFileManager) *SearchTool
func (*SearchTool) Call ¶
func (t *SearchTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*SearchTool) Check ¶
func (t *SearchTool) Check(ctx context.Context, args json.RawMessage) error
func (*SearchTool) Description ¶
func (t *SearchTool) Description() string
func (*SearchTool) JSONSchema ¶
func (t *SearchTool) JSONSchema() map[string]any
func (*SearchTool) Name ¶
func (t *SearchTool) Name() string
func (*SearchTool) PromptCategory ¶
func (t *SearchTool) PromptCategory() string
func (*SearchTool) PromptOrder ¶
func (t *SearchTool) PromptOrder() int
func (*SearchTool) PromptSection ¶
func (t *SearchTool) PromptSection() string
func (*SearchTool) PromptTemplateName ¶
func (t *SearchTool) PromptTemplateName() string
type SetupConfig ¶
type SetupConfig struct {
Cfg *config.Config
CheckpointMgr *checkpoint.Manager
ContextMgr *ctxtools.Manager
Logger DebugLogger // Optional debug logger (can be nil)
TempFileMgr *TempFileManager
PlanManager *PlanManager
ToolCtx *ToolContext // Shared mutable state for tools (created if nil)
}
SetupConfig contains all dependencies needed to set up the tool registry
type ShellAdvancedTool ¶
type ShellAdvancedTool struct {
// contains filtered or unexported fields
}
ShellAdvancedTool - full implementation with working_dir and timeout options
func NewShellAdvancedTool ¶
func NewShellAdvancedTool(cfg *config.Config, timeout time.Duration, tempFileMgr *TempFileManager) *ShellAdvancedTool
func (*ShellAdvancedTool) Call ¶
func (t *ShellAdvancedTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*ShellAdvancedTool) Check ¶
func (t *ShellAdvancedTool) Check(ctx context.Context, args json.RawMessage) error
Check performs validation for ShellAdvancedTool
func (*ShellAdvancedTool) Description ¶
func (t *ShellAdvancedTool) Description() string
func (*ShellAdvancedTool) JSONSchema ¶
func (t *ShellAdvancedTool) JSONSchema() map[string]any
func (*ShellAdvancedTool) Name ¶
func (t *ShellAdvancedTool) Name() string
func (*ShellAdvancedTool) PromptCategory ¶
func (t *ShellAdvancedTool) PromptCategory() string
func (*ShellAdvancedTool) PromptOrder ¶
func (t *ShellAdvancedTool) PromptOrder() int
func (*ShellAdvancedTool) PromptSection ¶
func (t *ShellAdvancedTool) PromptSection() string
func (*ShellAdvancedTool) PromptTemplateName ¶
func (t *ShellAdvancedTool) PromptTemplateName() string
type ShellTool ¶
type ShellTool struct {
// contains filtered or unexported fields
}
ShellTool - simple string-only interface, translates to Shell.advanced internally
func NewShellTool ¶
func (*ShellTool) Call ¶
Call executes command - delegates to Shell.advanced (ignores working_dir/timeout)
func (*ShellTool) Description ¶
func (*ShellTool) JSONSchema ¶
func (*ShellTool) PromptCategory ¶
func (*ShellTool) PromptOrder ¶
func (*ShellTool) PromptSection ¶
func (*ShellTool) PromptTemplateName ¶
type Step ¶
type Step struct {
Description string `json:"description"`
Status string `json:"status"` // "pending" | "active" | "complete"
}
Step represents a single step in the plan
type TasksAcceptDiffTool ¶
type TasksAcceptDiffTool struct {
// contains filtered or unexported fields
}
func NewTasksAcceptDiffTool ¶
func NewTasksAcceptDiffTool(manager *ctxtools.Manager) *TasksAcceptDiffTool
func (*TasksAcceptDiffTool) Call ¶
func (t *TasksAcceptDiffTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*TasksAcceptDiffTool) Check ¶
func (t *TasksAcceptDiffTool) Check(ctx context.Context, args json.RawMessage) error
func (*TasksAcceptDiffTool) Description ¶
func (t *TasksAcceptDiffTool) Description() string
func (*TasksAcceptDiffTool) JSONSchema ¶
func (t *TasksAcceptDiffTool) JSONSchema() map[string]any
func (*TasksAcceptDiffTool) Name ¶
func (t *TasksAcceptDiffTool) Name() string
func (*TasksAcceptDiffTool) PromptCategory ¶
func (t *TasksAcceptDiffTool) PromptCategory() string
func (*TasksAcceptDiffTool) PromptOrder ¶
func (t *TasksAcceptDiffTool) PromptOrder() int
func (*TasksAcceptDiffTool) PromptSection ¶
func (t *TasksAcceptDiffTool) PromptSection() string
func (*TasksAcceptDiffTool) PromptTemplateName ¶
func (t *TasksAcceptDiffTool) PromptTemplateName() string
type TasksDeclineDiffTool ¶
type TasksDeclineDiffTool struct {
// contains filtered or unexported fields
}
func NewTasksDeclineDiffTool ¶
func NewTasksDeclineDiffTool(manager *ctxtools.Manager) *TasksDeclineDiffTool
func (*TasksDeclineDiffTool) Call ¶
func (t *TasksDeclineDiffTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*TasksDeclineDiffTool) Check ¶
func (t *TasksDeclineDiffTool) Check(ctx context.Context, args json.RawMessage) error
func (*TasksDeclineDiffTool) Description ¶
func (t *TasksDeclineDiffTool) Description() string
func (*TasksDeclineDiffTool) JSONSchema ¶
func (t *TasksDeclineDiffTool) JSONSchema() map[string]any
func (*TasksDeclineDiffTool) Name ¶
func (t *TasksDeclineDiffTool) Name() string
func (*TasksDeclineDiffTool) PromptCategory ¶
func (t *TasksDeclineDiffTool) PromptCategory() string
func (*TasksDeclineDiffTool) PromptOrder ¶
func (t *TasksDeclineDiffTool) PromptOrder() int
func (*TasksDeclineDiffTool) PromptSection ¶
func (t *TasksDeclineDiffTool) PromptSection() string
func (*TasksDeclineDiffTool) PromptTemplateName ¶
func (t *TasksDeclineDiffTool) PromptTemplateName() string
type TasksFinishTool ¶
type TasksFinishTool struct {
// contains filtered or unexported fields
}
func NewTasksFinishTool ¶
func NewTasksFinishTool(manager *ctxtools.Manager) *TasksFinishTool
func (*TasksFinishTool) Call ¶
func (t *TasksFinishTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*TasksFinishTool) Check ¶
func (t *TasksFinishTool) Check(ctx context.Context, args json.RawMessage) error
func (*TasksFinishTool) Description ¶
func (t *TasksFinishTool) Description() string
func (*TasksFinishTool) JSONSchema ¶
func (t *TasksFinishTool) JSONSchema() map[string]any
func (*TasksFinishTool) Name ¶
func (t *TasksFinishTool) Name() string
func (*TasksFinishTool) PromptCategory ¶
func (t *TasksFinishTool) PromptCategory() string
func (*TasksFinishTool) PromptOrder ¶
func (t *TasksFinishTool) PromptOrder() int
func (*TasksFinishTool) PromptSection ¶
func (t *TasksFinishTool) PromptSection() string
func (*TasksFinishTool) PromptTemplateName ¶
func (t *TasksFinishTool) PromptTemplateName() string
type TasksRevertFileTool ¶
type TasksRevertFileTool struct {
// contains filtered or unexported fields
}
func NewTasksRevertFileTool ¶
func NewTasksRevertFileTool(manager *ctxtools.Manager) *TasksRevertFileTool
func (*TasksRevertFileTool) Call ¶
func (t *TasksRevertFileTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*TasksRevertFileTool) Check ¶
func (t *TasksRevertFileTool) Check(ctx context.Context, args json.RawMessage) error
func (*TasksRevertFileTool) Description ¶
func (t *TasksRevertFileTool) Description() string
func (*TasksRevertFileTool) JSONSchema ¶
func (t *TasksRevertFileTool) JSONSchema() map[string]any
func (*TasksRevertFileTool) Name ¶
func (t *TasksRevertFileTool) Name() string
func (*TasksRevertFileTool) PromptCategory ¶
func (t *TasksRevertFileTool) PromptCategory() string
func (*TasksRevertFileTool) PromptOrder ¶
func (t *TasksRevertFileTool) PromptOrder() int
func (*TasksRevertFileTool) PromptSection ¶
func (t *TasksRevertFileTool) PromptSection() string
func (*TasksRevertFileTool) PromptTemplateName ¶
func (t *TasksRevertFileTool) PromptTemplateName() string
type TasksRevertToTaskStartTool ¶
type TasksRevertToTaskStartTool struct {
// contains filtered or unexported fields
}
func NewTasksRevertToTaskStartTool ¶
func NewTasksRevertToTaskStartTool(manager *ctxtools.Manager) *TasksRevertToTaskStartTool
func (*TasksRevertToTaskStartTool) Call ¶
func (t *TasksRevertToTaskStartTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*TasksRevertToTaskStartTool) Check ¶
func (t *TasksRevertToTaskStartTool) Check(ctx context.Context, args json.RawMessage) error
func (*TasksRevertToTaskStartTool) Description ¶
func (t *TasksRevertToTaskStartTool) Description() string
func (*TasksRevertToTaskStartTool) JSONSchema ¶
func (t *TasksRevertToTaskStartTool) JSONSchema() map[string]any
func (*TasksRevertToTaskStartTool) Name ¶
func (t *TasksRevertToTaskStartTool) Name() string
func (*TasksRevertToTaskStartTool) PromptCategory ¶
func (t *TasksRevertToTaskStartTool) PromptCategory() string
func (*TasksRevertToTaskStartTool) PromptOrder ¶
func (t *TasksRevertToTaskStartTool) PromptOrder() int
func (*TasksRevertToTaskStartTool) PromptSection ¶
func (t *TasksRevertToTaskStartTool) PromptSection() string
func (*TasksRevertToTaskStartTool) PromptTemplateName ¶
func (t *TasksRevertToTaskStartTool) PromptTemplateName() string
type TasksStartTool ¶
type TasksStartTool struct {
// contains filtered or unexported fields
}
func NewTasksStartTool ¶
func NewTasksStartTool(manager *ctxtools.Manager) *TasksStartTool
func (*TasksStartTool) Call ¶
func (t *TasksStartTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*TasksStartTool) Check ¶
func (t *TasksStartTool) Check(ctx context.Context, args json.RawMessage) error
func (*TasksStartTool) Description ¶
func (t *TasksStartTool) Description() string
func (*TasksStartTool) JSONSchema ¶
func (t *TasksStartTool) JSONSchema() map[string]any
func (*TasksStartTool) Name ¶
func (t *TasksStartTool) Name() string
func (*TasksStartTool) PromptCategory ¶
func (t *TasksStartTool) PromptCategory() string
func (*TasksStartTool) PromptOrder ¶
func (t *TasksStartTool) PromptOrder() int
func (*TasksStartTool) PromptSection ¶
func (t *TasksStartTool) PromptSection() string
func (*TasksStartTool) PromptTemplateName ¶
func (t *TasksStartTool) PromptTemplateName() string
type TempFileManager ¶
type TempFileManager struct {
// contains filtered or unexported fields
}
TempFileManager tracks and manages temporary files created during the session
func NewTempFileManager ¶
func NewTempFileManager(workspaceRoot string) *TempFileManager
NewTempFileManager creates a new temp file manager in the workspace directory
func (*TempFileManager) CleanupAll ¶
func (m *TempFileManager) CleanupAll()
CleanupAll removes all tracked temp files (called at session end)
func (*TempFileManager) CreateTempFile ¶
func (m *TempFileManager) CreateTempFile() (*os.File, error)
CreateTempFile creates a new temporary file and tracks it for cleanup
type Tool ¶
type Tool interface {
// Name returns the tool identifier (e.g., "shell", "read")
Name() string
// Description returns a human-readable description for the LLM
Description() string
// JSONSchema returns the OpenAI-compatible function schema
JSONSchema() map[string]any
// Check performs validation and user confirmations before execution
// Returns error if the tool should not be executed
Check(ctx context.Context, args json.RawMessage) error
// Call executes the tool with the given arguments
// Check should be called before Call
Call(ctx context.Context, args json.RawMessage) (any, error)
// PromptSection returns detailed usage documentation for the system prompt.
// Returns empty string if no additional documentation is needed.
// Deprecated: Use PromptTemplateName() with the template system instead.
PromptSection() string
// PromptCategory returns the category for grouping in the system prompt.
// Valid categories: "filesystem", "shell", "plan", "checkpoint"
PromptCategory() string
// PromptOrder returns the sort order within the category (lower numbers first).
// This ensures deterministic ordering for prompt caching.
PromptOrder() int
// PromptTemplateName returns the name of the template file for this tool's
// system prompt documentation. Returns empty string to use PromptSection() instead.
// Template files are located in prompts/tools/<name>.tmpl
PromptTemplateName() string
}
Tool is the interface all agent tools must implement
type ToolContext ¶
type ToolContext struct {
ReadTracker *FileReadTracker
// contains filtered or unexported fields
}
ToolContext holds shared mutable state for all tools in a session. This replaces the global variables (globalReadTracker, globalPendingEdit, globalPendingWrite) and enables proper testing and concurrent session isolation.
func NewToolContext ¶
func NewToolContext() *ToolContext
NewToolContext creates a new ToolContext with initialized state.
func (*ToolContext) ClearPendingEdit ¶
func (tc *ToolContext) ClearPendingEdit()
ClearPendingEdit clears any pending edit.
func (*ToolContext) ClearPendingEditIfPath ¶
func (tc *ToolContext) ClearPendingEditIfPath(path string)
ClearPendingEditIfPath clears pending edit only if it matches the given path.
func (*ToolContext) GetAndClearPendingEdit ¶
func (tc *ToolContext) GetAndClearPendingEdit() *pendingEdit
GetAndClearPendingEdit returns and clears the pending edit.
func (*ToolContext) GetAndClearPendingWrite ¶
func (tc *ToolContext) GetAndClearPendingWrite() *pendingWrite
GetAndClearPendingWrite returns and clears the pending write.
func (*ToolContext) GetPendingEdit ¶
func (tc *ToolContext) GetPendingEdit() *pendingEdit
GetPendingEdit returns the current pending edit without clearing it.
func (*ToolContext) GetPendingEditDiff ¶
func (tc *ToolContext) GetPendingEditDiff() string
GetPendingEditDiff returns the diff of the pending edit, or empty if none.
func (*ToolContext) GetPendingEditPath ¶
func (tc *ToolContext) GetPendingEditPath() string
GetPendingEditPath returns the path of the pending edit, or empty if none.
func (*ToolContext) GetPendingWritePath ¶
func (tc *ToolContext) GetPendingWritePath() string
GetPendingWritePath returns the path of the pending write, or empty if none.
func (*ToolContext) HasPendingEdit ¶
func (tc *ToolContext) HasPendingEdit() bool
HasPendingEdit returns true if there's a pending edit.
func (*ToolContext) SetPendingEdit ¶
func (tc *ToolContext) SetPendingEdit(p *pendingEdit)
SetPendingEdit stores a pending edit operation.
func (*ToolContext) SetPendingWrite ¶
func (tc *ToolContext) SetPendingWrite(p *pendingWrite)
SetPendingWrite stores a pending write operation.
type ToolError ¶
type ToolError struct {
Type ToolErrorType
Message string
Details map[string]any // Optional structured data for LLM
}
ToolError is an error type that classifies errors as runtime or semantic
func CheckPendingEditBlockWithConfig ¶
func CheckPendingEditBlockWithConfig(toolName string, args json.RawMessage, blockCount int, cfg *config.Config, toolCtx *ToolContext) *ToolError
CheckPendingEditBlockWithConfig is the legacy version that uses RAM state. Deprecated: Use CheckPendingEditBlockWithState with history-derived state instead.
func CheckPendingEditBlockWithState ¶
func CheckPendingEditBlockWithState(toolName string, state PendingEditState, cfg *config.Config, toolCtx *ToolContext) *ToolError
CheckPendingEditBlockWithState checks if a tool call should be blocked due to pending edit. Uses history-derived state as the source of truth for whether a pending edit exists. The toolCtx is used for the diff content in error messages.
func RuntimeError ¶
RuntimeError creates a runtime error (not backtrackable) Use for: file system errors, network errors, external failures
func RuntimeErrorWithDetails ¶
RuntimeErrorWithDetails creates a runtime error with structured details
func RuntimeErrorf ¶
RuntimeErrorf creates a formatted runtime error
func SemanticError ¶
SemanticError creates a semantic error (backtrackable) Use for: LLM misuse, wrong tool sequence, invalid state, unknown tools
func SemanticErrorWithDetails ¶
SemanticErrorWithDetails creates a semantic error with structured details
func SemanticErrorf ¶
SemanticErrorf creates a formatted semantic error
func WrapAsRuntime ¶
WrapAsRuntime wraps any error as a runtime error
func WrapAsSemantic ¶
WrapAsSemantic wraps any error as a semantic error
type ToolErrorType ¶
type ToolErrorType int
ToolErrorType classifies tool errors for backtracking decisions
const ( // ToolErrorRuntime - Tool executed but failed (file not found, network error, etc.) // NOT backtrackable - error goes to history, LLM should see and handle it ToolErrorRuntime ToolErrorType = iota // ToolErrorSemantic - LLM misused the tool (wrong sequence, invalid state, etc.) // Backtrackable - discard and retry, LLM should have known better from prompt ToolErrorSemantic )
type TruncationResult ¶
type TruncationResult struct {
Content string // Full content if not truncated, formatted if truncated
WasTruncated bool // Whether content was truncated
TotalLines int // Total lines in original
TotalBytes int // Total bytes in original
}
TruncationResult contains the truncation outcome
func TruncateContent ¶
func TruncateContent(content []byte, maxLines, maxBytes, truncatedLines, truncatedBytes int) TruncationResult
TruncateContent truncates content to show first and last portions if it exceeds limits If content is within limits, returns it as-is Otherwise, shows first N and last N lines/bytes with truncation marker
type UnifiedEditTool ¶
type UnifiedEditTool struct {
BaseEditTool
}
UnifiedEditTool implements all edit modes with a shared flow
func NewUnifiedEditTool ¶
func NewUnifiedEditTool(cfg *config.Config, toolCtx *ToolContext) *UnifiedEditTool
NewUnifiedEditTool creates a new UnifiedEditTool
func (*UnifiedEditTool) Call ¶
func (t *UnifiedEditTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*UnifiedEditTool) Check ¶
func (t *UnifiedEditTool) Check(ctx context.Context, args json.RawMessage) error
func (*UnifiedEditTool) Description ¶
func (t *UnifiedEditTool) Description() string
func (*UnifiedEditTool) JSONSchema ¶
func (t *UnifiedEditTool) JSONSchema() map[string]any
func (*UnifiedEditTool) Name ¶
func (t *UnifiedEditTool) Name() string
func (*UnifiedEditTool) PromptCategory ¶
func (t *UnifiedEditTool) PromptCategory() string
func (*UnifiedEditTool) PromptOrder ¶
func (t *UnifiedEditTool) PromptOrder() int
func (*UnifiedEditTool) PromptSection ¶
func (t *UnifiedEditTool) PromptSection() string
func (*UnifiedEditTool) PromptTemplateName ¶
func (t *UnifiedEditTool) PromptTemplateName() string
type WriteFileTool ¶
type WriteFileTool struct {
// contains filtered or unexported fields
}
WriteFileTool writes entire content to a file (creates or overwrites)
func NewWriteFileTool ¶
func NewWriteFileTool(cfg *config.Config, toolCtx *ToolContext) *WriteFileTool
func (*WriteFileTool) Call ¶
func (t *WriteFileTool) Call(ctx context.Context, args json.RawMessage) (any, error)
func (*WriteFileTool) Check ¶
func (t *WriteFileTool) Check(ctx context.Context, args json.RawMessage) error
func (*WriteFileTool) Description ¶
func (t *WriteFileTool) Description() string
func (*WriteFileTool) JSONSchema ¶
func (t *WriteFileTool) JSONSchema() map[string]any
func (*WriteFileTool) Name ¶
func (t *WriteFileTool) Name() string
func (*WriteFileTool) PromptCategory ¶
func (t *WriteFileTool) PromptCategory() string
func (*WriteFileTool) PromptOrder ¶
func (t *WriteFileTool) PromptOrder() int
func (*WriteFileTool) PromptSection ¶
func (t *WriteFileTool) PromptSection() string
func (*WriteFileTool) PromptTemplateName ¶
func (t *WriteFileTool) PromptTemplateName() string
Source Files
¶
- argument_normalizer.go
- checkpoint.go
- context.go
- context_tools.go
- edit.go
- edit_apply_line.go
- edit_common.go
- edit_fuzzy.go
- edit_line.go
- edit_patch.go
- edit_searchreplace.go
- errors.go
- filesystem.go
- output_buffer.go
- output_utils.go
- path_utils.go
- plan.go
- registry.go
- restore_file.go
- search.go
- search_tool.go
- setup.go
- shell.go
- tempfile_manager.go
- tool.go
- toolcall_normalizer.go