Class: Aidp::Planning::Generators::LegacyResearchPlanner

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/planning/generators/legacy_research_planner.rb

Overview

Generates user research plan for existing/legacy codebases Analyzes code structure to identify features and suggest research priorities Uses Zero Framework Cognition (ZFC) for research question generation

Instance Method Summary collapse

Constructor Details

#initialize(ai_decision_engine:, prompt: nil, config: nil) ⇒ LegacyResearchPlanner

Returns a new instance of LegacyResearchPlanner.



13
14
15
16
17
# File 'lib/aidp/planning/generators/legacy_research_planner.rb', line 13

def initialize(ai_decision_engine:, prompt: nil, config: nil)
  @ai_decision_engine = ai_decision_engine
  @prompt = prompt || TTY::Prompt.new
  @config = config || Aidp::Config.agile_config
end

Instance Method Details

#format_as_markdown(plan) ⇒ String

Format research plan as markdown

Parameters:

  • plan (Hash)

    Research plan structure

Returns:

  • (String)

    Markdown formatted research plan



63
64
65
66
67
68
69
70
71
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/aidp/planning/generators/legacy_research_planner.rb', line 63

def format_as_markdown(plan)
  Aidp.log_debug("legacy_research_planner", "format_as_markdown")

  output = ["# Legacy User Research Plan", ""]
  output << "**Generated:** #{plan[:metadata][:generated_at]}"
  output << "**Codebase:** #{plan[:metadata][:codebase_path]}"
  output << "**Features Identified:** #{plan[:metadata][:feature_count]}"
  output << "**Files Analyzed:** #{plan[:metadata][:file_count]}"
  output << ""

  output << "## Overview"
  output << ""
  output << plan[:overview]
  output << ""

  output << "## Codebase Summary"
  output << ""
  output << plan[:codebase_summary]
  output << ""

  output << "## Current Features"
  output << ""
  output << "Features identified in the codebase:"
  output << ""
  plan[:current_features].each_with_index do |feature, idx|
    output << "### #{idx + 1}. #{feature[:name]}"
    output << ""
    output << "**Description:** #{feature[:description]}"
    output << ""
    output << "**Entry Points:** #{feature[:entry_points]&.join(", ") || "Unknown"}"
    output << ""
    output << "**Status:** #{feature[:status]}"
    output << ""
  end

  output << "## Research Questions"
  output << ""
  output << "Key questions to answer about user experience:"
  output << ""
  plan[:research_questions].each_with_index do |question, idx|
    output << "#{idx + 1}. #{question[:question]}"
    output << "   - **Category:** #{question[:category]}"
    output << "   - **Priority:** #{question[:priority]}"
    output << ""
  end

  output << "## Recommended Research Methods"
  output << ""
  plan[:research_methods].each do |method|
    output << "### #{method[:name]}"
    output << ""
    output << method[:description]
    output << ""
    output << "**When to Use:** #{method[:when_to_use]}"
    output << ""
    output << "**Expected Insights:** #{method[:expected_insights]}"
    output << ""
  end

  output << "## Testing Priorities"
  output << ""
  output << "Features/flows to focus on first:"
  output << ""
  plan[:testing_priorities].each_with_index do |priority, idx|
    output << "#{idx + 1}. **#{priority[:feature]}** (Priority: #{priority[:priority]})"
    output << "   - Rationale: #{priority[:rationale]}"
    output << "   - Focus Areas: #{priority[:focus_areas]&.join(", ")}"
    output << ""
  end

  output << "## User Segments"
  output << ""
  plan[:user_segments].each do |segment|
    output << "### #{segment[:name]}"
    output << ""
    output << segment[:description]
    output << ""
    output << "**Research Focus:** #{segment[:research_focus]}"
    output << ""
  end

  output << "## Improvement Opportunities"
  output << ""
  output << "Based on codebase analysis:"
  output << ""
  plan[:improvement_opportunities].each_with_index do |opportunity, idx|
    output << "#{idx + 1}. **#{opportunity[:title]}**"
    output << "   - Description: #{opportunity[:description]}"
    output << "   - Impact: #{opportunity[:impact]}"
    output << "   - Effort: #{opportunity[:effort]}"
    output << ""
  end

  output << "## Research Timeline"
  output << ""
  plan[:timeline].each do |phase|
    output << "- **#{phase[:phase]}:** #{phase[:duration]}"
  end
  output << ""

  output.join("\n")
end

#generate(codebase_path:, language: nil, known_users: nil) ⇒ Hash

Generate legacy research plan from codebase analysis

Parameters:

  • codebase_path (String)

    Path to codebase directory

  • language (String) (defaults to: nil)

    Primary language/framework (optional)

  • known_users (String) (defaults to: nil)

    Known user segments (optional)

Returns:

  • (Hash)

    Research plan structure



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/aidp/planning/generators/legacy_research_planner.rb', line 24

def generate(codebase_path:, language: nil, known_users: nil)
  Aidp.log_debug("legacy_research_planner", "generate",
    codebase_path: codebase_path,
    language: language)

  # Analyze codebase structure
  codebase_analysis = analyze_codebase(codebase_path, language)

  Aidp.log_debug("legacy_research_planner", "codebase_analyzed",
    features: codebase_analysis[:features].size,
    files: codebase_analysis[:file_count])

  # Use AI to generate research plan
  research_plan = generate_research_plan_with_ai(codebase_analysis, known_users)

  {
    overview: research_plan[:overview],
    current_features: research_plan[:current_features],
    research_questions: research_plan[:research_questions],
    research_methods: research_plan[:research_methods],
    testing_priorities: research_plan[:testing_priorities],
    user_segments: research_plan[:user_segments],
    improvement_opportunities: research_plan[:improvement_opportunities],
    timeline: research_plan[:timeline],
    codebase_summary: codebase_analysis[:summary],
    metadata: {
      generated_at: Time.now.iso8601,
      codebase_path: codebase_path,
      language: language,
      feature_count: research_plan[:current_features]&.size || 0,
      file_count: codebase_analysis[:file_count],
      research_question_count: research_plan[:research_questions]&.size || 0
    }
  }
end