Module: Legion::CLI::Chat::Permissions
- Defined in:
- lib/legion/cli/chat/permissions.rb
Defined Under Namespace
Modules: Gate
Constant Summary collapse
- TIERS =
if defined?(Tools::ReadFile) { Tools::ReadFile => :read, Tools::SearchFiles => :read, Tools::SearchContent => :read, Tools::WriteFile => :write, Tools::EditFile => :write, Tools::RunCommand => :shell }.freeze else {}.freeze end
Class Attribute Summary collapse
-
.mode ⇒ Object
Returns the value of attribute mode.
Class Method Summary collapse
- .apply!(tool_classes) ⇒ Object
- .auto_allow? ⇒ Boolean
- .clear_extension_tiers! ⇒ Object
- .confirm?(description) ⇒ Boolean
- .read_only? ⇒ Boolean
- .register_extension_tier(tool_class, tier) ⇒ Object
- .tier_for(tool_class) ⇒ Object
Class Attribute Details
.mode ⇒ Object
Returns the value of attribute mode.
26 27 28 |
# File 'lib/legion/cli/chat/permissions.rb', line 26 def mode @mode end |
Class Method Details
.apply!(tool_classes) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/legion/cli/chat/permissions.rb', line 58 def apply!(tool_classes) tool_classes.each do |klass| tier = tier_for(klass) klass.prepend(Gate) unless tier == :read end end |
.auto_allow? ⇒ Boolean
28 29 30 |
# File 'lib/legion/cli/chat/permissions.rb', line 28 def auto_allow? %i[headless auto_approve].include?(mode) end |
.clear_extension_tiers! ⇒ Object
50 51 52 |
# File 'lib/legion/cli/chat/permissions.rb', line 50 def clear_extension_tiers! @extension_tiers = {} end |
.confirm?(description) ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/legion/cli/chat/permissions.rb', line 36 def confirm?(description) return false if read_only? return true if auto_allow? $stderr.print "\e[33m#{description}\e[0m\n Allow? [y/n] " response = $stdin.gets&.strip&.downcase %w[y yes].include?(response) end |
.read_only? ⇒ Boolean
32 33 34 |
# File 'lib/legion/cli/chat/permissions.rb', line 32 def read_only? mode == :read_only end |
.register_extension_tier(tool_class, tier) ⇒ Object
45 46 47 48 |
# File 'lib/legion/cli/chat/permissions.rb', line 45 def register_extension_tier(tool_class, tier) @extension_tiers ||= {} @extension_tiers[tool_class] = tier end |
.tier_for(tool_class) ⇒ Object
54 55 56 |
# File 'lib/legion/cli/chat/permissions.rb', line 54 def tier_for(tool_class) TIERS[tool_class] || @extension_tiers&.[](tool_class) || :read end |