read_file (files.py)

agent-zero · files

Reads file, "retrieval"

from fnmatch import fnmatch
import os, re

import re

def read_file(relative_path, backup_dirs=None, encoding="utf-8", **kwargs):
    if backup_dirs is None:
        backup_dirs = []

    # Try to get the absolute path for the file from the original directory or backup directories
    absolute_path = find_file_in_dirs(relative_path, backup_dirs)

    # Read the file content
    with open(absolute_path, 'r', encoding=encoding) as f:
        content = remove_code_fences(f.read())

    # Replace placeholders with values from kwargs
    for key, value in kwargs.items():
        placeholder = "{{" + key + "}}"
        strval = str(value)
        content = content.replace(placeholder, strval)

    # Process include statements
    content = process_includes(content, os.path.dirname(relative_path)

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key