Commit ee54490
Changed files (11)
lib/elelem/tools/edit.rb
@@ -3,15 +3,14 @@
Elelem.configure do |config|
config.setup(:edit) do |agent|
agent.toolbox.add("edit",
- description: "Replace first occurrence of text in file",
- params: { path: { type: "string" }, old: { type: "string" }, new: { type: "string" } },
- required: ["path", "old", "new"]
- ) do |args|
+ description: "Replace first occurrence of text in file",
+ params: { path: { type: "string" }, old: { type: "string" }, new: { type: "string" } },
+ required: %w[path old new]) do |args|
path = Pathname.new(args["path"]).expand_path
content = path.read
agent.toolbox
- .run("write", { "path" => args["path"], "content" => content.sub(args["old"], args["new"]) })
- .merge(replaced: args["old"], with: args["new"])
+ .run("write", { "path" => args["path"], "content" => content.sub(args["old"], args["new"]) })
+ .merge(replaced: args["old"], with: args["new"])
end
end
end
lib/elelem/tools/eval.rb
@@ -12,11 +12,10 @@ Elelem.configure do |config|
DESC
agent.toolbox.add("eval",
- description: description,
- params: { ruby: { type: "string" } },
- required: ["ruby"]
- ) do |args|
- { result: binding.eval(args["ruby"]) }
+ description: description,
+ params: { ruby: { type: "string" } },
+ required: ["ruby"]) do |args|
+ { result: binding.eval(args["ruby"]) } # rubocop:disable Security/Eval
end
end
end
lib/elelem/tools/git.rb
@@ -3,10 +3,9 @@
Elelem.configure do |config|
config.setup(:git) do |agent|
agent.toolbox.add("git",
- description: "Run git command",
- params: { command: { type: "string" }, args: { type: "array", items: { type: "string" } } },
- required: ["command"]
- ) do |args|
+ description: "Run git command",
+ params: { command: { type: "string" }, args: { type: "array", items: { type: "string" } } },
+ required: ["command"]) do |args|
Elelem::Tools.exec(agent.toolbox, "git", args["command"], *(args["args"] || []))
end
lib/elelem/tools/glob.rb
@@ -3,10 +3,9 @@
Elelem.configure do |config|
config.setup(:glob) do |agent|
agent.toolbox.add("glob",
- description: "Find files matching pattern",
- params: { pattern: { type: "string" }, path: { type: "string" } },
- required: ["pattern"]
- ) do |args|
+ description: "Find files matching pattern",
+ params: { pattern: { type: "string" }, path: { type: "string" } },
+ required: ["pattern"]) do |args|
path = args["path"].to_s.empty? ? "." : args["path"]
result = Elelem::Tools.exec(agent.toolbox, "fd", "--glob", args["pattern"], path)
result[:ok] ? result : Elelem::Tools.exec(agent.toolbox, "find", path, "-name", args["pattern"])
lib/elelem/tools/grep.rb
@@ -3,10 +3,9 @@
Elelem.configure do |config|
config.setup(:grep) do |agent|
agent.toolbox.add("grep",
- description: "Search file contents",
- params: { pattern: { type: "string" }, path: { type: "string" }, glob: { type: "string" } },
- required: ["pattern"]
- ) do |args|
+ description: "Search file contents",
+ params: { pattern: { type: "string" }, path: { type: "string" }, glob: { type: "string" } },
+ required: ["pattern"]) do |args|
path = args["path"].to_s.empty? ? "." : args["path"]
glob = args["glob"]
lib/elelem/tools/interview.rb
@@ -3,12 +3,11 @@
Elelem.configure do |config|
config.setup(:interview) do |agent|
agent.toolbox.add("interview",
- description: "Ask the user a question and wait for their response",
- params: {
- question: { type: "string", description: "The question to ask the user" },
- },
- required: ["question"]
- ) do |args|
+ description: "Ask the user a question and wait for their response",
+ params: {
+ question: { type: "string", description: "The question to ask the user" }
+ },
+ required: ["question"]) do |args|
agent.output.say(args["question"], as: :markdown)
{ answer: agent.input.ask("> ") }
end
lib/elelem/tools/list.rb
@@ -3,11 +3,10 @@
Elelem.configure do |config|
config.setup(:list) do |agent|
agent.toolbox.add("list",
- description: "List directory contents",
- params: { path: { type: "string" }, recursive: { type: "boolean" } },
- required: [],
- aliases: ["ls"]
- ) do |args|
+ description: "List directory contents",
+ params: { path: { type: "string" }, recursive: { type: "boolean" } },
+ required: [],
+ aliases: ["ls"]) do |args|
path = args["path"] && !args["path"].empty? ? args["path"] : "."
flags = args["recursive"] ? "-laR" : "-la"
Elelem::Tools.exec(agent.toolbox, "ls", flags, path)
lib/elelem/tools/permissions.rb
@@ -32,7 +32,7 @@ module Elelem
{}
end
- def prompt(tool_name, args, input)
+ def prompt(tool_name, _args, input)
return true unless input.interactive?
answer = input.ask(" Allow? [Y/n] > ")&.downcase
lib/elelem/tools/shell.rb
@@ -2,7 +2,7 @@
Elelem.configure do |config|
config.setup(:shell) do |agent|
- strip_ansi = ->(text) do
+ strip_ansi = lambda do |text|
text
.gsub(/^Script started.*?\n/, "")
.gsub(/\nScript done.*$/, "")
@@ -11,7 +11,7 @@ Elelem.configure do |config|
.gsub(/\e[PX^_].*?\e\\/, "")
.gsub(/\e./, "")
.gsub(/[\b]/, "")
- .gsub(/\r/, "")
+ .gsub("\r", "")
end
agent.commands.register("shell", description: "Start interactive shell") do
lib/elelem/tools/task.rb
@@ -3,10 +3,9 @@
Elelem.configure do |config|
config.setup(:task) do |agent|
agent.toolbox.add("task",
- description: "Delegate subtask to focused agent (complex searches, multi-file analysis)",
- params: { prompt: { type: "string" } },
- required: ["prompt"]
- ) do |args|
+ description: "Delegate subtask to focused agent (complex searches, multi-file analysis)",
+ params: { prompt: { type: "string" } },
+ required: ["prompt"]) do |args|
sub = Elelem::Tools.fork(agent, system_prompt: "Research agent. Search, analyze, report. Be concise.")
sub.turn(args["prompt"])
{ result: sub.conversation.last[:content] }
lib/elelem/tools/verify.rb
@@ -8,7 +8,7 @@ class Verifiers
".go" => "go vet %{path}",
".rs" => "cargo check --quiet",
".ts" => "npx tsc --noEmit %{path}",
- ".js" => "node --check %{path}",
+ ".js" => "node --check %{path}"
}.freeze
def self.for(path)
@@ -16,7 +16,7 @@ class Verifiers
cmds = []
ext = File.extname(path)
- cmds << (SYNTAX[ext] % { path: path }) if SYNTAX[ext]
+ cmds << format(SYNTAX[ext], path: path) if SYNTAX[ext]
cmds << test_runner
cmds.compact
end
@@ -29,18 +29,16 @@ end
Elelem.configure do |config|
config.setup(:verify) do |agent|
agent.toolbox.add("verify",
- description: "Verify file syntax and run tests",
- params: { path: { type: "string" } },
- required: ["path"]
- ) do |args|
+ description: "Verify file syntax and run tests",
+ params: { path: { type: "string" } },
+ required: ["path"]) do |args|
path = args["path"]
- Verifiers.for(path).inject({ verified: [] }) do |memo, cmd|
+ Verifiers.for(path).each_with_object({ verified: [] }) do |cmd, memo|
agent.output.doing("execute", { "command" => cmd })
v = agent.toolbox.run("execute", { "command" => cmd })
break v.merge(path: path, command: cmd) if v[:exit_status] != 0
memo[:verified] << cmd
- memo
end
end
end