Class: Goal

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

Instance Method Details

#as_summaryHash{String => Object}

Serializes this goal for ActionCable broadcast and TUI display. Includes nested sub-goals for root goals.

Returns:

  • (Hash{String => Object})

    with keys “id”, “description”, “status”, and “sub_goals” (Array of Hash with “id”, “description”, “status”)



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.

Returns:

  • (Boolean)

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

Returns:

  • (Boolean)

    true if this is a root goal (no parent)



32
# File 'app/models/goal.rb', line 32

def root? = !parent_goal_id