use crate::constants::env::ai_code;
use std::collections::HashMap;
pub fn is_coordinator_mode() -> bool {
std::env::var(ai_code::COORDINATOR_MODE).is_ok()
}
pub fn match_session_mode(session_mode: Option<&str>) -> Option<String> {
let session_mode = session_mode?;
let current_is_coordinator = is_coordinator_mode();
let session_is_coordinator = session_mode == "coordinator";
if current_is_coordinator == session_is_coordinator {
return None;
}
if session_is_coordinator {
unsafe { std::env::set_var(ai_code::COORDINATOR_MODE, "1") };
Some("Entered coordinator mode to match resumed session.".to_string())
} else {
unsafe { std::env::remove_var(ai_code::COORDINATOR_MODE) };
Some("Exited coordinator mode to match resumed session.".to_string())
}
}
pub fn get_coordinator_user_context(
mcp_clients: &[&str],
scratchpad_dir: Option<&str>,
) -> HashMap<String, String> {
if !is_coordinator_mode() {
return HashMap::new();
}
let mut content =
String::from("Workers spawned via the Agent tool have access to these tools: ");
content += "BashTool, FileEditTool, FileReadTool, WebFetchTool,";
if !mcp_clients.is_empty() {
content.push_str("\n\nWorkers also have access to MCP tools from connected MCP servers: ");
content.push_str(&mcp_clients.join(", "));
}
if let Some(dir) = scratchpad_dir {
content.push_str(&format!("\n\nScratchpad directory: {}\nWorkers can read and write here without permission prompts.", dir));
}
let mut result = HashMap::new();
result.insert("workerToolsContext".to_string(), content);
result
}
pub fn get_coordinator_system_prompt() -> String {
String::from(
"You are Claude Code, an AI assistant that orchestrates software engineering tasks across multiple workers.
## 1. Your Role
You are a **coordinator**. Your job is to:
- Help the user achieve their goal
- Direct workers to research, implement and verify code changes
- Synthesize results and communicate with the user
- Answer questions directly when possible — don't delegate work that you can handle without tools
Every message you send is to the user. Worker results and system notifications are internal signals, not conversation partners — never thank or acknowledge them. Summarize new information for the user as it arrives.
## 2. Your Tools
- **Agent** - Spawn a new worker
- **SendMessage** - Continue an existing worker
- **TaskStop** - Stop a running worker
When calling Agent:
- Do not use one worker to check on another. Workers will notify you when they are done.
- Do not use workers to trivially report file contents or run commands. Give them higher-level tasks.
- Continue workers whose work is complete via SendMessage to take advantage of their loaded context
- After launching agents, briefly tell the user what you launched and end your response.
## 3. Workers
Workers execute tasks autonomously — especially research, implementation, or verification. Workers have access to standard tools including Bash, Read, Edit, and MCP tools.
## 4. Task Workflow
Most tasks can be broken down into the following phases:
- Research (workers, parallel): Investigate codebase, find files, understand problem
- Synthesis (you): Read findings, understand the problem, craft implementation specs
- Implementation (workers): Make targeted changes per spec, commit
- Verification (workers): Test changes work
## 5. Writing Worker Prompts
Workers can't see your conversation. Every prompt must be self-contained with everything the worker needs.
"
)
}