netsky 0.1.4

netsky CLI: the viable system launcher and subcommand dispatcher
Documentation
//! `netsky agentinfinity` — idempotently spawn the watchdog tmux session.
//!
//! Clears the readiness marker before spawn so the marker transitions
//! empty → present during agentinfinity's own startup (its final boot
//! step touches the marker; `netsky agentinit` polls for it). Ticker +
//! launchd integration is triggered by the caller (typically `netsky
//! up`) via the respective subcommands.

use std::fs;

use netsky_core::agent::AgentId;
use netsky_core::paths::{agentinfinity_ready_marker, ensure_state_dir};
use netsky_core::spawn::{self, SpawnOptions, SpawnOutcome};

pub fn run() -> netsky_core::Result<()> {
    let agent = AgentId::Agentinfinity;
    if spawn::is_up(agent) {
        println!(
            "[agentinfinity] session '{}' already up; skipping spawn",
            agent
        );
        return Ok(());
    }

    ensure_state_dir()?;
    let marker = agentinfinity_ready_marker();
    if marker.exists() {
        fs::remove_file(&marker).ok();
    }

    let cwd = std::env::current_dir()?;
    let opts = SpawnOptions::defaults_for(agent, cwd);
    match spawn::spawn(agent, &opts)? {
        SpawnOutcome::Spawned => {
            println!(
                "[agentinfinity] spawned '{}' ({})",
                agent,
                opts.runtime.describe()
            );
        }
        SpawnOutcome::AlreadyUp => {
            println!("[agentinfinity] already up (race)");
        }
    }
    Ok(())
}