Class: Mneme::Tools::AttachMessagesToGoals
- Inherits:
-
Tools::Base
- Object
- Tools::Base
- Mneme::Tools::AttachMessagesToGoals
- Defined in:
- lib/mneme/tools/attach_messages_to_goals.rb
Overview
Pins critical messages to active Goals so they survive viewport eviction. Mneme calls this when it sees important messages (user instructions, key decisions, critical corrections) approaching the eviction zone.
Messages are pinned via a many-to-many join: one message can be attached to multiple Goals. When all referencing Goals complete, the pin is automatically released (reference-counted cleanup in Goal#release_orphaned_pins!).
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(input) ⇒ String
Confirmation with link count, or error description.
-
#initialize(main_session:) ⇒ AttachMessagesToGoals
constructor
A new instance of AttachMessagesToGoals.
Methods inherited from Tools::Base
Constructor Details
#initialize(main_session:) ⇒ AttachMessagesToGoals
Returns a new instance of AttachMessagesToGoals.
35 36 37 |
# File 'lib/mneme/tools/attach_messages_to_goals.rb', line 35 def initialize(main_session:, **) @session = main_session end |
Class Method Details
.description ⇒ Object
15 |
# File 'lib/mneme/tools/attach_messages_to_goals.rb', line 15 def self.description = "Pin critical messages to goals so they survive viewport eviction." |
.input_schema ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mneme/tools/attach_messages_to_goals.rb', line 17 def self.input_schema { type: "object", properties: { message_ids: { type: "array", items: {type: "integer"} }, goal_ids: { type: "array", items: {type: "integer"} } }, required: %w[message_ids goal_ids] } end |
.tool_name ⇒ Object
13 |
# File 'lib/mneme/tools/attach_messages_to_goals.rb', line 13 def self.tool_name = "attach_messages_to_goals" |
Instance Method Details
#execute(input) ⇒ String
Returns confirmation with link count, or error description.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mneme/tools/attach_messages_to_goals.rb', line 41 def execute(input) = Array(input["message_ids"]).map(&:to_i).uniq goal_ids = Array(input["goal_ids"]).map(&:to_i).uniq return "Error: message_ids cannot be empty" if .empty? return "Error: goal_ids cannot be empty" if goal_ids.empty? = @session..where(id: ) all_goals = @session.goals goals = all_goals.active.where(id: goal_ids) = - .pluck(:id) inactive_goal_ids = goal_ids - goals.pluck(:id) errors = [] errors << "Messages not found: #{.join(", ")}" if .any? if inactive_goal_ids.any? completed_ids = all_goals.completed.where(id: inactive_goal_ids).pluck(:id) not_found_ids = inactive_goal_ids - completed_ids errors << "Goals already completed: #{completed_ids.join(", ")}" if completed_ids.any? errors << "Goals not found: #{not_found_ids.join(", ")}" if not_found_ids.any? end return "Error: #{errors.join("; ")}" if errors.any? attached = attach(, goals) "Pinned #{attached} message-goal links" end |