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 ¶
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 ¶
NewEditor creates an Editor bound to the given sandbox root directory.
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 ¶
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 ¶
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 ¶
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.
Source Files
¶
- editfile.go
- tool.go