Class: Elelem::Tools::Permissions

Inherits:
Object
  • Object
show all
Defined in:
lib/elelem/tools/permissions.rb

Constant Summary collapse

LOAD_PATHS =
[
  File.expand_path("permissions.json", __dir__),
  "~/.agents/permissions.json",
  ".agents/permissions.json"
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(rules: default_rules) ⇒ Permissions

Returns a new instance of Permissions.



12
13
14
# File 'lib/elelem/tools/permissions.rb', line 12

def initialize(rules: default_rules)
  @rules = rules
end

Instance Method Details

#check(tool_name, args, input:) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/elelem/tools/permissions.rb', line 16

def check(tool_name, args, input:)
  policy = @rules[tool_name.to_sym] || :ask
  case policy
  when :allow then true
  when :deny then raise "Permission denied: #{tool_name}"
  when :ask then prompt(tool_name, args, input)
  end
end