main
 1# frozen_string_literal: true
 2
 3Elelem::Plugins.register(:git) do |agent|
 4  allowed = %w[status diff log show branch checkout add reset stash].freeze
 5
 6  agent.toolbox.add("git",
 7    description: "Run git command",
 8    params: { command: { type: "string" }, args: { type: "array" } },
 9    required: ["command"]
10  ) do |a|
11    cmd = a["command"]
12    next { error: "not allowed: #{cmd}" } unless allowed.include?(cmd)
13
14    agent.toolbox.exec("git", cmd, *(a["args"] || []))
15  end
16
17  agent.toolbox.after("git") do |_, result|
18    agent.terminal.say "  ! #{result[:error]}" if result[:error]
19  end
20end