Alphakdeps.io is experimental and evolving — the registry and packages may change or reset.
Toolkdeps asset

kdeps-tools-read_file

v2.0.1

Read a file from the local filesystem. Returns the contents with a 1-based line number on every line (` 42\tcode$`) - use those numbers for edit_file insert/view. Tabs render as ^I, other control characters as ^X, and a $ marks the true end of each line, so indentation, trailing whitespace, and stray control characters are visible instead of hidden. IMPORTANT: ^I, ^X, and the trailing $ are a display convention this tool adds - the real file does NOT contain those literal characters. When quoting text back into edit_file's old_str, write the real tab/control character (or match a whole line via view_range/anchor instead), never the literal caret sequence - copying "^I" as text will not match a real tab byte. Plain text, source code, configuration files, and documentation are read directly. For PDF, DOCX, EPUB, RTF, and ODT documents, CSV/HTML structured parsing, or RAG chunking, use load_document. Pass match_id (from a search_local result) instead of file_path/offset to jump straight to that hit.

set tools / shelf tools

LLM context: ~592 tokens when loaded (prompt or tool definition)

Where it runs

Part of the tools set, used in workflow and agent mode. What the model is told about each built-in tool: its description, usage notes and parameters. kdeps runs the tool itself.

  1. the agent loop builds the request
  2. the tool definitions are sent to the modeltools/read_file
  3. the model calls a tool
  4. kdeps runs it
  5. the result goes back to the model

Loaded by: kdeps (agent loop), kdeps new, kdeps run, kdeps install, kdeps list, kdeps uninstall, kdeps update, kdeps upgrade

In the code: kdeps (agent loop)executor.(*Engine).Executeparallel.Runjudge.Panelagent.runJudgePanelagent.definedAs

Install

A kdeps asset: installed with the first-run profile that includes its set, or the first time a command needs it, and updated without a new release.

kdeps install tools/read_file

Pin a version with kdeps install tools/read_file@<version>.

Contents

Read a file from the local filesystem. Returns the contents with a 1-based line number on every line (` 42\tcode$`) - use those numbers for edit_file insert/view. Tabs render as ^I, other control characters as ^X, and a $ marks the true end of each line, so indentation, trailing whitespace, and stray control characters are visible instead of hidden. IMPORTANT: ^I, ^X, and the trailing $ are a display convention this tool adds - the real file does NOT contain those literal characters. When quoting text back into edit_file's old_str, write the real tab/control character (or match a whole line via view_range/anchor instead), never the literal caret sequence - copying "^I" as text will not match a real tab byte. Plain text, source code, configuration files, and documentation are read directly. For PDF, DOCX, EPUB, RTF, and ODT documents, CSV/HTML structured parsing, or RAG chunking, use load_document. Pass match_id (from a search_local result) instead of file_path/offset to jump straight to that hit.

category
file
seeAlso
list_files, search_local, edit_file, load_document
ParameterTypeDescription
context_afternumberOnly with match_id: lines of context after the match (default 20)
context_beforenumberOnly with match_id: lines of context before the match (default 20)
file_pathstringAbsolute path to the file to read. Omit to re-read the file most recently accessed this session (e.g. to read more of it with offset/limit), or use match_id instead.
limitnumberMaximum number of lines to read. Optional; reads entire file up to the size limit if omitted.
match_idstringA match_id from a search_local result, instead of file_path. Reads the region around that hit (context_before/context_after lines, default 20 each).
offsetnumberLine number to start reading from (1-based). Optional; reads from beginning if omitted.

Python script (declared in YAML, no Go code)

import json, os, sys

a = json.loads(sys.argv[1])
path = (a.get("file_path") or "").strip()
if not path:
    sys.exit("read_file: file_path is required")
path = os.path.abspath(path)
if os.path.isdir(path):
    sys.exit("read_file: %s is a directory" % path)
if os.path.splitext(path)[1].lower() in (".pdf", ".docx", ".epub", ".rtf", ".odt"):
    sys.exit("read_file: %s is a document; use load_document to extract its text" % path)

def number(v):
    try:
        n = int(float(v))
    except (TypeError, ValueError):
        return 0
    return n if n > 0 else 0

offset, limit = number(a.get("offset")), number(a.get("limit"))
try:
    size = os.path.getsize(path)
    # max_bytes comes from the file-read-limit event in an agent session.
    cap = int(a.get("max_bytes") or 0) or 1048576
    if size > cap and not (offset or limit):
        sys.exit("read_file: %s is %d bytes (max %d); pass offset/limit to read part of it" % (path, size, cap))
    with open(path, "rb") as f:
        head = f.read(512)
        if b"\0" in head:
            sys.exit("read_file: %s appears to be a binary file" % path)
        f.seek(0)
        if size <= cap:
            data = f.read()
        else:
            # A file over the cap streams: only the offset/limit window is
            # kept, and that window itself stays under the cap.
            first = offset - 1 if offset else 0
            kept, used, total = [], 0, 0
            for raw in f:
                if total >= first and (not limit or len(kept) < limit):
                    used += len(raw)
                    if used > cap:
                        sys.exit("read_file: lines %d-%d of %s exceed %d bytes; use a smaller limit" % (first + 1, total + 1, path, cap))
                    kept.append(raw)
                total += 1
            data = None
except OSError as e:
    sys.exit("read_file: %s: %s" % (path, e.strerror or e))

def visible(line):
    # cat -A: a tab is ^I, other C0 controls and DEL are caret notation.
    out = []
    for ch in line:
        o = ord(ch)
        if ch == "\t":
            out.append("^I")
        elif o == 0x7F:
            out.append("^?")
        elif o < 0x20:
            out.append("^" + chr(o + 64))
        else:
            out.append(ch)
    return "".join(out)

if data is None:
    shown = [r.decode("utf-8", "replace").rstrip("\n") for r in kept]
    start = min(first, total)
    end = start + len(shown)
else:
    lines = data.decode("utf-8", "replace").split("\n")
    if lines and lines[-1] == "":
        lines.pop()
    total = len(lines)
    start, end = 0, total
    if offset:
        start = min(offset - 1, total)
    if limit:
        end = min(start + limit, total)
    shown = lines[start:end]
width = len(str(start + len(shown)))
for i, line in enumerate(shown):
    print("%*d\t%s$" % (width, start + i + 1, visible(line)))
if 0 < end - start < total:
    print("[%d/%d lines shown]" % (end - start, total))

Paths kept in the workspace: file_path

aliases:
  - read
  - cat
  - view_file
  - open_file
  - read_text_file
constraints: max ~2000 lines per read; use offset/limit for large files; must
  use absolute path; do not re-read a file already in this conversation unless
  it changed; binary files and PDF/DOCX/EPUB/RTF/ODT documents are refused (use
  load_document)
outputFormat: text with a 1-based line number on each line; tabs shown as ^I,
  control chars as ^X, $ marks true end of line (display only - not literal file
  content)

Versions

VersionPublishedStatusSource
1.0.011/21/2026activeGitHub v1.0.0
1.1.011/21/2026activeGitHub v1.1.0
2.0.011/21/2026activeGitHub v2.0.0
2.0.111/21/2026activeGitHub v2.0.1

Details

Author
kdeps
License
Apache-2.0
Latest Version
2.0.1
Published
11/21/2026

Tags

kdepstool