Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

File I/O Tool

Provides file read, write, and listing capabilities with path traversal protection.

Details

IDnexus.tool.file
Tool Namesread_file, write_file, list_files
DependenciesNone

Configuration

KeyTypeDefaultDescription
base_dirstring(session files dir)Root directory for file operations. All paths are resolved relative to this.
allow_external_writesboolfalseWhen false, write_file always writes to the session files directory regardless of base_dir. When true, write_file can write anywhere within base_dir.

Tools

read_file

ParameterTypeRequiredDescription
pathstringYesPath to the file to read
offsetnumberNoByte offset to start reading from (default 0)
lengthnumberNoMaximum bytes to read (default 4096)

Reads up to length bytes starting at offset. Returns a JSON object with content, bytes_read, offset, and total_size so callers can page through files larger than the chunk size.

write_file

ParameterTypeRequiredDescription
pathstringYesPath to write to
contentstringYesContent to write

Creates or overwrites the file. Emits session.file.created or session.file.updated.

list_files

ParameterTypeRequiredDescription
pathstringYesDirectory to list
patternstringNoGlob pattern to filter results

Returns a listing with file names and sizes.

Events

Subscribes To

EventPriorityPurpose
tool.invoke50Handles file operations

Emits

EventWhen
tool.resultOperation result
tool.registerRegisters all three tools at boot
core.errorFile operation errors
session.file.createdNew file written
session.file.updatedExisting file overwritten

Security

All paths are resolved relative to base_dir. Path traversal attempts (e.g., ../../etc/passwd) are blocked.

By default, write_file is restricted to the session files directory even when a custom base_dir is configured. This prevents the agent from modifying files in the working directory unless explicitly opted in via allow_external_writes: true.

Example Configuration

# Use session files directory (default)
nexus.tool.file: {}

# Use a specific directory (reads from workspace, writes to session files)
nexus.tool.file:
  base_dir: /home/user/workspace

# Allow writes to the workspace directory
nexus.tool.file:
  base_dir: /home/user/workspace
  allow_external_writes: true