Class: Ask::Agent::Policies::PermissionRules::Rule

Inherits:
Data
  • Object
show all
Defined in:
lib/ask/agent/policies/permission_rules.rb

Overview

A single rule: tool pattern + optional argument pattern + decision.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argument_patternObject (readonly)

Returns the value of attribute argument_pattern

Returns:

  • (Object)

    the current value of argument_pattern



36
37
38
# File 'lib/ask/agent/policies/permission_rules.rb', line 36

def argument_pattern
  @argument_pattern
end

#decisionObject (readonly)

Returns the value of attribute decision

Returns:

  • (Object)

    the current value of decision



36
37
38
# File 'lib/ask/agent/policies/permission_rules.rb', line 36

def decision
  @decision
end

#tool_patternObject (readonly)

Returns the value of attribute tool_pattern

Returns:

  • (Object)

    the current value of tool_pattern



36
37
38
# File 'lib/ask/agent/policies/permission_rules.rb', line 36

def tool_pattern
  @tool_pattern
end

Instance Method Details

#argument_matches?(arguments) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
# File 'lib/ask/agent/policies/permission_rules.rb', line 49

def argument_matches?(arguments)
  return true if argument_pattern.nil?

  text = arguments.is_a?(Hash) ? JSON.generate(arguments) : arguments.to_s
  case argument_pattern
  when Regexp then argument_pattern.match?(text)
  else text.include?(argument_pattern.to_s)
  end
end

#matches?(tool_name, arguments) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/ask/agent/policies/permission_rules.rb', line 37

def matches?(tool_name, arguments)
  tool_matches?(tool_name) && argument_matches?(arguments)
end

#tool_matches?(tool_name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
# File 'lib/ask/agent/policies/permission_rules.rb', line 41

def tool_matches?(tool_name)
  case tool_pattern
  when :all then true
  when Regexp then tool_pattern.match?(tool_name.to_s)
  else tool_pattern.to_s == tool_name.to_s
  end
end

#universal?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/ask/agent/policies/permission_rules.rb', line 59

def universal?
  argument_pattern.nil?
end