Repository navigation
Filesystem API
All filesystem operations are sandboxed to the project root. Attempting to access files outside the project directory returns nil or an error.
Returns true if the file or directory exists within the project root.
if api:file_exists("src/main.rs") then
-- file exists
endReturns true if the path is a regular file (not a directory).
Reads file contents. Returns (content, nil) on success or (nil, error_message) on failure.
local content, err = api:read_file("config.toml")
if content then
api:log("File has " .. #content .. " bytes")
else
api:log("Error: " .. err)
endLists a single directory (non-recursive). Returns an array of entries or nil.
Each entry is a table: { name = "filename", is_dir = true/false }.
local entries = api:list_dir("src")
if entries then
for _, e in ipairs(entries) do
api:log(e.name .. (e.is_dir and " (dir)" or ""))
end
endRecursively scans a directory. max_depth is optional (default: 5, maximum: 10).
Returns an array of entries: { name = "filename", rel_path = "relative/path", is_dir = true/false }.
local files = api:scan_dir("src", 3)All write operations return (true, "") on success or (false, error_message) on failure.
Creates a new empty file. Fails if the file already exists.
Creates a directory and all parent directories.
Writes content to a file (creates or overwrites). Creates parent directories if needed.
local ok, err = api:write_file("output/result.txt", "Hello!")
if not ok then
api:log("Write failed: " .. err)
endRenames or moves a file/directory. Both paths must be within the project root.
Removes a file or directory (recursive). Use with caution.
Returns a table mapping relative file paths to git status codes, or nil if not a git repository.
Status codes: "M" (modified), "A" (added), "??" (untracked), "!!" (ignored), "D" (deleted), "R" (renamed), "U" (conflict).
local status = api:git_status(".")
if status then
for file, code in pairs(status) do
if code == "M" then
api:log("Modified: " .. file)
end
end
endComputes a line-aligned diff between two strings. Returns a table with:
-
left_content— aligned left text (with filler lines for insertions) -
right_content— aligned right text (with filler lines for deletions) -
left_highlights— array of highlight info for removed/modified lines -
right_highlights— array of highlight info for added/modified lines
This is used internally by the Git Diff plugin to populate split views.
- Relative paths are resolved against the project root
- Absolute paths are allowed only if they fall within the project root
-
Path traversal (
../../etc/passwd) is blocked —..is canonicalized and verified - Symlinks are resolved to their real path before validation