main
 1# frozen_string_literal: true
 2
 3Elelem::Plugins.register(:edit) do |agent|
 4  agent.toolbox.add("edit",
 5    description: "Replace first occurrence of text in file",
 6    params: { path: { type: "string" }, old: { type: "string" }, new: { type: "string" } },
 7    required: ["path", "old", "new"]
 8  ) do |a|
 9    path = Pathname.new(a["path"]).expand_path
10    content = path.read
11    agent.toolbox
12      .run("write", { "path" => a["path"], "content" => content.sub(a["old"], a["new"]) })
13      .merge(replaced: a["old"], with: a["new"])
14  end
15end