olyx-guardrails 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +117 -0
  3. data/CODE_OF_CONDUCT.md +28 -0
  4. data/CONTRIBUTING.md +63 -0
  5. data/LICENSE +134 -0
  6. data/README.md +611 -0
  7. data/SECURITY.md +35 -0
  8. data/docs/API.md +460 -0
  9. data/examples/claude_analyzer.rb +53 -0
  10. data/examples/custom_policy.rb +41 -0
  11. data/examples/notifier.rb +37 -0
  12. data/examples/openai_analyzer.rb +45 -0
  13. data/examples/rails_opt_in.rb +99 -0
  14. data/examples/ruby_only.rb +53 -0
  15. data/lib/generators/olyx_guardrails/install_generator.rb +22 -0
  16. data/lib/generators/olyx_guardrails/templates/initializer.rb.tt +16 -0
  17. data/lib/generators/olyx_guardrails/templates/policy.yml.tt +41 -0
  18. data/lib/olyx/guardrails/ai/analysis_normalizer.rb +26 -0
  19. data/lib/olyx/guardrails/ai/analysis_pipeline.rb +26 -0
  20. data/lib/olyx/guardrails/ai/boolean_validator.rb +18 -0
  21. data/lib/olyx/guardrails/ai/flag_finding_merger.rb +16 -0
  22. data/lib/olyx/guardrails/ai/result_sanitizer.rb +29 -0
  23. data/lib/olyx/guardrails/ai/secret_finding_merger.rb +19 -0
  24. data/lib/olyx/guardrails/ai/standard_finding_merger.rb +24 -0
  25. data/lib/olyx/guardrails/ai_analysis.rb +29 -0
  26. data/lib/olyx/guardrails/ai_context_builder.rb +32 -0
  27. data/lib/olyx/guardrails/ai_failure_handler.rb +17 -0
  28. data/lib/olyx/guardrails/ai_finding_merger.rb +30 -0
  29. data/lib/olyx/guardrails/check_analyzer.rb +26 -0
  30. data/lib/olyx/guardrails/check_base_result.rb +32 -0
  31. data/lib/olyx/guardrails/check_pipeline.rb +17 -0
  32. data/lib/olyx/guardrails/check_result_builder.rb +24 -0
  33. data/lib/olyx/guardrails/check_runner.rb +42 -0
  34. data/lib/olyx/guardrails/check_set.rb +33 -0
  35. data/lib/olyx/guardrails/checks/injection_check.rb +20 -0
  36. data/lib/olyx/guardrails/checks/injection_result.rb +22 -0
  37. data/lib/olyx/guardrails/checks/length_check.rb +18 -0
  38. data/lib/olyx/guardrails/checks/message_injection_check.rb +19 -0
  39. data/lib/olyx/guardrails/checks/pii_check.rb +19 -0
  40. data/lib/olyx/guardrails/checks/policy_check.rb +26 -0
  41. data/lib/olyx/guardrails/checks/secret_check.rb +30 -0
  42. data/lib/olyx/guardrails/checks/skipped_checks.rb +26 -0
  43. data/lib/olyx/guardrails/enum_value.rb +20 -0
  44. data/lib/olyx/guardrails/errors.rb +22 -0
  45. data/lib/olyx/guardrails/injection_detector.rb +27 -0
  46. data/lib/olyx/guardrails/injection_patterns.rb +44 -0
  47. data/lib/olyx/guardrails/integrations/openai/analyzer_setup.rb +21 -0
  48. data/lib/olyx/guardrails/integrations/openai/configuration_resolver.rb +28 -0
  49. data/lib/olyx/guardrails/integrations/openai/dependency_contracts.rb +28 -0
  50. data/lib/olyx/guardrails/integrations/openai/input_builder.rb +39 -0
  51. data/lib/olyx/guardrails/integrations/openai/member_reader.rb +21 -0
  52. data/lib/olyx/guardrails/integrations/openai/model_identifier.rb +28 -0
  53. data/lib/olyx/guardrails/integrations/openai/refusal_guard.rb +28 -0
  54. data/lib/olyx/guardrails/integrations/openai/request_builder.rb +36 -0
  55. data/lib/olyx/guardrails/integrations/openai/request_configuration.rb +25 -0
  56. data/lib/olyx/guardrails/integrations/openai/request_values.rb +33 -0
  57. data/lib/olyx/guardrails/integrations/openai/response_contents.rb +22 -0
  58. data/lib/olyx/guardrails/integrations/openai/response_option_keys.rb +32 -0
  59. data/lib/olyx/guardrails/integrations/openai/response_options.rb +23 -0
  60. data/lib/olyx/guardrails/integrations/openai/schema_registry.rb +46 -0
  61. data/lib/olyx/guardrails/integrations/openai/sdk.rb +26 -0
  62. data/lib/olyx/guardrails/integrations/openai/signal_summary.rb +40 -0
  63. data/lib/olyx/guardrails/integrations/openai_analyzer.rb +107 -0
  64. data/lib/olyx/guardrails/integrations/openai_analyzer_configuration.rb +38 -0
  65. data/lib/olyx/guardrails/integrations/openai_response_parser.rb +34 -0
  66. data/lib/olyx/guardrails/message_check_runner.rb +24 -0
  67. data/lib/olyx/guardrails/message_check_set.rb +20 -0
  68. data/lib/olyx/guardrails/message_content.rb +27 -0
  69. data/lib/olyx/guardrails/message_source.rb +16 -0
  70. data/lib/olyx/guardrails/multi_turn_injection_detector.rb +18 -0
  71. data/lib/olyx/guardrails/multi_turn_pair_scanner.rb +35 -0
  72. data/lib/olyx/guardrails/multi_turn_variant_pairs.rb +25 -0
  73. data/lib/olyx/guardrails/notification/base_event.rb +35 -0
  74. data/lib/olyx/guardrails/notification/deep_freezer.rb +25 -0
  75. data/lib/olyx/guardrails/notification/delivery_dispatcher.rb +38 -0
  76. data/lib/olyx/guardrails/notification/delivery_summary.rb +17 -0
  77. data/lib/olyx/guardrails/notification/handler.rb +33 -0
  78. data/lib/olyx/guardrails/notification/handler_collection.rb +25 -0
  79. data/lib/olyx/guardrails/notification/handler_collection_validator.rb +23 -0
  80. data/lib/olyx/guardrails/notification/key.rb +19 -0
  81. data/lib/olyx/guardrails/notification/metadata.rb +34 -0
  82. data/lib/olyx/guardrails/notification/notifier_setup.rb +19 -0
  83. data/lib/olyx/guardrails/notification/preview.rb +27 -0
  84. data/lib/olyx/guardrails/notification/scrubber.rb +22 -0
  85. data/lib/olyx/guardrails/notification/violation_labels.rb +19 -0
  86. data/lib/olyx/guardrails/notification_event_builder.rb +41 -0
  87. data/lib/olyx/guardrails/notification_sanitizer.rb +33 -0
  88. data/lib/olyx/guardrails/notifier.rb +53 -0
  89. data/lib/olyx/guardrails/notifier_configuration.rb +30 -0
  90. data/lib/olyx/guardrails/pii/ambiguous_numeric_date.rb +32 -0
  91. data/lib/olyx/guardrails/pii/block_scrubber.rb +31 -0
  92. data/lib/olyx/guardrails/pii/content_scrubber.rb +33 -0
  93. data/lib/olyx/guardrails/pii/date_validator.rb +25 -0
  94. data/lib/olyx/guardrails/pii/hash_key.rb +19 -0
  95. data/lib/olyx/guardrails/pii/iban_remainder.rb +25 -0
  96. data/lib/olyx/guardrails/pii/iban_validator.rb +34 -0
  97. data/lib/olyx/guardrails/pii/ipv4_validator.rb +17 -0
  98. data/lib/olyx/guardrails/pii/ipv6_validator.rb +20 -0
  99. data/lib/olyx/guardrails/pii/luhn_checksum.rb +29 -0
  100. data/lib/olyx/guardrails/pii/luhn_validator.rb +21 -0
  101. data/lib/olyx/guardrails/pii/message_scrubber.rb +31 -0
  102. data/lib/olyx/guardrails/pii/named_date_validator.rb +28 -0
  103. data/lib/olyx/guardrails/pii/numeric_date_validator.rb +26 -0
  104. data/lib/olyx/guardrails/pii/pattern_catalog.rb +41 -0
  105. data/lib/olyx/guardrails/pii/sin_validator.rb +24 -0
  106. data/lib/olyx/guardrails/pii/ssn_validator.rb +21 -0
  107. data/lib/olyx/guardrails/pii/text_scrubber.rb +28 -0
  108. data/lib/olyx/guardrails/pii/year_first_date.rb +18 -0
  109. data/lib/olyx/guardrails/pii_scrubber.rb +23 -0
  110. data/lib/olyx/guardrails/pii_validators.rb +26 -0
  111. data/lib/olyx/guardrails/policy/ai_failure_mode.rb +15 -0
  112. data/lib/olyx/guardrails/policy/configuration.rb +62 -0
  113. data/lib/olyx/guardrails/policy/configuration_hash.rb +20 -0
  114. data/lib/olyx/guardrails/policy/finding_order.rb +20 -0
  115. data/lib/olyx/guardrails/policy/finding_presenter.rb +41 -0
  116. data/lib/olyx/guardrails/policy/match_collector.rb +20 -0
  117. data/lib/olyx/guardrails/policy/name.rb +23 -0
  118. data/lib/olyx/guardrails/policy/normalized_pattern_matcher.rb +34 -0
  119. data/lib/olyx/guardrails/policy/pattern_matcher.rb +19 -0
  120. data/lib/olyx/guardrails/policy/redaction_result.rb +20 -0
  121. data/lib/olyx/guardrails/policy/redaction_spans.rb +32 -0
  122. data/lib/olyx/guardrails/policy/rule_collection.rb +34 -0
  123. data/lib/olyx/guardrails/policy/rule_matcher.rb +29 -0
  124. data/lib/olyx/guardrails/policy/rule_normalizer.rb +21 -0
  125. data/lib/olyx/guardrails/policy/scan_result.rb +21 -0
  126. data/lib/olyx/guardrails/policy/secret_pattern_collection.rb +22 -0
  127. data/lib/olyx/guardrails/policy/unmatched_segment_builder.rb +28 -0
  128. data/lib/olyx/guardrails/policy/unmatched_transformer.rb +20 -0
  129. data/lib/olyx/guardrails/policy.rb +46 -0
  130. data/lib/olyx/guardrails/policy_aware_redactor.rb +42 -0
  131. data/lib/olyx/guardrails/policy_redactor.rb +28 -0
  132. data/lib/olyx/guardrails/policy_rule/configuration.rb +46 -0
  133. data/lib/olyx/guardrails/policy_rule/description_value.rb +24 -0
  134. data/lib/olyx/guardrails/policy_rule/match_mode.rb +15 -0
  135. data/lib/olyx/guardrails/policy_rule/name_value.rb +22 -0
  136. data/lib/olyx/guardrails/policy_rule/pattern_compiler.rb +28 -0
  137. data/lib/olyx/guardrails/policy_rule/regexp_compiler.rb +31 -0
  138. data/lib/olyx/guardrails/policy_rule/replacement_value.rb +26 -0
  139. data/lib/olyx/guardrails/policy_rule/term_compiler.rb +33 -0
  140. data/lib/olyx/guardrails/policy_rule/text_values.rb +23 -0
  141. data/lib/olyx/guardrails/policy_rule/values.rb +33 -0
  142. data/lib/olyx/guardrails/policy_rule.rb +30 -0
  143. data/lib/olyx/guardrails/policy_scanner.rb +44 -0
  144. data/lib/olyx/guardrails/rails/action_cable.rb +21 -0
  145. data/lib/olyx/guardrails/rails/active_job_handler.rb +27 -0
  146. data/lib/olyx/guardrails/rails/active_model_validator.rb +23 -0
  147. data/lib/olyx/guardrails/rails/check_telemetry.rb +19 -0
  148. data/lib/olyx/guardrails/rails/configuration.rb +68 -0
  149. data/lib/olyx/guardrails/rails/configuration_finalizer.rb +30 -0
  150. data/lib/olyx/guardrails/rails/configuration_registry.rb +41 -0
  151. data/lib/olyx/guardrails/rails/configuration_values.rb +30 -0
  152. data/lib/olyx/guardrails/rails/constant_resolver.rb +18 -0
  153. data/lib/olyx/guardrails/rails/controller.rb +34 -0
  154. data/lib/olyx/guardrails/rails/controller_metadata.rb +22 -0
  155. data/lib/olyx/guardrails/rails/decision_service.rb +26 -0
  156. data/lib/olyx/guardrails/rails/enforcer.rb +33 -0
  157. data/lib/olyx/guardrails/rails/evaluation_lifecycle.rb +23 -0
  158. data/lib/olyx/guardrails/rails/evaluation_service.rb +12 -0
  159. data/lib/olyx/guardrails/rails/filter_parameters.rb +26 -0
  160. data/lib/olyx/guardrails/rails/graphql.rb +21 -0
  161. data/lib/olyx/guardrails/rails/ingress.rb +26 -0
  162. data/lib/olyx/guardrails/rails/input_runtime.rb +25 -0
  163. data/lib/olyx/guardrails/rails/instrumentation.rb +39 -0
  164. data/lib/olyx/guardrails/rails/instrumentation_payloads.rb +25 -0
  165. data/lib/olyx/guardrails/rails/instrumentation_publisher.rb +24 -0
  166. data/lib/olyx/guardrails/rails/integration_configuration.rb +27 -0
  167. data/lib/olyx/guardrails/rails/job.rb +37 -0
  168. data/lib/olyx/guardrails/rails/job_argument.rb +41 -0
  169. data/lib/olyx/guardrails/rails/job_reference.rb +36 -0
  170. data/lib/olyx/guardrails/rails/message_evaluation_service.rb +13 -0
  171. data/lib/olyx/guardrails/rails/message_runtime.rb +20 -0
  172. data/lib/olyx/guardrails/rails/notification_dispatcher.rb +22 -0
  173. data/lib/olyx/guardrails/rails/output_runtime.rb +26 -0
  174. data/lib/olyx/guardrails/rails/path_value.rb +30 -0
  175. data/lib/olyx/guardrails/rails/policy_configuration.rb +25 -0
  176. data/lib/olyx/guardrails/rails/policy_document.rb +40 -0
  177. data/lib/olyx/guardrails/rails/policy_file.rb +29 -0
  178. data/lib/olyx/guardrails/rails/policy_file_error.rb +25 -0
  179. data/lib/olyx/guardrails/rails/policy_rule_names.rb +19 -0
  180. data/lib/olyx/guardrails/rails/policy_yaml.rb +22 -0
  181. data/lib/olyx/guardrails/rails/queue_name.rb +21 -0
  182. data/lib/olyx/guardrails/rails/redaction_payload.rb +36 -0
  183. data/lib/olyx/guardrails/rails/redaction_service.rb +21 -0
  184. data/lib/olyx/guardrails/rails/result_summary.rb +36 -0
  185. data/lib/olyx/guardrails/rails/runtime.rb +30 -0
  186. data/lib/olyx/guardrails/rails/timer.rb +27 -0
  187. data/lib/olyx/guardrails/rails/upload.rb +34 -0
  188. data/lib/olyx/guardrails/rails.rb +35 -0
  189. data/lib/olyx/guardrails/railtie.rb +19 -0
  190. data/lib/olyx/guardrails/redaction/content_result.rb +32 -0
  191. data/lib/olyx/guardrails/redaction/input_validator.rb +17 -0
  192. data/lib/olyx/guardrails/redaction/public_result.rb +23 -0
  193. data/lib/olyx/guardrails/redaction/unrestricted_text.rb +17 -0
  194. data/lib/olyx/guardrails/redactor.rb +29 -0
  195. data/lib/olyx/guardrails/risk/ai_score.rb +19 -0
  196. data/lib/olyx/guardrails/risk/check_weights.rb +18 -0
  197. data/lib/olyx/guardrails/risk/deterministic_score.rb +20 -0
  198. data/lib/olyx/guardrails/risk/weights.rb +18 -0
  199. data/lib/olyx/guardrails/risk_scorer.rb +28 -0
  200. data/lib/olyx/guardrails/secret_finding_collector.rb +31 -0
  201. data/lib/olyx/guardrails/secret_scanner.rb +42 -0
  202. data/lib/olyx/guardrails/secrets/blocked.rb +17 -0
  203. data/lib/olyx/guardrails/secrets/catalog_source.rb +28 -0
  204. data/lib/olyx/guardrails/secrets/cloud_credential_patterns.rb +16 -0
  205. data/lib/olyx/guardrails/secrets/confidentiality_source.rb +21 -0
  206. data/lib/olyx/guardrails/secrets/custom_pattern_compiler.rb +23 -0
  207. data/lib/olyx/guardrails/secrets/custom_pattern_source.rb +30 -0
  208. data/lib/olyx/guardrails/secrets/finding_order.rb +17 -0
  209. data/lib/olyx/guardrails/secrets/finding_presenter.rb +34 -0
  210. data/lib/olyx/guardrails/secrets/generic_credential_patterns.rb +15 -0
  211. data/lib/olyx/guardrails/secrets/internal_endpoint_source.rb +28 -0
  212. data/lib/olyx/guardrails/secrets/network_patterns.rb +13 -0
  213. data/lib/olyx/guardrails/secrets/normalized_source_set.rb +27 -0
  214. data/lib/olyx/guardrails/secrets/pattern_catalog.rb +37 -0
  215. data/lib/olyx/guardrails/secrets/private_network_validator.rb +19 -0
  216. data/lib/olyx/guardrails/secrets/redaction_spans.rb +32 -0
  217. data/lib/olyx/guardrails/secrets/redactor.rb +27 -0
  218. data/lib/olyx/guardrails/secrets/regexp_finding_source.rb +21 -0
  219. data/lib/olyx/guardrails/secrets/source_set.rb +19 -0
  220. data/lib/olyx/guardrails/single_message_injection_detector.rb +35 -0
  221. data/lib/olyx/guardrails/supplemental_violation_labels.rb +22 -0
  222. data/lib/olyx/guardrails/text/base64_decoder.rb +45 -0
  223. data/lib/olyx/guardrails/text/detection_variants.rb +28 -0
  224. data/lib/olyx/guardrails/text/html_decoder.rb +18 -0
  225. data/lib/olyx/guardrails/text/mapped_builder.rb +33 -0
  226. data/lib/olyx/guardrails/text/mapped_normalization.rb +27 -0
  227. data/lib/olyx/guardrails/text/normalizer.rb +35 -0
  228. data/lib/olyx/guardrails/text/unicode_escape_decoder.rb +20 -0
  229. data/lib/olyx/guardrails/text/url_decoder.rb +20 -0
  230. data/lib/olyx/guardrails/validation.rb +33 -0
  231. data/lib/olyx/guardrails/version.rb +8 -0
  232. data/lib/olyx/guardrails/violation_labels.rb +24 -0
  233. data/lib/olyx/guardrails.rb +63 -0
  234. metadata +283 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '069f552d05ca4f0ee61bf1496b27da5961477bb75eb422424b1cd19b31e1ac61'
