Class: Ace::Support::Items::Atoms::FolderCompletionDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/items/atoms/folder_completion_detector.rb

Overview

Detects whether all spec files in a folder have terminal status. Used by orchestrator auto-archive: when all subtasks are done/skipped/blocked, the parent can be auto-archived.

Constant Summary collapse

TERMINAL_STATUSES =
%w[done skipped blocked].freeze

Class Method Summary collapse

Class Method Details

.all_terminal?(dir_path, spec_pattern: "*.s.md", terminal_statuses: TERMINAL_STATUSES, recursive: false) ⇒ Boolean

Check if all spec files in a directory have terminal status.

Parameters:

  • dir_path (String)

    Directory to check

  • spec_pattern (String) (defaults to: "*.s.md")

    Glob pattern for spec files (default: “*.s.md”)

  • terminal_statuses (Array<String>) (defaults to: TERMINAL_STATUSES)

    Statuses considered terminal

  • recursive (Boolean) (defaults to: false)

    If true, also check one level of subdirectories

Returns:

  • (Boolean)

    True if all found specs have terminal status; false if none found



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ace/support/items/atoms/folder_completion_detector.rb', line 22

def self.all_terminal?(dir_path, spec_pattern: "*.s.md", terminal_statuses: TERMINAL_STATUSES, recursive: false)
  patterns = [File.join(dir_path, spec_pattern)]
  patterns << File.join(dir_path, "*", spec_pattern) if recursive

  files = patterns.flat_map { |p| Dir.glob(p) }
  return false if files.empty?

  files.all? do |file|
    content = File.read(file)
    frontmatter, = FrontmatterParser.parse(content)
    status = frontmatter["status"].to_s.downcase
    terminal_statuses.include?(status)
  end
end