use collector_core::{
data_dir, open_store, port_from_env, serve, AuthMode, CommandHub, PmStore, DEFAULT_HTTP_PORT,
DEFAULT_WS_PORT, VERSION,
};
#[tokio::main]
async fn main() -> std::io::Result<()> {
let ws_port = port_from_env("RUNTIMESCOPE_PORT", DEFAULT_WS_PORT);
let http_port = port_from_env("RUNTIMESCOPE_HTTP_PORT", DEFAULT_HTTP_PORT);
collector_core::migration::first_run_guard(&data_dir()).map_err(std::io::Error::other)?;
let store = open_store()
.await
.map_err(|e| std::io::Error::other(format!("store init failed: {e}")))?;
let pm = PmStore::open(&data_dir().join("pm.db"))
.map_err(|e| std::io::Error::other(format!("pm store init failed: {e}")))?;
eprintln!("[RuntimeScope] collector-server (rust {VERSION})");
eprintln!("[RuntimeScope] WebSocket: ws://127.0.0.1:{ws_port}");
eprintln!("[RuntimeScope] HTTP API: http://127.0.0.1:{http_port}");
serve(store, CommandHub::new(), pm, ws_port, http_port, VERSION.to_string(), AuthMode::Standalone, false)
.await
}