Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

2.5 KB
Raw Blame
// Always run as the Windows GUI subsystem so launching the Tauri app does
// not pop a console window. Without this, debug builds default to
// console-subsystem and a console flashes on every launch. The `core` and
// `mcp` subcommand paths below re-attach to the parent shell's console at
// runtime via AttachConsole, so command-line output still works.
#![cfg_attr(target_os = "windows", windows_subsystem = "windows")]

fn main() {
    // Every path below boots a core that must reach the hosted backend
    // (billing, integrations, channel relay, login). Each boots through an
    // `openhuman_rpc::host` entry (`cli` for `core`/`mcp`, `desktop` for the
    // GUI's embedded server), which connects the TinyHumans backend transport
    // itself, so there is no separate install step here.
    let args: Vec<String> = std::env::args().collect();
    let sub = args.get(1).map(String::as_str);
    if sub == Some("core") {
        // CLI path: re-attach to the parent shell's console so eprintln!
        // output lands in the cmd/PowerShell window the user invoked us
        // from. No-op (and harmless) when launched without a parent
        // console, e.g. from Explorer.
        #[cfg(target_os = "windows")]
        attach_parent_console();

        if let Err(err) = openhuman::run_core_from_args(&args[2..]) {
            eprintln!("core process failed: {err}");
            std::process::exit(1);
        }
        return;
    }

    // MCP clients (e.g. the Claude Code CLI provider) spawn this binary as
    // `<bin> mcp` to get a stdio MCP server. The standalone `openhuman-core`
    // binary already accepts `mcp` directly; route it here too so the desktop
    // app binary behaves the same instead of falling through to GUI startup.
    if matches!(sub, Some("mcp") | Some("mcp-server")) {
        #[cfg(target_os = "windows")]
        attach_parent_console();

        if let Err(err) = openhuman::run_core_from_args(&args[1..]) {
            eprintln!("core mcp server failed: {err}");
            std::process::exit(1);
        }
        return;
    }

    openhuman::run()
}

#[cfg(target_os = "windows")]
fn attach_parent_console() {
    use windows_sys::Win32::System::Console::{AttachConsole, ATTACH_PARENT_PROCESS};
    // SAFETY: AttachConsole has no preconditions beyond a valid PID constant.
    // It returns 0 on failure (no parent console / already attached); both
    // outcomes are fine for our use — we just won't print anything in that
    // case, matching the GUI-launch behavior.
    unsafe {
        AttachConsole(ATTACH_PARENT_PROCESS);
    }
}