Class: ClaudeMemory::Domain::Observation
- Inherits:
-
Object
- Object
- ClaudeMemory::Domain::Observation
- Defined in:
- lib/claude_memory/domain/observation.rb
Overview
Domain model representing an episodic observation — “what happened”, as opposed to a Fact’s “what is true”. Instances are immutable (frozen).
Priority follows Mastra’s traffic-light scheme and is an internal signal for the Observer/Reflector pipeline: 1 = important (🔴), 2 = maybe (🟡), 3 = info only (🟢). Only 🔴 is meant to survive into the actor’s prompt.
Constant Summary collapse
- KINDS =
%w[user_statement agent_action tool_result preference decision event].freeze
- IMPORTANT =
1- MAYBE =
2- INFO =
3- PROMOTION_THRESHOLD =
Minimum corroboration (repeated sightings) before an observation may be promoted to a structured fact. The anti-hallucination gate: a one-off mention never becomes a committed fact.
2
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#consolidated_into ⇒ Object
readonly
Returns the value of attribute consolidated_into.
-
#corroboration_count ⇒ Object
readonly
Returns the value of attribute corroboration_count.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#observed_at ⇒ Object
readonly
Returns the value of attribute observed_at.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
-
#promoted_at ⇒ Object
readonly
Returns the value of attribute promoted_at.
-
#promoted_fact_id ⇒ Object
readonly
Returns the value of attribute promoted_fact_id.
-
#reflected_at ⇒ Object
readonly
Returns the value of attribute reflected_at.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#source_content_item_id ⇒ Object
readonly
Returns the value of attribute source_content_item_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#token_count ⇒ Object
readonly
Returns the value of attribute token_count.
Instance Method Summary collapse
-
#active? ⇒ Boolean
True when the observation has not been consolidated away.
-
#consolidated? ⇒ Boolean
True when the Reflector has merged this into another.
-
#corroborated?(threshold) ⇒ Boolean
True when corroborated enough to be promotion-eligible.
-
#expired? ⇒ Boolean
True when the Reflector retired this on TTL.
-
#global? ⇒ Boolean
True when scope is “global”.
-
#important? ⇒ Boolean
True for 🔴 — the only priority shown to the actor.
-
#initialize(attributes) ⇒ Observation
constructor
A new instance of Observation.
-
#promoted? ⇒ Boolean
True once promoted into a structured fact.
-
#to_h ⇒ Hash
All attributes as a plain hash.
Constructor Details
#initialize(attributes) ⇒ Observation
Returns a new instance of Observation.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/claude_memory/domain/observation.rb', line 29 def initialize(attributes) @id = attributes[:id] @body = attributes[:body] @kind = attributes[:kind] || "event" @priority = attributes[:priority] || INFO @scope = attributes[:scope] || "project" @project_path = attributes[:project_path] @source_content_item_id = attributes[:source_content_item_id] @consolidated_into = attributes[:consolidated_into] @token_count = attributes[:token_count] @status = attributes[:status] || "active" @session_id = attributes[:session_id] @observed_at = attributes[:observed_at] @created_at = attributes[:created_at] @reflected_at = attributes[:reflected_at] @corroboration_count = attributes[:corroboration_count] || 1 @promoted_at = attributes[:promoted_at] @promoted_fact_id = attributes[:promoted_fact_id] validate! freeze end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def body @body end |
#consolidated_into ⇒ Object (readonly)
Returns the value of attribute consolidated_into.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def consolidated_into @consolidated_into end |
#corroboration_count ⇒ Object (readonly)
Returns the value of attribute corroboration_count.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def corroboration_count @corroboration_count end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def id @id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def kind @kind end |
#observed_at ⇒ Object (readonly)
Returns the value of attribute observed_at.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def observed_at @observed_at end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def priority @priority end |
#project_path ⇒ Object (readonly)
Returns the value of attribute project_path.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def project_path @project_path end |
#promoted_at ⇒ Object (readonly)
Returns the value of attribute promoted_at.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def promoted_at @promoted_at end |
#promoted_fact_id ⇒ Object (readonly)
Returns the value of attribute promoted_fact_id.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def promoted_fact_id @promoted_fact_id end |
#reflected_at ⇒ Object (readonly)
Returns the value of attribute reflected_at.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def reflected_at @reflected_at end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def scope @scope end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def session_id @session_id end |
#source_content_item_id ⇒ Object (readonly)
Returns the value of attribute source_content_item_id.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def source_content_item_id @source_content_item_id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def status @status end |
#token_count ⇒ Object (readonly)
Returns the value of attribute token_count.
22 23 24 |
# File 'lib/claude_memory/domain/observation.rb', line 22 def token_count @token_count end |
Instance Method Details
#active? ⇒ Boolean
Returns true when the observation has not been consolidated away.
53 54 55 |
# File 'lib/claude_memory/domain/observation.rb', line 53 def active? status == "active" end |
#consolidated? ⇒ Boolean
Returns true when the Reflector has merged this into another.
58 59 60 |
# File 'lib/claude_memory/domain/observation.rb', line 58 def consolidated? status == "consolidated" end |
#corroborated?(threshold) ⇒ Boolean
Returns true when corroborated enough to be promotion-eligible.
73 74 75 |
# File 'lib/claude_memory/domain/observation.rb', line 73 def corroborated?(threshold) corroboration_count >= threshold end |
#expired? ⇒ Boolean
Returns true when the Reflector retired this on TTL.
63 64 65 |
# File 'lib/claude_memory/domain/observation.rb', line 63 def expired? status == "expired" end |
#global? ⇒ Boolean
Returns true when scope is “global”.
83 84 85 |
# File 'lib/claude_memory/domain/observation.rb', line 83 def global? scope == "global" end |
#important? ⇒ Boolean
Returns true for 🔴 — the only priority shown to the actor.
78 79 80 |
# File 'lib/claude_memory/domain/observation.rb', line 78 def important? priority == IMPORTANT end |
#promoted? ⇒ Boolean
Returns true once promoted into a structured fact.
68 69 70 |
# File 'lib/claude_memory/domain/observation.rb', line 68 def promoted? !promoted_at.nil? end |
#to_h ⇒ Hash
Returns all attributes as a plain hash.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/claude_memory/domain/observation.rb', line 88 def to_h { id: id, body: body, kind: kind, priority: priority, scope: scope, project_path: project_path, source_content_item_id: source_content_item_id, consolidated_into: consolidated_into, token_count: token_count, status: status, session_id: session_id, observed_at: observed_at, created_at: created_at, reflected_at: reflected_at, corroboration_count: corroboration_count, promoted_at: promoted_at, promoted_fact_id: promoted_fact_id } end |