Class: Ace::Git::Worktree::Molecules::TaskFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/worktree/molecules/task_fetcher.rb

Overview

Task fetcher molecule

Fetches task data from ace-task by delegating to its TaskManager. Uses organism-level API which handles all path resolution internally.

Examples:

Fetch task data

fetcher = TaskFetcher.new
task = fetcher.fetch("8pp.t.q7w")
task[:title] # => "Fix authentication bug"

Handle non-existent task

task = fetcher.fetch("999")
task # => nil

Instance Method Summary collapse

Constructor Details

#initializeTaskFetcher

Initialize a new TaskFetcher

TaskManager handles all path resolution internally, no configuration needed.



33
34
35
# File 'lib/ace/git/worktree/molecules/task_fetcher.rb', line 33

def initialize
  # TaskManager handles all path resolution internally
end

Instance Method Details

#ace_task_available?Boolean

Check if ace-task is available

Returns:

  • (Boolean)

    true if ace-task API is available



69
70
71
# File 'lib/ace/git/worktree/molecules/task_fetcher.rb', line 69

def ace_task_available?
  defined?(Ace::Task::Organisms::TaskManager)
end

#ace_task_unavailable_messageString

Get helpful error message when ace-task is unavailable

Returns:

  • (String)

    User-friendly error message with installation guidance



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ace/git/worktree/molecules/task_fetcher.rb', line 76

def ace_task_unavailable_message
  <<~MESSAGE
    ace-task is not available.

    Required for task-aware worktree operations.

    In a mono-repo environment, ensure ace-task is in your Gemfile.
    For standalone installation:
    1. Install ace-task gem: gem install ace-task

    For more information: https://github.com/cs3b/ace
  MESSAGE
end

#fetch(task_ref) ⇒ Hash?

Fetch task data by reference

Parameters:

  • task_ref (String)

    Task reference (e.g., “8pp.t.q7w”, “081”)

Returns:

  • (Hash, nil)

    Task data hash or nil if not found



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ace/git/worktree/molecules/task_fetcher.rb', line 41

def fetch(task_ref)
  return nil if task_ref.nil? || task_ref.empty?

  # Validate basic input for security
  return nil unless valid_task_reference?(task_ref)

  # Try organism-level API first (preferred)
  if ace_task_available?
    begin
      manager = Ace::Task::Organisms::TaskManager.new
      result = manager.show(task_ref)
      puts "DEBUG: TaskManager result: #{result.inspect}" if ENV["DEBUG"]
      return task_to_hash(result) if result
    rescue => e
      puts "DEBUG: TaskManager exception: #{e.message}" if ENV["DEBUG"]
      puts "DEBUG: Backtrace: #{e.backtrace.first(3).join(", ")}" if ENV["DEBUG"]
      # Fall through to CLI approach
    end
  end

  # Fallback to CLI-based approach
  puts "DEBUG: Falling back to CLI for task #{task_ref}" if ENV["DEBUG"]
  fetch_via_cli(task_ref)
end