| 1 | use serde::{Deserialize, Serialize}; |
| 2 | |
| 3 | const CLAUDE_COMMAND: &str = |
| 4 | "claude -p --output-format stream-json --verbose --session-id {session_id}"; |
| 5 | const COPILOT_COMMAND: &str = "copilot -p {prompt} --output-format json --session-id {session_id}"; |
| 6 | pub(crate) const LEGACY_CLAUDE_WSL_OPEN_SESSION: &str = |
| 7 | "wt.exe wsl.exe --cd {cwd} -e claude --resume {session_id}"; |
| 8 | pub(crate) const LEGACY_COPILOT_WSL_OPEN_SESSION: &str = |
| 9 | "wt.exe wsl.exe --cd {cwd} -e copilot --resume {session_id}"; |
| 10 | const CLAUDE_WSL_OPEN_SESSION: &str = |
| 11 | "wt.exe wsl.exe --cd {cwd} -e sh -lc \"exec claude --resume {session_id}\""; |
| 12 | const COPILOT_WSL_OPEN_SESSION: &str = |
| 13 | "wt.exe wsl.exe --cd {cwd} -e sh -lc \"exec copilot --resume {session_id}\""; |
| 14 | |
| 15 | #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] |
| 16 | pub enum Environment { |
| 17 | #[default] |
| 18 | Host, |
| 19 | Wsl { |
| 20 | distro: Option<String>, |
| 21 | }, |
| 22 | } |
| 23 | |
| 24 | #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] |
| 25 | pub enum OutputFormat { |
| 26 | #[default] |
| 27 | ClaudeStreamJson, |
| 28 | CopilotJsonl, |
| 29 | Text, |
| 30 | } |
| 31 | |
| 32 | #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] |
| 33 | #[serde(default)] |
| 34 | pub struct AgentProfile { |
| 35 | pub id: String, |
| 36 | pub name: String, |
| 37 | pub environment: Environment, |
| 38 | pub command: String, |
| 39 | pub output: OutputFormat, |
| 40 | pub open_session_command: String, |
| 41 | pub mcp_config_flag: String, |
| 42 | } |
| 43 | |
| 44 | impl AgentProfile { |
| 45 | pub(crate) fn migrate_open_session_command(&mut self) { |
| 46 | let replacement = match self.open_session_command.as_str() { |
| 47 | LEGACY_CLAUDE_WSL_OPEN_SESSION => CLAUDE_WSL_OPEN_SESSION, |
| 48 | LEGACY_COPILOT_WSL_OPEN_SESSION => COPILOT_WSL_OPEN_SESSION, |
| 49 | _ => return, |
| 50 | }; |
| 51 | self.open_session_command = replacement.to_string(); |
| 52 | } |
| 53 | |
| 54 | pub fn claude_wsl() -> Self { |
| 55 | Self { |
| 56 | id: "claude".to_string(), |
| 57 | name: "Claude Code (WSL)".to_string(), |
| 58 | environment: Environment::Wsl { distro: None }, |
| 59 | command: CLAUDE_COMMAND.to_string(), |
| 60 | output: OutputFormat::ClaudeStreamJson, |
| 61 | open_session_command: CLAUDE_WSL_OPEN_SESSION.to_string(), |
| 62 | mcp_config_flag: "--mcp-config".to_string(), |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | pub fn claude_host() -> Self { |
| 67 | Self { |
| 68 | id: "claude-host".to_string(), |
| 69 | name: "Claude Code".to_string(), |
| 70 | environment: Environment::Host, |
| 71 | command: CLAUDE_COMMAND.to_string(), |
| 72 | output: OutputFormat::ClaudeStreamJson, |
| 73 | open_session_command: "wt.exe -d {cwd} claude --resume {session_id}".to_string(), |
| 74 | mcp_config_flag: "--mcp-config".to_string(), |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | pub fn copilot_wsl() -> Self { |
| 79 | Self { |
| 80 | id: "copilot".to_string(), |
| 81 | name: "Copilot CLI (WSL)".to_string(), |
| 82 | environment: Environment::Wsl { distro: None }, |
| 83 | command: COPILOT_COMMAND.to_string(), |
| 84 | output: OutputFormat::CopilotJsonl, |
| 85 | open_session_command: COPILOT_WSL_OPEN_SESSION.to_string(), |
| 86 | mcp_config_flag: "--additional-mcp-config".to_string(), |
| 87 | } |
| 88 | } |
| 89 | } |