Class: Ace::PromptPrep::Atoms::TaskPathResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/prompt_prep/atoms/task_path_resolver.rb

Overview

Resolves task directory path from task ID and extracts task IDs from branch names Delegates to ace-task for task resolution to avoid duplicating logic

Pure functions only - git I/O is handled by Molecules::GitBranchReader

Class Method Summary collapse

Class Method Details

.extract_from_branch(branch_name, patterns: nil) ⇒ String|nil

Extract task ID from branch name using configurable patterns Default pattern matches:

117-feature → "117"
121.01-archive → "121.01"

Does not match:

main → nil
feature-123 → nil (number not at start)

Parameters:

  • branch_name (String)

    e.g., “117-feature-name”, “121.01-archive”

  • patterns (Array<String>|nil) (defaults to: nil)

    Optional regex patterns (uses config if nil)

Returns:

  • (String|nil)

    task ID or nil if not found



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ace/prompt_prep/atoms/task_path_resolver.rb', line 61

def self.extract_from_branch(branch_name, patterns: nil)
  return nil if branch_name.nil? || branch_name.empty?

  # Get patterns from config or use default
  patterns ||= Ace::PromptPrep.config.dig("task", "branch_patterns")
  patterns ||= ['^(\d+(?:\.\d+)?)-']

  patterns.each do |pattern|
    match = branch_name.match(Regexp.new(pattern))
    return match[1] if match && match[1]
  end

  nil
end

.resolve(task_id) ⇒ Hash

Find task directory by ID using ace-task API

Parameters:

  • task_id (String)

    e.g., “117”, “121.01”, “v.0.9.0+task.121”

Returns:

  • (Hash)

    { path: String, prompts_path: String, found: Boolean, error: String|nil }



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ace/prompt_prep/atoms/task_path_resolver.rb', line 17

def self.resolve(task_id)
  # Use ace-task's TaskManager to resolve task
  manager = Ace::Task::Organisms::TaskManager.new
  task = manager.show(task_id)

  unless task
    return {
      path: nil,
      prompts_path: nil,
      found: false,
      error: "Task not found: #{task_id}"
    }
  end

  # Extract task directory from task file path
  task_dir = task.path
  prompts_dir = File.join(task_dir, "prompts")

  {
    path: task_dir,
    prompts_path: prompts_dir,
    found: true,
    error: nil
  }
rescue => e
  {
    path: nil,
    prompts_path: nil,
    found: false,
    error: "Error resolving task path: #{e.message}"
  }
end