Class: SkillBench::Execution::SourcePathResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/skill_bench/execution/source_path_resolver.rb

Overview

Resolves the source skill or workflow path for a given evaluation target.

Class Method Summary collapse

Class Method Details

.call(eval_folder_path:, skill_path: nil, skill_sources: {}) ⇒ String?

Resolves the source path using either an explicit override or the eval directory convention.

Examples:

Infer a skill source path (NEW format):

SkillBench::Execution::SourcePathResolver.call(
  eval_folder_path: 'evals/skills/rails-code-review/review-order'
)
# => "skills/rails-code-review"

Infer a skill source path (OLD format, returns category):

SkillBench::Execution::SourcePathResolver.call(
  eval_folder_path: 'evals/skills/code-quality/rails-code-review/review-order'
)
# => "skills/code-quality/rails-code-review"

Parameters:

  • eval_folder_path (String)

    Relative path to the eval directory.

  • skill_path (String, nil) (defaults to: nil)

    Optional explicit override for the source directory.

  • skill_sources (Hash) (defaults to: {})

    Optional skill source name → directory path mapping for fallback. When provided and local resolution does not yield an existing path, each source is checked.

Returns:

  • (String, nil)

    The resolved source path relative to the evaluator repo root, or nil if unmappable.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/skill_bench/execution/source_path_resolver.rb', line 26

def self.call(eval_folder_path:, skill_path: nil, skill_sources: {})
  return skill_path if skill_path && !skill_path.empty?

  segments = Pathname.new(eval_folder_path.to_s).each_filename.to_a

  local = resolve_skills_path(segments) || resolve_workflows_path(segments)

  unless local.nil? || skill_sources.empty?
    skill_name = extract_skill_name(segments)
    return local unless skill_name
    return local if skill_exists_at?(local)

    skill_sources.each_value do |source_path|
      candidate = find_skill_in_source(source_path, skill_name)
      return candidate if candidate
    end
  end

  local
end

.extract_skill_name(segments) ⇒ String?

Extracts the skill name from the eval path segments.

Parameters:

  • segments (Array<String>)

    Path segments

Returns:

  • (String, nil)

    Skill name or nil



51
52
53
54
55
56
57
58
59
# File 'lib/skill_bench/execution/source_path_resolver.rb', line 51

def self.extract_skill_name(segments)
  index = segments.rindex('skills')
  return nil unless index

  remaining = segments[(index + 1)..]
  return nil if remaining.empty?

  remaining[0]
end

.find_skill_in_source(source_path, skill_name) ⇒ String?

Finds a skill directory within a source path by name.

Parameters:

  • source_path (String)

    Root directory containing skill categories

  • skill_name (String)

    Name of the skill to find

Returns:

  • (String, nil)

    Path to the skill directory or nil



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/skill_bench/execution/source_path_resolver.rb', line 66

def self.find_skill_in_source(source_path, skill_name)
  return nil unless source_path && Dir.exist?(source_path)

  Dir.glob(File.join(source_path, '*')).each do |entry|
    next unless Dir.exist?(entry)

    candidate = File.join(entry, skill_name)
    return candidate if Dir.exist?(candidate) && File.exist?(File.join(candidate, 'SKILL.md'))
  end

  nil
end