Module: Ariadna::Tools::PhaseManager
- Defined in:
- lib/ariadna/tools/phase_manager.rb
Class Method Summary collapse
- .add(description, raw: false) ⇒ Object
- .complete(phase, raw: false) ⇒ Object
- .dispatch(argv, raw: false) ⇒ Object
- .find(argv, raw: false) ⇒ Object
- .insert(after, description, raw: false) ⇒ Object
- .list(options, raw: false) ⇒ Object
- .milestone_complete(version, name: nil, raw: false) ⇒ Object
- .milestone_dispatch(argv, raw: false) ⇒ Object
- .next_decimal(base_phase, raw: false) ⇒ Object
- .phases_dispatch(argv, raw: false) ⇒ Object
- .plan_index(argv, raw: false) ⇒ Object
- .remove(phase, force: false, raw: false) ⇒ Object
Class Method Details
.add(description, raw: false) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/ariadna/tools/phase_manager.rb', line 222 def self.add(description, raw: false) Output.error("description required") unless description && !description.empty? cwd = Dir.pwd phases_dir = File.join(cwd, ".ariadna_planning", "phases") roadmap_path = File.join(cwd, ".ariadna_planning", "ROADMAP.md") existing = if File.directory?(phases_dir) Dir.children(phases_dir) .select { |d| File.directory?(File.join(phases_dir, d)) } .filter_map { |d| d.match(/\A(\d+)/); ::Regexp.last_match(1)&.to_i } .max || 0 else 0 end new_num = format("%02d", existing + 1) slug = description.downcase.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "") dir_name = "#{new_num}-#{slug}" FileUtils.mkdir_p(File.join(phases_dir, dir_name)) # Append to ROADMAP.md if it exists if File.exist?(roadmap_path) roadmap = File.read(roadmap_path) roadmap += "\n### Phase #{new_num.to_i}: #{description}\n\n**Goal:** TBD\n" File.write(roadmap_path, roadmap) end Output.json({ added: true, phase: new_num, directory: dir_name }, raw: raw, raw_value: new_num) end |
.complete(phase, raw: false) ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/ariadna/tools/phase_manager.rb', line 308 def self.complete(phase, raw: false) Output.error("phase required") unless phase cwd = Dir.pwd roadmap_path = File.join(cwd, ".ariadna_planning", "ROADMAP.md") normalized = normalize_phase_name(phase) # Mark in ROADMAP.md if File.exist?(roadmap_path) content = File.read(roadmap_path) escaped = Regexp.escape(normalized.to_i.to_s) content = content.sub(/(###\s*Phase\s+#{escaped}:)/, "\\1 ✅") File.write(roadmap_path, content) end Output.json({ completed: true, phase: normalized }, raw: raw, raw_value: "true") end |
.dispatch(argv, raw: false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ariadna/tools/phase_manager.rb', line 9 def self.dispatch(argv, raw: false) subcommand = argv.shift case subcommand when "next-decimal" next_decimal(argv.first, raw: raw) when "add" add(argv.join(" "), raw: raw) when "insert" after = argv.shift insert(after, argv.join(" "), raw: raw) when "remove" force = argv.delete("--force") remove(argv.first, force: !!force, raw: raw) when "complete" complete(argv.first, raw: raw) else Output.error("Unknown phase subcommand. Available: next-decimal, add, insert, remove, complete") end end |
.find(argv, raw: false) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 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 |
# File 'lib/ariadna/tools/phase_manager.rb', line 58 def self.find(argv, raw: false) phase = argv.first Output.error("phase identifier required") unless phase cwd = Dir.pwd phases_dir = File.join(cwd, ".ariadna_planning", "phases") normalized = normalize_phase_name(phase) not_found = { found: false, directory: nil, phase_number: nil, phase_name: nil, plans: [], summaries: [] } unless File.directory?(phases_dir) Output.json(not_found, raw: raw, raw_value: "") return end dirs = Dir.children(phases_dir).select { |d| File.directory?(File.join(phases_dir, d)) }.sort match = dirs.find { |d| d.start_with?(normalized) } unless match Output.json(not_found, raw: raw, raw_value: "") return end dir_match = match.match(/\A(\d+(?:\.\d+)?)-?(.*)/) phase_number = dir_match ? dir_match[1] : normalized phase_name = dir_match && !dir_match[2].empty? ? dir_match[2] : nil phase_dir = File.join(phases_dir, match) phase_files = Dir.children(phase_dir).sort plans = phase_files.select { |f| f.end_with?("-PLAN.md") || f == "PLAN.md" } summaries = phase_files.select { |f| f.end_with?("-SUMMARY.md") || f == "SUMMARY.md" } result = { found: true, directory: File.join(".ariadna_planning", "phases", match), phase_number: phase_number, phase_name: phase_name, plans: plans, summaries: summaries } Output.json(result, raw: raw, raw_value: result[:directory]) rescue StandardError Output.json(not_found, raw: raw, raw_value: "") end |
.insert(after, description, raw: false) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/ariadna/tools/phase_manager.rb', line 252 def self.insert(after, description, raw: false) Output.error("after phase and description required") unless after && description && !description.empty? cwd = Dir.pwd phases_dir = File.join(cwd, ".ariadna_planning", "phases") normalized = normalize_phase_name(after) # Calculate next decimal unless File.directory?(phases_dir) Output.json({ inserted: false, reason: "phases directory not found" }, raw: raw, raw_value: "false") return end dirs = Dir.children(phases_dir).select { |d| File.directory?(File.join(phases_dir, d)) } decimal_pattern = /\A#{Regexp.escape(normalized)}\.(\d+)/ existing = dirs.filter_map { |d| m = d.match(decimal_pattern); m[1].to_i if m } next_num = existing.empty? ? 1 : existing.max + 1 new_phase = "#{normalized}.#{next_num}" slug = description.downcase.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "") dir_name = "#{new_phase}-#{slug}" FileUtils.mkdir_p(File.join(phases_dir, dir_name)) Output.json({ inserted: true, phase: new_phase, directory: dir_name }, raw: raw, raw_value: new_phase) end |
.list(options, raw: false) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/ariadna/tools/phase_manager.rb', line 155 def self.list(, raw: false) cwd = Dir.pwd phases_dir = File.join(cwd, ".ariadna_planning", "phases") unless File.directory?(phases_dir) key = [:type] ? :files : :directories Output.json({ key => [], count: 0 }, raw: raw, raw_value: "") return end dirs = Dir.children(phases_dir) .select { |d| File.directory?(File.join(phases_dir, d)) } .sort_by { |d| d.match(/\A(\d+(?:\.\d+)?)/)&.[](1)&.to_f || 0 } if [:phase] normalized = normalize_phase_name([:phase]) match = dirs.find { |d| d.start_with?(normalized) } dirs = match ? [match] : [] end if [:type] files = [] dirs.each do |dir| dir_files = Dir.children(File.join(phases_dir, dir)) filtered = case [:type] when "plans" then dir_files.select { |f| f.end_with?("-PLAN.md") || f == "PLAN.md" } when "summaries" then dir_files.select { |f| f.end_with?("-SUMMARY.md") || f == "SUMMARY.md" } else dir_files end files.concat(filtered.sort) end Output.json({ files: files, count: files.size }, raw: raw, raw_value: files.join("\n")) else Output.json({ directories: dirs, count: dirs.size }, raw: raw, raw_value: dirs.join("\n")) end end |
.milestone_complete(version, name: nil, raw: false) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/ariadna/tools/phase_manager.rb', line 325 def self.milestone_complete(version, name: nil, raw: false) Output.error("version required") unless version cwd = Dir.pwd # Create milestone archive archive_dir = File.join(cwd, ".ariadna_planning", "milestones") FileUtils.mkdir_p(archive_dir) milestone_name = name || "v#{version}" archive_path = File.join(archive_dir, "#{milestone_name}.md") content = "# Milestone: #{milestone_name}\n\nCompleted: #{Time.now.utc.strftime('%Y-%m-%d')}\nVersion: #{version}\n" File.write(archive_path, content) Output.json({ archived: true, version: version, name: milestone_name, path: archive_path }, raw: raw, raw_value: "true") end |
.milestone_dispatch(argv, raw: false) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ariadna/tools/phase_manager.rb', line 45 def self.milestone_dispatch(argv, raw: false) subcommand = argv.shift case subcommand when "complete" version = argv.shift name_idx = argv.index("--name") name = name_idx ? argv[(name_idx + 1)..].join(" ") : nil milestone_complete(version, name: name, raw: raw) else Output.error("Unknown milestone subcommand. Available: complete") end end |
.next_decimal(base_phase, raw: false) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/ariadna/tools/phase_manager.rb', line 192 def self.next_decimal(base_phase, raw: false) Output.error("base phase required") unless base_phase cwd = Dir.pwd phases_dir = File.join(cwd, ".ariadna_planning", "phases") normalized = normalize_phase_name(base_phase) unless File.directory?(phases_dir) Output.json({ found: false, base_phase: normalized, next: "#{normalized}.1", existing: [] }, raw: raw, raw_value: "#{normalized}.1") return end dirs = Dir.children(phases_dir).select { |d| File.directory?(File.join(phases_dir, d)) } base_exists = dirs.any? { |d| d.start_with?("#{normalized}-") || d == normalized } decimal_pattern = /\A#{Regexp.escape(normalized)}\.(\d+)/ existing = dirs.filter_map { |d| m = d.match(decimal_pattern); "#{normalized}.#{m[1]}" if m } .sort_by { |d| d.to_f } next_val = if existing.empty? "#{normalized}.1" else last_num = existing.last.split(".")[1].to_i "#{normalized}.#{last_num + 1}" end Output.json({ found: base_exists, base_phase: normalized, next: next_val, existing: existing }, raw: raw, raw_value: next_val) end |
.phases_dispatch(argv, raw: false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ariadna/tools/phase_manager.rb', line 29 def self.phases_dispatch(argv, raw: false) subcommand = argv.shift case subcommand when "list" type_idx = argv.index("--type") phase_idx = argv.index("--phase") = { type: type_idx ? argv[type_idx + 1] : nil, phase: phase_idx ? argv[phase_idx + 1] : nil } list(, raw: raw) else Output.error("Unknown phases subcommand. Available: list") end end |
.plan_index(argv, raw: false) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/ariadna/tools/phase_manager.rb', line 102 def self.plan_index(argv, raw: false) phase = argv.first Output.error("phase required") unless phase cwd = Dir.pwd phases_dir = File.join(cwd, ".ariadna_planning", "phases") normalized = normalize_phase_name(phase) unless File.directory?(phases_dir) Output.json({ plans: [], count: 0 }, raw: raw, raw_value: "") return end dirs = Dir.children(phases_dir).select { |d| File.directory?(File.join(phases_dir, d)) }.sort match = dirs.find { |d| d.start_with?(normalized) } unless match Output.json({ plans: [], count: 0 }, raw: raw, raw_value: "") return end dir_path = File.join(phases_dir, match) plan_files = Dir.children(dir_path).select { |f| f.match?(/-PLAN\.md$/i) }.sort plans = plan_files.map do |f| content = File.read(File.join(dir_path, f)) fm = Frontmatter.extract(content) summary_name = f.sub(/-PLAN\.md$/i, "-SUMMARY.md") has_summary = File.exist?(File.join(dir_path, summary_name)) { file: f, phase: fm["phase"], plan: fm["plan"], wave: fm["wave"], type: fm["type"], completed: has_summary, domain: fm["domain"] || "general", depends_on: fm["depends_on"] || [], files_modified: fm["files_modified"] || [], autonomous: fm.key?("autonomous") ? fm["autonomous"] : true, objective: fm["objective"], task_count: content.scan(/<task\b/).count } end domains = plans.map { |p| p[:domain] }.uniq non_general = domains.reject { |d| d == "general" } Output.json({ plans: plans, count: plans.size, domains: domains, domain_count: non_general.size, multi_domain: non_general.size >= 2, recommend_team: plans.size >= 3 && non_general.size >= 2 }, raw: raw) end |
.remove(phase, force: false, raw: false) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/ariadna/tools/phase_manager.rb', line 277 def self.remove(phase, force: false, raw: false) Output.error("phase required") unless phase cwd = Dir.pwd phases_dir = File.join(cwd, ".ariadna_planning", "phases") normalized = normalize_phase_name(phase) unless File.directory?(phases_dir) Output.json({ removed: false, reason: "phases directory not found" }, raw: raw, raw_value: "false") return end dirs = Dir.children(phases_dir).select { |d| File.directory?(File.join(phases_dir, d)) }.sort match = dirs.find { |d| d.start_with?(normalized) } unless match Output.json({ removed: false, reason: "phase not found" }, raw: raw, raw_value: "false") return end dir_path = File.join(phases_dir, match) has_content = Dir.children(dir_path).any? { |f| f.end_with?(".md") } if has_content && !force Output.json({ removed: false, reason: "phase has content, use --force" }, raw: raw, raw_value: "false") return end FileUtils.rm_rf(dir_path) Output.json({ removed: true, phase: normalized, directory: match }, raw: raw, raw_value: "true") end |