Commit befde65
Changed files (3)
lib
elelem
lib/elelem/agent.rb
@@ -57,7 +57,7 @@ module Elelem
tool_calls.each do |tool_call|
name, args = tool_call[:name], tool_call[:arguments]
terminal.say "\n#{format_tool_display(name, args)}"
- result = toolbox.run(tool_call)
+ result = toolbox.run(name, args)
terminal.say format_tool_result(name, result)
ctx << { role: "tool", tool_call_id: tool_call[:id], content: result.to_json }
errors += 1 if result[:error]
lib/elelem/terminal.rb
@@ -18,7 +18,7 @@ module Elelem
def markdown(text)
width = $stdout.winsize[1] rescue 80
- IO.popen(["glow", "-s", "dark", "-w", width.to_s, "-"], "r+") do |io|
+ IO.popen(["bat", "--squeeze-blank", "--style=plain", "--paging=never", "--color=always", "--language", "markdown", "--terminal-width", width, "-"], "r+") do |io|
io.write(text)
io.close_write
io.read
@@ -41,6 +41,10 @@ module Elelem
say("")
end
+ def file(path)
+ Elelem.sh("bat", args: ["--style=plain", "--paging=never", "--color=always", path]) { |x| $stdout.print(x) }
+ end
+
def waiting
@dots_thread = Thread.new do
loop do
lib/elelem/toolbox.rb
@@ -4,7 +4,7 @@ module Elelem
class Toolbox
TOOLS = {
"read" => {
- desc: "Read file contents",
+ desc: "Read file",
params: { path: { type: "string" } },
required: ["path"],
fn: ->(a) { p = Pathname.new(a["path"]).expand_path; p.exist? ? { content: p.read } : { error: "not found" } }
@@ -48,11 +48,10 @@ module Elelem
end
end
- def run(tool_call)
- name, args = tool_call[:name], tool_call[:arguments]
+ def run(name, args)
name = ALIASES.fetch(name, name)
tool = tools[name]
- return { error: "unknown tool: #{tool_call}" } unless tool
+ return { error: "unknown tool: #{name}" } unless tool
tool[:fn].call(args)
rescue => e