Module: Ace::PromptPrep::CLI::Helpers

Defined in:
lib/ace/prompt_prep/cli.rb

Overview

Shared helper module for common CLI functionality

Class Method Summary collapse

Class Method Details

.path_within_root?(path, root) ⇒ Boolean

Returns true when path is inside root (or equal to root)

Parameters:

  • path (String)
  • root (String)

Returns:

  • (Boolean)


118
119
120
121
122
# File 'lib/ace/prompt_prep/cli.rb', line 118

def self.path_within_root?(path, root)
  expanded_path = File.expand_path(path)
  expanded_root = File.expand_path(root)
  expanded_path == expanded_root || expanded_path.start_with?("#{expanded_root}/")
end

.resolve_task_prompt_path(task_option) ⇒ String?

Resolve task prompt path from explicit task ID or auto-detection This is the global task resolution used by ALL commands

Parameters:

  • task_option (String, nil)

    Explicit task ID from –task flag

Returns:

  • (String, nil)

    Path to the-prompt.md in task’s prompts directory, or nil for default



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ace/prompt_prep/cli.rb', line 70

def self.resolve_task_prompt_path(task_option)
  # If task ID is explicitly provided, use it
  if task_option
    result = Ace::PromptPrep::Atoms::TaskPathResolver.resolve(task_option)
    raise Error, result[:error] unless result[:found]

    prompts_dir = result[:prompts_path]
    FileUtils.mkdir_p(prompts_dir)
    return File.join(prompts_dir, "the-prompt.md")
  end

  # Check if auto-detection is enabled in config
  return nil unless Ace::PromptPrep.config.dig("task", "detection")

  # Try to extract task ID from current branch (via ace-git for I/O)
  branch = Ace::Git::Molecules::BranchReader.current_branch
  return nil unless branch

  extracted_task_id = Ace::PromptPrep::Atoms::TaskPathResolver.extract_from_branch(branch)
  return nil unless extracted_task_id

  # Resolve task path
  result = Ace::PromptPrep::Atoms::TaskPathResolver.resolve(extracted_task_id)
  return nil unless result[:found]

  prompts_dir = result[:prompts_path]
  project_root = Ace::Support::Fs::Molecules::ProjectRootFinder.find_or_current
  unless path_within_root?(prompts_dir, project_root)
    warn "[ace-prompt-prep] Task auto-detection skipped: resolved path outside project root"
    return nil
  end

  FileUtils.mkdir_p(prompts_dir)
  File.join(prompts_dir, "the-prompt.md")
rescue => e
  # For explicit --task, re-raise the error
  raise if task_option

  # For auto-detection, notify user and continue without task context
  warn "[ace-prompt-prep] Task auto-detection skipped: #{e.message}"
  nil
end