Class: Goal
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Goal
- Defined in:
- app/models/goal.rb
Overview
A persistent objective tracked by the analytical brain during a session. Goals form a two-level hierarchy: root goals represent high-level objectives (semantic episodes), while sub-goals are TODO-style steps rendered as checklist items in the agent’s system prompt.
The analytical brain creates and completes goals; the main agent sees them in its context window but never manages them directly.
Constant Summary collapse
- STATUSES =
%w[active completed].freeze
Instance Method Summary collapse
-
#as_summary ⇒ Hash{String => Object}
Serializes this goal for ActionCable broadcast and TUI display.
-
#cascade_completion! ⇒ void
Cascades completion to all active sub-goals.
-
#completed? ⇒ Boolean
True if this goal has been completed.
-
#root? ⇒ Boolean
True if this is a root goal (no parent).
Instance Method Details
#as_summary ⇒ Hash{String => Object}
Serializes this goal for ActionCable broadcast and TUI display. Includes nested sub-goals for root goals.
54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/goal.rb', line 54 def as_summary { "id" => id, "description" => description, "status" => status, "sub_goals" => sub_goals.map { |sub| {"id" => sub.id, "description" => sub.description, "status" => sub.status} } } end |
#cascade_completion! ⇒ void
This method returns an undefined value.
Cascades completion to all active sub-goals. Called when a root goal is finished — remaining sub-items are implicitly resolved because the semantic episode that spawned them has ended.
Uses update_all to avoid N per-record after_commit broadcasts; the caller (AnalyticalBrain::Tools::FinishGoal) wraps the whole operation in a transaction so the root goal’s single broadcast includes the cascaded state.
44 45 46 47 |
# File 'app/models/goal.rb', line 44 def cascade_completion! now = Time.current sub_goals.active.update_all(status: "completed", completed_at: now, updated_at: now) end |
#completed? ⇒ Boolean
Returns true if this goal has been completed.
29 |
# File 'app/models/goal.rb', line 29 def completed? = status == "completed" |
#root? ⇒ Boolean
Returns true if this is a root goal (no parent).
32 |
# File 'app/models/goal.rb', line 32 def root? = !parent_goal_id |