feat: add ExecutionMode and CliExecutor for CLI orchestration

新增功能:
- ExecutionMode 枚舉 (Python/Cli/Hybrid)
- EXECUTION_MODE 全局配置
- CliExecutor 結構體

實現細節:
- config.rs: 添加 ExecutionMode 和相關函數
- executor.rs: 添加 CliExecutor 用於調用 Swift/Rust CLI

配置方式:
- MOMENTRY_EXECUTION_MODE=python/cli/hybrid (默認: hybrid)

下一步:
- 實現具體的 CLI 調用邏輯
- 添加環境變數切換測試
This commit is contained in:
Accusys
2026-09-27 13:19:11 +08:00
parent 40749888e3
commit 11319c0493
2 changed files with 76 additions and 0 deletions
+49
View File
@@ -1411,6 +1411,55 @@ impl Default for PythonExecutor {
}
}
// ─────────────────────────────────────────────────────────────
// CLI Executor for Swift/Rust processors
// ─────────────────────────────────────────────────────────────
pub struct CliExecutor {
cli_dir: PathBuf,
}
impl CliExecutor {
pub fn new() -> Result<Self> {
let cli_dir = std::env::var("MOMENTRY_CLI_DIR")
.unwrap_or_else(|_| {
let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
manifest.join("tools/cli").to_string_lossy().to_string()
});
let cli_path = PathBuf::from(&cli_dir);
if !cli_path.exists() {
anyhow::bail!(
"CLI directory not found at {} (set MOMENTRY_CLI_DIR env var)",
cli_dir
);
}
Ok(Self {
cli_dir: cli_path,
})
}
pub fn swift_cli_path(&self, name: &str) -> PathBuf {
self.cli_dir.join("swift").join(".build").join("release").join(name)
}
pub fn rust_cli_path(&self, name: &str) -> PathBuf {
self.cli_dir.join("rust").join("target").join("release").join(name)
}
pub fn cli_dir(&self) -> &PathBuf {
&self.cli_dir
}
}
impl Default for CliExecutor {
fn default() -> Self {
Self::new().expect("Failed to create CliExecutor")
}
}
#[cfg(test)]
mod tests {
use super::*;