Class: Aidp::PromptOptimization::TaskContext

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/prompt_optimization/relevance_scorer.rb

Overview

Represents the context for a task

Contains information about the current work being done, used to calculate relevance scores for fragments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_type: nil, description: nil, affected_files: [], step_name: nil, tags: []) ⇒ TaskContext

Returns a new instance of TaskContext.

Parameters:

  • task_type (Symbol) (defaults to: nil)

    Type of task (:feature, :bugfix, :refactor, etc.)

  • description (String) (defaults to: nil)

    Task description

  • affected_files (Array<String>) (defaults to: [])

    List of files being modified

  • step_name (String) (defaults to: nil)

    Current work loop step name

  • tags (Array<String>) (defaults to: [])

    Additional context tags



218
219
220
221
222
223
224
225
226
227
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 218

def initialize(task_type: nil, description: nil, affected_files: [], step_name: nil, tags: [])
  @task_type = task_type
  @description = description
  @affected_files = affected_files || []
  @step_name = step_name
  @tags = tags || []

  # Extract additional tags from description if provided
  extract_tags_from_description if @description
end

Instance Attribute Details

#affected_filesObject

Returns the value of attribute affected_files.



211
212
213
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 211

def affected_files
  @affected_files
end

#descriptionObject

Returns the value of attribute description.



211
212
213
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 211

def description
  @description
end

#step_nameObject

Returns the value of attribute step_name.



211
212
213
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 211

def step_name
  @step_name
end

#tagsObject

Returns the value of attribute tags.



211
212
213
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 211

def tags
  @tags
end

#task_typeObject

Returns the value of attribute task_type.



211
212
213
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 211

def task_type
  @task_type
end

Instance Method Details

#extract_tags_from_descriptionObject

Extract relevant tags from description text



230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 230

def extract_tags_from_description
  return unless @description

  desc_lower = @description.downcase

  @tags << "testing" if /test|spec|coverage/.match?(desc_lower)
  @tags << "security" if /security|auth|permission/.match?(desc_lower)
  @tags << "performance" if /performance|speed|optimization/.match?(desc_lower)
  @tags << "database" if /database|sql|migration/.match?(desc_lower)
  @tags << "api" if /\bapi\b|endpoint|rest/.match?(desc_lower)
  @tags << "ui" if /\bui\b|interface|view/.match?(desc_lower)

  @tags.uniq!
end

#to_hObject



245
246
247
248
249
250
251
252
253
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 245

def to_h
  {
    task_type: @task_type,
    description: @description,
    affected_files: @affected_files,
    step_name: @step_name,
    tags: @tags
  }
end