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

kdeps-tools-edit_file

v2.0.0

Edit one line of an existing file. Give file_path, the line to change (line, 1-based) or words that are on it (match), and either:

set tools / shelf tools

LLM context: ~315 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/edit_file
  3. the model calls a tool
  4. kdeps runs it
  5. the result goes back to the model

Loaded by: kdeps (agent loop), /update, /settings, kdeps run, kdeps install, kdeps list, kdeps uninstall, kdeps update

In the code: kdeps (agent loop)agent.RegisterBuiltinToolsagent.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/edit_file

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

Contents

Edit one line of an existing file. Give file_path, the line to change (line, 1-based) or words that are on it (match), and either: - text: the replacement. With match, only those words are replaced on the line; without match, the whole line is replaced. text may span several lines. - append: text inserted after the line (after the end of the file when neither line nor match is given). Use read_file first to get line numbers. To create a file or rewrite a whole file, use write_file.

category
code
constraints
give exactly one of text or append; the file must exist; with both line and match, the line must contain match
outputFormat
the edited line number and the line(s) as they now read
seeAlso
read_file, write_file
ParameterTypeDescription
file_path *stringAbsolute path of the file to edit
lineinteger1-based line to edit (or to append after)
matchstringWords on the line to edit. Without line, the first line containing them is used. With text, only these words are replaced.
textstringReplacement for the line, or for match on the line
appendstringText inserted after the line, or after the end of the file when neither line nor match is given

Python script (declared in YAML, no Go code)

import json, sys

a = json.loads(sys.argv[1])
path = a["file_path"]
# A component posts every input; an empty one counts as not given.
line = int(str(a.get("line") or 0) or 0)
match = a.get("match") or ""
text = a.get("text") or None
append = a.get("append") or None
if (text is None) == (append is None):
    sys.exit("edit_file: give exactly one of text or append")

with open(path, encoding="utf-8", newline="") as f:
    content = f.read()
lines = content.split("\n")
if lines and lines[-1] == "":
    lines.pop()
    trailing_newline = True
else:
    trailing_newline = False

target = None
if line:
    if line < 1 or line > len(lines):
        sys.exit("edit_file: line %d is outside 1-%d" % (line, len(lines)))
    target = line - 1
    if match and match not in lines[target]:
        sys.exit("edit_file: line %d does not contain %r" % (line, match))
elif match:
    target = next((i for i, l in enumerate(lines) if match in l), None)
    if target is None:
        sys.exit("edit_file: no line contains %r" % match)

if append is not None:
    at = len(lines) if target is None else target + 1
    added = append.split("\n")
    lines[at:at] = added
    shown = (at + 1, at + len(added))
else:
    if target is None:
        sys.exit("edit_file: replacing needs line or match")
    new = lines[target].replace(match, text, 1) if match else text
    new_lines = new.split("\n")
    lines[target:target + 1] = new_lines
    shown = (target + 1, target + len(new_lines))

out = "\n".join(lines) + ("\n" if trailing_newline else "")
with open(path, "w", encoding="utf-8", newline="") as f:
    f.write(out)
first, last = shown
print("edited %s at line %d:" % (path, first))
for n in range(first, last + 1):
    print("%6d\t%s" % (n, lines[n - 1]))

Paths kept in the workspace: file_path

aliases:
  - edit
  - str_replace_editor
  - str_replace_based_edit_tool
  - replace_in_file
  - edit_text_file

Versions

VersionPublishedStatus
2.0.010/23/2026active
1.1.010/17/2026active
1.0.010/11/2026active

Details

Author
kdeps
License
Apache-2.0
Latest Version
2.0.0
Published
10/11/2026

Tags

kdepstool