Class: Insika::EvidenceLedger
- Inherits:
-
Object
- Object
- Insika::EvidenceLedger
- Defined in:
- lib/insika/evidence.rb
Overview
The session evidence ledger (C4). A session-scoped SET with an ungrounded
counter: records every product id that entered the context via an
evidence-declared tool this session , plus the ungrounded
counter that feeds the daily metric. It is NOT a policy object — it records
and answers ids / ungrounded / lines; it never decides.
Constant Summary collapse
- MAX_IDS =
Oldest-evicted cap: a session that outlives it needs a real cap or the row grows forever.
1_000
Instance Attribute Summary collapse
-
#ungrounded ⇒ Object
readonly
Returns the value of attribute ungrounded.
Instance Method Summary collapse
-
#flush! ⇒ Object
-> self, flushed to the session record.
-
#ids ⇒ Object
-> the effective set for THIS turn: persisted session evidence (loaded at build) + the turn's new ids, deduped, capped.
-
#initialize(store: nil, session_id: nil) ⇒ EvidenceLedger
constructor
A new instance of EvidenceLedger.
-
#record(ids) ⇒ Object
The in-memory accumulator (the envelope appends, the validator/enforcer read the union).
- #ungrounded_count(claim) ⇒ Object
Constructor Details
#initialize(store: nil, session_id: nil) ⇒ EvidenceLedger
Returns a new instance of EvidenceLedger.
129 130 131 132 133 134 |
# File 'lib/insika/evidence.rb', line 129 def initialize(store: nil, session_id: nil) @store = store @session_id = session_id @ids = [] @ungrounded = 0 end |
Instance Attribute Details
#ungrounded ⇒ Object (readonly)
Returns the value of attribute ungrounded.
150 151 152 |
# File 'lib/insika/evidence.rb', line 150 def ungrounded @ungrounded end |
Instance Method Details
#flush! ⇒ Object
-> self, flushed to the session record. Idempotent. A store OR not-found failure is swallowed (evidence is audit — it must never fail a committed turn; a session purged mid-turn by forget_customer/session_purge reads as "nothing to append", never an explosion).
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/insika/evidence.rb', line 161 def flush! return self unless @store && @session_id @store.append_evidence(@session_id, ids: @ids, ungrounded: @ungrounded) @ids = [] @ungrounded = 0 self rescue Insika::Error self end |
#ids ⇒ Object
-> the effective set for THIS turn: persisted session evidence (loaded at build) + the turn's new ids, deduped, capped.
146 147 148 |
# File 'lib/insika/evidence.rb', line 146 def ids (session_ids + @ids).uniq.last(MAX_IDS) end |
#record(ids) ⇒ Object
The in-memory accumulator (the envelope appends, the validator/enforcer read the union). The PERSISTED list is appended on flush (Executor, stage 8) — the envelope never blocks on the store.
139 140 141 142 |
# File 'lib/insika/evidence.rb', line 139 def record(ids) @ids.concat(Array(ids).map(&:to_s).reject(&:empty?)) self end |
#ungrounded_count(claim) ⇒ Object
152 153 154 155 |
# File 'lib/insika/evidence.rb', line 152 def ungrounded_count(claim) @ungrounded += 1 claim end |