4
+ data.tar.gz: 9189f069fc540a3ecab429ebec194cb9c870917966837fb4c7fff428d705ed78
5
+ SHA512:
6
+ metadata.gz: 264d94b6a842c268cd30430ecf1cb6f2d49557d12266f331e594160e7100d8539b1c35351e4dbab58dd0525c97760c738a4f139270aefcb8d2f251835bd04e5c
7
+ data.tar.gz: 75bd129939354ed2333d622cc215cc4a34b0967e39fcb482345719ddd312f9637ceb6a13beddfd27cbfa242f6057bd82178590e8ab98e63e10d79a461fe99b6d
data/CHANGELOG.md ADDED
@@ -0,0 +1,117 @@
1
+ # Changelog
2
+
3
+ All notable changes to olyx-guardrails are documented here.
4
+ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
+
6
+ ## [1.0.0] - 2026-07-21
7
+
8
+ Initial public release.
9
+
10
+ ### Decision and transformation
11
+
12
+ - `Olyx::Guardrails.check` — makes an allow/block decision against PII,
13
+ prompt-injection, secret, and restricted-policy findings without
14
+ transforming the input. Returns `allowed`, per-category detection flags,
15
+ `risk_score`, and a `checks` array with one entry per category. The
16
+ `length` check runs first; content and AI checks are skipped (not just
17
+ failed) when it does, so an oversized payload never pays their cost.
18
+ - `Olyx::Guardrails.redact` — transforms text by removing every
19
+ regex-detected PII, secret, and restricted-policy match, without making an
20
+ allow/block decision. Findings expose a masked value, a short SHA-256
21
+ fingerprint, and source offsets — never plaintext credentials. Raises
22
+ `ArgumentError` on oversized input rather than running an unbounded
23
+ transformation.
24
+ - `check_messages` adds adjacent `user` → `assistant` multi-turn injection
25
+ detection over structured chat messages. `check_output`/`redact_output`
26
+ are explicit aliases for the completed-output boundary, distinct from
27
+ input checks so applications can instrument both without implying
28
+ streaming-token enforcement.
29
+
30
+ ### Policy
31
+
32
+ - Immutable `Policy` and `PolicyRule` configuration: named blocking or
33
+ monitoring-only restricted-content rules, `substring`/`whole_word`/`regexp`
34
+ term matching, case-aware regex support, configurable safe replacements,
35
+ and `Policy.from_h` for YAML/JSON-style Hash loading.
36
+ - `ai_failure_mode:` controls how an analyzer failure is handled: `:allow`
37
+ (default, keeps the deterministic result), `:block` (adds a failed `ai`
38
+ check and rejects), or `:raise` (`AiAnalyzerError`).
39
+ - Invalid configuration — duplicate rule names, empty-matching or invalid
40
+ patterns, malformed message arrays, invalid custom regexes — raises
41
+ `ArgumentError` at construction time rather than silently degrading into a
42
+ permissive policy.
43
+
44
+ ### Detection
45
+
46
+ - `PiiScrubber` recognizes email, formatted/international phone,
47
+ structurally valid U.S. SSN, Luhn-valid Canadian SIN, Luhn-valid payment
48
+ card, valid IPv4/IPv6, token prefixes, contextualized passports,
49
+ formatted/checksum-valid IBAN, and calendar-valid contextualized dates of
50
+ birth.
51
+ - `InjectionDetector` matches structural tags, jailbreak phrases, and
52
+ adjacent-turn split attacks against bounded variants produced by NFKC
53
+ normalization, common Greek/Cyrillic homoglyph folding, zero-width
54
+ removal, and one decoding layer each for URL, HTML-entity, Unicode-escape,
55
+ and Base64 encoding.
56
+ - `SecretScanner` detects common cloud/SaaS tokens, JWTs, PEM private keys,
57
+ credential-bearing database URLs, confidentiality markers, and private
58
+ network endpoints via explicit `scan` (detect), `redact` (transform), and
59
+ `scan!` (raise `Blocked`) operations. A confidentiality marker redacts the
60
+ complete input, since the marker alone doesn't identify the sensitive
61
+ span. Custom patterns extend detection and are classified as secrets; use
62
+ `PolicyRule` for named business restrictions instead.
63
+
64
+ ### AI analyzer hook
65
+
66
+ - Optional `ai_analyzer:` callable receives `(text, context)` and returns a
67
+ Hash or a schema-model object implementing `deep_to_h`/`to_h`. Findings
68
+ can add a violation but cannot clear a deterministic one. Boolean fields
69
+ must be actual `true`/`false` values; non-finite risk scores are ignored
70
+ rather than crashing. Exceptions and malformed responses are bounded under
71
+ `result[:ai_analysis][:error]` and handled per `ai_failure_mode`.
72
+ - Optional `Integrations::OpenAIAnalyzer` connector for the official OpenAI
73
+ Ruby SDK: sends a strict `OpenAI::BaseModel` schema through the Responses
74
+ API, consumes the parsed schema-model result, defaults to `store: false`,
75
+ and has no model allowlist — it forwards any String/Symbol model
76
+ identifier and relies on Structured Outputs support as the compatibility
77
+ check. Refusals, API failures, and missing parsed output degrade into the
78
+ same `result[:ai_analysis][:error]` path. The `openai` gem is optional and
79
+ loaded lazily.
80
+
81
+ ### Notifications
82
+
83
+ - Vendor-neutral `Notifier` dispatches one sanitized, deeply frozen,
84
+ versioned event to named callable handlers. Handlers run synchronously and
85
+ independently — one failure doesn't stop the others, and errors are
86
+ returned per handler rather than raised. Input previews, AI reasons,
87
+ metadata keys/values, and handler errors are bounded and redacted with the
88
+ policy's restricted-content rules and the built-in PII/secret detectors.
89
+
90
+ ### Rails integration
91
+
92
+ - Optional first-class Rails adapter, absent from the core runtime
93
+ dependency set: a Railtie with boot-finalized configuration, safe
94
+ environment-keyed YAML policy loading (`YAML.safe_load`, no ERB/aliases/
95
+ arbitrary classes), an install generator, and explicit opt-in boundary
96
+ adapters for controllers, GraphQL, Action Cable, Active Job arguments,
97
+ Active Model validation, caller-extracted uploads, and service objects
98
+ (`Rails::Enforcer`).
99
+ - Content-free Active Support instrumentation (`check`, `violation`,
100
+ `redact`, `notification` events) carries bounded decision/delivery fields
101
+ and duration only — never raw input, redacted output, metadata, or
102
+ analyzer prose. Subscriber failures are isolated from enforcement.
103
+ - `Rails::ActiveJobHandler` enqueues sanitized notification events through
104
+ any Active Job backend, resolving a reload-safe String/Symbol job
105
+ constant at delivery time.
106
+
107
+ ### Quality and security posture
108
+
109
+ - No runtime dependencies for the core checks; Rails and the OpenAI SDK are
110
+ both optional and loaded only when used.
111
+ - CI enforces RuboCop, a Flog structural-complexity gate (max 10 per
112
+ ordinary method, 60 per class/module, with documented DSL exemptions
113
+ only), and a RubyCritic maintainability gate, alongside the Appraisal
114
+ matrix across Rails 7.2, 8.0, and 8.1.
115
+ - Least-privilege, SHA-pinned CI actions; CodeQL and OpenSSF Scorecard
116
+ scanning; a private vulnerability-reporting process (see
117
+ [SECURITY.md](SECURITY.md)).
@@ -0,0 +1,28 @@
1
+ # Code of Conduct
2
+
3
+ ## Our commitment
4
+
5
+ We are committed to a welcoming, professional, and harassment-free community
6
+ for everyone, regardless of background, identity, experience, or ability.
7
+
8
+ ## Expected behavior
9
+
10
+ - Be respectful, constructive, and specific.
11
+ - Assume good intent while addressing harmful impact.
12
+ - Accept technical feedback without personal attacks.
13
+ - Respect privacy and confidentiality.
14
+ - Focus disagreement on ideas, evidence, and project outcomes.
15
+
16
+ Harassment, discrimination, threats, sexualized conduct, sustained disruption,
17
+ doxing, or publication of another person's private information are not
18
+ acceptable.
19
+
20
+ ## Enforcement
21
+
22
+ Report conduct concerns privately to `conduct@olyxai.io`. Maintainers may edit
23
+ or remove contributions, issue warnings, temporarily restrict participation, or
24
+ permanently ban participants when necessary. Reports will be handled as
25
+ confidentially as reasonably possible, with conflicts of interest recused.
26
+
27
+ This policy applies in project spaces and when someone is publicly representing
28
+ the project.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,63 @@
1
+ # Contributing
2
+
3
+ Thank you for improving Olyx Guardrails.
4
+
5
+ ## Development setup
6
+
7
+ ```bash
8
+ rbenv install
9
+ bundle install
10
+ bundle exec rake test
11
+ COVERAGE=true bundle exec rake test
12
+ bundle exec rubocop --cache false
13
+ bundle exec ruby script/flog_gate.rb
14
+ bundle exec rubycritic -f console -f json -p tmp/rubycritic
15
+ ruby script/rubycritic_gate.rb tmp/rubycritic/report.json
16
+ bundle exec appraisal install
17
+ bundle exec appraisal rake test
18
+ ```
19
+
20
+ Ruby 3.4 or newer is supported. Changes must remain compatible with the oldest
21
+ supported Ruby unless the same pull request deliberately changes the gem's
22
+ requirement.
23
+
24
+ RubyCritic is a blocking regression gate configured in `.rubycritic.yml`.
25
+ Do not lower its baseline to merge a change. Refactor new hot spots and ratchet
26
+ the minimum upward when sustained improvements raise the measured score.
27
+ The minimum score is 95; new files must remain focused on one reason to change,
28
+ and every production file must remain A-rated. RubyCritic smells, duplication,
29
+ and per-file complexity are review signals, not automatic design instructions:
30
+ address genuine responsibility or clarity problems, but do not introduce proxy
31
+ methods, unnecessary indirection, or metaprogramming merely to silence a
32
+ heuristic.
33
+
34
+ Flog is also a blocking structural gate: ordinary methods must score at most
35
+ 10, and each class or module must total at most 60. Do not split cohesive code,
36
+ hide behavior behind dynamic dispatch, or weaken a public API merely to improve
37
+ a score. A public DSL or metaprogramming macro may be listed in
38
+ `.flog_exemptions.yml` only when it is the clearest design; the entry must use
39
+ Flog's fully-qualified method name and contain an explicit DSL/metaprogramming
40
+ reason. Stale or unexplained exemptions fail CI.
41
+
42
+ The Appraisal matrix covers Rails 7.2, 8.0, and 8.1. Rails integration changes
43
+ must pass every configured Rails line while the standalone core remains free of
44
+ Rails runtime dependencies.
45
+
46
+ ## Pull requests
47
+
48
+ 1. Open an issue first for substantial API or policy changes.
49
+ 2. Keep each pull request focused and include tests for behavior changes.
50
+ 3. Add adversarial regression tests for security-sensitive fixes.
51
+ 4. Update README, API reference, examples, and changelog when public behavior
52
+ changes.
53
+ 5. Confirm tests, RuboCop, Flog, RubyCritic, syntax checks, and gem packaging
54
+ pass locally.
55
+
56
+ Never include real credentials, personal data, production endpoints, or
57
+ customer content in fixtures. Use clearly synthetic values.
58
+
59
+ By submitting a contribution, you agree that it is licensed under the
60
+ Apache-2.0 license used by this project.
61
+
62
+ Security vulnerabilities must follow [SECURITY.md](SECURITY.md), not the public
63
+ issue tracker.
data/LICENSE ADDED
@@ -0,0 +1,134 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other transformations
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf to the copyright owner.
50
+
51
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
52
+ whom a Contribution has been received by the Licensor and included
53
+ within the Work.
54
+
55
+ 2. Grant of Copyright License. Subject to the terms and conditions of
56
+ this License, each Contributor hereby grants to You a perpetual,
57
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
58
+ copyright license to reproduce, prepare Derivative Works of,
59
+ publicly display, publicly perform, sublicense, and distribute the
60
+ Work and such Derivative Works in Source or Object form.
61
+
62
+ 3. Grant of Patent License. Subject to the terms and conditions of
63
+ this License, each Contributor hereby grants to You a perpetual,
64
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
65
+ (except as stated in this section) patent license to make, have made,
66
+ use, offer to sell, sell, import, and otherwise transfer the Work,
67
+ where such license applies only to those patent claims licensable
68
+ by such Contributor that are necessarily infringed by their
69
+ Contribution(s) alone or by the combination of their Contribution(s)
70
+ with the Work to which such Contribution(s) was submitted.
71
+
72
+ 4. Redistribution. You may reproduce and distribute copies of the
73
+ Work or Derivative Works thereof in any medium, with or without
74
+ modifications, and in Source or Object form, provided that You
75
+ meet the following conditions:
76
+
77
+ (a) You must give any other recipients of the Work or Derivative
78
+ Works a copy of this License; and
79
+
80
+ (b) You must cause any modified files to carry prominent notices
81
+ stating that You changed the files; and
82
+
83
+ (c) You must retain, in the Source form of any Derivative Works
84
+ that You distribute, all copyright, patent, trademark, and
85
+ attribution notices from the Source form of the Work,
86
+ excluding those notices that do not pertain to any part of
87
+ the Derivative Works; and
88
+
89
+ (d) If the Work includes a "NOTICE" text file, you must include a
90
+ readable copy of the attribution notices contained within such
91
+ NOTICE file.
92
+
93
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
94
+ any Contribution intentionally submitted for inclusion in the Work
95
+ shall be under the terms and conditions of this License, without
96
+ any additional terms or conditions.
97
+
98
+ 6. Trademarks. This License does not grant permission to use the trade
99
+ names, trademarks, service marks, or product names of the Licensor.
100
+
101
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
102
+ to in writing, Licensor provides the Work on an "AS IS" BASIS,
103
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
104
+ implied, including, without limitation, any conditions of TITLE,
105
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
106
+ PURPOSE.
107
+
108
+ 8. Limitation of Liability. In no event and under no legal theory,
109
+ whether in tort (including negligence), contract, or otherwise,
110
+ shall any Contributor be liable to You for damages, including any
111
+ direct, indirect, special, incidental, or exemplary damages of any
112
+ character arising as a result of this License or out of the use or
113
+ inability to use the Work.
114
+
115
+ 9. Accepting Warranty or Additional Liability. While redistributing
116
+ the Work or Derivative Works thereof, You may choose to offer, and
117
+ charge a fee for, acceptance of support, warranty, indemnity, or
118
+ other liability obligations consistent with this License. However,
119
+ in accepting such obligations, You may offer such obligations only
120
+ on Your own behalf and on Your sole responsibility.
121
+
122
+ Copyright 2026 Moses Njoroge / Olyx Labs
123
+
124
+ Licensed under the Apache License, Version 2.0 (the "License");
125
+ you may not use this file except in compliance with the License.
126
+ You may obtain a copy of the License at
127
+
128
+ http://www.apache.org/licenses/LICENSE-2.0
129
+
130
+ Unless required by applicable law or agreed to in writing, software
131
+ distributed under the License is distributed on an "AS IS" BASIS,
132
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
133
+ implied. See the License for the specific language governing
134
+ permissions and limitations under the License.