Class: Antigravity::SkillResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/antigravity/skill_resolver.rb

Overview

Resolves skill paths from various inputs: single skill dir, container dir, or GitHub URL. Returns expanded absolute paths to skill directories.

Resolution logic:

1. Path contains SKILL.md -> single skill
2. Path has a skills/ subfolder -> discover children with SKILL.md
3. Path children have SKILL.md -> flat container discovery
4. GitHub URL -> clone/cache then resolve locally

Spec compliance: https://agentskills.io/specification

Constant Summary collapse

GITHUB_URL_PATTERN =
%r{\Ahttps?://github\.com/}i
CACHE_DIR =
File.expand_path('~/.antigravity/cache/ruby-sdk/skills')

Class Method Summary collapse

Class Method Details

.discover(container_path) ⇒ Array<String>

Discover all skill directories inside a container path. Checks for skills/ subfolder first, then scans children directly.

Parameters:

  • container_path (String)

    path to scan for skills

Returns:

  • (Array<String>)

    sorted list of skill directory paths



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/antigravity/skill_resolver.rb', line 37

def self.discover(container_path)
  expanded = File.expand_path(container_path)
  return [] unless File.directory?(expanded)

  # Check for skills/ subfolder first (convention from agentskills.io)
  skills_subdir = File.join(expanded, 'skills')
  scan_dir = File.directory?(skills_subdir) ? skills_subdir : expanded

  Dir.children(scan_dir)
     .map { |child| File.join(scan_dir, child) }
     .select { |child_path| skill_dir?(child_path) }
     .sort
end

.github_url?(str) ⇒ Boolean

Check if a string looks like a GitHub URL.

Parameters:

  • str (String)

Returns:

  • (Boolean)


61
62
63
# File 'lib/antigravity/skill_resolver.rb', line 61

def self.github_url?(str)
  str.match?(GITHUB_URL_PATTERN)
end

.resolve(path_or_url) ⇒ Array<String>

Resolve a path or URL to an array of valid skill directory paths.

Parameters:

  • path_or_url (String)

    local path or GitHub URL

Returns:

  • (Array<String>)

    expanded absolute paths to skill directories



23
24
25
26
27
28
29
30
31
# File 'lib/antigravity/skill_resolver.rb', line 23

def self.resolve(path_or_url)
  path_or_url = path_or_url.to_s.strip

  if github_url?(path_or_url)
    resolve_github(path_or_url)
  else
    resolve_local(path_or_url)
  end
end

.skill_dir?(path) ⇒ Boolean

Check if a directory is a valid skill (contains SKILL.md).

Parameters:

  • path (String)

    directory path to check

Returns:

  • (Boolean)


54
55
56
# File 'lib/antigravity/skill_resolver.rb', line 54

def self.skill_dir?(path)
  File.directory?(path) && File.exist?(File.join(path, 'SKILL.md'))
end