Class: PinnedEvent
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PinnedEvent
- Defined in:
- app/models/pinned_event.rb
Overview
A conversation event pinned to one or more Goals by Mneme to protect it from viewport eviction. Pinned events appear in the Goals section of the viewport, giving the main agent access to critical context that would otherwise scroll out of the sliding window.
Pinning is goal-scoped: when all Goals referencing a pin complete, the pin is automatically released (reference-counted cleanup).
Constant Summary collapse
- MAX_DISPLAY_TEXT_LENGTH =
Display text limit — enough to recognize content, cheap on tokens.
200
Instance Attribute Summary collapse
-
#display_text ⇒ String
Truncated event content (~200 chars) shown in the Goals section.
Instance Method Summary collapse
-
#orphaned ⇒ ActiveRecord::Relation
Pinned events with no remaining active goals — safe to release.
-
#token_cost ⇒ Integer
Token cost estimate for viewport budget accounting.
Instance Attribute Details
#display_text ⇒ String
Returns truncated event content (~200 chars) shown in the Goals section.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/pinned_event.rb', line 13 class PinnedEvent < ApplicationRecord # Display text limit — enough to recognize content, cheap on tokens. MAX_DISPLAY_TEXT_LENGTH = 200 belongs_to :event has_many :goal_pinned_events, dependent: :destroy has_many :goals, through: :goal_pinned_events validates :display_text, presence: true, length: {maximum: MAX_DISPLAY_TEXT_LENGTH} validates :event_id, uniqueness: true # Pinned events with no remaining active goals — safe to release. # # @return [ActiveRecord::Relation] scope :orphaned, -> { where.not( "EXISTS (SELECT 1 FROM goal_pinned_events gpe " \ "JOIN goals ON goals.id = gpe.goal_id " \ "WHERE gpe.pinned_event_id = pinned_events.id " \ "AND goals.status = 'active')" ) } # @return [Integer] token cost estimate for viewport budget accounting def token_cost [(display_text.bytesize / Event::BYTES_PER_TOKEN.to_f).ceil, 1].max end end |
Instance Method Details
#orphaned ⇒ ActiveRecord::Relation
Pinned events with no remaining active goals — safe to release.
28 29 30 31 32 33 34 35 |
# File 'app/models/pinned_event.rb', line 28 scope :orphaned, -> { where.not( "EXISTS (SELECT 1 FROM goal_pinned_events gpe " \ "JOIN goals ON goals.id = gpe.goal_id " \ "WHERE gpe.pinned_event_id = pinned_events.id " \ "AND goals.status = 'active')" ) } |
#token_cost ⇒ Integer
Returns token cost estimate for viewport budget accounting.
38 39 40 |
# File 'app/models/pinned_event.rb', line 38 def token_cost [(display_text.bytesize / Event::BYTES_PER_TOKEN.to_f).ceil, 1].max end |