ccswarm 0.9.1

AI Agent Workflow DevOps toolchain complementing Claude Code Agent Teams
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
49
50
51
52
53
54
55
56
57
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
101
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
154
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
191
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
221
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
use super::super::*;

impl CliRunner {
    pub(crate) async fn handle_task(&self, action: &TaskAction) -> Result<()> {
        match action {
            TaskAction::Add {
                description,
                priority,
                task_type,
                details,
                duration,
                auto_assign: _,
                template: _,
                template_vars: _,
                interactive: _,
            } => {
                self.add_task(
                    description,
                    priority,
                    task_type,
                    details.as_deref(),
                    *duration,
                )
                .await
            }
            TaskAction::List {
                all,
                status,
                agent,
                detailed,
                branches,
            } => {
                self.list_tasks(
                    *all,
                    status.as_deref(),
                    agent.as_deref(),
                    *detailed,
                    *branches,
                )
                .await
            }
            TaskAction::Status {
                task_id,
                history,
                orchestration,
            } => {
                self.show_task_status(task_id, *history, *orchestration)
                    .await
            }
            TaskAction::Cancel {
                task_id,
                force,
                reason,
            } => self.cancel_task(task_id, *force, reason.as_deref()).await,
            TaskAction::History {
                limit,
                agent,
                failed_only,
            } => {
                self.show_task_history(*limit, agent.as_deref(), *failed_only)
                    .await
            }
            TaskAction::Execute {
                task,
                agent,
                orchestrate,
            } => {
                self.execute_task_immediate(task, agent.as_deref(), *orchestrate)
                    .await
            }
            TaskAction::Stats {
                detailed,
                performance,
            } => self.show_task_stats(*detailed, *performance).await,
            TaskAction::Merge {
                task_id,
                cleanup,
                yes,
            } => self.merge_task_branch(task_id, *cleanup, *yes).await,
            TaskAction::Retry { task_id, force } => self.retry_task(task_id, *force).await,
            TaskAction::Delete { task_id, force } => self.delete_task(task_id, *force).await,
        }
    }

    pub(crate) async fn add_task(
        &self,
        description: &str,
        priority: &str,
        task_type: &str,
        details: Option<&str>,
        duration: Option<u32>,
    ) -> Result<()> {
        use crate::utils::user_error::CommonErrors;

        if description.trim().is_empty() {
            CommonErrors::invalid_task_format()
                .with_details("Task description cannot be empty")
                .with_suggestion("Provide a clear, actionable task description")
                .display();
            return Err(anyhow!("Invalid task description"));
        }

        println!(
            "Creating task: {}...",
            description.chars().take(50).collect::<String>()
        );

        let priority = match priority.to_lowercase().as_str() {
            "low" => Priority::Low,
            "medium" => Priority::Medium,
            "high" => Priority::High,
            "critical" => Priority::Critical,
            _ => Priority::Medium,
        };

        let task_type = match task_type.to_lowercase().as_str() {
            "development" | "dev" => TaskType::Development,
            "testing" | "test" => TaskType::Testing,
            "documentation" | "docs" => TaskType::Documentation,
            "infrastructure" | "infra" => TaskType::Infrastructure,
            "coordination" => TaskType::Coordination,
            "review" => TaskType::Review,
            "bugfix" | "bug" => TaskType::Bugfix,
            "feature" => TaskType::Feature,
            _ => TaskType::Development,
        };

        let task_type_clone = task_type;
        let mut task = Task::new(
            uuid::Uuid::new_v4().to_string(),
            description.to_string(),
            priority,
            task_type,
        );

        if let Some(details) = details {
            task = task.with_details(details.to_string());
        }

        if let Some(duration) = duration {
            task = task.with_duration(duration);
        }

        let task_id = task.id.clone();

        if self.json_output {
            println!(
                "{}",
                serde_json::to_string_pretty(&serde_json::json!({
                    "status": "success",
                    "message": "Task added",
                    "task_id": task_id,
                    "description": description,
                    "priority": priority,
                }))?
            );
        } else {
            println!();
            println!("{}", "✅ Task created successfully!".bright_green().bold());
            println!();
            println!(
                "   {} {}",
                "Task ID:".bright_cyan(),
                task_id[..8].bright_white()
            );
            println!("   {} {}", "Description:".bright_cyan(), description);
            println!(
                "   {} {}",
                "Priority:".bright_cyan(),
                match priority {
                    Priority::Critical => "🔴 Critical".bright_red(),
                    Priority::High => "🟡 High".bright_yellow(),
                    Priority::Medium => "🟢 Medium".bright_green(),
                    Priority::Low => "🔵 Low".bright_blue(),
                }
            );
            println!(
                "   {} {}",
                "Type:".bright_cyan(),
                format!("{:?}", task_type_clone).bright_white()
            );

            if let Some(duration) = task.estimated_duration {
                println!("   {} {} minutes", "Est. Duration:".bright_cyan(), duration);
            }
        }

        Ok(())
    }

