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
use super::super::*;
impl CliRunner {
pub(crate) async fn handle_config(&self, action: &ConfigAction) -> Result<()> {
match action {
ConfigAction::Generate { output, template } => {
let config = match template.as_str() {
"minimal" => create_minimal_config(&self.repo_path)?,
"frontend-only" => create_frontend_only_config(&self.repo_path)?,
"full-stack" => create_default_config(&self.repo_path)?,
_ => create_default_config(&self.repo_path)?,
};
config.to_file(output.clone()).await?;
if self.json_output {
println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"status": "success",
"message": "Configuration generated",
"file": output,
"template": template,
}))?
);
} else {
println!("✅ Configuration generated: {}", output.display());
println!(" Template: {}", template);
}
}
ConfigAction::Validate { file } => match CcswarmConfig::from_file(file.clone()).await {
Ok(_) => {
if self.json_output {
println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"status": "success",
"message": "Configuration is valid",
"file": file,
}))?
);
} else {
println!("✅ Configuration is valid: {}", file.display());
}
}
Err(e) => {
if self.json_output {
println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"status": "error",
"message": "Configuration is invalid",
"file": file,
"error": e.to_string(),
}))?
);
} else {
println!("❌ Configuration is invalid: {}", file.display());
println!(" Error: {}", e);
}
return Err(e);
}
},
ConfigAction::Show { file, agent, raw } => {
let raw_contents = match tokio::fs::read_to_string(file.clone()).await {
Ok(contents) => contents,
Err(e) => {
if self.json_output {
println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"status": "error",
"message": "Failed to read configuration file",
"file": file,
"error": e.to_string(),
}))?
);
} else {
println!("❌ Failed to read configuration {}: {}", file.display(), e);
}
return Err(e.into());
}
};
let config: CcswarmConfig = match serde_json::from_str(&raw_contents) {
Ok(cfg) => cfg,
Err(e) => {
if self.json_output {
println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"status": "error",
"message": "Configuration file is not valid JSON",
"file": file,
"error": e.to_string(),
}))?
);
} else {
println!(
"❌ Configuration {} is not valid JSON: {}",
file.display(),
e
);
}
return Err(e.into());
}
};
if *raw && agent.is_none() {
if self.json_output {
println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"status": "success",
"file": file,
"raw": raw_contents,
}))?
);
} else {
println!("{}", raw_contents);
}
return Ok(());
}
if let Some(agent_name) = agent {
match config.agents.get(agent_name) {
Some(agent_cfg) => {
if self.json_output {
println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"status": "success",
"file": file,
"agent": agent_name,
"config": agent_cfg,
}))?
);
} else if *raw {
println!("{}", serde_json::to_string_pretty(agent_cfg)?);
} else {
println!("📄 Agent configuration: {}", agent_name);
println!(" Specialization: {}", agent_cfg.specialization);
println!(" Worktree: {}", agent_cfg.worktree);
println!(" Branch: {}", agent_cfg.branch);
println!(
" Think mode: {}",
agent_cfg
.claude_config
.think_mode
.as_ref()
.map(|m| m.to_string())
.unwrap_or_else(|| "default".to_string())
);
println!(
" Custom commands: {}",
if agent_cfg.claude_config.custom_commands.is_empty() {
"none".to_string()
} else {
agent_cfg.claude_config.custom_commands.join(", ")
}
);
}
}
None => {
let err_msg =
format!("Agent '{}' not found in configuration", agent_name);
if self.json_output {
println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"status": "error",
"message": err_msg,
"file": file,
}))?
);
} else {
println!("❌ {}", err_msg);
}
return Err(anyhow::anyhow!(err_msg));
}
}
} else if self.json_output {
println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"status": "success",
"file": file,
"config": config,
}))?
);
} else {
println!("📄 Configuration: {}", file.display());
println!("Project: {}", config.project.name);
println!(
"Repository: {} (branch: {})",
config.project.repository.url, config.project.repository.main_branch
);
println!(
"Master Claude role: {}, think mode: {}",
config.project.master_claude.role, config.project.master_claude.think_mode
);
println!("Agents ({}):", config.agents.len());
for (name, agent) in &config.agents {
println!(
" - {} [{}] -> {}",
name, agent.specialization, agent.worktree
);
}
println!(
"Coordination: method={}, sync={}s, quality_gate={}, master_review={}",
config.coordination.communication_method,
config.coordination.sync_interval,
config.coordination.quality_gate_frequency,
config.coordination.master_review_trigger
);
}
}
}
Ok(())
}
}