tail-fin-daemon 0.7.8

Long-running browser-session daemon for tail-fin (tfd binary). Keeps Chrome tabs warm across invocations via a Unix-socket protocol; registers Site implementations through a runtime Arc<dyn Site> registry.
Documentation
use crate::spawn::ensure_daemon_safe;
use clap::Subcommand;
use night_fury_daemon_core::cli::make_req;
use night_fury_daemon_core::client;
use serde_json::json;

use super::{acquire_then_exec, ExecArgs};

#[derive(Subcommand)]
pub enum BloombergCmd {
    /// Normalized section article list (ai, tech, economics, industries, politics, green, opinion)
    Section {
        section: String,
        #[arg(long, default_value_t = 10)]
        limit: u64,
        #[arg(long, default_value_t = 0)]
        offset: u64,
    },
    /// Normalized article body by Bloomberg story ID
    Article { story_id: String },
    /// Section list plus normalized article bodies
    SectionFull {
        section: String,
        #[arg(long, default_value_t = 5)]
        limit: u64,
        #[arg(long, default_value_t = 0)]
        offset: u64,
    },
}

pub async fn run(
    cmd: BloombergCmd,
    socket: &str,
    host: &str,
    session: Option<String>,
) -> anyhow::Result<()> {
    let (cmd_name, params) = match cmd {
        BloombergCmd::Section {
            section,
            limit,
            offset,
        } => (
            "bloomberg.section",
            json!({"section": section, "limit": limit, "offset": offset}),
        ),
        BloombergCmd::Article { story_id } => ("bloomberg.article", json!({"story_id": story_id})),
        BloombergCmd::SectionFull {
            section,
            limit,
            offset,
        } => (
            "bloomberg.section-full",
            json!({"section": section, "limit": limit, "offset": offset}),
        ),
    };

    if let Some(sid) = session {
        ensure_daemon_safe(socket).await?;
        let req = make_req(cmd_name, Some(&sid), params);
        let resp = client::send(socket, &req).await?;
        super::print_and_check(&resp);
        return Ok(());
    }

    let args = ExecArgs {
        site: "bloomberg",
        host,
        cmd: cmd_name,
        params,
    };
    acquire_then_exec(socket, args).await
}