    /// Execute a task immediately
    pub(crate) async fn execute_task_immediate(
        &self,
        task: &str,
        agent: Option<&str>,
        orchestrate: bool,
    ) -> Result<()> {
        if self.json_output {
            println!(
                "{}",
                serde_json::to_string_pretty(&serde_json::json!({
                    "task": task,
                    "agent": agent,
                    "orchestrate": orchestrate,
                    "status": "not_implemented"
                }))?
            );
        } else {
            println!("Task execution engine has been removed.");
            println!("Use 'ccswarm pipeline' for workflow execution.");
        }
        Ok(())
    }

    pub(crate) async fn list_tasks(
        &self,
        _all: bool,
        _status_filter: Option<&str>,
        _agent_filter: Option<&str>,
        _detailed: bool,
        branches: bool,
    ) -> Result<()> {
        if self.json_output {
            println!(
                "{}",
                serde_json::to_string_pretty(&serde_json::json!({
                    "tasks": [],
                    "total": 0,
                    "message": "Task queue management has been removed. Use 'ccswarm pipeline' for workflow execution."
                }))?
            );
        } else {
            println!("Task queue management has been removed.");
            println!("Use 'ccswarm pipeline' for workflow execution.");
        }

        // Show worktree summary if --branches flag is set
        if branches {
            println!("{}", "Worktree Summary".bright_cyan().bold());
            println!("{}", "================".bright_cyan());
            if let Ok(manager) =
                crate::git::shell::ShellWorktreeManager::new(self.repo_path.clone())
            {
                match manager.list_worktrees().await {
                    Ok(worktrees) => {
                        let task_worktrees: Vec<_> = worktrees
                            .iter()
                            .filter(|wt| wt.branch.starts_with("task/"))
                            .collect();
                        if task_worktrees.is_empty() {
                            println!("No task worktrees found.");
                        } else {
                            for wt in &task_worktrees {
                                println!(
                                    "  🌿 {} ({})",
                                    wt.branch.bright_green(),
                                    wt.path.display()
                                );
                            }
                            println!();
                            println!("Total: {} task worktrees", task_worktrees.len());
                        }
                    }
                    Err(e) => {
                        println!("Failed to list worktrees: {}", e.to_string().bright_red());
                    }
                }
            }
            println!();
        }

        Ok(())
    }

