Class: Engram::PersistencePolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/engram/persistence_policy.rb

Overview

Default gate applied before memories are persisted. It keeps obvious secrets and transient task-progress updates out of durable memory, and can redact caller-supplied denylist patterns before storage.

Constant Summary collapse

SECRET_PATTERNS =
[
  /\b(?:api[_ -]?key|token|secret|password)\b\s*(?:is|=|:)\s+(?=\S*[0-9_-])\S{8,}/i,
  /\bsk-[A-Za-z0-9_-]{6,}\b/,
  /\b(?:ghp|github_pat)_[A-Za-z0-9_]{10,}\b/
].freeze
TRANSIENT_PATTERNS =
[
  /\b(?:fixed|resolved|done|completed|finished)\b.*\b(?:today|now|this session)\b/i,
  /\b(?:today|now|this session)\b.*\b(?:fixed|resolved|done|completed|finished)\b/i
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(denylist_patterns: []) ⇒ PersistencePolicy

Returns a new instance of PersistencePolicy.



19
20
21
# File 'lib/engram/persistence_policy.rb', line 19

def initialize(denylist_patterns: [])
  @denylist_patterns = denylist_patterns
end

Instance Method Details

#call(record) ⇒ Object



23
24
25
26
27
# File 'lib/engram/persistence_policy.rb', line 23

def call(record)
  return nil if reject?(record.content)

  redact(record)
end