Commit 22ab0ee
Changed files (2)
lib
elelem
plugins
lib/elelem/plugins/builtins.rb
@@ -34,16 +34,22 @@ Elelem::Plugins.register(:builtins) do |agent|
end
end
+ strip_ansi = ->(text) do
+ text
+ .gsub(/^Script started.*?\n/, "")
+ .gsub(/\nScript done.*$/, "")
+ .gsub(/\e\].*?(?:\a|\e\\)/, "")
+ .gsub(/\e\[[0-9;?]*[A-Za-z]/, "")
+ .gsub(/\e[PX^_].*?\e\\/, "")
+ .gsub(/\e./, "")
+ .gsub(/[\b]/, "")
+ .gsub(/\r/, "")
+ end
+
agent.commands.register("shell", description: "Start interactive shell") do
transcript = Tempfile.create do |file|
system("script", "-q", file.path, chdir: Dir.pwd)
- File.read(file.path)
- .gsub(/^Script started.*?\n/, "")
- .gsub(/\nScript done.*$/, "")
- .gsub(/\e\[[0-9;]*[a-zA-Z]/, "")
- .gsub(/\e\[\?[0-9]+[hl]/, "")
- .gsub(/[\b]/, "")
- .gsub(/\r/, "")
+ strip_ansi.call(File.read(file.path))
end
agent.conversation.add(role: "user", content: transcript) unless transcript.strip.empty?
end
lib/elelem/system_prompt.rb
@@ -83,8 +83,8 @@ module Elelem
end
def extract_symbols(files)
- output = `sg run -p 'def $NAME' -l ruby --json=compact . 2>/dev/null`
- return ctags_fallback(files) unless $?.success?
+ output, status = Open3.capture2("sg", "run", "-p", "def $NAME", "-l", "ruby", "--json=compact", ".", err: File::NULL)
+ return ctags_fallback(files) unless status.success?
parse_sg_output(output, files)
end