netsky 0.1.6

netsky CLI: the viable system launcher and subcommand dispatcher
Documentation
//! `netsky nap <seconds>` — write the quiet sentinel before a long
//! harness-owned ScheduleWakeup.
//!
//! The harness still owns the actual sleep primitive. This command
//! closes the memory-gated part of the contract: for naps long enough
//! to collide with the pane-stable detector, it writes the sentinel and
//! prints the exact ScheduleWakeup arguments to use next.

const QUIET_MARGIN_S: u64 = 60;
const LONG_NAP_S: u64 = 20 * 60;

pub fn run(seconds: u64, reason: Option<&str>) -> netsky_core::Result<()> {
    if seconds == 0 {
        netsky_core::bail!("seconds must be > 0");
    }

    let reason = reason.unwrap_or("planned nap");
    if seconds >= LONG_NAP_S {
        let quiet_seconds = seconds.saturating_add(QUIET_MARGIN_S);
        crate::cmd::quiet::run(quiet_seconds, Some(reason))?;
        println!(
            "nap prepared: quiet sentinel covers {quiet_seconds}s ({seconds}s + {QUIET_MARGIN_S}s margin)"
        );
    } else {
        println!("nap prepared: {seconds}s is below {LONG_NAP_S}s; quiet sentinel not needed");
    }
    println!("next: ScheduleWakeup(delaySeconds={seconds}, reason=\"{reason}\")");
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn rejects_zero() {
        assert!(run(0, None).is_err());
    }
}