use collector_core::{
data_dir, host_from_env, 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 host = host_from_env();
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://{host}:{ws_port}");
eprintln!("[RuntimeScope] HTTP API: http://{host}:{http_port}");
if !host.is_loopback() {
eprintln!(
"[RuntimeScope] ⚠ bound to {host} (non-loopback) — expose ONLY behind a \
reverse proxy/tunnel with TLS + access control (ADR-0010)"
);
}
serve(store, CommandHub::new(), pm, host, ws_port, http_port, VERSION.to_string(), AuthMode::Standalone, false)
.await
}