Class: Observ::Generators::AddPhaseTrackingGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/observ/add_phase_tracking/add_phase_tracking_generator.rb

Overview

Generator for adding phase tracking to Observ chats

This generator adds the ability to track multi-phase agent workflows by adding a current_phase column and including the AgentPhaseable concern.

Prerequisites:

- Observ chat feature already installed (rails generate observ:install:chat)
- Chat model exists at app/models/chat.rb
- ObservChatEnhancements concern exists

Usage:

rails generate observ:add_phase_tracking

What it does:

1. Adds current_phase column to chats table
2. Includes Observ::AgentPhaseable in ObservChatEnhancements

Instance Method Summary collapse

Instance Method Details

#check_prerequisitesObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/observ/add_phase_tracking/add_phase_tracking_generator.rb', line 30

def check_prerequisites
  say "\n"
  say "=" * 80, :cyan
  say "Adding Phase Tracking to Observ Chats", :cyan
  say "=" * 80, :cyan
  say "\n"

  check_chat_model_exists
  check_concern_exists
end

#create_migrationObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/observ/add_phase_tracking/add_phase_tracking_generator.rb', line 41

def create_migration
  say "Creating migration for current_phase column...", :cyan
  say "-" * 80, :cyan

  migration_template "migration.rb.tt",
                    "db/migrate/add_phase_tracking_to_chats.rb"

  say "  ✓ Created migration for current_phase column", :green
  say "\n"
end

#show_post_install_instructionsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/generators/observ/add_phase_tracking/add_phase_tracking_generator.rb', line 72

def show_post_install_instructions
  say "\n"
  say "=" * 80, :green
  say "Phase Tracking Installation Complete!", :green
  say "=" * 80, :green
  say "\n"

  say "Next steps:", :cyan
  say "\n"

  say "1. Run migrations:", :cyan
  say "   rails db:migrate", :white
  say "\n"

  say "2. (Optional) Define allowed phases in your Chat model:", :cyan
  say "   # app/models/chat.rb", :white
  say "   class Chat < ApplicationRecord", :white
  say "     # ...", :white
  say "     def allowed_phases", :white
  say "       %w[scoping research writing review]", :white
  say "     end", :white
  say "   end", :white
  say "\n"

  say "3. Use phase transitions in your agents:", :cyan
  say "   chat.transition_to_phase('research')", :white
  say "   chat.in_phase?('research') # => true", :white
  say "   chat.current_phase # => 'research'", :white
  say "\n"

  say "Documentation:", :cyan
  say "  • See app/models/concerns/observ/agent_phaseable.rb for full API", :white
  say "\n"
end

#update_chat_enhancementsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/generators/observ/add_phase_tracking/add_phase_tracking_generator.rb', line 52

def update_chat_enhancements
  say "Updating ObservChatEnhancements concern...", :cyan
  say "-" * 80, :cyan

  concern_path = Rails.root.join("app/models/concerns/observ_chat_enhancements.rb")
  concern_content = File.read(concern_path)

  if concern_content.include?("Observ::AgentPhaseable")
    say "  ⚠ AgentPhaseable already included in ObservChatEnhancements", :yellow
  else
    inject_into_file concern_path,
                    after: "include Observ::ObservabilityInstrumentation\n" do
      "    include Observ::AgentPhaseable\n"
    end
    say "  ✓ Included AgentPhaseable in ObservChatEnhancements", :green
  end

  say "\n"
end