proses 0.1.1

Proses – Professional Secure Execution System
pub mod runner;
pub mod store;

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, path::PathBuf};

/// Lifecycle state of a managed process.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum ProcessStatus {
    /// Process is alive and being monitored.
    Running,
    /// Process was deliberately stopped by the user.
    Stopped,
    /// Process crashed and exhausted its restart budget.
    Errored,
}

impl std::fmt::Display for ProcessStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Running => write!(f, "online"),
            Self::Stopped => write!(f, "stopped"),
            Self::Errored => write!(f, "errored"),
        }
    }
}

/// A single managed process entry.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Process {
    /// Monotonically increasing ID assigned by the daemon.
    pub id: u32,

    /// Human-readable name (must be unique).
    pub name: String,

    /// OS PID of the currently running process instance.
    /// 0 when the process is stopped or not yet started.
    pub pid: u32,

    /// Shell command passed verbatim to `sh -c`.
    pub command: String,

    /// Working directory for the process.
    pub cwd: PathBuf,

    /// Extra environment variables merged on top of the daemon's env.
    pub env: HashMap<String, String>,

    /// Current lifecycle status.
    pub status: ProcessStatus,

    /// Total number of automatic restarts since the process was created.
    pub restarts: u32,

    /// Maximum automatic restarts before marking as errored (0 = unlimited).
    pub max_restarts: u32,

    /// Timestamp of the most recent spawn.
    pub started_at: DateTime<Utc>,

    /// Absolute path to the stdout log file.
    pub log_out: PathBuf,

    /// Absolute path to the stderr log file.
    pub log_err: PathBuf,
}