Class: RosettAi::Mcp::Enforcement::Validator
- Inherits:
-
Object
- Object
- RosettAi::Mcp::Enforcement::Validator
- Defined in:
- lib/rosett_ai/mcp/enforcement/validator.rb
Overview
Validates enforcement blocks in behaviour rules.
Checks each rule's enforcement block for correctness:
- pattern present and compilable as regex
- pattern not degenerate (would match everything)
- applies_to present and non-empty
- action is a valid enum value
Invalid enforceable rules are downgraded to advisory with warnings. Rules without enforcement blocks are skipped (backward compatible).
Defined Under Namespace
Classes: RuleContext
Constant Summary collapse
- VALID_TYPES =
['enforceable', 'advisory', 'informational'].freeze
- VALID_ACTIONS =
['block', 'warn', 'log'].freeze
- DEGENERATE_PATTERNS =
Patterns that match everything or nearly everything — unsafe for hooks.
[ /\A\.\*\z/, # .* /\A\.\+\z/, # .+ /\A\\s\*\z/, # \s* /\A\\S\*\z/, # \S* /\A\\s\+\z/, # \s+ /\A\\S\+\z/, # \S+ /\A\.\*\?\z/, # .*? /\A\.\+\?\z/, # .+? /\A\(\.\*\)\z/, # (.*) /\A\(\.\+\)\z/ # (.+) ].freeze
Instance Method Summary collapse
-
#validate(behaviour) ⇒ Hash
Validates all enforcement blocks in a behaviour.
Instance Method Details
#validate(behaviour) ⇒ Hash
Validates all enforcement blocks in a behaviour.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rosett_ai/mcp/enforcement/validator.rb', line 57 def validate(behaviour) @result = { valid: [], downgraded: [], skipped: [], errors: [] } rules = behaviour['rules'] return @result unless rules.is_a?(Array) behaviour_name = behaviour['name'].to_s rules.each { |rule| validate_rule(rule, behaviour_name) } @result end |