Class: Insika::Grounding

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/grounding.rb

Overview

— the profile-facing half of grounding: parse the pack's grounding data into the per-turn Grounding object (mode + matcher).

Data (on the AgentProfile):

{ "mode" => "flag"|"enforce"|"off",
"matcher" => { "sku" => "\b[A-Z]{2,4}\d{4,8}\b" } }

Absent = the whole feature is OFF (parity). The matcher is built ONCE per turn (profile parse) and cached on the Grounding object. A sku that does not compile, or exceeds 256 chars, is a ValidationError at build — the engine refuses only uncompileable data; a matcher with no sku matches nothing (grounding on is harmless but useless; doctor warns).

Constant Summary collapse

MODES =
%w[flag enforce off].freeze
SKU_MAX =
256

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode:, matcher:) ⇒ Grounding

Returns a new instance of Grounding.



36
37
38
39
# File 'lib/insika/grounding.rb', line 36

def initialize(mode:, matcher:)
  @mode = mode
  @matcher = matcher
end

Instance Attribute Details

#matcherObject (readonly)

Returns the value of attribute matcher.



24
25
26
# File 'lib/insika/grounding.rb', line 24

def matcher
  @matcher
end

#modeObject (readonly)

Returns the value of attribute mode.



24
25
26
# File 'lib/insika/grounding.rb', line 24

def mode
  @mode
end

Class Method Details

.parse(raw) ⇒ Object

raw: the profile's grounding Hash | nil | false -> Grounding | nil. nil/false = off. A non-Hash (e.g. true) reads as an empty config.



28
29
30
31
32
33
34
# File 'lib/insika/grounding.rb', line 28

def self.parse(raw)
  return nil if raw.nil? || raw == false

  h = Coercion.deep_stringify(raw.is_a?(Hash) ? raw : {})
  mode = MODES.include?(h["mode"].to_s) ? h["mode"].to_s : "flag" # default :flag
  new(mode: mode, matcher: GroundingMatcher.build(h["matcher"]))
end

Instance Method Details

#enforce?Boolean

Returns:

  • (Boolean)


41
# File 'lib/insika/grounding.rb', line 41

def enforce? = mode == "enforce"

#off?Boolean

Returns:

  • (Boolean)


42
# File 'lib/insika/grounding.rb', line 42

def off? = mode == "off"