#![cfg_attr(coverage_nightly, coverage(off))]
use crate::agent::{AgentDaemon, DaemonConfig, DaemonManager};
use crate::cli::AgentCommands;
use anyhow::{anyhow, Result};
use std::path::PathBuf;
use std::time::Duration;
use tokio::fs;
use tracing::{error, info, warn};
#[derive(Debug, Clone)]
struct AgentStartConfig {
_project_path: PathBuf,
config_path: Option<PathBuf>,
working_dir: Option<PathBuf>,
pid_file: Option<PathBuf>,
log_file: Option<PathBuf>,
foreground: bool,
health_interval: u64,
max_memory_mb: u64,
auto_restart: bool,
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub async fn handle_agent_command(command: AgentCommands) -> Result<()> {
match command {
AgentCommands::Start {
project_path,
config,
working_dir,
pid_file,
log_file,
foreground,
health_interval,
max_memory_mb,
no_auto_restart,
} => {
let start_config = AgentStartConfig {
_project_path: project_path,
config_path: config,
working_dir,
pid_file,
log_file,
foreground,
health_interval,
max_memory_mb,
auto_restart: !no_auto_restart,
};
handle_agent_start(start_config).await
}
AgentCommands::Stop {
pid_file,
force,
timeout,
} => handle_agent_stop(pid_file, force, timeout).await,
AgentCommands::Status { pid_file, format } => handle_agent_status(pid_file, format).await,
AgentCommands::Monitor {
project_path,
project_id,
thresholds,
} => handle_agent_monitor(project_path, project_id, thresholds).await,
AgentCommands::Unmonitor { project_id } => handle_agent_unmonitor(project_id).await,
AgentCommands::Health { pid_file, detailed } => {
handle_agent_health(pid_file, detailed).await
}
AgentCommands::Reload { pid_file, config } => handle_agent_reload(pid_file, config).await,
AgentCommands::QualityGate {
project,
file,
format,
} => handle_agent_quality_gate(project, file, format).await,
AgentCommands::McpServer { config, debug } => handle_agent_mcp_server(config, debug).await,
}
}
include!("agent_daemon_lifecycle.rs");
include!("agent_monitoring_handlers.rs");
include!("agent_mcp_server.rs");
include!("agent_handlers_tests.rs");
include!("agent_handlers_property_tests.rs");