Module: Legion::Extensions::Assessor::Helpers::Classifier

Extended by:
Classifier
Included in:
Classifier
Defined in:
lib/legion/extensions/assessor/helpers/classifier.rb

Constant Summary collapse

CLASSIFICATION_SCHEMA =
{
  type:       :object,
  properties: {
    priority:             { type: :string, enum: %w[low medium high critical] },
    complexity:           {
      type: :string,
      enum: %w[trivial_fix simple_bug moderate_feature complex_feature critical_production background]
    },
    work_type:            { type: :string, enum: %w[bug_fix feature refactor test docs dependency security] },
    language:             { type: :string },
    estimated_difficulty: { type: :number, minimum: 0.0, maximum: 1.0 }
  },
  required:   %w[priority complexity work_type estimated_difficulty]
}.freeze

Instance Method Summary collapse

Instance Method Details

#build_prompt(work_item:) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/legion/extensions/assessor/helpers/classifier.rb', line 52

def build_prompt(work_item:)
  <<~PROMPT
    Classify this work item for an autonomous coding pipeline.

    Source: #{work_item[:source]}
    Reference: #{work_item[:source_ref]}
    Title: #{work_item[:title]}
    Description: #{work_item[:description]}

    Classify the complexity, priority, work type, primary language, and estimated difficulty (0.0 to 1.0).

    Complexity levels:
    - trivial_fix: one-line change, obvious fix
    - simple_bug: clear bug, single file, straightforward
    - moderate_feature: multi-file change, needs planning
    - complex_feature: architectural change, multiple subsystems
    - critical_production: production outage, needs immediate fix with max capability
    - background: low-priority chore, minimal review needed
  PROMPT
end

#classification_schemaObject



48
49
50
# File 'lib/legion/extensions/assessor/helpers/classifier.rb', line 48

def classification_schema
  CLASSIFICATION_SCHEMA
end

#classify(work_item:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/legion/extensions/assessor/helpers/classifier.rb', line 25

def classify(work_item:)
  prompt = build_prompt(work_item: work_item)
  result = Legion::LLM::Prompt.extract(
    prompt,
    schema:  classification_schema,
    tools:   [],
    intent:  { capability: :moderate },
    caller:  { extension: 'lex-assessor', operation: 'classify' },
    agent:   {
      id:   'fleet:assessor',
      name: 'Fleet Assessor',
      type: :autonomous,
      goal: work_item[:title]
    },
    tracing: {
      trace_id:       work_item[:work_item_id],
      correlation_id: work_item[:source_ref]
    }
  )

  normalize_result(json_parse(result.message[:content]))
end

#difficulty_to_capability(difficulty) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/legion/extensions/assessor/helpers/classifier.rb', line 73

def difficulty_to_capability(difficulty)
  case difficulty
  when 0.0...0.3 then :basic
  when 0.3...0.6 then :moderate
  else :reasoning
  end
end