Class: Ace::Review::Molecules::PromptResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/review/molecules/prompt_resolver.rb

Overview

Resolves prompt:// URIs and file paths with cascade lookup

Constant Summary collapse

PROTOCOL_PREFIX =
"prompt://"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root: nil) ⇒ PromptResolver

Returns a new instance of PromptResolver.



15
16
17
18
# File 'lib/ace/review/molecules/prompt_resolver.rb', line 15

def initialize(project_root: nil)
  @project_root = project_root || find_project_root
  @cache = {}
end

Instance Attribute Details

#project_rootObject (readonly)

Returns the value of attribute project_root.



13
14
15
# File 'lib/ace/review/molecules/prompt_resolver.rb', line 13

def project_root
  @project_root
end

Instance Method Details

#list_available(category = nil) ⇒ Object

List available prompt modules in a category



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ace/review/molecules/prompt_resolver.rb', line 45

def list_available(category = nil)
  prompts = {}

  # Collect from all locations
  locations = [
    {path: project_prompt_dir, label: "project"},
    {path: user_prompt_dir, label: "user"},
    {path: gem_prompt_dir, label: "built-in"}
  ]

  locations.each do |location|
    next unless location[:path] && Dir.exist?(location[:path])

    if category
      category_dir = File.join(location[:path], category)
      next unless Dir.exist?(category_dir)

      prompts[category] ||= {}
      collect_prompts_from_dir(category_dir, prompts[category], location[:label])
    else
      Dir.glob("#{location[:path]}/*").select { |f| File.directory?(f) }.each do |cat_dir|
        cat_name = File.basename(cat_dir)
        prompts[cat_name] ||= {}
        collect_prompts_from_dir(cat_dir, prompts[cat_name], location[:label])
      end
    end
  end

  prompts
end

#resolve(reference, config_dir: nil) ⇒ Object

Resolve a prompt reference to actual content Supports:

  • prompt://category/path - cascade lookup

  • prompt://project/path - project only

  • prompt://gem/path - gem built-in only

  • ./file.md - relative to config file directory

  • file.md - relative to project root



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ace/review/molecules/prompt_resolver.rb', line 27

def resolve(reference, config_dir: nil)
  return nil unless reference

  # Check cache
  cache_key = "#{reference}:#{config_dir}"
  return @cache[cache_key] if @cache.key?(cache_key)

  content = if reference.start_with?(PROTOCOL_PREFIX)
    resolve_protocol_uri(reference)
  else
    resolve_file_path(reference, config_dir)
  end

  @cache[cache_key] = content
  content
end