Class: ClaudeMemory::Domain::Observation

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Observation

Returns a new instance of Observation.

Parameters:

  • attributes (Hash)

    observation attributes (see column list)

Raises:

  • (ArgumentError)

    if body is blank or priority is out of range



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

#bodyObject (readonly)

Returns the value of attribute body.



22
23
24
# File 'lib/claude_memory/domain/observation.rb', line 22

def body
  @body
end

#consolidated_intoObject (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_countObject (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_atObject (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

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/claude_memory/domain/observation.rb', line 22

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind.



22
23
24
# File 'lib/claude_memory/domain/observation.rb', line 22

def kind
  @kind
end

#observed_atObject (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

#priorityObject (readonly)

Returns the value of attribute priority.



22
23
24
# File 'lib/claude_memory/domain/observation.rb', line 22

def priority
  @priority
end

#project_pathObject (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

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

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_atObject (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

#scopeObject (readonly)

Returns the value of attribute scope.



22
23
24
# File 'lib/claude_memory/domain/observation.rb', line 22

def scope
  @scope
end

#session_idObject (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_idObject (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

#statusObject (readonly)

Returns the value of attribute status.



22
23
24
# File 'lib/claude_memory/domain/observation.rb', line 22

def status
  @status
end

#token_countObject (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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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”.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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_hHash

Returns all attributes as a plain hash.

Returns:

  • (Hash)

    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