editfile

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package editfile implements the jungi built-in edit_file tool commands.

It handles view, create, str_replace, and insert operations on files within a sandboxed root directory. All paths are validated to prevent directory traversal outside the sandbox boundary.

The Editor tracks file modification times from view operations. When a str_replace or insert is attempted, it checks whether the file has been modified since the model last viewed it, rejecting stale edits early.

Index

Constants

View Source
const ToolName = "edit_file"

ToolName is the value the model uses to invoke this tool in tool_use blocks. Single string constant so toolexec and the editor can agree without circular imports.

Variables

This section is empty.

Functions

func ToolDef

func ToolDef() tooldef.Definition

ToolDef returns the jungi tool definition for the edit_file tool. It is registered on every Executor as a built-in alongside run_shell and run_unsafe_shell.

Types

type Editor

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

Editor executes text editor commands and tracks file view timestamps to detect when files have been modified externally between view and edit.

func NewEditor

func NewEditor(rootDir string) *Editor

NewEditor creates an Editor bound to the given sandbox root directory.

func (*Editor) Execute

func (e *Editor) Execute(input Input) Result

Execute runs a text editor command.

type Input

type Input struct {
	Command    string `json:"command"`
	Path       string `json:"path"`
	OldStr     string `json:"old_str"`
	NewStr     string `json:"new_str"`
	FileText   string `json:"file_text"`
	InsertLine *int   `json:"insert_line"`
	InsertText string `json:"insert_text"`
	ViewRange  []int  `json:"view_range"`
}

Input represents the JSON payload the model sends for the texteditor tool.

type Result

type Result struct {
	Output  string
	IsError bool
}

Result holds the output of a text editor command execution.

type Tool

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

Tool implements tool.Tool for the edit_file tool. It owns the underlying Editor (file operations within the sandbox root) and an accessor for the session's LSP manager so it can notify language servers after a write.

func NewTool

func NewTool(rootDir string, lsp func() *corelsp.Manager) *Tool

NewTool returns an edit_file Tool rooted at rootDir. lsp is the lazy accessor for the session's LSP manager (see Tool.lsp); pass nil when no language server should be notified.

func (*Tool) Definition

func (*Tool) Definition() tooldef.Definition

Definition delegates to the package-level ToolDef so the advertised definition stays identical whether or not a Tool has been constructed.

func (*Tool) Execute

func (t *Tool) Execute(ctx context.Context, req message.ToolUseRequest) tool.Result

Execute parses the editor command, runs it against the sandboxed Editor, and — on a successful write — notifies the LSP so diagnostics stay current. The model receives the raw editor output; the TUI receives a colored diff (or truncated view) via Display.

func (*Tool) Preview added in v0.2.1

func (*Tool) Preview(req message.ToolUseRequest) (string, string)

Preview returns the editor command and path (with an insert-line suffix) from the raw request so the start history line matches completion.

Source Files

  • editfile.go
  • tool.go

Jump to

Keyboard shortcuts

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