Commit e148995

mo khan <mo@mokhan.ca>
2026-09-12 21:57:41
style: apply rubocop autocorrect
1 parent 880cccc
lib/elelem/builtins/execute.rb
@@ -3,16 +3,15 @@
 Elelem.configure do |config|
   config.setup(:execute) do |agent|
     agent.toolbox.add("execute",
-      description: "Run shell command (supports pipes and redirections)",
-      params: { command: { type: "string" } },
-      required: ["command"],
-      aliases: ["bash", "sh", "exec", "execute<|channel|>"]
-    ) do |a|
+                      description: "Run shell command (supports pipes and redirections)",
+                      params: { command: { type: "string" } },
+                      required: ["command"],
+                      aliases: ["bash", "sh", "exec", "execute<|channel|>"]) do |a|
       Elelem::Builtins.sh("bash", args: ["-c", a["command"]], timeout: Elelem::Builtins.command_timeout) { |x| agent.output.print(x) }
     end
 
     agent.toolbox.after("execute") do |args, result|
-      next if result[:exit_status] == 0
+      next if result[:exit_status].zero?
 
       agent.output.doing("execute", args, state: "x")
     end
lib/elelem/builtins/provider.rb
@@ -2,7 +2,9 @@
 
 Elelem.configure do |config|
   config.setup(:provider) do |agent|
-    agent.commands.register("provider", description: "Switch provider", completions: -> { Elelem::Config.names }) do |name|
+    agent.commands.register("provider", description: "Switch provider", completions: lambda {
+      Elelem::Config.names
+    }) do |name|
       if name.nil? || name.empty?
         agent.output.say "  → available: #{Elelem::Config.names.join(", ")}"
       else
lib/elelem/builtins/read.rb
@@ -3,11 +3,10 @@
 Elelem.configure do |config|
   config.setup(:read) do |agent|
     agent.toolbox.add("read",
-      description: "Read file",
-      params: { path: { type: "string" } },
-      required: ["path"],
-      aliases: ["open"]
-    ) do |a|
+                      description: "Read file",
+                      params: { path: { type: "string" } },
+                      required: ["path"],
+                      aliases: ["open"]) do |a|
       path = Pathname.new(a["path"]).expand_path
       path.exist? ? { content: path.read, path: a["path"] } : { error: "not found" }
     end
lib/elelem/builtins/terminal.rb
@@ -57,7 +57,11 @@ module Elelem
         return text unless as == :markdown
 
         gap
-        width = @stream.winsize[1] rescue 80
+        width = begin
+          @stream.winsize[1]
+        rescue StandardError
+          80
+        end
         IO.popen(["glow", "-s", "dark", "-w", width.to_s, "-"], "r+") do |io|
           io.write(text)
           io.close_write
@@ -92,7 +96,7 @@ module Elelem
         state_dir = File.join(ENV.fetch("XDG_STATE_HOME", File.expand_path("~/.local/state")), "elelem", "sessions")
         FileUtils.mkdir_p(state_dir)
         session_id = "#{Time.now.utc.strftime("%Y%m%dT%H%M%SZ")}-#{Process.pid}"
-        File.open(File.join(state_dir, "#{session_id}.transcript"), "a").tap { |f| f.sync = true }
+        File.open(File.join(state_dir, "#{session_id}.transcript"), "a").tap { |f| f.sync = true } # rubocop:disable Style/FileOpen
       end
 
       def blank?(text)
lib/elelem/builtins/write.rb
@@ -3,11 +3,10 @@
 Elelem.configure do |config|
   config.setup(:write) do |agent|
     agent.toolbox.add("write",
-      description: "Write file",
-      params: { path: { type: "string" }, content: { type: "string" } },
-      required: ["path", "content"],
-      aliases: ["write<|channel|>"]
-    ) do |a|
+                      description: "Write file",
+                      params: { path: { type: "string" }, content: { type: "string" } },
+                      required: %w[path content],
+                      aliases: ["write<|channel|>"]) do |a|
       path = Pathname.new(a["path"]).expand_path
       FileUtils.mkdir_p(path.dirname)
       { bytes: path.write(a["content"]), path: a["path"] }
lib/elelem/builtins.rb
@@ -55,7 +55,7 @@ module Elelem
     end
 
     def self.command_timeout
-      value = ENV["ELELEM_CMD_TIMEOUT"]
+      value = ENV.fetch("ELELEM_CMD_TIMEOUT", nil)
       value && !value.empty? ? Integer(value) : nil
     end
   end
spec/elelem/builtins/tool_markdown_spec.rb
@@ -3,13 +3,12 @@
 RSpec.describe Elelem::Builtins::ToolMarkdown do
   subject(:tool) do
     Elelem::Tool.new("greet",
-      description: "Greets someone.\nMore detail.",
-      schema: Elelem::Schema.new(
-        params: { name: { type: "string", description: "who to greet" } },
-        required: ["name"]
-      ),
-      aliases: ["hi"]
-    ) { |args| { greeting: "hi #{args["name"]}" } }
+                     description: "Greets someone.\nMore detail.",
+                     schema: Elelem::Schema.new(
+                       params: { name: { type: "string", description: "who to greet" } },
+                       required: ["name"]
+                     ),
+                     aliases: ["hi"]) { |args| { greeting: "hi #{args["name"]}" } }
   end
 
   describe ".summary" do
@@ -29,7 +28,7 @@ RSpec.describe Elelem::Builtins::ToolMarkdown do
     end
 
     it "omits the aliases line when there are none" do
-      plain_tool = Elelem::Tool.new("greet", description: "Greets someone.") { }
+      plain_tool = Elelem::Tool.new("greet", description: "Greets someone.") {}
 
       expect(described_class.to_markdown(plain_tool)).not_to include("aliases:")
     end