Class: Ace::PromptPrep::Molecules::PromptReader

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/prompt_prep/molecules/prompt_reader.rb

Overview

Reads prompt file from standard location

Constant Summary collapse

DEFAULT_CACHE_DIR =

Default prompt file location relative to project root (fallback if config unavailable)

Ace::PromptPrep::Defaults::DEFAULT_CACHE_DIR
DEFAULT_PROMPT_FILE =
"prompts/the-prompt.md"

Class Method Summary collapse

Class Method Details

.call(path: nil) ⇒ Hash

Read prompt file

Parameters:

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

    Optional custom path (default: standard location)

Returns:

  • (Hash)

    Hash with :content, :path, :success, :error keys



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ace/prompt_prep/molecules/prompt_reader.rb', line 27

def self.call(path: nil)
  project_root = Ace::Support::Fs::Molecules::ProjectRootFinder.find_or_current
  prompt_path = path || File.join(project_root, prompt_path_from_config)
  prompt_path = File.expand_path(prompt_path)

  unless File.exist?(prompt_path)
    return {
      content: nil,
      path: prompt_path,
      success: false,
      error: "Prompt file not found: #{prompt_path}"
    }
  end

  # Check if it's a symlink and resolve it
  actual_path = File.realpath(prompt_path)

  content = File.read(actual_path, encoding: "utf-8")

  {
    content: content,
    path: prompt_path,
    actual_path: actual_path,
    success: true,
    error: nil
  }
rescue => e
  {
    content: nil,
    path: prompt_path,
    success: false,
    error: "Error reading file: #{e.message}"
  }
end

.prompt_path_from_configString

Get prompt path from config or use fallback

Returns:

  • (String)

    Prompt path relative to project root



16
17
18
19
20
21
# File 'lib/ace/prompt_prep/molecules/prompt_reader.rb', line 16

def self.prompt_path_from_config
  config = Ace::PromptPrep.config
  cache_dir = config.dig("paths", "cache_dir") || DEFAULT_CACHE_DIR
  prompt_file = config.dig("paths", "prompt_file") || DEFAULT_PROMPT_FILE
  File.join(cache_dir, prompt_file)
end