    /// Merge a completed task's worktree branch into the main branch
    pub(crate) async fn merge_task_branch(
        &self,
        task_id: &str,
        cleanup: bool,
        _yes: bool,
    ) -> Result<()> {
        let manager = crate::git::shell::ShellWorktreeManager::new(self.repo_path.clone())?;

        // Find the task's worktree branch
        let safe_id: String = task_id
            .chars()
            .map(|c| {
                if c.is_alphanumeric() || c == '-' {
                    c
                } else {
                    '-'
                }
            })
            .collect();
        let branch_name = format!("task/{}", safe_id);

        println!(
            "{} Merging branch {} into main...",
            ">>>".bright_green().bold(),
            branch_name.bright_cyan()
        );

        // Check the branch exists via worktree list
        let worktrees = manager.list_worktrees().await?;
        let task_wt = worktrees.iter().find(|wt| wt.branch == branch_name);

        if task_wt.is_none() {
            return Err(anyhow!("No worktree found for branch '{}'", branch_name));
        }

        // Merge using git merge
        let output = tokio::process::Command::new("git")
            .args([
                "merge",
                &branch_name,
                "--no-ff",
                "-m",
                &format!("Merge task {} branch", task_id),
            ])
            .current_dir(&self.repo_path)
            .output()
            .await
            .context("Failed to execute git merge")?;

        if !output.status.success() {
            let stderr = String::from_utf8_lossy(&output.stderr);
            return Err(anyhow!("Merge failed: {}", stderr));
        }

        println!("{}", "OK Merged successfully".bright_green().bold());

        // Cleanup worktree if requested
        if cleanup && let Some(wt) = task_wt {
            if let Err(e) = manager.remove_worktree(&wt.path).await {
                warn!("Failed to cleanup worktree: {}", e);
            } else {
                println!("Cleaned up worktree at {}", wt.path.display());
            }
        }

        Ok(())
    }

    /// Retry a failed task
    pub(crate) async fn retry_task(&self, _task_id: &str, _force: bool) -> Result<()> {
        print_task_queue_removed();
        Ok(())
    }

    /// Delete a task and its associated worktree
    pub(crate) async fn delete_task(&self, task_id: &str, _force: bool) -> Result<()> {
        // Clean up any associated worktree
        let safe_id: String = task_id
            .chars()
            .map(|c| {
                if c.is_alphanumeric() || c == '-' {
                    c
                } else {
                    '-'
                }
            })
            .collect();

        if let Ok(manager) = crate::git::shell::ShellWorktreeManager::new(self.repo_path.clone()) {
            let worktrees = manager.list_worktrees().await.unwrap_or_default();
            let branch_name = format!("task/{}", safe_id);
            if let Some(wt) = worktrees.iter().find(|wt| wt.branch == branch_name) {
                if let Err(e) = manager.remove_worktree(&wt.path).await {
                    warn!("Failed to cleanup worktree: {}", e);
                } else {
                    println!("Cleaned up worktree at {}", wt.path.display());
                }
            }
        }

        println!("{} Task '{}' deleted", "OK".bright_green().bold(), task_id);

        Ok(())
    }

    /// Show detailed task status
    pub(crate) async fn show_task_status(
        &self,
        task_id: &str,
        _history: bool,
        _orchestration: bool,
    ) -> Result<()> {
        if self.json_output {
            println!(
                "{}",
                serde_json::to_string_pretty(&serde_json::json!({
                    "task_id": task_id,
                    "status": "not_available",
                    "message": "Task queue management has been removed."
                }))?
            );
        } else {
            println!("Task queue management has been removed.");
            println!("Use 'ccswarm pipeline' for workflow execution.");
        }
        Ok(())
    }

    /// Cancel a task
    pub(crate) async fn cancel_task(
        &self,
        _task_id: &str,
        _force: bool,
        _reason: Option<&str>,
    ) -> Result<()> {
        print_task_queue_removed();
        Ok(())
    }

    /// Show task execution history
    pub(crate) async fn show_task_history(
        &self,
        _limit: usize,
        _agent_filter: Option<&str>,
        _failed_only: bool,
    ) -> Result<()> {
        print_task_queue_removed();
        Ok(())
    }

    /// Show task queue statistics
    pub(crate) async fn show_task_stats(&self, _detailed: bool, _performance: bool) -> Result<()> {
        print_task_queue_removed();
        Ok(())
    }
}

/// Shared message used by the legacy task-queue stubs. The old per-task queue was
/// removed in favor of `ccswarm pipeline` + `ccswarm queue`; the stubs are kept so
/// existing scripts don't crash, and this helper keeps the wording consistent.
fn print_task_queue_removed() {
    println!(
        "Task queue management has been removed. Use 'ccswarm pipeline' for workflow execution."
    );
}